wraplet 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AbstractWraplet.d.ts +5 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
|
@@ -5,9 +5,14 @@ import { DeepWriteable } from "./types/Utils";
|
|
|
5
5
|
export declare abstract class AbstractWraplet<T extends WrapletChildrenMap = {}, E extends Element = Element> implements Wraplet {
|
|
6
6
|
protected element: E;
|
|
7
7
|
isWraplet: true;
|
|
8
|
+
/**
|
|
9
|
+
* This is the log of all element accessors, available for easier debugging.
|
|
10
|
+
*/
|
|
11
|
+
private __debugElementAccessors;
|
|
8
12
|
protected children: WrapletChildren<T>;
|
|
9
13
|
protected static debug: boolean;
|
|
10
14
|
constructor(element: E, mapAlterCallback?: ((map: DeepWriteable<T>) => void) | null);
|
|
15
|
+
accessElement(callback: (element: E) => void): void;
|
|
11
16
|
protected abstract defineChildrenMap(): T;
|
|
12
17
|
protected instantiateChildren(map: T): WrapletChildren<T>;
|
|
13
18
|
protected createWraplet(wrapletClass: new (...args: any[]) => Wraplet, childElement: Element, args?: unknown[]): Wraplet;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.wraplet=t():e.wraplet=t()}(self,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},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:()=>o});class r extends Error{}class n extends Error{}class o{constructor(e,t=null){this.element=e,this.isWraplet=!0;const r=this.defineChildrenMap();t&&t(r),this.children=this.instantiateChildren(r),this.element.wraplets||(this.element.wraplets=[]),this.element.wraplets.push(this)}instantiateChildren(e){const t={};for(const o in e){const s=e[o],i=s.selector,l=s.Class,
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.wraplet=t():e.wraplet=t()}(self,(()=>(()=>{"use strict";var e={d:(t,r)=>{for(var n in r)e.o(r,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:r[n]})},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:()=>o});class r extends Error{}class n extends Error{}class o{constructor(e,t=null){if(this.element=e,this.isWraplet=!0,this.__debugElementAccessors=[],!e)throw new Error("Element is required to create a wraplet.");const r=this.defineChildrenMap();t&&t(r),this.children=this.instantiateChildren(r),this.element.wraplets||(this.element.wraplets=[]),this.element.wraplets.push(this)}accessElement(e){this.__debugElementAccessors.push(e),e(this.element)}instantiateChildren(e){const t={};for(const o in e){const s=e[o],i=s.selector,l=s.Class,c=s.args||[],a=s.multiple,u=s.required;if(!i){if(u)throw new n(`${this.constructor.name}: Child "${o}" cannot at the same be required and have no selector.`);t[o]=a?[]:null;continue}const h=this.element.querySelectorAll(i);if(0===h.length){if(u)throw new r(`${this.constructor.name}: Couldn't find an element for the wraplet "${o}". Selector used: "${i}".`);this.constructor.debug&&console.log(`${this.constructor.name}: Optional child '${o}' has not been found. Selector used: "${i}"`),t[o]=a?[]:null;continue}const d=[];for(const e of h)if(d.push(this.createWraplet(l,e,c)),!a)break;const f=a?d:d[0];if(a&&!f&&this.constructor.debug&&console.log(`${this.constructor.name}: no items for the multiple child '${o}' have been found. Selector used: "${i}"`),!this.childTypeGuard(f,o)){if(void 0===f)throw new Error(`${this.constructor.name}: Couldn't intantionate the "${o}" child. Selector used: "${i}".`);throw new Error(`${this.constructor.name}: Child value doesn't match the map. Value: ${f}. Expected: ${e[o].Class.name}`)}t[o]=f}return t}createWraplet(e,t,r=[]){return new e(...[t,...r])}childTypeGuard(e,t){const r=this.defineChildrenMap(),n=r[t].Class,o=r[t].required;return r[t].multiple?!!Array.isArray(e)&&(!o||e.every((e=>e instanceof n))):o?e instanceof n:e instanceof n||null===e}static createWraplets(e,t=[],r){if(this instanceof o)throw new Error("You cannot instantiate an abstract class.");const n=[],s=e.querySelectorAll(r);for(const e of s)n.push(new this(e,...t));return n}}return o.debug=!1,t})()));
|
|
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,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,2CCLvD,MAAMC,UAAk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enC,EAAOgB,GAAK,CACjC,QAAqB,IAAVhB,EACP,MAAM,IAAIE,MAAM,GAAGM,KAAKH,YAAYoB,oCAAoCT,6BAA8BE,OAE1G,MAAM,IAAIhB,MAAM,GAAGM,KAAKH,YAAYoB,mDAAmDzB,gBAAoBU,EAAIM,GAAW,MAAES,OAChI,CACAb,EAASI,GAAMhB,CACnB,CAEA,OAAOY,CACX,CACA,aAAAsB,CAAcf,EAAcc,EAAcZ,EAAO,IAC7C,OAAO,IAAIF,KAAgB,CAAKc,KAAkBZ,GACtD,CACA,cAAAc,CAAeC,EAAUpB,GACrB,MAAMN,EAAMF,KAAKG,oBACXS,EAAQV,EAAIM,GAAII,MAChBG,EAAab,EAAIM,GAAIQ,SAE3B,OADmBd,EAAIM,GAAIM,WAEPe,MAAMC,QAAQF,MAI1Bb,GACOa,EAASG,OAAOvC,GAAUA,aAAiBoB,KAItDG,EACOa,aAAoBhB,EAExBgB,aAAoBhB,GAAsB,OAAbgB,CACxC,CAIA,qBAAOI,CAAeC,EAAUC,EAAkB,GAAIxB,GAClD,GAAIV,gBAAgBJ,EAChB,MAAM,IAAIF,MAAM,6CAEpB,MAAMyC,EAAS,GACTC,EAAgBH,EAASd,iBAAiBT,GAChD,IAAK,MAAMZ,KAAWsC,EAClBD,EAAO5B,KAAK,IAAIP,KAAKF,KAAYoC,IAErC,OAAOC,CACX,E,OAEJvC,EAAgByB,OAAQ,E","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/AbstractWraplet.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}\n","import { MapError, MissingRequiredChildError } from \"./errors\";\nexport class AbstractWraplet {\n constructor(element, mapAlterCallback = null) {\n this.element = element;\n this.isWraplet = true;\n const map = this.defineChildrenMap();\n if (mapAlterCallback) {\n mapAlterCallback(map);\n }\n this.children = this.instantiateChildren(map);\n if (!this.element.wraplets) {\n this.element.wraplets = [];\n }\n this.element.wraplets.push(this);\n }\n instantiateChildren(map) {\n const children = {};\n for (const id in map) {\n const item = map[id];\n const selector = item.selector;\n const wrapletClass = item.Class;\n const args = item.args || [];\n const multiple = item.multiple;\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 children[id] = multiple\n ? []\n : null;\n continue;\n }\n const childElements = this.element.querySelectorAll(selector);\n if (childElements.length === 0) {\n if (isRequired) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find an element for the wraplet \"${id}\". Selector used: \"${selector}\".`);\n }\n if (this.constructor.debug) {\n console.log(`${this.constructor.name}: Optional child '${id}' has not been found. Selector used: \"${selector}\"`);\n }\n children[id] = multiple\n ? []\n : null;\n continue;\n }\n const childWraplet = [];\n for (const childElement of childElements) {\n childWraplet.push(this.createWraplet(wrapletClass, childElement, args));\n if (!multiple) {\n break;\n }\n }\n const value = multiple\n ? childWraplet\n : childWraplet[0];\n if (multiple && !value && this.constructor.debug) {\n console.log(`${this.constructor.name}: no items for the multiple child '${id}' have been found. Selector used: \"${selector}\"`);\n }\n if (!this.childTypeGuard(value, id)) {\n if (typeof value === \"undefined\") {\n throw new Error(`${this.constructor.name}: Couldn't intantionate the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n throw new Error(`${this.constructor.name}: Child value doesn't match the map. Value: ${value}. Expected: ${map[id][\"Class\"].name}`);\n }\n children[id] = value;\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n createWraplet(wrapletClass, childElement, args = []) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n childTypeGuard(variable, id) {\n const map = this.defineChildrenMap();\n const Class = map[id].Class;\n const isRequired = map[id].required;\n const isMultiple = map[id].multiple;\n if (isMultiple) {\n const isArray = Array.isArray(variable);\n if (!isArray) {\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 // 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(document, additional_args = [], selector) {\n if (this instanceof AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n const foundElements = document.querySelectorAll(selector);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\nAbstractWraplet.debug = false;\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","AbstractWraplet","constructor","element","mapAlterCallback","this","isWraplet","map","defineChildrenMap","children","instantiateChildren","wraplets","push","id","item","selector","wrapletClass","Class","args","multiple","isRequired","required","name","childElements","querySelectorAll","length","debug","console","log","childWraplet","childElement","createWraplet","childTypeGuard","variable","Array","isArray","every","createWraplets","document","additional_args","result","foundElements"],"sourceRoot":""}
|
|
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,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,2CCLvD,MAAMC,UAAkCC,OAExC,MAAMC,UAAiBD,OCDvB,MAAME,EACT,WAAAC,CAAYC,EAASC,EAAmB,MAOpC,GANAC,KAAKF,QAAUA,EACfE,KAAKC,WAAY,EAIjBD,KAAKE,wBAA0B,IAC1BJ,EACD,MAAM,IAAIJ,MAAM,4CAEpB,MAAMS,EAAMH,KAAKI,oBACbL,GACAA,EAAiBI,GAErBH,KAAKK,SAAWL,KAAKM,oBAAoBH,GACpCH,KAAKF,QAAQS,WACdP,KAAKF,QAAQS,SAAW,IAE5BP,KAAKF,QAAQS,SAASC,KAAKR,KAC/B,CACA,aAAAS,CAAc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AAOa,CACX,CACA,aAAAwB,CAAcf,EAAcc,EAAcZ,EAAO,IAC7C,OAAO,IAAIF,KAAgB,CAAKc,KAAkBZ,GACtD,CACA,cAAAc,CAAeC,EAAUpB,GACrB,MAAMR,EAAMH,KAAKI,oBACXW,EAAQZ,EAAIQ,GAAII,MAChBG,EAAaf,EAAIQ,GAAIQ,SAE3B,OADmBhB,EAAIQ,GAAIM,WAEPe,MAAMC,QAAQF,MAI1Bb,GACOa,EAASG,OAAO1C,GAAUA,aAAiBuB,KAItDG,EACOa,aAAoBhB,EAExBgB,aAAoBhB,GAAsB,OAAbgB,CACxC,CAIA,qBAAOI,CAAeC,EAAUC,EAAkB,GAAIxB,GAClD,GAAIb,gBAAgBJ,EAChB,MAAM,IAAIF,MAAM,6CAEpB,MAAM4C,EAAS,GACTC,EAAgBH,EAASd,iBAAiBT,GAChD,IAAK,MAAMf,KAAWyC,EAClBD,EAAO9B,KAAK,IAAIR,KAAKF,KAAYuC,IAErC,OAAOC,CACX,E,OAEJ1C,EAAgB4B,OAAQ,E","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/AbstractWraplet.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}\n","import { MapError, MissingRequiredChildError } from \"./errors\";\nexport class AbstractWraplet {\n constructor(element, mapAlterCallback = null) {\n this.element = element;\n this.isWraplet = true;\n /**\n * This is the log of all element accessors, available for easier debugging.\n */\n this.__debugElementAccessors = [];\n if (!element) {\n throw new Error(\"Element is required to create a wraplet.\");\n }\n const map = this.defineChildrenMap();\n if (mapAlterCallback) {\n mapAlterCallback(map);\n }\n this.children = this.instantiateChildren(map);\n if (!this.element.wraplets) {\n this.element.wraplets = [];\n }\n this.element.wraplets.push(this);\n }\n accessElement(callback) {\n this.__debugElementAccessors.push(callback);\n callback(this.element);\n }\n instantiateChildren(map) {\n const children = {};\n for (const id in map) {\n const item = map[id];\n const selector = item.selector;\n const wrapletClass = item.Class;\n const args = item.args || [];\n const multiple = item.multiple;\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 children[id] = multiple\n ? []\n : null;\n continue;\n }\n const childElements = this.element.querySelectorAll(selector);\n if (childElements.length === 0) {\n if (isRequired) {\n throw new MissingRequiredChildError(`${this.constructor.name}: Couldn't find an element for the wraplet \"${id}\". Selector used: \"${selector}\".`);\n }\n if (this.constructor.debug) {\n console.log(`${this.constructor.name}: Optional child '${id}' has not been found. Selector used: \"${selector}\"`);\n }\n children[id] = multiple\n ? []\n : null;\n continue;\n }\n const childWraplet = [];\n for (const childElement of childElements) {\n childWraplet.push(this.createWraplet(wrapletClass, childElement, args));\n if (!multiple) {\n break;\n }\n }\n const value = multiple\n ? childWraplet\n : childWraplet[0];\n if (multiple && !value && this.constructor.debug) {\n console.log(`${this.constructor.name}: no items for the multiple child '${id}' have been found. Selector used: \"${selector}\"`);\n }\n if (!this.childTypeGuard(value, id)) {\n if (typeof value === \"undefined\") {\n throw new Error(`${this.constructor.name}: Couldn't intantionate the \"${id}\" child. Selector used: \"${selector}\".`);\n }\n throw new Error(`${this.constructor.name}: Child value doesn't match the map. Value: ${value}. Expected: ${map[id][\"Class\"].name}`);\n }\n children[id] = value;\n }\n // Now we should have all properties set, so let's assert the final form.\n return children;\n }\n createWraplet(wrapletClass, childElement, args = []) {\n return new wrapletClass(...[...[childElement], ...args]);\n }\n childTypeGuard(variable, id) {\n const map = this.defineChildrenMap();\n const Class = map[id].Class;\n const isRequired = map[id].required;\n const isMultiple = map[id].multiple;\n if (isMultiple) {\n const isArray = Array.isArray(variable);\n if (!isArray) {\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 // 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(document, additional_args = [], selector) {\n if (this instanceof AbstractWraplet) {\n throw new Error(\"You cannot instantiate an abstract class.\");\n }\n const result = [];\n const foundElements = document.querySelectorAll(selector);\n for (const element of foundElements) {\n result.push(new this(element, ...additional_args));\n }\n return result;\n }\n}\nAbstractWraplet.debug = false;\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","AbstractWraplet","constructor","element","mapAlterCallback","this","isWraplet","__debugElementAccessors","map","defineChildrenMap","children","instantiateChildren","wraplets","push","accessElement","callback","id","item","selector","wrapletClass","Class","args","multiple","isRequired","required","name","childElements","querySelectorAll","length","debug","console","log","childWraplet","childElement","createWraplet","childTypeGuard","variable","Array","isArray","every","createWraplets","document","additional_args","result","foundElements"],"sourceRoot":""}
|
package/package.json
CHANGED