@twobirds/microcomponents 0.0.84 → 0.0.86
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/README.md +22 -6
- package/assets/documentation/MC.md +60 -81
- package/assets/documentation/elements.md +6 -9
- package/assets/documentation/observables.md +97 -11
- package/assets/test/{my-tag.css → myButton.css} +4 -4
- package/assets/test/test.html +1 -1
- package/dist/MC.d.ts +6 -9
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.js +40 -73
- package/dist/MC.min.js +40 -73
- package/dist/MC.ts +67 -114
- package/dist/elements.min.js +1 -1
- package/dist/formValues.min.js +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.min.js +1 -1
- package/package.json +2 -2
- package/public/MC.d.ts +6 -9
- package/public/MC.d.ts.map +1 -1
- package/public/MC.js +40 -73
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +40 -73
- package/public/MC.ts +67 -114
- package/public/documentation/MC.md +60 -81
- package/public/documentation/elements.md +6 -9
- package/public/documentation/observables.md +97 -11
- package/public/elements.min.js +1 -1
- package/public/formValues.min.js +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/observables.min.js +1 -1
- package/public/src/MC.d.ts +6 -9
- package/public/src/MC.d.ts.map +1 -1
- package/public/src/MC.js +40 -73
- package/public/src/MC.js.map +1 -1
- package/public/src/MC.ts +67 -114
- package/public/src/test/test/grandparent.js +1 -1
- package/public/src/test/test/testform.js +1 -1
- package/public/src/test/test.js +23 -31
- package/public/src/test/test.js.map +1 -1
- package/public/src/test/test.ts +61 -72
- package/public/test/MC.d.ts +6 -9
- package/public/test/MC.d.ts.map +1 -1
- package/public/test/MC.js +40 -73
- package/public/test/MC.min.js +40 -73
- package/public/test/MC.ts +67 -114
- package/public/test/elements.min.js +1 -1
- package/public/test/formValues.min.js +1 -1
- package/public/test/microcomponents.min.js +1 -1
- package/public/test/{my-tag.css → myButton.css} +4 -4
- package/public/test/observables.min.js +1 -1
- package/public/test/test/grandparent.js +1 -1
- package/public/test/test/testform.js +1 -1
- package/public/test/test.html +1 -1
- package/public/test/test.js +23 -31
- package/public/test/test.js.map +1 -1
- package/public/test/test.ts +61 -72
- package/public/typedoc/assets/navigation.js +1 -1
- package/public/typedoc/assets/search.js +1 -1
- package/public/typedoc/classes/MC.DC.html +3 -4
- package/public/typedoc/classes/MC.MC.html +2 -4
- package/public/typedoc/classes/MC.McBase.html +2 -2
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.off.html +1 -1
- package/public/typedoc/functions/MC.on.html +1 -1
- package/public/typedoc/functions/MC.one.html +1 -1
- package/public/typedoc/functions/MC.trigger.html +1 -0
- package/public/typedoc/functions/elements.defineCE.html +1 -1
- package/public/typedoc/functions/elements.getCE.html +1 -1
- package/public/typedoc/functions/formValues.formValues.html +1 -1
- package/public/typedoc/functions/observables.observe.html +1 -1
- package/public/typedoc/index.html +21 -10
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/typedoc/modules/MC.html +3 -3
- package/public/typedoc/modules/elements.html +1 -1
- package/public/typedoc/modules/formValues.html +1 -1
- package/public/typedoc/modules/observables.html +1 -1
- package/public/typedoc/types/observables.Observable.html +1 -1
- package/src/MC.ts +67 -114
- package/src/test/test.ts +61 -72
|
@@ -1 +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.TestTestform=t():e.TestTestform=t()}(self,(()=>(()=>{"use strict";var e=new Function("try {return this===window;}catch(e){ return false;}");function t(e,t){let n=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const a=e?._mc;!t&&a?n=n.concat(Object.values(e._mc)):t&&a&&a[t]&&n.push(a[t])}})),n}function n(e,t,n=!0){let a=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&a.push(e._mc[t]):a=a.concat(Object.values(e._mc)),n))return a;e=e.parentNode}return a}function a(e){return e&&e instanceof HTMLElement}function l(e,t,n={}){let a=e;if(!a._mc){let t=u?.debug;u.debug=!1,a._mc=new u(e),u.debug=t,delete a._mc._mc}const l=a._mc;return t.length&&!l[t]&&(l[t]=n,e instanceof HTMLElement&&!e.getAttribute("data-mc")&&e.setAttribute("data-mc","")),n}function r(e,t){if(!t)return;const n=e?._mc||{};n&&n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute("data-mc")&&e.removeAttribute("data-mc")}function o(e){return"_mc"+e[0].toUpperCase()+e.substring(1)}function s(e,t,n,a=!1){e.addEventListener(o(t),n,{capture:!1,once:a})}function i(e,t,n={},a="l"){const l="string"==typeof t?new CustomEvent(o(t),{detail:{data:n,bubble:a}}):t;a.length&&a.indexOf("l")>-1&&e.dispatchEvent(l),/[u|d]/.test(a)&&function(e,t){setTimeout((()=>{-1===t.detail.bubble.indexOf("l")&&(t.detail.bubble+="l"),t.detail.bubble.indexOf("u")>-1&&e.closest("[data-mc]")?.dispatchEvent(t),t.detail.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&u.trigger(e,t)}))}),0)}(e,l)}class c{_target;constructor(t,n=!1){var a;this._target=new WeakRef(t||{}),(a=this).constructor!==u&&setTimeout((()=>{a.trigger("Init")}),0),function(t){if(!e()||t.constructor===u)return;const n=t.target;if(n instanceof HTMLElement){let e=t;Object.getOwnPropertyNames(e.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof e.constructor.prototype[t])).forEach((t=>{let a=/^one/.test(t),l=t.replace(/^on[e]{0,1}/,""),r=l.toLowerCase(),o=n=>{e[t](n)};n["on"+r]?n.addEventListener(r,o):s(n,l,o,a)}))}}(this)}get target(){return this._target.deref()}}class u extends c{constructor(e,t=!1){super(e)}static add=l;static remove=r;static trigger=i;off(e,t){!function(e,t,n){e.removeEventListener(o(t),n)}(this.target,e,t)}on(e,t){s(this.target,e,t)}one(e,t){!function(e,t,n){s(e,t,n,!0)}(this.target,e,t)}trigger(e,t={},n="l"){}parent(e=""){let t=this.target;return a(t)?n(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return a(t)?n(this.target.parentNode,e,!1):[]}children(e=""){let n=this?.target;return a(n)?t([...function(e){const t=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+t+'"] [data-mc] [data-mc])';e.setAttribute("temp_id",t);const a=e.querySelectorAll(n);return e.removeAttribute("temp_id"),a}(n)],e):[]}descendants(e=""){let n=this?.target;return a(n)?t([...n.querySelectorAll("*[data-mc]")],e):[]}}function p(e){let t={};return[...Object.keys(e)].sort().forEach((n=>{var a;(a=e[n])&&a.constructor&&a.constructor===Object?t[n]=p(e[n]):t[n]=e[n]})),t}function d(e,t=!0){let n={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const a=d(e[t],!1);for(const e in a)n[t+"."+e]=a[e]}else n[t]=e[t]})),t?p(n):n}function b(e,t){return JSON.stringify(d(e))===JSON.stringify(d(t))}function m(e,t){let n;return()=>{clearTimeout(n),n=setTimeout((function(){e(...arguments)}),t)}}function f(e,t){const n=Object.getOwnPropertyDescriptors(e);for(const[e,a]of Object.entries(n))("get"in a||"set"in a)&&Object.defineProperty(t,e,a)}new Set;class h extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(e,t,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:e,oldValue:t,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function g(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}function y(e){return null!=e&&"object"==typeof e}function v(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter((t=>e.getAttribute(t)?.match(n))).forEach((t=>{let a=new Set(e.getAttribute(t)?.match(n));a.forEach((e=>a.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(n))).forEach((e=>{(e.nodeValue||"").match(n).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const O=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class E extends u{data={};oldDisplay="";constructor(e){super(e),v(e).forEach((e=>this.data[e]="")),k(this),this.#e()}#e(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter((t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g))).forEach((t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));var a;this.data.observe((a=e.getAttribute(t),l=>{let r=a;n.forEach((e=>{r=r.replace(e,l[e.replace(/[\{\}]/g,"")])})),e.setAttribute(t,r)}))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{t=!0;let a=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((t=>l=>{let r=t;a.forEach((e=>{r=r.replace(e,l[e.replace(/[\{\}]/g,"")])})),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=r})(n.nodeValue)),this.oldDisplay=e.getAttribute("style")||"",t&&!O.includes(e.constructor)&&"FIELDSET"!==e.tagName&&(e.style.display="none")}))}onData(e){let t={};Object.keys(e.detail.data).forEach((n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])})),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}}const w={};function x(e){let t=e.constructor.name;return w[t]||function(e){const t=e.constructor,n=t.name;let a=class extends t{#t=!0;#n=[];constructor(e){super(e),this.constructor.callbacks=[],y(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}get callbacks(){return this.#n}set callbacks(e){this.#n=e}observe(e){return this.#n.push(e),this}bind(e){if(y(this.valueOf())){!function(e){var t;(t=e,[t].concat([...t.querySelectorAll("*")]).filter((e=>!!v(e).length)).filter((e=>"STYLE"!==e?.tagName)).reverse()).forEach((e=>{e?._mc?._placeholders||u.add(e,"_placeholders",new E(e))}))}(e);const t=[e,...e.querySelectorAll("[data-mc]")].filter((e=>!!e?._mc?._placeholders)),n=function(e){let n=d(e);t.forEach((e=>{e&&i(e,"data",n)}))};this.#n.push(n),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(e){let t=y(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==e&&(this.#t=e),this.#n.forEach((e=>{e(t)})),this}};return w[n]=a,a}(e)}const k=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if(e.hasOwnProperty(t)&&"function"!=typeof e[t]&&!e?.[t]?.constructor?.prototype?.observe){if("_"===t[0]||void 0===e?.[t])return e;let n=e[t],a=new(x(n))(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(y(a.valueOf())){let e=structuredClone(Object.assign({},a));setTimeout(m((function(){b(structuredClone(Object.assign({},a)),e)||a.notify()}),0),0)}return a},set(e){if(typeof e==typeof a.valueOf())if(y(a.valueOf())&&a.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},a));void 0===a?.constructor?.prototype?.observe&&(a=new(x(e))(structuredClone(Object.assign({},e))),f(e,a),a.seal()),Object.assign(a,e),setTimeout(m((function(){b(structuredClone(Object.assign({},a)),t)||a.notify()}),0),0)}else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(x(e))(e),a.callbacks=n,a.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof a.valueOf(),a,"- CANNOT BECOME:",typeof e)}}),e[t]=n}})),e);class A{constructor(e){}}class C extends A{#a;constructor(e){super(e),this.#a=e}get val(){return new FormData(this.#a.form).get(this.#a.name)}set val(e){[...this.#a.form.querySelectorAll(`input[type="radio"][name="${this.#a.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class j extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.checked}set val(e){this.#a.checked=e}}class S extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}class _ extends A{#a;#l=!1;constructor(e){super(e),this.#a=e,this.#l=e.multiple}get val(){const e=[];return[...this.#a.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#l?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#a.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class N extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value||""}set val(e){this.#a.value=e}}return function(e,t,n=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let a=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");g(t.prototype.constructor)&&t.prototype instanceof c?customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(a,class extends h{instance;constructor(e){super();const n=g(t)?new t(this,e):t;u.add(this,a,n)}static get observedAttributes(){return n}})):customElements.define(e,t)}("test-testform",class extends u{data;constructor(e){super(e);let t=this.target.attachShadow({mode:"open"});t.innerHTML=`<style>${this.css}</style>${this.template}`,function(e,t,n){let a=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],n={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let a=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":a=new C(e);break;case"checkbox":a=new j(e);break;default:a=new S(e)}break;case"select":a=new _(e);break;case"textarea":a=new N(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}a&&(u.add(e,t,a),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val!==e&&(a.val=e)}}))}})),n})(n);e[t]=Object.assign({},a),k(e,t),f(a,e[t]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{e[t].notify()}))}))}(this,"data",t),this.data.bind(t),fetch("./testform.json").then((e=>e.json())).then((e=>{this.data=e}))}get template(){return'\n <form>\n \x3c!-- sample form to start with --\x3e\n <fieldset>\n <legend>Inputs</legend>\n <label>text</label><input type="text" name="textInput" value="Hallo" /> <strong>2wB: </strong>{textInput}<br />\n <label>color</label><input type="color" name="colorInput" value="#000000" /><br />\n <label>date</label><input type="date" name="dateInput" value="" /><br />\n <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" /><br />\n <label>email</label><input type="email" name="email" value="" /><br />\n <label>file</label><input type="file" name="fileInput" value="" /><br />\n <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" /><br />\n <label>month</label><input type="month" name="month" value="" /><br />\n <label>number</label><input type="number" name="number" value="" /><br />\n <label>password</label><input type="password" name="passInput" value="" /><br />\n <label>range</label><input type="range" name="rangeInput" value="" /><br />\n <label>search</label><input type="search" name="searchInput" value="" /><br />\n <label>tel</label><input type="tel" name="telInput" value="" /><br />\n <label>time</label><input type="time" name="timeInput" value="" /><br />\n <label>url</label><input type="url" name="urlInput" value="" /><br />\n <label>week</label><input type="week" name="weekInput" value="" /><br />\n </fieldset>\n\n <fieldset>\n <legend>Selects <strong>2wB: </strong> <span>"{singleSelect}"</span> <span>[{multiSelect}]</span></legend>\n\n <label>singleSelect</label>\n <select name="singleSelect">\n <option disabled selected value> -- select -- </option>\n <option value="1">Option 1</option>\n <option value="2">Option 2</option>\n <option value="3">Option 3</option>\n <option value="4">Option 4</option>\n </select><br />\n\n <label>multiSelect</label>\n <select name="multiSelect" multiple="multiple" type="select-multiple">\n <option value="1">Option 1</option>\n <option value="2" selected=true>Option 2</option>\n <option value="3">Option 3</option>\n <option value="4" selected=true>Option 4</option>\n </select>\n\n </fieldset>\n\n <fieldset>\n <legend>Radiobuttons <strong>2wB: </strong><span>"{myRadio}"</span></legend>\n\n <label>radio1</label><input type="radio" name="myRadio" value="radio1"><br />\n <label>radio2</label><input type="radio" name="myRadio" value="radio2"><br />\n <label>radio3</label><input type="radio" name="myRadio" value="radio3"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>Checkboxes</legend>\n <label>cb1</label><input type="checkbox" name="cb1"><br />\n <label>cb2</label><input type="checkbox" name="cb2"><br />\n <label>cb3</label><input type="checkbox" name="cb3"><br />\n <label>cb4</label><input type="checkbox" name="cb4"><br />\n <label>cb5</label><input type="checkbox" name="cb5"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>TextArea</legend>\n <label>textArea</label>\n <textarea name="textArea">abc</textarea>\n </fieldset>\n\n </form>\n '}get css(){return'\nlegend {\n display: inherit;\n margin: inherit;\n vertical-align: inherit;\n font-weight: bold;\n}\n\nlabel {\n display: inline-block;\n margin-top: 1em;\n margin-left: 5px;\n vertical-align: top;\n min-width:10em;\n text-align: right;\n}\n\nform input,\nform select,\nform textarea {\n display: inline-block;\n margin-left: 5px;\n margin-top: 1.1em;\n}\n\ninput[type="radio"],\ninput[type="checkbox"] {\n margin-top: 1.3em;\n}\n\nbody > form {\n display: block;\n}\n\nform fieldset {\n border: 1px solid #aaaaaa;\n border-radius: 3px;\n margin: 0.5em 0;\n}\n '}}),{}})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TestTestform=t():e.TestTestform=t()}(self,(()=>(()=>{"use strict";const e=new Function("try {return this===window;}catch(e){ return false;}");function t(e){return e&&e instanceof HTMLElement}function n(e,t,n={}){let a=e;a._mc||(a._mc=new i(e));const l=a._mc;return t.length&&!l[t]&&(l[t]=n,e instanceof HTMLElement&&!e.getAttribute("data-mc")&&e.setAttribute("data-mc","")),a}function a(e,t){if(!t)return;const n=e?._mc||{};n&&n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute("data-mc")&&e.removeAttribute("data-mc")}function l(e){return"_mc"+e[0].toUpperCase()+e.substring(1)}function r(e,t,n,a=!1){e.addEventListener(l(t),n,{capture:!1,once:a})}function s(e,t,n={},a="l"){const r="string"==typeof t?new CustomEvent(l(t),{detail:{data:n,bubble:a}}):t;a.length&&a.indexOf("l")>-1&&e.dispatchEvent(r),/[u|d]/.test(a)&&function(e,t){setTimeout((()=>{-1===t.detail.bubble.indexOf("l")&&(t.detail.bubble+="l"),t.detail.bubble.indexOf("u")>-1&&e.closest("[data-mc]")?.dispatchEvent(t),t.detail.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&e._mc.trigger(e,t)}))}),0)}(e,r)}class o{_target;constructor(t){var n;this._target=new WeakRef(t||{}),n=this,setTimeout((()=>{n.constructor!==i&&n.trigger("Init")}),0),function(t){if(!e()||t.constructor===i)return;const n=t.target;if(n instanceof HTMLElement){let e=t;Object.getOwnPropertyNames(e.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof e.constructor.prototype[t])).forEach((t=>{let a=/^one/.test(t),l=t.replace(/^on[e]{0,1}/,""),s=l.toLowerCase();if("on"+s in n){let a=n=>{e[t](n)};n.addEventListener(s,a)}else r(n,l,(n=>{e[t](n)}),a)}))}}(this)}get target(){return this._target.deref()}}class i extends o{constructor(e,t=!1){super(e)}static add=n;static remove=a;off(e,t){!function(e,t,n){e.removeEventListener(l(t),n)}(this.target,e,t)}on(e,t){r(this.target,e,t)}one(e,t){!function(e,t,n){r(e,t,n,!0)}(this.target,e,t)}trigger(e,t={},n="l"){s(this.target,e,t,n)}parent(){let e=this.target;return t(e)&&e.closest("[data-mc]")?._mc||null}ancestors(){let e=this?.target,n=[];if(!t(e))return[];for(;e=e.closest("[data-mc]");)e?._mc&&n.push(e?._mc);return n.length?n:null}children(){let e=this?.target;return t(e)?function(e){const t=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+t+'"] [data-mc] [data-mc])';e.setAttribute("temp_id",t);const a=[...e.querySelectorAll(n)].filter((e=>!!e._mc)).map((e=>e._mc));return e.removeAttribute("temp_id"),a.length?a:null}(e):null}descendants(){const e=this?.target;if(!t(e))return[];const n=[...e.querySelectorAll("[data-mc]")].filter((e=>!!e._mc)).map((e=>e._mc));return n.length?n:null}}function c(e){let t={};return[...Object.keys(e)].sort().forEach((n=>{var a;(a=e[n])&&a.constructor&&a.constructor===Object?t[n]=c(e[n]):t[n]=e[n]})),t}function u(e,t=!0){let n={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const a=u(e[t],!1);for(const e in a)n[t+"."+e]=a[e]}else n[t]=e[t]})),t?c(n):n}function p(e,t){return JSON.stringify(u(e))===JSON.stringify(u(t))}function d(e,t){let n;return()=>{clearTimeout(n),n=setTimeout((function(){e(...arguments)}),t)}}function b(e,t){const n=Object.getOwnPropertyDescriptors(e);for(const[e,a]of Object.entries(n))("get"in a||"set"in a)&&Object.defineProperty(t,e,a)}new Set;class m extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(e,t,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:e,oldValue:t,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function f(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}function h(e){return null!=e&&"object"==typeof e}function g(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter((t=>e.getAttribute(t)?.match(n))).forEach((t=>{let a=new Set(e.getAttribute(t)?.match(n));a.forEach((e=>a.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(n))).forEach((e=>{(e.nodeValue||"").match(n).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const y=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class v extends i{data={};oldDisplay="";constructor(e){super(e),g(e).forEach((e=>this.data[e]="")),w(this),this.#e()}#e(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter((t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g))).forEach((t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));var a;this.data.observe((a=e.getAttribute(t),l=>{let r=a;n.forEach((e=>{r=r.replace(e,l[e.replace(/[\{\}]/g,"")])})),e.setAttribute(t,r)}))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{t=!0;let a=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((t=>l=>{let r=t;a.forEach((e=>{r=r.replace(e,l[e.replace(/[\{\}]/g,"")])})),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=r})(n.nodeValue)),this.oldDisplay=e.getAttribute("style")||"",t&&!y.includes(e.constructor)&&"FIELDSET"!==e.tagName&&(e.style.display="none")}))}onData(e){let t={};Object.keys(e.detail.data).forEach((n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])})),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}}const O={};function E(e){let t=e.constructor.name;return O[t]||function(e){const t=e.constructor,n=t.name;let a=class extends t{#t=!0;#n=[];constructor(e){super(e),this.constructor.callbacks=[],h(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}get callbacks(){return this.#n}set callbacks(e){this.#n=e}observe(e){return this.#n.push(e),this}bind(e){if(h(this.valueOf())){!function(e){var t;(t=e,[t].concat([...t.querySelectorAll("*")]).filter((e=>!!g(e).length)).filter((e=>"STYLE"!==e?.tagName)).reverse()).forEach((e=>{e?._mc?._placeholders||i.add(e,"_placeholders",new v(e))}))}(e);const t=[e,...e.querySelectorAll("[data-mc]")].filter((e=>!!e?._mc?._placeholders)),n=function(e){let n=u(e);t.forEach((e=>{e&&s(e,"data",n)}))};this.#n.push(n),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(e){let t=h(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==e&&(this.#t=e),this.#n.forEach((e=>{e(t)})),this}};return O[n]=a,a}(e)}const w=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if(e.hasOwnProperty(t)&&"function"!=typeof e[t]&&!e?.[t]?.constructor?.prototype?.observe){if("_"===t[0]||void 0===e?.[t])return e;let n=e[t],a=new(E(n))(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(h(a.valueOf())){let e=structuredClone(Object.assign({},a));setTimeout(d((function(){p(structuredClone(Object.assign({},a)),e)||a.notify()}),0),0)}return a},set(e){if(typeof e==typeof a.valueOf())if(h(a.valueOf())&&a.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},a));void 0===a?.constructor?.prototype?.observe&&(a=new(E(e))(structuredClone(Object.assign({},e))),b(e,a),a.seal()),Object.assign(a,e),setTimeout(d((function(){p(structuredClone(Object.assign({},a)),t)||a.notify()}),0),0)}else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(E(e))(e),a.callbacks=n,a.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof a.valueOf(),a,"- CANNOT BECOME:",typeof e)}}),e[t]=n}})),e);class x{constructor(e){}}class k extends x{#a;constructor(e){super(e),this.#a=e}get val(){return new FormData(this.#a.form).get(this.#a.name)}set val(e){[...this.#a.form.querySelectorAll(`input[type="radio"][name="${this.#a.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class A extends x{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.checked}set val(e){this.#a.checked=e}}class C extends x{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}class S extends x{#a;#l=!1;constructor(e){super(e),this.#a=e,this.#l=e.multiple}get val(){const e=[];return[...this.#a.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#l?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#a.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class j extends x{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value||""}set val(e){this.#a.value=e}}return function(e,t,n=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let a=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");f(t.prototype.constructor)&&t.prototype instanceof o?customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(a,class extends m{instance;constructor(e){super();const n=f(t)?new t(this,e):t;i.add(this,a,n)}static get observedAttributes(){return n}})):customElements.define(e,t)}("test-testform",class extends i{data;constructor(e){super(e);let t=this.target.attachShadow({mode:"open"});t.innerHTML=`<style>${this.css}</style>${this.template}`,function(e,t,n){let a=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],n={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let a=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":a=new k(e);break;case"checkbox":a=new A(e);break;default:a=new C(e)}break;case"select":a=new S(e);break;case"textarea":a=new j(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}a&&(i.add(e,t,a),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val!==e&&(a.val=e)}}))}})),n})(n);e[t]=Object.assign({},a),w(e,t),b(a,e[t]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{e[t].notify()}))}))}(this,"data",t),this.data.bind(t),fetch("./testform.json").then((e=>e.json())).then((e=>{this.data=e}))}get template(){return'\n <form>\n \x3c!-- sample form to start with --\x3e\n <fieldset>\n <legend>Inputs</legend>\n <label>text</label><input type="text" name="textInput" value="Hallo" /> <strong>2wB: </strong>{textInput}<br />\n <label>color</label><input type="color" name="colorInput" value="#000000" /><br />\n <label>date</label><input type="date" name="dateInput" value="" /><br />\n <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" /><br />\n <label>email</label><input type="email" name="email" value="" /><br />\n <label>file</label><input type="file" name="fileInput" value="" /><br />\n <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" /><br />\n <label>month</label><input type="month" name="month" value="" /><br />\n <label>number</label><input type="number" name="number" value="" /><br />\n <label>password</label><input type="password" name="passInput" value="" /><br />\n <label>range</label><input type="range" name="rangeInput" value="" /><br />\n <label>search</label><input type="search" name="searchInput" value="" /><br />\n <label>tel</label><input type="tel" name="telInput" value="" /><br />\n <label>time</label><input type="time" name="timeInput" value="" /><br />\n <label>url</label><input type="url" name="urlInput" value="" /><br />\n <label>week</label><input type="week" name="weekInput" value="" /><br />\n </fieldset>\n\n <fieldset>\n <legend>Selects <strong>2wB: </strong> <span>"{singleSelect}"</span> <span>[{multiSelect}]</span></legend>\n\n <label>singleSelect</label>\n <select name="singleSelect">\n <option disabled selected value> -- select -- </option>\n <option value="1">Option 1</option>\n <option value="2">Option 2</option>\n <option value="3">Option 3</option>\n <option value="4">Option 4</option>\n </select><br />\n\n <label>multiSelect</label>\n <select name="multiSelect" multiple="multiple" type="select-multiple">\n <option value="1">Option 1</option>\n <option value="2" selected=true>Option 2</option>\n <option value="3">Option 3</option>\n <option value="4" selected=true>Option 4</option>\n </select>\n\n </fieldset>\n\n <fieldset>\n <legend>Radiobuttons <strong>2wB: </strong><span>"{myRadio}"</span></legend>\n\n <label>radio1</label><input type="radio" name="myRadio" value="radio1"><br />\n <label>radio2</label><input type="radio" name="myRadio" value="radio2"><br />\n <label>radio3</label><input type="radio" name="myRadio" value="radio3"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>Checkboxes</legend>\n <label>cb1</label><input type="checkbox" name="cb1"><br />\n <label>cb2</label><input type="checkbox" name="cb2"><br />\n <label>cb3</label><input type="checkbox" name="cb3"><br />\n <label>cb4</label><input type="checkbox" name="cb4"><br />\n <label>cb5</label><input type="checkbox" name="cb5"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>TextArea</legend>\n <label>textArea</label>\n <textarea name="textArea">abc</textarea>\n </fieldset>\n\n </form>\n '}get css(){return'\nlegend {\n display: inherit;\n margin: inherit;\n vertical-align: inherit;\n font-weight: bold;\n}\n\nlabel {\n display: inline-block;\n margin-top: 1em;\n margin-left: 5px;\n vertical-align: top;\n min-width:10em;\n text-align: right;\n}\n\nform input,\nform select,\nform textarea {\n display: inline-block;\n margin-left: 5px;\n margin-top: 1.1em;\n}\n\ninput[type="radio"],\ninput[type="checkbox"] {\n margin-top: 1.3em;\n}\n\nbody > form {\n display: block;\n}\n\nform fieldset {\n border: 1px solid #aaaaaa;\n border-radius: 3px;\n margin: 0.5em 0;\n}\n '}}),{}})()));
|
package/public/test/test.html
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
href="./MicroComponents.svg"
|
|
12
12
|
/>
|
|
13
13
|
<link href="style.css" rel="stylesheet" />
|
|
14
|
-
<link href="
|
|
14
|
+
<link href="myButton.css" rel="stylesheet" />
|
|
15
15
|
<link href="grandparent.css" rel="stylesheet" />
|
|
16
16
|
<script>
|
|
17
17
|
import("./microcomponents.js").then((m) => {
|
package/public/test/test.js
CHANGED
|
@@ -16,22 +16,11 @@ class Translator extends DC {
|
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
that.Translation.bind(translationTargetObject);
|
|
19
|
-
that.target.setAttribute('language', 'en');
|
|
20
19
|
that.Language.notify();
|
|
21
20
|
}
|
|
22
|
-
onAttributeChanged(ev) {
|
|
23
|
-
let detail = ev.detail || {};
|
|
24
|
-
if (!detail.newValue)
|
|
25
|
-
return;
|
|
26
|
-
switch (detail.name) {
|
|
27
|
-
case 'language':
|
|
28
|
-
this.Language = detail.newValue;
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
21
|
}
|
|
33
|
-
|
|
34
|
-
#template = '
|
|
22
|
+
class MyButton extends DC {
|
|
23
|
+
#template = '{lang.click} {counter}';
|
|
35
24
|
#languages = {
|
|
36
25
|
en: {
|
|
37
26
|
click: 'click me',
|
|
@@ -43,38 +32,41 @@ defineCE('my-tag', class MyTag extends DC {
|
|
|
43
32
|
Dom = {};
|
|
44
33
|
constructor(target) {
|
|
45
34
|
super(target);
|
|
46
|
-
let that = this;
|
|
47
35
|
target.innerHTML = this.#template;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
that.Dom = { counter: 0 };
|
|
53
|
-
observe(that);
|
|
54
|
-
that.Dom.bind(that.target);
|
|
36
|
+
this.Dom = { counter: 0 };
|
|
37
|
+
observe(this);
|
|
38
|
+
DC.add(target, 'Translator', new Translator(target, this.#languages, target));
|
|
39
|
+
this.Dom.bind(this.target);
|
|
55
40
|
}
|
|
56
41
|
onClick(ev) {
|
|
57
|
-
const
|
|
58
|
-
ev.
|
|
59
|
-
|
|
60
|
-
|
|
42
|
+
const c = this.Dom.counter++;
|
|
43
|
+
ev.stopPropagation();
|
|
44
|
+
this.target.classList.remove('clicked');
|
|
45
|
+
this.target.classList.add(this.Dom.counter > 9 ? 'overClicked' : 'clicked');
|
|
61
46
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
47
|
+
}
|
|
48
|
+
function makeButton() {
|
|
49
|
+
const button = document.createElement('button');
|
|
50
|
+
button.classList.add('myButton');
|
|
51
|
+
DC.add(button, 'MyButton', new MyButton(button));
|
|
52
|
+
return button;
|
|
53
|
+
}
|
|
54
|
+
defineCE('make-button', makeButton);
|
|
55
|
+
let fragment = new DocumentFragment();
|
|
64
56
|
let start = new Date().getTime(), max = 1000;
|
|
65
57
|
for (let x = 0; x < max; x++) {
|
|
66
|
-
fragment.append(
|
|
58
|
+
fragment.append(getCE('make-button')());
|
|
67
59
|
}
|
|
68
60
|
let end = new Date().getTime();
|
|
69
61
|
document.body.appendChild(fragment);
|
|
70
62
|
setTimeout(() => {
|
|
71
|
-
console.log('%c \n\nStress Test:\n\n %cInstancing %s web components (%s classes): %c %s ms.', 'font-weight: bold; color: black;', 'font-weight: normal;', max, max *
|
|
72
|
-
let element = document.querySelector('
|
|
63
|
+
console.log('%c \n\nStress Test:\n\n %cInstancing %s web components (%s classes): %c %s ms.', 'font-weight: bold; color: black;', 'font-weight: normal;', max, max * 2, 'font-weight: bold; color: blue;', end - start);
|
|
64
|
+
let element = document.querySelector('button');
|
|
73
65
|
console.log("\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s", 'font-weight: bold;', 'font-weight: normal;', element, 'font-weight: bold;', '\n\nLook up code in the debugger: test.js\n');
|
|
74
66
|
let form = document.querySelector('test-testform');
|
|
75
67
|
let formInstance = form._mc.TestTestform;
|
|
76
68
|
window.form = formInstance;
|
|
77
69
|
console.log("\n\n%cAttached a global variable 'form':%c \n\n %O %c %s %c %s %c %s", 'font-weight: bold;', 'font-weight: normal;', formInstance, 'font-weight: bold;', '\n\nYou can use it to change input values, e.g. \n\n', 'font-weight: normal;', ' form.data.textInput="other value"', 'font-weight: bold;', '\n\nChanges will be reflected in the form contents, same as vice versa.\n');
|
|
78
|
-
|
|
70
|
+
element._mc?.trigger('doSomething');
|
|
79
71
|
}, 1000);
|
|
80
72
|
//# sourceMappingURL=test.js.map
|
package/public/test/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/test/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,EAAE,EACF,QAAQ,EACR,KAAK,EACL,OAAO,
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../../src/test/test.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,EAAE,EACF,QAAQ,EACR,KAAK,EACL,OAAO,GAGP,MAAM,uBAAuB,CAAC;AAE/B,MAAM,UAAW,SAAQ,EAAE;IAC1B,aAAa,GAAgB,EAAE,CAAC;IAEhC,QAAQ,GAAY,IAAI,CAAC;IACzB,WAAW,GAAY,EAAE,CAAC;IAE1B,YACC,MAAmD,EACnD,YAAyB,EACzB,uBAAoC;QAEpC,KAAK,CAAC,MAAqB,CAAC,CAAC;QAC7B,IAAI,IAAI,GAAG,IAAI,CAAC;QAGhB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,EAAE,CAAC;QAEtB,OAAO,CAAC,IAAI,CAAC,CAAC;QAGd,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAGjC,IAAI,CAAC,QAAuB,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YAC9C,IAAI,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC7C,IAAI,CAAC,WAAW,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,EAAE,CAAC;YACvD,CAAC;QACF,CAAC,CAAC,CAAC;QAEF,IAAI,CAAC,WAA0B,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;QAE9D,IAAI,CAAC,QAAuB,CAAC,MAAM,EAAE,CAAC;IACxC,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tD,sBAAsB,EACtB,qCAAqC,EACrC,oBAAoB,EACpB,2EAA2E,CAC3E,CAAC;IAGA,OAAqC,CAAC,GAAG,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;AACrE,CAAC,EAAE,IAAI,CAAC,CAAC"}
|
package/public/test/test.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getCE,
|
|
6
6
|
observe,
|
|
7
7
|
Observable,
|
|
8
|
+
HTMLMcElement,
|
|
8
9
|
} from '../microcomponents.js';
|
|
9
10
|
|
|
10
11
|
class Translator extends DC {
|
|
@@ -39,83 +40,71 @@ class Translator extends DC {
|
|
|
39
40
|
|
|
40
41
|
(that.Translation as Observable).bind(translationTargetObject);
|
|
41
42
|
|
|
42
|
-
that.target.setAttribute('language', 'en');
|
|
43
|
-
|
|
44
43
|
(that.Language as Observable).notify();
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class MyButton extends DC {
|
|
49
|
+
#template: string = '{lang.click} {counter}';
|
|
50
|
+
|
|
51
|
+
#languages = {
|
|
52
|
+
en: {
|
|
53
|
+
click: 'click me',
|
|
54
|
+
},
|
|
55
|
+
de: {
|
|
56
|
+
click: 'klick mich',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Dom: LooseObject = {};
|
|
61
|
+
|
|
62
|
+
constructor(target: HTMLElement) {
|
|
63
|
+
super(target);
|
|
64
|
+
|
|
65
|
+
// render
|
|
66
|
+
target.innerHTML = this.#template;
|
|
67
|
+
|
|
68
|
+
// state
|
|
69
|
+
this.Dom = { counter: 0 };
|
|
70
|
+
|
|
71
|
+
// state: convert all props defined so far into observables
|
|
72
|
+
observe(this);
|
|
73
|
+
|
|
74
|
+
// add translator
|
|
75
|
+
DC.add(
|
|
76
|
+
target,
|
|
77
|
+
'Translator',
|
|
78
|
+
new Translator(target, this.#languages, target)
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// bind Dom to target
|
|
82
|
+
(this.Dom as Observable).bind(this.target);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onClick(ev: Event) {
|
|
86
|
+
// console.log('button.myButton onClick()');
|
|
87
|
+
const c = this.Dom.counter++;
|
|
88
|
+
ev.stopPropagation();
|
|
89
|
+
(this.target as HTMLElement).classList.remove('clicked');
|
|
90
|
+
(this.target as HTMLElement).classList.add( this.Dom.counter > 9 ? 'overClicked' : 'clicked' );
|
|
55
91
|
}
|
|
56
92
|
}
|
|
57
93
|
|
|
94
|
+
function makeButton(): HTMLMcElement {
|
|
95
|
+
const
|
|
96
|
+
button = document.createElement('button');
|
|
97
|
+
button.classList.add('myButton');
|
|
98
|
+
DC.add( button, 'MyButton', new MyButton(button) );
|
|
99
|
+
return button as unknown as HTMLMcElement;
|
|
100
|
+
}
|
|
101
|
+
|
|
58
102
|
defineCE(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
class MyTag extends DC {
|
|
62
|
-
#template: string = '<button>{lang.click} {counter}</button>';
|
|
63
|
-
|
|
64
|
-
#languages = {
|
|
65
|
-
en: {
|
|
66
|
-
click: 'click me',
|
|
67
|
-
},
|
|
68
|
-
de: {
|
|
69
|
-
click: 'klick mich',
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
Dom: LooseObject = {};
|
|
74
|
-
|
|
75
|
-
constructor(target: HTMLElement) {
|
|
76
|
-
super(target);
|
|
77
|
-
|
|
78
|
-
let that = this; // minifier help
|
|
79
|
-
|
|
80
|
-
// render
|
|
81
|
-
target.innerHTML = this.#template;
|
|
82
|
-
|
|
83
|
-
// add translator
|
|
84
|
-
DC.add(
|
|
85
|
-
target,
|
|
86
|
-
'translator',
|
|
87
|
-
new Translator(target, that.#languages, target)
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
oneInit(ev: CustomEvent) {
|
|
92
|
-
let that = this;
|
|
93
|
-
|
|
94
|
-
// state
|
|
95
|
-
that.Dom = { counter: 0 };
|
|
96
|
-
|
|
97
|
-
// state: convert all props defined so far into observables
|
|
98
|
-
observe(that);
|
|
99
|
-
|
|
100
|
-
// bind Dom to target
|
|
101
|
-
(that.Dom as Observable).bind(that.target);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
onClick(ev: CustomEvent) {
|
|
105
|
-
const that = this,
|
|
106
|
-
c = that.Dom.counter++;
|
|
107
|
-
(ev.detail.data as PointerEvent).stopPropagation();
|
|
108
|
-
(that.target as HTMLElement).classList.remove('clicked');
|
|
109
|
-
(that.target as HTMLElement).classList.add(
|
|
110
|
-
that.Dom.counter > 9 ? 'overClicked' : 'clicked'
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
['language']
|
|
103
|
+
'make-button',
|
|
104
|
+
makeButton
|
|
115
105
|
);
|
|
116
106
|
|
|
117
|
-
let
|
|
118
|
-
fragment = new DocumentFragment();
|
|
107
|
+
let fragment = new DocumentFragment();
|
|
119
108
|
|
|
120
109
|
/*
|
|
121
110
|
stress test
|
|
@@ -126,7 +115,7 @@ let start = new Date().getTime(),
|
|
|
126
115
|
|
|
127
116
|
// create 1000 elements
|
|
128
117
|
for (let x = 0; x < max; x++) {
|
|
129
|
-
fragment.append(
|
|
118
|
+
fragment.append( (getCE('make-button') as Function)());
|
|
130
119
|
}
|
|
131
120
|
|
|
132
121
|
let end = new Date().getTime();
|
|
@@ -148,14 +137,14 @@ setTimeout(() => {
|
|
|
148
137
|
'font-weight: bold; color: black;',
|
|
149
138
|
'font-weight: normal;',
|
|
150
139
|
max,
|
|
151
|
-
max *
|
|
140
|
+
max * 2,
|
|
152
141
|
'font-weight: bold; color: blue;',
|
|
153
142
|
end - start
|
|
154
143
|
);
|
|
155
144
|
|
|
156
145
|
//document.body.appendChild(new MyTag());
|
|
157
146
|
|
|
158
|
-
let element = document.querySelector('
|
|
147
|
+
let element = document.querySelector('button');
|
|
159
148
|
|
|
160
149
|
console.log(
|
|
161
150
|
"\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
|
|
@@ -184,5 +173,5 @@ setTimeout(() => {
|
|
|
184
173
|
);
|
|
185
174
|
|
|
186
175
|
// will trigger the event on all micro components contained in <my-tag>
|
|
187
|
-
|
|
176
|
+
( element as unknown as HTMLMcElement )._mc?.trigger('doSomething');
|
|
188
177
|
}, 1000);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAA42SQU
|
|
1
|
+
window.navigationData = "data:application/octet-stream;base64,H4sIAAAAAAAAA42SQU/DIBiG/wvnZrrFTe3RbokHGy/Gy7IDox8tkcIC1GiM/91kXQujgD2/7/P0++i3/0EGvgzKEXBoQRiNMnTCpkE5amXVcdA3Q7JoTMtRhj6YqFC+yhBpGK8UCJTvR00FlAkodlZDO0EMk8IRDaVr4+buNxs9NZh/JOfGxHBwHFSq9h3zDgJL2WzWWiGVncmRxbzeaGUxHaksZo2ydVDCsdY9uvXo5eoh8j0H8j/pQeQJawiD5ygFP7+VLyXZ9X/LOpgwoCgmveaq5G2/3jg23BnJJa5Cr18WiyFOHJSkNAJLSlOciGEiSUEUgwRnFKtrUBH2kiYvSx41qE985KGrd8JZt/Y69q3LfJ88k2150tvH++V6NRku+DSu8FIL7Hn4A8k0UvWxBAAA"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
window.searchData = "data:application/octet-stream;base64,
|
|
1
|
+
window.searchData = "data:application/octet-stream;base64,H4sIAAAAAAAAA82ZTW+kOBCG/4tzZXraZeim+7idkXaljfaymguKIgLuDBoaIqCzO4ry31fmy1WxIYadw5wStf2+VS4/Nsa8sqr8p2bH6JV9z4qUHcFjRXyR7MjuTsxj1ypnR3Yp02su6893p8235pIzjyV5XNeyZkfG3rxRG+xG9e9/3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