UNPKG

@muban/muban

Version:

Writing components for server-rendered HTML

74 lines (73 loc) 3.38 kB
import type { App, AppContext } from './api/apiCreateApp'; import type { Binding } from './bindings/bindings.types'; import type { LifecycleHooks } from './api/apiLifecycle'; import type { PropTypeDefinition, TypedProps } from './props/propDefinitions.types'; import type { ComponentRefItem, RefElementType, TypedRefs } from './refs/refDefinitions.types'; declare type CheckAny<T, Y, N> = 0 extends 1 & T ? Y : N; export declare type IsAny<T> = CheckAny<T, true, never>; export declare type IfAny<T, I, E> = IsAny<T> extends never ? E : I; export declare type ComponentFactory<P extends Record<string, PropTypeDefinition> = any, N extends string = any> = ComponentReturnValue<TypedProps<P>> & ComponentDisplayName<N>; export declare type ComponentApi<T extends ComponentFactory = any> = IsAny<T> extends true ? ReturnType<ComponentFactory> : ReturnType<T>; export declare type InternalNodeInstance = { uid: number; type: 'component' | 'ref'; name: string; parent: InternalComponentInstance | null; appContext: AppContext; element: RefElementType; binding?: Binding; }; declare type LifecycleHook = Array<Function> | null; export declare type InternalComponentInstance = InternalNodeInstance & { api: ComponentApi | null; subTree: Array<InternalNodeInstance>; props: Record<string, unknown>; reactiveProps: Record<string, unknown>; refs: TypedRefs<Record<string, ComponentRefItem>>; provides: Record<string, unknown>; children: Array<ComponentApi>; bindings: Array<Binding>; refChildren: Array<InternalNodeInstance>; removeBindingsList?: Array<(() => void) | undefined>; disposers: Array<() => void>; options: DefineComponentOptions<Record<string, PropTypeDefinition>, Record<string, ComponentRefItem>, string>; isSetup: boolean; isMounted: boolean; isUnmounted: boolean; [LifecycleHooks.Mounted]: LifecycleHook; [LifecycleHooks.Unmounted]: LifecycleHook; mount: () => void; unmount: () => void; }; export declare type ComponentCreateOptions = Partial<{ parent: InternalComponentInstance; app: App; }>; export declare type ComponentDisplayName<T extends string> = { displayName: T; }; export declare type ComponentReturnValue<P extends Record<string, any> = Record<string, any>> = (element: HTMLElement, options?: ComponentCreateOptions) => { readonly name: string; setProps: (props: P) => void; readonly props: P; readonly element: HTMLElement; setup: () => void; dispose: () => void; __instance: InternalComponentInstance; }; export declare type DefineComponentSetupContext<P extends Record<string, PropTypeDefinition>, R extends Record<string, ComponentRefItem>> = { props: Readonly<TypedProps<P>>; refs: TypedRefs<R>; element: HTMLElement; }; export declare type DefineComponentOptions<P extends Record<string, PropTypeDefinition> = {}, R extends Record<string, ComponentRefItem> = {}, N extends string = ''> = { name: N; components?: Array<ComponentFactory | LazyComponent>; props?: P; refs?: R; setup?: (context: DefineComponentSetupContext<P, R>) => undefined | null | Array<Binding>; }; export declare type LazyComponent<N extends string = any, P extends Record<string, PropTypeDefinition> = any> = (() => Promise<ComponentFactory<P>>) & ComponentDisplayName<N> & { isLazy: true; }; export {};