wraplet 0.13.0 → 0.15.0
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/{typescript/AbstractWraplet.d.ts → AbstractWraplet.d.ts} +20 -10
- package/dist/{typescript/Core.d.ts → DefaultChildrenManager.d.ts} +14 -34
- package/dist/NodeTreeManager/DefaultNodeTreeManager.d.ts +12 -0
- package/dist/NodeTreeManager/NodeTreeManager.d.ts +8 -0
- package/dist/Set/DefaultSearchableSet.d.ts +6 -0
- package/dist/Set/DefaultWrapletSet.d.ts +8 -0
- package/dist/Set/DefaultWrapletSetReadonly.d.ts +6 -0
- package/dist/{typescript/Storage → Storage}/ElementStorage.d.ts +2 -1
- package/dist/{typescript/errors.d.ts → errors.d.ts} +5 -3
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/storage.cjs +1 -1
- package/dist/storage.cjs.map +1 -1
- package/dist/{typescript/storage.d.ts → storage.d.ts} +1 -0
- package/dist/storage.js +1 -1
- package/dist/storage.js.map +1 -1
- package/dist/types/ChildrenManager.d.ts +66 -0
- package/dist/types/Groupable.d.ts +11 -0
- package/dist/types/NodeTreeParent.d.ts +8 -0
- package/dist/types/Set/BaseSet.d.ts +5 -0
- package/dist/types/Set/WrapletSet.d.ts +8 -0
- package/dist/types/Set/WrapletSetReadonly.d.ts +7 -0
- package/dist/types/Storage/StorageValidators.d.ts +2 -0
- package/dist/{typescript/types → types}/Utils.d.ts +5 -0
- package/dist/{typescript/types → types}/Wraplet.d.ts +5 -2
- package/dist/{typescript/types → types}/WrapletChildDefinition.d.ts +4 -0
- package/dist/{typescript/types → types}/WrapletChildren.d.ts +2 -1
- package/dist/types/WrapletChildrenMap.d.ts +7 -0
- package/dist/types/global.d.ts +6 -0
- package/dist/utils.d.ts +8 -0
- package/package.json +22 -21
- package/dist/typescript/DefaultWrapletManager.d.ts +0 -8
- package/dist/typescript/getGlobalWrapletManager.d.ts +0 -2
- package/dist/typescript/index.d.ts +0 -7
- package/dist/typescript/types/WrapletChildrenMap.d.ts +0 -4
- package/dist/typescript/types/WrapletManager.d.ts +0 -5
- package/dist/typescript/types/global.d.ts +0 -6
- package/dist/typescript/utils.d.ts +0 -5
- /package/dist/{typescript/types → types}/ChildInstance.d.ts +0 -0
- /package/dist/{typescript/types → types}/CoreInitOptions.d.ts +0 -0
- /package/dist/{typescript/types → types}/DestroyChildListener.d.ts +0 -0
- /package/dist/{typescript/types → types}/DestroyListener.d.ts +0 -0
- /package/dist/{typescript/types → types}/InstantiateChildListener.d.ts +0 -0
- /package/dist/{typescript/types → types}/Storage/Storage.d.ts +0 -0
- /package/dist/{typescript/types → types}/Storage/StorageReadonly.d.ts +0 -0
|
@@ -1,22 +1,32 @@
|
|
|
1
1
|
import { WrapletChildrenMap } from "./types/WrapletChildrenMap";
|
|
2
2
|
import { WrapletChildren } from "./types/WrapletChildren";
|
|
3
|
-
import { Wraplet } from "./types/Wraplet";
|
|
4
|
-
import { Core } from "./Core";
|
|
3
|
+
import { Wraplet, WrapletSymbol } from "./types/Wraplet";
|
|
5
4
|
import { DestroyListener } from "./types/DestroyListener";
|
|
6
5
|
import { ChildInstance } from "./types/ChildInstance";
|
|
7
6
|
import { CoreInitOptions } from "./types/CoreInitOptions";
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
export declare abstract class AbstractWraplet<M extends WrapletChildrenMap = {}, N extends Node = Node
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
import { Groupable, GroupableSymbol, GroupExtractor } from "./types/Groupable";
|
|
8
|
+
import { NodeTreeParent, NodeTreeParentSymbol } from "./types/NodeTreeParent";
|
|
9
|
+
import { ChildrenManager } from "./types/ChildrenManager";
|
|
10
|
+
export declare abstract class AbstractWraplet<M extends WrapletChildrenMap = {}, N extends Node = Node> implements Wraplet<N>, Groupable, NodeTreeParent {
|
|
11
|
+
protected node: N;
|
|
12
|
+
[WrapletSymbol]: true;
|
|
13
|
+
[GroupableSymbol]: true;
|
|
14
|
+
[NodeTreeParentSymbol]: true;
|
|
15
|
+
protected childrenManager: ChildrenManager<M, N>;
|
|
16
|
+
private groupsExtractor;
|
|
17
|
+
private destroyListeners;
|
|
18
|
+
/**
|
|
19
|
+
* This is the log of all node accessors, available for easier debugging.
|
|
20
|
+
*/
|
|
21
|
+
private __debugNodeAccessors;
|
|
14
22
|
constructor(node: N, initOptions?: Partial<CoreInitOptions<M>>);
|
|
15
|
-
|
|
23
|
+
getNodeTreeChildren(): Wraplet[];
|
|
24
|
+
setGroupsExtractor(callback: GroupExtractor): void;
|
|
25
|
+
getGroups(): string[];
|
|
16
26
|
protected get children(): WrapletChildren<M>;
|
|
17
27
|
accessNode(callback: (node: N) => void): void;
|
|
18
28
|
destroy(): void;
|
|
19
|
-
|
|
29
|
+
isDestroyed(completely?: boolean): boolean;
|
|
20
30
|
get isInitialized(): boolean;
|
|
21
31
|
addDestroyListener(callback: DestroyListener<N>): void;
|
|
22
32
|
/**
|
|
@@ -1,66 +1,45 @@
|
|
|
1
1
|
import { WrapletChildren } from "./types/WrapletChildren";
|
|
2
|
-
import {
|
|
3
|
-
import { WrapletChildrenMap } from "./types/WrapletChildrenMap";
|
|
4
|
-
import { CommonMethods } from "./AbstractWraplet";
|
|
5
|
-
import { DestroyListener } from "./types/DestroyListener";
|
|
2
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "./types/WrapletChildrenMap";
|
|
6
3
|
import { InstantiateChildListener } from "./types/InstantiateChildListener";
|
|
7
4
|
import { DestroyChildListener } from "./types/DestroyChildListener";
|
|
8
5
|
import { CoreInitOptions } from "./types/CoreInitOptions";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
private initOptions;
|
|
6
|
+
import { ChildrenManager, ChildrenManagerSymbol } from "./types/ChildrenManager";
|
|
7
|
+
export declare class DefaultChildrenManager<M extends WrapletChildrenMap = {}, N extends Node = Node> implements ChildrenManager<M, N> {
|
|
8
|
+
private node;
|
|
9
|
+
[ChildrenManagerSymbol]: true;
|
|
14
10
|
isDestroyed: boolean;
|
|
11
|
+
isGettingDestroyed: boolean;
|
|
15
12
|
isInitialized: boolean;
|
|
13
|
+
map: WrapletChildrenMapWithDefaults<M>;
|
|
16
14
|
private instantiatedChildren;
|
|
17
|
-
/**
|
|
18
|
-
* This is the log of all node accessors, available for easier debugging.
|
|
19
|
-
*/
|
|
20
|
-
private __debugNodeAccessors;
|
|
21
|
-
private destroyListeners;
|
|
22
15
|
private destroyChildListeners;
|
|
23
16
|
private instantiateChildListeners;
|
|
24
17
|
private listeners;
|
|
25
|
-
constructor(node: N, map: M,
|
|
18
|
+
constructor(node: N, map: M, initOptions?: Partial<CoreInitOptions<M>>);
|
|
26
19
|
/**
|
|
27
20
|
* Initialize core.
|
|
28
21
|
*
|
|
29
22
|
* We couldn't put this step in the constructor, because during initialization some wraplet
|
|
30
|
-
* processing occurs (instantiate child listeners) that needs access to the
|
|
31
|
-
* exist already.
|
|
23
|
+
* processing occurs (instantiate child listeners) that needs access to the children manager,
|
|
24
|
+
* so the children manager has to exist already.
|
|
32
25
|
*/
|
|
33
26
|
init(): void;
|
|
34
|
-
instantiateChildren(
|
|
27
|
+
instantiateChildren(): WrapletChildren<M>;
|
|
35
28
|
syncChildren(): void;
|
|
36
|
-
private isCorrectSingleWrapletInstanceGuard;
|
|
37
29
|
private findExistingWraplet;
|
|
38
30
|
private instantiateSingleWrapletChild;
|
|
39
31
|
private instantiateWrapletItem;
|
|
40
32
|
private instantiateMultipleWrapletsChild;
|
|
41
|
-
accessNode(callback: (node: N) => void): void;
|
|
42
|
-
addDestroyListener(callback: DestroyListener<N>): void;
|
|
43
33
|
addDestroyChildListener(callback: DestroyChildListener<M, keyof M>): void;
|
|
44
34
|
addInstantiateChildListener(callback: InstantiateChildListener<M, keyof M>): void;
|
|
45
35
|
private createIndividualWraplet;
|
|
46
36
|
private prepareIndividualWraplet;
|
|
47
37
|
/**
|
|
48
|
-
* This method
|
|
49
|
-
* The original wraplet and all children need to have this method implemented.
|
|
50
|
-
*/
|
|
51
|
-
executeOnChildren(children: WrapletChildren<M>, method: keyof CM & string, payload?: CM[keyof CM]): void;
|
|
52
|
-
/**
|
|
53
|
-
* This method removes from nodes references to this wraplet and its children recuresively.
|
|
38
|
+
* This method removes from nodes references to this wraplet and its children recursively.
|
|
54
39
|
*/
|
|
55
40
|
destroy(): void;
|
|
56
|
-
|
|
57
|
-
* Remove the wraplet from the list of wraplets.
|
|
58
|
-
*/
|
|
59
|
-
removeWrapletFromNode(wraplet: Wraplet<N>, node: N): void;
|
|
41
|
+
private fillMapWithDefaults;
|
|
60
42
|
private addDefaultsToChildDefinition;
|
|
61
|
-
private wrapletHasMethodGuard;
|
|
62
|
-
private isParentNode;
|
|
63
|
-
private childTypeGuard;
|
|
64
43
|
addEventListener(node: Node, eventName: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
|
|
65
44
|
get children(): WrapletChildren<M>;
|
|
66
45
|
get uninitializedChildren(): Partial<WrapletChildren<M>>;
|
|
@@ -74,4 +53,5 @@ export declare class Core<M extends WrapletChildrenMap = {}, N extends Node = No
|
|
|
74
53
|
private wrapChildren;
|
|
75
54
|
private defaultInitOptions;
|
|
76
55
|
private processInitOptions;
|
|
56
|
+
private destroyChildren;
|
|
77
57
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { NodeTreeManager } from "./NodeTreeManager";
|
|
2
|
+
import { Wraplet } from "../types/Wraplet";
|
|
3
|
+
import { WrapletSetReadonly } from "../types/Set/WrapletSetReadonly";
|
|
4
|
+
export type Initializer = (node: Node) => Wraplet[];
|
|
5
|
+
export default class DefaultNodeTreeManager implements NodeTreeManager {
|
|
6
|
+
private initializers;
|
|
7
|
+
private items;
|
|
8
|
+
addWrapletInitializer(callback: Initializer): void;
|
|
9
|
+
initializeNodeTree(node: Node): void;
|
|
10
|
+
destroyNodeTree(node: Node): void;
|
|
11
|
+
getSet(): WrapletSetReadonly;
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Initializer } from "./DefaultNodeTreeManager";
|
|
2
|
+
import { WrapletSetReadonly } from "../types/Set/WrapletSetReadonly";
|
|
3
|
+
export interface NodeTreeManager {
|
|
4
|
+
addWrapletInitializer(callback: Initializer): void;
|
|
5
|
+
initializeNodeTree(node: Node): void;
|
|
6
|
+
destroyNodeTree(node: Node): void;
|
|
7
|
+
getSet(): WrapletSetReadonly;
|
|
8
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BaseSet } from "../types/Set/BaseSet";
|
|
2
|
+
export declare class DefaultSearchableSet<T> extends Set<T> implements BaseSet<T> {
|
|
3
|
+
find(filter: (wraplet: T) => boolean): T[];
|
|
4
|
+
findOne(filter: (wraplet: T) => boolean): T | null;
|
|
5
|
+
getOrdered(callback: (item: T) => number): T[];
|
|
6
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WrapletSet, WrapletSetSymbol } from "../types/Set/WrapletSet";
|
|
2
|
+
import { Wraplet } from "../types/Wraplet";
|
|
3
|
+
import { DefaultSearchableSet } from "./DefaultSearchableSet";
|
|
4
|
+
import { WrapletSetReadonlySymbol } from "../types/Set/WrapletSetReadonly";
|
|
5
|
+
export declare class DefaultWrapletSet<T extends Wraplet> extends DefaultSearchableSet<T> implements WrapletSet {
|
|
6
|
+
[WrapletSetReadonlySymbol]: true;
|
|
7
|
+
[WrapletSetSymbol]: true;
|
|
8
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Wraplet } from "../types/Wraplet";
|
|
2
|
+
import { WrapletSetReadonly, WrapletSetReadonlySymbol } from "../types/Set/WrapletSetReadonly";
|
|
3
|
+
import { DefaultSearchableSet } from "./DefaultSearchableSet";
|
|
4
|
+
export declare class DefaultWrapletSetReadonly<T extends Wraplet> extends DefaultSearchableSet<T> implements WrapletSetReadonly {
|
|
5
|
+
[WrapletSetReadonlySymbol]: true;
|
|
6
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Storage } from "../types/Storage/Storage";
|
|
2
|
+
import { StorageValidators } from "../types/Storage/StorageValidators";
|
|
2
3
|
export type ElementStorageOptions = {
|
|
3
4
|
keepFresh?: boolean;
|
|
4
5
|
};
|
|
@@ -9,7 +10,7 @@ export declare class ElementStorage<D extends Record<string, unknown>> implement
|
|
|
9
10
|
private defaults;
|
|
10
11
|
private options;
|
|
11
12
|
private data;
|
|
12
|
-
constructor(element: Element, attribute: string, validators:
|
|
13
|
+
constructor(element: Element, attribute: string, validators: StorageValidators<D>, defaults: D, options?: ElementStorageOptions);
|
|
13
14
|
has(key: keyof D): boolean;
|
|
14
15
|
get<T extends keyof D>(key: T): D[T];
|
|
15
16
|
getMultiple<T extends keyof D>(keys: T[]): Pick<D, T>;
|
|
@@ -6,9 +6,11 @@ export declare class RequiredChildDestroyedError extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class ChildrenAreNotAvailableError extends Error {
|
|
8
8
|
}
|
|
9
|
-
export declare class
|
|
9
|
+
export declare class StorageValidationError extends Error {
|
|
10
10
|
}
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class ChildrenTooManyFoundError extends Error {
|
|
12
12
|
}
|
|
13
|
-
export declare class
|
|
13
|
+
export declare class ChildrenAreAlreadyDestroyedError extends Error {
|
|
14
|
+
}
|
|
15
|
+
export declare class InternalLogicError extends Error {
|
|
14
16
|
}
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var e={d:(t,i)=>{for(var
|
|
1
|
+
var e={d:(t,i)=>{for(var n in i)e.o(i,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:i[n]})},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,{AbstractWraplet:()=>I,DefaultChildrenManager:()=>w,DefaultWrapletSet:()=>p,DefaultWrapletSetReadonly:()=>E,destroyWrapletsRecursively:()=>g,getWrapletsFromNode:()=>y,isWraplet:()=>v});class i extends Error{}class n extends Error{}class r extends Error{}class s extends Error{}class o extends Error{}class a extends Error{}class l extends Error{}const d=(e,t)=>"object"==typeof e&&null!==e&&!0===e[t],h=Symbol("WrapletSet");function c(e){return d(e,h)}class u extends Set{find(e){const t=[];for(const i of this)e(i)&&t.push(i);return t}findOne(e){for(const t of this)if(e(t))return t;return null}getOrdered(e){return Array.from(this).sort((t,i)=>e(t)-e(i))}}const f=Symbol("WrapletSetReadonly");class p extends u{[f]=!0;[h]=!0}function y(e){const t=e.wraplets;return c(t)&&0!==t.size?t:new p}function C(e,t){t(e);const i=e.childNodes;for(const e of i)C(e,t)}function g(e){C(e,e=>{const t=y(e);for(const e of t)e.destroy()})}const m=Symbol("ChildrenManager");class w{node;[m]=!0;isDestroyed=!1;isGettingDestroyed=!1;isInitialized=!1;map;instantiatedChildren;destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(e,t,i={}){this.node=e,this.map=this.fillMapWithDefaults(t),this.processInitOptions(i),this.instantiatedChildren={}}init(){const e=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(e),this.isInitialized=!0}instantiateChildren(){const e=this.instantiatedChildren;if("function"!=typeof this.node.querySelectorAll){if(Object.keys(this.map).length>0)throw new n("If the node provided cannot have children, the children map should be empty.");return e}for(const t in this.map){const i=this.map[t],n=i.multiple;this.validateMapItem(t,i),e[t]=n?this.instantiateMultipleWrapletsChild(i,this.node,t):this.instantiateSingleWrapletChild(i,this.node,t)}return e}syncChildren(){this.instantiatedChildren=this.instantiateChildren()}findExistingWraplet(e,t){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[e])return null;const i=this.instantiatedChildren[e],n=y(t);if(this.map[e].multiple){if(!c(i))throw new l("Internal logic error. Expected a WrapletSet.");const e=this.intersect(i,n);if(0===e.length)return null;if(1===e.length)return e[0];throw new l("Internal logic error. Multiple instances of the same child found on a single node.")}return i}instantiateSingleWrapletChild(e,t,i){if(!e.selector)return null;const n=e.selector,r=t.querySelectorAll(n);if(this.validateElements(i,r,e),0===r.length)return null;if(r.length>1)throw new o(`${this.constructor.name}: More than one element was found for the "${i}" child. Selector used: "${n}".`);const s=r[0];return this.instantiateWrapletItem(i,e,s)}instantiateWrapletItem(e,t,i){const n=this.findExistingWraplet(e,i);if(n)return n;const r=t.Class,s=t.args,o=this.createIndividualWraplet(r,i,s);this.prepareIndividualWraplet(e,o);for(const t of this.instantiateChildListeners)t(o,e);return o}instantiateMultipleWrapletsChild(e,t,i){const n=e.selector;if(!n)return new p;const r=t.querySelectorAll(n);this.validateElements(i,r,e);const s=this.instantiatedChildren&&this.instantiatedChildren[i]?this.instantiatedChildren[i]:new p;for(const t of r){if(this.findExistingWraplet(i,t))continue;const n=this.instantiateWrapletItem(i,e,t);s.add(n)}return s}addDestroyChildListener(e){this.destroyChildListeners.push(e)}addInstantiateChildListener(e){this.instantiateChildListeners.push(e)}createIndividualWraplet(e,t,i){return new e(...[t,...i])}prepareIndividualWraplet(e,t){t.addDestroyListener(t=>{this.removeChild(t,e);for(const i of this.destroyChildListeners)i(t,e)})}destroy(){if(this.isDestroyed)throw new a("Children are already destroyed.");this.isGettingDestroyed=!0;for(const e of this.listeners){const t=e.node,i=e.eventName,n=e.callback,r=e.options;t.removeEventListener(i,n,r)}this.destroyChildren(),this.isGettingDestroyed=!1,this.isDestroyed=!0}fillMapWithDefaults(e){const t={};for(const i in e)t[i]=this.addDefaultsToChildDefinition(e[i]);return t}addDefaultsToChildDefinition(e){return{args:[],destructible:!0,...e}}addEventListener(e,t,i,n){this.listeners.push({node:e,eventName:t,callback:i,options:n}),e.addEventListener(t,i,n)}get children(){if(!this.isInitialized)throw new s("Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.");return this.instantiatedChildren}get uninitializedChildren(){if(this.isInitialized)throw new s("Wraplet is already initialized. Fetch children with 'children' property instead.");return this.instantiatedChildren}removeChild(e,t){if(c(this.instantiatedChildren[t])){if(!this.instantiatedChildren[t].delete(e))throw new l("Internal logic error. Destroyed child couldn't be removed because it's not among the children.")}else{if(this.map[t].required&&!this.isGettingDestroyed)throw new r("Required child has been destroyed.");if(null===this.instantiatedChildren[t])throw new l("Internal logic error. Destroyed child couldn't be removed because it's already null.");this.instantiatedChildren[t]=null}}intersect(e,t){return[...e].filter(e=>t.has(e))}validateMapItem(e,t){const i=t.selector,r=t.required;if(!i&&r)throw new n(`${this.constructor.name}: Child "${e}" cannot at the same be required and have no selector.`)}validateElements(e,t,n){if(0===t.length&&n.required)throw new i(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${n.selector}".`)}wrapChildren(e){return new Proxy(e,{get:function(e,t){if(!(t in e))throw new Error("Child has not been found.");return e[t]}})}defaultInitOptions(){return{instantiateChildListeners:[],destroyChildListeners:[]}}processInitOptions(e){const t=Object.assign(this.defaultInitOptions(),e);t.mapAlterCallback&&t.mapAlterCallback(this.map);for(const e of t.instantiateChildListeners)this.instantiateChildListeners.push(e);for(const e of t.destroyChildListeners)this.destroyChildListeners.push(e)}destroyChildren(){for(const[e,t]of Object.entries(this.children))if(t&&this.map[e].destructible)if(c(t))for(const e of t)e.destroy();else t.destroy()}}const b=Symbol("Wraplet");function v(e){return d(e,b)}const W=Symbol("Groupable"),D=Symbol("NodeTreeParent");class I{node;[b]=!0;[W]=!0;[D]=!0;childrenManager;groupsExtractor=e=>{if(e instanceof Element){const t=e.getAttribute("data-js-wraplet-groupable");if(t)return t.split(",")}return[]};destroyListeners=[];__debugNodeAccessors=[];constructor(e,t={}){if(this.node=e,!e)throw new Error("Node is required to create a wraplet.");const i=this.defineChildrenMap();t.instantiateChildListeners=[this.onChildInstantiated.bind(this)],t.destroyChildListeners=[this.onChildDestroyed.bind(this)],this.childrenManager=new w(e,i,t),this.initialize()}getNodeTreeChildren(){const e=[];for(const t of Object.values(this.children))if(c(t))for(const i of t)e.push(i);else e.push(t);return e.filter(e=>{let t=!1;return e.accessNode(e=>{t=this.node.contains(e)}),t})}setGroupsExtractor(e){this.groupsExtractor=e}getGroups(){return this.groupsExtractor(this.node)}get children(){return this.childrenManager.children}accessNode(e){this.__debugNodeAccessors.push(e),e(this.node)}destroy(){for(const e of this.destroyListeners)e(this);var e;this.destroyListeners.length=0,(e=this.node).wraplets&&e.wraplets.delete(this),this.childrenManager.destroy()}isDestroyed(e=!1){return e?this.childrenManager.isDestroyed:this.childrenManager.isGettingDestroyed||this.childrenManager.isDestroyed}get isInitialized(){return this.childrenManager.isInitialized}addDestroyListener(e){this.destroyListeners.push(e)}onChildDestroyed(e,t){}initialize(){var e;this.childrenManager.init(),(e=this.node).wraplets||(e.wraplets=new p),e.wraplets.add(this)}onChildInstantiated(e,t){}isChildInstance(e,t,i=null){return t===(i||t)&&e instanceof this.childrenManager.map[t].Class}static createWraplets(e,t,i=[]){if(this===I)throw new Error("You cannot instantiate an abstract class.");let n=e.parentNode,r=null;n||(e instanceof Document?n=e:(r=document.createElement("div"),r.appendChild(e),n=r));const s=[],o=n.querySelectorAll(t);r&&r.removeChild(e);for(const e of o)s.push(new this(e,...i));return s}}class E extends u{[f]=!0}var L=exports;for(var M in t)L[M]=t[M];t.__esModule&&Object.defineProperty(L,"__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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SAASC,IAIZ,OAHKD,IACDA,EAAuB,IAAIN,GAExBM,CACX,C","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.ts","webpack://wraplet/./src/Core.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/DefaultWrapletManager.ts","webpack://wraplet/./src/getGlobalWrapletManager.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 MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class ValidationMissingError extends Error {\n}\nexport class InvalidOptionsError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\n","export function isWraplet(obj) {\n return (typeof obj === \"object\" &&\n obj !== null &&\n \"isWraplet\" in obj &&\n obj.isWraplet === true);\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!Array.isArray(wraplets)) {\n return [];\n }\n return wraplets;\n}\nexport function actOnNodesRecursevily(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursevily(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursevily(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, } from \"./errors\";\nimport { isWraplet } from \"./utils\";\nexport class Core {\n node;\n map;\n wraplet;\n initOptions;\n isDestroyed = false;\n isInitialized = false;\n instantiatedChildren;\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n destroyListeners = [];\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, wraplet, initOptions = {}) {\n this.node = node;\n this.map = map;\n this.wraplet = wraplet;\n this.initOptions = initOptions;\n for (const id in map) {\n map[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\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 child listeners) that needs access to the core, so core has to\n * exist already.\n */\n init() {\n const children = this.instantiateChildren(this.node);\n this.instantiatedChildren = this.wrapChildren(children);\n if (!this.node.wraplets) {\n this.node.wraplets = [];\n }\n this.node.wraplets.push(this.wraplet);\n this.isInitialized = true;\n }\n instantiateChildren(node) {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!this.isParentNode(node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren(this.node);\n }\n isCorrectSingleWrapletInstanceGuard(item, id) {\n return item instanceof this.map[id].Class;\n }\n findExistingWraplet(id, childElement) {\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = childElement.wraplets || [];\n if (this.map[id][\"multiple\"]) {\n if (!Array.isArray(existingChild)) {\n throw new Error(\"Internal logic error. Expected an array.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n else if (intersection.length > 1) {\n throw new Error(\"Internal logic error. Multiple wraplets found for the same child.\");\n }\n }\n else if (this.instantiatedChildren[id] !== null) {\n return existingChild;\n }\n return null;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new Error(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args || [];\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return [];\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : [];\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n if (!wraplet) {\n continue;\n }\n if (!this.isCorrectSingleWrapletInstanceGuard(wraplet, id)) {\n throw new Error(`${this.constructor.name}: The \"${id}\" child is not an array of the expected type.`);\n }\n items.push(wraplet);\n }\n return items;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args = []) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = (wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n };\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method allows executing the specified method on the wraplet and all its children.\n * The original wraplet and all children need to have this method implemented.\n */\n executeOnChildren(children, method, payload) {\n for (const childEntries of Object.entries(children)) {\n const name = childEntries[0];\n const child = childEntries[1];\n const map = this.map;\n if (!map[name].destructible) {\n continue;\n }\n if (Array.isArray(child)) {\n // We need to loop through the copy of the array because some items can be removed from\n // the original during the loop.\n const childArray = child.slice(0);\n for (const item of childArray) {\n if (!isWraplet(item)) {\n throw new Error(\"Internal logic error. Item is not a wraplet.\");\n }\n if (!this.wrapletHasMethodGuard(item, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n item[method](payload);\n }\n else {\n item[method]();\n }\n }\n }\n else if (isWraplet(child)) {\n if (!this.wrapletHasMethodGuard(child, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n child[method](payload);\n }\n else {\n child[method]();\n }\n }\n }\n }\n /**\n * This method removes from nodes references to this wraplet and its children recuresively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new Error(\"Wraplet is already destroyed.\");\n }\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n for (const listener of this.destroyListeners) {\n listener(this.wraplet);\n }\n this.destroyListeners.length = 0;\n this.removeWrapletFromNode(this.wraplet, this.node);\n this.executeOnChildren(this.children, \"destroy\");\n this.isDestroyed = true;\n }\n /**\n * Remove the wraplet from the list of wraplets.\n */\n removeWrapletFromNode(wraplet, node) {\n const index = node.wraplets?.findIndex((value) => {\n return value === wraplet;\n });\n if (index !== undefined && index > -1) {\n node.wraplets?.splice(index, 1);\n }\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n wrapletHasMethodGuard(wraplet, method) {\n return typeof wraplet[method] === \"function\";\n }\n isParentNode(node) {\n return typeof node.querySelectorAll === \"function\";\n }\n childTypeGuard(variable, id) {\n const map = this.map;\n const Class = map[id].Class;\n const isRequired = map[id].required;\n const isMultiple = map[id].multiple;\n if (isMultiple) {\n if (!Array.isArray(variable)) {\n return false;\n }\n if (isRequired) {\n return variable.every((value) => value instanceof Class);\n }\n return true;\n }\n if (isRequired) {\n return variable instanceof Class;\n }\n return variable instanceof Class || variable === null;\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (Array.isArray(this.instantiatedChildren[id])) {\n const index = this.instantiatedChildren[id].findIndex((value) => {\n return value === wraplet;\n });\n if (index === -1) {\n throw new Error(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n this.instantiatedChildren[id].splice(index, 1);\n return;\n }\n if (this.map[id].required) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n const setB = new Set(b);\n return [...new Set(a)].filter((x) => setB.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${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 children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n function isDestroyed(wraplet) {\n return wraplet.isDestroyed;\n }\n const child = target[name];\n if (Array.isArray(child)) {\n const destroyed = child.find(isDestroyed);\n if (destroyed) {\n throw new Error(\"Core error: One of the children in the array has been destroyed but not removed\");\n }\n return target[name];\n }\n if (child !== null && isDestroyed(child)) {\n throw new Error(\"The child has been destroyed\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n}\n","import { Core } from \"./Core\";\nexport class AbstractWraplet {\n isWraplet = true;\n core;\n constructor(node, initOptions = {}) {\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.core = new Core(node, map, this, initOptions);\n this.initialize();\n }\n get node() {\n return this.core.node;\n }\n get children() {\n return this.core.children;\n }\n accessNode(callback) {\n this.core.accessNode(callback);\n }\n destroy() {\n this.core.destroy();\n }\n get isDestroyed() {\n return this.core.isDestroyed;\n }\n get isInitialized() {\n return this.core.isInitialized;\n }\n addDestroyListener(callback) {\n this.core.addDestroyListener(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.core.init();\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.core.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this instanceof AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nexport default class DefaultWrapletManager {\n initializers = [];\n addWrapletInitializer(callback) {\n this.initializers.push(callback);\n }\n initializeNodeTree(node) {\n for (const initializer of this.initializers) {\n initializer(node);\n }\n }\n destroyNodeTree(node) {\n destroyWrapletsRecursively(node);\n }\n}\n","import DefaultWrapletManager from \"./DefaultWrapletManager\";\nlet globalWrapletManager = null;\nexport function getGlobalWrapletManager() {\n if (!globalWrapletManager) {\n globalWrapletManager = new DefaultWrapletManager();\n }\n return globalWrapletManager;\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","isWraplet","getWrapletsFromNode","node","wraplets","Array","isArray","actOnNodesRecursevily","callback","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","Core","map","initOptions","isDestroyed","isInitialized","instantiatedChildren","__debugNodeAccessors","destroyListeners","destroyChildListeners","instantiateChildListeners","listeners","constructor","this","id","addDefaultsToChildDefinition","processInitOptions","init","instantiateChildren","wrapChildren","push","isParentNode","keys","length","item","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","isCorrectSingleWrapletInstanceGuard","Class","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","querySelectorAll","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","accessNode","addDestroyListener","addDestroyChildListener","addInstantiateChildListener","removeChild","executeOnChildren","method","payload","childEntries","entries","destructible","childArray","slice","wrapletHasMethodGuard","String","eventName","options","removeEventListener","removeWrapletFromNode","index","findIndex","splice","childTypeGuard","variable","isRequired","required","every","addEventListener","uninitializedChildren","a","b","setB","Set","filter","x","has","elements","Proxy","target","find","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","AbstractWraplet","core","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","result","foundElements","element","DefaultWrapletManager","initializers","addWrapletInitializer","initializeNodeTree","initializer","destroyNodeTree","globalWrapletManager","getGlobalWrapletManager"],"sourceRoot":""}
|
|
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,2MCLhD,MAAMC,UAAkCC,OAExC,MAAMC,UAAiBD,OAEvB,MAAME,UAAoCF,OAE1C,MAAMG,UAAqCH,OAI3C,MAAMI,UAAkCJ,OAExC,MAAMK,UAAyCL,OAE/C,MAAMM,UAA2BN,OCVxC,MAAM,EAAK,CAACO,EAAQC,IACU,iBAAXD,GACA,OAAXA,IACmB,IAAnBA,EAAOC,GCNTC,EAAmBb,OAAO,cAEzB,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a,KACZF,IACGpH,aAAgBuH,SAChBH,EAAapH,GAGbsH,EAAaE,SAASC,cAAc,OACpCH,EAAWI,YAAY1H,GACvBoH,EAAaE,IAGrB,MAAMd,EAAS,GACTmB,EAAgBP,EAAWzF,iBAAiBiB,GAC9C0E,GACAA,EAAWzD,YAAY7D,GAE3B,IAAK,MAAM4H,KAAWD,EAClBnB,EAAOpH,KAAK,IAAID,KAAKyI,KAAYT,IAErC,OAAOX,CACX,EC1JG,MAAMqB,UAAkChJ,EAC3C,CAACgB,IAA4B,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/types/Utils.ts","webpack://wraplet/./src/types/Set/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/types/Set/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/types/ChildrenManager.ts","webpack://wraplet/./src/DefaultChildrenManager.ts","webpack://wraplet/./src/types/Wraplet.ts","webpack://wraplet/./src/types/Groupable.ts","webpack://wraplet/./src/types/NodeTreeParent.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.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 MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","/* istanbul ignore next */\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\";\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/Set/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol } from \"../types/Set/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\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) || wraplets.size === 0) {\n return new DefaultWrapletSet();\n }\n return wraplets;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n if (!node.wraplets) {\n return false;\n }\n return node.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 function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursively(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","const ChildrenManagerSymbol = Symbol(\"ChildrenManager\");\nexport { ChildrenManagerSymbol };\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, ChildrenTooManyFoundError, ChildrenAreAlreadyDestroyedError, InternalLogicError, } from \"./errors\";\nimport { getWrapletsFromNode, isParentNode } from \"./utils\";\nimport { ChildrenManagerSymbol, } from \"./types/ChildrenManager\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nimport { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nexport class DefaultChildrenManager {\n node;\n [ChildrenManagerSymbol] = true;\n isDestroyed = false;\n isGettingDestroyed = false;\n isInitialized = false;\n map;\n instantiatedChildren;\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, initOptions = {}) {\n this.node = node;\n this.map = this.fillMapWithDefaults(map);\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\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 child listeners) that needs access to the children manager,\n * so the children manager has to exist already.\n */\n init() {\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n this.isInitialized = true;\n }\n instantiateChildren() {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, this.node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, this.node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren();\n }\n findExistingWraplet(id, childElement) {\n // If a child doesn't have instantiated wraplets yet, then return null.\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = getWrapletsFromNode(childElement);\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingChild)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n throw new InternalLogicError(\"Internal logic error. Multiple instances of the same child found on a single node.\");\n }\n // Handle single.\n return existingChild;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new ChildrenTooManyFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args;\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : new DefaultWrapletSet();\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n items.add(wraplet);\n }\n return items;\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = ((wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n });\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method removes from nodes references to this wraplet and its children recursively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new ChildrenAreAlreadyDestroyedError(\"Children are already destroyed.\");\n }\n this.isGettingDestroyed = true;\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n this.destroyChildren();\n this.isGettingDestroyed = false;\n this.isDestroyed = true;\n }\n fillMapWithDefaults(map) {\n const newMap = {};\n for (const id in map) {\n newMap[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n return newMap;\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (isWrapletSet(this.instantiatedChildren[id])) {\n if (!this.instantiatedChildren[id].delete(wraplet)) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n return;\n }\n if (this.map[id].required && !this.isGettingDestroyed) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n if (this.instantiatedChildren[id] === null) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's already null.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n return [...a].filter((x) => b.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${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 children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n destroyChildren() {\n for (const [key, child] of Object.entries(this.children)) {\n if (!child || !this.map[key][\"destructible\"]) {\n continue;\n }\n if (isWrapletSet(child)) {\n for (const item of child) {\n item.destroy();\n }\n }\n else {\n child.destroy();\n }\n }\n }\n}\n","import { is } from \"./Utils\";\nconst WrapletSymbol = Symbol(\"Wraplet\");\nexport { WrapletSymbol };\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","import { is } from \"./Utils\";\nconst GroupableSymbol = Symbol(\"Groupable\");\nexport { GroupableSymbol };\n/* istanbul ignore next */\nexport function isGroupable(object) {\n return is(object, GroupableSymbol);\n}\nconst defaultGroupableAttribute = \"data-js-wraplet-groupable\";\nexport { defaultGroupableAttribute };\n","const NodeTreeParentSymbol = Symbol(\"NodeTreeParent\");\nexport { NodeTreeParentSymbol };\n/* istanbul ignore next */\nexport function isNodeTreeParent(object) {\n return (object[NodeTreeParentSymbol] ===\n true);\n}\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { DefaultChildrenManager } from \"./DefaultChildrenManager\";\nimport { defaultGroupableAttribute, GroupableSymbol, } from \"./types/Groupable\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { addWrapletToNode, removeWrapletFromNode } from \"./utils\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n [GroupableSymbol] = true;\n [NodeTreeParentSymbol] = true;\n childrenManager;\n groupsExtractor = (node) => {\n if (node instanceof Element) {\n const groupsString = node.getAttribute(defaultGroupableAttribute);\n if (groupsString) {\n return groupsString.split(\",\");\n }\n }\n return [];\n };\n destroyListeners = [];\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n constructor(node, initOptions = {}) {\n this.node = node;\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.childrenManager = new DefaultChildrenManager(node, map, initOptions);\n this.initialize();\n }\n getNodeTreeChildren() {\n const children = [];\n for (const child of Object.values(this.children)) {\n if (isWrapletSet(child)) {\n for (const item of child) {\n children.push(item);\n }\n }\n else {\n children.push(child);\n }\n }\n // Return only descendants.\n return children.filter((child) => {\n let result = false;\n child.accessNode((childsNode) => {\n result = this.node.contains(childsNode);\n });\n return result;\n });\n }\n setGroupsExtractor(callback) {\n this.groupsExtractor = callback;\n }\n getGroups() {\n return this.groupsExtractor(this.node);\n }\n get children() {\n return this.childrenManager.children;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n destroy() {\n for (const listener of this.destroyListeners) {\n listener(this);\n }\n this.destroyListeners.length = 0;\n removeWrapletFromNode(this, this.node);\n this.childrenManager.destroy();\n }\n isDestroyed(completely = false) {\n return completely\n ? this.childrenManager.isDestroyed\n : this.childrenManager.isGettingDestroyed ||\n this.childrenManager.isDestroyed;\n }\n get isInitialized() {\n return this.childrenManager.isInitialized;\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.childrenManager.init();\n addWrapletToNode(this, this.node);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.childrenManager.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"../types/Set/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","ChildrenTooManyFoundError","ChildrenAreAlreadyDestroyedError","InternalLogicError","object","symbol","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","item","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","getWrapletsFromNode","node","wraplets","size","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","ChildrenManagerSymbol","DefaultChildrenManager","isDestroyed","isGettingDestroyed","isInitialized","map","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","constructor","initOptions","fillMapWithDefaults","processInitOptions","init","instantiateChildren","wrapChildren","querySelectorAll","keys","length","id","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","newMap","addDefaultsToChildDefinition","destructible","addEventListener","uninitializedChildren","delete","required","x","has","isRequired","elements","Proxy","target","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","entries","WrapletSymbol","isWraplet","GroupableSymbol","NodeTreeParentSymbol","AbstractWraplet","childrenManager","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","getNodeTreeChildren","values","result","accessNode","childsNode","contains","setGroupsExtractor","getGroups","completely","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","foundElements","element","DefaultWrapletSetReadonly"],"sourceRoot":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { DefaultChildrenManager } from "./DefaultChildrenManager";
|
|
2
|
+
export { AbstractWraplet } from "./AbstractWraplet";
|
|
3
|
+
export { destroyWrapletsRecursively, getWrapletsFromNode } from "./utils";
|
|
4
|
+
export type { WrapletSetReadonly } from "./types/Set/WrapletSetReadonly";
|
|
5
|
+
export type { WrapletSet } from "./types/Set/WrapletSet";
|
|
6
|
+
export { DefaultWrapletSetReadonly } from "./Set/DefaultWrapletSetReadonly";
|
|
7
|
+
export { DefaultWrapletSet } from "./Set/DefaultWrapletSet";
|
|
8
|
+
export { isWraplet } from "./types/Wraplet";
|
|
9
|
+
export type { WrapletChildrenMap } from "./types/WrapletChildrenMap";
|
|
10
|
+
export type { Wraplet } from "./types/Wraplet";
|
|
11
|
+
import "./types/global";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t extends Error{}class e extends Error{}class i extends Error{}class r extends Error{}
|
|
1
|
+
class t extends Error{}class e extends Error{}class i extends Error{}class n extends Error{}class s extends Error{}class r extends Error{}class o extends Error{}const a=(t,e)=>"object"==typeof t&&null!==t&&!0===t[e],l=Symbol("WrapletSet");function d(t){return a(t,l)}class h extends Set{find(t){const e=[];for(const i of this)t(i)&&e.push(i);return e}findOne(t){for(const e of this)if(t(e))return e;return null}getOrdered(t){return Array.from(this).sort((e,i)=>t(e)-t(i))}}const c=Symbol("WrapletSetReadonly");class u extends h{[c]=!0;[l]=!0}function f(t){const e=t.wraplets;return d(e)&&0!==e.size?e:new u}function p(t,e){e(t);const i=t.childNodes;for(const t of i)p(t,e)}function C(t){p(t,t=>{const e=f(t);for(const t of e)t.destroy()})}const y=Symbol("ChildrenManager");class g{node;[y]=!0;isDestroyed=!1;isGettingDestroyed=!1;isInitialized=!1;map;instantiatedChildren;destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(t,e,i={}){this.node=t,this.map=this.fillMapWithDefaults(e),this.processInitOptions(i),this.instantiatedChildren={}}init(){const t=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(t),this.isInitialized=!0}instantiateChildren(){const t=this.instantiatedChildren;if("function"!=typeof this.node.querySelectorAll){if(Object.keys(this.map).length>0)throw new e("If the node provided cannot have children, the children map should be empty.");return t}for(const e in this.map){const i=this.map[e],n=i.multiple;this.validateMapItem(e,i),t[e]=n?this.instantiateMultipleWrapletsChild(i,this.node,e):this.instantiateSingleWrapletChild(i,this.node,e)}return t}syncChildren(){this.instantiatedChildren=this.instantiateChildren()}findExistingWraplet(t,e){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[t])return null;const i=this.instantiatedChildren[t],n=f(e);if(this.map[t].multiple){if(!d(i))throw new o("Internal logic error. Expected a WrapletSet.");const t=this.intersect(i,n);if(0===t.length)return null;if(1===t.length)return t[0];throw new o("Internal logic error. Multiple instances of the same child found on a single node.")}return i}instantiateSingleWrapletChild(t,e,i){if(!t.selector)return null;const n=t.selector,r=e.querySelectorAll(n);if(this.validateElements(i,r,t),0===r.length)return null;if(r.length>1)throw new s(`${this.constructor.name}: More than one element was found for the "${i}" child. Selector used: "${n}".`);const o=r[0];return this.instantiateWrapletItem(i,t,o)}instantiateWrapletItem(t,e,i){const n=this.findExistingWraplet(t,i);if(n)return n;const s=e.Class,r=e.args,o=this.createIndividualWraplet(s,i,r);this.prepareIndividualWraplet(t,o);for(const e of this.instantiateChildListeners)e(o,t);return o}instantiateMultipleWrapletsChild(t,e,i){const n=t.selector;if(!n)return new u;const s=e.querySelectorAll(n);this.validateElements(i,s,t);const r=this.instantiatedChildren&&this.instantiatedChildren[i]?this.instantiatedChildren[i]:new u;for(const e of s){if(this.findExistingWraplet(i,e))continue;const n=this.instantiateWrapletItem(i,t,e);r.add(n)}return r}addDestroyChildListener(t){this.destroyChildListeners.push(t)}addInstantiateChildListener(t){this.instantiateChildListeners.push(t)}createIndividualWraplet(t,e,i){return new t(...[e,...i])}prepareIndividualWraplet(t,e){e.addDestroyListener(e=>{this.removeChild(e,t);for(const i of this.destroyChildListeners)i(e,t)})}destroy(){if(this.isDestroyed)throw new r("Children are already destroyed.");this.isGettingDestroyed=!0;for(const t of this.listeners){const e=t.node,i=t.eventName,n=t.callback,s=t.options;e.removeEventListener(i,n,s)}this.destroyChildren(),this.isGettingDestroyed=!1,this.isDestroyed=!0}fillMapWithDefaults(t){const e={};for(const i in t)e[i]=this.addDefaultsToChildDefinition(t[i]);return e}addDefaultsToChildDefinition(t){return{args:[],destructible:!0,...t}}addEventListener(t,e,i,n){this.listeners.push({node:t,eventName:e,callback:i,options:n}),t.addEventListener(e,i,n)}get children(){if(!this.isInitialized)throw new n("Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.");return this.instantiatedChildren}get uninitializedChildren(){if(this.isInitialized)throw new n("Wraplet is already initialized. Fetch children with 'children' property instead.");return this.instantiatedChildren}removeChild(t,e){if(d(this.instantiatedChildren[e])){if(!this.instantiatedChildren[e].delete(t))throw new o("Internal logic error. Destroyed child couldn't be removed because it's not among the children.")}else{if(this.map[e].required&&!this.isGettingDestroyed)throw new i("Required child has been destroyed.");if(null===this.instantiatedChildren[e])throw new o("Internal logic error. Destroyed child couldn't be removed because it's already null.");this.instantiatedChildren[e]=null}}intersect(t,e){return[...t].filter(t=>e.has(t))}validateMapItem(t,i){const n=i.selector,s=i.required;if(!n&&s)throw new e(`${this.constructor.name}: Child "${t}" cannot at the same be required and have no selector.`)}validateElements(e,i,n){if(0===i.length&&n.required)throw new t(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${n.selector}".`)}wrapChildren(t){return new Proxy(t,{get:function(t,e){if(!(e in t))throw new Error("Child has not been found.");return t[e]}})}defaultInitOptions(){return{instantiateChildListeners:[],destroyChildListeners:[]}}processInitOptions(t){const e=Object.assign(this.defaultInitOptions(),t);e.mapAlterCallback&&e.mapAlterCallback(this.map);for(const t of e.instantiateChildListeners)this.instantiateChildListeners.push(t);for(const t of e.destroyChildListeners)this.destroyChildListeners.push(t)}destroyChildren(){for(const[t,e]of Object.entries(this.children))if(e&&this.map[t].destructible)if(d(e))for(const t of e)t.destroy();else e.destroy()}}const w=Symbol("Wraplet");function m(t){return a(t,w)}const b=Symbol("Groupable"),v=Symbol("NodeTreeParent");class I{node;[w]=!0;[b]=!0;[v]=!0;childrenManager;groupsExtractor=t=>{if(t instanceof Element){const e=t.getAttribute("data-js-wraplet-groupable");if(e)return e.split(",")}return[]};destroyListeners=[];__debugNodeAccessors=[];constructor(t,e={}){if(this.node=t,!t)throw new Error("Node is required to create a wraplet.");const i=this.defineChildrenMap();e.instantiateChildListeners=[this.onChildInstantiated.bind(this)],e.destroyChildListeners=[this.onChildDestroyed.bind(this)],this.childrenManager=new g(t,i,e),this.initialize()}getNodeTreeChildren(){const t=[];for(const e of Object.values(this.children))if(d(e))for(const i of e)t.push(i);else t.push(e);return t.filter(t=>{let e=!1;return t.accessNode(t=>{e=this.node.contains(t)}),e})}setGroupsExtractor(t){this.groupsExtractor=t}getGroups(){return this.groupsExtractor(this.node)}get children(){return this.childrenManager.children}accessNode(t){this.__debugNodeAccessors.push(t),t(this.node)}destroy(){for(const t of this.destroyListeners)t(this);var t;this.destroyListeners.length=0,(t=this.node).wraplets&&t.wraplets.delete(this),this.childrenManager.destroy()}isDestroyed(t=!1){return t?this.childrenManager.isDestroyed:this.childrenManager.isGettingDestroyed||this.childrenManager.isDestroyed}get isInitialized(){return this.childrenManager.isInitialized}addDestroyListener(t){this.destroyListeners.push(t)}onChildDestroyed(t,e){}initialize(){var t;this.childrenManager.init(),(t=this.node).wraplets||(t.wraplets=new u),t.wraplets.add(this)}onChildInstantiated(t,e){}isChildInstance(t,e,i=null){return e===(i||e)&&t instanceof this.childrenManager.map[e].Class}static createWraplets(t,e,i=[]){if(this===I)throw new Error("You cannot instantiate an abstract class.");let n=t.parentNode,s=null;n||(t instanceof Document?n=t:(s=document.createElement("div"),s.appendChild(t),n=s));const r=[],o=n.querySelectorAll(e);s&&s.removeChild(t);for(const t of o)r.push(new this(t,...i));return r}}class E extends h{[c]=!0}export{I as AbstractWraplet,g as DefaultChildrenManager,u as DefaultWrapletSet,E as DefaultWrapletSetReadonly,C as destroyWrapletsRecursively,f as getWrapletsFromNode,m 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,UAAkCC,OAExC,MAAMC,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AAgH,CAAiB7G,EAAOiB,GAAM,CAC9B,UAAA6F,GACI9F,KAAKyF,KAAKrF,MACd,CAIA,mBAAAuF,CAEA3G,EAEAiB,GAAM,CAaN,eAAA8F,CAAgBnF,EAAMoF,EAAiBC,EAAS,MAC5C,OAAQD,KAAqBC,GAAUD,IACnCpF,aAAgBZ,KAAKyF,KAAKpG,IAAI2G,GAAwB,KAC9D,CAIA,qBAAOE,CAAe1H,EAAMoD,EAAUuE,EAAkB,IACpD,GAAInG,gBAAgBwF,EAChB,MAAM,IAAIvH,MAAM,6CAEpB,IAAImI,EAAa5H,EAAK6H,WAGlBC,EAAa,KACZF,IACG5H,aAAgB+H,SAChBH,EAAa5H,GAGb8H,EAAaE,SAASC,cAAc,OACpCH,EAAWI,YAAYlI,GACvB4H,EAAaE,IAGrB,MAAMK,EAAS,GACTC,EAAgBR,EAAWtE,iBAAiBF,GAC9C0E,GACAA,EAAWzD,YAAYrE,GAE3B,IAAK,MAAMqI,KAAWD,EAClBD,EAAOpG,KAAK,IAAIP,KAAK6G,KAAYV,IAErC,OAAOQ,CACX,EClGW,MAAMG,EACjBC,aAAe,GACf,qBAAAC,CAAsBnI,GAClBmB,KAAK+G,aAAaxG,KAAK1B,EAC3B,CACA,kBAAAoI,CAAmBzI,GACf,IAAK,MAAM0I,KAAelH,KAAK+G,aAC3BG,EAAY1I,EAEpB,CACA,eAAA2I,CAAgB3I,GACZS,EAA2BT,EAC/B,ECZJ,IAAI4I,EAAuB,KACpB,SAASC,IAIZ,OAHKD,IACDA,EAAuB,IAAIN,GAExBM,CACX,Q","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/Core.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/DefaultWrapletManager.ts","webpack://wraplet/./src/getGlobalWrapletManager.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class ValidationMissingError extends Error {\n}\nexport class InvalidOptionsError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\n","export function isWraplet(obj) {\n return (typeof obj === \"object\" &&\n obj !== null &&\n \"isWraplet\" in obj &&\n obj.isWraplet === true);\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!Array.isArray(wraplets)) {\n return [];\n }\n return wraplets;\n}\nexport function actOnNodesRecursevily(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursevily(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursevily(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, } from \"./errors\";\nimport { isWraplet } from \"./utils\";\nexport class Core {\n node;\n map;\n wraplet;\n initOptions;\n isDestroyed = false;\n isInitialized = false;\n instantiatedChildren;\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n destroyListeners = [];\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, wraplet, initOptions = {}) {\n this.node = node;\n this.map = map;\n this.wraplet = wraplet;\n this.initOptions = initOptions;\n for (const id in map) {\n map[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\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 child listeners) that needs access to the core, so core has to\n * exist already.\n */\n init() {\n const children = this.instantiateChildren(this.node);\n this.instantiatedChildren = this.wrapChildren(children);\n if (!this.node.wraplets) {\n this.node.wraplets = [];\n }\n this.node.wraplets.push(this.wraplet);\n this.isInitialized = true;\n }\n instantiateChildren(node) {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!this.isParentNode(node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren(this.node);\n }\n isCorrectSingleWrapletInstanceGuard(item, id) {\n return item instanceof this.map[id].Class;\n }\n findExistingWraplet(id, childElement) {\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = childElement.wraplets || [];\n if (this.map[id][\"multiple\"]) {\n if (!Array.isArray(existingChild)) {\n throw new Error(\"Internal logic error. Expected an array.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n else if (intersection.length > 1) {\n throw new Error(\"Internal logic error. Multiple wraplets found for the same child.\");\n }\n }\n else if (this.instantiatedChildren[id] !== null) {\n return existingChild;\n }\n return null;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new Error(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args || [];\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return [];\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : [];\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n if (!wraplet) {\n continue;\n }\n if (!this.isCorrectSingleWrapletInstanceGuard(wraplet, id)) {\n throw new Error(`${this.constructor.name}: The \"${id}\" child is not an array of the expected type.`);\n }\n items.push(wraplet);\n }\n return items;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args = []) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = (wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n };\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method allows executing the specified method on the wraplet and all its children.\n * The original wraplet and all children need to have this method implemented.\n */\n executeOnChildren(children, method, payload) {\n for (const childEntries of Object.entries(children)) {\n const name = childEntries[0];\n const child = childEntries[1];\n const map = this.map;\n if (!map[name].destructible) {\n continue;\n }\n if (Array.isArray(child)) {\n // We need to loop through the copy of the array because some items can be removed from\n // the original during the loop.\n const childArray = child.slice(0);\n for (const item of childArray) {\n if (!isWraplet(item)) {\n throw new Error(\"Internal logic error. Item is not a wraplet.\");\n }\n if (!this.wrapletHasMethodGuard(item, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n item[method](payload);\n }\n else {\n item[method]();\n }\n }\n }\n else if (isWraplet(child)) {\n if (!this.wrapletHasMethodGuard(child, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n child[method](payload);\n }\n else {\n child[method]();\n }\n }\n }\n }\n /**\n * This method removes from nodes references to this wraplet and its children recuresively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new Error(\"Wraplet is already destroyed.\");\n }\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n for (const listener of this.destroyListeners) {\n listener(this.wraplet);\n }\n this.destroyListeners.length = 0;\n this.removeWrapletFromNode(this.wraplet, this.node);\n this.executeOnChildren(this.children, \"destroy\");\n this.isDestroyed = true;\n }\n /**\n * Remove the wraplet from the list of wraplets.\n */\n removeWrapletFromNode(wraplet, node) {\n const index = node.wraplets?.findIndex((value) => {\n return value === wraplet;\n });\n if (index !== undefined && index > -1) {\n node.wraplets?.splice(index, 1);\n }\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n wrapletHasMethodGuard(wraplet, method) {\n return typeof wraplet[method] === \"function\";\n }\n isParentNode(node) {\n return typeof node.querySelectorAll === \"function\";\n }\n childTypeGuard(variable, id) {\n const map = this.map;\n const Class = map[id].Class;\n const isRequired = map[id].required;\n const isMultiple = map[id].multiple;\n if (isMultiple) {\n if (!Array.isArray(variable)) {\n return false;\n }\n if (isRequired) {\n return variable.every((value) => value instanceof Class);\n }\n return true;\n }\n if (isRequired) {\n return variable instanceof Class;\n }\n return variable instanceof Class || variable === null;\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (Array.isArray(this.instantiatedChildren[id])) {\n const index = this.instantiatedChildren[id].findIndex((value) => {\n return value === wraplet;\n });\n if (index === -1) {\n throw new Error(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n this.instantiatedChildren[id].splice(index, 1);\n return;\n }\n if (this.map[id].required) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n const setB = new Set(b);\n return [...new Set(a)].filter((x) => setB.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${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 children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n function isDestroyed(wraplet) {\n return wraplet.isDestroyed;\n }\n const child = target[name];\n if (Array.isArray(child)) {\n const destroyed = child.find(isDestroyed);\n if (destroyed) {\n throw new Error(\"Core error: One of the children in the array has been destroyed but not removed\");\n }\n return target[name];\n }\n if (child !== null && isDestroyed(child)) {\n throw new Error(\"The child has been destroyed\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n}\n","import { Core } from \"./Core\";\nexport class AbstractWraplet {\n isWraplet = true;\n core;\n constructor(node, initOptions = {}) {\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.core = new Core(node, map, this, initOptions);\n this.initialize();\n }\n get node() {\n return this.core.node;\n }\n get children() {\n return this.core.children;\n }\n accessNode(callback) {\n this.core.accessNode(callback);\n }\n destroy() {\n this.core.destroy();\n }\n get isDestroyed() {\n return this.core.isDestroyed;\n }\n get isInitialized() {\n return this.core.isInitialized;\n }\n addDestroyListener(callback) {\n this.core.addDestroyListener(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.core.init();\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.core.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this instanceof AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nexport default class DefaultWrapletManager {\n initializers = [];\n addWrapletInitializer(callback) {\n this.initializers.push(callback);\n }\n initializeNodeTree(node) {\n for (const initializer of this.initializers) {\n initializer(node);\n }\n }\n destroyNodeTree(node) {\n destroyWrapletsRecursively(node);\n }\n}\n","import DefaultWrapletManager from \"./DefaultWrapletManager\";\nlet globalWrapletManager = null;\nexport function getGlobalWrapletManager() {\n if (!globalWrapletManager) {\n globalWrapletManager = new DefaultWrapletManager();\n }\n return globalWrapletManager;\n}\n"],"names":["MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","isWraplet","obj","getWrapletsFromNode","node","wraplets","Array","isArray","actOnNodesRecursevily","callback","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","Core","map","initOptions","isDestroyed","isInitialized","instantiatedChildren","__debugNodeAccessors","destroyListeners","destroyChildListeners","instantiateChildListeners","listeners","constructor","this","id","addDefaultsToChildDefinition","processInitOptions","init","instantiateChildren","wrapChildren","push","isParentNode","Object","keys","length","item","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","isCorrectSingleWrapletInstanceGuard","Class","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","querySelectorAll","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","accessNode","addDestroyListener","addDestroyChildListener","addInstantiateChildListener","removeChild","executeOnChildren","method","payload","childEntries","entries","destructible","childArray","slice","wrapletHasMethodGuard","String","eventName","options","removeEventListener","removeWrapletFromNode","index","findIndex","value","splice","definition","childTypeGuard","variable","isRequired","required","every","addEventListener","uninitializedChildren","a","b","setB","Set","filter","x","has","elements","Proxy","get","target","find","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","AbstractWraplet","core","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","result","foundElements","element","DefaultWrapletManager","initializers","addWrapletInitializer","initializeNodeTree","initializer","destroyNodeTree","globalWrapletManager","getGlobalWrapletManager"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"AAAO,MAAMA,UAAkCC,OAExC,MAAMC,UAAiBD,OAEvB,MAAME,UAAoCF,OAE1C,MAAMG,UAAqCH,OAI3C,MAAMI,UAAkCJ,OAExC,MAAMK,UAAyCL,OAE/C,MAAMM,UAA2BN,OCVxC,MAAM,EAAK,CAACO,EAAQC,IACU,iBAAXD,GACA,OAAXA,IACmB,IAAnBA,EAAOC,GCNTC,EAAmBC,OAAO,cAEzB,SAASC,EAAaJ,GACzB,OAAO,EAAGA,EAAQE,EACtB,CCLO,MAAMG,UAA6BC,IACtC,IAAAC,CAAKC,GACD,MAAMC,EA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AaE,IAGrB,MAAMd,EAAS,GACTmB,EAAgBP,EAAW7F,iBAAiBkB,GAC9C6E,GACAA,EAAW5D,YAAY9D,GAE3B,IAAK,MAAMgI,KAAWD,EAClBnB,EAAOxH,KAAK,IAAID,KAAK6I,KAAYT,IAErC,OAAOX,CACX,EC1JG,MAAMqB,UAAkCpJ,EAC3C,CAACgB,IAA4B,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/types/Utils.ts","webpack://wraplet/./src/types/Set/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/types/Set/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/types/ChildrenManager.ts","webpack://wraplet/./src/DefaultChildrenManager.ts","webpack://wraplet/./src/types/Wraplet.ts","webpack://wraplet/./src/types/Groupable.ts","webpack://wraplet/./src/types/NodeTreeParent.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","/* istanbul ignore next */\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\";\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/Set/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol } from \"../types/Set/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\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) || wraplets.size === 0) {\n return new DefaultWrapletSet();\n }\n return wraplets;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n if (!node.wraplets) {\n return false;\n }\n return node.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 function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursively(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","const ChildrenManagerSymbol = Symbol(\"ChildrenManager\");\nexport { ChildrenManagerSymbol };\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, ChildrenTooManyFoundError, ChildrenAreAlreadyDestroyedError, InternalLogicError, } from \"./errors\";\nimport { getWrapletsFromNode, isParentNode } from \"./utils\";\nimport { ChildrenManagerSymbol, } from \"./types/ChildrenManager\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nimport { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nexport class DefaultChildrenManager {\n node;\n [ChildrenManagerSymbol] = true;\n isDestroyed = false;\n isGettingDestroyed = false;\n isInitialized = false;\n map;\n instantiatedChildren;\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, initOptions = {}) {\n this.node = node;\n this.map = this.fillMapWithDefaults(map);\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\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 child listeners) that needs access to the children manager,\n * so the children manager has to exist already.\n */\n init() {\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n this.isInitialized = true;\n }\n instantiateChildren() {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, this.node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, this.node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren();\n }\n findExistingWraplet(id, childElement) {\n // If a child doesn't have instantiated wraplets yet, then return null.\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = getWrapletsFromNode(childElement);\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingChild)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n throw new InternalLogicError(\"Internal logic error. Multiple instances of the same child found on a single node.\");\n }\n // Handle single.\n return existingChild;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new ChildrenTooManyFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args;\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : new DefaultWrapletSet();\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n items.add(wraplet);\n }\n return items;\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = ((wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n });\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method removes from nodes references to this wraplet and its children recursively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new ChildrenAreAlreadyDestroyedError(\"Children are already destroyed.\");\n }\n this.isGettingDestroyed = true;\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n this.destroyChildren();\n this.isGettingDestroyed = false;\n this.isDestroyed = true;\n }\n fillMapWithDefaults(map) {\n const newMap = {};\n for (const id in map) {\n newMap[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n return newMap;\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (isWrapletSet(this.instantiatedChildren[id])) {\n if (!this.instantiatedChildren[id].delete(wraplet)) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n return;\n }\n if (this.map[id].required && !this.isGettingDestroyed) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n if (this.instantiatedChildren[id] === null) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's already null.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n return [...a].filter((x) => b.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${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 children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n destroyChildren() {\n for (const [key, child] of Object.entries(this.children)) {\n if (!child || !this.map[key][\"destructible\"]) {\n continue;\n }\n if (isWrapletSet(child)) {\n for (const item of child) {\n item.destroy();\n }\n }\n else {\n child.destroy();\n }\n }\n }\n}\n","import { is } from \"./Utils\";\nconst WrapletSymbol = Symbol(\"Wraplet\");\nexport { WrapletSymbol };\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","import { is } from \"./Utils\";\nconst GroupableSymbol = Symbol(\"Groupable\");\nexport { GroupableSymbol };\n/* istanbul ignore next */\nexport function isGroupable(object) {\n return is(object, GroupableSymbol);\n}\nconst defaultGroupableAttribute = \"data-js-wraplet-groupable\";\nexport { defaultGroupableAttribute };\n","const NodeTreeParentSymbol = Symbol(\"NodeTreeParent\");\nexport { NodeTreeParentSymbol };\n/* istanbul ignore next */\nexport function isNodeTreeParent(object) {\n return (object[NodeTreeParentSymbol] ===\n true);\n}\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { DefaultChildrenManager } from \"./DefaultChildrenManager\";\nimport { defaultGroupableAttribute, GroupableSymbol, } from \"./types/Groupable\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { addWrapletToNode, removeWrapletFromNode } from \"./utils\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n [GroupableSymbol] = true;\n [NodeTreeParentSymbol] = true;\n childrenManager;\n groupsExtractor = (node) => {\n if (node instanceof Element) {\n const groupsString = node.getAttribute(defaultGroupableAttribute);\n if (groupsString) {\n return groupsString.split(\",\");\n }\n }\n return [];\n };\n destroyListeners = [];\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n constructor(node, initOptions = {}) {\n this.node = node;\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.childrenManager = new DefaultChildrenManager(node, map, initOptions);\n this.initialize();\n }\n getNodeTreeChildren() {\n const children = [];\n for (const child of Object.values(this.children)) {\n if (isWrapletSet(child)) {\n for (const item of child) {\n children.push(item);\n }\n }\n else {\n children.push(child);\n }\n }\n // Return only descendants.\n return children.filter((child) => {\n let result = false;\n child.accessNode((childsNode) => {\n result = this.node.contains(childsNode);\n });\n return result;\n });\n }\n setGroupsExtractor(callback) {\n this.groupsExtractor = callback;\n }\n getGroups() {\n return this.groupsExtractor(this.node);\n }\n get children() {\n return this.childrenManager.children;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n destroy() {\n for (const listener of this.destroyListeners) {\n listener(this);\n }\n this.destroyListeners.length = 0;\n removeWrapletFromNode(this, this.node);\n this.childrenManager.destroy();\n }\n isDestroyed(completely = false) {\n return completely\n ? this.childrenManager.isDestroyed\n : this.childrenManager.isGettingDestroyed ||\n this.childrenManager.isDestroyed;\n }\n get isInitialized() {\n return this.childrenManager.isInitialized;\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.childrenManager.init();\n addWrapletToNode(this, this.node);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.childrenManager.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"../types/Set/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n"],"names":["MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","ChildrenTooManyFoundError","ChildrenAreAlreadyDestroyedError","InternalLogicError","object","symbol","WrapletSetSymbol","Symbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","item","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","getWrapletsFromNode","node","wraplets","size","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","ChildrenManagerSymbol","DefaultChildrenManager","isDestroyed","isGettingDestroyed","isInitialized","map","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","constructor","initOptions","fillMapWithDefaults","processInitOptions","init","instantiateChildren","wrapChildren","querySelectorAll","Object","keys","length","id","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","newMap","addDefaultsToChildDefinition","definition","destructible","addEventListener","uninitializedChildren","delete","required","x","has","isRequired","elements","Proxy","get","target","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","key","entries","WrapletSymbol","isWraplet","GroupableSymbol","NodeTreeParentSymbol","AbstractWraplet","childrenManager","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","getNodeTreeChildren","values","result","accessNode","childsNode","contains","setGroupsExtractor","getGroups","completely","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","foundElements","element","DefaultWrapletSetReadonly"],"sourceRoot":""}
|
package/dist/storage.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t={d:(e,s)=>{for(var
|
|
1
|
+
var t={d:(e,s)=>{for(var i in s)t.o(s,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:s[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{ElementStorage:()=>i});class s extends Error{}class i{element;attribute;validators;defaults;options;data;constructor(t,e,s,i,r={}){this.element=t,this.attribute=e,this.validators=s,this.defaults=i,this.options=r,this.options={keepFresh:!0,...r},this.data=this.fetchFreshData()}has(t){return t in this.getAll()}get(t){return this.getAll()[t]}getMultiple(t){const e=this.getAll();return t.reduce((t,s)=>(t[s]=e[s],t),{})}getAll(){return this.options.keepFresh&&this.refresh(),this.data}set(t,e){const i=this.getAll();if(!this.validators[t](e))throw new s(`Attempted to set an invalid value for the key ${String(t)}.`);i[t]=e,this.setAll(i)}setMultiple(t){const e=this.getAll();this.setAll({...e,...t})}setAll(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}delete(t){const e=this.getAll();t in e&&(delete e[t],this.element.setAttribute(this.attribute,JSON.stringify(e)))}deleteMultiple(t){const e=this.getAll();for(const s of t)delete e[s];this.setAll(e)}deleteAll(){this.element.setAttribute(this.attribute,""),this.refresh()}refresh(){this.data=this.fetchFreshData()}fetchFreshData(){const t=this.getAttributeValue(this.attribute);if(t){if("{"!==t.charAt(0))throw new s("Data has to be defined as an object.");const e=JSON.parse(t);if(!this.validateData(e))throw new s("Invalid storage value.");return{...this.defaults,...e}}return{...this.defaults}}validateData(t){for(const e in t)if(!this.validators[e](t[e]))return!1;return!0}getAttributeValue(t){return this.element.getAttribute(t)}}var r=exports;for(var l in e)r[l]=e[l];e.__esModule&&Object.defineProperty(r,"__esModule",{value:!0});
|
|
2
2
|
//# sourceMappingURL=storage.cjs.map
|
package/dist/storage.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.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,
|
|
1
|
+
{"version":3,"file":"storage.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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ACPR,EAAKtB,GAEhBwB,KAAKY,OAAOd,EAChB,CACA,SAAAqB,GACInB,KAAKP,QAAQsB,aAAaf,KAAKN,UAAW,IAC1CM,KAAKS,SACT,CACA,OAAAA,GACIT,KAAKF,KAAOE,KAAKE,gBACrB,CACA,cAAAA,GACI,MAAMkB,EAAapB,KAAKqB,kBAAkBrB,KAAKN,WAC/C,GAAI0B,EAAY,CACZ,GAA6B,MAAzBA,EAAWE,OAAO,GAClB,MAAM,IAAIhC,EAAuB,wCAErC,MAAMQ,EAAOkB,KAAKO,MAAMH,GACxB,IAAKpB,KAAKwB,aAAa1B,GACnB,MAAM,IAAIR,EAAuB,0BAErC,MAAO,IAAKU,KAAKJ,YAAaE,EAClC,CACA,MAAO,IAAKE,KAAKJ,SACrB,CACA,YAAA4B,CAAa1B,GACT,IAAK,MAAMtB,KAAOsB,EACd,IAAKE,KAAKL,WAAWnB,GAAKsB,EAAKtB,IAC3B,OAAO,EAGf,OAAO,CACX,CACA,iBAAA6C,CAAkB3B,GACd,OAAOM,KAAKP,QAAQgC,aAAa/B,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/Storage/ElementStorage.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 MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class ElementStorage {\n element;\n attribute;\n validators;\n defaults;\n options;\n data;\n constructor(element, attribute, validators, defaults, options = {}) {\n this.element = element;\n this.attribute = attribute;\n this.validators = validators;\n this.defaults = defaults;\n this.options = options;\n this.options = {\n keepFresh: true,\n ...options,\n };\n this.data = this.fetchFreshData();\n }\n has(key) {\n const data = this.getAll();\n return key in data;\n }\n get(key) {\n const data = this.getAll();\n return data[key];\n }\n getMultiple(keys) {\n const data = this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n getAll() {\n if (this.options.keepFresh) {\n this.refresh();\n }\n return this.data;\n }\n set(key, value) {\n const data = this.getAll();\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n data[key] = value;\n this.setAll(data);\n }\n setMultiple(data) {\n const oldData = this.getAll();\n this.setAll({ ...oldData, ...data });\n }\n setAll(data) {\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n delete(key) {\n const data = this.getAll();\n if (!(key in data)) {\n return;\n }\n delete data[key];\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n deleteMultiple(keys) {\n const data = this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n this.setAll(data);\n }\n deleteAll() {\n this.element.setAttribute(this.attribute, \"\");\n this.refresh();\n }\n refresh() {\n this.data = this.fetchFreshData();\n }\n fetchFreshData() {\n const dataString = this.getAttributeValue(this.attribute);\n if (dataString) {\n if (dataString.charAt(0) !== \"{\") {\n throw new StorageValidationError(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return { ...this.defaults, ...data };\n }\n return { ...this.defaults };\n }\n validateData(data) {\n for (const key in data) {\n if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n getAttributeValue(attribute) {\n return this.element.getAttribute(attribute);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","StorageValidationError","Error","ElementStorage","element","attribute","validators","defaults","options","data","constructor","this","keepFresh","fetchFreshData","has","getAll","getMultiple","keys","reduce","acc","refresh","set","String","setAll","setMultiple","oldData","setAttribute","JSON","stringify","deleteMultiple","deleteAll","dataString","getAttributeValue","charAt","parse","validateData","getAttribute"],"sourceRoot":""}
|
package/dist/storage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t extends Error{}class e{element;attribute;validators;defaults;options;data;constructor(t,e,s,i,r={}){this.element=t,this.attribute=e,this.validators=s,this.defaults=i,this.options=r,this.options={keepFresh:!0,...r},this.data=this.fetchFreshData()}has(t){return t in this.getAll()}get(t){return this.getAll()[t]}getMultiple(t){const e=this.getAll();return t.reduce((t,s)=>(t[s]=e[s],t),{})}getAll(){return this.options.keepFresh&&this.refresh(),this.data}set(e,s){const i=this.getAll();if(!this.validators[e](s))throw new t(`Attempted to set an invalid value for the key ${String(e)}.`);i[e]=s,this.setAll(i)}setMultiple(t){const e=this.getAll();this.setAll({...e,...t})}setAll(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}delete(t){const e=this.getAll();e
|
|
1
|
+
class t extends Error{}class e{element;attribute;validators;defaults;options;data;constructor(t,e,s,i,r={}){this.element=t,this.attribute=e,this.validators=s,this.defaults=i,this.options=r,this.options={keepFresh:!0,...r},this.data=this.fetchFreshData()}has(t){return t in this.getAll()}get(t){return this.getAll()[t]}getMultiple(t){const e=this.getAll();return t.reduce((t,s)=>(t[s]=e[s],t),{})}getAll(){return this.options.keepFresh&&this.refresh(),this.data}set(e,s){const i=this.getAll();if(!this.validators[e](s))throw new t(`Attempted to set an invalid value for the key ${String(e)}.`);i[e]=s,this.setAll(i)}setMultiple(t){const e=this.getAll();this.setAll({...e,...t})}setAll(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}delete(t){const e=this.getAll();t in e&&(delete e[t],this.element.setAttribute(this.attribute,JSON.stringify(e)))}deleteMultiple(t){const e=this.getAll();for(const s of t)delete e[s];this.setAll(e)}deleteAll(){this.element.setAttribute(this.attribute,""),this.refresh()}refresh(){this.data=this.fetchFreshData()}fetchFreshData(){const e=this.getAttributeValue(this.attribute);if(e){if("{"!==e.charAt(0))throw new t("Data has to be defined as an object.");const s=JSON.parse(e);if(!this.validateData(s))throw new t("Invalid storage value.");return{...this.defaults,...s}}return{...this.defaults}}validateData(t){for(const e in t)if(!this.validators[e](t[e]))return!1;return!0}getAttributeValue(t){return this.element.getAttribute(t)}}export{e as ElementStorage};
|
|
2
2
|
//# sourceMappingURL=storage.js.map
|
package/dist/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","mappings":"
|
|
1
|
+
{"version":3,"file":"storage.js","mappings":"AAQO,MAAMA,UAA+BC,OCPrC,MAAMC,EACTC,QACAC,UACAC,WACAC,SACAC,QACAC,KACA,WAAAC,CAAYN,EAASC,EAAWC,EAAYC,EAAUC,EAAU,CAAC,GAC7DG,KAAKP,QAAUA,EACfO,KAAKN,UAAYA,EACjBM,KAAKL,WAAaA,EAClBK,KAAKJ,SAAWA,EAChBI,KAAKH,QAAUA,EACfG,KAAKH,QAAU,CACXI,WAAW,KACRJ,GAEPG,KAAKF,KAAOE,KAAKE,gBACrB,CACA,GAAAC,CAAIC,GAEA,OAAOA,KADMJ,KAAKK,QAEtB,CACA,GAAAC,CAAIF,GAEA,OADaJ,KAAKK,SACND,EAChB,CAC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AO,IAAKE,KAAKJ,SACrB,CACA,YAAA+B,CAAa7B,GACT,IAAK,MAAMM,KAAON,EACd,IAAKE,KAAKL,WAAWS,GAAKN,EAAKM,IAC3B,OAAO,EAGf,OAAO,CACX,CACA,iBAAAoB,CAAkB9B,GACd,OAAOM,KAAKP,QAAQmC,aAAalC,EACrC,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class ElementStorage {\n element;\n attribute;\n validators;\n defaults;\n options;\n data;\n constructor(element, attribute, validators, defaults, options = {}) {\n this.element = element;\n this.attribute = attribute;\n this.validators = validators;\n this.defaults = defaults;\n this.options = options;\n this.options = {\n keepFresh: true,\n ...options,\n };\n this.data = this.fetchFreshData();\n }\n has(key) {\n const data = this.getAll();\n return key in data;\n }\n get(key) {\n const data = this.getAll();\n return data[key];\n }\n getMultiple(keys) {\n const data = this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n getAll() {\n if (this.options.keepFresh) {\n this.refresh();\n }\n return this.data;\n }\n set(key, value) {\n const data = this.getAll();\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n data[key] = value;\n this.setAll(data);\n }\n setMultiple(data) {\n const oldData = this.getAll();\n this.setAll({ ...oldData, ...data });\n }\n setAll(data) {\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n delete(key) {\n const data = this.getAll();\n if (!(key in data)) {\n return;\n }\n delete data[key];\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n deleteMultiple(keys) {\n const data = this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n this.setAll(data);\n }\n deleteAll() {\n this.element.setAttribute(this.attribute, \"\");\n this.refresh();\n }\n refresh() {\n this.data = this.fetchFreshData();\n }\n fetchFreshData() {\n const dataString = this.getAttributeValue(this.attribute);\n if (dataString) {\n if (dataString.charAt(0) !== \"{\") {\n throw new StorageValidationError(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return { ...this.defaults, ...data };\n }\n return { ...this.defaults };\n }\n validateData(data) {\n for (const key in data) {\n if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n getAttributeValue(attribute) {\n return this.element.getAttribute(attribute);\n }\n}\n"],"names":["StorageValidationError","Error","ElementStorage","element","attribute","validators","defaults","options","data","constructor","this","keepFresh","fetchFreshData","has","key","getAll","get","getMultiple","keys","reduce","acc","refresh","set","value","String","setAll","setMultiple","oldData","setAttribute","JSON","stringify","deleteMultiple","deleteAll","dataString","getAttributeValue","charAt","parse","validateData","getAttribute"],"sourceRoot":""}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { WrapletChildren } from "./WrapletChildren";
|
|
2
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "./WrapletChildrenMap";
|
|
3
|
+
import { DestroyChildListener } from "./DestroyChildListener";
|
|
4
|
+
import { InstantiateChildListener } from "./InstantiateChildListener";
|
|
5
|
+
declare const ChildrenManagerSymbol: unique symbol;
|
|
6
|
+
export { ChildrenManagerSymbol };
|
|
7
|
+
/**
|
|
8
|
+
* Children manager interface that defines the public API for managing wraplet relationships
|
|
9
|
+
* and lifecycles.
|
|
10
|
+
*/
|
|
11
|
+
export interface ChildrenManager<M extends WrapletChildrenMap = {}, N extends Node = Node> {
|
|
12
|
+
[ChildrenManagerSymbol]: true;
|
|
13
|
+
/**
|
|
14
|
+
* Indicates whether the core is destroyed.
|
|
15
|
+
*/
|
|
16
|
+
isDestroyed: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Indicates whether the core is in the process of being destroyed.
|
|
19
|
+
*/
|
|
20
|
+
isGettingDestroyed: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Indicates whether the core has been initialized.
|
|
23
|
+
*/
|
|
24
|
+
isInitialized: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The children map that defines the relationships between nodes.
|
|
27
|
+
*/
|
|
28
|
+
map: WrapletChildrenMapWithDefaults<M>;
|
|
29
|
+
/**
|
|
30
|
+
* Initialize the core.
|
|
31
|
+
* This must be called after construction to fully initialize the core.
|
|
32
|
+
*/
|
|
33
|
+
init(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Instantiate children based on the map and the current node.
|
|
36
|
+
*/
|
|
37
|
+
instantiateChildren(node: N): WrapletChildren<M>;
|
|
38
|
+
/**
|
|
39
|
+
* Synchronize the children instances with the DOM.
|
|
40
|
+
*/
|
|
41
|
+
syncChildren(): void;
|
|
42
|
+
/**
|
|
43
|
+
* Add a listener that will be called when a child is destroyed.
|
|
44
|
+
*/
|
|
45
|
+
addDestroyChildListener(callback: DestroyChildListener<M, keyof M>): void;
|
|
46
|
+
/**
|
|
47
|
+
* Add a listener that will be called when a child is instantiated.
|
|
48
|
+
*/
|
|
49
|
+
addInstantiateChildListener(callback: InstantiateChildListener<M, keyof M>): void;
|
|
50
|
+
/**
|
|
51
|
+
* Destroy all children.
|
|
52
|
+
*/
|
|
53
|
+
destroy(): void;
|
|
54
|
+
/**
|
|
55
|
+
* Add an event listener to a node and track it for cleanup.
|
|
56
|
+
*/
|
|
57
|
+
addEventListener(node: Node, eventName: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* Get the instantiated children.
|
|
60
|
+
*/
|
|
61
|
+
readonly children: WrapletChildren<M>;
|
|
62
|
+
/**
|
|
63
|
+
* Get the partially initialized children (before initialization is complete).
|
|
64
|
+
*/
|
|
65
|
+
readonly uninitializedChildren: Partial<WrapletChildren<M>>;
|
|
66
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type GroupExtractor = (node: Node) => string[];
|
|
2
|
+
declare const GroupableSymbol: unique symbol;
|
|
3
|
+
export { GroupableSymbol };
|
|
4
|
+
export interface Groupable {
|
|
5
|
+
[GroupableSymbol]: true;
|
|
6
|
+
setGroupsExtractor(callback: GroupExtractor): void;
|
|
7
|
+
getGroups(): string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function isGroupable(object: unknown): object is Groupable;
|
|
10
|
+
declare const defaultGroupableAttribute = "data-js-wraplet-groupable";
|
|
11
|
+
export { defaultGroupableAttribute };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Wraplet } from "./Wraplet";
|
|
2
|
+
declare const NodeTreeParentSymbol: unique symbol;
|
|
3
|
+
export { NodeTreeParentSymbol };
|
|
4
|
+
export interface NodeTreeParent {
|
|
5
|
+
[NodeTreeParentSymbol]: true;
|
|
6
|
+
getNodeTreeChildren(): Wraplet[];
|
|
7
|
+
}
|
|
8
|
+
export declare function isNodeTreeParent(object: object): object is NodeTreeParent;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Wraplet } from "../Wraplet";
|
|
2
|
+
import { BaseSet } from "./BaseSet";
|
|
3
|
+
declare const WrapletSetSymbol: unique symbol;
|
|
4
|
+
export { WrapletSetSymbol };
|
|
5
|
+
export interface WrapletSet<W extends Wraplet = Wraplet> extends BaseSet<W>, Set<W> {
|
|
6
|
+
[WrapletSetSymbol]: true;
|
|
7
|
+
}
|
|
8
|
+
export declare function isWrapletSet<W extends Wraplet>(object: unknown): object is WrapletSet<W>;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Wraplet } from "../Wraplet";
|
|
2
|
+
import { BaseSet } from "./BaseSet";
|
|
3
|
+
declare const WrapletSetReadonlySymbol: unique symbol;
|
|
4
|
+
export { WrapletSetReadonlySymbol };
|
|
5
|
+
export interface WrapletSetReadonly<T extends Wraplet = Wraplet> extends BaseSet<T>, ReadonlySet<T> {
|
|
6
|
+
[WrapletSetReadonlySymbol]: true;
|
|
7
|
+
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { DestroyListener } from "./DestroyListener";
|
|
2
|
+
declare const WrapletSymbol: unique symbol;
|
|
3
|
+
export { WrapletSymbol };
|
|
2
4
|
export interface Wraplet<N extends Node = Node> {
|
|
3
|
-
|
|
4
|
-
isDestroyed: boolean;
|
|
5
|
+
[WrapletSymbol]: true;
|
|
5
6
|
isInitialized: boolean;
|
|
7
|
+
isDestroyed(completely: boolean): boolean;
|
|
6
8
|
accessNode(callback: (node: N) => void): void;
|
|
7
9
|
destroy(): void;
|
|
8
10
|
addDestroyListener(callback: DestroyListener<N>): void;
|
|
9
11
|
}
|
|
12
|
+
export declare function isWraplet<N extends Node>(object: unknown): object is Wraplet<N>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WrapletChildrenMap } from "./WrapletChildrenMap";
|
|
2
2
|
import { InstantiableReturnType } from "./Utils";
|
|
3
|
+
import { WrapletSet } from "./Set/WrapletSet";
|
|
3
4
|
export type OptionalSingleInstantiableReturnType<T extends WrapletChildrenMap, K extends keyof T> = T[K]["required"] extends true ? InstantiableReturnType<T[K]["Class"]> : InstantiableReturnType<T[K]["Class"]> | null;
|
|
4
5
|
export type WrapletChildren<T extends WrapletChildrenMap> = {
|
|
5
|
-
[id in keyof T]: T[id]["multiple"] extends true ? InstantiableReturnType<T[id]["Class"]
|
|
6
|
+
[id in keyof T]: T[id]["multiple"] extends true ? WrapletSet<InstantiableReturnType<T[id]["Class"]>> : OptionalSingleInstantiableReturnType<T, id>;
|
|
6
7
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { WrapletChildDefinition, WrapletChildDefinitionWithDefaults } from "./WrapletChildDefinition";
|
|
2
|
+
export type WrapletChildrenMap = {
|
|
3
|
+
[id: string]: WrapletChildDefinition;
|
|
4
|
+
};
|
|
5
|
+
export type WrapletChildrenMapWithDefaults<M extends WrapletChildrenMap> = {
|
|
6
|
+
[key in keyof M]: WrapletChildDefinitionWithDefaults<M[key]>;
|
|
7
|
+
};
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Wraplet } from "./types/Wraplet";
|
|
2
|
+
import { WrapletSet } from "./types/Set/WrapletSet";
|
|
3
|
+
export declare function isParentNode(node: Node): node is ParentNode;
|
|
4
|
+
export declare function getWrapletsFromNode<N extends Node = Node, W extends Wraplet<N> = Wraplet<N>>(node: N): WrapletSet<W>;
|
|
5
|
+
export declare function removeWrapletFromNode<N extends Node>(wraplet: Wraplet<N>, node: N): boolean;
|
|
6
|
+
export declare function addWrapletToNode<N extends Node>(wraplet: Wraplet<N>, node: N): void;
|
|
7
|
+
export declare function actOnNodesRecursively(node: Node, callback: (node: Node) => void): void;
|
|
8
|
+
export declare function destroyWrapletsRecursively(node: Node): void;
|
package/package.json
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wraplet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
9
10
|
"import": "./dist/index.js",
|
|
10
|
-
"require": "./dist/index.cjs"
|
|
11
|
-
"types": "./dist/typescript/index.d.ts"
|
|
11
|
+
"require": "./dist/index.cjs"
|
|
12
12
|
},
|
|
13
13
|
"./storage": {
|
|
14
|
+
"types": "./dist/storage.d.ts",
|
|
14
15
|
"import": "./dist/storage.js",
|
|
15
|
-
"require": "./dist/storage.cjs"
|
|
16
|
-
"types": "./dist/typescript/storage.d.ts"
|
|
16
|
+
"require": "./dist/storage.cjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
@@ -32,30 +32,31 @@
|
|
|
32
32
|
"dev:watch": "NODE_OPTIONS='--no-experimental-strip-types --import tsx' node ./node_modules/.bin/webpack --mode development --watch --config ./webpack.config.ts",
|
|
33
33
|
"lint": "tsc --noemit && npx eslint './src/**/*.ts' './tests/**/*.ts'",
|
|
34
34
|
"lint:fix": "npx eslint './src/**/*.ts' './tests/**/*.ts' --fix",
|
|
35
|
-
"tests": "jest"
|
|
35
|
+
"tests": "jest --coverage"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@eslint/js": "^9.
|
|
39
|
+
"@eslint/js": "^9.34.0",
|
|
40
40
|
"@types/jest": "^30.0.0",
|
|
41
|
-
"@types/node": "^24.
|
|
41
|
+
"@types/node": "^24.3.0",
|
|
42
42
|
"@types/webpack": "^5.28.5",
|
|
43
43
|
"esbuild-register": "^3.6.0",
|
|
44
|
-
"eslint": "^9.
|
|
45
|
-
"eslint-config-prettier": "^10.1.
|
|
46
|
-
"eslint-plugin-prettier": "^5.5.
|
|
47
|
-
"globals": "^16.
|
|
48
|
-
"jest": "^30.
|
|
49
|
-
"jest-cli": "^30.
|
|
50
|
-
"jest-environment-jsdom": "^30.
|
|
51
|
-
"
|
|
44
|
+
"eslint": "^9.34.0",
|
|
45
|
+
"eslint-config-prettier": "^10.1.8",
|
|
46
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
47
|
+
"globals": "^16.3.0",
|
|
48
|
+
"jest": "^30.1.2",
|
|
49
|
+
"jest-cli": "^30.1.2",
|
|
50
|
+
"jest-environment-jsdom": "^30.1.2",
|
|
51
|
+
"npx": "^10.2.2",
|
|
52
|
+
"prettier": "^3.6.2",
|
|
52
53
|
"prettier-eslint": "^16.4.2",
|
|
53
|
-
"ts-jest": "^29.4.
|
|
54
|
-
"ts-loader": "^9.5.
|
|
54
|
+
"ts-jest": "^29.4.1",
|
|
55
|
+
"ts-loader": "^9.5.4",
|
|
55
56
|
"tsx": "^4.20.3",
|
|
56
|
-
"typescript": "^5.
|
|
57
|
-
"typescript-eslint": "^8.
|
|
58
|
-
"webpack": "^5.
|
|
57
|
+
"typescript": "^5.9.2",
|
|
58
|
+
"typescript-eslint": "^8.41.0",
|
|
59
|
+
"webpack": "^5.101.3",
|
|
59
60
|
"webpack-cli": "^6.0.1"
|
|
60
61
|
}
|
|
61
62
|
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { WrapletManager } from "./types/WrapletManager";
|
|
2
|
-
export type Initializer = (node: Node) => void;
|
|
3
|
-
export default class DefaultWrapletManager implements WrapletManager {
|
|
4
|
-
private initializers;
|
|
5
|
-
addWrapletInitializer(callback: Initializer): void;
|
|
6
|
-
initializeNodeTree(node: Node): void;
|
|
7
|
-
destroyNodeTree(node: Node): void;
|
|
8
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { Core } from "./Core";
|
|
2
|
-
export { AbstractWraplet } from "./AbstractWraplet";
|
|
3
|
-
export { isWraplet, destroyWrapletsRecursively, getWrapletsFromNode, } from "./utils";
|
|
4
|
-
export { getGlobalWrapletManager } from "./getGlobalWrapletManager";
|
|
5
|
-
export type { WrapletChildrenMap } from "./types/WrapletChildrenMap";
|
|
6
|
-
export type { Wraplet } from "./types/Wraplet";
|
|
7
|
-
import "./types/global";
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import { Wraplet } from "./types/Wraplet";
|
|
2
|
-
export declare function isWraplet<N extends Node = Node>(obj: unknown): obj is Wraplet<N>;
|
|
3
|
-
export declare function getWrapletsFromNode<N extends Node = Node>(node: N): Wraplet<N>[];
|
|
4
|
-
export declare function actOnNodesRecursevily(node: Node, callback: (node: Node) => void): void;
|
|
5
|
-
export declare function destroyWrapletsRecursively(node: Node): void;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|