wraplet 0.27.0 → 0.28.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 +2 -2
- package/dist/DefaultCore.d.ts +2 -2
- package/dist/Map/MapRepeat.d.ts +1 -1
- package/dist/{types/Map → Map/types}/DynamicMap.d.ts +2 -2
- package/dist/NodeTreeManager/DefaultNodeTreeManager.d.ts +4 -4
- package/dist/NodeTreeManager/NodeTreeManager.d.ts +3 -3
- package/dist/Set/DefaultSearchableSet.d.ts +1 -1
- package/dist/Set/DefaultWrapletSet.d.ts +2 -2
- package/dist/Set/DefaultWrapletSetReadonly.d.ts +1 -1
- package/dist/{types/Set → Set/types}/WrapletSet.d.ts +1 -1
- package/dist/{types/Set → Set/types}/WrapletSetReadonly.d.ts +1 -1
- package/dist/Storage/AbstractNongranularStorage.d.ts +27 -0
- package/dist/Storage/ElementAttributeStorage.d.ts +17 -0
- package/dist/Storage/ElementStorage.d.ts +10 -28
- package/dist/Storage/NongranularStorageOptions.d.ts +5 -0
- package/dist/Storage/StorageWrapper.d.ts +20 -0
- package/dist/Storage/types/Storage.d.ts +9 -0
- package/dist/Storage/types/StorageDefaults.d.ts +1 -0
- package/dist/Storage/types/StorageReadonly.d.ts +6 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/storage.cjs +1 -1
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.d.ts +6 -2
- package/dist/storage.js +1 -1
- package/dist/storage.js.map +1 -1
- package/dist/types/Core.d.ts +2 -2
- package/dist/types/DestroyListener.d.ts +1 -1
- package/dist/types/Wraplet.d.ts +2 -1
- package/dist/types/WrapletChildDefinition.d.ts +1 -1
- package/dist/types/WrapletChildren.d.ts +1 -1
- package/dist/types/global.d.ts +1 -1
- package/dist/utils.d.ts +3 -3
- package/package.json +2 -2
- package/dist/types/Storage/Storage.d.ts +0 -9
- package/dist/types/Storage/StorageReadonly.d.ts +0 -6
- /package/dist/{types/Set → Set/types}/BaseSet.d.ts +0 -0
- /package/dist/{types/Storage → Storage/types}/StorageValidators.d.ts +0 -0
|
@@ -27,13 +27,13 @@ export declare abstract class AbstractWraplet<N extends Node = Node, M extends W
|
|
|
27
27
|
getGroups(): string[];
|
|
28
28
|
protected get children(): WrapletChildren<M>;
|
|
29
29
|
accessNode(callback: (node: N) => void): void;
|
|
30
|
-
destroy(): void
|
|
30
|
+
destroy(): Promise<void>;
|
|
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
|
+
initialize(): Promise<void>;
|
|
37
37
|
protected get node(): N;
|
|
38
38
|
/**
|
|
39
39
|
* This method will be ivoked if one of the wraplet's children has been instantiated.
|
package/dist/DefaultCore.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class DefaultCore<N extends Node = Node, M extends WrapletChildre
|
|
|
31
31
|
* processing occurs (instantiate child listeners) that needs access to the children manager,
|
|
32
32
|
* so the children manager has to exist already.
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
initialize(): Promise<void>;
|
|
35
35
|
get map(): WrapletChildrenMapWithDefaults<M>;
|
|
36
36
|
instantiateChildren(): WrapletChildren<M>;
|
|
37
37
|
syncChildren(): void;
|
|
@@ -47,7 +47,7 @@ export declare class DefaultCore<N extends Node = Node, M extends WrapletChildre
|
|
|
47
47
|
/**
|
|
48
48
|
* This method removes from nodes references to this wraplet and its children recursively.
|
|
49
49
|
*/
|
|
50
|
-
destroy(): void
|
|
50
|
+
destroy(): Promise<void>;
|
|
51
51
|
private findChildren;
|
|
52
52
|
addEventListener(node: Node, eventName: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
|
|
53
53
|
get children(): WrapletChildren<M>;
|
package/dist/Map/MapRepeat.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MapWrapper } from "./MapWrapper";
|
|
2
2
|
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../types/WrapletChildrenMap";
|
|
3
|
-
import { DynamicMap, DynamicMapSymbol } from "
|
|
3
|
+
import { DynamicMap, DynamicMapSymbol } from "./types/DynamicMap";
|
|
4
4
|
export declare class MapRepeat implements DynamicMap {
|
|
5
5
|
private readonly levels;
|
|
6
6
|
[DynamicMapSymbol]: true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "
|
|
2
|
-
import { MapWrapper } from "
|
|
1
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../../types/WrapletChildrenMap";
|
|
2
|
+
import { MapWrapper } from "../MapWrapper";
|
|
3
3
|
declare const DynamicMapSymbol: unique symbol;
|
|
4
4
|
export { DynamicMapSymbol };
|
|
5
5
|
export interface DynamicMap {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { NodeTreeManager } from "./NodeTreeManager";
|
|
2
2
|
import { Wraplet } from "../types/Wraplet";
|
|
3
|
-
import { WrapletSetReadonly } from "../types/
|
|
4
|
-
export type Initializer = (node: Node) => Wraplet[]
|
|
3
|
+
import { WrapletSetReadonly } from "../Set/types/WrapletSetReadonly";
|
|
4
|
+
export type Initializer = (node: Node) => Promise<Wraplet[]>;
|
|
5
5
|
export default class DefaultNodeTreeManager implements NodeTreeManager {
|
|
6
6
|
private initializers;
|
|
7
7
|
private items;
|
|
8
8
|
addWrapletInitializer(callback: Initializer): void;
|
|
9
|
-
initializeNodeTree(node: Node): void
|
|
10
|
-
destroyNodeTree(node: Node): void
|
|
9
|
+
initializeNodeTree(node: Node): Promise<void>;
|
|
10
|
+
destroyNodeTree(node: Node): Promise<void>;
|
|
11
11
|
getSet(): WrapletSetReadonly;
|
|
12
12
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Initializer } from "./DefaultNodeTreeManager";
|
|
2
|
-
import { WrapletSetReadonly } from "../types/
|
|
2
|
+
import { WrapletSetReadonly } from "../Set/types/WrapletSetReadonly";
|
|
3
3
|
export interface NodeTreeManager {
|
|
4
4
|
addWrapletInitializer(callback: Initializer): void;
|
|
5
|
-
initializeNodeTree(node: Node): void
|
|
6
|
-
destroyNodeTree(node: Node): void
|
|
5
|
+
initializeNodeTree(node: Node): Promise<void>;
|
|
6
|
+
destroyNodeTree(node: Node): Promise<void>;
|
|
7
7
|
getSet(): WrapletSetReadonly;
|
|
8
8
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseSet } from "
|
|
1
|
+
import { BaseSet } from "./types/BaseSet";
|
|
2
2
|
export declare class DefaultSearchableSet<T> extends Set<T> implements BaseSet<T> {
|
|
3
3
|
find(filter: (wraplet: T) => boolean): T[];
|
|
4
4
|
findOne(filter: (wraplet: T) => boolean): T | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { WrapletSet, WrapletSetSymbol } from "
|
|
1
|
+
import { WrapletSet, WrapletSetSymbol } from "./types/WrapletSet";
|
|
2
2
|
import { Wraplet } from "../types/Wraplet";
|
|
3
3
|
import { DefaultSearchableSet } from "./DefaultSearchableSet";
|
|
4
|
-
import { WrapletSetReadonlySymbol } from "
|
|
4
|
+
import { WrapletSetReadonlySymbol } from "./types/WrapletSetReadonly";
|
|
5
5
|
export declare class DefaultWrapletSet<T extends Wraplet> extends DefaultSearchableSet<T> implements WrapletSet {
|
|
6
6
|
[WrapletSetReadonlySymbol]: true;
|
|
7
7
|
[WrapletSetSymbol]: true;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Wraplet } from "../types/Wraplet";
|
|
2
|
-
import { WrapletSetReadonly, WrapletSetReadonlySymbol } from "
|
|
2
|
+
import { WrapletSetReadonly, WrapletSetReadonlySymbol } from "./types/WrapletSetReadonly";
|
|
3
3
|
import { DefaultSearchableSet } from "./DefaultSearchableSet";
|
|
4
4
|
export declare class DefaultWrapletSetReadonly<T extends Wraplet> extends DefaultSearchableSet<T> implements WrapletSetReadonly {
|
|
5
5
|
[WrapletSetReadonlySymbol]: true;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Storage } from "./types/Storage";
|
|
2
|
+
import { StorageValidators } from "./types/StorageValidators";
|
|
3
|
+
import { NongranularStorageOptions } from "./NongranularStorageOptions";
|
|
4
|
+
export declare abstract class AbstractNongranularStorage<D extends Record<string, unknown>> implements Storage<D> {
|
|
5
|
+
protected defaults: D;
|
|
6
|
+
protected validators: StorageValidators<D>;
|
|
7
|
+
private data;
|
|
8
|
+
private options;
|
|
9
|
+
constructor(defaults: D, validators: StorageValidators<D>, options: Partial<NongranularStorageOptions<D>>);
|
|
10
|
+
has(key: keyof D): Promise<boolean>;
|
|
11
|
+
get<T extends keyof D>(key: T): Promise<D[T]>;
|
|
12
|
+
getMultiple<T extends keyof D>(keys: T[]): Promise<Pick<D, T>>;
|
|
13
|
+
getAll(): Promise<D>;
|
|
14
|
+
set<T extends keyof D>(key: T, value: D[T]): Promise<void>;
|
|
15
|
+
setMultiple(data: Partial<D>): Promise<void>;
|
|
16
|
+
setAll(data: D): Promise<void>;
|
|
17
|
+
delete(key: keyof D): Promise<void>;
|
|
18
|
+
deleteMultiple(keys: (keyof D)[]): Promise<void>;
|
|
19
|
+
deleteAll(): Promise<void>;
|
|
20
|
+
refresh(): Promise<void>;
|
|
21
|
+
private fetchFreshData;
|
|
22
|
+
private validateData;
|
|
23
|
+
private validateValidators;
|
|
24
|
+
protected abstract getValue(): Promise<string>;
|
|
25
|
+
protected abstract setValue(value: D): Promise<void>;
|
|
26
|
+
protected abstract deleteAllValues(): Promise<void>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StorageValidators } from "./types/StorageValidators";
|
|
2
|
+
import { ElementOptionsMerger } from "./ElementOptionsMerger";
|
|
3
|
+
import { AbstractNongranularStorage } from "./AbstractNongranularStorage";
|
|
4
|
+
export type ElementStorageOptions<D extends Record<string, unknown>> = {
|
|
5
|
+
keepFresh: boolean;
|
|
6
|
+
elementOptionsMerger: ElementOptionsMerger<D>;
|
|
7
|
+
};
|
|
8
|
+
export declare class ElementAttributeStorage<D extends Record<string, unknown>> extends AbstractNongranularStorage<D> {
|
|
9
|
+
private element;
|
|
10
|
+
private attribute;
|
|
11
|
+
protected defaults: D;
|
|
12
|
+
protected validators: StorageValidators<D>;
|
|
13
|
+
constructor(element: Element, attribute: string, defaults: D, validators: StorageValidators<D>, options?: Partial<ElementStorageOptions<D>>);
|
|
14
|
+
protected getValue(): Promise<string>;
|
|
15
|
+
protected setValue(value: D): Promise<void>;
|
|
16
|
+
protected deleteAllValues(): Promise<void>;
|
|
17
|
+
}
|
|
@@ -1,30 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
export
|
|
5
|
-
keepFresh: boolean;
|
|
6
|
-
elementOptionsMerger: ElementOptionsMerger<D>;
|
|
7
|
-
};
|
|
8
|
-
export declare class ElementStorage<D extends Record<string, unknown>> implements Storage<D> {
|
|
1
|
+
import { StorageValidators } from "./types/StorageValidators";
|
|
2
|
+
import { AbstractNongranularStorage } from "./AbstractNongranularStorage";
|
|
3
|
+
import { NongranularStorageOptions } from "./NongranularStorageOptions";
|
|
4
|
+
export declare class ElementStorage<D extends Record<string, unknown>, E extends Element = HTMLScriptElement> extends AbstractNongranularStorage<D> {
|
|
9
5
|
private element;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
has(key: keyof D): boolean;
|
|
17
|
-
get<T extends keyof D>(key: T): D[T];
|
|
18
|
-
getMultiple<T extends keyof D>(keys: T[]): Pick<D, T>;
|
|
19
|
-
getAll(): D;
|
|
20
|
-
set<T extends keyof D>(key: T, value: D[T]): void;
|
|
21
|
-
setMultiple(data: Partial<D>): void;
|
|
22
|
-
setAll(data: D): void;
|
|
23
|
-
delete(key: keyof D): void;
|
|
24
|
-
deleteMultiple(keys: (keyof D)[]): void;
|
|
25
|
-
deleteAll(): void;
|
|
26
|
-
refresh(): void;
|
|
27
|
-
private fetchFreshData;
|
|
28
|
-
private validateData;
|
|
29
|
-
private getAttributeValue;
|
|
6
|
+
protected defaults: D;
|
|
7
|
+
protected validators: StorageValidators<D>;
|
|
8
|
+
constructor(element: E, defaults: D, validators: StorageValidators<D>, options?: Partial<NongranularStorageOptions<D>>);
|
|
9
|
+
protected getValue(): Promise<string>;
|
|
10
|
+
protected setValue(value: D): Promise<void>;
|
|
11
|
+
protected deleteAllValues(): Promise<void>;
|
|
30
12
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Storage } from "./types/Storage";
|
|
2
|
+
import { StorageValidators } from "./types/StorageValidators";
|
|
3
|
+
export declare class StorageWrapper<D extends Record<string, unknown>> implements Storage<D> {
|
|
4
|
+
private storage;
|
|
5
|
+
private defaults;
|
|
6
|
+
private validators;
|
|
7
|
+
constructor(storage: Storage<D>, defaults: D, validators: StorageValidators<D>);
|
|
8
|
+
has(key: keyof D): Promise<boolean>;
|
|
9
|
+
get<T extends keyof D>(key: T): Promise<D[T]>;
|
|
10
|
+
getMultiple<T extends keyof D>(keys: T[]): Promise<Pick<D, T>>;
|
|
11
|
+
getAll(): Promise<D>;
|
|
12
|
+
set<T extends keyof D>(key: T, value: D[T]): Promise<void>;
|
|
13
|
+
setMultiple(data: Partial<D>): Promise<void>;
|
|
14
|
+
setAll(data: D): Promise<void>;
|
|
15
|
+
delete(key: keyof D): Promise<void>;
|
|
16
|
+
deleteMultiple(keys: (keyof D)[]): Promise<void>;
|
|
17
|
+
deleteAll(): Promise<void>;
|
|
18
|
+
private validateGetValue;
|
|
19
|
+
private validateSetValue;
|
|
20
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StorageReadonly } from "./StorageReadonly";
|
|
2
|
+
export interface Storage<D extends Record<string, unknown>> extends StorageReadonly<D> {
|
|
3
|
+
set: <T extends keyof D>(key: T, value: D[T]) => Promise<void>;
|
|
4
|
+
setMultiple: (data: Partial<D>) => Promise<void>;
|
|
5
|
+
setAll: (data: D) => Promise<void>;
|
|
6
|
+
delete: (key: keyof D) => Promise<void>;
|
|
7
|
+
deleteMultiple: (keys: (keyof D)[]) => Promise<void>;
|
|
8
|
+
deleteAll: () => Promise<void>;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type StorageDefaults<D extends Record<string, unknown>> = Record<keyof D, Exclude<D[keyof D], undefined>>;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
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:()=>O});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 W(t){const e={};for(const i in t){const r=t[i];e[i]=I(r);const n=r.map;n&&h(n)&&(e[i].map=W(n))}return e}const E=Symbol("DynamicMap");function M(t){return d(t,E)}class S{fullMap;startingPath;currentMap=null;path;currentPath=[];constructor(t,e=[],i=!0){this.path=e,this.startingPath=e,this.fullMap=W(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}findMap(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.findMap(t)}}class D{node;[v]=!0;[b]=!0;isDestroyed=!1;isGettingDestroyed=!1;isGettingInitialized=!1;isInitialized=!1;mapWrapper;instantiatedChildren={};destroyChildListeners=[];instantiateChildListeners=[];listeners=[];defaultWrapletCreator=t=>{const e=new this.constructor(t.element,t.map,t.initOptions);return new t.Class(e,...t.args)};wrapletCreator=this.defaultWrapletCreator;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.wrapletCreator({id:t,Class:s,element:r,map:i,initOptions:e.coreOptions,args:o,defaultCreator:this.defaultWrapletCreator});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)}setWrapletCreator(t){this.wrapletCreator=t}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 O(t){return d(t,L)}const x=Symbol("Groupable");class z{core;[L]=!0;[x]=!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;[E]=!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});
|
|
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:()=>S,DefaultWrapletSet:()=>y,DefaultWrapletSetReadonly:()=>j,MapRepeat:()=>G,destroyWrapletsRecursively:()=>m,getWrapletsFromNode:()=>w,isWraplet:()=>L});class i extends Error{}class r extends Error{}class s extends Error{}class n extends Error{}class a extends Error{}class o 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 w(t){const e=t.wraplets;return p(e)&&0!==e.size?e:new y}function C(t,e){return!!e.wraplets&&e.wraplets.delete(t)}async function g(t,e){await e(t);const i=t.childNodes;for(const t of i)await g(t,e)}async function m(t){await g(t,async t=>{const e=w(t);for(const i of e)i.isGettingDestroyed||i.isDestroyed||await i.destroy(),C(i,t)})}const b=Symbol("NodeTreeParent"),v=Symbol("ChildrenManager");function I(t){return{args:[],destructible:!0,map:{},coreOptions:{},...t}}function W(t){const e={};for(const i in t){const r=t[i];e[i]=I(r);const s=r.map;s&&h(s)&&(e[i].map=W(s))}return e}const E=Symbol("DynamicMap");function M(t){return d(t,E)}class D{fullMap;startingPath;currentMap=null;path;currentPath=[];constructor(t,e=[],i=!0){this.path=e,this.startingPath=e,this.fullMap=W(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}findMap(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 D(this.fullMap,t,e)}resolve(t){return this.findMap(t)}}class S{node;[v]=!0;[b]=!0;isDestroyed=!1;isGettingDestroyed=!1;isGettingInitialized=!1;isInitialized=!1;mapWrapper;instantiatedChildren={};destroyChildListeners=[];instantiateChildListeners=[];listeners=[];defaultWrapletCreator=t=>{const e=new this.constructor(t.element,t.map,t.initOptions);return new t.Class(e,...t.args)};wrapletCreator=this.defaultWrapletCreator;constructor(t,e,i={}){if(this.node=t,h(e))this.mapWrapper=new D(e);else{if(!(e instanceof D))throw new r("The map provided to the Core is not a valid map.");this.mapWrapper=e}this.processInitOptions(i),this.instantiatedChildren={}}async initialize(){this.isGettingInitialized=!0;const t=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(t);const e=Object.values(this.instantiatedChildren).flatMap(t=>t?p(t)?Array.from(t):[t]:[]);await Promise.all(e.map(t=>t.initialize())),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,s=this.mapWrapper.clone([...this.mapWrapper.path,e]);this.validateMapItem(e,i),t[e]=r?this.instantiateMultipleWrapletsChild(i,s,this.node,e):this.instantiateSingleWrapletChild(i,s,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 s=t.selector,n=this.findChildren(s,i);if(this.validateElements(r,n,t),0===n.length)return null;if(n.length>1)throw new a(`${this.constructor.name}: More than one element was found for the "${r}" child. Selector used: "${s}".`);const o=n[0];return this.instantiateWrapletItem(r,t,e,o)}instantiateWrapletItem(t,e,i,r){const s=this.findExistingWraplet(t,r);if(s)return s;const n=e.Class,a=e.args,o=this.wrapletCreator({id:t,Class:n,element:r,map:i,initOptions:e.coreOptions,args:a,defaultCreator:this.defaultWrapletCreator});this.prepareIndividualWraplet(t,o);for(const e of this.instantiateChildListeners)e(o,t);return o}instantiateMultipleWrapletsChild(t,e,i,r){const s=t.selector;if(!s)return new y;const n=this.findChildren(s,i);this.validateElements(r,n,t);const a=this.instantiatedChildren&&this.instantiatedChildren[r]?this.instantiatedChildren[r]:new y;for(const i of n){if(this.findExistingWraplet(r,i))continue;const s=this.instantiateWrapletItem(r,t,e,i);a.add(s)}return a}addDestroyChildListener(t){this.destroyChildListeners.push(t)}addInstantiateChildListener(t){this.instantiateChildListeners.push(t)}setWrapletCreator(t){this.wrapletCreator=t}prepareIndividualWraplet(t,e){e.addDestroyListener(e=>{this.removeChild(e,t);for(const i of this.destroyChildListeners)i(e,t)})}async destroy(){if(this.isDestroyed)throw new o("Children are already destroyed.");this.isGettingDestroyed=!0;for(const t of this.listeners){const e=t.node,i=t.eventName,r=t.callback,s=t.options;e.removeEventListener(i,r,s)}await 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 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(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 s("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,s=e.required;if(!i&&s)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)}async destroyChildren(){for(const[t,e]of Object.entries(this.children))if(e&&this.map[t].destructible)if(p(e))for(const t of e)await t.destroy();else await e.destroy()}}const O=Symbol("Wraplet");function L(t){return d(t,O)}const x=Symbol("Groupable");class z{core;[O]=!0;[x]=!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))}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)}async destroy(){if(!this.isDestroyed&&(this.isGettingDestroyed=!0,!this.isGettingInitialized)){if(!this.isInitialized)return this.isDestroyed=!0,void(this.isGettingDestroyed=!1);for(const t of this.destroyListeners)await t(this);this.destroyListeners.length=0,await this.core.destroy(),this.isDestroyed=!0,this.isGettingDestroyed=!1}}addDestroyListener(t){this.destroyListeners.push(t)}onChildDestroyed(t,e){}async initialize(){this.isGettingInitialized=!0,await this.core.initialize(),this.isInitialized=!0,this.isGettingInitialized=!1,this.isGettingDestroyed&&await this.destroy()}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 S(t,e)}static createWraplets(t,e,i,r=[]){if(this===z)throw new Error("You cannot instantiate an abstract class.");const s=[];if(t instanceof Element&&t.hasAttribute(i)){const i=z.createCore(t,e);s.push(new this(i,...r))}const n=t.querySelectorAll(`[${i}]`);for(const t of n){const i=z.createCore(t,e);s.push(new this(i,...r))}return s}}class G{levels;[E]=!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 P=exports;for(var N in e)P[N]=e[N];e.__esModule&&Object.defineProperty(P,"__esModule",{value:!0});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","mappings":"AACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7D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AI,EAAGA,EAAItK,KAAKoK,OAAQE,IAC7BD,EAAexG,OAEnB,OAAOwG,EAAenH,eAC1B,CACA,aAAOK,CAAO6G,EAAS,GACnB,OAAO,IAAID,EAAUC,EACzB,EChBG,MAAMG,UAAkC7K,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 const def = map[id];\n newMap[id] = addDefaultsToChildDefinition(def);\n const subMap = def[\"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 findMap(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.findMap(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 defaultWrapletCreator = (args) => {\n const core = new this.constructor(args.element, args.map, args.initOptions);\n return new args.Class(core, ...args.args);\n };\n wrapletCreator = this.defaultWrapletCreator;\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.wrapletCreator({\n id: id,\n Class: wrapletClass,\n element: node,\n map: childMap,\n initOptions: childDefinition.coreOptions,\n args: args,\n defaultCreator: this.defaultWrapletCreator,\n });\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 setWrapletCreator(wrapletCreator) {\n this.wrapletCreator = wrapletCreator;\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","def","subMap","DynamicMapSymbol","isDynamicMap","MapWrapper","fullMap","startingPath","currentMap","path","currentPath","constructor","resolveImmediately","resolve","getStartingMap","getCurrentMap","findMap","resultMap","pathPart","join","create","clone","up","pathExists","tempMap","hasOwn","down","length","pop","DefaultCore","isGettingInitialized","isInitialized","mapWrapper","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","defaultWrapletCreator","core","element","initOptions","Class","wrapletCreator","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","defaultCreator","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","setWrapletCreator","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","defaultSelectorCallback","addEventListener","uninitializedChildren","required","isRequired","elements","mapItem","Proxy","target","defaultInitOptions","initOptionsPartial","assign","entries","WrapletSymbol","isWraplet","GroupableSymbol","AbstractWraplet","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","onChildDestroyed","bind","onChildInstantiated","initialize","setGroupsExtractor","getGroups","isChildInstance","actualUnknownId","onlyId","createCore","createWraplets","attribute","additional_args","hasAttribute","foundElements","MapRepeat","levels","parentMapClone","i","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,EAAaJ,GACzB,OAAO,EAAGA,EAAQG,EACtB,CCLO,MAAME,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,MAAM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AM,CAaN,eAAA0H,CAAgB/J,EAAMgK,EAAiBC,EAAS,MAC5C,OAAQD,KAAqBC,GAAUD,IACnChK,aAAgBC,KAAK0E,KAAK1C,IAAI+H,GAAwB,KAC9D,CACA,iBAAOE,CAAWrJ,EAAMoB,GACpB,OAAO,IAAIiC,EAAYrD,EAAMoB,EACjC,CAIA,qBAAOkI,CAAetJ,EAAMoB,EAAKmI,EAAWC,EAAkB,IAC1D,GAAIpK,OAASiJ,EACT,MAAM,IAAIpK,MAAM,6CAEpB,MAAMoH,EAAS,GACf,GAAIrF,aAAgBuI,SAAWvI,EAAKyJ,aAAaF,GAAY,CACzD,MAAMzF,EAAOuE,EAAgBgB,WAAWrJ,EAAMoB,GAC9CiE,EAAOhG,KAAK,IAAID,KAAK0E,KAAS0F,GAClC,CACA,MAAME,EAAgB1J,EAAK4E,iBAAiB,IAAI2E,MAChD,IAAK,MAAMxF,KAAW2F,EAAe,CACjC,MAAM5F,EAAOuE,EAAgBgB,WAAWtF,EAAS3C,GACjDiE,EAAOhG,KAAK,IAAID,KAAK0E,KAAS0F,GAClC,CACA,OAAOnE,CACX,ECjJG,MAAMsE,EACTC,OACA,CAACjI,IAAoB,EACrB,WAAAQ,CAAYyH,EAAS,GAEjB,GADAxK,KAAKwK,OAASA,EACVA,EAAS,EACT,MAAM,IAAI3L,MAAM,gDAExB,CACA,MAAA2E,CAAOiH,GACH,IAAK,IAAIC,EAAI,EAAGA,EAAI1K,KAAKwK,OAAQE,IAC7BD,EAAe3G,OAEnB,OAAO2G,EAAetH,eAC1B,CACA,aAAOK,CAAOgH,EAAS,GACnB,OAAO,IAAID,EAAUC,EACzB,EChBG,MAAMG,UAAkCjL,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/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/types/NodeTreeParent.ts","webpack://wraplet/./src/types/Core.ts","webpack://wraplet/./src/WrapletChildrenMap.ts","webpack://wraplet/./src/Map/types/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 \"../../types/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/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"./Set/types/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 async function actOnNodesRecursively(node, callback) {\n await callback(node);\n const children = node.childNodes;\n for (const child of children) {\n await actOnNodesRecursively(child, callback);\n }\n}\nexport async function destroyWrapletsRecursively(node) {\n await actOnNodesRecursively(node, async (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n if (!wraplet.isGettingDestroyed && !wraplet.isDestroyed) {\n await 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 const def = map[id];\n newMap[id] = addDefaultsToChildDefinition(def);\n const subMap = def[\"map\"];\n if (subMap && isWrapletChildrenMapWithDefaults(subMap)) {\n newMap[id][\"map\"] = fillMapWithDefaults(subMap);\n }\n }\n return newMap;\n}\n","import { is } from \"../../types/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/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 findMap(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.findMap(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 \"./Set/types/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 defaultWrapletCreator = (args) => {\n const core = new this.constructor(args.element, args.map, args.initOptions);\n return new args.Class(core, ...args.args);\n };\n wrapletCreator = this.defaultWrapletCreator;\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 async initialize() {\n this.isGettingInitialized = true;\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n const childInstances = Object.values(this.instantiatedChildren).flatMap((child) => {\n if (!child)\n return [];\n return isWrapletSet(child) ? Array.from(child) : [child];\n });\n await Promise.all(childInstances.map((child) => child.initialize()));\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.wrapletCreator({\n id: id,\n Class: wrapletClass,\n element: node,\n map: childMap,\n initOptions: childDefinition.coreOptions,\n args: args,\n defaultCreator: this.defaultWrapletCreator,\n });\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 setWrapletCreator(wrapletCreator) {\n this.wrapletCreator = wrapletCreator;\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 async 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 await 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 async 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 await item.destroy();\n }\n }\n else {\n await 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 }\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 async destroy() {\n if (this.isDestroyed) {\n // We are already destroyed.\n return;\n }\n this.isGettingDestroyed = true;\n if (this.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!this.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.isDestroyed = true;\n this.isGettingDestroyed = false;\n return;\n }\n for (const listener of this.destroyListeners) {\n await listener(this);\n }\n this.destroyListeners.length = 0;\n await 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 async initialize() {\n this.isGettingInitialized = true;\n await this.core.initialize();\n this.isInitialized = true;\n this.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (this.isGettingDestroyed) {\n await this.destroy();\n }\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/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/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","async","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","isGettingDestroyed","isDestroyed","destroy","NodeTreeParentSymbol","CoreSymbol","addDefaultsToChildDefinition","args","destructible","map","coreOptions","fillMapWithDefaults","newMap","id","def","subMap","DynamicMapSymbol","isDynamicMap","MapWrapper","fullMap","startingPath","currentMap","path","currentPath","constructor","resolveImmediately","resolve","getStartingMap","getCurrentMap","findMap","resultMap","pathPart","join","create","clone","up","pathExists","tempMap","hasOwn","down","length","pop","DefaultCore","isGettingInitialized","isInitialized","mapWrapper","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","defaultWrapletCreator","core","element","initOptions","Class","wrapletCreator","processInitOptions","initialize","instantiateChildren","wrapChildren","childInstances","values","flatMap","Promise","all","querySelectorAll","keys","childDefinition","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","getNodeTreeChildren","result","accessNode","childsNode","contains","findExistingWraplet","childElement","undefined","existingChild","existingWraplets","childMap","selector","childElements","findChildren","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","defaultCreator","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","setWrapletCreator","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","defaultSelectorCallback","addEventListener","uninitializedChildren","required","isRequired","elements","mapItem","Proxy","target","defaultInitOptions","initOptionsPartial","assign","entries","WrapletSymbol","isWraplet","GroupableSymbol","AbstractWraplet","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","onChildDestroyed","bind","onChildInstantiated","setGroupsExtractor","getGroups","isChildInstance","actualUnknownId","onlyId","createCore","createWraplets","attribute","additional_args","hasAttribute","foundElements","MapRepeat","levels","parentMapClone","i","DefaultWrapletSetReadonly"],"ignoreList":[],"sourceRoot":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,10 +3,10 @@ export type { WrapletCreator } from "./types/WrapletCreator";
|
|
|
3
3
|
export { DefaultCore } from "./DefaultCore";
|
|
4
4
|
export { AbstractWraplet } from "./AbstractWraplet";
|
|
5
5
|
export { destroyWrapletsRecursively, getWrapletsFromNode } from "./utils";
|
|
6
|
-
export type { DynamicMap } from "./types/
|
|
6
|
+
export type { DynamicMap } from "./Map/types/DynamicMap";
|
|
7
7
|
export { MapRepeat } from "./Map/MapRepeat";
|
|
8
|
-
export type { WrapletSetReadonly } from "./types/
|
|
9
|
-
export type { WrapletSet } from "./types/
|
|
8
|
+
export type { WrapletSetReadonly } from "./Set/types/WrapletSetReadonly";
|
|
9
|
+
export type { WrapletSet } from "./Set/types/WrapletSet";
|
|
10
10
|
export { DefaultWrapletSetReadonly } from "./Set/DefaultWrapletSetReadonly";
|
|
11
11
|
export { DefaultWrapletSet } from "./Set/DefaultWrapletSet";
|
|
12
12
|
export { isWraplet } from "./types/Wraplet";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t extends Error{}class e extends Error{}class i extends Error{}class r extends Error{}class n 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 p=Symbol("WrapletSetReadonly");class u extends c{[p]=!0;[l]=!0}function f(t){const e=t.wraplets;return d(e)&&0!==e.size?e:new u}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 b(t){return{args:[],destructible:!0,map:{},coreOptions:{},...t}}function v(t){const e={};for(const i in t){const r=t[i];e[i]=b(r);const n=r.map;n&&a(n)&&(e[i].map=v(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=v(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}findMap(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(a(r))e=r;else{if(!E(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(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.findMap(t)}}class M{node;[m]=!0;[g]=!0;isDestroyed=!1;isGettingDestroyed=!1;isGettingInitialized=!1;isInitialized=!1;mapWrapper;instantiatedChildren={};destroyChildListeners=[];instantiateChildListeners=[];listeners=[];defaultWrapletCreator=t=>{const e=new this.constructor(t.element,t.map,t.initOptions);return new t.Class(e,...t.args)};wrapletCreator=this.defaultWrapletCreator;constructor(t,i,r={}){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(r),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],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(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,r){if(!t.selector)return null;const s=t.selector,o=this.findChildren(s,i);if(this.validateElements(r,o,t),0===o.length)return null;if(o.length>1)throw new n(`${this.constructor.name}: More than one element was found for the "${r}" child. Selector used: "${s}".`);const a=o[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.wrapletCreator({id:t,Class:s,element:r,map:i,initOptions:e.coreOptions,args:o,defaultCreator:this.defaultWrapletCreator});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 u;const s=this.findChildren(n,i);this.validateElements(r,s,t);const o=this.instantiatedChildren&&this.instantiatedChildren[r]?this.instantiatedChildren[r]:new u;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)}setWrapletCreator(t){this.wrapletCreator=t}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,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 r("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 r("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 r=i.selector,n=i.required;if(!r&&n)throw new e(`${this.constructor.name}: Child "${t}" cannot at the same be required and have no selector.`)}validateElements(e,i,r){if(0===i.length&&r.required)throw new t(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". 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(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,r=[]){if(this===S)throw new Error("You cannot instantiate an abstract class.");const n=[];if(t instanceof Element&&t.hasAttribute(i)){const i=S.createCore(t,e);n.push(new this(i,...r))}const s=t.querySelectorAll(`[${i}]`);for(const t of s){const i=S.createCore(t,e);n.push(new this(i,...r))}return n}}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 O extends c{[p]=!0}export{S as AbstractWraplet,M as DefaultCore,u as DefaultWrapletSet,O as DefaultWrapletSetReadonly,z as MapRepeat,w as destroyWrapletsRecursively,f as getWrapletsFromNode,D as isWraplet};
|
|
1
|
+
class t extends Error{}class e extends Error{}class i extends Error{}class r extends Error{}class s extends Error{}class n extends Error{}class a extends Error{}function o(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 p=Symbol("WrapletSetReadonly");class u extends c{[p]=!0;[l]=!0}function f(t){const e=t.wraplets;return d(e)&&0!==e.size?e:new u}function y(t,e){return!!e.wraplets&&e.wraplets.delete(t)}async function w(t,e){await e(t);const i=t.childNodes;for(const t of i)await w(t,e)}async function C(t){await w(t,async t=>{const e=f(t);for(const i of e)i.isGettingDestroyed||i.isDestroyed||await i.destroy(),y(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){const r=t[i];e[i]=v(r);const s=r.map;s&&o(s)&&(e[i].map=b(s))}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}findMap(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(o(r))e=r;else{if(!E(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(E(t))return!0;if(!o(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.findMap(t)}}class D{node;[m]=!0;[g]=!0;isDestroyed=!1;isGettingDestroyed=!1;isGettingInitialized=!1;isInitialized=!1;mapWrapper;instantiatedChildren={};destroyChildListeners=[];instantiateChildListeners=[];listeners=[];defaultWrapletCreator=t=>{const e=new this.constructor(t.element,t.map,t.initOptions);return new t.Class(e,...t.args)};wrapletCreator=this.defaultWrapletCreator;constructor(t,i,r={}){if(this.node=t,o(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(r),this.instantiatedChildren={}}async initialize(){this.isGettingInitialized=!0;const t=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(t);const e=Object.values(this.instantiatedChildren).flatMap(t=>t?d(t)?Array.from(t):[t]:[]);await Promise.all(e.map(t=>t.initialize())),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],r=i.multiple,s=this.mapWrapper.clone([...this.mapWrapper.path,e]);this.validateMapItem(e,i),t[e]=r?this.instantiateMultipleWrapletsChild(i,s,this.node,e):this.instantiateSingleWrapletChild(i,s,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 a("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 a("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,a=this.findChildren(n,i);if(this.validateElements(r,a,t),0===a.length)return null;if(a.length>1)throw new s(`${this.constructor.name}: More than one element was found for the "${r}" child. Selector used: "${n}".`);const o=a[0];return this.instantiateWrapletItem(r,t,e,o)}instantiateWrapletItem(t,e,i,r){const s=this.findExistingWraplet(t,r);if(s)return s;const n=e.Class,a=e.args,o=this.wrapletCreator({id:t,Class:n,element:r,map:i,initOptions:e.coreOptions,args:a,defaultCreator:this.defaultWrapletCreator});this.prepareIndividualWraplet(t,o);for(const e of this.instantiateChildListeners)e(o,t);return o}instantiateMultipleWrapletsChild(t,e,i,r){const s=t.selector;if(!s)return new u;const n=this.findChildren(s,i);this.validateElements(r,n,t);const a=this.instantiatedChildren&&this.instantiatedChildren[r]?this.instantiatedChildren[r]:new u;for(const i of n){if(this.findExistingWraplet(r,i))continue;const s=this.instantiateWrapletItem(r,t,e,i);a.add(s)}return a}addDestroyChildListener(t){this.destroyChildListeners.push(t)}addInstantiateChildListener(t){this.instantiateChildListeners.push(t)}setWrapletCreator(t){this.wrapletCreator=t}prepareIndividualWraplet(t,e){e.addDestroyListener(e=>{this.removeChild(e,t);for(const i of this.destroyChildListeners)i(e,t)})}async destroy(){if(this.isDestroyed)throw new n("Children are already destroyed.");this.isGettingDestroyed=!0;for(const t of this.listeners){const e=t.node,i=t.eventName,r=t.callback,s=t.options;e.removeEventListener(i,r,s)}await 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 r("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 r("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 a("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 a("Internal logic error. Destroyed child couldn't be removed because it's already null.");this.instantiatedChildren[e]=null}}validateMapItem(t,i){const r=i.selector,s=i.required;if(!r&&s)throw new e(`${this.constructor.name}: Child "${t}" cannot at the same be required and have no selector.`)}validateElements(e,i,r){if(0===i.length&&r.required)throw new t(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". 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)}async destroyChildren(){for(const[t,e]of Object.entries(this.children))if(e&&this.map[t].destructible)if(d(e))for(const t of e)await t.destroy();else await e.destroy()}}const M=Symbol("Wraplet");function L(t){return h(t,M)}const x=Symbol("Groupable");class z{core;[M]=!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))}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)}async destroy(){if(!this.isDestroyed&&(this.isGettingDestroyed=!0,!this.isGettingInitialized)){if(!this.isInitialized)return this.isDestroyed=!0,void(this.isGettingDestroyed=!1);for(const t of this.destroyListeners)await t(this);this.destroyListeners.length=0,await this.core.destroy(),this.isDestroyed=!0,this.isGettingDestroyed=!1}}addDestroyListener(t){this.destroyListeners.push(t)}onChildDestroyed(t,e){}async initialize(){this.isGettingInitialized=!0,await this.core.initialize(),this.isInitialized=!0,this.isGettingInitialized=!1,this.isGettingDestroyed&&await this.destroy()}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 s=[];if(t instanceof Element&&t.hasAttribute(i)){const i=z.createCore(t,e);s.push(new this(i,...r))}const n=t.querySelectorAll(`[${i}]`);for(const t of n){const i=z.createCore(t,e);s.push(new this(i,...r))}return s}}class S{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 S(t)}}class G extends c{[p]=!0}export{z as AbstractWraplet,D as DefaultCore,u as DefaultWrapletSet,G as DefaultWrapletSetReadonly,S as MapRepeat,C as destroyWrapletsRecursively,f as getWrapletsFromNode,L 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,OCdjC,SAASO,EAAiCC,GAC7C,OAAOC,OAAOC,eAAeF,KAAYC,OAAOE,SACpD,CCEA,MAAM,EAAK,CAACH,EAAQI,IACU,iBAAXJ,GACA,OAAXA,IACmB,IAAnBA,EAAOI,GCNTC,EAAmBC,OAAO,cAEzB,SAASC,EAAaP,GACzB,OAAO,EAAGA,EAAQK,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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CACzD,MAAMxF,EAAOqE,EAAgBiB,WAAWpJ,EAAMoB,GAC9C6D,EAAO5F,KAAK,IAAID,KAAK0E,KAASyF,GAClC,CACA,MAAME,EAAgBzJ,EAAKuE,iBAAiB,IAAI+E,MAChD,IAAK,MAAMvF,KAAW0F,EAAe,CACjC,MAAM3F,EAAOqE,EAAgBiB,WAAWrF,EAAS3C,GACjD6D,EAAO5F,KAAK,IAAID,KAAK0E,KAASyF,GAClC,CACA,OAAOtE,CACX,EC5HG,MAAMyE,EACTC,OACA,CAAChI,IAAoB,EACrB,WAAAQ,CAAYwH,EAAS,GAEjB,GADAvK,KAAKuK,OAASA,EACVA,EAAS,EACT,MAAM,IAAI7L,MAAM,gDAExB,CACA,MAAA8E,CAAOgH,GACH,IAAK,IAAIC,EAAI,EAAGA,EAAIzK,KAAKuK,OAAQE,IAC7BD,EAAe1G,OAEnB,OAAO0G,EAAerH,eAC1B,CACA,aAAOK,CAAO+G,EAAS,GACnB,OAAO,IAAID,EAAUC,EACzB,EChBG,MAAMG,UAAkChL,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 const def = map[id];\n newMap[id] = addDefaultsToChildDefinition(def);\n const subMap = def[\"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 findMap(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.findMap(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 defaultWrapletCreator = (args) => {\n const core = new this.constructor(args.element, args.map, args.initOptions);\n return new args.Class(core, ...args.args);\n };\n wrapletCreator = this.defaultWrapletCreator;\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.wrapletCreator({\n id: id,\n Class: wrapletClass,\n element: node,\n map: childMap,\n initOptions: childDefinition.coreOptions,\n args: args,\n defaultCreator: this.defaultWrapletCreator,\n });\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 setWrapletCreator(wrapletCreator) {\n this.wrapletCreator = wrapletCreator;\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","def","subMap","DynamicMapSymbol","isDynamicMap","MapWrapper","fullMap","startingPath","currentMap","path","currentPath","constructor","resolveImmediately","resolve","getStartingMap","getCurrentMap","findMap","resultMap","pathPart","join","create","clone","up","pathExists","tempMap","hasOwn","down","length","pop","DefaultCore","isGettingInitialized","isInitialized","mapWrapper","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","defaultWrapletCreator","core","element","initOptions","Class","wrapletCreator","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","defaultCreator","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","setWrapletCreator","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","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","onChildDestroyed","bind","onChildInstantiated","initialize","setGroupsExtractor","getGroups","isChildInstance","actualUnknownId","onlyId","createCore","createWraplets","attribute","additional_args","hasAttribute","foundElements","MapRepeat","levels","parentMapClone","i","DefaultWrapletSetReadonly"],"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,IAAK,MAAM1F,KAAW6F,EAAe,CACjC,MAAM9F,EAAOyE,EAAgBgB,WAAWxF,EAAS3C,GACjDiE,EAAOjG,KAAK,IAAID,KAAK2E,KAAS4F,GAClC,CACA,OAAOrE,CACX,ECjJG,MAAMwE,EACTC,OACA,CAACnI,IAAoB,EACrB,WAAAQ,CAAY2H,EAAS,GAEjB,GADA3K,KAAK2K,OAASA,EACVA,EAAS,EACT,MAAM,IAAIjM,MAAM,gDAExB,CACA,MAAA+E,CAAOmH,GACH,IAAK,IAAIC,EAAI,EAAGA,EAAI7K,KAAK2K,OAAQE,IAC7BD,EAAe7G,OAEnB,OAAO6G,EAAexH,eAC1B,CACA,aAAOK,CAAOkH,EAAS,GACnB,OAAO,IAAID,EAAUC,EACzB,EChBG,MAAMG,UAAkCpL,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/Set/types/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/Set/types/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/types/NodeTreeParent.ts","webpack://wraplet/./src/types/Core.ts","webpack://wraplet/./src/WrapletChildrenMap.ts","webpack://wraplet/./src/Map/types/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 \"../../types/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/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol } from \"./types/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"./Set/types/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 async function actOnNodesRecursively(node, callback) {\n await callback(node);\n const children = node.childNodes;\n for (const child of children) {\n await actOnNodesRecursively(child, callback);\n }\n}\nexport async function destroyWrapletsRecursively(node) {\n await actOnNodesRecursively(node, async (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n if (!wraplet.isGettingDestroyed && !wraplet.isDestroyed) {\n await 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 const def = map[id];\n newMap[id] = addDefaultsToChildDefinition(def);\n const subMap = def[\"map\"];\n if (subMap && isWrapletChildrenMapWithDefaults(subMap)) {\n newMap[id][\"map\"] = fillMapWithDefaults(subMap);\n }\n }\n return newMap;\n}\n","import { is } from \"../../types/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/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 findMap(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.findMap(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 \"./Set/types/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 defaultWrapletCreator = (args) => {\n const core = new this.constructor(args.element, args.map, args.initOptions);\n return new args.Class(core, ...args.args);\n };\n wrapletCreator = this.defaultWrapletCreator;\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 async initialize() {\n this.isGettingInitialized = true;\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n const childInstances = Object.values(this.instantiatedChildren).flatMap((child) => {\n if (!child)\n return [];\n return isWrapletSet(child) ? Array.from(child) : [child];\n });\n await Promise.all(childInstances.map((child) => child.initialize()));\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.wrapletCreator({\n id: id,\n Class: wrapletClass,\n element: node,\n map: childMap,\n initOptions: childDefinition.coreOptions,\n args: args,\n defaultCreator: this.defaultWrapletCreator,\n });\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 setWrapletCreator(wrapletCreator) {\n this.wrapletCreator = wrapletCreator;\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 async 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 await 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 async 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 await item.destroy();\n }\n }\n else {\n await 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 }\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 async destroy() {\n if (this.isDestroyed) {\n // We are already destroyed.\n return;\n }\n this.isGettingDestroyed = true;\n if (this.isGettingInitialized) {\n // If we are still initializing, then postpone destruction until after\n // initialization is finished.\n // We are leaving this method, but with `isGettingDestroyed` set to true, so\n // the initialization process will know to return here after it will finish.\n return;\n }\n if (!this.isInitialized) {\n // If we are not initialized, then we have nothing to do here.\n this.isDestroyed = true;\n this.isGettingDestroyed = false;\n return;\n }\n for (const listener of this.destroyListeners) {\n await listener(this);\n }\n this.destroyListeners.length = 0;\n await 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 async initialize() {\n this.isGettingInitialized = true;\n await this.core.initialize();\n this.isInitialized = true;\n this.isGettingInitialized = false;\n // If destruction has been invoked in the meantime, we can finally do it, when initialization\n // is finished.\n if (this.isGettingDestroyed) {\n await this.destroy();\n }\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/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/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","async","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","isGettingDestroyed","isDestroyed","destroy","NodeTreeParentSymbol","CoreSymbol","addDefaultsToChildDefinition","definition","args","destructible","map","coreOptions","fillMapWithDefaults","newMap","id","def","subMap","DynamicMapSymbol","isDynamicMap","MapWrapper","fullMap","startingPath","currentMap","path","currentPath","constructor","resolveImmediately","resolve","getStartingMap","getCurrentMap","findMap","resultMap","pathPart","join","create","clone","up","pathExists","tempMap","hasOwn","down","length","pop","DefaultCore","isGettingInitialized","isInitialized","mapWrapper","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","defaultWrapletCreator","core","element","initOptions","Class","wrapletCreator","processInitOptions","initialize","instantiateChildren","wrapChildren","childInstances","values","flatMap","Promise","all","querySelectorAll","keys","childDefinition","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","getNodeTreeChildren","result","accessNode","childsNode","contains","findExistingWraplet","childElement","undefined","existingChild","existingWraplets","childMap","selector","childElements","findChildren","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","defaultCreator","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","setWrapletCreator","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","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","onChildDestroyed","bind","onChildInstantiated","setGroupsExtractor","getGroups","isChildInstance","actualUnknownId","onlyId","createCore","createWraplets","attribute","additional_args","hasAttribute","foundElements","MapRepeat","levels","parentMapClone","i","DefaultWrapletSetReadonly"],"ignoreList":[],"sourceRoot":""}
|
package/dist/storage.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var t={d:(e,
|
|
1
|
+
var t={d:(e,a)=>{for(var s in a)t.o(a,s)&&!t.o(e,s)&&Object.defineProperty(e,s,{enumerable:!0,get:a[s]})},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,{AbstractNongranularStorage:()=>i,ElementAttributeStorage:()=>l,ElementStorage:()=>r,StorageWrapper:()=>s});class a extends Error{}class s{storage;defaults;validators;constructor(t,e,a){this.storage=t,this.defaults=e,this.validators=a}async has(t){return await this.storage.has(t)}async get(t){const e=await this.storage.get(t);return void 0!==e?(this.validateGetValue(t,e),e):this.defaults[t]}async getMultiple(t){const e={...await this.storage.getMultiple(t)};for(const a of t)void 0===e[a]&&(e[a]=this.defaults[a]);return e}async getAll(){const t={...await this.storage.getAll()};for(const e of Object.keys(this.defaults))void 0===t[e]&&(t[e]=this.defaults[e]);return t}async set(t,e){this.validateSetValue(t,e),await this.storage.set(t,e)}async setMultiple(t){for(const e in t)this.validateSetValue(e,t[e]);await this.storage.setMultiple(t)}async setAll(t){for(const e in t)this.validateSetValue(e,t[e]);await this.storage.setAll(t)}async delete(t){await this.storage.delete(t)}async deleteMultiple(t){await this.storage.deleteMultiple(t)}async deleteAll(){await this.storage.deleteAll()}validateGetValue(t,e){if(!this.validators[t](e))throw new a(`Got an invalid value for the key ${String(t)}.`)}validateSetValue(t,e){if(!this.validators[t](e))throw new a(`Attempted to set an invalid value for the key ${String(t)}.`)}}class i{defaults;validators;data=null;options;constructor(t,e,a){this.defaults=t,this.validators=e,this.validateValidators(e),this.options={keepFresh:!0,elementOptionsMerger:(t,e)=>({...t,...e}),...a}}async has(t){return t in await this.getAll()}async get(t){return(await this.getAll())[t]}async getMultiple(t){const e=await this.getAll();return t.reduce((t,a)=>(t[a]=e[a],t),{})}async getAll(){return this.options.keepFresh&&await this.refresh(),this.data||await this.refresh(),this.data}async set(t,e){if(!this.validators[t](e))throw new a(`Attempted to set an invalid value for the key ${String(t)}.`);const s=await this.getValue(),i=JSON.parse(s);i[t]=e,await this.setAll(i)}async setMultiple(t){const e=await this.getAll();await this.setAll({...e,...t})}async setAll(t){await this.setValue(t)}async delete(t){const e=await this.getAll();t in e&&(delete e[t],await this.setValue(e))}async deleteMultiple(t){const e=await this.getAll();for(const a of t)delete e[a];await this.setAll(e)}async deleteAll(){await this.deleteAllValues(),await this.refresh()}async refresh(){this.data=await this.fetchFreshData()}async fetchFreshData(){const t=await this.getValue();if("{"!==t.charAt(0))throw new a("Data has to be defined as an object.");const e=JSON.parse(t);if(!this.validateData(e))throw new a("Invalid storage value.");return this.options.elementOptionsMerger(this.defaults,e)}validateData(t){for(const e in t){if(!(e in this.validators))return!1;if(!this.validators[e](t[e]))return!1}return!0}validateValidators(t){for(const e in t)if("function"!=typeof t[e])throw new a(`Validator for ${e} is not a function.`)}}class l extends i{element;attribute;defaults;validators;constructor(t,e,a,s,i={}){super(a,s,i),this.element=t,this.attribute=e,this.defaults=a,this.validators=s}async getValue(){return this.element.getAttribute(this.attribute)||"{}"}async setValue(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}async deleteAllValues(){this.element.removeAttribute(this.attribute)}}class r extends i{element;defaults;validators;constructor(t,e,a,s={}){super(e,a,s),this.element=t,this.defaults=e,this.validators=a}async getValue(){return this.element.textContent||"{}"}async setValue(t){this.element.textContent=JSON.stringify(t)}async deleteAllValues(){this.element.textContent="{}"}}var n=exports;for(var o in e)n[o]=e[o];e.__esModule&&Object.defineProperty(n,"__esModule",{value:!0});
|
|
2
2
|
//# sourceMappingURL=storage.cjs.map
|
package/dist/storage.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.cjs","mappings":"AACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,0CCGhD,MAAMC,UAA+BC,OCPrC,MAAMC,EACTC,QACAC,UACAC,SACAC,WACAC,KACAC,QACA,WAAAC,CAAYN,EAASC,EAAWC,EAAUC,EAAYE,EAAU,CAAC,GAC7DE,KAAKP,QAAUA,EACfO,KAAKN,UAAYA,EACjBM,KAAKL,SAAWA,EAChBK,KAAKJ,WAAaA,EAClBI,KAAKF,QAAU,CACXG,WAAW,EACXC,qBAAsB,CAACC,EAAgBC,KAC5B,IAAKD,KAAmBC,OAEhCN,GAEPE,KAAKH,KAAOG,KAAKK,gBACrB,CACA,GAAAC,CAAI9B,GAEA,OAAOA,KADMwB,KAAKO,QAEtB,CACA,GAAA1B,CAAIL,GAEA,OADawB,KAAKO,SACN/B,EAChB,CACA,WAAAgC,CAAYC,GACR,MAAMZ,EA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,KAAKF,QAAQI,qBAAqBF,KAAKL,SAAUE,EAC5D,CACA,YAAAgC,CAAahC,GACT,IAAK,MAAMrB,KAAOqB,EAAM,CACpB,KAAMrB,KAAOwB,KAAKJ,YAEd,OADAkC,QAAQC,KAAK,UAAUvD,gCAChB,EAEN,GAAoC,mBAAzBwB,KAAKJ,WAAWpB,GAE5B,OADAsD,QAAQC,KAAK,wBAAwBvD,yBAC9B,EAEN,IAAKwB,KAAKJ,WAAWpB,GAAKqB,EAAKrB,IAChC,OAAO,CAEf,CACA,OAAO,CACX,CACA,iBAAAwC,CAAkBtB,GACd,OAAOM,KAAKP,QAAQuC,aAAatC,IAAc,IACnD,E","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class ElementStorage {\n element;\n attribute;\n defaults;\n validators;\n data;\n options;\n constructor(element, attribute, defaults, validators, options = {}) {\n this.element = element;\n this.attribute = attribute;\n this.defaults = defaults;\n this.validators = validators;\n this.options = {\n keepFresh: true,\n elementOptionsMerger: (defaultOptions, elementOptions) => {\n return { ...defaultOptions, ...elementOptions };\n },\n ...options,\n };\n this.data = this.fetchFreshData();\n }\n has(key) {\n const data = this.getAll();\n return key in data;\n }\n get(key) {\n const data = this.getAll();\n return data[key];\n }\n getMultiple(keys) {\n const data = this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n getAll() {\n if (this.options.keepFresh) {\n this.refresh();\n }\n return this.data;\n }\n set(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n const attributeValue = this.getAttributeValue(this.attribute);\n const data = JSON.parse(attributeValue);\n data[key] = value;\n this.setAll(data);\n }\n setMultiple(data) {\n const oldData = this.getAll();\n this.setAll({ ...oldData, ...data });\n }\n setAll(data) {\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n delete(key) {\n const data = this.getAll();\n if (!(key in data)) {\n return;\n }\n delete data[key];\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n deleteMultiple(keys) {\n const data = this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n this.setAll(data);\n }\n deleteAll() {\n this.element.removeAttribute(this.attribute);\n this.refresh();\n }\n refresh() {\n this.data = this.fetchFreshData();\n }\n fetchFreshData() {\n const dataString = this.getAttributeValue(this.attribute);\n if (dataString.charAt(0) !== \"{\") {\n throw new StorageValidationError(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return this.options.elementOptionsMerger(this.defaults, data);\n }\n validateData(data) {\n for (const key in data) {\n if (!(key in this.validators)) {\n console.warn(`Option ${key} doesn't have a validator.`);\n return false;\n }\n else if (typeof this.validators[key] !== \"function\") {\n console.warn(`Validator for option ${key} is not a function.`);\n return false;\n }\n else if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n getAttributeValue(attribute) {\n return this.element.getAttribute(attribute) || \"{}\";\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","StorageValidationError","Error","ElementStorage","element","attribute","defaults","validators","data","options","constructor","this","keepFresh","elementOptionsMerger","defaultOptions","elementOptions","fetchFreshData","has","getAll","getMultiple","keys","reduce","acc","refresh","set","String","attributeValue","getAttributeValue","JSON","parse","setAll","setMultiple","oldData","setAttribute","stringify","deleteMultiple","deleteAll","removeAttribute","dataString","charAt","validateData","console","warn","getAttribute"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"storage.cjs","mappings":"AACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,8HCGhD,MAAMC,UAA+BC,OCPrC,MAAMC,EACTC,QACAC,SACAC,WACA,WAAAC,CAAYH,EAASC,EAAUC,GAC3BE,KAAKJ,QAAUA,EACfI,KAAKH,SAAWA,EAChBG,KAAKF,WAAaA,CACtB,CACA,SAAMG,CAAItB,GACN,aAAaqB,KAAKJ,QAAQK,IAAItB,EA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C,CAAYwC,EAAS1C,EAAUC,EAAYoB,EAAU,CAAC,GAClDuB,MAAM5C,EAAUC,EAAYoB,GAC5BlB,KAAKuC,QAAUA,EACfvC,KAAKH,SAAWA,EAChBG,KAAKF,WAAaA,CACtB,CACA,cAAM8B,GACF,OAAO5B,KAAKuC,QAAQQ,aAAe,IACvC,CACA,cAAMf,CAASxC,GACXQ,KAAKuC,QAAQQ,YAAclB,KAAKe,UAAUpD,EAC9C,CACA,qBAAMyC,GACFjC,KAAKuC,QAAQQ,YAAc,IAC/B,E","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/StorageWrapper.ts","webpack://wraplet/./src/Storage/AbstractNongranularStorage.ts","webpack://wraplet/./src/Storage/ElementAttributeStorage.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class StorageWrapper {\n storage;\n defaults;\n validators;\n constructor(storage, defaults, validators) {\n this.storage = storage;\n this.defaults = defaults;\n this.validators = validators;\n }\n async has(key) {\n return await this.storage.has(key);\n }\n async get(key) {\n const value = await this.storage.get(key);\n // Only validate when the underlying storage actually returned a value.\n if (value !== undefined) {\n this.validateGetValue(key, value);\n return value;\n }\n return this.defaults[key];\n }\n async getMultiple(keys) {\n const multiple = await this.storage.getMultiple(keys);\n const result = { ...multiple };\n for (const key of keys) {\n if (result[key] === undefined) {\n result[key] = this.defaults[key];\n }\n }\n return result;\n }\n async getAll() {\n const all = await this.storage.getAll();\n const result = { ...all };\n for (const key of Object.keys(this.defaults)) {\n if (result[key] === undefined) {\n result[key] = this.defaults[key];\n }\n }\n return result;\n }\n async set(key, value) {\n this.validateSetValue(key, value);\n await this.storage.set(key, value);\n }\n async setMultiple(data) {\n for (const key in data) {\n this.validateSetValue(key, data[key]);\n }\n await this.storage.setMultiple(data);\n }\n async setAll(data) {\n for (const key in data) {\n this.validateSetValue(key, data[key]);\n }\n await this.storage.setAll(data);\n }\n async delete(key) {\n await this.storage.delete(key);\n }\n async deleteMultiple(keys) {\n await this.storage.deleteMultiple(keys);\n }\n async deleteAll() {\n await this.storage.deleteAll();\n }\n validateGetValue(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Got an invalid value for the key ${String(key)}.`);\n }\n }\n validateSetValue(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n }\n}\n","import { StorageValidationError } from \"../errors\";\nexport class AbstractNongranularStorage {\n defaults;\n validators;\n data = null;\n options;\n constructor(defaults, validators, options) {\n this.defaults = defaults;\n this.validators = validators;\n this.validateValidators(validators);\n this.options = {\n keepFresh: true,\n elementOptionsMerger: (defaultOptions, elementOptions) => {\n return { ...defaultOptions, ...elementOptions };\n },\n ...options,\n };\n }\n async has(key) {\n const data = await this.getAll();\n return key in data;\n }\n async get(key) {\n const data = await this.getAll();\n return data[key];\n }\n async getMultiple(keys) {\n const data = await this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n async getAll() {\n if (this.options.keepFresh) {\n await this.refresh();\n }\n if (!this.data) {\n await this.refresh();\n }\n return this.data;\n }\n async set(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n const attributeValue = await this.getValue();\n const data = JSON.parse(attributeValue);\n data[key] = value;\n await this.setAll(data);\n }\n async setMultiple(data) {\n const oldData = await this.getAll();\n await this.setAll({ ...oldData, ...data });\n }\n async setAll(data) {\n await this.setValue(data);\n }\n async delete(key) {\n const data = await this.getAll();\n if (!(key in data)) {\n return;\n }\n delete data[key];\n await this.setValue(data);\n }\n async deleteMultiple(keys) {\n const data = await this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n await this.setAll(data);\n }\n async deleteAll() {\n await this.deleteAllValues();\n await this.refresh();\n }\n async refresh() {\n this.data = await this.fetchFreshData();\n }\n async fetchFreshData() {\n const dataString = await this.getValue();\n if (dataString.charAt(0) !== \"{\") {\n throw new StorageValidationError(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return this.options.elementOptionsMerger(this.defaults, data);\n }\n validateData(data) {\n for (const key in data) {\n if (!(key in this.validators)) {\n return false;\n }\n else if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n validateValidators(validators) {\n for (const key in validators) {\n if (typeof validators[key] !== \"function\") {\n throw new StorageValidationError(`Validator for ${key} is not a function.`);\n }\n }\n }\n}\n","import { AbstractNongranularStorage } from \"./AbstractNongranularStorage\";\nexport class ElementAttributeStorage extends AbstractNongranularStorage {\n element;\n attribute;\n defaults;\n validators;\n constructor(element, attribute, defaults, validators, options = {}) {\n super(defaults, validators, options);\n this.element = element;\n this.attribute = attribute;\n this.defaults = defaults;\n this.validators = validators;\n }\n async getValue() {\n return this.element.getAttribute(this.attribute) || \"{}\";\n }\n async setValue(value) {\n this.element.setAttribute(this.attribute, JSON.stringify(value));\n }\n async deleteAllValues() {\n this.element.removeAttribute(this.attribute);\n }\n}\n","import { AbstractNongranularStorage } from \"./AbstractNongranularStorage\";\nexport class ElementStorage extends AbstractNongranularStorage {\n element;\n defaults;\n validators;\n constructor(element, defaults, validators, options = {}) {\n super(defaults, validators, options);\n this.element = element;\n this.defaults = defaults;\n this.validators = validators;\n }\n async getValue() {\n return this.element.textContent || \"{}\";\n }\n async setValue(value) {\n this.element.textContent = JSON.stringify(value);\n }\n async deleteAllValues() {\n this.element.textContent = \"{}\";\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","StorageValidationError","Error","StorageWrapper","storage","defaults","validators","constructor","this","has","undefined","validateGetValue","getMultiple","keys","result","getAll","set","validateSetValue","setMultiple","data","setAll","delete","deleteMultiple","deleteAll","String","AbstractNongranularStorage","options","validateValidators","keepFresh","elementOptionsMerger","defaultOptions","elementOptions","reduce","acc","refresh","attributeValue","getValue","JSON","parse","oldData","setValue","deleteAllValues","fetchFreshData","dataString","charAt","validateData","ElementAttributeStorage","element","attribute","super","getAttribute","setAttribute","stringify","removeAttribute","ElementStorage","textContent"],"ignoreList":[],"sourceRoot":""}
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
export { StorageWrapper } from "./Storage/StorageWrapper";
|
|
2
|
+
export { AbstractNongranularStorage } from "./Storage/AbstractNongranularStorage";
|
|
3
|
+
export { ElementAttributeStorage } from "./Storage/ElementAttributeStorage";
|
|
1
4
|
export { ElementStorage } from "./Storage/ElementStorage";
|
|
2
5
|
export type { ElementOptionsMerger } from "./Storage/ElementOptionsMerger";
|
|
3
|
-
export type { Storage } from "./types/Storage
|
|
4
|
-
export type { StorageValidators, StorageValidator, } from "./types/
|
|
6
|
+
export type { Storage } from "./Storage/types/Storage";
|
|
7
|
+
export type { StorageValidators, StorageValidator, } from "./Storage/types/StorageValidators";
|
|
8
|
+
export type { NongranularStorageOptions } from "./Storage/NongranularStorageOptions";
|
package/dist/storage.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t extends Error{}class e{
|
|
1
|
+
class t extends Error{}class e{storage;defaults;validators;constructor(t,e,a){this.storage=t,this.defaults=e,this.validators=a}async has(t){return await this.storage.has(t)}async get(t){const e=await this.storage.get(t);return void 0!==e?(this.validateGetValue(t,e),e):this.defaults[t]}async getMultiple(t){const e={...await this.storage.getMultiple(t)};for(const a of t)void 0===e[a]&&(e[a]=this.defaults[a]);return e}async getAll(){const t={...await this.storage.getAll()};for(const e of Object.keys(this.defaults))void 0===t[e]&&(t[e]=this.defaults[e]);return t}async set(t,e){this.validateSetValue(t,e),await this.storage.set(t,e)}async setMultiple(t){for(const e in t)this.validateSetValue(e,t[e]);await this.storage.setMultiple(t)}async setAll(t){for(const e in t)this.validateSetValue(e,t[e]);await this.storage.setAll(t)}async delete(t){await this.storage.delete(t)}async deleteMultiple(t){await this.storage.deleteMultiple(t)}async deleteAll(){await this.storage.deleteAll()}validateGetValue(e,a){if(!this.validators[e](a))throw new t(`Got an invalid value for the key ${String(e)}.`)}validateSetValue(e,a){if(!this.validators[e](a))throw new t(`Attempted to set an invalid value for the key ${String(e)}.`)}}class a{defaults;validators;data=null;options;constructor(t,e,a){this.defaults=t,this.validators=e,this.validateValidators(e),this.options={keepFresh:!0,elementOptionsMerger:(t,e)=>({...t,...e}),...a}}async has(t){return t in await this.getAll()}async get(t){return(await this.getAll())[t]}async getMultiple(t){const e=await this.getAll();return t.reduce((t,a)=>(t[a]=e[a],t),{})}async getAll(){return this.options.keepFresh&&await this.refresh(),this.data||await this.refresh(),this.data}async set(e,a){if(!this.validators[e](a))throw new t(`Attempted to set an invalid value for the key ${String(e)}.`);const s=await this.getValue(),i=JSON.parse(s);i[e]=a,await this.setAll(i)}async setMultiple(t){const e=await this.getAll();await this.setAll({...e,...t})}async setAll(t){await this.setValue(t)}async delete(t){const e=await this.getAll();t in e&&(delete e[t],await this.setValue(e))}async deleteMultiple(t){const e=await this.getAll();for(const a of t)delete e[a];await this.setAll(e)}async deleteAll(){await this.deleteAllValues(),await this.refresh()}async refresh(){this.data=await this.fetchFreshData()}async fetchFreshData(){const e=await this.getValue();if("{"!==e.charAt(0))throw new t("Data has to be defined as an object.");const a=JSON.parse(e);if(!this.validateData(a))throw new t("Invalid storage value.");return this.options.elementOptionsMerger(this.defaults,a)}validateData(t){for(const e in t){if(!(e in this.validators))return!1;if(!this.validators[e](t[e]))return!1}return!0}validateValidators(e){for(const a in e)if("function"!=typeof e[a])throw new t(`Validator for ${a} is not a function.`)}}class s extends a{element;attribute;defaults;validators;constructor(t,e,a,s,i={}){super(a,s,i),this.element=t,this.attribute=e,this.defaults=a,this.validators=s}async getValue(){return this.element.getAttribute(this.attribute)||"{}"}async setValue(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}async deleteAllValues(){this.element.removeAttribute(this.attribute)}}class i extends a{element;defaults;validators;constructor(t,e,a,s={}){super(e,a,s),this.element=t,this.defaults=e,this.validators=a}async getValue(){return this.element.textContent||"{}"}async setValue(t){this.element.textContent=JSON.stringify(t)}async deleteAllValues(){this.element.textContent="{}"}}export{a as AbstractNongranularStorage,s as ElementAttributeStorage,i as ElementStorage,e as StorageWrapper};
|
|
2
2
|
//# sourceMappingURL=storage.js.map
|
package/dist/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","mappings":"AAQO,MAAMA,UAA+BC,OCPrC,MAAMC,EACTC,QACAC,UACAC,SACAC,WACAC,KACAC,QACA,WAAAC,CAAYN,EAASC,EAAWC,EAAUC,EAAYE,EAAU,CAAC,GAC7DE,KAAKP,QA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BAAgB7B,KAAKN,WAClCM,KAAKc,SACT,CACA,OAAAA,GACId,KAAKH,KAAOG,KAAKK,gBACrB,CACA,cAAAA,GACI,MAAMyB,EAAa9B,KAAKmB,kBAAkBnB,KAAKN,WAC/C,GAA6B,MAAzBoC,EAAWC,OAAO,GAClB,MAAM,IAAIzC,EAAuB,wCAErC,MAAMO,EAAOuB,KAAKC,MAAMS,GACxB,IAAK9B,KAAKgC,aAAanC,GACnB,MAAM,IAAIP,EAAuB,0BAErC,OAAOU,KAAKF,QAAQI,qBAAqBF,KAAKL,SAAUE,EAC5D,CACA,YAAAmC,CAAanC,GACT,IAAK,MAAMU,KAAOV,EAAM,CACpB,KAAMU,KAAOP,KAAKJ,YAEd,OADAqC,QAAQC,KAAK,UAAU3B,gCAChB,EAEN,GAAoC,mBAAzBP,KAAKJ,WAAWW,GAE5B,OADA0B,QAAQC,KAAK,wBAAwB3B,yBAC9B,EAEN,IAAKP,KAAKJ,WAAWW,GAAKV,EAAKU,IAChC,OAAO,CAEf,CACA,OAAO,CACX,CACA,iBAAAY,CAAkBzB,GACd,OAAOM,KAAKP,QAAQ0C,aAAazC,IAAc,IACnD,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class ElementStorage {\n element;\n attribute;\n defaults;\n validators;\n data;\n options;\n constructor(element, attribute, defaults, validators, options = {}) {\n this.element = element;\n this.attribute = attribute;\n this.defaults = defaults;\n this.validators = validators;\n this.options = {\n keepFresh: true,\n elementOptionsMerger: (defaultOptions, elementOptions) => {\n return { ...defaultOptions, ...elementOptions };\n },\n ...options,\n };\n this.data = this.fetchFreshData();\n }\n has(key) {\n const data = this.getAll();\n return key in data;\n }\n get(key) {\n const data = this.getAll();\n return data[key];\n }\n getMultiple(keys) {\n const data = this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n getAll() {\n if (this.options.keepFresh) {\n this.refresh();\n }\n return this.data;\n }\n set(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n const attributeValue = this.getAttributeValue(this.attribute);\n const data = JSON.parse(attributeValue);\n data[key] = value;\n this.setAll(data);\n }\n setMultiple(data) {\n const oldData = this.getAll();\n this.setAll({ ...oldData, ...data });\n }\n setAll(data) {\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n delete(key) {\n const data = this.getAll();\n if (!(key in data)) {\n return;\n }\n delete data[key];\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n deleteMultiple(keys) {\n const data = this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n this.setAll(data);\n }\n deleteAll() {\n this.element.removeAttribute(this.attribute);\n this.refresh();\n }\n refresh() {\n this.data = this.fetchFreshData();\n }\n fetchFreshData() {\n const dataString = this.getAttributeValue(this.attribute);\n if (dataString.charAt(0) !== \"{\") {\n throw new StorageValidationError(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return this.options.elementOptionsMerger(this.defaults, data);\n }\n validateData(data) {\n for (const key in data) {\n if (!(key in this.validators)) {\n console.warn(`Option ${key} doesn't have a validator.`);\n return false;\n }\n else if (typeof this.validators[key] !== \"function\") {\n console.warn(`Validator for option ${key} is not a function.`);\n return false;\n }\n else if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n getAttributeValue(attribute) {\n return this.element.getAttribute(attribute) || \"{}\";\n }\n}\n"],"names":["StorageValidationError","Error","ElementStorage","element","attribute","defaults","validators","data","options","constructor","this","keepFresh","elementOptionsMerger","defaultOptions","elementOptions","fetchFreshData","has","key","getAll","get","getMultiple","keys","reduce","acc","refresh","set","value","String","attributeValue","getAttributeValue","JSON","parse","setAll","setMultiple","oldData","setAttribute","stringify","deleteMultiple","deleteAll","removeAttribute","dataString","charAt","validateData","console","warn","getAttribute"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"storage.js","mappings":"AAQO,MAAMA,UAA+BC,OCPrC,MAAMC,EACTC,QACAC,SACAC,WACA,WAAAC,CAAYH,EAASC,EAAUC,GAC3BE,KAAKJ,QAAUA,EACfI,KAAKH,SAAWA,EAChBG,KAAKF,WAAaA,CACtB,CACA,SAAMG,CAAIC,GACN,aAAaF,KAAKJ,QAAQK,IAAIC,EAClC,CACA,SAAMC,CAAID,GACN,MAAME,QAAcJ,KAAKJ,QAAQO,IAAID,GAErC,YAAcG,IAAVD,GACAJ,KAAKM,iBAAiBJ,EAAKE,GACpBA,GAEJJ,KAAKH,SAASK,EACzB,CACA,iBAAMK,CAAYC,GACd,MACMC,EAAS,UADQT,KAAKJ,QAAQW,YAAYC,IAEhD,IAAK,MAAMN,KAAOM,OACMH,IAAhBI,EAAOP,KACPO,EAAOP,GAAOF,KAAKH,SAASK,IAGpC,OAAOO,CACX,CACA,YAAMC,GACF,MACMD,EAAS,UADGT,KAAKJ,QAAQc,UAE/B,IAAK,MAAMR,KAAOS,OAAOH,KAAKR,KAAKH,eACXQ,IAAhBI,EAAOP,KACPO,EAAOP,GAAOF,KAAKH,SAASK,IAGpC,OAAOO,CACX,CACA,SAAMG,CAAIV,EAAKE,GACXJ,KAAKa,iBAAiBX,EAAKE,SACrBJ,KAAKJ,QAAQgB,IAAIV,EAAKE,EAChC,CACA,iBAAMU,CAAYC,GACd,IAAK,MAAMb,KAAOa,EACdf,KAAKa,iBAAiBX,EAAKa,EAAKb,UAE9BF,KAAKJ,QAAQkB,YAAYC,EACnC,CACA,YAAMC,CA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C,GAC7DuB,MAAMhD,EAAUC,EAAYwB,GAC5BtB,KAAK2C,QAAUA,EACf3C,KAAK4C,UAAYA,EACjB5C,KAAKH,SAAWA,EAChBG,KAAKF,WAAaA,CACtB,CACA,cAAMkC,GACF,OAAOhC,KAAK2C,QAAQG,aAAa9C,KAAK4C,YAAc,IACxD,CACA,cAAMR,CAAShC,GACXJ,KAAK2C,QAAQI,aAAa/C,KAAK4C,UAAWX,KAAKe,UAAU5C,GAC7D,CACA,qBAAMiC,GACFrC,KAAK2C,QAAQM,gBAAgBjD,KAAK4C,UACtC,ECpBG,MAAMM,UAAuB7B,EAChCsB,QACA9C,SACAC,WACA,WAAAC,CAAY4C,EAAS9C,EAAUC,EAAYwB,EAAU,CAAC,GAClDuB,MAAMhD,EAAUC,EAAYwB,GAC5BtB,KAAK2C,QAAUA,EACf3C,KAAKH,SAAWA,EAChBG,KAAKF,WAAaA,CACtB,CACA,cAAMkC,GACF,OAAOhC,KAAK2C,QAAQQ,aAAe,IACvC,CACA,cAAMf,CAAShC,GACXJ,KAAK2C,QAAQQ,YAAclB,KAAKe,UAAU5C,EAC9C,CACA,qBAAMiC,GACFrC,KAAK2C,QAAQQ,YAAc,IAC/B,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/StorageWrapper.ts","webpack://wraplet/./src/Storage/AbstractNongranularStorage.ts","webpack://wraplet/./src/Storage/ElementAttributeStorage.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class StorageWrapper {\n storage;\n defaults;\n validators;\n constructor(storage, defaults, validators) {\n this.storage = storage;\n this.defaults = defaults;\n this.validators = validators;\n }\n async has(key) {\n return await this.storage.has(key);\n }\n async get(key) {\n const value = await this.storage.get(key);\n // Only validate when the underlying storage actually returned a value.\n if (value !== undefined) {\n this.validateGetValue(key, value);\n return value;\n }\n return this.defaults[key];\n }\n async getMultiple(keys) {\n const multiple = await this.storage.getMultiple(keys);\n const result = { ...multiple };\n for (const key of keys) {\n if (result[key] === undefined) {\n result[key] = this.defaults[key];\n }\n }\n return result;\n }\n async getAll() {\n const all = await this.storage.getAll();\n const result = { ...all };\n for (const key of Object.keys(this.defaults)) {\n if (result[key] === undefined) {\n result[key] = this.defaults[key];\n }\n }\n return result;\n }\n async set(key, value) {\n this.validateSetValue(key, value);\n await this.storage.set(key, value);\n }\n async setMultiple(data) {\n for (const key in data) {\n this.validateSetValue(key, data[key]);\n }\n await this.storage.setMultiple(data);\n }\n async setAll(data) {\n for (const key in data) {\n this.validateSetValue(key, data[key]);\n }\n await this.storage.setAll(data);\n }\n async delete(key) {\n await this.storage.delete(key);\n }\n async deleteMultiple(keys) {\n await this.storage.deleteMultiple(keys);\n }\n async deleteAll() {\n await this.storage.deleteAll();\n }\n validateGetValue(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Got an invalid value for the key ${String(key)}.`);\n }\n }\n validateSetValue(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n }\n}\n","import { StorageValidationError } from \"../errors\";\nexport class AbstractNongranularStorage {\n defaults;\n validators;\n data = null;\n options;\n constructor(defaults, validators, options) {\n this.defaults = defaults;\n this.validators = validators;\n this.validateValidators(validators);\n this.options = {\n keepFresh: true,\n elementOptionsMerger: (defaultOptions, elementOptions) => {\n return { ...defaultOptions, ...elementOptions };\n },\n ...options,\n };\n }\n async has(key) {\n const data = await this.getAll();\n return key in data;\n }\n async get(key) {\n const data = await this.getAll();\n return data[key];\n }\n async getMultiple(keys) {\n const data = await this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n async getAll() {\n if (this.options.keepFresh) {\n await this.refresh();\n }\n if (!this.data) {\n await this.refresh();\n }\n return this.data;\n }\n async set(key, value) {\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n const attributeValue = await this.getValue();\n const data = JSON.parse(attributeValue);\n data[key] = value;\n await this.setAll(data);\n }\n async setMultiple(data) {\n const oldData = await this.getAll();\n await this.setAll({ ...oldData, ...data });\n }\n async setAll(data) {\n await this.setValue(data);\n }\n async delete(key) {\n const data = await this.getAll();\n if (!(key in data)) {\n return;\n }\n delete data[key];\n await this.setValue(data);\n }\n async deleteMultiple(keys) {\n const data = await this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n await this.setAll(data);\n }\n async deleteAll() {\n await this.deleteAllValues();\n await this.refresh();\n }\n async refresh() {\n this.data = await this.fetchFreshData();\n }\n async fetchFreshData() {\n const dataString = await this.getValue();\n if (dataString.charAt(0) !== \"{\") {\n throw new StorageValidationError(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return this.options.elementOptionsMerger(this.defaults, data);\n }\n validateData(data) {\n for (const key in data) {\n if (!(key in this.validators)) {\n return false;\n }\n else if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n validateValidators(validators) {\n for (const key in validators) {\n if (typeof validators[key] !== \"function\") {\n throw new StorageValidationError(`Validator for ${key} is not a function.`);\n }\n }\n }\n}\n","import { AbstractNongranularStorage } from \"./AbstractNongranularStorage\";\nexport class ElementAttributeStorage extends AbstractNongranularStorage {\n element;\n attribute;\n defaults;\n validators;\n constructor(element, attribute, defaults, validators, options = {}) {\n super(defaults, validators, options);\n this.element = element;\n this.attribute = attribute;\n this.defaults = defaults;\n this.validators = validators;\n }\n async getValue() {\n return this.element.getAttribute(this.attribute) || \"{}\";\n }\n async setValue(value) {\n this.element.setAttribute(this.attribute, JSON.stringify(value));\n }\n async deleteAllValues() {\n this.element.removeAttribute(this.attribute);\n }\n}\n","import { AbstractNongranularStorage } from \"./AbstractNongranularStorage\";\nexport class ElementStorage extends AbstractNongranularStorage {\n element;\n defaults;\n validators;\n constructor(element, defaults, validators, options = {}) {\n super(defaults, validators, options);\n this.element = element;\n this.defaults = defaults;\n this.validators = validators;\n }\n async getValue() {\n return this.element.textContent || \"{}\";\n }\n async setValue(value) {\n this.element.textContent = JSON.stringify(value);\n }\n async deleteAllValues() {\n this.element.textContent = \"{}\";\n }\n}\n"],"names":["StorageValidationError","Error","StorageWrapper","storage","defaults","validators","constructor","this","has","key","get","value","undefined","validateGetValue","getMultiple","keys","result","getAll","Object","set","validateSetValue","setMultiple","data","setAll","delete","deleteMultiple","deleteAll","String","AbstractNongranularStorage","options","validateValidators","keepFresh","elementOptionsMerger","defaultOptions","elementOptions","reduce","acc","refresh","attributeValue","getValue","JSON","parse","oldData","setValue","deleteAllValues","fetchFreshData","dataString","charAt","validateData","ElementAttributeStorage","element","attribute","super","getAttribute","setAttribute","stringify","removeAttribute","ElementStorage","textContent"],"ignoreList":[],"sourceRoot":""}
|
package/dist/types/Core.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export interface Core<N extends Node = Node, M extends WrapletChildrenMap = {}>
|
|
|
42
42
|
* Initialize the core.
|
|
43
43
|
* This must be called after construction to fully initialize the core.
|
|
44
44
|
*/
|
|
45
|
-
|
|
45
|
+
initialize(): Promise<void>;
|
|
46
46
|
/**
|
|
47
47
|
* Instantiate children based on the map and the current node.
|
|
48
48
|
*/
|
|
@@ -62,7 +62,7 @@ export interface Core<N extends Node = Node, M extends WrapletChildrenMap = {}>
|
|
|
62
62
|
/**
|
|
63
63
|
* Destroy all children.
|
|
64
64
|
*/
|
|
65
|
-
destroy(): void
|
|
65
|
+
destroy(): Promise<void>;
|
|
66
66
|
/**
|
|
67
67
|
* Add an event listener to a node and track it for cleanup.
|
|
68
68
|
*/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Wraplet } from "./Wraplet";
|
|
2
|
-
export type DestroyListener<N extends Node> = (wraplet: Wraplet<N>) => void
|
|
2
|
+
export type DestroyListener<N extends Node> = (wraplet: Wraplet<N>) => Promise<void>;
|
package/dist/types/Wraplet.d.ts
CHANGED
|
@@ -8,7 +8,8 @@ export interface Wraplet<N extends Node = Node> {
|
|
|
8
8
|
isDestroyed: boolean;
|
|
9
9
|
isGettingDestroyed: boolean;
|
|
10
10
|
accessNode(callback: (node: N) => void): void;
|
|
11
|
-
destroy(): void
|
|
11
|
+
destroy(): Promise<void>;
|
|
12
|
+
initialize(): Promise<void>;
|
|
12
13
|
addDestroyListener(callback: DestroyListener<N>): void;
|
|
13
14
|
}
|
|
14
15
|
export declare function isWraplet<N extends Node>(object: unknown): object is Wraplet<N>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Wraplet } from "./Wraplet";
|
|
2
2
|
import { WrapletChildrenMap } from "./WrapletChildrenMap";
|
|
3
3
|
import { CoreInitOptions } from "./CoreInitOptions";
|
|
4
|
-
import { DynamicMap } from "
|
|
4
|
+
import { DynamicMap } from "../Map/types/DynamicMap";
|
|
5
5
|
import { Constructable } from "./Utils";
|
|
6
6
|
export type SelectorCallback<N extends ParentNode = ParentNode> = (node: N) => Node[];
|
|
7
7
|
export type WrapletChildDefinition<M extends WrapletChildrenMap = WrapletChildrenMap> = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WrapletChildrenMap } from "./WrapletChildrenMap";
|
|
2
2
|
import { InstantiableReturnType } from "./Utils";
|
|
3
|
-
import { WrapletSet } from "
|
|
3
|
+
import { WrapletSet } from "../Set/types/WrapletSet";
|
|
4
4
|
export type OptionalSingleInstantiableReturnType<T extends WrapletChildrenMap, K extends keyof T> = T[K]["required"] extends true ? InstantiableReturnType<T[K]["Class"]> : InstantiableReturnType<T[K]["Class"]> | null;
|
|
5
5
|
export type WrapletChildren<T extends WrapletChildrenMap> = {
|
|
6
6
|
[id in keyof T]: T[id]["multiple"] extends true ? WrapletSet<InstantiableReturnType<T[id]["Class"]>> : OptionalSingleInstantiableReturnType<T, id>;
|
package/dist/types/global.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Wraplet } from "./types/Wraplet";
|
|
2
|
-
import { WrapletSet } from "./types/
|
|
2
|
+
import { WrapletSet } from "./Set/types/WrapletSet";
|
|
3
3
|
export declare function isParentNode(node: Node): node is ParentNode;
|
|
4
4
|
export declare function getWrapletsFromNode<N extends Node = Node, W extends Wraplet<N> = Wraplet<N>>(node: N): WrapletSet<W>;
|
|
5
5
|
export declare function removeWrapletFromNode<N extends Node>(wraplet: Wraplet<N>, node: N): boolean;
|
|
6
6
|
export declare function addWrapletToNode<N extends Node>(wraplet: Wraplet<N>, node: N): void;
|
|
7
|
-
export declare function actOnNodesRecursively(node: Node, callback: (node: Node) => void): void
|
|
8
|
-
export declare function destroyWrapletsRecursively(node: Node): void
|
|
7
|
+
export declare function actOnNodesRecursively(node: Node, callback: (node: Node) => Promise<void>): Promise<void>;
|
|
8
|
+
export declare function destroyWrapletsRecursively(node: Node): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wraplet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.28.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dev:watch": "tsx ./node_modules/.bin/webpack --mode development --watch --config ./webpack.config.ts",
|
|
33
33
|
"lint": "tsc --noemit && npx eslint './src/**/*.ts' './tests/**/*.ts'",
|
|
34
34
|
"lint:fix": "npx eslint './src/**/*.ts' './tests/**/*.ts' --fix",
|
|
35
|
-
"tests": "jest --coverage"
|
|
35
|
+
"tests": "node --unhandled-rejections=throw node_modules/.bin/jest --coverage --detectOpenHandles"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {},
|
|
38
38
|
"devDependencies": {
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { StorageReadonly } from "./StorageReadonly";
|
|
2
|
-
export interface Storage<D extends Record<string, unknown>> extends StorageReadonly<D> {
|
|
3
|
-
set: <T extends keyof D>(key: T, value: D[T]) => void;
|
|
4
|
-
setMultiple: (data: Partial<D>) => void;
|
|
5
|
-
setAll: (data: D) => void;
|
|
6
|
-
delete: (key: keyof D) => void;
|
|
7
|
-
deleteMultiple: (keys: (keyof D)[]) => void;
|
|
8
|
-
deleteAll: () => void;
|
|
9
|
-
}
|
|
File without changes
|
|
File without changes
|