@twobirds/microcomponents 0.0.82 → 0.0.84
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/documentation/MC.md +0 -1
- package/assets/test/test.html +1 -1
- package/dist/MC.d.ts +11 -10
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.js +137 -200
- package/dist/MC.min.js +157 -296
- package/dist/MC.ts +202 -337
- package/dist/elements.d.ts +1 -1
- package/dist/elements.d.ts.map +1 -1
- package/dist/elements.js +26 -6
- package/dist/elements.min.js +1 -1
- package/dist/elements.ts +50 -7
- package/dist/formValues.js +2 -2
- package/dist/formValues.min.js +1 -1
- package/dist/formValues.ts +3 -3
- package/dist/microcomponents.d.ts +0 -1
- package/dist/microcomponents.d.ts.map +1 -1
- package/dist/microcomponents.js +0 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/microcomponents.ts +1 -1
- package/dist/observables.d.ts.map +1 -1
- package/dist/observables.js +52 -57
- package/dist/observables.min.js +1 -1
- package/dist/observables.ts +68 -73
- package/package.json +6 -5
- package/public/MC.d.ts +11 -10
- package/public/MC.d.ts.map +1 -1
- package/public/MC.js +137 -200
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +157 -296
- package/public/MC.ts +202 -337
- package/public/documentation/MC.md +0 -1
- package/public/elements.d.ts +1 -1
- package/public/elements.d.ts.map +1 -1
- package/public/elements.js +26 -6
- package/public/elements.js.map +1 -1
- package/public/elements.min.js +1 -1
- package/public/elements.ts +50 -7
- package/public/formValues.js +2 -2
- package/public/formValues.js.map +1 -1
- package/public/formValues.min.js +1 -1
- package/public/formValues.ts +3 -3
- package/public/microcomponents.d.ts +0 -1
- package/public/microcomponents.d.ts.map +1 -1
- package/public/microcomponents.js +0 -1
- package/public/microcomponents.js.map +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/microcomponents.ts +1 -1
- package/public/observables.d.ts.map +1 -1
- package/public/observables.js +52 -57
- package/public/observables.js.map +1 -1
- package/public/observables.min.js +1 -1
- package/public/observables.ts +68 -73
- package/public/{test/selectors.ts → selectors._ts} +2 -367
- package/public/src/MC.d.ts +37 -0
- package/public/src/MC.d.ts.map +1 -0
- package/public/src/MC.js +316 -0
- package/public/src/MC.js.map +1 -0
- package/public/src/MC.ts +202 -337
- package/public/src/elements.d.ts +5 -0
- package/public/src/elements.d.ts.map +1 -0
- package/public/src/elements.js +68 -0
- package/public/src/elements.js.map +1 -0
- package/public/src/elements.ts +50 -7
- package/public/src/formValues.d.ts +3 -0
- package/public/src/formValues.d.ts.map +1 -0
- package/public/src/formValues.js +162 -0
- package/public/src/formValues.js.map +1 -0
- package/public/src/formValues.ts +3 -3
- package/public/src/helpers.d.ts +14 -0
- package/public/src/helpers.d.ts.map +1 -0
- package/public/src/helpers.js +113 -0
- package/public/src/microcomponents.d.ts +6 -0
- package/public/src/microcomponents.d.ts.map +1 -0
- package/public/src/microcomponents.js +7 -0
- package/public/src/microcomponents.js.map +1 -0
- package/public/src/microcomponents.ts +1 -1
- package/public/src/observables.d.ts +11 -0
- package/public/src/observables.d.ts.map +1 -0
- package/public/src/observables.js +244 -0
- package/public/src/observables.js.map +1 -0
- package/public/src/observables.ts +68 -73
- package/public/{selectors.ts → src/selectors._ts} +2 -367
- package/public/src/test/grandparent.css +11 -0
- package/public/src/test/test/child.d.ts +2 -0
- package/public/src/test/test/child.d.ts.map +1 -0
- package/public/src/test/test/child.js +15 -0
- package/public/src/test/test/child.js.map +1 -0
- package/public/src/test/test/child.ts +21 -0
- package/public/src/test/test/grandchild.d.ts +2 -0
- package/public/src/test/test/grandchild.d.ts.map +1 -0
- package/public/src/test/test/grandchild.js +15 -0
- package/public/src/test/test/grandchild.js.map +1 -0
- package/public/src/test/test/grandchild.ts +21 -0
- package/public/src/test/test/grandparent.d.ts +2 -0
- package/public/src/test/test/grandparent.d.ts.map +1 -0
- package/public/src/test/test/grandparent.js +1 -0
- package/public/src/test/test/grandparent.js.map +1 -0
- package/public/src/test/test/grandparent.ts +29 -0
- package/public/src/test/test/greatgrandchild.d.ts +2 -0
- package/public/src/test/test/greatgrandchild.d.ts.map +1 -0
- package/public/src/test/test/greatgrandchild.js +29 -0
- package/public/src/test/test/greatgrandchild.js.map +1 -0
- package/public/src/test/test/greatgrandchild.ts +42 -0
- package/public/src/test/test/parent.d.ts +2 -0
- package/public/src/test/test/parent.d.ts.map +1 -0
- package/public/src/test/test/parent.js +15 -0
- package/public/src/test/test/parent.js.map +1 -0
- package/public/src/test/test/parent.ts +21 -0
- package/public/src/test/test/testform.d.ts +2 -0
- package/public/src/test/test/testform.d.ts.map +1 -0
- package/public/src/test/test/testform.js +1 -0
- package/public/src/test/test/testform.js.map +1 -0
- package/public/src/test/test/testform.ts +153 -0
- package/public/src/test/test/testfunction.d.ts +3 -0
- package/public/src/test/test/testfunction.d.ts.map +1 -0
- package/public/src/test/test/testfunction.js +7 -0
- package/public/src/test/test/testfunction.js.map +1 -0
- package/public/src/test/test/testfunction.ts +12 -0
- package/public/src/test/test/testmc.d.ts +3 -0
- package/public/src/test/test/testmc.d.ts.map +1 -0
- package/public/src/test/test/testmc.js +10 -0
- package/public/src/test/test/testmc.js.map +1 -0
- package/public/src/test/test/testmc.ts +16 -0
- package/public/src/test/test/testsimpleclass.d.ts +3 -0
- package/public/src/test/test/testsimpleclass.d.ts.map +1 -0
- package/public/src/test/test/testsimpleclass.js +9 -0
- package/public/src/test/test/testsimpleclass.js.map +1 -0
- package/public/src/test/test/testsimpleclass.ts +15 -0
- package/public/src/test/test.d.ts +2 -0
- package/public/src/test/test.d.ts.map +1 -0
- package/public/src/test/test.js +80 -0
- package/public/src/test/test.js.map +1 -0
- package/public/src/test/test.ts +188 -0
- package/public/src/test/testform.css +47 -0
- package/public/src/test/testform.html +56 -0
- package/public/src/test/testform.json +27 -0
- package/public/test/MC.d.ts +11 -10
- package/public/test/MC.d.ts.map +1 -1
- package/public/test/MC.js +137 -200
- package/public/test/MC.min.js +377 -0
- package/public/test/MC.ts +202 -337
- package/public/test/elements.d.ts +1 -1
- package/public/test/elements.d.ts.map +1 -1
- package/public/test/elements.js +26 -6
- package/public/test/elements.min.js +1 -0
- package/public/test/elements.ts +50 -7
- package/public/test/formValues.js +2 -2
- package/public/test/formValues.min.js +1 -0
- package/public/test/formValues.ts +3 -3
- package/public/test/grandparent.css +1 -3
- package/public/test/microcomponents.d.ts +0 -1
- package/public/test/microcomponents.d.ts.map +1 -1
- package/public/test/microcomponents.js +0 -1
- package/public/test/microcomponents.min.js +1 -1
- package/public/test/microcomponents.ts +1 -1
- package/public/test/observables.d.ts.map +1 -1
- package/public/test/observables.js +52 -57
- package/public/test/observables.min.js +1 -0
- package/public/test/observables.ts +68 -73
- package/public/test/test/child.ts +21 -0
- package/public/test/test/grandchild.ts +21 -0
- package/public/test/test/grandparent.d.ts.map +1 -1
- package/public/test/test/grandparent.js +1 -1
- package/public/test/test/grandparent.js.map +1 -1
- package/public/test/test/grandparent.ts +29 -0
- package/public/test/test/greatgrandchild.ts +42 -0
- package/public/test/test/parent.ts +21 -0
- package/public/test/test/testform.js +1 -1
- package/public/test/test/testform.js.map +1 -1
- package/public/test/test/testform.ts +153 -0
- package/public/test/test/testfunction.d.ts +3 -0
- package/public/test/test/testfunction.d.ts.map +1 -0
- package/public/test/test/testfunction.js +7 -0
- package/public/test/test/testfunction.js.map +1 -0
- package/public/test/test/testfunction.ts +12 -0
- package/public/test/test/testmc.d.ts +2 -5
- package/public/test/test/testmc.d.ts.map +1 -1
- package/public/test/test/testmc.js +4 -4
- package/public/test/test/testmc.js.map +1 -1
- package/public/test/test/testmc.ts +16 -0
- package/public/test/test/testsimpleclass.d.ts +3 -0
- package/public/test/test/testsimpleclass.d.ts.map +1 -0
- package/public/test/test/testsimpleclass.js +9 -0
- package/public/test/test/testsimpleclass.js.map +1 -0
- package/public/test/test/testsimpleclass.ts +15 -0
- package/public/test/test.html +1 -1
- package/public/test/test.js +5 -6
- package/public/test/test.js.map +1 -1
- package/public/test/test.ts +188 -0
- package/public/test/testform.css +47 -0
- package/public/test/testform.html +56 -0
- package/public/test/testform.json +3 -3
- package/public/typedoc/assets/navigation.js +1 -1
- package/public/typedoc/assets/search.js +1 -1
- package/public/typedoc/classes/MC.DC.html +6 -4
- package/public/typedoc/classes/MC.MC.html +3 -4
- package/public/typedoc/classes/MC.McBase.html +2 -2
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.off.html +1 -0
- package/public/typedoc/functions/MC.on.html +1 -0
- package/public/typedoc/functions/MC.one.html +1 -0
- package/public/typedoc/functions/elements.defineCE.html +1 -1
- package/public/typedoc/functions/elements.getCE.html +1 -1
- package/public/typedoc/functions/formValues.formValues.html +1 -1
- package/public/typedoc/functions/observables.observe.html +1 -1
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/typedoc/modules/MC.html +7 -6
- package/public/typedoc/modules/elements.html +1 -1
- package/public/typedoc/modules/formValues.html +1 -1
- package/public/typedoc/modules/observables.html +1 -1
- package/public/typedoc/types/observables.Observable.html +1 -1
- package/src/MC.ts +202 -337
- package/src/elements.ts +50 -7
- package/src/formValues.ts +3 -3
- package/src/microcomponents.ts +1 -1
- package/src/observables.ts +68 -73
- package/{dist/selectors.ts → src/selectors._ts} +2 -367
- package/src/test/test/grandparent.ts +12 -4
- package/src/test/test/testform.ts +13 -11
- package/src/test/test/testfunction.ts +12 -0
- package/src/test/test/testmc.ts +13 -9
- package/src/test/test/testsimpleclass.ts +15 -0
- package/src/test/test.ts +8 -20
- package/tasks.md +36 -0
- package/tsconfig.json +2 -2
- package/typedoc.json +1 -1
- package/webpack.config.js +2 -2
- package/dist/McEvent.d.ts +0 -15
- package/dist/McEvent.d.ts.map +0 -1
- package/dist/McEvent.js +0 -71
- package/dist/selectors.d.ts +0 -108
- package/dist/selectors.d.ts.map +0 -1
- package/dist/selectors.js +0 -971
- package/dist/selectors.min.js +0 -1
- package/public/McEvent.d.ts +0 -15
- package/public/McEvent.d.ts.map +0 -1
- package/public/McEvent.js +0 -71
- package/public/McEvent.js.map +0 -1
- package/public/selectors.d.ts +0 -108
- package/public/selectors.d.ts.map +0 -1
- package/public/selectors.js +0 -971
- package/public/selectors.js.map +0 -1
- package/public/selectors.min.js +0 -1
- package/public/src/selectors.ts +0 -1634
- package/public/test/MC.js.map +0 -1
- package/public/test/McEvent.d.ts +0 -15
- package/public/test/McEvent.d.ts.map +0 -1
- package/public/test/McEvent.js +0 -71
- package/public/test/McEvent.js.map +0 -1
- package/public/test/McEvent.ts +0 -96
- package/public/test/elements.js.map +0 -1
- package/public/test/formValues.js.map +0 -1
- package/public/test/microcomponents.js.map +0 -1
- package/public/test/observables.js.map +0 -1
- package/public/test/selectors.d.ts +0 -108
- package/public/test/selectors.d.ts.map +0 -1
- package/public/test/selectors.js +0 -971
- package/public/test/selectors.js.map +0 -1
- package/public/typedoc/classes/MC.McEvent.html +0 -9
- package/public/typedoc/functions/MC.addListener.html +0 -1
- package/public/typedoc/functions/MC.removeListener.html +0 -1
- package/src/McEvent.ts +0 -96
- package/src/selectors.ts +0 -1634
- /package/{dist/McEvent.ts → public/McEvent._ts} +0 -0
- /package/public/{McEvent.ts → src/McEvent._ts} +0 -0
- /package/public/{test → src}/helpers.js.map +0 -0
- /package/{public/src/McEvent.ts → src/McEvent._ts} +0 -0
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
copyGettersSetters,
|
|
9
9
|
} from './helpers.js';
|
|
10
10
|
|
|
11
|
-
import { DC, HTMLMcElement,
|
|
11
|
+
import { DC, HTMLMcElement, trigger } from './MC.js';
|
|
12
12
|
|
|
13
13
|
function isObservableObject(value: any): boolean {
|
|
14
14
|
return value != null && typeof value === 'object';
|
|
@@ -21,12 +21,11 @@ function getPlaceholders(target: HTMLElement): string[] {
|
|
|
21
21
|
regEx = /\{[^\{\}]*\}/g;
|
|
22
22
|
|
|
23
23
|
// scan attributes
|
|
24
|
-
target
|
|
25
|
-
.getAttributeNames()
|
|
24
|
+
( !!target.getAttributeNames ? target.getAttributeNames() : [] )
|
|
26
25
|
.filter((attr) => target.getAttribute(attr)?.match(regEx)) // extract placeholder(s)
|
|
27
26
|
.forEach((attr) => {
|
|
28
|
-
let
|
|
29
|
-
|
|
27
|
+
let placeholders: Set<string> = new Set(target.getAttribute(attr)?.match(regEx));
|
|
28
|
+
placeholders.forEach((placeholder) =>
|
|
30
29
|
placeholders.add(placeholder.replace(/[\{\}]/g, ''))
|
|
31
30
|
);
|
|
32
31
|
});
|
|
@@ -62,35 +61,31 @@ class Placeholders extends DC {
|
|
|
62
61
|
|
|
63
62
|
constructor(target: HTMLElement) {
|
|
64
63
|
super(target);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
that.#attachCallbacks();
|
|
69
|
-
delete that._mc; // cleanup, not needed
|
|
64
|
+
getPlaceholders(target).forEach((property) => (this.data[property] = ''));
|
|
65
|
+
observe(this);
|
|
66
|
+
this.#attachCallbacks();
|
|
70
67
|
}
|
|
71
68
|
|
|
72
69
|
#attachCallbacks() {
|
|
73
|
-
let
|
|
74
|
-
target = that.target,
|
|
70
|
+
let target = this.target,
|
|
75
71
|
hide: boolean = false;
|
|
76
72
|
|
|
77
|
-
//console.log('attachCallbacks',
|
|
73
|
+
//console.log('attachCallbacks', this.target);
|
|
78
74
|
|
|
79
75
|
// scan attributes
|
|
80
|
-
target
|
|
81
|
-
.getAttributeNames()
|
|
76
|
+
( !!target.getAttributeNames ? target.getAttributeNames() : [] )
|
|
82
77
|
.filter((attr: string) =>
|
|
83
78
|
target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)
|
|
84
79
|
) // extract placeholder(s)
|
|
85
80
|
.forEach((attr: string) => {
|
|
86
|
-
let
|
|
81
|
+
let placeholders: Set<string> = new Set(
|
|
87
82
|
target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g)
|
|
88
83
|
);
|
|
89
84
|
// attach callback
|
|
90
|
-
|
|
85
|
+
this.data.observe(
|
|
91
86
|
((template: string) => (data: LooseObject) => {
|
|
92
87
|
let result: string = template;
|
|
93
|
-
|
|
88
|
+
placeholders.forEach((placeholder) => {
|
|
94
89
|
result = result.replace(
|
|
95
90
|
placeholder,
|
|
96
91
|
data[placeholder.replace(/[\{\}]/g, '')]
|
|
@@ -108,44 +103,41 @@ class Placeholders extends DC {
|
|
|
108
103
|
return (
|
|
109
104
|
// is text node and has placeholders
|
|
110
105
|
childNode.nodeType === 3 &&
|
|
111
|
-
((childNode as
|
|
106
|
+
((childNode as Node).nodeValue || '').match(/\{[^\{\}]*\}/g)
|
|
112
107
|
);
|
|
113
108
|
})
|
|
114
109
|
.forEach((childNode) => {
|
|
115
110
|
hide = true;
|
|
116
|
-
let
|
|
111
|
+
let placeholders: Set<string> = new Set(
|
|
117
112
|
childNode.nodeValue.match(/\{[^\{\}]*\}/g)
|
|
118
113
|
);
|
|
119
114
|
|
|
120
115
|
// attach callback
|
|
121
|
-
|
|
116
|
+
this.data.observe(
|
|
122
117
|
((template: string) => (data: LooseObject) => {
|
|
123
118
|
let result: string = template;
|
|
124
|
-
//console.log('text node "', template, '"
|
|
125
|
-
|
|
119
|
+
//console.log('text node "', template, '" callback data:', data);
|
|
120
|
+
placeholders.forEach((placeholder) => {
|
|
126
121
|
result = result.replace(
|
|
127
122
|
placeholder,
|
|
128
123
|
data[placeholder.replace(/[\{\}]/g, '')]
|
|
129
124
|
);
|
|
130
125
|
});
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (!!that.oldDisplay) {
|
|
137
|
-
target.style = that.oldDisplay;
|
|
138
|
-
} else {
|
|
139
|
-
target.removeAttribute('style');
|
|
140
|
-
}
|
|
141
|
-
delete that.oldDisplay;
|
|
126
|
+
|
|
127
|
+
if (!!this.oldDisplay) {
|
|
128
|
+
target.style = this.oldDisplay;
|
|
129
|
+
} else {
|
|
130
|
+
target.removeAttribute('style');
|
|
142
131
|
}
|
|
132
|
+
delete this.oldDisplay;
|
|
133
|
+
|
|
143
134
|
childNode.nodeValue = result;
|
|
144
135
|
})(childNode.nodeValue)
|
|
145
136
|
);
|
|
146
137
|
|
|
147
138
|
// hide for now
|
|
148
|
-
|
|
139
|
+
this.oldDisplay = target.getAttribute('style') || ''; // TBD allow null to indicate there was no old style attribute
|
|
140
|
+
|
|
149
141
|
if (
|
|
150
142
|
hide &&
|
|
151
143
|
!inputs.includes((target as any).constructor) &&
|
|
@@ -156,27 +148,25 @@ class Placeholders extends DC {
|
|
|
156
148
|
});
|
|
157
149
|
}
|
|
158
150
|
|
|
159
|
-
onData(ev:
|
|
160
|
-
let
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (that.data.hasOwnProperty(key)) data[key] = ev.data[key];
|
|
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];
|
|
164
155
|
});
|
|
165
|
-
//console.log('onData
|
|
166
|
-
if (JSON.stringify(data) !== JSON.stringify(
|
|
167
|
-
Object.assign(
|
|
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
|
|
168
159
|
}
|
|
169
160
|
}
|
|
170
161
|
|
|
171
162
|
function getPlaceholderElements(
|
|
172
163
|
target: HTMLElement | DocumentFragment | ShadowRoot
|
|
173
164
|
): HTMLElement[] {
|
|
174
|
-
let elements: Array<
|
|
175
|
-
target instanceof HTMLElement ? [target] : []
|
|
176
|
-
)
|
|
165
|
+
let elements: Array<Node> = [target]
|
|
177
166
|
.concat([...(target.querySelectorAll('*') as unknown as HTMLElement[])])
|
|
178
167
|
.filter((e) => !!getPlaceholders(e as HTMLElement).length)
|
|
179
|
-
.filter((e) => e
|
|
168
|
+
.filter((e) => (e as HTMLElement)?.tagName !== 'STYLE')
|
|
169
|
+
.reverse(); // to start with inner elements
|
|
180
170
|
//console.log('getPlaceholderElements', elements);
|
|
181
171
|
return elements as HTMLElement[];
|
|
182
172
|
}
|
|
@@ -232,40 +222,46 @@ function makeObservable(val: any): Class<typeof val>{
|
|
|
232
222
|
this.#callbacks = callbacks
|
|
233
223
|
}
|
|
234
224
|
|
|
235
|
-
observe(
|
|
225
|
+
observe( callback: Function ) {
|
|
236
226
|
//console.log('observe');
|
|
237
|
-
this.#callbacks.push(
|
|
227
|
+
this.#callbacks.push( callback );
|
|
238
228
|
return this;
|
|
239
229
|
}
|
|
240
230
|
|
|
241
231
|
bind(target: HTMLElement | DocumentFragment | ShadowRoot) {
|
|
242
|
-
const
|
|
243
|
-
iso = isObservableObject(that.valueOf());
|
|
232
|
+
const iso = isObservableObject(this.valueOf());
|
|
244
233
|
//console.log('bind', iso, target);
|
|
245
234
|
|
|
246
235
|
if (iso) {
|
|
247
236
|
makePlaceholders(target);
|
|
248
|
-
const placeholders: unknown =
|
|
249
|
-
|
|
250
|
-
|
|
237
|
+
const placeholders: unknown =
|
|
238
|
+
[
|
|
239
|
+
target,
|
|
240
|
+
...target.querySelectorAll('[data-mc]'),
|
|
241
|
+
]
|
|
242
|
+
.filter(
|
|
243
|
+
(e) => !!(e as LooseObject)?._mc?._placeholders
|
|
244
|
+
);
|
|
245
|
+
|
|
251
246
|
//console.log('placeholders:', target, placeholders);
|
|
247
|
+
|
|
252
248
|
const func = function callback(data: LooseObject) {
|
|
253
249
|
// avoid bubbling for speed
|
|
254
|
-
let
|
|
255
|
-
//console.log('inside callback', target,
|
|
256
|
-
(placeholders as
|
|
250
|
+
let flattenedData = flattenObject(data);
|
|
251
|
+
//console.log('inside placeholder callback', target, flattenedData);
|
|
252
|
+
(placeholders as Node[]).forEach((node) => {
|
|
257
253
|
// console.log('trigger callback', e);
|
|
258
|
-
if (!
|
|
259
|
-
(
|
|
254
|
+
if (!node) return;
|
|
255
|
+
trigger(node as HTMLMcElement, 'data', flattenedData);
|
|
260
256
|
});
|
|
261
257
|
};
|
|
262
|
-
(
|
|
263
|
-
|
|
258
|
+
(this as any).#callbacks.push(func);
|
|
259
|
+
this.notify();
|
|
264
260
|
} else {
|
|
265
261
|
console.warn(
|
|
266
262
|
'IGNORED - cannot bind a non-Object to the dom, IS:',
|
|
267
|
-
typeof
|
|
268
|
-
|
|
263
|
+
typeof this.valueOf(),
|
|
264
|
+
this
|
|
269
265
|
);
|
|
270
266
|
}
|
|
271
267
|
|
|
@@ -273,20 +269,19 @@ function makeObservable(val: any): Class<typeof val>{
|
|
|
273
269
|
}
|
|
274
270
|
|
|
275
271
|
notify(notify?: boolean) {
|
|
276
|
-
let
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
: that.valueOf();
|
|
272
|
+
let data =
|
|
273
|
+
isObservableObject(this.valueOf()) &&
|
|
274
|
+
this.valueOf() instanceof Array === false
|
|
275
|
+
? structuredClone(Object.assign({}, this))
|
|
276
|
+
: this.valueOf();
|
|
282
277
|
|
|
283
278
|
if (notify !== undefined) {
|
|
284
|
-
|
|
279
|
+
this.#notify = notify;
|
|
285
280
|
// return;
|
|
286
281
|
}
|
|
287
282
|
|
|
288
|
-
//if (
|
|
289
|
-
(
|
|
283
|
+
//if (this.#notify) console.log('notify', this, data);
|
|
284
|
+
(this as any).#callbacks.forEach((f: Function) => {
|
|
290
285
|
// console.log(
|
|
291
286
|
// (this.constructor as any).callbacks,
|
|
292
287
|
// 'notify: exec callback',
|
|
@@ -296,7 +291,7 @@ function makeObservable(val: any): Class<typeof val>{
|
|
|
296
291
|
f(data);
|
|
297
292
|
});
|
|
298
293
|
|
|
299
|
-
return
|
|
294
|
+
return this;
|
|
300
295
|
}
|
|
301
296
|
};
|
|
302
297
|
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
);
|
|
20
|
+
|
|
21
|
+
export const Child = getCE('test-child');
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
);
|
|
20
|
+
|
|
21
|
+
export const Grandchild = getCE('test-grandchild');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grandparent.d.ts","sourceRoot":"","sources":["../../../src/test/test/grandparent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"grandparent.d.ts","sourceRoot":"","sources":["../../../src/test/test/grandparent.ts"],"names":[],"mappings":"AA4BA,eAAO,MAAM,WAAW,sCAA4B,CAAC"}
|
|
@@ -1 +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.grandparent=e():t.grandparent=e()}(self,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},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:()=>
|
|
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 r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},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:()=>_});var n=new Function("try {return this===window;}catch(e){ return false;}");function r(t,e){let n=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const r=t?._mc;!e&&r?n=n.concat(Object.values(t._mc)):e&&r&&r[e]&&n.push(r[e])}})),n}function o(t,e,n=!0){let r=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&r.push(t._mc[e]):r=r.concat(Object.values(t._mc)),n))return r;t=t.parentNode}return r}function c(t){return t&&t instanceof HTMLElement}function s(t,e,n={}){let r=t;if(!r._mc){let e=p?.debug;p.debug=!1,r._mc=new p(t),p.debug=e,delete r._mc._mc}const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}function a(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")}function i(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function d(t,e,n,r=!1){t.addEventListener(i(e),n,{capture:!1,once:r})}function u(t,e,n={},r="l"){const o="string"==typeof e?new CustomEvent(i(e),{detail:{data:n,bubble:r}}):e;r.length&&r.indexOf("l")>-1&&t.dispatchEvent(o),/[u|d]/.test(r)&&function(t,e){setTimeout((()=>{-1===e.detail.bubble.indexOf("l")&&(e.detail.bubble+="l"),e.detail.bubble.indexOf("u")>-1&&t.closest("[data-mc]")?.dispatchEvent(e),e.detail.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&p.trigger(t,e)}))}),0)}(t,o)}class l{_target;constructor(t,e=!1){var r;this._target=new WeakRef(t||{}),(r=this).constructor!==p&&setTimeout((()=>{r.trigger("Init")}),0),function(t){if(!n()||t.constructor===p)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 r=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase(),s=e=>{n[t](e)};e["on"+c]?e.addEventListener(c,s):d(e,o,s,r)}))}}(this)}get target(){return this._target.deref()}}class p extends l{constructor(t,e=!1){super(t)}static add=s;static remove=a;static trigger=u;off(t,e){!function(t,e,n){t.removeEventListener(i(e),n)}(this.target,t,e)}on(t,e){d(this.target,t,e)}one(t,e){!function(t,e,n){d(t,e,n,!0)}(this.target,t,e)}trigger(t,e={},n="l"){}parent(t=""){let e=this.target;return c(e)?o(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return c(e)?o(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;return c(e)?r([...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 r=t.querySelectorAll(n);return t.removeAttribute("temp_id"),r}(e)],t):[]}descendants(t=""){let e=this?.target;return c(e)?r([...e.querySelectorAll("*[data-mc]")],t):[]}}new Set;class m extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(t,e,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:t,oldValue:e,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function f(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function h(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 r=t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("");f(e.prototype.constructor)&&e.prototype instanceof l?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends m{instance;constructor(t){super();const n=f(e)?new e(this,t):e;p.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function g(t){return customElements.get(t)}function b(t,e){return Math.floor(Math.random()*(e-t+1)+t)}h("test-greatgrandchild",class extends p{constructor(t){super(t)}onConnected(){this.updateStyle()}updateStyle(){this.target.setAttribute("style","border-color:rgb("+b(0,255)+","+b(0,255)+","+b(0,255)+")")}});const v=g("test-greatgrandchild");h("test-grandchild",class extends p{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<2;e++)t.target.append(new v)}});const E=g("test-grandchild");h("test-child",class extends p{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<10;e++)t.target.append(new E)}});const y=g("test-child");h("test-parent",class extends p{constructor(t){super(t)}onConnected(){let t=this;for(let e=0;e<5;e++)t.target.append(new y)}});const C=g("test-parent");h("test-grandparent",class extends p{constructor(t){super(t)}onConnected(t){for(let t=0;t<5;t++)this.target.append(new C)}onDisconnected(t){}onAdopted(t){}onAttributeChanged(t){}});const _=g("test-grandparent");return e})()));
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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;CAED,CACD,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,CAAC,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
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
|
+
}
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export const GrandParent = getCE('test-grandparent');
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { DC, defineCE, getCE } from '../../microcomponents.js';
|
|
2
|
+
|
|
3
|
+
function random(min: number, max: number) {
|
|
4
|
+
var random = Math.floor(Math.random() * (max - min + 1) + min);
|
|
5
|
+
return random;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
defineCE(
|
|
9
|
+
'test-greatgrandchild',
|
|
10
|
+
|
|
11
|
+
class TestGreatgrandchild extends DC {
|
|
12
|
+
constructor(target: HTMLElement) {
|
|
13
|
+
super(target);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
onConnected() {
|
|
17
|
+
let that = this;
|
|
18
|
+
|
|
19
|
+
that.updateStyle();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
updateStyle() {
|
|
23
|
+
var that = this;
|
|
24
|
+
|
|
25
|
+
function randomBorderColor() {
|
|
26
|
+
return (
|
|
27
|
+
'rgb(' +
|
|
28
|
+
random(0, 255) +
|
|
29
|
+
',' +
|
|
30
|
+
random(0, 255) +
|
|
31
|
+
',' +
|
|
32
|
+
random(0, 255) +
|
|
33
|
+
')'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
that.target.setAttribute('style', 'border-color:' + randomBorderColor());
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
|
|
42
|
+
export const Greatgrandchild = getCE('test-greatgrandchild');
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DC, defineCE, getCE } from '../../microcomponents.js';
|
|
2
|
+
import { Child } from './child.js';
|
|
3
|
+
defineCE(
|
|
4
|
+
'test-parent',
|
|
5
|
+
|
|
6
|
+
class Parent extends DC {
|
|
7
|
+
constructor(target: HTMLElement) {
|
|
8
|
+
super(target);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
onConnected() {
|
|
12
|
+
let that = this;
|
|
13
|
+
|
|
14
|
+
for (let x = 0; x < 5; x++) {
|
|
15
|
+
that.target.append(new Child!());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
export const Parent = getCE('test-parent');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TestTestform=t():e.TestTestform=t()}(self,(()=>(()=>{"use strict";var e=new Function("try {return this===window;}catch(e){ return false;}");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 r=new Function("try {return this===window;}catch(e){ return false;}");let a=new Set;function l(e,t){let n=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const r=e?._mc;!t&&r?n=n.concat(Object.values(e._mc)):t&&r&&r[t]&&n.push(r[t])}})),n}function o(e,t,n=!0){let r=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&r.push(e._mc[t]):r=r.concat(Object.values(e._mc)),n))return r;e=e.parentNode}return r}function s(e){return e&&e instanceof HTMLElement}function i(e,t,n,r=!1,a=!1){let l={once:!1};r&&(l.capture=r),a&&(l.once=a),e.addEventListener(t,n,l)}function c(e,t,n={}){let r=e;if(!r._mc){let t=f?.debug;f.debug=!1,r._mc=new f(e),f.debug=t,delete r._mc._mc}const a=r._mc;return t.length&&!a[t]&&(a[t]=n,e instanceof HTMLElement&&!e.getAttribute("_mc")&&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,r={},a="l"){let l=e?._mc;if(!l)return;let o=t instanceof n?new n(t.type,t.data,"l"):new n(t,r,"l"),s="string"!=typeof t?t:new n(t,r,a);[...Object.values(l)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(o)})),/[ud]/.test(s.bubble)&&d(e,s)}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&&f.trigger(n,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&f.trigger(e,t)}))}),0)}r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>a.add(e)));class m{#r;constructor(e,t=!1){var n;this.#r=new WeakRef(e||{}),(n=this).constructor!==f&&setTimeout((()=>{n.trigger("Init")}),0),function(e){if(!r()||e.constructor===f)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((r=>{let l=/^one/.test(r),o=r.replace(/^on[e]{0,1}/,""),s=o.toLowerCase();l&&Object.defineProperty(e,"on"+o,{configurable:!0,enumerable:!1,writable:!0,value:e=>{n.constructor.prototype[r].bind(n)(e)}}),a.has("on"+s)&&i(t,s,(e=>{n.trigger(o,e)}),!1,l)}))}}(this)}get target(){return this.#r.deref()}}class b extends m{_mc={};constructor(e){super(e)}static trigger=p;trigger(e,t={},r="l"){let a=this;if(a.constructor===b||a.constructor===f){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,r);return[...Object.getOwnPropertyNames(a)].forEach((e=>{a[e]?.trigger&&"function"==typeof a[e]?.trigger&&a[e]?.trigger(l)})),void(/[ud]/.test(o.bubble)&&d(a.target,o))}if(a instanceof b||a instanceof f){const a=this,l="string"!=typeof e?e:new n(e,t,r),o="on"+l.type[0].toUpperCase()+l.type.slice(1);if(l.bubble.indexOf("l")>-1&&(l.immediateStopped||"function"!=typeof a[o]||(a[o](l),a.hasOwnProperty(o)&&delete a[o])),l.stopped||"l"===l.bubble)return a;/[ud]/.test(l.bubble)&&d(a.target,l)}}}class f extends m{_mc={};constructor(e,t=!1){super(e)}static add=c;static remove=u;static trigger=p;trigger(e,t={},n){b.prototype.trigger.call(this,e,t,n)}parent(e=""){let t=this.target;return s(t)?o(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return s(t)?o(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!s(t))return[];const n=Math.random().toString().replace(".",""),r='[_mc]:not([temp_id="'+n+'"] [_mc] [_mc])';t.setAttribute("temp_id",n);const a=l([...t.querySelectorAll(r)],e);return t.removeAttribute("temp_id"),a}descendants(e=""){let t=this?.target;return s(t)?l([...t.querySelectorAll("*[_mc]")],e):[]}}const g=new Map,h=new Map;function y(e){const t="./"+e.split("-").join("/")+".js",n=document.createElement("script");return n.setAttribute("src",t),n.setAttribute("blocking","render"),n.async=!0,n.setAttribute("type","module"),n.setAttribute("name",e),n.setAttribute("loading",""),i(n,"load",(e=>{n.removeAttribute("loading"),n.setAttribute("loaded","")})),i(n,"error",(e=>{console.error("could not load Custom Element code from",t)})),n}function v(){[...document.querySelectorAll(":not(:defined)")].filter((e=>!!e&&!customElements.get(e.tagName.toLowerCase())&&!g.has(e.tagName.toLowerCase()))).forEach((e=>{const t=e.tagName.toLowerCase(),n=(t.split("-").join("/"),y(t));i(n,"load",(()=>{g.set(t,customElements.get(e.tagName.toLowerCase()))})),g.set(t,"loading"),document.head.append(n)})),[...document.querySelectorAll('[_mc]:not([_mc=""]')].filter((e=>!!e)).forEach((e=>{const t=e.getAttribute("_mc")?.split(" ").filter((e=>!!e))||[],n=t.filter((e=>!h.has(e)));n?.forEach((e=>{const t=y(e);i(t,"load",(()=>{return t=document.head.querySelector(`script[name="${e}"]`),void setTimeout((function(){const e=t.getAttribute("src"),n=t.getAttribute("name"),r=document.createElement("script");r.async=!0,r.setAttribute("type","module");const a=`\n\n\t\t\timport _ from "${e}";\n\t\t\timport { DC } from "./microcomponents.js";\n\n\t\t\tconst elements = Array.from(document.querySelectorAll('[_mc*="${n}"]')).filter( element => element instanceof HTMLElement );\n\n\t\t\telements.forEach((element) => {\n\t\t\t\t// add class to MCs repository\n\t\t\t\tautoload.state.MCs.set( '${n}', _ );\n\t\t\t\t// add instance to HTMLElement \n\t\t\t\tDC.add(element, _.name, new _(element));\n\t\t\t\t// remove instance name from elements "_mc" attribute\n\t\t\t\telement.setAttribute('_mc', element.getAttribute('_mc').replace('${n}', '').replace( /ww/g, ' ').trim()); \n\t\t\t});\n\n\t\t\tsetTimeout( () => {\n\t\t\t\tdocument.body.querySelector('script[name="${n}]"')?.remove();\n\t\t\t},0);\n\n\t\t`;r.innerHTML=a,document.body.append(r)}),0);var t})),h.set(e,"loading"),document.head.append(t)}));const r=t.filter((e=>h.has(e)&&!h.get(e).length));r?.forEach((t=>{setTimeout((()=>{f.add(e,t,new(E.state.MCs.get(t))(e)),e.getAttribute("_mc").replace("${elementName}","").replace(/\w\w/g," ").trim(),e.setAttribute("_mc")}),5)}))}))}let w=!1,O=null;function E(e=!0){return e?(w=e,O=new MutationObserver(v),setTimeout((()=>{O.observe(document.body,{childList:!0,subtree:!0}),v()}),5),window.autoload=window.autoload||E,w):(O?.disconnect(),O=null,w)}function A(e){let t={};return[...Object.keys(e)].sort().forEach((n=>{var r;(r=e[n])&&r.constructor&&r.constructor===Object?t[n]=A(e[n]):t[n]=e[n]})),t}function x(e,t=!0){let n={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const r=x(e[t],!1);for(const e in r)n[t+"."+e]=r[e]}else n[t]=e[t]})),t?A(n):n}function _(e,t){return JSON.stringify(x(e))===JSON.stringify(x(t))}function k(e,t){let n;return()=>{clearTimeout(n),n=setTimeout((function(){e(...arguments)}),t)}}function j(e,t){const n=Object.getOwnPropertyDescriptors(e);for(const[e,r]of Object.entries(n))("get"in r||"set"in r)&&Object.defineProperty(t,e,r)}E.state={CEs:g,MCs:h};class S extends HTMLElement{constructor(){super()}connectedCallback(){f.trigger(this,"Connected")}disconnectedCallback(){f.trigger(this,"Disconnected")}adoptedCallback(){f.trigger(this,"Adopted")}attributeChangedCallback(e,t,n){f.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:n})}}function C(e){return null!=e&&"object"==typeof e}function T(e){let t=new Set,n=/\{[^\{\}]*\}/g;return e.getAttributeNames().filter((t=>e.getAttribute(t)?.match(n))).forEach((r=>{new Set(e.getAttribute(r)?.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,"")))}const N=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class L extends f{data={};oldDisplay="";constructor(e){super(e);let t=this;T(e).forEach((e=>t.data[e]="")),H(t),t.#a(),delete t._mc}#a(){let e=this,t=e.target,n=!1;t.getAttributeNames().filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((n=>{let r=new Set(t.getAttribute(n)?.match(/\{[^\{\}]*\}/g));var a;e.data.observe((a=t.getAttribute(n),e=>{let l=a;r.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((r=>{n=!0;let a=new Set(r.nodeValue.match(/\{[^\{\}]*\}/g));var l;e.data.observe((l=r.nodeValue,n=>{let o=l;a.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),r.nodeValue=o})),e.oldDisplay=t.getAttribute("style)")||"",n&&!N.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(e){let t=this,n={};Object.keys(e.data).forEach((r=>{t.data.hasOwnProperty(r)&&(n[r]=e.data[r])})),JSON.stringify(n)!==JSON.stringify(t.data)&&Object.assign(t.data,n)}}const M={};function I(e){let t=e.constructor.name;return M[t]||function(e){const t=e.constructor,n=t.name;let r=class extends t{#l=!0;#o=[];constructor(e){super(e),this.constructor.callbacks=[],C(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}get callbacks(){return this.#o}set callbacks(e){this.#o=e}observe(e){return this.#o.push(e),this}bind(e){const t=this;if(C(t.valueOf())){!function(e){var t;(t=e,(t instanceof HTMLElement?[t]:[]).concat([...t.querySelectorAll("*")]).filter((e=>!!T(e).length)).filter((e=>"STYLE"!==e.tagName))).forEach((e=>{e?._mc?._placeholders||f.add(e,"_placeholders",new L(e))}))}(e);const n=[...e.querySelectorAll("[_mc]")].filter((e=>!!e?._mc?._placeholders)),r=function(e){let t=x(e);n.forEach((e=>{e&&e._mc.trigger("data",t)}))};t.#o.push(r),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=C(t.valueOf())&&t.valueOf()instanceof Array==0?structuredClone(Object.assign({},t)):t.valueOf();return void 0!==e&&(t.#l=e),t.#o.forEach((e=>{e(n)})),t}};return M[n]=r,r}(e)}const H=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if(e.hasOwnProperty(t)&&"function"!=typeof e[t]&&!e?.[t]?.constructor?.prototype?.observe){if("_"===t[0]||void 0===e?.[t])return e;let n=e[t],r=new(I(n))(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(C(r.valueOf())){let e=structuredClone(Object.assign({},r));setTimeout(k((function(){_(structuredClone(Object.assign({},r)),e)||r.notify()}),0),0)}return r},set(e){if(typeof e==typeof r.valueOf())if(C(r.valueOf())&&r.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},r));void 0===r?.constructor?.prototype?.observe&&(r=new(I(e))(structuredClone(Object.assign({},e))),j(e,r),r.seal()),Object.assign(r,e),setTimeout(k((function(){_(structuredClone(Object.assign({},r)),t)||r.notify()}),0),0)}else{let t=r.valueOf(),n=r.callbacks;e!==t&&(r=new(I(e))(e),r.callbacks=n,r.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof r.valueOf(),r,"- CANNOT BECOME:",typeof e)}}),e[t]=n}})),e);class P{constructor(e){}}class D extends P{#s;constructor(e){super(e),this.#s=e}get val(){return new FormData(this.#s.form).get(this.#s.name)}set val(e){[...this.#s.form.querySelectorAll(`input[type="radio"][name="${this.#s.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class q extends P{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.checked}set val(e){this.#s.checked=e}}class $ extends P{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.value}set val(e){this.#s.value=e}}class R extends P{#s;#i=!1;constructor(e){super(e),this.#s=e,this.#i=e.multiple}get val(){const e=[];return[...this.#s.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#i?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#s.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class V extends P{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.value||""}set val(e){this.#s.value=e}}return function(e,t,n=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=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})}(r,class extends S{instance;constructor(e){super();let n=new t(this,e);f.add(this,r,n)}static get observedAttributes(){return n}}))}("test-testform",class extends f{data;constructor(e){super(e);const t=this;delete t._mc;let n=t.target.attachShadow({mode:"open"});n.innerHTML=`<style>${t.css}</style>${t.template}`,function(e,t,n){let r=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],n={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let r=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":r=new D(e);break;case"checkbox":r=new q(e);break;default:r=new $(e)}break;case"select":r=new R(e);break;case"textarea":r=new V(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}r&&(f.add(e,t,r),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>r.val,set:e=>{r.val!==e&&(r.val=e)}}))}})),n})(n);e[t]=Object.assign({},r),H(e,t),j(r,e[t]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{i(n,"input",(n=>{e[t].notify()}))}))}(t,"data",n),t.data.bind(n),fetch("./testform.json").then((e=>e.json())).then((e=>{t.data=e}))}get template(){return'\n <form>\n \x3c!-- sample form to start with --\x3e\n <fieldset>\n <legend>Inputs</legend>\n <label>text</label><input type="text" name="textInput" value="Hallo" /> <strong>2wB: </strong>{textInput}<br />\n <label>color</label><input type="color" name="colorInput" value="#000000" /><br />\n <label>date</label><input type="date" name="dateInput" value="" /><br />\n <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" /><br />\n <label>email</label><input type="email" name="email" value="" /><br />\n <label>file</label><input type="file" name="fileInput" value="" /><br />\n <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" /><br />\n <label>month</label><input type="month" name="month" value="" /><br />\n <label>number</label><input type="number" name="number" value="" /><br />\n <label>password</label><input type="password" name="passInput" value="" /><br />\n <label>range</label><input type="range" name="rangeInput" value="" /><br />\n <label>search</label><input type="search" name="searchInput" value="" /><br />\n <label>tel</label><input type="tel" name="telInput" value="" /><br />\n <label>time</label><input type="time" name="timeInput" value="" /><br />\n <label>url</label><input type="url" name="urlInput" value="" /><br />\n <label>week</label><input type="week" name="weekInput" value="" /><br />\n </fieldset>\n\n <fieldset>\n <legend>Selects <strong>2wB: </strong> <span>"{singleSelect}"</span> <span>[{multiSelect}]</span></legend>\n\n <label>singleSelect</label>\n <select name="singleSelect">\n <option disabled selected value> -- select -- </option>\n <option value="1">Option 1</option>\n <option value="2">Option 2</option>\n <option value="3">Option 3</option>\n <option value="4">Option 4</option>\n </select><br />\n\n <label>multiSelect</label>\n <select name="multiSelect" multiple="multiple" type="select-multiple">\n <option value="1">Option 1</option>\n <option value="2" selected=true>Option 2</option>\n <option value="3">Option 3</option>\n <option value="4" selected=true>Option 4</option>\n </select>\n\n </fieldset>\n\n <fieldset>\n <legend>Radiobuttons <strong>2wB: </strong><span>"{myRadio}"</span></legend>\n\n <label>radio1</label><input type="radio" name="myRadio" value="radio1"><br />\n <label>radio2</label><input type="radio" name="myRadio" value="radio2"><br />\n <label>radio3</label><input type="radio" name="myRadio" value="radio3"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>Checkboxes</legend>\n <label>cb1</label><input type="checkbox" name="cb1"><br />\n <label>cb2</label><input type="checkbox" name="cb2"><br />\n <label>cb3</label><input type="checkbox" name="cb3"><br />\n <label>cb4</label><input type="checkbox" name="cb4"><br />\n <label>cb5</label><input type="checkbox" name="cb5"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>TextArea</legend>\n <label>textArea</label>\n <textarea name="textArea">abc</textarea>\n </fieldset>\n\n </form>\n '}get css(){return'\nlegend {\n display: inherit;\n margin: inherit;\n vertical-align: inherit;\n font-weight: bold;\n}\n\nlabel {\n display: inline-block;\n margin-top: 1em;\n margin-left: 5px;\n vertical-align: top;\n min-width:10em;\n text-align: right;\n}\n\nform input,\nform select,\nform textarea {\n display: inline-block;\n margin-left: 5px;\n margin-top: 1.1em;\n}\n\ninput[type="radio"],\ninput[type="checkbox"] {\n margin-top: 1.3em;\n}\n\nbody > form {\n display: block;\n}\n\nform fieldset {\n border: 1px solid #aaaaaa;\n border-radius: 3px;\n margin: 0.5em 0;\n}\n '}}),{}})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TestTestform=t():e.TestTestform=t()}(self,(()=>(()=>{"use strict";var e=new Function("try {return this===window;}catch(e){ return false;}");function t(e,t){let n=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const a=e?._mc;!t&&a?n=n.concat(Object.values(e._mc)):t&&a&&a[t]&&n.push(a[t])}})),n}function n(e,t,n=!0){let a=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&a.push(e._mc[t]):a=a.concat(Object.values(e._mc)),n))return a;e=e.parentNode}return a}function a(e){return e&&e instanceof HTMLElement}function l(e,t,n={}){let a=e;if(!a._mc){let t=u?.debug;u.debug=!1,a._mc=new u(e),u.debug=t,delete a._mc._mc}const l=a._mc;return t.length&&!l[t]&&(l[t]=n,e instanceof HTMLElement&&!e.getAttribute("data-mc")&&e.setAttribute("data-mc","")),n}function r(e,t){if(!t)return;const n=e?._mc||{};n&&n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute("data-mc")&&e.removeAttribute("data-mc")}function o(e){return"_mc"+e[0].toUpperCase()+e.substring(1)}function s(e,t,n,a=!1){e.addEventListener(o(t),n,{capture:!1,once:a})}function i(e,t,n={},a="l"){const l="string"==typeof t?new CustomEvent(o(t),{detail:{data:n,bubble:a}}):t;a.length&&a.indexOf("l")>-1&&e.dispatchEvent(l),/[u|d]/.test(a)&&function(e,t){setTimeout((()=>{-1===t.detail.bubble.indexOf("l")&&(t.detail.bubble+="l"),t.detail.bubble.indexOf("u")>-1&&e.closest("[data-mc]")?.dispatchEvent(t),t.detail.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&u.trigger(e,t)}))}),0)}(e,l)}class c{_target;constructor(t,n=!1){var a;this._target=new WeakRef(t||{}),(a=this).constructor!==u&&setTimeout((()=>{a.trigger("Init")}),0),function(t){if(!e()||t.constructor===u)return;const n=t.target;if(n instanceof HTMLElement){let e=t;Object.getOwnPropertyNames(e.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof e.constructor.prototype[t])).forEach((t=>{let a=/^one/.test(t),l=t.replace(/^on[e]{0,1}/,""),r=l.toLowerCase(),o=n=>{e[t](n)};n["on"+r]?n.addEventListener(r,o):s(n,l,o,a)}))}}(this)}get target(){return this._target.deref()}}class u extends c{constructor(e,t=!1){super(e)}static add=l;static remove=r;static trigger=i;off(e,t){!function(e,t,n){e.removeEventListener(o(t),n)}(this.target,e,t)}on(e,t){s(this.target,e,t)}one(e,t){!function(e,t,n){s(e,t,n,!0)}(this.target,e,t)}trigger(e,t={},n="l"){}parent(e=""){let t=this.target;return a(t)?n(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return a(t)?n(this.target.parentNode,e,!1):[]}children(e=""){let n=this?.target;return a(n)?t([...function(e){const t=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+t+'"] [data-mc] [data-mc])';e.setAttribute("temp_id",t);const a=e.querySelectorAll(n);return e.removeAttribute("temp_id"),a}(n)],e):[]}descendants(e=""){let n=this?.target;return a(n)?t([...n.querySelectorAll("*[data-mc]")],e):[]}}function p(e){let t={};return[...Object.keys(e)].sort().forEach((n=>{var a;(a=e[n])&&a.constructor&&a.constructor===Object?t[n]=p(e[n]):t[n]=e[n]})),t}function d(e,t=!0){let n={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const a=d(e[t],!1);for(const e in a)n[t+"."+e]=a[e]}else n[t]=e[t]})),t?p(n):n}function b(e,t){return JSON.stringify(d(e))===JSON.stringify(d(t))}function m(e,t){let n;return()=>{clearTimeout(n),n=setTimeout((function(){e(...arguments)}),t)}}function f(e,t){const n=Object.getOwnPropertyDescriptors(e);for(const[e,a]of Object.entries(n))("get"in a||"set"in a)&&Object.defineProperty(t,e,a)}new Set;class h extends HTMLElement{constructor(){super()}connectedCallback(){this.dispatchEvent(new CustomEvent("_mcConnected"))}connectedMoveCallback(){this.dispatchEvent(new CustomEvent("_mcConnectedMove"))}disconnectedCallback(){this.dispatchEvent(new CustomEvent("_mcDisconnected"))}adoptedCallback(){this.dispatchEvent(new CustomEvent("_mcAdopted"))}attributeChangedCallback(e,t,n){this.dispatchEvent(new CustomEvent("_mcAttributeChanged",{detail:{name:e,oldValue:t,newValue:n}}))}formResetCallback(){this.dispatchEvent(new CustomEvent("_mcFormReset"))}}function g(e){return"function"==typeof e&&/^class\s/.test(Function.prototype.toString.call(e))}function y(e){return null!=e&&"object"==typeof e}function v(e){let t=new Set,n=/\{[^\{\}]*\}/g;return(e.getAttributeNames?e.getAttributeNames():[]).filter((t=>e.getAttribute(t)?.match(n))).forEach((t=>{let a=new Set(e.getAttribute(t)?.match(n));a.forEach((e=>a.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(n))).forEach((e=>{(e.nodeValue||"").match(n).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const O=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class E extends u{data={};oldDisplay="";constructor(e){super(e),v(e).forEach((e=>this.data[e]="")),k(this),this.#e()}#e(){let e=this.target,t=!1;(e.getAttributeNames?e.getAttributeNames():[]).filter((t=>e.getAttribute(t)?.match(/\{[^\{\}]*\}/g))).forEach((t=>{let n=new Set(e.getAttribute(t)?.match(/\{[^\{\}]*\}/g));var a;this.data.observe((a=e.getAttribute(t),l=>{let r=a;n.forEach((e=>{r=r.replace(e,l[e.replace(/[\{\}]/g,"")])})),e.setAttribute(t,r)}))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{t=!0;let a=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((t=>l=>{let r=t;a.forEach((e=>{r=r.replace(e,l[e.replace(/[\{\}]/g,"")])})),this.oldDisplay?e.style=this.oldDisplay:e.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=r})(n.nodeValue)),this.oldDisplay=e.getAttribute("style")||"",t&&!O.includes(e.constructor)&&"FIELDSET"!==e.tagName&&(e.style.display="none")}))}onData(e){let t={};Object.keys(e.detail.data).forEach((n=>{this.data.hasOwnProperty(n)&&(t[n]=e.detail.data[n])})),JSON.stringify(t)!==JSON.stringify(this.data)&&Object.assign(this.data,t)}}const w={};function x(e){let t=e.constructor.name;return w[t]||function(e){const t=e.constructor,n=t.name;let a=class extends t{#t=!0;#n=[];constructor(e){super(e),this.constructor.callbacks=[],y(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}get callbacks(){return this.#n}set callbacks(e){this.#n=e}observe(e){return this.#n.push(e),this}bind(e){if(y(this.valueOf())){!function(e){var t;(t=e,[t].concat([...t.querySelectorAll("*")]).filter((e=>!!v(e).length)).filter((e=>"STYLE"!==e?.tagName)).reverse()).forEach((e=>{e?._mc?._placeholders||u.add(e,"_placeholders",new E(e))}))}(e);const t=[e,...e.querySelectorAll("[data-mc]")].filter((e=>!!e?._mc?._placeholders)),n=function(e){let n=d(e);t.forEach((e=>{e&&i(e,"data",n)}))};this.#n.push(n),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(e){let t=y(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==e&&(this.#t=e),this.#n.forEach((e=>{e(t)})),this}};return w[n]=a,a}(e)}const k=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if(e.hasOwnProperty(t)&&"function"!=typeof e[t]&&!e?.[t]?.constructor?.prototype?.observe){if("_"===t[0]||void 0===e?.[t])return e;let n=e[t],a=new(x(n))(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(y(a.valueOf())){let e=structuredClone(Object.assign({},a));setTimeout(m((function(){b(structuredClone(Object.assign({},a)),e)||a.notify()}),0),0)}return a},set(e){if(typeof e==typeof a.valueOf())if(y(a.valueOf())&&a.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},a));void 0===a?.constructor?.prototype?.observe&&(a=new(x(e))(structuredClone(Object.assign({},e))),f(e,a),a.seal()),Object.assign(a,e),setTimeout(m((function(){b(structuredClone(Object.assign({},a)),t)||a.notify()}),0),0)}else{let t=a.valueOf(),n=a.callbacks;e!==t&&(a=new(x(e))(e),a.callbacks=n,a.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof a.valueOf(),a,"- CANNOT BECOME:",typeof e)}}),e[t]=n}})),e);class A{constructor(e){}}class C extends A{#a;constructor(e){super(e),this.#a=e}get val(){return new FormData(this.#a.form).get(this.#a.name)}set val(e){[...this.#a.form.querySelectorAll(`input[type="radio"][name="${this.#a.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class j extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.checked}set val(e){this.#a.checked=e}}class S extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value}set val(e){this.#a.value=e}}class _ extends A{#a;#l=!1;constructor(e){super(e),this.#a=e,this.#l=e.multiple}get val(){const e=[];return[...this.#a.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#l?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#a.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class N extends A{#a;constructor(e){super(e),this.#a=e}get val(){return this.#a.value||""}set val(e){this.#a.value=e}}return function(e,t,n=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let a=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");g(t.prototype.constructor)&&t.prototype instanceof c?customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(a,class extends h{instance;constructor(e){super();const n=g(t)?new t(this,e):t;u.add(this,a,n)}static get observedAttributes(){return n}})):customElements.define(e,t)}("test-testform",class extends u{data;constructor(e){super(e);let t=this.target.attachShadow({mode:"open"});t.innerHTML=`<style>${this.css}</style>${this.template}`,function(e,t,n){let a=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],n={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let a=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":a=new C(e);break;case"checkbox":a=new j(e);break;default:a=new S(e)}break;case"select":a=new _(e);break;case"textarea":a=new N(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}a&&(u.add(e,t,a),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>a.val,set:e=>{a.val!==e&&(a.val=e)}}))}})),n})(n);e[t]=Object.assign({},a),k(e,t),f(a,e[t]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{e[t].notify()}))}))}(this,"data",t),this.data.bind(t),fetch("./testform.json").then((e=>e.json())).then((e=>{this.data=e}))}get template(){return'\n <form>\n \x3c!-- sample form to start with --\x3e\n <fieldset>\n <legend>Inputs</legend>\n <label>text</label><input type="text" name="textInput" value="Hallo" /> <strong>2wB: </strong>{textInput}<br />\n <label>color</label><input type="color" name="colorInput" value="#000000" /><br />\n <label>date</label><input type="date" name="dateInput" value="" /><br />\n <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" /><br />\n <label>email</label><input type="email" name="email" value="" /><br />\n <label>file</label><input type="file" name="fileInput" value="" /><br />\n <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" /><br />\n <label>month</label><input type="month" name="month" value="" /><br />\n <label>number</label><input type="number" name="number" value="" /><br />\n <label>password</label><input type="password" name="passInput" value="" /><br />\n <label>range</label><input type="range" name="rangeInput" value="" /><br />\n <label>search</label><input type="search" name="searchInput" value="" /><br />\n <label>tel</label><input type="tel" name="telInput" value="" /><br />\n <label>time</label><input type="time" name="timeInput" value="" /><br />\n <label>url</label><input type="url" name="urlInput" value="" /><br />\n <label>week</label><input type="week" name="weekInput" value="" /><br />\n </fieldset>\n\n <fieldset>\n <legend>Selects <strong>2wB: </strong> <span>"{singleSelect}"</span> <span>[{multiSelect}]</span></legend>\n\n <label>singleSelect</label>\n <select name="singleSelect">\n <option disabled selected value> -- select -- </option>\n <option value="1">Option 1</option>\n <option value="2">Option 2</option>\n <option value="3">Option 3</option>\n <option value="4">Option 4</option>\n </select><br />\n\n <label>multiSelect</label>\n <select name="multiSelect" multiple="multiple" type="select-multiple">\n <option value="1">Option 1</option>\n <option value="2" selected=true>Option 2</option>\n <option value="3">Option 3</option>\n <option value="4" selected=true>Option 4</option>\n </select>\n\n </fieldset>\n\n <fieldset>\n <legend>Radiobuttons <strong>2wB: </strong><span>"{myRadio}"</span></legend>\n\n <label>radio1</label><input type="radio" name="myRadio" value="radio1"><br />\n <label>radio2</label><input type="radio" name="myRadio" value="radio2"><br />\n <label>radio3</label><input type="radio" name="myRadio" value="radio3"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>Checkboxes</legend>\n <label>cb1</label><input type="checkbox" name="cb1"><br />\n <label>cb2</label><input type="checkbox" name="cb2"><br />\n <label>cb3</label><input type="checkbox" name="cb3"><br />\n <label>cb4</label><input type="checkbox" name="cb4"><br />\n <label>cb5</label><input type="checkbox" name="cb5"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>TextArea</legend>\n <label>textArea</label>\n <textarea name="textArea">abc</textarea>\n </fieldset>\n\n </form>\n '}get css(){return'\nlegend {\n display: inherit;\n margin: inherit;\n vertical-align: inherit;\n font-weight: bold;\n}\n\nlabel {\n display: inline-block;\n margin-top: 1em;\n margin-left: 5px;\n vertical-align: top;\n min-width:10em;\n text-align: right;\n}\n\nform input,\nform select,\nform textarea {\n display: inline-block;\n margin-left: 5px;\n margin-top: 1.1em;\n}\n\ninput[type="radio"],\ninput[type="checkbox"] {\n margin-top: 1.3em;\n}\n\nbody > form {\n display: block;\n}\n\nform fieldset {\n border: 1px solid #aaaaaa;\n border-radius: 3px;\n margin: 0.5em 0;\n}\n '}}),{}})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"testform.js","sourceRoot":"","sources":["../../../src/test/test/testform.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,
|
|
1
|
+
{"version":3,"file":"testform.js","sourceRoot":"","sources":["../../../src/test/test/testform.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AACb,OAAO,EACH,EAAE,EACF,QAAQ,EAER,UAAU,EAEb,MAAM,0BAA0B,CAAC;AAElC,QAAQ,CACP,eAAe,EAEf,MAAM,QAAS,SAAQ,EAAE;IACxB,IAAI,CAAU;IAEd,YAAY,MAAmB;QAC9B,KAAK,CAAC,MAAM,CAAC,CAAC;QAEd,IAAI,MAAM,GAAI,IAAW,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;QAChE,MAAM,CAAC,SAAS,GAAG,UAAU,IAAI,CAAC,GAAG,WAAW,IAAI,CAAC,QAAQ,EAAE,CAAC;QAEhE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAEhC,IAAI,CAAC,IAAmB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAG9B,KAAK,CAAC,iBAAiB,CAAC;aACnB,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;aACxB,IAAI,CAAE,IAAI,CAAC,EAAE;YACV,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC,CAAC,CAAC;IAEjB,CAAC;IAED,IAAI,QAAQ;QACX,OAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAuEN,CAAC;IACZ,CAAC;IAED,IAAI,GAAG;QACN,OAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aAuCL,CAAC;IACZ,CAAC;CACD,CACD,CAAC"}
|