@twobirds/microcomponents 0.0.72 → 0.0.75
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/README.md +35 -24
- package/assets/documentation/MC.md +2 -2
- package/assets/documentation/MicroComponents.svg +15 -0
- package/assets/documentation/elements.md +18 -16
- package/assets/documentation/formvalues.md +5 -26
- package/assets/documentation/observables.md +18 -24
- package/assets/test/test.html +5 -4
- package/assets/test/testform.json +27 -0
- package/dist/MC.d.ts +2 -2
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.min.js +2 -1
- package/dist/MC.ts +6 -3
- package/dist/elements.min.js +1 -1
- package/dist/formValues.d.ts.map +1 -1
- package/dist/formValues.ts +0 -14
- package/dist/formvValues.min.js +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.d.ts.map +1 -1
- package/dist/observables.min.js +1 -1
- package/dist/observables.ts +177 -169
- package/dist/selectors.min.js +1 -1
- package/package.json +1 -1
- package/public/MC.d.ts +2 -2
- package/public/MC.d.ts.map +1 -1
- package/public/MC.js +4 -3
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +2 -1
- package/public/MC.ts +6 -3
- package/public/documentation/MC.md +2 -2
- package/public/documentation/MicroComponents.svg +15 -0
- package/public/documentation/elements.md +18 -16
- package/public/documentation/formvalues.md +5 -26
- package/public/documentation/klemmstein.png +0 -0
- package/public/documentation/observables.md +18 -24
- package/public/elements.min.js +1 -1
- package/public/formValues.d.ts.map +1 -1
- package/public/formValues.js.map +1 -1
- package/public/formValues.ts +0 -14
- package/public/formvValues.min.js +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/observables.d.ts.map +1 -1
- package/public/observables.js +111 -118
- package/public/observables.js.map +1 -1
- package/public/observables.min.js +1 -1
- package/public/observables.ts +177 -169
- package/public/selectors.min.js +1 -1
- package/public/src/MC.ts +6 -3
- package/public/src/formValues.ts +0 -14
- package/public/src/observables.ts +177 -169
- package/public/test/MC.d.ts +2 -2
- package/public/test/MC.d.ts.map +1 -1
- package/public/test/MC.js +4 -3
- package/public/test/MC.js.map +1 -1
- package/public/test/MC.ts +6 -3
- package/public/test/formValues.d.ts.map +1 -1
- package/public/test/formValues.js.map +1 -1
- package/public/test/formValues.ts +0 -14
- package/public/test/microcomponents.min.js +1 -1
- package/public/test/observables.d.ts.map +1 -1
- package/public/test/observables.js +111 -118
- package/public/test/observables.js.map +1 -1
- package/public/test/observables.ts +177 -169
- package/public/test/test/grandparent.js +1 -1
- package/public/test/test/testform.js +1 -1
- package/public/test/test/testform.js.map +1 -1
- package/public/test/test.d.ts.map +1 -1
- package/public/test/test.html +5 -4
- package/public/test/test.js +5 -6
- package/public/test/test.js.map +1 -1
- package/public/test/testform.json +27 -0
- package/public/typedoc/assets/navigation.js +1 -1
- package/public/typedoc/assets/search.js +1 -1
- package/public/typedoc/classes/MC.DC.html +2 -2
- package/public/typedoc/classes/MC.MC.html +2 -2
- package/public/typedoc/classes/MC.McBase.html +2 -2
- package/public/typedoc/classes/MC.McEvent.html +2 -2
- package/public/typedoc/functions/MC.addListener.html +1 -1
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.removeListener.html +1 -1
- package/public/typedoc/functions/elements.defineCE.html +1 -1
- package/public/typedoc/functions/elements.getCE.html +1 -1
- package/public/typedoc/functions/formValues.formValues.html +1 -1
- package/public/typedoc/functions/observables.observe.html +1 -1
- package/public/typedoc/index.html +40 -23
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/typedoc/modules/MC.html +1 -1
- package/public/typedoc/modules/elements.html +1 -1
- package/public/typedoc/modules/formValues.html +1 -1
- package/public/typedoc/modules/observables.html +1 -1
- package/public/typedoc/modules.html +0 -1
- package/public/typedoc/types/observables.Observable.html +1 -1
- package/src/MC.ts +6 -3
- package/src/formValues.ts +0 -14
- package/src/observables.ts +177 -169
- package/src/test/test/testform.ts +10 -2
- package/src/{test.ts → test/test.ts} +32 -26
- package/tsconfig.json +2 -2
- package/typedoc.json +1 -1
- package/checklist.md +0 -93
- package/dist/microcomponents.es3.d.ts +0 -2
- package/dist/microcomponents.es3.d.ts.map +0 -1
- package/dist/test.d.ts +0 -2
- package/dist/test.d.ts.map +0 -1
- package/dist/test.ts +0 -194
- package/public/microcomponents.es3.d.ts +0 -2
- package/public/microcomponents.es3.d.ts.map +0 -1
- package/public/microcomponents.es3.js +0 -303
- package/public/microcomponents.es3.js.map +0 -1
- package/public/src/test.ts +0 -194
- package/public/test/microcomponents.es3.d.ts +0 -2
- package/public/test/microcomponents.es3.d.ts.map +0 -1
- package/public/test/microcomponents.es3.js +0 -303
- package/public/test/microcomponents.es3.js.map +0 -1
- package/public/test/test.ts +0 -194
- package/public/typedoc/functions/selectors._d.html +0 -1
- package/public/typedoc/functions/selectors._t.html +0 -1
- package/public/typedoc/interfaces/selectors.DSelector.html +0 -50
- package/public/typedoc/interfaces/selectors.TSelector.html +0 -34
- package/public/typedoc/modules/selectors.html +0 -7
- package/public/typedoc/types/selectors.selection.html +0 -1
- package/public/typedoc/types/selectors.singleSelector.html +0 -1
- package/src/microcomponents.es3.js +0 -377
- /package/{klemmstein.png → assets/documentation/klemmstein.png} +0 -0
package/README.md
CHANGED
|
@@ -4,19 +4,25 @@
|
|
|
4
4
|
|
|
5
5
|
**This code aims at improving Javascript modularity and encapsulation**.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
Micro Components are built on **OOP** for structure, so you should embrace **DRY, KISS and SOLID** principles. That said, OOP is not a religion here, in fact you can do FP also. MCs provide a structure for your code, no more. It is agnostic as to what code you put in this structure.
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Its basic principle is **composition over inheritance**. So: using OOP its recommended you do not extend your own classes, as it is not needed.
|
|
10
|
+
|
|
11
|
+
Also it helps to embrace **DIY** (Do It Yourself) **over Toolchains**, but this is up to your personal preference.
|
|
12
|
+
|
|
13
|
+
You can use **Vanilla JS or Typescript** or both in your project. For example you could use plain JS for rapid prototyping functionalities, then convert to TS for production.
|
|
10
14
|
|
|
11
15
|
## Think **Building Blocks**
|
|
12
16
|
|
|
13
17
|
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.
|
|
14
18
|
|
|
15
|
-
When coding with this system, you create classes that extend either the **[MC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#mc-class-extends-mcbase)** or **[DC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#dc-class-extends-mcbase)** superclasses provided here. These classes provide the structure you need to build your wonderland.
|
|
19
|
+
When coding with this system, you create classes that extend either the **[MC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#mc-class-extends-mcbase)** or **[DC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MC.md?ref_type=heads#dc-class-extends-mcbase)** superclasses provided here. These classes provide the structure you need to build your wonderland.
|
|
16
20
|
|
|
17
|
-
In an almost literal sense they work like childrens building blocks, where a chest full of unassuming parts lets you compose whatever functionality lies in your imagination.
|
|
21
|
+
You **attach instances of your classes to any HTMLElement**, and there can be as many as you want connected to a single HTML tag. In an almost literal sense they work like childrens building blocks, where a chest full of unassuming parts lets you compose whatever functionality lies in your imagination.
|
|
18
22
|
|
|
19
|
-
Also you can easily define
|
|
23
|
+
Also you can easily **define JS custom elements**. Since these are just another instance of a DC internally, you can enhance them even at runtime, as they are displayed in the browser.
|
|
24
|
+
|
|
25
|
+
## Principles
|
|
20
26
|
|
|
21
27
|
This systems **modular** approach gives you full control over your software, without the need to rely on other frameworks.
|
|
22
28
|
|
|
@@ -24,20 +30,24 @@ On the other hand, its **minimalistic** stance enables you to use the resulting
|
|
|
24
30
|
|
|
25
31
|
## Status
|
|
26
32
|
|
|
27
|
-
|
|
33
|
+
In [manual testing](https://twobirds.gitlab.io/microcomponents/test/test.html) ( also a speed test). I am working on the documentation.
|
|
28
34
|
|
|
29
35
|
## General
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
- You can use it **Vanilla JS or Typescript**.
|
|
33
|
-
|
|
34
|
-
This repository exports 5 independent functionalities:
|
|
37
|
+
This repository exports 4 independent functionalities:
|
|
35
38
|
|
|
36
39
|
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.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
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).
|
|
43
|
+
- [Basic Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/elements.md?ref_type=heads#create-a-custom-element).
|
|
44
|
+
- [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
|
|
45
|
+
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.
|
|
46
|
+
- [Basic Usage](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/observables.md?ref_type=heads#example)
|
|
47
|
+
- [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
|
|
48
|
+
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).
|
|
49
|
+
- [Example Code](https://gitlab.com/twoBirds/microcomponents/-/blob/main/src/test/test/testform.ts?ref_type=heads)
|
|
50
|
+
- [Live Example](https://twobirds.gitlab.io/microcomponents/test/test.html)
|
|
41
51
|
|
|
42
52
|
Also there is a bundle file that contains all of the above.
|
|
43
53
|
|
|
@@ -94,15 +104,6 @@ The `_mc` **attribute** indicates that this **HTML element contains at least one
|
|
|
94
104
|
|
|
95
105
|
The `_mc` **attribute** and **property** are the only interference with the DOM, so any other system should be happy to work with this.
|
|
96
106
|
|
|
97
|
-
## Disclaimer
|
|
98
|
-
I decided to extract this functionality from the [twoBirds framework](https://www.npmjs.com/package/twobirds-core), because it is a useful tool in itself and it is framework agnostic. It relies solely on the standard DOM and native javascript or typescript.
|
|
99
|
-
|
|
100
|
-
Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.
|
|
101
|
-
|
|
102
|
-
**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. By **"Open Source"** I mean **really free and open**, as **you get all my inner source code with it**. Once you understand the Micro Component principle, you are back in command of your software, no matter what MC functionality you import in your system.
|
|
103
|
-
|
|
104
|
-
Since **Micro Components** are encapsuled, off-shoring and near-shoring is no problem, and reusability is guaranteed. Your external coders do not need to access your code repository or your toolchain. They only need to understand MCs.
|
|
105
|
-
|
|
106
107
|
## Distinct differences to other frameworks
|
|
107
108
|
|
|
108
109
|
There are a few potentially unique aspects of this micro components system that might differentiate it from other frameworks:
|
|
@@ -120,4 +121,14 @@ Feel free to contact me for any questions or inquiries:
|
|
|
120
121
|
|
|
121
122
|
email [Frank Thürigen](mailto:fthuerigen@gmail.com?subject=Micro%20Components)
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
You can [fund this](https://www.gofundme.com/f/nachhaltige-programmierung).
|
|
125
|
+
|
|
126
|
+
## Disclaimer
|
|
127
|
+
I decided to extract this functionality from the [twoBirds framework](https://www.npmjs.com/package/twobirds-core), because it is a useful tool in itself and it is framework agnostic. It relies solely on the standard DOM and native javascript or typescript.
|
|
128
|
+
|
|
129
|
+
Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.
|
|
130
|
+
|
|
131
|
+
**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. By **"Open Source"** I mean **really free and open**, as **you get all my inner source code with it**. Once you understand the Micro Component principle, you are back in command of your software, no matter what MC functionality you import in your system.
|
|
132
|
+
|
|
133
|
+
Since **Micro Components** are encapsuled, off-shoring and near-shoring is no problem, and reusability is guaranteed. Your external coders do not need to access your code repository or your toolchain. They only need to understand MCs.
|
|
134
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
# Micro
|
|
3
|
+
# Micro Components
|
|
4
4
|
|
|
5
5
|
This document details a lightweight JavaScript framework for creating and managing "microcomponents" (MCs) associated with DOM elements or other microcomponents. It allows you to define reusable components and attach them to build complex functionalities.
|
|
6
6
|
|
|
@@ -101,7 +101,7 @@ The `DC` class provides methods (`parent`, `ancestors`, `children`, `descendants
|
|
|
101
101
|
|
|
102
102
|
### Autoloading Concept
|
|
103
103
|
|
|
104
|
-
An optional feature (`autoload()`) that automatically detects specific HTML tags (e.g., `<my-component>`) or elements with an `_mc="
|
|
104
|
+
An optional feature (`autoload()`) that automatically detects specific HTML tags (e.g., `<my-component>`) or elements with an `_mc="my-component"` attribute and attempts to dynamically load the corresponding JavaScript module (e.g., `/my/component.js`).
|
|
105
105
|
|
|
106
106
|
### Important Rule
|
|
107
107
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg">
|
|
2
|
+
<!-- Created with SVG-edit - http://svg-edit.googlecode.com/ -->
|
|
3
|
+
<title>test</title>
|
|
4
|
+
<rect fill="transparent" x="0" y="0" width="200" height="200" fill-opacity="1"/>
|
|
5
|
+
<g style="fill:transparent">
|
|
6
|
+
<title>first bird</title>
|
|
7
|
+
<path fill="#18829c" d="
|
|
8
|
+
m15,160
|
|
9
|
+
a30,75 45 1 0 160,-150
|
|
10
|
+
a20,50 225 1 1 -110,100
|
|
11
|
+
a12,25 45 1 1 60,-50
|
|
12
|
+
a20,50 225 1 0 -110,100
|
|
13
|
+
" />
|
|
14
|
+
</g>
|
|
15
|
+
</svg>
|
|
@@ -21,10 +21,10 @@ Before:
|
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
```javascript
|
|
24
|
+
// customElementRegistry.define() wrapper
|
|
24
25
|
defineCE(
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
class extends DC {
|
|
26
|
+
"my-tag", // tag name
|
|
27
|
+
class MyTag extends DC { // definition class
|
|
28
28
|
|
|
29
29
|
constructor(target, data = {} ) {
|
|
30
30
|
super(target);
|
|
@@ -54,7 +54,7 @@ After:
|
|
|
54
54
|
</body>
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
**Hints**
|
|
58
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
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
60
|
- After you created a custom element, the custom element will contain a **property `<my-tag>._mc`** which contains your class instance.
|
|
@@ -62,10 +62,10 @@ After:
|
|
|
62
62
|
- Note that you can hand over data natively via parameters, when handling custom elements in above way.
|
|
63
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
64
|
|
|
65
|
-
|
|
66
65
|
## Web Component Lifecycle Events
|
|
67
66
|
|
|
68
67
|
```javascript
|
|
68
|
+
// customElementRegistry.define() wrapper
|
|
69
69
|
defineCE(
|
|
70
70
|
"my-tag",
|
|
71
71
|
class MyTag extends DC {
|
|
@@ -98,12 +98,14 @@ defineCE(
|
|
|
98
98
|
['my-attribute'] // DOM node attributes to observe
|
|
99
99
|
);
|
|
100
100
|
|
|
101
|
-
let MyTag = getCE("my-tag"),
|
|
102
|
-
myTag = new MyTag();
|
|
101
|
+
let MyTag = getCE("my-tag"), // customElemtentRegistry.get("my-tag")
|
|
102
|
+
myTag = new MyTag(); // programmatically create a custom element instance
|
|
103
103
|
|
|
104
104
|
document.body.append( myTag );
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
## Composition with Micro Components
|
|
108
|
+
|
|
107
109
|
You can use your Web Component constructor to add other modules to the `<my-tag>` DOM node:
|
|
108
110
|
|
|
109
111
|
```javascript
|
|
@@ -142,12 +144,12 @@ let MyTag = getCE("my-tag");
|
|
|
142
144
|
document.body.append( new MyTag() );
|
|
143
145
|
```
|
|
144
146
|
|
|
145
|
-
|
|
147
|
+
**Hints**
|
|
146
148
|
- You can add as many other micro components to the DOM node as you like.
|
|
147
149
|
- The native web component lifecycle events will be triggered on **all** micro components.
|
|
148
150
|
- The event parameter handed over is an internal event instance, that contains the original native event in its `data` property.
|
|
149
151
|
|
|
150
|
-
## Native Event Handlers
|
|
152
|
+
## Native HTMLElement Event Handlers
|
|
151
153
|
|
|
152
154
|
Native event handlers will be auto-attached, when the method name follows one of these two schemes:
|
|
153
155
|
|
|
@@ -178,11 +180,11 @@ let MyTag = getCE("my-tag");
|
|
|
178
180
|
document.body.append( new MyTag() );
|
|
179
181
|
```
|
|
180
182
|
|
|
181
|
-
|
|
183
|
+
**Hints**
|
|
182
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.
|
|
183
|
-
- The event parameter handed over is an internal event instance, that contains the original native event in its
|
|
185
|
+
- The event parameter handed over is an internal event instance, that contains the original native event in its `data` property.
|
|
184
186
|
|
|
185
|
-
|
|
187
|
+
# Lifecycle Event Handlers
|
|
186
188
|
|
|
187
189
|
Currently there is only one lifecycle event handler: the **oneInit(){ ... }** method you provide with your class.
|
|
188
190
|
|
|
@@ -212,11 +214,11 @@ let MyTag = getCE("my-tag");
|
|
|
212
214
|
document.body.append( new MyTag() );
|
|
213
215
|
```
|
|
214
216
|
|
|
215
|
-
|
|
217
|
+
**Hints**
|
|
216
218
|
- 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
219
|
- The event parameter handed over is an internal event instance that contains no data.
|
|
218
220
|
|
|
219
|
-
|
|
221
|
+
# Custom Events
|
|
220
222
|
|
|
221
223
|
```javascript
|
|
222
224
|
defineCE(
|
|
@@ -274,5 +276,5 @@ sendSpecialEvent(){
|
|
|
274
276
|
}
|
|
275
277
|
```
|
|
276
278
|
|
|
277
|
-
|
|
278
|
-
- The event parameter handed over is an internal event instance, that contains the payload in its
|
|
279
|
+
**Hints**
|
|
280
|
+
- The event parameter handed over is an internal event instance, that contains the payload in its `data` property.
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+

|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Key Components
|
|
6
|
-
|
|
7
|
-
### InputBase (Abstract Class)
|
|
8
|
-
- Base class for all input handlers
|
|
9
|
-
- Defines `val` getter/setter interface
|
|
10
|
-
|
|
11
|
-
### Input Handlers
|
|
12
|
-
- **RadioHandler**: Manages radio button groups
|
|
13
|
-
- **CheckboxHandler**: Handles checkbox state
|
|
14
|
-
- **InputHandler**: For standard text inputs
|
|
15
|
-
- **SelectHandler**: Manages select dropdowns (single/multi-select)
|
|
16
|
-
- **TextAreaHandler**: For textarea elements
|
|
3
|
+
# Form Values
|
|
17
4
|
|
|
18
|
-
|
|
19
|
-
- Scans DOM for form elements
|
|
20
|
-
- Returns object with name-to-handler mappings
|
|
21
|
-
- Automatically creates appropriate handler type
|
|
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.
|
|
22
6
|
|
|
23
|
-
|
|
7
|
+
## formValues Function
|
|
24
8
|
Binds form elements to a target object:
|
|
25
9
|
```ts
|
|
26
10
|
formValues(targetObject: LooseObject, propertyName: string, dom: HTMLElement | ShadowRoot)
|
|
@@ -31,16 +15,11 @@ Example code in constructor
|
|
|
31
15
|
constructor(target: HTMLElement) {
|
|
32
16
|
super(target);
|
|
33
17
|
|
|
34
|
-
const that = this;
|
|
35
|
-
|
|
36
|
-
delete that._mc; // not needed
|
|
37
|
-
|
|
38
18
|
let shadow = (that as DC).target.attachShadow({ mode: 'open' });
|
|
39
|
-
shadow.innerHTML = `<style>${
|
|
19
|
+
shadow.innerHTML = `<style>${this.css}</style>${this.template}`;
|
|
40
20
|
|
|
41
21
|
formValues(that, 'data', shadow); // create this.data formdata observable
|
|
42
22
|
|
|
43
|
-
(that.data as Observable).bind(shadow); // 1 way bind formdata to the form DOM
|
|
44
23
|
}
|
|
45
24
|
```
|
|
46
25
|
Full example [here](https://gitlab.com/twoBirds/microcomponents/-/blob/main/src/test/test/testform.ts?ref_type=heads).
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|

|
|
2
2
|
|
|
3
|
-
# Observables
|
|
3
|
+
# Observables
|
|
4
4
|
|
|
5
5
|
This module provides utilities for observing and binding data to DOM elements using placeholders. It supports reactive updates when data changes.
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ This module provides utilities for observing and binding data to DOM elements us
|
|
|
9
9
|
- [Overview](#overview)
|
|
10
10
|
- [Functions](#functions)
|
|
11
11
|
- [Types](#types)
|
|
12
|
-
- [Example
|
|
12
|
+
- [Example](#example)
|
|
13
13
|
|
|
14
14
|
---
|
|
15
15
|
|
|
@@ -32,7 +32,7 @@ Registers a distinct property or all object properties as an observable, making
|
|
|
32
32
|
Those properties are dual use:
|
|
33
33
|
|
|
34
34
|
- **Direct Assign Native Values**:
|
|
35
|
-
- Directly assign native values to the property, and the observable will be notified of the change.
|
|
35
|
+
- Directly assign native values to the property, and the observable will be notified of the change and its callbacks will be run.
|
|
36
36
|
|
|
37
37
|
- **Use as an Instance of Observable**
|
|
38
38
|
- Use the property as an instance of the `Observable` class. This allows you to attach callbacks and react to changes. You can bind the property to DOM elements.
|
|
@@ -41,7 +41,7 @@ Those properties are dual use:
|
|
|
41
41
|
|
|
42
42
|
### `Observable`
|
|
43
43
|
|
|
44
|
-
**
|
|
44
|
+
**Type**
|
|
45
45
|
```typescript
|
|
46
46
|
export type Observable = {
|
|
47
47
|
observe: (cb: Callback) => void; // attach a callback to be notified of changes
|
|
@@ -59,47 +59,41 @@ export type Observable = {
|
|
|
59
59
|
- Enables / Disables notifications.
|
|
60
60
|
- By default, notifications are enabled.
|
|
61
61
|
- If `enable` is `false`, notifications are disabled. You need to explicitly call `notify(true)` to re-enable notifications.
|
|
62
|
-
-
|
|
62
|
+
- Otherwise calls all registered callbacks with the current data.
|
|
63
63
|
|
|
64
64
|
- `bind(target: HTMLElement | DocumentFragment | ShadowRoot)`
|
|
65
65
|
Binds the observable to a DOM element, replacing placeholders with data values.
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
## Example
|
|
68
|
+
## Example
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
HTML:
|
|
71
|
+
```html
|
|
72
|
+
<div id="user-card">
|
|
73
|
+
<p>Hello, {name}</p>
|
|
74
|
+
<p>Age: {age}</p>
|
|
75
|
+
</div>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
JavaScript:
|
|
79
|
+
```javascript
|
|
80
|
+
import { observe } from './observables.js';
|
|
72
81
|
|
|
73
82
|
const data = {
|
|
74
83
|
name: 'John',
|
|
75
84
|
age: 30,
|
|
76
85
|
};
|
|
77
86
|
|
|
78
|
-
observe(data);
|
|
87
|
+
observe(data); // all properties of the data object will be observed.
|
|
79
88
|
|
|
80
89
|
const element = document.getElementById('user-card');
|
|
81
90
|
data.bind(element);
|
|
82
91
|
```
|
|
83
92
|
|
|
84
|
-
In HTML:
|
|
85
|
-
```html
|
|
86
|
-
<div id="user-card">
|
|
87
|
-
<p>Hello, {name}</p>
|
|
88
|
-
<p>Age: {age}</p>
|
|
89
|
-
</div>
|
|
90
|
-
```
|
|
91
|
-
|
|
92
93
|
When `data.name` or `data.age` changes, the DOM updates automatically.
|
|
93
94
|
|
|
94
95
|
---
|
|
95
96
|
|
|
96
|
-
## Dependencies
|
|
97
|
-
|
|
98
|
-
- `helpers.js` - Provides utilities like `deepEqual`, `debounce`, `flattenObject`, etc.
|
|
99
|
-
- `MC.js` - Contains `DC`, `HTMLMcElement`, and `McEvent` for DOM manipulation and event handling.
|
|
100
|
-
|
|
101
|
-
---
|
|
102
|
-
|
|
103
97
|
## Notes
|
|
104
98
|
|
|
105
99
|
- Only objects can be bound to the DOM.
|
package/assets/test/test.html
CHANGED
|
@@ -12,11 +12,12 @@
|
|
|
12
12
|
/>
|
|
13
13
|
<link href="style.css" rel="stylesheet" />
|
|
14
14
|
<link href="my-tag.css" rel="stylesheet" />
|
|
15
|
-
<link href="grandparent.css" rel="stylesheet" />
|
|
16
|
-
<script src="microcomponents.min.js"></script>
|
|
15
|
+
<link href="grandparent.css" rel="stylesheet" />
|
|
17
16
|
<script>
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
import("./microcomponents.js").then((m) => {
|
|
18
|
+
m.autoload(true); // automatically load web components that are undefined
|
|
19
|
+
Object.assign(window, m);
|
|
20
|
+
});
|
|
20
21
|
</script>
|
|
21
22
|
<script type="module" src="test.js"></script>
|
|
22
23
|
</head>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"textInput":"Hello World",
|
|
3
|
+
"colorInput":"#eaf8f8",
|
|
4
|
+
"dateInput":"",
|
|
5
|
+
"dtlInput":"",
|
|
6
|
+
"email":"",
|
|
7
|
+
"hiddenInput":"",
|
|
8
|
+
"hiddenVal":"",
|
|
9
|
+
"month":"",
|
|
10
|
+
"number":"",
|
|
11
|
+
"passInput":"",
|
|
12
|
+
"rangeInput":"30",
|
|
13
|
+
"searchInput":"",
|
|
14
|
+
"telInput":"",
|
|
15
|
+
"timeInput":"",
|
|
16
|
+
"urlInput":"",
|
|
17
|
+
"weekInput":"",
|
|
18
|
+
"myRadio":"radio3",
|
|
19
|
+
"cb1":true,
|
|
20
|
+
"cb2":false,
|
|
21
|
+
"cb3":true,
|
|
22
|
+
"cb4":false,
|
|
23
|
+
"cb5":false,
|
|
24
|
+
"singleSelect":"1",
|
|
25
|
+
"multiSelect":["2","4"],
|
|
26
|
+
"textArea":"This is some example text\r..."
|
|
27
|
+
}
|
package/dist/MC.d.ts
CHANGED
|
@@ -31,6 +31,6 @@ declare class DC extends McBase {
|
|
|
31
31
|
children(search?: string): any[];
|
|
32
32
|
descendants(search?: string): any[];
|
|
33
33
|
}
|
|
34
|
-
|
|
35
|
-
export { addListener, removeListener, McBase, MC, DC, McEvent };
|
|
34
|
+
declare function autoload(enable?: boolean): boolean;
|
|
35
|
+
export { addListener, removeListener, McBase, MC, DC, McEvent, autoload };
|
|
36
36
|
//# sourceMappingURL=MC.d.ts.map
|
package/dist/MC.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAevC,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AA8CD,iBAAS,WAAW,CACnB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kCAAkC,GAAG,IAAI,EAClD,OAAO,GAAE,OAAe,EACxB,IAAI,GAAE,OAAe,QAarB;AAED,iBAAS,cAAc,CACtB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kCAAkC,GAAG,IAAI,QAGlD;AAmDD,iBAAS,OAAO,CACf,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,OAAO,GAAG,MAAM,EACpB,IAAI,GAAE,GAAQ,EACd,MAAM,GAAE,MAAY,QAwBpB;AAiGD,cAAM,MAAM;;gBAGC,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,KAAK,GAAE,OAAe;IAWnE,IAAI,MAAM,IAAI,GAAG,CAEhB;CACD;AAED,cAAM,EAAG,SAAQ,MAAM;IACtB,GAAG,CAAC,EAAE,WAAW,CAAM;gBAEX,MAAM,CAAC,EAAE,GAAG;IAIxB,MAAM,CAAC,OAAO,iBAAW;IAEzB,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,GAAE,MAAY;CAmElE;AAED,cAAM,EAAG,SAAQ,MAAM;IACtB,GAAG,CAAC,EAAE,WAAW,CAAM;gBAEX,MAAM,EAAE,WAAW,EAAE,KAAK,GAAE,OAAe;IAIvD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IACjC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAW;IAEnC,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;IAI7D,MAAM,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMlC,SAAS,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMrC,QAAQ,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAYpC,WAAW,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;CAMvC;AA6KD,
|
|
1
|
+
{"version":3,"file":"MC.d.ts","sourceRoot":"","sources":["../src/MC.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAevC,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AA8CD,iBAAS,WAAW,CACnB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kCAAkC,GAAG,IAAI,EAClD,OAAO,GAAE,OAAe,EACxB,IAAI,GAAE,OAAe,QAarB;AAED,iBAAS,cAAc,CACtB,OAAO,EAAE,IAAI,EACb,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,kCAAkC,GAAG,IAAI,QAGlD;AAmDD,iBAAS,OAAO,CACf,MAAM,EAAE,WAAW,EACnB,EAAE,EAAE,OAAO,GAAG,MAAM,EACpB,IAAI,GAAE,GAAQ,EACd,MAAM,GAAE,MAAY,QAwBpB;AAiGD,cAAM,MAAM;;gBAGC,MAAM,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,EAAE,KAAK,GAAE,OAAe;IAWnE,IAAI,MAAM,IAAI,GAAG,CAEhB;CACD;AAED,cAAM,EAAG,SAAQ,MAAM;IACtB,GAAG,CAAC,EAAE,WAAW,CAAM;gBAEX,MAAM,CAAC,EAAE,GAAG;IAIxB,MAAM,CAAC,OAAO,iBAAW;IAEzB,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,GAAE,MAAY;CAmElE;AAED,cAAM,EAAG,SAAQ,MAAM;IACtB,GAAG,CAAC,EAAE,WAAW,CAAM;gBAEX,MAAM,EAAE,WAAW,EAAE,KAAK,GAAE,OAAe;IAIvD,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IACjC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAW;IAEnC,OAAO,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;IAI7D,MAAM,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMlC,SAAS,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAMrC,QAAQ,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;IAYpC,WAAW,CAAC,MAAM,GAAE,MAAW,GAAG,GAAG,EAAE;CAMvC;AA6KD,iBAAS,QAAQ,CAAC,MAAM,GAAE,OAAc,GAAG,OAAO,CAmBjD;AAID,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC"}
|
package/dist/MC.min.js
CHANGED
|
@@ -430,7 +430,7 @@ function onLoadCallback(script) {
|
|
|
430
430
|
const code = `
|
|
431
431
|
|
|
432
432
|
import _ from "${importFileName}";
|
|
433
|
-
import {DC} from "./microcomponents.js";
|
|
433
|
+
import { DC } from "./microcomponents.js";
|
|
434
434
|
|
|
435
435
|
const elements = Array.from(document.querySelectorAll('[_mc*="${elementName}"]')).filter( element => element instanceof HTMLElement );
|
|
436
436
|
|
|
@@ -504,6 +504,7 @@ function autoload(enable = true) {
|
|
|
504
504
|
observer.observe(document.body, { childList: true, subtree: true });
|
|
505
505
|
loadUndefinedMicroComponents();
|
|
506
506
|
}, 5);
|
|
507
|
+
window.autoload = window.autoload || autoload;
|
|
507
508
|
return autoloadEnabled;
|
|
508
509
|
}
|
|
509
510
|
autoload.state = { CEs, MCs };
|
package/dist/MC.ts
CHANGED
|
@@ -491,7 +491,7 @@ function onLoadCallback( script: HTMLScriptElement ) {
|
|
|
491
491
|
const code = /*javascript*/`
|
|
492
492
|
|
|
493
493
|
import _ from "${importFileName}";
|
|
494
|
-
import {DC} from "./microcomponents.js";
|
|
494
|
+
import { DC } from "./microcomponents.js";
|
|
495
495
|
|
|
496
496
|
const elements = Array.from(document.querySelectorAll('[_mc*="${elementName}"]')).filter( element => element instanceof HTMLElement );
|
|
497
497
|
|
|
@@ -581,7 +581,8 @@ function loadUndefinedMicroComponents() {
|
|
|
581
581
|
let autoloadEnabled: boolean = false;
|
|
582
582
|
let observer: MutationObserver | null = null;
|
|
583
583
|
|
|
584
|
-
|
|
584
|
+
function autoload(enable: boolean = true): boolean {
|
|
585
|
+
|
|
585
586
|
if (!enable) {
|
|
586
587
|
observer?.disconnect();
|
|
587
588
|
observer = null;
|
|
@@ -596,10 +597,12 @@ export function autoload(enable: boolean = true): boolean {
|
|
|
596
597
|
loadUndefinedMicroComponents();
|
|
597
598
|
}, 5);
|
|
598
599
|
|
|
600
|
+
(window as any).autoload = (window as any).autoload || autoload;
|
|
601
|
+
|
|
599
602
|
return autoloadEnabled;
|
|
600
603
|
}
|
|
601
604
|
|
|
602
605
|
(autoload as LooseObject).state = { CEs, MCs };
|
|
603
606
|
|
|
604
|
-
export { addListener, removeListener, McBase, MC, DC, McEvent };
|
|
607
|
+
export { addListener, removeListener, McBase, MC, DC, McEvent, autoload };
|
|
605
608
|
|
package/dist/elements.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.elements=e():t.elements=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{defineCE:()=>j,getCE:()=>M});var n=new Function("try {return this===window;}catch(e){ return false;}");let r=new Set;n()&&Object.keys(HTMLElement.prototype).filter((t=>/^on/.test(t))).forEach((t=>r.add(t)));class o{#t;#e=!1;#n=!1;constructor(t,e={},n="l"){this.#t=t,this.data=e,this.bubble=n}get type(){return this.#t}get stopped(){return this.#e}get immediateStopped(){return this.#n}stopPropagation(){this.#e=!0}stopImmediatePropagation(){this.stopPropagation(),this.#n=!0}}var c=new Function("try {return this===window;}catch(e){ return false;}");let s=new Set;function i(t,e){let n=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const r=t?._mc;!e&&r?n=n.concat(Object.values(t._mc)):e&&r&&r[e]&&n.push(r[e])}})),n}function a(t,e,n=!0){let r=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&r.push(t._mc[e]):r=r.concat(Object.values(t._mc)),n))return r;t=t.parentNode}return r}function l(t){return t&&t instanceof HTMLElement}function u(t,e,n,r=!1,o=!1){let c={once:!1};r&&(c.capture=r),o&&(c.once=o),t.addEventListener(e,n,c)}function
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.elements=e():t.elements=e()}(this,(()=>(()=>{"use strict";var t={d:(e,n)=>{for(var r in n)t.o(n,r)&&!t.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:n[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{defineCE:()=>j,getCE:()=>M});var n=new Function("try {return this===window;}catch(e){ return false;}");let r=new Set;n()&&Object.keys(HTMLElement.prototype).filter((t=>/^on/.test(t))).forEach((t=>r.add(t)));class o{#t;#e=!1;#n=!1;constructor(t,e={},n="l"){this.#t=t,this.data=e,this.bubble=n}get type(){return this.#t}get stopped(){return this.#e}get immediateStopped(){return this.#n}stopPropagation(){this.#e=!0}stopImmediatePropagation(){this.stopPropagation(),this.#n=!0}}var c=new Function("try {return this===window;}catch(e){ return false;}");let s=new Set;function i(t,e){let n=[];return t.forEach((t=>{if(t&&t instanceof HTMLElement){const r=t?._mc;!e&&r?n=n.concat(Object.values(t._mc)):e&&r&&r[e]&&n.push(r[e])}})),n}function a(t,e,n=!0){let r=[];for(;t;){if(t._mc&&(e?e&&t._mc[e]&&r.push(t._mc[e]):r=r.concat(Object.values(t._mc)),n))return r;t=t.parentNode}return r}function l(t){return t&&t instanceof HTMLElement}function u(t,e,n,r=!1,o=!1){let c={once:!1};r&&(c.capture=r),o&&(c.once=o),t.addEventListener(e,n,c)}function d(t,e,n={}){let r=t;if(!r._mc){let e=h?.debug;h.debug=!1,r._mc=new h(t),h.debug=e,delete r._mc._mc}const o=r._mc;return e.length&&!o[e]&&(o[e]=n,t instanceof HTMLElement&&!t.getAttribute("_mc")&&t.setAttribute("_mc","")),n}function m(t,e){if(!e)return;const n=t?._mc||{};n&&n[e]&&delete n[e],!Object.keys(n).length&&t instanceof HTMLElement&&t.hasAttribute("_mc")&&t.removeAttribute("_mc")}function p(t,e,n={},r="l"){let c=t?._mc;if(!c)return;let s=e instanceof o?new o(e.type,e.data,"l"):new o(e,n,"l"),i="string"!=typeof e?e:new o(e,n,r);[...Object.values(c)].forEach((t=>{t?.trigger&&"function"==typeof t?.trigger&&t?.trigger(s)})),/[ud]/.test(i.bubble)&&f(t,i)}function f(t,e){/[ud]/.test(e.bubble)&&setTimeout((()=>{if(-1===e.bubble.indexOf("l")&&(e.bubble+="l"),e.bubble.indexOf("u")>-1){let n=a(t,"",!0)?.[0].target;n&&h.trigger(n,e)}e.bubble.indexOf("d")>-1&&new Set(t._mc.children().map((t=>t?.target))).forEach((t=>{t&&h.trigger(t,e)}))}),0)}c()&&Object.keys(HTMLElement.prototype).filter((t=>/^on/.test(t))).forEach((t=>s.add(t)));class g{#r;constructor(t,e=!1){var n;this.#r=new WeakRef(t||{}),(n=this).constructor!==h&&setTimeout((()=>{n.trigger("Init")}),0),function(t){if(!c()||t.constructor===h)return;const e=t.target;if(e instanceof HTMLElement){let n=t;Object.getOwnPropertyNames(n.constructor.prototype).filter((t=>/^on[A-Z]|one[A-Z]/.test(t)&&"function"==typeof n.constructor.prototype[t])).forEach((r=>{let o=/^one/.test(r),c=r.replace(/^on[e]{0,1}/,""),i=c.toLowerCase();o&&Object.defineProperty(t,"on"+c,{configurable:!0,enumerable:!1,writable:!0,value:t=>{n.constructor.prototype[r].bind(n)(t)}}),s.has("on"+i)&&u(e,i,(t=>{n.trigger(c,t)}),!1,o)}))}}(this)}get target(){return this.#r.deref()}}class b extends g{_mc={};constructor(t){super(t)}static trigger=p;trigger(t,e={},n="l"){let r=this;if(r.constructor===b||r.constructor===h){let c=t instanceof o?new o(t.type,t.data,"l"):new o(t,e,"l"),s="string"!=typeof t?t:new o(t,e,n);return[...Object.getOwnPropertyNames(r)].forEach((t=>{r[t]?.trigger&&"function"==typeof r[t]?.trigger&&r[t]?.trigger(c)})),void(/[ud]/.test(s.bubble)&&f(r.target,s))}if(r instanceof b||r instanceof h){const r=this,c="string"!=typeof t?t:new o(t,e,n),s="on"+c.type[0].toUpperCase()+c.type.slice(1);if(c.bubble.indexOf("l")>-1&&(c.immediateStopped||"function"!=typeof r[s]||(r[s](c),r.hasOwnProperty(s)&&delete r[s])),c.stopped||"l"===c.bubble)return r;/[ud]/.test(c.bubble)&&f(r.target,c)}}}class h extends g{_mc={};constructor(t,e=!1){super(t)}static add=d;static remove=m;static trigger=p;trigger(t,e={},n){b.prototype.trigger.call(this,t,e,n)}parent(t=""){let e=this.target;return l(e)?a(e.parentNode,t,!0):[]}ancestors(t=""){let e=this?.target;return l(e)?a(this.target.parentNode,t,!1):[]}children(t=""){let e=this?.target;if(!l(e))return[];const n=Math.random().toString().replace(".",""),r='[_mc]:not([temp_id="'+n+'"] [_mc] [_mc])';e.setAttribute("temp_id",n);const o=i([...e.querySelectorAll(r)],t);return e.removeAttribute("temp_id"),o}descendants(t=""){let e=this?.target;return l(e)?i([...e.querySelectorAll("*[_mc]")],t):[]}}const y=new Map,w=new Map;function _(t){const e="./"+t.split("-").join("/")+".js",n=document.createElement("script");return n.setAttribute("src",e),n.setAttribute("blocking","render"),n.async=!0,n.setAttribute("type","module"),n.setAttribute("name",t),n.setAttribute("loading",""),u(n,"load",(t=>{n.removeAttribute("loading"),n.setAttribute("loaded","")})),u(n,"error",(t=>{console.error("could not load Custom Element code from",e)})),n}function E(){[...document.querySelectorAll(":not(:defined)")].filter((t=>!!t&&!customElements.get(t.tagName.toLowerCase())&&!y.has(t.tagName.toLowerCase()))).forEach((t=>{const e=t.tagName.toLowerCase(),n=(e.split("-").join("/"),_(e));u(n,"load",(()=>{y.set(e,customElements.get(t.tagName.toLowerCase()))})),y.set(e,"loading"),document.head.append(n)})),[...document.querySelectorAll('[_mc]:not([_mc=""]')].filter((t=>!!t)).forEach((t=>{const e=t.getAttribute("_mc")?.split(" ").filter((t=>!!t))||[],n=e.filter((t=>!w.has(t)));n?.forEach((t=>{const e=_(t);u(e,"load",(()=>{return e=document.head.querySelector(`script[name="${t}"]`),void setTimeout((function(){const t=e.getAttribute("src"),n=e.getAttribute("name"),r=document.createElement("script");r.async=!0,r.setAttribute("type","module");const o=`\n\n\t\t\timport _ from "${t}";\n\t\t\timport { DC } from "./microcomponents.js";\n\n\t\t\tconst elements = Array.from(document.querySelectorAll('[_mc*="${n}"]')).filter( element => element instanceof HTMLElement );\n\n\t\t\telements.forEach((element) => {\n\t\t\t\t// add class to MCs repository\n\t\t\t\tautoload.state.MCs.set( '${n}', _ );\n\t\t\t\t// add instance to HTMLElement \n\t\t\t\tDC.add(element, _.name, new _(element));\n\t\t\t\t// remove instance name from elements "_mc" attribute\n\t\t\t\telement.setAttribute('_mc', element.getAttribute('_mc').replace('${n}', '').replace( /ww/g, ' ').trim()); \n\t\t\t});\n\n\t\t\tsetTimeout( () => {\n\t\t\t\tdocument.body.querySelector('script[name="${n}]"')?.remove();\n\t\t\t},0);\n\n\t\t`;r.innerHTML=o,document.body.append(r)}),0);var e})),w.set(t,"loading"),document.head.append(e)}));const r=e.filter((t=>w.has(t)&&!w.get(t).length));r?.forEach((e=>{setTimeout((()=>{h.add(t,e,new(C.state.MCs.get(e))(t)),t.getAttribute("_mc").replace("${elementName}","").replace(/\w\w/g," ").trim(),t.setAttribute("_mc")}),5)}))}))}let A=!1,v=null;function C(t=!0){return t?(A=t,v=new MutationObserver(E),setTimeout((()=>{v.observe(document.body,{childList:!0,subtree:!0}),E()}),5),window.autoload=window.autoload||C,A):(v?.disconnect(),v=null,A)}C.state={CEs:y,MCs:w};class O extends HTMLElement{constructor(){super()}connectedCallback(){h.trigger(this,"Connected")}disconnectedCallback(){h.trigger(this,"Disconnected")}adoptedCallback(){h.trigger(this,"Adopted")}attributeChangedCallback(t,e,n){h.trigger(this,"AttributeChanged",{name:t,oldValue:e,newValue:n})}}function j(t,e,n=[]){if(customElements.get(t))return void console.warn(`IGNORED: Custom element "${t}" is already defined!`);if(!t.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=t.split("-").map((t=>t.charAt(0).toUpperCase()+t.slice(1))).join("");customElements.define(t,function(t,e){return Object.defineProperty(e,"name",{value:t})}(r,class extends O{instance;constructor(t){super();let n=new e(this,t);h.add(this,r,n)}static get observedAttributes(){return n}}))}function M(t){return customElements.get(t)}return e})()));
|
package/dist/formValues.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../src/formValues.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAC;AA0M/D,wBAAgB,UAAU,CACzB,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,WAAW,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"formValues.d.ts","sourceRoot":"","sources":["../src/formValues.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAsB,MAAM,cAAc,CAAC;AA0M/D,wBAAgB,UAAU,CACzB,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,MAAM,EACpB,GAAG,EAAE,WAAW,GAAG,UAAU,QAgB7B"}
|
package/dist/formValues.ts
CHANGED
|
@@ -220,20 +220,6 @@ export function formValues(
|
|
|
220
220
|
//console.log('keyup', ev);
|
|
221
221
|
targetObject[propertyName].notify();
|
|
222
222
|
});
|
|
223
|
-
/*
|
|
224
|
-
addListener(input as inputTypes, 'keyup', (ev: Event) => {
|
|
225
|
-
//console.log('keyup', ev);
|
|
226
|
-
targetObject[propertyName].notify();
|
|
227
|
-
});
|
|
228
|
-
addListener(input as inputTypes, 'change', (ev: Event) => {
|
|
229
|
-
//console.log('change', ev);
|
|
230
|
-
targetObject[propertyName].notify();
|
|
231
|
-
});
|
|
232
|
-
addListener(input as inputTypes, 'select', (ev: Event) => {
|
|
233
|
-
//console.log('select', ev);
|
|
234
|
-
targetObject[propertyName].notify();
|
|
235
|
-
});
|
|
236
|
-
*/
|
|
237
223
|
});
|
|
238
224
|
}
|
|
239
225
|
|