wraplet 0.18.0 → 0.19.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/AbstractWraplet.d.ts +10 -9
- package/dist/{DefaultChildrenManager.d.ts → DefaultCore.d.ts} +13 -9
- package/dist/Map/MapRepeat.d.ts +10 -0
- package/dist/Map/MapWrapper.d.ts +33 -0
- package/dist/WrapletChildrenMap.d.ts +4 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/{ChildrenManager.d.ts → Core.d.ts} +17 -4
- package/dist/types/CoreInitOptions.d.ts +0 -2
- package/dist/types/Map/DynamicMap.d.ts +9 -0
- package/dist/types/MapDefinitions.d.ts +3 -0
- package/dist/types/Wraplet.d.ts +3 -1
- package/dist/types/WrapletChildDefinition.d.ts +9 -2
- package/dist/types/WrapletChildrenMap.d.ts +2 -1
- package/package.json +1 -1
|
@@ -3,37 +3,38 @@ import { WrapletChildren } from "./types/WrapletChildren";
|
|
|
3
3
|
import { Wraplet, WrapletSymbol } from "./types/Wraplet";
|
|
4
4
|
import { DestroyListener } from "./types/DestroyListener";
|
|
5
5
|
import { ChildInstance } from "./types/ChildInstance";
|
|
6
|
-
import { CoreInitOptions } from "./types/CoreInitOptions";
|
|
7
6
|
import { Groupable, GroupableSymbol, GroupExtractor } from "./types/Groupable";
|
|
8
7
|
import { NodeTreeParent, NodeTreeParentSymbol } from "./types/NodeTreeParent";
|
|
9
|
-
import {
|
|
8
|
+
import { Core } from "./types/Core";
|
|
10
9
|
export declare abstract class AbstractWraplet<M extends WrapletChildrenMap = {}, N extends Node = Node> implements Wraplet<N>, Groupable, NodeTreeParent {
|
|
11
|
-
protected
|
|
10
|
+
protected core: Core<M, N>;
|
|
12
11
|
[WrapletSymbol]: true;
|
|
13
12
|
[GroupableSymbol]: true;
|
|
14
13
|
[NodeTreeParentSymbol]: true;
|
|
15
|
-
|
|
14
|
+
isGettingDestroyed: boolean;
|
|
15
|
+
isDestroyed: boolean;
|
|
16
|
+
isGettingInitialized: boolean;
|
|
17
|
+
isInitialized: boolean;
|
|
16
18
|
private groupsExtractor;
|
|
17
19
|
private destroyListeners;
|
|
18
20
|
/**
|
|
19
21
|
* This is the log of all node accessors, available for easier debugging.
|
|
20
22
|
*/
|
|
21
23
|
private __debugNodeAccessors;
|
|
22
|
-
constructor(
|
|
24
|
+
constructor(core: Core<M, N>);
|
|
23
25
|
getNodeTreeChildren(): Wraplet[];
|
|
24
26
|
setGroupsExtractor(callback: GroupExtractor): void;
|
|
25
27
|
getGroups(): string[];
|
|
26
28
|
protected get children(): WrapletChildren<M>;
|
|
27
29
|
accessNode(callback: (node: N) => void): void;
|
|
28
30
|
destroy(): void;
|
|
29
|
-
isDestroyed(completely?: boolean): boolean;
|
|
30
|
-
get isInitialized(): boolean;
|
|
31
31
|
addDestroyListener(callback: DestroyListener<N>): void;
|
|
32
32
|
/**
|
|
33
33
|
* This method will be ivoked if one of the wraplet's children has been destroyed.
|
|
34
34
|
*/
|
|
35
35
|
protected onChildDestroyed(child: ChildInstance<M, keyof M>, id: keyof M): void;
|
|
36
36
|
protected initialize(): void;
|
|
37
|
+
protected get node(): N;
|
|
37
38
|
/**
|
|
38
39
|
* This method will be ivoked if one of the wraplet's children has been instantiated.
|
|
39
40
|
*/
|
|
@@ -51,6 +52,6 @@ export declare abstract class AbstractWraplet<M extends WrapletChildrenMap = {},
|
|
|
51
52
|
* @protected
|
|
52
53
|
*/
|
|
53
54
|
protected isChildInstance<K extends keyof M>(item: ChildInstance<M, keyof M>, actualUnknownId: keyof M, onlyId?: K | null): item is ChildInstance<M, K>;
|
|
54
|
-
protected
|
|
55
|
-
protected static createWraplets<N extends Node, T extends AbstractWraplet<any, N> = never>(node: ParentNode, attribute: string, additional_args?: unknown[]): T[];
|
|
55
|
+
protected static createCore<N extends Node, M extends WrapletChildrenMap>(node: N, map: M): Core<M, N>;
|
|
56
|
+
protected static createWraplets<N extends Node, T extends AbstractWraplet<any, N> = never>(node: ParentNode, map: WrapletChildrenMap, attribute: string, additional_args?: unknown[]): T[];
|
|
56
57
|
}
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { WrapletChildren } from "./types/WrapletChildren";
|
|
2
|
+
import { Wraplet } from "./types/Wraplet";
|
|
2
3
|
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "./types/WrapletChildrenMap";
|
|
3
4
|
import { InstantiateChildListener } from "./types/InstantiateChildListener";
|
|
4
5
|
import { DestroyChildListener } from "./types/DestroyChildListener";
|
|
5
6
|
import { CoreInitOptions } from "./types/CoreInitOptions";
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
import { Core, CoreSymbol } from "./types/Core";
|
|
8
|
+
import { NodeTreeParentSymbol } from "./types/NodeTreeParent";
|
|
9
|
+
import { MapWrapper } from "./Map/MapWrapper";
|
|
10
|
+
export declare class DefaultCore<M extends WrapletChildrenMap = {}, N extends Node = Node> implements Core<M, N> {
|
|
11
|
+
node: N;
|
|
12
|
+
[CoreSymbol]: true;
|
|
13
|
+
[NodeTreeParentSymbol]: true;
|
|
10
14
|
isDestroyed: boolean;
|
|
11
15
|
isGettingDestroyed: boolean;
|
|
16
|
+
isGettingInitialized: boolean;
|
|
12
17
|
isInitialized: boolean;
|
|
13
|
-
|
|
18
|
+
mapWrapper: MapWrapper<M>;
|
|
14
19
|
private instantiatedChildren;
|
|
15
20
|
private destroyChildListeners;
|
|
16
21
|
private instantiateChildListeners;
|
|
17
22
|
private listeners;
|
|
18
|
-
constructor(node: N, map: M
|
|
23
|
+
constructor(node: N, map: M | MapWrapper<M>, initOptions?: Partial<CoreInitOptions<M>>);
|
|
19
24
|
/**
|
|
20
25
|
* Initialize core.
|
|
21
26
|
*
|
|
@@ -24,8 +29,10 @@ export declare class DefaultChildrenManager<M extends WrapletChildrenMap = {}, N
|
|
|
24
29
|
* so the children manager has to exist already.
|
|
25
30
|
*/
|
|
26
31
|
init(): void;
|
|
32
|
+
get map(): WrapletChildrenMapWithDefaults<M>;
|
|
27
33
|
instantiateChildren(): WrapletChildren<M>;
|
|
28
34
|
syncChildren(): void;
|
|
35
|
+
getNodeTreeChildren(): Wraplet[];
|
|
29
36
|
private findExistingWraplet;
|
|
30
37
|
private instantiateSingleWrapletChild;
|
|
31
38
|
private instantiateWrapletItem;
|
|
@@ -39,13 +46,10 @@ export declare class DefaultChildrenManager<M extends WrapletChildrenMap = {}, N
|
|
|
39
46
|
*/
|
|
40
47
|
destroy(): void;
|
|
41
48
|
private findChildren;
|
|
42
|
-
private fillMapWithDefaults;
|
|
43
|
-
private addDefaultsToChildDefinition;
|
|
44
49
|
addEventListener(node: Node, eventName: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
|
|
45
50
|
get children(): WrapletChildren<M>;
|
|
46
51
|
get uninitializedChildren(): Partial<WrapletChildren<M>>;
|
|
47
52
|
private removeChild;
|
|
48
|
-
private intersect;
|
|
49
53
|
private validateMapItem;
|
|
50
54
|
private validateElements;
|
|
51
55
|
/**
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { MapWrapper } from "./MapWrapper";
|
|
2
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../types/WrapletChildrenMap";
|
|
3
|
+
import { DynamicMap, DynamicMapSymbol } from "../types/Map/DynamicMap";
|
|
4
|
+
export declare class MapRepeat implements DynamicMap {
|
|
5
|
+
private readonly levels;
|
|
6
|
+
[DynamicMapSymbol]: true;
|
|
7
|
+
constructor(levels?: number);
|
|
8
|
+
create<M extends WrapletChildrenMap>(parentMapClone: MapWrapper<M>): WrapletChildrenMapWithDefaults;
|
|
9
|
+
static create(levels?: number): MapRepeat;
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../types/WrapletChildrenMap";
|
|
2
|
+
type RecursiveMapKeys<T extends WrapletChildrenMap> = {
|
|
3
|
+
[K in keyof T]: T[K] extends {
|
|
4
|
+
map: infer M extends WrapletChildrenMap;
|
|
5
|
+
} ? K | RecursiveMapKeys<M> : K;
|
|
6
|
+
}[keyof T];
|
|
7
|
+
export declare class MapWrapper<M extends WrapletChildrenMap> {
|
|
8
|
+
private readonly fullMap;
|
|
9
|
+
private startingPath;
|
|
10
|
+
private currentMap;
|
|
11
|
+
path: string[];
|
|
12
|
+
private currentPath;
|
|
13
|
+
/**
|
|
14
|
+
* @param fullMap
|
|
15
|
+
* @param path
|
|
16
|
+
* Path to the current definition.
|
|
17
|
+
* @param resolveImmediately
|
|
18
|
+
*/
|
|
19
|
+
constructor(fullMap: M, path?: (RecursiveMapKeys<M> | string)[], resolveImmediately?: boolean);
|
|
20
|
+
getStartingMap(): WrapletChildrenMapWithDefaults;
|
|
21
|
+
getCurrentMap(): WrapletChildrenMapWithDefaults;
|
|
22
|
+
/**
|
|
23
|
+
* @param path
|
|
24
|
+
* @private
|
|
25
|
+
*/
|
|
26
|
+
private findCurrentMap;
|
|
27
|
+
up(pathPart: string, resolve?: boolean): void;
|
|
28
|
+
private pathExists;
|
|
29
|
+
down(resolve?: boolean): void;
|
|
30
|
+
clone(path: string[], resolveImmediately?: boolean): MapWrapper<M>;
|
|
31
|
+
resolve(path: string[]): WrapletChildrenMapWithDefaults;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { WrapletChildDefinition, WrapletChildDefinitionWithDefaults } from "./types/WrapletChildDefinition";
|
|
2
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "./types/WrapletChildrenMap";
|
|
3
|
+
export declare function addDefaultsToChildDefinition<T extends WrapletChildDefinition>(definition: T): WrapletChildDefinitionWithDefaults<T>;
|
|
4
|
+
export declare function fillMapWithDefaults<T extends WrapletChildrenMap>(map: T): WrapletChildrenMapWithDefaults<T>;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},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,{AbstractWraplet:()=>D,DefaultChildrenManager:()=>m,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=(t,e)=>"object"==typeof t&&null!==t&&!0===t[e],h=Symbol("WrapletSet");function c(t){return d(t,h)}class u 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 f=Symbol("WrapletSetReadonly");class p extends u{[f]=!0;[h]=!0}function y(t){const e=t.wraplets;return c(e)&&0!==e.size?e:new p}function C(t,e){e(t);const i=t.childNodes;for(const t of i)C(t,e)}function g(t){C(t,t=>{const e=y(t);for(const t of e)t.destroy()})}const w=Symbol("ChildrenManager");class m{node;[w]=!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 n("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=y(e);if(this.map[t].multiple){if(!c(i))throw new l("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 l("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=this.findChildren(n,e);if(this.validateElements(i,r,t),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,t,s)}instantiateWrapletItem(t,e,i){const n=this.findExistingWraplet(t,i);if(n)return n;const r=e.Class,s=e.args,o=this.createIndividualWraplet(r,i,s);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 p;const r=this.findChildren(n,e);this.validateElements(i,r,t);const s=this.instantiatedChildren&&this.instantiatedChildren[i]?this.instantiatedChildren[i]:new p;for(const e of r){if(this.findExistingWraplet(i,e))continue;const n=this.instantiateWrapletItem(i,t,e);s.add(n)}return s}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 a("Children are already destroyed.");this.isGettingDestroyed=!0;for(const t of this.listeners){const e=t.node,i=t.eventName,n=t.callback,r=t.options;e.removeEventListener(i,n,r)}this.destroyChildren(),this.isGettingDestroyed=!1,this.isDestroyed=!0}findChildren(t,e){return"string"==typeof t?((t,e)=>Array.from(e.querySelectorAll(t)))(t,e):t(e)}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 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(t,e){if(c(this.instantiatedChildren[e])){if(!this.instantiatedChildren[e].delete(t))throw new l("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 r("Required child has been destroyed.");if(null===this.instantiatedChildren[e])throw new l("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,e){const i=e.selector,r=e.required;if(!i&&r)throw new n(`${this.constructor.name}: Child "${t}" cannot at the same be required and have no selector.`)}validateElements(t,e,n){if(0===e.length&&n.required)throw new i(`${this.constructor.name}: Couldn't find a node for the wraplet "${t}". 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(c(e))for(const t of e)t.destroy();else e.destroy()}}const b=Symbol("Wraplet");function v(t){return d(t,b)}const W=Symbol("Groupable"),I=Symbol("NodeTreeParent");class D{node;[b]=!0;[W]=!0;[I]=!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 m(t,i,e),this.initialize()}getNodeTreeChildren(){const t=[];for(const e of Object.values(this.children))if(c(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 p),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===D)throw new Error("You cannot instantiate an abstract class.");const n=[];t instanceof Element&&t.hasAttribute(e)&&n.push(new this(t,...i));const r=t.querySelectorAll(`[${e}]`);for(const t of r)n.push(new this(t,...i));return n}}class E extends u{[f]=!0}var L=exports;for(var M in e)L[M]=e[M];e.__esModule&&Object.defineProperty(L,"__esModule",{value:!0});
|
|
1
|
+
var t={d:(e,i)=>{for(var r in i)t.o(i,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:i[r]})},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,{AbstractWraplet:()=>z,DefaultCore:()=>D,DefaultWrapletSet:()=>y,DefaultWrapletSetReadonly:()=>j,MapRepeat:()=>G,destroyWrapletsRecursively:()=>m,getWrapletsFromNode:()=>C,isWraplet:()=>x});class i extends Error{}class r extends Error{}class n extends Error{}class s extends Error{}class o extends Error{}class a extends Error{}class l extends Error{}function h(t){return Object.getPrototypeOf(t)===Object.prototype}const d=(t,e)=>"object"==typeof t&&null!==t&&!0===t[e],c=Symbol("WrapletSet");function p(t){return d(t,c)}class u 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 f=Symbol("WrapletSetReadonly");class y extends u{[f]=!0;[c]=!0}function C(t){const e=t.wraplets;return p(e)&&0!==e.size?e:new y}function g(t,e){return!!e.wraplets&&e.wraplets.delete(t)}function w(t,e){e(t);const i=t.childNodes;for(const t of i)w(t,e)}function m(t){w(t,t=>{const e=C(t);for(const i of e)i.isGettingDestroyed||i.isDestroyed||i.destroy(),g(i,t)})}const b=Symbol("NodeTreeParent"),v=Symbol("ChildrenManager");function I(t){return{args:[],destructible:!0,map:{},coreOptions:{},...t}}function E(t){const e={};for(const i in t){e[i]=I(t[i]);const r=t[i].map;r&&h(r)&&(e[i].map=E(r))}return e}const W=Symbol("DynamicMap");function M(t){return d(t,W)}class S{fullMap;startingPath;currentMap=null;path;currentPath=[];constructor(t,e=[],i=!0){this.path=e,this.startingPath=e,this.fullMap=E(t),i&&(this.currentMap=this.resolve(this.path))}getStartingMap(){return this.resolve(this.startingPath)}getCurrentMap(){return this.currentMap&&this.currentPath==this.path||(this.currentMap=this.resolve(this.path),this.currentPath=this.path),this.currentMap}findCurrentMap(t){let e=this.fullMap;for(const i of t){if(!e[i])throw new Error(`Invalid path: ${this.path.join(".")} . No such definition.`);const r=e[i].map;if(h(r))e=r;else{if(!M(r))throw new Error("Invalid map type.");e=r.create(this.clone(t,!1))}}return e}up(t,e=!0){if(!this.pathExists([...this.path,t]))throw new Error("Map doesn't exist.");this.path.push(t),e&&(this.currentMap=this.resolve(this.path))}pathExists(t){let e=this.fullMap;for(const i of t){if(!Object.hasOwn(e,i))return!1;const t=e[i].map;if(M(t))return!0;if(!h(t))throw new Error("Invalid map type.");e=t}return!0}down(t=!0){if(0===this.path.length)throw new Error("At the root already.");this.path.pop(),t&&(this.currentMap=this.resolve(this.path))}clone(t,e=!0){return new S(this.fullMap,t,e)}resolve(t){return this.findCurrentMap(t)}}class D{node;[v]=!0;[b]=!0;isDestroyed=!1;isGettingDestroyed=!1;isGettingInitialized=!1;isInitialized=!1;mapWrapper;instantiatedChildren={};destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(t,e,i={}){if(this.node=t,h(e))this.mapWrapper=new S(e);else{if(!(e instanceof S))throw new r("The map provided to the Core is not a valid map.");this.mapWrapper=e}this.processInitOptions(i),this.instantiatedChildren={}}init(){this.isGettingInitialized=!0;const t=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(t),this.isInitialized=!0,this.isGettingInitialized=!1}get map(){return this.mapWrapper.getStartingMap()}instantiateChildren(){const t=this.instantiatedChildren;if("function"!=typeof this.node.querySelectorAll){if(Object.keys(this.map).length>0)throw new r("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],r=i.multiple,n=this.mapWrapper.clone([...this.mapWrapper.path,e]);this.validateMapItem(e,i),t[e]=r?this.instantiateMultipleWrapletsChild(i,n,this.node,e):this.instantiateSingleWrapletChild(i,n,this.node,e)}return t}syncChildren(){this.instantiatedChildren=this.instantiateChildren()}getNodeTreeChildren(){const t=[];for(const e of Object.values(this.children))if(p(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})}findExistingWraplet(t,e){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[t])return null;const i=this.instantiatedChildren[t];if(this.map[t].multiple){if(!p(i))throw new l("Internal logic error. Expected a WrapletSet.");const t=i.find(t=>{let i=!1;return t.accessNode(t=>{t===e&&(i=!0)}),i});if(0===t.length)return null;if(t.length>1)throw new l("Internal logic error. Multiple instances wrapping the same element found in the core.");return t[0]}return i}instantiateSingleWrapletChild(t,e,i,r){if(!t.selector)return null;const n=t.selector,s=this.findChildren(n,i);if(this.validateElements(r,s,t),0===s.length)return null;if(s.length>1)throw new o(`${this.constructor.name}: More than one element was found for the "${r}" child. Selector used: "${n}".`);const a=s[0];return this.instantiateWrapletItem(r,t,e,a)}instantiateWrapletItem(t,e,i,r){const n=this.findExistingWraplet(t,r);if(n)return n;const s=e.Class,o=e.args,a=this.createIndividualWraplet(s,r,i,e.coreOptions,o);this.prepareIndividualWraplet(t,a);for(const e of this.instantiateChildListeners)e(a,t);return a}instantiateMultipleWrapletsChild(t,e,i,r){const n=t.selector;if(!n)return new y;const s=this.findChildren(n,i);this.validateElements(r,s,t);const o=this.instantiatedChildren&&this.instantiatedChildren[r]?this.instantiatedChildren[r]:new y;for(const i of s){if(this.findExistingWraplet(r,i))continue;const n=this.instantiateWrapletItem(r,t,e,i);o.add(n)}return o}addDestroyChildListener(t){this.destroyChildListeners.push(t)}addInstantiateChildListener(t){this.instantiateChildListeners.push(t)}createIndividualWraplet(t,e,i,r,n){return new t(...[new this.constructor(e,i,r),...n])}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 a("Children are already destroyed.");this.isGettingDestroyed=!0;for(const t of this.listeners){const e=t.node,i=t.eventName,r=t.callback,n=t.options;e.removeEventListener(i,r,n)}this.destroyChildren(),this.isGettingDestroyed=!1,this.isDestroyed=!0}findChildren(t,e){return"string"==typeof t?((t,e)=>Array.from(e.querySelectorAll(t)))(t,e):t(e)}addEventListener(t,e,i,r){this.listeners.push({node:t,eventName:e,callback:i,options:r}),t.addEventListener(e,i,r)}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(t,e){if(p(this.instantiatedChildren[e])){if(!this.instantiatedChildren[e].delete(t))throw new l("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 n("Required child has been destroyed.");if(null===this.instantiatedChildren[e])throw new l("Internal logic error. Destroyed child couldn't be removed because it's already null.");this.instantiatedChildren[e]=null}}validateMapItem(t,e){const i=e.selector,n=e.required;if(!i&&n)throw new r(`${this.constructor.name}: Child "${t}" cannot at the same be required and have no selector.`)}validateElements(t,e,r){if(0===e.length&&r.required)throw new i(`${this.constructor.name}: Couldn't find a node for the wraplet "${t}". Selector used: "${r.selector}".`)}wrapChildren(t){return new Proxy(t,{get:function(t,e){if(!(e in t))throw new Error(`Child '${e}' has not been found.`);return t[e]}})}defaultInitOptions(){return{instantiateChildListeners:[],destroyChildListeners:[]}}processInitOptions(t){const e=Object.assign(this.defaultInitOptions(),t);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(p(e))for(const t of e)t.destroy();else e.destroy()}}const L=Symbol("Wraplet");function x(t){return d(t,L)}const O=Symbol("Groupable");class z{core;[L]=!0;[O]=!0;[b]=!0;isGettingDestroyed=!1;isDestroyed=!1;isGettingInitialized=!1;isInitialized=!1;groupsExtractor=t=>{if(t instanceof Element){const e=t.getAttribute("data-js-wraplet-groupable");if(e)return e.split(",")}return[]};destroyListeners=[];__debugNodeAccessors=[];constructor(t){if(this.core=t,!d(t,v))throw new Error("AbstractWraplet requires a Core instance.");t.addDestroyChildListener(this.onChildDestroyed.bind(this)),t.addInstantiateChildListener(this.onChildInstantiated.bind(this)),this.initialize()}getNodeTreeChildren(){return this.core.getNodeTreeChildren()}setGroupsExtractor(t){this.groupsExtractor=t}getGroups(){return this.groupsExtractor(this.node)}get children(){return this.core.children}accessNode(t){this.__debugNodeAccessors.push(t),t(this.node)}destroy(){this.isGettingDestroyed=!0;for(const t of this.destroyListeners)t(this);this.destroyListeners.length=0,this.core.destroy(),this.isDestroyed=!0,this.isGettingDestroyed=!1}addDestroyListener(t){this.destroyListeners.push(t)}onChildDestroyed(t,e){}initialize(){this.isGettingInitialized=!0,this.core.init(),this.isInitialized=!0,this.isGettingInitialized=!1}get node(){return this.core.node}onChildInstantiated(t,e){}isChildInstance(t,e,i=null){return e===(i||e)&&t instanceof this.core.map[e].Class}static createCore(t,e){return new D(t,e)}static createWraplets(t,e,i,r=[]){if(this===z)throw new Error("You cannot instantiate an abstract class.");const n=[];if(t instanceof Element&&t.hasAttribute(i)){const i=z.createCore(t,e);n.push(new this(i,...r))}const s=t.querySelectorAll(`[${i}]`);for(const t of s){const i=z.createCore(t,e);n.push(new this(i,...r))}return n}}class G{levels;[W]=!0;constructor(t=1){if(this.levels=t,t<1)throw new Error("There have to be more than 0 repeated levels.")}create(t){for(let e=0;e<this.levels;e++)t.down();return t.getCurrentMap()}static create(t=1){return new G(t)}}class j extends u{[f]=!0}var N=exports;for(var P in e)N[P]=e[P];e.__esModule&&Object.defineProperty(N,"__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,EA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Q7B,EMiEXb,KAAKa,MNhE3BC,UAGHD,EAAKC,SAASwE,OM6DKtF,MACtBA,KAAKwG,gBAAgBlF,SACzB,CACA,WAAAG,CAAYoG,GAAa,GACrB,OAAOA,EACD7H,KAAKwG,gBAAgB/E,YACrBzB,KAAKwG,gBAAgB9E,oBACnB1B,KAAKwG,gBAAgB/E,WACjC,CACA,iBAAIE,GACA,OAAO3B,KAAKwG,gBAAgB7E,aAChC,CACA,kBAAA+C,CAAmBtE,GACfJ,KAAK8G,iBAAiB7G,KAAKG,EAC/B,CAKA,gBAAA+G,CAAiBhG,EAAOwB,GAAM,CAC9B,UAAAyE,GN/EG,IAAmCvG,EMgFlCb,KAAKwG,gBAAgBnE,QNhFaxB,EMiFXb,KAAKa,MNhFtBC,WACND,EAAKC,SAAW,IAAIH,GAExBE,EAAKC,SAASyD,IM6EOvE,KACrB,CAIA,mBAAAiH,CAEA9F,EAEAwB,GAAM,CAaN,eAAAmF,CAAgB/H,EAAMgI,EAAiBC,EAAS,MAC5C,OAAQD,KAAqBC,GAAUD,IACnChI,aAAgBC,KAAKwG,gBAAgB5E,IAAImG,GAAwB,KACzE,CAIA,qBAAOE,CAAepH,EAAMqH,EAAWC,EAAkB,IACrD,GAAInI,OAASuG,EACT,MAAM,IAAIxH,MAAM,6CAEpB,MAAMwI,EAAS,GACX1G,aAAgB6F,SAAW7F,EAAKuH,aAAaF,IAC7CX,EAAOtH,KAAK,IAAID,KAAKa,KAASsH,IAElC,MAAME,EAAgBxH,EAAK2B,iBAAiB,IAAI0F,MAChD,IAAK,MAAMI,KAAWD,EAClBd,EAAOtH,KAAK,IAAID,KAAKsI,KAAYH,IAErC,OAAOZ,CACX,EC5IG,MAAMgB,UAAkC7I,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 = this.findChildren(selector, node);\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 = this.findChildren(selector, node);\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 findChildren(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n 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, attribute, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","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","findChildren","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","defaultSelectorCallback","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","attribute","additional_args","hasAttribute","foundElements","element","DefaultWrapletSetReadonly"],"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,gNCLhD,MAAMC,UAAkCC,OAExC,MAAMC,UAAiBD,OAEvB,MAAME,UAAoCF,OAE1C,MAAMG,UAAqCH,OAI3C,MAAMI,UAAkCJ,OAExC,MAAMK,UAAyCL,OAE/C,MAAMM,UAA2BN,OCdjC,SAASO,EAAiCC,GAC7C,OAAOrB,OAAOsB,eAAeD,KAAYrB,OAAOM,SACpD,CCEA,MAAM,EAAK,CAACe,EAAQE,IACU,iBAAXF,GACA,OAAXA,IACmB,IAAnBA,EAAOE,GCNTC,EAAmBf,OAAO,cAEzB,SAASgB,E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AAe7I,EAAMmB,EAAK2H,EAAWC,EAAkB,IAC1D,GAAI3J,OAASsI,EACT,MAAM,IAAIzJ,MAAM,6CAEpB,MAAMyG,EAAS,GACf,GAAI1E,aAAgB6H,SAAW7H,EAAKgJ,aAAaF,GAAY,CACzD,MAAMnB,EAAOD,EAAgBkB,WAAW5I,EAAMmB,GAC9CuD,EAAOrF,KAAK,IAAID,KAAKuI,KAASoB,GAClC,CACA,MAAME,EAAgBjJ,EAAKgE,iBAAiB,IAAI8E,MAChD,IAAK,MAAMI,KAAWD,EAAe,CACjC,MAAMtB,EAAOD,EAAgBkB,WAAWM,EAAS/H,GACjDuD,EAAOrF,KAAK,IAAID,KAAKuI,KAASoB,GAClC,CACA,OAAOrE,CACX,EC5HG,MAAMyE,EACTC,OACA,CAAC3H,IAAoB,EACrB,WAAAQ,CAAYmH,EAAS,GAEjB,GADAhK,KAAKgK,OAASA,EACVA,EAAS,EACT,MAAM,IAAInL,MAAM,gDAExB,CACA,MAAAyE,CAAO2G,GACH,IAAK,IAAIC,EAAI,EAAGA,EAAIlK,KAAKgK,OAAQE,IAC7BD,EAAerG,OAEnB,OAAOqG,EAAehH,eAC1B,CACA,aAAOK,CAAO0G,EAAS,GACnB,OAAO,IAAID,EAAUC,EACzB,EChBG,MAAMG,UAAkCzK,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/WrapletChildrenMap.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/NodeTreeParent.ts","webpack://wraplet/./src/types/Core.ts","webpack://wraplet/./src/WrapletChildrenMap.ts","webpack://wraplet/./src/types/Map/DynamicMap.ts","webpack://wraplet/./src/Map/MapWrapper.ts","webpack://wraplet/./src/DefaultCore.ts","webpack://wraplet/./src/types/Wraplet.ts","webpack://wraplet/./src/types/Groupable.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/Map/MapRepeat.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","export function isWrapletChildrenMapWithDefaults(object) {\n return Object.getPrototypeOf(object) === Object.prototype;\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 if (!wraplet.isGettingDestroyed && !wraplet.isDestroyed) {\n wraplet.destroy();\n }\n removeWrapletFromNode(wraplet, node);\n }\n });\n}\n","const NodeTreeParentSymbol = Symbol(\"NodeTreeParent\");\nexport { NodeTreeParentSymbol };\n/* istanbul ignore next */\nexport function isNodeTreeParent(object) {\n return (object[NodeTreeParentSymbol] ===\n true);\n}\n","import { is } from \"./Utils\";\nimport { NodeTreeParentSymbol } from \"./NodeTreeParent\";\nconst CoreSymbol = Symbol(\"ChildrenManager\");\nexport { CoreSymbol };\nexport function isCore(object) {\n return is(object, CoreSymbol);\n}\n","import { isWrapletChildrenMapWithDefaults, } from \"./types/WrapletChildrenMap\";\nexport function addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n map: {},\n coreOptions: {},\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id in map) {\n newMap[id] = addDefaultsToChildDefinition(map[id]);\n const subMap = map[id][\"map\"];\n if (subMap && isWrapletChildrenMapWithDefaults(subMap)) {\n newMap[id][\"map\"] = fillMapWithDefaults(subMap);\n }\n }\n return newMap;\n}\n","import { is } from \"../Utils\";\nconst DynamicMapSymbol = Symbol(\"DynamicMap\");\nexport { DynamicMapSymbol };\nexport function isDynamicMap(object) {\n return is(object, DynamicMapSymbol);\n}\n","import { isWrapletChildrenMapWithDefaults, } from \"../types/WrapletChildrenMap\";\nimport { fillMapWithDefaults } from \"../WrapletChildrenMap\";\nimport { isDynamicMap } from \"../types/Map/DynamicMap\";\nexport class MapWrapper {\n fullMap;\n startingPath;\n currentMap = null;\n path;\n currentPath = [];\n /**\n * @param fullMap\n * @param path\n * Path to the current definition.\n * @param resolveImmediately\n */\n constructor(fullMap, path = [], resolveImmediately = true) {\n this.path = path;\n this.startingPath = path;\n this.fullMap = fillMapWithDefaults(fullMap);\n if (resolveImmediately) {\n this.currentMap = this.resolve(this.path);\n }\n }\n getStartingMap() {\n return this.resolve(this.startingPath);\n }\n getCurrentMap() {\n if (!this.currentMap || this.currentPath != this.path) {\n this.currentMap = this.resolve(this.path);\n this.currentPath = this.path;\n }\n return this.currentMap;\n }\n /**\n * @param path\n * @private\n */\n findCurrentMap(path) {\n let resultMap = this.fullMap;\n for (const pathPart of path) {\n if (!resultMap[pathPart]) {\n throw new Error(`Invalid path: ${this.path.join(\".\")} . No such definition.`);\n }\n const map = resultMap[pathPart][\"map\"];\n if (isWrapletChildrenMapWithDefaults(map)) {\n resultMap = map;\n }\n else if (isDynamicMap(map)) {\n resultMap = map.create(this.clone(path, false));\n }\n else {\n throw new Error(\"Invalid map type.\");\n }\n }\n return resultMap;\n }\n up(pathPart, resolve = true) {\n if (!this.pathExists([...this.path, pathPart])) {\n throw new Error(\"Map doesn't exist.\");\n }\n this.path.push(pathPart);\n if (resolve) {\n this.currentMap = this.resolve(this.path);\n }\n }\n pathExists(path) {\n let tempMap = this.fullMap;\n for (const pathPart of path) {\n if (!Object.hasOwn(tempMap, pathPart)) {\n return false;\n }\n const map = tempMap[pathPart][\"map\"];\n if (isDynamicMap(map)) {\n return true;\n }\n if (!isWrapletChildrenMapWithDefaults(map)) {\n throw new Error(\"Invalid map type.\");\n }\n tempMap = map;\n }\n return true;\n }\n down(resolve = true) {\n if (this.path.length === 0) {\n throw new Error(\"At the root already.\");\n }\n this.path.pop();\n if (resolve) {\n this.currentMap = this.resolve(this.path);\n }\n }\n clone(path, resolveImmediately = true) {\n return new MapWrapper(this.fullMap, path, resolveImmediately);\n }\n resolve(path) {\n return this.findCurrentMap(path);\n }\n}\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, ChildrenTooManyFoundError, ChildrenAreAlreadyDestroyedError, InternalLogicError, } from \"./errors\";\nimport { isWrapletChildrenMapWithDefaults, } from \"./types/WrapletChildrenMap\";\nimport { isParentNode } from \"./utils\";\nimport { CoreSymbol } from \"./types/Core\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nimport { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { MapWrapper } from \"./Map/MapWrapper\";\nexport class DefaultCore {\n node;\n [CoreSymbol] = true;\n [NodeTreeParentSymbol] = true;\n isDestroyed = false;\n isGettingDestroyed = false;\n isGettingInitialized = false;\n isInitialized = false;\n mapWrapper;\n instantiatedChildren = {};\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, initOptions = {}) {\n this.node = node;\n if (isWrapletChildrenMapWithDefaults(map)) {\n this.mapWrapper = new MapWrapper(map);\n }\n else if (map instanceof MapWrapper) {\n this.mapWrapper = map;\n }\n else {\n throw new MapError(\"The map provided to the Core is not a valid map.\");\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 children manager,\n * so the children manager has to exist already.\n */\n init() {\n this.isGettingInitialized = true;\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n this.isInitialized = true;\n this.isGettingInitialized = false;\n }\n get map() {\n return this.mapWrapper.getStartingMap();\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 childDefinition = this.map[id];\n const multiple = childDefinition.multiple;\n const mapWrapper = this.mapWrapper.clone([...this.mapWrapper.path, id]);\n this.validateMapItem(id, childDefinition);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(childDefinition, mapWrapper, this.node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(childDefinition, mapWrapper, 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 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 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 // 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 existingWraplets = existingChild.find((wraplet) => {\n let result = false;\n wraplet.accessNode((node) => {\n if (node === childElement) {\n result = true;\n }\n });\n return result;\n });\n if (existingWraplets.length === 0) {\n return null;\n }\n if (existingWraplets.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the core.\");\n }\n return existingWraplets[0];\n }\n // Handle single.\n return existingChild;\n }\n instantiateSingleWrapletChild(childDefinition, childMap, node, id) {\n if (!childDefinition.selector) {\n return null;\n }\n const selector = childDefinition.selector;\n // Find children elements based on the map.\n const childElements = this.findChildren(selector, node);\n this.validateElements(id, childElements, childDefinition);\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, childDefinition, childMap, childElement);\n }\n instantiateWrapletItem(id, childDefinition, childMap, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = childDefinition.Class;\n const args = childDefinition.args;\n const wraplet = this.createIndividualWraplet(wrapletClass, node, childMap, childDefinition.coreOptions, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(childDefinition, childMap, node, id) {\n const selector = childDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildren(selector, node);\n this.validateElements(id, childElements, childDefinition);\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, childDefinition, childMap, 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, map, initOptions, args) {\n const core = new this.constructor(childElement, map, initOptions);\n return new wrapletClass(...[core, ...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 findChildren(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n 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 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 '${name}' 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 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","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { defaultGroupableAttribute, GroupableSymbol, } from \"./types/Groupable\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { isCore } from \"./types/Core\";\nimport { DefaultCore } from \"./DefaultCore\";\nexport class AbstractWraplet {\n core;\n [WrapletSymbol] = true;\n [GroupableSymbol] = true;\n [NodeTreeParentSymbol] = true;\n isGettingDestroyed = false;\n isDestroyed = false;\n isGettingInitialized = false;\n isInitialized = false;\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(core) {\n this.core = core;\n if (!isCore(core)) {\n throw new Error(\"AbstractWraplet requires a Core instance.\");\n }\n core.addDestroyChildListener(this.onChildDestroyed.bind(this));\n core.addInstantiateChildListener(this.onChildInstantiated.bind(this));\n this.initialize();\n }\n getNodeTreeChildren() {\n return this.core.getNodeTreeChildren();\n }\n setGroupsExtractor(callback) {\n this.groupsExtractor = callback;\n }\n getGroups() {\n return this.groupsExtractor(this.node);\n }\n get children() {\n return this.core.children;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n destroy() {\n this.isGettingDestroyed = true;\n for (const listener of this.destroyListeners) {\n listener(this);\n }\n this.destroyListeners.length = 0;\n this.core.destroy();\n this.isDestroyed = true;\n this.isGettingDestroyed = false;\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.isGettingInitialized = true;\n this.core.init();\n this.isInitialized = true;\n this.isGettingInitialized = false;\n }\n get node() {\n return this.core.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.core.map[actualUnknownId][\"Class\"]);\n }\n static createCore(node, map) {\n return new DefaultCore(node, map);\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, map, attribute, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const core = AbstractWraplet.createCore(node, map);\n result.push(new this(core, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n const core = AbstractWraplet.createCore(element, map);\n result.push(new this(core, ...additional_args));\n }\n return result;\n }\n}\n","import { DynamicMapSymbol } from \"../types/Map/DynamicMap\";\nexport class MapRepeat {\n levels;\n [DynamicMapSymbol] = true;\n constructor(levels = 1) {\n this.levels = levels;\n if (levels < 1) {\n throw new Error(\"There have to be more than 0 repeated levels.\");\n }\n }\n create(parentMapClone) {\n for (let i = 0; i < this.levels; i++) {\n parentMapClone.down();\n }\n return parentMapClone.getCurrentMap();\n }\n static create(levels = 1) {\n return new MapRepeat(levels);\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","isWrapletChildrenMapWithDefaults","object","getPrototypeOf","symbol","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","item","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","getWrapletsFromNode","node","wraplets","size","removeWrapletFromNode","wraplet","delete","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","isGettingDestroyed","isDestroyed","destroy","NodeTreeParentSymbol","CoreSymbol","addDefaultsToChildDefinition","args","destructible","map","coreOptions","fillMapWithDefaults","newMap","id","subMap","DynamicMapSymbol","isDynamicMap","MapWrapper","fullMap","startingPath","currentMap","path","currentPath","constructor","resolveImmediately","resolve","getStartingMap","getCurrentMap","findCurrentMap","resultMap","pathPart","join","create","clone","up","pathExists","tempMap","hasOwn","down","length","pop","DefaultCore","isGettingInitialized","isInitialized","mapWrapper","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","initOptions","processInitOptions","init","instantiateChildren","wrapChildren","querySelectorAll","keys","childDefinition","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","getNodeTreeChildren","values","result","accessNode","childsNode","contains","findExistingWraplet","childElement","undefined","existingChild","existingWraplets","childMap","selector","childElements","findChildren","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","defaultSelectorCallback","addEventListener","uninitializedChildren","required","isRequired","elements","mapItem","Proxy","target","defaultInitOptions","initOptionsPartial","assign","entries","WrapletSymbol","isWraplet","GroupableSymbol","AbstractWraplet","core","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","onChildDestroyed","bind","onChildInstantiated","initialize","setGroupsExtractor","getGroups","isChildInstance","actualUnknownId","onlyId","createCore","createWraplets","attribute","additional_args","hasAttribute","foundElements","element","MapRepeat","levels","parentMapClone","i","DefaultWrapletSetReadonly"],"sourceRoot":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { DefaultCore } from "./DefaultCore";
|
|
2
2
|
export { AbstractWraplet } from "./AbstractWraplet";
|
|
3
3
|
export { destroyWrapletsRecursively, getWrapletsFromNode } from "./utils";
|
|
4
|
+
export { MapRepeat } from "./Map/MapRepeat";
|
|
4
5
|
export type { WrapletSetReadonly } from "./types/Set/WrapletSetReadonly";
|
|
5
6
|
export type { WrapletSet } from "./types/Set/WrapletSet";
|
|
6
7
|
export { DefaultWrapletSetReadonly } from "./Set/DefaultWrapletSetReadonly";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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=this.findChildren(n,e);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=this.findChildren(n,e);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}findChildren(t,e){return"string"==typeof t?((t,e)=>Array.from(e.querySelectorAll(t)))(t,e):t(e)}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"),I=Symbol("NodeTreeParent");class v{node;[w]=!0;[b]=!0;[I]=!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===v)throw new Error("You cannot instantiate an abstract class.");const n=[];t instanceof Element&&t.hasAttribute(e)&&n.push(new this(t,...i));const s=t.querySelectorAll(`[${e}]`);for(const t of s)n.push(new this(t,...i));return n}}class E extends h{[c]=!0}export{v as AbstractWraplet,g as DefaultChildrenManager,u as DefaultWrapletSet,E as DefaultWrapletSetReadonly,C as destroyWrapletsRecursively,f as getWrapletsFromNode,m as isWraplet};
|
|
1
|
+
class t extends Error{}class e extends Error{}class i extends Error{}class n extends Error{}class r extends Error{}class s extends Error{}class o extends Error{}function a(t){return Object.getPrototypeOf(t)===Object.prototype}const h=(t,e)=>"object"==typeof t&&null!==t&&!0===t[e],l=Symbol("WrapletSet");function d(t){return h(t,l)}class c 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 u=Symbol("WrapletSetReadonly");class p extends c{[u]=!0;[l]=!0}function f(t){const e=t.wraplets;return d(e)&&0!==e.size?e:new p}function C(t,e){return!!e.wraplets&&e.wraplets.delete(t)}function y(t,e){e(t);const i=t.childNodes;for(const t of i)y(t,e)}function w(t){y(t,t=>{const e=f(t);for(const i of e)i.isGettingDestroyed||i.isDestroyed||i.destroy(),C(i,t)})}const g=Symbol("NodeTreeParent"),m=Symbol("ChildrenManager");function v(t){return{args:[],destructible:!0,map:{},coreOptions:{},...t}}function b(t){const e={};for(const i in t){e[i]=v(t[i]);const n=t[i].map;n&&a(n)&&(e[i].map=b(n))}return e}const I=Symbol("DynamicMap");function E(t){return h(t,I)}class W{fullMap;startingPath;currentMap=null;path;currentPath=[];constructor(t,e=[],i=!0){this.path=e,this.startingPath=e,this.fullMap=b(t),i&&(this.currentMap=this.resolve(this.path))}getStartingMap(){return this.resolve(this.startingPath)}getCurrentMap(){return this.currentMap&&this.currentPath==this.path||(this.currentMap=this.resolve(this.path),this.currentPath=this.path),this.currentMap}findCurrentMap(t){let e=this.fullMap;for(const i of t){if(!e[i])throw new Error(`Invalid path: ${this.path.join(".")} . No such definition.`);const n=e[i].map;if(a(n))e=n;else{if(!E(n))throw new Error("Invalid map type.");e=n.create(this.clone(t,!1))}}return e}up(t,e=!0){if(!this.pathExists([...this.path,t]))throw new Error("Map doesn't exist.");this.path.push(t),e&&(this.currentMap=this.resolve(this.path))}pathExists(t){let e=this.fullMap;for(const i of t){if(!Object.hasOwn(e,i))return!1;const t=e[i].map;if(E(t))return!0;if(!a(t))throw new Error("Invalid map type.");e=t}return!0}down(t=!0){if(0===this.path.length)throw new Error("At the root already.");this.path.pop(),t&&(this.currentMap=this.resolve(this.path))}clone(t,e=!0){return new W(this.fullMap,t,e)}resolve(t){return this.findCurrentMap(t)}}class M{node;[m]=!0;[g]=!0;isDestroyed=!1;isGettingDestroyed=!1;isGettingInitialized=!1;isInitialized=!1;mapWrapper;instantiatedChildren={};destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(t,i,n={}){if(this.node=t,a(i))this.mapWrapper=new W(i);else{if(!(i instanceof W))throw new e("The map provided to the Core is not a valid map.");this.mapWrapper=i}this.processInitOptions(n),this.instantiatedChildren={}}init(){this.isGettingInitialized=!0;const t=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(t),this.isInitialized=!0,this.isGettingInitialized=!1}get map(){return this.mapWrapper.getStartingMap()}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,r=this.mapWrapper.clone([...this.mapWrapper.path,e]);this.validateMapItem(e,i),t[e]=n?this.instantiateMultipleWrapletsChild(i,r,this.node,e):this.instantiateSingleWrapletChild(i,r,this.node,e)}return t}syncChildren(){this.instantiatedChildren=this.instantiateChildren()}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})}findExistingWraplet(t,e){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[t])return null;const i=this.instantiatedChildren[t];if(this.map[t].multiple){if(!d(i))throw new o("Internal logic error. Expected a WrapletSet.");const t=i.find(t=>{let i=!1;return t.accessNode(t=>{t===e&&(i=!0)}),i});if(0===t.length)return null;if(t.length>1)throw new o("Internal logic error. Multiple instances wrapping the same element found in the core.");return t[0]}return i}instantiateSingleWrapletChild(t,e,i,n){if(!t.selector)return null;const s=t.selector,o=this.findChildren(s,i);if(this.validateElements(n,o,t),0===o.length)return null;if(o.length>1)throw new r(`${this.constructor.name}: More than one element was found for the "${n}" child. Selector used: "${s}".`);const a=o[0];return this.instantiateWrapletItem(n,t,e,a)}instantiateWrapletItem(t,e,i,n){const r=this.findExistingWraplet(t,n);if(r)return r;const s=e.Class,o=e.args,a=this.createIndividualWraplet(s,n,i,e.coreOptions,o);this.prepareIndividualWraplet(t,a);for(const e of this.instantiateChildListeners)e(a,t);return a}instantiateMultipleWrapletsChild(t,e,i,n){const r=t.selector;if(!r)return new p;const s=this.findChildren(r,i);this.validateElements(n,s,t);const o=this.instantiatedChildren&&this.instantiatedChildren[n]?this.instantiatedChildren[n]:new p;for(const i of s){if(this.findExistingWraplet(n,i))continue;const r=this.instantiateWrapletItem(n,t,e,i);o.add(r)}return o}addDestroyChildListener(t){this.destroyChildListeners.push(t)}addInstantiateChildListener(t){this.instantiateChildListeners.push(t)}createIndividualWraplet(t,e,i,n,r){return new t(...[new this.constructor(e,i,n),...r])}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 s("Children are already destroyed.");this.isGettingDestroyed=!0;for(const t of this.listeners){const e=t.node,i=t.eventName,n=t.callback,r=t.options;e.removeEventListener(i,n,r)}this.destroyChildren(),this.isGettingDestroyed=!1,this.isDestroyed=!0}findChildren(t,e){return"string"==typeof t?((t,e)=>Array.from(e.querySelectorAll(t)))(t,e):t(e)}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}}validateMapItem(t,i){const n=i.selector,r=i.required;if(!n&&r)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 '${e}' has not been found.`);return t[e]}})}defaultInitOptions(){return{instantiateChildListeners:[],destroyChildListeners:[]}}processInitOptions(t){const e=Object.assign(this.defaultInitOptions(),t);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 L=Symbol("Wraplet");function D(t){return h(t,L)}const x=Symbol("Groupable");class S{core;[L]=!0;[x]=!0;[g]=!0;isGettingDestroyed=!1;isDestroyed=!1;isGettingInitialized=!1;isInitialized=!1;groupsExtractor=t=>{if(t instanceof Element){const e=t.getAttribute("data-js-wraplet-groupable");if(e)return e.split(",")}return[]};destroyListeners=[];__debugNodeAccessors=[];constructor(t){if(this.core=t,!h(t,m))throw new Error("AbstractWraplet requires a Core instance.");t.addDestroyChildListener(this.onChildDestroyed.bind(this)),t.addInstantiateChildListener(this.onChildInstantiated.bind(this)),this.initialize()}getNodeTreeChildren(){return this.core.getNodeTreeChildren()}setGroupsExtractor(t){this.groupsExtractor=t}getGroups(){return this.groupsExtractor(this.node)}get children(){return this.core.children}accessNode(t){this.__debugNodeAccessors.push(t),t(this.node)}destroy(){this.isGettingDestroyed=!0;for(const t of this.destroyListeners)t(this);this.destroyListeners.length=0,this.core.destroy(),this.isDestroyed=!0,this.isGettingDestroyed=!1}addDestroyListener(t){this.destroyListeners.push(t)}onChildDestroyed(t,e){}initialize(){this.isGettingInitialized=!0,this.core.init(),this.isInitialized=!0,this.isGettingInitialized=!1}get node(){return this.core.node}onChildInstantiated(t,e){}isChildInstance(t,e,i=null){return e===(i||e)&&t instanceof this.core.map[e].Class}static createCore(t,e){return new M(t,e)}static createWraplets(t,e,i,n=[]){if(this===S)throw new Error("You cannot instantiate an abstract class.");const r=[];if(t instanceof Element&&t.hasAttribute(i)){const i=S.createCore(t,e);r.push(new this(i,...n))}const s=t.querySelectorAll(`[${i}]`);for(const t of s){const i=S.createCore(t,e);r.push(new this(i,...n))}return r}}class z{levels;[I]=!0;constructor(t=1){if(this.levels=t,t<1)throw new Error("There have to be more than 0 repeated levels.")}create(t){for(let e=0;e<this.levels;e++)t.down();return t.getCurrentMap()}static create(t=1){return new z(t)}}class G extends c{[u]=!0}export{S as AbstractWraplet,M as DefaultCore,p as DefaultWrapletSet,G as DefaultWrapletSetReadonly,z as MapRepeat,w as destroyWrapletsRecursively,f as getWrapletsFromNode,D 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,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,EAAU,GAChB,IAAK,MAAMC,KAAQC,KACVH,EAAOE,IAGZD,EAAQG,KAAKF,GAEjB,OAAOD,CACX,CACA,OAAAI,CAAQL,GACJ,IAAK,MAAME,KAAQC,KACf,GAAIH,EAAOE,GACP,OAAOA,EAGf,OAAO,IACX,CACA,UAAAI,CAAWC,GACP,OAAOC,MAAMC,KAAKN,MAAMO,KAAK,CAACC,EAAGC,IAAML,EAASI,GAAKJ,EAASK,GAClE,ECrBJ,MAAMC,EAA2BlB,OAAO,sBCGjC,MAAMmB,UAA0BjB,EACnC,CAACgB,IAA4B,EAC7B,CAACnB,IAAoB,ECClB,SAASqB,EAAoBC,GAChC,MAAMC,EAAWD,EAAKC,SACtB,OAAKrB,EAAaqB,IAA+B,IAAlBA,EAASC,KAGjCD,EAFI,IAAIH,CAGnB,CAaO,SAASK,EAAsBH,EAAMT,GACxCA,EAASS,GACT,MAAMI,EAAWJ,EAAKK,WACtB,IAA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OAAOA,EACDjI,KAAK4G,gBAAgBnF,YACrBzB,KAAK4G,gBAAgBlF,oBACnB1B,KAAK4G,gBAAgBnF,WACjC,CACA,iBAAIE,GACA,OAAO3B,KAAK4G,gBAAgBjF,aAChC,CACA,kBAAAgD,CAAmBvE,GACfJ,KAAKkH,iBAAiBjH,KAAKG,EAC/B,CAKA,gBAAAmH,CAAiBpG,EAAOyB,GAAM,CAC9B,UAAA4E,GN/EG,IAAmC3G,EMgFlCb,KAAK4G,gBAAgBvE,QNhFaxB,EMiFXb,KAAKa,MNhFtBC,WACND,EAAKC,SAAW,IAAIH,GAExBE,EAAKC,SAAS0D,IM6EOxE,KACrB,CAIA,mBAAAqH,CAEAlG,EAEAyB,GAAM,CAaN,eAAAsF,CAAgBnI,EAAMoI,EAAiBC,EAAS,MAC5C,OAAQD,KAAqBC,GAAUD,IACnCpI,aAAgBC,KAAK4G,gBAAgBhF,IAAIuG,GAAwB,KACzE,CAIA,qBAAOE,CAAexH,EAAMyH,EAAWC,EAAkB,IACrD,GAAIvI,OAAS2G,EACT,MAAM,IAAI7H,MAAM,6CAEpB,MAAM6I,EAAS,GACX9G,aAAgBiG,SAAWjG,EAAK2H,aAAaF,IAC7CX,EAAO1H,KAAK,IAAID,KAAKa,KAAS0H,IAElC,MAAME,EAAgB5H,EAAK2B,iBAAiB,IAAI8F,MAChD,IAAK,MAAMI,KAAWD,EAClBd,EAAO1H,KAAK,IAAID,KAAK0I,KAAYH,IAErC,OAAOZ,CACX,EC5IG,MAAMgB,UAAkCjJ,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 = this.findChildren(selector, node);\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 = this.findChildren(selector, node);\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 findChildren(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n 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, attribute, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","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","findChildren","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","defaultSelectorCallback","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","attribute","additional_args","hasAttribute","foundElements","element","DefaultWrapletSetReadonly"],"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,OCdjC,SAASO,EAAiCC,GAC7C,OAAOC,OAAOC,eAAeF,KAAYC,OAAOE,SACpD,CCEA,MAAM,EAAK,CAACH,EAAQI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E,CAAW/I,EAAMoB,GACpB,OAAO,IAAIgC,EAAYpD,EAAMoB,EACjC,CAIA,qBAAO4H,CAAehJ,EAAMoB,EAAK6H,EAAWC,EAAkB,IAC1D,GAAI9J,OAASyI,EACT,MAAM,IAAI/J,MAAM,6CAEpB,MAAM6G,EAAS,GACf,GAAI3E,aAAgBgI,SAAWhI,EAAKmJ,aAAaF,GAAY,CACzD,MAAMnB,EAAOD,EAAgBkB,WAAW/I,EAAMoB,GAC9CuD,EAAOtF,KAAK,IAAID,KAAK0I,KAASoB,GAClC,CACA,MAAME,EAAgBpJ,EAAKiE,iBAAiB,IAAIgF,MAChD,IAAK,MAAMI,KAAWD,EAAe,CACjC,MAAMtB,EAAOD,EAAgBkB,WAAWM,EAASjI,GACjDuD,EAAOtF,KAAK,IAAID,KAAK0I,KAASoB,GAClC,CACA,OAAOvE,CACX,EC5HG,MAAM2E,EACTC,OACA,CAAC7H,IAAoB,EACrB,WAAAQ,CAAYqH,EAAS,GAEjB,GADAnK,KAAKmK,OAASA,EACVA,EAAS,EACT,MAAM,IAAIzL,MAAM,gDAExB,CACA,MAAA6E,CAAO6G,GACH,IAAK,IAAIC,EAAI,EAAGA,EAAIrK,KAAKmK,OAAQE,IAC7BD,EAAevG,OAEnB,OAAOuG,EAAelH,eAC1B,CACA,aAAOK,CAAO4G,EAAS,GACnB,OAAO,IAAID,EAAUC,EACzB,EChBG,MAAMG,UAAkC5K,EAC3C,CAACgB,IAA4B,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/types/WrapletChildrenMap.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/NodeTreeParent.ts","webpack://wraplet/./src/types/Core.ts","webpack://wraplet/./src/WrapletChildrenMap.ts","webpack://wraplet/./src/types/Map/DynamicMap.ts","webpack://wraplet/./src/Map/MapWrapper.ts","webpack://wraplet/./src/DefaultCore.ts","webpack://wraplet/./src/types/Wraplet.ts","webpack://wraplet/./src/types/Groupable.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/Map/MapRepeat.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","export function isWrapletChildrenMapWithDefaults(object) {\n return Object.getPrototypeOf(object) === Object.prototype;\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 if (!wraplet.isGettingDestroyed && !wraplet.isDestroyed) {\n wraplet.destroy();\n }\n removeWrapletFromNode(wraplet, node);\n }\n });\n}\n","const NodeTreeParentSymbol = Symbol(\"NodeTreeParent\");\nexport { NodeTreeParentSymbol };\n/* istanbul ignore next */\nexport function isNodeTreeParent(object) {\n return (object[NodeTreeParentSymbol] ===\n true);\n}\n","import { is } from \"./Utils\";\nimport { NodeTreeParentSymbol } from \"./NodeTreeParent\";\nconst CoreSymbol = Symbol(\"ChildrenManager\");\nexport { CoreSymbol };\nexport function isCore(object) {\n return is(object, CoreSymbol);\n}\n","import { isWrapletChildrenMapWithDefaults, } from \"./types/WrapletChildrenMap\";\nexport function addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n map: {},\n coreOptions: {},\n },\n ...definition,\n };\n}\nexport function fillMapWithDefaults(map) {\n const newMap = {};\n for (const id in map) {\n newMap[id] = addDefaultsToChildDefinition(map[id]);\n const subMap = map[id][\"map\"];\n if (subMap && isWrapletChildrenMapWithDefaults(subMap)) {\n newMap[id][\"map\"] = fillMapWithDefaults(subMap);\n }\n }\n return newMap;\n}\n","import { is } from \"../Utils\";\nconst DynamicMapSymbol = Symbol(\"DynamicMap\");\nexport { DynamicMapSymbol };\nexport function isDynamicMap(object) {\n return is(object, DynamicMapSymbol);\n}\n","import { isWrapletChildrenMapWithDefaults, } from \"../types/WrapletChildrenMap\";\nimport { fillMapWithDefaults } from \"../WrapletChildrenMap\";\nimport { isDynamicMap } from \"../types/Map/DynamicMap\";\nexport class MapWrapper {\n fullMap;\n startingPath;\n currentMap = null;\n path;\n currentPath = [];\n /**\n * @param fullMap\n * @param path\n * Path to the current definition.\n * @param resolveImmediately\n */\n constructor(fullMap, path = [], resolveImmediately = true) {\n this.path = path;\n this.startingPath = path;\n this.fullMap = fillMapWithDefaults(fullMap);\n if (resolveImmediately) {\n this.currentMap = this.resolve(this.path);\n }\n }\n getStartingMap() {\n return this.resolve(this.startingPath);\n }\n getCurrentMap() {\n if (!this.currentMap || this.currentPath != this.path) {\n this.currentMap = this.resolve(this.path);\n this.currentPath = this.path;\n }\n return this.currentMap;\n }\n /**\n * @param path\n * @private\n */\n findCurrentMap(path) {\n let resultMap = this.fullMap;\n for (const pathPart of path) {\n if (!resultMap[pathPart]) {\n throw new Error(`Invalid path: ${this.path.join(\".\")} . No such definition.`);\n }\n const map = resultMap[pathPart][\"map\"];\n if (isWrapletChildrenMapWithDefaults(map)) {\n resultMap = map;\n }\n else if (isDynamicMap(map)) {\n resultMap = map.create(this.clone(path, false));\n }\n else {\n throw new Error(\"Invalid map type.\");\n }\n }\n return resultMap;\n }\n up(pathPart, resolve = true) {\n if (!this.pathExists([...this.path, pathPart])) {\n throw new Error(\"Map doesn't exist.\");\n }\n this.path.push(pathPart);\n if (resolve) {\n this.currentMap = this.resolve(this.path);\n }\n }\n pathExists(path) {\n let tempMap = this.fullMap;\n for (const pathPart of path) {\n if (!Object.hasOwn(tempMap, pathPart)) {\n return false;\n }\n const map = tempMap[pathPart][\"map\"];\n if (isDynamicMap(map)) {\n return true;\n }\n if (!isWrapletChildrenMapWithDefaults(map)) {\n throw new Error(\"Invalid map type.\");\n }\n tempMap = map;\n }\n return true;\n }\n down(resolve = true) {\n if (this.path.length === 0) {\n throw new Error(\"At the root already.\");\n }\n this.path.pop();\n if (resolve) {\n this.currentMap = this.resolve(this.path);\n }\n }\n clone(path, resolveImmediately = true) {\n return new MapWrapper(this.fullMap, path, resolveImmediately);\n }\n resolve(path) {\n return this.findCurrentMap(path);\n }\n}\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, ChildrenTooManyFoundError, ChildrenAreAlreadyDestroyedError, InternalLogicError, } from \"./errors\";\nimport { isWrapletChildrenMapWithDefaults, } from \"./types/WrapletChildrenMap\";\nimport { isParentNode } from \"./utils\";\nimport { CoreSymbol } from \"./types/Core\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nimport { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { MapWrapper } from \"./Map/MapWrapper\";\nexport class DefaultCore {\n node;\n [CoreSymbol] = true;\n [NodeTreeParentSymbol] = true;\n isDestroyed = false;\n isGettingDestroyed = false;\n isGettingInitialized = false;\n isInitialized = false;\n mapWrapper;\n instantiatedChildren = {};\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, initOptions = {}) {\n this.node = node;\n if (isWrapletChildrenMapWithDefaults(map)) {\n this.mapWrapper = new MapWrapper(map);\n }\n else if (map instanceof MapWrapper) {\n this.mapWrapper = map;\n }\n else {\n throw new MapError(\"The map provided to the Core is not a valid map.\");\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 children manager,\n * so the children manager has to exist already.\n */\n init() {\n this.isGettingInitialized = true;\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n this.isInitialized = true;\n this.isGettingInitialized = false;\n }\n get map() {\n return this.mapWrapper.getStartingMap();\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 childDefinition = this.map[id];\n const multiple = childDefinition.multiple;\n const mapWrapper = this.mapWrapper.clone([...this.mapWrapper.path, id]);\n this.validateMapItem(id, childDefinition);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(childDefinition, mapWrapper, this.node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(childDefinition, mapWrapper, 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 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 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 // 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 existingWraplets = existingChild.find((wraplet) => {\n let result = false;\n wraplet.accessNode((node) => {\n if (node === childElement) {\n result = true;\n }\n });\n return result;\n });\n if (existingWraplets.length === 0) {\n return null;\n }\n if (existingWraplets.length > 1) {\n throw new InternalLogicError(\"Internal logic error. Multiple instances wrapping the same element found in the core.\");\n }\n return existingWraplets[0];\n }\n // Handle single.\n return existingChild;\n }\n instantiateSingleWrapletChild(childDefinition, childMap, node, id) {\n if (!childDefinition.selector) {\n return null;\n }\n const selector = childDefinition.selector;\n // Find children elements based on the map.\n const childElements = this.findChildren(selector, node);\n this.validateElements(id, childElements, childDefinition);\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, childDefinition, childMap, childElement);\n }\n instantiateWrapletItem(id, childDefinition, childMap, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = childDefinition.Class;\n const args = childDefinition.args;\n const wraplet = this.createIndividualWraplet(wrapletClass, node, childMap, childDefinition.coreOptions, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(childDefinition, childMap, node, id) {\n const selector = childDefinition.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildren(selector, node);\n this.validateElements(id, childElements, childDefinition);\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, childDefinition, childMap, 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, map, initOptions, args) {\n const core = new this.constructor(childElement, map, initOptions);\n return new wrapletClass(...[core, ...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 findChildren(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n 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 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 '${name}' 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 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","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { defaultGroupableAttribute, GroupableSymbol, } from \"./types/Groupable\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { isCore } from \"./types/Core\";\nimport { DefaultCore } from \"./DefaultCore\";\nexport class AbstractWraplet {\n core;\n [WrapletSymbol] = true;\n [GroupableSymbol] = true;\n [NodeTreeParentSymbol] = true;\n isGettingDestroyed = false;\n isDestroyed = false;\n isGettingInitialized = false;\n isInitialized = false;\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(core) {\n this.core = core;\n if (!isCore(core)) {\n throw new Error(\"AbstractWraplet requires a Core instance.\");\n }\n core.addDestroyChildListener(this.onChildDestroyed.bind(this));\n core.addInstantiateChildListener(this.onChildInstantiated.bind(this));\n this.initialize();\n }\n getNodeTreeChildren() {\n return this.core.getNodeTreeChildren();\n }\n setGroupsExtractor(callback) {\n this.groupsExtractor = callback;\n }\n getGroups() {\n return this.groupsExtractor(this.node);\n }\n get children() {\n return this.core.children;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n destroy() {\n this.isGettingDestroyed = true;\n for (const listener of this.destroyListeners) {\n listener(this);\n }\n this.destroyListeners.length = 0;\n this.core.destroy();\n this.isDestroyed = true;\n this.isGettingDestroyed = false;\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.isGettingInitialized = true;\n this.core.init();\n this.isInitialized = true;\n this.isGettingInitialized = false;\n }\n get node() {\n return this.core.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.core.map[actualUnknownId][\"Class\"]);\n }\n static createCore(node, map) {\n return new DefaultCore(node, map);\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, map, attribute, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n const core = AbstractWraplet.createCore(node, map);\n result.push(new this(core, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n const core = AbstractWraplet.createCore(element, map);\n result.push(new this(core, ...additional_args));\n }\n return result;\n }\n}\n","import { DynamicMapSymbol } from \"../types/Map/DynamicMap\";\nexport class MapRepeat {\n levels;\n [DynamicMapSymbol] = true;\n constructor(levels = 1) {\n this.levels = levels;\n if (levels < 1) {\n throw new Error(\"There have to be more than 0 repeated levels.\");\n }\n }\n create(parentMapClone) {\n for (let i = 0; i < this.levels; i++) {\n parentMapClone.down();\n }\n return parentMapClone.getCurrentMap();\n }\n static create(levels = 1) {\n return new MapRepeat(levels);\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","isWrapletChildrenMapWithDefaults","object","Object","getPrototypeOf","prototype","symbol","WrapletSetSymbol","Symbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","item","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","getWrapletsFromNode","node","wraplets","size","removeWrapletFromNode","wraplet","delete","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","isGettingDestroyed","isDestroyed","destroy","NodeTreeParentSymbol","CoreSymbol","addDefaultsToChildDefinition","definition","args","destructible","map","coreOptions","fillMapWithDefaults","newMap","id","subMap","DynamicMapSymbol","isDynamicMap","MapWrapper","fullMap","startingPath","currentMap","path","currentPath","constructor","resolveImmediately","resolve","getStartingMap","getCurrentMap","findCurrentMap","resultMap","pathPart","join","create","clone","up","pathExists","tempMap","hasOwn","down","length","pop","DefaultCore","isGettingInitialized","isInitialized","mapWrapper","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","initOptions","processInitOptions","init","instantiateChildren","wrapChildren","querySelectorAll","keys","childDefinition","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","getNodeTreeChildren","values","result","accessNode","childsNode","contains","findExistingWraplet","childElement","undefined","existingChild","existingWraplets","childMap","selector","childElements","findChildren","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","defaultSelectorCallback","addEventListener","uninitializedChildren","required","isRequired","elements","mapItem","Proxy","get","target","defaultInitOptions","initOptionsPartial","assign","key","entries","WrapletSymbol","isWraplet","GroupableSymbol","AbstractWraplet","core","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","onChildDestroyed","bind","onChildInstantiated","initialize","setGroupsExtractor","getGroups","isChildInstance","actualUnknownId","onlyId","createCore","createWraplets","attribute","additional_args","hasAttribute","foundElements","element","MapRepeat","levels","parentMapClone","i","DefaultWrapletSetReadonly"],"sourceRoot":""}
|
|
@@ -2,14 +2,17 @@ import { WrapletChildren } from "./WrapletChildren";
|
|
|
2
2
|
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "./WrapletChildrenMap";
|
|
3
3
|
import { DestroyChildListener } from "./DestroyChildListener";
|
|
4
4
|
import { InstantiateChildListener } from "./InstantiateChildListener";
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
import { NodeTreeParent, NodeTreeParentSymbol } from "./NodeTreeParent";
|
|
6
|
+
import { Wraplet } from "./Wraplet";
|
|
7
|
+
declare const CoreSymbol: unique symbol;
|
|
8
|
+
export { CoreSymbol };
|
|
7
9
|
/**
|
|
8
10
|
* Children manager interface that defines the public API for managing wraplet relationships
|
|
9
11
|
* and lifecycles.
|
|
10
12
|
*/
|
|
11
|
-
export interface
|
|
12
|
-
[
|
|
13
|
+
export interface Core<M extends WrapletChildrenMap = {}, N extends Node = Node> extends NodeTreeParent {
|
|
14
|
+
[CoreSymbol]: true;
|
|
15
|
+
[NodeTreeParentSymbol]: true;
|
|
13
16
|
/**
|
|
14
17
|
* Indicates whether the core is destroyed.
|
|
15
18
|
*/
|
|
@@ -18,6 +21,10 @@ export interface ChildrenManager<M extends WrapletChildrenMap = {}, N extends No
|
|
|
18
21
|
* Indicates whether the core is in the process of being destroyed.
|
|
19
22
|
*/
|
|
20
23
|
isGettingDestroyed: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Indicates whether the core is in the process of being initialized.
|
|
26
|
+
*/
|
|
27
|
+
isGettingInitialized: boolean;
|
|
21
28
|
/**
|
|
22
29
|
* Indicates whether the core has been initialized.
|
|
23
30
|
*/
|
|
@@ -26,6 +33,10 @@ export interface ChildrenManager<M extends WrapletChildrenMap = {}, N extends No
|
|
|
26
33
|
* The children map that defines the relationships between nodes.
|
|
27
34
|
*/
|
|
28
35
|
map: WrapletChildrenMapWithDefaults<M>;
|
|
36
|
+
/**
|
|
37
|
+
* Node attached to the current wraplet.
|
|
38
|
+
*/
|
|
39
|
+
node: N;
|
|
29
40
|
/**
|
|
30
41
|
* Initialize the core.
|
|
31
42
|
* This must be called after construction to fully initialize the core.
|
|
@@ -55,6 +66,7 @@ export interface ChildrenManager<M extends WrapletChildrenMap = {}, N extends No
|
|
|
55
66
|
* Add an event listener to a node and track it for cleanup.
|
|
56
67
|
*/
|
|
57
68
|
addEventListener(node: Node, eventName: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
|
|
69
|
+
getNodeTreeChildren(): Wraplet[];
|
|
58
70
|
/**
|
|
59
71
|
* Get the instantiated children.
|
|
60
72
|
*/
|
|
@@ -64,3 +76,4 @@ export interface ChildrenManager<M extends WrapletChildrenMap = {}, N extends No
|
|
|
64
76
|
*/
|
|
65
77
|
readonly uninitializedChildren: Partial<WrapletChildren<M>>;
|
|
66
78
|
}
|
|
79
|
+
export declare function isCore(object: unknown): object is Core;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { InstantiateChildListener } from "./InstantiateChildListener";
|
|
2
2
|
import { WrapletChildrenMap } from "./WrapletChildrenMap";
|
|
3
3
|
import { DestroyChildListener } from "./DestroyChildListener";
|
|
4
|
-
import { DeepWriteable } from "./Utils";
|
|
5
4
|
export type CoreInitOptions<M extends WrapletChildrenMap> = {
|
|
6
5
|
instantiateChildListeners: InstantiateChildListener<M, keyof M>[];
|
|
7
6
|
destroyChildListeners: DestroyChildListener<M, keyof M>[];
|
|
8
|
-
mapAlterCallback?: (map: DeepWriteable<M>) => void;
|
|
9
7
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../WrapletChildrenMap";
|
|
2
|
+
import { MapWrapper } from "../../Map/MapWrapper";
|
|
3
|
+
declare const DynamicMapSymbol: unique symbol;
|
|
4
|
+
export { DynamicMapSymbol };
|
|
5
|
+
export interface DynamicMap {
|
|
6
|
+
[DynamicMapSymbol]: true;
|
|
7
|
+
create<M extends WrapletChildrenMap>(parentMapClone: MapWrapper<M>): WrapletChildrenMapWithDefaults;
|
|
8
|
+
}
|
|
9
|
+
export declare function isDynamicMap(object: unknown): object is DynamicMap;
|
package/dist/types/Wraplet.d.ts
CHANGED
|
@@ -4,7 +4,9 @@ export { WrapletSymbol };
|
|
|
4
4
|
export interface Wraplet<N extends Node = Node> {
|
|
5
5
|
[WrapletSymbol]: true;
|
|
6
6
|
isInitialized: boolean;
|
|
7
|
-
|
|
7
|
+
isGettingInitialized: boolean;
|
|
8
|
+
isDestroyed: boolean;
|
|
9
|
+
isGettingDestroyed: boolean;
|
|
8
10
|
accessNode(callback: (node: N) => void): void;
|
|
9
11
|
destroy(): void;
|
|
10
12
|
addDestroyListener(callback: DestroyListener<N>): void;
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
import { Wraplet } from "./Wraplet";
|
|
2
|
+
import { WrapletChildrenMap } from "./WrapletChildrenMap";
|
|
3
|
+
import { CoreInitOptions } from "./CoreInitOptions";
|
|
4
|
+
import { DynamicMap } from "./Map/DynamicMap";
|
|
2
5
|
export type SelectorCallback<N extends ParentNode = ParentNode> = (node: N) => Node[];
|
|
3
|
-
export type WrapletChildDefinition = {
|
|
6
|
+
export type WrapletChildDefinition<M extends WrapletChildrenMap = WrapletChildrenMap> = {
|
|
4
7
|
selector?: string | SelectorCallback;
|
|
5
8
|
Class: {
|
|
6
9
|
new (...args: any[]): Wraplet<any>;
|
|
7
10
|
};
|
|
11
|
+
map?: M | DynamicMap;
|
|
12
|
+
coreOptions?: CoreInitOptions<M>;
|
|
8
13
|
required: boolean;
|
|
9
14
|
multiple: boolean;
|
|
10
15
|
args?: unknown[];
|
|
11
16
|
destructible?: boolean;
|
|
12
17
|
};
|
|
13
|
-
export type WrapletChildDefinitionWithDefaults<T extends WrapletChildDefinition> = T & {
|
|
18
|
+
export type WrapletChildDefinitionWithDefaults<T extends WrapletChildDefinition = WrapletChildDefinition, M extends WrapletChildrenMap = WrapletChildrenMap> = T & {
|
|
14
19
|
args: unknown[];
|
|
15
20
|
destructible: boolean;
|
|
21
|
+
map: M | DynamicMap;
|
|
22
|
+
coreOptions: CoreInitOptions<M>;
|
|
16
23
|
};
|
|
@@ -2,6 +2,7 @@ import { WrapletChildDefinition, WrapletChildDefinitionWithDefaults } from "./Wr
|
|
|
2
2
|
export type WrapletChildrenMap = {
|
|
3
3
|
[id: string]: WrapletChildDefinition;
|
|
4
4
|
};
|
|
5
|
-
export type WrapletChildrenMapWithDefaults<M extends WrapletChildrenMap> = {
|
|
5
|
+
export type WrapletChildrenMapWithDefaults<M extends WrapletChildrenMap = WrapletChildrenMap> = {
|
|
6
6
|
[key in keyof M]: WrapletChildDefinitionWithDefaults<M[key]>;
|
|
7
7
|
};
|
|
8
|
+
export declare function isWrapletChildrenMapWithDefaults(object: unknown): object is WrapletChildrenMapWithDefaults;
|