@twobirds/microcomponents 0.0.66 → 0.0.67

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.
Files changed (93) hide show
  1. package/README.md +10 -6
  2. package/assets/{test.html → test/test.html} +3 -3
  3. package/package.json +4 -4
  4. package/public/documentation/MC.md +588 -0
  5. package/public/documentation/ajaxian-1.png +0 -0
  6. package/public/documentation/ajaxian-2.png +0 -0
  7. package/public/documentation/ajaxian-3.png +0 -0
  8. package/public/documentation/elements.md +278 -0
  9. package/public/documentation/functional_requirements.md +8 -0
  10. package/public/documentation/history.md +436 -0
  11. package/public/documentation/magic.md +29 -0
  12. package/public/documentation/observables.md +107 -0
  13. package/public/documentation/rnd0023-1.jpg +0 -0
  14. package/public/documentation/rnd0023-2.jpg +0 -0
  15. package/public/documentation/rnd0023-3.jpg +0 -0
  16. package/public/documentation/tB_react.md +207 -0
  17. package/public/documentation/usage.md +142 -0
  18. package/public/documentation/why.md +25 -0
  19. package/public/fiddle/MicroComponents.svg +15 -0
  20. package/public/fiddle/fiddle.css +0 -0
  21. package/public/fiddle/fiddle.js +0 -0
  22. package/public/fiddle/index.html +0 -0
  23. package/public/src/MC.ts +605 -0
  24. package/public/src/McEvent.ts +96 -0
  25. package/public/src/elements.ts +76 -0
  26. package/public/src/formValues.ts +233 -0
  27. package/public/src/helpers.ts +149 -0
  28. package/public/src/microcomponents.ts +8 -0
  29. package/public/src/observables.ts +401 -0
  30. package/public/src/selectors.ts +1634 -0
  31. package/public/src/test.ts +193 -0
  32. package/public/test/child.js +15 -0
  33. package/public/test/child.js.map +1 -0
  34. package/public/test/grandchild.js +15 -0
  35. package/public/test/grandchild.js.map +1 -0
  36. package/public/test/grandparent.css +13 -0
  37. package/public/test/grandparent.js +1 -0
  38. package/public/test/grandparent.js.map +1 -0
  39. package/public/test/greatgrandchild.js +29 -0
  40. package/public/test/greatgrandchild.js.map +1 -0
  41. package/public/test/my-tag.css +19 -0
  42. package/public/test/parent.js +15 -0
  43. package/public/test/parent.js.map +1 -0
  44. package/public/test/test.html +27 -0
  45. package/public/test/testform.js +1 -0
  46. package/public/test/testform.js.map +1 -0
  47. package/public/test/testmc.js +10 -0
  48. package/public/test/testmc.js.map +1 -0
  49. package/public/typedoc/.nojekyll +1 -0
  50. package/public/{classes → typedoc/classes}/MC.DC.html +2 -2
  51. package/public/{classes → typedoc/classes}/MC.MC.html +2 -2
  52. package/public/{classes → typedoc/classes}/MC.McBase.html +2 -2
  53. package/public/{classes → typedoc/classes}/MC.McEvent.html +2 -2
  54. package/public/{functions → typedoc/functions}/MC.addListener.html +1 -1
  55. package/public/{functions → typedoc/functions}/MC.autoload.html +1 -1
  56. package/public/{functions → typedoc/functions}/MC.removeListener.html +1 -1
  57. package/public/{functions → typedoc/functions}/elements.defineCE.html +1 -1
  58. package/public/{functions → typedoc/functions}/elements.getCE.html +1 -1
  59. package/public/{functions → typedoc/functions}/formValues.formValues.html +1 -1
  60. package/public/{functions → typedoc/functions}/observables.observe.html +1 -1
  61. package/public/{functions → typedoc/functions}/selectors._d.html +1 -1
  62. package/public/{functions → typedoc/functions}/selectors._t.html +1 -1
  63. package/public/{index.html → typedoc/index.html} +8 -6
  64. package/public/{interfaces → typedoc/interfaces}/MC.HTMLMcElement.html +2 -2
  65. package/public/{interfaces → typedoc/interfaces}/selectors.DSelector.html +2 -2
  66. package/public/{interfaces → typedoc/interfaces}/selectors.TSelector.html +2 -2
  67. package/public/typedoc/media/MicroComponents.svg +15 -0
  68. package/public/{modules → typedoc/modules}/MC.html +1 -1
  69. package/public/{modules → typedoc/modules}/elements.html +1 -1
  70. package/public/{modules → typedoc/modules}/formValues.html +1 -1
  71. package/public/{modules → typedoc/modules}/observables.html +1 -1
  72. package/public/{modules → typedoc/modules}/selectors.html +1 -1
  73. package/public/{types → typedoc/types}/observables.Observable.html +1 -1
  74. package/public/{types → typedoc/types}/selectors.selection.html +1 -1
  75. package/public/{types → typedoc/types}/selectors.singleSelector.html +1 -1
  76. package/src/test/testmc.ts +0 -6
  77. package/typedoc.json +1 -1
  78. package/webpack.config.js +1 -1
  79. package/assets/3d.html +0 -42
  80. package/public/microcomponents.min.js +0 -1
  81. /package/assets/{grandparent.css → test/grandparent.css} +0 -0
  82. /package/assets/{my-tag.css → test/my-tag.css} +0 -0
  83. /package/dist/{microcomponents.min.js → microcomponents.js} +0 -0
  84. /package/public/{media/MicroComponents.svg → MicroComponents.svg} +0 -0
  85. /package/public/{assets → typedoc/assets}/highlight.css +0 -0
  86. /package/public/{assets → typedoc/assets}/icons.js +0 -0
  87. /package/public/{assets → typedoc/assets}/icons.svg +0 -0
  88. /package/public/{assets → typedoc/assets}/main.js +0 -0
  89. /package/public/{assets → typedoc/assets}/navigation.js +0 -0
  90. /package/public/{assets → typedoc/assets}/search.js +0 -0
  91. /package/public/{assets → typedoc/assets}/style.css +0 -0
  92. /package/public/{hierarchy.html → typedoc/hierarchy.html} +0 -0
  93. /package/public/{modules.html → typedoc/modules.html} +0 -0
@@ -0,0 +1,278 @@
1
+ ![logo](./MicroComponents.svg)
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
+ defineCE(
25
+ // equivalent to and internally using customElementRegistry.define()
26
+ "my-tag",
27
+ class extends DC {
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 _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 `<my-tag>._mc`** which contains your class instance.
61
+ - Also the custom element then has an **attribute '_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
+
66
+ ## Web Component Lifecycle Events
67
+
68
+ ```javascript
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"),
102
+ myTag = new MyTag();
103
+
104
+ document.body.append( myTag );
105
+ ```
106
+
107
+ You can use your Web Component constructor to add other modules to the `<my-tag>` DOM node:
108
+
109
+ ```javascript
110
+
111
+ class OtherModule extends DC {
112
+
113
+ constructor(target) {
114
+ super(target);
115
+ }
116
+
117
+ onConnected(ev) {
118
+ console.info("[OtherModule] .onConnected() handler", ev);
119
+ }
120
+ }
121
+
122
+ defineCE(
123
+ "my-tag",
124
+ class MyTag extends DC {
125
+
126
+ constructor(target) {
127
+ super(target);
128
+ DC.add( target, 'otherModule', new OtherModule(target) );
129
+ // equivalent:
130
+ // target._mc.otherModule = new OtherModule(target);
131
+ }
132
+
133
+ onConnected(ev) {
134
+ console.info("[MyTag] .onConnected() handler", ev);
135
+ }
136
+ }
137
+ );
138
+
139
+
140
+ let MyTag = getCE("my-tag");
141
+
142
+ document.body.append( new MyTag() );
143
+ ```
144
+
145
+ ### **Hints**
146
+ - You can add as many other micro components to the DOM node as you like.
147
+ - The native web component lifecycle events will be triggered on **all** micro components.
148
+ - The event parameter handed over is an internal event instance, that contains the original native event in its `data` property.
149
+
150
+ ## Native Event Handlers
151
+
152
+ Native event handlers will be auto-attached, when the method name follows one of these two schemes:
153
+
154
+ - **on[A-Z]...**: e.g. **onClick(){ ... }** will be called when the native event is triggered
155
+ - **one[A-Z]...**: e.g. **oneClick(){ ... }** will be called **once** only when the native event is triggered. Subsequent events will be ignored.
156
+
157
+ ```javascript
158
+ defineCE(
159
+ "my-tag",
160
+ class MyTag extends DC {
161
+
162
+ constructor(target) {
163
+ super(target);
164
+ target.innerHTML = "Click Me";
165
+ }
166
+
167
+ /*
168
+ native event handlers
169
+ */
170
+ onClick(ev) {
171
+ console.info("MyTag .onClick() handler", ev);
172
+ }
173
+ }
174
+ );
175
+
176
+ let MyTag = getCE("my-tag");
177
+
178
+ document.body.append( new MyTag() );
179
+ ```
180
+
181
+ ### **Hints**
182
+ - 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.
183
+ - The event parameter handed over is an internal event instance, that contains the original native event in its .data property.
184
+
185
+ ## Lifecycle Event Handlers
186
+
187
+ Currently there is only one lifecycle event handler: the **oneInit(){ ... }** method you provide with your class.
188
+
189
+ This method is triggered asynchronous via a timeout after you made a new instance of your class.
190
+
191
+ ```javascript
192
+ defineCE(
193
+ "my-tag",
194
+ class MyTag extends DC {
195
+
196
+ constructor(target) {
197
+ super(target);
198
+ target.innerHTML = "Hello World";
199
+ }
200
+
201
+ /*
202
+ lifecycle event handlers
203
+ */
204
+ oneInit(ev) {
205
+ console.info("MyTag .onInit() handler", ev);
206
+ }
207
+ }
208
+ );
209
+
210
+ let MyTag = getCE("my-tag");
211
+
212
+ document.body.append( new MyTag() );
213
+ ```
214
+
215
+ ### **Hints**
216
+ - 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.
217
+ - The event parameter handed over is an internal event instance that contains no data.
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
+ ?._mc
257
+ .trigger('specialEvent'); // ...on all micro components contained in <my-tag>
258
+
259
+ /*
260
+ traversing the DOM:
261
+ <my-tag>
262
+ <my-inner-tag />
263
+ </my-tag>
264
+ */
265
+
266
+ // <my-tag> method:
267
+ onSpecialEvent(ev){
268
+ console.log( ev.data );
269
+ }
270
+
271
+ // <my-inner-tag> method:
272
+ sendSpecialEvent(){
273
+ this.trigger( 'specialEvent', "Hello World", 'u' ); // 'u' = bubble up.
274
+ }
275
+ ```
276
+
277
+ ### **Hints**
278
+ - The event parameter handed over is an internal event instance, that contains the payload in its .data property.
@@ -0,0 +1,8 @@
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**.