@twobirds/microcomponents 0.1.20 → 0.1.23

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 (66) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +97 -102
  3. package/dist/MC.min.js +1 -342
  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 +95 -61
  45. package/dist/MC.d.ts +0 -39
  46. package/dist/MC.d.ts.map +0 -1
  47. package/dist/MC.js +0 -299
  48. package/dist/MC.ts +0 -457
  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 -50
  53. package/dist/elements.ts +0 -94
  54. package/dist/formValues.d.ts +0 -3
  55. package/dist/formValues.d.ts.map +0 -1
  56. package/dist/formValues.js +0 -158
  57. package/dist/formValues.ts +0 -213
  58. package/dist/helpers.d.ts +0 -14
  59. package/dist/helpers.d.ts.map +0 -1
  60. package/dist/helpers.js +0 -111
  61. package/dist/helpers.ts +0 -138
  62. package/dist/microcomponents.ts +0 -6
  63. package/dist/observables.d.ts +0 -11
  64. package/dist/observables.d.ts.map +0 -1
  65. package/dist/observables.js +0 -228
  66. package/dist/observables.ts +0 -338
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,15 +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
- For a quick glance try [this](https://gitlab.com/twoBirds/mc_template_webcomponents)...
21
+ Automatic tests added.
22
22
 
23
- In [manual testing](https://twobirds.gitlab.io/microcomponents/test/test.html) ( also a speed test).
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).
24
26
 
25
27
  Check the [typedoc API reference](https://twobirds.gitlab.io/microcomponents/typedoc/index.html) if you want to drill into the source code.
26
28
 
@@ -30,142 +32,146 @@ The progress of coding is being streamed on [twitch](https://twitch.tv/frankieth
30
32
 
31
33
  ### **Micro Components**
32
34
 
33
- **Hint:** This code only shows how Micro Components are stored in the DOM.
35
+ **Hint:** The following code only shows how Micro Components are stored in the DOM.
36
+
37
+ html before:
34
38
 
35
- before:
36
39
  ```HTML
37
40
  <div></div>
38
41
  ```
39
42
 
40
43
  code:
44
+
41
45
  ```javascript
42
46
  // create a custom micro component class
43
- class MyMC extends DC{
44
-
45
- constructor( target ){
46
- super( target );
47
+ class MyMC extends DC {
48
+ constructor(target) {
49
+ super(target);
47
50
  }
48
51
 
49
- helloWorld(){
50
- console.log( 'Hello World' );
52
+ helloWorld() {
53
+ console.log('Hello World');
51
54
  }
52
-
53
55
  }
54
56
 
55
57
  // get some element from the DOM
56
58
  const element = document.querySelector('div');
57
59
 
58
- // Add the custom micro component instance to the target element
59
- DC.add(
60
- element,
61
- 'myMC',
62
- new MyMC( element )
63
- );
64
-
65
- // Hello World
66
- element
67
- ._mc
68
- .myMC
69
- .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
+ }
70
67
  ```
71
68
 
72
- after:
69
+ html after:
70
+
73
71
  ```HTML
74
72
  <div data-mc></div>
75
73
  ```
74
+
76
75
  The `data-mc` **attribute** indicates that this **HTML element contains at least one micro component**. This is needed for the selectors.
77
76
 
78
77
  The `_mc` **property** is the only interference with the DOM, so any other system should be happy to work with this.
79
78
 
80
-
81
79
  ### **Web Components / Custom Elements**
82
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
+
83
83
  code:
84
+
84
85
  ```javascript
85
86
  // create a custom micro component class
86
- class MyComponent extends DC{
87
-
88
- constructor( target ){
89
- super( target );
87
+ class MyComponent extends DC {
88
+ constructor(target) {
89
+ super(target);
90
90
  }
91
91
 
92
92
  // this event handler is attached automatically
93
- onClick(){
94
- console.log( '<my-component> clicked!' );
93
+ onClick() {
94
+ console.log('<my-component> clicked!');
95
95
  }
96
96
  }
97
97
 
98
- defineCE( 'my-component', MyComponent );
98
+ defineCE('my-component', MyComponent);
99
99
  ```
100
100
 
101
101
  after: you can use ...
102
+
102
103
  ```HTML
103
104
  <my-component></my-component>
104
105
  ```
106
+
105
107
  ... in your template.
106
108
 
107
109
  Or you can construct it programmatically:
110
+
108
111
  ```javascript
109
112
  const myComponentClass = getCE('my-component');
110
113
  const body = document.body;
111
- body.append( new myComponentClass() );
114
+ body.append(new myComponentClass());
112
115
  ```
113
116
 
114
117
  ### **State and 1-way-binding**
115
118
 
119
+ Declare states and directly connect them to DOM placeholders:
116
120
  code:
121
+
117
122
  ```javascript
118
123
  // create a custom micro component class
119
- class MyMC extends DC{
124
+ class MyMC extends DC {
125
+ state = { text: 'Hello world!' };
120
126
 
121
- constructor( target ){
122
- super( target );
123
- this.state = { text: 'Hello world!' };
127
+ constructor(target) {
128
+ super(target);
124
129
 
125
130
  // observe one property ...
126
- observe( this, 'state' );
127
-
128
- // or observe all properties defined so far
129
- observe( this );
131
+ observe(this, 'state');
132
+
133
+ // alternatively: observe all properties defined so far
134
+ // observe( this ); // omit property name
130
135
 
131
136
  this.target.innerHTML = '{text}';
132
137
 
133
138
  // one way binding
134
- this.state.bind( target ); // links the state to DOM placeholders
139
+ this.state.bind(target); // links the state to DOM placeholders
135
140
 
136
141
  // attach your own callbacks
137
- this.state.observe( (value) => {
138
- console.log(value);
142
+ this.state.subscribe((value) => {
143
+ console.log(value);
139
144
  });
140
145
 
141
146
  // now simply changing the state will change the DOM
142
- this.state.text = 'Hallo Welt';
147
+ this.state.text = 'Hallo Welt'; // replaces DOM placeholder, also triggers console.log()
143
148
  }
144
-
145
149
  }
146
150
  ```
147
151
 
148
152
  ### **Forms and 2-way-binding**
149
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
+
150
156
  code:
157
+
151
158
  ```javascript
152
159
  // create a custom micro component class
153
- class MyMC extends DC{
160
+ class MyMC extends DC {
161
+ constructor(target) {
162
+ super(target);
154
163
 
155
- constructor( target ){
156
- super( target );
164
+ this.target.innerHTML = /*HTML*/ `
165
+ <form>
166
+ <input name="textinput" value="Hallo Welt!"/>
167
+ </form>`;
157
168
 
158
- this.form = { textinput: 'Hello world!' };
159
-
160
- this.target.innerHTML = '<input name="textinput" />';
161
-
162
169
  // link the form property to the DOM input fields
163
- formValues( this, 'form', this.target );
164
-
170
+ formValues(this, 'form', this.target);
171
+
165
172
  // now simply changing the form property will change the DOM input fields
166
173
  this.form.textinput = 'Hallo Welt';
167
174
  }
168
-
169
175
  }
170
176
  ```
171
177
 
@@ -173,63 +179,60 @@ class MyMC extends DC{
173
179
 
174
180
  #### Native Events
175
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
+
176
184
  code:
185
+
177
186
  ```javascript
178
187
  // create a custom micro component class
179
- class MyMC extends DC{
180
-
181
- constructor( target ){
182
- super( target );
188
+ class MyMC extends DC {
189
+ constructor(target) {
190
+ super(target);
183
191
 
184
- // attach event handlers programatically
185
- const onClickHandler = this.on( 'click', () => {
192
+ // attach event handler programatically
193
+ let onHoverHandler = this.on('hover', () => {
186
194
  // ...
187
195
  });
188
196
 
189
- this.one( 'click', () => {
190
- // ...
191
- });
192
-
193
- this.off( 'click', onClickHandler );
197
+ // remove event handler
198
+ this.off('hover', onHoverHandler);
194
199
  }
195
200
 
196
201
  // this event handler is attached automatically
197
- onClick(){
198
- console.log( 'HTMLElement clicked!' );
202
+ onClick() {
203
+ console.log('HTMLElement clicked!');
199
204
  }
200
205
 
201
206
  // this event handler is attached automatically
202
- oneClick(){
203
- console.log( 'HTMLElement clicked! ( only fires once )' );
207
+ oneClick() {
208
+ console.log('HTMLElement clicked! ( only fires once )');
204
209
  }
205
-
206
210
  }
207
211
  ```
208
212
 
209
213
  #### Custom Events
210
214
 
211
215
  code:
216
+
212
217
  ```javascript
213
218
  // create a custom micro component class
214
- class MyMC extends DC{
215
-
216
- constructor( target ){
217
- super( target );
219
+ class MyMC extends DC {
220
+ constructor(target) {
221
+ super(target);
218
222
 
219
223
  payload = {
220
- test: 42
224
+ test: 42,
221
225
  };
222
226
 
223
- setTimeout( () => {
224
- this.trigger('customEvent', payload );
227
+ setTimeout(() => {
228
+ this.trigger('customEvent', payload);
225
229
  });
226
230
  }
227
231
 
228
232
  // this event handler is attached automatically
229
- onCustomEvent( ev ){
230
- console.log( 'onCustomEvent called with', ev.data.test ); // "42"
233
+ onCustomEvent(ev) {
234
+ console.log('onCustomEvent called with', ev.data.test); // "42"
231
235
  }
232
-
233
236
  }
234
237
  ```
235
238
 
@@ -241,7 +244,7 @@ MCs provide a runtime app structure that is directly linked to the browser DOM.
241
244
 
242
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.
243
246
 
244
- 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.
245
248
 
246
249
  And, of course, you can use it as your main framework using its custom web component functionality.
247
250
 
@@ -253,27 +256,26 @@ Most of all this system by design **allows for outsourcing without sharing the m
253
256
 
254
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.
255
258
 
256
-
257
259
  ## Documentation
258
260
 
259
261
  This repository exports 4 independent functionalities:
260
262
 
261
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.
262
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).
263
266
 
264
- 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).
265
- - [Basic Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/elements.md?ref_type=heads#create-a-custom-element).
266
- - [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)
267
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.
268
271
 
269
- 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.
270
- - [Basic Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/observables.md?ref_type=heads#example)
271
- - [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)
272
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).
273
276
 
274
- 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).
275
- - [Example Code](https://gitlab.com/twoBirds/microcomponents/-/blob/main/src/test/test/testform.ts?ref_type=heads)
276
- - [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)
277
279
 
278
280
  Also there is a bundle file that contains all of the above.
279
281
 
@@ -285,19 +287,14 @@ There are a few potentially unique aspects of this micro components system that
285
287
 
286
288
  - **Pure OOP Approach**: The system explicitly positions itself as a strict object-oriented alternative to the functional approaches that dominate many modern frameworks.
287
289
 
288
-
289
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.
290
291
 
291
-
292
292
  - **Hierarchical Component Traversal**: The built-in ancestor/closest/child/descendant traversal methods provide a clean way to navigate component relationships.
293
293
 
294
-
295
294
  - **Direct DOM Integration**: Unlike virtual DOM-based frameworks, this approach works directly with the actual DOM while still providing component encapsulation.
296
295
 
297
-
298
296
  - **Outsourcing Potential**: Your external coders do not need to access your code repository or your toolchain.
299
297
 
300
-
301
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.
302
299
 
303
300
  ## Contact
@@ -314,6 +311,4 @@ I decided to extract this functionality from the [twoBirds framework](https://ww
314
311
 
315
312
  Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.
316
313
 
317
- **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.
318
-
319
-
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.