@twobirds/microcomponents 0.0.21 → 0.0.23
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/.gitlab-ci.yml +1 -0
- package/README.md +31 -12
- package/assets/documentation/MicroComponents.md +228 -0
- package/assets/my-tag.css +4 -0
- package/assets/test.html +5 -1
- package/dist/MC.d.ts +32 -0
- package/dist/MC.d.ts.map +1 -0
- package/dist/MC.min.js +414 -0
- package/dist/MC.ts +350 -0
- package/dist/McEvent.d.ts +15 -0
- package/dist/McEvent.d.ts.map +1 -0
- package/dist/McEvent.ts +96 -0
- package/dist/autoloader.d.ts +2 -0
- package/dist/autoloader.d.ts.map +1 -0
- package/dist/autoloader.ts +98 -0
- package/dist/customElements.d.ts +5 -0
- package/dist/customElements.d.ts.map +1 -0
- package/dist/customElements.min.js +1 -0
- package/dist/customElements.ts +67 -0
- package/dist/customObservables.d.ts +3 -0
- package/dist/customObservables.d.ts.map +1 -0
- package/dist/customObservables.min.js +1 -0
- package/dist/customObservables.ts +340 -0
- package/dist/customSelectors.d.ts +108 -0
- package/dist/customSelectors.d.ts.map +1 -0
- package/dist/customSelectors.min.js +1 -0
- package/dist/customSelectors.ts +1634 -0
- package/dist/formValues.d.ts +4 -0
- package/dist/formValues.d.ts.map +1 -0
- package/dist/formValues.ts +275 -0
- package/dist/formvValues.min.js +1 -0
- package/dist/helpers.d.ts +11 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.ts +173 -0
- package/dist/microcomponents.d.ts +7 -25
- package/dist/microcomponents.d.ts.map +1 -1
- package/dist/microcomponents.es3.d.ts +1 -20
- package/dist/microcomponents.es3.d.ts.map +1 -1
- package/dist/microcomponents.min.js +1 -38
- package/dist/microcomponents.ts +8 -216
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/package.json +11 -7
- package/public/MC.js +273 -0
- package/public/MC.min.js +414 -0
- package/public/MCbundle.js +8 -0
- package/public/MCbundle.min.js +1 -0
- package/public/McEvent.js +74 -0
- package/public/MicroComponents.svg +15 -0
- package/public/assets/search.js +1 -1
- package/public/autoloader.js +57 -0
- package/public/classes/MC.DC.html +247 -0
- package/public/classes/MC.MC.html +150 -0
- package/public/classes/MC.McBase.html +123 -0
- package/public/classes/MCbundle.McEvent.html +184 -0
- package/public/customElements.js +48 -0
- package/public/customElements.min.js +1 -0
- package/public/customObservables.js +255 -0
- package/public/customObservables.min.js +1 -0
- package/public/customSelectors.js +1088 -0
- package/public/customSelectors.min.js +1 -0
- package/public/documentation/MicroComponents.md +228 -0
- package/public/formValues.js +211 -0
- package/public/formvValues.min.js +1 -0
- package/public/functions/MC.addListener.html +73 -0
- package/public/functions/MC.removeListener.html +69 -0
- package/public/functions/MCbundle._d.html +85 -0
- package/public/functions/MCbundle._t.html +85 -0
- package/public/functions/MCbundle.debounce.html +85 -0
- package/public/functions/MCbundle.deepEqual.html +85 -0
- package/public/functions/MCbundle.defineCE.html +98 -0
- package/public/functions/MCbundle.formValues.html +89 -0
- package/public/functions/MCbundle.getCE.html +83 -0
- package/public/functions/MCbundle.htmlToElements.html +83 -0
- package/public/functions/MCbundle.isObject.html +83 -0
- package/public/functions/MCbundle.kebabToPascal.html +83 -0
- package/public/functions/MCbundle.makeCO.html +85 -0
- package/public/functions/MCbundle.nameSpace.html +89 -0
- package/public/functions/MCbundle.parse.html +85 -0
- package/public/helpers.js +128 -0
- package/public/index.html +22 -13
- package/public/interfaces/MC.HTMLMcElement.html +3605 -0
- package/public/interfaces/MCbundle.DSelector.html +1010 -0
- package/public/interfaces/MCbundle.LooseObject.html +80 -0
- package/public/interfaces/MCbundle.TSelector.html +709 -0
- package/public/microcomponents.es3.js +348 -0
- package/public/microcomponents.js +8 -176
- package/public/microcomponents.min.js +1 -0
- package/public/modules/MC.html +84 -0
- package/public/modules/MCbundle.html +133 -0
- package/public/modules.html +4 -4
- package/public/my-tag.css +4 -0
- package/public/test.html +5 -1
- package/public/test.js +100 -202
- package/public/types/MCbundle.selection.html +74 -0
- package/public/types/MCbundle.singleSelector.html +74 -0
- package/src/MC.ts +350 -0
- package/src/McEvent.ts +96 -0
- package/src/autoloader.ts +98 -0
- package/src/customElements.ts +67 -0
- package/src/customObservables.ts +340 -0
- package/src/customSelectors.ts +1634 -0
- package/src/formValues.ts +275 -0
- package/src/helpers.ts +173 -0
- package/src/microcomponents.es3.js +353 -82
- package/src/microcomponents.ts +8 -216
- package/src/test.js +137 -218
- package/tsconfig.json +2 -2
- package/typedoc.json +1 -1
- package/webpack.config.js +233 -0
- package/dist/microcomponents.es3.js +0 -96
- package/dist/microcomponents.es3.min.js +0 -15
- package/dist/microcomponents.js +0 -176
- package/public/classes/microcomponents.MC.html +0 -313
- package/public/classes/microcomponents_es3.MC.html +0 -336
- package/public/functions/microcomponents_es3.__isEmpty.html +0 -60
- package/public/modules/microcomponents.html +0 -57
- package/public/modules/microcomponents_es3.html +0 -60
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.customSelectors=t():e.customSelectors=t()}(this,(()=>(()=>{"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,{$d:()=>E,$t:()=>m});var r=new Function("try {return this===window;}catch(e){ return false;}");let n=new Set;r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>n.add(e)));var a=new Function("try {return this===window;}catch(e){ return false;}");let s=new Set;function i(e,t,r,n=!1,a=!1){let s={once:!1};n&&(s.capture=n),a&&(s.once=a),e.addEventListener(t,r,s)}function o(e,t,r){e.removeEventListener(t,r)}a()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>s.add(e)));const c=e=>{let t=new Set;return e.forEach((e=>{(e=e.trim()).split(" ").forEach((e=>{""!==e&&t.add(e)}))})),Array.from(t)},l=e=>{let t=E("input,select,textarea",e).array,r={};return t.forEach((t=>{const n=t.getAttribute("name")||"undefined";if(n){let a;switch((e=>e instanceof HTMLInputElement?"input":e instanceof HTMLSelectElement?"select":e instanceof HTMLTextAreaElement?"textarea":"")(t)){case"input":a=new f(t,e),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;case"select":a=new u(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;case"textarea":a=new d(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val=e}});break;default:console.warn("handler missing:",n,"for",t)}}})),r};class h{constructor(e){}}class f extends h{#e;#t;#r;constructor(e,t){super(e),this.#e=e,this.#t=e.type,this.#r=t}get val(){let e,t=this;switch(t.#t){case"radio":const r=E(`input[type="radio"][name="${this.#e.getAttribute("name")}"]`,this.#r).filter((e=>e.checked));return r.length?(e=r.array[0],e.value):"";case"checkbox":return t.#e.checked;default:return t.#e.value}return""}set val(e){let t=this;switch(t.#t){case"radio":const r=`input[type="radio"][name="${this.#e.getAttribute("name")}"]`,n=E(r,this.#r);if(!n.length)return;if(""===e)return void n.forEach((e=>{e.checked&&(e.checked=!1)}));const a=n.filter((t=>t.getAttribute("value")===e));if(!a.length)return;return void(a.array[0].checked=!0);case"checkbox":t.#e.checked=e;break;default:t.#e.value=e}}}class u extends h{#e;#n=!1;constructor(e){super(e),this.#e=e,this.#n="select-multiple"===e.type}get val(){const e=[];return E(this.#e.querySelectorAll("option")).filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#n?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,E(this.#e.querySelectorAll("option")).forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected",!0),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class d extends h{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}}class p{#a=new Set;get set(){return this.#a}get array(){return Array.from(this.#a)}set set(e){this.#a=e}get length(){return this.#a.size}constructor(e,t=document.body){if(new Set,!e)return this}$t(e){let t=new y;return this.#a.forEach((e=>{e._mc&&Object.values(e._mc).forEach((e=>{t.set.add(e)}))})),e&&t.filter((t=>t.nameSpace===e)),t}add(e,t){let r=this;return E(e,t).forEach((e=>{r.#a.add(e)})),r}addClass(...e){return e=c(e),this.forEach((t=>{t.classList.add(...e)})),this}after(e,t){let r=this,n=E(e,t);return n.length?(n.first().forEach((e=>{r.array.reverse().forEach((t=>{t.after(e)}))})),r):r}append(e,t){let r=this.array[0],n=E(e,t);return r&&n.forEach((e=>{r.append(e)})),this}appendTo(e,t){let r=E(e,t).array[0];return r&&this.forEach((e=>{r.append(e)})),this}attr(e,t){let r=this,n={};return r.length?arguments.length?"string"==typeof e?void 0===t?[...r.set][0].getAttribute(e):null===t?([...r.set].forEach((t=>{t.removeAttribute(e)})),r):("object"==typeof t&&(t=JSON.stringify(t)),[...r.set].forEach((r=>{r.setAttribute(e,t)})),r):"object"==typeof e?([...r.set].forEach((t=>{Object.keys(e).forEach((r=>{E(t).attr(r,e.key)}))})),r):r:(Array.from([...r.set][0].attributes).forEach((e=>{n[e.name]=e.value})),n):r}before(e,t){let r=this,n=E(e,t);return n.length?(n.first().forEach((e=>{r.forEach((t=>{t.before(e)}))})),r):r}children(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{Array.from(e.children).forEach((e=>{n.add(e)}))})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}descendants(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{e.querySelectorAll("*").forEach((e=>{n.add(e)}))})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}empty(){return this.filter((e=>!1))}first(e,t){let r=this,n=new Set,a=!1;return e&&(a=E(e,t)),r.#a.forEach((e=>{e.parentNode&&n.add(e.parentNode.children[0])})),r=E([...n]),e&&r.filter((e=>a.has(e))),r}has(e){return this.#a.has(e)}hasClass(...e){return e=c(e),this.every((e=>Array.from(e.classList).every((t=>e.contains(t)))))}html(e){let t=this;return e?(t.forEach((t=>{t.parentNode?t.innerHTML=e:(()=>{console.warn("Cannot access the .innerHTML of a HTMLElement that hasnt been inserted yet",t),console.trace(t,this),console.info("If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!","color: blue;")})()})),t):t.array[0].innerHTML}last(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{let t=e.parentNode?.children;t&&n.add(Array.from(t).at(-1))})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}next(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),a=r.indexOf(e)+1;a<r.length&&n.add(r.at(a))}})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}normalize(){return this.#a.forEach((e=>{e.normalize()})),this}off(e,t){let r=e.indexOf(" ")>-1?e.split(" "):[e];return this.array.forEach((e=>{r.forEach((function(r){o(e,r,t)}))})),this}on(e,t,r=!1,n=!1){let a=this,s=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function o(){o.cb.apply(a,Array.from(arguments))}return o.cb=t,a.forEach((e=>{s.forEach((function(t){i(e,t,o,r,n)}))})),o}one(e,t,r=!1){let n=this,a=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function s(){s.cb.apply(n,Array.from(arguments))}return s.cb=t,n.forEach((e=>{a.forEach((function(t){i(e,t,s,r,!0)}))})),s}parent(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{e.parentNode&&"HTML"!==e.parentNode.tagName&&n.add(e.parentNode)})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}parents(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{let t=e;for(;t.parentNode&&"HTML"!==t.parentNode.tagName;)t=t.parentNode,n.add(t)})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}prepend(e,t){let r=this.array[0],n=E(e,t);return r&&n.forEach((e=>{r.prepend(e)})),this}prev(e,t){let r=this,n=new Set;if(r.#a.forEach((e=>{let t=e.parentNode?.children;if(t){let r=Array.from(t),a=r.indexOf(e)-1;a>-1&&n.add(r.at(a))}})),r=E([...n]),e){let n=E(e,t);r.filter((e=>n.has(e)))}return r}removeClass(...e){return e=c(e),this.forEach((t=>{t.classList.remove(...e)})),this}text(e){let t=this;return e?(t.forEach((t=>{t.parentNode?t.innerText=e:(()=>{console.warn("Cannot access the .textContent of a HTMLElement that hasnt been inserted yet",t),console.trace(t,this),console.info("If you called this from inside a Web Component constructor, consider using the %c[connected] event callback!","color: blue;")})()})),t):t.array[0].innerText??""}toggleClass(...e){return e=c(e),this.forEach((t=>{t.classList.toggle(...e)})),this}trigger(e,t={},r=!1,n=!1,a=!1){let s,i={bubbles:r,cancelable:n,composed:a},o=e.indexOf(" ")>-1?e.split(" "):[e];return this.#a.forEach((e=>{o.forEach((function(r){s=new Event(r,i),s.data=t,e.dispatchEvent(s)}))})),this}val(e,t){if(!this.length)return this;const r=this;let n,a=l(r.array[0]);var s;return e?null!=(s=e)&&"object"==typeof s?(Object.assign(a,e),n=r):"string"==typeof e&&(void 0===t?n=a[e]:(a[e]=t,n=r)):n=Object.assign({},a),n}values(e){const t=this;let r={};if(!t.length)return console.warn("no dom selection to search inputs in"),{};let n=l(t.array[0]);return Object.keys(n).forEach((e=>{r[e]=n[e]})),0===Object.keys(r).length&&console.warn("no inputs in this dom selection",t.array[0],r),e&&Object.keys(e).forEach((t=>{n.hasOwnProperty(t)&&(console.log("key found",t),n[t]=e[t])})),structuredClone(Object.assign(n))}at(e){return E(this.array.at(e))}concat(e){let t=this;return(e instanceof p?e.array:e).forEach((e=>{t.#a.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return this.#a=new Set(this.array.filter(e,t)),this}forEach(e,t){return this.array.forEach(e,t),this}includes(e){return-1!==this.array.indexOf(e,0)}indexOf(e,t){return this.array.indexOf(e,t)}map(e,t){return this.array.map(e,t)}pop(){return this.array.pop()}push(...e){return e.forEach((e=>{this.#a.add(e)})),this}shift(){let e=this,t=e.#a.size?e.array[0]:void 0;return t&&e.#a.delete(t),t}slice(e,t){return E(this.array.slice(e,t))}some(e,t){return this.array.some(e,t)}splice(e,t,...r){let n=this.array;return n.splice(e,t,...r),E(n)}}class y{#a=new Set;get set(){return this.#a}get array(){return Array.from(this.#a)}set set(e){this.#a=e}get length(){return this.#a.size}set length(e){}constructor(e,t=document.body){if(!e)return this;E(e,t).forEach((e=>{m(e).forEach((e=>{this.#a.add(e)}))}))}$d(e,t=document.body){let r=new p,n=new Set,a=!!e||!1,s=new Set;return a&&(s=E(e,t).set),this.#a.forEach((e=>{a&&!s.has(e._tg)||n.add(e._tg)})),r.set=n,r}children(e){let t=this,r=new Set;return t.#a.forEach((t=>{t.children(e).forEach((e=>{r.add(e)}))})),t.#a=r,t}descendants(e){let t=this,r=new Set;return t.#a.forEach((t=>{t.descendants(e).forEach((e=>{r.add(e)}))})),t.#a=r,t}first(e){let t=this,r=new Set;return t.#a.forEach((e=>{e.parent().children().$d().first().$t().forEach((e=>{r.add(e)}))})),t.#a=r,e&&t.filter((t=>t.nameSpace=e)),t}has(e){return this.#a.has(e)}last(e){let t=this,r=new Set;return t.#a.forEach((e=>{e.parent().children().$d().last().$t().forEach((e=>{r.add(e)}))})),t.#a=r,e&&t.filter((t=>t.nameSpace=e)),t}next(e){let t=this,r=new Set;return t.#a.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.nextElementSibling;)t=t.nextElementSibling,n.add(t);m([...n]).$d().first().$t().forEach((e=>{r.add(e)}))})),t.#a=r,e&&t.filter((t=>t.nameSpace=e)),t}ns(e){return this.filter((t=>t.nameSpace===e))}off(e,t){let r=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];return this.$d().array.forEach((e=>{r.forEach((function(r){o(e,`[TB]${r}`,t)}))})),this}on(e,t,r=!1){let n=this,a=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function s(){s.cb.apply(n,Array.from(arguments))}return s.cb=t,n.forEach((e=>{a.forEach((function(t){i(e._tg,`[TB]${t}`,s,!1,r)}))})),s}one(e,t){let r=this,n=e.indexOf(" ")>-1?e.split(" ").filter((e=>""!==e)):[e];function a(){a.cb.apply(r,Array.from(arguments))}return a.cb=t,r.forEach((e=>{n.forEach((function(t){i(e._tg,`[TB]${t}`,a,!1,!0)}))})),a}parent(e){let t=this,r=new Set;return t.#a.forEach((t=>{t.parent(e).forEach((e=>{r.add(e)}))})),t.#a=r,t}parents(e){let t=this,r=new Set;return t.#a.forEach((t=>{t.parents(e).forEach((e=>{r.add(e)}))})),t.#a=r,t}prev(e){let t=this,r=new Set;return t.#a.forEach((e=>{let t,n=new Set;for(t=e._tg;null!==t.previousElementSibling;)t=t.previousElementSibling,n.add(t);m([...n]).$d().last().$t().forEach((e=>{r.add(e)}))})),t.#a=r,e&&t.filter((t=>t.nameSpace=e)),t}trigger(e,t={},r="l"){return this.forEach((n=>{n.trigger(e,t,r)})),this}at(e){return m(this.array.at(e))}concat(e){let t=this;return e.forEach((e=>{t.#a.add(e)})),t}entries(){return this.array.entries()}every(e,t){return this.array.every(e,t)}filter(e,t){return m(this.array.filter(e,t))}forEach(e,t){return this.array.forEach(e,t),this}includes(e){return-1!==this.array.indexOf(e)}indexOf(e,t){return this.array.indexOf(e,t)}map(e,t){return this.array.map(e,t)}pop(){let e=this.array,t=e.pop();return this.#a=new Set(e),t}push(e){return this.#a.add(e),this}shift(){let e=this.array.shift();return this.#a.delete(e),e}slice(e,t){return m(this.array.slice(e,t))}some(e,t){return this.array.some(e,t)}splice(e,t,...r){let n=this.array.splice(e,t,...r);return m(n)}}const E=(e,t=document)=>{let r=new Set;return e instanceof Array?(e.forEach((e=>{E(e,t).forEach((e=>{r.add(e)}))})),new p([...r])):new p(e,t)},m=(e,t=document)=>E(e,t).$t();return t})()));
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Micro Components
|
|
2
|
+
|
|
3
|
+
This system allows you to to define **Micro Components** and attach them to DOM elements or other Micro Components.
|
|
4
|
+
|
|
5
|
+
The module exports 2 classes:
|
|
6
|
+
- **MC**: Micro Component ( not DOM related, works on the server also )
|
|
7
|
+
- **DC**: Dom Component ( extends MC and adds DOM related methods, client only )
|
|
8
|
+
|
|
9
|
+
## tldr;
|
|
10
|
+
|
|
11
|
+
In general when coding with this system, you create classes that extend either the **DC** or **MC** class provided here.
|
|
12
|
+
|
|
13
|
+
**If your functionality needs to access the DOM**, e.g. to find other DC instances, **your class extends DC**.
|
|
14
|
+
|
|
15
|
+
**Otherwise** - and always on the server - **your class extends MC**.
|
|
16
|
+
|
|
17
|
+
In any case, your class instances will contain a property **"_mc"** where you can put in other MCs.
|
|
18
|
+
|
|
19
|
+
Also your class instances will have a readonly **"target"** property that is back reference to the instance they are contained in.
|
|
20
|
+
|
|
21
|
+
- if your class extends **DC: "target"** will refer the **DOM HTMLElement your instance resides in**.
|
|
22
|
+
- if your class extends **MC: "target"** will refer the **parent MC your instance resides in**.
|
|
23
|
+
|
|
24
|
+
As an application programmer you should understand **MC** and **DC** methods and the structure they provide:
|
|
25
|
+
- **MC** encapsule functionality in a reusable way. Think DRY, and SOLID because we talk about objects.
|
|
26
|
+
- **MC** can use observables to provide data driven workflow between multiple MCs.
|
|
27
|
+
- **DC** use observables and formValues to provide 1-way and 2-way binding to the DOM.
|
|
28
|
+
- **DC** have selectors to find other DCs in the DOM.
|
|
29
|
+
|
|
30
|
+
## MC() Class overview
|
|
31
|
+
|
|
32
|
+
**Instance Properties**
|
|
33
|
+
- `.target`: readonly, a getter returning the DOM element or parent MC instance your instance resides in
|
|
34
|
+
- `._mc`: a hash object that contains inner micro components
|
|
35
|
+
|
|
36
|
+
- **Instance Methods:**
|
|
37
|
+
- `.trigger( eventName, data )`: trigger an event on this instance
|
|
38
|
+
|
|
39
|
+
## DC() Class Overview
|
|
40
|
+
|
|
41
|
+
- **Static Methods:**
|
|
42
|
+
- `DC.add( DomElement, key, mc)`: Add a DC to an HTMLElement.
|
|
43
|
+
- `DC.remove( DomElement, key )`: Remove a DC from an HTMLElement.
|
|
44
|
+
- `DC.trigger( eventName, DomElement, data, bubble )`: trigger an event, handles directional traversal in the DOM.
|
|
45
|
+
|
|
46
|
+
**Instance Properties**
|
|
47
|
+
|
|
48
|
+
( inherited from MC )
|
|
49
|
+
- `.target`: readonly, a getter returning the DOM element the instance resides in
|
|
50
|
+
- `._mc`: a hash object that contains inner MCs
|
|
51
|
+
|
|
52
|
+
- **Instance Methods:**
|
|
53
|
+
- `.parent(search?)`: Get parent DCs.
|
|
54
|
+
- `.ancestors(search?)`: Get ancestor DCs.
|
|
55
|
+
- `.children(search?)`: Get child DCs.
|
|
56
|
+
- `.descendants(search?)`: Get descendant DCs.
|
|
57
|
+
- `.autoAttachListeners()`: methods in your MC that start with "on[A-Z]" or "one[A-Z]" and describe native DOM events (e.g. "onClick") will be added to the DOM Element as listeners.
|
|
58
|
+
|
|
59
|
+
(inherited from MC )
|
|
60
|
+
- `.trigger( eventName, data, bubble )`: trigger an event on "this", handles directional bubbling in the DOM.
|
|
61
|
+
|
|
62
|
+
### Typical Workflow
|
|
63
|
+
|
|
64
|
+
1. **Attach DCs** to HTMLElements using `DC.add()`.
|
|
65
|
+
2. **Access** other DCs by their property key or navigating through DOM (e.g., `ancestors()`, `children()`, etc.) **and use their inner functionality**.
|
|
66
|
+
|
|
67
|
+
# Attaching Micro Components to a DOM element
|
|
68
|
+
|
|
69
|
+
To attach a micro component to an HTML element, use the `DC.add()` static function.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const myElement = document.getElementById('myDiv');
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
usage with classes, both PUBLIC and PRIVATE
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
// internal MC class
|
|
79
|
+
MyInnerClass = class extends MC{
|
|
80
|
+
constructor(target){
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// external DC class
|
|
85
|
+
MyPublicClass = class extends DC{
|
|
86
|
+
constructor(target){
|
|
87
|
+
// add a internal inner MC
|
|
88
|
+
this._mc.myInnerComponent = new MyInnerClass( this );
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// attach a DC
|
|
93
|
+
DC.add( myElement, 'myDcComponent', new MyClass( myElement ) );
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- After you added a micro component using this function, the **HTMLElement will contain a property `_mc`** which contains the external MC instances.
|
|
97
|
+
- Also the **HTMLElement then has an attribute '_mc'** which will indicate that at least one micro component is attached to this dom element.
|
|
98
|
+
|
|
99
|
+
# Removing a top level Micro Component from a DOM element
|
|
100
|
+
|
|
101
|
+
Micro components can be removed using the `DC.remove()` static method.
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
DC.remove( myDomElement, 'myComponent');
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**When all micro components are removed** (the _mc object has no more properties), the **`_mc` attribute is also removed** from the HTML element.
|
|
108
|
+
|
|
109
|
+
# Retrieve all top level Micro Components from a DOM element
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
const target = document.querySelector( 'div' );
|
|
113
|
+
console.log(target._mc);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
To retrieve a specific micro component by its key:
|
|
117
|
+
```javascript
|
|
118
|
+
const target = document.querySelector( 'div' );
|
|
119
|
+
const specificInstance = target._mc?.myPublicComponent;
|
|
120
|
+
console.log(specificInstance);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Trigger an Event on all DCs
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
const target = document.querySelector( 'div' );
|
|
127
|
+
DC.trigger( target, '<eventName>', data | null, bubble );
|
|
128
|
+
|
|
129
|
+
// bubble is any combination of 'lud', meaning [local|up|down]
|
|
130
|
+
// local is only "this", "up" traverses towards root, "down" traverses the inner DOM.
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
# Methods you can use in your Micro Component Instances
|
|
134
|
+
|
|
135
|
+
## Retrieving Inner Micro Components
|
|
136
|
+
|
|
137
|
+
You can retrieve an inner micro component by using the ._mc property.
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
const innerComponent = this._mc.myInnerComponent;
|
|
141
|
+
console.log(innerComponent);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**The following methods hop over HTMLElements that DO NOT contain micro components.**
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
## Navigating Parent and Ancestor Micro Components
|
|
148
|
+
|
|
149
|
+
The `.parent()` and `.ancestors()` methods allow you to retrieve micro components attached to parent elements.
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
const parentMcs = this.parent();
|
|
153
|
+
console.log(parentMcs); // all micro components of the closest ancestor that has an _mc attribute
|
|
154
|
+
|
|
155
|
+
const allAncestorsMcs = this.ancestors();
|
|
156
|
+
console.log(allAncestorsMcs); // all ancestor micro components up to document root.
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
To retrieve specific micro component(s) attached to ancestors:
|
|
160
|
+
```javascript
|
|
161
|
+
const specificAncestorMc = this.ancestors('myComponent');
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Retrieving Child and Descendant Micro Components
|
|
165
|
+
|
|
166
|
+
The `.children()` and `.descendants()` methods retrieve micro components attached to child elements or any descendants.
|
|
167
|
+
```javascript
|
|
168
|
+
const childComponents = this.children();
|
|
169
|
+
console.log(childComponents); // an array of nearest micro components in the inner DOM
|
|
170
|
+
|
|
171
|
+
const descendantComponents = this.descendants();
|
|
172
|
+
console.log(descendantComponents); // an array of all descendant micro components in the inner DOM
|
|
173
|
+
|
|
174
|
+
//To search for a specific micro component by key:
|
|
175
|
+
const specificMcs = this.descenants('specificMc');
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Trigger Events on MCs
|
|
179
|
+
```javascript
|
|
180
|
+
// trigger an event on yourself
|
|
181
|
+
this
|
|
182
|
+
.trigger('myEvent', data); // calls the "onMyEvent" callback
|
|
183
|
+
|
|
184
|
+
// trigger an event on your external siblings
|
|
185
|
+
DC
|
|
186
|
+
.trigger( this.target, 'myEvent', data); // calls the "onMyEvent" callback on all externalh MCs that listen to it
|
|
187
|
+
|
|
188
|
+
// trigger an event on some remote DOM instance(s)
|
|
189
|
+
DC
|
|
190
|
+
.trigger(
|
|
191
|
+
this.target, // the DOM node your are in
|
|
192
|
+
'myEvent', // event name
|
|
193
|
+
null, // no data
|
|
194
|
+
'd' // into descendants
|
|
195
|
+
); // calls the "onMyEvent" callback
|
|
196
|
+
|
|
197
|
+
// trigger an event on some remote DC instance that you know the name of
|
|
198
|
+
this
|
|
199
|
+
.descendants('myRemoteInstance') // into my inner HTML
|
|
200
|
+
?.[0] // hopefully we found one
|
|
201
|
+
.trigger(
|
|
202
|
+
'myEvent', // event name
|
|
203
|
+
null, // no data
|
|
204
|
+
);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Automatically attach Listener Methods to the DOM
|
|
208
|
+
|
|
209
|
+
On any **DC** instance, you can call **.autoAttachListeners()** in the constructor.
|
|
210
|
+
|
|
211
|
+
Any methods you define in your code that start with **"on"** or **"one"**, and also match DOM event names, will be called accordingly:
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
class MyEventTarget extends MC {
|
|
215
|
+
constructor(target) {
|
|
216
|
+
super(target);
|
|
217
|
+
this.autoAttachListeners();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
onClick(ev) {
|
|
221
|
+
console.log("onClick", ev);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let myFirstDiv = document.querySelector('div');
|
|
226
|
+
DC.add( myFirstDiv, 'myEventTarget', new MyEventTarget( myFirstDiv ) );
|
|
227
|
+
// now wait for somebody to click on that <div>
|
|
228
|
+
```
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
import { addListener } from './MC.js';
|
|
3
|
+
const getInputName = (e) => {
|
|
4
|
+
let ret = e instanceof HTMLInputElement
|
|
5
|
+
? 'input'
|
|
6
|
+
: e instanceof HTMLSelectElement
|
|
7
|
+
? 'select'
|
|
8
|
+
: e instanceof HTMLTextAreaElement
|
|
9
|
+
? 'textarea'
|
|
10
|
+
: '';
|
|
11
|
+
return ret;
|
|
12
|
+
};
|
|
13
|
+
class InputBase {
|
|
14
|
+
constructor(e) {
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
const getInputHandlers = (e) => {
|
|
18
|
+
let
|
|
19
|
+
//inputList = ( Array.from( e.querySelectorAll('*') ) as HTMLElement[] ).filter( i => isInputElement(i) ),
|
|
20
|
+
inputList = [...(e || document).querySelectorAll('input,select,textarea')], handlers = {};
|
|
21
|
+
inputList.forEach((i) => {
|
|
22
|
+
const name = i.getAttribute('name') || 'undefined';
|
|
23
|
+
if (name) {
|
|
24
|
+
let h;
|
|
25
|
+
switch (getInputName(i)) {
|
|
26
|
+
case 'input':
|
|
27
|
+
//console.log( i, 'is HTMLInputElement');
|
|
28
|
+
h = new InputHandler(i, e); // e = element to search radios in = radioBase
|
|
29
|
+
Object.defineProperty(handlers, name, {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
get: () => { return h.val; },
|
|
33
|
+
set: (value) => { h.val = value; }
|
|
34
|
+
});
|
|
35
|
+
break;
|
|
36
|
+
case 'select':
|
|
37
|
+
//console.log( i, 'is HTMLSelectElement');
|
|
38
|
+
h = new SelectHandler(i);
|
|
39
|
+
Object.defineProperty(handlers, name, {
|
|
40
|
+
enumerable: true,
|
|
41
|
+
configurable: true,
|
|
42
|
+
get: () => { return h.val; },
|
|
43
|
+
set: (value) => { h.val = value; }
|
|
44
|
+
});
|
|
45
|
+
break;
|
|
46
|
+
case 'textarea':
|
|
47
|
+
//console.log( i, 'is HTMLTextAreaElement');
|
|
48
|
+
h = new TextAreaHandler(i);
|
|
49
|
+
Object.defineProperty(handlers, name, {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
get: () => { return h.val; },
|
|
53
|
+
set: (value) => { h.val = value; }
|
|
54
|
+
});
|
|
55
|
+
break;
|
|
56
|
+
default:
|
|
57
|
+
console.warn('handler missing:', name, 'for', i);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return handlers;
|
|
63
|
+
};
|
|
64
|
+
class InputHandler extends InputBase {
|
|
65
|
+
#e;
|
|
66
|
+
#type;
|
|
67
|
+
#radioBase;
|
|
68
|
+
constructor(e, radioBase) {
|
|
69
|
+
super(e);
|
|
70
|
+
this.#e = e;
|
|
71
|
+
this.#type = e.type;
|
|
72
|
+
this.#radioBase = radioBase;
|
|
73
|
+
}
|
|
74
|
+
get val() {
|
|
75
|
+
let that = this, type = that.#type, ret;
|
|
76
|
+
switch (type) {
|
|
77
|
+
case 'radio':
|
|
78
|
+
const check = [...(this.#radioBase || document).querySelectorAll(`input[type="radio"][name="${this.#e.getAttribute('name')}"]`)]
|
|
79
|
+
.filter(e => e.checked);
|
|
80
|
+
if (!check.length)
|
|
81
|
+
return '';
|
|
82
|
+
ret = check?.[0];
|
|
83
|
+
return ret.value;
|
|
84
|
+
case 'checkbox':
|
|
85
|
+
return that.#e.checked;
|
|
86
|
+
default:
|
|
87
|
+
return that.#e.value;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
return '';
|
|
91
|
+
}
|
|
92
|
+
set val(value) {
|
|
93
|
+
let that = this, type = that.#type, ret;
|
|
94
|
+
switch (type) {
|
|
95
|
+
case 'radio':
|
|
96
|
+
const radios = [...(this.#radioBase || document).querySelectorAll(`input[type="radio"][name="${this.#e.getAttribute('name')}"]`)];
|
|
97
|
+
// console.log('set radios', selection, this.#radioBase, radios.array );
|
|
98
|
+
if (!radios.length)
|
|
99
|
+
return;
|
|
100
|
+
if (value === '') { // uncheck all
|
|
101
|
+
radios.forEach(r => { if (r.checked)
|
|
102
|
+
r.checked = false; });
|
|
103
|
+
//console.log('unset all radios', radios.array );
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const setRadioElement = radios.filter(r => r.getAttribute('value') === value);
|
|
107
|
+
if (!setRadioElement.length)
|
|
108
|
+
return;
|
|
109
|
+
// console.log('set this radio', setRadioElement.array );
|
|
110
|
+
(setRadioElement?.[0]).checked = true;
|
|
111
|
+
// console.log('done', setRadioElement.array );
|
|
112
|
+
return;
|
|
113
|
+
break;
|
|
114
|
+
case 'checkbox':
|
|
115
|
+
that.#e.checked = value;
|
|
116
|
+
break;
|
|
117
|
+
default:
|
|
118
|
+
that.#e.value = value;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
class SelectHandler extends InputBase {
|
|
125
|
+
#e;
|
|
126
|
+
#multi = false;
|
|
127
|
+
constructor(e) {
|
|
128
|
+
super(e);
|
|
129
|
+
this.#e = e;
|
|
130
|
+
this.#multi = e.type === 'select-multiple';
|
|
131
|
+
}
|
|
132
|
+
get val() {
|
|
133
|
+
const that = this, ret = [];
|
|
134
|
+
// get all options
|
|
135
|
+
const options = [...that.#e.querySelectorAll('option')]
|
|
136
|
+
.filter(o => o.selected)
|
|
137
|
+
.forEach(o => { if (o.selected)
|
|
138
|
+
ret.push(o.value); });
|
|
139
|
+
if (this.#multi)
|
|
140
|
+
return ret;
|
|
141
|
+
return ret.length ? ret[0] : '';
|
|
142
|
+
}
|
|
143
|
+
set val(value) {
|
|
144
|
+
const that = this;
|
|
145
|
+
value = typeof value === 'string' ? [value] : value;
|
|
146
|
+
//console.log('set values', value );
|
|
147
|
+
// set all options
|
|
148
|
+
const options = [...that.#e.querySelectorAll('option')]
|
|
149
|
+
.forEach(o => {
|
|
150
|
+
if (value.indexOf(o.value) > -1) {
|
|
151
|
+
o.setAttribute('selected', 'selected');
|
|
152
|
+
o.selected = true;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
o.removeAttribute('selected');
|
|
156
|
+
o.selected = false;
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
class TextAreaHandler extends InputBase {
|
|
163
|
+
#e;
|
|
164
|
+
constructor(e) {
|
|
165
|
+
super(e);
|
|
166
|
+
this.#e = e;
|
|
167
|
+
}
|
|
168
|
+
get val() {
|
|
169
|
+
return this.#e.value;
|
|
170
|
+
}
|
|
171
|
+
set val(value) {
|
|
172
|
+
this.#e.value = value;
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
export const formValues = (target, values = {}, mc, observable) => {
|
|
177
|
+
//console.log( 'values(', target, ',', values, ',', observable, ')' );
|
|
178
|
+
//console.log( 'values()', values );
|
|
179
|
+
let handlers = getInputHandlers(target);
|
|
180
|
+
function updateForm(values) {
|
|
181
|
+
Object
|
|
182
|
+
.keys(values)
|
|
183
|
+
.forEach((key) => {
|
|
184
|
+
if (handlers.hasOwnProperty(key) && values.hasOwnProperty(key)) {
|
|
185
|
+
//console.log( 'set value', key, values[key] );
|
|
186
|
+
handlers[key] = values[key];
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (Object.keys(values).length > 0) {
|
|
191
|
+
updateForm(values);
|
|
192
|
+
}
|
|
193
|
+
//console.log( 'set observable on form change', observable );
|
|
194
|
+
if (observable !== undefined) {
|
|
195
|
+
let obs = mc[observable];
|
|
196
|
+
if (!obs.constructor?.hasFormHandler) {
|
|
197
|
+
obs.constructor.hasFormHandler = true;
|
|
198
|
+
obs.observe(updateForm);
|
|
199
|
+
}
|
|
200
|
+
mc[observable].observe(() => { });
|
|
201
|
+
[...target.querySelectorAll('input, textarea, select')].forEach((e) => {
|
|
202
|
+
addListener(e, 'keyup', () => { mc[observable] = structuredClone(Object.assign(handlers)); });
|
|
203
|
+
addListener(e, 'change', () => { mc[observable] = structuredClone(Object.assign(handlers)); });
|
|
204
|
+
if (e instanceof HTMLSelectElement) {
|
|
205
|
+
addListener(e, 'select', () => { mc[observable] = structuredClone(Object.assign(handlers)); });
|
|
206
|
+
}
|
|
207
|
+
;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return observable ? mc[observable] : Object.assign({}, handlers);
|
|
211
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.formValues=t():e.formValues=t()}(this,(()=>(()=>{"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,{formValues:()=>d});var r=new Function("try {return this===window;}catch(e){ return false;}");let n=new Set;r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>n.add(e)));var o=new Function("try {return this===window;}catch(e){ return false;}");let s=new Set;function c(e,t,r,n=!1,o=!1){let s={once:!1};n&&(s.capture=n),o&&(s.once=o),e.addEventListener(t,r,s)}o()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>s.add(e)));class l{constructor(e){}}class a extends l{#e;#t;#r;constructor(e,t){super(e),this.#e=e,this.#t=e.type,this.#r=t}get val(){let e,t=this;switch(t.#t){case"radio":const r=[...(this.#r||document).querySelectorAll(`input[type="radio"][name="${this.#e.getAttribute("name")}"]`)].filter((e=>e.checked));return r.length?(e=r?.[0],e.value):"";case"checkbox":return t.#e.checked;default:return t.#e.value}return""}set val(e){let t=this;switch(t.#t){case"radio":const r=[...(this.#r||document).querySelectorAll(`input[type="radio"][name="${this.#e.getAttribute("name")}"]`)];if(!r.length)return;if(""===e)return void r.forEach((e=>{e.checked&&(e.checked=!1)}));const n=r.filter((t=>t.getAttribute("value")===e));if(!n.length)return;return void((n?.[0]).checked=!0);case"checkbox":t.#e.checked=e;break;default:t.#e.value=e}}}class i extends l{#e;#n=!1;constructor(e){super(e),this.#e=e,this.#n="select-multiple"===e.type}get val(){const e=[];return[...this.#e.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#n?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#e.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected","selected"),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class u extends l{#e;constructor(e){super(e),this.#e=e}get val(){return this.#e.value}set val(e){this.#e.value=e}}const d=(e,t={},r,n)=>{let o=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],r={};return t.forEach((t=>{const n=t.getAttribute("name")||"undefined";if(n){let o;switch((e=>e instanceof HTMLInputElement?"input":e instanceof HTMLSelectElement?"select":e instanceof HTMLTextAreaElement?"textarea":"")(t)){case"input":o=new a(t,e),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>o.val,set:e=>{o.val=e}});break;case"select":o=new i(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>o.val,set:e=>{o.val=e}});break;case"textarea":o=new u(t),Object.defineProperty(r,n,{enumerable:!0,configurable:!0,get:()=>o.val,set:e=>{o.val=e}});break;default:console.warn("handler missing:",n,"for",t)}}})),r})(e);function s(e){Object.keys(e).forEach((t=>{o.hasOwnProperty(t)&&e.hasOwnProperty(t)&&(o[t]=e[t])}))}if(Object.keys(t).length>0&&s(t),void 0!==n){let t=r[n];t.constructor?.hasFormHandler||(t.constructor.hasFormHandler=!0,t.observe(s)),r[n].observe((()=>{})),[...e.querySelectorAll("input, textarea, select")].forEach((e=>{c(e,"keyup",(()=>{r[n]=structuredClone(Object.assign(o))})),c(e,"change",(()=>{r[n]=structuredClone(Object.assign(o))})),e instanceof HTMLSelectElement&&c(e,"select",(()=>{r[n]=structuredClone(Object.assign(o))}))}))}return n?r[n]:Object.assign({},o)};return t})()));
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>addListener | Micro Components</title><meta name="description" content="Documentation for Micro Components"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script async src="../assets/search.js" id="search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar">
|
|
2
|
+
<div class="tsd-toolbar-contents container">
|
|
3
|
+
<div class="table-cell" id="tsd-search" data-base="..">
|
|
4
|
+
<div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
|
|
5
|
+
<div class="field">
|
|
6
|
+
<div id="tsd-toolbar-links"></div></div>
|
|
7
|
+
<ul class="results">
|
|
8
|
+
<li class="state loading">Preparing search index...</li>
|
|
9
|
+
<li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">Micro Components</a></div>
|
|
10
|
+
<div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header>
|
|
11
|
+
<div class="container container-main">
|
|
12
|
+
<div class="col-8 col-content">
|
|
13
|
+
<div class="tsd-page-title">
|
|
14
|
+
<ul class="tsd-breadcrumb">
|
|
15
|
+
<li><a href="../modules.html">Micro Components</a></li>
|
|
16
|
+
<li><a href="../modules/MC.html">MC</a></li>
|
|
17
|
+
<li><a href="MC.addListener.html">addListener</a></li></ul>
|
|
18
|
+
<h1>Function addListener</h1></div>
|
|
19
|
+
<section class="tsd-panel">
|
|
20
|
+
<ul class="tsd-signatures tsd-kind-function tsd-parent-kind-module">
|
|
21
|
+
<li class="tsd-signature tsd-anchor-link" id="addListener">add<wbr/>Listener<span class="tsd-signature-symbol">(</span>domNode<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Node</span>, eventName<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, handler<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">EventListenerOrEventListenerObject</span>, capture<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span>, once<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">void</span><a href="#addListener" aria-label="Permalink" class="tsd-anchor-icon"><svg class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none" id="icon-anchor-a"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5" id="icon-anchor-b"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5" id="icon-anchor-c"></path></svg></a></li>
|
|
22
|
+
<li class="tsd-description">
|
|
23
|
+
<div class="tsd-parameters">
|
|
24
|
+
<h4 class="tsd-parameters-title">Parameters</h4>
|
|
25
|
+
<ul class="tsd-parameter-list">
|
|
26
|
+
<li>
|
|
27
|
+
<h5>domNode: <span class="tsd-signature-type">Node</span></h5></li>
|
|
28
|
+
<li>
|
|
29
|
+
<h5>eventName: <span class="tsd-signature-type">string</span></h5></li>
|
|
30
|
+
<li>
|
|
31
|
+
<h5>handler: <span class="tsd-signature-type">null</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">EventListenerOrEventListenerObject</span></h5></li>
|
|
32
|
+
<li>
|
|
33
|
+
<h5>capture: <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> = false</span></h5></li>
|
|
34
|
+
<li>
|
|
35
|
+
<h5>once: <span class="tsd-signature-type">boolean</span><span class="tsd-signature-symbol"> = false</span></h5></li></ul></div>
|
|
36
|
+
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4><aside class="tsd-sources">
|
|
37
|
+
<ul>
|
|
38
|
+
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/3ccde69/src/MC.ts#L62">src/MC.ts:62</a></li></ul></aside></li></ul></section></div>
|
|
39
|
+
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
|
40
|
+
<div class="tsd-navigation settings">
|
|
41
|
+
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
|
|
42
|
+
<h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-text)"></path></svg> Settings</h3></summary>
|
|
43
|
+
<div class="tsd-accordion-details">
|
|
44
|
+
<div class="tsd-filter-visibility">
|
|
45
|
+
<h4 class="uppercase">Member Visibility</h4><form>
|
|
46
|
+
<ul id="tsd-filter-options">
|
|
47
|
+
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li>
|
|
48
|
+
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li>
|
|
49
|
+
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li>
|
|
50
|
+
<li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div>
|
|
51
|
+
<div class="tsd-theme-toggle">
|
|
52
|
+
<h4 class="uppercase">Theme</h4><select id="theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div>
|
|
53
|
+
<nav class="tsd-navigation primary">
|
|
54
|
+
<details class="tsd-index-accordion" open><summary class="tsd-accordion-summary">
|
|
55
|
+
<h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-text)"></path></svg> Modules</h3></summary>
|
|
56
|
+
<div class="tsd-accordion-details">
|
|
57
|
+
<ul>
|
|
58
|
+
<li class="current"><a href="../modules.html">Micro <wbr/>Components</a>
|
|
59
|
+
<ul>
|
|
60
|
+
<li class="current tsd-kind-module"><a href="../modules/MC.html">MC</a></li>
|
|
61
|
+
<li class="tsd-kind-module"><a href="../modules/MCbundle.html">MCbundle</a></li></ul></li></ul></div></details></nav>
|
|
62
|
+
<nav class="tsd-navigation secondary menu-sticky">
|
|
63
|
+
<ul>
|
|
64
|
+
<li class="tsd-kind-reference tsd-parent-kind-module"><a href="../modules/MC.html#McEvent" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="#FF4D82" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="12" id="icon-8388608-path"></rect><path d="M10.354 17V8.24H13.066C13.586 8.24 14.042 8.348 14.434 8.564C14.826 8.772 15.13 9.064 15.346 9.44C15.562 9.816 15.67 10.256 15.67 10.76C15.67 11.352 15.514 11.86 15.202 12.284C14.898 12.708 14.482 13 13.954 13.16L15.79 17H14.518L12.838 13.28H11.434V17H10.354ZM11.434 12.308H13.066C13.514 12.308 13.874 12.168 14.146 11.888C14.418 11.6 14.554 11.224 14.554 10.76C14.554 10.288 14.418 9.912 14.146 9.632C13.874 9.352 13.514 9.212 13.066 9.212H11.434V12.308Z" fill="var(--color-text)" id="icon-8388608-text"></path></svg>Mc<wbr/>Event</a></li>
|
|
65
|
+
<li class="tsd-kind-class tsd-parent-kind-module"><a href="../classes/MC.DC.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-class)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6" id="icon-128-path"></rect><path d="M11.898 16.1201C11.098 16.1201 10.466 15.8961 10.002 15.4481C9.53803 15.0001 9.30603 14.3841 9.30603 13.6001V9.64012C9.30603 8.85612 9.53803 8.24012 10.002 7.79212C10.466 7.34412 11.098 7.12012 11.898 7.12012C12.682 7.12012 13.306 7.34812 13.77 7.80412C14.234 8.25212 14.466 8.86412 14.466 9.64012H13.386C13.386 9.14412 13.254 8.76412 12.99 8.50012C12.734 8.22812 12.37 8.09212 11.898 8.09212C11.426 8.09212 11.054 8.22412 10.782 8.48812C10.518 8.75212 10.386 9.13212 10.386 9.62812V13.6001C10.386 14.0961 10.518 14.4801 10.782 14.7521C11.054 15.0161 11.426 15.1481 11.898 15.1481C12.37 15.1481 12.734 15.0161 12.99 14.7521C13.254 14.4801 13.386 14.0961 13.386 13.6001H14.466C14.466 14.3761 14.234 14.9921 13.77 15.4481C13.306 15.8961 12.682 16.1201 11.898 16.1201Z" fill="var(--color-text)" id="icon-128-text"></path></svg>DC</a></li>
|
|
66
|
+
<li class="tsd-kind-class tsd-parent-kind-module"><a href="../classes/MC.MC.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-128-path"></use><use href="#icon-128-text"></use></svg>MC</a></li>
|
|
67
|
+
<li class="tsd-kind-class tsd-parent-kind-module"><a href="../classes/MC.McBase.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-128-path"></use><use href="#icon-128-text"></use></svg>Mc<wbr/>Base</a></li>
|
|
68
|
+
<li class="tsd-kind-interface tsd-parent-kind-module"><a href="../interfaces/MC.HTMLMcElement.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-interface)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6" id="icon-256-path"></rect><path d="M9.51 16V15.016H11.298V8.224H9.51V7.24H14.19V8.224H12.402V15.016H14.19V16H9.51Z" fill="var(--color-text)" id="icon-256-text"></path></svg>HTMLMc<wbr/>Element</a></li>
|
|
69
|
+
<li class="current tsd-kind-function tsd-parent-kind-module"><a href="MC.addListener.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-function)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6" id="icon-64-path"></rect><path d="M9.39 16V7.24H14.55V8.224H10.446V11.128H14.238V12.112H10.47V16H9.39Z" fill="var(--color-text)" id="icon-64-text"></path></svg>add<wbr/>Listener</a></li>
|
|
70
|
+
<li class="tsd-kind-function tsd-parent-kind-module"><a href="MC.removeListener.html" class="tsd-index-link"><svg class="tsd-kind-icon" width="24" height="24" viewBox="0 0 24 24"><use href="#icon-64-path"></use><use href="#icon-64-text"></use></svg>remove<wbr/>Listener</a></li></ul></nav></div></div>
|
|
71
|
+
<div class="container tsd-generator">
|
|
72
|
+
<p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
|
|
73
|
+
<div class="overlay"></div><script src="../assets/main.js"></script></body></html>
|