class DDM implements DependencyManager { node: N; [DependencyManagerSymbol]: true; private dependenciesAreInstantiated; private initializePromise; private destroyPromise; private syncPromise; status: DDMStatus; private readonly mapTree; private directDependencies; private wrappedDependencies; private instantiatedDependencyListeners; private initializedDependencyListeners; private destroyedDependencyListeners; constructor(node: N, map: M | MapTreeBuilder, options?: Partial>); initializeDependencies(): Promise; /** * Initialize dependencies. */ private initializeDeps; syncDependencies(): Promise; get map(): WrapletDependencyMapWithDefaults; private instantiateDeps; instantiateDependencies(): void; private findExistingWraplet; private instantiateSingleWrapletDependency; private instantiateWrapletItem; private instantiateMultipleDependencies; addDependencyInstantiatedListener(id: K, callback: DependencyLifecycleListener): void; addDependencyInitializedListener(id: K, callback: DependencyLifecycleAsyncListener): void; addDependencyDestroyedListener(id: K, callback: DependencyLifecycleAsyncListener): void; setExistingInstance & Extract>(id: K, wraplet: DependencyInstance): void; addExistingInstance & Extract>(id: K, wraplet: DependencyInstance): void; private prepareIndividualWraplet; private createDependencyDestroyListener; /** * Checks whether a required dependency has been removed while the DDM * is NOT being destroyed itself. Returns the error instance instead of * throwing, so the caller can route it through the lifecycle error pipeline. */ private validateRequiredDependencyAfterRemoval; /** * This method removes from nodes references to this wraplet and its dependencies recursively. */ destroyDependencies(): Promise; private findChildrenElements; get dependencies(): WrapletDependencies; private removeDependency; private validateMapItem; private validateMapItemForNonParent; private validateElements; /** * Set up a proxy to check if dependencies have not been destroyed before fetching them. */ private wrapDependencies; private defaultOptions; private destroyDeps; /** * Creates a definition for creating a node wrapper. * * @param map_or_position * You can provide a map or a number representing the * relative position of the ancestor map that should be * reused. * * This is useful for recursive maps. * @param options */ static createInjector(map_or_position: WrapletDependencyMap | number, options?: DDMOptions): Injector; } type DDMOptions = { dependencyInstantiatedListeners?: Map[]>; dependencyInitializedListeners?: Map[]>; dependencyDestroyedListeners?: Map[]>; }; interface DDMStatus { isInitialized: boolean; isGettingInitialized: boolean; isGettingSynced: boolean; isDestroyed: boolean; isGettingDestroyed: boolean; } type DependencyLifecycleAsyncListener = (wraplet: DependencyInstance) => Promise; type DependencyLifecycleListener = (wraplet: DependencyInstance) => void; const DependencyManagerSymbol: unique symbol; /** * Dependency manager interface that defines the public API for managing wraplet relationships * and lifecycles. */ interface DependencyManager { [DependencyManagerSymbol]: true; /** * The node that the manager is managing. */ node: N; /** * Instantiate dependencies based on the map and the current node. */ instantiateDependencies(): void; /** * Initialize dependencies. */ initializeDependencies(): Promise; /** * Synchronizes dependencies in the DOM. * * When new nodes were added to the DOM, you might want to * synchronize the DependencyManager to inject new dependencies * that might be available. * * Dependencies that are no longer part of the descendant DOM tree * will be destroyed unless they are marked "destructable: false" * or have no "selector" property on the map. * * This is an experimental feature. * * @experimental */ syncDependencies(): Promise; /** * Destroy all dependencies. */ destroyDependencies(): Promise; /** * Add a listener that will be called when a dependency is initialized. */ addDependencyInitializedListener(id: K, callback: DependencyLifecycleAsyncListener): void; /** * Add a listener that will be called when a dependency is destroyed. */ addDependencyDestroyedListener(id: K, callback: DependencyLifecycleAsyncListener): void; /** * Add a listener that will be called when a dependency is instantiated. */ addDependencyInstantiatedListener(id: K, callback: DependencyLifecycleListener): void; /** * This method allows you to set an existing dependency instance. */ setExistingInstance & Extract>(id: K, wraplet: DependencyInstance): void; /** * This method allows you to add an existing dependency instance * to a wraplet set. */ addExistingInstance & Extract>(id: K, wraplet: DependencyInstance): void; /** * Get the available dependencies. */ readonly dependencies: WrapletDependencies; } function isDependencyManager(object: unknown): object is DependencyManager; type DestroyListener = (wraplet: W) => Promise; type WrapletCreator = (node: N, definition: WrapletDependencyDefinitionWithDefaults, map: MapTreeBuilder) => Wraplet; type Injector = { data?: D; callback: (node: N, map: MapTreeBuilder, data?: D) => unknown; }; const MapTreeBuilderSymbol: unique symbol; class MapTreeBuilder { private parent?; [MapTreeBuilderSymbol]: true; private map?; private children; constructor(parent?: MapTreeBuilder | undefined); getParent(): MapTreeBuilder; createChild(name: keyof M): MapTreeBuilder; setMap(map: M): void; getMap(): WrapletDependencyMapWithDefaults; } function isMapTreeBuilder(object: unknown): object is MapTreeBuilder; function addDefaultsToDependencyDefinition(definition: T): WrapletDependencyDefinitionWithDefaults; function fillMapWithDefaults(map: M): WrapletDependencyMapWithDefaults; class DNTM implements NodeTreeManager { private initializers; addNodeInitializer(callback: NodeInitializer): void; initializeNode(node: Node, context?: CONTEXT): Promise; destroyNode(node: Node): Promise; } type NodeInitializer = (node: Node, context?: CONTEXT) => Promise; interface NodeTreeManager { addNodeInitializer(callback: NodeInitializer): void; initializeNode(node: Node, context?: CONTEXT): Promise; destroyNode(node: Node): Promise; } function isParentNode(node: Node): node is ParentNode; function getWrapletsFromNode(node: N): WrapletSet | null; function removeWrapletFromNode(wraplet: Wraplet, node: N): boolean; function addWrapletToNode(wraplet: Wraplet, node: N): void; function actOnNodesRecursively(node: Node, callback: (node: Node) => void): void; function findWrapletsOutsideTheTree(wraplets: Wraplet[], node: Node): Promise; function destroyWrapletsRecursively(node: Node): Promise; class DefaultSearchableSet extends Set implements BaseSet { find(filter: (wraplet: T) => boolean): T[]; findOne(filter: (wraplet: T) => boolean): T | null; getOrdered(callback: (item: T) => number): T[]; } class DefaultWrapletSet extends DefaultSearchableSet implements WrapletSet, WrapletSetReadonly { [WrapletSetReadonlySymbol]: true; [WrapletSetSymbol]: true; } class DefaultWrapletSetReadonly extends DefaultSearchableSet implements WrapletSetReadonly { [WrapletSetReadonlySymbol]: true; } interface BaseSet { find(filter: (wraplet: T) => boolean): T[]; findOne(filter: (wraplet: T) => boolean): T | null; getOrdered(callback: (item: T) => number): T[]; } const WrapletSetSymbol: unique symbol; interface WrapletSet extends BaseSet, Set { [WrapletSetSymbol]: true; } function isWrapletSet(object: unknown): object is WrapletSet; const WrapletSetReadonlySymbol: unique symbol; interface WrapletSetReadonly extends BaseSet, ReadonlySet { [WrapletSetReadonlySymbol]: true; } interface AbstractDependentWrapletWiringArgs extends AbstractWrapletWiringArgs { dependencyManager: (() => DependencyManager) | DependencyManager; } abstract class AbstractDependentWraplet extends AbstractWraplet implements Wraplet { protected dm: DependencyManager; constructor(dm: DependencyManager); protected createWrapletApi(): WrapletApi; protected defaultWrapletApiWiring(): Wiring; /** * Dependencies. */ protected get d(): WrapletDependencies; static wiring(args: AbstractDependentWrapletWiringArgs): Wiring; protected static createDependencyManager(node: N, map: M): DependencyManager; protected static createWraplets(): InstanceType any>; protected static createAndInitializeWraplets(): Promise any>>; /** * Instantiates wraplets on a given ParentNode. * * @param node - The ParentNode to instantiate wraplets on. * @param attribute - The attribute to look for or a function to retrieve nodes. * @param map - The dependency map for the wraplets. * @param additional_args - Additional arguments to pass to the wraplet constructor. * * @returns An array of instantiated wraplets. */ protected static createDependentWraplets AbstractDependentWraplet, PN extends ParentNode>(this: T, node: PN, attribute: string | ((node: PN) => Iterable), map: WrapletDependencyMap, additional_args?: unknown[]): InstanceType[]; /** * Instantiates and initializes wraplets on a given ParentNode. * * @param node - The ParentNode to instantiate wraplets on. * @param attribute - The attribute to look for or a function to retrieve nodes. * @param map - The dependency map for the wraplets. * @param additional_args - Additional arguments to pass to the wraplet constructor. * * @returns An array of instantiated and initialized wraplets. */ protected static createAndInitializeDependentWraplets; }, PN extends ParentNode>(this: T, node: PN, attribute: string | ((node: PN) => Iterable), map: WrapletDependencyMap, additional_args?: unknown[]): Promise[]>; } interface AbstractWrapletWiringArgs { initializeCallback?: () => Promise; destroyCallback?: () => Promise; nodeManager?: (() => NodeManager | undefined) | NodeManager; } abstract class AbstractWraplet implements Wraplet { protected node: N; wraplet: WrapletApi; private _nodeManager; constructor(node: N); /** * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet) * can override this to supply their own lifecycle callbacks without causing a * double-creation of WrapletApi. */ protected createWrapletApi(): WrapletApi; protected defaultWrapletApiWiring(): Wiring; /** * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup * is always wired into the destroy path. * * @deprecated * The new method of building WrapletApi is through adding wirings in the `wrapletApiWirings` method. * `buildWrapletApi` method will be removed in future versions. */ protected buildWrapletApi(initializeCallback?: WrapletApiFactoryBasicCallback, destroyCallback?: WrapletApiFactoryBasicCallback): WrapletApi; /** * Wires up the WrapletApi with lifecycle callbacks and NodeManager integration. */ protected wrapletApiWirings(): Wiring[]; protected get nodeManager(): NodeManager; /** * Subclasses must return an array of constructors covering all types in union N. * Wrap the result in the `supportedTypeGuard` helper to make sure that the array contains all * and only classes that extend the given type. */ protected supportedNodeTypes(): readonly Constructable[] | null; /** * Helper for subclasses to easily satisfy the exhaustive check. */ protected supportedNodeTypesGuard[]>(types: T & (Exclude> extends never ? T : never)): T; /** * This method gets invoked when the wraplet is initialized. */ protected onInitialize(): Promise; /** * This method gets invoked when the wraplet is destroyed. */ protected onDestroy(): Promise; static wiring(args: AbstractWrapletWiringArgs): Wiring; /** * Instantiates wraplets on a given ParentNode. * * @param node - The ParentNode to instantiate wraplets on. * @param attribute - The attribute to look for or a function to retrieve nodes. * @param additional_args - Additional arguments to pass to the wraplet constructor. * * @returns An array of instantiated wraplets. */ protected static createWraplets AbstractWraplet, PN extends ParentNode>(this: T, node: PN, attribute: string | ((node: PN) => Iterable), additional_args?: unknown[]): InstanceType[]; /** * Instantiates and initializes wraplets on a given ParentNode. * * @param node - The ParentNode to instantiate wraplets on. * @param attribute - The attribute to look for or a function to retrieve nodes. * @param additional_args - Additional arguments to pass to the wraplet constructor. * * @returns An array of instantiated wraplets. */ protected static createAndInitializeWraplets; }, PN extends ParentNode>(this: T, node: PN, attribute: string | ((node: PN) => Iterable), additional_args?: unknown[]): Promise[]>; } class NodeManager implements Wireable { private node; private listeners; constructor(node: N); /** * Add a listener to the current node. */ addListener(eventName: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void; /** * Add a listener to one of the descendants. * * Note: Most of the time it's not recommended to use this * method because it makes a wraplet impure. * * Ideally, wraplet should directly interact only with its * own node. However, you can make a wraplet impure if you * know what you are doing. */ addListenerTo(target: SelectorCallback | string, eventName: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean, required?: boolean): void; destroy(): void; wiring(): Wiring; /** * @deprecated * For an existing instance, use `nodeManager.wiring()`. * For lazy wiring, use `lazyWiring`, but note that it evaluates the provider * on the first lifecycle event, which may be initialization. */ static wire(nodeManager: (() => NodeManager | undefined) | NodeManager): Wiring; } type Wiring = Omit; type Wireable = { wiring(): Wiring; }; function mergeWirings(wirings: Wiring[]): Wiring; function wireCallback(callbackName: keyof Wiring, callback: WrapletApiFactoryBasicCallback): Wiring; /** * Returns a wiring that evaluates the callback lazily on the first lifecycle event * and then reuses the same returned wiring for subsequent lifecycle events. */ function lazyWiring(callback: () => Wiring | void): Wiring; function composeWrapletApi(node: Node, wraplet: Wraplet, wirings: Wiring[]): import("..").WrapletApi & import("./types/WrapletApi").WrapletApiDebug; type OuterDestroyCallbackArgs = { wraplet: Wraplet; destroyListeners: DestroyListener[]; status: Status; }; function createOuterDestroyCallback(args: OuterDestroyCallbackArgs, destroyLogic?: WrapletApiFactoryBasicCallback): () => Promise; type OuterInitializeCallbackArgs = { wraplet: Wraplet; destroyCallback: () => Promise; status: Status; }; function createOuterInitializeCallback(args: OuterInitializeCallbackArgs, initializeLogic?: WrapletApiFactoryBasicCallback): () => Promise; const createWrapletApi: (args: WrapletApiFactoryArgs) => WrapletApi & WrapletApiDebug; type DependencyInstance = InstantiableReturnType; interface Status { readonly isInitialized: boolean; readonly isGettingInitialized: boolean; readonly isDestroyed: boolean; readonly isGettingDestroyed: boolean; } type StatusWritable = { -readonly [K in keyof Status]: Status[K]; }; interface Wraplet { wraplet: WrapletApi; } function isWraplet(value: unknown): value is Wraplet; const WrapletApiSymbol: unique symbol; interface WrapletApi { [WrapletApiSymbol]: true; status: Status; destroy(): Promise; initialize(): Promise; addDestroyListener(callback: DestroyListener): void; } function isWrapletApi(object: unknown): object is WrapletApi; interface WrapletApiDebug { __destroyListeners: DestroyListener[]; } type WrapletApiFactoryArgs = { node?: N; wraplet: Wraplet; destroyCallback?: WrapletApiFactoryBasicCallback; initializeCallback?: WrapletApiFactoryBasicCallback; }; type WrapletApiFactoryBasicCallback = () => Promise; type OptionalSingleInstantiableReturnType = T[K]["required"] extends true ? InstantiableReturnType : InstantiableReturnType | null; type WrapletDependencies = { [id in keyof T]: T[id]["multiple"] extends true ? WrapletSet> : OptionalSingleInstantiableReturnType; }; type SelectorCallback = (node: N) => Node[]; type WrapletDependencyDefinition = { selector?: string | SelectorCallback; Class: Constructable; injector?: Injector; required: boolean; multiple: boolean; args?: unknown[]; destructible?: boolean; }; type WrapletDependencyDefinitionWithDefaults = T & { args: unknown[]; destructible: boolean; injector: Injector; }; type WrapletDependencyMap = { [id: string]: WrapletDependencyDefinition; }; type WrapletDependencyMapWithDefaults = { [key in keyof M]: WrapletDependencyDefinitionWithDefaults; }; type SingleDependencyKeys = Extract; type MultipleDependencyKeys = Extract; function isWrapletDependencyMap(object: unknown): object is WrapletDependencyMapWithDefaults; class MissingRequiredDependencyError extends Error { } class MapError extends Error { } class RequiredDependencyDestroyedError extends Error { } class DependenciesAreNotAvailableError extends Error { } class TooManyChildrenFoundError extends Error { } class InternalLogicError extends Error { } class UnsupportedNodeTypeError extends Error { } class LifecycleError extends Error { } /** * Generic guard. */ const is: (object: unknown, symbol: symbol) => object is T; type Constructable = { new (firstArg: F, ...args: any[]): T; }; type InstantiableReturnType = T extends { new (...args: any[]): infer R; } ? R : never; type Nullable = { [K in keyof T]: T[K] | null; }; const RESOLVE: Promise; function throwIfErrors(errors: Error[], message: string): void; /** * @deprecated * Will be removed with the next major release. */ function flattenDependencies(dependencies: Partial>): Wraplet[]; function actOnDependencies(deps: WrapletDependencies, callback: >(id: T & string, dependency: WrapletDependencies[T]) => Promise): Promise; function actOnDependenciesWraplets(deps: WrapletDependencies, callback: (id: string, wraplet: Wraplet) => Promise): Promise;