@twobirds/microcomponents 0.0.48 → 0.0.50
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/assets/Grandparent.css +13 -0
- package/assets/documentation/MC.md +380 -166
- package/assets/test.html +5 -1
- package/dist/MC.d.ts +1 -0
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.min.js +44 -0
- package/dist/MC.ts +65 -0
- package/dist/elements.min.js +1 -1
- package/dist/elements.ts +10 -10
- package/dist/formValues.d.ts +3 -2
- package/dist/formValues.d.ts.map +1 -1
- package/dist/formValues.ts +206 -203
- package/dist/formvValues.min.js +1 -1
- package/dist/helpers.d.ts +1 -0
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.ts +9 -0
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.d.ts +1 -1
- package/dist/observables.d.ts.map +1 -1
- package/dist/observables.min.js +1 -1
- package/dist/observables.ts +64 -31
- package/dist/selectors.min.js +1 -1
- package/dist/test.ts +8 -5
- package/package.json +1 -1
- package/public/Grandparent.css +13 -0
- package/public/Grandparent.js +338 -0
- package/public/MC.js +43 -0
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +44 -0
- package/public/TestForm.css +47 -0
- package/public/TestForm.html +56 -0
- package/public/TestForm.js +56 -0
- package/public/TestForm.json +27 -0
- package/public/Testform.js +149 -0
- package/public/classes/MC.DC.html +13 -13
- package/public/classes/MC.MC.html +7 -7
- package/public/classes/MC.McBase.html +4 -4
- package/public/classes/MC.McEvent.html +13 -13
- package/public/documentation/MC.md +380 -166
- package/public/documentation/observe.md +317 -0
- package/public/elements.js +9 -9
- package/public/elements.js.map +1 -1
- package/public/elements.min.js +1 -1
- package/public/formValues.js +142 -133
- package/public/formValues.js.map +1 -1
- package/public/formvValues.min.js +1 -1
- package/public/functions/MC.addListener.html +1 -1
- package/public/functions/MC.removeListener.html +1 -1
- package/public/functions/elements.defineCE.html +1 -1
- package/public/functions/elements.getCE.html +1 -1
- package/public/functions/formValues.formValues.html +1 -1
- package/public/functions/observables.observe.html +1 -1
- package/public/functions/selectors._d.html +1 -1
- package/public/functions/selectors._t.html +1 -1
- package/public/helpers.js +8 -0
- package/public/helpers.js.map +1 -1
- package/public/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/interfaces/selectors.DSelector.html +55 -55
- package/public/interfaces/selectors.TSelector.html +37 -37
- package/public/microcomponents.min.js +1 -1
- package/public/modules/MC.html +1 -1
- package/public/modules/elements.html +1 -1
- package/public/modules/formValues.html +1 -1
- package/public/modules/observables.html +1 -1
- package/public/modules/selectors.html +1 -1
- package/public/observables.js +31 -19
- package/public/observables.js.map +1 -1
- package/public/observables.min.js +1 -1
- package/public/selectors.min.js +1 -1
- package/public/src/MC.ts +65 -0
- package/public/src/elements.ts +10 -10
- package/public/src/formValues.ts +206 -203
- package/public/src/helpers.ts +9 -0
- package/public/src/observables.ts +64 -31
- package/public/src/test.ts +8 -5
- package/public/test/Grandparent.js +1 -0
- package/public/test/Testform.js +1 -0
- package/public/test.html +5 -1
- package/public/test.js +3 -4
- package/public/test.js.map +1 -1
- package/public/types/observables.Observable.html +1 -1
- package/public/types/selectors.selection.html +1 -1
- package/public/types/selectors.singleSelector.html +1 -1
- package/src/MC.ts +65 -0
- package/src/elements.ts +10 -10
- package/src/formValues.ts +206 -203
- package/src/helpers.ts +9 -0
- package/src/observables.ts +64 -31
- package/src/test/Child.ts +21 -0
- package/src/test/Grandchild.ts +21 -0
- package/src/test/Grandparent.css +11 -0
- package/src/test/Grandparent.ts +21 -0
- package/src/test/Greatgrandchild.ts +42 -0
- package/src/test/Parent.ts +21 -0
- package/src/test/Testform.css +47 -0
- package/src/test/Testform.html +56 -0
- package/src/test/Testform.json +27 -0
- package/src/test/Testform.ts +159 -0
- package/src/test.ts +8 -5
- package/webpack.config.js +135 -61
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
LooseObject,
|
|
5
|
-
parse,
|
|
6
5
|
debounce,
|
|
7
6
|
deepEqual,
|
|
8
|
-
nameSpace,
|
|
9
7
|
flattenObject,
|
|
8
|
+
copyGettersSetters,
|
|
10
9
|
} from './helpers.js';
|
|
11
10
|
|
|
12
11
|
import { DC, HTMLMcElement, McEvent } from './MC.js';
|
|
@@ -79,7 +78,7 @@ class Placeholders extends DC {
|
|
|
79
78
|
target = that.target,
|
|
80
79
|
hide: boolean = false;
|
|
81
80
|
|
|
82
|
-
//
|
|
81
|
+
//console.log('attachCallbacks', that.target);
|
|
83
82
|
|
|
84
83
|
// scan attributes
|
|
85
84
|
target
|
|
@@ -126,6 +125,7 @@ class Placeholders extends DC {
|
|
|
126
125
|
that.data.observe(
|
|
127
126
|
((template: string) => (data: LooseObject) => {
|
|
128
127
|
let result: string = template;
|
|
128
|
+
//console.log('text node "', template, '" callbach data:', data);
|
|
129
129
|
phs.forEach((placeholder) => {
|
|
130
130
|
result = result.replace(
|
|
131
131
|
placeholder,
|
|
@@ -150,7 +150,11 @@ class Placeholders extends DC {
|
|
|
150
150
|
|
|
151
151
|
// hide for now
|
|
152
152
|
that.oldDisplay = target.getAttribute('style)') || '';
|
|
153
|
-
if (
|
|
153
|
+
if (
|
|
154
|
+
hide &&
|
|
155
|
+
!inputs.includes((target as any).constructor) &&
|
|
156
|
+
target.tagName !== 'FIELDSET'
|
|
157
|
+
) {
|
|
154
158
|
target.style.display = 'none';
|
|
155
159
|
}
|
|
156
160
|
});
|
|
@@ -162,7 +166,7 @@ class Placeholders extends DC {
|
|
|
162
166
|
Object.keys(ev.data).forEach((key) => {
|
|
163
167
|
if (that.data.hasOwnProperty(key)) data[key] = ev.data[key];
|
|
164
168
|
});
|
|
165
|
-
//
|
|
169
|
+
//console.log('onData()', ev, data, that.data);
|
|
166
170
|
if (JSON.stringify(data) !== JSON.stringify(that.data))
|
|
167
171
|
Object.assign(that.data, data); // will trigger callbacks
|
|
168
172
|
}
|
|
@@ -175,13 +179,16 @@ function getPlaceholderElements(
|
|
|
175
179
|
target instanceof HTMLElement ? [target] : []
|
|
176
180
|
)
|
|
177
181
|
.concat([...(target.querySelectorAll('*') as unknown as HTMLElement[])])
|
|
178
|
-
.filter((e) => !!getPlaceholders(e as HTMLElement).length)
|
|
182
|
+
.filter((e) => !!getPlaceholders(e as HTMLElement).length)
|
|
183
|
+
.filter((e) => e.tagName !== 'STYLE');
|
|
184
|
+
//console.log('getPlaceholderElements', elements);
|
|
179
185
|
return elements as HTMLElement[];
|
|
180
186
|
}
|
|
181
187
|
|
|
182
|
-
function
|
|
188
|
+
function makePlaceholders(
|
|
183
189
|
element: HTMLElement | DocumentFragment | ShadowRoot
|
|
184
190
|
): void {
|
|
191
|
+
//console.log('makePlaceholders', element);
|
|
185
192
|
getPlaceholderElements(element).forEach((e: HTMLElement) => {
|
|
186
193
|
if ((e as HTMLMcElement)?._mc?._placeholders) return;
|
|
187
194
|
DC.add(e, '_placeholders', new Placeholders(e));
|
|
@@ -194,14 +201,17 @@ export type Observable = {
|
|
|
194
201
|
bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
|
|
195
202
|
};
|
|
196
203
|
|
|
197
|
-
export const observe = (
|
|
204
|
+
export const observe = (
|
|
205
|
+
target: LooseObject,
|
|
206
|
+
propertyName?: string
|
|
207
|
+
): LooseObject => {
|
|
198
208
|
let keys = !propertyName
|
|
199
209
|
? [...Object.getOwnPropertyNames(target)]
|
|
200
210
|
: [propertyName];
|
|
201
211
|
|
|
202
212
|
keys.forEach((key) => {
|
|
203
213
|
// console.log( 'co propname', key, typeof target[key], target[key] );
|
|
204
|
-
if (key[0] === '_' || target?.[key] === undefined) return;
|
|
214
|
+
if (key[0] === '_' || target?.[key] === undefined) return target;
|
|
205
215
|
let val: any = target[key],
|
|
206
216
|
Constructor: any;
|
|
207
217
|
|
|
@@ -229,6 +239,8 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
229
239
|
}
|
|
230
240
|
|
|
231
241
|
let Observable = class extends Constructor {
|
|
242
|
+
#notify: boolean = true;
|
|
243
|
+
|
|
232
244
|
constructor(val: any) {
|
|
233
245
|
super(val);
|
|
234
246
|
(this.constructor as LooseObject).callbacks = [];
|
|
@@ -252,16 +264,22 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
252
264
|
//console.log('bind', iso, target);
|
|
253
265
|
|
|
254
266
|
if (iso) {
|
|
255
|
-
|
|
256
|
-
|
|
267
|
+
makePlaceholders(target);
|
|
268
|
+
const placeholders: unknown = [
|
|
269
|
+
...target.querySelectorAll('[_mc]'),
|
|
270
|
+
].filter((e) => !!(e as LooseObject)?._mc?._placeholders);
|
|
271
|
+
//console.log('placeholders:', target, placeholders);
|
|
272
|
+
const func = function callback(data: LooseObject) {
|
|
257
273
|
// avoid bubbling for speed
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
274
|
+
let d = flattenObject(data);
|
|
275
|
+
//console.log('inside callback', target, d);
|
|
276
|
+
(placeholders as DC[]).forEach((e) => {
|
|
277
|
+
// console.log('trigger callback', e);
|
|
278
|
+
if (!e) return;
|
|
279
|
+
(e as any)._mc.trigger('data', d);
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
(that.constructor as any).callbacks.push(func);
|
|
265
283
|
that.notify();
|
|
266
284
|
} else {
|
|
267
285
|
console.warn(
|
|
@@ -274,22 +292,34 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
274
292
|
return this;
|
|
275
293
|
}
|
|
276
294
|
|
|
277
|
-
notify() {
|
|
295
|
+
notify(notify?: boolean) {
|
|
278
296
|
let that = this,
|
|
279
297
|
data =
|
|
280
298
|
isObservableObject(that.valueOf()) &&
|
|
281
299
|
that.valueOf() instanceof Array === false
|
|
282
300
|
? structuredClone(Object.assign({}, that))
|
|
283
301
|
: that.valueOf();
|
|
302
|
+
|
|
303
|
+
if (notify !== undefined) {
|
|
304
|
+
that.#notify = notify;
|
|
305
|
+
// return;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
//if (that.#notify) console.log('notify', this, data);
|
|
284
309
|
(that.constructor as any).callbacks.forEach((f: Function) => {
|
|
285
|
-
// console.log(
|
|
310
|
+
// console.log(
|
|
311
|
+
// (this.constructor as any).callbacks,
|
|
312
|
+
// 'notify: exec callback',
|
|
313
|
+
// f,
|
|
314
|
+
// data
|
|
315
|
+
// );
|
|
286
316
|
f(data);
|
|
287
317
|
});
|
|
288
|
-
|
|
318
|
+
|
|
319
|
+
return that;
|
|
289
320
|
}
|
|
290
321
|
};
|
|
291
322
|
|
|
292
|
-
//(Observable.constructor as LooseObject).callbacks = [];
|
|
293
323
|
let o = new Observable(val);
|
|
294
324
|
|
|
295
325
|
Object.defineProperty(target, key, {
|
|
@@ -317,20 +347,21 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
317
347
|
let iso =
|
|
318
348
|
isObservableObject(o.valueOf()) &&
|
|
319
349
|
o.valueOf() instanceof Array === false;
|
|
320
|
-
//let iso = o.constructor.prototype.__proto__.constructor === Object;
|
|
321
350
|
//console.log('target iso:', iso);
|
|
322
351
|
if (iso) {
|
|
323
352
|
let old = structuredClone(Object.assign({}, o));
|
|
324
|
-
val = structuredClone(Object.assign({}, val));
|
|
353
|
+
//val = structuredClone(Object.assign({}, val));
|
|
325
354
|
|
|
326
|
-
let
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
355
|
+
//let callbacks = (o.constructor as LooseObject).callbacks;
|
|
356
|
+
if (o instanceof Observable === false) {
|
|
357
|
+
o = new Observable(structuredClone(Object.assign({}, val)));
|
|
358
|
+
copyGettersSetters(val, o);
|
|
359
|
+
o.seal();
|
|
360
|
+
}
|
|
361
|
+
Object.assign(o, val);
|
|
330
362
|
|
|
331
|
-
//console.log('after set o=', o, 'check', old);
|
|
332
|
-
(o.constructor as LooseObject).callbacks =
|
|
333
|
-
(o.constructor as LooseObject).callbacks = callbacks;
|
|
363
|
+
// console.log('after set o=', o, 'check', old);
|
|
364
|
+
// (o.constructor as LooseObject).callbacks = callbacks;
|
|
334
365
|
|
|
335
366
|
setTimeout(
|
|
336
367
|
// check for changes
|
|
@@ -369,4 +400,6 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
369
400
|
// replace old property with proxy (observable)
|
|
370
401
|
target[key] = val;
|
|
371
402
|
});
|
|
403
|
+
|
|
404
|
+
return target;
|
|
372
405
|
};
|
package/public/src/test.ts
CHANGED
|
@@ -127,10 +127,11 @@ let MyTag: CustomElementConstructor = getCE('my-tag')!,
|
|
|
127
127
|
stress test
|
|
128
128
|
*/
|
|
129
129
|
|
|
130
|
-
let start = new Date().getTime()
|
|
130
|
+
let start = new Date().getTime(),
|
|
131
|
+
max = 100;
|
|
131
132
|
|
|
132
|
-
// create
|
|
133
|
-
for (let x = 0; x <
|
|
133
|
+
// create 1000 elements
|
|
134
|
+
for (let x = 0; x < max; x++) {
|
|
134
135
|
fragment.append(new MyTag());
|
|
135
136
|
}
|
|
136
137
|
|
|
@@ -149,14 +150,16 @@ setTimeout(() => {
|
|
|
149
150
|
// console.clear();
|
|
150
151
|
|
|
151
152
|
console.log(
|
|
152
|
-
'%c \n\nStress Test:\n\n %cInstancing
|
|
153
|
+
'%c \n\nStress Test:\n\n %cInstancing %s web components (%s classes): %c %s ms.',
|
|
153
154
|
'font-weight: bold; color: black;',
|
|
154
155
|
'font-weight: normal;',
|
|
156
|
+
max,
|
|
157
|
+
max * 3,
|
|
155
158
|
'font-weight: bold; color: blue;',
|
|
156
159
|
end - start
|
|
157
160
|
);
|
|
158
161
|
|
|
159
|
-
document.body.appendChild(new MyTag());
|
|
162
|
+
//document.body.appendChild(new MyTag());
|
|
160
163
|
|
|
161
164
|
let element = document.querySelector('my-tag');
|
|
162
165
|
|
|
@@ -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,l,o=t.type;switch((e=>e.tagName.toLowerCase())(t)){case"input":switch(o){case"radio":r=new _(t,e.constructor===HTMLFormElement?e:e.querySelector("form")),l=m.add(t,a,r);break;case"checkbox":r=new T(t),l=m.add(t,a,r);break;default:r=new N(t),l=m.add(t,a,r)}Object.defineProperty(n,a,{enumerable:!0,configurable:!0,get:()=>l.val,set:e=>{l.val!==e&&(l.val=e)}});break;case"select":r=new C(t),l=m.add(t,a,r),Object.defineProperty(n,a,{enumerable:!0,configurable:!0,get:()=>l.val,set:e=>{l.val!==e&&(l.val=e)}});break;case"textarea":r=new I(t),l=m.add(t,a,r),Object.defineProperty(n,a,{enumerable:!0,configurable:!0,get:()=>l.val,set:e=>{l.val!==e&&(l.val=e)}});break;default:console.warn("handler missing:",a,"for",t.tagName.toLowerCase(),t)}}})),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
CHANGED
|
@@ -11,13 +11,17 @@
|
|
|
11
11
|
href="MicroComponents.svg"
|
|
12
12
|
/>
|
|
13
13
|
<link href="./my-tag.css" rel="stylesheet" />
|
|
14
|
+
<link href="./Grandparent.css" rel="stylesheet" />
|
|
14
15
|
<script src="./microcomponents.min.js"></script>
|
|
15
16
|
<script>
|
|
16
|
-
Object.assign(window, microcomponents); // make global
|
|
17
|
+
Object.assign(window, microcomponents); // make system global, for debugging
|
|
18
|
+
autoload(true); // automatically load web components that are undefined
|
|
17
19
|
</script>
|
|
18
20
|
<script type="module" src="./test.js"></script>
|
|
19
21
|
</head>
|
|
20
22
|
<body>
|
|
23
|
+
<test-grandparent></test-grandparent>
|
|
24
|
+
<test-testform></test-testform>
|
|
21
25
|
Open the debugger, read console, then:<br />
|
|
22
26
|
</body>
|
|
23
27
|
</html>
|
package/public/test.js
CHANGED
|
@@ -63,15 +63,14 @@ defineCE('my-tag', class MyTag extends DC {
|
|
|
63
63
|
}
|
|
64
64
|
}, ['language']);
|
|
65
65
|
let MyTag = getCE('my-tag'), fragment = new DocumentFragment();
|
|
66
|
-
let start = new Date().getTime();
|
|
67
|
-
for (let x = 0; x <
|
|
66
|
+
let start = new Date().getTime(), max = 100;
|
|
67
|
+
for (let x = 0; x < max; x++) {
|
|
68
68
|
fragment.append(new MyTag());
|
|
69
69
|
}
|
|
70
70
|
let end = new Date().getTime();
|
|
71
71
|
document.body.appendChild(fragment);
|
|
72
72
|
setTimeout(() => {
|
|
73
|
-
console.log('%c \n\nStress Test:\n\n %cInstancing
|
|
74
|
-
document.body.appendChild(new MyTag());
|
|
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);
|
|
75
74
|
let element = document.querySelector('my-tag');
|
|
76
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');
|
|
77
76
|
DC.trigger(element, 'doSomething');
|
package/public/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAEN,EAAE,EAEF,QAAQ,EACR,KAAK,EACL,OAAO,GAEP,MAAM,sBAAsB,CAAC;AAE9B,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;QAE/D,IAAI,CAAC,MAAM,CAAC,YAAY,C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WAAW,CAAC,QAAQ,CAAC,CAAC;AAQpC,UAAU,CAAC,GAAG,EAAE;IAGf,OAAO,CAAC,GAAG,CACV,gFAAgF,EAChF,kCAAkC,EAClC,sBAAsB,EACtB,GAAG,EACH,GAAG,GAAG,CAAC,EACP,iCAAiC,EACjC,GAAG,GAAG,KAAK,CACX,CAAC;IAIF,IAAI,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,CACV,mGAAmG,EACnG,oBAAoB,EACpB,sBAAsB,EACtB,OAAO,EACP,oBAAoB,EACpB,+CAA+C,CAC/C,CAAC;IAGF,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AACpC,CAAC,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
<h5>cb: <span class="tsd-signature-type">Callback</span></h5></li></ul></div>
|
|
56
56
|
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul></div><aside class="tsd-sources">
|
|
57
57
|
<ul>
|
|
58
|
-
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/
|
|
58
|
+
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/404f13d/src/observables.ts#L191">src/observables.ts:191</a></li></ul></aside></div>
|
|
59
59
|
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
|
60
60
|
<div class="tsd-navigation settings">
|
|
61
61
|
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<h1>Type alias selection</h1></div>
|
|
19
19
|
<div class="tsd-signature">selection<span class="tsd-signature-symbol">:</span> <a href="selectors.singleSelector.html" class="tsd-signature-type" data-tsd-kind="Type alias">singleSelector</a><span class="tsd-signature-symbol"> | </span><a href="selectors.singleSelector.html" class="tsd-signature-type" data-tsd-kind="Type alias">singleSelector</a><span class="tsd-signature-symbol">[]</span></div><aside class="tsd-sources">
|
|
20
20
|
<ul>
|
|
21
|
-
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/
|
|
21
|
+
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/404f13d/src/selectors.ts#L1634">src/selectors.ts:1634</a></li></ul></aside></div>
|
|
22
22
|
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
|
23
23
|
<div class="tsd-navigation settings">
|
|
24
24
|
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<h1>Type alias singleSelector</h1></div>
|
|
19
19
|
<div class="tsd-signature">single<wbr/>Selector<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">ShadowRoot</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">HTMLElement</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">HTMLElement</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">HTMLCollection</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">NodeList</span><span class="tsd-signature-symbol"> | </span><a href="../interfaces/selectors.DSelector.html" class="tsd-signature-type" data-tsd-kind="Interface">DSelector</a><span class="tsd-signature-symbol"> | </span><a href="../classes/MC.MC.html" class="tsd-signature-type" data-tsd-kind="Class">MC</a><span class="tsd-signature-symbol"> | </span><a href="../classes/MC.DC.html" class="tsd-signature-type" data-tsd-kind="Class">DC</a><span class="tsd-signature-symbol"> | </span><a href="../interfaces/selectors.TSelector.html" class="tsd-signature-type" data-tsd-kind="Interface">TSelector</a><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">undefined</span></div><aside class="tsd-sources">
|
|
20
20
|
<ul>
|
|
21
|
-
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/
|
|
21
|
+
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/404f13d/src/selectors.ts#L1632">src/selectors.ts:1632</a></li></ul></aside></div>
|
|
22
22
|
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
|
23
23
|
<div class="tsd-navigation settings">
|
|
24
24
|
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
|
package/src/MC.ts
CHANGED
|
@@ -411,3 +411,68 @@ class DC extends McBase {
|
|
|
411
411
|
}
|
|
412
412
|
|
|
413
413
|
export { addListener, removeListener, McBase, MC, DC, McEvent };
|
|
414
|
+
|
|
415
|
+
let observer: MutationObserver | null = null;
|
|
416
|
+
const unresolved = new Map();
|
|
417
|
+
|
|
418
|
+
function loadit() {
|
|
419
|
+
document
|
|
420
|
+
.querySelectorAll(':not(:defined),[_mc]:not([_mc=""])')
|
|
421
|
+
.forEach((el) => {
|
|
422
|
+
const load: string[] = el.tagName.includes('-')
|
|
423
|
+
? [el.tagName.toLowerCase()]
|
|
424
|
+
: el.getAttribute('_mc')!.trim().split(' ');
|
|
425
|
+
|
|
426
|
+
load.forEach((elementName) => {
|
|
427
|
+
let fileName: any = elementName.toLowerCase().split('-'), // intentional any
|
|
428
|
+
lastElement = fileName[fileName.length - 1],
|
|
429
|
+
renameLastElement =
|
|
430
|
+
lastElement[0].toUpperCase() + lastElement.slice(1);
|
|
431
|
+
fileName[fileName.length - 1] = renameLastElement;
|
|
432
|
+
fileName = fileName.join('/') + '.js';
|
|
433
|
+
|
|
434
|
+
// autoload web components
|
|
435
|
+
// TBD: _mc components
|
|
436
|
+
if (
|
|
437
|
+
el.tagName.includes('-') &&
|
|
438
|
+
!unresolved.has(el.tagName.toLowerCase())
|
|
439
|
+
) {
|
|
440
|
+
const se: HTMLScriptElement = document.createElement('script');
|
|
441
|
+
|
|
442
|
+
unresolved.set(elementName, fileName);
|
|
443
|
+
|
|
444
|
+
se.setAttribute('src', fileName);
|
|
445
|
+
se.setAttribute('blocking', 'render');
|
|
446
|
+
se.setAttribute('type', 'module');
|
|
447
|
+
se.onload = () => {
|
|
448
|
+
// console.info('loaded', s);
|
|
449
|
+
unresolved.delete(elementName);
|
|
450
|
+
//console.log(unresolved);
|
|
451
|
+
};
|
|
452
|
+
|
|
453
|
+
document.head.append(se);
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
//console.log(unresolved);
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
let autoloadEnabled: boolean = false;
|
|
461
|
+
|
|
462
|
+
export function autoload(enable: boolean = true): boolean {
|
|
463
|
+
if (!enable) {
|
|
464
|
+
observer?.disconnect();
|
|
465
|
+
observer = null;
|
|
466
|
+
return autoloadEnabled;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
autoloadEnabled = enable;
|
|
470
|
+
observer = new MutationObserver(loadit);
|
|
471
|
+
|
|
472
|
+
setTimeout(() => {
|
|
473
|
+
observer!.observe(document.body, { childList: true, subtree: true });
|
|
474
|
+
loadit();
|
|
475
|
+
}, 5);
|
|
476
|
+
|
|
477
|
+
return autoloadEnabled;
|
|
478
|
+
}
|
package/src/elements.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
2
|
|
|
3
|
-
import { DC } from
|
|
4
|
-
import { kebabToPascal } from
|
|
3
|
+
import { DC } from './MC.js';
|
|
4
|
+
import { kebabToPascal } from './helpers.js';
|
|
5
5
|
|
|
6
6
|
class CeBaseClass extends HTMLElement {
|
|
7
7
|
constructor() {
|
|
@@ -9,19 +9,19 @@ class CeBaseClass extends HTMLElement {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
connectedCallback() {
|
|
12
|
-
(DC as any).trigger(this,
|
|
12
|
+
(DC as any).trigger(this, 'Connected');
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
disconnectedCallback() {
|
|
16
|
-
(DC as any).trigger(this,
|
|
16
|
+
(DC as any).trigger(this, 'Disconnected');
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
adoptedCallback() {
|
|
20
|
-
(DC as any).trigger(this,
|
|
20
|
+
(DC as any).trigger(this, 'Adopted');
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
attributeChangedCallback(name: string, oldValue: any, newValue: any) {
|
|
24
|
-
(DC as any).trigger(this,
|
|
24
|
+
(DC as any).trigger(this, 'AttributeChanged', { name, oldValue, newValue });
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -29,7 +29,7 @@ function createNamedClass(
|
|
|
29
29
|
name: string,
|
|
30
30
|
ClassBody: { new (...args: any[]): any }
|
|
31
31
|
) {
|
|
32
|
-
return Object.defineProperty(ClassBody,
|
|
32
|
+
return Object.defineProperty(ClassBody, 'name', { value: name });
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export function defineCE(
|
|
@@ -42,7 +42,7 @@ export function defineCE(
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
-
if (!tagName.includes(
|
|
45
|
+
if (!tagName.includes('-')) {
|
|
46
46
|
throw new Error(
|
|
47
47
|
'createCustomElement: tagName must contain at least one hyphen ("-").'
|
|
48
48
|
);
|
|
@@ -60,7 +60,7 @@ export function defineCE(
|
|
|
60
60
|
constructor(data?: any) {
|
|
61
61
|
super();
|
|
62
62
|
let instance = new DefinitionClass(this, data);
|
|
63
|
-
|
|
63
|
+
DC.add(this, name, instance);
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
static get observedAttributes() {
|