import { Injector } from './injector'; import { Changes, UpdateTemplate, MountTemplate } from './types'; import { Store } from './store'; export interface RefMap { [key: string]: Element | null; } export declare type ComponentEventHandler = (component: Component, event: Event, target: HTMLElement) => void; export declare type StaticEventHandler = (evt: Event) => void; export declare type PluginFactory = (component: C) => ComponentDefinition[] | undefined; export declare type PartialDeps = any[]; export interface AttachedStaticEvents { handler: StaticEventHandler; listeners: { [event: string]: ComponentEventHandler[]; }; } export interface Component

extends HTMLElement { /** * Pointer to component view container. By default, it’s the same as component * element, but for native Web Components it points to shadow root */ componentView: Element; /** Internal component model */ componentModel: ComponentModel; /** Component properties (external contract) */ props: P; /** Component state (internal contract) */ state: S; /** Named references to elements rendered inside current component */ refs: RefMap; /** A store, bound to current component */ store: T; /** Reference to the root component of the current app */ root?: Component; /** * Updates props with data from `value` * @param value Updated props */ setProps(value: Partial

): void; /** * Updates state with data from `value` * @param value Updated values */ setState(value: Partial): void; } declare type HookCallback = () => void; interface ComponentHooks { init: []; didChange: HookCallback[]; willMount: HookCallback[]; didMount: HookCallback[]; willRender: HookCallback[]; willUpdate: HookCallback[]; } /** * Internal Endorphin component descriptor */ interface ComponentModel { /** Component’s definition */ definition: ComponentDefinition; /** Plugins attached to current component, including current component definition */ plugins: ComponentDefinition[]; /** Injector for incoming component data */ input: Injector; /** Runtime variables */ vars: Record; /** Hooks callbacks */ hooks: ComponentHooks; /** * A function for updating rendered component content. Might be available * after component was mounted and only if component has update cycle */ update?: UpdateTemplate | undefined; /** List of attached event handlers */ events?: AttachedStaticEvents; /** Indicates that component was mounted */ mounted: boolean; /** Component render is queued */ queued: boolean; /** Indicates that component is preparing to rendering */ preparing: boolean; /** Default props values */ defaultProps: Record; partialDeps: PartialDeps | null; } /** * A definition of component, written as ES module */ export interface ComponentDefinition { /** Listeners for events bubbling from component contents */ events?: { [type: string]: ComponentEventHandler; }; /** * Public methods to attach to component element * @deprecated Use `extend` instead */ methods?: { [name: string]: (this: Component) => void; }; /** Methods and properties to extend component with */ extend?: Record; /** List of plugins for current component of factory method for producing plugins */ plugins?: ComponentDefinition[] | PluginFactory; /** A scope token to be added for every element, created inside current component bound */ cssScope?: string; /** * A function for rendering component contents. Will be added automatically * in compilation step with compiled HTML template, if not provided. * If rendered result must be updated, should return function that will be * invoked for update */ default?: MountTemplate; /** Initial props factory */ props?(component: Component): Record; /** Initial state factory */ state?(component: Component): Record; /** Returns instance of store used for components */ store?(root?: Component): Store; /** Component created */ init?(component: Component): void; /** Component is about to be mounted (will be initially rendered) */ willMount?(component: Component): void; /** Component just mounted (initially rendered) */ didMount?(component: Component): void; /** Component props changed */ didChange?(component: Component, changes: Changes): void; /** * Component is about to be updated (next renders after mount) * @param component * @param changes List of changed properties which caused component update */ willUpdate?(component: Component, changes: Changes): void; /** * Component just updated (next renders after mount) * @param component * @param changes List of changed properties which caused component update */ didUpdate?(component: Component, changes: Changes): void; /** * Component is about to be rendered. If `false` value is returned, component * rendering will be cancelled * @param component * @param changes List of changed properties which caused component update */ willRender?(component: Component, changes: Changes): void; /** * Component just rendered * @param component * @param changes List of changed properties which caused component update */ didRender?(component: Component, changes: Changes): void; /** Component is about to be removed */ willUnmount?(component: Component): void; /** Component was removed */ didUnmount?(component: Component): void; /** Contents of `slotName` slot were updated */ didSlotUpdate?(component: Component, slotName: string, slotContainer: Element | DocumentFragment): void; [key: string]: any; } /** * Creates Endorphin DOM component with given definition */ export declare function createComponent(name: string, definition: ComponentDefinition, host?: HTMLElement | Component): Component; /** * Convert HTMLElement into Endorphin DOM component with given definition */ export declare function createComponentFromElement(el: HTMLElement | Component, definition: ComponentDefinition, root?: Component): Component; /** * Mounts given component */ export declare function mountComponent(component: Component, props?: Record): void; /** * Updates given mounted component */ export declare function updateComponent(component: Component, props?: Record, partialDeps?: PartialDeps): number; /** * Destroys given component: removes static event listeners and cleans things up * @returns Should return nothing since function result will be used * as shorthand to reset cached value */ export declare function unmountComponent(component: Component): void; /** * Subscribes to store updates of given component */ export declare function subscribeStore(component: Component, keys?: string[]): void; /** * Schedules render of given component on next tick */ export declare function scheduleRender(component: Component, changes?: Changes): void; /** * Renders given component */ export declare function renderComponent(component: Component, changes?: Changes): void; export declare function afterUpdate(component: C, callback: HookCallback): void; export {};