@twobirds/microcomponents 0.0.45 → 0.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MC.min.js +7 -56
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.d.ts.map +1 -1
- package/dist/observables.min.js +1 -1
- package/dist/observables.ts +15 -18
- package/dist/test.ts +6 -13
- package/package.json +1 -1
- package/public/MC.js +7 -52
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +7 -56
- package/public/McEvent.js +0 -4
- package/public/McEvent.js.map +1 -1
- package/public/assets/search.js +1 -1
- package/public/autoloader.js +1 -6
- package/public/autoloader.js.map +1 -1
- package/public/classes/MC.DC.html +18 -23
- package/public/classes/MC.MC.html +12 -17
- package/public/classes/MC.McBase.html +4 -4
- package/public/classes/MC.McEvent.html +13 -13
- package/public/formValues.js +3 -19
- package/public/formValues.js.map +1 -1
- package/public/functions/MC.addListener.html +1 -1
- package/public/functions/MC.removeListener.html +1 -1
- package/public/functions/elements.defineCE.html +1 -1
- package/public/functions/elements.getCE.html +1 -1
- package/public/functions/formValues.formValues.html +1 -1
- package/public/functions/observables.observe.html +1 -1
- package/public/functions/selectors._d.html +1 -1
- package/public/functions/selectors._t.html +1 -1
- package/public/helpers.js +4 -5
- package/public/helpers.js.map +1 -1
- package/public/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/interfaces/selectors.DSelector.html +55 -55
- package/public/interfaces/selectors.TSelector.html +37 -37
- package/public/microcomponents.es3.js +15 -61
- package/public/microcomponents.es3.js.map +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/modules/MC.html +1 -1
- package/public/modules/elements.html +1 -1
- package/public/modules/formValues.html +1 -1
- package/public/modules/observables.html +1 -1
- package/public/modules/selectors.html +1 -1
- package/public/observables.js +20 -58
- package/public/observables.js.map +1 -1
- package/public/observables.min.js +1 -1
- package/public/selectors.js +7 -125
- package/public/selectors.js.map +1 -1
- package/public/src/observables.ts +15 -18
- package/public/src/test.ts +6 -13
- package/public/test.js +12 -37
- package/public/test.js.map +1 -1
- package/public/types/observables.Observable.html +1 -1
- package/public/types/selectors.selection.html +1 -1
- package/public/types/selectors.singleSelector.html +1 -1
- package/src/observables.ts +15 -18
- package/src/test.ts +6 -13
- package/tsconfig.json +97 -101
|
@@ -70,17 +70,14 @@ class Placeholders extends DC {
|
|
|
70
70
|
let that = this;
|
|
71
71
|
getPlaceholders(target).forEach((property) => (that.data[property] = ''));
|
|
72
72
|
observe(that);
|
|
73
|
-
that.oldDisplay = target.style.display;
|
|
74
|
-
if (!inputs.includes((target as any).constructor)) {
|
|
75
|
-
target.style.display = 'none';
|
|
76
|
-
}
|
|
77
73
|
that.#attachCallbacks();
|
|
78
74
|
delete that._mc; // cleanup, not needed
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
#attachCallbacks() {
|
|
82
78
|
let that = this,
|
|
83
|
-
target = that.target
|
|
79
|
+
target = that.target,
|
|
80
|
+
hide: boolean = false;
|
|
84
81
|
|
|
85
82
|
// console.log('attachCallbacks', that.target);
|
|
86
83
|
|
|
@@ -120,6 +117,7 @@ class Placeholders extends DC {
|
|
|
120
117
|
);
|
|
121
118
|
})
|
|
122
119
|
.forEach((childNode) => {
|
|
120
|
+
hide = true;
|
|
123
121
|
let phs: Set<string> = new Set(
|
|
124
122
|
childNode.nodeValue.match(/\{[^\{\}]*\}/g)
|
|
125
123
|
);
|
|
@@ -139,12 +137,22 @@ class Placeholders extends DC {
|
|
|
139
137
|
return !!data[key];
|
|
140
138
|
})
|
|
141
139
|
) {
|
|
142
|
-
|
|
140
|
+
if (!!that.oldDisplay) {
|
|
141
|
+
target.style = that.oldDisplay;
|
|
142
|
+
} else {
|
|
143
|
+
target.removeAttribute('style');
|
|
144
|
+
}
|
|
143
145
|
delete that.oldDisplay;
|
|
144
146
|
}
|
|
145
147
|
childNode.nodeValue = result;
|
|
146
148
|
})(childNode.nodeValue)
|
|
147
149
|
);
|
|
150
|
+
|
|
151
|
+
// hide for now
|
|
152
|
+
that.oldDisplay = target.getAttribute('style)') || '';
|
|
153
|
+
if (hide && !inputs.includes((target as any).constructor)) {
|
|
154
|
+
target.style.display = 'none';
|
|
155
|
+
}
|
|
148
156
|
});
|
|
149
157
|
}
|
|
150
158
|
|
|
@@ -226,7 +234,6 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
226
234
|
(this.constructor as LooseObject).callbacks = [];
|
|
227
235
|
if (isObservableObject(val)) {
|
|
228
236
|
// you cannot bind native values to the dom
|
|
229
|
-
(this.constructor as LooseObject).bound = [];
|
|
230
237
|
Object.getOwnPropertyNames(val).forEach((key) => {
|
|
231
238
|
this[key] = val[key];
|
|
232
239
|
});
|
|
@@ -274,18 +281,10 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
274
281
|
that.valueOf() instanceof Array === false
|
|
275
282
|
? structuredClone(Object.assign({}, that))
|
|
276
283
|
: that.valueOf();
|
|
277
|
-
// console.log('notify', that.constructor, (that.constructor as any).callbacks.length, (that.constructor as any)?.bound?.length, data );
|
|
278
284
|
(that.constructor as any).callbacks.forEach((f: Function) => {
|
|
279
285
|
// console.log( 'callback', f, data);
|
|
280
286
|
f(data);
|
|
281
287
|
});
|
|
282
|
-
if (isObservableObject(that.valueOf())) {
|
|
283
|
-
// console.log('bound', this.constructor);
|
|
284
|
-
(that.constructor as any).bound.forEach((f: Function) => {
|
|
285
|
-
// console.log( 'bound', f, data);
|
|
286
|
-
f(data);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
288
|
return this;
|
|
290
289
|
}
|
|
291
290
|
};
|
|
@@ -326,14 +325,12 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
326
325
|
|
|
327
326
|
let hasFormHandler =
|
|
328
327
|
(o.constructor as LooseObject)?.hasFormHandler ?? false,
|
|
329
|
-
callbacks = (o.constructor as LooseObject).callbacks
|
|
330
|
-
bound = (o.constructor as LooseObject).bound;
|
|
328
|
+
callbacks = (o.constructor as LooseObject).callbacks;
|
|
331
329
|
o = new Observable(structuredClone(Object.assign({}, val)));
|
|
332
330
|
|
|
333
331
|
//console.log('after set o=', o, 'check', old);
|
|
334
332
|
(o.constructor as LooseObject).callbacks = hasFormHandler;
|
|
335
333
|
(o.constructor as LooseObject).callbacks = callbacks;
|
|
336
|
-
(o.constructor as LooseObject).bound = bound;
|
|
337
334
|
|
|
338
335
|
setTimeout(
|
|
339
336
|
// check for changes
|
package/public/src/test.ts
CHANGED
|
@@ -42,21 +42,18 @@ class Translator extends DC {
|
|
|
42
42
|
|
|
43
43
|
(that.Translation as Observable).bind(translationTargetObject);
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
that.target.setAttribute('language', 'en');
|
|
46
46
|
|
|
47
|
-
(
|
|
47
|
+
(that.Language as Observable).notify();
|
|
48
48
|
|
|
49
49
|
delete that._mc; // cleanup, not needed
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
onAttributeChanged(ev: McEvent) {
|
|
53
53
|
if (!ev.data.newValue) return;
|
|
54
|
-
|
|
55
|
-
let that = this;
|
|
56
|
-
|
|
57
54
|
switch (ev.data.name) {
|
|
58
55
|
case 'language':
|
|
59
|
-
|
|
56
|
+
this.Language = ev.data.newValue;
|
|
60
57
|
break;
|
|
61
58
|
}
|
|
62
59
|
}
|
|
@@ -110,16 +107,12 @@ defineCE(
|
|
|
110
107
|
(that.Dom as Observable).bind(that.target);
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
onAttributeChanged(ev: McEvent) {
|
|
114
|
-
this.target._mc.translator.Language = ev.data.newValue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
110
|
onClick(ev: McEvent) {
|
|
118
111
|
const that = this,
|
|
119
|
-
c =
|
|
112
|
+
c = that.Dom.counter++;
|
|
120
113
|
(ev.data as PointerEvent).stopPropagation();
|
|
121
|
-
(
|
|
122
|
-
(
|
|
114
|
+
(that.target as HTMLElement).classList.remove('clicked');
|
|
115
|
+
(that.target as HTMLElement).classList.add(
|
|
123
116
|
that.Dom.counter > 9 ? 'overClicked' : 'clicked'
|
|
124
117
|
);
|
|
125
118
|
}
|
package/public/test.js
CHANGED
|
@@ -6,38 +6,32 @@ class Translator extends DC {
|
|
|
6
6
|
Translation = {};
|
|
7
7
|
constructor(target, translations, translationTargetObject) {
|
|
8
8
|
super(target);
|
|
9
|
-
let that = this;
|
|
10
|
-
// state
|
|
9
|
+
let that = this;
|
|
11
10
|
that.Language = 'en';
|
|
12
11
|
that.Translation = {};
|
|
13
12
|
observe(that);
|
|
14
|
-
// setup
|
|
15
13
|
that.#translations = translations;
|
|
16
|
-
// state
|
|
17
14
|
that.Language.observe((lang) => {
|
|
18
15
|
if (that.#translations.hasOwnProperty(lang)) {
|
|
19
|
-
that.Translation = { lang: that.#translations[lang] };
|
|
16
|
+
that.Translation = { lang: that.#translations[lang] };
|
|
20
17
|
}
|
|
21
18
|
});
|
|
22
19
|
that.Translation.bind(translationTargetObject);
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
delete that._mc;
|
|
20
|
+
that.target.setAttribute('language', 'en');
|
|
21
|
+
that.Language.notify();
|
|
22
|
+
delete that._mc;
|
|
26
23
|
}
|
|
27
24
|
onAttributeChanged(ev) {
|
|
28
25
|
if (!ev.data.newValue)
|
|
29
26
|
return;
|
|
30
|
-
let that = this;
|
|
31
27
|
switch (ev.data.name) {
|
|
32
28
|
case 'language':
|
|
33
|
-
|
|
29
|
+
this.Language = ev.data.newValue;
|
|
34
30
|
break;
|
|
35
31
|
}
|
|
36
32
|
}
|
|
37
33
|
}
|
|
38
|
-
defineCE(
|
|
39
|
-
// equivalent to custom element registry .define()
|
|
40
|
-
'my-tag', class MyTag extends DC {
|
|
34
|
+
defineCE('my-tag', class MyTag extends DC {
|
|
41
35
|
#template = '<button>{lang.click} {counter}</button>';
|
|
42
36
|
#languages = {
|
|
43
37
|
en: {
|
|
@@ -50,55 +44,36 @@ defineCE(
|
|
|
50
44
|
Dom = {};
|
|
51
45
|
constructor(target) {
|
|
52
46
|
super(target);
|
|
53
|
-
let that = this;
|
|
54
|
-
// render
|
|
47
|
+
let that = this;
|
|
55
48
|
target.innerHTML = this.#template;
|
|
56
|
-
// add translator
|
|
57
49
|
DC.add(target, 'translator', new Translator(target, that.#languages, target));
|
|
58
|
-
delete that._mc;
|
|
50
|
+
delete that._mc;
|
|
59
51
|
}
|
|
60
52
|
oneInit(ev) {
|
|
61
53
|
let that = this;
|
|
62
|
-
// state
|
|
63
54
|
that.Dom = { counter: 0 };
|
|
64
|
-
// state: convert all props defined so far into observables
|
|
65
55
|
observe(that);
|
|
66
|
-
// bind Dom to target
|
|
67
56
|
that.Dom.bind(that.target);
|
|
68
57
|
}
|
|
69
|
-
onAttributeChanged(ev) {
|
|
70
|
-
this.target._mc.translator.Language = ev.data.newValue;
|
|
71
|
-
}
|
|
72
58
|
onClick(ev) {
|
|
73
|
-
const that = this, c =
|
|
59
|
+
const that = this, c = that.Dom.counter++;
|
|
74
60
|
ev.data.stopPropagation();
|
|
75
|
-
|
|
76
|
-
|
|
61
|
+
that.target.classList.remove('clicked');
|
|
62
|
+
that.target.classList.add(that.Dom.counter > 9 ? 'overClicked' : 'clicked');
|
|
77
63
|
}
|
|
78
64
|
}, ['language']);
|
|
79
65
|
let MyTag = getCE('my-tag'), fragment = new DocumentFragment();
|
|
80
|
-
/*
|
|
81
|
-
stress test
|
|
82
|
-
*/
|
|
83
66
|
let start = new Date().getTime();
|
|
84
|
-
// create 100 elements
|
|
85
67
|
for (let x = 0; x < 1000; x++) {
|
|
86
68
|
fragment.append(new MyTag());
|
|
87
69
|
}
|
|
88
70
|
let end = new Date().getTime();
|
|
89
|
-
// and put them into the DOM
|
|
90
71
|
document.body.appendChild(fragment);
|
|
91
|
-
//document.querySelectorAll('my-tag').forEach((e) => e.remove());
|
|
92
|
-
/*
|
|
93
|
-
console test
|
|
94
|
-
*/
|
|
95
72
|
setTimeout(() => {
|
|
96
|
-
// console.clear();
|
|
97
73
|
console.log('%c \n\nStress Test:\n\n %cInstancing 1000 web components (3000 classes): %c %s ms.', 'font-weight: bold; color: black;', 'font-weight: normal;', 'font-weight: bold; color: blue;', end - start);
|
|
98
74
|
document.body.appendChild(new MyTag());
|
|
99
75
|
let element = document.querySelector('my-tag');
|
|
100
76
|
console.log("\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s", 'font-weight: bold;', 'font-weight: normal;', element, 'font-weight: bold;', '\n\nLook up code in the debugger: test.js\n\n');
|
|
101
|
-
// will trigger the event on all micro components contained in <my-tag>
|
|
102
77
|
DC.trigger(element, 'doSomething');
|
|
103
78
|
}, 500);
|
|
104
79
|
//# sourceMappingURL=test.js.map
|
package/public/test.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAEN,EAAE,EAEF,QAAQ,EACR,KAAK,EACL,OAAO,GAEP,MAAM,sBAAsB,CAAC;AAE9B,MAAM,UAAW,SAAQ,EAAE;IAC1B,aAAa,GAAgB,EAAE,CAAC;IAEhC,QAAQ,GAAY,IAAI,CAAC;IACzB,WAAW,GAAY,EAAE,CAAC;IAE1B,YACC,MAAmD,EACnD,YAAyB,EACzB,uBAAoC;QAEpC,KAAK,CAAC,MAAqB,CAAC,CAAC;QAC7B,IAAI,IAAI,GAAG,IAAI,CAAC
|
|
1
|
+
{"version":3,"file":"test.js","sourceRoot":"","sources":["../src/test.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;AAEb,OAAO,EAEN,EAAE,EAEF,QAAQ,EACR,KAAK,EACL,OAAO,GAEP,MAAM,sBAAsB,CAAC;AAE9B,MAAM,UAAW,SAAQ,EAAE;IAC1B,aAAa,GAAgB,EAAE,CAAC;IAEhC,QAAQ,GAAY,IAAI,CAAC;IACzB,WAAW,GAAY,EAAE,CAAC;IAE1B,YACC,MAAmD,EACnD,YAAyB,E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AAC;AAGjC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC;IAC/B,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;AAC9B,CAAC;AAED,IAAI,GAAG,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;AAG/B,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAQpC,UAAU,CAAC,GAAG,EAAE;IAGf,OAAO,CAAC,GAAG,CACV,oFAAoF,EACpF,kCAAkC,EAClC,sBAAsB,EACtB,iCAAiC,EACjC,GAAG,GAAG,KAAK,CACX,CAAC;IAEF,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,KAAK,EAAE,CAAC,CAAC;IAEvC,IAAI,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;IAE/C,OAAO,CAAC,GAAG,CACV,mGAAmG,EACnG,oBAAoB,EACpB,sBAAsB,EACtB,OAAO,EACP,oBAAoB,EACpB,+CAA+C,CAC/C,CAAC;IAGF,EAAE,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC;AACpC,CAAC,EAAE,GAAG,CAAC,CAAC"}
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
<h5>cb: <span class="tsd-signature-type">Callback</span></h5></li></ul></div>
|
|
56
56
|
<h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">void</span></h4></li></ul></li></ul></li></ul></div><aside class="tsd-sources">
|
|
57
57
|
<ul>
|
|
58
|
-
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/
|
|
58
|
+
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/b10756d/src/observables.ts#L185">src/observables.ts:185</a></li></ul></aside></div>
|
|
59
59
|
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
|
60
60
|
<div class="tsd-navigation settings">
|
|
61
61
|
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<h1>Type alias selection</h1></div>
|
|
19
19
|
<div class="tsd-signature">selection<span class="tsd-signature-symbol">:</span> <a href="selectors.singleSelector.html" class="tsd-signature-type" data-tsd-kind="Type alias">singleSelector</a><span class="tsd-signature-symbol"> | </span><a href="selectors.singleSelector.html" class="tsd-signature-type" data-tsd-kind="Type alias">singleSelector</a><span class="tsd-signature-symbol">[]</span></div><aside class="tsd-sources">
|
|
20
20
|
<ul>
|
|
21
|
-
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/
|
|
21
|
+
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/b10756d/src/selectors.ts#L1634">src/selectors.ts:1634</a></li></ul></aside></div>
|
|
22
22
|
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
|
23
23
|
<div class="tsd-navigation settings">
|
|
24
24
|
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
<h1>Type alias singleSelector</h1></div>
|
|
19
19
|
<div class="tsd-signature">single<wbr/>Selector<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">ShadowRoot</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">HTMLElement</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">HTMLElement</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">HTMLCollection</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">NodeList</span><span class="tsd-signature-symbol"> | </span><a href="../interfaces/selectors.DSelector.html" class="tsd-signature-type" data-tsd-kind="Interface">DSelector</a><span class="tsd-signature-symbol"> | </span><a href="../classes/MC.MC.html" class="tsd-signature-type" data-tsd-kind="Class">MC</a><span class="tsd-signature-symbol"> | </span><a href="../classes/MC.DC.html" class="tsd-signature-type" data-tsd-kind="Class">DC</a><span class="tsd-signature-symbol"> | </span><a href="../interfaces/selectors.TSelector.html" class="tsd-signature-type" data-tsd-kind="Interface">TSelector</a><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">undefined</span></div><aside class="tsd-sources">
|
|
20
20
|
<ul>
|
|
21
|
-
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/
|
|
21
|
+
<li>Defined in <a href="https://gitlab.com/twoBirds/microcomponents/-/blob/b10756d/src/selectors.ts#L1632">src/selectors.ts:1632</a></li></ul></aside></div>
|
|
22
22
|
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
|
|
23
23
|
<div class="tsd-navigation settings">
|
|
24
24
|
<details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
|
package/src/observables.ts
CHANGED
|
@@ -70,17 +70,14 @@ class Placeholders extends DC {
|
|
|
70
70
|
let that = this;
|
|
71
71
|
getPlaceholders(target).forEach((property) => (that.data[property] = ''));
|
|
72
72
|
observe(that);
|
|
73
|
-
that.oldDisplay = target.style.display;
|
|
74
|
-
if (!inputs.includes((target as any).constructor)) {
|
|
75
|
-
target.style.display = 'none';
|
|
76
|
-
}
|
|
77
73
|
that.#attachCallbacks();
|
|
78
74
|
delete that._mc; // cleanup, not needed
|
|
79
75
|
}
|
|
80
76
|
|
|
81
77
|
#attachCallbacks() {
|
|
82
78
|
let that = this,
|
|
83
|
-
target = that.target
|
|
79
|
+
target = that.target,
|
|
80
|
+
hide: boolean = false;
|
|
84
81
|
|
|
85
82
|
// console.log('attachCallbacks', that.target);
|
|
86
83
|
|
|
@@ -120,6 +117,7 @@ class Placeholders extends DC {
|
|
|
120
117
|
);
|
|
121
118
|
})
|
|
122
119
|
.forEach((childNode) => {
|
|
120
|
+
hide = true;
|
|
123
121
|
let phs: Set<string> = new Set(
|
|
124
122
|
childNode.nodeValue.match(/\{[^\{\}]*\}/g)
|
|
125
123
|
);
|
|
@@ -139,12 +137,22 @@ class Placeholders extends DC {
|
|
|
139
137
|
return !!data[key];
|
|
140
138
|
})
|
|
141
139
|
) {
|
|
142
|
-
|
|
140
|
+
if (!!that.oldDisplay) {
|
|
141
|
+
target.style = that.oldDisplay;
|
|
142
|
+
} else {
|
|
143
|
+
target.removeAttribute('style');
|
|
144
|
+
}
|
|
143
145
|
delete that.oldDisplay;
|
|
144
146
|
}
|
|
145
147
|
childNode.nodeValue = result;
|
|
146
148
|
})(childNode.nodeValue)
|
|
147
149
|
);
|
|
150
|
+
|
|
151
|
+
// hide for now
|
|
152
|
+
that.oldDisplay = target.getAttribute('style)') || '';
|
|
153
|
+
if (hide && !inputs.includes((target as any).constructor)) {
|
|
154
|
+
target.style.display = 'none';
|
|
155
|
+
}
|
|
148
156
|
});
|
|
149
157
|
}
|
|
150
158
|
|
|
@@ -226,7 +234,6 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
226
234
|
(this.constructor as LooseObject).callbacks = [];
|
|
227
235
|
if (isObservableObject(val)) {
|
|
228
236
|
// you cannot bind native values to the dom
|
|
229
|
-
(this.constructor as LooseObject).bound = [];
|
|
230
237
|
Object.getOwnPropertyNames(val).forEach((key) => {
|
|
231
238
|
this[key] = val[key];
|
|
232
239
|
});
|
|
@@ -274,18 +281,10 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
274
281
|
that.valueOf() instanceof Array === false
|
|
275
282
|
? structuredClone(Object.assign({}, that))
|
|
276
283
|
: that.valueOf();
|
|
277
|
-
// console.log('notify', that.constructor, (that.constructor as any).callbacks.length, (that.constructor as any)?.bound?.length, data );
|
|
278
284
|
(that.constructor as any).callbacks.forEach((f: Function) => {
|
|
279
285
|
// console.log( 'callback', f, data);
|
|
280
286
|
f(data);
|
|
281
287
|
});
|
|
282
|
-
if (isObservableObject(that.valueOf())) {
|
|
283
|
-
// console.log('bound', this.constructor);
|
|
284
|
-
(that.constructor as any).bound.forEach((f: Function) => {
|
|
285
|
-
// console.log( 'bound', f, data);
|
|
286
|
-
f(data);
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
288
|
return this;
|
|
290
289
|
}
|
|
291
290
|
};
|
|
@@ -326,14 +325,12 @@ export const observe = (target: LooseObject, propertyName?: string) => {
|
|
|
326
325
|
|
|
327
326
|
let hasFormHandler =
|
|
328
327
|
(o.constructor as LooseObject)?.hasFormHandler ?? false,
|
|
329
|
-
callbacks = (o.constructor as LooseObject).callbacks
|
|
330
|
-
bound = (o.constructor as LooseObject).bound;
|
|
328
|
+
callbacks = (o.constructor as LooseObject).callbacks;
|
|
331
329
|
o = new Observable(structuredClone(Object.assign({}, val)));
|
|
332
330
|
|
|
333
331
|
//console.log('after set o=', o, 'check', old);
|
|
334
332
|
(o.constructor as LooseObject).callbacks = hasFormHandler;
|
|
335
333
|
(o.constructor as LooseObject).callbacks = callbacks;
|
|
336
|
-
(o.constructor as LooseObject).bound = bound;
|
|
337
334
|
|
|
338
335
|
setTimeout(
|
|
339
336
|
// check for changes
|
package/src/test.ts
CHANGED
|
@@ -42,21 +42,18 @@ class Translator extends DC {
|
|
|
42
42
|
|
|
43
43
|
(that.Translation as Observable).bind(translationTargetObject);
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
that.target.setAttribute('language', 'en');
|
|
46
46
|
|
|
47
|
-
(
|
|
47
|
+
(that.Language as Observable).notify();
|
|
48
48
|
|
|
49
49
|
delete that._mc; // cleanup, not needed
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
onAttributeChanged(ev: McEvent) {
|
|
53
53
|
if (!ev.data.newValue) return;
|
|
54
|
-
|
|
55
|
-
let that = this;
|
|
56
|
-
|
|
57
54
|
switch (ev.data.name) {
|
|
58
55
|
case 'language':
|
|
59
|
-
|
|
56
|
+
this.Language = ev.data.newValue;
|
|
60
57
|
break;
|
|
61
58
|
}
|
|
62
59
|
}
|
|
@@ -110,16 +107,12 @@ defineCE(
|
|
|
110
107
|
(that.Dom as Observable).bind(that.target);
|
|
111
108
|
}
|
|
112
109
|
|
|
113
|
-
onAttributeChanged(ev: McEvent) {
|
|
114
|
-
this.target._mc.translator.Language = ev.data.newValue;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
110
|
onClick(ev: McEvent) {
|
|
118
111
|
const that = this,
|
|
119
|
-
c =
|
|
112
|
+
c = that.Dom.counter++;
|
|
120
113
|
(ev.data as PointerEvent).stopPropagation();
|
|
121
|
-
(
|
|
122
|
-
(
|
|
114
|
+
(that.target as HTMLElement).classList.remove('clicked');
|
|
115
|
+
(that.target as HTMLElement).classList.add(
|
|
123
116
|
that.Dom.counter > 9 ? 'overClicked' : 'clicked'
|
|
124
117
|
);
|
|
125
118
|
}
|