@twobirds/microcomponents 0.1.1 → 0.1.3
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.d.ts +0 -1
- package/dist/MC.js +6 -5
- package/dist/MC.min.js +39 -56
- package/dist/MC.ts +6 -4
- package/dist/elements.d.ts +0 -1
- package/dist/elements.js +0 -1
- package/dist/elements.min.js +1 -1
- package/dist/formValues.d.ts +0 -1
- package/dist/formValues.js +0 -1
- package/dist/formValues.min.js +1 -1
- package/dist/helpers.d.ts +0 -1
- package/dist/helpers.js +0 -1
- package/dist/microcomponents.d.ts +0 -1
- package/dist/microcomponents.js +0 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.d.ts +0 -1
- package/dist/observables.js +0 -1
- package/dist/observables.min.js +1 -1
- package/package.json +10 -2
- package/.gitlab-ci.yml +0 -18
- package/.vscode/settings.json +0 -3
- package/MicroComponents.svg +0 -15
- package/assets/documentation/MC.md +0 -547
- package/assets/documentation/MicroComponents.svg +0 -15
- package/assets/documentation/ajaxian-1.png +0 -0
- package/assets/documentation/ajaxian-2.png +0 -0
- package/assets/documentation/ajaxian-3.png +0 -0
- package/assets/documentation/elements.md +0 -277
- package/assets/documentation/formvalues.md +0 -25
- package/assets/documentation/functional_requirements.md +0 -8
- package/assets/documentation/history.md +0 -436
- package/assets/documentation/klemmstein.png +0 -0
- package/assets/documentation/magic.md +0 -29
- package/assets/documentation/observables.md +0 -187
- package/assets/documentation/rnd0023-1.jpg +0 -0
- package/assets/documentation/rnd0023-2.jpg +0 -0
- package/assets/documentation/rnd0023-3.jpg +0 -0
- package/assets/documentation/tB_react.md +0 -207
- package/assets/documentation/usage.md +0 -142
- package/assets/documentation/why.md +0 -25
- package/assets/fiddle/MicroComponents.svg +0 -15
- package/assets/fiddle/fiddle.css +0 -0
- package/assets/fiddle/fiddle.js +0 -0
- package/assets/fiddle/index.html +0 -0
- package/assets/test/MicroComponents.svg +0 -15
- package/assets/test/grandparent.css +0 -16
- package/assets/test/myButton.css +0 -19
- package/assets/test/style.css +0 -8
- package/assets/test/test.html +0 -29
- package/assets/test/testform.json +0 -27
- package/dist/MC.d.ts.map +0 -1
- package/dist/elements.d.ts.map +0 -1
- package/dist/formValues.d.ts.map +0 -1
- package/dist/helpers.d.ts.map +0 -1
- package/dist/microcomponents.d.ts.map +0 -1
- package/dist/observables.d.ts.map +0 -1
- package/public/.nojekyll +0 -1
- package/public/MC.d.ts +0 -39
- package/public/MC.d.ts.map +0 -1
- package/public/MC.js +0 -287
- package/public/MC.js.map +0 -1
- package/public/MC.min.js +0 -348
- package/public/MC.ts +0 -431
- package/public/MicroComponents.svg +0 -15
- package/public/documentation/MC.md +0 -547
- package/public/documentation/MicroComponents.svg +0 -15
- package/public/documentation/ajaxian-1.png +0 -0
- package/public/documentation/ajaxian-2.png +0 -0
- package/public/documentation/ajaxian-3.png +0 -0
- package/public/documentation/elements.md +0 -277
- package/public/documentation/formvalues.md +0 -25
- package/public/documentation/functional_requirements.md +0 -8
- package/public/documentation/history.md +0 -436
- package/public/documentation/klemmstein.png +0 -0
- package/public/documentation/magic.md +0 -29
- package/public/documentation/observables.md +0 -187
- package/public/documentation/rnd0023-1.jpg +0 -0
- package/public/documentation/rnd0023-2.jpg +0 -0
- package/public/documentation/rnd0023-3.jpg +0 -0
- package/public/documentation/tB_react.md +0 -207
- package/public/documentation/usage.md +0 -142
- package/public/documentation/why.md +0 -25
- package/public/elements.d.ts +0 -5
- package/public/elements.d.ts.map +0 -1
- package/public/elements.js +0 -68
- package/public/elements.js.map +0 -1
- package/public/elements.min.js +0 -1
- package/public/elements.ts +0 -119
- package/public/fiddle/MicroComponents.svg +0 -15
- package/public/fiddle/fiddle.css +0 -0
- package/public/fiddle/fiddle.js +0 -0
- package/public/fiddle/index.html +0 -0
- package/public/formValues.d.ts +0 -3
- package/public/formValues.d.ts.map +0 -1
- package/public/formValues.js +0 -162
- package/public/formValues.js.map +0 -1
- package/public/formValues.min.js +0 -1
- package/public/formValues.ts +0 -225
- package/public/helpers.d.ts +0 -14
- package/public/helpers.d.ts.map +0 -1
- package/public/helpers.js +0 -113
- package/public/helpers.js.map +0 -1
- package/public/helpers.ts +0 -149
- package/public/microcomponents.d.ts +0 -6
- package/public/microcomponents.d.ts.map +0 -1
- package/public/microcomponents.js +0 -7
- package/public/microcomponents.js.map +0 -1
- package/public/microcomponents.min.js +0 -1
- package/public/microcomponents.ts +0 -8
- package/public/observables.d.ts +0 -11
- package/public/observables.d.ts.map +0 -1
- package/public/observables.js +0 -244
- package/public/observables.js.map +0 -1
- package/public/observables.min.js +0 -1
- package/public/observables.ts +0 -416
- package/public/selectors._ts +0 -1269
- package/public/src/MC.d.ts +0 -39
- package/public/src/MC.d.ts.map +0 -1
- package/public/src/MC.js +0 -287
- package/public/src/MC.js.map +0 -1
- package/public/src/MC.ts +0 -431
- package/public/src/elements.d.ts +0 -5
- package/public/src/elements.d.ts.map +0 -1
- package/public/src/elements.js +0 -68
- package/public/src/elements.js.map +0 -1
- package/public/src/elements.ts +0 -119
- package/public/src/formValues.d.ts +0 -3
- package/public/src/formValues.d.ts.map +0 -1
- package/public/src/formValues.js +0 -162
- package/public/src/formValues.js.map +0 -1
- package/public/src/formValues.ts +0 -225
- package/public/src/helpers.d.ts +0 -14
- package/public/src/helpers.d.ts.map +0 -1
- package/public/src/helpers.js +0 -113
- package/public/src/helpers.js.map +0 -1
- package/public/src/helpers.ts +0 -149
- package/public/src/microcomponents.d.ts +0 -6
- package/public/src/microcomponents.d.ts.map +0 -1
- package/public/src/microcomponents.js +0 -7
- package/public/src/microcomponents.js.map +0 -1
- package/public/src/microcomponents.ts +0 -8
- package/public/src/observables.d.ts +0 -11
- package/public/src/observables.d.ts.map +0 -1
- package/public/src/observables.js +0 -244
- package/public/src/observables.js.map +0 -1
- package/public/src/observables.ts +0 -416
- package/public/src/selectors._ts +0 -1269
- package/public/src/test/grandparent.css +0 -14
- package/public/src/test/test/child.d.ts +0 -2
- package/public/src/test/test/child.d.ts.map +0 -1
- package/public/src/test/test/child.js +0 -26
- package/public/src/test/test/child.js.map +0 -1
- package/public/src/test/test/child.ts +0 -36
- package/public/src/test/test/grandchild.d.ts +0 -2
- package/public/src/test/test/grandchild.d.ts.map +0 -1
- package/public/src/test/test/grandchild.js +0 -22
- package/public/src/test/test/grandchild.js.map +0 -1
- package/public/src/test/test/grandchild.ts +0 -31
- package/public/src/test/test/grandparent.d.ts +0 -2
- package/public/src/test/test/grandparent.d.ts.map +0 -1
- package/public/src/test/test/grandparent.js +0 -1
- package/public/src/test/test/grandparent.js.map +0 -1
- package/public/src/test/test/grandparent.ts +0 -43
- package/public/src/test/test/greatgrandchild.d.ts +0 -2
- package/public/src/test/test/greatgrandchild.d.ts.map +0 -1
- package/public/src/test/test/greatgrandchild.js +0 -36
- package/public/src/test/test/greatgrandchild.js.map +0 -1
- package/public/src/test/test/greatgrandchild.ts +0 -51
- package/public/src/test/test/parent.d.ts +0 -2
- package/public/src/test/test/parent.d.ts.map +0 -1
- package/public/src/test/test/parent.js +0 -25
- package/public/src/test/test/parent.js.map +0 -1
- package/public/src/test/test/parent.ts +0 -35
- package/public/src/test/test/testform.d.ts +0 -2
- package/public/src/test/test/testform.d.ts.map +0 -1
- package/public/src/test/test/testform.js +0 -1
- package/public/src/test/test/testform.js.map +0 -1
- package/public/src/test/test/testform.ts +0 -153
- package/public/src/test/test/testfunction.d.ts +0 -3
- package/public/src/test/test/testfunction.d.ts.map +0 -1
- package/public/src/test/test/testfunction.js +0 -7
- package/public/src/test/test/testfunction.js.map +0 -1
- package/public/src/test/test/testfunction.ts +0 -12
- package/public/src/test/test/testmc.d.ts +0 -3
- package/public/src/test/test/testmc.d.ts.map +0 -1
- package/public/src/test/test/testmc.js +0 -10
- package/public/src/test/test/testmc.js.map +0 -1
- package/public/src/test/test/testmc.ts +0 -16
- package/public/src/test/test/testsimpleclass.d.ts +0 -3
- package/public/src/test/test/testsimpleclass.d.ts.map +0 -1
- package/public/src/test/test/testsimpleclass.js +0 -9
- package/public/src/test/test/testsimpleclass.js.map +0 -1
- package/public/src/test/test/testsimpleclass.ts +0 -15
- package/public/src/test/test.d.ts +0 -2
- package/public/src/test/test.d.ts.map +0 -1
- package/public/src/test/test.js +0 -72
- package/public/src/test/test.js.map +0 -1
- package/public/src/test/test.ts +0 -176
- package/public/src/test/testform.css +0 -47
- package/public/src/test/testform.html +0 -56
- package/public/src/test/testform.json +0 -27
- package/public/test/MC.d.ts +0 -39
- package/public/test/MC.d.ts.map +0 -1
- package/public/test/MC.js +0 -287
- package/public/test/MC.min.js +0 -348
- package/public/test/MC.ts +0 -431
- package/public/test/MicroComponents.svg +0 -15
- package/public/test/elements.d.ts +0 -5
- package/public/test/elements.d.ts.map +0 -1
- package/public/test/elements.js +0 -68
- package/public/test/elements.min.js +0 -1
- package/public/test/elements.ts +0 -119
- package/public/test/formValues.d.ts +0 -3
- package/public/test/formValues.d.ts.map +0 -1
- package/public/test/formValues.js +0 -162
- package/public/test/formValues.min.js +0 -1
- package/public/test/formValues.ts +0 -225
- package/public/test/grandparent.css +0 -14
- package/public/test/helpers.d.ts +0 -14
- package/public/test/helpers.d.ts.map +0 -1
- package/public/test/helpers.js +0 -113
- package/public/test/helpers.ts +0 -149
- package/public/test/microcomponents.d.ts +0 -6
- package/public/test/microcomponents.d.ts.map +0 -1
- package/public/test/microcomponents.js +0 -7
- package/public/test/microcomponents.min.js +0 -1
- package/public/test/microcomponents.ts +0 -8
- package/public/test/myButton.css +0 -19
- package/public/test/observables.d.ts +0 -11
- package/public/test/observables.d.ts.map +0 -1
- package/public/test/observables.js +0 -244
- package/public/test/observables.min.js +0 -1
- package/public/test/observables.ts +0 -416
- package/public/test/style.css +0 -8
- package/public/test/test/child.d.ts +0 -2
- package/public/test/test/child.d.ts.map +0 -1
- package/public/test/test/child.js +0 -26
- package/public/test/test/child.js.map +0 -1
- package/public/test/test/child.ts +0 -36
- package/public/test/test/grandchild.d.ts +0 -2
- package/public/test/test/grandchild.d.ts.map +0 -1
- package/public/test/test/grandchild.js +0 -22
- package/public/test/test/grandchild.js.map +0 -1
- package/public/test/test/grandchild.ts +0 -31
- package/public/test/test/grandparent.d.ts +0 -2
- package/public/test/test/grandparent.d.ts.map +0 -1
- package/public/test/test/grandparent.js +0 -1
- package/public/test/test/grandparent.js.map +0 -1
- package/public/test/test/grandparent.ts +0 -43
- package/public/test/test/greatgrandchild.d.ts +0 -2
- package/public/test/test/greatgrandchild.d.ts.map +0 -1
- package/public/test/test/greatgrandchild.js +0 -36
- package/public/test/test/greatgrandchild.js.map +0 -1
- package/public/test/test/greatgrandchild.ts +0 -51
- package/public/test/test/parent.d.ts +0 -2
- package/public/test/test/parent.d.ts.map +0 -1
- package/public/test/test/parent.js +0 -25
- package/public/test/test/parent.js.map +0 -1
- package/public/test/test/parent.ts +0 -35
- package/public/test/test/testform.d.ts +0 -2
- package/public/test/test/testform.d.ts.map +0 -1
- package/public/test/test/testform.js +0 -1
- package/public/test/test/testform.js.map +0 -1
- package/public/test/test/testform.ts +0 -153
- package/public/test/test/testfunction.d.ts +0 -3
- package/public/test/test/testfunction.d.ts.map +0 -1
- package/public/test/test/testfunction.js +0 -7
- package/public/test/test/testfunction.js.map +0 -1
- package/public/test/test/testfunction.ts +0 -12
- package/public/test/test/testmc.d.ts +0 -3
- package/public/test/test/testmc.d.ts.map +0 -1
- package/public/test/test/testmc.js +0 -10
- package/public/test/test/testmc.js.map +0 -1
- package/public/test/test/testmc.ts +0 -16
- package/public/test/test/testsimpleclass.d.ts +0 -3
- package/public/test/test/testsimpleclass.d.ts.map +0 -1
- package/public/test/test/testsimpleclass.js +0 -9
- package/public/test/test/testsimpleclass.js.map +0 -1
- package/public/test/test/testsimpleclass.ts +0 -15
- package/public/test/test.d.ts +0 -2
- package/public/test/test.d.ts.map +0 -1
- package/public/test/test.html +0 -29
- package/public/test/test.js +0 -72
- package/public/test/test.js.map +0 -1
- package/public/test/test.ts +0 -176
- package/public/test/testform.css +0 -47
- package/public/test/testform.html +0 -56
- package/public/test/testform.json +0 -27
- package/public/typedoc/.nojekyll +0 -1
- package/public/typedoc/assets/highlight.css +0 -106
- package/public/typedoc/assets/icons.js +0 -18
- package/public/typedoc/assets/icons.svg +0 -1
- package/public/typedoc/assets/main.js +0 -60
- package/public/typedoc/assets/navigation.js +0 -1
- package/public/typedoc/assets/search.js +0 -1
- package/public/typedoc/assets/style.css +0 -1493
- package/public/typedoc/classes/MC.DC.html +0 -13
- package/public/typedoc/classes/MC.MC.html +0 -3
- package/public/typedoc/classes/MC.McBase.html +0 -3
- package/public/typedoc/functions/MC.autoload.html +0 -1
- package/public/typedoc/functions/MC.off.html +0 -1
- package/public/typedoc/functions/MC.on.html +0 -1
- package/public/typedoc/functions/MC.one.html +0 -1
- package/public/typedoc/functions/MC.trigger.html +0 -1
- package/public/typedoc/functions/elements.defineCE.html +0 -1
- package/public/typedoc/functions/elements.getCE.html +0 -1
- package/public/typedoc/functions/formValues.formValues.html +0 -1
- package/public/typedoc/functions/observables.observe.html +0 -1
- package/public/typedoc/hierarchy.html +0 -1
- package/public/typedoc/index.html +0 -122
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +0 -758
- package/public/typedoc/media/MicroComponents.svg +0 -15
- package/public/typedoc/modules/MC.html +0 -10
- package/public/typedoc/modules/elements.html +0 -3
- package/public/typedoc/modules/formValues.html +0 -2
- package/public/typedoc/modules/observables.html +0 -3
- package/public/typedoc/modules.html +0 -5
- package/public/typedoc/types/observables.Observable.html +0 -1
- package/src/MC.ts +0 -431
- package/src/elements.ts +0 -119
- package/src/formValues.ts +0 -225
- package/src/helpers.ts +0 -149
- package/src/microcomponents.ts +0 -8
- package/src/observables.ts +0 -416
- package/src/selectors._ts +0 -1269
- package/src/test/grandparent.css +0 -14
- package/src/test/test/child.ts +0 -36
- package/src/test/test/grandchild.ts +0 -31
- package/src/test/test/grandparent.ts +0 -43
- package/src/test/test/greatgrandchild.ts +0 -51
- package/src/test/test/parent.ts +0 -35
- package/src/test/test/testform.ts +0 -153
- package/src/test/test/testfunction.ts +0 -12
- package/src/test/test/testmc.ts +0 -16
- package/src/test/test/testsimpleclass.ts +0 -15
- package/src/test/test.ts +0 -176
- package/src/test/testform.css +0 -47
- package/src/test/testform.html +0 -56
- package/src/test/testform.json +0 -27
- package/tasks.md +0 -36
- package/tsconfig.json +0 -107
- package/typedoc.json +0 -7
- package/webpack.config.js +0 -346
package/public/test/helpers.ts
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
export interface LooseObject {
|
|
4
|
-
[key: string | symbol]: any;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function isNativeObject(value: any): boolean {
|
|
8
|
-
return value && value['constructor'] && value.constructor === Object;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function sortObject(o: LooseObject): LooseObject {
|
|
12
|
-
let result: LooseObject = {},
|
|
13
|
-
keys = [...Object.keys(o)].sort();
|
|
14
|
-
|
|
15
|
-
keys.forEach((key) => {
|
|
16
|
-
if (isNativeObject(o[key])) {
|
|
17
|
-
result[key] = sortObject(o[key]);
|
|
18
|
-
} else {
|
|
19
|
-
result[key] = o[key];
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function flattenObject(
|
|
27
|
-
o: LooseObject,
|
|
28
|
-
doSort: boolean = true
|
|
29
|
-
): LooseObject {
|
|
30
|
-
let result: LooseObject = {};
|
|
31
|
-
|
|
32
|
-
[...Object.getOwnPropertyNames(o)].forEach((propName) => {
|
|
33
|
-
if (
|
|
34
|
-
o[propName] &&
|
|
35
|
-
o[propName]['constructor'] &&
|
|
36
|
-
o[propName].constructor === Object
|
|
37
|
-
) {
|
|
38
|
-
const temp = flattenObject(o[propName], false);
|
|
39
|
-
for (const j in temp) {
|
|
40
|
-
result[propName + '.' + j] = temp[j];
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
result[propName] = o[propName];
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
return doSort ? sortObject(result) : result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export function deepEqual(o1: LooseObject, o2: LooseObject): boolean {
|
|
51
|
-
return (
|
|
52
|
-
JSON.stringify(flattenObject(o1)) === JSON.stringify(flattenObject(o2))
|
|
53
|
-
);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function nameSpace(ns: string | string[], obj: LooseObject = {}): any {
|
|
57
|
-
let nsa = ns.constructor === String ? ns.split('.') : ns;
|
|
58
|
-
|
|
59
|
-
if (!obj || !nsa[0] || !obj[nsa[0]]) {
|
|
60
|
-
console.warn('ns', nsa[0], 'not in', obj);
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
if (obj[nsa[0]].constructor === Object && nsa.length > 1) {
|
|
64
|
-
return nameSpace((nsa as string[]).splice(1), obj[nsa[0]]);
|
|
65
|
-
}
|
|
66
|
-
return obj[nsa[0]];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function parse(what: string | Object | any[], parseThis: Object) {
|
|
70
|
-
var args = Array.from(arguments);
|
|
71
|
-
|
|
72
|
-
if (args.length > 2) {
|
|
73
|
-
while (args.length > 1) {
|
|
74
|
-
args[0] = parse(args[0], args[1]);
|
|
75
|
-
args.splice(1, 1);
|
|
76
|
-
}
|
|
77
|
-
return args[0];
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (typeof what === 'string') {
|
|
81
|
-
what.match(/\{[^\{\}]*\}/g)?.forEach(function (pPropname) {
|
|
82
|
-
var propname = pPropname.substring(1, pPropname.length - 1),
|
|
83
|
-
value = nameSpace(propname, parseThis);
|
|
84
|
-
//console.log(propname, value);
|
|
85
|
-
if (typeof value !== 'undefined') {
|
|
86
|
-
what = (what as string).replace(pPropname, value);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
} else if (isNativeObject(what)) {
|
|
90
|
-
switch (what.constructor) {
|
|
91
|
-
case Object:
|
|
92
|
-
Object.keys(what).forEach(function (pKey) {
|
|
93
|
-
if (what.hasOwnProperty(pKey)) {
|
|
94
|
-
(what as LooseObject)[pKey] = parse(
|
|
95
|
-
(what as LooseObject)[pKey],
|
|
96
|
-
parseThis
|
|
97
|
-
);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
break;
|
|
101
|
-
case Array:
|
|
102
|
-
(what as Array<any>).forEach(function (pValue, pKey, original) {
|
|
103
|
-
original[pKey] = parse((what as any)[pKey], parseThis);
|
|
104
|
-
});
|
|
105
|
-
break;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return what;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export function kebabToPascal(str: string) {
|
|
113
|
-
return str
|
|
114
|
-
.split('-') // Split by hyphens
|
|
115
|
-
.map((word) => word.charAt(0).toUpperCase() + word.slice(1)) // Capitalize each part
|
|
116
|
-
.join(''); // Join without spaces
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export function debounce(func: Function, milliseconds: number): Function {
|
|
120
|
-
let timeout: any;
|
|
121
|
-
return () => {
|
|
122
|
-
clearTimeout(timeout);
|
|
123
|
-
|
|
124
|
-
timeout = setTimeout(function () {
|
|
125
|
-
func(...arguments);
|
|
126
|
-
}, milliseconds);
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export function htmlToElements(html: string): HTMLElement[] {
|
|
131
|
-
let template = document.createElement('template');
|
|
132
|
-
|
|
133
|
-
html = html.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi, '<$1$2></$1>'); // replace XHTML closing tags by full closing tags
|
|
134
|
-
|
|
135
|
-
template.innerHTML = html;
|
|
136
|
-
|
|
137
|
-
template.content.normalize();
|
|
138
|
-
|
|
139
|
-
return Array.from(template.content.childNodes) as HTMLElement[];
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function copyGettersSetters(source: LooseObject, target: LooseObject) {
|
|
143
|
-
const descriptors = Object.getOwnPropertyDescriptors(source);
|
|
144
|
-
for (const [key, descriptor] of Object.entries(descriptors)) {
|
|
145
|
-
if ('get' in descriptor || 'set' in descriptor) {
|
|
146
|
-
Object.defineProperty(target, key, descriptor);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"microcomponents.d.ts","sourceRoot":"","sources":["../src/microcomponents.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AAExB,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AAEjC,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.microcomponents=e():t.microcomponents=e()}(this,(()=>(()=>{"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={};function n(t){return t&&t.constructor&&t.constructor===Object}function r(t){let e={};return[...Object.keys(t)].sort().forEach((o=>{n(t[o])?e[o]=r(t[o]):e[o]=t[o]})),e}function o(t,e=!0){let n={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=o(t[e],!1);for(const t in r)n[e+"."+t]=r[t]}else n[e]=t[e]})),e?r(n):n}function s(t,e){return JSON.stringify(o(t))===JSON.stringify(o(e))}function c(t,e={}){let n=t.constructor===String?t.split("."):t;if(e&&n[0]&&e[n[0]])return e[n[0]].constructor===Object&&n.length>1?c(n.splice(1),e[n[0]]):e[n[0]];console.warn("ns",n[0],"not in",e)}function a(t,e){var r=Array.from(arguments);if(r.length>2){for(;r.length>1;)r[0]=a(r[0],r[1]),r.splice(1,1);return r[0]}if("string"==typeof t)t.match(/\{[^\{\}]*\}/g)?.forEach((function(n){var r=c(n.substring(1,n.length-1),e);void 0!==r&&(t=t.replace(n,r))}));else if(n(t))switch(t.constructor){case Object:Object.keys(t).forEach((function(n){t.hasOwnProperty(n)&&(t[n]=a(t[n],e))}));break;case Array:t.forEach((function(n,r,o){o[r]=a(t[r],e)}))}return t}function i(t){return t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("")}function l(t,e){let n;return()=>{clearTimeout(n),n=setTimeout((function(){t(...arguments)}),e)}}function u(t){let e=document.createElement("template");return t=t.replace(/<([A-Za-z0-9\-]*)([^>\/]*)(\/>)/gi,"<$1$2></$1>"),e.innerHTML=t,e.content.normalize(),Array.from(e.content.childNodes)}function d(t,e){const n=Object.getOwnPropertyDescriptors(t);for(const[t,r]of Object.entries(n))("get"in r||"set"in r)&&Object.defineProperty(e,t,r)}t.r(e),t.d(e,{DC:()=>w,MC:()=>O,McBase:()=>E,autoload:()=>N,copyGettersSetters:()=>d,debounce:()=>l,deepEqual:()=>s,defineCE:()=>x,flattenObject:()=>o,formValues:()=>U,getCE:()=>M,htmlToElements:()=>u,isNativeObject:()=>n,kebabToPascal:()=>i,nameSpace:()=>c,observe:()=>$,off:()=>p,on:()=>b,one:()=>g,parse:()=>a,sortObject:()=>r,trigger:()=>v});const f=new Function("try {return this===window;}catch(e){ return false;}");function m(t){return t&&t instanceof HTMLElement}function h(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function p(t,e,n){t.removeEventListener(h(e),n)}function b(t,e,n,r=!1){return t.addEventListener(h(e),n,{capture:!1,once:r}),n}function g(t,e,n){return b(t,e,n,!0),n}class y{stopped=!1;constructor(){}stop(){this.stopped=!0}}function v(t,e,n={},r="l",o){const s=/^_mc/.test(e)?e:h(e),c=o||new y,a=new CustomEvent(s,{detail:{data:n,control:c},bubbles:!1});c.stopped||(t.dispatchEvent(a),a.stopImmediatePropagation(),c.stopped||/[ud]/.test(r)&&(-1===r.indexOf("l")&&(r+="l"),setTimeout((()=>{if(r.indexOf("u")>-1){let e=t.parentElement?.closest("[data-mc]");e&&e?._mc.trigger(s,n,r,c)}if(r.indexOf("d")>-1){let e=t._mc.children();e&&e.forEach((t=>t.trigger(s,n,r)))}}),0)))}class E{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==w&&e.trigger("Init")}),0),function(t){if(!f()||t.constructor===w)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}/,""),s=o.toLowerCase();if("on"+s in e){let r=e=>{n[t](e)};e.addEventListener(s,r)}else b(e,o,(e=>{n[t](e)}),r)}))}}(this)}get target(){return this._target.deref()}}class O extends E{constructor(t){super(t)}}class w extends E{constructor(t){super(t)}static add(t,e,n={}){return function(t,e,n={}){let r=t;r._mc||(r._mc=new w(t));const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),r}(t,e,n)}static remove(t,e){!function(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}(t,e)}off(t,e){p(this.target,t,e)}on(t,e){return b(this.target,t,e)}one(t,e){return g(this.target,t,e)}trigger(t,e={},n="l",r){v(this.target,t,e,n,r)}ancestors(){let t=this?.target,e=[];if(!m(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}closest(){let t=this.target;return m(t)&&t.closest("[data-mc]")?._mc||null}children(){let t=this?.target;return m(t)?function(t){const e=Math.random().toString().replace(".",""),n='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const r=[...t.querySelectorAll(n)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),r.length?r:null}(t):null}descendants(){const t=this?.target;if(!m(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}const A=new Set;function j(t){return()=>{const e=Array.from(document.querySelectorAll(`[data-mc*="${t}"]`)).filter((t=>t instanceof HTMLElement));if(0===e.length)return;const n=customElements.get(t);e.forEach((e=>{w.add(e,n.name,new n(e));const r=e.getAttribute("data-mc").split(" ").filter((e=>e!==t&&""!==e)).join(" ").trim();e.setAttribute("data-mc",r)}))}}function C(t){if(A.has(t))return;A.add(t);const e="./"+t.split("-").join("/")+".js",n=document.createElement("script");n.setAttribute("src",e),n.setAttribute("blocking","render"),n.async=!0,n.setAttribute("type","module"),n.setAttribute("data-name",t),n.setAttribute("loading",""),customElements.whenDefined(t).then(j(t)),n.addEventListener("load",(e=>{A.delete(t),document.head.querySelector(`script[data-name="${t}"]`)?.remove()})),n.addEventListener("error",(t=>{console.error("could not load DC code from",e)})),document.head.append(n)}function S(){[...document.querySelectorAll(":not(:defined)")].filter((t=>!!t&&!customElements.get(t.tagName.toLowerCase())&&!A.has(t.tagName.toLowerCase()))).forEach((t=>{C(t.tagName.toLowerCase())})),[...document.querySelectorAll('[data-mc]:not([data-mc=""]')].filter((t=>!!t)).forEach((t=>{const e=t.getAttribute("data-mc")?.split(" ").filter((t=>""!==t));e?.forEach((t=>{const e=customElements.get(t);A.has(t)||e?e&&j(t)():C(t)}))}))}let k=!1,_=null;function N(t=!0){return t?(k=t,_=new MutationObserver(S),setTimeout((()=>{_.observe(document.body,{childList:!0,subtree:!0}),S()}),5),window.autoload=window.autoload||N,k):(_?.disconnect(),_=null,k)}N.state=A;class T 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 L(t){return"function"==typeof t&&/^class\s/.test(Function.prototype.toString.call(t))}function x(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=i(t);L(e.prototype.constructor)&&e.prototype instanceof E?customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends T{instance;constructor(t){super();const n=L(e)?new e(this,t):e;w.add(this,r,n)}static get observedAttributes(){return n}})):customElements.define(t,e)}function M(t){return customElements.get(t)}function P(t){return null!=t&&"object"==typeof t}function D(t){let e=new Set,n=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(n))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(n));r.forEach((t=>r.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(n))).forEach((t=>{(t.nodeValue||"").match(n).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}const q=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class H extends w{data={};oldDisplay="";constructor(t){super(t),D(t).forEach((t=>this.data[t]="")),$(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var r;this.data.observe((r=t.getAttribute(e),o=>{let s=r;n.forEach((t=>{s=s.replace(t,o[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,s)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((n=>{e=!0;let r=new Set(n.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>o=>{let s=e;r.forEach((t=>{s=s.replace(t,o[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,n.nodeValue=s})(n.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!q.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((n=>{this.data.hasOwnProperty(n)&&(e[n]=t.detail.data[n])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const I={};function V(t){let e=t.constructor.name;return I[e]||function(t){const e=t.constructor,n=e.name;let r=class extends e{#e=!0;#n=[];constructor(t){super(t),this.constructor.callbacks=[],P(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#n}set callbacks(t){this.#n=t}observe(t){return this.#n.push(t),this}bind(t){if(P(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!D(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||w.add(t,"_placeholders",new H(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),n=function(t){let n=o(t);e.forEach((t=>{t&&v(t,"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(t){let e=P(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#n.forEach((t=>{t(e)})),this}};return I[n]=r,r}(t)}const $=(t,e)=>((e?[e]:[...Object.getOwnPropertyNames(t)]).forEach((e=>{if(t.hasOwnProperty(e)&&"function"!=typeof t[e]&&!t?.[e]?.constructor?.prototype?.observe){if("_"===e[0]||void 0===t?.[e])return t;let n=t[e],r=new(V(n))(n);Object.defineProperty(t,e,{enumerable:!0,get(){if(P(r.valueOf())){let t=structuredClone(Object.assign({},r));setTimeout(l((function(){s(structuredClone(Object.assign({},r)),t)||r.notify()}),0),0)}return r},set(t){if(typeof t==typeof r.valueOf())if(P(r.valueOf())&&r.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},r));void 0===r?.constructor?.prototype?.observe&&(r=new(V(t))(structuredClone(Object.assign({},t))),d(t,r),r.seal()),Object.assign(r,t),setTimeout(l((function(){s(structuredClone(Object.assign({},r)),e)||r.notify()}),0),0)}else{let e=r.valueOf(),n=r.callbacks;t!==e&&(r=new(V(t))(t),r.callbacks=n,r.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof r.valueOf(),r,"- CANNOT BECOME:",typeof t)}}),t[e]=n}})),t);class R{constructor(t){}}class F extends R{#r;constructor(t){super(t),this.#r=t}get val(){return new FormData(this.#r.form).get(this.#r.name)}set val(t){[...this.#r.form.querySelectorAll(`input[type="radio"][name="${this.#r.name}"]`)].filter((e=>e.getAttribute("value")===t)).shift().checked=!0}}class G extends R{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.checked}set val(t){this.#r.checked=t}}class J extends R{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value}set val(t){this.#r.value=t}}class Z extends R{#r;#o=!1;constructor(t){super(t),this.#r=t,this.#o=t.multiple}get val(){const t=[];return[...this.#r.querySelectorAll("option")].filter((t=>t.selected)).forEach((e=>{t.push(e.value)})),this.#o?t:t.length?t[0]:""}set val(t){t="string"==typeof t?[t]:t,[...this.#r.querySelectorAll("option")].forEach((e=>{t.indexOf(e.value)>-1?e.selected=!0:e.selected=!1}))}}class z extends R{#r;constructor(t){super(t),this.#r=t}get val(){return this.#r.value||""}set val(t){this.#r.value=t}}const B=t=>{let e=[...(t||document).querySelectorAll("input,select,textarea")],n={};return e.forEach((t=>{const e=t.getAttribute("name");if(e){let r=!1;switch((t=>t.tagName.toLowerCase())(t)){case"input":switch(t.type){case"radio":r=new F(t);break;case"checkbox":r=new G(t);break;default:r=new J(t)}break;case"select":r=new Z(t);break;case"textarea":r=new z(t);break;default:console.warn("handler missing:",e,"for",t.tagName.toLowerCase(),t)}r&&(w.add(t,e,r),Object.defineProperty(n,e,{enumerable:!0,configurable:!0,get:()=>r.val,set:t=>{r.val!==t&&(r.val=t)}}))}})),n};function U(t,e,n){let r=B(n);t[e]=Object.assign({},r),$(t,e),d(r,t[e]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{n.addEventListener("input",(n=>{t[e].notify()}))}))}return e})()));
|
package/public/test/myButton.css
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
button.myButton {
|
|
2
|
-
border: 2px solid gray;
|
|
3
|
-
margin: 3px;
|
|
4
|
-
padding: 2px 5px;
|
|
5
|
-
display: inline-block;
|
|
6
|
-
width: 8em;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
button.myButton.clicked {
|
|
10
|
-
border-color: blue;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
button.myButton.overClicked {
|
|
14
|
-
border-color: orange;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
button.myButton:hover {
|
|
18
|
-
border-color: red;
|
|
19
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { LooseObject } from './helpers.js';
|
|
2
|
-
type Callback = (value: any) => void;
|
|
3
|
-
export type Observable = {
|
|
4
|
-
observe: (cb: Callback) => void;
|
|
5
|
-
notify: () => void;
|
|
6
|
-
bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
|
|
7
|
-
callbacks: Array<Function>;
|
|
8
|
-
};
|
|
9
|
-
export declare const observe: (target: LooseObject, propertyName?: string) => LooseObject;
|
|
10
|
-
export {};
|
|
11
|
-
//# sourceMappingURL=observables.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"observables.d.ts","sourceRoot":"","sources":["../src/observables.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,WAAW,EAKX,MAAM,cAAc,CAAC;AAQtB,KAAK,QAAQ,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,IAAI,CAAC;AAuKrC,MAAM,MAAM,UAAU,GAAG;IACxB,OAAO,EAAE,CAAC,EAAE,EAAE,QAAQ,KAAK,IAAI,CAAC;IAChC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,IAAI,EAAE,CAAC,MAAM,EAAE,WAAW,GAAG,gBAAgB,GAAG,UAAU,KAAM,IAAI,CAAC;IACrE,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAC;CAC3B,CAAC;AAyHF,eAAO,MAAM,OAAO,WACX,WAAW,iBACJ,MAAM,KACnB,WAuGF,CAAC"}
|
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
import { debounce, deepEqual, flattenObject, copyGettersSetters, } from './helpers.js';
|
|
3
|
-
import { DC, trigger } from './MC.js';
|
|
4
|
-
function isObservableObject(value) {
|
|
5
|
-
return value != null && typeof value === 'object';
|
|
6
|
-
}
|
|
7
|
-
function getPlaceholders(target) {
|
|
8
|
-
let placeholders = new Set(), regEx = /\{[^\{\}]*\}/g;
|
|
9
|
-
(!!target.getAttributeNames ? target.getAttributeNames() : [])
|
|
10
|
-
.filter((attr) => target.getAttribute(attr)?.match(regEx))
|
|
11
|
-
.forEach((attr) => {
|
|
12
|
-
let placeholders = new Set(target.getAttribute(attr)?.match(regEx));
|
|
13
|
-
placeholders.forEach((placeholder) => placeholders.add(placeholder.replace(/[\{\}]/g, '')));
|
|
14
|
-
});
|
|
15
|
-
[...target.childNodes]
|
|
16
|
-
.filter((childNode) => {
|
|
17
|
-
return (childNode.nodeType === 3 &&
|
|
18
|
-
(childNode.nodeValue || '').match(regEx));
|
|
19
|
-
})
|
|
20
|
-
.forEach((childNode) => {
|
|
21
|
-
(childNode.nodeValue || '')
|
|
22
|
-
.match(regEx)
|
|
23
|
-
.forEach((placeholder) => {
|
|
24
|
-
placeholders.add(placeholder.replace(/[\{\}]/g, ''));
|
|
25
|
-
});
|
|
26
|
-
});
|
|
27
|
-
return [...placeholders].map((placeholder) => placeholder.replace(/[\{\}]/g, ''));
|
|
28
|
-
}
|
|
29
|
-
const inputs = [HTMLInputElement, HTMLSelectElement, HTMLTextAreaElement];
|
|
30
|
-
class Placeholders extends DC {
|
|
31
|
-
data = {};
|
|
32
|
-
oldDisplay = '';
|
|
33
|
-
constructor(target) {
|
|
34
|
-
super(target);
|
|
35
|
-
getPlaceholders(target).forEach((property) => (this.data[property] = ''));
|
|
36
|
-
observe(this);
|
|
37
|
-
this.#attachCallbacks();
|
|
38
|
-
}
|
|
39
|
-
#attachCallbacks() {
|
|
40
|
-
let target = this.target, hide = false;
|
|
41
|
-
(!!target.getAttributeNames ? target.getAttributeNames() : [])
|
|
42
|
-
.filter((attr) => target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g))
|
|
43
|
-
.forEach((attr) => {
|
|
44
|
-
let placeholders = new Set(target.getAttribute(attr)?.match(/\{[^\{\}]*\}/g));
|
|
45
|
-
this.data.observe(((template) => (data) => {
|
|
46
|
-
let result = template;
|
|
47
|
-
placeholders.forEach((placeholder) => {
|
|
48
|
-
result = result.replace(placeholder, data[placeholder.replace(/[\{\}]/g, '')]);
|
|
49
|
-
});
|
|
50
|
-
target.setAttribute(attr, result);
|
|
51
|
-
})(target.getAttribute(attr)));
|
|
52
|
-
});
|
|
53
|
-
[...target.childNodes]
|
|
54
|
-
.filter((childNode) => {
|
|
55
|
-
return (childNode.nodeType === 3 &&
|
|
56
|
-
(childNode.nodeValue || '').match(/\{[^\{\}]*\}/g));
|
|
57
|
-
})
|
|
58
|
-
.forEach((childNode) => {
|
|
59
|
-
hide = true;
|
|
60
|
-
let placeholders = new Set(childNode.nodeValue.match(/\{[^\{\}]*\}/g));
|
|
61
|
-
this.data.observe(((template) => (data) => {
|
|
62
|
-
let result = template;
|
|
63
|
-
placeholders.forEach((placeholder) => {
|
|
64
|
-
result = result.replace(placeholder, data[placeholder.replace(/[\{\}]/g, '')]);
|
|
65
|
-
});
|
|
66
|
-
if (!!this.oldDisplay) {
|
|
67
|
-
target.style = this.oldDisplay;
|
|
68
|
-
}
|
|
69
|
-
else {
|
|
70
|
-
target.removeAttribute('style');
|
|
71
|
-
}
|
|
72
|
-
delete this.oldDisplay;
|
|
73
|
-
childNode.nodeValue = result;
|
|
74
|
-
})(childNode.nodeValue));
|
|
75
|
-
this.oldDisplay = target.getAttribute('style') || '';
|
|
76
|
-
if (hide &&
|
|
77
|
-
!inputs.includes(target.constructor) &&
|
|
78
|
-
target.tagName !== 'FIELDSET') {
|
|
79
|
-
target.style.display = 'none';
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
onData(ev) {
|
|
84
|
-
let data = {};
|
|
85
|
-
Object.keys(ev.detail.data).forEach((key) => {
|
|
86
|
-
if (this.data.hasOwnProperty(key))
|
|
87
|
-
data[key] = ev.detail.data[key];
|
|
88
|
-
});
|
|
89
|
-
if (JSON.stringify(data) !== JSON.stringify(this.data))
|
|
90
|
-
Object.assign(this.data, data);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
function getPlaceholderElements(target) {
|
|
94
|
-
let elements = [target]
|
|
95
|
-
.concat([...target.querySelectorAll('*')])
|
|
96
|
-
.filter((e) => !!getPlaceholders(e).length)
|
|
97
|
-
.filter((e) => e?.tagName !== 'STYLE')
|
|
98
|
-
.reverse();
|
|
99
|
-
return elements;
|
|
100
|
-
}
|
|
101
|
-
function makePlaceholders(element) {
|
|
102
|
-
getPlaceholderElements(element).forEach((e) => {
|
|
103
|
-
if (e?._mc?._placeholders)
|
|
104
|
-
return;
|
|
105
|
-
DC.add(e, '_placeholders', new Placeholders(e));
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
const classRepo = {};
|
|
109
|
-
function makeObservable(val) {
|
|
110
|
-
const Constructor = val.constructor, ConstructorName = Constructor.name;
|
|
111
|
-
let ObservableClass = class extends Constructor {
|
|
112
|
-
#notify = true;
|
|
113
|
-
#callbacks = [];
|
|
114
|
-
constructor(val) {
|
|
115
|
-
super(val);
|
|
116
|
-
this.constructor.callbacks = [];
|
|
117
|
-
if (isObservableObject(val)) {
|
|
118
|
-
Object.getOwnPropertyNames(val).forEach((key) => {
|
|
119
|
-
this[key] = val[key];
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
get callbacks() {
|
|
124
|
-
return this.#callbacks;
|
|
125
|
-
}
|
|
126
|
-
set callbacks(callbacks) {
|
|
127
|
-
this.#callbacks = callbacks;
|
|
128
|
-
}
|
|
129
|
-
observe(callback) {
|
|
130
|
-
this.#callbacks.push(callback);
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
bind(target) {
|
|
134
|
-
const iso = isObservableObject(this.valueOf());
|
|
135
|
-
if (iso) {
|
|
136
|
-
makePlaceholders(target);
|
|
137
|
-
const placeholders = [
|
|
138
|
-
target,
|
|
139
|
-
...target.querySelectorAll('[data-mc]'),
|
|
140
|
-
]
|
|
141
|
-
.filter((e) => !!e?._mc?._placeholders);
|
|
142
|
-
const func = function callback(data) {
|
|
143
|
-
let flattenedData = flattenObject(data);
|
|
144
|
-
placeholders.forEach((node) => {
|
|
145
|
-
if (!node)
|
|
146
|
-
return;
|
|
147
|
-
trigger(node, 'data', flattenedData);
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
this.#callbacks.push(func);
|
|
151
|
-
this.notify();
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
console.warn('IGNORED - cannot bind a non-Object to the dom, IS:', typeof this.valueOf(), this);
|
|
155
|
-
}
|
|
156
|
-
return this;
|
|
157
|
-
}
|
|
158
|
-
notify(notify) {
|
|
159
|
-
let data = isObservableObject(this.valueOf()) &&
|
|
160
|
-
this.valueOf() instanceof Array === false
|
|
161
|
-
? structuredClone(Object.assign({}, this))
|
|
162
|
-
: this.valueOf();
|
|
163
|
-
if (notify !== undefined) {
|
|
164
|
-
this.#notify = notify;
|
|
165
|
-
}
|
|
166
|
-
this.#callbacks.forEach((f) => {
|
|
167
|
-
f(data);
|
|
168
|
-
});
|
|
169
|
-
return this;
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
classRepo[ConstructorName] = ObservableClass;
|
|
173
|
-
return ObservableClass;
|
|
174
|
-
}
|
|
175
|
-
function getConstructor(val) {
|
|
176
|
-
let key = val.constructor.name;
|
|
177
|
-
return classRepo[key] || makeObservable(val);
|
|
178
|
-
}
|
|
179
|
-
export const observe = (target, propertyName) => {
|
|
180
|
-
let keys = !propertyName
|
|
181
|
-
? [...Object.getOwnPropertyNames(target)]
|
|
182
|
-
: [propertyName];
|
|
183
|
-
keys.forEach((key) => {
|
|
184
|
-
if (target.hasOwnProperty(key)
|
|
185
|
-
&& typeof target[key] !== 'function'
|
|
186
|
-
&& !target?.[key]?.constructor?.prototype?.observe) {
|
|
187
|
-
if (key[0] === '_' || target?.[key] === undefined)
|
|
188
|
-
return target;
|
|
189
|
-
let val = target[key];
|
|
190
|
-
let o = new (getConstructor(val))(val);
|
|
191
|
-
Object.defineProperty(target, key, {
|
|
192
|
-
enumerable: true,
|
|
193
|
-
get() {
|
|
194
|
-
if (isObservableObject(o.valueOf())) {
|
|
195
|
-
let check = structuredClone(Object.assign({}, o));
|
|
196
|
-
setTimeout(debounce(function checkChanges() {
|
|
197
|
-
let state = structuredClone(Object.assign({}, o));
|
|
198
|
-
if (!deepEqual(state, check)) {
|
|
199
|
-
o.notify();
|
|
200
|
-
}
|
|
201
|
-
}, 0), 0);
|
|
202
|
-
}
|
|
203
|
-
return o;
|
|
204
|
-
},
|
|
205
|
-
set(val) {
|
|
206
|
-
if (typeof val === typeof o.valueOf()) {
|
|
207
|
-
let iso = isObservableObject(o.valueOf()) &&
|
|
208
|
-
o.valueOf() instanceof Array === false;
|
|
209
|
-
if (iso) {
|
|
210
|
-
let old = structuredClone(Object.assign({}, o));
|
|
211
|
-
if (o?.constructor?.prototype?.observe === undefined) {
|
|
212
|
-
o = new (getConstructor(val))(structuredClone(Object.assign({}, val)));
|
|
213
|
-
copyGettersSetters(val, o);
|
|
214
|
-
o.seal();
|
|
215
|
-
}
|
|
216
|
-
Object.assign(o, val);
|
|
217
|
-
setTimeout(debounce(function checkChanges() {
|
|
218
|
-
let state = structuredClone(Object.assign({}, o));
|
|
219
|
-
if (!deepEqual(state, old)) {
|
|
220
|
-
o.notify();
|
|
221
|
-
}
|
|
222
|
-
}, 0), 0);
|
|
223
|
-
}
|
|
224
|
-
else {
|
|
225
|
-
let old = o.valueOf(), callbacks = o.callbacks;
|
|
226
|
-
if (val !== old) {
|
|
227
|
-
o = new (getConstructor(val))(val);
|
|
228
|
-
o.callbacks = callbacks;
|
|
229
|
-
o.notify();
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
console.warn('IGNORED - cannot change observable types, IS:', typeof o.valueOf(), o, '- CANNOT BECOME:', typeof val);
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
target[key] = val;
|
|
239
|
-
}
|
|
240
|
-
;
|
|
241
|
-
});
|
|
242
|
-
return target;
|
|
243
|
-
};
|
|
244
|
-
//# sourceMappingURL=observables.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.observables=e():t.observables=e()}(this,(()=>(()=>{"use strict";var t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};function r(t){let e={};return[...Object.keys(t)].sort().forEach((n=>{var o;(o=t[n])&&o.constructor&&o.constructor===Object?e[n]=r(t[n]):e[n]=t[n]})),e}function n(t,e=!0){let o={};return[...Object.getOwnPropertyNames(t)].forEach((e=>{if(t[e]&&t[e].constructor&&t[e].constructor===Object){const r=n(t[e],!1);for(const t in r)o[e+"."+t]=r[t]}else o[e]=t[e]})),e?r(o):o}function o(t,e){return JSON.stringify(n(t))===JSON.stringify(n(e))}function c(t,e){let r;return()=>{clearTimeout(r),r=setTimeout((function(){t(...arguments)}),e)}}t.r(e),t.d(e,{observe:()=>v});const s=new Function("try {return this===window;}catch(e){ return false;}");function a(t){return t&&t instanceof HTMLElement}function i(t){return"_mc"+t[0].toUpperCase()+t.substring(1)}function l(t,e,r,n=!1){return t.addEventListener(i(e),r,{capture:!1,once:n}),r}class u{stopped=!1;constructor(){}stop(){this.stopped=!0}}function f(t,e,r={},n="l",o){const c=/^_mc/.test(e)?e:i(e),s=o||new u,a=new CustomEvent(c,{detail:{data:r,control:s},bubbles:!1});s.stopped||(t.dispatchEvent(a),a.stopImmediatePropagation(),s.stopped||/[ud]/.test(n)&&(-1===n.indexOf("l")&&(n+="l"),setTimeout((()=>{if(n.indexOf("u")>-1){let e=t.parentElement?.closest("[data-mc]");e&&e?._mc.trigger(c,r,n,s)}if(n.indexOf("d")>-1){let e=t._mc.children();e&&e.forEach((t=>t.trigger(c,r,n)))}}),0)))}class d{_target;constructor(t){var e;this._target=new WeakRef(t||{}),e=this,setTimeout((()=>{e.constructor!==h&&e.trigger("Init")}),0),function(t){if(!s()||t.constructor===h)return;const e=t.target;if(e instanceof HTMLElement){let r=t;Object.getOwnPropertyNames(r.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof r.constructor.prototype[t])).forEach((t=>{let n=/^one/.test(t),o=t.replace(/^on[e]{0,1}/,""),c=o.toLowerCase();if("on"+c in e){let n=e=>{r[t](e)};e.addEventListener(c,n)}else l(e,o,(e=>{r[t](e)}),n)}))}}(this)}get target(){return this._target.deref()}}class h extends d{constructor(t){super(t)}static add(t,e,r={}){return function(t,e,r={}){let n=t;n._mc||(n._mc=new h(t));const o=n._mc;return e.length&&!o[e]&&(o[e]=r,t instanceof HTMLElement&&!t.getAttribute("data-mc")&&t.setAttribute("data-mc","")),n}(t,e,r)}static remove(t,e){!function(t,e){if(!e)return;const r=t?._mc||{};r&&r[e]&&delete r[e],!Object.keys(r).length&&t instanceof HTMLElement&&t.hasAttribute("data-mc")&&t.removeAttribute("data-mc")}(t,e)}off(t,e){!function(t,e,r){t.removeEventListener(i(e),r)}(this.target,t,e)}on(t,e){return l(this.target,t,e)}one(t,e){return function(t,e,r){return l(t,e,r,!0),r}(this.target,t,e)}trigger(t,e={},r="l",n){f(this.target,t,e,r,n)}ancestors(){let t=this?.target,e=[];if(!a(t))return[];for(;t=t.closest("[data-mc]");)t?._mc&&e.push(t?._mc);return e.length?e:null}closest(){let t=this.target;return a(t)&&t.closest("[data-mc]")?._mc||null}children(){let t=this?.target;return a(t)?function(t){const e=Math.random().toString().replace(".",""),r='[data-mc]:not([temp_id="'+e+'"] [data-mc] [data-mc])';t.setAttribute("temp_id",e);const n=[...t.querySelectorAll(r)].filter((t=>!!t._mc)).map((t=>t._mc));return t.removeAttribute("temp_id"),n.length?n:null}(t):null}descendants(){const t=this?.target;if(!a(t))return[];const e=[...t.querySelectorAll("[data-mc]")].filter((t=>!!t._mc)).map((t=>t._mc));return e.length?e:null}}function p(t){return null!=t&&"object"==typeof t}function m(t){let e=new Set,r=/\{[^\{\}]*\}/g;return(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(r))).forEach((e=>{let n=new Set(t.getAttribute(e)?.match(r));n.forEach((t=>n.add(t.replace(/[\{\}]/g,""))))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(r))).forEach((t=>{(t.nodeValue||"").match(r).forEach((t=>{e.add(t.replace(/[\{\}]/g,""))}))})),[...e].map((t=>t.replace(/[\{\}]/g,"")))}new Set;const b=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class g extends h{data={};oldDisplay="";constructor(t){super(t),m(t).forEach((t=>this.data[t]="")),v(this),this.#t()}#t(){let t=this.target,e=!1;(t.getAttributeNames?t.getAttributeNames():[]).filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((e=>{let r=new Set(t.getAttribute(e)?.match(/\{[^\{\}]*\}/g));var n;this.data.observe((n=t.getAttribute(e),o=>{let c=n;r.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),t.setAttribute(e,c)}))})),[...t.childNodes].filter((t=>3===t.nodeType&&(t.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((r=>{e=!0;let n=new Set(r.nodeValue.match(/\{[^\{\}]*\}/g));this.data.observe((e=>o=>{let c=e;n.forEach((t=>{c=c.replace(t,o[t.replace(/[\{\}]/g,"")])})),this.oldDisplay?t.style=this.oldDisplay:t.removeAttribute("style"),delete this.oldDisplay,r.nodeValue=c})(r.nodeValue)),this.oldDisplay=t.getAttribute("style")||"",e&&!b.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(t){let e={};Object.keys(t.detail.data).forEach((r=>{this.data.hasOwnProperty(r)&&(e[r]=t.detail.data[r])})),JSON.stringify(e)!==JSON.stringify(this.data)&&Object.assign(this.data,e)}}const y={};function O(t){let e=t.constructor.name;return y[e]||function(t){const e=t.constructor,r=e.name;let o=class extends e{#e=!0;#r=[];constructor(t){super(t),this.constructor.callbacks=[],p(t)&&Object.getOwnPropertyNames(t).forEach((e=>{this[e]=t[e]}))}get callbacks(){return this.#r}set callbacks(t){this.#r=t}observe(t){return this.#r.push(t),this}bind(t){if(p(this.valueOf())){!function(t){var e;(e=t,[e].concat([...e.querySelectorAll("*")]).filter((t=>!!m(t).length)).filter((t=>"STYLE"!==t?.tagName)).reverse()).forEach((t=>{t?._mc?._placeholders||h.add(t,"_placeholders",new g(t))}))}(t);const e=[t,...t.querySelectorAll("[data-mc]")].filter((t=>!!t?._mc?._placeholders)),r=function(t){let r=n(t);e.forEach((t=>{t&&f(t,"data",r)}))};this.#r.push(r),this.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof this.valueOf(),this);return this}notify(t){let e=p(this.valueOf())&&this.valueOf()instanceof Array==0?structuredClone(Object.assign({},this)):this.valueOf();return void 0!==t&&(this.#e=t),this.#r.forEach((t=>{t(e)})),this}};return y[r]=o,o}(t)}const v=(t,e)=>((e?[e]:[...Object.getOwnPropertyNames(t)]).forEach((e=>{if(t.hasOwnProperty(e)&&"function"!=typeof t[e]&&!t?.[e]?.constructor?.prototype?.observe){if("_"===e[0]||void 0===t?.[e])return t;let r=t[e],n=new(O(r))(r);Object.defineProperty(t,e,{enumerable:!0,get(){if(p(n.valueOf())){let t=structuredClone(Object.assign({},n));setTimeout(c((function(){o(structuredClone(Object.assign({},n)),t)||n.notify()}),0),0)}return n},set(t){if(typeof t==typeof n.valueOf())if(p(n.valueOf())&&n.valueOf()instanceof Array==0){let e=structuredClone(Object.assign({},n));void 0===n?.constructor?.prototype?.observe&&(n=new(O(t))(structuredClone(Object.assign({},t))),function(t,e){const r=Object.getOwnPropertyDescriptors(t);for(const[t,n]of Object.entries(r))("get"in n||"set"in n)&&Object.defineProperty(e,t,n)}(t,n),n.seal()),Object.assign(n,t),setTimeout(c((function(){o(structuredClone(Object.assign({},n)),e)||n.notify()}),0),0)}else{let e=n.valueOf(),r=n.callbacks;t!==e&&(n=new(O(t))(t),n.callbacks=r,n.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof n.valueOf(),n,"- CANNOT BECOME:",typeof t)}}),t[e]=r}})),t);return e})()));
|