@twobirds/microcomponents 0.1.21 → 0.2.0

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 (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +91 -92
  3. package/dist/MC.min.js +1 -345
  4. package/dist/autoload.min.js +1 -0
  5. package/dist/core/MC.d.ts +401 -0
  6. package/dist/core/MC.d.ts.map +1 -0
  7. package/dist/core/MC.js +471 -0
  8. package/dist/core/autoload.d.ts +54 -0
  9. package/dist/core/autoload.d.ts.map +1 -0
  10. package/dist/core/autoload.js +158 -0
  11. package/dist/core/elements.d.ts +232 -0
  12. package/dist/core/elements.d.ts.map +1 -0
  13. package/dist/core/elements.js +123 -0
  14. package/dist/core/events.d.ts +231 -0
  15. package/dist/core/events.d.ts.map +1 -0
  16. package/dist/core/events.js +228 -0
  17. package/dist/core/mcGuards.d.ts +49 -0
  18. package/dist/core/mcGuards.d.ts.map +1 -0
  19. package/dist/core/mcGuards.js +19 -0
  20. package/dist/elements.min.js +1 -1
  21. package/dist/events.min.js +1 -0
  22. package/dist/formValues.min.js +1 -1
  23. package/dist/mcGuards.min.js +1 -0
  24. package/dist/microcomponents.d.ts +8 -5
  25. package/dist/microcomponents.d.ts.map +1 -1
  26. package/dist/microcomponents.js +8 -5
  27. package/dist/microcomponents.min.js +1 -1
  28. package/dist/observables.min.js +1 -1
  29. package/dist/state/formValues.d.ts +70 -0
  30. package/dist/state/formValues.d.ts.map +1 -0
  31. package/dist/state/formValues.js +334 -0
  32. package/dist/state/observables.d.ts +276 -0
  33. package/dist/state/observables.d.ts.map +1 -0
  34. package/dist/state/observables.js +382 -0
  35. package/dist/state/placeholders.d.ts +62 -0
  36. package/dist/state/placeholders.d.ts.map +1 -0
  37. package/dist/state/placeholders.js +181 -0
  38. package/dist/types/mcTypes.d.ts +201 -0
  39. package/dist/types/mcTypes.d.ts.map +1 -0
  40. package/dist/types/mcTypes.js +9 -0
  41. package/dist/utils/helpers.d.ts +195 -0
  42. package/dist/utils/helpers.d.ts.map +1 -0
  43. package/dist/utils/helpers.js +340 -0
  44. package/package.json +96 -62
  45. package/dist/MC.d.ts +0 -31
  46. package/dist/MC.d.ts.map +0 -1
  47. package/dist/MC.js +0 -249
  48. package/dist/MC.ts +0 -613
  49. package/dist/MicroComponents.svg +0 -15
  50. package/dist/elements.d.ts +0 -5
  51. package/dist/elements.d.ts.map +0 -1
  52. package/dist/elements.js +0 -49
  53. package/dist/elements.ts +0 -114
  54. package/dist/events.d.ts +0 -11
  55. package/dist/events.d.ts.map +0 -1
  56. package/dist/events.js +0 -55
  57. package/dist/events.ts +0 -158
  58. package/dist/formValues.d.ts +0 -3
  59. package/dist/formValues.d.ts.map +0 -1
  60. package/dist/formValues.js +0 -156
  61. package/dist/formValues.ts +0 -371
  62. package/dist/helpers.d.ts +0 -15
  63. package/dist/helpers.d.ts.map +0 -1
  64. package/dist/helpers.js +0 -113
  65. package/dist/helpers.ts +0 -219
  66. package/dist/main.mjs +0 -1
  67. package/dist/microcomponents.ts +0 -6
  68. package/dist/observables.d.ts +0 -11
  69. package/dist/observables.d.ts.map +0 -1
  70. package/dist/observables.js +0 -228
  71. package/dist/observables.ts +0 -449
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Frank Thürigen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -12,13 +12,17 @@ There are helpers for the following functionalities:
12
12
  - **Communication** between DOM micro components is ensured via direct selected or directional bubbling CustomEvent's.
13
13
  - **Autoloading** allows for build-free websites that dynamically load JS requirements into DOM HTMLElements.
14
14
 
15
- The distinguishing feature - compared to other frameworks - is its **minimalism**, **portability** and **granular modularization**. In an almost literal sense MCs work like childrens building blocks, where a chest full of unassuming parts lets you compose whatever functionality lies in your imagination.
15
+ The distinguishing feature - compared to other frameworks - is its **minimalism**, **portability** and **granular modularization**. In an almost literal sense MCs work like childrens building blocks, where a chest full of unassuming parts lets you compose whatever functionality lies in your imagination.
16
16
 
17
17
  **You work with one of the established frameworks?** You can still put this hands-on tool in your tool belt. You then have a plugin fallback solution for when your FW fails you or lacks functionality.
18
18
 
19
19
  ## Status
20
20
 
21
- In [manual testing](https://twobirds.gitlab.io/microcomponents/test/test.html) ( also a speed test).
21
+ Automatic tests added.
22
+
23
+ [manual testing](https://twobirds.gitlab.io/microcomponents/test/index.html) ( also a speed test).
24
+
25
+ [demo shop (autoload enabled)](https://twobirds.gitlab.io/microcomponents/shop/index.html).
22
26
 
23
27
  Check the [typedoc API reference](https://twobirds.gitlab.io/microcomponents/typedoc/index.html) if you want to drill into the source code.
24
28
 
@@ -31,140 +35,143 @@ The progress of coding is being streamed on [twitch](https://twitch.tv/frankieth
31
35
  **Hint:** The following code only shows how Micro Components are stored in the DOM.
32
36
 
33
37
  html before:
38
+
34
39
  ```HTML
35
40
  <div></div>
36
41
  ```
37
42
 
38
43
  code:
44
+
39
45
  ```javascript
40
46
  // create a custom micro component class
41
- class MyMC extends DC{
42
-
43
- constructor( target ){
44
- super( target );
47
+ class MyMC extends DC {
48
+ constructor(target) {
49
+ super(target);
45
50
  }
46
51
 
47
- helloWorld(){
48
- console.log( 'Hello World' );
52
+ helloWorld() {
53
+ console.log('Hello World');
49
54
  }
50
-
51
55
  }
52
56
 
53
57
  // get some element from the DOM
54
58
  const element = document.querySelector('div');
55
59
 
56
- // Add the custom micro component instance to the target element
57
- DC.add(
58
- element,
59
- 'myMC',
60
- new MyMC( element )
61
- );
62
-
63
- // Hello World
64
- element
65
- ._mc
66
- .myMC
67
- .helloWorld();
60
+ if (element) {
61
+ // Add the custom micro component instance to the target element
62
+ const host = DC.add(element, 'myMC', new MyMC(element));
63
+
64
+ // Hello World
65
+ host._mc.myMC.helloWorld();
66
+ }
68
67
  ```
69
68
 
70
69
  html after:
70
+
71
71
  ```HTML
72
72
  <div data-mc></div>
73
73
  ```
74
+
74
75
  The `data-mc` **attribute** indicates that this **HTML element contains at least one micro component**. This is needed for the selectors.
75
76
 
76
77
  The `_mc` **property** is the only interference with the DOM, so any other system should be happy to work with this.
77
78
 
78
-
79
79
  ### **Web Components / Custom Elements**
80
80
 
81
+ You can define a custom element using a micro component as its primary functional instance. You are still free to add many more micro components at runtime.
82
+
81
83
  code:
84
+
82
85
  ```javascript
83
86
  // create a custom micro component class
84
- class MyComponent extends DC{
85
-
86
- constructor( target ){
87
- super( target );
87
+ class MyComponent extends DC {
88
+ constructor(target) {
89
+ super(target);
88
90
  }
89
91
 
90
92
  // this event handler is attached automatically
91
- onClick(){
92
- console.log( '<my-component> clicked!' );
93
+ onClick() {
94
+ console.log('<my-component> clicked!');
93
95
  }
94
96
  }
95
97
 
96
- defineCE( 'my-component', MyComponent );
98
+ defineCE('my-component', MyComponent);
97
99
  ```
98
100
 
99
101
  after: you can use ...
102
+
100
103
  ```HTML
101
104
  <my-component></my-component>
102
105
  ```
106
+
103
107
  ... in your template.
104
108
 
105
109
  Or you can construct it programmatically:
110
+
106
111
  ```javascript
107
112
  const myComponentClass = getCE('my-component');
108
113
  const body = document.body;
109
- body.append( new myComponentClass() );
114
+ body.append(new myComponentClass());
110
115
  ```
111
116
 
112
117
  ### **State and 1-way-binding**
113
118
 
119
+ Declare states and directly connect them to DOM placeholders:
114
120
  code:
121
+
115
122
  ```javascript
116
123
  // create a custom micro component class
117
- class MyMC extends DC{
124
+ class MyMC extends DC {
125
+ state = { text: 'Hello world!' };
118
126
 
119
- constructor( target ){
120
- super( target );
121
- this.state = { text: 'Hello world!' };
127
+ constructor(target) {
128
+ super(target);
122
129
 
123
130
  // observe one property ...
124
- observe( this, 'state' );
125
-
126
- // or observe all properties defined so far
127
- observe( this );
131
+ observe(this, 'state');
132
+
133
+ // alternatively: observe all properties defined so far
134
+ // observe( this ); // omit property name
128
135
 
129
136
  this.target.innerHTML = '{text}';
130
137
 
131
138
  // one way binding
132
- this.state.bind( target ); // links the state to DOM placeholders
139
+ this.state.bind(target); // links the state to DOM placeholders
133
140
 
134
141
  // attach your own callbacks
135
- this.state.subscribe( (value) => {
136
- console.log(value);
142
+ this.state.subscribe((value) => {
143
+ console.log(value);
137
144
  });
138
145
 
139
146
  // now simply changing the state will change the DOM
140
- this.state.text = 'Hallo Welt';
147
+ this.state.text = 'Hallo Welt'; // replaces DOM placeholder, also triggers console.log()
141
148
  }
142
-
143
149
  }
144
150
  ```
145
151
 
146
152
  ### **Forms and 2-way-binding**
147
153
 
154
+ Similar to observables above, you can 2-way-bind an observable object to form input fields. Changes in the object properties trigger input field changes and vice versa.
155
+
148
156
  code:
157
+
149
158
  ```javascript
150
159
  // create a custom micro component class
151
- class MyMC extends DC{
152
-
153
- constructor( target ){
154
- super( target );
160
+ class MyMC extends DC {
161
+ constructor(target) {
162
+ super(target);
155
163
 
156
164
  this.target.innerHTML = /*HTML*/ `
157
165
  <form>
158
166
  <input name="textinput" value="Hallo Welt!"/>
159
- </form>`;
160
-
167
+ </form>`;
168
+
161
169
  // link the form property to the DOM input fields
162
- formValues( this, 'form', this.target );
163
-
170
+ formValues(this, 'form', this.target);
171
+
164
172
  // now simply changing the form property will change the DOM input fields
165
173
  this.form.textinput = 'Hallo Welt';
166
174
  }
167
-
168
175
  }
169
176
  ```
170
177
 
@@ -172,60 +179,60 @@ class MyMC extends DC{
172
179
 
173
180
  #### Native Events
174
181
 
182
+ Events and there handlers are defined and triggered inside the system automatically. You can use events separately in vanilla JS to communicate with micro components.
183
+
175
184
  code:
185
+
176
186
  ```javascript
177
187
  // create a custom micro component class
178
- class MyMC extends DC{
179
-
180
- constructor( target ){
181
- super( target );
188
+ class MyMC extends DC {
189
+ constructor(target) {
190
+ super(target);
182
191
 
183
192
  // attach event handler programatically
184
- let onHoverHandler = this.on( 'hover', () => {
193
+ let onHoverHandler = this.on('hover', () => {
185
194
  // ...
186
195
  });
187
196
 
188
197
  // remove event handler
189
- this.off( 'hover', onHoverHandler );
198
+ this.off('hover', onHoverHandler);
190
199
  }
191
200
 
192
201
  // this event handler is attached automatically
193
- onClick(){
194
- console.log( 'HTMLElement clicked!' );
202
+ onClick() {
203
+ console.log('HTMLElement clicked!');
195
204
  }
196
205
 
197
206
  // this event handler is attached automatically
198
- oneClick(){
199
- console.log( 'HTMLElement clicked! ( only fires once )' );
207
+ oneClick() {
208
+ console.log('HTMLElement clicked! ( only fires once )');
200
209
  }
201
-
202
210
  }
203
211
  ```
204
212
 
205
213
  #### Custom Events
206
214
 
207
215
  code:
216
+
208
217
  ```javascript
209
218
  // create a custom micro component class
210
- class MyMC extends DC{
211
-
212
- constructor( target ){
213
- super( target );
219
+ class MyMC extends DC {
220
+ constructor(target) {
221
+ super(target);
214
222
 
215
223
  payload = {
216
- test: 42
224
+ test: 42,
217
225
  };
218
226
 
219
- setTimeout( () => {
220
- this.trigger('customEvent', payload );
227
+ setTimeout(() => {
228
+ this.trigger('customEvent', payload);
221
229
  });
222
230
  }
223
231
 
224
232
  // this event handler is attached automatically
225
- onCustomEvent( ev ){
226
- console.log( 'onCustomEvent called with', ev.data.test ); // "42"
233
+ onCustomEvent(ev) {
234
+ console.log('onCustomEvent called with', ev.data.test); // "42"
227
235
  }
228
-
229
236
  }
230
237
  ```
231
238
 
@@ -237,7 +244,7 @@ MCs provide a runtime app structure that is directly linked to the browser DOM.
237
244
 
238
245
  In general this is a **HTML / Web Standards first** system. There is almost no abstraction, especially not for templating, except state binding to the DOM via simple placeholders.
239
246
 
240
- It has no interference with other frameworks, since it creates a second layer that hovers above the DOM. So what you intended to work as an add-on to React, is usable e.g. in Angular also.
247
+ It has no interference with other frameworks, since it creates a second layer that hovers above the DOM. So what you intended to work as an add-on to React, is usable e.g. in Angular also.
241
248
 
242
249
  And, of course, you can use it as your main framework using its custom web component functionality.
243
250
 
@@ -249,27 +256,26 @@ Most of all this system by design **allows for outsourcing without sharing the m
249
256
 
250
257
  Finally it allows for a clear distinction between `Junior`, `Senior` and `Architect` roles in a project. No more hiring junior programmers with 5 years experience in 50 tools under their belt. A junior in this system is somebody who likes HTML, CSS and JS/TS - nothing more. Teaching all of this system starting at zero takes 1 day. The rest is finger muscle memory and learning/knowing web standards.
251
258
 
252
-
253
259
  ## Documentation
254
260
 
255
261
  This repository exports 4 independent functionalities:
256
262
 
257
263
  1. **[Micro Components](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads)** contains the **MC** and **DC** classes you can use as super classes.
258
264
 
265
+ 2. **[Elements](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/elements.md?ref_type=heads)** lets you define and use your own native web components. Uses (1).
259
266
 
260
- 2. **[Elements](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/elements.md?ref_type=heads)** lets you define and use your own native web components. Uses (1).
261
- - [Basic Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/elements.md?ref_type=heads#create-a-custom-element).
262
- - [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
267
+ - [Basic Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/elements.md?ref_type=heads#create-a-custom-element).
268
+ - [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
263
269
 
270
+ 3. **[Observables](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/observables.md?ref_type=heads)** add **observability** and **run time type safety** to object properties. Also they provide **1-way binding** to placeholders in your template HTML.
264
271
 
265
- 3. **[Observables](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/observables.md?ref_type=heads)** add **observability** and **run time type safety** to object properties. Also they provide **1-way binding** to placeholders in your template HTML.
266
- - [Basic Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/observables.md?ref_type=heads#example)
267
- - [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
272
+ - [Basic Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/observables.md?ref_type=heads#example)
273
+ - [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
268
274
 
275
+ 4. **[Formvalues](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/formvalues.md?ref_type=heads)** gives you **2-way binding** between a HTML form and an observable object. Uses (3).
269
276
 
270
- 4. **[Formvalues](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/formvalues.md?ref_type=heads)** gives you **2-way binding** between a HTML form and an observable object. Uses (3).
271
- - [Example Code](https://gitlab.com/twoBirds/microcomponents/-/blob/main/src/test/test/testform.ts?ref_type=heads)
272
- - [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
277
+ - [Example Code](https://gitlab.com/twoBirds/microcomponents/-/blob/main/src/test/test/testform.ts?ref_type=heads)
278
+ - [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
273
279
 
274
280
  Also there is a bundle file that contains all of the above.
275
281
 
@@ -281,19 +287,14 @@ There are a few potentially unique aspects of this micro components system that
281
287
 
282
288
  - **Pure OOP Approach**: The system explicitly positions itself as a strict object-oriented alternative to the functional approaches that dominate many modern frameworks.
283
289
 
284
-
285
290
  - **Minimal Interference**: The system has minimal DOM interference, only adding _mc property to DOM nodes that contain code. This makes it unusually compatible with other frameworks or libraries.
286
291
 
287
-
288
292
  - **Hierarchical Component Traversal**: The built-in ancestor/closest/child/descendant traversal methods provide a clean way to navigate component relationships.
289
293
 
290
-
291
294
  - **Direct DOM Integration**: Unlike virtual DOM-based frameworks, this approach works directly with the actual DOM while still providing component encapsulation.
292
295
 
293
-
294
296
  - **Outsourcing Potential**: Your external coders do not need to access your code repository or your toolchain.
295
297
 
296
-
297
298
  The strongest argument might be for developers who prefer OOP, want minimal framework lock-in, and need a lightweight solution that works well with existing code or other libraries.
298
299
 
299
300
  ## Contact
@@ -310,6 +311,4 @@ I decided to extract this functionality from the [twoBirds framework](https://ww
310
311
 
311
312
  Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.
312
313
 
313
- **This is a massive undertaking.** MCs are just the foundation of what I do. I am about to dump [20+ years of javascript programming](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/magic.md?ref_type=heads#things-i-already-did-with-this-in-my-own-framework-twobirds-or-in-apps-that-i-developed-with-it) into open source libraries, so feel free to [fund this](https://www.gofundme.com/f/nachhaltige-programmierung). The better this is funded, the faster it will be done. Given enough resources, I will start a crowdfunded company that will develop a new open source ecosystem for javascript/typescript programming.
314
-
315
-
314
+ **This is a massive undertaking.** MCs are just the foundation of what I do. I am about to dump [20+ years of javascript programming](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/magic.md?ref_type=heads#things-i-already-did-with-this-in-my-own-framework-twobirds-or-in-apps-that-i-developed-with-it) into open source libraries, so feel free to [fund this](https://www.gofundme.com/f/nachhaltige-programmierung). The better this is funded, the faster it will be done. Given enough resources, I will start a crowdfunded company that will develop a new open source ecosystem for javascript/typescript programming.