@twobirds/microcomponents 0.0.51 → 0.0.53

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