@twobirds/microcomponents 0.1.1 → 0.1.2
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/MC.min.js +33 -52
- 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 +11 -2
- package/.gitlab-ci.yml +0 -18
- package/.vscode/settings.json +0 -3
- package/MicroComponents.svg +0 -15
- package/assets/documentation/MC.md +0 -547
- package/assets/documentation/MicroComponents.svg +0 -15
- package/assets/documentation/ajaxian-1.png +0 -0
- package/assets/documentation/ajaxian-2.png +0 -0
- package/assets/documentation/ajaxian-3.png +0 -0
- package/assets/documentation/elements.md +0 -277
- package/assets/documentation/formvalues.md +0 -25
- package/assets/documentation/functional_requirements.md +0 -8
- package/assets/documentation/history.md +0 -436
- package/assets/documentation/klemmstein.png +0 -0
- package/assets/documentation/magic.md +0 -29
- package/assets/documentation/observables.md +0 -187
- package/assets/documentation/rnd0023-1.jpg +0 -0
- package/assets/documentation/rnd0023-2.jpg +0 -0
- package/assets/documentation/rnd0023-3.jpg +0 -0
- package/assets/documentation/tB_react.md +0 -207
- package/assets/documentation/usage.md +0 -142
- package/assets/documentation/why.md +0 -25
- package/assets/fiddle/MicroComponents.svg +0 -15
- package/assets/fiddle/fiddle.css +0 -0
- package/assets/fiddle/fiddle.js +0 -0
- package/assets/fiddle/index.html +0 -0
- package/assets/test/MicroComponents.svg +0 -15
- package/assets/test/grandparent.css +0 -16
- package/assets/test/myButton.css +0 -19
- package/assets/test/style.css +0 -8
- package/assets/test/test.html +0 -29
- package/assets/test/testform.json +0 -27
- package/public/.nojekyll +0 -1
- package/public/MC.d.ts +0 -39
- package/public/MC.d.ts.map +0 -1
- package/public/MC.js +0 -287
- package/public/MC.js.map +0 -1
- package/public/MC.min.js +0 -348
- package/public/MC.ts +0 -431
- package/public/MicroComponents.svg +0 -15
- package/public/documentation/MC.md +0 -547
- package/public/documentation/MicroComponents.svg +0 -15
- 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/elements.md +0 -277
- package/public/documentation/formvalues.md +0 -25
- package/public/documentation/functional_requirements.md +0 -8
- package/public/documentation/history.md +0 -436
- package/public/documentation/klemmstein.png +0 -0
- package/public/documentation/magic.md +0 -29
- package/public/documentation/observables.md +0 -187
- 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 +0 -207
- package/public/documentation/usage.md +0 -142
- package/public/documentation/why.md +0 -25
- package/public/elements.d.ts +0 -5
- package/public/elements.d.ts.map +0 -1
- package/public/elements.js +0 -68
- package/public/elements.js.map +0 -1
- package/public/elements.min.js +0 -1
- package/public/elements.ts +0 -119
- package/public/fiddle/MicroComponents.svg +0 -15
- package/public/fiddle/fiddle.css +0 -0
- package/public/fiddle/fiddle.js +0 -0
- package/public/fiddle/index.html +0 -0
- package/public/formValues.d.ts +0 -3
- package/public/formValues.d.ts.map +0 -1
- package/public/formValues.js +0 -162
- package/public/formValues.js.map +0 -1
- package/public/formValues.min.js +0 -1
- package/public/formValues.ts +0 -225
- package/public/helpers.d.ts +0 -14
- package/public/helpers.d.ts.map +0 -1
- package/public/helpers.js +0 -113
- package/public/helpers.js.map +0 -1
- package/public/helpers.ts +0 -149
- package/public/microcomponents.d.ts +0 -6
- package/public/microcomponents.d.ts.map +0 -1
- package/public/microcomponents.js +0 -7
- package/public/microcomponents.js.map +0 -1
- package/public/microcomponents.min.js +0 -1
- package/public/microcomponents.ts +0 -8
- package/public/observables.d.ts +0 -11
- package/public/observables.d.ts.map +0 -1
- package/public/observables.js +0 -244
- package/public/observables.js.map +0 -1
- package/public/observables.min.js +0 -1
- package/public/observables.ts +0 -416
- package/public/selectors._ts +0 -1269
- package/public/src/MC.d.ts +0 -39
- package/public/src/MC.d.ts.map +0 -1
- package/public/src/MC.js +0 -287
- package/public/src/MC.js.map +0 -1
- package/public/src/MC.ts +0 -431
- package/public/src/elements.d.ts +0 -5
- package/public/src/elements.d.ts.map +0 -1
- package/public/src/elements.js +0 -68
- package/public/src/elements.js.map +0 -1
- package/public/src/elements.ts +0 -119
- package/public/src/formValues.d.ts +0 -3
- package/public/src/formValues.d.ts.map +0 -1
- package/public/src/formValues.js +0 -162
- package/public/src/formValues.js.map +0 -1
- package/public/src/formValues.ts +0 -225
- package/public/src/helpers.d.ts +0 -14
- package/public/src/helpers.d.ts.map +0 -1
- package/public/src/helpers.js +0 -113
- package/public/src/helpers.js.map +0 -1
- package/public/src/helpers.ts +0 -149
- package/public/src/microcomponents.d.ts +0 -6
- package/public/src/microcomponents.d.ts.map +0 -1
- package/public/src/microcomponents.js +0 -7
- package/public/src/microcomponents.js.map +0 -1
- package/public/src/microcomponents.ts +0 -8
- package/public/src/observables.d.ts +0 -11
- package/public/src/observables.d.ts.map +0 -1
- package/public/src/observables.js +0 -244
- package/public/src/observables.js.map +0 -1
- package/public/src/observables.ts +0 -416
- package/public/src/selectors._ts +0 -1269
- package/public/src/test/grandparent.css +0 -14
- package/public/src/test/test/child.d.ts +0 -2
- package/public/src/test/test/child.d.ts.map +0 -1
- package/public/src/test/test/child.js +0 -26
- package/public/src/test/test/child.js.map +0 -1
- package/public/src/test/test/child.ts +0 -36
- package/public/src/test/test/grandchild.d.ts +0 -2
- package/public/src/test/test/grandchild.d.ts.map +0 -1
- package/public/src/test/test/grandchild.js +0 -22
- package/public/src/test/test/grandchild.js.map +0 -1
- package/public/src/test/test/grandchild.ts +0 -31
- package/public/src/test/test/grandparent.d.ts +0 -2
- package/public/src/test/test/grandparent.d.ts.map +0 -1
- package/public/src/test/test/grandparent.js +0 -1
- package/public/src/test/test/grandparent.js.map +0 -1
- package/public/src/test/test/grandparent.ts +0 -43
- package/public/src/test/test/greatgrandchild.d.ts +0 -2
- package/public/src/test/test/greatgrandchild.d.ts.map +0 -1
- package/public/src/test/test/greatgrandchild.js +0 -36
- package/public/src/test/test/greatgrandchild.js.map +0 -1
- package/public/src/test/test/greatgrandchild.ts +0 -51
- package/public/src/test/test/parent.d.ts +0 -2
- package/public/src/test/test/parent.d.ts.map +0 -1
- package/public/src/test/test/parent.js +0 -25
- package/public/src/test/test/parent.js.map +0 -1
- package/public/src/test/test/parent.ts +0 -35
- package/public/src/test/test/testform.d.ts +0 -2
- package/public/src/test/test/testform.d.ts.map +0 -1
- package/public/src/test/test/testform.js +0 -1
- package/public/src/test/test/testform.js.map +0 -1
- package/public/src/test/test/testform.ts +0 -153
- package/public/src/test/test/testfunction.d.ts +0 -3
- package/public/src/test/test/testfunction.d.ts.map +0 -1
- package/public/src/test/test/testfunction.js +0 -7
- package/public/src/test/test/testfunction.js.map +0 -1
- package/public/src/test/test/testfunction.ts +0 -12
- package/public/src/test/test/testmc.d.ts +0 -3
- package/public/src/test/test/testmc.d.ts.map +0 -1
- package/public/src/test/test/testmc.js +0 -10
- package/public/src/test/test/testmc.js.map +0 -1
- package/public/src/test/test/testmc.ts +0 -16
- package/public/src/test/test/testsimpleclass.d.ts +0 -3
- package/public/src/test/test/testsimpleclass.d.ts.map +0 -1
- package/public/src/test/test/testsimpleclass.js +0 -9
- package/public/src/test/test/testsimpleclass.js.map +0 -1
- package/public/src/test/test/testsimpleclass.ts +0 -15
- package/public/src/test/test.d.ts +0 -2
- package/public/src/test/test.d.ts.map +0 -1
- package/public/src/test/test.js +0 -72
- package/public/src/test/test.js.map +0 -1
- package/public/src/test/test.ts +0 -176
- package/public/src/test/testform.css +0 -47
- package/public/src/test/testform.html +0 -56
- package/public/src/test/testform.json +0 -27
- package/public/test/MC.d.ts +0 -39
- package/public/test/MC.d.ts.map +0 -1
- package/public/test/MC.js +0 -287
- package/public/test/MC.min.js +0 -348
- package/public/test/MC.ts +0 -431
- package/public/test/MicroComponents.svg +0 -15
- package/public/test/elements.d.ts +0 -5
- package/public/test/elements.d.ts.map +0 -1
- package/public/test/elements.js +0 -68
- package/public/test/elements.min.js +0 -1
- package/public/test/elements.ts +0 -119
- package/public/test/formValues.d.ts +0 -3
- package/public/test/formValues.d.ts.map +0 -1
- package/public/test/formValues.js +0 -162
- package/public/test/formValues.min.js +0 -1
- package/public/test/formValues.ts +0 -225
- package/public/test/grandparent.css +0 -14
- package/public/test/helpers.d.ts +0 -14
- package/public/test/helpers.d.ts.map +0 -1
- package/public/test/helpers.js +0 -113
- package/public/test/helpers.ts +0 -149
- package/public/test/microcomponents.d.ts +0 -6
- package/public/test/microcomponents.d.ts.map +0 -1
- package/public/test/microcomponents.js +0 -7
- package/public/test/microcomponents.min.js +0 -1
- package/public/test/microcomponents.ts +0 -8
- package/public/test/myButton.css +0 -19
- package/public/test/observables.d.ts +0 -11
- package/public/test/observables.d.ts.map +0 -1
- package/public/test/observables.js +0 -244
- package/public/test/observables.min.js +0 -1
- package/public/test/observables.ts +0 -416
- package/public/test/style.css +0 -8
- package/public/test/test/child.d.ts +0 -2
- package/public/test/test/child.d.ts.map +0 -1
- package/public/test/test/child.js +0 -26
- package/public/test/test/child.js.map +0 -1
- package/public/test/test/child.ts +0 -36
- package/public/test/test/grandchild.d.ts +0 -2
- package/public/test/test/grandchild.d.ts.map +0 -1
- package/public/test/test/grandchild.js +0 -22
- package/public/test/test/grandchild.js.map +0 -1
- package/public/test/test/grandchild.ts +0 -31
- package/public/test/test/grandparent.d.ts +0 -2
- package/public/test/test/grandparent.d.ts.map +0 -1
- package/public/test/test/grandparent.js +0 -1
- package/public/test/test/grandparent.js.map +0 -1
- package/public/test/test/grandparent.ts +0 -43
- package/public/test/test/greatgrandchild.d.ts +0 -2
- package/public/test/test/greatgrandchild.d.ts.map +0 -1
- package/public/test/test/greatgrandchild.js +0 -36
- package/public/test/test/greatgrandchild.js.map +0 -1
- package/public/test/test/greatgrandchild.ts +0 -51
- package/public/test/test/parent.d.ts +0 -2
- package/public/test/test/parent.d.ts.map +0 -1
- package/public/test/test/parent.js +0 -25
- package/public/test/test/parent.js.map +0 -1
- package/public/test/test/parent.ts +0 -35
- package/public/test/test/testform.d.ts +0 -2
- package/public/test/test/testform.d.ts.map +0 -1
- package/public/test/test/testform.js +0 -1
- package/public/test/test/testform.js.map +0 -1
- package/public/test/test/testform.ts +0 -153
- package/public/test/test/testfunction.d.ts +0 -3
- package/public/test/test/testfunction.d.ts.map +0 -1
- package/public/test/test/testfunction.js +0 -7
- package/public/test/test/testfunction.js.map +0 -1
- package/public/test/test/testfunction.ts +0 -12
- package/public/test/test/testmc.d.ts +0 -3
- package/public/test/test/testmc.d.ts.map +0 -1
- package/public/test/test/testmc.js +0 -10
- package/public/test/test/testmc.js.map +0 -1
- package/public/test/test/testmc.ts +0 -16
- package/public/test/test/testsimpleclass.d.ts +0 -3
- package/public/test/test/testsimpleclass.d.ts.map +0 -1
- package/public/test/test/testsimpleclass.js +0 -9
- package/public/test/test/testsimpleclass.js.map +0 -1
- package/public/test/test/testsimpleclass.ts +0 -15
- package/public/test/test.d.ts +0 -2
- package/public/test/test.d.ts.map +0 -1
- package/public/test/test.html +0 -29
- package/public/test/test.js +0 -72
- package/public/test/test.js.map +0 -1
- package/public/test/test.ts +0 -176
- package/public/test/testform.css +0 -47
- package/public/test/testform.html +0 -56
- package/public/test/testform.json +0 -27
- package/public/typedoc/.nojekyll +0 -1
- package/public/typedoc/assets/highlight.css +0 -106
- package/public/typedoc/assets/icons.js +0 -18
- package/public/typedoc/assets/icons.svg +0 -1
- package/public/typedoc/assets/main.js +0 -60
- package/public/typedoc/assets/navigation.js +0 -1
- package/public/typedoc/assets/search.js +0 -1
- package/public/typedoc/assets/style.css +0 -1493
- package/public/typedoc/classes/MC.DC.html +0 -13
- package/public/typedoc/classes/MC.MC.html +0 -3
- package/public/typedoc/classes/MC.McBase.html +0 -3
- package/public/typedoc/functions/MC.autoload.html +0 -1
- package/public/typedoc/functions/MC.off.html +0 -1
- package/public/typedoc/functions/MC.on.html +0 -1
- package/public/typedoc/functions/MC.one.html +0 -1
- package/public/typedoc/functions/MC.trigger.html +0 -1
- package/public/typedoc/functions/elements.defineCE.html +0 -1
- package/public/typedoc/functions/elements.getCE.html +0 -1
- package/public/typedoc/functions/formValues.formValues.html +0 -1
- package/public/typedoc/functions/observables.observe.html +0 -1
- package/public/typedoc/hierarchy.html +0 -1
- package/public/typedoc/index.html +0 -122
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +0 -758
- package/public/typedoc/media/MicroComponents.svg +0 -15
- package/public/typedoc/modules/MC.html +0 -10
- package/public/typedoc/modules/elements.html +0 -3
- package/public/typedoc/modules/formValues.html +0 -2
- package/public/typedoc/modules/observables.html +0 -3
- package/public/typedoc/modules.html +0 -5
- package/public/typedoc/types/observables.Observable.html +0 -1
- package/src/MC.ts +0 -431
- package/src/elements.ts +0 -119
- package/src/formValues.ts +0 -225
- package/src/helpers.ts +0 -149
- package/src/microcomponents.ts +0 -8
- package/src/observables.ts +0 -416
- package/src/selectors._ts +0 -1269
- package/src/test/grandparent.css +0 -14
- package/src/test/test/child.ts +0 -36
- package/src/test/test/grandchild.ts +0 -31
- package/src/test/test/grandparent.ts +0 -43
- package/src/test/test/greatgrandchild.ts +0 -51
- package/src/test/test/parent.ts +0 -35
- package/src/test/test/testform.ts +0 -153
- package/src/test/test/testfunction.ts +0 -12
- package/src/test/test/testmc.ts +0 -16
- package/src/test/test/testsimpleclass.ts +0 -15
- package/src/test/test.ts +0 -176
- package/src/test/testform.css +0 -47
- package/src/test/testform.html +0 -56
- package/src/test/testform.json +0 -27
- package/tasks.md +0 -36
- package/tsconfig.json +0 -107
- package/typedoc.json +0 -7
- package/webpack.config.js +0 -346
|
@@ -1,416 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
LooseObject,
|
|
5
|
-
debounce,
|
|
6
|
-
deepEqual,
|
|
7
|
-
flattenObject,
|
|
8
|
-
copyGettersSetters,
|
|
9
|
-
} from './helpers.js';
|
|
10
|
-
|
|
11
|
-
import { DC, HTMLMcElement, trigger } from './MC.js';
|
|
12
|
-
|
|
13
|
-
function isObservableObject(value: any): boolean {
|
|
14
|
-
return value != null && typeof value === 'object';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
type Callback = (value: any) => void;
|
|
18
|
-
|
|
19
|
-
function getPlaceholders(target: HTMLElement): string[] {
|
|
20
|
-
let placeholders: Set<string> = new Set(),
|
|
21
|
-
regEx = /\{[^\{\}]*\}/g;
|
|
22
|
-
|
|
23
|
-
// scan attributes
|
|
24
|
-
( !!target.getAttributeNames ? target.getAttributeNames() : [] )
|
|
25
|
-
.filter((attr) => target.getAttribute(attr)?.match(regEx)) // extract placeholder(s)
|
|
26
|
-
.forEach((attr) => {
|
|
27
|
-
let placeholders: Set<string> = new Set(target.getAttribute(attr)?.match(regEx));
|
|
28
|
-
placeholders.forEach((placeholder) =>
|
|
29
|
-
placeholders.add(placeholder.replace(/[\{\}]/g, ''))
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
// scan children text nodes
|
|
34
|
-
[...target.childNodes]
|
|
35
|
-
.filter((childNode) => {
|
|
36
|
-
return (
|
|
37
|
-
// is text node and has placeholders
|
|
38
|
-
childNode.nodeType === 3 &&
|
|
39
|
-
((childNode as any).nodeValue || '').match(regEx)
|
|
40
|
-
);
|
|
41
|
-
})
|
|
42
|
-
.forEach((childNode) => {
|
|
43
|
-
((childNode as any).nodeValue || '')
|
|
44
|
-
.match(regEx)
|
|
45
|
-
.forEach((placeholder: string) => {
|
|
46
|
-
placeholders.add(placeholder.replace(/[\{\}]/g, ''));
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// extract {} and return result
|
|
51
|
-
return [...placeholders].map((placeholder) =>
|
|
52
|
-
placeholder.replace(/[\{\}]/g, '')
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const inputs = [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement];
|
|
57
|
-
|
|
58
|
-
class Placeholders extends DC {
|
|
59
|
-
data: LooseObject = {};
|
|
60
|
-
oldDisplay?: string = '';
|
|
61
|
-
|
|
62
|
-
constructor(target: HTMLElement) {
|
|
63
|
-
super(target);
|
|
64
|
-
getPlaceholders(target).forEach((property) => (this.data[property] = ''));
|
|
65
|
-
observe(this);
|
|
66
|
-
this.#attachCallbacks();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
#attachCallbacks() {
|
|
70
|
-
let target = this.target,
|
|
71
|
-
hide: boolean = false;
|
|
72
|
-
|
|
73
|
-
//console.log('attachCallbacks', this.target);
|
|
74
|
-
|
|
75
|
-
// scan attributes
|
|
76
|
-
( !!target.getAttributeNames ? target.getAttributeNames() : [] )
|
|
77
|
-
.filter((attr: string) =>
|
|
78
|
-
target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)
|
|
79
|
-
) // extract placeholder(s)
|
|
80
|
-
.forEach((attr: string) => {
|
|
81
|
-
let placeholders: Set<string> = new Set(
|
|
82
|
-
target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)
|
|
83
|
-
);
|
|
84
|
-
// attach callback
|
|
85
|
-
this.data.observe(
|
|
86
|
-
((template: string) => (data: LooseObject) => {
|
|
87
|
-
let result: string = template;
|
|
88
|
-
placeholders.forEach((placeholder) => {
|
|
89
|
-
result = result.replace(
|
|
90
|
-
placeholder,
|
|
91
|
-
data[placeholder.replace(/[\{\}]/g, '')]
|
|
92
|
-
);
|
|
93
|
-
});
|
|
94
|
-
target.setAttribute(attr, result);
|
|
95
|
-
//console.log('cb setAttribute()', data, template, attr, result);
|
|
96
|
-
})(target.getAttribute(attr))
|
|
97
|
-
);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
// scan children text nodes
|
|
101
|
-
[...target.childNodes]
|
|
102
|
-
.filter((childNode) => {
|
|
103
|
-
return (
|
|
104
|
-
// is text node and has placeholders
|
|
105
|
-
childNode.nodeType === 3 &&
|
|
106
|
-
((childNode as Node).nodeValue || '').match(/\{[^\{\}]*\}/g)
|
|
107
|
-
);
|
|
108
|
-
})
|
|
109
|
-
.forEach((childNode) => {
|
|
110
|
-
hide = true;
|
|
111
|
-
let placeholders: Set<string> = new Set(
|
|
112
|
-
childNode.nodeValue.match(/\{[^\{\}]*\}/g)
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
// attach callback
|
|
116
|
-
this.data.observe(
|
|
117
|
-
((template: string) => (data: LooseObject) => {
|
|
118
|
-
let result: string = template;
|
|
119
|
-
//console.log('text node "', template, '" callback data:', data);
|
|
120
|
-
placeholders.forEach((placeholder) => {
|
|
121
|
-
result = result.replace(
|
|
122
|
-
placeholder,
|
|
123
|
-
data[placeholder.replace(/[\{\}]/g, '')]
|
|
124
|
-
);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
if (!!this.oldDisplay) {
|
|
128
|
-
target.style = this.oldDisplay;
|
|
129
|
-
} else {
|
|
130
|
-
target.removeAttribute('style');
|
|
131
|
-
}
|
|
132
|
-
delete this.oldDisplay;
|
|
133
|
-
|
|
134
|
-
childNode.nodeValue = result;
|
|
135
|
-
})(childNode.nodeValue)
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
// hide for now
|
|
139
|
-
this.oldDisplay = target.getAttribute('style') || ''; // TBD allow null to indicate there was no old style attribute
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
hide &&
|
|
143
|
-
!inputs.includes((target as any).constructor) &&
|
|
144
|
-
target.tagName !== 'FIELDSET'
|
|
145
|
-
) {
|
|
146
|
-
target.style.display = 'none';
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
onData(ev: CustomEvent) {
|
|
152
|
-
let data: LooseObject = {};
|
|
153
|
-
Object.keys(ev.detail.data).forEach((key) => {
|
|
154
|
-
if (this.data.hasOwnProperty(key)) data[key] = ev.detail.data[key];
|
|
155
|
-
});
|
|
156
|
-
//console.log( 'Placeholder onData', ev, data );
|
|
157
|
-
if (JSON.stringify(data) !== JSON.stringify(this.data))
|
|
158
|
-
Object.assign(this.data, data); // will trigger callbacks
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
function getPlaceholderElements(
|
|
163
|
-
target: HTMLElement | DocumentFragment | ShadowRoot
|
|
164
|
-
): HTMLElement[] {
|
|
165
|
-
let elements: Array<Node> = [target]
|
|
166
|
-
.concat([...(target.querySelectorAll('*') as unknown as HTMLElement[])])
|
|
167
|
-
.filter((e) => !!getPlaceholders(e as HTMLElement).length)
|
|
168
|
-
.filter((e) => (e as HTMLElement)?.tagName !== 'STYLE')
|
|
169
|
-
.reverse(); // to start with inner elements
|
|
170
|
-
//console.log('getPlaceholderElements', elements);
|
|
171
|
-
return elements as HTMLElement[];
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function makePlaceholders(
|
|
175
|
-
element: HTMLElement | DocumentFragment | ShadowRoot
|
|
176
|
-
): void {
|
|
177
|
-
//console.log('makePlaceholders', element);
|
|
178
|
-
getPlaceholderElements(element).forEach((e: HTMLElement) => {
|
|
179
|
-
if ((e as HTMLMcElement)?._mc?._placeholders) return;
|
|
180
|
-
DC.add(e, '_placeholders', new Placeholders(e));
|
|
181
|
-
});
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export type Observable = {
|
|
185
|
-
observe: (cb: Callback) => void;
|
|
186
|
-
notify: () => void;
|
|
187
|
-
bind: (target: HTMLElement | DocumentFragment | ShadowRoot ) => void;
|
|
188
|
-
callbacks: Array<Function>;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
type Class<T> = new (...args: any[]) => T;
|
|
192
|
-
|
|
193
|
-
// repository for observable class wrappers
|
|
194
|
-
const classRepo: LooseObject = {};
|
|
195
|
-
|
|
196
|
-
// creates a new observable class wrapper
|
|
197
|
-
function makeObservable(val: any): Class<typeof val>{
|
|
198
|
-
|
|
199
|
-
const Constructor = val.constructor,
|
|
200
|
-
ConstructorName: string = Constructor.name;
|
|
201
|
-
|
|
202
|
-
let ObservableClass = class extends Constructor {
|
|
203
|
-
#notify: boolean = true;
|
|
204
|
-
#callbacks: Array<Function> = [];
|
|
205
|
-
|
|
206
|
-
constructor(val: any) {
|
|
207
|
-
super(val);
|
|
208
|
-
(this.constructor as LooseObject).callbacks = [];
|
|
209
|
-
if (isObservableObject(val)) {
|
|
210
|
-
// you cannot bind native values to the dom
|
|
211
|
-
Object.getOwnPropertyNames(val).forEach((key) => {
|
|
212
|
-
this[key] = val[key];
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
get callbacks(): Array<Function> {
|
|
218
|
-
return this.#callbacks
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
set callbacks( callbacks: Array<Function> ){
|
|
222
|
-
this.#callbacks = callbacks
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
observe( callback: Function ) {
|
|
226
|
-
//console.log('observe');
|
|
227
|
-
this.#callbacks.push( callback );
|
|
228
|
-
return this;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
bind(target: HTMLElement | DocumentFragment | ShadowRoot) {
|
|
232
|
-
const iso = isObservableObject(this.valueOf());
|
|
233
|
-
//console.log('bind', iso, target);
|
|
234
|
-
|
|
235
|
-
if (iso) {
|
|
236
|
-
makePlaceholders(target);
|
|
237
|
-
const placeholders: unknown =
|
|
238
|
-
[
|
|
239
|
-
target,
|
|
240
|
-
...target.querySelectorAll('[data-mc]'),
|
|
241
|
-
]
|
|
242
|
-
.filter(
|
|
243
|
-
(e) => !!(e as LooseObject)?._mc?._placeholders
|
|
244
|
-
);
|
|
245
|
-
|
|
246
|
-
//console.log('placeholders:', target, placeholders);
|
|
247
|
-
|
|
248
|
-
const func = function callback(data: LooseObject) {
|
|
249
|
-
// avoid bubbling for speed
|
|
250
|
-
let flattenedData = flattenObject(data);
|
|
251
|
-
//console.log('inside placeholder callback', target, flattenedData);
|
|
252
|
-
(placeholders as Node[]).forEach((node) => {
|
|
253
|
-
// console.log('trigger callback', e);
|
|
254
|
-
if (!node) return;
|
|
255
|
-
trigger(node as HTMLMcElement, 'data', flattenedData);
|
|
256
|
-
});
|
|
257
|
-
};
|
|
258
|
-
(this as any).#callbacks.push(func);
|
|
259
|
-
this.notify();
|
|
260
|
-
} else {
|
|
261
|
-
console.warn(
|
|
262
|
-
'IGNORED - cannot bind a non-Object to the dom, IS:',
|
|
263
|
-
typeof this.valueOf(),
|
|
264
|
-
this
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
notify(notify?: boolean) {
|
|
272
|
-
let data =
|
|
273
|
-
isObservableObject(this.valueOf()) &&
|
|
274
|
-
this.valueOf() instanceof Array === false
|
|
275
|
-
? structuredClone(Object.assign({}, this))
|
|
276
|
-
: this.valueOf();
|
|
277
|
-
|
|
278
|
-
if (notify !== undefined) {
|
|
279
|
-
this.#notify = notify;
|
|
280
|
-
// return;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
//if (this.#notify) console.log('notify', this, data);
|
|
284
|
-
(this as any).#callbacks.forEach((f: Function) => {
|
|
285
|
-
// console.log(
|
|
286
|
-
// (this.constructor as any).callbacks,
|
|
287
|
-
// 'notify: exec callback',
|
|
288
|
-
// f,
|
|
289
|
-
// data
|
|
290
|
-
// );
|
|
291
|
-
f(data);
|
|
292
|
-
});
|
|
293
|
-
|
|
294
|
-
return this;
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
(classRepo as any)[ConstructorName] = ObservableClass;
|
|
299
|
-
|
|
300
|
-
// console.log( 'classRepo:', classRepo );
|
|
301
|
-
|
|
302
|
-
return ObservableClass;
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
function getConstructor( val: any ): Class<typeof val> {
|
|
306
|
-
let key: string = val.constructor.name;
|
|
307
|
-
return classRepo[key] || makeObservable( val );
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
export const observe = (
|
|
311
|
-
target: LooseObject,
|
|
312
|
-
propertyName?: string
|
|
313
|
-
): LooseObject => {
|
|
314
|
-
let keys = !propertyName
|
|
315
|
-
? [...Object.getOwnPropertyNames(target)]
|
|
316
|
-
: [propertyName];
|
|
317
|
-
|
|
318
|
-
keys.forEach((key) => {
|
|
319
|
-
if (
|
|
320
|
-
target.hasOwnProperty(key)
|
|
321
|
-
&& typeof target[key] !== 'function'
|
|
322
|
-
&& !target?.[key]?.constructor?.prototype?.observe
|
|
323
|
-
) {
|
|
324
|
-
|
|
325
|
-
// console.log( 'co propname', key, typeof target[key], target[key] );
|
|
326
|
-
if (key[0] === '_' || target?.[key] === undefined) return target;
|
|
327
|
-
let val: any = target[key];
|
|
328
|
-
|
|
329
|
-
let o = new ( getConstructor(val) as Class<typeof val> )( val );
|
|
330
|
-
|
|
331
|
-
Object.defineProperty(target, key, {
|
|
332
|
-
enumerable: true,
|
|
333
|
-
get() {
|
|
334
|
-
if (isObservableObject(o.valueOf())) {
|
|
335
|
-
let check = structuredClone(Object.assign({}, o));
|
|
336
|
-
setTimeout(
|
|
337
|
-
debounce(function checkChanges() {
|
|
338
|
-
let state = structuredClone(Object.assign({}, o));
|
|
339
|
-
//console.log( 'check changes', state, check );
|
|
340
|
-
if (!deepEqual(state, check)) {
|
|
341
|
-
//console.log( '-> not equal!' );
|
|
342
|
-
o.notify();
|
|
343
|
-
}
|
|
344
|
-
}, 0),
|
|
345
|
-
0
|
|
346
|
-
);
|
|
347
|
-
}
|
|
348
|
-
return o;
|
|
349
|
-
},
|
|
350
|
-
set(val: any) {
|
|
351
|
-
//console.log( 'SET:', isObservableObject( val.valueOf() ), 'set:', val, 'to', isObservableObject( o.valueOf() ), o, );
|
|
352
|
-
if (typeof val === typeof o.valueOf()) {
|
|
353
|
-
let iso =
|
|
354
|
-
isObservableObject(o.valueOf()) &&
|
|
355
|
-
o.valueOf() instanceof Array === false;
|
|
356
|
-
//console.log('target iso:', iso);
|
|
357
|
-
if (iso) {
|
|
358
|
-
let old = structuredClone(Object.assign({}, o));
|
|
359
|
-
//val = structuredClone(Object.assign({}, val));
|
|
360
|
-
|
|
361
|
-
//let callbacks = (o.constructor as LooseObject).callbacks;
|
|
362
|
-
if (o?.constructor?.prototype?.observe === undefined ) {
|
|
363
|
-
o = new ( getConstructor(val) as Class<typeof val> )( structuredClone(Object.assign({}, val)) );
|
|
364
|
-
copyGettersSetters(val, o);
|
|
365
|
-
o.seal();
|
|
366
|
-
}
|
|
367
|
-
Object.assign(o, val);
|
|
368
|
-
|
|
369
|
-
// console.log('after set o=', o, 'check', old);
|
|
370
|
-
// (o.constructor as LooseObject).callbacks = callbacks;
|
|
371
|
-
|
|
372
|
-
setTimeout(
|
|
373
|
-
// check for changes
|
|
374
|
-
debounce(function checkChanges() {
|
|
375
|
-
let state = structuredClone(Object.assign({}, o));
|
|
376
|
-
//console.log( 'check changes', state, check );
|
|
377
|
-
if (!deepEqual(state, old)) {
|
|
378
|
-
//console.log( '-> not equal!' );
|
|
379
|
-
o.notify();
|
|
380
|
-
}
|
|
381
|
-
}, 0),
|
|
382
|
-
0
|
|
383
|
-
);
|
|
384
|
-
} else {
|
|
385
|
-
// simple native var
|
|
386
|
-
let old = o.valueOf(),
|
|
387
|
-
callbacks = (o as Observable).callbacks;
|
|
388
|
-
|
|
389
|
-
// console.log( 'sO', o, o.valueOf(), 'val', val );
|
|
390
|
-
if (val !== old) {
|
|
391
|
-
// console.log( '-> sO new val', val );
|
|
392
|
-
o = new ( getConstructor(val) as Class<typeof val> )( val );
|
|
393
|
-
(o as Observable).callbacks = callbacks;
|
|
394
|
-
o.notify();
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
} else {
|
|
398
|
-
console.warn(
|
|
399
|
-
'IGNORED - cannot change observable types, IS:',
|
|
400
|
-
typeof o.valueOf(),
|
|
401
|
-
o,
|
|
402
|
-
'- CANNOT BECOME:',
|
|
403
|
-
typeof val
|
|
404
|
-
);
|
|
405
|
-
}
|
|
406
|
-
},
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
// replace old property with proxy (observable)
|
|
410
|
-
target[key] = val;
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
return target;
|
|
416
|
-
};
|
package/public/test/style.css
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"child.d.ts","sourceRoot":"","sources":["../../../src/test/test/child.ts"],"names":[],"mappings":"AAmCA,eAAO,MAAM,KAAK,sCAAsB,CAAC"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { DC, defineCE, getCE } from './../../microcomponents.js';
|
|
2
|
-
import { Grandchild } from './grandchild.js';
|
|
3
|
-
defineCE('test-child', class TestChild extends DC {
|
|
4
|
-
constructor(target) {
|
|
5
|
-
super(target);
|
|
6
|
-
}
|
|
7
|
-
onConnected() {
|
|
8
|
-
let that = this;
|
|
9
|
-
for (let x = 0; x < 10; x++) {
|
|
10
|
-
that.target.append(new Grandchild());
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
onClick(ev) {
|
|
14
|
-
this.trigger('Up', null, 'lu');
|
|
15
|
-
ev.stopImmediatePropagation();
|
|
16
|
-
}
|
|
17
|
-
onUp(ev) {
|
|
18
|
-
console.log('child "Up" handler');
|
|
19
|
-
ev.detail.control.stop();
|
|
20
|
-
}
|
|
21
|
-
onDown(ev) {
|
|
22
|
-
console.log('child "Down" handler');
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
export const Child = getCE('test-child');
|
|
26
|
-
//# sourceMappingURL=child.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"child.js","sourceRoot":"","sources":["../../../src/test/test/child.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,QAAQ,CACP,YAAY,EAEZ,MAAM,SAAU,SAAQ,EAAE;IACzB,YAAY,MAAmB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;IACf,CAAC;IAED,WAAW;QACV,IAAI,IAAI,GAAG,IAAI,CAAC;QAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,UAAW,EAAE,CAAC,CAAC;QACvC,CAAC;IACF,CAAC;IAED,OAAO,CAAC,EAAS;QAChB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/B,EAAE,CAAC,wBAAwB,EAAE,CAAC;IAC/B,CAAC;IAED,IAAI,CAAE,EAAe;QACpB,OAAO,CAAC,GAAG,CAAE,oBAAoB,CAAE,CAAC;QACpC,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC;IAC1B,CAAC;IAED,MAAM,CAAE,EAAe;QACtB,OAAO,CAAC,GAAG,CAAE,sBAAsB,CAAE,CAAC;IACvC,CAAC;CAED,CACD,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DC, defineCE, getCE } from './../../microcomponents.js';
|
|
2
|
-
import { Grandchild } from './grandchild.js';
|
|
3
|
-
defineCE(
|
|
4
|
-
'test-child',
|
|
5
|
-
|
|
6
|
-
class TestChild extends DC {
|
|
7
|
-
constructor(target: HTMLElement) {
|
|
8
|
-
super(target);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
onConnected() {
|
|
12
|
-
let that = this;
|
|
13
|
-
|
|
14
|
-
for (let x = 0; x < 10; x++) {
|
|
15
|
-
that.target.append(new Grandchild!());
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
onClick(ev: Event){
|
|
20
|
-
this.trigger('Up', null, 'lu');
|
|
21
|
-
ev.stopImmediatePropagation();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
onUp( ev: CustomEvent ){
|
|
25
|
-
console.log( 'child "Up" handler' );
|
|
26
|
-
ev.detail.control.stop();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
onDown( ev: CustomEvent ){
|
|
30
|
-
console.log( 'child "Down" handler' );
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
|
|
36
|
-
export const Child = getCE('test-child');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grandchild.d.ts","sourceRoot":"","sources":["../../../src/test/test/grandchild.ts"],"names":[],"mappings":"AA8BA,eAAO,MAAM,UAAU,sCAA2B,CAAC"}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { DC, defineCE, getCE } from '../../microcomponents.js';
|
|
2
|
-
import { Greatgrandchild } from './greatgrandchild.js';
|
|
3
|
-
defineCE('test-grandchild', class TestGrandchild extends DC {
|
|
4
|
-
constructor(target) {
|
|
5
|
-
super(target);
|
|
6
|
-
}
|
|
7
|
-
onConnected() {
|
|
8
|
-
let that = this;
|
|
9
|
-
for (let x = 0; x < 2; x++) {
|
|
10
|
-
that.target.append(new Greatgrandchild());
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
onClick(ev) {
|
|
14
|
-
this.trigger('Up', null, 'lu');
|
|
15
|
-
ev.stopImmediatePropagation();
|
|
16
|
-
}
|
|
17
|
-
onUp(ev) {
|
|
18
|
-
console.log('grandchild "Up" handler');
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
export const Grandchild = getCE('test-grandchild');
|
|
22
|
-
//# sourceMappingURL=grandchild.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grandchild.js","sourceRoot":"","sources":["../../../src/test/test/grandchild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,QAAQ,CACP,iBAAiB,EAEjB,MAAM,cAAe,SAAQ,EAAE;IAC9B,YAAY,MAAmB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;IACf,CAAC;IAED,WAAW;QACV,IAAI,IAAI,GAAG,IAAI,CAAC;QAEhB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,eAAgB,EAAE,CAAC,CAAC;QAC5C,CAAC;IACF,CAAC;IAED,OAAO,CAAC,EAAS;QAChB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/B,EAAE,CAAC,wBAAwB,EAAE,CAAC;IAC/B,CAAC;IAED,IAAI,CAAE,EAAe;QACpB,OAAO,CAAC,GAAG,CAAE,yBAAyB,CAAE,CAAC;IAC1C,CAAC;CAED,CACD,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,CAAC,iBAAiB,CAAC,CAAC"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { DC, defineCE, getCE } from '../../microcomponents.js';
|
|
2
|
-
import { Greatgrandchild } from './greatgrandchild.js';
|
|
3
|
-
defineCE(
|
|
4
|
-
'test-grandchild',
|
|
5
|
-
|
|
6
|
-
class TestGrandchild extends DC {
|
|
7
|
-
constructor(target: HTMLElement) {
|
|
8
|
-
super(target);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
onConnected() {
|
|
12
|
-
let that = this;
|
|
13
|
-
|
|
14
|
-
for (let x = 0; x < 2; x++) {
|
|
15
|
-
that.target.append(new Greatgrandchild!());
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
onClick(ev: Event){
|
|
20
|
-
this.trigger('Up', null, 'lu');
|
|
21
|
-
ev.stopImmediatePropagation();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
onUp( ev: CustomEvent ){
|
|
25
|
-
console.log( 'grandchild "Up" handler' );
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
export const Grandchild = getCE('test-grandchild');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grandparent.d.ts","sourceRoot":"","sources":["../../../src/test/test/grandparent.ts"],"names":[],"mappings":"AA0CA,eAAO,MAAM,WAAW,sCAA4B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.grandparent=e():t.grandparent=e()}(self,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var o in n)t.o(n,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:n[o]})},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,{GrandParent:()=>w});const n=new Function("try {return this===window;}catch(e){ return false;}");function o(t){return t&&t instanceof HTMLElement}function r(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function s(t,e,n,o=!1){return t.addEventListener(r(e),n,{capture:!1,once:o}),n}class c{stopped=!1;constructor(){}stop(){this.stopped=!0}}class a{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==l&&e.trigger("Init")}),0),function(t){if(!n()||t.constructor===l)return;const e=t.target;if(e instanceof HTMLElement){let n=t;Object.getOwnPropertyNames(n.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof n.constructor.prototype[t])).forEach((t=>{let o=/^one/.test(t),r=t.replace(/^on[e]{0,1}/,""),c=r.toLowerCase();if("on"+c in e){let o=e=>{n[t](e)};e.addEventListener(c,o)}else s(e,r,(e=>{n[t](e)}),o)}))}}(this)}get target(){return this._target.deref()}}class l extends a{constructor(t){super(t)}static add(t,e,n={}){return function(t,e,n={}){let o=t;o._mc||(o._mc=new l(t));const r=o._mc;return e.length&&!r[e]&&(r[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),o}(t,e,n)}static remove(t,e){!function(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}(t,e)}off(t,e){!function(t,e,n){t.removeEventListener(r(e),n)}(this.target,t,e)}on(t,e){return s(this.target,t,e)}one(t,e){return function(t,e,n){return s(t,e,n,!0),n}(this.target,t,e)}trigger(t,e={},n="l",o){!function(t,e,n={},o="l",s){const a=/^_mc/.test(e)?e:r(e),l=s||new c,i=new CustomEvent(a,{detail:{data:n,control:l},bubbles:!1});l.stopped||(t.dispatchEvent(i),i.stopImmediatePropagation(),l.stopped||/[ud]/.test(o)&&(-1===o.indexOf("l")&&(o+="l"),setTimeout((()=>{if(o.indexOf("u")>-1){let e=t.parentElement?.closest("[data-mc]");e&&e?._mc.trigger(a,n,o,l)}if(o.indexOf("d")>-1){let e=t._mc.children();e&&e.forEach((t=>t.trigger(a,n,o)))}}),0)))}(this.target,t,e,n,o)}ancestors(){let t=this?.target,e=[];if(!o(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}closest(){let t=this.target;return o(t)&&t.closest("[data-mc]")?._mc||null}children(){let t=this?.target;return o(t)?function(t){const e=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const o=[...t.querySelectorAll(n)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),o.length?o:null}(t):null}descendants(){const t=this?.target;if(!o(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}new Set;class i 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(t,e,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:t,oldValue:e,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function d(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function u(t,e,n=[]){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 o=t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("");d(e.prototype.constructor)&&e.prototype instanceof a?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(o,class extends i{instance;constructor(t){super();const n=d(e)?new e(this,t):e;l.add(this,o,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function p(t){return customElements.get(t)}function m(t,e){return Math.floor(Math.random()*(e-t+1)+t)}u("test-greatgrandchild",class extends l{constructor(t){super(t)}onConnected(){this.updateStyle()}onClick(t){this.trigger("Up",null,"lu"),t.stopImmediatePropagation()}onUp(t){console.log('greatgrandchild "Up" handler')}updateStyle(){this.target.setAttribute("style","border-color:rgb("+m(0,255)+","+m(0,255)+","+m(0,255)+")")}});const g=p("test-greatgrandchild");u("test-grandchild",class extends l{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<2;e++)t.target.append(new g)}onClick(t){this.trigger("Up",null,"lu"),t.stopImmediatePropagation()}onUp(t){console.log('grandchild "Up" handler')}});const h=p("test-grandchild");u("test-child",class extends l{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<10;e++)t.target.append(new h)}onClick(t){this.trigger("Up",null,"lu"),t.stopImmediatePropagation()}onUp(t){console.log('child "Up" handler'),t.detail.control.stop()}onDown(t){console.log('child "Down" handler')}});const f=p("test-child");u("test-parent",class extends l{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<5;e++)t.target.append(new f)}onClick(t){this.trigger("Up",null,"lu"),t.stopImmediatePropagation()}onUp(t){console.log('parent "Up" handler')}onDown(t){console.log('parent "Down" handler')}});const b=p("test-parent");u("test-grandparent",class extends l{constructor(t){super(t)}onConnected(t){for(let t=0;t<5;t++)this.target.append(new b)}onDisconnected(t){}onAdopted(t){}onAttributeChanged(t){}onClick(t){this.trigger("Up",null,"lu"),t.stopImmediatePropagation()}onUp(t){console.log('grandparent "Up" handler'),this.trigger("Down",{},"ld")}onDown(t){console.log('grandparent "Down" handler')}});const w=p("test-grandparent");return e})()));
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"grandparent.js","sourceRoot":"","sources":["../../../src/test/test/grandparent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,QAAQ,CACP,kBAAkB,EAElB,MAAM,eAAgB,SAAQ,EAAE;IAC/B,YAAY,MAAmB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;IACf,CAAC;IAED,WAAW,CAAC,EAAc;QACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,MAAO,EAAE,CAAC,CAAC;QACnC,CAAC;IACF,CAAC;IAED,cAAc,CAAC,EAAc;IAC7B,CAAC;IAED,SAAS,CAAC,EAAc;IACxB,CAAC;IAED,kBAAkB,CAAC,EAAc;IACjC,CAAC;IAED,OAAO,CAAC,EAAS;QAChB,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAC/B,EAAE,CAAC,wBAAwB,EAAE,CAAC;IAC/B,CAAC;IAED,IAAI,CAAE,EAAe;QACpB,OAAO,CAAC,GAAG,CAAE,0BAA0B,CAAE,CAAC;QAC1C,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,MAAM,CAAE,EAAe;QACtB,OAAO,CAAC,GAAG,CAAE,4BAA4B,CAAE,CAAC;IAC7C,CAAC;CAED,CACD,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,kBAAkB,CAAC,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { DC, defineCE, getCE } from '../../microcomponents.js';
|
|
2
|
-
import { Parent } from './parent.js';
|
|
3
|
-
defineCE(
|
|
4
|
-
'test-grandparent',
|
|
5
|
-
|
|
6
|
-
class TestGrandparent extends DC {
|
|
7
|
-
constructor(target: HTMLElement) {
|
|
8
|
-
super(target);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
onConnected(ev:CustomEvent) {
|
|
12
|
-
for (let x = 0; x < 5; x++) {
|
|
13
|
-
this.target.append(new Parent!());
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
onDisconnected(ev:CustomEvent) {
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
onAdopted(ev:CustomEvent) {
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
onAttributeChanged(ev:CustomEvent) {
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
onClick(ev: Event){
|
|
27
|
-
this.trigger('Up', null, 'lu');
|
|
28
|
-
ev.stopImmediatePropagation();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
onUp( ev: CustomEvent ){
|
|
32
|
-
console.log( 'grandparent "Up" handler' );
|
|
33
|
-
this.trigger('Down', {}, 'ld');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
onDown( ev: CustomEvent ){
|
|
37
|
-
console.log( 'grandparent "Down" handler' );
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
export const GrandParent = getCE('test-grandparent');
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"greatgrandchild.d.ts","sourceRoot":"","sources":["../../../src/test/test/greatgrandchild.ts"],"names":[],"mappings":"AAkDA,eAAO,MAAM,eAAe,sCAAgC,CAAC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { DC, defineCE, getCE } from '../../microcomponents.js';
|
|
2
|
-
function random(min, max) {
|
|
3
|
-
var random = Math.floor(Math.random() * (max - min + 1) + min);
|
|
4
|
-
return random;
|
|
5
|
-
}
|
|
6
|
-
defineCE('test-greatgrandchild', class TestGreatgrandchild extends DC {
|
|
7
|
-
constructor(target) {
|
|
8
|
-
super(target);
|
|
9
|
-
}
|
|
10
|
-
onConnected() {
|
|
11
|
-
let that = this;
|
|
12
|
-
that.updateStyle();
|
|
13
|
-
}
|
|
14
|
-
onClick(ev) {
|
|
15
|
-
this.trigger('Up', null, 'lu');
|
|
16
|
-
ev.stopImmediatePropagation();
|
|
17
|
-
}
|
|
18
|
-
onUp(ev) {
|
|
19
|
-
console.log('greatgrandchild "Up" handler');
|
|
20
|
-
}
|
|
21
|
-
updateStyle() {
|
|
22
|
-
var that = this;
|
|
23
|
-
function randomBorderColor() {
|
|
24
|
-
return ('rgb(' +
|
|
25
|
-
random(0, 255) +
|
|
26
|
-
',' +
|
|
27
|
-
random(0, 255) +
|
|
28
|
-
',' +
|
|
29
|
-
random(0, 255) +
|
|
30
|
-
')');
|
|
31
|
-
}
|
|
32
|
-
that.target.setAttribute('style', 'border-color:' + randomBorderColor());
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
export const Greatgrandchild = getCE('test-greatgrandchild');
|
|
36
|
-
//# sourceMappingURL=greatgrandchild.js.map
|