@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
package/src/elements.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
import { DC } from './MC.js';
|
|
3
|
+
import { DC, McBase } from './MC.js';
|
|
4
4
|
import { kebabToPascal } from './helpers.js';
|
|
5
5
|
|
|
6
6
|
class CeBaseClass extends HTMLElement {
|
|
@@ -9,19 +9,32 @@ class CeBaseClass extends HTMLElement {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
connectedCallback() {
|
|
12
|
-
(
|
|
12
|
+
this.dispatchEvent( new CustomEvent('_mcConnected') );
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
connectedMoveCallback() {
|
|
16
|
+
this.dispatchEvent( new CustomEvent('_mcConnectedMove') );
|
|
13
17
|
}
|
|
14
18
|
|
|
15
19
|
disconnectedCallback() {
|
|
16
|
-
(
|
|
20
|
+
this.dispatchEvent( new CustomEvent('_mcDisconnected') );
|
|
17
21
|
}
|
|
18
22
|
|
|
19
23
|
adoptedCallback() {
|
|
20
|
-
(
|
|
24
|
+
this.dispatchEvent( new CustomEvent('_mcAdopted') );
|
|
21
25
|
}
|
|
22
26
|
|
|
23
27
|
attributeChangedCallback(name: string, oldValue: any, newValue: any) {
|
|
24
|
-
|
|
28
|
+
this.dispatchEvent(
|
|
29
|
+
new CustomEvent(
|
|
30
|
+
'_mcAttributeChanged',
|
|
31
|
+
{ detail: { name, oldValue, newValue } }
|
|
32
|
+
)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
formResetCallback(){
|
|
37
|
+
this.dispatchEvent( new CustomEvent('_mcFormReset') );
|
|
25
38
|
}
|
|
26
39
|
}
|
|
27
40
|
|
|
@@ -32,9 +45,14 @@ function createNamedClass(
|
|
|
32
45
|
return Object.defineProperty(ClassBody, 'name', { value: name });
|
|
33
46
|
}
|
|
34
47
|
|
|
48
|
+
function isClass(func: any) {
|
|
49
|
+
return typeof func === 'function'
|
|
50
|
+
&& /^class\s/.test(Function.prototype.toString.call(func));
|
|
51
|
+
}
|
|
52
|
+
|
|
35
53
|
export function defineCE(
|
|
36
54
|
tagName: string,
|
|
37
|
-
DefinitionClass: { new (...args: any[]): any },
|
|
55
|
+
DefinitionClass: { new (...args: any[]): any } | Function,
|
|
38
56
|
observedAttributes: string[] = []
|
|
39
57
|
) {
|
|
40
58
|
if (customElements.get(tagName)) {
|
|
@@ -50,6 +68,27 @@ export function defineCE(
|
|
|
50
68
|
|
|
51
69
|
let name = kebabToPascal(tagName);
|
|
52
70
|
|
|
71
|
+
// not a class, but a function
|
|
72
|
+
if ( !isClass( DefinitionClass.prototype.constructor ) ){
|
|
73
|
+
customElements.define(
|
|
74
|
+
tagName,
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
DefinitionClass
|
|
77
|
+
);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// a class, but not a MC
|
|
82
|
+
if ( !( DefinitionClass.prototype instanceof McBase ) ){
|
|
83
|
+
customElements.define(
|
|
84
|
+
tagName,
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
DefinitionClass
|
|
87
|
+
);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// a MC
|
|
53
92
|
customElements.define(
|
|
54
93
|
tagName,
|
|
55
94
|
createNamedClass(
|
|
@@ -59,7 +98,11 @@ export function defineCE(
|
|
|
59
98
|
|
|
60
99
|
constructor(data?: any) {
|
|
61
100
|
super();
|
|
62
|
-
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
const instance = isClass( DefinitionClass )
|
|
103
|
+
// @ts-ignore
|
|
104
|
+
? new DefinitionClass(this, data)
|
|
105
|
+
: DefinitionClass;
|
|
63
106
|
DC.add(this, name, instance);
|
|
64
107
|
}
|
|
65
108
|
|
package/src/formValues.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
import { LooseObject, copyGettersSetters } from './helpers.js';
|
|
4
|
-
import { DC,
|
|
4
|
+
import { DC, on } from './MC.js';
|
|
5
5
|
import { observe } from './observables.js';
|
|
6
6
|
|
|
7
7
|
type inputTypes = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
@@ -216,8 +216,8 @@ export function formValues(
|
|
|
216
216
|
copyGettersSetters(handlers, targetObject[propertyName]);
|
|
217
217
|
|
|
218
218
|
[...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
|
|
219
|
-
|
|
220
|
-
//console.log('
|
|
219
|
+
input.addEventListener('input', (ev) => {
|
|
220
|
+
//console.log('input event', input, ev);
|
|
221
221
|
targetObject[propertyName].notify();
|
|
222
222
|
});
|
|
223
223
|
});
|
package/src/microcomponents.ts
CHANGED
package/src/observables.ts
CHANGED
|
@@ -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
|
|