@twobirds/microcomponents 0.0.51 → 0.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/formValues.d.ts.map +1 -1
- package/dist/formValues.ts +17 -44
- package/dist/formvValues.min.js +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/package.json +1 -1
- package/public/3d.html +42 -0
- package/public/Grandparent.css +13 -0
- package/public/MC.js +314 -0
- package/public/MC.js.map +1 -0
- package/public/MC.min.js +451 -0
- package/public/McEvent.js +71 -0
- package/public/McEvent.js.map +1 -0
- package/public/MicroComponents.svg +15 -0
- package/public/autoloader.js +53 -0
- package/public/autoloader.js.map +1 -0
- package/public/documentation/MC.md +470 -0
- package/public/documentation/ajaxian-1.png +0 -0
- package/public/documentation/ajaxian-2.png +0 -0
- package/public/documentation/ajaxian-3.png +0 -0
- package/public/documentation/comparision.md +0 -0
- package/public/documentation/elements.md +276 -0
- package/public/documentation/functional_requirements.md +8 -0
- package/public/documentation/history.md +436 -0
- package/public/documentation/how_tos.md +0 -0
- package/public/documentation/introduction.md +0 -0
- package/public/documentation/magic.md +29 -0
- package/public/documentation/proposal_draft.md +37 -0
- package/public/documentation/rnd0023-1.jpg +0 -0
- package/public/documentation/rnd0023-2.jpg +0 -0
- package/public/documentation/rnd0023-3.jpg +0 -0
- package/public/documentation/tB_react.md +207 -0
- package/public/documentation/usage.md +142 -0
- package/public/documentation/why.md +25 -0
- package/public/elements.js +48 -0
- package/public/elements.js.map +1 -0
- package/public/elements.min.js +1 -0
- package/public/fiddle/MicroComponents.svg +15 -0
- package/public/fiddle/fiddle.css +0 -0
- package/public/fiddle/fiddle.js +0 -0
- package/public/fiddle/index.html +0 -0
- package/public/formValues.js +179 -0
- package/public/formValues.js.map +1 -0
- package/public/formvValues.min.js +1 -0
- package/public/helpers.js +113 -0
- package/public/helpers.js.map +1 -0
- package/public/microcomponents.es3.js +303 -0
- package/public/microcomponents.es3.js.map +1 -0
- package/public/microcomponents.js +9 -0
- package/public/microcomponents.js.map +1 -0
- package/public/microcomponents.min.js +1 -0
- package/public/my-tag.css +19 -0
- package/public/observables.js +251 -0
- package/public/observables.js.map +1 -0
- package/public/observables.min.js +1 -0
- package/public/selectors.js +971 -0
- package/public/selectors.js.map +1 -0
- package/public/selectors.min.js +1 -0
- package/public/src/MC.ts +478 -0
- package/public/src/McEvent.ts +96 -0
- package/public/src/autoloader.ts +98 -0
- package/public/src/elements.ts +76 -0
- package/public/src/formValues.ts +250 -0
- package/public/src/helpers.ts +149 -0
- package/public/src/microcomponents.ts +8 -0
- package/public/src/observables.ts +405 -0
- package/public/src/selectors.ts +1634 -0
- package/public/src/test.ts +177 -0
- package/public/test/Grandparent.js +1 -0
- package/public/test/Testform.js +1 -0
- package/public/test.html +27 -0
- package/public/test.js +78 -0
- package/public/test.js.map +1 -0
- package/src/formValues.ts +17 -44
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
LooseObject,
|
|
5
|
+
DC,
|
|
6
|
+
McEvent,
|
|
7
|
+
defineCE,
|
|
8
|
+
getCE,
|
|
9
|
+
observe,
|
|
10
|
+
Observable,
|
|
11
|
+
} from './microcomponents.js';
|
|
12
|
+
|
|
13
|
+
class Translator extends DC {
|
|
14
|
+
#translations: LooseObject = {};
|
|
15
|
+
|
|
16
|
+
Language: unknown = 'en';
|
|
17
|
+
Translation: unknown = {};
|
|
18
|
+
|
|
19
|
+
constructor(
|
|
20
|
+
target: HTMLElement | ShadowRoot | DocumentFragment,
|
|
21
|
+
translations: LooseObject,
|
|
22
|
+
translationTargetObject: HTMLElement
|
|
23
|
+
) {
|
|
24
|
+
super(target as HTMLElement);
|
|
25
|
+
let that = this; // minifier help
|
|
26
|
+
|
|
27
|
+
// state
|
|
28
|
+
that.Language = 'en';
|
|
29
|
+
that.Translation = {};
|
|
30
|
+
|
|
31
|
+
observe(that);
|
|
32
|
+
|
|
33
|
+
// setup
|
|
34
|
+
that.#translations = translations;
|
|
35
|
+
|
|
36
|
+
// state
|
|
37
|
+
(that.Language as Observable).observe((lang) => {
|
|
38
|
+
if (that.#translations.hasOwnProperty(lang)) {
|
|
39
|
+
that.Translation = { lang: that.#translations[lang] }; // set translation
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
(that.Translation as Observable).bind(translationTargetObject);
|
|
44
|
+
|
|
45
|
+
that.target.setAttribute('language', 'en');
|
|
46
|
+
|
|
47
|
+
(that.Language as Observable).notify();
|
|
48
|
+
|
|
49
|
+
delete that._mc; // cleanup, not needed
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
onAttributeChanged(ev: McEvent) {
|
|
53
|
+
if (!ev.data.newValue) return;
|
|
54
|
+
switch (ev.data.name) {
|
|
55
|
+
case 'language':
|
|
56
|
+
this.Language = ev.data.newValue;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
defineCE(
|
|
63
|
+
// equivalent to custom element registry .define()
|
|
64
|
+
'my-tag',
|
|
65
|
+
class MyTag extends DC {
|
|
66
|
+
#template: string = '<button>{lang.click} {counter}</button>';
|
|
67
|
+
|
|
68
|
+
#languages = {
|
|
69
|
+
en: {
|
|
70
|
+
click: 'click me',
|
|
71
|
+
},
|
|
72
|
+
de: {
|
|
73
|
+
click: 'klick mich',
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
Dom: LooseObject = {};
|
|
78
|
+
|
|
79
|
+
constructor(target: HTMLElement) {
|
|
80
|
+
super(target);
|
|
81
|
+
|
|
82
|
+
let that = this; // minifier help
|
|
83
|
+
|
|
84
|
+
// render
|
|
85
|
+
target.innerHTML = this.#template;
|
|
86
|
+
|
|
87
|
+
// add translator
|
|
88
|
+
DC.add(
|
|
89
|
+
target,
|
|
90
|
+
'translator',
|
|
91
|
+
new Translator(target, that.#languages, target)
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
delete that._mc; // cleanup, not needed
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
oneInit(ev: McEvent) {
|
|
98
|
+
let that = this;
|
|
99
|
+
|
|
100
|
+
// state
|
|
101
|
+
that.Dom = { counter: 0 };
|
|
102
|
+
|
|
103
|
+
// state: convert all props defined so far into observables
|
|
104
|
+
observe(that);
|
|
105
|
+
|
|
106
|
+
// bind Dom to target
|
|
107
|
+
(that.Dom as Observable).bind(that.target);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
onClick(ev: McEvent) {
|
|
111
|
+
const that = this,
|
|
112
|
+
c = that.Dom.counter++;
|
|
113
|
+
(ev.data as PointerEvent).stopPropagation();
|
|
114
|
+
(that.target as HTMLElement).classList.remove('clicked');
|
|
115
|
+
(that.target as HTMLElement).classList.add(
|
|
116
|
+
that.Dom.counter > 9 ? 'overClicked' : 'clicked'
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
['language']
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
let MyTag: CustomElementConstructor = getCE('my-tag')!,
|
|
124
|
+
fragment = new DocumentFragment();
|
|
125
|
+
|
|
126
|
+
/*
|
|
127
|
+
stress test
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
let start = new Date().getTime(),
|
|
131
|
+
max = 100;
|
|
132
|
+
|
|
133
|
+
// create 1000 elements
|
|
134
|
+
for (let x = 0; x < max; x++) {
|
|
135
|
+
fragment.append(new MyTag());
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
let end = new Date().getTime();
|
|
139
|
+
|
|
140
|
+
// and put them into the DOM
|
|
141
|
+
document.body.appendChild(fragment);
|
|
142
|
+
|
|
143
|
+
//document.querySelectorAll('my-tag').forEach((e) => e.remove());
|
|
144
|
+
|
|
145
|
+
/*
|
|
146
|
+
console test
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
setTimeout(() => {
|
|
150
|
+
// console.clear();
|
|
151
|
+
|
|
152
|
+
console.log(
|
|
153
|
+
'%c \n\nStress Test:\n\n %cInstancing %s web components (%s classes): %c %s ms.',
|
|
154
|
+
'font-weight: bold; color: black;',
|
|
155
|
+
'font-weight: normal;',
|
|
156
|
+
max,
|
|
157
|
+
max * 3,
|
|
158
|
+
'font-weight: bold; color: blue;',
|
|
159
|
+
end - start
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
//document.body.appendChild(new MyTag());
|
|
163
|
+
|
|
164
|
+
let element = document.querySelector('my-tag');
|
|
165
|
+
|
|
166
|
+
console.log(
|
|
167
|
+
"\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
|
|
168
|
+
'font-weight: bold;',
|
|
169
|
+
'font-weight: normal;',
|
|
170
|
+
element,
|
|
171
|
+
'font-weight: bold;',
|
|
172
|
+
'\n\nLook up code in the debugger: test.js\n\n'
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
// will trigger the event on all micro components contained in <my-tag>
|
|
176
|
+
DC.trigger(element, 'doSomething');
|
|
177
|
+
}, 500);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.TestGrandparent=e():t.TestGrandparent=e()}(self,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{TestGrandparent:()=>S});var r=new Function("try {return this===window;}catch(e){ return false;}");let n=new Set;r()&&Object.keys(HTMLElement.prototype).filter((t=>/^on/.test(t))).forEach((t=>n.add(t)));class o{#t;#e=!1;#r=!1;constructor(t,e={},r="l"){this.#t=t,this.data=e,this.bubble=r}get type(){return this.#t}get stopped(){return this.#e}get immediateStopped(){return this.#r}stopPropagation(){this.#e=!0}stopImmediatePropagation(){this.stopPropagation(),this.#r=!0}}var s=new Function("try {return this===window;}catch(e){ return false;}");let c=new Set;function i(t,e){let r=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const n=t?._mc;!e&&n?r=r.concat(Object.values(t._mc)):e&&n&&n[e]&&r.push(n[e])}})),r}function a(t,e,r=!0){let n=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&n.push(t._mc[e]):n=n.concat(Object.values(t._mc)),r))return n;t=t.parentNode}return n}function l(t){return t&&t instanceof HTMLElement}function u(t,e,r={}){let n=t;if(!n._mc){let e=b?.debug;b.debug=!1,n._mc=new b(t),b.debug=e,delete n._mc._mc}const o=n._mc;return e.length&&!o[e]&&(o[e]=r,t instanceof HTMLElement&&t.setAttribute("_mc","")),r}function d(t,e){if(!e)return;const r=t?._mc||{};r&&r[e]&&delete r[e],!Object.keys(r).length&&t instanceof HTMLElement&&t.hasAttribute("_mc")&&t.removeAttribute("_mc")}function p(t,e,r={},n="l"){let s=t?._mc;if(!s)return;let c=e instanceof o?new o(e.type,e.data,"l"):new o(e,r,"l"),i="string"!=typeof e?e:new o(e,r,n);[...Object.values(s)].forEach((t=>{t?.trigger&&"function"==typeof t?.trigger&&t?.trigger(c)})),/[ud]/.test(i.bubble)&&g(t,i)}function g(t,e){/[ud]/.test(e.bubble)&&setTimeout((()=>{if(-1===e.bubble.indexOf("l")&&(e.bubble+="l"),e.bubble.indexOf("u")>-1){let r=a(t,"",!0)?.[0].target;r&&b.trigger(r,e)}e.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&b.trigger(t,e)}))}),0)}s()&&Object.keys(HTMLElement.prototype).filter((t=>/^on/.test(t))).forEach((t=>c.add(t)));class f{#n;constructor(t,e=!1){var r;this.#n=new WeakRef(t||{}),(r=this).constructor!==b&&setTimeout((()=>{r.trigger("Init")}),0),function(t){if(!s()||t.constructor===b)return;const e=t.target;if(e instanceof HTMLElement){let r=t;Object.getOwnPropertyNames(r.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof r.constructor.prototype[t])).forEach((n=>{let o=/^one/.test(n),s=n.replace(/^on[e]{0,1}/,""),i=s.toLowerCase();o&&Object.defineProperty(t,"on"+s,{configurable:!0,enumerable:!1,writable:!0,value:t=>{r.constructor.prototype[n].bind(r)(t)}}),c.has("on"+i)&&function(t,e,r,n=!1,o=!1){let s={once:!1};n&&(s.capture=n),o&&(s.once=o),t.addEventListener(e,r,s)}(e,i,(t=>{r.trigger(s,t)}),!1,o)}))}}(this)}get target(){return this.#n.deref()}}class m extends f{_mc={};constructor(t){super(t)}static trigger=p;trigger(t,e={},r="l"){let n=this;if(n.constructor===m||n.constructor===b){let s=t instanceof o?new o(t.type,t.data,"l"):new o(t,e,"l"),c="string"!=typeof t?t:new o(t,e,r);return[...Object.getOwnPropertyNames(n)].forEach((t=>{n[t]?.trigger&&"function"==typeof n[t]?.trigger&&n[t]?.trigger(s)})),void(/[ud]/.test(c.bubble)&&g(n.target,c))}if(n instanceof m||n instanceof b){const n=this,s="string"!=typeof t?t:new o(t,e,r),c="on"+s.type[0].toUpperCase()+s.type.slice(1);if(s.bubble.indexOf("l")>-1&&(s.immediateStopped||"function"!=typeof n[c]||(n[c](s),n.hasOwnProperty(c)&&delete n[c])),s.stopped||"l"===s.bubble)return n;/[ud]/.test(s.bubble)&&g(n.target,s)}}}class b extends f{_mc={};constructor(t,e=!1){super(t)}static add=u;static remove=d;static trigger=p;trigger(t,e={},r){m.prototype.trigger.call(this,t,e,r)}parent(t=""){let e=this.target;return l(e)?a(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return l(e)?a(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;if(!l(e))return[];const r=Math.random().toString().replace(".",""),n='[_mc]:not([temp_id="'+r+'"] [_mc] [_mc])';e.setAttribute("temp_id",r);const o=i([...e.querySelectorAll(n)],t);return e.removeAttribute("temp_id"),o}descendants(t=""){let e=this?.target;return l(e)?i([...e.querySelectorAll("*[_mc]")],t):[]}}new Map;class h extends HTMLElement{constructor(){super()}connectedCallback(){b.trigger(this,"Connected")}disconnectedCallback(){b.trigger(this,"Disconnected")}adoptedCallback(){b.trigger(this,"Adopted")}attributeChangedCallback(t,e,r){b.trigger(this,"AttributeChanged",{name:t,oldValue:e,newValue:r})}}function y(t,e,r=[]){if(customElements.get(t))return void console.warn(`IGNORED: Custom element "${t}" is already defined!`);if(!t.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let n=t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("");customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(n,class extends h{instance;constructor(t){super();let r=new e(this,t);b.add(this,n,r)}static get observedAttributes(){return r}}))}function w(t){return customElements.get(t)}function _(t,e){return Math.floor(Math.random()*(e-t+1)+t)}y("test-greatgrandchild",class extends b{constructor(t){super(t)}onConnected(){this.updateStyle()}updateStyle(){this.target.setAttribute("style","border-color:rgb("+_(0,255)+","+_(0,255)+","+_(0,255)+")")}});const O=w("test-greatgrandchild");y("test-grandchild",class extends b{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<2;e++)t.target.append(new O)}});const E=w("test-grandchild");y("test-child",class extends b{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<10;e++)t.target.append(new E)}});const v=w("test-child");y("test-parent",class extends b{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<5;e++)t.target.append(new v)}});const j=w("test-parent");y("test-grandparent",class extends b{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<5;e++)t.target.append(new j)}});const S=w("test-grandparent");return e})()));
|
|
@@ -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.TestTestform=t():e.TestTestform=t()}(self,(()=>(()=>{"use strict";var e=new Function("try {return this===window;}catch(e){ return false;}");let t=new Set;e()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>t.add(e)));class n{#e;#t=!1;#n=!1;constructor(e,t={},n="l"){this.#e=e,this.data=t,this.bubble=n}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#n}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#n=!0}}var a=new Function("try {return this===window;}catch(e){ return false;}");let r=new Set;function l(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 o(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 i(e){return e&&e instanceof HTMLElement}function s(e,t,n,a=!1,r=!1){let l={once:!1};a&&(l.capture=a),r&&(l.once=r),e.addEventListener(t,n,l)}function c(e,t,n={}){let a=e;if(!a._mc){let t=m?.debug;m.debug=!1,a._mc=new m(e),m.debug=t,delete a._mc._mc}const r=a._mc;return t.length&&!r[t]&&(r[t]=n,e instanceof HTMLElement&&e.setAttribute("_mc","")),n}function u(e,t){if(!t)return;const n=e?._mc||{};n&&n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function p(e,t,a={},r="l"){let l=e?._mc;if(!l)return;let o=t instanceof n?new n(t.type,t.data,"l"):new n(t,a,"l"),i="string"!=typeof t?t:new n(t,a,r);[...Object.values(l)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(o)})),/[ud]/.test(i.bubble)&&d(e,i)}function d(e,t){/[ud]/.test(t.bubble)&&setTimeout((()=>{if(-1===t.bubble.indexOf("l")&&(t.bubble+="l"),t.bubble.indexOf("u")>-1){let n=o(e,"",!0)?.[0].target;n&&m.trigger(n,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&m.trigger(e,t)}))}),0)}a()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>r.add(e)));class b{#a;constructor(e,t=!1){var n;this.#a=new WeakRef(e||{}),(n=this).constructor!==m&&setTimeout((()=>{n.trigger("Init")}),0),function(e){if(!a()||e.constructor===m)return;const t=e.target;if(t instanceof HTMLElement){let n=e;Object.getOwnPropertyNames(n.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof n.constructor.prototype[e])).forEach((a=>{let l=/^one/.test(a),o=a.replace(/^on[e]{0,1}/,""),i=o.toLowerCase();l&&Object.defineProperty(e,"on"+o,{configurable:!0,enumerable:!1,writable:!0,value:e=>{n.constructor.prototype[a].bind(n)(e)}}),r.has("on"+i)&&s(t,i,(e=>{n.trigger(o,e)}),!1,l)}))}}(this)}get target(){return this.#a.deref()}}class f extends b{_mc={};constructor(e){super(e)}static trigger=p;trigger(e,t={},a="l"){let r=this;if(r.constructor===f||r.constructor===m){let l=e instanceof n?new n(e.type,e.data,"l"):new n(e,t,"l"),o="string"!=typeof e?e:new n(e,t,a);return[...Object.getOwnPropertyNames(r)].forEach((e=>{r[e]?.trigger&&"function"==typeof r[e]?.trigger&&r[e]?.trigger(l)})),void(/[ud]/.test(o.bubble)&&d(r.target,o))}if(r instanceof f||r instanceof m){const r=this,l="string"!=typeof e?e:new n(e,t,a),o="on"+l.type[0].toUpperCase()+l.type.slice(1);if(l.bubble.indexOf("l")>-1&&(l.immediateStopped||"function"!=typeof r[o]||(r[o](l),r.hasOwnProperty(o)&&delete r[o])),l.stopped||"l"===l.bubble)return r;/[ud]/.test(l.bubble)&&d(r.target,l)}}}class m extends b{_mc={};constructor(e,t=!1){super(e)}static add=c;static remove=u;static trigger=p;trigger(e,t={},n){f.prototype.trigger.call(this,e,t,n)}parent(e=""){let t=this.target;return i(t)?o(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return i(t)?o(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!i(t))return[];const n=Math.random().toString().replace(".",""),a='[_mc]:not([temp_id="'+n+'"] [_mc] [_mc])';t.setAttribute("temp_id",n);const r=l([...t.querySelectorAll(a)],e);return t.removeAttribute("temp_id"),r}descendants(e=""){let t=this?.target;return i(t)?l([...t.querySelectorAll("*[_mc]")],e):[]}}function g(e){let t={};return[...Object.keys(e)].sort().forEach((n=>{var a;(a=e[n])&&a.constructor&&a.constructor===Object?t[n]=g(e[n]):t[n]=e[n]})),t}function h(e,t=!0){let n={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const a=h(e[t],!1);for(const e in a)n[t+"."+e]=a[e]}else n[t]=e[t]})),t?g(n):n}function y(e,t){return JSON.stringify(h(e))===JSON.stringify(h(t))}function v(e,t){let n;return()=>{clearTimeout(n),n=setTimeout((function(){e(...arguments)}),t)}}function O(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 Map;class w extends HTMLElement{constructor(){super()}connectedCallback(){m.trigger(this,"Connected")}disconnectedCallback(){m.trigger(this,"Disconnected")}adoptedCallback(){m.trigger(this,"Adopted")}attributeChangedCallback(e,t,n){m.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:n})}}function x(e){return null!=e&&"object"==typeof e}function E(e){let t=new Set,n=/\{[^\{\}]*\}/g;return e.getAttributeNames().filter((t=>e.getAttribute(t)?.match(n))).forEach((a=>{new Set(e.getAttribute(a)?.match(n)).forEach((e=>t.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,""))),[...t]}const k=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class A extends m{data={};oldDisplay="";constructor(e){super(e);let t=this;E(e).forEach((e=>t.data[e]="")),j(t),t.#r(),delete t._mc}#r(){let e=this,t=e.target,n=!1;t.getAttributeNames().filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((n=>{let a=new Set(t.getAttribute(n)?.match(/\{[^\{\}]*\}/g));var r;e.data.observe((r=t.getAttribute(n),e=>{let l=r;a.forEach((t=>{l=l.replace(t,e[t.replace(/[\{\}]/g,"")])})),t.setAttribute(n,l)}))})),[...t.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((a=>{n=!0;let r=new Set(a.nodeValue.match(/\{[^\{\}]*\}/g));var l;e.data.observe((l=a.nodeValue,n=>{let o=l;r.forEach((e=>{o=o.replace(e,n[e.replace(/[\{\}]/g,"")])})),Object.keys(n).some((e=>!!n[e]))&&(e.oldDisplay?t.style=e.oldDisplay:t.removeAttribute("style"),delete e.oldDisplay),a.nodeValue=o})),e.oldDisplay=t.getAttribute("style)")||"",n&&!k.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(e){let t=this,n={};Object.keys(e.data).forEach((a=>{t.data.hasOwnProperty(a)&&(n[a]=e.data[a])})),JSON.stringify(n)!==JSON.stringify(t.data)&&Object.assign(t.data,n)}}const j=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return e;let n,a=e[t];if(!a.prototype)switch(typeof a){case"string":n=String;break;case"number":n=Number;break;case"boolean":n=Boolean;break;case"object":n=a instanceof Array?Array:Object;break;default:return}let r=class extends n{#l=!0;constructor(e){super(e),this.constructor.callbacks=[],x(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}observe(e){return this.constructor.callbacks.push(e),this}bind(e){const t=this;if(x(t.valueOf())){!function(e){var t;(t=e,(t instanceof HTMLElement?[t]:[]).concat([...t.querySelectorAll("*")]).filter((e=>!!E(e).length)).filter((e=>"STYLE"!==e.tagName))).forEach((e=>{e?._mc?._placeholders||m.add(e,"_placeholders",new A(e))}))}(e);const n=[...e.querySelectorAll("[_mc]")].filter((e=>!!e?._mc?._placeholders)),a=function(e){let t=h(e);n.forEach((e=>{e&&e._mc.trigger("data",t)}))};t.constructor.callbacks.push(a),t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf(),t);return this}notify(e){let t=this,n=x(t.valueOf())&&t.valueOf()instanceof Array==0?structuredClone(Object.assign({},t)):t.valueOf();return void 0!==e&&(t.#l=e),t.constructor.callbacks.forEach((e=>{e(n)})),t}},l=new r(a);Object.defineProperty(e,t,{enumerable:!0,get(){if(x(l.valueOf())){let e=structuredClone(Object.assign({},l));setTimeout(v((function(){y(structuredClone(Object.assign({},l)),e)||l.notify()}),0),0)}return l},set(e){if(typeof e==typeof l.valueOf())if(x(l.valueOf())&&l.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},l));l instanceof r==0&&(l=new r(structuredClone(Object.assign({},e))),O(e,l),l.seal()),Object.assign(l,e),setTimeout(v((function(){y(structuredClone(Object.assign({},l)),t)||l.notify()}),0),0)}else{let t=l.valueOf(),n=l.constructor.callbacks;l=new r(e),l.constructor.callbacks=n,e!==t&&l.notify()}else console.warn("IGNORED - cannot change observable types, IS:",typeof l.valueOf(),l,"- CANNOT BECOME:",typeof e)}}),e[t]=a})),e);class S{constructor(e){}}class _ extends S{#o;#i;constructor(e,t){super(e),this.#o=e,this.#i=t}get val(){return new FormData(this.#i).get(this.#o.name)}set val(e){[...this.#i.querySelectorAll(`input[type="radio][name="${this.#o.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class T extends S{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.checked}set val(e){this.#o.checked=e}}class N extends S{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.value}set val(e){this.#o.value=e}}class C extends S{#o;#s=!1;constructor(e){super(e),this.#o=e,this.#s=e.multiple}get val(){const e=[];return[...this.#o.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{t.selected&&e.push(t.value)})),this.#s?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#o.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?(t.setAttribute("selected","selected"),t.selected=!0):(t.removeAttribute("selected"),t.selected=!1)}))}}class I extends S{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.value||""}set val(e){this.#o.value=e}}class L{constructor(e,t,n){let a=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],n={};return t.forEach((t=>{const a=t.getAttribute("name")||"undefined";if(a){let r=t.type,l=!1;switch((e=>e.tagName.toLowerCase())(t)){case"input":switch(r){case"radio":l=new _(t,e.constructor===HTMLFormElement?e:e.querySelector("form"));break;case"checkbox":l=new T(t);break;default:l=new N(t)}break;case"select":l=new C(t);break;case"textarea":l=new I(t);break;default:console.warn("handler missing:",a,"for",t.tagName.toLowerCase(),t)}l&&(m.add(t,a,l),Object.defineProperty(n,a,{enumerable:!0,configurable:!0,get:()=>l.val,set:e=>{l.val!==e&&(l.val=e)}}))}})),n})(n);e[t]=Object.assign({},a),j(e,t),O(a,e[t]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{s(n,"keyup",(n=>{e[t].notify()})),s(n,"change",(n=>{e[t].notify()})),s(n,"select",(n=>{e[t].notify()}))}))}}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("");customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(a,class extends w{instance;constructor(e){super();let n=new t(this,e);m.add(this,a,n)}static get observedAttributes(){return n}}))}("test-testform",class extends m{data;constructor(e){super(e);const t=this;delete this._mc;let n=t.target.attachShadow({mode:"open"});n.innerHTML=`<style>${this.css}</style>${this.template}`,new L(t,"data",n),t.data.bind(n)}onConnected(){}oneInit(){}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}\n <label>color</label><input type="color" name="colorInput" value="" />\n <label>date</label><input type="date" name="dateInput" value="" />\n <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" />\n <label>email</label><input type="email" name="email" value="" />\n <label>file</label><input type="file" name="fileInput" value="" />\n <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" />\n <label>month</label><input type="month" name="month" value="" />\n <label>number</label><input type="number" name="number" value="" />\n <label>password</label><input type="password" name="passInput" value="" />\n <label>range</label><input type="range" name="rangeInput" value="" />\n <label>search</label><input type="search" name="searchInput" value="" />\n <label>tel</label><input type="tel" name="telInput" value="" />\n <label>time</label><input type="time" name="timeInput" value="" />\n <label>url</label><input type="url" name="urlInput" value="" />\n <label>week</label><input type="week" name="weekInput" value="" />\n </fieldset>\n\n <fieldset>\n <legend>Selects</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>\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">\n <label>radio2</label><input type="radio" name="myRadio" value="radio2">\n <label>radio3</label><input type="radio" name="myRadio" value="radio3">\n\n </fieldset>\n\n <fieldset>\n <legend>Checkboxes</legend>\n <label>cb1</label><input type="checkbox" name="cb1">\n <label>cb2</label><input type="checkbox" name="cb2">\n <label>cb3</label><input type="checkbox" name="cb3">\n <label>cb4</label><input type="checkbox" name="cb4">\n <label>cb5</label><input type="checkbox" name="cb5">\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}\n\nlabel {\n display: inline;\n margin-top: 5px;\n margin-left: 5px;\n vertical-align: top;\n width: 10em;\n text-align: right;\n}\n\nlabel::before {\n content: ' ';\n display: block;\n}\n\nform input,\nform select,\nform textarea {\n margin-left: 5px;\n margin-top: 0px;\n display: inline;\n}\n\nform label + textarea {\n display: inline-block;\n margin-top: 3px;\n}\n\nform input + label {\n width: inherit;\n margin-top: 3px;\n text-align: left;\n}\n\nbody > form {\n display: block;\n}\n\nform fieldset {\n border: 1px solid darkslategrey;\n border-radius: 3px;\n margin: 0.5em 0;\n}\n "}}),{}})()));
|
package/public/test.html
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Micro Components Manual Test</title>
|
|
7
|
+
<link
|
|
8
|
+
rel="icon"
|
|
9
|
+
type="image/svg+xml"
|
|
10
|
+
sizes="any"
|
|
11
|
+
href="MicroComponents.svg"
|
|
12
|
+
/>
|
|
13
|
+
<link href="./my-tag.css" rel="stylesheet" />
|
|
14
|
+
<link href="./Grandparent.css" rel="stylesheet" />
|
|
15
|
+
<script src="./microcomponents.min.js"></script>
|
|
16
|
+
<script>
|
|
17
|
+
Object.assign(window, microcomponents); // make system global, for debugging
|
|
18
|
+
autoload(true); // automatically load web components that are undefined
|
|
19
|
+
</script>
|
|
20
|
+
<script type="module" src="./test.js"></script>
|
|
21
|
+
</head>
|
|
22
|
+
<body>
|
|
23
|
+
<test-grandparent></test-grandparent>
|
|
24
|
+
<test-testform></test-testform>
|
|
25
|
+
Open the debugger, read console, then:<br />
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
package/public/test.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
import { DC, defineCE, getCE, observe, } from './microcomponents.js';
|
|
3
|
+
class Translator extends DC {
|
|
4
|
+
#translations = {};
|
|
5
|
+
Language = 'en';
|
|
6
|
+
Translation = {};
|
|
7
|
+
constructor(target, translations, translationTargetObject) {
|
|
8
|
+
super(target);
|
|
9
|
+
let that = this;
|
|
10
|
+
that.Language = 'en';
|
|
11
|
+
that.Translation = {};
|
|
12
|
+
observe(that);
|
|
13
|
+
that.#translations = translations;
|
|
14
|
+
that.Language.observe((lang) => {
|
|
15
|
+
if (that.#translations.hasOwnProperty(lang)) {
|
|
16
|
+
that.Translation = { lang: that.#translations[lang] };
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
that.Translation.bind(translationTargetObject);
|
|
20
|
+
that.target.setAttribute('language', 'en');
|
|
21
|
+
that.Language.notify();
|
|
22
|
+
delete that._mc;
|
|
23
|
+
}
|
|
24
|
+
onAttributeChanged(ev) {
|
|
25
|
+
if (!ev.data.newValue)
|
|
26
|
+
return;
|
|
27
|
+
switch (ev.data.name) {
|
|
28
|
+
case 'language':
|
|
29
|
+
this.Language = ev.data.newValue;
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
defineCE('my-tag', class MyTag extends DC {
|
|
35
|
+
#template = '<button>{lang.click} {counter}</button>';
|
|
36
|
+
#languages = {
|
|
37
|
+
en: {
|
|
38
|
+
click: 'click me',
|
|
39
|
+
},
|
|
40
|
+
de: {
|
|
41
|
+
click: 'klick mich',
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
Dom = {};
|
|
45
|
+
constructor(target) {
|
|
46
|
+
super(target);
|
|
47
|
+
let that = this;
|
|
48
|
+
target.innerHTML = this.#template;
|
|
49
|
+
DC.add(target, 'translator', new Translator(target, that.#languages, target));
|
|
50
|
+
delete that._mc;
|
|
51
|
+
}
|
|
52
|
+
oneInit(ev) {
|
|
53
|
+
let that = this;
|
|
54
|
+
that.Dom = { counter: 0 };
|
|
55
|
+
observe(that);
|
|
56
|
+
that.Dom.bind(that.target);
|
|
57
|
+
}
|
|
58
|
+
onClick(ev) {
|
|
59
|
+
const that = this, c = that.Dom.counter++;
|
|
60
|
+
ev.data.stopPropagation();
|
|
61
|
+
that.target.classList.remove('clicked');
|
|
62
|
+
that.target.classList.add(that.Dom.counter > 9 ? 'overClicked' : 'clicked');
|
|
63
|
+
}
|
|
64
|
+
}, ['language']);
|
|
65
|
+
let MyTag = getCE('my-tag'), fragment = new DocumentFragment();
|
|
66
|
+
let start = new Date().getTime(), max = 100;
|
|
67
|
+
for (let x = 0; x < max; x++) {
|
|
68
|
+
fragment.append(new MyTag());
|
|
69
|
+
}
|
|
70
|
+
let end = new Date().getTime();
|
|
71
|
+
document.body.appendChild(fragment);
|
|
72
|
+
setTimeout(() => {
|
|
73
|
+
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 * 3, 'font-weight: bold; color: blue;', end - start);
|
|
74
|
+
let element = document.querySelector('my-tag');
|
|
75
|
+
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\n');
|
|
76
|
+
DC.trigger(element, 'doSomething');
|
|
77
|
+
}, 500);
|
|
78
|
+
//# sourceMappingURL=test.js.map
|
|
@@ -0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
160
160
|
if (name) {
|
|
161
161
|
let h: InputBase,
|
|
162
162
|
type = (i as HTMLInputElement).type,
|
|
163
|
-
handler: any;
|
|
163
|
+
handler: any = false;
|
|
164
164
|
switch (getInputName(i as inputTypes)) {
|
|
165
165
|
case 'input':
|
|
166
166
|
switch (type) {
|
|
@@ -171,62 +171,19 @@ const getInputHandlers = (e: HTMLElement | ShadowRoot): LooseObject => {
|
|
|
171
171
|
? e
|
|
172
172
|
: e.querySelector('form')) as HTMLFormElement
|
|
173
173
|
);
|
|
174
|
-
DC.add(i, name, handler);
|
|
175
174
|
break;
|
|
176
175
|
case 'checkbox':
|
|
177
176
|
handler = new CheckboxHandler(i as HTMLInputElement);
|
|
178
|
-
DC.add(i, name, handler);
|
|
179
177
|
break;
|
|
180
178
|
default:
|
|
181
179
|
handler = new InputHandler(i as HTMLInputElement);
|
|
182
|
-
DC.add(i, name, handler);
|
|
183
180
|
}
|
|
184
|
-
|
|
185
|
-
Object.defineProperty(handlers, name, {
|
|
186
|
-
enumerable: true,
|
|
187
|
-
configurable: true,
|
|
188
|
-
get: (): any => {
|
|
189
|
-
return handler.val;
|
|
190
|
-
},
|
|
191
|
-
set: (value: any) => {
|
|
192
|
-
if (handler.val !== value) {
|
|
193
|
-
handler.val = value;
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
});
|
|
197
|
-
|
|
198
181
|
break;
|
|
199
182
|
case 'select':
|
|
200
183
|
handler = new SelectHandler(i as HTMLSelectElement);
|
|
201
|
-
DC.add(i, name, handler);
|
|
202
|
-
Object.defineProperty(handlers, name, {
|
|
203
|
-
enumerable: true,
|
|
204
|
-
configurable: true,
|
|
205
|
-
get: (): any => {
|
|
206
|
-
return handler.val;
|
|
207
|
-
},
|
|
208
|
-
set: (value: any) => {
|
|
209
|
-
if (handler.val !== value) {
|
|
210
|
-
handler.val = value;
|
|
211
|
-
}
|
|
212
|
-
},
|
|
213
|
-
});
|
|
214
184
|
break;
|
|
215
185
|
case 'textarea':
|
|
216
186
|
handler = new TextAreaHandler(i as HTMLTextAreaElement);
|
|
217
|
-
DC.add(i, name, handler);
|
|
218
|
-
Object.defineProperty(handlers, name, {
|
|
219
|
-
enumerable: true,
|
|
220
|
-
configurable: true,
|
|
221
|
-
get: (): any => {
|
|
222
|
-
return handler.val;
|
|
223
|
-
},
|
|
224
|
-
set: (value: any) => {
|
|
225
|
-
if (handler.val !== value) {
|
|
226
|
-
handler.val = value;
|
|
227
|
-
}
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
187
|
break;
|
|
231
188
|
default:
|
|
232
189
|
console.warn(
|
|
@@ -238,6 +195,22 @@ const getInputHandlers = (e: HTMLElement | ShadowRoot): LooseObject => {
|
|
|
238
195
|
);
|
|
239
196
|
break;
|
|
240
197
|
}
|
|
198
|
+
|
|
199
|
+
if (handler) {
|
|
200
|
+
DC.add(i, name, handler);
|
|
201
|
+
Object.defineProperty(handlers, name, {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
configurable: true,
|
|
204
|
+
get: (): any => {
|
|
205
|
+
return handler.val;
|
|
206
|
+
},
|
|
207
|
+
set: (value: any) => {
|
|
208
|
+
if (handler.val !== value) {
|
|
209
|
+
handler.val = value;
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
});
|
|
213
|
+
}
|
|
241
214
|
}
|
|
242
215
|
});
|
|
243
216
|
|