import { IRefOrRefs } from "./ref"; import { ComponentInstance, TShouldUpdate } from "./component"; import { ClassNameItem } from "./jsx-types"; import { IState } from "./states"; export type VirtualNodeTypes = "comment" | "text" | "element"; export interface IVirtualNode { virtualType: VirtualNodeTypes; parent?: IVirtualElement; } export interface IVirtualComment extends IVirtualNode { virtualType: "comment"; data: string; } export interface IVirtualText extends IVirtualNode { virtualType: "text"; nodeValue: string; } export interface IVirtualElement extends IVirtualNode { virtualType: "element"; namespace: string; type: string; readonly attributes: object; readonly children: IVirtualNode[]; addEventListener(...rest: any[]): any; removeEventListener(...rest: any[]): any; setAttribute(name: string, value: any): any; getAttribute(name: string): any; removeAttribute(name: string): any; removeChild(child: IVirtualNode): any; appendChild(child: IVirtualNode): any; remove(): any; insertBefore(child: IVirtualNode, before: IVirtualNode): any; innerHTML: string; toString(): string; style: object; } export interface IVirtualDocument { createComment(data: string): IVirtualComment; createTextNode(data: string): IVirtualText; createElement(type: string): IVirtualElement; createElementNS(namespace: string, type: string): IVirtualElement; isVirtual: true; } export type TComponentFunctionProperties = { isFactory?: boolean; shouldUpdate?: TShouldUpdate; renderFilter?: (component: ComponentInstance, renderResult: VNode) => VNode; }; export type RenderDom = Element | Text | Comment; export type RenderFunction = (props?: GProps) => VNode; export type ComponentReturn = RenderFunction | VNode; export type FactoryComponent = (props?: GProps) => RenderFunction; export type ComponentFunction = (RenderFunction | FactoryComponent) & TComponentFunctionProperties; export type LifecycleHandler> = (...rest: any[]) => GReturn; type LifecycleHandlerMultipleReturns = (LifecycleHandler | boolean)[]; export type MountHandler = (LifecycleHandler | LifecycleHandler); type _VNodeTypes_NULL = 0; type _VNodeTypes_TEXT = 1; type _VNodeTypes_ARGUMENT_STATE = 2; type _VNodeTypes_VALUE_STATE = 3; type _VNodeTypes_CONTAINERS = 4; type _VNodeTypes_ROOT = 5; type _VNodeTypes_ELEMENT = 6; type _VNodeTypes_COMPONENT = 7; type _VNodeTypes_LIST = 8; export type VNodeTypes = _VNodeTypes_NULL | _VNodeTypes_TEXT | _VNodeTypes_ARGUMENT_STATE | _VNodeTypes_VALUE_STATE | _VNodeTypes_CONTAINERS | _VNodeTypes_ROOT | _VNodeTypes_ELEMENT | _VNodeTypes_COMPONENT | _VNodeTypes_LIST; export type VNodeElementValue = keyof (HTMLElementTagNameMap | SVGElementTagNameMap); export type VNodeTextValue = string; export type VNodeValue = (VNodeElementValue | VNodeTextValue | ComponentFunction | IState) & TComponentFunctionProperties; export interface VNode { type: VNodeTypes; value: VNodeValue; props?: DefaultReflexProps; dom?: RenderDom; component?: ComponentInstance; _keys?: Map; _propertyName?: string; _id?: number; _isSVG?: boolean; _document?: Document | IVirtualDocument; } export interface DefaultReflexBaseProps { key?: number | string; ref?: IRefOrRefs; innerHTML?: string; innerText?: string; } export interface DefaultReflexProps extends DefaultReflexBaseProps { children?: VNode[]; } export interface HasClassProp { class?: ClassNameItem | ClassNameItem[]; } export declare const _dispatch: (handlers: Function[], ...rest: any[]) => any[]; type TTaskHandler = (element: GType) => void; /** * TODO : DOC * @param task */ export declare function createBatch(task: TTaskHandler): (element: GType, resolve?: () => any) => void; export declare let _featureHooks: THookHandler[]; type THookHandler = (type: number, ...rest: any[]) => any | void; /** * Hook into Reflex core functions. * Will call handler for every hook. Handler have to check type * 0 -> NEW ROOT Rendered a root. [ previousNode, newNode ] * 1 -> MOUNT / UNMOUNT Component mounted or unmounted [ componentInstance, isMounted ] * 2 -> DIFFING NODE Updating a component node [ vNode ]. Have to return a handler, called when diffing finished. * 3 -> MUTATING NODE Mutating a dom element [ key ] * 4 -> NEW STATE A new state is created * @param handler */ export declare function featureHook(handler: THookHandler): () => THookHandler[]; export {};