wraplet 1.0.0-beta.13 → 1.0.0-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DependencyManager/{Core.d.ts → DDM.d.ts} +6 -10
- package/dist/DependencyManager/types/{CoreOptions.d.ts → DDMOptions.d.ts} +1 -1
- package/dist/Wraplet/AbstractDependentWraplet.d.ts +3 -3
- package/dist/Wraplet/AbstractWraplet.d.ts +2 -2
- package/dist/ambient.d.ts +11 -15
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { WrapletDependencies } from "../Wraplet/types/WrapletDependencies";
|
|
2
2
|
import { MultipleDependencyKeys, SingleDependencyKeys, WrapletDependencyMap, WrapletDependencyMapWithDefaults } from "../Wraplet/types/WrapletDependencyMap";
|
|
3
3
|
import { DependencyInstance } from "../Wraplet/types/DependencyInstance";
|
|
4
|
-
import {
|
|
4
|
+
import { DDMOptions } from "./types/DDMOptions";
|
|
5
5
|
import { DependencyManager, DependencyManagerSymbol } from "./types/DependencyManager";
|
|
6
6
|
import { Status } from "../Wraplet/types/Status";
|
|
7
7
|
import { DependencyLifecycleAsyncListener } from "./types/DependencyLifecycleAsyncListener";
|
|
8
8
|
import { DependencyLifecycleListener } from "./types/DependencyLifecycleListener";
|
|
9
9
|
import { MapTreeBuilder } from "../Map/MapTreeBuilder";
|
|
10
10
|
import { Injector } from "../Injector/types/Injector";
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class DDM<N extends Node = Node, M extends WrapletDependencyMap = {}> implements DependencyManager<N, M> {
|
|
12
12
|
node: N;
|
|
13
13
|
[DependencyManagerSymbol]: true;
|
|
14
14
|
private logger;
|
|
@@ -21,13 +21,9 @@ export declare class Core<N extends Node = Node, M extends WrapletDependencyMap
|
|
|
21
21
|
private destroyedDependencyListeners;
|
|
22
22
|
private instantiatedDependencyListeners;
|
|
23
23
|
private initializedDependencyListeners;
|
|
24
|
-
constructor(node: N, map: M | MapTreeBuilder<M>, options?: Partial<
|
|
24
|
+
constructor(node: N, map: M | MapTreeBuilder<M>, options?: Partial<DDMOptions<M>>);
|
|
25
25
|
/**
|
|
26
|
-
* Initialize
|
|
27
|
-
*
|
|
28
|
-
* We couldn't put this step in the constructor, because during initialization some wraplet
|
|
29
|
-
* processing occurs (instantiate dependency listeners) that needs access to the Core,
|
|
30
|
-
* so the Core has to exist already.
|
|
26
|
+
* Initialize DDM.
|
|
31
27
|
*/
|
|
32
28
|
initializeDependencies(): Promise<void>;
|
|
33
29
|
get map(): WrapletDependencyMapWithDefaults<M>;
|
|
@@ -44,7 +40,7 @@ export declare class Core<N extends Node = Node, M extends WrapletDependencyMap
|
|
|
44
40
|
private prepareIndividualWraplet;
|
|
45
41
|
private createDependencyDestroyListener;
|
|
46
42
|
/**
|
|
47
|
-
* Checks whether a required dependency has been removed while the
|
|
43
|
+
* Checks whether a required dependency has been removed while the DDM
|
|
48
44
|
* is NOT being destroyed itself. Returns the error instance instead of
|
|
49
45
|
* throwing, so the caller can route it through the lifecycle error pipeline.
|
|
50
46
|
*/
|
|
@@ -76,5 +72,5 @@ export declare class Core<N extends Node = Node, M extends WrapletDependencyMap
|
|
|
76
72
|
* This is useful for recursive maps.
|
|
77
73
|
* @param options
|
|
78
74
|
*/
|
|
79
|
-
static createInjector<N extends Node, M extends WrapletDependencyMap>(map_or_position: WrapletDependencyMap | number, options?:
|
|
75
|
+
static createInjector<N extends Node, M extends WrapletDependencyMap>(map_or_position: WrapletDependencyMap | number, options?: DDMOptions): Injector<N, M, DDMOptions>;
|
|
80
76
|
}
|
|
@@ -2,7 +2,7 @@ import { WrapletDependencyMap } from "../../Wraplet/types/WrapletDependencyMap";
|
|
|
2
2
|
import { DependencyLifecycleAsyncListener } from "./DependencyLifecycleAsyncListener";
|
|
3
3
|
import { DependencyLifecycleListener } from "./DependencyLifecycleListener";
|
|
4
4
|
import { Logger } from "../../Logger/types/Logger";
|
|
5
|
-
export type
|
|
5
|
+
export type DDMOptions<M extends WrapletDependencyMap = WrapletDependencyMap> = {
|
|
6
6
|
dependencyInstantiatedListeners?: DependencyLifecycleListener<M, keyof M>[];
|
|
7
7
|
dependencyInitializedListeners?: DependencyLifecycleAsyncListener<M, keyof M>[];
|
|
8
8
|
dependencyDestroyedListeners?: DependencyLifecycleAsyncListener<M, keyof M>[];
|
|
@@ -9,7 +9,7 @@ export declare abstract class AbstractDependentWraplet<N extends Node = Node, M
|
|
|
9
9
|
protected dm: DependencyManager<N, M>;
|
|
10
10
|
constructor(dm: DependencyManager<N, M>);
|
|
11
11
|
/**
|
|
12
|
-
* Override createWrapletApi to provide
|
|
12
|
+
* Override createWrapletApi to provide DependencyManager-aware lifecycle callbacks
|
|
13
13
|
* instead of the base class's version — this avoids creating two WrapletApi
|
|
14
14
|
* instances.
|
|
15
15
|
*/
|
|
@@ -38,11 +38,11 @@ export declare abstract class AbstractDependentWraplet<N extends Node = Node, M
|
|
|
38
38
|
/**
|
|
39
39
|
* Instantiates wraplets on a given ParentNode.
|
|
40
40
|
*/
|
|
41
|
-
protected static createDependentWraplets<T extends abstract new (
|
|
41
|
+
protected static createDependentWraplets<T extends abstract new (ddm: any, ...args: any[]) => AbstractDependentWraplet<any, any>>(this: T, node: ParentNode, map: WrapletDependencyMap, attribute: string, additional_args?: unknown[]): InstanceType<T>[];
|
|
42
42
|
/**
|
|
43
43
|
* Instantiates and initializes wraplets on a given ParentNode.
|
|
44
44
|
*/
|
|
45
45
|
protected static createAndInitializeDependentWraplets<T extends {
|
|
46
|
-
new (
|
|
46
|
+
new (ddm: any, ...args: any[]): AbstractDependentWraplet<any, any>;
|
|
47
47
|
}>(this: T, node: ParentNode, map: WrapletDependencyMap, attribute: string, additional_args?: unknown[]): Promise<InstanceType<T>[]>;
|
|
48
48
|
}
|
|
@@ -42,11 +42,11 @@ export declare abstract class AbstractWraplet<N extends Node = Node> implements
|
|
|
42
42
|
/**
|
|
43
43
|
* Instantiates wraplets on a given ParentNode.
|
|
44
44
|
*/
|
|
45
|
-
protected static createWraplets<T extends abstract new (
|
|
45
|
+
protected static createWraplets<T extends abstract new (ddm: any, ...args: any[]) => AbstractWraplet<any>>(this: T, node: ParentNode, attribute: string, additional_args?: unknown[]): InstanceType<T>[];
|
|
46
46
|
/**
|
|
47
47
|
* Instantiates and initializes wraplets on a given ParentNode.
|
|
48
48
|
*/
|
|
49
49
|
protected static createAndInitializeWraplets<T extends {
|
|
50
|
-
new (
|
|
50
|
+
new (ddm: any, ...args: any[]): AbstractWraplet<any>;
|
|
51
51
|
}>(this: T, node: ParentNode, attribute: string, additional_args?: unknown[]): Promise<InstanceType<T>[]>;
|
|
52
52
|
}
|
package/dist/ambient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class
|
|
1
|
+
class DDM<N extends Node = Node, M extends WrapletDependencyMap = {}> implements DependencyManager<N, M> {
|
|
2
2
|
node: N;
|
|
3
3
|
[DependencyManagerSymbol]: true;
|
|
4
4
|
private logger;
|
|
@@ -11,13 +11,9 @@ class Core<N extends Node = Node, M extends WrapletDependencyMap = {}> implement
|
|
|
11
11
|
private destroyedDependencyListeners;
|
|
12
12
|
private instantiatedDependencyListeners;
|
|
13
13
|
private initializedDependencyListeners;
|
|
14
|
-
constructor(node: N, map: M | MapTreeBuilder<M>, options?: Partial<
|
|
14
|
+
constructor(node: N, map: M | MapTreeBuilder<M>, options?: Partial<DDMOptions<M>>);
|
|
15
15
|
/**
|
|
16
|
-
* Initialize
|
|
17
|
-
*
|
|
18
|
-
* We couldn't put this step in the constructor, because during initialization some wraplet
|
|
19
|
-
* processing occurs (instantiate dependency listeners) that needs access to the Core,
|
|
20
|
-
* so the Core has to exist already.
|
|
16
|
+
* Initialize DDM.
|
|
21
17
|
*/
|
|
22
18
|
initializeDependencies(): Promise<void>;
|
|
23
19
|
get map(): WrapletDependencyMapWithDefaults<M>;
|
|
@@ -34,7 +30,7 @@ class Core<N extends Node = Node, M extends WrapletDependencyMap = {}> implement
|
|
|
34
30
|
private prepareIndividualWraplet;
|
|
35
31
|
private createDependencyDestroyListener;
|
|
36
32
|
/**
|
|
37
|
-
* Checks whether a required dependency has been removed while the
|
|
33
|
+
* Checks whether a required dependency has been removed while the DDM
|
|
38
34
|
* is NOT being destroyed itself. Returns the error instance instead of
|
|
39
35
|
* throwing, so the caller can route it through the lifecycle error pipeline.
|
|
40
36
|
*/
|
|
@@ -66,9 +62,9 @@ class Core<N extends Node = Node, M extends WrapletDependencyMap = {}> implement
|
|
|
66
62
|
* This is useful for recursive maps.
|
|
67
63
|
* @param options
|
|
68
64
|
*/
|
|
69
|
-
static createInjector<N extends Node, M extends WrapletDependencyMap>(map_or_position: WrapletDependencyMap | number, options?:
|
|
65
|
+
static createInjector<N extends Node, M extends WrapletDependencyMap>(map_or_position: WrapletDependencyMap | number, options?: DDMOptions): Injector<N, M, DDMOptions>;
|
|
70
66
|
}
|
|
71
|
-
type
|
|
67
|
+
type DDMOptions<M extends WrapletDependencyMap = WrapletDependencyMap> = {
|
|
72
68
|
dependencyInstantiatedListeners?: DependencyLifecycleListener<M, keyof M>[];
|
|
73
69
|
dependencyInitializedListeners?: DependencyLifecycleAsyncListener<M, keyof M>[];
|
|
74
70
|
dependencyDestroyedListeners?: DependencyLifecycleAsyncListener<M, keyof M>[];
|
|
@@ -299,7 +295,7 @@ abstract class AbstractDependentWraplet<N extends Node = Node, M extends Wraplet
|
|
|
299
295
|
protected dm: DependencyManager<N, M>;
|
|
300
296
|
constructor(dm: DependencyManager<N, M>);
|
|
301
297
|
/**
|
|
302
|
-
* Override createWrapletApi to provide
|
|
298
|
+
* Override createWrapletApi to provide DependencyManager-aware lifecycle callbacks
|
|
303
299
|
* instead of the base class's version — this avoids creating two WrapletApi
|
|
304
300
|
* instances.
|
|
305
301
|
*/
|
|
@@ -328,12 +324,12 @@ abstract class AbstractDependentWraplet<N extends Node = Node, M extends Wraplet
|
|
|
328
324
|
/**
|
|
329
325
|
* Instantiates wraplets on a given ParentNode.
|
|
330
326
|
*/
|
|
331
|
-
protected static createDependentWraplets<T extends abstract new (
|
|
327
|
+
protected static createDependentWraplets<T extends abstract new (ddm: any, ...args: any[]) => AbstractDependentWraplet<any, any>>(this: T, node: ParentNode, map: WrapletDependencyMap, attribute: string, additional_args?: unknown[]): InstanceType<T>[];
|
|
332
328
|
/**
|
|
333
329
|
* Instantiates and initializes wraplets on a given ParentNode.
|
|
334
330
|
*/
|
|
335
331
|
protected static createAndInitializeDependentWraplets<T extends {
|
|
336
|
-
new (
|
|
332
|
+
new (ddm: any, ...args: any[]): AbstractDependentWraplet<any, any>;
|
|
337
333
|
}>(this: T, node: ParentNode, map: WrapletDependencyMap, attribute: string, additional_args?: unknown[]): Promise<InstanceType<T>[]>;
|
|
338
334
|
}
|
|
339
335
|
abstract class AbstractWraplet<N extends Node = Node> implements Wraplet {
|
|
@@ -375,12 +371,12 @@ abstract class AbstractWraplet<N extends Node = Node> implements Wraplet {
|
|
|
375
371
|
/**
|
|
376
372
|
* Instantiates wraplets on a given ParentNode.
|
|
377
373
|
*/
|
|
378
|
-
protected static createWraplets<T extends abstract new (
|
|
374
|
+
protected static createWraplets<T extends abstract new (ddm: any, ...args: any[]) => AbstractWraplet<any>>(this: T, node: ParentNode, attribute: string, additional_args?: unknown[]): InstanceType<T>[];
|
|
379
375
|
/**
|
|
380
376
|
* Instantiates and initializes wraplets on a given ParentNode.
|
|
381
377
|
*/
|
|
382
378
|
protected static createAndInitializeWraplets<T extends {
|
|
383
|
-
new (
|
|
379
|
+
new (ddm: any, ...args: any[]): AbstractWraplet<any>;
|
|
384
380
|
}>(this: T, node: ParentNode, attribute: string, additional_args?: unknown[]): Promise<InstanceType<T>[]>;
|
|
385
381
|
}
|
|
386
382
|
class NodeManager<N extends Node> {
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AbstractDependentWraplet:()=>U,AbstractWraplet:()=>F,Core:()=>j,DefaultNodeTreeManager:()=>B,DefaultWrapletSet:()=>E,DefaultWrapletSetReadonly:()=>Y,DependenciesAreNotAvailableError:()=>s,InternalLogicError:()=>d,LifecycleAsyncErrors:()=>p,LifecycleError:()=>l,MapError:()=>i,MissingRequiredDependencyError:()=>n,RequiredDependencyDestroyedError:()=>r,StorageValidationError:()=>a,TooManyChildrenFoundError:()=>o,UnsupportedNodeTypeError:()=>c,WrapletSymbol:()=>u,createOuterDestroyCallback:()=>N,createOuterInitializeCallback:()=>_,createWrapletApi:()=>R,destroyWrapletsRecursively:()=>M,destructionCompleted:()=>q,destructionStarted:()=>$,getWrapletsFromNode:()=>W,initializationCompleted:()=>T,initializationStarted:()=>P,isWraplet:()=>y});class n extends Error{}class i extends Error{}class r extends Error{}class s extends Error{}class a extends Error{}class o extends Error{}class d extends Error{}class c extends Error{}class l extends Error{}class p extends Error{errors=[]}const h=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],u=Symbol("Wraplet");function y(e){return h(e,u)}function f(e){return"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype}function w(e){for(const t of Object.keys(e))if(!["selector","Class","multiple","required","destructible","injector","map","args"].includes(t))return!1;return!!["string","function","undefined"].includes(typeof e.selector)&&"function"==typeof e.Class&&"boolean"==typeof e.required&&"boolean"==typeof e.multiple}function D(e){if(!f(e))return!1;for(const t in e){if(!f(e[t]))return!1;if(!w(e[t]))return!1}return!0}const b=Symbol("WrapletSet");function m(e){return h(e,b)}class g extends Set{find(e){const t=[];for(const n of this)e(n)&&t.push(n);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,n)=>e(t)-e(n))}}const I=Symbol("WrapletSetReadonly");class E extends g{[I]=!0;[b]=!0}function z(e,t,n=!0){const i=new p(e);for(const e of t)"rejected"===e.status&&i.errors.push(e.reason);if(0===i.errors.length)return null;if(n)throw i;return i}function W(e){const t=e.wraplets;return m(t)?t:null}async function v(e,t){t(e);const n=e.childNodes;for(const e of n)await v(e,t)}async function M(e){const t=[];await v(e,e=>{const n=W(e);if(n)for(const e of[...n])e.wraplet.status.isGettingDestroyed||e.wraplet.status.isDestroyed||t.push(e)}),z("Some wraplets threw exceptions during destruction",await Promise.allSettled(t.map(e=>e.wraplet.destroy())))}const S=Symbol("DependencyManager");class L{static#e=new L;constructor(){}dumpError(e){console.dir(e,{depth:null})}static getGlobalLogger(){return this.#e}}function A(e){return{args:[],destructible:!0,injector:{callback:e=>e},...e}}const C=Symbol("MapTreeBuilder");class O{parent;[C]=!0;map;children={};constructor(e){this.parent=e}getParent(){if(!this.parent)throw new Error("Parent not found.");return this.parent}createChild(e){const t=new O(this);return this.children[e]=t,t}setMap(e){this.map=function(e){const t={};for(const n of Object.keys(e)){const i=e[n];t[n]=A(i)}return t}(e)}getMap(){if(!this.map)throw new Error("Map is not set.");return this.map}}class j{node;[S]=!0;logger;dependenciesAreInstantiated=!1;statusWritable={isDestroyed:!1,isGettingDestroyed:!1,isInitialized:!1,isGettingInitialized:!1};get status(){return this.statusWritable}mapTree;directDependencies={};wrappedDependencies={};destroyedDependencyListeners=[];instantiatedDependencyListeners=[];initializedDependencyListeners=[];constructor(e,t,n={}){if(this.node=e,!(e instanceof Node))throw new Error("The node provided to the Core is not a valid node.");if(D(t))this.mapTree=new O,this.mapTree.setMap(t);else{if("object"!=typeof(r=t)||null===r||!(C in r))throw new i("The map provided to the Core is not a valid map.");this.mapTree=t}var r;const s=Object.assign(this.defaultOptions(),n);this.logger=s.logger;for(const e of s.dependencyInstantiatedListeners)this.instantiatedDependencyListeners.push(e);for(const e of s.dependencyInitializedListeners)this.initializedDependencyListeners.push(e);for(const e of s.dependencyDestroyedListeners)this.destroyedDependencyListeners.push(e)}async initializeDependencies(){if(this.status.isInitialized)throw new l("Dependencies are already initialized.");this.statusWritable.isGettingInitialized=!0;const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t)return;const n=m(t)?Array.from(t):[t],i=await Promise.allSettled(n.map(async t=>{if(t.wraplet.status.isInitialized||t.wraplet.status.isGettingInitialized)return;await t.wraplet.initialize();const n=await Promise.allSettled(this.initializedDependencyListeners.map(n=>n(t,e)));z(`Errors in the core's dependency "${e}" initialize listeners.`,n)}));z(`Error at "${e}" dependency's initialization.`,i)})),t=z("Error at Core's initialization.",e,!1);if(t)throw this.logger.dumpError(t),t;this.statusWritable.isInitialized=!0,this.statusWritable.isGettingInitialized=!1,this.statusWritable.isGettingDestroyed&&await this.destroyDependencies()}get map(){return this.mapTree.getMap()}instantiateDependencies(){if(this.dependenciesAreInstantiated)throw new l("Dependencies are already instantiated.");const e=this.directDependencies;if("function"!=typeof this.node.querySelectorAll){for(const e in this.map){const t=this.map[e];this.validateMapItemForNonParent(e,t)}return this.wrappedDependencies=this.wrapDependencies(this.directDependencies),void(this.dependenciesAreInstantiated=!0)}for(const t in this.map){const n=this.map[t],i=n.multiple;if(this.validateMapItem(t,n),i){e[t]||(e[t]=new E);const i=e[t],r=this.instantiateMultipleDependencies(n,this.node,t);for(const e of r)i.add(e);continue}e[t]=this.instantiateSingleWrapletDependency(n,this.node,t)}this.wrappedDependencies=this.wrapDependencies(this.directDependencies),this.dependenciesAreInstantiated=!0}findExistingWraplet(e,t){if(void 0===this.directDependencies||!this.directDependencies[e])return null;const n=this.directDependencies[e];if(this.map[e].multiple){if(!m(n))throw new d("Internal logic error. Expected a WrapletSet.");const e=t.wraplets;if(!e)return null;const i=n.find(t=>e.has(t));if(i.length>1)throw new d("Internal logic error. Multiple instances wrapping the same element found in the core.");return i[0]}if(!y(n))throw new d("Internal logic error. Expected a Wraplet.");return t.wraplets&&t.wraplets.has(n)?n:null}instantiateSingleWrapletDependency(e,t,n){if(!e.selector)return this.directDependencies[n]||null;if(!this.dependenciesAreInstantiated&&this.directDependencies[n])throw new i("It's not possible to provide a single-type dependency manually and use selector at the same time.");const r=e.selector,s=this.findChildrenElements(r,t);if(this.validateElements(n,s,e),0===s.length)return null;if(s.length>1)throw new o(`${this.constructor.name}: More than one element was found for the "${n}" dependency. Selector used: "${r}".`);const a=s[0];return this.instantiateWrapletItem(n,e,a)}instantiateWrapletItem(e,t,n){const i=this.findExistingWraplet(e,n);if(i)return i;let r=null;try{const i=new t.Class(t.injector.callback(n,this.mapTree.createChild(e),t.injector.data),...t.args);if(!y(i))throw new Error("Created dependency is not a Wraplet instance.");r=i}catch(n){if(n instanceof c&&!t.required)return console.warn(`${n.message} Skipping instantiation of the "${e}" dependency.`),null;throw n}this.prepareIndividualWraplet(e,r);for(const t of this.instantiatedDependencyListeners)t(r,e);return r}instantiateMultipleDependencies(e,t,n){const i=e.selector;if(!i)return new E;const r=this.findChildrenElements(i,t);this.validateElements(n,r,e);const s=new E;for(const t of r){let i=this.findExistingWraplet(n,t);i||(i=this.instantiateWrapletItem(n,e,t)),i&&s.add(i)}return s}addDependencyDestroyedListener(e){this.destroyedDependencyListeners.push(e)}addDependencyInstantiatedListener(e){this.instantiatedDependencyListeners.push(e)}addDependencyInitializedListener(e){this.initializedDependencyListeners.push(e)}setExistingInstance(e,t){if(this.map[e].multiple)throw new i("This method can only be used to set a single-value dependency.");if(this.directDependencies[e])throw new i("Dependency is already set.");if(!y(t))throw new i("Provided instance is not a valid dependency.");this.prepareIndividualWraplet(e,t),this.directDependencies[e]=t}addExistingInstance(e,t){if(!this.map[e].multiple)throw new i("This method can only be used to set a multi-value dependency.");this.prepareIndividualWraplet(e,t);const n=this.directDependencies&&this.directDependencies[e]?this.directDependencies[e]:new E;n.add(t),this.directDependencies[e]=n}prepareIndividualWraplet(e,t){t.wraplet.addDestroyListener(this.createDependencyDestroyListener(e))}createDependencyDestroyListener(e){return async t=>{this.removeDependency(t,e);const n=await Promise.allSettled(this.destroyedDependencyListeners.map(n=>n(t,e))),i=this.validateRequiredDependencyAfterRemoval(e);i&&n.push({status:"rejected",reason:i}),z(`Errors in the destruction callbacks of the "${e} dependency."`,n)}}validateRequiredDependencyAfterRemoval(e){return this.map[e].required&&!this.status.isGettingDestroyed?new r(`Required dependency "${e}" has been destroyed.`):null}async destroyDependencies(){if(this.statusWritable.isDestroyed)throw new l("Dependencies are already destroyed.");if(this.statusWritable.isGettingDestroyed=!0,!this.statusWritable.isGettingInitialized){if(!this.statusWritable.isInitialized)return this.statusWritable.isDestroyed=!0,void(this.statusWritable.isGettingDestroyed=!1);await this.destroyDeps(),this.statusWritable.isInitialized=!1,this.statusWritable.isDestroyed=!0,this.statusWritable.isGettingDestroyed=!1}}findChildrenElements(e,t){return"string"==typeof e?((e,t)=>Array.from(t.querySelectorAll(e)))(e,t):e(t)}get dependencies(){if(!this.dependenciesAreInstantiated)throw new s("Wraplet is not yet fully initialized.");return this.wrappedDependencies}removeDependency(e,t){m(this.directDependencies[t])?this.directDependencies[t].delete(e):this.directDependencies[t]===e&&(this.directDependencies[t]=null)}validateMapItem(e,t){const n=t.selector,r=t.required;if(!n&&r&&(!this.directDependencies[e]||m(this.directDependencies[e])&&0===this.directDependencies[e].size))throw new i(`${this.constructor.name}: Dependency "${e}" cannot at the same be required, have no selector, and be not provided otherwise.`)}validateMapItemForNonParent(e,t){if(t.required)throw new i(`Dependency "${e}" error: If the node provided cannot have children, there should be no required dependencies.`)}validateElements(e,t,i){if(0===t.length&&i.required)throw new n(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${i.selector}".`)}wrapDependencies(e){return new Proxy(e,{get:(e,t)=>{if("symbol"==typeof t)throw new Error("Symbol access is not supported for dependencies.");if(!(t in e))throw new Error(`Dependency '${t}' has not been found.`);return e[t]},set:()=>{throw new Error("Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.")}})}defaultOptions(){return{dependencyInstantiatedListeners:[],dependencyInitializedListeners:[],dependencyDestroyedListeners:[],logger:L.getGlobalLogger()}}async destroyDeps(){const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t||!this.map[e].destructible)return;const n=[];if(m(t))for(const e of t)n.push(e);else n.push(t);z(`Errors during destruction of the "${e}" dependency.`,await Promise.allSettled(n.map(async e=>{if(!e.wraplet.status.isDestroyed&&!e.wraplet.status.isGettingDestroyed)return e.wraplet.destroy()})))})),t=z("Errors during the dependencies destruction.",e,!1);if(t)throw this.logger.dumpError(t),t}static createInjector(e,t){return{data:t||{},callback:(t,n,i)=>{let r=n;if(s=e,Number.isInteger(s))for(let t=0;t<e;t++)r=r.getParent();else{if(!D(e))throw new Error("Invalid map argument.");r.setMap(e)}var s;return new j(t,r,i)}}}}const x=(e,t,n)=>{let i=Object.getPrototypeOf(e);const r=n?n.prototype:Object.getPrototypeOf(i);for(;i&&i!==r;){if(Object.prototype.hasOwnProperty.call(i,t))return!0;i=Object.getPrototypeOf(i)}return!1};class G{node;listeners=[];constructor(e){this.node=e}addListener(e,t,n){this.node.addEventListener(e,t,n),this.listeners.push({callback:t,event:e,options:n})}destroy(){for(const e of this.listeners)this.node.removeEventListener(e.event,e.callback,e.options);this.listeners.length=0}}const k=Symbol("WrapletApi");function P(e){return!(e.isInitialized||e.isGettingInitialized||e.isDestroyed||e.isGettingDestroyed||(e.isGettingInitialized=!0,0))}async function T(e,t){e.isInitialized=!0,e.isGettingInitialized=!1,e.isGettingDestroyed&&await t()}function $(e){if(e.isDestroyed)return!1;if(e.isGettingDestroyed=!0,e.isGettingInitialized)return!1;if(!e.isInitialized)throw new l("Wraplet cannot be destroyed before it is initialized.");return!0}async function q(e,t,n){e.isGettingDestroyed=!1,e.isInitialized=!1,e.isDestroyed=!0;for(const e of[...n].reverse())await e(t);n.length=0}function N(e,t){return async function(){const n=e.status;$(n)&&(t&&await t(),await q(n,e.wraplet,e.destroyListeners))}}function _(e,t){return async function(){const n=e.status;P(n)&&(t&&await t(),await T(n,e.destroyCallback))}}const R=e=>{!function(e){if(!y(e.wraplet))throw new Error("Correct wraplet instance has to be provided.");if(e.node&&!(e.node instanceof Node))throw new Error("Correct node has to be provided.");if(e.initializeCallback&&"function"!=typeof e.initializeCallback)throw new Error("initializeCallback has to be a function.");if(e.destroyCallback&&"function"!=typeof e.destroyCallback)throw new Error("destroyCallback has to be a function.")}(e);const t={...e},n={isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},i={},r=[],s=N({status:n,wraplet:t.wraplet,destroyListeners:r},async()=>{t.destroyCallback&&await t.destroyCallback(),t.node&&function(e,t){const n=W(t);n&&n.delete(e)}(t.wraplet,t.node)}).bind(i),a=_({status:n,destroyCallback:s,wraplet:t.wraplet},async()=>{var e,n;t.node&&(e=t.wraplet,(n=t.node).wraplets||(n.wraplets=new E),n.wraplets.add(e)),t.initializeCallback&&await t.initializeCallback()}).bind(i);return Object.assign(i,{[k]:!0,__destroyListeners:r,status:n,addDestroyListener:e=>{r.push(e)},initialize:a,destroy:s})};class F{node;[u]=!0;wraplet;_nodeManager;constructor(e){if(this.node=e,!(e instanceof Node))throw new Error("AbstractWraplet requires a Node instance.");const t=this.supportedNodeTypes();if(null!==t&&!t.find(t=>e instanceof t))throw new c(`Node type ${e.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);this.wraplet=this.createWrapletApi()}createWrapletApi(){const e=x(this,"onInitialize",F)?this.onInitialize.bind(this):void 0,t=x(this,"onDestroy",F)?this.onDestroy.bind(this):void 0;return this.buildWrapletApi(e,t)}buildWrapletApi(e,t){return R({node:this.node,wraplet:this,initializeCallback:e,destroyCallback:async()=>{t&&await t(),this._nodeManager&&this._nodeManager.destroy()}})}get nodeManager(){return this._nodeManager||(this._nodeManager=new G(this.node)),this._nodeManager}supportedNodeTypes(){return null}supportedNodeTypesGuard(e){return e}async onInitialize(){throw new Error("Method has to be implemented by subclass.")}async onDestroy(){throw new Error("Method has to be implemented by subclass.")}static createWraplets(e,t,n=[]){if(this===F)throw new Error("You cannot instantiate an abstract class.");const i=[];e instanceof Element&&e.hasAttribute(t)&&i.push(new this(e,...n));const r=e.querySelectorAll(`[${t}]`);for(const e of r)i.push(new this(e,...n));return i}static async createAndInitializeWraplets(e,t,n=[]){const i=this.createWraplets(e,t,n);for(const e of i)await e.wraplet.initialize();return i}}class U extends F{dm;constructor(e){if(!h(e,S))throw new Error("AbstractDependentWraplet requires an instance implementing DependencyManager and NodeManager interfaces.");super(e.node),this.dm=e,x(this,"onDependencyInitialized",U)&&e.addDependencyInitializedListener(this.onDependencyInitialized.bind(this)),x(this,"onDependencyInstantiated",U)&&e.addDependencyInstantiatedListener(this.onDependencyInstantiated.bind(this)),x(this,"onDependencyDestroyed",U)&&e.addDependencyDestroyedListener(this.onDependencyDestroyed.bind(this)),e.instantiateDependencies()}createWrapletApi(){return this.buildWrapletApi(this.onInitialize.bind(this),this.onDestroy.bind(this))}async onDestroy(){await this.dm.destroyDependencies()}async onInitialize(){await this.dm.initializeDependencies()}get d(){return this.dm.dependencies}onDependencyInstantiated(e,t){throw new Error("Method has to be implemented by subclass.")}async onDependencyInitialized(e,t){throw new Error("Method has to be implemented by subclass.")}async onDependencyDestroyed(e,t){throw new Error("Method has to be implemented by subclass.")}static createDependencyManager(e,t){return new j(e,t)}static createWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createAndInitializeWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createDependentWraplets(e,t,n,i=[]){if(this===U)throw new Error("You cannot instantiate an abstract class.");const r=this,s=[];if(e instanceof Element&&e.hasAttribute(n)){const n=r.createDependencyManager(e,t);s.push(new this(n,...i))}const a=e.querySelectorAll(`[${n}]`);for(const e of a){const n=r.createDependencyManager(e,t);s.push(new this(n,...i))}return s}static async createAndInitializeDependentWraplets(e,t,n,i=[]){const r=this.createDependentWraplets(e,t,n,i);for(const e of r)await e.wraplet.initialize();return r}}class Y extends g{[I]=!0}class B{initializers=[];addNodeInitializer(e){this.initializers.push(e)}async initializeNode(e,t){z("There were errors during the node's initialization.",await Promise.allSettled(this.initializers.map(n=>n(e,t))))}async destroyNode(e){await M(e)}}var V=exports;for(var H in t)V[H]=t[H];t.__esModule&&Object.defineProperty(V,"__esModule",{value:!0});
|
|
1
|
+
var e={d:(t,n)=>{for(var i in n)e.o(n,i)&&!e.o(t,i)&&Object.defineProperty(t,i,{enumerable:!0,get:n[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AbstractDependentWraplet:()=>U,AbstractWraplet:()=>F,DDM:()=>j,DefaultNodeTreeManager:()=>B,DefaultWrapletSet:()=>E,DefaultWrapletSetReadonly:()=>Y,DependenciesAreNotAvailableError:()=>s,InternalLogicError:()=>d,LifecycleAsyncErrors:()=>p,LifecycleError:()=>l,MapError:()=>i,MissingRequiredDependencyError:()=>n,RequiredDependencyDestroyedError:()=>r,StorageValidationError:()=>a,TooManyChildrenFoundError:()=>o,UnsupportedNodeTypeError:()=>c,WrapletSymbol:()=>u,createOuterDestroyCallback:()=>N,createOuterInitializeCallback:()=>_,createWrapletApi:()=>R,destroyWrapletsRecursively:()=>M,destructionCompleted:()=>q,destructionStarted:()=>$,getWrapletsFromNode:()=>W,initializationCompleted:()=>T,initializationStarted:()=>P,isWraplet:()=>y});class n extends Error{}class i extends Error{}class r extends Error{}class s extends Error{}class a extends Error{}class o extends Error{}class d extends Error{}class c extends Error{}class l extends Error{}class p extends Error{errors=[]}const h=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],u=Symbol("Wraplet");function y(e){return h(e,u)}function f(e){return"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype}function w(e){for(const t of Object.keys(e))if(!["selector","Class","multiple","required","destructible","injector","map","args"].includes(t))return!1;return!!["string","function","undefined"].includes(typeof e.selector)&&"function"==typeof e.Class&&"boolean"==typeof e.required&&"boolean"==typeof e.multiple}function D(e){if(!f(e))return!1;for(const t in e){if(!f(e[t]))return!1;if(!w(e[t]))return!1}return!0}const b=Symbol("WrapletSet");function m(e){return h(e,b)}class g extends Set{find(e){const t=[];for(const n of this)e(n)&&t.push(n);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,n)=>e(t)-e(n))}}const I=Symbol("WrapletSetReadonly");class E extends g{[I]=!0;[b]=!0}function z(e,t,n=!0){const i=new p(e);for(const e of t)"rejected"===e.status&&i.errors.push(e.reason);if(0===i.errors.length)return null;if(n)throw i;return i}function W(e){const t=e.wraplets;return m(t)?t:null}async function v(e,t){t(e);const n=e.childNodes;for(const e of n)await v(e,t)}async function M(e){const t=[];await v(e,e=>{const n=W(e);if(n)for(const e of[...n])e.wraplet.status.isGettingDestroyed||e.wraplet.status.isDestroyed||t.push(e)}),z("Some wraplets threw exceptions during destruction",await Promise.allSettled(t.map(e=>e.wraplet.destroy())))}const S=Symbol("DependencyManager");class L{static#e=new L;constructor(){}dumpError(e){console.dir(e,{depth:null})}static getGlobalLogger(){return this.#e}}function A(e){return{args:[],destructible:!0,injector:{callback:e=>e},...e}}const C=Symbol("MapTreeBuilder");class O{parent;[C]=!0;map;children={};constructor(e){this.parent=e}getParent(){if(!this.parent)throw new Error("Parent not found.");return this.parent}createChild(e){const t=new O(this);return this.children[e]=t,t}setMap(e){this.map=function(e){const t={};for(const n of Object.keys(e)){const i=e[n];t[n]=A(i)}return t}(e)}getMap(){if(!this.map)throw new Error("Map is not set.");return this.map}}class j{node;[S]=!0;logger;dependenciesAreInstantiated=!1;statusWritable={isDestroyed:!1,isGettingDestroyed:!1,isInitialized:!1,isGettingInitialized:!1};get status(){return this.statusWritable}mapTree;directDependencies={};wrappedDependencies={};destroyedDependencyListeners=[];instantiatedDependencyListeners=[];initializedDependencyListeners=[];constructor(e,t,n={}){if(this.node=e,!(e instanceof Node))throw new Error("The node provided to the DDM is not a valid node.");if(D(t))this.mapTree=new O,this.mapTree.setMap(t);else{if("object"!=typeof(r=t)||null===r||!(C in r))throw new i("The map provided to the DDM is not a valid map.");this.mapTree=t}var r;const s=Object.assign(this.defaultOptions(),n);this.logger=s.logger;for(const e of s.dependencyInstantiatedListeners)this.instantiatedDependencyListeners.push(e);for(const e of s.dependencyInitializedListeners)this.initializedDependencyListeners.push(e);for(const e of s.dependencyDestroyedListeners)this.destroyedDependencyListeners.push(e)}async initializeDependencies(){if(this.status.isInitialized)throw new l("Dependencies are already initialized.");this.statusWritable.isGettingInitialized=!0;const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t)return;const n=m(t)?Array.from(t):[t],i=await Promise.allSettled(n.map(async t=>{if(t.wraplet.status.isInitialized||t.wraplet.status.isGettingInitialized)return;await t.wraplet.initialize();const n=await Promise.allSettled(this.initializedDependencyListeners.map(n=>n(t,e)));z(`Errors in the DDM's dependency "${e}" initialize listeners.`,n)}));z(`Error at "${e}" dependency's initialization.`,i)})),t=z("Error at DDM's initialization.",e,!1);if(t)throw this.logger.dumpError(t),t;this.statusWritable.isInitialized=!0,this.statusWritable.isGettingInitialized=!1,this.statusWritable.isGettingDestroyed&&await this.destroyDependencies()}get map(){return this.mapTree.getMap()}instantiateDependencies(){if(this.dependenciesAreInstantiated)throw new l("Dependencies are already instantiated.");const e=this.directDependencies;if("function"!=typeof this.node.querySelectorAll){for(const e in this.map){const t=this.map[e];this.validateMapItemForNonParent(e,t)}return this.wrappedDependencies=this.wrapDependencies(this.directDependencies),void(this.dependenciesAreInstantiated=!0)}for(const t in this.map){const n=this.map[t],i=n.multiple;if(this.validateMapItem(t,n),i){e[t]||(e[t]=new E);const i=e[t],r=this.instantiateMultipleDependencies(n,this.node,t);for(const e of r)i.add(e);continue}e[t]=this.instantiateSingleWrapletDependency(n,this.node,t)}this.wrappedDependencies=this.wrapDependencies(this.directDependencies),this.dependenciesAreInstantiated=!0}findExistingWraplet(e,t){if(void 0===this.directDependencies||!this.directDependencies[e])return null;const n=this.directDependencies[e];if(this.map[e].multiple){if(!m(n))throw new d("Internal logic error. Expected a WrapletSet.");const e=t.wraplets;if(!e)return null;const i=n.find(t=>e.has(t));if(i.length>1)throw new d("Internal logic error. Multiple instances wrapping the same element found in the DDM.");return i[0]}if(!y(n))throw new d("Internal logic error. Expected a Wraplet.");return t.wraplets&&t.wraplets.has(n)?n:null}instantiateSingleWrapletDependency(e,t,n){if(!e.selector)return this.directDependencies[n]||null;if(!this.dependenciesAreInstantiated&&this.directDependencies[n])throw new i("It's not possible to provide a single-type dependency manually and use selector at the same time.");const r=e.selector,s=this.findChildrenElements(r,t);if(this.validateElements(n,s,e),0===s.length)return null;if(s.length>1)throw new o(`${this.constructor.name}: More than one element was found for the "${n}" dependency. Selector used: "${r}".`);const a=s[0];return this.instantiateWrapletItem(n,e,a)}instantiateWrapletItem(e,t,n){const i=this.findExistingWraplet(e,n);if(i)return i;let r=null;try{const i=new t.Class(t.injector.callback(n,this.mapTree.createChild(e),t.injector.data),...t.args);if(!y(i))throw new Error("Created dependency is not a Wraplet instance.");r=i}catch(n){if(n instanceof c&&!t.required)return console.warn(`${n.message} Skipping instantiation of the "${e}" dependency.`),null;throw n}this.prepareIndividualWraplet(e,r);for(const t of this.instantiatedDependencyListeners)t(r,e);return r}instantiateMultipleDependencies(e,t,n){const i=e.selector;if(!i)return new E;const r=this.findChildrenElements(i,t);this.validateElements(n,r,e);const s=new E;for(const t of r){let i=this.findExistingWraplet(n,t);i||(i=this.instantiateWrapletItem(n,e,t)),i&&s.add(i)}return s}addDependencyDestroyedListener(e){this.destroyedDependencyListeners.push(e)}addDependencyInstantiatedListener(e){this.instantiatedDependencyListeners.push(e)}addDependencyInitializedListener(e){this.initializedDependencyListeners.push(e)}setExistingInstance(e,t){if(this.map[e].multiple)throw new i("This method can only be used to set a single-value dependency.");if(this.directDependencies[e])throw new i("Dependency is already set.");if(!y(t))throw new i("Provided instance is not a valid dependency.");this.prepareIndividualWraplet(e,t),this.directDependencies[e]=t}addExistingInstance(e,t){if(!this.map[e].multiple)throw new i("This method can only be used to set a multi-value dependency.");this.prepareIndividualWraplet(e,t);const n=this.directDependencies&&this.directDependencies[e]?this.directDependencies[e]:new E;n.add(t),this.directDependencies[e]=n}prepareIndividualWraplet(e,t){t.wraplet.addDestroyListener(this.createDependencyDestroyListener(e))}createDependencyDestroyListener(e){return async t=>{this.removeDependency(t,e);const n=await Promise.allSettled(this.destroyedDependencyListeners.map(n=>n(t,e))),i=this.validateRequiredDependencyAfterRemoval(e);i&&n.push({status:"rejected",reason:i}),z(`Errors in the destruction callbacks of the "${e} dependency."`,n)}}validateRequiredDependencyAfterRemoval(e){return this.map[e].required&&!this.status.isGettingDestroyed?new r(`Required dependency "${e}" has been destroyed.`):null}async destroyDependencies(){if(this.statusWritable.isDestroyed)throw new l("Dependencies are already destroyed.");if(this.statusWritable.isGettingDestroyed=!0,!this.statusWritable.isGettingInitialized){if(!this.statusWritable.isInitialized)return this.statusWritable.isDestroyed=!0,void(this.statusWritable.isGettingDestroyed=!1);await this.destroyDeps(),this.statusWritable.isInitialized=!1,this.statusWritable.isDestroyed=!0,this.statusWritable.isGettingDestroyed=!1}}findChildrenElements(e,t){return"string"==typeof e?((e,t)=>Array.from(t.querySelectorAll(e)))(e,t):e(t)}get dependencies(){if(!this.dependenciesAreInstantiated)throw new s("Wraplet is not yet fully initialized.");return this.wrappedDependencies}removeDependency(e,t){m(this.directDependencies[t])?this.directDependencies[t].delete(e):this.directDependencies[t]===e&&(this.directDependencies[t]=null)}validateMapItem(e,t){const n=t.selector,r=t.required;if(!n&&r&&(!this.directDependencies[e]||m(this.directDependencies[e])&&0===this.directDependencies[e].size))throw new i(`${this.constructor.name}: Dependency "${e}" cannot at the same be required, have no selector, and be not provided otherwise.`)}validateMapItemForNonParent(e,t){if(t.required)throw new i(`Dependency "${e}" error: If the node provided cannot have children, there should be no required dependencies.`)}validateElements(e,t,i){if(0===t.length&&i.required)throw new n(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${i.selector}".`)}wrapDependencies(e){return new Proxy(e,{get:(e,t)=>{if("symbol"==typeof t)throw new Error("Symbol access is not supported for dependencies.");if(!(t in e))throw new Error(`Dependency '${t}' has not been found.`);return e[t]},set:()=>{throw new Error("Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.")}})}defaultOptions(){return{dependencyInstantiatedListeners:[],dependencyInitializedListeners:[],dependencyDestroyedListeners:[],logger:L.getGlobalLogger()}}async destroyDeps(){const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t||!this.map[e].destructible)return;const n=[];if(m(t))for(const e of t)n.push(e);else n.push(t);z(`Errors during destruction of the "${e}" dependency.`,await Promise.allSettled(n.map(async e=>{if(!e.wraplet.status.isDestroyed&&!e.wraplet.status.isGettingDestroyed)return e.wraplet.destroy()})))})),t=z("Errors during the dependencies destruction.",e,!1);if(t)throw this.logger.dumpError(t),t}static createInjector(e,t){return{data:t||{},callback:(t,n,i)=>{let r=n;if(s=e,Number.isInteger(s))for(let t=0;t<e;t++)r=r.getParent();else{if(!D(e))throw new Error("Invalid map argument.");r.setMap(e)}var s;return new j(t,r,i)}}}}const x=(e,t,n)=>{let i=Object.getPrototypeOf(e);const r=n?n.prototype:Object.getPrototypeOf(i);for(;i&&i!==r;){if(Object.prototype.hasOwnProperty.call(i,t))return!0;i=Object.getPrototypeOf(i)}return!1};class G{node;listeners=[];constructor(e){this.node=e}addListener(e,t,n){this.node.addEventListener(e,t,n),this.listeners.push({callback:t,event:e,options:n})}destroy(){for(const e of this.listeners)this.node.removeEventListener(e.event,e.callback,e.options);this.listeners.length=0}}const k=Symbol("WrapletApi");function P(e){return!(e.isInitialized||e.isGettingInitialized||e.isDestroyed||e.isGettingDestroyed||(e.isGettingInitialized=!0,0))}async function T(e,t){e.isInitialized=!0,e.isGettingInitialized=!1,e.isGettingDestroyed&&await t()}function $(e){if(e.isDestroyed)return!1;if(e.isGettingDestroyed=!0,e.isGettingInitialized)return!1;if(!e.isInitialized)throw new l("Wraplet cannot be destroyed before it is initialized.");return!0}async function q(e,t,n){e.isGettingDestroyed=!1,e.isInitialized=!1,e.isDestroyed=!0;for(const e of[...n].reverse())await e(t);n.length=0}function N(e,t){return async function(){const n=e.status;$(n)&&(t&&await t(),await q(n,e.wraplet,e.destroyListeners))}}function _(e,t){return async function(){const n=e.status;P(n)&&(t&&await t(),await T(n,e.destroyCallback))}}const R=e=>{!function(e){if(!y(e.wraplet))throw new Error("Correct wraplet instance has to be provided.");if(e.node&&!(e.node instanceof Node))throw new Error("Correct node has to be provided.");if(e.initializeCallback&&"function"!=typeof e.initializeCallback)throw new Error("initializeCallback has to be a function.");if(e.destroyCallback&&"function"!=typeof e.destroyCallback)throw new Error("destroyCallback has to be a function.")}(e);const t={...e},n={isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},i={},r=[],s=N({status:n,wraplet:t.wraplet,destroyListeners:r},async()=>{t.destroyCallback&&await t.destroyCallback(),t.node&&function(e,t){const n=W(t);n&&n.delete(e)}(t.wraplet,t.node)}).bind(i),a=_({status:n,destroyCallback:s,wraplet:t.wraplet},async()=>{t.initializeCallback&&await t.initializeCallback()}).bind(i);var o,d;return t.node&&(o=t.wraplet,(d=t.node).wraplets||(d.wraplets=new E),d.wraplets.add(o)),Object.assign(i,{[k]:!0,__destroyListeners:r,status:n,addDestroyListener:e=>{r.push(e)},initialize:a,destroy:s})};class F{node;[u]=!0;wraplet;_nodeManager;constructor(e){if(this.node=e,!(e instanceof Node))throw new Error("AbstractWraplet requires a Node instance.");const t=this.supportedNodeTypes();if(null!==t&&!t.find(t=>e instanceof t))throw new c(`Node type ${e.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);this.wraplet=this.createWrapletApi()}createWrapletApi(){const e=x(this,"onInitialize",F)?this.onInitialize.bind(this):void 0,t=x(this,"onDestroy",F)?this.onDestroy.bind(this):void 0;return this.buildWrapletApi(e,t)}buildWrapletApi(e,t){return R({node:this.node,wraplet:this,initializeCallback:e,destroyCallback:async()=>{t&&await t(),this._nodeManager&&this._nodeManager.destroy()}})}get nodeManager(){return this._nodeManager||(this._nodeManager=new G(this.node)),this._nodeManager}supportedNodeTypes(){return null}supportedNodeTypesGuard(e){return e}async onInitialize(){throw new Error("Method has to be implemented by subclass.")}async onDestroy(){throw new Error("Method has to be implemented by subclass.")}static createWraplets(e,t,n=[]){if(this===F)throw new Error("You cannot instantiate an abstract class.");const i=[];e instanceof Element&&e.hasAttribute(t)&&i.push(new this(e,...n));const r=e.querySelectorAll(`[${t}]`);for(const e of r)i.push(new this(e,...n));return i}static async createAndInitializeWraplets(e,t,n=[]){const i=this.createWraplets(e,t,n);for(const e of i)await e.wraplet.initialize();return i}}class U extends F{dm;constructor(e){if(!h(e,S))throw new Error("AbstractDependentWraplet requires an instance implementing DependencyManager and NodeManager interfaces.");super(e.node),this.dm=e,x(this,"onDependencyInitialized",U)&&e.addDependencyInitializedListener(this.onDependencyInitialized.bind(this)),x(this,"onDependencyInstantiated",U)&&e.addDependencyInstantiatedListener(this.onDependencyInstantiated.bind(this)),x(this,"onDependencyDestroyed",U)&&e.addDependencyDestroyedListener(this.onDependencyDestroyed.bind(this)),e.instantiateDependencies()}createWrapletApi(){return this.buildWrapletApi(async()=>{await this.dm.initializeDependencies(),await this.onInitialize.bind(this)()},async()=>{await this.onDestroy.bind(this)(),await this.dm.destroyDependencies()})}async onDestroy(){}async onInitialize(){}get d(){return this.dm.dependencies}onDependencyInstantiated(e,t){throw new Error("Method has to be implemented by subclass.")}async onDependencyInitialized(e,t){throw new Error("Method has to be implemented by subclass.")}async onDependencyDestroyed(e,t){throw new Error("Method has to be implemented by subclass.")}static createDependencyManager(e,t){return new j(e,t)}static createWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createAndInitializeWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createDependentWraplets(e,t,n,i=[]){if(this===U)throw new Error("You cannot instantiate an abstract class.");const r=this,s=[];if(e instanceof Element&&e.hasAttribute(n)){const n=r.createDependencyManager(e,t);s.push(new this(n,...i))}const a=e.querySelectorAll(`[${n}]`);for(const e of a){const n=r.createDependencyManager(e,t);s.push(new this(n,...i))}return s}static async createAndInitializeDependentWraplets(e,t,n,i=[]){const r=this.createDependentWraplets(e,t,n,i);for(const e of r)await e.wraplet.initialize();return r}}class Y extends g{[I]=!0}class B{initializers=[];addNodeInitializer(e){this.initializers.push(e)}async initializeNode(e,t){z("There were errors during the node's initialization.",await Promise.allSettled(this.initializers.map(n=>n(e,t))))}async destroyNode(e){await M(e)}}var V=exports;for(var H in t)V[H]=t[H];t.__esModule&&Object.defineProperty(V,"__esModule",{value:!0});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","mappings":"AACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,0vBCLhD,MAAMC,UAAuCC,OAE7C,MAAMC,UAAiBD,OAEvB,MAAME,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KyN,aAAaxN,KAAKG,EAC3B,CACA,oBAAMuN,CAAetM,EAAMuM,GAEvBhN,EAA0B,4DADJqB,QAAQC,WAAWlC,KAAKyN,aAAatL,IAAK0L,GAAgBA,EAAYxM,EAAMuM,KAEtG,CACA,iBAAME,CAAYzM,SACRO,EAA2BP,EACrC,E","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils/is.ts","webpack://wraplet/./src/Wraplet/types/Wraplet.ts","webpack://wraplet/./src/Wraplet/types/WrapletDependencyMap.ts","webpack://wraplet/./src/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils/createLifecycleAsyncError.ts","webpack://wraplet/./src/NodeTreeManager/utils.ts","webpack://wraplet/./src/DependencyManager/types/DependencyManager.ts","webpack://wraplet/./src/Logger/ConsoleLogger.ts","webpack://wraplet/./src/Map/utils.ts","webpack://wraplet/./src/Map/MapTreeBuilder.ts","webpack://wraplet/./src/DependencyManager/Core.ts","webpack://wraplet/./src/Wraplet/utils.ts","webpack://wraplet/./src/Wraplet/NodeManager.ts","webpack://wraplet/./src/Wraplet/types/WrapletApi.ts","webpack://wraplet/./src/Wraplet/statusActions.ts","webpack://wraplet/./src/Wraplet/createOuterDestroyCallback.ts","webpack://wraplet/./src/Wraplet/createOuterInitializeCallback.ts","webpack://wraplet/./src/Wraplet/createWrapletApi.ts","webpack://wraplet/./src/Wraplet/AbstractWraplet.ts","webpack://wraplet/./src/Wraplet/AbstractDependentWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts","webpack://wraplet/./src/NodeTreeManager/DefaultNodeTreeManager.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredDependencyError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredDependencyDestroyedError extends Error {\n}\nexport class DependenciesAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class TooManyChildrenFoundError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\nexport class UnsupportedNodeTypeError extends Error {\n}\nexport class LifecycleError extends Error {\n}\nexport class LifecycleAsyncErrors extends Error {\n errors = [];\n}\n","/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../../utils/is\";\nexport const WrapletSymbol = Symbol(\"Wraplet\");\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","function isSimpleObject(input) {\n return (typeof input === \"object\" &&\n input !== null &&\n Object.getPrototypeOf(input) === Object.prototype);\n}\nfunction isDependencyMapItem(item) {\n for (const key of Object.keys(item)) {\n if (![\n \"selector\",\n \"Class\",\n \"multiple\",\n \"required\",\n \"destructible\",\n \"injector\",\n \"map\",\n \"args\",\n ].includes(key)) {\n return false;\n }\n }\n if (![\"string\", \"function\", \"undefined\"].includes(typeof item[\"selector\"])) {\n return false;\n }\n if (typeof item[\"Class\"] !== \"function\") {\n return false;\n }\n if (typeof item[\"required\"] !== \"boolean\") {\n return false;\n }\n return typeof item[\"multiple\"] === \"boolean\";\n}\nexport function isWrapletDependencyMap(object) {\n if (!isSimpleObject(object)) {\n return false;\n }\n for (const key in object) {\n if (!isSimpleObject(object[key])) {\n return false;\n }\n const item = object[key];\n if (!isDependencyMapItem(item)) {\n return false;\n }\n }\n return true;\n}\n","import { is } from \"../../utils/is\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"./types/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { LifecycleAsyncErrors } from \"../errors\";\nexport function createLifecycleAsyncError(message, results, throwError = true) {\n const error = new LifecycleAsyncErrors(message);\n for (const result of results) {\n if (result.status === \"rejected\") {\n error.errors.push(result.reason);\n }\n }\n if (error.errors.length === 0) {\n return null;\n }\n if (throwError) {\n throw error;\n }\n return error;\n}\n","import { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (isWrapletSet(wraplets)) {\n return wraplets;\n }\n return null;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return false;\n }\n return wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport async function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n await actOnNodesRecursively(child, callback);\n }\n}\nexport async function destroyWrapletsRecursively(node) {\n const allWraplets = [];\n await actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return;\n }\n for (const wraplet of [...wraplets]) {\n if (wraplet.wraplet.status.isGettingDestroyed ||\n wraplet.wraplet.status.isDestroyed) {\n continue;\n }\n allWraplets.push(wraplet);\n }\n });\n const results = await Promise.allSettled(allWraplets.map((wraplet) => wraplet.wraplet.destroy()));\n createLifecycleAsyncError(\"Some wraplets threw exceptions during destruction\", results);\n}\n","import { is } from \"../../utils/is\";\nexport const DependencyManagerSymbol = Symbol(\"DependencyManager\");\nexport function isDependencyManager(object) {\n return is(object, DependencyManagerSymbol);\n}\n","export class ConsoleLogger {\n static #instance = new ConsoleLogger();\n constructor() { }\n dumpError(error) {\n console.dir(error, { depth: null });\n }\n static getGlobalLogger() {\n return this.#instance;\n }\n}\n","export function addDefaultsToDependencyDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n injector: {\n callback: (node) => node,\n },\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id of Object.keys(map)) {\n const def = map[id];\n newMap[id] = addDefaultsToDependencyDefinition(def);\n }\n return newMap;\n}\n","import { fillMapWithDefaults } from \"./utils\";\nconst MapTreeBuilderSymbol = Symbol(\"MapTreeBuilder\");\nexport class MapTreeBuilder {\n parent;\n [MapTreeBuilderSymbol] = true;\n map;\n children = {};\n constructor(parent) {\n this.parent = parent;\n }\n getParent() {\n if (!this.parent) {\n throw new Error(\"Parent not found.\");\n }\n return this.parent;\n }\n createChild(name) {\n const mapBuilder = new MapTreeBuilder(this);\n this.children[name] = mapBuilder;\n return mapBuilder;\n }\n setMap(map) {\n this.map = fillMapWithDefaults(map);\n }\n getMap() {\n if (!this.map) {\n throw new Error(\"Map is not set.\");\n }\n return this.map;\n }\n}\nexport function isMapTreeBuilder(object) {\n return (typeof object === \"object\" &&\n object !== null &&\n MapTreeBuilderSymbol in object);\n}\n","import { DependenciesAreNotAvailableError, TooManyChildrenFoundError, InternalLogicError, MapError, MissingRequiredDependencyError, UnsupportedNodeTypeError, LifecycleError, RequiredDependencyDestroyedError, } from \"../errors\";\nimport { isWraplet } from \"../Wraplet/types/Wraplet\";\nimport { isWrapletDependencyMap, } from \"../Wraplet/types/WrapletDependencyMap\";\nimport { isParentNode } from \"../NodeTreeManager/utils\";\nimport { DependencyManagerSymbol, } from \"./types/DependencyManager\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { ConsoleLogger } from \"../Logger/ConsoleLogger\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nimport { isMapTreeBuilder, MapTreeBuilder } from \"../Map/MapTreeBuilder\";\nexport class Core {\n node;\n [DependencyManagerSymbol] = true;\n logger;\n dependenciesAreInstantiated = false;\n statusWritable = {\n isDestroyed: false,\n isGettingDestroyed: false,\n isInitialized: false,\n isGettingInitialized: false,\n };\n get status() {\n return this.statusWritable;\n }\n mapTree;\n directDependencies = {};\n wrappedDependencies = {};\n destroyedDependencyListeners = [];\n instantiatedDependencyListeners = [];\n initializedDependencyListeners = [];\n constructor(node, map, options = {}) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"The node provided to the Core is not a valid node.\");\n }\n if (isWrapletDependencyMap(map)) {\n this.mapTree = new MapTreeBuilder();\n this.mapTree.setMap(map);\n }\n else if (isMapTreeBuilder(map)) {\n this.mapTree = map;\n }\n else {\n throw new MapError(\"The map provided to the Core is not a valid map.\");\n }\n // Process init options.\n const optionsWithDefaults = Object.assign(this.defaultOptions(), options);\n this.logger = optionsWithDefaults.logger;\n for (const listener of optionsWithDefaults.dependencyInstantiatedListeners) {\n this.instantiatedDependencyListeners.push(listener);\n }\n for (const listener of optionsWithDefaults.dependencyInitializedListeners) {\n this.initializedDependencyListeners.push(listener);\n }\n for (const listener of optionsWithDefaults.dependencyDestroyedListeners) {\n this.destroyedDependencyListeners.push(listener);\n }\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate dependency listeners) that needs access to the Core,\n * so the Core has to exist already.\n */\n async initializeDependencies() {\n if (this.status.isInitialized) {\n throw new LifecycleError(\"Dependencies are already initialized.\");\n }\n this.statusWritable.isGettingInitialized = true;\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency)\n return;\n const wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isInitialized ||\n wraplet.wraplet.status.isGettingInitialized) {\n return;\n }\n await wraplet.wraplet.initialize();\n const listenerResults = await Promise.allSettled(this.initializedDependencyListeners.map((listener) => {\n return listener(wraplet, id);\n }));\n createLifecycleAsyncError(`Errors in the core's dependency \"${id}\" initialize listeners.`, listenerResults);\n }));\n createLifecycleAsyncError(`Error at \"${id}\" dependency's initialization.`, results);\n }));\n const error = createLifecycleAsyncError(`Error at Core's initialization.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n this.statusWritable.isInitialized = true;\n this.statusWritable.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it when initialization\n // is finished.\n if (this.statusWritable.isGettingDestroyed) {\n await this.destroyDependencies();\n }\n }\n get map() {\n return this.mapTree.getMap();\n }\n instantiateDependencies() {\n if (this.dependenciesAreInstantiated) {\n throw new LifecycleError(\"Dependencies are already instantiated.\");\n }\n const dependencies = this.directDependencies;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n this.validateMapItemForNonParent(id, dependencyDefinition);\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.dependenciesAreInstantiated = true;\n return;\n }\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n const multiple = dependencyDefinition.multiple;\n this.validateMapItem(id, dependencyDefinition);\n if (multiple) {\n if (!dependencies[id]) {\n dependencies[id] = new DefaultWrapletSet();\n }\n const currentDependencies = dependencies[id];\n // We can assert as much because items\n const instantiatedDependencies = this.instantiateMultipleDependencies(dependencyDefinition, this.node, id);\n // Add new items to the current wraplet set.\n for (const item of instantiatedDependencies) {\n currentDependencies.add(item);\n }\n continue;\n }\n dependencies[id] = this.instantiateSingleWrapletDependency(dependencyDefinition, this.node, id);\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.dependenciesAreInstantiated = true;\n }\n findExistingWraplet(id, childElement) {\n // If an element doesn't have instantiated wraplets yet, then return null.\n if (this.directDependencies === undefined || !this.directDependencies[id]) {\n return null;\n }\n const existingDependency = this.directDependencies[id];\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const childElementWraplets = childElement.wraplets;\n if (!childElementWraplets) {\n return null;\n }\n const existingDependencies = existingDependency.find((wraplet) => {\n return childElementWraplets.has(wraplet);\n });\n if (existingDependencies.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the core.\");\n }\n return existingDependencies[0];\n }\n else {\n if (!isWraplet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a Wraplet.\");\n }\n if (!childElement.wraplets) {\n return null;\n }\n if (!childElement.wraplets.has(existingDependency)) {\n return null;\n }\n }\n // Handle single.\n return existingDependency;\n }\n instantiateSingleWrapletDependency(dependencyDefinition, node, id) {\n if (!dependencyDefinition.selector) {\n return this.directDependencies[id] || null;\n }\n if (!this.dependenciesAreInstantiated && this.directDependencies[id]) {\n throw new MapError(`It's not possible to provide a single-type dependency manually and use selector at the same time.`);\n }\n const selector = dependencyDefinition.selector;\n // Find children elements based on the map.\n const childrenElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childrenElements, dependencyDefinition);\n if (childrenElements.length === 0) {\n return null;\n }\n if (childrenElements.length > 1) {\n throw new TooManyChildrenFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" dependency. Selector used: \"${selector}\".`);\n }\n const childElement = childrenElements[0];\n return this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n instantiateWrapletItem(id, dependencyDefinition, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n let wraplet = null;\n try {\n const instance = new dependencyDefinition.Class(dependencyDefinition.injector.callback(node, this.mapTree.createChild(id), dependencyDefinition.injector.data), ...dependencyDefinition.args);\n if (!isWraplet(instance)) {\n throw new Error(\"Created dependency is not a Wraplet instance.\");\n }\n wraplet = instance;\n }\n catch (e) {\n if (e instanceof UnsupportedNodeTypeError) {\n if (!dependencyDefinition.required) {\n console.warn(`${e.message} Skipping instantiation of the \"${id}\" dependency.`);\n return null;\n }\n }\n throw e;\n }\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiatedDependencyListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleDependencies(dependencyDefinition, node, id) {\n const selector = dependencyDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childElements, dependencyDefinition);\n const items = new DefaultWrapletSet();\n for (const childElement of childElements) {\n let wraplet = this.findExistingWraplet(id, childElement);\n if (!wraplet) {\n wraplet = this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n if (wraplet) {\n items.add(wraplet);\n }\n }\n return items;\n }\n addDependencyDestroyedListener(callback) {\n this.destroyedDependencyListeners.push(callback);\n }\n addDependencyInstantiatedListener(callback) {\n this.instantiatedDependencyListeners.push(callback);\n }\n addDependencyInitializedListener(callback) {\n this.initializedDependencyListeners.push(callback);\n }\n setExistingInstance(id, wraplet) {\n const map = this.map;\n if (map[id].multiple) {\n throw new MapError(`This method can only be used to set a single-value dependency.`);\n }\n if (this.directDependencies[id]) {\n throw new MapError(`Dependency is already set.`);\n }\n if (!isWraplet(wraplet)) {\n throw new MapError(`Provided instance is not a valid dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n this.directDependencies[id] = wraplet;\n }\n addExistingInstance(id, wraplet) {\n const map = this.map;\n if (!map[id].multiple) {\n throw new MapError(`This method can only be used to set a multi-value dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n const items = this.directDependencies && this.directDependencies[id]\n ? this.directDependencies[id]\n : new DefaultWrapletSet();\n items.add(wraplet);\n this.directDependencies[id] = items;\n }\n prepareIndividualWraplet(id, wraplet) {\n // Listen for the dependency's destruction.\n wraplet.wraplet.addDestroyListener(this.createDependencyDestroyListener(id));\n }\n createDependencyDestroyListener(id) {\n return (async (w) => {\n this.removeDependency(w, id);\n const results = await Promise.allSettled(this.destroyedDependencyListeners.map((listener) => listener(w, id)));\n // Collect the required-dependency error alongside listener results\n // so that everything surfaces through the same LifecycleError mechanism.\n const requiredError = this.validateRequiredDependencyAfterRemoval(id);\n if (requiredError) {\n results.push({ status: \"rejected\", reason: requiredError });\n }\n createLifecycleAsyncError(`Errors in the destruction callbacks of the \"${id} dependency.\"`, results);\n });\n }\n /**\n * Checks whether a required dependency has been removed while the core\n * is NOT being destroyed itself. Returns the error instance instead of\n * throwing, so the caller can route it through the lifecycle error pipeline.\n */\n validateRequiredDependencyAfterRemoval(id) {\n if (this.map[id].required && !this.status.isGettingDestroyed) {\n return new RequiredDependencyDestroyedError(`Required dependency \"${id}\" has been destroyed.`);\n }\n return null;\n }\n /**\n * This method removes from nodes references to this wraplet and its dependencies recursively.\n */\n async destroyDependencies() {\n if (this.statusWritable.isDestroyed) {\n throw new LifecycleError(\"Dependencies are already destroyed.\");\n }\n this.statusWritable.isGettingDestroyed = true;\n if (this.statusWritable.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!this.statusWritable.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.statusWritable.isDestroyed = true;\n this.statusWritable.isGettingDestroyed = false;\n return;\n }\n await this.destroyDeps();\n this.statusWritable.isInitialized = false;\n this.statusWritable.isDestroyed = true;\n this.statusWritable.isGettingDestroyed = false;\n }\n findChildrenElements(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n get dependencies() {\n if (!this.dependenciesAreInstantiated) {\n throw new DependenciesAreNotAvailableError(\"Wraplet is not yet fully initialized.\");\n }\n return this.wrappedDependencies;\n }\n removeDependency(wraplet, id) {\n if (isWrapletSet(this.directDependencies[id])) {\n this.directDependencies[id].delete(wraplet);\n return;\n }\n // Only nullify the dependency if the current instance is the same one.\n // If it's not, then we don't care as there is no reference either way.\n if (this.directDependencies[id] === wraplet) {\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.directDependencies[id] = null;\n }\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector &&\n isRequired &&\n (!this.directDependencies[id] ||\n (isWrapletSet(this.directDependencies[id]) &&\n this.directDependencies[id].size === 0))) {\n throw new MapError(`${this.constructor.name}: Dependency \"${id}\" cannot at the same be required, have no selector, and be not provided otherwise.`);\n }\n }\n validateMapItemForNonParent(id, item) {\n if (item.required) {\n throw new MapError(`Dependency \"${id}\" error: If the node provided cannot have children, there should be no required dependencies.`);\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredDependencyError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if dependencies have not been destroyed before fetching them.\n */\n wrapDependencies(dependencies) {\n return new Proxy(dependencies, {\n get: (target, name) => {\n if (typeof name === \"symbol\") {\n throw new Error(`Symbol access is not supported for dependencies.`);\n }\n if (!(name in target)) {\n throw new Error(`Dependency '${name}' has not been found.`);\n }\n return target[name];\n },\n set: () => {\n throw new Error(`Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.`);\n },\n });\n }\n defaultOptions() {\n return {\n dependencyInstantiatedListeners: [],\n dependencyInitializedListeners: [],\n dependencyDestroyedListeners: [],\n logger: ConsoleLogger.getGlobalLogger(),\n };\n }\n async destroyDeps() {\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency || !this.map[id][\"destructible\"]) {\n return;\n }\n const wraplets = [];\n if (isWrapletSet(dependency)) {\n for (const item of dependency) {\n wraplets.push(item);\n }\n }\n else {\n wraplets.push(dependency);\n }\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isDestroyed ||\n wraplet.wraplet.status.isGettingDestroyed) {\n return;\n }\n return wraplet.wraplet.destroy();\n }));\n createLifecycleAsyncError(`Errors during destruction of the \"${id}\" dependency.`, results);\n }));\n const error = createLifecycleAsyncError(`Errors during the dependencies destruction.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n }\n /**\n * Creates a definition for creating a node wrapper.\n *\n * @param map_or_position\n * You can provide a map or a number representing the\n * relative position of the ancestor map that should be\n * reused.\n *\n * This is useful for recursive maps.\n * @param options\n */\n static createInjector(map_or_position, options) {\n return {\n data: options || {},\n callback: (node, map, data) => {\n let currentMap = map;\n const integerGuard = (input) => Number.isInteger(input);\n if (integerGuard(map_or_position)) {\n for (let i = 0; i < map_or_position; i++) {\n currentMap = currentMap.getParent();\n }\n }\n else if (isWrapletDependencyMap(map_or_position)) {\n currentMap.setMap(map_or_position);\n }\n else {\n throw new Error(`Invalid map argument.`);\n }\n return new Core(node, currentMap, data);\n },\n };\n }\n}\n","export const isOverridden = (instance, methodName, \n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nstopAt) => {\n let proto = Object.getPrototypeOf(instance);\n const stopProto = stopAt ? stopAt.prototype : Object.getPrototypeOf(proto);\n while (proto && proto !== stopProto) {\n if (Object.prototype.hasOwnProperty.call(proto, methodName)) {\n return true;\n }\n proto = Object.getPrototypeOf(proto);\n }\n return false;\n};\n","export class NodeManager {\n node;\n listeners = [];\n constructor(node) {\n this.node = node;\n }\n addListener(eventName, callback, options) {\n this.node.addEventListener(eventName, callback, options);\n this.listeners.push({\n callback,\n event: eventName,\n options: options,\n });\n }\n destroy() {\n for (const listener of this.listeners) {\n this.node.removeEventListener(listener.event, listener.callback, listener.options);\n }\n this.listeners.length = 0;\n }\n}\n","import { is } from \"../../utils/is\";\nexport const WrapletApiSymbol = Symbol(\"WrapletApi\");\nexport function isWrapletApi(object) {\n return is(object, WrapletApiSymbol);\n}\n","import { LifecycleError } from \"../errors\";\nexport function initializationStarted(status) {\n if (status.isInitialized ||\n status.isGettingInitialized ||\n status.isDestroyed ||\n status.isGettingDestroyed) {\n return false;\n }\n status.isGettingInitialized = true;\n return true;\n}\nexport async function initializationCompleted(status, destroyMethod) {\n status.isInitialized = true;\n status.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (status.isGettingDestroyed) {\n await destroyMethod();\n }\n}\nexport function destructionStarted(status) {\n if (status.isDestroyed) {\n return false;\n }\n status.isGettingDestroyed = true;\n if (status.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return false;\n }\n if (!status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n throw new LifecycleError(\"Wraplet cannot be destroyed before it is initialized.\");\n }\n return true;\n}\nexport async function destructionCompleted(status, wraplet, destroyListeners) {\n status.isGettingDestroyed = false;\n status.isInitialized = false;\n status.isDestroyed = true;\n for (const listener of [...destroyListeners].reverse()) {\n await listener(wraplet);\n }\n destroyListeners.length = 0;\n}\n","import { destructionCompleted, destructionStarted, } from \"../Wraplet/statusActions\";\nexport function createOuterDestroyCallback(args, destroyLogic) {\n return async function () {\n const outerStatus = args.status;\n if (!destructionStarted(outerStatus)) {\n return;\n }\n if (destroyLogic) {\n await destroyLogic();\n }\n await destructionCompleted(outerStatus, args.wraplet, args.destroyListeners);\n };\n}\n","import { initializationCompleted, initializationStarted, } from \"../Wraplet/statusActions\";\nexport function createOuterInitializeCallback(args, initializeLogic) {\n return async function () {\n const outerStatus = args.status;\n if (!initializationStarted(outerStatus)) {\n return;\n }\n if (initializeLogic) {\n await initializeLogic();\n }\n await initializationCompleted(outerStatus, args.destroyCallback);\n };\n}\n","import { addWrapletToNode, removeWrapletFromNode, } from \"../NodeTreeManager/utils\";\nimport { WrapletApiSymbol, } from \"./types/WrapletApi\";\nimport { isWraplet } from \"./types/Wraplet\";\nimport { createOuterDestroyCallback } from \"./createOuterDestroyCallback\";\nimport { createOuterInitializeCallback } from \"./createOuterInitializeCallback\";\nfunction validateNodeWrapletApiFactoryArgs(args) {\n if (!isWraplet(args.wraplet)) {\n throw new Error(\"Correct wraplet instance has to be provided.\");\n }\n if (args.node && !(args.node instanceof Node)) {\n throw new Error(\"Correct node has to be provided.\");\n }\n if (args.initializeCallback &&\n typeof args.initializeCallback !== \"function\") {\n throw new Error(\"initializeCallback has to be a function.\");\n }\n if (args.destroyCallback && typeof args.destroyCallback !== \"function\") {\n throw new Error(\"destroyCallback has to be a function.\");\n }\n}\nexport const createWrapletApi = (args) => {\n validateNodeWrapletApiFactoryArgs(args);\n const newArgs = { ...args };\n const defaultStatus = {\n isGettingInitialized: false,\n isDestroyed: false,\n isInitialized: false,\n isGettingDestroyed: false,\n };\n const api = {};\n const destroyListeners = [];\n const destroyCallback = createOuterDestroyCallback({\n status: defaultStatus,\n wraplet: newArgs.wraplet,\n destroyListeners: destroyListeners,\n }, async () => {\n if (newArgs.destroyCallback) {\n await newArgs.destroyCallback();\n }\n if (newArgs.node) {\n removeWrapletFromNode(newArgs.wraplet, newArgs.node);\n }\n }).bind(api);\n const initializeCallback = createOuterInitializeCallback({\n status: defaultStatus,\n destroyCallback: destroyCallback,\n wraplet: newArgs.wraplet,\n }, async () => {\n if (newArgs.node) {\n addWrapletToNode(newArgs.wraplet, newArgs.node);\n }\n if (newArgs.initializeCallback) {\n await newArgs.initializeCallback();\n }\n }).bind(api);\n return Object.assign(api, {\n [WrapletApiSymbol]: true,\n __destroyListeners: destroyListeners,\n status: defaultStatus,\n addDestroyListener: (callback) => {\n destroyListeners.push(callback);\n },\n initialize: initializeCallback,\n destroy: destroyCallback,\n });\n};\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { UnsupportedNodeTypeError } from \"../errors\";\nimport { isOverridden } from \"./utils\";\nimport { NodeManager } from \"./NodeManager\";\nimport { createWrapletApi } from \"./createWrapletApi\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n wraplet;\n _nodeManager;\n constructor(node) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"AbstractWraplet requires a Node instance.\");\n }\n const supportedNodeTypes = this.supportedNodeTypes();\n if (supportedNodeTypes !== null) {\n if (!supportedNodeTypes.find((value) => node instanceof value)) {\n throw new UnsupportedNodeTypeError(`Node type ${node.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);\n }\n }\n this.wraplet = this.createWrapletApi();\n }\n /**\n * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet)\n * can override this to supply their own lifecycle callbacks without causing a\n * double-creation of WrapletApi.\n */\n createWrapletApi() {\n const initializeCallback = isOverridden(this, \"onInitialize\", AbstractWraplet)\n ? this.onInitialize.bind(this)\n : undefined;\n const destroyCallback = isOverridden(this, \"onDestroy\", AbstractWraplet)\n ? this.onDestroy.bind(this)\n : undefined;\n return this.buildWrapletApi(initializeCallback, destroyCallback);\n }\n /**\n * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup\n * is always wired into the destroy path.\n */\n buildWrapletApi(initializeCallback, destroyCallback) {\n return createWrapletApi({\n node: this.node,\n wraplet: this,\n initializeCallback,\n destroyCallback: async () => {\n if (destroyCallback) {\n await destroyCallback();\n }\n if (this._nodeManager) {\n this._nodeManager.destroy();\n }\n },\n });\n }\n get nodeManager() {\n if (!this._nodeManager) {\n this._nodeManager = new NodeManager(this.node);\n }\n return this._nodeManager;\n }\n /**\n * Subclasses must return an array of constructors covering all types in union N.\n * Wrap the result in the `supportedTypeCheck` helper to make sure that the array contains all\n * and only classes that extend the given type.\n */\n supportedNodeTypes() {\n return null;\n }\n /**\n * Helper for subclasses to easily satisfy the exhaustive check.\n */\n supportedNodeTypesGuard(types) {\n return types;\n }\n /**\n * This method gets invoked when the wraplet is initialized.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onInitialize() {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * This method gets invoked when the wraplet is destroyed.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDestroy() {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n */\n static createWraplets(node, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n */\n static async createAndInitializeWraplets(node, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createWraplets(node, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { isDependencyManager, } from \"../DependencyManager/types/DependencyManager\";\nimport { Core } from \"../DependencyManager/Core\";\nimport { isOverridden } from \"./utils\";\nimport { AbstractWraplet } from \"./AbstractWraplet\";\nexport class AbstractDependentWraplet extends AbstractWraplet {\n dm;\n constructor(dm) {\n if (!isDependencyManager(dm)) {\n throw new Error(\"AbstractDependentWraplet requires an instance implementing DependencyManager and NodeManager interfaces.\");\n }\n super(dm.node);\n this.dm = dm;\n if (isOverridden(this, \"onDependencyInitialized\", AbstractDependentWraplet)) {\n dm.addDependencyInitializedListener(this.onDependencyInitialized.bind(this));\n }\n if (isOverridden(this, \"onDependencyInstantiated\", AbstractDependentWraplet)) {\n dm.addDependencyInstantiatedListener(this.onDependencyInstantiated.bind(this));\n }\n if (isOverridden(this, \"onDependencyDestroyed\", AbstractDependentWraplet)) {\n dm.addDependencyDestroyedListener(this.onDependencyDestroyed.bind(this));\n }\n dm.instantiateDependencies();\n }\n /**\n * Override createWrapletApi to provide Core-aware lifecycle callbacks\n * instead of the base class's version — this avoids creating two WrapletApi\n * instances.\n */\n createWrapletApi() {\n return this.buildWrapletApi(this.onInitialize.bind(this), this.onDestroy.bind(this));\n }\n async onDestroy() {\n await this.dm.destroyDependencies();\n }\n async onInitialize() {\n await this.dm.initializeDependencies();\n }\n /**\n * Dependencies.\n */\n get d() {\n return this.dm.dependencies;\n }\n /**\n * his method will be invoked if one of the wraplet's dependencies has been instantiated.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n onDependencyInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * his method will be invoked if one of the wraplet's dependencies has been initialized.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDependencyInitialized(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * This method will be ivoked if one of the wraplet's dependencies has been destroyed.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDependencyDestroyed(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n static createDependencyManager(node, map) {\n return new Core(node, map);\n }\n static createWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n static createAndInitializeWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n */\n static createDependentWraplets(node, map, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractDependentWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const self = this;\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const dm = self.createDependencyManager(node, map);\n result.push(new this(dm, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n const dm = self.createDependencyManager(element, map);\n result.push(new this(dm, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n */\n static async createAndInitializeDependentWraplets(node, map, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createDependentWraplets(node, map, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport class DefaultNodeTreeManager {\n initializers = [];\n addNodeInitializer(callback) {\n this.initializers.push(callback);\n }\n async initializeNode(node, context) {\n const results = await Promise.allSettled(this.initializers.map((initializer) => initializer(node, context)));\n createLifecycleAsyncError(`There were errors during the node's initialization.`, results);\n }\n async destroyNode(node) {\n await destroyWrapletsRecursively(node);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredDependencyError","Error","MapError","RequiredDependencyDestroyedError","DependenciesAreNotAvailableError","StorageValidationError","TooManyChildrenFoundError","InternalLogicError","UnsupportedNodeTypeError","LifecycleError","LifecycleAsyncErrors","errors","is","object","symbol","WrapletSymbol","isWraplet","isSimpleObject","input","getPrototypeOf","isDependencyMapItem","item","keys","includes","isWrapletDependencyMap","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","createLifecycleAsyncError","message","throwError","error","result","status","reason","length","getWrapletsFromNode","node","wraplets","async","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","allWraplets","wraplet","isGettingDestroyed","isDestroyed","Promise","allSettled","map","destroy","DependencyManagerSymbol","ConsoleLogger","static","constructor","dumpError","console","dir","depth","getGlobalLogger","addDefaultsToDependencyDefinition","args","destructible","injector","MapTreeBuilderSymbol","MapTreeBuilder","parent","getParent","createChild","name","mapBuilder","setMap","newMap","id","def","fillMapWithDefaults","getMap","Core","logger","dependenciesAreInstantiated","statusWritable","isInitialized","isGettingInitialized","mapTree","directDependencies","wrappedDependencies","destroyedDependencyListeners","instantiatedDependencyListeners","initializedDependencyListeners","options","Node","optionsWithDefaults","assign","defaultOptions","listener","dependencyInstantiatedListeners","dependencyInitializedListeners","dependencyDestroyedListeners","initializeDependencies","entries","dependency","initialize","listenerResults","destroyDependencies","instantiateDependencies","dependencies","querySelectorAll","dependencyDefinition","validateMapItemForNonParent","wrapDependencies","multiple","validateMapItem","currentDependencies","instantiatedDependencies","instantiateMultipleDependencies","add","instantiateSingleWrapletDependency","findExistingWraplet","childElement","undefined","existingDependency","childElementWraplets","existingDependencies","has","selector","childrenElements","findChildrenElements","validateElements","instantiateWrapletItem","existingWraplet","instance","Class","data","e","required","warn","prepareIndividualWraplet","childElements","items","addDependencyDestroyedListener","addDependencyInstantiatedListener","addDependencyInitializedListener","setExistingInstance","addExistingInstance","addDestroyListener","createDependencyDestroyListener","w","removeDependency","requiredError","validateRequiredDependencyAfterRemoval","destroyDeps","defaultSelectorCallback","delete","isRequired","size","elements","mapItem","Proxy","target","set","createInjector","map_or_position","currentMap","Number","isInteger","i","isOverridden","methodName","stopAt","proto","stopProto","NodeManager","listeners","addListener","eventName","addEventListener","event","removeEventListener","WrapletApiSymbol","initializationStarted","initializationCompleted","destroyMethod","destructionStarted","destructionCompleted","destroyListeners","reverse","createOuterDestroyCallback","destroyLogic","outerStatus","createOuterInitializeCallback","initializeLogic","destroyCallback","createWrapletApi","initializeCallback","validateNodeWrapletApiFactoryArgs","newArgs","defaultStatus","api","removeWrapletFromNode","bind","__destroyListeners","AbstractWraplet","_nodeManager","supportedNodeTypes","onInitialize","onDestroy","buildWrapletApi","nodeManager","supportedNodeTypesGuard","types","createWraplets","attribute","additional_args","Element","hasAttribute","foundElements","element","createAndInitializeWraplets","AbstractDependentWraplet","dm","super","onDependencyInitialized","onDependencyInstantiated","onDependencyDestroyed","d","createDependencyManager","createDependentWraplets","self","createAndInitializeDependentWraplets","DefaultWrapletSetReadonly","DefaultNodeTreeManager","initializers","addNodeInitializer","initialize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AY,CACzD,MAAMQ,EAAKQ,EAAKF,wBAAwB9L,EAAMc,GAC9CnB,EAAOf,KAAK,IAAID,KAAK6M,KAAOP,GAChC,CACA,MAAMG,EAAgBpL,EAAKuE,iBAAiB,IAAIyG,MAChD,IAAK,MAAMK,KAAWD,EAAe,CACjC,MAAMI,EAAKQ,EAAKF,wBAAwBT,EAASvK,GACjDnB,EAAOf,KAAK,IAAID,KAAK6M,KAAOP,GAChC,CACA,OAAOtL,CACX,CAIA,iDAAasM,CAAqCjM,EAAMc,EAAKkK,EAAWC,EAAkB,IACtF,MACMhL,EADOtB,KACSoN,wBAAwB/L,EAAMc,EAAKkK,EAAWC,GACpE,IAAK,MAAMxK,KAAWR,QACZQ,EAAQA,QAAQyD,aAE1B,OAAOjE,CACX,ECpHG,MAAMiM,UAAkC5N,EAC3C,CAACe,IAA4B,ECD1B,MAAM8M,EACTC,aAAe,GACf,kBAAAC,CAAmBtN,GACfJ,KAAKyN,aAAaxN,KAAKG,EAC3B,CACA,oBAAMuN,CAAetM,EAAMuM,GAEvBhN,EAA0B,4DADJqB,QAAQC,WAAWlC,KAAKyN,aAAatL,IAAK0L,GAAgBA,EAAYxM,EAAMuM,KAEtG,CACA,iBAAME,CAAYzM,SACRO,EAA2BP,EACrC,E","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils/is.ts","webpack://wraplet/./src/Wraplet/types/Wraplet.ts","webpack://wraplet/./src/Wraplet/types/WrapletDependencyMap.ts","webpack://wraplet/./src/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils/createLifecycleAsyncError.ts","webpack://wraplet/./src/NodeTreeManager/utils.ts","webpack://wraplet/./src/DependencyManager/types/DependencyManager.ts","webpack://wraplet/./src/Logger/ConsoleLogger.ts","webpack://wraplet/./src/Map/utils.ts","webpack://wraplet/./src/Map/MapTreeBuilder.ts","webpack://wraplet/./src/DependencyManager/DDM.ts","webpack://wraplet/./src/Wraplet/utils.ts","webpack://wraplet/./src/Wraplet/NodeManager.ts","webpack://wraplet/./src/Wraplet/types/WrapletApi.ts","webpack://wraplet/./src/Wraplet/statusActions.ts","webpack://wraplet/./src/Wraplet/createOuterDestroyCallback.ts","webpack://wraplet/./src/Wraplet/createOuterInitializeCallback.ts","webpack://wraplet/./src/Wraplet/createWrapletApi.ts","webpack://wraplet/./src/Wraplet/AbstractWraplet.ts","webpack://wraplet/./src/Wraplet/AbstractDependentWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts","webpack://wraplet/./src/NodeTreeManager/DefaultNodeTreeManager.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredDependencyError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredDependencyDestroyedError extends Error {\n}\nexport class DependenciesAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class TooManyChildrenFoundError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\nexport class UnsupportedNodeTypeError extends Error {\n}\nexport class LifecycleError extends Error {\n}\nexport class LifecycleAsyncErrors extends Error {\n errors = [];\n}\n","/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../../utils/is\";\nexport const WrapletSymbol = Symbol(\"Wraplet\");\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","function isSimpleObject(input) {\n return (typeof input === \"object\" &&\n input !== null &&\n Object.getPrototypeOf(input) === Object.prototype);\n}\nfunction isDependencyMapItem(item) {\n for (const key of Object.keys(item)) {\n if (![\n \"selector\",\n \"Class\",\n \"multiple\",\n \"required\",\n \"destructible\",\n \"injector\",\n \"map\",\n \"args\",\n ].includes(key)) {\n return false;\n }\n }\n if (![\"string\", \"function\", \"undefined\"].includes(typeof item[\"selector\"])) {\n return false;\n }\n if (typeof item[\"Class\"] !== \"function\") {\n return false;\n }\n if (typeof item[\"required\"] !== \"boolean\") {\n return false;\n }\n return typeof item[\"multiple\"] === \"boolean\";\n}\nexport function isWrapletDependencyMap(object) {\n if (!isSimpleObject(object)) {\n return false;\n }\n for (const key in object) {\n if (!isSimpleObject(object[key])) {\n return false;\n }\n const item = object[key];\n if (!isDependencyMapItem(item)) {\n return false;\n }\n }\n return true;\n}\n","import { is } from \"../../utils/is\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"./types/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { LifecycleAsyncErrors } from \"../errors\";\nexport function createLifecycleAsyncError(message, results, throwError = true) {\n const error = new LifecycleAsyncErrors(message);\n for (const result of results) {\n if (result.status === \"rejected\") {\n error.errors.push(result.reason);\n }\n }\n if (error.errors.length === 0) {\n return null;\n }\n if (throwError) {\n throw error;\n }\n return error;\n}\n","import { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (isWrapletSet(wraplets)) {\n return wraplets;\n }\n return null;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return false;\n }\n return wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport async function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n await actOnNodesRecursively(child, callback);\n }\n}\nexport async function destroyWrapletsRecursively(node) {\n const allWraplets = [];\n await actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return;\n }\n for (const wraplet of [...wraplets]) {\n if (wraplet.wraplet.status.isGettingDestroyed ||\n wraplet.wraplet.status.isDestroyed) {\n continue;\n }\n allWraplets.push(wraplet);\n }\n });\n const results = await Promise.allSettled(allWraplets.map((wraplet) => wraplet.wraplet.destroy()));\n createLifecycleAsyncError(\"Some wraplets threw exceptions during destruction\", results);\n}\n","import { is } from \"../../utils/is\";\nexport const DependencyManagerSymbol = Symbol(\"DependencyManager\");\nexport function isDependencyManager(object) {\n return is(object, DependencyManagerSymbol);\n}\n","export class ConsoleLogger {\n static #instance = new ConsoleLogger();\n constructor() { }\n dumpError(error) {\n console.dir(error, { depth: null });\n }\n static getGlobalLogger() {\n return this.#instance;\n }\n}\n","export function addDefaultsToDependencyDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n injector: {\n callback: (node) => node,\n },\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id of Object.keys(map)) {\n const def = map[id];\n newMap[id] = addDefaultsToDependencyDefinition(def);\n }\n return newMap;\n}\n","import { fillMapWithDefaults } from \"./utils\";\nconst MapTreeBuilderSymbol = Symbol(\"MapTreeBuilder\");\nexport class MapTreeBuilder {\n parent;\n [MapTreeBuilderSymbol] = true;\n map;\n children = {};\n constructor(parent) {\n this.parent = parent;\n }\n getParent() {\n if (!this.parent) {\n throw new Error(\"Parent not found.\");\n }\n return this.parent;\n }\n createChild(name) {\n const mapBuilder = new MapTreeBuilder(this);\n this.children[name] = mapBuilder;\n return mapBuilder;\n }\n setMap(map) {\n this.map = fillMapWithDefaults(map);\n }\n getMap() {\n if (!this.map) {\n throw new Error(\"Map is not set.\");\n }\n return this.map;\n }\n}\nexport function isMapTreeBuilder(object) {\n return (typeof object === \"object\" &&\n object !== null &&\n MapTreeBuilderSymbol in object);\n}\n","import { DependenciesAreNotAvailableError, TooManyChildrenFoundError, InternalLogicError, MapError, MissingRequiredDependencyError, UnsupportedNodeTypeError, LifecycleError, RequiredDependencyDestroyedError, } from \"../errors\";\nimport { isWraplet } from \"../Wraplet/types/Wraplet\";\nimport { isWrapletDependencyMap, } from \"../Wraplet/types/WrapletDependencyMap\";\nimport { isParentNode } from \"../NodeTreeManager/utils\";\nimport { DependencyManagerSymbol, } from \"./types/DependencyManager\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { ConsoleLogger } from \"../Logger/ConsoleLogger\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nimport { isMapTreeBuilder, MapTreeBuilder } from \"../Map/MapTreeBuilder\";\nexport class DDM {\n node;\n [DependencyManagerSymbol] = true;\n logger;\n dependenciesAreInstantiated = false;\n statusWritable = {\n isDestroyed: false,\n isGettingDestroyed: false,\n isInitialized: false,\n isGettingInitialized: false,\n };\n get status() {\n return this.statusWritable;\n }\n mapTree;\n directDependencies = {};\n wrappedDependencies = {};\n destroyedDependencyListeners = [];\n instantiatedDependencyListeners = [];\n initializedDependencyListeners = [];\n constructor(node, map, options = {}) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"The node provided to the DDM is not a valid node.\");\n }\n if (isWrapletDependencyMap(map)) {\n this.mapTree = new MapTreeBuilder();\n this.mapTree.setMap(map);\n }\n else if (isMapTreeBuilder(map)) {\n this.mapTree = map;\n }\n else {\n throw new MapError(\"The map provided to the DDM is not a valid map.\");\n }\n // Process init options.\n const optionsWithDefaults = Object.assign(this.defaultOptions(), options);\n this.logger = optionsWithDefaults.logger;\n for (const listener of optionsWithDefaults.dependencyInstantiatedListeners) {\n this.instantiatedDependencyListeners.push(listener);\n }\n for (const listener of optionsWithDefaults.dependencyInitializedListeners) {\n this.initializedDependencyListeners.push(listener);\n }\n for (const listener of optionsWithDefaults.dependencyDestroyedListeners) {\n this.destroyedDependencyListeners.push(listener);\n }\n }\n /**\n * Initialize DDM.\n */\n async initializeDependencies() {\n if (this.status.isInitialized) {\n throw new LifecycleError(\"Dependencies are already initialized.\");\n }\n this.statusWritable.isGettingInitialized = true;\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency)\n return;\n const wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isInitialized ||\n wraplet.wraplet.status.isGettingInitialized) {\n return;\n }\n await wraplet.wraplet.initialize();\n const listenerResults = await Promise.allSettled(this.initializedDependencyListeners.map((listener) => {\n return listener(wraplet, id);\n }));\n createLifecycleAsyncError(`Errors in the DDM's dependency \"${id}\" initialize listeners.`, listenerResults);\n }));\n createLifecycleAsyncError(`Error at \"${id}\" dependency's initialization.`, results);\n }));\n const error = createLifecycleAsyncError(`Error at DDM's initialization.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n this.statusWritable.isInitialized = true;\n this.statusWritable.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it when initialization\n // is finished.\n if (this.statusWritable.isGettingDestroyed) {\n await this.destroyDependencies();\n }\n }\n get map() {\n return this.mapTree.getMap();\n }\n instantiateDependencies() {\n if (this.dependenciesAreInstantiated) {\n throw new LifecycleError(\"Dependencies are already instantiated.\");\n }\n const dependencies = this.directDependencies;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n this.validateMapItemForNonParent(id, dependencyDefinition);\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.dependenciesAreInstantiated = true;\n return;\n }\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n const multiple = dependencyDefinition.multiple;\n this.validateMapItem(id, dependencyDefinition);\n if (multiple) {\n if (!dependencies[id]) {\n dependencies[id] = new DefaultWrapletSet();\n }\n const currentDependencies = dependencies[id];\n // We can assert as much because items\n const instantiatedDependencies = this.instantiateMultipleDependencies(dependencyDefinition, this.node, id);\n // Add new items to the current wraplet set.\n for (const item of instantiatedDependencies) {\n currentDependencies.add(item);\n }\n continue;\n }\n dependencies[id] = this.instantiateSingleWrapletDependency(dependencyDefinition, this.node, id);\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.dependenciesAreInstantiated = true;\n }\n findExistingWraplet(id, childElement) {\n // If an element doesn't have instantiated wraplets yet, then return null.\n if (this.directDependencies === undefined || !this.directDependencies[id]) {\n return null;\n }\n const existingDependency = this.directDependencies[id];\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const childElementWraplets = childElement.wraplets;\n if (!childElementWraplets) {\n return null;\n }\n const existingDependencies = existingDependency.find((wraplet) => {\n return childElementWraplets.has(wraplet);\n });\n if (existingDependencies.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the DDM.\");\n }\n return existingDependencies[0];\n }\n else {\n if (!isWraplet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a Wraplet.\");\n }\n if (!childElement.wraplets) {\n return null;\n }\n if (!childElement.wraplets.has(existingDependency)) {\n return null;\n }\n }\n // Handle single.\n return existingDependency;\n }\n instantiateSingleWrapletDependency(dependencyDefinition, node, id) {\n if (!dependencyDefinition.selector) {\n return this.directDependencies[id] || null;\n }\n if (!this.dependenciesAreInstantiated && this.directDependencies[id]) {\n throw new MapError(`It's not possible to provide a single-type dependency manually and use selector at the same time.`);\n }\n const selector = dependencyDefinition.selector;\n // Find children elements based on the map.\n const childrenElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childrenElements, dependencyDefinition);\n if (childrenElements.length === 0) {\n return null;\n }\n if (childrenElements.length > 1) {\n throw new TooManyChildrenFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" dependency. Selector used: \"${selector}\".`);\n }\n const childElement = childrenElements[0];\n return this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n instantiateWrapletItem(id, dependencyDefinition, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n let wraplet = null;\n try {\n const instance = new dependencyDefinition.Class(dependencyDefinition.injector.callback(node, this.mapTree.createChild(id), dependencyDefinition.injector.data), ...dependencyDefinition.args);\n if (!isWraplet(instance)) {\n throw new Error(\"Created dependency is not a Wraplet instance.\");\n }\n wraplet = instance;\n }\n catch (e) {\n if (e instanceof UnsupportedNodeTypeError) {\n if (!dependencyDefinition.required) {\n console.warn(`${e.message} Skipping instantiation of the \"${id}\" dependency.`);\n return null;\n }\n }\n throw e;\n }\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiatedDependencyListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleDependencies(dependencyDefinition, node, id) {\n const selector = dependencyDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childElements, dependencyDefinition);\n const items = new DefaultWrapletSet();\n for (const childElement of childElements) {\n let wraplet = this.findExistingWraplet(id, childElement);\n if (!wraplet) {\n wraplet = this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n if (wraplet) {\n items.add(wraplet);\n }\n }\n return items;\n }\n addDependencyDestroyedListener(callback) {\n this.destroyedDependencyListeners.push(callback);\n }\n addDependencyInstantiatedListener(callback) {\n this.instantiatedDependencyListeners.push(callback);\n }\n addDependencyInitializedListener(callback) {\n this.initializedDependencyListeners.push(callback);\n }\n setExistingInstance(id, wraplet) {\n const map = this.map;\n if (map[id].multiple) {\n throw new MapError(`This method can only be used to set a single-value dependency.`);\n }\n if (this.directDependencies[id]) {\n throw new MapError(`Dependency is already set.`);\n }\n if (!isWraplet(wraplet)) {\n throw new MapError(`Provided instance is not a valid dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n this.directDependencies[id] = wraplet;\n }\n addExistingInstance(id, wraplet) {\n const map = this.map;\n if (!map[id].multiple) {\n throw new MapError(`This method can only be used to set a multi-value dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n const items = this.directDependencies && this.directDependencies[id]\n ? this.directDependencies[id]\n : new DefaultWrapletSet();\n items.add(wraplet);\n this.directDependencies[id] = items;\n }\n prepareIndividualWraplet(id, wraplet) {\n // Listen for the dependency's destruction.\n wraplet.wraplet.addDestroyListener(this.createDependencyDestroyListener(id));\n }\n createDependencyDestroyListener(id) {\n return (async (w) => {\n this.removeDependency(w, id);\n const results = await Promise.allSettled(this.destroyedDependencyListeners.map((listener) => listener(w, id)));\n // Collect the required-dependency error alongside listener results\n // so that everything surfaces through the same LifecycleError mechanism.\n const requiredError = this.validateRequiredDependencyAfterRemoval(id);\n if (requiredError) {\n results.push({ status: \"rejected\", reason: requiredError });\n }\n createLifecycleAsyncError(`Errors in the destruction callbacks of the \"${id} dependency.\"`, results);\n });\n }\n /**\n * Checks whether a required dependency has been removed while the DDM\n * is NOT being destroyed itself. Returns the error instance instead of\n * throwing, so the caller can route it through the lifecycle error pipeline.\n */\n validateRequiredDependencyAfterRemoval(id) {\n if (this.map[id].required && !this.status.isGettingDestroyed) {\n return new RequiredDependencyDestroyedError(`Required dependency \"${id}\" has been destroyed.`);\n }\n return null;\n }\n /**\n * This method removes from nodes references to this wraplet and its dependencies recursively.\n */\n async destroyDependencies() {\n if (this.statusWritable.isDestroyed) {\n throw new LifecycleError(\"Dependencies are already destroyed.\");\n }\n this.statusWritable.isGettingDestroyed = true;\n if (this.statusWritable.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!this.statusWritable.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.statusWritable.isDestroyed = true;\n this.statusWritable.isGettingDestroyed = false;\n return;\n }\n await this.destroyDeps();\n this.statusWritable.isInitialized = false;\n this.statusWritable.isDestroyed = true;\n this.statusWritable.isGettingDestroyed = false;\n }\n findChildrenElements(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n get dependencies() {\n if (!this.dependenciesAreInstantiated) {\n throw new DependenciesAreNotAvailableError(\"Wraplet is not yet fully initialized.\");\n }\n return this.wrappedDependencies;\n }\n removeDependency(wraplet, id) {\n if (isWrapletSet(this.directDependencies[id])) {\n this.directDependencies[id].delete(wraplet);\n return;\n }\n // Only nullify the dependency if the current instance is the same one.\n // If it's not, then we don't care as there is no reference either way.\n if (this.directDependencies[id] === wraplet) {\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.directDependencies[id] = null;\n }\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector &&\n isRequired &&\n (!this.directDependencies[id] ||\n (isWrapletSet(this.directDependencies[id]) &&\n this.directDependencies[id].size === 0))) {\n throw new MapError(`${this.constructor.name}: Dependency \"${id}\" cannot at the same be required, have no selector, and be not provided otherwise.`);\n }\n }\n validateMapItemForNonParent(id, item) {\n if (item.required) {\n throw new MapError(`Dependency \"${id}\" error: If the node provided cannot have children, there should be no required dependencies.`);\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredDependencyError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if dependencies have not been destroyed before fetching them.\n */\n wrapDependencies(dependencies) {\n return new Proxy(dependencies, {\n get: (target, name) => {\n if (typeof name === \"symbol\") {\n throw new Error(`Symbol access is not supported for dependencies.`);\n }\n if (!(name in target)) {\n throw new Error(`Dependency '${name}' has not been found.`);\n }\n return target[name];\n },\n set: () => {\n throw new Error(`Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.`);\n },\n });\n }\n defaultOptions() {\n return {\n dependencyInstantiatedListeners: [],\n dependencyInitializedListeners: [],\n dependencyDestroyedListeners: [],\n logger: ConsoleLogger.getGlobalLogger(),\n };\n }\n async destroyDeps() {\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency || !this.map[id][\"destructible\"]) {\n return;\n }\n const wraplets = [];\n if (isWrapletSet(dependency)) {\n for (const item of dependency) {\n wraplets.push(item);\n }\n }\n else {\n wraplets.push(dependency);\n }\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isDestroyed ||\n wraplet.wraplet.status.isGettingDestroyed) {\n return;\n }\n return wraplet.wraplet.destroy();\n }));\n createLifecycleAsyncError(`Errors during destruction of the \"${id}\" dependency.`, results);\n }));\n const error = createLifecycleAsyncError(`Errors during the dependencies destruction.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n }\n /**\n * Creates a definition for creating a node wrapper.\n *\n * @param map_or_position\n * You can provide a map or a number representing the\n * relative position of the ancestor map that should be\n * reused.\n *\n * This is useful for recursive maps.\n * @param options\n */\n static createInjector(map_or_position, options) {\n return {\n data: options || {},\n callback: (node, map, data) => {\n let currentMap = map;\n const integerGuard = (input) => Number.isInteger(input);\n if (integerGuard(map_or_position)) {\n for (let i = 0; i < map_or_position; i++) {\n currentMap = currentMap.getParent();\n }\n }\n else if (isWrapletDependencyMap(map_or_position)) {\n currentMap.setMap(map_or_position);\n }\n else {\n throw new Error(`Invalid map argument.`);\n }\n return new DDM(node, currentMap, data);\n },\n };\n }\n}\n","export const isOverridden = (instance, methodName, \n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nstopAt) => {\n let proto = Object.getPrototypeOf(instance);\n const stopProto = stopAt ? stopAt.prototype : Object.getPrototypeOf(proto);\n while (proto && proto !== stopProto) {\n if (Object.prototype.hasOwnProperty.call(proto, methodName)) {\n return true;\n }\n proto = Object.getPrototypeOf(proto);\n }\n return false;\n};\n","export class NodeManager {\n node;\n listeners = [];\n constructor(node) {\n this.node = node;\n }\n addListener(eventName, callback, options) {\n this.node.addEventListener(eventName, callback, options);\n this.listeners.push({\n callback,\n event: eventName,\n options: options,\n });\n }\n destroy() {\n for (const listener of this.listeners) {\n this.node.removeEventListener(listener.event, listener.callback, listener.options);\n }\n this.listeners.length = 0;\n }\n}\n","import { is } from \"../../utils/is\";\nexport const WrapletApiSymbol = Symbol(\"WrapletApi\");\nexport function isWrapletApi(object) {\n return is(object, WrapletApiSymbol);\n}\n","import { LifecycleError } from \"../errors\";\nexport function initializationStarted(status) {\n if (status.isInitialized ||\n status.isGettingInitialized ||\n status.isDestroyed ||\n status.isGettingDestroyed) {\n return false;\n }\n status.isGettingInitialized = true;\n return true;\n}\nexport async function initializationCompleted(status, destroyMethod) {\n status.isInitialized = true;\n status.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (status.isGettingDestroyed) {\n await destroyMethod();\n }\n}\nexport function destructionStarted(status) {\n if (status.isDestroyed) {\n return false;\n }\n status.isGettingDestroyed = true;\n if (status.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return false;\n }\n if (!status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n throw new LifecycleError(\"Wraplet cannot be destroyed before it is initialized.\");\n }\n return true;\n}\nexport async function destructionCompleted(status, wraplet, destroyListeners) {\n status.isGettingDestroyed = false;\n status.isInitialized = false;\n status.isDestroyed = true;\n for (const listener of [...destroyListeners].reverse()) {\n await listener(wraplet);\n }\n destroyListeners.length = 0;\n}\n","import { destructionCompleted, destructionStarted, } from \"../Wraplet/statusActions\";\nexport function createOuterDestroyCallback(args, destroyLogic) {\n return async function () {\n const outerStatus = args.status;\n if (!destructionStarted(outerStatus)) {\n return;\n }\n if (destroyLogic) {\n await destroyLogic();\n }\n await destructionCompleted(outerStatus, args.wraplet, args.destroyListeners);\n };\n}\n","import { initializationCompleted, initializationStarted, } from \"../Wraplet/statusActions\";\nexport function createOuterInitializeCallback(args, initializeLogic) {\n return async function () {\n const outerStatus = args.status;\n if (!initializationStarted(outerStatus)) {\n return;\n }\n if (initializeLogic) {\n await initializeLogic();\n }\n await initializationCompleted(outerStatus, args.destroyCallback);\n };\n}\n","import { addWrapletToNode, removeWrapletFromNode, } from \"../NodeTreeManager/utils\";\nimport { WrapletApiSymbol, } from \"./types/WrapletApi\";\nimport { isWraplet } from \"./types/Wraplet\";\nimport { createOuterDestroyCallback } from \"./createOuterDestroyCallback\";\nimport { createOuterInitializeCallback } from \"./createOuterInitializeCallback\";\nfunction validateNodeWrapletApiFactoryArgs(args) {\n if (!isWraplet(args.wraplet)) {\n throw new Error(\"Correct wraplet instance has to be provided.\");\n }\n if (args.node && !(args.node instanceof Node)) {\n throw new Error(\"Correct node has to be provided.\");\n }\n if (args.initializeCallback &&\n typeof args.initializeCallback !== \"function\") {\n throw new Error(\"initializeCallback has to be a function.\");\n }\n if (args.destroyCallback && typeof args.destroyCallback !== \"function\") {\n throw new Error(\"destroyCallback has to be a function.\");\n }\n}\nexport const createWrapletApi = (args) => {\n validateNodeWrapletApiFactoryArgs(args);\n const newArgs = { ...args };\n const defaultStatus = {\n isGettingInitialized: false,\n isDestroyed: false,\n isInitialized: false,\n isGettingDestroyed: false,\n };\n const api = {};\n const destroyListeners = [];\n const destroyCallback = createOuterDestroyCallback({\n status: defaultStatus,\n wraplet: newArgs.wraplet,\n destroyListeners: destroyListeners,\n }, async () => {\n if (newArgs.destroyCallback) {\n await newArgs.destroyCallback();\n }\n if (newArgs.node) {\n removeWrapletFromNode(newArgs.wraplet, newArgs.node);\n }\n }).bind(api);\n const initializeCallback = createOuterInitializeCallback({\n status: defaultStatus,\n destroyCallback: destroyCallback,\n wraplet: newArgs.wraplet,\n }, async () => {\n if (newArgs.initializeCallback) {\n await newArgs.initializeCallback();\n }\n }).bind(api);\n // Note that it's added immediately without initialization required.\n if (newArgs.node) {\n addWrapletToNode(newArgs.wraplet, newArgs.node);\n }\n return Object.assign(api, {\n [WrapletApiSymbol]: true,\n __destroyListeners: destroyListeners,\n status: defaultStatus,\n addDestroyListener: (callback) => {\n destroyListeners.push(callback);\n },\n initialize: initializeCallback,\n destroy: destroyCallback,\n });\n};\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { UnsupportedNodeTypeError } from \"../errors\";\nimport { isOverridden } from \"./utils\";\nimport { NodeManager } from \"./NodeManager\";\nimport { createWrapletApi } from \"./createWrapletApi\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n wraplet;\n _nodeManager;\n constructor(node) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"AbstractWraplet requires a Node instance.\");\n }\n const supportedNodeTypes = this.supportedNodeTypes();\n if (supportedNodeTypes !== null) {\n if (!supportedNodeTypes.find((value) => node instanceof value)) {\n throw new UnsupportedNodeTypeError(`Node type ${node.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);\n }\n }\n this.wraplet = this.createWrapletApi();\n }\n /**\n * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet)\n * can override this to supply their own lifecycle callbacks without causing a\n * double-creation of WrapletApi.\n */\n createWrapletApi() {\n const initializeCallback = isOverridden(this, \"onInitialize\", AbstractWraplet)\n ? this.onInitialize.bind(this)\n : undefined;\n const destroyCallback = isOverridden(this, \"onDestroy\", AbstractWraplet)\n ? this.onDestroy.bind(this)\n : undefined;\n return this.buildWrapletApi(initializeCallback, destroyCallback);\n }\n /**\n * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup\n * is always wired into the destroy path.\n */\n buildWrapletApi(initializeCallback, destroyCallback) {\n return createWrapletApi({\n node: this.node,\n wraplet: this,\n initializeCallback,\n destroyCallback: async () => {\n if (destroyCallback) {\n await destroyCallback();\n }\n if (this._nodeManager) {\n this._nodeManager.destroy();\n }\n },\n });\n }\n get nodeManager() {\n if (!this._nodeManager) {\n this._nodeManager = new NodeManager(this.node);\n }\n return this._nodeManager;\n }\n /**\n * Subclasses must return an array of constructors covering all types in union N.\n * Wrap the result in the `supportedTypeCheck` helper to make sure that the array contains all\n * and only classes that extend the given type.\n */\n supportedNodeTypes() {\n return null;\n }\n /**\n * Helper for subclasses to easily satisfy the exhaustive check.\n */\n supportedNodeTypesGuard(types) {\n return types;\n }\n /**\n * This method gets invoked when the wraplet is initialized.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onInitialize() {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * This method gets invoked when the wraplet is destroyed.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDestroy() {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n */\n static createWraplets(node, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n */\n static async createAndInitializeWraplets(node, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createWraplets(node, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { isDependencyManager, } from \"../DependencyManager/types/DependencyManager\";\nimport { DDM } from \"../DependencyManager/DDM\";\nimport { isOverridden } from \"./utils\";\nimport { AbstractWraplet } from \"./AbstractWraplet\";\nexport class AbstractDependentWraplet extends AbstractWraplet {\n dm;\n constructor(dm) {\n if (!isDependencyManager(dm)) {\n throw new Error(\"AbstractDependentWraplet requires an instance implementing DependencyManager and NodeManager interfaces.\");\n }\n super(dm.node);\n this.dm = dm;\n if (isOverridden(this, \"onDependencyInitialized\", AbstractDependentWraplet)) {\n dm.addDependencyInitializedListener(this.onDependencyInitialized.bind(this));\n }\n if (isOverridden(this, \"onDependencyInstantiated\", AbstractDependentWraplet)) {\n dm.addDependencyInstantiatedListener(this.onDependencyInstantiated.bind(this));\n }\n if (isOverridden(this, \"onDependencyDestroyed\", AbstractDependentWraplet)) {\n dm.addDependencyDestroyedListener(this.onDependencyDestroyed.bind(this));\n }\n dm.instantiateDependencies();\n }\n /**\n * Override createWrapletApi to provide DependencyManager-aware lifecycle callbacks\n * instead of the base class's version — this avoids creating two WrapletApi\n * instances.\n */\n createWrapletApi() {\n return this.buildWrapletApi(async () => {\n await this.dm.initializeDependencies();\n await this.onInitialize.bind(this)();\n }, async () => {\n await this.onDestroy.bind(this)();\n await this.dm.destroyDependencies();\n });\n }\n async onDestroy() { }\n async onInitialize() { }\n /**\n * Dependencies.\n */\n get d() {\n return this.dm.dependencies;\n }\n /**\n * his method will be invoked if one of the wraplet's dependencies has been instantiated.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n onDependencyInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * his method will be invoked if one of the wraplet's dependencies has been initialized.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDependencyInitialized(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * This method will be ivoked if one of the wraplet's dependencies has been destroyed.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDependencyDestroyed(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n static createDependencyManager(node, map) {\n return new DDM(node, map);\n }\n static createWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n static createAndInitializeWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n */\n static createDependentWraplets(node, map, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractDependentWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const self = this;\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const dm = self.createDependencyManager(node, map);\n result.push(new this(dm, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n const dm = self.createDependencyManager(element, map);\n result.push(new this(dm, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n */\n static async createAndInitializeDependentWraplets(node, map, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createDependentWraplets(node, map, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport class DefaultNodeTreeManager {\n initializers = [];\n addNodeInitializer(callback) {\n this.initializers.push(callback);\n }\n async initializeNode(node, context) {\n const results = await Promise.allSettled(this.initializers.map((initializer) => initializer(node, context)));\n createLifecycleAsyncError(`There were errors during the node's initialization.`, results);\n }\n async destroyNode(node) {\n await destroyWrapletsRecursively(node);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredDependencyError","Error","MapError","RequiredDependencyDestroyedError","DependenciesAreNotAvailableError","StorageValidationError","TooManyChildrenFoundError","InternalLogicError","UnsupportedNodeTypeError","LifecycleError","LifecycleAsyncErrors","errors","is","object","symbol","WrapletSymbol","isWraplet","isSimpleObject","input","getPrototypeOf","isDependencyMapItem","item","keys","includes","isWrapletDependencyMap","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","createLifecycleAsyncError","message","throwError","error","result","status","reason","length","getWrapletsFromNode","node","wraplets","async","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","allWraplets","wraplet","isGettingDestroyed","isDestroyed","Promise","allSettled","map","destroy","DependencyManagerSymbol","ConsoleLogger","static","constructor","dumpError","console","dir","depth","getGlobalLogger","addDefaultsToDependencyDefinition","args","destructible","injector","MapTreeBuilderSymbol","MapTreeBuilder","parent","getParent","createChild","name","mapBuilder","setMap","newMap","id","def","fillMapWithDefaults","getMap","DDM","logger","dependenciesAreInstantiated","statusWritable","isInitialized","isGettingInitialized","mapTree","directDependencies","wrappedDependencies","destroyedDependencyListeners","instantiatedDependencyListeners","initializedDependencyListeners","options","Node","optionsWithDefaults","assign","defaultOptions","listener","dependencyInstantiatedListeners","dependencyInitializedListeners","dependencyDestroyedListeners","initializeDependencies","entries","dependency","initialize","listenerResults","destroyDependencies","instantiateDependencies","dependencies","querySelectorAll","dependencyDefinition","validateMapItemForNonParent","wrapDependencies","multiple","validateMapItem","currentDependencies","instantiatedDependencies","instantiateMultipleDependencies","add","instantiateSingleWrapletDependency","findExistingWraplet","childElement","undefined","existingDependency","childElementWraplets","existingDependencies","has","selector","childrenElements","findChildrenElements","validateElements","instantiateWrapletItem","existingWraplet","instance","Class","data","e","required","warn","prepareIndividualWraplet","childElements","items","addDependencyDestroyedListener","addDependencyInstantiatedListener","addDependencyInitializedListener","setExistingInstance","addExistingInstance","addDestroyListener","createDependencyDestroyListener","w","removeDependency","requiredError","validateRequiredDependencyAfterRemoval","destroyDeps","defaultSelectorCallback","delete","isRequired","size","elements","mapItem","Proxy","target","set","createInjector","map_or_position","currentMap","Number","isInteger","i","isOverridden","methodName","stopAt","proto","stopProto","NodeManager","listeners","addListener","eventName","addEventListener","event","removeEventListener","WrapletApiSymbol","initializationStarted","initializationCompleted","destroyMethod","destructionStarted","destructionCompleted","destroyListeners","reverse","createOuterDestroyCallback","destroyLogic","outerStatus","createOuterInitializeCallback","initializeLogic","destroyCallback","createWrapletApi","initializeCallback","validateNodeWrapletApiFactoryArgs","newArgs","defaultStatus","api","removeWrapletFromNode","bind","__destroyListeners","AbstractWraplet","_nodeManager","supportedNodeTypes","onInitialize","onDestroy","buildWrapletApi","nodeManager","supportedNodeTypesGuard","types","createWraplets","attribute","additional_args","Element","hasAttribute","foundElements","element","createAndInitializeWraplets","AbstractDependentWraplet","dm","super","onDependencyInitialized","onDependencyInstantiated","onDependencyDestroyed","d","createDependencyManager","createDependentWraplets","self","createAndInitializeDependentWraplets","DefaultWrapletSetReadonly","DefaultNodeTreeManager","initializers","addNodeInitializer","initializeNode","context","initializer","destroyNode"],"sourceRoot":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export type { DependencyManager } from "./DependencyManager/types/DependencyMana
|
|
|
2
2
|
export type { WrapletCreator } from "./DependencyManager/types/WrapletCreator";
|
|
3
3
|
export type { DependencyLifecycleAsyncListener } from "./DependencyManager/types/DependencyLifecycleAsyncListener";
|
|
4
4
|
export type { DependencyLifecycleListener } from "./DependencyManager/types/DependencyLifecycleListener";
|
|
5
|
-
export {
|
|
5
|
+
export { DDM } from "./DependencyManager/DDM";
|
|
6
6
|
export { AbstractWraplet } from "./Wraplet/AbstractWraplet";
|
|
7
7
|
export { AbstractDependentWraplet } from "./Wraplet/AbstractDependentWraplet";
|
|
8
8
|
export { destroyWrapletsRecursively, getWrapletsFromNode, } from "./NodeTreeManager/utils";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class e extends Error{}class t extends Error{}class n extends Error{}class i extends Error{}class s extends Error{}class r extends Error{}class a extends Error{}class o extends Error{}class d extends Error{}class c extends Error{errors=[]}const l=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],p=Symbol("Wraplet");function h(e){return l(e,p)}function u(e){return"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype}function y(e){for(const t of Object.keys(e))if(!["selector","Class","multiple","required","destructible","injector","map","args"].includes(t))return!1;return!!["string","function","undefined"].includes(typeof e.selector)&&"function"==typeof e.Class&&"boolean"==typeof e.required&&"boolean"==typeof e.multiple}function f(e){if(!u(e))return!1;for(const t in e){if(!u(e[t]))return!1;if(!y(e[t]))return!1}return!0}const w=Symbol("WrapletSet");function D(e){return l(e,w)}class m extends Set{find(e){const t=[];for(const n of this)e(n)&&t.push(n);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,n)=>e(t)-e(n))}}const b=Symbol("WrapletSetReadonly");class g extends m{[b]=!0;[w]=!0}function I(e,t,n=!0){const i=new c(e);for(const e of t)"rejected"===e.status&&i.errors.push(e.reason);if(0===i.errors.length)return null;if(n)throw i;return i}function z(e){const t=e.wraplets;return D(t)?t:null}async function E(e,t){t(e);const n=e.childNodes;for(const e of n)await E(e,t)}async function W(e){const t=[];await E(e,e=>{const n=z(e);if(n)for(const e of[...n])e.wraplet.status.isGettingDestroyed||e.wraplet.status.isDestroyed||t.push(e)}),I("Some wraplets threw exceptions during destruction",await Promise.allSettled(t.map(e=>e.wraplet.destroy())))}const v=Symbol("DependencyManager");class L{static#e=new L;constructor(){}dumpError(e){console.dir(e,{depth:null})}static getGlobalLogger(){return this.#e}}function M(e){return{args:[],destructible:!0,injector:{callback:e=>e},...e}}const A=Symbol("MapTreeBuilder");class C{parent;[A]=!0;map;children={};constructor(e){this.parent=e}getParent(){if(!this.parent)throw new Error("Parent not found.");return this.parent}createChild(e){const t=new C(this);return this.children[e]=t,t}setMap(e){this.map=function(e){const t={};for(const n of Object.keys(e)){const i=e[n];t[n]=M(i)}return t}(e)}getMap(){if(!this.map)throw new Error("Map is not set.");return this.map}}class S{node;[v]=!0;logger;dependenciesAreInstantiated=!1;statusWritable={isDestroyed:!1,isGettingDestroyed:!1,isInitialized:!1,isGettingInitialized:!1};get status(){return this.statusWritable}mapTree;directDependencies={};wrappedDependencies={};destroyedDependencyListeners=[];instantiatedDependencyListeners=[];initializedDependencyListeners=[];constructor(e,n,i={}){if(this.node=e,!(e instanceof Node))throw new Error("The node provided to the Core is not a valid node.");if(f(n))this.mapTree=new C,this.mapTree.setMap(n);else{if("object"!=typeof(s=n)||null===s||!(A in s))throw new t("The map provided to the Core is not a valid map.");this.mapTree=n}var s;const r=Object.assign(this.defaultOptions(),i);this.logger=r.logger;for(const e of r.dependencyInstantiatedListeners)this.instantiatedDependencyListeners.push(e);for(const e of r.dependencyInitializedListeners)this.initializedDependencyListeners.push(e);for(const e of r.dependencyDestroyedListeners)this.destroyedDependencyListeners.push(e)}async initializeDependencies(){if(this.status.isInitialized)throw new d("Dependencies are already initialized.");this.statusWritable.isGettingInitialized=!0;const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t)return;const n=D(t)?Array.from(t):[t],i=await Promise.allSettled(n.map(async t=>{if(t.wraplet.status.isInitialized||t.wraplet.status.isGettingInitialized)return;await t.wraplet.initialize();const n=await Promise.allSettled(this.initializedDependencyListeners.map(n=>n(t,e)));I(`Errors in the core's dependency "${e}" initialize listeners.`,n)}));I(`Error at "${e}" dependency's initialization.`,i)})),t=I("Error at Core's initialization.",e,!1);if(t)throw this.logger.dumpError(t),t;this.statusWritable.isInitialized=!0,this.statusWritable.isGettingInitialized=!1,this.statusWritable.isGettingDestroyed&&await this.destroyDependencies()}get map(){return this.mapTree.getMap()}instantiateDependencies(){if(this.dependenciesAreInstantiated)throw new d("Dependencies are already instantiated.");const e=this.directDependencies;if("function"!=typeof this.node.querySelectorAll){for(const e in this.map){const t=this.map[e];this.validateMapItemForNonParent(e,t)}return this.wrappedDependencies=this.wrapDependencies(this.directDependencies),void(this.dependenciesAreInstantiated=!0)}for(const t in this.map){const n=this.map[t],i=n.multiple;if(this.validateMapItem(t,n),i){e[t]||(e[t]=new g);const i=e[t],s=this.instantiateMultipleDependencies(n,this.node,t);for(const e of s)i.add(e);continue}e[t]=this.instantiateSingleWrapletDependency(n,this.node,t)}this.wrappedDependencies=this.wrapDependencies(this.directDependencies),this.dependenciesAreInstantiated=!0}findExistingWraplet(e,t){if(void 0===this.directDependencies||!this.directDependencies[e])return null;const n=this.directDependencies[e];if(this.map[e].multiple){if(!D(n))throw new a("Internal logic error. Expected a WrapletSet.");const e=t.wraplets;if(!e)return null;const i=n.find(t=>e.has(t));if(i.length>1)throw new a("Internal logic error. Multiple instances wrapping the same element found in the core.");return i[0]}if(!h(n))throw new a("Internal logic error. Expected a Wraplet.");return t.wraplets&&t.wraplets.has(n)?n:null}instantiateSingleWrapletDependency(e,n,i){if(!e.selector)return this.directDependencies[i]||null;if(!this.dependenciesAreInstantiated&&this.directDependencies[i])throw new t("It's not possible to provide a single-type dependency manually and use selector at the same time.");const s=e.selector,a=this.findChildrenElements(s,n);if(this.validateElements(i,a,e),0===a.length)return null;if(a.length>1)throw new r(`${this.constructor.name}: More than one element was found for the "${i}" dependency. Selector used: "${s}".`);const o=a[0];return this.instantiateWrapletItem(i,e,o)}instantiateWrapletItem(e,t,n){const i=this.findExistingWraplet(e,n);if(i)return i;let s=null;try{const i=new t.Class(t.injector.callback(n,this.mapTree.createChild(e),t.injector.data),...t.args);if(!h(i))throw new Error("Created dependency is not a Wraplet instance.");s=i}catch(n){if(n instanceof o&&!t.required)return console.warn(`${n.message} Skipping instantiation of the "${e}" dependency.`),null;throw n}this.prepareIndividualWraplet(e,s);for(const t of this.instantiatedDependencyListeners)t(s,e);return s}instantiateMultipleDependencies(e,t,n){const i=e.selector;if(!i)return new g;const s=this.findChildrenElements(i,t);this.validateElements(n,s,e);const r=new g;for(const t of s){let i=this.findExistingWraplet(n,t);i||(i=this.instantiateWrapletItem(n,e,t)),i&&r.add(i)}return r}addDependencyDestroyedListener(e){this.destroyedDependencyListeners.push(e)}addDependencyInstantiatedListener(e){this.instantiatedDependencyListeners.push(e)}addDependencyInitializedListener(e){this.initializedDependencyListeners.push(e)}setExistingInstance(e,n){if(this.map[e].multiple)throw new t("This method can only be used to set a single-value dependency.");if(this.directDependencies[e])throw new t("Dependency is already set.");if(!h(n))throw new t("Provided instance is not a valid dependency.");this.prepareIndividualWraplet(e,n),this.directDependencies[e]=n}addExistingInstance(e,n){if(!this.map[e].multiple)throw new t("This method can only be used to set a multi-value dependency.");this.prepareIndividualWraplet(e,n);const i=this.directDependencies&&this.directDependencies[e]?this.directDependencies[e]:new g;i.add(n),this.directDependencies[e]=i}prepareIndividualWraplet(e,t){t.wraplet.addDestroyListener(this.createDependencyDestroyListener(e))}createDependencyDestroyListener(e){return async t=>{this.removeDependency(t,e);const n=await Promise.allSettled(this.destroyedDependencyListeners.map(n=>n(t,e))),i=this.validateRequiredDependencyAfterRemoval(e);i&&n.push({status:"rejected",reason:i}),I(`Errors in the destruction callbacks of the "${e} dependency."`,n)}}validateRequiredDependencyAfterRemoval(e){return this.map[e].required&&!this.status.isGettingDestroyed?new n(`Required dependency "${e}" has been destroyed.`):null}async destroyDependencies(){if(this.statusWritable.isDestroyed)throw new d("Dependencies are already destroyed.");if(this.statusWritable.isGettingDestroyed=!0,!this.statusWritable.isGettingInitialized){if(!this.statusWritable.isInitialized)return this.statusWritable.isDestroyed=!0,void(this.statusWritable.isGettingDestroyed=!1);await this.destroyDeps(),this.statusWritable.isInitialized=!1,this.statusWritable.isDestroyed=!0,this.statusWritable.isGettingDestroyed=!1}}findChildrenElements(e,t){return"string"==typeof e?((e,t)=>Array.from(t.querySelectorAll(e)))(e,t):e(t)}get dependencies(){if(!this.dependenciesAreInstantiated)throw new i("Wraplet is not yet fully initialized.");return this.wrappedDependencies}removeDependency(e,t){D(this.directDependencies[t])?this.directDependencies[t].delete(e):this.directDependencies[t]===e&&(this.directDependencies[t]=null)}validateMapItem(e,n){const i=n.selector,s=n.required;if(!i&&s&&(!this.directDependencies[e]||D(this.directDependencies[e])&&0===this.directDependencies[e].size))throw new t(`${this.constructor.name}: Dependency "${e}" cannot at the same be required, have no selector, and be not provided otherwise.`)}validateMapItemForNonParent(e,n){if(n.required)throw new t(`Dependency "${e}" error: If the node provided cannot have children, there should be no required dependencies.`)}validateElements(t,n,i){if(0===n.length&&i.required)throw new e(`${this.constructor.name}: Couldn't find a node for the wraplet "${t}". Selector used: "${i.selector}".`)}wrapDependencies(e){return new Proxy(e,{get:(e,t)=>{if("symbol"==typeof t)throw new Error("Symbol access is not supported for dependencies.");if(!(t in e))throw new Error(`Dependency '${t}' has not been found.`);return e[t]},set:()=>{throw new Error("Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.")}})}defaultOptions(){return{dependencyInstantiatedListeners:[],dependencyInitializedListeners:[],dependencyDestroyedListeners:[],logger:L.getGlobalLogger()}}async destroyDeps(){const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t||!this.map[e].destructible)return;const n=[];if(D(t))for(const e of t)n.push(e);else n.push(t);I(`Errors during destruction of the "${e}" dependency.`,await Promise.allSettled(n.map(async e=>{if(!e.wraplet.status.isDestroyed&&!e.wraplet.status.isGettingDestroyed)return e.wraplet.destroy()})))})),t=I("Errors during the dependencies destruction.",e,!1);if(t)throw this.logger.dumpError(t),t}static createInjector(e,t){return{data:t||{},callback:(t,n,i)=>{let s=n;if(r=e,Number.isInteger(r))for(let t=0;t<e;t++)s=s.getParent();else{if(!f(e))throw new Error("Invalid map argument.");s.setMap(e)}var r;return new S(t,s,i)}}}}const x=(e,t,n)=>{let i=Object.getPrototypeOf(e);const s=n?n.prototype:Object.getPrototypeOf(i);for(;i&&i!==s;){if(Object.prototype.hasOwnProperty.call(i,t))return!0;i=Object.getPrototypeOf(i)}return!1};class G{node;listeners=[];constructor(e){this.node=e}addListener(e,t,n){this.node.addEventListener(e,t,n),this.listeners.push({callback:t,event:e,options:n})}destroy(){for(const e of this.listeners)this.node.removeEventListener(e.event,e.callback,e.options);this.listeners.length=0}}const k=Symbol("WrapletApi");function j(e){return!(e.isInitialized||e.isGettingInitialized||e.isDestroyed||e.isGettingDestroyed||(e.isGettingInitialized=!0,0))}async function O(e,t){e.isInitialized=!0,e.isGettingInitialized=!1,e.isGettingDestroyed&&await t()}function $(e){if(e.isDestroyed)return!1;if(e.isGettingDestroyed=!0,e.isGettingInitialized)return!1;if(!e.isInitialized)throw new d("Wraplet cannot be destroyed before it is initialized.");return!0}async function P(e,t,n){e.isGettingDestroyed=!1,e.isInitialized=!1,e.isDestroyed=!0;for(const e of[...n].reverse())await e(t);n.length=0}function q(e,t){return async function(){const n=e.status;$(n)&&(t&&await t(),await P(n,e.wraplet,e.destroyListeners))}}function T(e,t){return async function(){const n=e.status;j(n)&&(t&&await t(),await O(n,e.destroyCallback))}}const N=e=>{!function(e){if(!h(e.wraplet))throw new Error("Correct wraplet instance has to be provided.");if(e.node&&!(e.node instanceof Node))throw new Error("Correct node has to be provided.");if(e.initializeCallback&&"function"!=typeof e.initializeCallback)throw new Error("initializeCallback has to be a function.");if(e.destroyCallback&&"function"!=typeof e.destroyCallback)throw new Error("destroyCallback has to be a function.")}(e);const t={...e},n={isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},i={},s=[],r=q({status:n,wraplet:t.wraplet,destroyListeners:s},async()=>{t.destroyCallback&&await t.destroyCallback(),t.node&&function(e,t){const n=z(t);n&&n.delete(e)}(t.wraplet,t.node)}).bind(i),a=T({status:n,destroyCallback:r,wraplet:t.wraplet},async()=>{var e,n;t.node&&(e=t.wraplet,(n=t.node).wraplets||(n.wraplets=new g),n.wraplets.add(e)),t.initializeCallback&&await t.initializeCallback()}).bind(i);return Object.assign(i,{[k]:!0,__destroyListeners:s,status:n,addDestroyListener:e=>{s.push(e)},initialize:a,destroy:r})};class _{node;[p]=!0;wraplet;_nodeManager;constructor(e){if(this.node=e,!(e instanceof Node))throw new Error("AbstractWraplet requires a Node instance.");const t=this.supportedNodeTypes();if(null!==t&&!t.find(t=>e instanceof t))throw new o(`Node type ${e.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);this.wraplet=this.createWrapletApi()}createWrapletApi(){const e=x(this,"onInitialize",_)?this.onInitialize.bind(this):void 0,t=x(this,"onDestroy",_)?this.onDestroy.bind(this):void 0;return this.buildWrapletApi(e,t)}buildWrapletApi(e,t){return N({node:this.node,wraplet:this,initializeCallback:e,destroyCallback:async()=>{t&&await t(),this._nodeManager&&this._nodeManager.destroy()}})}get nodeManager(){return this._nodeManager||(this._nodeManager=new G(this.node)),this._nodeManager}supportedNodeTypes(){return null}supportedNodeTypesGuard(e){return e}async onInitialize(){throw new Error("Method has to be implemented by subclass.")}async onDestroy(){throw new Error("Method has to be implemented by subclass.")}static createWraplets(e,t,n=[]){if(this===_)throw new Error("You cannot instantiate an abstract class.");const i=[];e instanceof Element&&e.hasAttribute(t)&&i.push(new this(e,...n));const s=e.querySelectorAll(`[${t}]`);for(const e of s)i.push(new this(e,...n));return i}static async createAndInitializeWraplets(e,t,n=[]){const i=this.createWraplets(e,t,n);for(const e of i)await e.wraplet.initialize();return i}}class R extends _{dm;constructor(e){if(!l(e,v))throw new Error("AbstractDependentWraplet requires an instance implementing DependencyManager and NodeManager interfaces.");super(e.node),this.dm=e,x(this,"onDependencyInitialized",R)&&e.addDependencyInitializedListener(this.onDependencyInitialized.bind(this)),x(this,"onDependencyInstantiated",R)&&e.addDependencyInstantiatedListener(this.onDependencyInstantiated.bind(this)),x(this,"onDependencyDestroyed",R)&&e.addDependencyDestroyedListener(this.onDependencyDestroyed.bind(this)),e.instantiateDependencies()}createWrapletApi(){return this.buildWrapletApi(this.onInitialize.bind(this),this.onDestroy.bind(this))}async onDestroy(){await this.dm.destroyDependencies()}async onInitialize(){await this.dm.initializeDependencies()}get d(){return this.dm.dependencies}onDependencyInstantiated(e,t){throw new Error("Method has to be implemented by subclass.")}async onDependencyInitialized(e,t){throw new Error("Method has to be implemented by subclass.")}async onDependencyDestroyed(e,t){throw new Error("Method has to be implemented by subclass.")}static createDependencyManager(e,t){return new S(e,t)}static createWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createAndInitializeWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createDependentWraplets(e,t,n,i=[]){if(this===R)throw new Error("You cannot instantiate an abstract class.");const s=this,r=[];if(e instanceof Element&&e.hasAttribute(n)){const n=s.createDependencyManager(e,t);r.push(new this(n,...i))}const a=e.querySelectorAll(`[${n}]`);for(const e of a){const n=s.createDependencyManager(e,t);r.push(new this(n,...i))}return r}static async createAndInitializeDependentWraplets(e,t,n,i=[]){const s=this.createDependentWraplets(e,t,n,i);for(const e of s)await e.wraplet.initialize();return s}}class F extends m{[b]=!0}class Y{initializers=[];addNodeInitializer(e){this.initializers.push(e)}async initializeNode(e,t){I("There were errors during the node's initialization.",await Promise.allSettled(this.initializers.map(n=>n(e,t))))}async destroyNode(e){await W(e)}}export{R as AbstractDependentWraplet,_ as AbstractWraplet,S as Core,Y as DefaultNodeTreeManager,g as DefaultWrapletSet,F as DefaultWrapletSetReadonly,i as DependenciesAreNotAvailableError,a as InternalLogicError,c as LifecycleAsyncErrors,d as LifecycleError,t as MapError,e as MissingRequiredDependencyError,n as RequiredDependencyDestroyedError,s as StorageValidationError,r as TooManyChildrenFoundError,o as UnsupportedNodeTypeError,p as WrapletSymbol,q as createOuterDestroyCallback,T as createOuterInitializeCallback,N as createWrapletApi,W as destroyWrapletsRecursively,P as destructionCompleted,$ as destructionStarted,z as getWrapletsFromNode,O as initializationCompleted,j as initializationStarted,h as isWraplet};
|
|
1
|
+
class e extends Error{}class t extends Error{}class n extends Error{}class i extends Error{}class s extends Error{}class r extends Error{}class a extends Error{}class o extends Error{}class d extends Error{}class c extends Error{errors=[]}const l=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],p=Symbol("Wraplet");function h(e){return l(e,p)}function u(e){return"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype}function y(e){for(const t of Object.keys(e))if(!["selector","Class","multiple","required","destructible","injector","map","args"].includes(t))return!1;return!!["string","function","undefined"].includes(typeof e.selector)&&"function"==typeof e.Class&&"boolean"==typeof e.required&&"boolean"==typeof e.multiple}function f(e){if(!u(e))return!1;for(const t in e){if(!u(e[t]))return!1;if(!y(e[t]))return!1}return!0}const w=Symbol("WrapletSet");function D(e){return l(e,w)}class m extends Set{find(e){const t=[];for(const n of this)e(n)&&t.push(n);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,n)=>e(t)-e(n))}}const b=Symbol("WrapletSetReadonly");class g extends m{[b]=!0;[w]=!0}function I(e,t,n=!0){const i=new c(e);for(const e of t)"rejected"===e.status&&i.errors.push(e.reason);if(0===i.errors.length)return null;if(n)throw i;return i}function z(e){const t=e.wraplets;return D(t)?t:null}async function E(e,t){t(e);const n=e.childNodes;for(const e of n)await E(e,t)}async function W(e){const t=[];await E(e,e=>{const n=z(e);if(n)for(const e of[...n])e.wraplet.status.isGettingDestroyed||e.wraplet.status.isDestroyed||t.push(e)}),I("Some wraplets threw exceptions during destruction",await Promise.allSettled(t.map(e=>e.wraplet.destroy())))}const v=Symbol("DependencyManager");class M{static#e=new M;constructor(){}dumpError(e){console.dir(e,{depth:null})}static getGlobalLogger(){return this.#e}}function L(e){return{args:[],destructible:!0,injector:{callback:e=>e},...e}}const A=Symbol("MapTreeBuilder");class S{parent;[A]=!0;map;children={};constructor(e){this.parent=e}getParent(){if(!this.parent)throw new Error("Parent not found.");return this.parent}createChild(e){const t=new S(this);return this.children[e]=t,t}setMap(e){this.map=function(e){const t={};for(const n of Object.keys(e)){const i=e[n];t[n]=L(i)}return t}(e)}getMap(){if(!this.map)throw new Error("Map is not set.");return this.map}}class x{node;[v]=!0;logger;dependenciesAreInstantiated=!1;statusWritable={isDestroyed:!1,isGettingDestroyed:!1,isInitialized:!1,isGettingInitialized:!1};get status(){return this.statusWritable}mapTree;directDependencies={};wrappedDependencies={};destroyedDependencyListeners=[];instantiatedDependencyListeners=[];initializedDependencyListeners=[];constructor(e,n,i={}){if(this.node=e,!(e instanceof Node))throw new Error("The node provided to the DDM is not a valid node.");if(f(n))this.mapTree=new S,this.mapTree.setMap(n);else{if("object"!=typeof(s=n)||null===s||!(A in s))throw new t("The map provided to the DDM is not a valid map.");this.mapTree=n}var s;const r=Object.assign(this.defaultOptions(),i);this.logger=r.logger;for(const e of r.dependencyInstantiatedListeners)this.instantiatedDependencyListeners.push(e);for(const e of r.dependencyInitializedListeners)this.initializedDependencyListeners.push(e);for(const e of r.dependencyDestroyedListeners)this.destroyedDependencyListeners.push(e)}async initializeDependencies(){if(this.status.isInitialized)throw new d("Dependencies are already initialized.");this.statusWritable.isGettingInitialized=!0;const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t)return;const n=D(t)?Array.from(t):[t],i=await Promise.allSettled(n.map(async t=>{if(t.wraplet.status.isInitialized||t.wraplet.status.isGettingInitialized)return;await t.wraplet.initialize();const n=await Promise.allSettled(this.initializedDependencyListeners.map(n=>n(t,e)));I(`Errors in the DDM's dependency "${e}" initialize listeners.`,n)}));I(`Error at "${e}" dependency's initialization.`,i)})),t=I("Error at DDM's initialization.",e,!1);if(t)throw this.logger.dumpError(t),t;this.statusWritable.isInitialized=!0,this.statusWritable.isGettingInitialized=!1,this.statusWritable.isGettingDestroyed&&await this.destroyDependencies()}get map(){return this.mapTree.getMap()}instantiateDependencies(){if(this.dependenciesAreInstantiated)throw new d("Dependencies are already instantiated.");const e=this.directDependencies;if("function"!=typeof this.node.querySelectorAll){for(const e in this.map){const t=this.map[e];this.validateMapItemForNonParent(e,t)}return this.wrappedDependencies=this.wrapDependencies(this.directDependencies),void(this.dependenciesAreInstantiated=!0)}for(const t in this.map){const n=this.map[t],i=n.multiple;if(this.validateMapItem(t,n),i){e[t]||(e[t]=new g);const i=e[t],s=this.instantiateMultipleDependencies(n,this.node,t);for(const e of s)i.add(e);continue}e[t]=this.instantiateSingleWrapletDependency(n,this.node,t)}this.wrappedDependencies=this.wrapDependencies(this.directDependencies),this.dependenciesAreInstantiated=!0}findExistingWraplet(e,t){if(void 0===this.directDependencies||!this.directDependencies[e])return null;const n=this.directDependencies[e];if(this.map[e].multiple){if(!D(n))throw new a("Internal logic error. Expected a WrapletSet.");const e=t.wraplets;if(!e)return null;const i=n.find(t=>e.has(t));if(i.length>1)throw new a("Internal logic error. Multiple instances wrapping the same element found in the DDM.");return i[0]}if(!h(n))throw new a("Internal logic error. Expected a Wraplet.");return t.wraplets&&t.wraplets.has(n)?n:null}instantiateSingleWrapletDependency(e,n,i){if(!e.selector)return this.directDependencies[i]||null;if(!this.dependenciesAreInstantiated&&this.directDependencies[i])throw new t("It's not possible to provide a single-type dependency manually and use selector at the same time.");const s=e.selector,a=this.findChildrenElements(s,n);if(this.validateElements(i,a,e),0===a.length)return null;if(a.length>1)throw new r(`${this.constructor.name}: More than one element was found for the "${i}" dependency. Selector used: "${s}".`);const o=a[0];return this.instantiateWrapletItem(i,e,o)}instantiateWrapletItem(e,t,n){const i=this.findExistingWraplet(e,n);if(i)return i;let s=null;try{const i=new t.Class(t.injector.callback(n,this.mapTree.createChild(e),t.injector.data),...t.args);if(!h(i))throw new Error("Created dependency is not a Wraplet instance.");s=i}catch(n){if(n instanceof o&&!t.required)return console.warn(`${n.message} Skipping instantiation of the "${e}" dependency.`),null;throw n}this.prepareIndividualWraplet(e,s);for(const t of this.instantiatedDependencyListeners)t(s,e);return s}instantiateMultipleDependencies(e,t,n){const i=e.selector;if(!i)return new g;const s=this.findChildrenElements(i,t);this.validateElements(n,s,e);const r=new g;for(const t of s){let i=this.findExistingWraplet(n,t);i||(i=this.instantiateWrapletItem(n,e,t)),i&&r.add(i)}return r}addDependencyDestroyedListener(e){this.destroyedDependencyListeners.push(e)}addDependencyInstantiatedListener(e){this.instantiatedDependencyListeners.push(e)}addDependencyInitializedListener(e){this.initializedDependencyListeners.push(e)}setExistingInstance(e,n){if(this.map[e].multiple)throw new t("This method can only be used to set a single-value dependency.");if(this.directDependencies[e])throw new t("Dependency is already set.");if(!h(n))throw new t("Provided instance is not a valid dependency.");this.prepareIndividualWraplet(e,n),this.directDependencies[e]=n}addExistingInstance(e,n){if(!this.map[e].multiple)throw new t("This method can only be used to set a multi-value dependency.");this.prepareIndividualWraplet(e,n);const i=this.directDependencies&&this.directDependencies[e]?this.directDependencies[e]:new g;i.add(n),this.directDependencies[e]=i}prepareIndividualWraplet(e,t){t.wraplet.addDestroyListener(this.createDependencyDestroyListener(e))}createDependencyDestroyListener(e){return async t=>{this.removeDependency(t,e);const n=await Promise.allSettled(this.destroyedDependencyListeners.map(n=>n(t,e))),i=this.validateRequiredDependencyAfterRemoval(e);i&&n.push({status:"rejected",reason:i}),I(`Errors in the destruction callbacks of the "${e} dependency."`,n)}}validateRequiredDependencyAfterRemoval(e){return this.map[e].required&&!this.status.isGettingDestroyed?new n(`Required dependency "${e}" has been destroyed.`):null}async destroyDependencies(){if(this.statusWritable.isDestroyed)throw new d("Dependencies are already destroyed.");if(this.statusWritable.isGettingDestroyed=!0,!this.statusWritable.isGettingInitialized){if(!this.statusWritable.isInitialized)return this.statusWritable.isDestroyed=!0,void(this.statusWritable.isGettingDestroyed=!1);await this.destroyDeps(),this.statusWritable.isInitialized=!1,this.statusWritable.isDestroyed=!0,this.statusWritable.isGettingDestroyed=!1}}findChildrenElements(e,t){return"string"==typeof e?((e,t)=>Array.from(t.querySelectorAll(e)))(e,t):e(t)}get dependencies(){if(!this.dependenciesAreInstantiated)throw new i("Wraplet is not yet fully initialized.");return this.wrappedDependencies}removeDependency(e,t){D(this.directDependencies[t])?this.directDependencies[t].delete(e):this.directDependencies[t]===e&&(this.directDependencies[t]=null)}validateMapItem(e,n){const i=n.selector,s=n.required;if(!i&&s&&(!this.directDependencies[e]||D(this.directDependencies[e])&&0===this.directDependencies[e].size))throw new t(`${this.constructor.name}: Dependency "${e}" cannot at the same be required, have no selector, and be not provided otherwise.`)}validateMapItemForNonParent(e,n){if(n.required)throw new t(`Dependency "${e}" error: If the node provided cannot have children, there should be no required dependencies.`)}validateElements(t,n,i){if(0===n.length&&i.required)throw new e(`${this.constructor.name}: Couldn't find a node for the wraplet "${t}". Selector used: "${i.selector}".`)}wrapDependencies(e){return new Proxy(e,{get:(e,t)=>{if("symbol"==typeof t)throw new Error("Symbol access is not supported for dependencies.");if(!(t in e))throw new Error(`Dependency '${t}' has not been found.`);return e[t]},set:()=>{throw new Error("Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.")}})}defaultOptions(){return{dependencyInstantiatedListeners:[],dependencyInitializedListeners:[],dependencyDestroyedListeners:[],logger:M.getGlobalLogger()}}async destroyDeps(){const e=await Promise.allSettled(Object.entries(this.directDependencies).map(async([e,t])=>{if(!t||!this.map[e].destructible)return;const n=[];if(D(t))for(const e of t)n.push(e);else n.push(t);I(`Errors during destruction of the "${e}" dependency.`,await Promise.allSettled(n.map(async e=>{if(!e.wraplet.status.isDestroyed&&!e.wraplet.status.isGettingDestroyed)return e.wraplet.destroy()})))})),t=I("Errors during the dependencies destruction.",e,!1);if(t)throw this.logger.dumpError(t),t}static createInjector(e,t){return{data:t||{},callback:(t,n,i)=>{let s=n;if(r=e,Number.isInteger(r))for(let t=0;t<e;t++)s=s.getParent();else{if(!f(e))throw new Error("Invalid map argument.");s.setMap(e)}var r;return new x(t,s,i)}}}}const C=(e,t,n)=>{let i=Object.getPrototypeOf(e);const s=n?n.prototype:Object.getPrototypeOf(i);for(;i&&i!==s;){if(Object.prototype.hasOwnProperty.call(i,t))return!0;i=Object.getPrototypeOf(i)}return!1};class G{node;listeners=[];constructor(e){this.node=e}addListener(e,t,n){this.node.addEventListener(e,t,n),this.listeners.push({callback:t,event:e,options:n})}destroy(){for(const e of this.listeners)this.node.removeEventListener(e.event,e.callback,e.options);this.listeners.length=0}}const k=Symbol("WrapletApi");function j(e){return!(e.isInitialized||e.isGettingInitialized||e.isDestroyed||e.isGettingDestroyed||(e.isGettingInitialized=!0,0))}async function O(e,t){e.isInitialized=!0,e.isGettingInitialized=!1,e.isGettingDestroyed&&await t()}function $(e){if(e.isDestroyed)return!1;if(e.isGettingDestroyed=!0,e.isGettingInitialized)return!1;if(!e.isInitialized)throw new d("Wraplet cannot be destroyed before it is initialized.");return!0}async function P(e,t,n){e.isGettingDestroyed=!1,e.isInitialized=!1,e.isDestroyed=!0;for(const e of[...n].reverse())await e(t);n.length=0}function q(e,t){return async function(){const n=e.status;$(n)&&(t&&await t(),await P(n,e.wraplet,e.destroyListeners))}}function T(e,t){return async function(){const n=e.status;j(n)&&(t&&await t(),await O(n,e.destroyCallback))}}const N=e=>{!function(e){if(!h(e.wraplet))throw new Error("Correct wraplet instance has to be provided.");if(e.node&&!(e.node instanceof Node))throw new Error("Correct node has to be provided.");if(e.initializeCallback&&"function"!=typeof e.initializeCallback)throw new Error("initializeCallback has to be a function.");if(e.destroyCallback&&"function"!=typeof e.destroyCallback)throw new Error("destroyCallback has to be a function.")}(e);const t={...e},n={isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},i={},s=[],r=q({status:n,wraplet:t.wraplet,destroyListeners:s},async()=>{t.destroyCallback&&await t.destroyCallback(),t.node&&function(e,t){const n=z(t);n&&n.delete(e)}(t.wraplet,t.node)}).bind(i),a=T({status:n,destroyCallback:r,wraplet:t.wraplet},async()=>{t.initializeCallback&&await t.initializeCallback()}).bind(i);var o,d;return t.node&&(o=t.wraplet,(d=t.node).wraplets||(d.wraplets=new g),d.wraplets.add(o)),Object.assign(i,{[k]:!0,__destroyListeners:s,status:n,addDestroyListener:e=>{s.push(e)},initialize:a,destroy:r})};class _{node;[p]=!0;wraplet;_nodeManager;constructor(e){if(this.node=e,!(e instanceof Node))throw new Error("AbstractWraplet requires a Node instance.");const t=this.supportedNodeTypes();if(null!==t&&!t.find(t=>e instanceof t))throw new o(`Node type ${e.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);this.wraplet=this.createWrapletApi()}createWrapletApi(){const e=C(this,"onInitialize",_)?this.onInitialize.bind(this):void 0,t=C(this,"onDestroy",_)?this.onDestroy.bind(this):void 0;return this.buildWrapletApi(e,t)}buildWrapletApi(e,t){return N({node:this.node,wraplet:this,initializeCallback:e,destroyCallback:async()=>{t&&await t(),this._nodeManager&&this._nodeManager.destroy()}})}get nodeManager(){return this._nodeManager||(this._nodeManager=new G(this.node)),this._nodeManager}supportedNodeTypes(){return null}supportedNodeTypesGuard(e){return e}async onInitialize(){throw new Error("Method has to be implemented by subclass.")}async onDestroy(){throw new Error("Method has to be implemented by subclass.")}static createWraplets(e,t,n=[]){if(this===_)throw new Error("You cannot instantiate an abstract class.");const i=[];e instanceof Element&&e.hasAttribute(t)&&i.push(new this(e,...n));const s=e.querySelectorAll(`[${t}]`);for(const e of s)i.push(new this(e,...n));return i}static async createAndInitializeWraplets(e,t,n=[]){const i=this.createWraplets(e,t,n);for(const e of i)await e.wraplet.initialize();return i}}class R extends _{dm;constructor(e){if(!l(e,v))throw new Error("AbstractDependentWraplet requires an instance implementing DependencyManager and NodeManager interfaces.");super(e.node),this.dm=e,C(this,"onDependencyInitialized",R)&&e.addDependencyInitializedListener(this.onDependencyInitialized.bind(this)),C(this,"onDependencyInstantiated",R)&&e.addDependencyInstantiatedListener(this.onDependencyInstantiated.bind(this)),C(this,"onDependencyDestroyed",R)&&e.addDependencyDestroyedListener(this.onDependencyDestroyed.bind(this)),e.instantiateDependencies()}createWrapletApi(){return this.buildWrapletApi(async()=>{await this.dm.initializeDependencies(),await this.onInitialize.bind(this)()},async()=>{await this.onDestroy.bind(this)(),await this.dm.destroyDependencies()})}async onDestroy(){}async onInitialize(){}get d(){return this.dm.dependencies}onDependencyInstantiated(e,t){throw new Error("Method has to be implemented by subclass.")}async onDependencyInitialized(e,t){throw new Error("Method has to be implemented by subclass.")}async onDependencyDestroyed(e,t){throw new Error("Method has to be implemented by subclass.")}static createDependencyManager(e,t){return new x(e,t)}static createWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createAndInitializeWraplets(){throw new Error("This method is not supported for AbstractDependentWraplet.")}static createDependentWraplets(e,t,n,i=[]){if(this===R)throw new Error("You cannot instantiate an abstract class.");const s=this,r=[];if(e instanceof Element&&e.hasAttribute(n)){const n=s.createDependencyManager(e,t);r.push(new this(n,...i))}const a=e.querySelectorAll(`[${n}]`);for(const e of a){const n=s.createDependencyManager(e,t);r.push(new this(n,...i))}return r}static async createAndInitializeDependentWraplets(e,t,n,i=[]){const s=this.createDependentWraplets(e,t,n,i);for(const e of s)await e.wraplet.initialize();return s}}class F extends m{[b]=!0}class Y{initializers=[];addNodeInitializer(e){this.initializers.push(e)}async initializeNode(e,t){I("There were errors during the node's initialization.",await Promise.allSettled(this.initializers.map(n=>n(e,t))))}async destroyNode(e){await W(e)}}export{R as AbstractDependentWraplet,_ as AbstractWraplet,x as DDM,Y as DefaultNodeTreeManager,g as DefaultWrapletSet,F as DefaultWrapletSetReadonly,i as DependenciesAreNotAvailableError,a as InternalLogicError,c as LifecycleAsyncErrors,d as LifecycleError,t as MapError,e as MissingRequiredDependencyError,n as RequiredDependencyDestroyedError,s as StorageValidationError,r as TooManyChildrenFoundError,o as UnsupportedNodeTypeError,p as WrapletSymbol,q as createOuterDestroyCallback,T as createOuterInitializeCallback,N as createWrapletApi,W as destroyWrapletsRecursively,P as destructionCompleted,$ as destructionStarted,z as getWrapletsFromNode,O as initializationCompleted,j as initializationStarted,h as isWraplet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"AAAO,MAAMA,UAAuCC,OAE7C,MAAMC,UAAiBD,OAEvB,MAAME,UAAyCF,OAE/C,MAAMG,UAAyCH,OAE/C,MAAMI,UAA+BJ,OAErC,MAAMK,UAAkCL,OAExC,MAAMM,UAA2BN,OAEjC,MAAMO,UAAiC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EtG,CACA,iBAAME,CAAY9M,SACRO,EAA2BP,EACrC,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils/is.ts","webpack://wraplet/./src/Wraplet/types/Wraplet.ts","webpack://wraplet/./src/Wraplet/types/WrapletDependencyMap.ts","webpack://wraplet/./src/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils/createLifecycleAsyncError.ts","webpack://wraplet/./src/NodeTreeManager/utils.ts","webpack://wraplet/./src/DependencyManager/types/DependencyManager.ts","webpack://wraplet/./src/Logger/ConsoleLogger.ts","webpack://wraplet/./src/Map/utils.ts","webpack://wraplet/./src/Map/MapTreeBuilder.ts","webpack://wraplet/./src/DependencyManager/Core.ts","webpack://wraplet/./src/Wraplet/utils.ts","webpack://wraplet/./src/Wraplet/NodeManager.ts","webpack://wraplet/./src/Wraplet/types/WrapletApi.ts","webpack://wraplet/./src/Wraplet/statusActions.ts","webpack://wraplet/./src/Wraplet/createOuterDestroyCallback.ts","webpack://wraplet/./src/Wraplet/createOuterInitializeCallback.ts","webpack://wraplet/./src/Wraplet/createWrapletApi.ts","webpack://wraplet/./src/Wraplet/AbstractWraplet.ts","webpack://wraplet/./src/Wraplet/AbstractDependentWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts","webpack://wraplet/./src/NodeTreeManager/DefaultNodeTreeManager.ts"],"sourcesContent":["export class MissingRequiredDependencyError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredDependencyDestroyedError extends Error {\n}\nexport class DependenciesAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class TooManyChildrenFoundError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\nexport class UnsupportedNodeTypeError extends Error {\n}\nexport class LifecycleError extends Error {\n}\nexport class LifecycleAsyncErrors extends Error {\n errors = [];\n}\n","/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../../utils/is\";\nexport const WrapletSymbol = Symbol(\"Wraplet\");\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","function isSimpleObject(input) {\n return (typeof input === \"object\" &&\n input !== null &&\n Object.getPrototypeOf(input) === Object.prototype);\n}\nfunction isDependencyMapItem(item) {\n for (const key of Object.keys(item)) {\n if (![\n \"selector\",\n \"Class\",\n \"multiple\",\n \"required\",\n \"destructible\",\n \"injector\",\n \"map\",\n \"args\",\n ].includes(key)) {\n return false;\n }\n }\n if (![\"string\", \"function\", \"undefined\"].includes(typeof item[\"selector\"])) {\n return false;\n }\n if (typeof item[\"Class\"] !== \"function\") {\n return false;\n }\n if (typeof item[\"required\"] !== \"boolean\") {\n return false;\n }\n return typeof item[\"multiple\"] === \"boolean\";\n}\nexport function isWrapletDependencyMap(object) {\n if (!isSimpleObject(object)) {\n return false;\n }\n for (const key in object) {\n if (!isSimpleObject(object[key])) {\n return false;\n }\n const item = object[key];\n if (!isDependencyMapItem(item)) {\n return false;\n }\n }\n return true;\n}\n","import { is } from \"../../utils/is\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"./types/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { LifecycleAsyncErrors } from \"../errors\";\nexport function createLifecycleAsyncError(message, results, throwError = true) {\n const error = new LifecycleAsyncErrors(message);\n for (const result of results) {\n if (result.status === \"rejected\") {\n error.errors.push(result.reason);\n }\n }\n if (error.errors.length === 0) {\n return null;\n }\n if (throwError) {\n throw error;\n }\n return error;\n}\n","import { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (isWrapletSet(wraplets)) {\n return wraplets;\n }\n return null;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return false;\n }\n return wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport async function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n await actOnNodesRecursively(child, callback);\n }\n}\nexport async function destroyWrapletsRecursively(node) {\n const allWraplets = [];\n await actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return;\n }\n for (const wraplet of [...wraplets]) {\n if (wraplet.wraplet.status.isGettingDestroyed ||\n wraplet.wraplet.status.isDestroyed) {\n continue;\n }\n allWraplets.push(wraplet);\n }\n });\n const results = await Promise.allSettled(allWraplets.map((wraplet) => wraplet.wraplet.destroy()));\n createLifecycleAsyncError(\"Some wraplets threw exceptions during destruction\", results);\n}\n","import { is } from \"../../utils/is\";\nexport const DependencyManagerSymbol = Symbol(\"DependencyManager\");\nexport function isDependencyManager(object) {\n return is(object, DependencyManagerSymbol);\n}\n","export class ConsoleLogger {\n static #instance = new ConsoleLogger();\n constructor() { }\n dumpError(error) {\n console.dir(error, { depth: null });\n }\n static getGlobalLogger() {\n return this.#instance;\n }\n}\n","export function addDefaultsToDependencyDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n injector: {\n callback: (node) => node,\n },\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id of Object.keys(map)) {\n const def = map[id];\n newMap[id] = addDefaultsToDependencyDefinition(def);\n }\n return newMap;\n}\n","import { fillMapWithDefaults } from \"./utils\";\nconst MapTreeBuilderSymbol = Symbol(\"MapTreeBuilder\");\nexport class MapTreeBuilder {\n parent;\n [MapTreeBuilderSymbol] = true;\n map;\n children = {};\n constructor(parent) {\n this.parent = parent;\n }\n getParent() {\n if (!this.parent) {\n throw new Error(\"Parent not found.\");\n }\n return this.parent;\n }\n createChild(name) {\n const mapBuilder = new MapTreeBuilder(this);\n this.children[name] = mapBuilder;\n return mapBuilder;\n }\n setMap(map) {\n this.map = fillMapWithDefaults(map);\n }\n getMap() {\n if (!this.map) {\n throw new Error(\"Map is not set.\");\n }\n return this.map;\n }\n}\nexport function isMapTreeBuilder(object) {\n return (typeof object === \"object\" &&\n object !== null &&\n MapTreeBuilderSymbol in object);\n}\n","import { DependenciesAreNotAvailableError, TooManyChildrenFoundError, InternalLogicError, MapError, MissingRequiredDependencyError, UnsupportedNodeTypeError, LifecycleError, RequiredDependencyDestroyedError, } from \"../errors\";\nimport { isWraplet } from \"../Wraplet/types/Wraplet\";\nimport { isWrapletDependencyMap, } from \"../Wraplet/types/WrapletDependencyMap\";\nimport { isParentNode } from \"../NodeTreeManager/utils\";\nimport { DependencyManagerSymbol, } from \"./types/DependencyManager\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { ConsoleLogger } from \"../Logger/ConsoleLogger\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nimport { isMapTreeBuilder, MapTreeBuilder } from \"../Map/MapTreeBuilder\";\nexport class Core {\n node;\n [DependencyManagerSymbol] = true;\n logger;\n dependenciesAreInstantiated = false;\n statusWritable = {\n isDestroyed: false,\n isGettingDestroyed: false,\n isInitialized: false,\n isGettingInitialized: false,\n };\n get status() {\n return this.statusWritable;\n }\n mapTree;\n directDependencies = {};\n wrappedDependencies = {};\n destroyedDependencyListeners = [];\n instantiatedDependencyListeners = [];\n initializedDependencyListeners = [];\n constructor(node, map, options = {}) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"The node provided to the Core is not a valid node.\");\n }\n if (isWrapletDependencyMap(map)) {\n this.mapTree = new MapTreeBuilder();\n this.mapTree.setMap(map);\n }\n else if (isMapTreeBuilder(map)) {\n this.mapTree = map;\n }\n else {\n throw new MapError(\"The map provided to the Core is not a valid map.\");\n }\n // Process init options.\n const optionsWithDefaults = Object.assign(this.defaultOptions(), options);\n this.logger = optionsWithDefaults.logger;\n for (const listener of optionsWithDefaults.dependencyInstantiatedListeners) {\n this.instantiatedDependencyListeners.push(listener);\n }\n for (const listener of optionsWithDefaults.dependencyInitializedListeners) {\n this.initializedDependencyListeners.push(listener);\n }\n for (const listener of optionsWithDefaults.dependencyDestroyedListeners) {\n this.destroyedDependencyListeners.push(listener);\n }\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate dependency listeners) that needs access to the Core,\n * so the Core has to exist already.\n */\n async initializeDependencies() {\n if (this.status.isInitialized) {\n throw new LifecycleError(\"Dependencies are already initialized.\");\n }\n this.statusWritable.isGettingInitialized = true;\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency)\n return;\n const wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isInitialized ||\n wraplet.wraplet.status.isGettingInitialized) {\n return;\n }\n await wraplet.wraplet.initialize();\n const listenerResults = await Promise.allSettled(this.initializedDependencyListeners.map((listener) => {\n return listener(wraplet, id);\n }));\n createLifecycleAsyncError(`Errors in the core's dependency \"${id}\" initialize listeners.`, listenerResults);\n }));\n createLifecycleAsyncError(`Error at \"${id}\" dependency's initialization.`, results);\n }));\n const error = createLifecycleAsyncError(`Error at Core's initialization.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n this.statusWritable.isInitialized = true;\n this.statusWritable.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it when initialization\n // is finished.\n if (this.statusWritable.isGettingDestroyed) {\n await this.destroyDependencies();\n }\n }\n get map() {\n return this.mapTree.getMap();\n }\n instantiateDependencies() {\n if (this.dependenciesAreInstantiated) {\n throw new LifecycleError(\"Dependencies are already instantiated.\");\n }\n const dependencies = this.directDependencies;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n this.validateMapItemForNonParent(id, dependencyDefinition);\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.dependenciesAreInstantiated = true;\n return;\n }\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n const multiple = dependencyDefinition.multiple;\n this.validateMapItem(id, dependencyDefinition);\n if (multiple) {\n if (!dependencies[id]) {\n dependencies[id] = new DefaultWrapletSet();\n }\n const currentDependencies = dependencies[id];\n // We can assert as much because items\n const instantiatedDependencies = this.instantiateMultipleDependencies(dependencyDefinition, this.node, id);\n // Add new items to the current wraplet set.\n for (const item of instantiatedDependencies) {\n currentDependencies.add(item);\n }\n continue;\n }\n dependencies[id] = this.instantiateSingleWrapletDependency(dependencyDefinition, this.node, id);\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.dependenciesAreInstantiated = true;\n }\n findExistingWraplet(id, childElement) {\n // If an element doesn't have instantiated wraplets yet, then return null.\n if (this.directDependencies === undefined || !this.directDependencies[id]) {\n return null;\n }\n const existingDependency = this.directDependencies[id];\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const childElementWraplets = childElement.wraplets;\n if (!childElementWraplets) {\n return null;\n }\n const existingDependencies = existingDependency.find((wraplet) => {\n return childElementWraplets.has(wraplet);\n });\n if (existingDependencies.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the core.\");\n }\n return existingDependencies[0];\n }\n else {\n if (!isWraplet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a Wraplet.\");\n }\n if (!childElement.wraplets) {\n return null;\n }\n if (!childElement.wraplets.has(existingDependency)) {\n return null;\n }\n }\n // Handle single.\n return existingDependency;\n }\n instantiateSingleWrapletDependency(dependencyDefinition, node, id) {\n if (!dependencyDefinition.selector) {\n return this.directDependencies[id] || null;\n }\n if (!this.dependenciesAreInstantiated && this.directDependencies[id]) {\n throw new MapError(`It's not possible to provide a single-type dependency manually and use selector at the same time.`);\n }\n const selector = dependencyDefinition.selector;\n // Find children elements based on the map.\n const childrenElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childrenElements, dependencyDefinition);\n if (childrenElements.length === 0) {\n return null;\n }\n if (childrenElements.length > 1) {\n throw new TooManyChildrenFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" dependency. Selector used: \"${selector}\".`);\n }\n const childElement = childrenElements[0];\n return this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n instantiateWrapletItem(id, dependencyDefinition, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n let wraplet = null;\n try {\n const instance = new dependencyDefinition.Class(dependencyDefinition.injector.callback(node, this.mapTree.createChild(id), dependencyDefinition.injector.data), ...dependencyDefinition.args);\n if (!isWraplet(instance)) {\n throw new Error(\"Created dependency is not a Wraplet instance.\");\n }\n wraplet = instance;\n }\n catch (e) {\n if (e instanceof UnsupportedNodeTypeError) {\n if (!dependencyDefinition.required) {\n console.warn(`${e.message} Skipping instantiation of the \"${id}\" dependency.`);\n return null;\n }\n }\n throw e;\n }\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiatedDependencyListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleDependencies(dependencyDefinition, node, id) {\n const selector = dependencyDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childElements, dependencyDefinition);\n const items = new DefaultWrapletSet();\n for (const childElement of childElements) {\n let wraplet = this.findExistingWraplet(id, childElement);\n if (!wraplet) {\n wraplet = this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n if (wraplet) {\n items.add(wraplet);\n }\n }\n return items;\n }\n addDependencyDestroyedListener(callback) {\n this.destroyedDependencyListeners.push(callback);\n }\n addDependencyInstantiatedListener(callback) {\n this.instantiatedDependencyListeners.push(callback);\n }\n addDependencyInitializedListener(callback) {\n this.initializedDependencyListeners.push(callback);\n }\n setExistingInstance(id, wraplet) {\n const map = this.map;\n if (map[id].multiple) {\n throw new MapError(`This method can only be used to set a single-value dependency.`);\n }\n if (this.directDependencies[id]) {\n throw new MapError(`Dependency is already set.`);\n }\n if (!isWraplet(wraplet)) {\n throw new MapError(`Provided instance is not a valid dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n this.directDependencies[id] = wraplet;\n }\n addExistingInstance(id, wraplet) {\n const map = this.map;\n if (!map[id].multiple) {\n throw new MapError(`This method can only be used to set a multi-value dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n const items = this.directDependencies && this.directDependencies[id]\n ? this.directDependencies[id]\n : new DefaultWrapletSet();\n items.add(wraplet);\n this.directDependencies[id] = items;\n }\n prepareIndividualWraplet(id, wraplet) {\n // Listen for the dependency's destruction.\n wraplet.wraplet.addDestroyListener(this.createDependencyDestroyListener(id));\n }\n createDependencyDestroyListener(id) {\n return (async (w) => {\n this.removeDependency(w, id);\n const results = await Promise.allSettled(this.destroyedDependencyListeners.map((listener) => listener(w, id)));\n // Collect the required-dependency error alongside listener results\n // so that everything surfaces through the same LifecycleError mechanism.\n const requiredError = this.validateRequiredDependencyAfterRemoval(id);\n if (requiredError) {\n results.push({ status: \"rejected\", reason: requiredError });\n }\n createLifecycleAsyncError(`Errors in the destruction callbacks of the \"${id} dependency.\"`, results);\n });\n }\n /**\n * Checks whether a required dependency has been removed while the core\n * is NOT being destroyed itself. Returns the error instance instead of\n * throwing, so the caller can route it through the lifecycle error pipeline.\n */\n validateRequiredDependencyAfterRemoval(id) {\n if (this.map[id].required && !this.status.isGettingDestroyed) {\n return new RequiredDependencyDestroyedError(`Required dependency \"${id}\" has been destroyed.`);\n }\n return null;\n }\n /**\n * This method removes from nodes references to this wraplet and its dependencies recursively.\n */\n async destroyDependencies() {\n if (this.statusWritable.isDestroyed) {\n throw new LifecycleError(\"Dependencies are already destroyed.\");\n }\n this.statusWritable.isGettingDestroyed = true;\n if (this.statusWritable.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!this.statusWritable.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.statusWritable.isDestroyed = true;\n this.statusWritable.isGettingDestroyed = false;\n return;\n }\n await this.destroyDeps();\n this.statusWritable.isInitialized = false;\n this.statusWritable.isDestroyed = true;\n this.statusWritable.isGettingDestroyed = false;\n }\n findChildrenElements(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n get dependencies() {\n if (!this.dependenciesAreInstantiated) {\n throw new DependenciesAreNotAvailableError(\"Wraplet is not yet fully initialized.\");\n }\n return this.wrappedDependencies;\n }\n removeDependency(wraplet, id) {\n if (isWrapletSet(this.directDependencies[id])) {\n this.directDependencies[id].delete(wraplet);\n return;\n }\n // Only nullify the dependency if the current instance is the same one.\n // If it's not, then we don't care as there is no reference either way.\n if (this.directDependencies[id] === wraplet) {\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.directDependencies[id] = null;\n }\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector &&\n isRequired &&\n (!this.directDependencies[id] ||\n (isWrapletSet(this.directDependencies[id]) &&\n this.directDependencies[id].size === 0))) {\n throw new MapError(`${this.constructor.name}: Dependency \"${id}\" cannot at the same be required, have no selector, and be not provided otherwise.`);\n }\n }\n validateMapItemForNonParent(id, item) {\n if (item.required) {\n throw new MapError(`Dependency \"${id}\" error: If the node provided cannot have children, there should be no required dependencies.`);\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredDependencyError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if dependencies have not been destroyed before fetching them.\n */\n wrapDependencies(dependencies) {\n return new Proxy(dependencies, {\n get: (target, name) => {\n if (typeof name === \"symbol\") {\n throw new Error(`Symbol access is not supported for dependencies.`);\n }\n if (!(name in target)) {\n throw new Error(`Dependency '${name}' has not been found.`);\n }\n return target[name];\n },\n set: () => {\n throw new Error(`Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.`);\n },\n });\n }\n defaultOptions() {\n return {\n dependencyInstantiatedListeners: [],\n dependencyInitializedListeners: [],\n dependencyDestroyedListeners: [],\n logger: ConsoleLogger.getGlobalLogger(),\n };\n }\n async destroyDeps() {\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency || !this.map[id][\"destructible\"]) {\n return;\n }\n const wraplets = [];\n if (isWrapletSet(dependency)) {\n for (const item of dependency) {\n wraplets.push(item);\n }\n }\n else {\n wraplets.push(dependency);\n }\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isDestroyed ||\n wraplet.wraplet.status.isGettingDestroyed) {\n return;\n }\n return wraplet.wraplet.destroy();\n }));\n createLifecycleAsyncError(`Errors during destruction of the \"${id}\" dependency.`, results);\n }));\n const error = createLifecycleAsyncError(`Errors during the dependencies destruction.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n }\n /**\n * Creates a definition for creating a node wrapper.\n *\n * @param map_or_position\n * You can provide a map or a number representing the\n * relative position of the ancestor map that should be\n * reused.\n *\n * This is useful for recursive maps.\n * @param options\n */\n static createInjector(map_or_position, options) {\n return {\n data: options || {},\n callback: (node, map, data) => {\n let currentMap = map;\n const integerGuard = (input) => Number.isInteger(input);\n if (integerGuard(map_or_position)) {\n for (let i = 0; i < map_or_position; i++) {\n currentMap = currentMap.getParent();\n }\n }\n else if (isWrapletDependencyMap(map_or_position)) {\n currentMap.setMap(map_or_position);\n }\n else {\n throw new Error(`Invalid map argument.`);\n }\n return new Core(node, currentMap, data);\n },\n };\n }\n}\n","export const isOverridden = (instance, methodName, \n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nstopAt) => {\n let proto = Object.getPrototypeOf(instance);\n const stopProto = stopAt ? stopAt.prototype : Object.getPrototypeOf(proto);\n while (proto && proto !== stopProto) {\n if (Object.prototype.hasOwnProperty.call(proto, methodName)) {\n return true;\n }\n proto = Object.getPrototypeOf(proto);\n }\n return false;\n};\n","export class NodeManager {\n node;\n listeners = [];\n constructor(node) {\n this.node = node;\n }\n addListener(eventName, callback, options) {\n this.node.addEventListener(eventName, callback, options);\n this.listeners.push({\n callback,\n event: eventName,\n options: options,\n });\n }\n destroy() {\n for (const listener of this.listeners) {\n this.node.removeEventListener(listener.event, listener.callback, listener.options);\n }\n this.listeners.length = 0;\n }\n}\n","import { is } from \"../../utils/is\";\nexport const WrapletApiSymbol = Symbol(\"WrapletApi\");\nexport function isWrapletApi(object) {\n return is(object, WrapletApiSymbol);\n}\n","import { LifecycleError } from \"../errors\";\nexport function initializationStarted(status) {\n if (status.isInitialized ||\n status.isGettingInitialized ||\n status.isDestroyed ||\n status.isGettingDestroyed) {\n return false;\n }\n status.isGettingInitialized = true;\n return true;\n}\nexport async function initializationCompleted(status, destroyMethod) {\n status.isInitialized = true;\n status.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (status.isGettingDestroyed) {\n await destroyMethod();\n }\n}\nexport function destructionStarted(status) {\n if (status.isDestroyed) {\n return false;\n }\n status.isGettingDestroyed = true;\n if (status.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return false;\n }\n if (!status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n throw new LifecycleError(\"Wraplet cannot be destroyed before it is initialized.\");\n }\n return true;\n}\nexport async function destructionCompleted(status, wraplet, destroyListeners) {\n status.isGettingDestroyed = false;\n status.isInitialized = false;\n status.isDestroyed = true;\n for (const listener of [...destroyListeners].reverse()) {\n await listener(wraplet);\n }\n destroyListeners.length = 0;\n}\n","import { destructionCompleted, destructionStarted, } from \"../Wraplet/statusActions\";\nexport function createOuterDestroyCallback(args, destroyLogic) {\n return async function () {\n const outerStatus = args.status;\n if (!destructionStarted(outerStatus)) {\n return;\n }\n if (destroyLogic) {\n await destroyLogic();\n }\n await destructionCompleted(outerStatus, args.wraplet, args.destroyListeners);\n };\n}\n","import { initializationCompleted, initializationStarted, } from \"../Wraplet/statusActions\";\nexport function createOuterInitializeCallback(args, initializeLogic) {\n return async function () {\n const outerStatus = args.status;\n if (!initializationStarted(outerStatus)) {\n return;\n }\n if (initializeLogic) {\n await initializeLogic();\n }\n await initializationCompleted(outerStatus, args.destroyCallback);\n };\n}\n","import { addWrapletToNode, removeWrapletFromNode, } from \"../NodeTreeManager/utils\";\nimport { WrapletApiSymbol, } from \"./types/WrapletApi\";\nimport { isWraplet } from \"./types/Wraplet\";\nimport { createOuterDestroyCallback } from \"./createOuterDestroyCallback\";\nimport { createOuterInitializeCallback } from \"./createOuterInitializeCallback\";\nfunction validateNodeWrapletApiFactoryArgs(args) {\n if (!isWraplet(args.wraplet)) {\n throw new Error(\"Correct wraplet instance has to be provided.\");\n }\n if (args.node && !(args.node instanceof Node)) {\n throw new Error(\"Correct node has to be provided.\");\n }\n if (args.initializeCallback &&\n typeof args.initializeCallback !== \"function\") {\n throw new Error(\"initializeCallback has to be a function.\");\n }\n if (args.destroyCallback && typeof args.destroyCallback !== \"function\") {\n throw new Error(\"destroyCallback has to be a function.\");\n }\n}\nexport const createWrapletApi = (args) => {\n validateNodeWrapletApiFactoryArgs(args);\n const newArgs = { ...args };\n const defaultStatus = {\n isGettingInitialized: false,\n isDestroyed: false,\n isInitialized: false,\n isGettingDestroyed: false,\n };\n const api = {};\n const destroyListeners = [];\n const destroyCallback = createOuterDestroyCallback({\n status: defaultStatus,\n wraplet: newArgs.wraplet,\n destroyListeners: destroyListeners,\n }, async () => {\n if (newArgs.destroyCallback) {\n await newArgs.destroyCallback();\n }\n if (newArgs.node) {\n removeWrapletFromNode(newArgs.wraplet, newArgs.node);\n }\n }).bind(api);\n const initializeCallback = createOuterInitializeCallback({\n status: defaultStatus,\n destroyCallback: destroyCallback,\n wraplet: newArgs.wraplet,\n }, async () => {\n if (newArgs.node) {\n addWrapletToNode(newArgs.wraplet, newArgs.node);\n }\n if (newArgs.initializeCallback) {\n await newArgs.initializeCallback();\n }\n }).bind(api);\n return Object.assign(api, {\n [WrapletApiSymbol]: true,\n __destroyListeners: destroyListeners,\n status: defaultStatus,\n addDestroyListener: (callback) => {\n destroyListeners.push(callback);\n },\n initialize: initializeCallback,\n destroy: destroyCallback,\n });\n};\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { UnsupportedNodeTypeError } from \"../errors\";\nimport { isOverridden } from \"./utils\";\nimport { NodeManager } from \"./NodeManager\";\nimport { createWrapletApi } from \"./createWrapletApi\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n wraplet;\n _nodeManager;\n constructor(node) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"AbstractWraplet requires a Node instance.\");\n }\n const supportedNodeTypes = this.supportedNodeTypes();\n if (supportedNodeTypes !== null) {\n if (!supportedNodeTypes.find((value) => node instanceof value)) {\n throw new UnsupportedNodeTypeError(`Node type ${node.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);\n }\n }\n this.wraplet = this.createWrapletApi();\n }\n /**\n * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet)\n * can override this to supply their own lifecycle callbacks without causing a\n * double-creation of WrapletApi.\n */\n createWrapletApi() {\n const initializeCallback = isOverridden(this, \"onInitialize\", AbstractWraplet)\n ? this.onInitialize.bind(this)\n : undefined;\n const destroyCallback = isOverridden(this, \"onDestroy\", AbstractWraplet)\n ? this.onDestroy.bind(this)\n : undefined;\n return this.buildWrapletApi(initializeCallback, destroyCallback);\n }\n /**\n * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup\n * is always wired into the destroy path.\n */\n buildWrapletApi(initializeCallback, destroyCallback) {\n return createWrapletApi({\n node: this.node,\n wraplet: this,\n initializeCallback,\n destroyCallback: async () => {\n if (destroyCallback) {\n await destroyCallback();\n }\n if (this._nodeManager) {\n this._nodeManager.destroy();\n }\n },\n });\n }\n get nodeManager() {\n if (!this._nodeManager) {\n this._nodeManager = new NodeManager(this.node);\n }\n return this._nodeManager;\n }\n /**\n * Subclasses must return an array of constructors covering all types in union N.\n * Wrap the result in the `supportedTypeCheck` helper to make sure that the array contains all\n * and only classes that extend the given type.\n */\n supportedNodeTypes() {\n return null;\n }\n /**\n * Helper for subclasses to easily satisfy the exhaustive check.\n */\n supportedNodeTypesGuard(types) {\n return types;\n }\n /**\n * This method gets invoked when the wraplet is initialized.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onInitialize() {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * This method gets invoked when the wraplet is destroyed.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDestroy() {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n */\n static createWraplets(node, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n */\n static async createAndInitializeWraplets(node, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createWraplets(node, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { isDependencyManager, } from \"../DependencyManager/types/DependencyManager\";\nimport { Core } from \"../DependencyManager/Core\";\nimport { isOverridden } from \"./utils\";\nimport { AbstractWraplet } from \"./AbstractWraplet\";\nexport class AbstractDependentWraplet extends AbstractWraplet {\n dm;\n constructor(dm) {\n if (!isDependencyManager(dm)) {\n throw new Error(\"AbstractDependentWraplet requires an instance implementing DependencyManager and NodeManager interfaces.\");\n }\n super(dm.node);\n this.dm = dm;\n if (isOverridden(this, \"onDependencyInitialized\", AbstractDependentWraplet)) {\n dm.addDependencyInitializedListener(this.onDependencyInitialized.bind(this));\n }\n if (isOverridden(this, \"onDependencyInstantiated\", AbstractDependentWraplet)) {\n dm.addDependencyInstantiatedListener(this.onDependencyInstantiated.bind(this));\n }\n if (isOverridden(this, \"onDependencyDestroyed\", AbstractDependentWraplet)) {\n dm.addDependencyDestroyedListener(this.onDependencyDestroyed.bind(this));\n }\n dm.instantiateDependencies();\n }\n /**\n * Override createWrapletApi to provide Core-aware lifecycle callbacks\n * instead of the base class's version — this avoids creating two WrapletApi\n * instances.\n */\n createWrapletApi() {\n return this.buildWrapletApi(this.onInitialize.bind(this), this.onDestroy.bind(this));\n }\n async onDestroy() {\n await this.dm.destroyDependencies();\n }\n async onInitialize() {\n await this.dm.initializeDependencies();\n }\n /**\n * Dependencies.\n */\n get d() {\n return this.dm.dependencies;\n }\n /**\n * his method will be invoked if one of the wraplet's dependencies has been instantiated.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n onDependencyInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * his method will be invoked if one of the wraplet's dependencies has been initialized.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDependencyInitialized(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * This method will be ivoked if one of the wraplet's dependencies has been destroyed.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDependencyDestroyed(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n static createDependencyManager(node, map) {\n return new Core(node, map);\n }\n static createWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n static createAndInitializeWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n */\n static createDependentWraplets(node, map, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractDependentWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const self = this;\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const dm = self.createDependencyManager(node, map);\n result.push(new this(dm, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n const dm = self.createDependencyManager(element, map);\n result.push(new this(dm, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n */\n static async createAndInitializeDependentWraplets(node, map, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createDependentWraplets(node, map, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport class DefaultNodeTreeManager {\n initializers = [];\n addNodeInitializer(callback) {\n this.initializers.push(callback);\n }\n async initializeNode(node, context) {\n const results = await Promise.allSettled(this.initializers.map((initializer) => initializer(node, context)));\n createLifecycleAsyncError(`There were errors during the node's initialization.`, results);\n }\n async destroyNode(node) {\n await destroyWrapletsRecursively(node);\n }\n}\n"],"names":["MissingRequiredDependencyError","Error","MapError","RequiredDependencyDestroyedError","DependenciesAreNotAvailableError","StorageValidationError","TooManyChildrenFoundError","InternalLogicError","UnsupportedNodeTypeError","LifecycleError","LifecycleAsyncErrors","errors","is","object","symbol","WrapletSymbol","Symbol","isWraplet","isSimpleObject","input","Object","getPrototypeOf","prototype","isDependencyMapItem","item","key","keys","includes","isWrapletDependencyMap","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","createLifecycleAsyncError","message","throwError","error","result","status","reason","length","getWrapletsFromNode","node","wraplets","async","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","allWraplets","wraplet","isGettingDestroyed","isDestroyed","Promise","allSettled","map","destroy","DependencyManagerSymbol","ConsoleLogger","static","constructor","dumpError","console","dir","depth","getGlobalLogger","addDefaultsToDependencyDefinition","definition","args","destructible","injector","MapTreeBuilderSymbol","MapTreeBuilder","parent","getParent","createChild","name","mapBuilder","setMap","newMap","id","def","fillMapWithDefaults","getMap","Core","logger","dependenciesAreInstantiated","statusWritable","isInitialized","isGettingInitialized","mapTree","directDependencies","wrappedDependencies","destroyedDependencyListeners","instantiatedDependencyListeners","initializedDependencyListeners","options","Node","optionsWithDefaults","assign","defaultOptions","listener","dependencyInstantiatedListeners","dependencyInitializedListeners","dependencyDestroyedListeners","initializeDependencies","entries","dependency","initialize","listenerResults","destroyDependencies","instantiateDependencies","dependencies","querySelectorAll","dependencyDefinition","validateMapItemForNonParent","wrapDependencies","multiple","validateMapItem","currentDependencies","instantiatedDependencies","instantiateMultipleDependencies","add","instantiateSingleWrapletDependency","findExistingWraplet","childElement","undefined","existingDependency","childElementWraplets","existingDependencies","has","selector","childrenElements","findChildrenElements","validateElements","instantiateWrapletItem","existingWraplet","instance","Class","data","e","required","warn","prepareIndividualWraplet","childElements","items","addDependencyDestroyedListener","addDependencyInstantiatedListener","addDependencyInitializedListener","setExistingInstance","addExistingInstance","addDestroyListener","createDependencyDestroyListener","w","removeDependency","requiredError","validateRequiredDependencyAfterRemoval","destroyDeps","defaultSelectorCallback","delete","isRequired","size","elements","mapItem","Proxy","get","target","set","createInjector","map_or_position","currentMap","Number","isInteger","i","isOverridden","methodName","stopAt","proto","stopProto","hasOwnProperty","call","NodeManager","listeners","addListener","eventName","addEventListener","event","removeEventListener","WrapletApiSymbol","initializationStarted","initializationCompleted","destroyMethod","destructionStarted","destructionCompleted","destroyListeners","reverse","createOuterDestroyCallback","destroyLogic","outerStatus","createOuterInitializeCallback","initializeLogic","destroyCallback","createWrapletApi","initializeCallback","validateNodeWrapletApiFactoryArgs","newArgs","defaultStatus","api","removeWrapletFromNode","bind","__destroyListeners","AbstractWraplet","_nodeManager","supportedNodeTypes","value","onInitialize","onDestroy","buildWrapletApi","nodeManager","supportedNodeTypesGuard","types","createWraplets","attribute","additional_args","Element","hasAttribute","foundElements","element","createAndInitializeWraplets","AbstractDependentWraplet","dm","super","onDependencyInitialized","onDependencyInstantiated","onDependencyDestroyed","d","createDependencyManager","createDependentWraplets","self","createAndInitializeDependentWraplets","DefaultWrapletSetReadonly","DefaultNodeTreeManager","initializers","addNodeInitializer","initializeNode","context","initializer","destroyNode"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"AAAO,MAAMA,UAAuCC,OAE7C,MAAMC,UAAiBD,OAEvB,MAAME,UAAyCF,OAE/C,MAAMG,UAAyCH,OAE/C,MAAMI,UAA+BJ,OAErC,MAAMK,UAAkCL,OAExC,MAAMM,UAA2BN,OAEjC,MAAMO,UAAiCP,OAEvC,MAAMQ,UAAuBR,OAE7B,MAAMS,UAA6BT,MACtCU,OAAS,GChBb,MAAMC,EAAK,CAACC,EAAQC,IACU,iBAAXD,GACA,OAAXA,IACmB,IAAnBA,EAAOC,GCLFC,EAAgBC,OAAO,WAC7B,SAASC,EAAUJ,GACtB,OAAOD,EAAGC,EAAQE,EACtB,CCJA,SAASG,EAAeC,GACpB,MAAyB,iBAAVA,GACD,OAAVA,GACAC,OAAOC,eAAeF,KAAWC,OAAOE,SAChD,CACA,SAASC,EAAoBC,GACzB,IAAK,MAAMC,KAAOL,OAAOM,KAAKF,GAC1B,IAAK,CACD,WACA,QACA,WACA,WACA,eACA,WACA,MACA,QACFG,SAASF,GACP,OAAO,EAGf,QAAK,CAAC,SAAU,WAAY,aA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IK,aAAgBuL,SAAWvL,EAAKwL,aAAaH,GAAY,CACzD,MAAMQ,EAAKQ,EAAKF,wBAAwBnM,EAAMc,GAC9CnB,EAAOf,KAAK,IAAID,KAAKkN,KAAOP,GAChC,CACA,MAAMG,EAAgBzL,EAAKwE,iBAAiB,IAAI6G,MAChD,IAAK,MAAMK,KAAWD,EAAe,CACjC,MAAMI,EAAKQ,EAAKF,wBAAwBT,EAAS5K,GACjDnB,EAAOf,KAAK,IAAID,KAAKkN,KAAOP,GAChC,CACA,OAAO3L,CACX,CAIA,iDAAa2M,CAAqCtM,EAAMc,EAAKuK,EAAWC,EAAkB,IACtF,MACMrL,EADOtB,KACSyN,wBAAwBpM,EAAMc,EAAKuK,EAAWC,GACpE,IAAK,MAAM7K,KAAWR,QACZQ,EAAQA,QAAQ0D,aAE1B,OAAOlE,CACX,ECpHG,MAAMsM,UAAkCjO,EAC3C,CAACe,IAA4B,ECD1B,MAAMmN,EACTC,aAAe,GACf,kBAAAC,CAAmB3N,GACfJ,KAAK8N,aAAa7N,KAAKG,EAC3B,CACA,oBAAM4N,CAAe3M,EAAM4M,GAEvBrN,EAA0B,4DADJqB,QAAQC,WAAWlC,KAAK8N,aAAa3L,IAAK+L,GAAgBA,EAAY7M,EAAM4M,KAEtG,CACA,iBAAME,CAAY9M,SACRO,EAA2BP,EACrC,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils/is.ts","webpack://wraplet/./src/Wraplet/types/Wraplet.ts","webpack://wraplet/./src/Wraplet/types/WrapletDependencyMap.ts","webpack://wraplet/./src/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils/createLifecycleAsyncError.ts","webpack://wraplet/./src/NodeTreeManager/utils.ts","webpack://wraplet/./src/DependencyManager/types/DependencyManager.ts","webpack://wraplet/./src/Logger/ConsoleLogger.ts","webpack://wraplet/./src/Map/utils.ts","webpack://wraplet/./src/Map/MapTreeBuilder.ts","webpack://wraplet/./src/DependencyManager/DDM.ts","webpack://wraplet/./src/Wraplet/utils.ts","webpack://wraplet/./src/Wraplet/NodeManager.ts","webpack://wraplet/./src/Wraplet/types/WrapletApi.ts","webpack://wraplet/./src/Wraplet/statusActions.ts","webpack://wraplet/./src/Wraplet/createOuterDestroyCallback.ts","webpack://wraplet/./src/Wraplet/createOuterInitializeCallback.ts","webpack://wraplet/./src/Wraplet/createWrapletApi.ts","webpack://wraplet/./src/Wraplet/AbstractWraplet.ts","webpack://wraplet/./src/Wraplet/AbstractDependentWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts","webpack://wraplet/./src/NodeTreeManager/DefaultNodeTreeManager.ts"],"sourcesContent":["export class MissingRequiredDependencyError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredDependencyDestroyedError extends Error {\n}\nexport class DependenciesAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class TooManyChildrenFoundError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\nexport class UnsupportedNodeTypeError extends Error {\n}\nexport class LifecycleError extends Error {\n}\nexport class LifecycleAsyncErrors extends Error {\n errors = [];\n}\n","/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../../utils/is\";\nexport const WrapletSymbol = Symbol(\"Wraplet\");\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","function isSimpleObject(input) {\n return (typeof input === \"object\" &&\n input !== null &&\n Object.getPrototypeOf(input) === Object.prototype);\n}\nfunction isDependencyMapItem(item) {\n for (const key of Object.keys(item)) {\n if (![\n \"selector\",\n \"Class\",\n \"multiple\",\n \"required\",\n \"destructible\",\n \"injector\",\n \"map\",\n \"args\",\n ].includes(key)) {\n return false;\n }\n }\n if (![\"string\", \"function\", \"undefined\"].includes(typeof item[\"selector\"])) {\n return false;\n }\n if (typeof item[\"Class\"] !== \"function\") {\n return false;\n }\n if (typeof item[\"required\"] !== \"boolean\") {\n return false;\n }\n return typeof item[\"multiple\"] === \"boolean\";\n}\nexport function isWrapletDependencyMap(object) {\n if (!isSimpleObject(object)) {\n return false;\n }\n for (const key in object) {\n if (!isSimpleObject(object[key])) {\n return false;\n }\n const item = object[key];\n if (!isDependencyMapItem(item)) {\n return false;\n }\n }\n return true;\n}\n","import { is } from \"../../utils/is\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"./types/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { LifecycleAsyncErrors } from \"../errors\";\nexport function createLifecycleAsyncError(message, results, throwError = true) {\n const error = new LifecycleAsyncErrors(message);\n for (const result of results) {\n if (result.status === \"rejected\") {\n error.errors.push(result.reason);\n }\n }\n if (error.errors.length === 0) {\n return null;\n }\n if (throwError) {\n throw error;\n }\n return error;\n}\n","import { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (isWrapletSet(wraplets)) {\n return wraplets;\n }\n return null;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return false;\n }\n return wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport async function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n await actOnNodesRecursively(child, callback);\n }\n}\nexport async function destroyWrapletsRecursively(node) {\n const allWraplets = [];\n await actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n if (!wraplets) {\n return;\n }\n for (const wraplet of [...wraplets]) {\n if (wraplet.wraplet.status.isGettingDestroyed ||\n wraplet.wraplet.status.isDestroyed) {\n continue;\n }\n allWraplets.push(wraplet);\n }\n });\n const results = await Promise.allSettled(allWraplets.map((wraplet) => wraplet.wraplet.destroy()));\n createLifecycleAsyncError(\"Some wraplets threw exceptions during destruction\", results);\n}\n","import { is } from \"../../utils/is\";\nexport const DependencyManagerSymbol = Symbol(\"DependencyManager\");\nexport function isDependencyManager(object) {\n return is(object, DependencyManagerSymbol);\n}\n","export class ConsoleLogger {\n static #instance = new ConsoleLogger();\n constructor() { }\n dumpError(error) {\n console.dir(error, { depth: null });\n }\n static getGlobalLogger() {\n return this.#instance;\n }\n}\n","export function addDefaultsToDependencyDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n injector: {\n callback: (node) => node,\n },\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id of Object.keys(map)) {\n const def = map[id];\n newMap[id] = addDefaultsToDependencyDefinition(def);\n }\n return newMap;\n}\n","import { fillMapWithDefaults } from \"./utils\";\nconst MapTreeBuilderSymbol = Symbol(\"MapTreeBuilder\");\nexport class MapTreeBuilder {\n parent;\n [MapTreeBuilderSymbol] = true;\n map;\n children = {};\n constructor(parent) {\n this.parent = parent;\n }\n getParent() {\n if (!this.parent) {\n throw new Error(\"Parent not found.\");\n }\n return this.parent;\n }\n createChild(name) {\n const mapBuilder = new MapTreeBuilder(this);\n this.children[name] = mapBuilder;\n return mapBuilder;\n }\n setMap(map) {\n this.map = fillMapWithDefaults(map);\n }\n getMap() {\n if (!this.map) {\n throw new Error(\"Map is not set.\");\n }\n return this.map;\n }\n}\nexport function isMapTreeBuilder(object) {\n return (typeof object === \"object\" &&\n object !== null &&\n MapTreeBuilderSymbol in object);\n}\n","import { DependenciesAreNotAvailableError, TooManyChildrenFoundError, InternalLogicError, MapError, MissingRequiredDependencyError, UnsupportedNodeTypeError, LifecycleError, RequiredDependencyDestroyedError, } from \"../errors\";\nimport { isWraplet } from \"../Wraplet/types/Wraplet\";\nimport { isWrapletDependencyMap, } from \"../Wraplet/types/WrapletDependencyMap\";\nimport { isParentNode } from \"../NodeTreeManager/utils\";\nimport { DependencyManagerSymbol, } from \"./types/DependencyManager\";\nimport { isWrapletSet } from \"../Set/types/WrapletSet\";\nimport { DefaultWrapletSet } from \"../Set/DefaultWrapletSet\";\nimport { ConsoleLogger } from \"../Logger/ConsoleLogger\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nimport { isMapTreeBuilder, MapTreeBuilder } from \"../Map/MapTreeBuilder\";\nexport class DDM {\n node;\n [DependencyManagerSymbol] = true;\n logger;\n dependenciesAreInstantiated = false;\n statusWritable = {\n isDestroyed: false,\n isGettingDestroyed: false,\n isInitialized: false,\n isGettingInitialized: false,\n };\n get status() {\n return this.statusWritable;\n }\n mapTree;\n directDependencies = {};\n wrappedDependencies = {};\n destroyedDependencyListeners = [];\n instantiatedDependencyListeners = [];\n initializedDependencyListeners = [];\n constructor(node, map, options = {}) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"The node provided to the DDM is not a valid node.\");\n }\n if (isWrapletDependencyMap(map)) {\n this.mapTree = new MapTreeBuilder();\n this.mapTree.setMap(map);\n }\n else if (isMapTreeBuilder(map)) {\n this.mapTree = map;\n }\n else {\n throw new MapError(\"The map provided to the DDM is not a valid map.\");\n }\n // Process init options.\n const optionsWithDefaults = Object.assign(this.defaultOptions(), options);\n this.logger = optionsWithDefaults.logger;\n for (const listener of optionsWithDefaults.dependencyInstantiatedListeners) {\n this.instantiatedDependencyListeners.push(listener);\n }\n for (const listener of optionsWithDefaults.dependencyInitializedListeners) {\n this.initializedDependencyListeners.push(listener);\n }\n for (const listener of optionsWithDefaults.dependencyDestroyedListeners) {\n this.destroyedDependencyListeners.push(listener);\n }\n }\n /**\n * Initialize DDM.\n */\n async initializeDependencies() {\n if (this.status.isInitialized) {\n throw new LifecycleError(\"Dependencies are already initialized.\");\n }\n this.statusWritable.isGettingInitialized = true;\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency)\n return;\n const wraplets = isWrapletSet(dependency)\n ? Array.from(dependency)\n : [dependency];\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isInitialized ||\n wraplet.wraplet.status.isGettingInitialized) {\n return;\n }\n await wraplet.wraplet.initialize();\n const listenerResults = await Promise.allSettled(this.initializedDependencyListeners.map((listener) => {\n return listener(wraplet, id);\n }));\n createLifecycleAsyncError(`Errors in the DDM's dependency \"${id}\" initialize listeners.`, listenerResults);\n }));\n createLifecycleAsyncError(`Error at \"${id}\" dependency's initialization.`, results);\n }));\n const error = createLifecycleAsyncError(`Error at DDM's initialization.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n this.statusWritable.isInitialized = true;\n this.statusWritable.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it when initialization\n // is finished.\n if (this.statusWritable.isGettingDestroyed) {\n await this.destroyDependencies();\n }\n }\n get map() {\n return this.mapTree.getMap();\n }\n instantiateDependencies() {\n if (this.dependenciesAreInstantiated) {\n throw new LifecycleError(\"Dependencies are already instantiated.\");\n }\n const dependencies = this.directDependencies;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n this.validateMapItemForNonParent(id, dependencyDefinition);\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.dependenciesAreInstantiated = true;\n return;\n }\n for (const id in this.map) {\n const dependencyDefinition = this.map[id];\n const multiple = dependencyDefinition.multiple;\n this.validateMapItem(id, dependencyDefinition);\n if (multiple) {\n if (!dependencies[id]) {\n dependencies[id] = new DefaultWrapletSet();\n }\n const currentDependencies = dependencies[id];\n // We can assert as much because items\n const instantiatedDependencies = this.instantiateMultipleDependencies(dependencyDefinition, this.node, id);\n // Add new items to the current wraplet set.\n for (const item of instantiatedDependencies) {\n currentDependencies.add(item);\n }\n continue;\n }\n dependencies[id] = this.instantiateSingleWrapletDependency(dependencyDefinition, this.node, id);\n }\n this.wrappedDependencies = this.wrapDependencies(this.directDependencies);\n this.dependenciesAreInstantiated = true;\n }\n findExistingWraplet(id, childElement) {\n // If an element doesn't have instantiated wraplets yet, then return null.\n if (this.directDependencies === undefined || !this.directDependencies[id]) {\n return null;\n }\n const existingDependency = this.directDependencies[id];\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const childElementWraplets = childElement.wraplets;\n if (!childElementWraplets) {\n return null;\n }\n const existingDependencies = existingDependency.find((wraplet) => {\n return childElementWraplets.has(wraplet);\n });\n if (existingDependencies.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the DDM.\");\n }\n return existingDependencies[0];\n }\n else {\n if (!isWraplet(existingDependency)) {\n throw new InternalLogicError(\"Internal logic error. Expected a Wraplet.\");\n }\n if (!childElement.wraplets) {\n return null;\n }\n if (!childElement.wraplets.has(existingDependency)) {\n return null;\n }\n }\n // Handle single.\n return existingDependency;\n }\n instantiateSingleWrapletDependency(dependencyDefinition, node, id) {\n if (!dependencyDefinition.selector) {\n return this.directDependencies[id] || null;\n }\n if (!this.dependenciesAreInstantiated && this.directDependencies[id]) {\n throw new MapError(`It's not possible to provide a single-type dependency manually and use selector at the same time.`);\n }\n const selector = dependencyDefinition.selector;\n // Find children elements based on the map.\n const childrenElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childrenElements, dependencyDefinition);\n if (childrenElements.length === 0) {\n return null;\n }\n if (childrenElements.length > 1) {\n throw new TooManyChildrenFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" dependency. Selector used: \"${selector}\".`);\n }\n const childElement = childrenElements[0];\n return this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n instantiateWrapletItem(id, dependencyDefinition, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n let wraplet = null;\n try {\n const instance = new dependencyDefinition.Class(dependencyDefinition.injector.callback(node, this.mapTree.createChild(id), dependencyDefinition.injector.data), ...dependencyDefinition.args);\n if (!isWraplet(instance)) {\n throw new Error(\"Created dependency is not a Wraplet instance.\");\n }\n wraplet = instance;\n }\n catch (e) {\n if (e instanceof UnsupportedNodeTypeError) {\n if (!dependencyDefinition.required) {\n console.warn(`${e.message} Skipping instantiation of the \"${id}\" dependency.`);\n return null;\n }\n }\n throw e;\n }\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiatedDependencyListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleDependencies(dependencyDefinition, node, id) {\n const selector = dependencyDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildrenElements(selector, node);\n this.validateElements(id, childElements, dependencyDefinition);\n const items = new DefaultWrapletSet();\n for (const childElement of childElements) {\n let wraplet = this.findExistingWraplet(id, childElement);\n if (!wraplet) {\n wraplet = this.instantiateWrapletItem(id, dependencyDefinition, childElement);\n }\n if (wraplet) {\n items.add(wraplet);\n }\n }\n return items;\n }\n addDependencyDestroyedListener(callback) {\n this.destroyedDependencyListeners.push(callback);\n }\n addDependencyInstantiatedListener(callback) {\n this.instantiatedDependencyListeners.push(callback);\n }\n addDependencyInitializedListener(callback) {\n this.initializedDependencyListeners.push(callback);\n }\n setExistingInstance(id, wraplet) {\n const map = this.map;\n if (map[id].multiple) {\n throw new MapError(`This method can only be used to set a single-value dependency.`);\n }\n if (this.directDependencies[id]) {\n throw new MapError(`Dependency is already set.`);\n }\n if (!isWraplet(wraplet)) {\n throw new MapError(`Provided instance is not a valid dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n this.directDependencies[id] = wraplet;\n }\n addExistingInstance(id, wraplet) {\n const map = this.map;\n if (!map[id].multiple) {\n throw new MapError(`This method can only be used to set a multi-value dependency.`);\n }\n this.prepareIndividualWraplet(id, wraplet);\n const items = this.directDependencies && this.directDependencies[id]\n ? this.directDependencies[id]\n : new DefaultWrapletSet();\n items.add(wraplet);\n this.directDependencies[id] = items;\n }\n prepareIndividualWraplet(id, wraplet) {\n // Listen for the dependency's destruction.\n wraplet.wraplet.addDestroyListener(this.createDependencyDestroyListener(id));\n }\n createDependencyDestroyListener(id) {\n return (async (w) => {\n this.removeDependency(w, id);\n const results = await Promise.allSettled(this.destroyedDependencyListeners.map((listener) => listener(w, id)));\n // Collect the required-dependency error alongside listener results\n // so that everything surfaces through the same LifecycleError mechanism.\n const requiredError = this.validateRequiredDependencyAfterRemoval(id);\n if (requiredError) {\n results.push({ status: \"rejected\", reason: requiredError });\n }\n createLifecycleAsyncError(`Errors in the destruction callbacks of the \"${id} dependency.\"`, results);\n });\n }\n /**\n * Checks whether a required dependency has been removed while the DDM\n * is NOT being destroyed itself. Returns the error instance instead of\n * throwing, so the caller can route it through the lifecycle error pipeline.\n */\n validateRequiredDependencyAfterRemoval(id) {\n if (this.map[id].required && !this.status.isGettingDestroyed) {\n return new RequiredDependencyDestroyedError(`Required dependency \"${id}\" has been destroyed.`);\n }\n return null;\n }\n /**\n * This method removes from nodes references to this wraplet and its dependencies recursively.\n */\n async destroyDependencies() {\n if (this.statusWritable.isDestroyed) {\n throw new LifecycleError(\"Dependencies are already destroyed.\");\n }\n this.statusWritable.isGettingDestroyed = true;\n if (this.statusWritable.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!this.statusWritable.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.statusWritable.isDestroyed = true;\n this.statusWritable.isGettingDestroyed = false;\n return;\n }\n await this.destroyDeps();\n this.statusWritable.isInitialized = false;\n this.statusWritable.isDestroyed = true;\n this.statusWritable.isGettingDestroyed = false;\n }\n findChildrenElements(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n get dependencies() {\n if (!this.dependenciesAreInstantiated) {\n throw new DependenciesAreNotAvailableError(\"Wraplet is not yet fully initialized.\");\n }\n return this.wrappedDependencies;\n }\n removeDependency(wraplet, id) {\n if (isWrapletSet(this.directDependencies[id])) {\n this.directDependencies[id].delete(wraplet);\n return;\n }\n // Only nullify the dependency if the current instance is the same one.\n // If it's not, then we don't care as there is no reference either way.\n if (this.directDependencies[id] === wraplet) {\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.directDependencies[id] = null;\n }\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector &&\n isRequired &&\n (!this.directDependencies[id] ||\n (isWrapletSet(this.directDependencies[id]) &&\n this.directDependencies[id].size === 0))) {\n throw new MapError(`${this.constructor.name}: Dependency \"${id}\" cannot at the same be required, have no selector, and be not provided otherwise.`);\n }\n }\n validateMapItemForNonParent(id, item) {\n if (item.required) {\n throw new MapError(`Dependency \"${id}\" error: If the node provided cannot have children, there should be no required dependencies.`);\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredDependencyError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if dependencies have not been destroyed before fetching them.\n */\n wrapDependencies(dependencies) {\n return new Proxy(dependencies, {\n get: (target, name) => {\n if (typeof name === \"symbol\") {\n throw new Error(`Symbol access is not supported for dependencies.`);\n }\n if (!(name in target)) {\n throw new Error(`Dependency '${name}' has not been found.`);\n }\n return target[name];\n },\n set: () => {\n throw new Error(`Dependencies cannot be set directly. Use the 'setExistingInstance' or 'addExistingInstance' methods instead.`);\n },\n });\n }\n defaultOptions() {\n return {\n dependencyInstantiatedListeners: [],\n dependencyInitializedListeners: [],\n dependencyDestroyedListeners: [],\n logger: ConsoleLogger.getGlobalLogger(),\n };\n }\n async destroyDeps() {\n const results = await Promise.allSettled(Object.entries(this.directDependencies).map(async ([id, dependency]) => {\n if (!dependency || !this.map[id][\"destructible\"]) {\n return;\n }\n const wraplets = [];\n if (isWrapletSet(dependency)) {\n for (const item of dependency) {\n wraplets.push(item);\n }\n }\n else {\n wraplets.push(dependency);\n }\n const results = await Promise.allSettled(wraplets.map(async (wraplet) => {\n if (wraplet.wraplet.status.isDestroyed ||\n wraplet.wraplet.status.isGettingDestroyed) {\n return;\n }\n return wraplet.wraplet.destroy();\n }));\n createLifecycleAsyncError(`Errors during destruction of the \"${id}\" dependency.`, results);\n }));\n const error = createLifecycleAsyncError(`Errors during the dependencies destruction.`, results, false);\n if (error) {\n this.logger.dumpError(error);\n throw error;\n }\n }\n /**\n * Creates a definition for creating a node wrapper.\n *\n * @param map_or_position\n * You can provide a map or a number representing the\n * relative position of the ancestor map that should be\n * reused.\n *\n * This is useful for recursive maps.\n * @param options\n */\n static createInjector(map_or_position, options) {\n return {\n data: options || {},\n callback: (node, map, data) => {\n let currentMap = map;\n const integerGuard = (input) => Number.isInteger(input);\n if (integerGuard(map_or_position)) {\n for (let i = 0; i < map_or_position; i++) {\n currentMap = currentMap.getParent();\n }\n }\n else if (isWrapletDependencyMap(map_or_position)) {\n currentMap.setMap(map_or_position);\n }\n else {\n throw new Error(`Invalid map argument.`);\n }\n return new DDM(node, currentMap, data);\n },\n };\n }\n}\n","export const isOverridden = (instance, methodName, \n// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\nstopAt) => {\n let proto = Object.getPrototypeOf(instance);\n const stopProto = stopAt ? stopAt.prototype : Object.getPrototypeOf(proto);\n while (proto && proto !== stopProto) {\n if (Object.prototype.hasOwnProperty.call(proto, methodName)) {\n return true;\n }\n proto = Object.getPrototypeOf(proto);\n }\n return false;\n};\n","export class NodeManager {\n node;\n listeners = [];\n constructor(node) {\n this.node = node;\n }\n addListener(eventName, callback, options) {\n this.node.addEventListener(eventName, callback, options);\n this.listeners.push({\n callback,\n event: eventName,\n options: options,\n });\n }\n destroy() {\n for (const listener of this.listeners) {\n this.node.removeEventListener(listener.event, listener.callback, listener.options);\n }\n this.listeners.length = 0;\n }\n}\n","import { is } from \"../../utils/is\";\nexport const WrapletApiSymbol = Symbol(\"WrapletApi\");\nexport function isWrapletApi(object) {\n return is(object, WrapletApiSymbol);\n}\n","import { LifecycleError } from \"../errors\";\nexport function initializationStarted(status) {\n if (status.isInitialized ||\n status.isGettingInitialized ||\n status.isDestroyed ||\n status.isGettingDestroyed) {\n return false;\n }\n status.isGettingInitialized = true;\n return true;\n}\nexport async function initializationCompleted(status, destroyMethod) {\n status.isInitialized = true;\n status.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (status.isGettingDestroyed) {\n await destroyMethod();\n }\n}\nexport function destructionStarted(status) {\n if (status.isDestroyed) {\n return false;\n }\n status.isGettingDestroyed = true;\n if (status.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return false;\n }\n if (!status.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n throw new LifecycleError(\"Wraplet cannot be destroyed before it is initialized.\");\n }\n return true;\n}\nexport async function destructionCompleted(status, wraplet, destroyListeners) {\n status.isGettingDestroyed = false;\n status.isInitialized = false;\n status.isDestroyed = true;\n for (const listener of [...destroyListeners].reverse()) {\n await listener(wraplet);\n }\n destroyListeners.length = 0;\n}\n","import { destructionCompleted, destructionStarted, } from \"../Wraplet/statusActions\";\nexport function createOuterDestroyCallback(args, destroyLogic) {\n return async function () {\n const outerStatus = args.status;\n if (!destructionStarted(outerStatus)) {\n return;\n }\n if (destroyLogic) {\n await destroyLogic();\n }\n await destructionCompleted(outerStatus, args.wraplet, args.destroyListeners);\n };\n}\n","import { initializationCompleted, initializationStarted, } from \"../Wraplet/statusActions\";\nexport function createOuterInitializeCallback(args, initializeLogic) {\n return async function () {\n const outerStatus = args.status;\n if (!initializationStarted(outerStatus)) {\n return;\n }\n if (initializeLogic) {\n await initializeLogic();\n }\n await initializationCompleted(outerStatus, args.destroyCallback);\n };\n}\n","import { addWrapletToNode, removeWrapletFromNode, } from \"../NodeTreeManager/utils\";\nimport { WrapletApiSymbol, } from \"./types/WrapletApi\";\nimport { isWraplet } from \"./types/Wraplet\";\nimport { createOuterDestroyCallback } from \"./createOuterDestroyCallback\";\nimport { createOuterInitializeCallback } from \"./createOuterInitializeCallback\";\nfunction validateNodeWrapletApiFactoryArgs(args) {\n if (!isWraplet(args.wraplet)) {\n throw new Error(\"Correct wraplet instance has to be provided.\");\n }\n if (args.node && !(args.node instanceof Node)) {\n throw new Error(\"Correct node has to be provided.\");\n }\n if (args.initializeCallback &&\n typeof args.initializeCallback !== \"function\") {\n throw new Error(\"initializeCallback has to be a function.\");\n }\n if (args.destroyCallback && typeof args.destroyCallback !== \"function\") {\n throw new Error(\"destroyCallback has to be a function.\");\n }\n}\nexport const createWrapletApi = (args) => {\n validateNodeWrapletApiFactoryArgs(args);\n const newArgs = { ...args };\n const defaultStatus = {\n isGettingInitialized: false,\n isDestroyed: false,\n isInitialized: false,\n isGettingDestroyed: false,\n };\n const api = {};\n const destroyListeners = [];\n const destroyCallback = createOuterDestroyCallback({\n status: defaultStatus,\n wraplet: newArgs.wraplet,\n destroyListeners: destroyListeners,\n }, async () => {\n if (newArgs.destroyCallback) {\n await newArgs.destroyCallback();\n }\n if (newArgs.node) {\n removeWrapletFromNode(newArgs.wraplet, newArgs.node);\n }\n }).bind(api);\n const initializeCallback = createOuterInitializeCallback({\n status: defaultStatus,\n destroyCallback: destroyCallback,\n wraplet: newArgs.wraplet,\n }, async () => {\n if (newArgs.initializeCallback) {\n await newArgs.initializeCallback();\n }\n }).bind(api);\n // Note that it's added immediately without initialization required.\n if (newArgs.node) {\n addWrapletToNode(newArgs.wraplet, newArgs.node);\n }\n return Object.assign(api, {\n [WrapletApiSymbol]: true,\n __destroyListeners: destroyListeners,\n status: defaultStatus,\n addDestroyListener: (callback) => {\n destroyListeners.push(callback);\n },\n initialize: initializeCallback,\n destroy: destroyCallback,\n });\n};\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { UnsupportedNodeTypeError } from \"../errors\";\nimport { isOverridden } from \"./utils\";\nimport { NodeManager } from \"./NodeManager\";\nimport { createWrapletApi } from \"./createWrapletApi\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n wraplet;\n _nodeManager;\n constructor(node) {\n this.node = node;\n if (!(node instanceof Node)) {\n throw new Error(\"AbstractWraplet requires a Node instance.\");\n }\n const supportedNodeTypes = this.supportedNodeTypes();\n if (supportedNodeTypes !== null) {\n if (!supportedNodeTypes.find((value) => node instanceof value)) {\n throw new UnsupportedNodeTypeError(`Node type ${node.constructor.name} is not supported by the ${this.constructor.name} wraplet.`);\n }\n }\n this.wraplet = this.createWrapletApi();\n }\n /**\n * Creates the WrapletApi for this wraplet. Subclasses (e.g. AbstractDependentWraplet)\n * can override this to supply their own lifecycle callbacks without causing a\n * double-creation of WrapletApi.\n */\n createWrapletApi() {\n const initializeCallback = isOverridden(this, \"onInitialize\", AbstractWraplet)\n ? this.onInitialize.bind(this)\n : undefined;\n const destroyCallback = isOverridden(this, \"onDestroy\", AbstractWraplet)\n ? this.onDestroy.bind(this)\n : undefined;\n return this.buildWrapletApi(initializeCallback, destroyCallback);\n }\n /**\n * Builds a WrapletApi with the given callbacks and ensures NodeManager cleanup\n * is always wired into the destroy path.\n */\n buildWrapletApi(initializeCallback, destroyCallback) {\n return createWrapletApi({\n node: this.node,\n wraplet: this,\n initializeCallback,\n destroyCallback: async () => {\n if (destroyCallback) {\n await destroyCallback();\n }\n if (this._nodeManager) {\n this._nodeManager.destroy();\n }\n },\n });\n }\n get nodeManager() {\n if (!this._nodeManager) {\n this._nodeManager = new NodeManager(this.node);\n }\n return this._nodeManager;\n }\n /**\n * Subclasses must return an array of constructors covering all types in union N.\n * Wrap the result in the `supportedTypeCheck` helper to make sure that the array contains all\n * and only classes that extend the given type.\n */\n supportedNodeTypes() {\n return null;\n }\n /**\n * Helper for subclasses to easily satisfy the exhaustive check.\n */\n supportedNodeTypesGuard(types) {\n return types;\n }\n /**\n * This method gets invoked when the wraplet is initialized.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onInitialize() {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * This method gets invoked when the wraplet is destroyed.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDestroy() {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n */\n static createWraplets(node, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n */\n static async createAndInitializeWraplets(node, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createWraplets(node, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { isDependencyManager, } from \"../DependencyManager/types/DependencyManager\";\nimport { DDM } from \"../DependencyManager/DDM\";\nimport { isOverridden } from \"./utils\";\nimport { AbstractWraplet } from \"./AbstractWraplet\";\nexport class AbstractDependentWraplet extends AbstractWraplet {\n dm;\n constructor(dm) {\n if (!isDependencyManager(dm)) {\n throw new Error(\"AbstractDependentWraplet requires an instance implementing DependencyManager and NodeManager interfaces.\");\n }\n super(dm.node);\n this.dm = dm;\n if (isOverridden(this, \"onDependencyInitialized\", AbstractDependentWraplet)) {\n dm.addDependencyInitializedListener(this.onDependencyInitialized.bind(this));\n }\n if (isOverridden(this, \"onDependencyInstantiated\", AbstractDependentWraplet)) {\n dm.addDependencyInstantiatedListener(this.onDependencyInstantiated.bind(this));\n }\n if (isOverridden(this, \"onDependencyDestroyed\", AbstractDependentWraplet)) {\n dm.addDependencyDestroyedListener(this.onDependencyDestroyed.bind(this));\n }\n dm.instantiateDependencies();\n }\n /**\n * Override createWrapletApi to provide DependencyManager-aware lifecycle callbacks\n * instead of the base class's version — this avoids creating two WrapletApi\n * instances.\n */\n createWrapletApi() {\n return this.buildWrapletApi(async () => {\n await this.dm.initializeDependencies();\n await this.onInitialize.bind(this)();\n }, async () => {\n await this.onDestroy.bind(this)();\n await this.dm.destroyDependencies();\n });\n }\n async onDestroy() { }\n async onInitialize() { }\n /**\n * Dependencies.\n */\n get d() {\n return this.dm.dependencies;\n }\n /**\n * his method will be invoked if one of the wraplet's dependencies has been instantiated.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n onDependencyInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * his method will be invoked if one of the wraplet's dependencies has been initialized.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDependencyInitialized(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n /**\n * This method will be ivoked if one of the wraplet's dependencies has been destroyed.\n */\n /* istanbul ignore next -- Base method; only called when overridden by subclass. */\n async onDependencyDestroyed(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n dependency, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) {\n throw new Error(\"Method has to be implemented by subclass.\");\n }\n static createDependencyManager(node, map) {\n return new DDM(node, map);\n }\n static createWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n static createAndInitializeWraplets() {\n throw new Error(\"This method is not supported for AbstractDependentWraplet.\");\n }\n /**\n * Instantiates wraplets on a given ParentNode.\n */\n static createDependentWraplets(node, map, attribute, additional_args = []) {\n // @ts-expect-error TypeScript doesn't like this, but we still do this check.\n if (this === AbstractDependentWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const self = this;\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const dm = self.createDependencyManager(node, map);\n result.push(new this(dm, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n const dm = self.createDependencyManager(element, map);\n result.push(new this(dm, ...additional_args));\n }\n return result;\n }\n /**\n * Instantiates and initializes wraplets on a given ParentNode.\n */\n static async createAndInitializeDependentWraplets(node, map, attribute, additional_args = []) {\n const self = this;\n const wraplets = self.createDependentWraplets(node, map, attribute, additional_args);\n for (const wraplet of wraplets) {\n await wraplet.wraplet.initialize();\n }\n return wraplets;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"./types/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nimport { createLifecycleAsyncError } from \"../utils/createLifecycleAsyncError\";\nexport class DefaultNodeTreeManager {\n initializers = [];\n addNodeInitializer(callback) {\n this.initializers.push(callback);\n }\n async initializeNode(node, context) {\n const results = await Promise.allSettled(this.initializers.map((initializer) => initializer(node, context)));\n createLifecycleAsyncError(`There were errors during the node's initialization.`, results);\n }\n async destroyNode(node) {\n await destroyWrapletsRecursively(node);\n }\n}\n"],"names":["MissingRequiredDependencyError","Error","MapError","RequiredDependencyDestroyedError","DependenciesAreNotAvailableError","StorageValidationError","TooManyChildrenFoundError","InternalLogicError","UnsupportedNodeTypeError","LifecycleError","LifecycleAsyncErrors","errors","is","object","symbol","WrapletSymbol","Symbol","isWraplet","isSimpleObject","input","Object","getPrototypeOf","prototype","isDependencyMapItem","item","key","keys","includes","isWrapletDependencyMap","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","createLifecycleAsyncError","message","throwError","error","result","status","reason","length","getWrapletsFromNode","node","wraplets","async","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","allWraplets","wraplet","isGettingDestroyed","isDestroyed","Promise","allSettled","map","destroy","DependencyManagerSymbol","ConsoleLogger","static","constructor","dumpError","console","dir","depth","getGlobalLogger","addDefaultsToDependencyDefinition","definition","args","destructible","injector","MapTreeBuilderSymbol","MapTreeBuilder","parent","getParent","createChild","name","mapBuilder","setMap","newMap","id","def","fillMapWithDefaults","getMap","DDM","logger","dependenciesAreInstantiated","statusWritable","isInitialized","isGettingInitialized","mapTree","directDependencies","wrappedDependencies","destroyedDependencyListeners","instantiatedDependencyListeners","initializedDependencyListeners","options","Node","optionsWithDefaults","assign","defaultOptions","listener","dependencyInstantiatedListeners","dependencyInitializedListeners","dependencyDestroyedListeners","initializeDependencies","entries","dependency","initialize","listenerResults","destroyDependencies","instantiateDependencies","dependencies","querySelectorAll","dependencyDefinition","validateMapItemForNonParent","wrapDependencies","multiple","validateMapItem","currentDependencies","instantiatedDependencies","instantiateMultipleDependencies","add","instantiateSingleWrapletDependency","findExistingWraplet","childElement","undefined","existingDependency","childElementWraplets","existingDependencies","has","selector","childrenElements","findChildrenElements","validateElements","instantiateWrapletItem","existingWraplet","instance","Class","data","e","required","warn","prepareIndividualWraplet","childElements","items","addDependencyDestroyedListener","addDependencyInstantiatedListener","addDependencyInitializedListener","setExistingInstance","addExistingInstance","addDestroyListener","createDependencyDestroyListener","w","removeDependency","requiredError","validateRequiredDependencyAfterRemoval","destroyDeps","defaultSelectorCallback","delete","isRequired","size","elements","mapItem","Proxy","get","target","set","createInjector","map_or_position","currentMap","Number","isInteger","i","isOverridden","methodName","stopAt","proto","stopProto","hasOwnProperty","call","NodeManager","listeners","addListener","eventName","addEventListener","event","removeEventListener","WrapletApiSymbol","initializationStarted","initializationCompleted","destroyMethod","destructionStarted","destructionCompleted","destroyListeners","reverse","createOuterDestroyCallback","destroyLogic","outerStatus","createOuterInitializeCallback","initializeLogic","destroyCallback","createWrapletApi","initializeCallback","validateNodeWrapletApiFactoryArgs","newArgs","defaultStatus","api","removeWrapletFromNode","bind","__destroyListeners","AbstractWraplet","_nodeManager","supportedNodeTypes","value","onInitialize","onDestroy","buildWrapletApi","nodeManager","supportedNodeTypesGuard","types","createWraplets","attribute","additional_args","Element","hasAttribute","foundElements","element","createAndInitializeWraplets","AbstractDependentWraplet","dm","super","onDependencyInitialized","onDependencyInstantiated","onDependencyDestroyed","d","createDependencyManager","createDependentWraplets","self","createAndInitializeDependentWraplets","DefaultWrapletSetReadonly","DefaultNodeTreeManager","initializers","addNodeInitializer","initializeNode","context","initializer","destroyNode"],"sourceRoot":""}
|