wraplet 0.12.0 → 0.13.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/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/storage.cjs +2 -0
- package/dist/storage.cjs.map +1 -0
- package/dist/storage.js +2 -0
- package/dist/storage.js.map +1 -0
- package/dist/typescript/Storage/ElementStorage.d.ts +27 -0
- package/dist/{errors.d.ts → typescript/errors.d.ts} +6 -0
- package/dist/typescript/storage.d.ts +2 -0
- package/dist/typescript/types/Storage/Storage.d.ts +9 -0
- package/dist/typescript/types/Storage/StorageReadonly.d.ts +6 -0
- package/dist/typescript/types/WrapletChildDefinition.d.ts +11 -0
- package/package.json +36 -18
- package/dist/types/WrapletChildDefinition.d.ts +0 -11
- /package/dist/{AbstractWraplet.d.ts → typescript/AbstractWraplet.d.ts} +0 -0
- /package/dist/{Core.d.ts → typescript/Core.d.ts} +0 -0
- /package/dist/{DefaultWrapletManager.d.ts → typescript/DefaultWrapletManager.d.ts} +0 -0
- /package/dist/{getGlobalWrapletManager.d.ts → typescript/getGlobalWrapletManager.d.ts} +0 -0
- /package/dist/{index.d.ts → typescript/index.d.ts} +0 -0
- /package/dist/{types → typescript/types}/ChildInstance.d.ts +0 -0
- /package/dist/{types → typescript/types}/CoreInitOptions.d.ts +0 -0
- /package/dist/{types → typescript/types}/DestroyChildListener.d.ts +0 -0
- /package/dist/{types → typescript/types}/DestroyListener.d.ts +0 -0
- /package/dist/{types → typescript/types}/InstantiateChildListener.d.ts +0 -0
- /package/dist/{types → typescript/types}/Utils.d.ts +0 -0
- /package/dist/{types → typescript/types}/Wraplet.d.ts +0 -0
- /package/dist/{types → typescript/types}/WrapletChildren.d.ts +0 -0
- /package/dist/{types → typescript/types}/WrapletChildrenMap.d.ts +0 -0
- /package/dist/{types → typescript/types}/WrapletManager.d.ts +0 -0
- /package/dist/{types → typescript/types}/global.d.ts +0 -0
- /package/dist/{utils.d.ts → typescript/utils.d.ts} +0 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e={d:(t,i)=>{for(var r in i)e.o(i,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:i[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{AbstractWraplet:()=>c,Core:()=>h,destroyWrapletsRecursively:()=>d,getGlobalWrapletManager:()=>f,getWrapletsFromNode:()=>a,isWraplet:()=>o});class i extends Error{}class r extends Error{}class n extends Error{}class s extends Error{}function o(e){return"object"==typeof e&&null!==e&&"isWraplet"in e&&!0===e.isWraplet}function a(e){const t=e.wraplets;return Array.isArray(t)?t:[]}function l(e,t){t(e);const i=e.childNodes;for(const e of i)l(e,t)}function d(e){l(e,e=>{const t=a(e);for(const e of t)e.destroy()})}class h{node;map;wraplet;initOptions;isDestroyed=!1;isInitialized=!1;instantiatedChildren;__debugNodeAccessors=[];destroyListeners=[];destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(e,t,i,r={}){this.node=e,this.map=t,this.wraplet=i,this.initOptions=r;for(const e in t)t[e]=this.addDefaultsToChildDefinition(t[e]);this.processInitOptions(r),this.instantiatedChildren={}}init(){const e=this.instantiateChildren(this.node);this.instantiatedChildren=this.wrapChildren(e),this.node.wraplets||(this.node.wraplets=[]),this.node.wraplets.push(this.wraplet),this.isInitialized=!0}instantiateChildren(e){const t=this.instantiatedChildren;if(!this.isParentNode(e)){if(Object.keys(this.map).length>0)throw new r("If the node provided cannot have children, the children map should be empty.");return t}for(const i in this.map){const r=this.map[i],n=r.multiple;this.validateMapItem(i,r),t[i]=n?this.instantiateMultipleWrapletsChild(r,e,i):this.instantiateSingleWrapletChild(r,e,i)}return t}syncChildren(){this.instantiatedChildren=this.instantiateChildren(this.node)}isCorrectSingleWrapletInstanceGuard(e,t){return e instanceof this.map[t].Class}findExistingWraplet(e,t){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[e])return null;const i=this.instantiatedChildren[e],r=t.wraplets||[];if(this.map[e].multiple){if(!Array.isArray(i))throw new Error("Internal logic error. Expected an array.");const e=this.intersect(i,r);if(0===e.length)return null;if(1===e.length)return e[0];if(e.length>1)throw new Error("Internal logic error. Multiple wraplets found for the same child.")}else if(null!==this.instantiatedChildren[e])return i;return null}instantiateSingleWrapletChild(e,t,i){if(!e.selector)return null;const r=e.selector,n=t.querySelectorAll(r);if(this.validateElements(i,n,e),0===n.length)return null;if(n.length>1)throw new Error(`${this.constructor.name}: More than one element was found for the "${i}" child. Selector used: "${r}".`);const s=n[0];return this.instantiateWrapletItem(i,e,s)}instantiateWrapletItem(e,t,i){const r=this.findExistingWraplet(e,i);if(r)return r;const n=t.Class,s=t.args||[],o=this.createIndividualWraplet(n,i,s);this.prepareIndividualWraplet(e,o);for(const t of this.instantiateChildListeners)t(o,e);return o}instantiateMultipleWrapletsChild(e,t,i){const r=e.selector;if(!r)return[];const n=t.querySelectorAll(r);this.validateElements(i,n,e);const s=this.instantiatedChildren&&this.instantiatedChildren[i]?this.instantiatedChildren[i]:[];for(const t of n){if(this.findExistingWraplet(i,t))continue;const r=this.instantiateWrapletItem(i,e,t);if(r){if(!this.isCorrectSingleWrapletInstanceGuard(r,i))throw new Error(`${this.constructor.name}: The "${i}" child is not an array of the expected type.`);s.push(r)}}return s}accessNode(e){this.__debugNodeAccessors.push(e),e(this.node)}addDestroyListener(e){this.destroyListeners.push(e)}addDestroyChildListener(e){this.destroyChildListeners.push(e)}addInstantiateChildListener(e){this.instantiateChildListeners.push(e)}createIndividualWraplet(e,t,i=[]){return new e(...[t,...i])}prepareIndividualWraplet(e,t){t.addDestroyListener(t=>{this.removeChild(t,e);for(const i of this.destroyChildListeners)i(t,e)})}executeOnChildren(e,t,i){for(const r of Object.entries(e)){const e=r[0],n=r[1];if(this.map[e].destructible)if(Array.isArray(n)){const r=n.slice(0);for(const n of r){if(!o(n))throw new Error("Internal logic error. Item is not a wraplet.");if(!this.wrapletHasMethodGuard(n,t))throw new Error(`Internal logic error. Action "${String(t)}" is not defined for the child "${e}".`);i?n[t](i):n[t]()}}else if(o(n)){if(!this.wrapletHasMethodGuard(n,t))throw new Error(`Internal logic error. Action "${String(t)}" is not defined for the child "${e}".`);i?n[t](i):n[t]()}}}destroy(){if(this.isDestroyed)throw new Error("Wraplet is already destroyed.");for(const e of this.listeners){const t=e.node,i=e.eventName,r=e.callback,n=e.options;t.removeEventListener(i,r,n)}for(const e of this.destroyListeners)e(this.wraplet);this.destroyListeners.length=0,this.removeWrapletFromNode(this.wraplet,this.node),this.executeOnChildren(this.children,"destroy"),this.isDestroyed=!0}removeWrapletFromNode(e,t){const i=t.wraplets?.findIndex(t=>t===e);void 0!==i&&i>-1&&t.wraplets?.splice(i,1)}addDefaultsToChildDefinition(e){return{args:[],destructible:!0,...e}}wrapletHasMethodGuard(e,t){return"function"==typeof e[t]}isParentNode(e){return"function"==typeof e.querySelectorAll}childTypeGuard(e,t){const i=this.map,r=i[t].Class,n=i[t].required;return i[t].multiple?!!Array.isArray(e)&&(!n||e.every(e=>e instanceof r)):n?e instanceof r:e instanceof r||null===e}addEventListener(e,t,i,r){this.listeners.push({node:e,eventName:t,callback:i,options:r}),e.addEventListener(t,i,r)}get children(){if(!this.isInitialized)throw new s("Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.");return this.instantiatedChildren}get uninitializedChildren(){if(this.isInitialized)throw new s("Wraplet is already initialized. Fetch children with 'children' property instead.");return this.instantiatedChildren}removeChild(e,t){if(Array.isArray(this.instantiatedChildren[t])){const i=this.instantiatedChildren[t].findIndex(t=>t===e);if(-1===i)throw new Error("Internal logic error. Destroyed child couldn't be removed because it's not among the children.");return void this.instantiatedChildren[t].splice(i,1)}if(this.map[t].required)throw new n("Required child has been destroyed.");this.instantiatedChildren[t]=null}intersect(e,t){const i=new Set(t);return[...new Set(e)].filter(e=>i.has(e))}validateMapItem(e,t){const i=t.selector,n=t.required;if(!i&&n)throw new r(`${this.constructor.name}: Child "${e}" cannot at the same be required and have no selector.`)}validateElements(e,t,r){if(0===t.length&&r.required)throw new i(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${r.selector}".`)}wrapChildren(e){return new Proxy(e,{get:function(e,t){if(!(t in e))throw new Error("Child has not been found.");function i(e){return e.isDestroyed}const r=e[t];if(Array.isArray(r)){if(r.find(i))throw new Error("Core error: One of the children in the array has been destroyed but not removed");return e[t]}if(null!==r&&i(r))throw new Error("The child has been destroyed");return e[t]}})}defaultInitOptions(){return{instantiateChildListeners:[],destroyChildListeners:[]}}processInitOptions(e){const t=Object.assign(this.defaultInitOptions(),e);t.mapAlterCallback&&t.mapAlterCallback(this.map);for(const e of t.instantiateChildListeners)this.instantiateChildListeners.push(e);for(const e of t.destroyChildListeners)this.destroyChildListeners.push(e)}}class c{isWraplet=!0;core;constructor(e,t={}){if(!e)throw new Error("Node is required to create a wraplet.");const i=this.defineChildrenMap();t.instantiateChildListeners=[this.onChildInstantiated.bind(this)],t.destroyChildListeners=[this.onChildDestroyed.bind(this)],this.core=new h(e,i,this,t),this.initialize()}get node(){return this.core.node}get children(){return this.core.children}accessNode(e){this.core.accessNode(e)}destroy(){this.core.destroy()}get isDestroyed(){return this.core.isDestroyed}get isInitialized(){return this.core.isInitialized}addDestroyListener(e){this.core.addDestroyListener(e)}onChildDestroyed(e,t){}initialize(){this.core.init()}onChildInstantiated(e,t){}isChildInstance(e,t,i=null){return t===(i||t)&&e instanceof this.core.map[t].Class}static createWraplets(e,t,i=[]){if(this instanceof c)throw new Error("You cannot instantiate an abstract class.");let r=e.parentNode,n=null;r||(e instanceof Document?r=e:(n=document.createElement("div"),n.appendChild(e),r=n));const s=[],o=r.querySelectorAll(t);n&&n.removeChild(e);for(const e of o)s.push(new this(e,...i));return s}}class u{initializers=[];addWrapletInitializer(e){this.initializers.push(e)}initializeNodeTree(e){for(const t of this.initializers)t(e)}destroyNodeTree(e){d(e)}}let p=null;function f(){return p||(p=new u),p}var y=exports;for(var C in t)y[C]=t[C];t.__esModule&&Object.defineProperty(y,"__esModule",{value:!0});
|
|
2
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","mappings":"AACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,+JCLhD,MAAMC,UAAkCC,OAExC,MAAMC,UAAiBD,OAEvB,MAAME,UAAoCF,OAE1C,MAAMG,UAAqCH,OCN3C,SAASI,EAAUb,GACtB,MAAuB,iBAARA,GACH,OAARA,GACA,cAAeA,IACG,IAAlBA,EAAIa,SACZ,CACO,SAASC,EAAoBC,GAChC,MAAMC,EAAWD,EAAKC,SACtB,OAAKC,MAAMC,QAAQF,GAGZA,EAFI,EAGf,CACO,SAASG,EAAsBJ,EAAMK,GACxCA,EAASL,GACT,MAAMM,EAAWN,EAAKO,WACtB,IAAK,MAAMC,KAASF,EAChBF,EAAsBI,EAAOH,EAErC,CACO,SAASI,EAA2BT,GACvCI,EAAsBJ,EAAOA,IACzB,MAAMC,EAAWF,EAAoBC,GACrC,IAAK,MAAMU,KAA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AaE,SAASC,cAAc,OACpCH,EAAWI,YAAY9H,GACvBwH,EAAaE,IAGrB,MAAMK,EAAS,GACTC,EAAgBR,EAAWnE,iBAAiBF,GAC9CuE,GACAA,EAAWtD,YAAYpE,GAE3B,IAAK,MAAMiI,KAAWD,EAClBD,EAAOhG,KAAK,IAAIP,KAAKyG,KAAYV,IAErC,OAAOQ,CACX,EClGW,MAAMG,EACjBC,aAAe,GACf,qBAAAC,CAAsB/H,GAClBmB,KAAK2G,aAAapG,KAAK1B,EAC3B,CACA,kBAAAgI,CAAmBrI,GACf,IAAK,MAAMsI,KAAe9G,KAAK2G,aAC3BG,EAAYtI,EAEpB,CACA,eAAAuI,CAAgBvI,GACZS,EAA2BT,EAC/B,ECZJ,IAAIwI,EAAuB,KACpB,SAASC,IAIZ,OAHKD,IACDA,EAAuB,IAAIN,GAExBM,CACX,C","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/Core.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/DefaultWrapletManager.ts","webpack://wraplet/./src/getGlobalWrapletManager.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class ValidationMissingError extends Error {\n}\nexport class InvalidOptionsError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\n","export function isWraplet(obj) {\n return (typeof obj === \"object\" &&\n obj !== null &&\n \"isWraplet\" in obj &&\n obj.isWraplet === true);\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!Array.isArray(wraplets)) {\n return [];\n }\n return wraplets;\n}\nexport function actOnNodesRecursevily(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursevily(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursevily(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, } from \"./errors\";\nimport { isWraplet } from \"./utils\";\nexport class Core {\n node;\n map;\n wraplet;\n initOptions;\n isDestroyed = false;\n isInitialized = false;\n instantiatedChildren;\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n destroyListeners = [];\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, wraplet, initOptions = {}) {\n this.node = node;\n this.map = map;\n this.wraplet = wraplet;\n this.initOptions = initOptions;\n for (const id in map) {\n map[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate child listeners) that needs access to the core, so core has to\n * exist already.\n */\n init() {\n const children = this.instantiateChildren(this.node);\n this.instantiatedChildren = this.wrapChildren(children);\n if (!this.node.wraplets) {\n this.node.wraplets = [];\n }\n this.node.wraplets.push(this.wraplet);\n this.isInitialized = true;\n }\n instantiateChildren(node) {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!this.isParentNode(node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren(this.node);\n }\n isCorrectSingleWrapletInstanceGuard(item, id) {\n return item instanceof this.map[id].Class;\n }\n findExistingWraplet(id, childElement) {\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = childElement.wraplets || [];\n if (this.map[id][\"multiple\"]) {\n if (!Array.isArray(existingChild)) {\n throw new Error(\"Internal logic error. Expected an array.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n else if (intersection.length > 1) {\n throw new Error(\"Internal logic error. Multiple wraplets found for the same child.\");\n }\n }\n else if (this.instantiatedChildren[id] !== null) {\n return existingChild;\n }\n return null;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new Error(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args || [];\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return [];\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : [];\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n if (!wraplet) {\n continue;\n }\n if (!this.isCorrectSingleWrapletInstanceGuard(wraplet, id)) {\n throw new Error(`${this.constructor.name}: The \"${id}\" child is not an array of the expected type.`);\n }\n items.push(wraplet);\n }\n return items;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args = []) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = (wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n };\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method allows executing the specified method on the wraplet and all its children.\n * The original wraplet and all children need to have this method implemented.\n */\n executeOnChildren(children, method, payload) {\n for (const childEntries of Object.entries(children)) {\n const name = childEntries[0];\n const child = childEntries[1];\n const map = this.map;\n if (!map[name].destructible) {\n continue;\n }\n if (Array.isArray(child)) {\n // We need to loop through the copy of the array because some items can be removed from\n // the original during the loop.\n const childArray = child.slice(0);\n for (const item of childArray) {\n if (!isWraplet(item)) {\n throw new Error(\"Internal logic error. Item is not a wraplet.\");\n }\n if (!this.wrapletHasMethodGuard(item, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n item[method](payload);\n }\n else {\n item[method]();\n }\n }\n }\n else if (isWraplet(child)) {\n if (!this.wrapletHasMethodGuard(child, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n child[method](payload);\n }\n else {\n child[method]();\n }\n }\n }\n }\n /**\n * This method removes from nodes references to this wraplet and its children recuresively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new Error(\"Wraplet is already destroyed.\");\n }\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n for (const listener of this.destroyListeners) {\n listener(this.wraplet);\n }\n this.destroyListeners.length = 0;\n this.removeWrapletFromNode(this.wraplet, this.node);\n this.executeOnChildren(this.children, \"destroy\");\n this.isDestroyed = true;\n }\n /**\n * Remove the wraplet from the list of wraplets.\n */\n removeWrapletFromNode(wraplet, node) {\n const index = node.wraplets?.findIndex((value) => {\n return value === wraplet;\n });\n if (index !== undefined && index > -1) {\n node.wraplets?.splice(index, 1);\n }\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n wrapletHasMethodGuard(wraplet, method) {\n return typeof wraplet[method] === \"function\";\n }\n isParentNode(node) {\n return typeof node.querySelectorAll === \"function\";\n }\n childTypeGuard(variable, id) {\n const map = this.map;\n const Class = map[id].Class;\n const isRequired = map[id].required;\n const isMultiple = map[id].multiple;\n if (isMultiple) {\n if (!Array.isArray(variable)) {\n return false;\n }\n if (isRequired) {\n return variable.every((value) => value instanceof Class);\n }\n return true;\n }\n if (isRequired) {\n return variable instanceof Class;\n }\n return variable instanceof Class || variable === null;\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (Array.isArray(this.instantiatedChildren[id])) {\n const index = this.instantiatedChildren[id].findIndex((value) => {\n return value === wraplet;\n });\n if (index === -1) {\n throw new Error(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n this.instantiatedChildren[id].splice(index, 1);\n return;\n }\n if (this.map[id].required) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n const setB = new Set(b);\n return [...new Set(a)].filter((x) => setB.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n function isDestroyed(wraplet) {\n return wraplet.isDestroyed;\n }\n const child = target[name];\n if (Array.isArray(child)) {\n const destroyed = child.find(isDestroyed);\n if (destroyed) {\n throw new Error(\"Core error: One of the children in the array has been destroyed but not removed\");\n }\n return target[name];\n }\n if (child !== null && isDestroyed(child)) {\n throw new Error(\"The child has been destroyed\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n}\n","import { Core } from \"./Core\";\nexport class AbstractWraplet {\n isWraplet = true;\n core;\n constructor(node, initOptions = {}) {\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.core = new Core(node, map, this, initOptions);\n this.initialize();\n }\n get node() {\n return this.core.node;\n }\n get children() {\n return this.core.children;\n }\n accessNode(callback) {\n this.core.accessNode(callback);\n }\n destroy() {\n this.core.destroy();\n }\n get isDestroyed() {\n return this.core.isDestroyed;\n }\n get isInitialized() {\n return this.core.isInitialized;\n }\n addDestroyListener(callback) {\n this.core.addDestroyListener(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.core.init();\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.core.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this instanceof AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nexport default class DefaultWrapletManager {\n initializers = [];\n addWrapletInitializer(callback) {\n this.initializers.push(callback);\n }\n initializeNodeTree(node) {\n for (const initializer of this.initializers) {\n initializer(node);\n }\n }\n destroyNodeTree(node) {\n destroyWrapletsRecursively(node);\n }\n}\n","import DefaultWrapletManager from \"./DefaultWrapletManager\";\nlet globalWrapletManager = null;\nexport function getGlobalWrapletManager() {\n if (!globalWrapletManager) {\n globalWrapletManager = new DefaultWrapletManager();\n }\n return globalWrapletManager;\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","isWraplet","getWrapletsFromNode","node","wraplets","Array","isArray","actOnNodesRecursevily","callback","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","Core","map","initOptions","isDestroyed","isInitialized","instantiatedChildren","__debugNodeAccessors","destroyListeners","destroyChildListeners","instantiateChildListeners","listeners","constructor","this","id","addDefaultsToChildDefinition","processInitOptions","init","instantiateChildren","wrapChildren","push","isParentNode","keys","length","item","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","isCorrectSingleWrapletInstanceGuard","Class","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","querySelectorAll","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","accessNode","addDestroyListener","addDestroyChildListener","addInstantiateChildListener","removeChild","executeOnChildren","method","payload","childEntries","entries","destructible","childArray","slice","wrapletHasMethodGuard","String","eventName","options","removeEventListener","removeWrapletFromNode","index","findIndex","splice","childTypeGuard","variable","isRequired","required","every","addEventListener","uninitializedChildren","a","b","setB","Set","filter","x","has","elements","Proxy","target","find","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","AbstractWraplet","core","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","result","foundElements","element","DefaultWrapletManager","initializers","addWrapletInitializer","initializeNodeTree","initializer","destroyNodeTree","globalWrapletManager","getGlobalWrapletManager"],"sourceRoot":""}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
class t extends Error{}class e extends Error{}class i extends Error{}class r extends Error{}function n(t){return"object"==typeof t&&null!==t&&"isWraplet"in t&&!0===t.isWraplet}function s(t){const e=t.wraplets;return Array.isArray(e)?e:[]}function o(t,e){e(t);const i=t.childNodes;for(const t of i)o(t,e)}function a(t){o(t,t=>{const e=s(t);for(const t of e)t.destroy()})}class l{node;map;wraplet;initOptions;isDestroyed=!1;isInitialized=!1;instantiatedChildren;__debugNodeAccessors=[];destroyListeners=[];destroyChildListeners=[];instantiateChildListeners=[];listeners=[];constructor(t,e,i,r={}){this.node=t,this.map=e,this.wraplet=i,this.initOptions=r;for(const t in e)e[t]=this.addDefaultsToChildDefinition(e[t]);this.processInitOptions(r),this.instantiatedChildren={}}init(){const t=this.instantiateChildren(this.node);this.instantiatedChildren=this.wrapChildren(t),this.node.wraplets||(this.node.wraplets=[]),this.node.wraplets.push(this.wraplet),this.isInitialized=!0}instantiateChildren(t){const i=this.instantiatedChildren;if(!this.isParentNode(t)){if(Object.keys(this.map).length>0)throw new e("If the node provided cannot have children, the children map should be empty.");return i}for(const e in this.map){const r=this.map[e],n=r.multiple;this.validateMapItem(e,r),i[e]=n?this.instantiateMultipleWrapletsChild(r,t,e):this.instantiateSingleWrapletChild(r,t,e)}return i}syncChildren(){this.instantiatedChildren=this.instantiateChildren(this.node)}isCorrectSingleWrapletInstanceGuard(t,e){return t instanceof this.map[e].Class}findExistingWraplet(t,e){if(void 0===this.instantiatedChildren||!this.instantiatedChildren[t])return null;const i=this.instantiatedChildren[t],r=e.wraplets||[];if(this.map[t].multiple){if(!Array.isArray(i))throw new Error("Internal logic error. Expected an array.");const t=this.intersect(i,r);if(0===t.length)return null;if(1===t.length)return t[0];if(t.length>1)throw new Error("Internal logic error. Multiple wraplets found for the same child.")}else if(null!==this.instantiatedChildren[t])return i;return null}instantiateSingleWrapletChild(t,e,i){if(!t.selector)return null;const r=t.selector,n=e.querySelectorAll(r);if(this.validateElements(i,n,t),0===n.length)return null;if(n.length>1)throw new Error(`${this.constructor.name}: More than one element was found for the "${i}" child. Selector used: "${r}".`);const s=n[0];return this.instantiateWrapletItem(i,t,s)}instantiateWrapletItem(t,e,i){const r=this.findExistingWraplet(t,i);if(r)return r;const n=e.Class,s=e.args||[],o=this.createIndividualWraplet(n,i,s);this.prepareIndividualWraplet(t,o);for(const e of this.instantiateChildListeners)e(o,t);return o}instantiateMultipleWrapletsChild(t,e,i){const r=t.selector;if(!r)return[];const n=e.querySelectorAll(r);this.validateElements(i,n,t);const s=this.instantiatedChildren&&this.instantiatedChildren[i]?this.instantiatedChildren[i]:[];for(const e of n){if(this.findExistingWraplet(i,e))continue;const r=this.instantiateWrapletItem(i,t,e);if(r){if(!this.isCorrectSingleWrapletInstanceGuard(r,i))throw new Error(`${this.constructor.name}: The "${i}" child is not an array of the expected type.`);s.push(r)}}return s}accessNode(t){this.__debugNodeAccessors.push(t),t(this.node)}addDestroyListener(t){this.destroyListeners.push(t)}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)})}executeOnChildren(t,e,i){for(const r of Object.entries(t)){const t=r[0],s=r[1];if(this.map[t].destructible)if(Array.isArray(s)){const r=s.slice(0);for(const s of r){if(!n(s))throw new Error("Internal logic error. Item is not a wraplet.");if(!this.wrapletHasMethodGuard(s,e))throw new Error(`Internal logic error. Action "${String(e)}" is not defined for the child "${t}".`);i?s[e](i):s[e]()}}else if(n(s)){if(!this.wrapletHasMethodGuard(s,e))throw new Error(`Internal logic error. Action "${String(e)}" is not defined for the child "${t}".`);i?s[e](i):s[e]()}}}destroy(){if(this.isDestroyed)throw new Error("Wraplet is already destroyed.");for(const t of this.listeners){const e=t.node,i=t.eventName,r=t.callback,n=t.options;e.removeEventListener(i,r,n)}for(const t of this.destroyListeners)t(this.wraplet);this.destroyListeners.length=0,this.removeWrapletFromNode(this.wraplet,this.node),this.executeOnChildren(this.children,"destroy"),this.isDestroyed=!0}removeWrapletFromNode(t,e){const i=e.wraplets?.findIndex(e=>e===t);void 0!==i&&i>-1&&e.wraplets?.splice(i,1)}addDefaultsToChildDefinition(t){return{args:[],destructible:!0,...t}}wrapletHasMethodGuard(t,e){return"function"==typeof t[e]}isParentNode(t){return"function"==typeof t.querySelectorAll}childTypeGuard(t,e){const i=this.map,r=i[e].Class,n=i[e].required;return i[e].multiple?!!Array.isArray(t)&&(!n||t.every(t=>t instanceof r)):n?t instanceof r:t instanceof r||null===t}addEventListener(t,e,i,r){this.listeners.push({node:t,eventName:e,callback:i,options:r}),t.addEventListener(e,i,r)}get children(){if(!this.isInitialized)throw new r("Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.");return this.instantiatedChildren}get uninitializedChildren(){if(this.isInitialized)throw new r("Wraplet is already initialized. Fetch children with 'children' property instead.");return this.instantiatedChildren}removeChild(t,e){if(Array.isArray(this.instantiatedChildren[e])){const i=this.instantiatedChildren[e].findIndex(e=>e===t);if(-1===i)throw new Error("Internal logic error. Destroyed child couldn't be removed because it's not among the children.");return void this.instantiatedChildren[e].splice(i,1)}if(this.map[e].required)throw new i("Required child has been destroyed.");this.instantiatedChildren[e]=null}intersect(t,e){const i=new Set(e);return[...new Set(t)].filter(t=>i.has(t))}validateMapItem(t,i){const r=i.selector,n=i.required;if(!r&&n)throw new e(`${this.constructor.name}: Child "${t}" cannot at the same be required and have no selector.`)}validateElements(e,i,r){if(0===i.length&&r.required)throw new t(`${this.constructor.name}: Couldn't find a node for the wraplet "${e}". Selector used: "${r.selector}".`)}wrapChildren(t){return new Proxy(t,{get:function(t,e){if(!(e in t))throw new Error("Child has not been found.");function i(t){return t.isDestroyed}const r=t[e];if(Array.isArray(r)){if(r.find(i))throw new Error("Core error: One of the children in the array has been destroyed but not removed");return t[e]}if(null!==r&&i(r))throw new Error("The child has been destroyed");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)}}class d{isWraplet=!0;core;constructor(t,e={}){if(!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.core=new l(t,i,this,e),this.initialize()}get node(){return this.core.node}get children(){return this.core.children}accessNode(t){this.core.accessNode(t)}destroy(){this.core.destroy()}get isDestroyed(){return this.core.isDestroyed}get isInitialized(){return this.core.isInitialized}addDestroyListener(t){this.core.addDestroyListener(t)}onChildDestroyed(t,e){}initialize(){this.core.init()}onChildInstantiated(t,e){}isChildInstance(t,e,i=null){return e===(i||e)&&t instanceof this.core.map[e].Class}static createWraplets(t,e,i=[]){if(this instanceof d)throw new Error("You cannot instantiate an abstract class.");let r=t.parentNode,n=null;r||(t instanceof Document?r=t:(n=document.createElement("div"),n.appendChild(t),r=n));const s=[],o=r.querySelectorAll(e);n&&n.removeChild(t);for(const t of o)s.push(new this(t,...i));return s}}class h{initializers=[];addWrapletInitializer(t){this.initializers.push(t)}initializeNodeTree(t){for(const e of this.initializers)e(t)}destroyNodeTree(t){a(t)}}let c=null;function u(){return c||(c=new h),c}export{d as AbstractWraplet,l as Core,a as destroyWrapletsRecursively,u as getGlobalWrapletManager,s as getWrapletsFromNode,n as isWraplet};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAiB,QAAID,IAErBD,EAAc,QAAIC,GACnB,CATD,CASGK,KAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EA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,eAAAuI,CAAgBvI,GACZS,EAA2BT,EAC/B,ECZJ,IAAIwI,EAAuB,KACpB,SAASC,IAIZ,OAHKD,IACDA,EAAuB,IAAIN,GAExBM,CACX,C","sources":["webpack://wraplet/webpack/universalModuleDefinition","webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/Core.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/DefaultWrapletManager.ts","webpack://wraplet/./src/getGlobalWrapletManager.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"wraplet\"] = factory();\n\telse\n\t\troot[\"wraplet\"] = factory();\n})(self, () => {\nreturn ","// 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}\n","export function isWraplet(obj) {\n return (typeof obj === \"object\" &&\n obj !== null &&\n \"isWraplet\" in obj &&\n obj.isWraplet === true);\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!Array.isArray(wraplets)) {\n return [];\n }\n return wraplets;\n}\nexport function actOnNodesRecursevily(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursevily(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursevily(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, } from \"./errors\";\nimport { isWraplet } from \"./utils\";\nexport class Core {\n node;\n map;\n wraplet;\n initOptions;\n isDestroyed = false;\n isInitialized = false;\n instantiatedChildren;\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n destroyListeners = [];\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, wraplet, initOptions = {}) {\n this.node = node;\n this.map = map;\n this.wraplet = wraplet;\n this.initOptions = initOptions;\n for (const id in map) {\n map[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate child listeners) that needs access to the core, so core has to\n * exist already.\n */\n init() {\n const children = this.instantiateChildren(this.node);\n this.instantiatedChildren = this.wrapChildren(children);\n if (!this.node.wraplets) {\n this.node.wraplets = [];\n }\n this.node.wraplets.push(this.wraplet);\n this.isInitialized = true;\n }\n instantiateChildren(node) {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!this.isParentNode(node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren(this.node);\n }\n isCorrectSingleWrapletInstanceGuard(item, id) {\n return item instanceof this.map[id].Class;\n }\n findExistingWraplet(id, childElement) {\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = childElement.wraplets || [];\n if (this.map[id][\"multiple\"]) {\n if (!Array.isArray(existingChild)) {\n throw new Error(\"Internal logic error. Expected an array.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n else if (intersection.length > 1) {\n throw new Error(\"Internal logic error. Multiple wraplets found for the same child.\");\n }\n }\n else if (this.instantiatedChildren[id] !== null) {\n return existingChild;\n }\n return null;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new Error(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args || [];\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return [];\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : [];\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n if (!wraplet) {\n continue;\n }\n if (!this.isCorrectSingleWrapletInstanceGuard(wraplet, id)) {\n throw new Error(`${this.constructor.name}: The \"${id}\" child is not an array of the expected type.`);\n }\n items.push(wraplet);\n }\n return items;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args = []) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = (wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n };\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method allows executing the specified method on the wraplet and all its children.\n * The original wraplet and all children need to have this method implemented.\n */\n executeOnChildren(children, method, payload) {\n for (const childEntries of Object.entries(children)) {\n const name = childEntries[0];\n const child = childEntries[1];\n const map = this.map;\n if (!map[name].destructible) {\n continue;\n }\n if (Array.isArray(child)) {\n // We need to loop through the copy of the array because some items can be removed from\n // the original during the loop.\n const childArray = child.slice(0);\n for (const item of childArray) {\n if (!isWraplet(item)) {\n throw new Error(\"Internal logic error. Item is not a wraplet.\");\n }\n if (!this.wrapletHasMethodGuard(item, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n item[method](payload);\n }\n else {\n item[method]();\n }\n }\n }\n else if (isWraplet(child)) {\n if (!this.wrapletHasMethodGuard(child, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n child[method](payload);\n }\n else {\n child[method]();\n }\n }\n }\n }\n /**\n * This method removes from nodes references to this wraplet and its children recuresively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new Error(\"Wraplet is already destroyed.\");\n }\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n for (const listener of this.destroyListeners) {\n listener(this.wraplet);\n }\n this.destroyListeners.length = 0;\n this.removeWrapletFromNode(this.wraplet, this.node);\n this.executeOnChildren(this.children, \"destroy\");\n this.isDestroyed = true;\n }\n /**\n * Remove the wraplet from the list of wraplets.\n */\n removeWrapletFromNode(wraplet, node) {\n const index = node.wraplets?.findIndex((value) => {\n return value === wraplet;\n });\n if (index !== undefined && index > -1) {\n node.wraplets?.splice(index, 1);\n }\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n wrapletHasMethodGuard(wraplet, method) {\n return typeof wraplet[method] === \"function\";\n }\n isParentNode(node) {\n return typeof node.querySelectorAll === \"function\";\n }\n childTypeGuard(variable, id) {\n const map = this.map;\n const Class = map[id].Class;\n const isRequired = map[id].required;\n const isMultiple = map[id].multiple;\n if (isMultiple) {\n if (!Array.isArray(variable)) {\n return false;\n }\n if (isRequired) {\n return variable.every((value) => value instanceof Class);\n }\n return true;\n }\n if (isRequired) {\n return variable instanceof Class;\n }\n return variable instanceof Class || variable === null;\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (Array.isArray(this.instantiatedChildren[id])) {\n const index = this.instantiatedChildren[id].findIndex((value) => {\n return value === wraplet;\n });\n if (index === -1) {\n throw new Error(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n this.instantiatedChildren[id].splice(index, 1);\n return;\n }\n if (this.map[id].required) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n const setB = new Set(b);\n return [...new Set(a)].filter((x) => setB.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n function isDestroyed(wraplet) {\n return wraplet.isDestroyed;\n }\n const child = target[name];\n if (Array.isArray(child)) {\n const destroyed = child.find(isDestroyed);\n if (destroyed) {\n throw new Error(\"Core error: One of the children in the array has been destroyed but not removed\");\n }\n return target[name];\n }\n if (child !== null && isDestroyed(child)) {\n throw new Error(\"The child has been destroyed\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n}\n","import { Core } from \"./Core\";\nexport class AbstractWraplet {\n isWraplet = true;\n core;\n constructor(node, initOptions = {}) {\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.core = new Core(node, map, this, initOptions);\n this.initialize();\n }\n get node() {\n return this.core.node;\n }\n get children() {\n return this.core.children;\n }\n accessNode(callback) {\n this.core.accessNode(callback);\n }\n destroy() {\n this.core.destroy();\n }\n get isDestroyed() {\n return this.core.isDestroyed;\n }\n get isInitialized() {\n return this.core.isInitialized;\n }\n addDestroyListener(callback) {\n this.core.addDestroyListener(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.core.init();\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.core.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this instanceof AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nexport default class DefaultWrapletManager {\n initializers = [];\n addWrapletInitializer(callback) {\n this.initializers.push(callback);\n }\n initializeNodeTree(node) {\n for (const initializer of this.initializers) {\n initializer(node);\n }\n }\n destroyNodeTree(node) {\n destroyWrapletsRecursively(node);\n }\n}\n","import DefaultWrapletManager from \"./DefaultWrapletManager\";\nlet globalWrapletManager = null;\nexport function getGlobalWrapletManager() {\n if (!globalWrapletManager) {\n globalWrapletManager = new DefaultWrapletManager();\n }\n return globalWrapletManager;\n}\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","isWraplet","getWrapletsFromNode","node","wraplets","Array","isArray","actOnNodesRecursevily","callback","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","Core","map","initOptions","isDestroyed","isInitialized","instantiatedChildren","__debugNodeAccessors","destroyListeners","destroyChildListeners","instantiateChildListeners","listeners","constructor","this","id","addDefaultsToChildDefinition","processInitOptions","init","instantiateChildren","wrapChildren","push","isParentNode","keys","length","item","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","isCorrectSingleWrapletInstanceGuard","Class","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","querySelectorAll","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","accessNode","addDestroyListener","addDestroyChildListener","addInstantiateChildListener","removeChild","executeOnChildren","method","payload","childEntries","entries","destructible","childArray","slice","wrapletHasMethodGuard","String","eventName","options","removeEventListener","removeWrapletFromNode","index","findIndex","splice","childTypeGuard","variable","isRequired","required","every","addEventListener","uninitializedChildren","a","b","setB","Set","filter","x","has","elements","Proxy","target","find","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","AbstractWraplet","core","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","result","foundElements","element","DefaultWrapletManager","initializers","addWrapletInitializer","initializeNodeTree","initializer","destroyNodeTree","globalWrapletManager","getGlobalWrapletManager"],"sourceRoot":""}
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"AAAO,MAAMA,UAAkCC,OAExC,MAAMC,UAAiBD,OAEvB,MAAME,UAAoCF,OAE1C,MAAMG,UAAqCH,OCN3C,SAASI,EAAUC,GACtB,MAAuB,iBAARA,GACH,OAARA,GACA,cAAeA,IACG,IAAlBA,EAAID,SACZ,CACO,SAASE,EAAoBC,GAChC,MAAMC,EAAWD,EAAKC,SACtB,OAAKC,MAAMC,QAAQF,GAGZA,EAFI,EAGf,CACO,SAASG,EAAsBJ,EAAMK,GACxCA,EAASL,GACT,MAAMM,EAAWN,EAAKO,WACtB,IAAK,MAAMC,KAASF,EAChBF,EAAsBI,EAAOH,EAErC,CACO,SAASI,EAA2BT,GACvCI,EAAsBJ,EAAOA,IAC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H,aAAgB+H,SAChBH,EAAa5H,GAGb8H,EAAaE,SAASC,cAAc,OACpCH,EAAWI,YAAYlI,GACvB4H,EAAaE,IAGrB,MAAMK,EAAS,GACTC,EAAgBR,EAAWtE,iBAAiBF,GAC9C0E,GACAA,EAAWzD,YAAYrE,GAE3B,IAAK,MAAMqI,KAAWD,EAClBD,EAAOpG,KAAK,IAAIP,KAAK6G,KAAYV,IAErC,OAAOQ,CACX,EClGW,MAAMG,EACjBC,aAAe,GACf,qBAAAC,CAAsBnI,GAClBmB,KAAK+G,aAAaxG,KAAK1B,EAC3B,CACA,kBAAAoI,CAAmBzI,GACf,IAAK,MAAM0I,KAAelH,KAAK+G,aAC3BG,EAAY1I,EAEpB,CACA,eAAA2I,CAAgB3I,GACZS,EAA2BT,EAC/B,ECZJ,IAAI4I,EAAuB,KACpB,SAASC,IAIZ,OAHKD,IACDA,EAAuB,IAAIN,GAExBM,CACX,Q","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/utils.ts","webpack://wraplet/./src/Core.ts","webpack://wraplet/./src/AbstractWraplet.ts","webpack://wraplet/./src/DefaultWrapletManager.ts","webpack://wraplet/./src/getGlobalWrapletManager.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class ValidationMissingError extends Error {\n}\nexport class InvalidOptionsError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\n","export function isWraplet(obj) {\n return (typeof obj === \"object\" &&\n obj !== null &&\n \"isWraplet\" in obj &&\n obj.isWraplet === true);\n}\nexport function getWrapletsFromNode(node) {\n const wraplets = node.wraplets;\n if (!Array.isArray(wraplets)) {\n return [];\n }\n return wraplets;\n}\nexport function actOnNodesRecursevily(node, callback) {\n callback(node);\n const children = node.childNodes;\n for (const child of children) {\n actOnNodesRecursevily(child, callback);\n }\n}\nexport function destroyWrapletsRecursively(node) {\n actOnNodesRecursevily(node, (node) => {\n const wraplets = getWrapletsFromNode(node);\n for (const wraplet of wraplets) {\n wraplet.destroy();\n }\n });\n}\n","import { ChildrenAreNotAvailableError, MapError, MissingRequiredChildError, RequiredChildDestroyedError, } from \"./errors\";\nimport { isWraplet } from \"./utils\";\nexport class Core {\n node;\n map;\n wraplet;\n initOptions;\n isDestroyed = false;\n isInitialized = false;\n instantiatedChildren;\n /**\n * This is the log of all node accessors, available for easier debugging.\n */\n __debugNodeAccessors = [];\n destroyListeners = [];\n destroyChildListeners = [];\n instantiateChildListeners = [];\n listeners = [];\n constructor(node, map, wraplet, initOptions = {}) {\n this.node = node;\n this.map = map;\n this.wraplet = wraplet;\n this.initOptions = initOptions;\n for (const id in map) {\n map[id] = this.addDefaultsToChildDefinition(map[id]);\n }\n this.processInitOptions(initOptions);\n this.instantiatedChildren = {};\n }\n /**\n * Initialize core.\n *\n * We couldn't put this step in the constructor, because during initialization some wraplet\n * processing occurs (instantiate child listeners) that needs access to the core, so core has to\n * exist already.\n */\n init() {\n const children = this.instantiateChildren(this.node);\n this.instantiatedChildren = this.wrapChildren(children);\n if (!this.node.wraplets) {\n this.node.wraplets = [];\n }\n this.node.wraplets.push(this.wraplet);\n this.isInitialized = true;\n }\n instantiateChildren(node) {\n const children = this.instantiatedChildren;\n // We check if are dealing with the ParentNode object.\n if (!this.isParentNode(node)) {\n if (Object.keys(this.map).length > 0) {\n throw new MapError(\"If the node provided cannot have children, the children map should be empty.\");\n }\n return children;\n }\n for (const id in this.map) {\n const item = this.map[id];\n const multiple = item.multiple;\n this.validateMapItem(id, item);\n if (multiple) {\n // We can assert as much because items\n children[id] = this.instantiateMultipleWrapletsChild(item, node, id);\n continue;\n }\n children[id] = this.instantiateSingleWrapletChild(item, node, id);\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n syncChildren() {\n this.instantiatedChildren = this.instantiateChildren(this.node);\n }\n isCorrectSingleWrapletInstanceGuard(item, id) {\n return item instanceof this.map[id].Class;\n }\n findExistingWraplet(id, childElement) {\n if (this.instantiatedChildren === undefined ||\n !this.instantiatedChildren[id]) {\n return null;\n }\n const existingChild = this.instantiatedChildren[id];\n const existingWrapletsOnNode = childElement.wraplets || [];\n if (this.map[id][\"multiple\"]) {\n if (!Array.isArray(existingChild)) {\n throw new Error(\"Internal logic error. Expected an array.\");\n }\n const intersection = this.intersect(existingChild, existingWrapletsOnNode);\n if (intersection.length === 0) {\n return null;\n }\n else if (intersection.length === 1) {\n return intersection[0];\n }\n else if (intersection.length > 1) {\n throw new Error(\"Internal logic error. Multiple wraplets found for the same child.\");\n }\n }\n else if (this.instantiatedChildren[id] !== null) {\n return existingChild;\n }\n return null;\n }\n instantiateSingleWrapletChild(mapItem, node, id) {\n if (!mapItem.selector) {\n return null;\n }\n const selector = mapItem.selector;\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n if (childElements.length === 0) {\n return null;\n }\n if (childElements.length > 1) {\n throw new Error(`${this.constructor.name}: More than one element was found for the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n const childElement = childElements[0];\n return this.instantiateWrapletItem(id, mapItem, childElement);\n }\n instantiateWrapletItem(id, mapItem, node) {\n // Re-use existing wraplet.\n const existingWraplet = this.findExistingWraplet(id, node);\n if (existingWraplet) {\n return existingWraplet;\n }\n const wrapletClass = mapItem.Class;\n const args = mapItem.args || [];\n const wraplet = this.createIndividualWraplet(wrapletClass, node, args);\n this.prepareIndividualWraplet(id, wraplet);\n for (const listener of this.instantiateChildListeners) {\n listener(wraplet, id);\n }\n return wraplet;\n }\n instantiateMultipleWrapletsChild(mapItem, node, id) {\n const selector = mapItem.selector;\n if (!selector) {\n return [];\n }\n // Find children elements based on the map.\n const childElements = node.querySelectorAll(selector);\n this.validateElements(id, childElements, mapItem);\n const items = this.instantiatedChildren && this.instantiatedChildren[id]\n ? this.instantiatedChildren[id]\n : [];\n for (const childElement of childElements) {\n const existingWraplet = this.findExistingWraplet(id, childElement);\n if (existingWraplet) {\n continue;\n }\n const wraplet = this.instantiateWrapletItem(id, mapItem, childElement);\n if (!wraplet) {\n continue;\n }\n if (!this.isCorrectSingleWrapletInstanceGuard(wraplet, id)) {\n throw new Error(`${this.constructor.name}: The \"${id}\" child is not an array of the expected type.`);\n }\n items.push(wraplet);\n }\n return items;\n }\n accessNode(callback) {\n this.__debugNodeAccessors.push(callback);\n callback(this.node);\n }\n addDestroyListener(callback) {\n this.destroyListeners.push(callback);\n }\n addDestroyChildListener(callback) {\n this.destroyChildListeners.push(callback);\n }\n addInstantiateChildListener(callback) {\n this.instantiateChildListeners.push(callback);\n }\n createIndividualWraplet(wrapletClass, childElement, args = []) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n prepareIndividualWraplet(id, wraplet) {\n const destroyListener = (wraplet) => {\n this.removeChild(wraplet, id);\n for (const listener of this.destroyChildListeners) {\n listener(wraplet, id);\n }\n };\n // Listen for the child's destruction.\n wraplet.addDestroyListener(destroyListener);\n }\n /**\n * This method allows executing the specified method on the wraplet and all its children.\n * The original wraplet and all children need to have this method implemented.\n */\n executeOnChildren(children, method, payload) {\n for (const childEntries of Object.entries(children)) {\n const name = childEntries[0];\n const child = childEntries[1];\n const map = this.map;\n if (!map[name].destructible) {\n continue;\n }\n if (Array.isArray(child)) {\n // We need to loop through the copy of the array because some items can be removed from\n // the original during the loop.\n const childArray = child.slice(0);\n for (const item of childArray) {\n if (!isWraplet(item)) {\n throw new Error(\"Internal logic error. Item is not a wraplet.\");\n }\n if (!this.wrapletHasMethodGuard(item, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n item[method](payload);\n }\n else {\n item[method]();\n }\n }\n }\n else if (isWraplet(child)) {\n if (!this.wrapletHasMethodGuard(child, method)) {\n throw new Error(`Internal logic error. Action \"${String(method)}\" is not defined for the child \"${name}\".`);\n }\n if (payload) {\n child[method](payload);\n }\n else {\n child[method]();\n }\n }\n }\n }\n /**\n * This method removes from nodes references to this wraplet and its children recuresively.\n */\n destroy() {\n if (this.isDestroyed) {\n throw new Error(\"Wraplet is already destroyed.\");\n }\n // Remove listeners.\n for (const listener of this.listeners) {\n const node = listener.node;\n const eventName = listener.eventName;\n const callback = listener.callback;\n const options = listener.options;\n node.removeEventListener(eventName, callback, options);\n }\n for (const listener of this.destroyListeners) {\n listener(this.wraplet);\n }\n this.destroyListeners.length = 0;\n this.removeWrapletFromNode(this.wraplet, this.node);\n this.executeOnChildren(this.children, \"destroy\");\n this.isDestroyed = true;\n }\n /**\n * Remove the wraplet from the list of wraplets.\n */\n removeWrapletFromNode(wraplet, node) {\n const index = node.wraplets?.findIndex((value) => {\n return value === wraplet;\n });\n if (index !== undefined && index > -1) {\n node.wraplets?.splice(index, 1);\n }\n }\n addDefaultsToChildDefinition(definition) {\n return {\n ...{\n args: [],\n destructible: true,\n },\n ...definition,\n };\n }\n wrapletHasMethodGuard(wraplet, method) {\n return typeof wraplet[method] === \"function\";\n }\n isParentNode(node) {\n return typeof node.querySelectorAll === \"function\";\n }\n childTypeGuard(variable, id) {\n const map = this.map;\n const Class = map[id].Class;\n const isRequired = map[id].required;\n const isMultiple = map[id].multiple;\n if (isMultiple) {\n if (!Array.isArray(variable)) {\n return false;\n }\n if (isRequired) {\n return variable.every((value) => value instanceof Class);\n }\n return true;\n }\n if (isRequired) {\n return variable instanceof Class;\n }\n return variable instanceof Class || variable === null;\n }\n addEventListener(node, eventName, callback, options) {\n this.listeners.push({ node, eventName, callback, options });\n node.addEventListener(eventName, callback, options);\n }\n get children() {\n if (!this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is not yet fully initialized. You can fetch partial children with the 'uninitializedChildren' property.\");\n }\n return this.instantiatedChildren;\n }\n get uninitializedChildren() {\n if (this.isInitialized) {\n throw new ChildrenAreNotAvailableError(\"Wraplet is already initialized. Fetch children with 'children' property instead.\");\n }\n return this.instantiatedChildren;\n }\n removeChild(wraplet, id) {\n if (Array.isArray(this.instantiatedChildren[id])) {\n const index = this.instantiatedChildren[id].findIndex((value) => {\n return value === wraplet;\n });\n if (index === -1) {\n throw new Error(\"Internal logic error. Destroyed child couldn't be removed because it's not among the children.\");\n }\n this.instantiatedChildren[id].splice(index, 1);\n return;\n }\n if (this.map[id].required) {\n throw new RequiredChildDestroyedError(\"Required child has been destroyed.\");\n }\n // @ts-expect-error The type is unknown because we are dealing with a generic here.\n this.instantiatedChildren[id] = null;\n }\n intersect(a, b) {\n const setB = new Set(b);\n return [...new Set(a)].filter((x) => setB.has(x));\n }\n validateMapItem(id, item) {\n const selector = item.selector;\n const isRequired = item.required;\n if (!selector) {\n if (isRequired) {\n throw new MapError(`${this.constructor.name}: Child \"${id}\" cannot at the same be required and have no selector.`);\n }\n }\n }\n validateElements(id, elements, mapItem) {\n if (elements.length === 0 && mapItem.required) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find a node for the wraplet \"${id}\". Selector used: \"${mapItem.selector}\".`);\n }\n }\n /**\n * Set up a proxy to check if children have not been destroyed before fetching them.\n */\n wrapChildren(children) {\n return new Proxy(children, {\n get: function get(target, name) {\n if (!(name in target)) {\n throw new Error(\"Child has not been found.\");\n }\n function isDestroyed(wraplet) {\n return wraplet.isDestroyed;\n }\n const child = target[name];\n if (Array.isArray(child)) {\n const destroyed = child.find(isDestroyed);\n if (destroyed) {\n throw new Error(\"Core error: One of the children in the array has been destroyed but not removed\");\n }\n return target[name];\n }\n if (child !== null && isDestroyed(child)) {\n throw new Error(\"The child has been destroyed\");\n }\n return target[name];\n },\n });\n }\n defaultInitOptions() {\n return {\n instantiateChildListeners: [],\n destroyChildListeners: [],\n };\n }\n processInitOptions(initOptionsPartial) {\n const initOptions = Object.assign(this.defaultInitOptions(), initOptionsPartial);\n if (initOptions.mapAlterCallback) {\n initOptions.mapAlterCallback(this.map);\n }\n for (const listener of initOptions.instantiateChildListeners) {\n this.instantiateChildListeners.push(listener);\n }\n for (const listener of initOptions.destroyChildListeners) {\n this.destroyChildListeners.push(listener);\n }\n }\n}\n","import { Core } from \"./Core\";\nexport class AbstractWraplet {\n isWraplet = true;\n core;\n constructor(node, initOptions = {}) {\n if (!node) {\n throw new Error(\"Node is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n initOptions.instantiateChildListeners = [\n this.onChildInstantiated.bind(this),\n ];\n initOptions.destroyChildListeners = [this.onChildDestroyed.bind(this)];\n this.core = new Core(node, map, this, initOptions);\n this.initialize();\n }\n get node() {\n return this.core.node;\n }\n get children() {\n return this.core.children;\n }\n accessNode(callback) {\n this.core.accessNode(callback);\n }\n destroy() {\n this.core.destroy();\n }\n get isDestroyed() {\n return this.core.isDestroyed;\n }\n get isInitialized() {\n return this.core.isInitialized;\n }\n addDestroyListener(callback) {\n this.core.addDestroyListener(callback);\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been destroyed.\n */\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n onChildDestroyed(child, id) { }\n initialize() {\n this.core.init();\n }\n /**\n * This method will be ivoked if one of the wraplet's children has been instantiated.\n */\n onChildInstantiated(\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n child, \n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n id) { }\n /**\n * This method makes sure that the given instance is an instance of a class belonging to the\n * given child.\n *\n * @param item\n * @param actualUnknownId\n * @param onlyId\n * By hardcoding onlyId you can filter out any other children. It allows you to learn not only\n * that the class is correct, but also that the child is correct (in case multiple children can\n * use the same class).\n * @protected\n */\n isChildInstance(item, actualUnknownId, onlyId = null) {\n return (actualUnknownId === (onlyId || actualUnknownId) &&\n item instanceof this.core.map[actualUnknownId][\"Class\"]);\n }\n // We can afford \"any\" here because this method is only for the external usage, and external\n // callers don't need to know what map is the current wraplet using, as it's its internal\n // matter.\n static createWraplets(node, selector, additional_args = []) {\n if (this instanceof AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n let searchNode = node.parentNode;\n // We use a temporary parent to be able to match the top element with the \"querySelectorAll\"\n // method.\n let tempParent = null;\n if (!searchNode) {\n if (node instanceof Document) {\n searchNode = node;\n }\n else {\n tempParent = document.createElement(\"div\");\n tempParent.appendChild(node);\n searchNode = tempParent;\n }\n }\n const result = [];\n const foundElements = searchNode.querySelectorAll(selector);\n if (tempParent) {\n tempParent.removeChild(node);\n }\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\n","import { destroyWrapletsRecursively } from \"./utils\";\nexport default class DefaultWrapletManager {\n initializers = [];\n addWrapletInitializer(callback) {\n this.initializers.push(callback);\n }\n initializeNodeTree(node) {\n for (const initializer of this.initializers) {\n initializer(node);\n }\n }\n destroyNodeTree(node) {\n destroyWrapletsRecursively(node);\n }\n}\n","import DefaultWrapletManager from \"./DefaultWrapletManager\";\nlet globalWrapletManager = null;\nexport function getGlobalWrapletManager() {\n if (!globalWrapletManager) {\n globalWrapletManager = new DefaultWrapletManager();\n }\n return globalWrapletManager;\n}\n"],"names":["MissingRequiredChildError","Error","MapError","RequiredChildDestroyedError","ChildrenAreNotAvailableError","isWraplet","obj","getWrapletsFromNode","node","wraplets","Array","isArray","actOnNodesRecursevily","callback","children","childNodes","child","destroyWrapletsRecursively","wraplet","destroy","Core","map","initOptions","isDestroyed","isInitialized","instantiatedChildren","__debugNodeAccessors","destroyListeners","destroyChildListeners","instantiateChildListeners","listeners","constructor","this","id","addDefaultsToChildDefinition","processInitOptions","init","instantiateChildren","wrapChildren","push","isParentNode","Object","keys","length","item","multiple","validateMapItem","instantiateMultipleWrapletsChild","instantiateSingleWrapletChild","syncChildren","isCorrectSingleWrapletInstanceGuard","Class","findExistingWraplet","childElement","undefined","existingChild","existingWrapletsOnNode","intersection","intersect","mapItem","selector","childElements","querySelectorAll","validateElements","name","instantiateWrapletItem","existingWraplet","wrapletClass","args","createIndividualWraplet","prepareIndividualWraplet","listener","items","accessNode","addDestroyListener","addDestroyChildListener","addInstantiateChildListener","removeChild","executeOnChildren","method","payload","childEntries","entries","destructible","childArray","slice","wrapletHasMethodGuard","String","eventName","options","removeEventListener","removeWrapletFromNode","index","findIndex","value","splice","definition","childTypeGuard","variable","isRequired","required","every","addEventListener","uninitializedChildren","a","b","setB","Set","filter","x","has","elements","Proxy","get","target","find","defaultInitOptions","initOptionsPartial","assign","mapAlterCallback","AbstractWraplet","core","defineChildrenMap","onChildInstantiated","bind","onChildDestroyed","initialize","isChildInstance","actualUnknownId","onlyId","createWraplets","additional_args","searchNode","parentNode","tempParent","Document","document","createElement","appendChild","result","foundElements","element","DefaultWrapletManager","initializers","addWrapletInitializer","initializeNodeTree","initializer","destroyNodeTree","globalWrapletManager","getGlobalWrapletManager"],"sourceRoot":""}
|
package/dist/storage.cjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var t={d:(e,s)=>{for(var r in s)t.o(s,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:s[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{ElementStorage:()=>r});class s extends Error{}class r{element;attribute;validators;defaults;options;data;constructor(t,e,s,r,i={}){this.element=t,this.attribute=e,this.validators=s,this.defaults=r,this.options=i,this.options={keepFresh:!0,...i},this.data=this.fetchFreshData()}has(t){return t in this.getAll()}get(t){return this.getAll()[t]}getMultiple(t){const e=this.getAll();return t.reduce((t,s)=>(t[s]=e[s],t),{})}getAll(){return this.options.keepFresh&&this.refresh(),this.data}set(t,e){const r=this.getAll();if(!this.validators[t](e))throw new s(`Attempted to set an invalid value for the key ${String(t)}.`);r[t]=e,this.setAll(r)}setMultiple(t){const e=this.getAll();this.setAll({...e,...t})}setAll(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}delete(t){const e=this.getAll();e[t]&&delete e[t],this.element.setAttribute(this.attribute,JSON.stringify(e))}deleteMultiple(t){const e=this.getAll();for(const s of t)delete e[s];this.setAll(e)}deleteAll(){this.element.setAttribute(this.attribute,""),this.refresh()}refresh(){this.data=this.fetchFreshData()}fetchFreshData(){const t=this.getAttributeValue(this.attribute);if(t){if("{"!==t.charAt(0))throw new Error("Data has to be defined as an object.");const e=JSON.parse(t);if(!this.validateData(e))throw new s("Invalid storage value.");return{...this.defaults,...e}}return{...this.defaults}}validateData(t){for(const e in t)if(!this.validators[e](t[e]))return!1;return!0}getAttributeValue(t){return this.element.getAttribute(t)}}var i=exports;for(var l in e)i[l]=e[l];e.__esModule&&Object.defineProperty(i,"__esModule",{value:!0});
|
|
2
|
+
//# sourceMappingURL=storage.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.cjs","mappings":"AACA,IAAIA,EAAsB,CCA1BA,EAAwB,CAACC,EAASC,KACjC,IAAI,IAAIC,KAAOD,EACXF,EAAoBI,EAAEF,EAAYC,KAASH,EAAoBI,EAAEH,EAASE,IAC5EE,OAAOC,eAAeL,EAASE,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,MCJ3EH,EAAwB,CAACS,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFV,EAAyBC,IACH,oBAAXa,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeL,EAASa,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeL,EAAS,aAAc,CAAEe,OAAO,M,0CCOhD,MAAMC,UAA+BC,OCXrC,MAAMC,EACTC,QACAC,UACAC,WACAC,SACAC,QACAC,KACA,WAAAC,CAAYN,EAASC,EAAWC,EAAYC,EAAUC,EAAU,CAAC,GAC7DG,KAAKP,QAAUA,EACfO,KAAKN,UAAYA,EACjBM,KAAKL,WAAaA,EAClBK,KAAKJ,SAAWA,EAChBI,KAAKH,QAAUA,EACfG,KAAKH,QAAU,CACXI,WAAW,KACRJ,GAEPG,KAAKF,KAAOE,KAAKE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AEpB,MAAMO,EAAOkB,KAAKO,MAAMH,GACxB,IAAKpB,KAAKwB,aAAa1B,GACnB,MAAM,IAAIR,EAAuB,0BAErC,MAAO,IAAKU,KAAKJ,YAAaE,EAClC,CACA,MAAO,IAAKE,KAAKJ,SACrB,CACA,YAAA4B,CAAa1B,GACT,IAAK,MAAMtB,KAAOsB,EACd,IAAKE,KAAKL,WAAWnB,GAAKsB,EAAKtB,IAC3B,OAAO,EAGf,OAAO,CACX,CACA,iBAAA6C,CAAkB3B,GACd,OAAOM,KAAKP,QAAQgC,aAAa/B,EACrC,E","sources":["webpack://wraplet/webpack/bootstrap","webpack://wraplet/webpack/runtime/define property getters","webpack://wraplet/webpack/runtime/hasOwnProperty shorthand","webpack://wraplet/webpack/runtime/make namespace object","webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class ValidationMissingError extends Error {\n}\nexport class InvalidOptionsError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class ElementStorage {\n element;\n attribute;\n validators;\n defaults;\n options;\n data;\n constructor(element, attribute, validators, defaults, options = {}) {\n this.element = element;\n this.attribute = attribute;\n this.validators = validators;\n this.defaults = defaults;\n this.options = options;\n this.options = {\n keepFresh: true,\n ...options,\n };\n this.data = this.fetchFreshData();\n }\n has(key) {\n const data = this.getAll();\n return key in data;\n }\n get(key) {\n const data = this.getAll();\n return data[key];\n }\n getMultiple(keys) {\n const data = this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n getAll() {\n if (this.options.keepFresh) {\n this.refresh();\n }\n return this.data;\n }\n set(key, value) {\n const data = this.getAll();\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n data[key] = value;\n this.setAll(data);\n }\n setMultiple(data) {\n const oldData = this.getAll();\n this.setAll({ ...oldData, ...data });\n }\n setAll(data) {\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n delete(key) {\n const data = this.getAll();\n if (data[key]) {\n delete data[key];\n }\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n deleteMultiple(keys) {\n const data = this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n this.setAll(data);\n }\n deleteAll() {\n this.element.setAttribute(this.attribute, \"\");\n this.refresh();\n }\n refresh() {\n this.data = this.fetchFreshData();\n }\n fetchFreshData() {\n const dataString = this.getAttributeValue(this.attribute);\n if (dataString) {\n if (dataString.charAt(0) !== \"{\") {\n throw new Error(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return { ...this.defaults, ...data };\n }\n return { ...this.defaults };\n }\n validateData(data) {\n for (const key in data) {\n if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n getAttributeValue(attribute) {\n return this.element.getAttribute(attribute);\n }\n}\n"],"names":["__webpack_require__","exports","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","StorageValidationError","Error","ElementStorage","element","attribute","validators","defaults","options","data","constructor","this","keepFresh","fetchFreshData","has","getAll","getMultiple","keys","reduce","acc","refresh","set","String","setAll","setMultiple","oldData","setAttribute","JSON","stringify","deleteMultiple","deleteAll","dataString","getAttributeValue","charAt","parse","validateData","getAttribute"],"sourceRoot":""}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
class t extends Error{}class e{element;attribute;validators;defaults;options;data;constructor(t,e,s,i,r={}){this.element=t,this.attribute=e,this.validators=s,this.defaults=i,this.options=r,this.options={keepFresh:!0,...r},this.data=this.fetchFreshData()}has(t){return t in this.getAll()}get(t){return this.getAll()[t]}getMultiple(t){const e=this.getAll();return t.reduce((t,s)=>(t[s]=e[s],t),{})}getAll(){return this.options.keepFresh&&this.refresh(),this.data}set(e,s){const i=this.getAll();if(!this.validators[e](s))throw new t(`Attempted to set an invalid value for the key ${String(e)}.`);i[e]=s,this.setAll(i)}setMultiple(t){const e=this.getAll();this.setAll({...e,...t})}setAll(t){this.element.setAttribute(this.attribute,JSON.stringify(t))}delete(t){const e=this.getAll();e[t]&&delete e[t],this.element.setAttribute(this.attribute,JSON.stringify(e))}deleteMultiple(t){const e=this.getAll();for(const s of t)delete e[s];this.setAll(e)}deleteAll(){this.element.setAttribute(this.attribute,""),this.refresh()}refresh(){this.data=this.fetchFreshData()}fetchFreshData(){const e=this.getAttributeValue(this.attribute);if(e){if("{"!==e.charAt(0))throw new Error("Data has to be defined as an object.");const s=JSON.parse(e);if(!this.validateData(s))throw new t("Invalid storage value.");return{...this.defaults,...s}}return{...this.defaults}}validateData(t){for(const e in t)if(!this.validators[e](t[e]))return!1;return!0}getAttributeValue(t){return this.element.getAttribute(t)}}export{e as ElementStorage};
|
|
2
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","mappings":"AAYO,MAAMA,UAA+BC,OCXrC,MAAMC,EACTC,QACAC,UACAC,WACAC,SACA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UAAW,IAC1CM,KAAKW,SACT,CACA,OAAAA,GACIX,KAAKF,KAAOE,KAAKE,gBACrB,CACA,cAAAA,GACI,MAAMqB,EAAavB,KAAKwB,kBAAkBxB,KAAKN,WAC/C,GAAI6B,EAAY,CACZ,GAA6B,MAAzBA,EAAWE,OAAO,GAClB,MAAM,IAAIlC,MAAM,wCAEpB,MAAMO,EAAOqB,KAAKO,MAAMH,GACxB,IAAKvB,KAAK2B,aAAa7B,GACnB,MAAM,IAAIR,EAAuB,0BAErC,MAAO,IAAKU,KAAKJ,YAAaE,EAClC,CACA,MAAO,IAAKE,KAAKJ,SACrB,CACA,YAAA+B,CAAa7B,GACT,IAAK,MAAMM,KAAON,EACd,IAAKE,KAAKL,WAAWS,GAAKN,EAAKM,IAC3B,OAAO,EAGf,OAAO,CACX,CACA,iBAAAoB,CAAkB9B,GACd,OAAOM,KAAKP,QAAQmC,aAAalC,EACrC,S","sources":["webpack://wraplet/./src/errors.ts","webpack://wraplet/./src/Storage/ElementStorage.ts"],"sourcesContent":["export class MissingRequiredChildError extends Error {\n}\nexport class MapError extends Error {\n}\nexport class RequiredChildDestroyedError extends Error {\n}\nexport class ChildrenAreNotAvailableError extends Error {\n}\nexport class ValidationMissingError extends Error {\n}\nexport class InvalidOptionsError extends Error {\n}\nexport class StorageValidationError extends Error {\n}\n","import { StorageValidationError } from \"../errors\";\nexport class ElementStorage {\n element;\n attribute;\n validators;\n defaults;\n options;\n data;\n constructor(element, attribute, validators, defaults, options = {}) {\n this.element = element;\n this.attribute = attribute;\n this.validators = validators;\n this.defaults = defaults;\n this.options = options;\n this.options = {\n keepFresh: true,\n ...options,\n };\n this.data = this.fetchFreshData();\n }\n has(key) {\n const data = this.getAll();\n return key in data;\n }\n get(key) {\n const data = this.getAll();\n return data[key];\n }\n getMultiple(keys) {\n const data = this.getAll();\n return keys.reduce((acc, key) => {\n acc[key] = data[key];\n return acc;\n }, {});\n }\n getAll() {\n if (this.options.keepFresh) {\n this.refresh();\n }\n return this.data;\n }\n set(key, value) {\n const data = this.getAll();\n if (!this.validators[key](value)) {\n throw new StorageValidationError(`Attempted to set an invalid value for the key ${String(key)}.`);\n }\n data[key] = value;\n this.setAll(data);\n }\n setMultiple(data) {\n const oldData = this.getAll();\n this.setAll({ ...oldData, ...data });\n }\n setAll(data) {\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n delete(key) {\n const data = this.getAll();\n if (data[key]) {\n delete data[key];\n }\n this.element.setAttribute(this.attribute, JSON.stringify(data));\n }\n deleteMultiple(keys) {\n const data = this.getAll();\n for (const key of keys) {\n delete data[key];\n }\n this.setAll(data);\n }\n deleteAll() {\n this.element.setAttribute(this.attribute, \"\");\n this.refresh();\n }\n refresh() {\n this.data = this.fetchFreshData();\n }\n fetchFreshData() {\n const dataString = this.getAttributeValue(this.attribute);\n if (dataString) {\n if (dataString.charAt(0) !== \"{\") {\n throw new Error(`Data has to be defined as an object.`);\n }\n const data = JSON.parse(dataString);\n if (!this.validateData(data)) {\n throw new StorageValidationError(\"Invalid storage value.\");\n }\n return { ...this.defaults, ...data };\n }\n return { ...this.defaults };\n }\n validateData(data) {\n for (const key in data) {\n if (!this.validators[key](data[key])) {\n return false;\n }\n }\n return true;\n }\n getAttributeValue(attribute) {\n return this.element.getAttribute(attribute);\n }\n}\n"],"names":["StorageValidationError","Error","ElementStorage","element","attribute","validators","defaults","options","data","constructor","this","keepFresh","fetchFreshData","has","key","getAll","get","getMultiple","keys","reduce","acc","refresh","set","value","String","setAll","setMultiple","oldData","setAttribute","JSON","stringify","deleteMultiple","deleteAll","dataString","getAttributeValue","charAt","parse","validateData","getAttribute"],"sourceRoot":""}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Storage } from "../types/Storage/Storage";
|
|
2
|
+
export type ElementStorageOptions = {
|
|
3
|
+
keepFresh?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare class ElementStorage<D extends Record<string, unknown>> implements Storage<D> {
|
|
6
|
+
private element;
|
|
7
|
+
private attribute;
|
|
8
|
+
private validators;
|
|
9
|
+
private defaults;
|
|
10
|
+
private options;
|
|
11
|
+
private data;
|
|
12
|
+
constructor(element: Element, attribute: string, validators: Record<keyof D, (value: unknown) => boolean>, defaults: D, options?: ElementStorageOptions);
|
|
13
|
+
has(key: keyof D): boolean;
|
|
14
|
+
get<T extends keyof D>(key: T): D[T];
|
|
15
|
+
getMultiple<T extends keyof D>(keys: T[]): Pick<D, T>;
|
|
16
|
+
getAll(): D;
|
|
17
|
+
set<T extends keyof D>(key: T, value: D[T]): void;
|
|
18
|
+
setMultiple(data: Partial<D>): void;
|
|
19
|
+
setAll(data: D): void;
|
|
20
|
+
delete(key: keyof D): void;
|
|
21
|
+
deleteMultiple(keys: (keyof D)[]): void;
|
|
22
|
+
deleteAll(): void;
|
|
23
|
+
refresh(): void;
|
|
24
|
+
private fetchFreshData;
|
|
25
|
+
private validateData;
|
|
26
|
+
private getAttributeValue;
|
|
27
|
+
}
|
|
@@ -6,3 +6,9 @@ export declare class RequiredChildDestroyedError extends Error {
|
|
|
6
6
|
}
|
|
7
7
|
export declare class ChildrenAreNotAvailableError extends Error {
|
|
8
8
|
}
|
|
9
|
+
export declare class ValidationMissingError extends Error {
|
|
10
|
+
}
|
|
11
|
+
export declare class InvalidOptionsError extends Error {
|
|
12
|
+
}
|
|
13
|
+
export declare class StorageValidationError extends Error {
|
|
14
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StorageReadonly } from "./StorageReadonly";
|
|
2
|
+
export interface Storage<D extends Record<string, unknown>> extends StorageReadonly<D> {
|
|
3
|
+
set: <T extends keyof D>(key: T, value: D[T]) => void;
|
|
4
|
+
setMultiple: (data: Partial<D>) => void;
|
|
5
|
+
setAll: (data: D) => void;
|
|
6
|
+
delete: (key: keyof D) => void;
|
|
7
|
+
deleteMultiple: (keys: (keyof D)[]) => void;
|
|
8
|
+
deleteAll: () => void;
|
|
9
|
+
}
|
package/package.json
CHANGED
|
@@ -1,43 +1,61 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wraplet",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"import": "./dist/index.js",
|
|
10
|
+
"require": "./dist/index.cjs",
|
|
11
|
+
"types": "./dist/typescript/index.d.ts"
|
|
12
|
+
},
|
|
13
|
+
"./storage": {
|
|
14
|
+
"import": "./dist/storage.js",
|
|
15
|
+
"require": "./dist/storage.cjs",
|
|
16
|
+
"types": "./dist/typescript/storage.d.ts"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
6
19
|
"license": "MIT",
|
|
7
20
|
"author": "Łukasz Zaroda",
|
|
8
21
|
"repository": {
|
|
9
22
|
"type": "git",
|
|
10
|
-
"url": "https://github.com/
|
|
23
|
+
"url": "https://github.com/wraplet/wraplet.git"
|
|
11
24
|
},
|
|
12
|
-
"files": [
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
],
|
|
13
28
|
"scripts": {
|
|
14
29
|
"setup": "yarn install",
|
|
15
|
-
"build": "./node_modules/.bin/webpack --mode production --config ./webpack.config.
|
|
16
|
-
"dev:build": "./node_modules/.bin/webpack --mode development --config ./webpack.config.
|
|
17
|
-
"dev:watch": "./node_modules/.bin/webpack --mode development --watch --config ./webpack.config.
|
|
30
|
+
"build": "NODE_OPTIONS='--no-experimental-strip-types --import tsx' node ./node_modules/.bin/webpack --mode production --config ./webpack.config.ts",
|
|
31
|
+
"dev:build": "NODE_OPTIONS='--no-experimental-strip-types --import tsx' node ./node_modules/.bin/webpack --mode development --config ./webpack.config.ts",
|
|
32
|
+
"dev:watch": "NODE_OPTIONS='--no-experimental-strip-types --import tsx' node ./node_modules/.bin/webpack --mode development --watch --config ./webpack.config.ts",
|
|
18
33
|
"lint": "tsc --noemit && npx eslint './src/**/*.ts' './tests/**/*.ts'",
|
|
19
34
|
"lint:fix": "npx eslint './src/**/*.ts' './tests/**/*.ts' --fix",
|
|
20
35
|
"tests": "jest"
|
|
21
36
|
},
|
|
22
|
-
"dependencies": {
|
|
23
|
-
},
|
|
37
|
+
"dependencies": {},
|
|
24
38
|
"devDependencies": {
|
|
25
|
-
"typescript": "^5.8.3",
|
|
26
|
-
"ts-loader": "^9.5.2",
|
|
27
39
|
"@eslint/js": "^9.29.0",
|
|
40
|
+
"@types/jest": "^30.0.0",
|
|
41
|
+
"@types/node": "^24.1.0",
|
|
42
|
+
"@types/webpack": "^5.28.5",
|
|
43
|
+
"esbuild-register": "^3.6.0",
|
|
28
44
|
"eslint": "^9.29.0",
|
|
29
|
-
"globals": "^16.2.0",
|
|
30
|
-
"typescript-eslint": "^8.35.0",
|
|
31
|
-
"webpack": "^5.99.9",
|
|
32
|
-
"webpack-cli": "^6.0.1",
|
|
33
|
-
"prettier": "^3.6.1",
|
|
34
45
|
"eslint-config-prettier": "^10.1.5",
|
|
35
46
|
"eslint-plugin-prettier": "^5.5.1",
|
|
36
|
-
"
|
|
47
|
+
"globals": "^16.2.0",
|
|
37
48
|
"jest": "^30.0.3",
|
|
38
49
|
"jest-cli": "^30.0.3",
|
|
50
|
+
"jest-environment-jsdom": "^30.0.2",
|
|
51
|
+
"prettier": "^3.6.1",
|
|
52
|
+
"prettier-eslint": "^16.4.2",
|
|
39
53
|
"ts-jest": "^29.4.0",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
54
|
+
"ts-loader": "^9.5.2",
|
|
55
|
+
"tsx": "^4.20.3",
|
|
56
|
+
"typescript": "^5.8.3",
|
|
57
|
+
"typescript-eslint": "^8.35.0",
|
|
58
|
+
"webpack": "^5.99.9",
|
|
59
|
+
"webpack-cli": "^6.0.1"
|
|
42
60
|
}
|
|
43
61
|
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { AbstractWraplet } from "../AbstractWraplet";
|
|
2
|
-
export type WrapletChildDefinition<T extends AbstractWraplet<any, any, any> = AbstractWraplet<any, any, any>> = {
|
|
3
|
-
selector?: string;
|
|
4
|
-
Class: {
|
|
5
|
-
new (...args: any[]): T;
|
|
6
|
-
};
|
|
7
|
-
required: boolean;
|
|
8
|
-
multiple: boolean;
|
|
9
|
-
args?: unknown[];
|
|
10
|
-
destructible?: boolean;
|
|
11
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|