@muban/muban
Version:
Writing components for server-rendered HTML
80 lines (79 loc) • 4.68 kB
TypeScript
import type { Ref } from '@vue/reactivity';
import type { ComponentFactory } from '../Component.types';
import type { RefElementType, CollectionRef, ComponentParams, ComponentsRef, AnyRef, ElementRef, ComponentRef } from '../refs/refDefinitions.types';
import type { Binding, BindProps, TemplateProps } from './bindings.types';
export declare function bind<T extends Pick<AnyRef<RefElementType>, 'getBindingDefinition'>>(target: T, props: Pick<Parameters<T['getBindingDefinition']>[0], keyof Parameters<T['getBindingDefinition']>[0]>): ElementBinding<RefElementType, BindProps> | CollectionBinding<RefElementType, BindProps> | ComponentBinding<{
readonly name: string;
setProps: (props: import("../..").TypedProps<any>) => void;
readonly props: import("../..").TypedProps<any>;
readonly element: HTMLElement;
setup: () => void;
dispose: () => void;
__instance: import("../Component.types").InternalComponentInstance;
}> | ComponentCollectionBinding<{
readonly name: string;
setProps: (props: import("../..").TypedProps<any>) => void;
readonly props: import("../..").TypedProps<any>;
readonly element: HTMLElement;
setup: () => void;
dispose: () => void;
__instance: import("../Component.types").InternalComponentInstance;
}>;
export declare type BindMapBinding = {
type: 'bindMap';
getElements(): ReadonlyArray<RefElementType>;
props: {};
dispose: () => void;
};
/**
*
* @param target Either a ref collection (either element or component),
* or an Array of refs. When an Array is passed, it just loops over the refs
* inside the Array and executes getProps to get the props for each ref.
* When a refCollection is called, it will keep watching for changes in the
* collection and call the getProps each time the collection is updated.
* @param getProps A function that will be called for each ref in the Array or
* Collection, receiving the ref and the index, and expects the binding object
* returned to apply this to each ref.
*/
export declare function bindMap<T extends Pick<CollectionRef<RefElementType, BindProps> | ComponentsRef<ComponentFactory<any>>, 'getRefs' | 'getBindingDefinition'>>(target: T, getProps: (ref: ReturnType<T['getRefs']>[number], index: number) => Parameters<T['getBindingDefinition']>[0]): Array<Binding>;
export declare function bindMap<T extends Pick<ElementRef<RefElementType, BindProps> | ComponentRef<ComponentFactory<any>>, 'getBindingDefinition'>>(target: Array<T>, getProps: (ref: T, index: number) => Parameters<T['getBindingDefinition']>[0]): Array<Binding>;
export declare type TemplateBinding<T extends RefElementType> = {
type: 'template';
props: TemplateProps<T>;
getElements(): ReadonlyArray<RefElementType>;
};
export declare function BindTemplate<T extends RefElementType>(props: TemplateProps<T>): TemplateBinding<T>;
export declare function bindTemplate(target: ElementRef<RefElementType, BindProps>, onUpdate: TemplateProps<RefElementType>['onUpdate'], options?: {
forceImmediateRender?: boolean;
extract?: TemplateProps<RefElementType>['extract'];
}): TemplateBinding<RefElementType>;
export declare type ElementBinding<T extends RefElementType, P extends BindProps> = {
ref: Ref<T | undefined>;
type: 'element';
props: P;
getElements(): Array<T>;
};
export declare function bindElement<T extends RefElementType, P extends BindProps>(ref: Ref<T | undefined>, props: P): ElementBinding<T, P>;
export declare type CollectionBinding<T extends RefElementType, P extends BindProps> = {
ref: Ref<ReadonlyArray<Ref<T>>>;
type: 'collection';
props: P;
getElements(): ReadonlyArray<T>;
};
export declare function bindCollection<T extends RefElementType, P extends BindProps>(ref: Ref<ReadonlyArray<Ref<T>>>, props: P): CollectionBinding<T, P>;
export declare type SimpleComponentApi = Pick<ReturnType<ComponentFactory<any>>, 'setProps' | 'element'>;
export declare type ComponentBinding<T extends SimpleComponentApi> = {
ref: Ref<T | undefined>;
type: 'component';
props: ComponentParams<T>;
getElements(): ReadonlyArray<RefElementType>;
};
export declare function BindComponent<T extends SimpleComponentApi>(ref: Ref<T | undefined>, props: ComponentParams<T>): ComponentBinding<T>;
export declare type ComponentCollectionBinding<T extends SimpleComponentApi> = {
ref: Ref<ReadonlyArray<Ref<T>>>;
type: 'componentCollection';
props: ComponentParams<T>;
getElements(): ReadonlyArray<RefElementType>;
};
export declare function bindComponentCollection<T extends SimpleComponentApi>(ref: Ref<ReadonlyArray<Ref<T>>>, props: ComponentParams<T>): ComponentCollectionBinding<T>;