wraplet 0.15.0 → 0.17.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 +1 -1
- package/dist/DefaultChildrenManager.d.ts +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/WrapletChildDefinition.d.ts +2 -1
- package/package.json +1 -1
|
@@ -52,5 +52,5 @@ export declare abstract class AbstractWraplet<M extends WrapletChildrenMap = {},
|
|
|
52
52
|
*/
|
|
53
53
|
protected isChildInstance<K extends keyof M>(item: ChildInstance<M, keyof M>, actualUnknownId: keyof M, onlyId?: K | null): item is ChildInstance<M, K>;
|
|
54
54
|
protected abstract defineChildrenMap(): M;
|
|
55
|
-
protected static createWraplets<N extends Node, T extends AbstractWraplet<any, N> = never>(node: ParentNode,
|
|
55
|
+
protected static createWraplets<N extends Node, T extends AbstractWraplet<any, N> = never>(node: ParentNode, attribute: string, additional_args?: unknown[]): T[];
|
|
56
56
|
}
|
|
@@ -38,6 +38,7 @@ export declare class DefaultChildrenManager<M extends WrapletChildrenMap = {}, N
|
|
|
38
38
|
* This method removes from nodes references to this wraplet and its children recursively.
|
|
39
39
|
*/
|
|
40
40
|
destroy(): void;
|
|
41
|
+
private findChildren;
|
|
41
42
|
private fillMapWithDefaults;
|
|
42
43
|
private addDefaultsToChildDefinition;
|
|
43
44
|
addEventListener(node: Node, eventName: string, callback: EventListenerOrEventListenerObject, options?: AddEventListenerOptions | boolean): void;
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var t={d:(e,i)=>{for(var n in i)t.o(i,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:i[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{AbstractWraplet:()=>D,DefaultChildrenManager:()=>m,DefaultWrapletSet:()=>p,DefaultWrapletSetReadonly:()=>E,destroyWrapletsRecursively:()=>g,getWrapletsFromNode:()=>y,isWraplet:()=>v});class i extends Error{}class n extends Error{}class r extends Error{}class s extends Error{}class o extends Error{}class a extends Error{}class l extends Error{}const d=(t,e)=>"object"==typeof t&&null!==t&&!0===t[e],h=Symbol("WrapletSet");function c(t){return d(t,h)}class u extends Set{find(t){const e=[];for(const i of this)t(i)&&e.push(i);return e}findOne(t){for(const e of this)if(t(e))return e;return null}getOrdered(t){return Array.from(this).sort((e,i)=>t(e)-t(i))}}const f=Symbol("WrapletSetReadonly");class p extends u{[f]=!0;[h]=!0}function y(t){const e=t.wraplets;return c(e)&&0!==e.size?e:new p}function C(t,e){e(t);const i=t.childNodes;for(const t of i)C(t,e)}function g(t){C(t,t=>{const e=y(t);for(const t of e)t.destroy()})}const w=Symbol("ChildrenManager");class m{node;[w]=!0;isDestroyed=!1;isGettingDestroyed=!1;isInitialized=!1;map;instantiatedChildren;destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(t,e,i={}){this.node=t,this.map=this.fillMapWithDefaults(e),this.processInitOptions(i),this.instantiatedChildren={}}init(){const t=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(t),this.isInitialized=!0}instantiateChildren(){const t=this.instantiatedChildren;if("function"!=typeof this.node.querySelectorAll){if(Object.keys(this.map).length>0)throw new n("If the node provided cannot have children, the children map should be empty.");return t}for(const e in this.map){const i=this.map[e],n=i.multiple;this.validateMapItem(e,i),t[e]=n?this.instantiateMultipleWrapletsChild(i,this.node,e):this.instantiateSingleWrapletChild(i,this.node,e)}return t}syncChildren(){this.instantiatedChildren=this.instantiateChildren()}findExistingWraplet(t,e){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[t])return null;const i=this.instantiatedChildren[t],n=y(e);if(this.map[t].multiple){if(!c(i))throw new l("Internal logic error. Expected a WrapletSet.");const t=this.intersect(i,n);if(0===t.length)return null;if(1===t.length)return t[0];throw new l("Internal logic error. Multiple instances of the same child found on a single node.")}return i}instantiateSingleWrapletChild(t,e,i){if(!t.selector)return null;const n=t.selector,r=this.findChildren(n,e);if(this.validateElements(i,r,t),0===r.length)return null;if(r.length>1)throw new o(`${this.constructor.name}: More than one element was found for the "${i}" child. Selector used: "${n}".`);const s=r[0];return this.instantiateWrapletItem(i,t,s)}instantiateWrapletItem(t,e,i){const n=this.findExistingWraplet(t,i);if(n)return n;const r=e.Class,s=e.args,o=this.createIndividualWraplet(r,i,s);this.prepareIndividualWraplet(t,o);for(const e of this.instantiateChildListeners)e(o,t);return o}instantiateMultipleWrapletsChild(t,e,i){const n=t.selector;if(!n)return new p;const r=this.findChildren(n,e);this.validateElements(i,r,t);const s=this.instantiatedChildren&&this.instantiatedChildren[i]?this.instantiatedChildren[i]:new p;for(const e of r){if(this.findExistingWraplet(i,e))continue;const n=this.instantiateWrapletItem(i,t,e);s.add(n)}return s}addDestroyChildListener(t){this.destroyChildListeners.push(t)}addInstantiateChildListener(t){this.instantiateChildListeners.push(t)}createIndividualWraplet(t,e,i){return new t(...[e,...i])}prepareIndividualWraplet(t,e){e.addDestroyListener(e=>{this.removeChild(e,t);for(const i of this.destroyChildListeners)i(e,t)})}destroy(){if(this.isDestroyed)throw new a("Children are already destroyed.");this.isGettingDestroyed=!0;for(const t of this.listeners){const e=t.node,i=t.eventName,n=t.callback,r=t.options;e.removeEventListener(i,n,r)}this.destroyChildren(),this.isGettingDestroyed=!1,this.isDestroyed=!0}findChildren(t,e){return"string"==typeof t?((t,e)=>Array.from(e.querySelectorAll(t)))(t,e):t(e)}fillMapWithDefaults(t){const e={};for(const i in t)e[i]=this.addDefaultsToChildDefinition(t[i]);return e}addDefaultsToChildDefinition(t){return{args:[],destructible:!0,...t}}addEventListener(t,e,i,n){this.listeners.push({node:t,eventName:e,callback:i,options:n}),t.addEventListener(e,i,n)}get children(){if(!this.isInitialized)throw new s("Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.");return this.instantiatedChildren}get uninitializedChildren(){if(this.isInitialized)throw new s("Wraplet is already initialized. Fetch children with 'children' property instead.");return this.instantiatedChildren}removeChild(t,e){if(c(this.instantiatedChildren[e])){if(!this.instantiatedChildren[e].delete(t))throw new l("Internal logic error. Destroyed child couldn't be removed because it's not among the children.")}else{if(this.map[e].required&&!this.isGettingDestroyed)throw new r("Required child has been destroyed.");if(null===this.instantiatedChildren[e])throw new l("Internal logic error. Destroyed child couldn't be removed because it's already null.");this.instantiatedChildren[e]=null}}intersect(t,e){return[...t].filter(t=>e.has(t))}validateMapItem(t,e){const i=e.selector,r=e.required;if(!i&&r)throw new n(`${this.constructor.name}: Child "${t}" cannot at the same be required and have no selector.`)}validateElements(t,e,n){if(0===e.length&&n.required)throw new i(`${this.constructor.name}: Couldn't find a node for the wraplet "${t}". Selector used: "${n.selector}".`)}wrapChildren(t){return new Proxy(t,{get:function(t,e){if(!(e in t))throw new Error("Child has not been found.");return t[e]}})}defaultInitOptions(){return{instantiateChildListeners:[],destroyChildListeners:[]}}processInitOptions(t){const e=Object.assign(this.defaultInitOptions(),t);e.mapAlterCallback&&e.mapAlterCallback(this.map);for(const t of e.instantiateChildListeners)this.instantiateChildListeners.push(t);for(const t of e.destroyChildListeners)this.destroyChildListeners.push(t)}destroyChildren(){for(const[t,e]of Object.entries(this.children))if(e&&this.map[t].destructible)if(c(e))for(const t of e)t.destroy();else e.destroy()}}const b=Symbol("Wraplet");function v(t){return d(t,b)}const W=Symbol("Groupable"),I=Symbol("NodeTreeParent");class D{node;[b]=!0;[W]=!0;[I]=!0;childrenManager;groupsExtractor=t=>{if(t instanceof Element){const e=t.getAttribute("data-js-wraplet-groupable");if(e)return e.split(",")}return[]};destroyListeners=[];__debugNodeAccessors=[];constructor(t,e={}){if(this.node=t,!t)throw new Error("Node is required to create a wraplet.");const i=this.defineChildrenMap();e.instantiateChildListeners=[this.onChildInstantiated.bind(this)],e.destroyChildListeners=[this.onChildDestroyed.bind(this)],this.childrenManager=new m(t,i,e),this.initialize()}getNodeTreeChildren(){const t=[];for(const e of Object.values(this.children))if(c(e))for(const i of e)t.push(i);else t.push(e);return t.filter(t=>{let e=!1;return t.accessNode(t=>{e=this.node.contains(t)}),e})}setGroupsExtractor(t){this.groupsExtractor=t}getGroups(){return this.groupsExtractor(this.node)}get children(){return this.childrenManager.children}accessNode(t){this.__debugNodeAccessors.push(t),t(this.node)}destroy(){for(const t of this.destroyListeners)t(this);var t;this.destroyListeners.length=0,(t=this.node).wraplets&&t.wraplets.delete(this),this.childrenManager.destroy()}isDestroyed(t=!1){return t?this.childrenManager.isDestroyed:this.childrenManager.isGettingDestroyed||this.childrenManager.isDestroyed}get isInitialized(){return this.childrenManager.isInitialized}addDestroyListener(t){this.destroyListeners.push(t)}onChildDestroyed(t,e){}initialize(){var t;this.childrenManager.init(),(t=this.node).wraplets||(t.wraplets=new p),t.wraplets.add(this)}onChildInstantiated(t,e){}isChildInstance(t,e,i=null){return e===(i||e)&&t instanceof this.childrenManager.map[e].Class}static createWraplets(t,e,i=[]){if(this===D)throw new Error("You cannot instantiate an abstract class.");const n=[];t instanceof Element&&t.hasAttribute(e)&&n.push(new this(t,...i));const r=t.querySelectorAll(`[${e}]`);for(const t of r)n.push(new this(t,...i));return n}}class E extends u{[f]=!0}var L=exports;for(var M in e)L[M]=e[M];e.__esModule&&Object.defineProperty(L,"__esModule",{value:!0});
|
|
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,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C,CAAmBrE,GACfJ,KAAK4G,iBAAiB3G,KAAKG,EAC/B,CAKA,gBAAA6G,CAAiB9F,EAAOwB,GAAM,CAC9B,UAAAuE,GN/EG,IAAmCrG,EMgFlCb,KAAKsG,gBAAgBjE,QNhFaxB,EMiFXb,KAAKa,MNhFtBC,WACND,EAAKC,SAAW,IAAIH,GAExBE,EAAKC,SAASwD,IM6EOtE,KACrB,CAIA,mBAAA+G,CAEA5F,EAEAwB,GAAM,CAaN,eAAAiF,CAAgB7H,EAAM8H,EAAiBC,EAAS,MAC5C,OAAQD,KAAqBC,GAAUD,IACnC9H,aAAgBC,KAAKsG,gBAAgB1E,IAAIiG,GAAwB,KACzE,CAIA,qBAAOE,CAAelH,EAAM4C,EAAUuE,EAAkB,IACpD,GAAIhI,OAASqG,EACT,MAAM,IAAItH,MAAM,6CAEpB,IAAIkJ,EAAapH,EAAKqH,WAGlBC,EAAa,KACZF,IACGpH,aAAgBuH,SAChBH,EAAapH,GAGbsH,EAAaE,SAASC,cAAc,OACpCH,EAAWI,YAAY1H,GACvBoH,EAAaE,IAGrB,MAAMd,EAAS,GACTmB,EAAgBP,EAAWzF,iBAAiBiB,GAC9C0E,GACAA,EAAWzD,YAAY7D,GAE3B,IAAK,MAAM4H,KAAWD,EAClBnB,EAAOpH,KAAK,IAAID,KAAKyI,KAAYT,IAErC,OAAOX,CACX,EC1JG,MAAMqB,UAAkChJ,EAC3C,CAACgB,IAA4B,E","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/types/Utils.ts","webpack://wraplet/./src/types/Set/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/types/Set/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/types/ChildrenManager.ts","webpack://wraplet/./src/DefaultChildrenManager.ts","webpack://wraplet/./src/types/Wraplet.ts","webpack://wraplet/./src/types/Groupable.ts","webpack://wraplet/./src/types/NodeTreeParent.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","/* istanbul ignore next */\n/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../Utils\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"../types/Set/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol } from \"../types/Set/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!isWrapletSet(wraplets) || wraplets.size === 0) {\n return new DefaultWrapletSet();\n }\n return wraplets;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n if (!node.wraplets) {\n return false;\n }\n return node.wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursively(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","const ChildrenManagerSymbol = Symbol(\"ChildrenManager\");\nexport { ChildrenManagerSymbol };\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, ChildrenTooManyFoundError, ChildrenAreAlreadyDestroyedError, InternalLogicError, } from \"./errors\";\nimport { getWrapletsFromNode, isParentNode } from \"./utils\";\nimport { ChildrenManagerSymbol, } from \"./types/ChildrenManager\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nimport { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nexport class DefaultChildrenManager {\n node;\n [ChildrenManagerSymbol] = true;\n isDestroyed = false;\n isGettingDestroyed = false;\n isInitialized = false;\n map;\n instantiatedChildren;\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, initOptions = {}) {\n this.node = node;\n this.map = this.fillMapWithDefaults(map);\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate child listeners) that needs access to the children manager,\n * so the children manager has to exist already.\n */\n init() {\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n this.isInitialized = true;\n }\n instantiateChildren() {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, this.node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, this.node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren();\n }\n findExistingWraplet(id, childElement) {\n // If a child doesn't have instantiated wraplets yet, then return null.\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = getWrapletsFromNode(childElement);\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingChild)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n throw new InternalLogicError(\"Internal logic error. Multiple instances of the same child found on a single node.\");\n }\n // Handle single.\n return existingChild;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new ChildrenTooManyFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args;\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : new DefaultWrapletSet();\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n items.add(wraplet);\n }\n return items;\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = ((wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n });\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method removes from nodes references to this wraplet and its children recursively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new ChildrenAreAlreadyDestroyedError(\"Children are already destroyed.\");\n }\n this.isGettingDestroyed = true;\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n this.destroyChildren();\n this.isGettingDestroyed = false;\n this.isDestroyed = true;\n }\n fillMapWithDefaults(map) {\n const newMap = {};\n for (const id in map) {\n newMap[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n return newMap;\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (isWrapletSet(this.instantiatedChildren[id])) {\n if (!this.instantiatedChildren[id].delete(wraplet)) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n return;\n }\n if (this.map[id].required && !this.isGettingDestroyed) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n if (this.instantiatedChildren[id] === null) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's already null.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n return [...a].filter((x) => b.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n destroyChildren() {\n for (const [key, child] of Object.entries(this.children)) {\n if (!child || !this.map[key][\"destructible\"]) {\n continue;\n }\n if (isWrapletSet(child)) {\n for (const item of child) {\n item.destroy();\n }\n }\n else {\n child.destroy();\n }\n }\n }\n}\n","import { is } from \"./Utils\";\nconst WrapletSymbol = Symbol(\"Wraplet\");\nexport { WrapletSymbol };\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","import { is } from \"./Utils\";\nconst GroupableSymbol = Symbol(\"Groupable\");\nexport { GroupableSymbol };\n/* istanbul ignore next */\nexport function isGroupable(object) {\n return is(object, GroupableSymbol);\n}\nconst defaultGroupableAttribute = \"data-js-wraplet-groupable\";\nexport { defaultGroupableAttribute };\n","const NodeTreeParentSymbol = Symbol(\"NodeTreeParent\");\nexport { NodeTreeParentSymbol };\n/* istanbul ignore next */\nexport function isNodeTreeParent(object) {\n return (object[NodeTreeParentSymbol] ===\n true);\n}\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { DefaultChildrenManager } from \"./DefaultChildrenManager\";\nimport { defaultGroupableAttribute, GroupableSymbol, } from \"./types/Groupable\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { addWrapletToNode, removeWrapletFromNode } from \"./utils\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n [GroupableSymbol] = true;\n [NodeTreeParentSymbol] = true;\n childrenManager;\n groupsExtractor = (node) => {\n if (node instanceof Element) {\n const groupsString = node.getAttribute(defaultGroupableAttribute);\n if (groupsString) {\n return groupsString.split(\",\");\n }\n }\n return [];\n };\n destroyListeners = [];\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n constructor(node, initOptions = {}) {\n this.node = node;\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.childrenManager = new DefaultChildrenManager(node, map, initOptions);\n this.initialize();\n }\n getNodeTreeChildren() {\n const children = [];\n for (const child of Object.values(this.children)) {\n if (isWrapletSet(child)) {\n for (const item of child) {\n children.push(item);\n }\n }\n else {\n children.push(child);\n }\n }\n // Return only descendants.\n return children.filter((child) => {\n let result = false;\n child.accessNode((childsNode) => {\n result = this.node.contains(childsNode);\n });\n return result;\n });\n }\n setGroupsExtractor(callback) {\n this.groupsExtractor = callback;\n }\n getGroups() {\n return this.groupsExtractor(this.node);\n }\n get children() {\n return this.childrenManager.children;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n destroy() {\n for (const listener of this.destroyListeners) {\n listener(this);\n }\n this.destroyListeners.length = 0;\n removeWrapletFromNode(this, this.node);\n this.childrenManager.destroy();\n }\n isDestroyed(completely = false) {\n return completely\n ? this.childrenManager.isDestroyed\n : this.childrenManager.isGettingDestroyed ||\n this.childrenManager.isDestroyed;\n }\n get isInitialized() {\n return this.childrenManager.isInitialized;\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.childrenManager.init();\n addWrapletToNode(this, this.node);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.childrenManager.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"../types/Set/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","ChildrenTooManyFoundError","ChildrenAreAlreadyDestroyedError","InternalLogicError","object","symbol","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","item","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","getWrapletsFromNode","node","wraplets","size","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","ChildrenManagerSymbol","DefaultChildrenManager","isDestroyed","isGettingDestroyed","isInitialized","map","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","constructor","initOptions","fillMapWithDefaults","processInitOptions","init","instantiateChildren","wrapChildren","querySelectorAll","keys","length","id","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","newMap","addDefaultsToChildDefinition","destructible","addEventListener","uninitializedChildren","delete","required","x","has","isRequired","elements","Proxy","target","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","entries","WrapletSymbol","isWraplet","GroupableSymbol","NodeTreeParentSymbol","AbstractWraplet","childrenManager","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","getNodeTreeChildren","values","result","accessNode","childsNode","contains","setGroupsExtractor","getGroups","completely","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","foundElements","element","DefaultWrapletSetReadonly"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.cjs","mappings":"AACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,2MCLhD,MAAMC,UAAkCC,OAExC,MAAMC,UAAiBD,OAEvB,MAAME,UAAoCF,OAE1C,MAAMG,UAAqCH,OAI3C,MAAMI,UAAkCJ,OAExC,MAAMK,UAAyCL,OAE/C,MAAMM,UAA2BN,OCVxC,MAAM,EAAK,CAACO,EAAQC,IACU,iBAAXD,GACA,OAAXA,IACmB,IAAnBA,EAAOC,GCNTC,EAAmBb,OAAO,cAEzB,SAASc,EAAaH,GACzB,OAAO,EAAGA,EAAQE,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,E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AAiB,IAAI0F,MAChD,IAAK,MAAMI,KAAWD,EAClBd,EAAOtH,KAAK,IAAID,KAAKsI,KAAYH,IAErC,OAAOZ,CACX,EC5IG,MAAMgB,UAAkC7I,EAC3C,CAACgB,IAA4B,E","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/types/Utils.ts","webpack://wraplet/./src/types/Set/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/types/Set/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/types/ChildrenManager.ts","webpack://wraplet/./src/DefaultChildrenManager.ts","webpack://wraplet/./src/types/Wraplet.ts","webpack://wraplet/./src/types/Groupable.ts","webpack://wraplet/./src/types/NodeTreeParent.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","/* istanbul ignore next */\n/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../Utils\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"../types/Set/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol } from \"../types/Set/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!isWrapletSet(wraplets) || wraplets.size === 0) {\n return new DefaultWrapletSet();\n }\n return wraplets;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n if (!node.wraplets) {\n return false;\n }\n return node.wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursively(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","const ChildrenManagerSymbol = Symbol(\"ChildrenManager\");\nexport { ChildrenManagerSymbol };\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, ChildrenTooManyFoundError, ChildrenAreAlreadyDestroyedError, InternalLogicError, } from \"./errors\";\nimport { getWrapletsFromNode, isParentNode } from \"./utils\";\nimport { ChildrenManagerSymbol, } from \"./types/ChildrenManager\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nimport { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nexport class DefaultChildrenManager {\n node;\n [ChildrenManagerSymbol] = true;\n isDestroyed = false;\n isGettingDestroyed = false;\n isInitialized = false;\n map;\n instantiatedChildren;\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, initOptions = {}) {\n this.node = node;\n this.map = this.fillMapWithDefaults(map);\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate child listeners) that needs access to the children manager,\n * so the children manager has to exist already.\n */\n init() {\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n this.isInitialized = true;\n }\n instantiateChildren() {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, this.node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, this.node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren();\n }\n findExistingWraplet(id, childElement) {\n // If a child doesn't have instantiated wraplets yet, then return null.\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = getWrapletsFromNode(childElement);\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingChild)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n throw new InternalLogicError(\"Internal logic error. Multiple instances of the same child found on a single node.\");\n }\n // Handle single.\n return existingChild;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = this.findChildren(selector, node);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new ChildrenTooManyFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args;\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildren(selector, node);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : new DefaultWrapletSet();\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n items.add(wraplet);\n }\n return items;\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = ((wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n });\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method removes from nodes references to this wraplet and its children recursively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new ChildrenAreAlreadyDestroyedError(\"Children are already destroyed.\");\n }\n this.isGettingDestroyed = true;\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n this.destroyChildren();\n this.isGettingDestroyed = false;\n this.isDestroyed = true;\n }\n findChildren(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n fillMapWithDefaults(map) {\n const newMap = {};\n for (const id in map) {\n newMap[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n return newMap;\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (isWrapletSet(this.instantiatedChildren[id])) {\n if (!this.instantiatedChildren[id].delete(wraplet)) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n return;\n }\n if (this.map[id].required && !this.isGettingDestroyed) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n if (this.instantiatedChildren[id] === null) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's already null.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n return [...a].filter((x) => b.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n destroyChildren() {\n for (const [key, child] of Object.entries(this.children)) {\n if (!child || !this.map[key][\"destructible\"]) {\n continue;\n }\n if (isWrapletSet(child)) {\n for (const item of child) {\n item.destroy();\n }\n }\n else {\n child.destroy();\n }\n }\n }\n}\n","import { is } from \"./Utils\";\nconst WrapletSymbol = Symbol(\"Wraplet\");\nexport { WrapletSymbol };\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","import { is } from \"./Utils\";\nconst GroupableSymbol = Symbol(\"Groupable\");\nexport { GroupableSymbol };\n/* istanbul ignore next */\nexport function isGroupable(object) {\n return is(object, GroupableSymbol);\n}\nconst defaultGroupableAttribute = \"data-js-wraplet-groupable\";\nexport { defaultGroupableAttribute };\n","const NodeTreeParentSymbol = Symbol(\"NodeTreeParent\");\nexport { NodeTreeParentSymbol };\n/* istanbul ignore next */\nexport function isNodeTreeParent(object) {\n return (object[NodeTreeParentSymbol] ===\n true);\n}\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { DefaultChildrenManager } from \"./DefaultChildrenManager\";\nimport { defaultGroupableAttribute, GroupableSymbol, } from \"./types/Groupable\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { addWrapletToNode, removeWrapletFromNode } from \"./utils\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n [GroupableSymbol] = true;\n [NodeTreeParentSymbol] = true;\n childrenManager;\n groupsExtractor = (node) => {\n if (node instanceof Element) {\n const groupsString = node.getAttribute(defaultGroupableAttribute);\n if (groupsString) {\n return groupsString.split(\",\");\n }\n }\n return [];\n };\n destroyListeners = [];\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n constructor(node, initOptions = {}) {\n this.node = node;\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.childrenManager = new DefaultChildrenManager(node, map, initOptions);\n this.initialize();\n }\n getNodeTreeChildren() {\n const children = [];\n for (const child of Object.values(this.children)) {\n if (isWrapletSet(child)) {\n for (const item of child) {\n children.push(item);\n }\n }\n else {\n children.push(child);\n }\n }\n // Return only descendants.\n return children.filter((child) => {\n let result = false;\n child.accessNode((childsNode) => {\n result = this.node.contains(childsNode);\n });\n return result;\n });\n }\n setGroupsExtractor(callback) {\n this.groupsExtractor = callback;\n }\n getGroups() {\n return this.groupsExtractor(this.node);\n }\n get children() {\n return this.childrenManager.children;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n destroy() {\n for (const listener of this.destroyListeners) {\n listener(this);\n }\n this.destroyListeners.length = 0;\n removeWrapletFromNode(this, this.node);\n this.childrenManager.destroy();\n }\n isDestroyed(completely = false) {\n return completely\n ? this.childrenManager.isDestroyed\n : this.childrenManager.isGettingDestroyed ||\n this.childrenManager.isDestroyed;\n }\n get isInitialized() {\n return this.childrenManager.isInitialized;\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.childrenManager.init();\n addWrapletToNode(this, this.node);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.childrenManager.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, attribute, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"../types/Set/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","ChildrenTooManyFoundError","ChildrenAreAlreadyDestroyedError","InternalLogicError","object","symbol","WrapletSetSymbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","item","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","getWrapletsFromNode","node","wraplets","size","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","ChildrenManagerSymbol","DefaultChildrenManager","isDestroyed","isGettingDestroyed","isInitialized","map","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","constructor","initOptions","fillMapWithDefaults","processInitOptions","init","instantiateChildren","wrapChildren","querySelectorAll","keys","length","id","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","findChildren","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","defaultSelectorCallback","newMap","addDefaultsToChildDefinition","destructible","addEventListener","uninitializedChildren","delete","required","x","has","isRequired","elements","Proxy","target","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","entries","WrapletSymbol","isWraplet","GroupableSymbol","NodeTreeParentSymbol","AbstractWraplet","childrenManager","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","getNodeTreeChildren","values","result","accessNode","childsNode","contains","setGroupsExtractor","getGroups","completely","isChildInstance","actualUnknownId","onlyId","createWraplets","attribute","additional_args","hasAttribute","foundElements","element","DefaultWrapletSetReadonly"],"sourceRoot":""}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export type { WrapletSet } from "./types/Set/WrapletSet";
|
|
|
6
6
|
export { DefaultWrapletSetReadonly } from "./Set/DefaultWrapletSetReadonly";
|
|
7
7
|
export { DefaultWrapletSet } from "./Set/DefaultWrapletSet";
|
|
8
8
|
export { isWraplet } from "./types/Wraplet";
|
|
9
|
+
export type { StorageValidators } from "./types/Storage/StorageValidators";
|
|
9
10
|
export type { WrapletChildrenMap } from "./types/WrapletChildrenMap";
|
|
10
11
|
export type { Wraplet } from "./types/Wraplet";
|
|
12
|
+
export type { SelectorCallback } from "./types/WrapletChildDefinition";
|
|
11
13
|
import "./types/global";
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t extends Error{}class e extends Error{}class i extends Error{}class n extends Error{}class s extends Error{}class r extends Error{}class o extends Error{}const a=(t,e)=>"object"==typeof t&&null!==t&&!0===t[e],l=Symbol("WrapletSet");function d(t){return a(t,l)}class h extends Set{find(t){const e=[];for(const i of this)t(i)&&e.push(i);return e}findOne(t){for(const e of this)if(t(e))return e;return null}getOrdered(t){return Array.from(this).sort((e,i)=>t(e)-t(i))}}const c=Symbol("WrapletSetReadonly");class u extends h{[c]=!0;[l]=!0}function f(t){const e=t.wraplets;return d(e)&&0!==e.size?e:new u}function p(t,e){e(t);const i=t.childNodes;for(const t of i)p(t,e)}function C(t){p(t,t=>{const e=f(t);for(const t of e)t.destroy()})}const y=Symbol("ChildrenManager");class g{node;[y]=!0;isDestroyed=!1;isGettingDestroyed=!1;isInitialized=!1;map;instantiatedChildren;destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(t,e,i={}){this.node=t,this.map=this.fillMapWithDefaults(e),this.processInitOptions(i),this.instantiatedChildren={}}init(){const t=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(t),this.isInitialized=!0}instantiateChildren(){const t=this.instantiatedChildren;if("function"!=typeof this.node.querySelectorAll){if(Object.keys(this.map).length>0)throw new e("If the node provided cannot have children, the children map should be empty.");return t}for(const e in this.map){const i=this.map[e],n=i.multiple;this.validateMapItem(e,i),t[e]=n?this.instantiateMultipleWrapletsChild(i,this.node,e):this.instantiateSingleWrapletChild(i,this.node,e)}return t}syncChildren(){this.instantiatedChildren=this.instantiateChildren()}findExistingWraplet(t,e){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[t])return null;const i=this.instantiatedChildren[t],n=f(e);if(this.map[t].multiple){if(!d(i))throw new o("Internal logic error. Expected a WrapletSet.");const t=this.intersect(i,n);if(0===t.length)return null;if(1===t.length)return t[0];throw new o("Internal logic error. Multiple instances of the same child found on a single node.")}return i}instantiateSingleWrapletChild(t,e,i){if(!t.selector)return null;const n=t.selector,r=
|
|
1
|
+
class t extends Error{}class e extends Error{}class i extends Error{}class n extends Error{}class s extends Error{}class r extends Error{}class o extends Error{}const a=(t,e)=>"object"==typeof t&&null!==t&&!0===t[e],l=Symbol("WrapletSet");function d(t){return a(t,l)}class h extends Set{find(t){const e=[];for(const i of this)t(i)&&e.push(i);return e}findOne(t){for(const e of this)if(t(e))return e;return null}getOrdered(t){return Array.from(this).sort((e,i)=>t(e)-t(i))}}const c=Symbol("WrapletSetReadonly");class u extends h{[c]=!0;[l]=!0}function f(t){const e=t.wraplets;return d(e)&&0!==e.size?e:new u}function p(t,e){e(t);const i=t.childNodes;for(const t of i)p(t,e)}function C(t){p(t,t=>{const e=f(t);for(const t of e)t.destroy()})}const y=Symbol("ChildrenManager");class g{node;[y]=!0;isDestroyed=!1;isGettingDestroyed=!1;isInitialized=!1;map;instantiatedChildren;destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(t,e,i={}){this.node=t,this.map=this.fillMapWithDefaults(e),this.processInitOptions(i),this.instantiatedChildren={}}init(){const t=this.instantiateChildren();this.instantiatedChildren=this.wrapChildren(t),this.isInitialized=!0}instantiateChildren(){const t=this.instantiatedChildren;if("function"!=typeof this.node.querySelectorAll){if(Object.keys(this.map).length>0)throw new e("If the node provided cannot have children, the children map should be empty.");return t}for(const e in this.map){const i=this.map[e],n=i.multiple;this.validateMapItem(e,i),t[e]=n?this.instantiateMultipleWrapletsChild(i,this.node,e):this.instantiateSingleWrapletChild(i,this.node,e)}return t}syncChildren(){this.instantiatedChildren=this.instantiateChildren()}findExistingWraplet(t,e){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[t])return null;const i=this.instantiatedChildren[t],n=f(e);if(this.map[t].multiple){if(!d(i))throw new o("Internal logic error. Expected a WrapletSet.");const t=this.intersect(i,n);if(0===t.length)return null;if(1===t.length)return t[0];throw new o("Internal logic error. Multiple instances of the same child found on a single node.")}return i}instantiateSingleWrapletChild(t,e,i){if(!t.selector)return null;const n=t.selector,r=this.findChildren(n,e);if(this.validateElements(i,r,t),0===r.length)return null;if(r.length>1)throw new s(`${this.constructor.name}: More than one element was found for the "${i}" child. Selector used: "${n}".`);const o=r[0];return this.instantiateWrapletItem(i,t,o)}instantiateWrapletItem(t,e,i){const n=this.findExistingWraplet(t,i);if(n)return n;const s=e.Class,r=e.args,o=this.createIndividualWraplet(s,i,r);this.prepareIndividualWraplet(t,o);for(const e of this.instantiateChildListeners)e(o,t);return o}instantiateMultipleWrapletsChild(t,e,i){const n=t.selector;if(!n)return new u;const s=this.findChildren(n,e);this.validateElements(i,s,t);const r=this.instantiatedChildren&&this.instantiatedChildren[i]?this.instantiatedChildren[i]:new u;for(const e of s){if(this.findExistingWraplet(i,e))continue;const n=this.instantiateWrapletItem(i,t,e);r.add(n)}return r}addDestroyChildListener(t){this.destroyChildListeners.push(t)}addInstantiateChildListener(t){this.instantiateChildListeners.push(t)}createIndividualWraplet(t,e,i){return new t(...[e,...i])}prepareIndividualWraplet(t,e){e.addDestroyListener(e=>{this.removeChild(e,t);for(const i of this.destroyChildListeners)i(e,t)})}destroy(){if(this.isDestroyed)throw new r("Children are already destroyed.");this.isGettingDestroyed=!0;for(const t of this.listeners){const e=t.node,i=t.eventName,n=t.callback,s=t.options;e.removeEventListener(i,n,s)}this.destroyChildren(),this.isGettingDestroyed=!1,this.isDestroyed=!0}findChildren(t,e){return"string"==typeof t?((t,e)=>Array.from(e.querySelectorAll(t)))(t,e):t(e)}fillMapWithDefaults(t){const e={};for(const i in t)e[i]=this.addDefaultsToChildDefinition(t[i]);return e}addDefaultsToChildDefinition(t){return{args:[],destructible:!0,...t}}addEventListener(t,e,i,n){this.listeners.push({node:t,eventName:e,callback:i,options:n}),t.addEventListener(e,i,n)}get children(){if(!this.isInitialized)throw new n("Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.");return this.instantiatedChildren}get uninitializedChildren(){if(this.isInitialized)throw new n("Wraplet is already initialized. Fetch children with 'children' property instead.");return this.instantiatedChildren}removeChild(t,e){if(d(this.instantiatedChildren[e])){if(!this.instantiatedChildren[e].delete(t))throw new o("Internal logic error. Destroyed child couldn't be removed because it's not among the children.")}else{if(this.map[e].required&&!this.isGettingDestroyed)throw new i("Required child has been destroyed.");if(null===this.instantiatedChildren[e])throw new o("Internal logic error. Destroyed child couldn't be removed because it's already null.");this.instantiatedChildren[e]=null}}intersect(t,e){return[...t].filter(t=>e.has(t))}validateMapItem(t,i){const n=i.selector,s=i.required;if(!n&&s)throw new e(`${this.constructor.name}: Child "${t}" cannot at the same be required and have no selector.`)}validateElements(e,i,n){if(0===i.length&&n.required)throw new t(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${n.selector}".`)}wrapChildren(t){return new Proxy(t,{get:function(t,e){if(!(e in t))throw new Error("Child has not been found.");return t[e]}})}defaultInitOptions(){return{instantiateChildListeners:[],destroyChildListeners:[]}}processInitOptions(t){const e=Object.assign(this.defaultInitOptions(),t);e.mapAlterCallback&&e.mapAlterCallback(this.map);for(const t of e.instantiateChildListeners)this.instantiateChildListeners.push(t);for(const t of e.destroyChildListeners)this.destroyChildListeners.push(t)}destroyChildren(){for(const[t,e]of Object.entries(this.children))if(e&&this.map[t].destructible)if(d(e))for(const t of e)t.destroy();else e.destroy()}}const w=Symbol("Wraplet");function m(t){return a(t,w)}const b=Symbol("Groupable"),I=Symbol("NodeTreeParent");class v{node;[w]=!0;[b]=!0;[I]=!0;childrenManager;groupsExtractor=t=>{if(t instanceof Element){const e=t.getAttribute("data-js-wraplet-groupable");if(e)return e.split(",")}return[]};destroyListeners=[];__debugNodeAccessors=[];constructor(t,e={}){if(this.node=t,!t)throw new Error("Node is required to create a wraplet.");const i=this.defineChildrenMap();e.instantiateChildListeners=[this.onChildInstantiated.bind(this)],e.destroyChildListeners=[this.onChildDestroyed.bind(this)],this.childrenManager=new g(t,i,e),this.initialize()}getNodeTreeChildren(){const t=[];for(const e of Object.values(this.children))if(d(e))for(const i of e)t.push(i);else t.push(e);return t.filter(t=>{let e=!1;return t.accessNode(t=>{e=this.node.contains(t)}),e})}setGroupsExtractor(t){this.groupsExtractor=t}getGroups(){return this.groupsExtractor(this.node)}get children(){return this.childrenManager.children}accessNode(t){this.__debugNodeAccessors.push(t),t(this.node)}destroy(){for(const t of this.destroyListeners)t(this);var t;this.destroyListeners.length=0,(t=this.node).wraplets&&t.wraplets.delete(this),this.childrenManager.destroy()}isDestroyed(t=!1){return t?this.childrenManager.isDestroyed:this.childrenManager.isGettingDestroyed||this.childrenManager.isDestroyed}get isInitialized(){return this.childrenManager.isInitialized}addDestroyListener(t){this.destroyListeners.push(t)}onChildDestroyed(t,e){}initialize(){var t;this.childrenManager.init(),(t=this.node).wraplets||(t.wraplets=new u),t.wraplets.add(this)}onChildInstantiated(t,e){}isChildInstance(t,e,i=null){return e===(i||e)&&t instanceof this.childrenManager.map[e].Class}static createWraplets(t,e,i=[]){if(this===v)throw new Error("You cannot instantiate an abstract class.");const n=[];t instanceof Element&&t.hasAttribute(e)&&n.push(new this(t,...i));const s=t.querySelectorAll(`[${e}]`);for(const t of s)n.push(new this(t,...i));return n}}class E extends h{[c]=!0}export{v as AbstractWraplet,g as DefaultChildrenManager,u as DefaultWrapletSet,E as DefaultWrapletSetReadonly,C as destroyWrapletsRecursively,f as getWrapletsFromNode,m as isWraplet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"AAAO,MAAMA,UAAkCC,OAExC,MAAMC,UAAiBD,OAEvB,MAAME,UAAoCF,OAE1C,MAAMG,UAAqCH,OAI3C,MAAMI,UAAkCJ,OAExC,MAAMK,UAAyCL,OAE/C,MAAMM,UAA2BN,OCVxC,MAAM,EAAK,CAACO,EAAQC,IACU,iBAAXD,GACA,OAAXA,IACmB,IAAnBA,EAAOC,GCNTC,EAAmBC,OAAO,cAEzB,SAASC,EAAaJ,GACzB,OAAO,EAAGA,EAAQE,EACtB,CCLO,MAAMG,UAA6BC,IACtC,IAAAC,CAAKC,GACD,MAAMC,EAA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aE,IAGrB,MAAMd,EAAS,GACTmB,EAAgBP,EAAW7F,iBAAiBkB,GAC9C6E,GACAA,EAAW5D,YAAY9D,GAE3B,IAAK,MAAMgI,KAAWD,EAClBnB,EAAOxH,KAAK,IAAID,KAAK6I,KAAYT,IAErC,OAAOX,CACX,EC1JG,MAAMqB,UAAkCpJ,EAC3C,CAACgB,IAA4B,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/types/Utils.ts","webpack://wraplet/./src/types/Set/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/types/Set/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/types/ChildrenManager.ts","webpack://wraplet/./src/DefaultChildrenManager.ts","webpack://wraplet/./src/types/Wraplet.ts","webpack://wraplet/./src/types/Groupable.ts","webpack://wraplet/./src/types/NodeTreeParent.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","/* istanbul ignore next */\n/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../Utils\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"../types/Set/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol } from \"../types/Set/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!isWrapletSet(wraplets) || wraplets.size === 0) {\n return new DefaultWrapletSet();\n }\n return wraplets;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n if (!node.wraplets) {\n return false;\n }\n return node.wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursively(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","const ChildrenManagerSymbol = Symbol(\"ChildrenManager\");\nexport { ChildrenManagerSymbol };\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, ChildrenTooManyFoundError, ChildrenAreAlreadyDestroyedError, InternalLogicError, } from \"./errors\";\nimport { getWrapletsFromNode, isParentNode } from \"./utils\";\nimport { ChildrenManagerSymbol, } from \"./types/ChildrenManager\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nimport { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nexport class DefaultChildrenManager {\n node;\n [ChildrenManagerSymbol] = true;\n isDestroyed = false;\n isGettingDestroyed = false;\n isInitialized = false;\n map;\n instantiatedChildren;\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, initOptions = {}) {\n this.node = node;\n this.map = this.fillMapWithDefaults(map);\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate child listeners) that needs access to the children manager,\n * so the children manager has to exist already.\n */\n init() {\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n this.isInitialized = true;\n }\n instantiateChildren() {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, this.node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, this.node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren();\n }\n findExistingWraplet(id, childElement) {\n // If a child doesn't have instantiated wraplets yet, then return null.\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = getWrapletsFromNode(childElement);\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingChild)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n throw new InternalLogicError(\"Internal logic error. Multiple instances of the same child found on a single node.\");\n }\n // Handle single.\n return existingChild;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new ChildrenTooManyFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args;\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : new DefaultWrapletSet();\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n items.add(wraplet);\n }\n return items;\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = ((wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n });\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method removes from nodes references to this wraplet and its children recursively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new ChildrenAreAlreadyDestroyedError(\"Children are already destroyed.\");\n }\n this.isGettingDestroyed = true;\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n this.destroyChildren();\n this.isGettingDestroyed = false;\n this.isDestroyed = true;\n }\n fillMapWithDefaults(map) {\n const newMap = {};\n for (const id in map) {\n newMap[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n return newMap;\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (isWrapletSet(this.instantiatedChildren[id])) {\n if (!this.instantiatedChildren[id].delete(wraplet)) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n return;\n }\n if (this.map[id].required && !this.isGettingDestroyed) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n if (this.instantiatedChildren[id] === null) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's already null.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n return [...a].filter((x) => b.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n destroyChildren() {\n for (const [key, child] of Object.entries(this.children)) {\n if (!child || !this.map[key][\"destructible\"]) {\n continue;\n }\n if (isWrapletSet(child)) {\n for (const item of child) {\n item.destroy();\n }\n }\n else {\n child.destroy();\n }\n }\n }\n}\n","import { is } from \"./Utils\";\nconst WrapletSymbol = Symbol(\"Wraplet\");\nexport { WrapletSymbol };\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","import { is } from \"./Utils\";\nconst GroupableSymbol = Symbol(\"Groupable\");\nexport { GroupableSymbol };\n/* istanbul ignore next */\nexport function isGroupable(object) {\n return is(object, GroupableSymbol);\n}\nconst defaultGroupableAttribute = \"data-js-wraplet-groupable\";\nexport { defaultGroupableAttribute };\n","const NodeTreeParentSymbol = Symbol(\"NodeTreeParent\");\nexport { NodeTreeParentSymbol };\n/* istanbul ignore next */\nexport function isNodeTreeParent(object) {\n return (object[NodeTreeParentSymbol] ===\n true);\n}\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { DefaultChildrenManager } from \"./DefaultChildrenManager\";\nimport { defaultGroupableAttribute, GroupableSymbol, } from \"./types/Groupable\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { addWrapletToNode, removeWrapletFromNode } from \"./utils\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n [GroupableSymbol] = true;\n [NodeTreeParentSymbol] = true;\n childrenManager;\n groupsExtractor = (node) => {\n if (node instanceof Element) {\n const groupsString = node.getAttribute(defaultGroupableAttribute);\n if (groupsString) {\n return groupsString.split(\",\");\n }\n }\n return [];\n };\n destroyListeners = [];\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n constructor(node, initOptions = {}) {\n this.node = node;\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.childrenManager = new DefaultChildrenManager(node, map, initOptions);\n this.initialize();\n }\n getNodeTreeChildren() {\n const children = [];\n for (const child of Object.values(this.children)) {\n if (isWrapletSet(child)) {\n for (const item of child) {\n children.push(item);\n }\n }\n else {\n children.push(child);\n }\n }\n // Return only descendants.\n return children.filter((child) => {\n let result = false;\n child.accessNode((childsNode) => {\n result = this.node.contains(childsNode);\n });\n return result;\n });\n }\n setGroupsExtractor(callback) {\n this.groupsExtractor = callback;\n }\n getGroups() {\n return this.groupsExtractor(this.node);\n }\n get children() {\n return this.childrenManager.children;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n destroy() {\n for (const listener of this.destroyListeners) {\n listener(this);\n }\n this.destroyListeners.length = 0;\n removeWrapletFromNode(this, this.node);\n this.childrenManager.destroy();\n }\n isDestroyed(completely = false) {\n return completely\n ? this.childrenManager.isDestroyed\n : this.childrenManager.isGettingDestroyed ||\n this.childrenManager.isDestroyed;\n }\n get isInitialized() {\n return this.childrenManager.isInitialized;\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.childrenManager.init();\n addWrapletToNode(this, this.node);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.childrenManager.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"../types/Set/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n"],"names":["MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","ChildrenTooManyFoundError","ChildrenAreAlreadyDestroyedError","InternalLogicError","object","symbol","WrapletSetSymbol","Symbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","item","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","getWrapletsFromNode","node","wraplets","size","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","ChildrenManagerSymbol","DefaultChildrenManager","isDestroyed","isGettingDestroyed","isInitialized","map","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","constructor","initOptions","fillMapWithDefaults","processInitOptions","init","instantiateChildren","wrapChildren","querySelectorAll","Object","keys","length","id","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","newMap","addDefaultsToChildDefinition","definition","destructible","addEventListener","uninitializedChildren","delete","required","x","has","isRequired","elements","Proxy","get","target","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","key","entries","WrapletSymbol","isWraplet","GroupableSymbol","NodeTreeParentSymbol","AbstractWraplet","childrenManager","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","getNodeTreeChildren","values","result","accessNode","childsNode","contains","setGroupsExtractor","getGroups","completely","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","foundElements","element","DefaultWrapletSetReadonly"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"AAAO,MAAMA,UAAkCC,OAExC,MAAMC,UAAiBD,OAEvB,MAAME,UAAoCF,OAE1C,MAAMG,UAAqCH,OAI3C,MAAMI,UAAkCJ,OAExC,MAAMK,UAAyCL,OAE/C,MAAMM,UAA2BN,OCVxC,MAAM,EAAK,CAACO,EAAQC,IACU,iBAAXD,GACA,OAAXA,IACmB,IAAnBA,EAAOC,GCNTC,EAAmBC,OAAO,cAEzB,SAASC,EAAaJ,GACzB,OAAO,EAAGA,EAAQE,EACtB,CCLO,MAAMG,UAA6BC,IACtC,IAAAC,CAAKC,GACD,MAAMC,EAAU,GAChB,IAAK,MAAMC,KAAQC,KACVH,EAAOE,IAGZD,EAAQG,KAAKF,GAEjB,OAAOD,CACX,CACA,OAAAI,CAAQL,GACJ,IAAK,MAAME,KAAQC,KACf,GAAIH,EAAOE,GACP,OAAOA,EAGf,OAAO,IACX,CACA,UAAAI,CAAWC,GACP,OAAOC,MAAMC,KAAKN,MAAMO,KAAK,CAACC,EAAGC,IAAML,EAASI,GAAKJ,EAASK,GAClE,ECrBJ,MAAMC,EAA2BlB,OAAO,sBCGjC,MAAMmB,UAA0BjB,EACnC,CAACgB,IAA4B,EAC7B,CAACnB,IAAoB,ECClB,SAASqB,EAAoBC,GAChC,MAAMC,EAAWD,EAAKC,SACtB,OAAKrB,EAAaqB,IAA+B,IAAlBA,EAASC,KAGjCD,EAFI,IAAIH,CAGnB,CAaO,SAASK,EAAsBH,EAAMT,GACxCA,EAASS,GACT,MAAMI,EAAWJ,EAAKK,WACtB,IAAK,MAAMC,KAASF,EAChBD,EAAsBG,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F,YACrBzB,KAAK4G,gBAAgBlF,oBACnB1B,KAAK4G,gBAAgBnF,WACjC,CACA,iBAAIE,GACA,OAAO3B,KAAK4G,gBAAgBjF,aAChC,CACA,kBAAAgD,CAAmBvE,GACfJ,KAAKkH,iBAAiBjH,KAAKG,EAC/B,CAKA,gBAAAmH,CAAiBpG,EAAOyB,GAAM,CAC9B,UAAA4E,GN/EG,IAAmC3G,EMgFlCb,KAAK4G,gBAAgBvE,QNhFaxB,EMiFXb,KAAKa,MNhFtBC,WACND,EAAKC,SAAW,IAAIH,GAExBE,EAAKC,SAAS0D,IM6EOxE,KACrB,CAIA,mBAAAqH,CAEAlG,EAEAyB,GAAM,CAaN,eAAAsF,CAAgBnI,EAAMoI,EAAiBC,EAAS,MAC5C,OAAQD,KAAqBC,GAAUD,IACnCpI,aAAgBC,KAAK4G,gBAAgBhF,IAAIuG,GAAwB,KACzE,CAIA,qBAAOE,CAAexH,EAAMyH,EAAWC,EAAkB,IACrD,GAAIvI,OAAS2G,EACT,MAAM,IAAI7H,MAAM,6CAEpB,MAAM6I,EAAS,GACX9G,aAAgBiG,SAAWjG,EAAK2H,aAAaF,IAC7CX,EAAO1H,KAAK,IAAID,KAAKa,KAAS0H,IAElC,MAAME,EAAgB5H,EAAK2B,iBAAiB,IAAI8F,MAChD,IAAK,MAAMI,KAAWD,EAClBd,EAAO1H,KAAK,IAAID,KAAK0I,KAAYH,IAErC,OAAOZ,CACX,EC5IG,MAAMgB,UAAkCjJ,EAC3C,CAACgB,IAA4B,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/types/Utils.ts","webpack://wraplet/./src/types/Set/WrapletSet.ts","webpack://wraplet/./src/Set/DefaultSearchableSet.ts","webpack://wraplet/./src/types/Set/WrapletSetReadonly.ts","webpack://wraplet/./src/Set/DefaultWrapletSet.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/types/ChildrenManager.ts","webpack://wraplet/./src/DefaultChildrenManager.ts","webpack://wraplet/./src/types/Wraplet.ts","webpack://wraplet/./src/types/Groupable.ts","webpack://wraplet/./src/types/NodeTreeParent.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/Set/DefaultWrapletSetReadonly.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\nexport class ChildrenTooManyFoundError extends Error {\n}\nexport class ChildrenAreAlreadyDestroyedError extends Error {\n}\nexport class InternalLogicError extends Error {\n}\n","/* istanbul ignore next */\n/**\n * Generic guard.\n */\nconst is = (object, symbol) => {\n return (typeof object === \"object\" &&\n object !== null &&\n object[symbol] === true);\n};\nexport { is };\n","import { is } from \"../Utils\";\nconst WrapletSetSymbol = Symbol(\"WrapletSet\");\nexport { WrapletSetSymbol };\nexport function isWrapletSet(object) {\n return is(object, WrapletSetSymbol);\n}\n","export class DefaultSearchableSet extends Set {\n find(filter) {\n const results = [];\n for (const item of this) {\n if (!filter(item)) {\n continue;\n }\n results.push(item);\n }\n return results;\n }\n findOne(filter) {\n for (const item of this) {\n if (filter(item)) {\n return item;\n }\n }\n return null;\n }\n getOrdered(callback) {\n return Array.from(this).sort((a, b) => callback(a) - callback(b));\n }\n}\n","const WrapletSetReadonlySymbol = Symbol(\"WrapletSetReadonly\");\nexport { WrapletSetReadonlySymbol };\n","import { WrapletSetSymbol } from \"../types/Set/WrapletSet\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nimport { WrapletSetReadonlySymbol } from \"../types/Set/WrapletSetReadonly\";\nexport class DefaultWrapletSet extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n [WrapletSetSymbol] = true;\n}\n","import { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport function isParentNode(node) {\n return (typeof node.querySelectorAll ===\n \"function\");\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!isWrapletSet(wraplets) || wraplets.size === 0) {\n return new DefaultWrapletSet();\n }\n return wraplets;\n}\nexport function removeWrapletFromNode(wraplet, node) {\n if (!node.wraplets) {\n return false;\n }\n return node.wraplets.delete(wraplet);\n}\nexport function addWrapletToNode(wraplet, node) {\n if (!node.wraplets) {\n node.wraplets = new DefaultWrapletSet();\n }\n node.wraplets.add(wraplet);\n}\nexport function actOnNodesRecursively(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursively(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursively(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","const ChildrenManagerSymbol = Symbol(\"ChildrenManager\");\nexport { ChildrenManagerSymbol };\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, ChildrenTooManyFoundError, ChildrenAreAlreadyDestroyedError, InternalLogicError, } from \"./errors\";\nimport { getWrapletsFromNode, isParentNode } from \"./utils\";\nimport { ChildrenManagerSymbol, } from \"./types/ChildrenManager\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nimport { DefaultWrapletSet } from \"./Set/DefaultWrapletSet\";\nexport class DefaultChildrenManager {\n node;\n [ChildrenManagerSymbol] = true;\n isDestroyed = false;\n isGettingDestroyed = false;\n isInitialized = false;\n map;\n instantiatedChildren;\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, initOptions = {}) {\n this.node = node;\n this.map = this.fillMapWithDefaults(map);\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate child listeners) that needs access to the children manager,\n * so the children manager has to exist already.\n */\n init() {\n const children = this.instantiateChildren();\n this.instantiatedChildren = this.wrapChildren(children);\n this.isInitialized = true;\n }\n instantiateChildren() {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!isParentNode(this.node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, this.node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, this.node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren();\n }\n findExistingWraplet(id, childElement) {\n // If a child doesn't have instantiated wraplets yet, then return null.\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = getWrapletsFromNode(childElement);\n // Handle multiple.\n if (this.map[id][\"multiple\"]) {\n if (!isWrapletSet(existingChild)) {\n throw new InternalLogicError(\"Internal logic error. Expected a WrapletSet.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n throw new InternalLogicError(\"Internal logic error. Multiple instances of the same child found on a single node.\");\n }\n // Handle single.\n return existingChild;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = this.findChildren(selector, node);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new ChildrenTooManyFoundError(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args;\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return new DefaultWrapletSet();\n }\n // Find children elements based on the map.\n const childElements = this.findChildren(selector, node);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : new DefaultWrapletSet();\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n items.add(wraplet);\n }\n return items;\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = ((wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n });\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method removes from nodes references to this wraplet and its children recursively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new ChildrenAreAlreadyDestroyedError(\"Children are already destroyed.\");\n }\n this.isGettingDestroyed = true;\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n this.destroyChildren();\n this.isGettingDestroyed = false;\n this.isDestroyed = true;\n }\n findChildren(selector, node) {\n const defaultSelectorCallback = (selector, node) => {\n return Array.from(node.querySelectorAll(selector));\n };\n // Find children elements based on the map.\n return typeof selector === \"string\"\n ? defaultSelectorCallback(selector, node)\n : selector(node);\n }\n fillMapWithDefaults(map) {\n const newMap = {};\n for (const id in map) {\n newMap[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n return newMap;\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (isWrapletSet(this.instantiatedChildren[id])) {\n if (!this.instantiatedChildren[id].delete(wraplet)) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n return;\n }\n if (this.map[id].required && !this.isGettingDestroyed) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n if (this.instantiatedChildren[id] === null) {\n throw new InternalLogicError(\"Internal logic error. Destroyed child couldn't be removed because it's already null.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n return [...a].filter((x) => b.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n destroyChildren() {\n for (const [key, child] of Object.entries(this.children)) {\n if (!child || !this.map[key][\"destructible\"]) {\n continue;\n }\n if (isWrapletSet(child)) {\n for (const item of child) {\n item.destroy();\n }\n }\n else {\n child.destroy();\n }\n }\n }\n}\n","import { is } from \"./Utils\";\nconst WrapletSymbol = Symbol(\"Wraplet\");\nexport { WrapletSymbol };\nexport function isWraplet(object) {\n return is(object, WrapletSymbol);\n}\n","import { is } from \"./Utils\";\nconst GroupableSymbol = Symbol(\"Groupable\");\nexport { GroupableSymbol };\n/* istanbul ignore next */\nexport function isGroupable(object) {\n return is(object, GroupableSymbol);\n}\nconst defaultGroupableAttribute = \"data-js-wraplet-groupable\";\nexport { defaultGroupableAttribute };\n","const NodeTreeParentSymbol = Symbol(\"NodeTreeParent\");\nexport { NodeTreeParentSymbol };\n/* istanbul ignore next */\nexport function isNodeTreeParent(object) {\n return (object[NodeTreeParentSymbol] ===\n true);\n}\n","import { WrapletSymbol } from \"./types/Wraplet\";\nimport { DefaultChildrenManager } from \"./DefaultChildrenManager\";\nimport { defaultGroupableAttribute, GroupableSymbol, } from \"./types/Groupable\";\nimport { NodeTreeParentSymbol } from \"./types/NodeTreeParent\";\nimport { addWrapletToNode, removeWrapletFromNode } from \"./utils\";\nimport { isWrapletSet } from \"./types/Set/WrapletSet\";\nexport class AbstractWraplet {\n node;\n [WrapletSymbol] = true;\n [GroupableSymbol] = true;\n [NodeTreeParentSymbol] = true;\n childrenManager;\n groupsExtractor = (node) => {\n if (node instanceof Element) {\n const groupsString = node.getAttribute(defaultGroupableAttribute);\n if (groupsString) {\n return groupsString.split(\",\");\n }\n }\n return [];\n };\n destroyListeners = [];\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n constructor(node, initOptions = {}) {\n this.node = node;\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.childrenManager = new DefaultChildrenManager(node, map, initOptions);\n this.initialize();\n }\n getNodeTreeChildren() {\n const children = [];\n for (const child of Object.values(this.children)) {\n if (isWrapletSet(child)) {\n for (const item of child) {\n children.push(item);\n }\n }\n else {\n children.push(child);\n }\n }\n // Return only descendants.\n return children.filter((child) => {\n let result = false;\n child.accessNode((childsNode) => {\n result = this.node.contains(childsNode);\n });\n return result;\n });\n }\n setGroupsExtractor(callback) {\n this.groupsExtractor = callback;\n }\n getGroups() {\n return this.groupsExtractor(this.node);\n }\n get children() {\n return this.childrenManager.children;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n destroy() {\n for (const listener of this.destroyListeners) {\n listener(this);\n }\n this.destroyListeners.length = 0;\n removeWrapletFromNode(this, this.node);\n this.childrenManager.destroy();\n }\n isDestroyed(completely = false) {\n return completely\n ? this.childrenManager.isDestroyed\n : this.childrenManager.isGettingDestroyed ||\n this.childrenManager.isDestroyed;\n }\n get isInitialized() {\n return this.childrenManager.isInitialized;\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.childrenManager.init();\n addWrapletToNode(this, this.node);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.childrenManager.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, attribute, additional_args = []) {\n if (this === AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n if (node instanceof Element && node.hasAttribute(attribute)) {\n result.push(new this(node, ...additional_args));\n }\n const foundElements = node.querySelectorAll(`[${attribute}]`);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { WrapletSetReadonlySymbol, } from \"../types/Set/WrapletSetReadonly\";\nimport { DefaultSearchableSet } from \"./DefaultSearchableSet\";\nexport class DefaultWrapletSetReadonly extends DefaultSearchableSet {\n [WrapletSetReadonlySymbol] = true;\n}\n"],"names":["MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","ChildrenTooManyFoundError","ChildrenAreAlreadyDestroyedError","InternalLogicError","object","symbol","WrapletSetSymbol","Symbol","isWrapletSet","DefaultSearchableSet","Set","find","filter","results","item","this","push","findOne","getOrdered","callback","Array","from","sort","a","b","WrapletSetReadonlySymbol","DefaultWrapletSet","getWrapletsFromNode","node","wraplets","size","actOnNodesRecursively","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","ChildrenManagerSymbol","DefaultChildrenManager","isDestroyed","isGettingDestroyed","isInitialized","map","instantiatedChildren","destroyChildListeners","instantiateChildListeners","listeners","constructor","initOptions","fillMapWithDefaults","processInitOptions","init","instantiateChildren","wrapChildren","querySelectorAll","Object","keys","length","id","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","findChildren","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","Class","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","add","addDestroyChildListener","addInstantiateChildListener","addDestroyListener","removeChild","eventName","options","removeEventListener","destroyChildren","defaultSelectorCallback","newMap","addDefaultsToChildDefinition","definition","destructible","addEventListener","uninitializedChildren","delete","required","x","has","isRequired","elements","Proxy","get","target","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","key","entries","WrapletSymbol","isWraplet","GroupableSymbol","NodeTreeParentSymbol","AbstractWraplet","childrenManager","groupsExtractor","Element","groupsString","getAttribute","split","destroyListeners","__debugNodeAccessors","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","getNodeTreeChildren","values","result","accessNode","childsNode","contains","setGroupsExtractor","getGroups","completely","isChildInstance","actualUnknownId","onlyId","createWraplets","attribute","additional_args","hasAttribute","foundElements","element","DefaultWrapletSetReadonly"],"sourceRoot":""}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Wraplet } from "./Wraplet";
|
|
2
|
+
export type SelectorCallback<N extends ParentNode = ParentNode> = (node: N) => Node[];
|
|
2
3
|
export type WrapletChildDefinition = {
|
|
3
|
-
selector?: string;
|
|
4
|
+
selector?: string | SelectorCallback;
|
|
4
5
|
Class: {
|
|
5
6
|
new (...args: any[]): Wraplet<any>;
|
|
6
7
|
};
|