import type { IObjectOf } from "@thi.ng/api"; export interface ILifecycle { /** * Component init method. Called with the actual DOM element, hdom user * context and any other args when the component is first used, but * **after** `render()` has been called once already AND all of the * components children have been realized. Therefore, if any children have * their own `init` lifecycle method, these hooks will be executed before * that of the parent. */ init?(el: Element, ctx: any, ...args: any[]): void; /** * Returns the hdom tree of this component. Note: Always will be called * first (prior to `init`/`release`) to obtain the actual component * definition used for diffing. Therefore might have to include checks if * any local state has already been initialized via `init`. This is the only * mandatory method which MUST be implemented. * * `render` is executed before `init` because `normalizeTree()` must obtain * the component's hdom tree first before it can determine if an `init` is * necessary. `init` itself will be called from `diffTree`, `createDOM` or * `hydrateDOM()` in a later phase of processing. * * `render` should ALWAYS return an array or another function, else the * component's `init` or `release` fns will NOT be able to be called later. * E.g. If the return value of `render` evaluates as a string or number, the * return value should be wrapped as `["span", "foo"]`. If no `init` or * `release` are used, this requirement is relaxed. */ render(ctx: any, ...args: any[]): any; /** * Called when the underlying DOM of this component is removed (or * replaced). Intended for cleanup tasks. */ release?(ctx: any, ...args: any[]): void; } export interface HDOMBehaviorAttribs { /** * HDOM behavior control attribute. If true (default), the element will be * fully processed by `diffTree()`. If false, no diff will be computed and * the `replaceChild()` operation will be called in the currently active * hdom target implementation. */ __diff?: boolean; /** * HDOM behavior control attribute. If true, the element will not be diffed * and simply skipped. IMPORTANT: This attribute is only intended for cases * when a component / tree branch should not be updated, but MUST NEVER be * enabled when that component is first included in the tree. Doing so will * result in undefined future behavior. * * Note, skipped elements and their children are being normalized, but are * ignored during diffing. Therefore, if this attribute is enabled the * element should either have no children OR the children are the same * (type) as when the attribute is disabled (i.e. when `__skip` is falsy). */ __skip?: boolean; /** * HDOM behavior control attribute. If present, the element and all of its * children will be processed by the given `HDOMImplementation` instead of * the default implementation. */ __impl?: HDOMImplementation; /** * HDOM behavior control attribute. If `false`, the current element's * children will not be normalized. Use this when you're sure that all * children are already in canonical format (incl. `key` attributes). See * `normalizeTree()` for details. */ __normalize?: boolean; /** * HDOM behavior control attribute. If `false`, hdom will not attempt to * call `release()` lifecycle methods on this element or any of its * children. */ __release?: boolean; /** * Currently only used by [`thi.ng/hiccup`](https://thi.ng/hiccup). No * relevance for hdom. If `false`, the element and its children will be * omitted from the serialized result. */ __serialize?: boolean; } export interface ComponentAttribs extends HDOMBehaviorAttribs { class?: string; disabled?: boolean; href?: string; id?: string; key?: string; style?: string | IObjectOf; [_: string]: any; } export interface HDOMOpts { /** * Root element or ID * @defaultValue "app" */ root?: Element | string; /** * Arbitrary user context object, passed to all component functions embedded * in the tree. */ ctx?: any; /** * Attempts to auto-expand/deref the given keys in the user supplied context * object (`ctx` option) prior to *each* tree normalization. All of these * values should implement the * [`IDeref`](https://docs.thi.ng/umbrella/api/interfaces/IDeref.html) * interface (e.g. atoms, cursors, views, rstreams etc.). This feature can * be used to define dynamic contexts linked to the main app state, e.g. * using derived views provided by [`thi.ng/atom`](https://thi.ng/atom). * * @defaultValue none */ autoDerefKeys: PropertyKey[]; /** * If true, each elements will receive an auto-generated `key` attribute * (unless one already exists). * * @defaultValue true */ keys?: boolean; /** * If true, all text content will be wrapped in `` elements. Spans * will never be created inside