wraplet 0.28.0 → 0.29.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 +16 -28
- package/dist/Core/DefaultArgCreator.d.ts +10 -0
- package/dist/{DefaultCore.d.ts → Core/DefaultCore.d.ts} +9 -11
- package/dist/Core/defaultWrapletCreator.d.ts +6 -0
- package/dist/Core/types/ArgCreator.d.ts +9 -0
- package/dist/{types → Core/types}/Core.d.ts +8 -21
- package/dist/{types → Core/types}/CoreInitOptions.d.ts +1 -1
- package/dist/Core/types/DestroyChildListener.d.ts +3 -0
- package/dist/{types → Core/types}/DestroyListener.d.ts +1 -1
- package/dist/Core/types/InstantiateChildListener.d.ts +3 -0
- package/dist/Core/types/WrapletCreator.d.ts +15 -0
- package/dist/Map/MapRepeat.d.ts +1 -1
- package/dist/Map/MapWrapper.d.ts +1 -1
- package/dist/Map/types/DynamicMap.d.ts +1 -1
- package/dist/{WrapletChildrenMap.d.ts → Map/utils.d.ts} +2 -2
- package/dist/NodeTreeManager/DefaultNodeTreeManager.d.ts +2 -2
- package/dist/NodeTreeManager/{NodeTreeManager.d.ts → types/NodeTreeManager.d.ts} +2 -2
- package/dist/{types → NodeTreeManager/types}/NodeTreeParent.d.ts +4 -2
- package/dist/{utils.d.ts → NodeTreeManager/utils.d.ts} +2 -2
- package/dist/Set/DefaultWrapletSet.d.ts +1 -1
- package/dist/Set/DefaultWrapletSetReadonly.d.ts +1 -1
- package/dist/Set/types/WrapletSet.d.ts +1 -1
- package/dist/Set/types/WrapletSetReadonly.d.ts +1 -1
- package/dist/Storage/{AbstractNongranularStorage.d.ts → AbstractNongranularKeyValueStorage.d.ts} +3 -2
- package/dist/Storage/ElementAttributeStorage.d.ts +2 -2
- package/dist/Storage/ElementStorage.d.ts +2 -2
- package/dist/Storage/InMemoryKeyValueStorage.d.ts +0 -0
- package/dist/Storage/StorageWrapper.d.ts +4 -3
- package/dist/Storage/types/KeyValueStorage.d.ts +13 -0
- package/dist/Storage/types/{StorageReadonly.d.ts → KeyValueStorageReadonly.d.ts} +1 -1
- package/dist/Wraplet/createWrapletApi.d.ts +6 -0
- package/dist/Wraplet/types/Status.d.ts +9 -0
- package/dist/Wraplet/types/Wraplet.d.ts +8 -0
- package/dist/Wraplet/types/WrapletApi.d.ts +12 -0
- package/dist/Wraplet/types/WrapletApiFactoryArgs.d.ts +16 -0
- package/dist/Wraplet/types/WrapletApiFactoryBasicCallback.d.ts +1 -0
- package/dist/{types → Wraplet/types}/WrapletChildDefinition.d.ts +3 -3
- package/dist/{types → Wraplet/types}/WrapletChildren.d.ts +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -9
- 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 +3 -2
- package/dist/storage.js +1 -1
- package/dist/storage.js.map +1 -1
- package/dist/types/Groupable.d.ts +4 -2
- package/dist/utils/is.d.ts +5 -0
- package/dist/{types → utils/types}/Utils.d.ts +0 -5
- package/package.json +1 -1
- package/dist/Storage/types/Storage.d.ts +0 -9
- package/dist/Storage/types/StorageDefaults.d.ts +0 -1
- package/dist/types/DestroyChildListener.d.ts +0 -3
- package/dist/types/InstantiateChildListener.d.ts +0 -3
- package/dist/types/Wraplet.d.ts +0 -15
- package/dist/types/WrapletCreator.d.ts +0 -15
- /package/dist/{types → Wraplet/types}/ChildInstance.d.ts +0 -0
- /package/dist/{types → Wraplet/types}/WrapletChildrenMap.d.ts +0 -0
|
@@ -1,44 +1,32 @@
|
|
|
1
|
-
import { WrapletChildrenMap } from "./types/WrapletChildrenMap";
|
|
2
|
-
import { WrapletChildren } from "./types/WrapletChildren";
|
|
3
|
-
import { Wraplet, WrapletSymbol } from "./types/Wraplet";
|
|
4
|
-
import { DestroyListener } from "./types/DestroyListener";
|
|
5
|
-
import { ChildInstance } from "./types/ChildInstance";
|
|
6
|
-
import { Groupable, GroupableSymbol
|
|
7
|
-
import { NodeTreeParent, NodeTreeParentSymbol } from "./types/NodeTreeParent";
|
|
8
|
-
import { Core } from "./types/Core";
|
|
1
|
+
import { WrapletChildrenMap } from "./Wraplet/types/WrapletChildrenMap";
|
|
2
|
+
import { WrapletChildren } from "./Wraplet/types/WrapletChildren";
|
|
3
|
+
import { Wraplet, WrapletSymbol } from "./Wraplet/types/Wraplet";
|
|
4
|
+
import { DestroyListener } from "./Core/types/DestroyListener";
|
|
5
|
+
import { ChildInstance } from "./Wraplet/types/ChildInstance";
|
|
6
|
+
import { Groupable, GroupableSymbol } from "./types/Groupable";
|
|
7
|
+
import { NodeTreeParent, NodeTreeParentSymbol } from "./NodeTreeManager/types/NodeTreeParent";
|
|
8
|
+
import { Core } from "./Core/types/Core";
|
|
9
|
+
import { WrapletApiFactoryArgs } from "./Wraplet/types/WrapletApiFactoryArgs";
|
|
10
|
+
import { WrapletApi } from "./Wraplet/types/WrapletApi";
|
|
9
11
|
export declare abstract class AbstractWraplet<N extends Node = Node, M extends WrapletChildrenMap = {}> implements Wraplet<N>, Groupable, NodeTreeParent {
|
|
10
12
|
protected core: Core<N, M>;
|
|
11
13
|
[WrapletSymbol]: true;
|
|
12
14
|
[GroupableSymbol]: true;
|
|
13
15
|
[NodeTreeParentSymbol]: true;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
isGettingInitialized: boolean;
|
|
17
|
-
isInitialized: boolean;
|
|
18
|
-
private groupsExtractor;
|
|
19
|
-
private destroyListeners;
|
|
20
|
-
/**
|
|
21
|
-
* This is the log of all node accessors, available for easier debugging.
|
|
22
|
-
*/
|
|
23
|
-
private __debugNodeAccessors;
|
|
16
|
+
protected destroyListeners: DestroyListener<N>[];
|
|
17
|
+
wraplet: WrapletApi<N> & NodeTreeParent["wraplet"] & Groupable["wraplet"];
|
|
24
18
|
constructor(core: Core<N, M>);
|
|
25
|
-
|
|
26
|
-
setGroupsExtractor(callback: GroupExtractor): void;
|
|
27
|
-
getGroups(): string[];
|
|
19
|
+
protected createWrapletApi(args: WrapletApiFactoryArgs<N, M>): WrapletApi<N> & NodeTreeParent["wraplet"] & Groupable["wraplet"];
|
|
28
20
|
protected get children(): WrapletChildren<M>;
|
|
29
|
-
accessNode(callback: (node: N) => void): void;
|
|
30
|
-
destroy(): Promise<void>;
|
|
31
|
-
addDestroyListener(callback: DestroyListener<N>): void;
|
|
32
21
|
/**
|
|
33
22
|
* This method will be ivoked if one of the wraplet's children has been destroyed.
|
|
34
23
|
*/
|
|
35
|
-
protected
|
|
36
|
-
initialize(): Promise<void>;
|
|
24
|
+
protected onChildDestroy(child: ChildInstance<M, keyof M>, id: keyof M): void;
|
|
37
25
|
protected get node(): N;
|
|
38
26
|
/**
|
|
39
|
-
* This method will be
|
|
27
|
+
* This method will be invoked if one of the wraplet's children has been instantiated.
|
|
40
28
|
*/
|
|
41
|
-
protected
|
|
29
|
+
protected onChildInstantiate(child: ChildInstance<M, keyof M>, id: keyof M): void;
|
|
42
30
|
/**
|
|
43
31
|
* This method makes sure that the given instance is an instance of a class belonging to the
|
|
44
32
|
* given child.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ArgCreator, ArgCreatorSymbol } from "./types/ArgCreator";
|
|
2
|
+
import { WrapletChildrenMap } from "../Wraplet/types/WrapletChildrenMap";
|
|
3
|
+
import { WrapletCreatorArgs } from "./types/WrapletCreator";
|
|
4
|
+
export declare class DefaultArgCreator<N extends Node, M extends WrapletChildrenMap = WrapletChildrenMap> implements ArgCreator<N, M> {
|
|
5
|
+
private creator;
|
|
6
|
+
[ArgCreatorSymbol]: true;
|
|
7
|
+
constructor(creator: ArgCreator<N, M>["createArg"]);
|
|
8
|
+
createArg(args: WrapletCreatorArgs<N, M>): unknown;
|
|
9
|
+
static create<N extends Node, M extends WrapletChildrenMap = WrapletChildrenMap>(creator: ArgCreator<N, M>["createArg"]): DefaultArgCreator<N, M>;
|
|
10
|
+
}
|
|
@@ -1,27 +1,25 @@
|
|
|
1
|
-
import { WrapletChildren } from "
|
|
2
|
-
import { Wraplet } from "
|
|
3
|
-
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "
|
|
1
|
+
import { WrapletChildren } from "../Wraplet/types/WrapletChildren";
|
|
2
|
+
import { Wraplet } from "../Wraplet/types/Wraplet";
|
|
3
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../Wraplet/types/WrapletChildrenMap";
|
|
4
4
|
import { InstantiateChildListener } from "./types/InstantiateChildListener";
|
|
5
5
|
import { DestroyChildListener } from "./types/DestroyChildListener";
|
|
6
6
|
import { CoreInitOptions } from "./types/CoreInitOptions";
|
|
7
7
|
import { Core, CoreSymbol } from "./types/Core";
|
|
8
|
-
import { NodeTreeParentSymbol } from "
|
|
9
|
-
import { MapWrapper } from "
|
|
8
|
+
import { NodeTreeParentSymbol } from "../NodeTreeManager/types/NodeTreeParent";
|
|
9
|
+
import { MapWrapper } from "../Map/MapWrapper";
|
|
10
10
|
import { WrapletCreator } from "./types/WrapletCreator";
|
|
11
|
+
import { Status } from "../Wraplet/types/Status";
|
|
11
12
|
export declare class DefaultCore<N extends Node = Node, M extends WrapletChildrenMap = {}> implements Core<N, M> {
|
|
12
13
|
node: N;
|
|
13
14
|
[CoreSymbol]: true;
|
|
14
15
|
[NodeTreeParentSymbol]: true;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
isGettingInitialized: boolean;
|
|
18
|
-
isInitialized: boolean;
|
|
16
|
+
private statusWritable;
|
|
17
|
+
get status(): Status;
|
|
19
18
|
mapWrapper: MapWrapper<M>;
|
|
20
19
|
private instantiatedChildren;
|
|
21
20
|
private destroyChildListeners;
|
|
22
21
|
private instantiateChildListeners;
|
|
23
22
|
private listeners;
|
|
24
|
-
private defaultWrapletCreator;
|
|
25
23
|
private wrapletCreator;
|
|
26
24
|
constructor(node: N, map: M | MapWrapper<M>, initOptions?: Partial<CoreInitOptions<M>>);
|
|
27
25
|
/**
|
|
@@ -42,7 +40,7 @@ export declare class DefaultCore<N extends Node = Node, M extends WrapletChildre
|
|
|
42
40
|
private instantiateMultipleWrapletsChild;
|
|
43
41
|
addDestroyChildListener(callback: DestroyChildListener<M, keyof M>): void;
|
|
44
42
|
addInstantiateChildListener(callback: InstantiateChildListener<M, keyof M>): void;
|
|
45
|
-
setWrapletCreator(wrapletCreator: WrapletCreator<
|
|
43
|
+
setWrapletCreator(wrapletCreator: WrapletCreator<Node, WrapletChildrenMap>): void;
|
|
46
44
|
private prepareIndividualWraplet;
|
|
47
45
|
/**
|
|
48
46
|
* This method removes from nodes references to this wraplet and its children recursively.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WrapletCreatorArgs } from "./types/WrapletCreator";
|
|
2
|
+
import { WrapletChildrenMap } from "../Wraplet/types/WrapletChildrenMap";
|
|
3
|
+
import { Constructable } from "../utils/types/Utils";
|
|
4
|
+
import { Core } from "./types/Core";
|
|
5
|
+
import { Wraplet } from "../Wraplet/types/Wraplet";
|
|
6
|
+
export declare function defaultWrapletCreator(args: WrapletCreatorArgs<Node, WrapletChildrenMap>, currentCoreClass: Constructable<Core>): Wraplet;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WrapletCreatorArgs } from "./WrapletCreator";
|
|
2
|
+
import { WrapletChildrenMap } from "../../Wraplet/types/WrapletChildrenMap";
|
|
3
|
+
declare const ArgCreatorSymbol: unique symbol;
|
|
4
|
+
export { ArgCreatorSymbol };
|
|
5
|
+
export interface ArgCreator<N extends Node, M extends WrapletChildrenMap = {}> {
|
|
6
|
+
[ArgCreatorSymbol]: true;
|
|
7
|
+
createArg(args: WrapletCreatorArgs<N, M>): unknown;
|
|
8
|
+
}
|
|
9
|
+
export declare function isArgCreator<N extends Node, M extends WrapletChildrenMap = {}>(object: unknown): object is ArgCreator<N, M>;
|
|
@@ -1,35 +1,22 @@
|
|
|
1
|
-
import { WrapletChildren } from "
|
|
2
|
-
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "
|
|
1
|
+
import { WrapletChildren } from "../../Wraplet/types/WrapletChildren";
|
|
2
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../../Wraplet/types/WrapletChildrenMap";
|
|
3
3
|
import { DestroyChildListener } from "./DestroyChildListener";
|
|
4
4
|
import { InstantiateChildListener } from "./InstantiateChildListener";
|
|
5
|
-
import {
|
|
6
|
-
import { Wraplet } from "./Wraplet";
|
|
5
|
+
import { Wraplet } from "../../Wraplet/types/Wraplet";
|
|
7
6
|
import { WrapletCreator } from "./WrapletCreator";
|
|
7
|
+
import { Status } from "../../Wraplet/types/Status";
|
|
8
8
|
declare const CoreSymbol: unique symbol;
|
|
9
9
|
export { CoreSymbol };
|
|
10
10
|
/**
|
|
11
11
|
* Children manager interface that defines the public API for managing wraplet relationships
|
|
12
12
|
* and lifecycles.
|
|
13
13
|
*/
|
|
14
|
-
export interface Core<N extends Node = Node, M extends WrapletChildrenMap = {}>
|
|
14
|
+
export interface Core<N extends Node = Node, M extends WrapletChildrenMap = {}> {
|
|
15
15
|
[CoreSymbol]: true;
|
|
16
|
-
[NodeTreeParentSymbol]: true;
|
|
17
16
|
/**
|
|
18
|
-
*
|
|
17
|
+
* Core status.
|
|
19
18
|
*/
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Indicates whether the core is in the process of being destroyed.
|
|
23
|
-
*/
|
|
24
|
-
isGettingDestroyed: boolean;
|
|
25
|
-
/**
|
|
26
|
-
* Indicates whether the core is in the process of being initialized.
|
|
27
|
-
*/
|
|
28
|
-
isGettingInitialized: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Indicates whether the core has been initialized.
|
|
31
|
-
*/
|
|
32
|
-
isInitialized: boolean;
|
|
19
|
+
status: Status;
|
|
33
20
|
/**
|
|
34
21
|
* The children map that defines the relationships between nodes.
|
|
35
22
|
*/
|
|
@@ -71,7 +58,7 @@ export interface Core<N extends Node = Node, M extends WrapletChildrenMap = {}>
|
|
|
71
58
|
/**
|
|
72
59
|
* Allows for overriding the default wraplet creation process.
|
|
73
60
|
*/
|
|
74
|
-
setWrapletCreator(wrapletCreator: WrapletCreator<
|
|
61
|
+
setWrapletCreator(wrapletCreator: WrapletCreator<Node, WrapletChildrenMap>): void;
|
|
75
62
|
/**
|
|
76
63
|
* Get the instantiated children.
|
|
77
64
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { InstantiateChildListener } from "./InstantiateChildListener";
|
|
2
|
-
import { WrapletChildrenMap } from "
|
|
2
|
+
import { WrapletChildrenMap } from "../../Wraplet/types/WrapletChildrenMap";
|
|
3
3
|
import { DestroyChildListener } from "./DestroyChildListener";
|
|
4
4
|
export type CoreInitOptions<M extends WrapletChildrenMap = WrapletChildrenMap> = {
|
|
5
5
|
instantiateChildListeners: InstantiateChildListener<M, keyof M>[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { WrapletChildrenMap } from "../../Wraplet/types/WrapletChildrenMap";
|
|
2
|
+
import { ChildInstance } from "../../Wraplet/types/ChildInstance";
|
|
3
|
+
export type DestroyChildListener<M extends WrapletChildrenMap, K extends keyof M> = (wraplet: ChildInstance<M, K>, id: K) => void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Wraplet } from "
|
|
1
|
+
import { Wraplet } from "../../Wraplet/types/Wraplet";
|
|
2
2
|
export type DestroyListener<N extends Node> = (wraplet: Wraplet<N>) => Promise<void>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { WrapletChildrenMap } from "../../Wraplet/types/WrapletChildrenMap";
|
|
2
|
+
import { ChildInstance } from "../../Wraplet/types/ChildInstance";
|
|
3
|
+
export type InstantiateChildListener<M extends WrapletChildrenMap, K extends keyof M> = (wraplet: ChildInstance<M, K>, id: K) => void;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Wraplet } from "../../Wraplet/types/Wraplet";
|
|
2
|
+
import { MapWrapper } from "../../Map/MapWrapper";
|
|
3
|
+
import { WrapletChildrenMap } from "../../Wraplet/types/WrapletChildrenMap";
|
|
4
|
+
import { CoreInitOptions } from "./CoreInitOptions";
|
|
5
|
+
import { Constructable } from "../../utils/types/Utils";
|
|
6
|
+
import { Core } from "./Core";
|
|
7
|
+
export type WrapletCreator<N extends Node, M extends WrapletChildrenMap> = (args: WrapletCreatorArgs<N, M>, currentCoreClass: Constructable<Core>) => Wraplet<N>;
|
|
8
|
+
export type WrapletCreatorArgs<N extends Node, M extends WrapletChildrenMap> = {
|
|
9
|
+
id: keyof M;
|
|
10
|
+
Class: Constructable<Wraplet<N>>;
|
|
11
|
+
element: N;
|
|
12
|
+
map: MapWrapper<M>;
|
|
13
|
+
initOptions: CoreInitOptions<M>;
|
|
14
|
+
args: unknown[];
|
|
15
|
+
};
|
package/dist/Map/MapRepeat.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MapWrapper } from "./MapWrapper";
|
|
2
|
-
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../types/WrapletChildrenMap";
|
|
2
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../Wraplet/types/WrapletChildrenMap";
|
|
3
3
|
import { DynamicMap, DynamicMapSymbol } from "./types/DynamicMap";
|
|
4
4
|
export declare class MapRepeat implements DynamicMap {
|
|
5
5
|
private readonly levels;
|
package/dist/Map/MapWrapper.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../types/WrapletChildrenMap";
|
|
1
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../Wraplet/types/WrapletChildrenMap";
|
|
2
2
|
type RecursiveMapKeys<T extends WrapletChildrenMap> = {
|
|
3
3
|
[K in keyof T]: T[K] extends {
|
|
4
4
|
map: infer M extends WrapletChildrenMap;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../../types/WrapletChildrenMap";
|
|
1
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../../Wraplet/types/WrapletChildrenMap";
|
|
2
2
|
import { MapWrapper } from "../MapWrapper";
|
|
3
3
|
declare const DynamicMapSymbol: unique symbol;
|
|
4
4
|
export { DynamicMapSymbol };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WrapletChildDefinition, WrapletChildDefinitionWithDefaults } from "
|
|
2
|
-
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "
|
|
1
|
+
import { WrapletChildDefinition, WrapletChildDefinitionWithDefaults } from "../Wraplet/types/WrapletChildDefinition";
|
|
2
|
+
import { WrapletChildrenMap, WrapletChildrenMapWithDefaults } from "../Wraplet/types/WrapletChildrenMap";
|
|
3
3
|
export declare function addDefaultsToChildDefinition<M extends WrapletChildrenMap, T extends WrapletChildDefinition<M>>(definition: T): WrapletChildDefinitionWithDefaults<T, M>;
|
|
4
4
|
export declare function fillMapWithDefaults<M extends WrapletChildrenMap>(map: M): WrapletChildrenMapWithDefaults<M>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NodeTreeManager } from "./NodeTreeManager";
|
|
2
|
-
import { Wraplet } from "../types/Wraplet";
|
|
1
|
+
import { NodeTreeManager } from "./types/NodeTreeManager";
|
|
2
|
+
import { Wraplet } from "../Wraplet/types/Wraplet";
|
|
3
3
|
import { WrapletSetReadonly } from "../Set/types/WrapletSetReadonly";
|
|
4
4
|
export type Initializer = (node: Node) => Promise<Wraplet[]>;
|
|
5
5
|
export default class DefaultNodeTreeManager implements NodeTreeManager {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Initializer } from "
|
|
2
|
-
import { WrapletSetReadonly } from "
|
|
1
|
+
import { Initializer } from "../DefaultNodeTreeManager";
|
|
2
|
+
import { WrapletSetReadonly } from "../../Set/types/WrapletSetReadonly";
|
|
3
3
|
export interface NodeTreeManager {
|
|
4
4
|
addWrapletInitializer(callback: Initializer): void;
|
|
5
5
|
initializeNodeTree(node: Node): Promise<void>;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Wraplet } from "
|
|
1
|
+
import { Wraplet } from "../../Wraplet/types/Wraplet";
|
|
2
2
|
declare const NodeTreeParentSymbol: unique symbol;
|
|
3
3
|
export { NodeTreeParentSymbol };
|
|
4
4
|
export interface NodeTreeParent {
|
|
5
5
|
[NodeTreeParentSymbol]: true;
|
|
6
|
-
|
|
6
|
+
wraplet: {
|
|
7
|
+
getNodeTreeChildren(): Wraplet[];
|
|
8
|
+
};
|
|
7
9
|
}
|
|
8
10
|
export declare function isNodeTreeParent(object: object): object is NodeTreeParent;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Wraplet } from "
|
|
2
|
-
import { WrapletSet } from "
|
|
1
|
+
import { Wraplet } from "../Wraplet/types/Wraplet";
|
|
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;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WrapletSet, WrapletSetSymbol } from "./types/WrapletSet";
|
|
2
|
-
import { Wraplet } from "../types/Wraplet";
|
|
2
|
+
import { Wraplet } from "../Wraplet/types/Wraplet";
|
|
3
3
|
import { DefaultSearchableSet } from "./DefaultSearchableSet";
|
|
4
4
|
import { WrapletSetReadonlySymbol } from "./types/WrapletSetReadonly";
|
|
5
5
|
export declare class DefaultWrapletSet<T extends Wraplet> extends DefaultSearchableSet<T> implements WrapletSet {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Wraplet } from "../types/Wraplet";
|
|
1
|
+
import { Wraplet } from "../Wraplet/types/Wraplet";
|
|
2
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 {
|
package/dist/Storage/{AbstractNongranularStorage.d.ts → AbstractNongranularKeyValueStorage.d.ts}
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KeyValueStorage, KeyValueStorageSymbol } from "./types/KeyValueStorage";
|
|
2
2
|
import { StorageValidators } from "./types/StorageValidators";
|
|
3
3
|
import { NongranularStorageOptions } from "./NongranularStorageOptions";
|
|
4
|
-
export declare abstract class
|
|
4
|
+
export declare abstract class AbstractNongranularKeyValueStorage<D extends Record<string, unknown>> implements KeyValueStorage<D> {
|
|
5
5
|
protected defaults: D;
|
|
6
6
|
protected validators: StorageValidators<D>;
|
|
7
|
+
[KeyValueStorageSymbol]: true;
|
|
7
8
|
private data;
|
|
8
9
|
private options;
|
|
9
10
|
constructor(defaults: D, validators: StorageValidators<D>, options: Partial<NongranularStorageOptions<D>>);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { StorageValidators } from "./types/StorageValidators";
|
|
2
2
|
import { ElementOptionsMerger } from "./ElementOptionsMerger";
|
|
3
|
-
import {
|
|
3
|
+
import { AbstractNongranularKeyValueStorage } from "./AbstractNongranularKeyValueStorage";
|
|
4
4
|
export type ElementStorageOptions<D extends Record<string, unknown>> = {
|
|
5
5
|
keepFresh: boolean;
|
|
6
6
|
elementOptionsMerger: ElementOptionsMerger<D>;
|
|
7
7
|
};
|
|
8
|
-
export declare class ElementAttributeStorage<D extends Record<string, unknown>> extends
|
|
8
|
+
export declare class ElementAttributeStorage<D extends Record<string, unknown>> extends AbstractNongranularKeyValueStorage<D> {
|
|
9
9
|
private element;
|
|
10
10
|
private attribute;
|
|
11
11
|
protected defaults: D;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { StorageValidators } from "./types/StorageValidators";
|
|
2
|
-
import {
|
|
2
|
+
import { AbstractNongranularKeyValueStorage } from "./AbstractNongranularKeyValueStorage";
|
|
3
3
|
import { NongranularStorageOptions } from "./NongranularStorageOptions";
|
|
4
|
-
export declare class ElementStorage<D extends Record<string, unknown>, E extends Element = HTMLScriptElement> extends
|
|
4
|
+
export declare class ElementStorage<D extends Record<string, unknown>, E extends Element = HTMLScriptElement> extends AbstractNongranularKeyValueStorage<D> {
|
|
5
5
|
private element;
|
|
6
6
|
protected defaults: D;
|
|
7
7
|
protected validators: StorageValidators<D>;
|
|
File without changes
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { KeyValueStorage, KeyValueStorageSymbol } from "./types/KeyValueStorage";
|
|
2
2
|
import { StorageValidators } from "./types/StorageValidators";
|
|
3
|
-
export declare class StorageWrapper<D extends Record<string, unknown>> implements
|
|
3
|
+
export declare class StorageWrapper<D extends Record<string, unknown>> implements KeyValueStorage<D> {
|
|
4
4
|
private storage;
|
|
5
5
|
private defaults;
|
|
6
6
|
private validators;
|
|
7
|
-
|
|
7
|
+
[KeyValueStorageSymbol]: true;
|
|
8
|
+
constructor(storage: KeyValueStorage<D>, defaults: D, validators: StorageValidators<D>);
|
|
8
9
|
has(key: keyof D): Promise<boolean>;
|
|
9
10
|
get<T extends keyof D>(key: T): Promise<D[T]>;
|
|
10
11
|
getMultiple<T extends keyof D>(keys: T[]): Promise<Pick<D, T>>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { KeyValueStorageReadonly } from "./KeyValueStorageReadonly";
|
|
2
|
+
declare const KeyValueStorageSymbol: unique symbol;
|
|
3
|
+
export { KeyValueStorageSymbol };
|
|
4
|
+
export interface KeyValueStorage<D extends Record<string, unknown>> extends KeyValueStorageReadonly<D> {
|
|
5
|
+
[KeyValueStorageSymbol]: true;
|
|
6
|
+
set: <T extends keyof D>(key: T, value: D[T]) => Promise<void>;
|
|
7
|
+
setMultiple: (data: Partial<D>) => Promise<void>;
|
|
8
|
+
setAll: (data: D) => Promise<void>;
|
|
9
|
+
delete: (key: keyof D) => Promise<void>;
|
|
10
|
+
deleteMultiple: (keys: (keyof D)[]) => Promise<void>;
|
|
11
|
+
deleteAll: () => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
export declare function isKeyValueStorage<D extends Record<string, unknown>>(object: unknown): object is KeyValueStorage<D>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type
|
|
1
|
+
export type KeyValueStorageReadonly<D extends Record<string, unknown>> = {
|
|
2
2
|
get: <T extends keyof D>(key: T) => Promise<D[T]>;
|
|
3
3
|
getMultiple: <T extends keyof D>(keys: T[]) => Promise<Pick<D, T>>;
|
|
4
4
|
getAll: () => Promise<D>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { WrapletChildrenMap } from "./types/WrapletChildrenMap";
|
|
2
|
+
import { Groupable } from "../types/Groupable";
|
|
3
|
+
import { NodeTreeParent } from "../NodeTreeManager/types/NodeTreeParent";
|
|
4
|
+
import { WrapletApiFactoryArgs } from "./types/WrapletApiFactoryArgs";
|
|
5
|
+
import { WrapletApi, WrapletApiDebug } from "./types/WrapletApi";
|
|
6
|
+
export declare const createWrapletApi: <N extends Node, M extends WrapletChildrenMap>(args: WrapletApiFactoryArgs<N, M>) => WrapletApi<N> & WrapletApiDebug<N> & NodeTreeParent["wraplet"] & Groupable["wraplet"];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WrapletApi } from "./WrapletApi";
|
|
2
|
+
declare const WrapletSymbol: unique symbol;
|
|
3
|
+
export { WrapletSymbol };
|
|
4
|
+
export interface Wraplet<N extends Node = Node> {
|
|
5
|
+
[WrapletSymbol]: true;
|
|
6
|
+
wraplet: WrapletApi<N>;
|
|
7
|
+
}
|
|
8
|
+
export declare function isWraplet<N extends Node>(object: unknown): object is Wraplet<N>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { DestroyListener } from "../../Core/types/DestroyListener";
|
|
2
|
+
import { Status } from "./Status";
|
|
3
|
+
export interface WrapletApi<N extends Node = Node> {
|
|
4
|
+
status: Status;
|
|
5
|
+
accessNode(callback: (node: N) => void): void;
|
|
6
|
+
destroy(): Promise<void>;
|
|
7
|
+
initialize(): Promise<void>;
|
|
8
|
+
addDestroyListener(callback: DestroyListener<N>): void;
|
|
9
|
+
}
|
|
10
|
+
export interface WrapletApiDebug<N extends Node> {
|
|
11
|
+
__nodeAccessors: ((node: N) => void)[];
|
|
12
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WrapletChildrenMap } from "./WrapletChildrenMap";
|
|
2
|
+
import { Core } from "../../Core/types/Core";
|
|
3
|
+
import { DestroyListener } from "../../Core/types/DestroyListener";
|
|
4
|
+
import { WrapletApiFactoryBasicCallback } from "./WrapletApiFactoryBasicCallback";
|
|
5
|
+
import { GroupExtractor } from "../../types/Groupable";
|
|
6
|
+
import { Status } from "./Status";
|
|
7
|
+
import { Wraplet } from "./Wraplet";
|
|
8
|
+
export type WrapletApiFactoryArgs<N extends Node = Node, M extends WrapletChildrenMap = WrapletChildrenMap> = {
|
|
9
|
+
core: Core<N, M>;
|
|
10
|
+
wraplet: Wraplet<N>;
|
|
11
|
+
status?: Status;
|
|
12
|
+
destroyListeners?: DestroyListener<N>[];
|
|
13
|
+
initializeCallback?: WrapletApiFactoryBasicCallback;
|
|
14
|
+
destroyCallback?: WrapletApiFactoryBasicCallback;
|
|
15
|
+
groupExtractor?: GroupExtractor;
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type WrapletApiFactoryBasicCallback = () => Promise<void>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Wraplet } from "./Wraplet";
|
|
2
2
|
import { WrapletChildrenMap } from "./WrapletChildrenMap";
|
|
3
|
-
import { CoreInitOptions } from "
|
|
4
|
-
import { DynamicMap } from "
|
|
5
|
-
import { Constructable } from "
|
|
3
|
+
import { CoreInitOptions } from "../../Core/types/CoreInitOptions";
|
|
4
|
+
import { DynamicMap } from "../../Map/types/DynamicMap";
|
|
5
|
+
import { Constructable } from "../../utils/types/Utils";
|
|
6
6
|
export type SelectorCallback<N extends ParentNode = ParentNode> = (node: N) => Node[];
|
|
7
7
|
export type WrapletChildDefinition<M extends WrapletChildrenMap = WrapletChildrenMap> = {
|
|
8
8
|
selector?: string | SelectorCallback;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WrapletChildrenMap } from "./WrapletChildrenMap";
|
|
2
|
-
import { InstantiableReturnType } from "
|
|
3
|
-
import { WrapletSet } from "
|
|
2
|
+
import { InstantiableReturnType } from "../../utils/types/Utils";
|
|
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/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:()=>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});
|
|
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:()=>j,DefaultArgCreator:()=>L,DefaultCore:()=>O,DefaultWrapletSet:()=>y,DefaultWrapletSetReadonly:()=>N,MapRepeat:()=>P,defaultWrapletCreator:()=>S,destroyWrapletsRecursively:()=>m,getWrapletsFromNode:()=>w,isWraplet:()=>x});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.wraplet.status.isGettingDestroyed||i.wraplet.status.isDestroyed||await i.wraplet.destroy(),C(i,t)})}const b=Symbol("ChildrenManager"),W=Symbol("NodeTreeParent");function v(t){return{args:[],destructible:!0,map:{},coreOptions:{},...t}}function I(t){const e={};for(const i in t){const r=t[i];e[i]=v(r);const s=r.map;s&&h(s)&&(e[i].map=I(s))}return e}const D=Symbol("DynamicMap");function M(t){return d(t,D)}class E{fullMap;startingPath;currentMap=null;path;currentPath=[];constructor(t,e=[],i=!0){this.path=e,this.startingPath=e,this.fullMap=I(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 E(this.fullMap,t,e)}resolve(t){return this.findMap(t)}}const z=Symbol("ArgCreator");function S(t,e){const i=new e(t.element,t.map,t.initOptions);return new t.Class(i,...t.args)}class O{node;[b]=!0;[W]=!0;statusWritable={isDestroyed:!1,isGettingDestroyed:!1,isInitialized:!1,isGettingInitialized:!1};get status(){return this.statusWritable}mapWrapper;instantiatedChildren={};destroyChildListeners=[];instantiateChildListeners=[];listeners=[];wrapletCreator=S;constructor(t,e,i={}){if(this.node=t,h(e))this.mapWrapper=new E(e);else{if(!(e instanceof E))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.statusWritable.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.wraplet.initialize())),this.statusWritable.isInitialized=!0,this.statusWritable.isGettingInitialized=!1,this.statusWritable.isGettingDestroyed&&await this.destroy()}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.wraplet.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.wraplet.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={id:t,Class:e.Class,element:r,map:i,initOptions:e.coreOptions,args:e.args};n.args=n.args.map(t=>d(t,z)?t.createArg(n):t);const a=this.wrapletCreator(n,this.constructor);this.prepareIndividualWraplet(t,a);for(const e of this.instantiateChildListeners)e(a,t);return a}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.wraplet.addDestroyListener(e=>{this.removeChild(e,t);for(const i of this.destroyChildListeners)i(e,t)})}async destroy(){if(this.statusWritable.isDestroyed)throw new o("Children are already destroyed.");if(this.statusWritable.isGettingDestroyed=!0,!this.statusWritable.isGettingInitialized){if(!this.statusWritable.isInitialized)return this.statusWritable.isDestroyed=!0,void(this.statusWritable.isGettingDestroyed=!1);for(const t of this.listeners){const e=t.node,i=t.eventName,r=t.callback,s=t.options;e.removeEventListener(i,r,s)}this.listeners.length=0,await this.destroyChildren(),this.statusWritable.isInitialized=!1,this.statusWritable.isDestroyed=!0,this.statusWritable.isGettingDestroyed=!1}}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.statusWritable.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.statusWritable.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.statusWritable.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.wraplet.destroy();else await e.wraplet.destroy()}}class L{creator;[z]=!0;constructor(t){this.creator=t}createArg(t){return this.creator(t)}static create(t){return new L(t)}}const G=Symbol("Wraplet");function x(t){return d(t,G)}const A=Symbol("Groupable");class j{core;[G]=!0;[A]=!0;[W]=!0;destroyListeners=[];wraplet;constructor(t){if(this.core=t,!d(t,b))throw new Error("AbstractWraplet requires a Core instance.");t.addDestroyChildListener(this.onChildDestroy.bind(this)),t.addInstantiateChildListener(this.onChildInstantiate.bind(this)),this.wraplet=this.createWrapletApi({core:this.core,wraplet:this,destroyListeners:this.destroyListeners})}createWrapletApi(t){return(t=>{const e=[],i=t.destroyListeners||[];let r=t.groupExtractor||(t=>{if(t instanceof Element){const e=t.getAttribute("data-js-wraplet-groupable");if(e)return e.split(",")}return[]});const s=t.destroyCallback,n=t.status||{isGettingInitialized:!1,isDestroyed:!1,isInitialized:!1,isGettingDestroyed:!1},a=t.initializeCallback,o=async()=>{if(!n.isDestroyed&&(n.isGettingDestroyed=!0,!n.isGettingInitialized)){if(!n.isInitialized)return n.isDestroyed=!0,void(n.isGettingDestroyed=!1);await t.core.destroy();for(const e of i)await e(t.wraplet);s&&await s(),n.isGettingDestroyed=!1,n.isInitialized=!1,n.isDestroyed=!0}};return{__nodeAccessors:e,status:n,addDestroyListener:t=>{i.push(t)},initialize:async()=>{n.isInitialized||(n.isGettingInitialized=!0,await t.core.initialize(),a&&await a(),n.isInitialized=!0,n.isGettingInitialized=!1,n.isGettingDestroyed&&await o())},destroy:o,accessNode:i=>{e.push(i),i(t.core.node)},getNodeTreeChildren:()=>t.core.getNodeTreeChildren(),setGroupsExtractor:t=>{r=t},getGroups:()=>r(t.core.node)}})(t)}get children(){return this.core.children}onChildDestroy(t,e){}get node(){return this.core.node}onChildInstantiate(t,e){}isChildInstance(t,e,i=null){return e===(i||e)&&t instanceof this.core.map[e].Class}static createCore(t,e){return new O(t,e)}static createWraplets(t,e,i,r=[]){if(this===j)throw new Error("You cannot instantiate an abstract class.");const s=[];if(t instanceof Element&&t.hasAttribute(i)){const i=this.createCore(t,e);s.push(new this(i,...r))}const n=t.querySelectorAll(`[${i}]`);for(const t of n){const i=this.createCore(t,e);s.push(new this(i,...r))}return s}}class P{levels;[D]=!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 P(t)}}class N extends u{[f]=!0}var $=exports;for(var q in e)$[q]=e[q];e.__esModule&&Object.defineProperty($,"__esModule",{value:!0});
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|