@twobirds/microcomponents 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MC.min.js +33 -52
- package/dist/elements.min.js +1 -1
- package/dist/formValues.min.js +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.min.js +1 -1
- package/package.json +11 -2
- package/.gitlab-ci.yml +0 -18
- package/.vscode/settings.json +0 -3
- package/MicroComponents.svg +0 -15
- package/assets/documentation/MC.md +0 -547
- package/assets/documentation/MicroComponents.svg +0 -15
- package/assets/documentation/ajaxian-1.png +0 -0
- package/assets/documentation/ajaxian-2.png +0 -0
- package/assets/documentation/ajaxian-3.png +0 -0
- package/assets/documentation/elements.md +0 -277
- package/assets/documentation/formvalues.md +0 -25
- package/assets/documentation/functional_requirements.md +0 -8
- package/assets/documentation/history.md +0 -436
- package/assets/documentation/klemmstein.png +0 -0
- package/assets/documentation/magic.md +0 -29
- package/assets/documentation/observables.md +0 -187
- package/assets/documentation/rnd0023-1.jpg +0 -0
- package/assets/documentation/rnd0023-2.jpg +0 -0
- package/assets/documentation/rnd0023-3.jpg +0 -0
- package/assets/documentation/tB_react.md +0 -207
- package/assets/documentation/usage.md +0 -142
- package/assets/documentation/why.md +0 -25
- package/assets/fiddle/MicroComponents.svg +0 -15
- package/assets/fiddle/fiddle.css +0 -0
- package/assets/fiddle/fiddle.js +0 -0
- package/assets/fiddle/index.html +0 -0
- package/assets/test/MicroComponents.svg +0 -15
- package/assets/test/grandparent.css +0 -16
- package/assets/test/myButton.css +0 -19
- package/assets/test/style.css +0 -8
- package/assets/test/test.html +0 -29
- package/assets/test/testform.json +0 -27
- package/public/.nojekyll +0 -1
- package/public/MC.d.ts +0 -39
- package/public/MC.d.ts.map +0 -1
- package/public/MC.js +0 -287
- package/public/MC.js.map +0 -1
- package/public/MC.min.js +0 -348
- package/public/MC.ts +0 -431
- package/public/MicroComponents.svg +0 -15
- package/public/documentation/MC.md +0 -547
- package/public/documentation/MicroComponents.svg +0 -15
- package/public/documentation/ajaxian-1.png +0 -0
- package/public/documentation/ajaxian-2.png +0 -0
- package/public/documentation/ajaxian-3.png +0 -0
- package/public/documentation/elements.md +0 -277
- package/public/documentation/formvalues.md +0 -25
- package/public/documentation/functional_requirements.md +0 -8
- package/public/documentation/history.md +0 -436
- package/public/documentation/klemmstein.png +0 -0
- package/public/documentation/magic.md +0 -29
- package/public/documentation/observables.md +0 -187
- package/public/documentation/rnd0023-1.jpg +0 -0
- package/public/documentation/rnd0023-2.jpg +0 -0
- package/public/documentation/rnd0023-3.jpg +0 -0
- package/public/documentation/tB_react.md +0 -207
- package/public/documentation/usage.md +0 -142
- package/public/documentation/why.md +0 -25
- package/public/elements.d.ts +0 -5
- package/public/elements.d.ts.map +0 -1
- package/public/elements.js +0 -68
- package/public/elements.js.map +0 -1
- package/public/elements.min.js +0 -1
- package/public/elements.ts +0 -119
- package/public/fiddle/MicroComponents.svg +0 -15
- package/public/fiddle/fiddle.css +0 -0
- package/public/fiddle/fiddle.js +0 -0
- package/public/fiddle/index.html +0 -0
- package/public/formValues.d.ts +0 -3
- package/public/formValues.d.ts.map +0 -1
- package/public/formValues.js +0 -162
- package/public/formValues.js.map +0 -1
- package/public/formValues.min.js +0 -1
- package/public/formValues.ts +0 -225
- package/public/helpers.d.ts +0 -14
- package/public/helpers.d.ts.map +0 -1
- package/public/helpers.js +0 -113
- package/public/helpers.js.map +0 -1
- package/public/helpers.ts +0 -149
- package/public/microcomponents.d.ts +0 -6
- package/public/microcomponents.d.ts.map +0 -1
- package/public/microcomponents.js +0 -7
- package/public/microcomponents.js.map +0 -1
- package/public/microcomponents.min.js +0 -1
- package/public/microcomponents.ts +0 -8
- package/public/observables.d.ts +0 -11
- package/public/observables.d.ts.map +0 -1
- package/public/observables.js +0 -244
- package/public/observables.js.map +0 -1
- package/public/observables.min.js +0 -1
- package/public/observables.ts +0 -416
- package/public/selectors._ts +0 -1269
- package/public/src/MC.d.ts +0 -39
- package/public/src/MC.d.ts.map +0 -1
- package/public/src/MC.js +0 -287
- package/public/src/MC.js.map +0 -1
- package/public/src/MC.ts +0 -431
- package/public/src/elements.d.ts +0 -5
- package/public/src/elements.d.ts.map +0 -1
- package/public/src/elements.js +0 -68
- package/public/src/elements.js.map +0 -1
- package/public/src/elements.ts +0 -119
- package/public/src/formValues.d.ts +0 -3
- package/public/src/formValues.d.ts.map +0 -1
- package/public/src/formValues.js +0 -162
- package/public/src/formValues.js.map +0 -1
- package/public/src/formValues.ts +0 -225
- package/public/src/helpers.d.ts +0 -14
- package/public/src/helpers.d.ts.map +0 -1
- package/public/src/helpers.js +0 -113
- package/public/src/helpers.js.map +0 -1
- package/public/src/helpers.ts +0 -149
- package/public/src/microcomponents.d.ts +0 -6
- package/public/src/microcomponents.d.ts.map +0 -1
- package/public/src/microcomponents.js +0 -7
- package/public/src/microcomponents.js.map +0 -1
- package/public/src/microcomponents.ts +0 -8
- package/public/src/observables.d.ts +0 -11
- package/public/src/observables.d.ts.map +0 -1
- package/public/src/observables.js +0 -244
- package/public/src/observables.js.map +0 -1
- package/public/src/observables.ts +0 -416
- package/public/src/selectors._ts +0 -1269
- package/public/src/test/grandparent.css +0 -14
- package/public/src/test/test/child.d.ts +0 -2
- package/public/src/test/test/child.d.ts.map +0 -1
- package/public/src/test/test/child.js +0 -26
- package/public/src/test/test/child.js.map +0 -1
- package/public/src/test/test/child.ts +0 -36
- package/public/src/test/test/grandchild.d.ts +0 -2
- package/public/src/test/test/grandchild.d.ts.map +0 -1
- package/public/src/test/test/grandchild.js +0 -22
- package/public/src/test/test/grandchild.js.map +0 -1
- package/public/src/test/test/grandchild.ts +0 -31
- package/public/src/test/test/grandparent.d.ts +0 -2
- package/public/src/test/test/grandparent.d.ts.map +0 -1
- package/public/src/test/test/grandparent.js +0 -1
- package/public/src/test/test/grandparent.js.map +0 -1
- package/public/src/test/test/grandparent.ts +0 -43
- package/public/src/test/test/greatgrandchild.d.ts +0 -2
- package/public/src/test/test/greatgrandchild.d.ts.map +0 -1
- package/public/src/test/test/greatgrandchild.js +0 -36
- package/public/src/test/test/greatgrandchild.js.map +0 -1
- package/public/src/test/test/greatgrandchild.ts +0 -51
- package/public/src/test/test/parent.d.ts +0 -2
- package/public/src/test/test/parent.d.ts.map +0 -1
- package/public/src/test/test/parent.js +0 -25
- package/public/src/test/test/parent.js.map +0 -1
- package/public/src/test/test/parent.ts +0 -35
- package/public/src/test/test/testform.d.ts +0 -2
- package/public/src/test/test/testform.d.ts.map +0 -1
- package/public/src/test/test/testform.js +0 -1
- package/public/src/test/test/testform.js.map +0 -1
- package/public/src/test/test/testform.ts +0 -153
- package/public/src/test/test/testfunction.d.ts +0 -3
- package/public/src/test/test/testfunction.d.ts.map +0 -1
- package/public/src/test/test/testfunction.js +0 -7
- package/public/src/test/test/testfunction.js.map +0 -1
- package/public/src/test/test/testfunction.ts +0 -12
- package/public/src/test/test/testmc.d.ts +0 -3
- package/public/src/test/test/testmc.d.ts.map +0 -1
- package/public/src/test/test/testmc.js +0 -10
- package/public/src/test/test/testmc.js.map +0 -1
- package/public/src/test/test/testmc.ts +0 -16
- package/public/src/test/test/testsimpleclass.d.ts +0 -3
- package/public/src/test/test/testsimpleclass.d.ts.map +0 -1
- package/public/src/test/test/testsimpleclass.js +0 -9
- package/public/src/test/test/testsimpleclass.js.map +0 -1
- package/public/src/test/test/testsimpleclass.ts +0 -15
- package/public/src/test/test.d.ts +0 -2
- package/public/src/test/test.d.ts.map +0 -1
- package/public/src/test/test.js +0 -72
- package/public/src/test/test.js.map +0 -1
- package/public/src/test/test.ts +0 -176
- package/public/src/test/testform.css +0 -47
- package/public/src/test/testform.html +0 -56
- package/public/src/test/testform.json +0 -27
- package/public/test/MC.d.ts +0 -39
- package/public/test/MC.d.ts.map +0 -1
- package/public/test/MC.js +0 -287
- package/public/test/MC.min.js +0 -348
- package/public/test/MC.ts +0 -431
- package/public/test/MicroComponents.svg +0 -15
- package/public/test/elements.d.ts +0 -5
- package/public/test/elements.d.ts.map +0 -1
- package/public/test/elements.js +0 -68
- package/public/test/elements.min.js +0 -1
- package/public/test/elements.ts +0 -119
- package/public/test/formValues.d.ts +0 -3
- package/public/test/formValues.d.ts.map +0 -1
- package/public/test/formValues.js +0 -162
- package/public/test/formValues.min.js +0 -1
- package/public/test/formValues.ts +0 -225
- package/public/test/grandparent.css +0 -14
- package/public/test/helpers.d.ts +0 -14
- package/public/test/helpers.d.ts.map +0 -1
- package/public/test/helpers.js +0 -113
- package/public/test/helpers.ts +0 -149
- package/public/test/microcomponents.d.ts +0 -6
- package/public/test/microcomponents.d.ts.map +0 -1
- package/public/test/microcomponents.js +0 -7
- package/public/test/microcomponents.min.js +0 -1
- package/public/test/microcomponents.ts +0 -8
- package/public/test/myButton.css +0 -19
- package/public/test/observables.d.ts +0 -11
- package/public/test/observables.d.ts.map +0 -1
- package/public/test/observables.js +0 -244
- package/public/test/observables.min.js +0 -1
- package/public/test/observables.ts +0 -416
- package/public/test/style.css +0 -8
- package/public/test/test/child.d.ts +0 -2
- package/public/test/test/child.d.ts.map +0 -1
- package/public/test/test/child.js +0 -26
- package/public/test/test/child.js.map +0 -1
- package/public/test/test/child.ts +0 -36
- package/public/test/test/grandchild.d.ts +0 -2
- package/public/test/test/grandchild.d.ts.map +0 -1
- package/public/test/test/grandchild.js +0 -22
- package/public/test/test/grandchild.js.map +0 -1
- package/public/test/test/grandchild.ts +0 -31
- package/public/test/test/grandparent.d.ts +0 -2
- package/public/test/test/grandparent.d.ts.map +0 -1
- package/public/test/test/grandparent.js +0 -1
- package/public/test/test/grandparent.js.map +0 -1
- package/public/test/test/grandparent.ts +0 -43
- package/public/test/test/greatgrandchild.d.ts +0 -2
- package/public/test/test/greatgrandchild.d.ts.map +0 -1
- package/public/test/test/greatgrandchild.js +0 -36
- package/public/test/test/greatgrandchild.js.map +0 -1
- package/public/test/test/greatgrandchild.ts +0 -51
- package/public/test/test/parent.d.ts +0 -2
- package/public/test/test/parent.d.ts.map +0 -1
- package/public/test/test/parent.js +0 -25
- package/public/test/test/parent.js.map +0 -1
- package/public/test/test/parent.ts +0 -35
- package/public/test/test/testform.d.ts +0 -2
- package/public/test/test/testform.d.ts.map +0 -1
- package/public/test/test/testform.js +0 -1
- package/public/test/test/testform.js.map +0 -1
- package/public/test/test/testform.ts +0 -153
- package/public/test/test/testfunction.d.ts +0 -3
- package/public/test/test/testfunction.d.ts.map +0 -1
- package/public/test/test/testfunction.js +0 -7
- package/public/test/test/testfunction.js.map +0 -1
- package/public/test/test/testfunction.ts +0 -12
- package/public/test/test/testmc.d.ts +0 -3
- package/public/test/test/testmc.d.ts.map +0 -1
- package/public/test/test/testmc.js +0 -10
- package/public/test/test/testmc.js.map +0 -1
- package/public/test/test/testmc.ts +0 -16
- package/public/test/test/testsimpleclass.d.ts +0 -3
- package/public/test/test/testsimpleclass.d.ts.map +0 -1
- package/public/test/test/testsimpleclass.js +0 -9
- package/public/test/test/testsimpleclass.js.map +0 -1
- package/public/test/test/testsimpleclass.ts +0 -15
- package/public/test/test.d.ts +0 -2
- package/public/test/test.d.ts.map +0 -1
- package/public/test/test.html +0 -29
- package/public/test/test.js +0 -72
- package/public/test/test.js.map +0 -1
- package/public/test/test.ts +0 -176
- package/public/test/testform.css +0 -47
- package/public/test/testform.html +0 -56
- package/public/test/testform.json +0 -27
- package/public/typedoc/.nojekyll +0 -1
- package/public/typedoc/assets/highlight.css +0 -106
- package/public/typedoc/assets/icons.js +0 -18
- package/public/typedoc/assets/icons.svg +0 -1
- package/public/typedoc/assets/main.js +0 -60
- package/public/typedoc/assets/navigation.js +0 -1
- package/public/typedoc/assets/search.js +0 -1
- package/public/typedoc/assets/style.css +0 -1493
- package/public/typedoc/classes/MC.DC.html +0 -13
- package/public/typedoc/classes/MC.MC.html +0 -3
- package/public/typedoc/classes/MC.McBase.html +0 -3
- package/public/typedoc/functions/MC.autoload.html +0 -1
- package/public/typedoc/functions/MC.off.html +0 -1
- package/public/typedoc/functions/MC.on.html +0 -1
- package/public/typedoc/functions/MC.one.html +0 -1
- package/public/typedoc/functions/MC.trigger.html +0 -1
- package/public/typedoc/functions/elements.defineCE.html +0 -1
- package/public/typedoc/functions/elements.getCE.html +0 -1
- package/public/typedoc/functions/formValues.formValues.html +0 -1
- package/public/typedoc/functions/observables.observe.html +0 -1
- package/public/typedoc/hierarchy.html +0 -1
- package/public/typedoc/index.html +0 -122
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +0 -758
- package/public/typedoc/media/MicroComponents.svg +0 -15
- package/public/typedoc/modules/MC.html +0 -10
- package/public/typedoc/modules/elements.html +0 -3
- package/public/typedoc/modules/formValues.html +0 -2
- package/public/typedoc/modules/observables.html +0 -3
- package/public/typedoc/modules.html +0 -5
- package/public/typedoc/types/observables.Observable.html +0 -1
- package/src/MC.ts +0 -431
- package/src/elements.ts +0 -119
- package/src/formValues.ts +0 -225
- package/src/helpers.ts +0 -149
- package/src/microcomponents.ts +0 -8
- package/src/observables.ts +0 -416
- package/src/selectors._ts +0 -1269
- package/src/test/grandparent.css +0 -14
- package/src/test/test/child.ts +0 -36
- package/src/test/test/grandchild.ts +0 -31
- package/src/test/test/grandparent.ts +0 -43
- package/src/test/test/greatgrandchild.ts +0 -51
- package/src/test/test/parent.ts +0 -35
- package/src/test/test/testform.ts +0 -153
- package/src/test/test/testfunction.ts +0 -12
- package/src/test/test/testmc.ts +0 -16
- package/src/test/test/testsimpleclass.ts +0 -15
- package/src/test/test.ts +0 -176
- package/src/test/testform.css +0 -47
- package/src/test/testform.html +0 -56
- package/src/test/testform.json +0 -27
- package/tasks.md +0 -36
- package/tsconfig.json +0 -107
- package/typedoc.json +0 -7
- package/webpack.config.js +0 -346
package/src/elements.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { DC, McBase } from './MC.js';
|
|
4
|
-
import { kebabToPascal } from './helpers.js';
|
|
5
|
-
|
|
6
|
-
class CeBaseClass extends HTMLElement {
|
|
7
|
-
constructor() {
|
|
8
|
-
super();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
connectedCallback() {
|
|
12
|
-
this.dispatchEvent( new CustomEvent('_mcConnected') );
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
connectedMoveCallback() {
|
|
16
|
-
this.dispatchEvent( new CustomEvent('_mcConnectedMove') );
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
disconnectedCallback() {
|
|
20
|
-
this.dispatchEvent( new CustomEvent('_mcDisconnected') );
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
adoptedCallback() {
|
|
24
|
-
this.dispatchEvent( new CustomEvent('_mcAdopted') );
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
attributeChangedCallback(name: string, oldValue: any, newValue: any) {
|
|
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') );
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function createNamedClass(
|
|
42
|
-
name: string,
|
|
43
|
-
ClassBody: { new (...args: any[]): any }
|
|
44
|
-
) {
|
|
45
|
-
return Object.defineProperty(ClassBody, 'name', { value: name });
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function isClass(func: any) {
|
|
49
|
-
return typeof func === 'function'
|
|
50
|
-
&& /^class\s/.test(Function.prototype.toString.call(func));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export function defineCE(
|
|
54
|
-
tagName: string,
|
|
55
|
-
DefinitionClass: { new (...args: any[]): any } | Function,
|
|
56
|
-
observedAttributes: string[] = []
|
|
57
|
-
) {
|
|
58
|
-
if (customElements.get(tagName)) {
|
|
59
|
-
console.warn(`IGNORED: Custom element "${tagName}" is already defined!`);
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (!tagName.includes('-')) {
|
|
64
|
-
throw new Error(
|
|
65
|
-
'createCustomElement: tagName must contain at least one hyphen ("-").'
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let name = kebabToPascal(tagName);
|
|
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
|
|
92
|
-
customElements.define(
|
|
93
|
-
tagName,
|
|
94
|
-
createNamedClass(
|
|
95
|
-
name,
|
|
96
|
-
class extends CeBaseClass {
|
|
97
|
-
instance: any;
|
|
98
|
-
|
|
99
|
-
constructor(data?: any) {
|
|
100
|
-
super();
|
|
101
|
-
// @ts-ignore
|
|
102
|
-
const instance = isClass( DefinitionClass )
|
|
103
|
-
// @ts-ignore
|
|
104
|
-
? new DefinitionClass(this, data)
|
|
105
|
-
: DefinitionClass;
|
|
106
|
-
DC.add(this, name, instance);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
static get observedAttributes() {
|
|
110
|
-
return observedAttributes;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
)
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export function getCE(tagName: string): CustomElementConstructor | undefined {
|
|
118
|
-
return customElements.get(tagName);
|
|
119
|
-
}
|
package/src/formValues.ts
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
import { LooseObject, copyGettersSetters } from './helpers.js';
|
|
4
|
-
import { DC, on } from './MC.js';
|
|
5
|
-
import { observe } from './observables.js';
|
|
6
|
-
|
|
7
|
-
type inputTypes = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
8
|
-
|
|
9
|
-
const getInputName = (
|
|
10
|
-
e: HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
|
|
11
|
-
): string => {
|
|
12
|
-
return e.tagName.toLowerCase();
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
abstract class InputBase {
|
|
16
|
-
constructor(e: inputTypes) {}
|
|
17
|
-
|
|
18
|
-
abstract get val(): any;
|
|
19
|
-
|
|
20
|
-
abstract set val(value: any);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
class RadioHandler extends InputBase {
|
|
24
|
-
#e: HTMLInputElement;
|
|
25
|
-
|
|
26
|
-
constructor(e: HTMLInputElement) {
|
|
27
|
-
super(e);
|
|
28
|
-
this.#e = e;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
get val(): string {
|
|
32
|
-
let ret = new FormData(this.#e.form as HTMLFormElement).get(this.#e.name);
|
|
33
|
-
|
|
34
|
-
//console.log('radio[', this.#e.name, '] = "' + ret + '"');
|
|
35
|
-
return ret as string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
set val(value: string) {
|
|
39
|
-
let arr = [
|
|
40
|
-
...(this.#e.form as HTMLFormElement).querySelectorAll(
|
|
41
|
-
`input[type="radio"][name="${this.#e.name}"]`
|
|
42
|
-
),
|
|
43
|
-
] as HTMLInputElement[];
|
|
44
|
-
|
|
45
|
-
(
|
|
46
|
-
arr
|
|
47
|
-
.filter((e) => e.getAttribute('value') === value)
|
|
48
|
-
.shift() as HTMLInputElement
|
|
49
|
-
).checked = true;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
class CheckboxHandler extends InputBase {
|
|
54
|
-
#e: HTMLInputElement;
|
|
55
|
-
|
|
56
|
-
constructor(e: HTMLInputElement) {
|
|
57
|
-
super(e);
|
|
58
|
-
this.#e = e;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
get val(): boolean {
|
|
62
|
-
return this.#e.checked;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
set val(value: boolean) {
|
|
66
|
-
this.#e.checked = value;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
class InputHandler extends InputBase {
|
|
71
|
-
#e: HTMLInputElement;
|
|
72
|
-
|
|
73
|
-
constructor(e: HTMLInputElement) {
|
|
74
|
-
super(e);
|
|
75
|
-
this.#e = e;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
get val(): string {
|
|
79
|
-
return this.#e.value;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
set val(value: string) {
|
|
83
|
-
this.#e.value = value;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
class SelectHandler extends InputBase {
|
|
88
|
-
#e: HTMLSelectElement;
|
|
89
|
-
#multi: boolean = false;
|
|
90
|
-
|
|
91
|
-
constructor(e: HTMLSelectElement) {
|
|
92
|
-
super(e);
|
|
93
|
-
this.#e = e;
|
|
94
|
-
this.#multi = e.multiple;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get val(): string[] | string {
|
|
98
|
-
const that = this,
|
|
99
|
-
ret: string[] = [];
|
|
100
|
-
|
|
101
|
-
// get all options
|
|
102
|
-
[...that.#e.querySelectorAll('option')]
|
|
103
|
-
.filter((o) => o.selected)
|
|
104
|
-
.forEach((o) => {
|
|
105
|
-
ret.push(o.value);
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
if (this.#multi) return ret;
|
|
109
|
-
return ret.length ? ret[0] : '';
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
set val(value: string[] | string) {
|
|
113
|
-
const that = this;
|
|
114
|
-
|
|
115
|
-
value = typeof value === 'string' ? [value] : value;
|
|
116
|
-
|
|
117
|
-
// set all options
|
|
118
|
-
[...that.#e.querySelectorAll('option')].forEach((o) => {
|
|
119
|
-
if (value.indexOf(o.value) > -1) {
|
|
120
|
-
o.selected = true;
|
|
121
|
-
} else {
|
|
122
|
-
o.selected = false;
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
class TextAreaHandler extends InputBase {
|
|
129
|
-
#e: HTMLTextAreaElement;
|
|
130
|
-
constructor(e: HTMLTextAreaElement) {
|
|
131
|
-
super(e);
|
|
132
|
-
this.#e = e;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
get val(): string {
|
|
136
|
-
return this.#e.value || '';
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
set val(value: string) {
|
|
140
|
-
this.#e.value = value;
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const getInputHandlers = (e: HTMLElement | ShadowRoot): LooseObject => {
|
|
145
|
-
let inputList = [
|
|
146
|
-
...(e || document).querySelectorAll('input,select,textarea'),
|
|
147
|
-
],
|
|
148
|
-
handlers: LooseObject = {};
|
|
149
|
-
|
|
150
|
-
inputList.forEach((input) => {
|
|
151
|
-
const name: string | null = (input as inputTypes).getAttribute('name');
|
|
152
|
-
if (name) {
|
|
153
|
-
let handler: any = false;
|
|
154
|
-
switch (getInputName(input as inputTypes)) {
|
|
155
|
-
case 'input':
|
|
156
|
-
switch ((input as HTMLInputElement).type) {
|
|
157
|
-
case 'radio':
|
|
158
|
-
handler = new RadioHandler(input as HTMLInputElement);
|
|
159
|
-
break;
|
|
160
|
-
case 'checkbox':
|
|
161
|
-
handler = new CheckboxHandler(input as HTMLInputElement);
|
|
162
|
-
break;
|
|
163
|
-
default:
|
|
164
|
-
handler = new InputHandler(input as HTMLInputElement);
|
|
165
|
-
}
|
|
166
|
-
break;
|
|
167
|
-
case 'select':
|
|
168
|
-
handler = new SelectHandler(input as HTMLSelectElement);
|
|
169
|
-
break;
|
|
170
|
-
case 'textarea':
|
|
171
|
-
handler = new TextAreaHandler(input as HTMLTextAreaElement);
|
|
172
|
-
break;
|
|
173
|
-
default:
|
|
174
|
-
console.warn(
|
|
175
|
-
'handler missing:',
|
|
176
|
-
name,
|
|
177
|
-
'for',
|
|
178
|
-
input.tagName.toLowerCase(),
|
|
179
|
-
input
|
|
180
|
-
);
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (handler) {
|
|
185
|
-
DC.add(input as HTMLElement, name, handler);
|
|
186
|
-
Object.defineProperty(handlers, name, {
|
|
187
|
-
enumerable: true,
|
|
188
|
-
configurable: true,
|
|
189
|
-
get: (): any => {
|
|
190
|
-
return handler.val;
|
|
191
|
-
},
|
|
192
|
-
set: (value: any) => {
|
|
193
|
-
if (handler.val !== value) {
|
|
194
|
-
handler.val = value;
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
|
|
202
|
-
return handlers;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
export function formValues(
|
|
206
|
-
targetObject: LooseObject,
|
|
207
|
-
propertyName: string,
|
|
208
|
-
dom: HTMLElement | ShadowRoot
|
|
209
|
-
) {
|
|
210
|
-
let handlers = getInputHandlers(dom);
|
|
211
|
-
|
|
212
|
-
targetObject[propertyName] = Object.assign({}, handlers);
|
|
213
|
-
|
|
214
|
-
observe(targetObject, propertyName);
|
|
215
|
-
|
|
216
|
-
copyGettersSetters(handlers, targetObject[propertyName]);
|
|
217
|
-
|
|
218
|
-
[...dom.querySelectorAll('input, textarea, select')].forEach((input) => {
|
|
219
|
-
input.addEventListener('input', (ev) => {
|
|
220
|
-
//console.log('input event', input, ev);
|
|
221
|
-
targetObject[propertyName].notify();
|
|
222
|
-
});
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
package/src/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
|
-
}
|
package/src/microcomponents.ts
DELETED