@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
|
@@ -1,277 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
# Custom Elements
|
|
4
|
-
|
|
5
|
-
Custom Elements provides two funktions:
|
|
6
|
-
- **defineCE()** lets you define a custom tag and add functionality to it. Internally it uses [Web Components](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define).
|
|
7
|
-
- **getCE()** retrieves a custom element constructor from the web component registry via [CustomElementRegistry.get()](https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/get).
|
|
8
|
-
|
|
9
|
-
# Prerequisites
|
|
10
|
-
|
|
11
|
-
You should at least know Micro Components **[DC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MicroComponents.md?ref_type=heads#dc-class-extends-mcbase)** superclass usage, since your own class code extends from it and uses its static functions. It is recommended that you have read and understood the **[Micro Component documentation](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MicroComponents.md?ref_type=heads)**, since custom elements is just an extension that internally uses micro components.
|
|
12
|
-
|
|
13
|
-
# Usage
|
|
14
|
-
|
|
15
|
-
## Create a Custom Element
|
|
16
|
-
|
|
17
|
-
Before:
|
|
18
|
-
|
|
19
|
-
```html
|
|
20
|
-
<body></body>
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
```javascript
|
|
24
|
-
// customElementRegistry.define() wrapper
|
|
25
|
-
defineCE(
|
|
26
|
-
"my-tag", // tag name
|
|
27
|
-
class MyTag extends DC { // definition class
|
|
28
|
-
|
|
29
|
-
constructor(target, data = {} ) {
|
|
30
|
-
super(target);
|
|
31
|
-
this.data = data;
|
|
32
|
-
target.innerHTML = "Hello World";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
let MyTag = getCE("my-tag"),
|
|
38
|
-
data = { a: 1 },
|
|
39
|
-
myTag = new MyTag( data );
|
|
40
|
-
|
|
41
|
-
/*
|
|
42
|
-
HINT:
|
|
43
|
-
At this point the web component is not yet attached to the DOM.
|
|
44
|
-
But you can perform any operation on it, e.g. calling methods on its inner micro components.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
document.body.append( myTag );
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
After:
|
|
51
|
-
```html
|
|
52
|
-
<body>
|
|
53
|
-
<my-tag data-mc>Hello World</my-tag>
|
|
54
|
-
</body>
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
**Hints**
|
|
58
|
-
- Your code extends the **[DC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MicroComponents.md?ref_type=heads#dc-class-extends-mcbase)** superclass. This superclass provides methods to traverse the DOM and select other micro components contained in HTML elements.
|
|
59
|
-
- it is essential to understand that your web component code is only one of the numerous micro components that can reside inside `<my-tag>`
|
|
60
|
-
- After you created a custom element, the custom element will contain a **property `_mc`** which contains your class instance.
|
|
61
|
-
- Also the custom element then has an **attribute `data-mc`** which will indicate that at least one micro component is attached to it.
|
|
62
|
-
- Note that you can hand over data natively via parameters, when handling custom elements in above way.
|
|
63
|
-
- The native way of usage, simply adding the tag to the template, is still possible. You have to use attributes then to hand in data.
|
|
64
|
-
|
|
65
|
-
## Web Component Lifecycle Events
|
|
66
|
-
|
|
67
|
-
```javascript
|
|
68
|
-
// customElementRegistry.define() wrapper
|
|
69
|
-
defineCE(
|
|
70
|
-
"my-tag",
|
|
71
|
-
class MyTag extends DC {
|
|
72
|
-
|
|
73
|
-
constructor(target) {
|
|
74
|
-
super(target);
|
|
75
|
-
target.setAttribute('my-attribute', 'change me');
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/*
|
|
79
|
-
web component specific event handlers
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
onConnected(ev) {
|
|
83
|
-
console.info("MyTag .onConnected() handler", ev);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
onAttributeChanged(ev) {
|
|
87
|
-
console.info("MyTag .onAttributeChanged() handler", ev);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
onAdopted(ev) {
|
|
91
|
-
console.info("MyTag .onAdopted() handler", ev);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
onDisconnected(ev) {
|
|
95
|
-
console.info("MyTag .onDisconnected() handler", ev);
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
['my-attribute'] // DOM node attributes to observe
|
|
99
|
-
);
|
|
100
|
-
|
|
101
|
-
let MyTag = getCE("my-tag"), // customElementRegistry.get("my-tag")
|
|
102
|
-
myTag = new MyTag(); // programmatically create a custom element instance
|
|
103
|
-
|
|
104
|
-
document.body.append( myTag );
|
|
105
|
-
```
|
|
106
|
-
|
|
107
|
-
## Composition with Micro Components
|
|
108
|
-
|
|
109
|
-
You can use your Web Component constructor to add other modules to the `<my-tag>` DOM node:
|
|
110
|
-
|
|
111
|
-
```javascript
|
|
112
|
-
|
|
113
|
-
class OtherModule extends DC {
|
|
114
|
-
|
|
115
|
-
constructor(target) {
|
|
116
|
-
super(target);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
onConnected(ev) {
|
|
120
|
-
console.info("[OtherModule] .onConnected() handler", ev);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
defineCE(
|
|
125
|
-
"my-tag",
|
|
126
|
-
class MyTag extends DC {
|
|
127
|
-
|
|
128
|
-
constructor(target) {
|
|
129
|
-
super(target);
|
|
130
|
-
DC.add( target, 'otherModule', new OtherModule(target) );
|
|
131
|
-
// equivalent:
|
|
132
|
-
// target._mc.otherModule = new OtherModule(target);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
onConnected(ev) {
|
|
136
|
-
console.info("[MyTag] .onConnected() handler", ev);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
let MyTag = getCE("my-tag");
|
|
143
|
-
|
|
144
|
-
document.body.append( new MyTag() );
|
|
145
|
-
```
|
|
146
|
-
|
|
147
|
-
**Hints**
|
|
148
|
-
- You can add as many other micro components to the DOM node as you like.
|
|
149
|
-
- The native web component lifecycle events will be triggered on **all** micro components.
|
|
150
|
-
- The event parameter handed over is an CustomEvent instance, that contains the original native event in its `detail` property.
|
|
151
|
-
|
|
152
|
-
## Native HTMLElement Event Handlers
|
|
153
|
-
|
|
154
|
-
Native event handlers will be auto-attached, when the method name follows one of these two schemes:
|
|
155
|
-
|
|
156
|
-
- **on[A-Z]...**: e.g. **onClick(){ ... }** will be called when the native event is triggered
|
|
157
|
-
- **one[A-Z]...**: e.g. **oneClick(){ ... }** will be called **once** only when the native event is triggered. Subsequent events will be ignored.
|
|
158
|
-
|
|
159
|
-
```javascript
|
|
160
|
-
defineCE(
|
|
161
|
-
"my-tag",
|
|
162
|
-
class MyTag extends DC {
|
|
163
|
-
|
|
164
|
-
constructor(target) {
|
|
165
|
-
super(target);
|
|
166
|
-
target.innerHTML = "Click Me";
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/*
|
|
170
|
-
native event handlers
|
|
171
|
-
*/
|
|
172
|
-
onClick(ev) {
|
|
173
|
-
console.info("MyTag .onClick() handler", ev);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
let MyTag = getCE("my-tag");
|
|
179
|
-
|
|
180
|
-
document.body.append( new MyTag() );
|
|
181
|
-
```
|
|
182
|
-
|
|
183
|
-
**Hints**
|
|
184
|
-
- The native web component lifecycle events will be triggered on **all** micro components contained in the custom element, provided the MC contains a matching named handler.
|
|
185
|
-
|
|
186
|
-
# Lifecycle Event Handlers
|
|
187
|
-
|
|
188
|
-
Currently there is only one lifecycle event handler: the **oneInit(){ ... }** method you provide with your class.
|
|
189
|
-
|
|
190
|
-
This method is triggered asynchronous via a timeout after you made a new instance of your class.
|
|
191
|
-
|
|
192
|
-
```javascript
|
|
193
|
-
defineCE(
|
|
194
|
-
"my-tag",
|
|
195
|
-
class MyTag extends DC {
|
|
196
|
-
|
|
197
|
-
constructor(target) {
|
|
198
|
-
super(target);
|
|
199
|
-
target.innerHTML = "Hello World";
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/*
|
|
203
|
-
lifecycle event handlers
|
|
204
|
-
*/
|
|
205
|
-
oneInit(ev) {
|
|
206
|
-
console.info("MyTag .onInit() handler", ev);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
);
|
|
210
|
-
|
|
211
|
-
let MyTag = getCE("my-tag");
|
|
212
|
-
|
|
213
|
-
document.body.append( new MyTag() );
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
**Hints**
|
|
217
|
-
- The native web component lifecycle events will be triggered on **all** micro components contained in the custom element, provided the specific micro component contains a matching named handler.
|
|
218
|
-
|
|
219
|
-
# Custom Events
|
|
220
|
-
|
|
221
|
-
```javascript
|
|
222
|
-
defineCE(
|
|
223
|
-
"my-tag",
|
|
224
|
-
class MyTag extends DC {
|
|
225
|
-
|
|
226
|
-
constructor(target) {
|
|
227
|
-
super(target);
|
|
228
|
-
target.innerHTML = "Hello World";
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/*
|
|
232
|
-
custom event handlers
|
|
233
|
-
*/
|
|
234
|
-
onSpecialEvent(ev) {
|
|
235
|
-
console.log('MyTag .onSpecialEvent() handler', ev);
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
let MyTag = getCE("my-tag");
|
|
241
|
-
|
|
242
|
-
document.body.append( new MyTag() );
|
|
243
|
-
|
|
244
|
-
document
|
|
245
|
-
.querySelector( 'my-tag' )
|
|
246
|
-
?._mc
|
|
247
|
-
.MyTag
|
|
248
|
-
.trigger('specialEvent');
|
|
249
|
-
|
|
250
|
-
/*
|
|
251
|
-
Alternatives:
|
|
252
|
-
*/
|
|
253
|
-
|
|
254
|
-
document
|
|
255
|
-
.querySelector( 'my-tag' )
|
|
256
|
-
.dispatchEvent('specialEvent'); // ...on all micro components contained in <my-tag>
|
|
257
|
-
|
|
258
|
-
/*
|
|
259
|
-
traversing the DOM:
|
|
260
|
-
<my-tag>
|
|
261
|
-
<my-inner-tag />
|
|
262
|
-
</my-tag>
|
|
263
|
-
*/
|
|
264
|
-
|
|
265
|
-
// <my-tag> method:
|
|
266
|
-
onSpecialEvent(ev){
|
|
267
|
-
console.log( ev.data );
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// <my-inner-tag> method:
|
|
271
|
-
sendSpecialEvent(){
|
|
272
|
-
this.trigger( 'specialEvent', "Hello World", 'u' ); // 'u' = bubble up.
|
|
273
|
-
}
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
**Hints**
|
|
277
|
-
- The event parameter handed over is an internal event instance, that contains the payload in its `data` property.
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
# Form Values
|
|
4
|
-
|
|
5
|
-
This module provides a way to bind form input elements (text, radio, checkbox, select, textarea) to a JavaScript object, enabling two-way data binding and change observation.
|
|
6
|
-
|
|
7
|
-
## formValues Function
|
|
8
|
-
Binds form elements to a target object:
|
|
9
|
-
```ts
|
|
10
|
-
formValues(targetObject: LooseObject, propertyName: string, dom: HTMLElement | ShadowRoot)
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
Example code in constructor
|
|
14
|
-
```ts
|
|
15
|
-
constructor(target: HTMLElement) {
|
|
16
|
-
super(target);
|
|
17
|
-
|
|
18
|
-
let shadow = (that as DC).target.attachShadow({ mode: 'open' });
|
|
19
|
-
shadow.innerHTML = `<style>${this.css}</style>${this.template}`;
|
|
20
|
-
|
|
21
|
-
formValues(that, 'data', shadow); // create this.data formdata observable
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
```
|
|
25
|
-
Full example [here](https://gitlab.com/twoBirds/microcomponents/-/blob/main/src/test/test/testform.ts?ref_type=heads).
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
## Functional Requirements
|
|
2
|
-
|
|
3
|
-
- I want to **enrich a standard HTMLElement instance or any object with encapsuled and modular javascript**, without having to resort to web components or big frameworks.
|
|
4
|
-
- I want to have an **interface** into this functionality that I can both tight and loosely couple.
|
|
5
|
-
- I want to **import and use Micro Components in any framework** that allows for direct DOM access.
|
|
6
|
-
- I want **a single location** in an HTMLElement instance where all this functionality is **stored and sufficiently organized**.
|
|
7
|
-
- I want to be able to use **selectors** to find those instances in the DOM.
|
|
8
|
-
- All this must stricly follow **web standards**.
|