Comparing version 1.1.12 to 1.2.0
@@ -35,2 +35,18 @@ /** | ||
/** | ||
* Represents a component function. The function takes an element | ||
* as its first argument. It may optionally receive further props | ||
* arguments. It can return anything. | ||
*/ | ||
interface IComponent { | ||
(element: Element, ...props: any[]): any; | ||
} | ||
/** | ||
* Represents an object that is used to register multiple components | ||
* at once. The object keys become component names and the values become | ||
* component functions. | ||
*/ | ||
interface IRegisterMap { | ||
[key: string | number]: IComponent; | ||
} | ||
/** | ||
* An Actribute class. Similar to a custom elements registry 'class'. | ||
@@ -104,4 +120,4 @@ */ | ||
* const act = new Actribute(fallbackProps); | ||
* act.register('comp1', (node, prop1) => node.textContent = prop1); | ||
* act.register('comp2', (node, prop2) => node.style.left = prop2); | ||
* act.register('comp1', (element, prop1) => element.textContent = prop1); | ||
* act.register('comp2', (element, prop2) => element.style.left = prop2); | ||
* | ||
@@ -112,4 +128,23 @@ * @param {string} name The component name | ||
*/ | ||
register(name: string, component: Function): Actribute; | ||
register(name: string, component: IComponent): Actribute; | ||
/** | ||
* Registers multiple components at once using an object that maps | ||
* component names to component functions. This is more succint than | ||
* repeated calls to `this.register()`. | ||
* @example | ||
* import { Actribute } from 'deleight/actribute'; | ||
* const fallbackProps = { | ||
* prop1: 'Fallback', prop4: 'Last resort' | ||
* }; | ||
* const act = new Actribute(fallbackProps); | ||
* act.registerAll({ | ||
* comp1: (element, prop1) => element.textContent = prop1, | ||
* comp2: (element, prop2) => element.style.left = prop2 | ||
* }); | ||
* | ||
* @param registerMap | ||
* @returns | ||
*/ | ||
registerAll(registerMap: IRegisterMap): this; | ||
/** | ||
* Recursively processes the node to identify and apply components. | ||
@@ -144,2 +179,2 @@ * | ||
export { Actribute }; | ||
export { Actribute, type IRegisterMap }; |
@@ -1,1 +0,1 @@ | ||
"use strict";function t(t,r){const e=r.split(".");let i=t[e[0].trim()];for(let r=1;r<e.length&&("object"==typeof i||"function"==typeof i);r++)i=(t=i)[e[r].trim()];return i}exports.Actribute=class{registry={};props;attrPrefix;constructor(t,r){this.props=t||{},this.attrPrefix=r||"c-"}register(t,r){return this.registry[t]=r,this}process(r,e,i){e||(e={}),void 0===i&&(i=" ");let s,o,n,f=[],h=!1;for(let{name:p,value:c}of Array.from(r.attributes))if(p.startsWith(this.attrPrefix)){if(h=!0,s=p.substring(this.attrPrefix.length),!this.registry.hasOwnProperty(s))throw new Error(`The component "${s}" was not found in the registry.`);if(f=[],c=c.trim(),c)for(o of c.split(i))if(o=o.trim(),""!==o){if(n=t(e,o)||t(this.props,o),void 0===n)throw new Error(`The property "${o}" was not found for the component "${s}" in the element "${r.toString()}"."`);f.push(n)}this.registry[s](r,...f)}if(!h)for(let t of Array.from(r.children))this.process(t,e,i);return this}}; | ||
"use strict";function t(t,r){const e=r.split(".");let i=t[e[0].trim()];for(let r=1;r<e.length&&("object"==typeof i||"function"==typeof i);r++)i=(t=i)[e[r].trim()];return i}exports.Actribute=class{registry={};props;attrPrefix;constructor(t,r){this.props=t||{},this.attrPrefix=r||"c-"}register(t,r){return(this.registry[t]=r)&&this}registerAll(t){return Object.assign(this.registry,t)&&this}process(r,e,i){e||(e={}),void 0===i&&(i=" ");let s,o,n,f=[],h=!1;for(let{name:p,value:c}of Array.from(r.attributes))if(p.startsWith(this.attrPrefix)){if(h=!0,s=p.substring(this.attrPrefix.length),!this.registry.hasOwnProperty(s))throw new Error(`The component "${s}" was not found in the registry.`);if(f=[],c=c.trim(),c)for(o of c.split(i))if(o=o.trim(),""!==o){if(n=t(e,o)||t(this.props,o),void 0===n)throw new Error(`The property "${o}" was not found for the component "${s}" in the element "${r.toString()}"."`);f.push(n)}this.registry[s](r,...f)}if(!h)for(let t of Array.from(r.children))this.process(t,e,i);return this}}; |
@@ -35,2 +35,18 @@ /** | ||
/** | ||
* Represents a component function. The function takes an element | ||
* as its first argument. It may optionally receive further props | ||
* arguments. It can return anything. | ||
*/ | ||
interface IComponent { | ||
(element: Element, ...props: any[]): any; | ||
} | ||
/** | ||
* Represents an object that is used to register multiple components | ||
* at once. The object keys become component names and the values become | ||
* component functions. | ||
*/ | ||
interface IRegisterMap { | ||
[key: string | number]: IComponent; | ||
} | ||
/** | ||
* An Actribute class. Similar to a custom elements registry 'class'. | ||
@@ -104,4 +120,4 @@ */ | ||
* const act = new Actribute(fallbackProps); | ||
* act.register('comp1', (node, prop1) => node.textContent = prop1); | ||
* act.register('comp2', (node, prop2) => node.style.left = prop2); | ||
* act.register('comp1', (element, prop1) => element.textContent = prop1); | ||
* act.register('comp2', (element, prop2) => element.style.left = prop2); | ||
* | ||
@@ -112,4 +128,23 @@ * @param {string} name The component name | ||
*/ | ||
register(name: string, component: Function): Actribute; | ||
register(name: string, component: IComponent): Actribute; | ||
/** | ||
* Registers multiple components at once using an object that maps | ||
* component names to component functions. This is more succint than | ||
* repeated calls to `this.register()`. | ||
* @example | ||
* import { Actribute } from 'deleight/actribute'; | ||
* const fallbackProps = { | ||
* prop1: 'Fallback', prop4: 'Last resort' | ||
* }; | ||
* const act = new Actribute(fallbackProps); | ||
* act.registerAll({ | ||
* comp1: (element, prop1) => element.textContent = prop1, | ||
* comp2: (element, prop2) => element.style.left = prop2 | ||
* }); | ||
* | ||
* @param registerMap | ||
* @returns | ||
*/ | ||
registerAll(registerMap: IRegisterMap): this; | ||
/** | ||
* Recursively processes the node to identify and apply components. | ||
@@ -144,2 +179,2 @@ * | ||
export { Actribute }; | ||
export { Actribute, type IRegisterMap }; |
@@ -1,1 +0,1 @@ | ||
class t{registry={};props;attrPrefix;constructor(t,r){this.props=t||{},this.attrPrefix=r||"c-"}register(t,r){return this.registry[t]=r,this}process(t,e,i){e||(e={}),void 0===i&&(i=" ");let o,s,n,f=[],h=!1;for(let{name:p,value:a}of Array.from(t.attributes))if(p.startsWith(this.attrPrefix)){if(h=!0,o=p.substring(this.attrPrefix.length),!this.registry.hasOwnProperty(o))throw new Error(`The component "${o}" was not found in the registry.`);if(f=[],a=a.trim(),a)for(s of a.split(i))if(s=s.trim(),""!==s){if(n=r(e,s)||r(this.props,s),void 0===n)throw new Error(`The property "${s}" was not found for the component "${o}" in the element "${t.toString()}"."`);f.push(n)}this.registry[o](t,...f)}if(!h)for(let r of Array.from(t.children))this.process(r,e,i);return this}}function r(t,r){const e=r.split(".");let i=t[e[0].trim()];for(let r=1;r<e.length&&("object"==typeof i||"function"==typeof i);r++)i=(t=i)[e[r].trim()];return i}export{t as Actribute}; | ||
class t{registry={};props;attrPrefix;constructor(t,r){this.props=t||{},this.attrPrefix=r||"c-"}register(t,r){return(this.registry[t]=r)&&this}registerAll(t){return Object.assign(this.registry,t)&&this}process(t,e,i){e||(e={}),void 0===i&&(i=" ");let s,o,n,f=[],h=!1;for(let{name:p,value:a}of Array.from(t.attributes))if(p.startsWith(this.attrPrefix)){if(h=!0,s=p.substring(this.attrPrefix.length),!this.registry.hasOwnProperty(s))throw new Error(`The component "${s}" was not found in the registry.`);if(f=[],a=a.trim(),a)for(o of a.split(i))if(o=o.trim(),""!==o){if(n=r(e,o)||r(this.props,o),void 0===n)throw new Error(`The property "${o}" was not found for the component "${s}" in the element "${t.toString()}"."`);f.push(n)}this.registry[s](t,...f)}if(!h)for(let r of Array.from(t.children))this.process(r,e,i);return this}}function r(t,r){const e=r.split(".");let i=t[e[0].trim()];for(let r=1;r<e.length&&("object"==typeof i||"function"==typeof i);r++)i=(t=i)[e[r].trim()];return i}export{t as Actribute}; |
{ | ||
"name": "deleight", | ||
"version": "1.1.12", | ||
"version": "1.2.0", | ||
"description": "A group of 8 libraries for writing accessible and joyfully interactive web applications with traditional HTML, CSS and JavaScript.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -36,5 +36,3 @@ # Deleight | ||
*NB: Fully tested* | ||
## Domitory | ||
@@ -57,5 +55,3 @@ | ||
*NB: Fully tested* | ||
## Eventivity | ||
@@ -84,3 +80,2 @@ | ||
*NB: Fully tested* | ||
@@ -107,5 +102,3 @@ ## OneToMany | ||
*NB: Fully tested* | ||
## Apriori | ||
@@ -120,5 +113,3 @@ | ||
*NB: Fully tested* | ||
## Sophistry | ||
@@ -134,5 +125,3 @@ | ||
*NB: Fully tested* | ||
## Generational | ||
@@ -151,5 +140,3 @@ | ||
*NB: Fully tested* | ||
## Actribute | ||
@@ -185,3 +172,2 @@ | ||
*NB: Fully tested* | ||
@@ -201,5 +187,3 @@ ## Withy | ||
*NB: Fully tested* | ||
## Installation | ||
@@ -206,0 +190,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
128791
2592
232