@twobirds/microcomponents 0.0.21 → 0.0.22
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/.gitlab-ci.yml +1 -0
- package/README.md +31 -12
- package/assets/documentation/MicroComponents.md +228 -0
- package/assets/my-tag.css +4 -0
- package/assets/test.html +5 -1
- package/dist/MC.d.ts +32 -0
- package/dist/MC.d.ts.map +1 -0
- package/dist/MC.min.js +414 -0
- package/dist/MC.ts +350 -0
- package/dist/MCbundle.d.ts +8 -0
- package/dist/MCbundle.d.ts.map +1 -0
- package/dist/MCbundle.min.js +1 -0
- package/dist/MCbundle.ts +8 -0
- package/dist/McEvent.d.ts +15 -0
- package/dist/McEvent.d.ts.map +1 -0
- package/dist/McEvent.ts +96 -0
- package/dist/autoloader.d.ts +2 -0
- package/dist/autoloader.d.ts.map +1 -0
- package/dist/autoloader.ts +98 -0
- package/dist/customElements.d.ts +5 -0
- package/dist/customElements.d.ts.map +1 -0
- package/dist/customElements.min.js +1 -0
- package/dist/customElements.ts +67 -0
- package/dist/customObservables.d.ts +3 -0
- package/dist/customObservables.d.ts.map +1 -0
- package/dist/customObservables.min.js +1 -0
- package/dist/customObservables.ts +340 -0
- package/dist/customSelectors.d.ts +108 -0
- package/dist/customSelectors.d.ts.map +1 -0
- package/dist/customSelectors.min.js +1 -0
- package/dist/customSelectors.ts +1634 -0
- package/dist/formValues.d.ts +4 -0
- package/dist/formValues.d.ts.map +1 -0
- package/dist/formValues.ts +275 -0
- package/dist/formvValues.min.js +1 -0
- package/dist/helpers.d.ts +11 -0
- package/dist/helpers.d.ts.map +1 -0
- package/dist/helpers.ts +173 -0
- package/dist/microcomponents.es3.d.ts +1 -20
- package/dist/microcomponents.es3.d.ts.map +1 -1
- package/dist/test.d.ts +2 -0
- package/dist/test.d.ts.map +1 -0
- package/package.json +11 -7
- package/public/MC.js +273 -0
- package/public/MC.min.js +414 -0
- package/public/MCbundle.js +8 -0
- package/public/MCbundle.min.js +1 -0
- package/public/McEvent.js +74 -0
- package/public/MicroComponents.svg +15 -0
- package/public/assets/search.js +1 -1
- package/public/autoloader.js +57 -0
- package/public/classes/MC.DC.html +247 -0
- package/public/classes/MC.MC.html +150 -0
- package/public/classes/MC.McBase.html +123 -0
- package/public/classes/MCbundle.McEvent.html +184 -0
- package/public/customElements.js +48 -0
- package/public/customElements.min.js +1 -0
- package/public/customObservables.js +255 -0
- package/public/customObservables.min.js +1 -0
- package/public/customSelectors.js +1088 -0
- package/public/customSelectors.min.js +1 -0
- package/public/documentation/MicroComponents.md +228 -0
- package/public/formValues.js +211 -0
- package/public/formvValues.min.js +1 -0
- package/public/functions/MC.addListener.html +73 -0
- package/public/functions/MC.removeListener.html +69 -0
- package/public/functions/MCbundle._d.html +85 -0
- package/public/functions/MCbundle._t.html +85 -0
- package/public/functions/MCbundle.debounce.html +85 -0
- package/public/functions/MCbundle.deepEqual.html +85 -0
- package/public/functions/MCbundle.defineCE.html +98 -0
- package/public/functions/MCbundle.formValues.html +89 -0
- package/public/functions/MCbundle.getCE.html +83 -0
- package/public/functions/MCbundle.htmlToElements.html +83 -0
- package/public/functions/MCbundle.isObject.html +83 -0
- package/public/functions/MCbundle.kebabToPascal.html +83 -0
- package/public/functions/MCbundle.makeCO.html +85 -0
- package/public/functions/MCbundle.nameSpace.html +89 -0
- package/public/functions/MCbundle.parse.html +85 -0
- package/public/helpers.js +128 -0
- package/public/index.html +22 -13
- package/public/interfaces/MC.HTMLMcElement.html +3605 -0
- package/public/interfaces/MCbundle.DSelector.html +1010 -0
- package/public/interfaces/MCbundle.LooseObject.html +80 -0
- package/public/interfaces/MCbundle.TSelector.html +709 -0
- package/public/microcomponents.es3.js +348 -0
- package/public/modules/MC.html +84 -0
- package/public/modules/MCbundle.html +133 -0
- package/public/modules.html +4 -4
- package/public/my-tag.css +4 -0
- package/public/test.html +5 -1
- package/public/test.js +100 -202
- package/public/types/MCbundle.selection.html +74 -0
- package/public/types/MCbundle.singleSelector.html +74 -0
- package/src/MC.ts +350 -0
- package/src/MCbundle.ts +8 -0
- package/src/McEvent.ts +96 -0
- package/src/autoloader.ts +98 -0
- package/src/customElements.ts +67 -0
- package/src/customObservables.ts +340 -0
- package/src/customSelectors.ts +1634 -0
- package/src/formValues.ts +275 -0
- package/src/helpers.ts +173 -0
- package/src/microcomponents.es3.js +353 -82
- package/src/test.js +137 -218
- package/tsconfig.json +2 -2
- package/typedoc.json +1 -1
- package/webpack.config.js +233 -0
- package/dist/microcomponents.d.ts +0 -26
- package/dist/microcomponents.d.ts.map +0 -1
- package/dist/microcomponents.es3.js +0 -96
- package/dist/microcomponents.es3.min.js +0 -15
- package/dist/microcomponents.js +0 -176
- package/dist/microcomponents.min.js +0 -38
- package/dist/microcomponents.ts +0 -216
- package/public/classes/microcomponents.MC.html +0 -313
- package/public/classes/microcomponents_es3.MC.html +0 -336
- package/public/functions/microcomponents_es3.__isEmpty.html +0 -60
- package/public/microcomponents.js +0 -176
- package/public/modules/microcomponents.html +0 -57
- package/public/modules/microcomponents_es3.html +0 -60
- package/src/microcomponents.ts +0 -216
package/.gitlab-ci.yml
CHANGED
package/README.md
CHANGED
|
@@ -4,25 +4,44 @@
|
|
|
4
4
|
|
|
5
5
|
**This code aims at improving Javascript modularity and encapsulation**.
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Using micro components enforces **DRY, KISS and SOLID** principles in Javascript programming. Read this [RFC](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/proposal_draft.md?ref_type=heads) for the shortest info, and [click here to see why you may want to use it](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/why.md?ref_type=heads).
|
|
7
|
+
Using micro components enforces **DRY, KISS and SOLID** principles in Javascript programming.
|
|
10
8
|
|
|
11
9
|
## Status
|
|
12
|
-
WIP. Should be done soon. In [manual testing](http://twobirds.gitlab.io/microcomponents/test.html), also working a lot on the documentation.
|
|
13
10
|
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
**WIP**. Should be done soon. In [manual testing](http://twobirds.gitlab.io/microcomponents/test.html), also working a lot on the documentation.
|
|
12
|
+
|
|
13
|
+
## Skippable Disclaimer
|
|
14
|
+
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.
|
|
15
|
+
|
|
16
|
+
Later this will be backported into twoBirds as a dependency, and twoBirds will become completely modularized on the base of MCs.
|
|
16
17
|
|
|
17
18
|
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. 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.
|
|
18
19
|
|
|
19
20
|
## General
|
|
20
21
|
|
|
21
|
-
This is a low-level approach
|
|
22
|
+
**This is a low-level OOP approach to Javascript programming.**
|
|
23
|
+
|
|
24
|
+
It aims at proving that strict OOP is a valid alternative to other frameworks functional approaches.
|
|
25
|
+
|
|
26
|
+
You can use it in vanilla JS or Typescript coding environments. It has been used to create very complex single page applications.
|
|
27
|
+
|
|
28
|
+
Also you can use it in any other framework to enhance it with missing functionality.
|
|
29
|
+
|
|
30
|
+
This functionality is **portable**, so you can **reuse your MCs** - e.g. originally written in the context of an **Angular** project - in your next **react** project right away.
|
|
31
|
+
|
|
32
|
+
In its core it consists of a two classes named **MC** and **DC**. Your class code extends from one of these classes.
|
|
33
|
+
|
|
34
|
+
This repository exports 5 independent functionalities:
|
|
35
|
+
|
|
36
|
+
1. **[Micro Components](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/MicroComponents.md?ref_type=heads)** contains the **MC** and **DC** classes you can use as super classes.
|
|
37
|
+
2. **Custom Elements** lets you define and retrieve your own custom elements based on your DC instance code. Uses and re-exports (1).
|
|
38
|
+
3. **Convenience Observables** adds observability and run time type safety to object properties.
|
|
39
|
+
4. **Form Values** gives you 2-way binding between a HTML form and an observable.
|
|
40
|
+
5. (tbd) **Convenience Selectors** provide jQuery like selectors for both the DOM and micro components.
|
|
22
41
|
|
|
23
|
-
|
|
42
|
+
Also there is a bundle file that contains all of the above.
|
|
24
43
|
|
|
25
|
-
Check the [typedoc API reference](
|
|
44
|
+
Check the [typedoc API reference](https://twobirds.gitlab.io/microcomponents/modules.html) if you want to drill into the source code.
|
|
26
45
|
|
|
27
46
|
To see what can be done, go to [additional concepts](https://gitlab.com/twoBirds/microcomponents/-/blob/main/assets/documentation/magic.md?ref_type=heads) which shows what it already has been used for.
|
|
28
47
|
|
|
@@ -38,7 +57,7 @@ before:
|
|
|
38
57
|
code:
|
|
39
58
|
```typescript
|
|
40
59
|
// create a custom micro component class
|
|
41
|
-
class MyMC extends
|
|
60
|
+
class MyMC extends DC{
|
|
42
61
|
|
|
43
62
|
constructor( target ){
|
|
44
63
|
super( target );
|
|
@@ -54,7 +73,7 @@ class MyMC extends MC{
|
|
|
54
73
|
const element = document.querySelector('div')
|
|
55
74
|
|
|
56
75
|
// Add the custom micro component instance to the target element
|
|
57
|
-
|
|
76
|
+
DC.add(
|
|
58
77
|
element,
|
|
59
78
|
'myMC',
|
|
60
79
|
new MyMC( element )
|
|
@@ -73,7 +92,7 @@ after:
|
|
|
73
92
|
```
|
|
74
93
|
_mc indicates that this HTML element contains at least one micro component. This is needed for the selectors.
|
|
75
94
|
|
|
76
|
-
|
|
95
|
+
The _mc attribute and properties are the only interference with the DOM, so every other system should be happy to work with this.
|
|
77
96
|
|
|
78
97
|
## Contact
|
|
79
98
|
Feel free to contact me for any questions or inquiries:
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# Micro Components
|
|
2
|
+
|
|
3
|
+
This system allows you to to define **Micro Components** and attach them to DOM elements or other Micro Components.
|
|
4
|
+
|
|
5
|
+
The module exports 2 classes:
|
|
6
|
+
- **MC**: Micro Component ( not DOM related, works on the server also )
|
|
7
|
+
- **DC**: Dom Component ( extends MC and adds DOM related methods, client only )
|
|
8
|
+
|
|
9
|
+
## tldr;
|
|
10
|
+
|
|
11
|
+
In general when coding with this system, you create classes that extend either the **DC** or **MC** class provided here.
|
|
12
|
+
|
|
13
|
+
**If your functionality needs to access the DOM**, e.g. to find other DC instances, **your class extends DC**.
|
|
14
|
+
|
|
15
|
+
**Otherwise** - and always on the server - **your class extends MC**.
|
|
16
|
+
|
|
17
|
+
In any case, your class instances will contain a property **"_mc"** where you can put in other MCs.
|
|
18
|
+
|
|
19
|
+
Also your class instances will have a readonly **"target"** property that is back reference to the instance they are contained in.
|
|
20
|
+
|
|
21
|
+
- if your class extends **DC: "target"** will refer the **DOM HTMLElement your instance resides in**.
|
|
22
|
+
- if your class extends **MC: "target"** will refer the **parent MC your instance resides in**.
|
|
23
|
+
|
|
24
|
+
As an application programmer you should understand **MC** and **DC** methods and the structure they provide:
|
|
25
|
+
- **MC** encapsule functionality in a reusable way. Think DRY, and SOLID because we talk about objects.
|
|
26
|
+
- **MC** can use observables to provide data driven workflow between multiple MCs.
|
|
27
|
+
- **DC** use observables and formValues to provide 1-way and 2-way binding to the DOM.
|
|
28
|
+
- **DC** have selectors to find other DCs in the DOM.
|
|
29
|
+
|
|
30
|
+
## MC() Class overview
|
|
31
|
+
|
|
32
|
+
**Instance Properties**
|
|
33
|
+
- `.target`: readonly, a getter returning the DOM element or parent MC instance your instance resides in
|
|
34
|
+
- `._mc`: a hash object that contains inner micro components
|
|
35
|
+
|
|
36
|
+
- **Instance Methods:**
|
|
37
|
+
- `.trigger( eventName, data )`: trigger an event on this instance
|
|
38
|
+
|
|
39
|
+
## DC() Class Overview
|
|
40
|
+
|
|
41
|
+
- **Static Methods:**
|
|
42
|
+
- `DC.add( DomElement, key, mc)`: Add a DC to an HTMLElement.
|
|
43
|
+
- `DC.remove( DomElement, key )`: Remove a DC from an HTMLElement.
|
|
44
|
+
- `DC.trigger( eventName, DomElement, data, bubble )`: trigger an event, handles directional traversal in the DOM.
|
|
45
|
+
|
|
46
|
+
**Instance Properties**
|
|
47
|
+
|
|
48
|
+
( inherited from MC )
|
|
49
|
+
- `.target`: readonly, a getter returning the DOM element the instance resides in
|
|
50
|
+
- `._mc`: a hash object that contains inner MCs
|
|
51
|
+
|
|
52
|
+
- **Instance Methods:**
|
|
53
|
+
- `.parent(search?)`: Get parent DCs.
|
|
54
|
+
- `.ancestors(search?)`: Get ancestor DCs.
|
|
55
|
+
- `.children(search?)`: Get child DCs.
|
|
56
|
+
- `.descendants(search?)`: Get descendant DCs.
|
|
57
|
+
- `.autoAttachListeners()`: methods in your MC that start with "on[A-Z]" or "one[A-Z]" and describe native DOM events (e.g. "onClick") will be added to the DOM Element as listeners.
|
|
58
|
+
|
|
59
|
+
(inherited from MC )
|
|
60
|
+
- `.trigger( eventName, data, bubble )`: trigger an event on "this", handles directional bubbling in the DOM.
|
|
61
|
+
|
|
62
|
+
### Typical Workflow
|
|
63
|
+
|
|
64
|
+
1. **Attach DCs** to HTMLElements using `DC.add()`.
|
|
65
|
+
2. **Access** other DCs by their property key or navigating through DOM (e.g., `ancestors()`, `children()`, etc.) **and use their inner functionality**.
|
|
66
|
+
|
|
67
|
+
# Attaching Micro Components to a DOM element
|
|
68
|
+
|
|
69
|
+
To attach a micro component to an HTML element, use the `DC.add()` static function.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
const myElement = document.getElementById('myDiv');
|
|
73
|
+
|
|
74
|
+
/*
|
|
75
|
+
usage with classes, both PUBLIC and PRIVATE
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
// internal MC class
|
|
79
|
+
MyInnerClass = class extends MC{
|
|
80
|
+
constructor(target){
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// external DC class
|
|
85
|
+
MyPublicClass = class extends DC{
|
|
86
|
+
constructor(target){
|
|
87
|
+
// add a internal inner MC
|
|
88
|
+
this._mc.myInnerComponent = new MyInnerClass( this );
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// attach a DC
|
|
93
|
+
DC.add( myElement, 'myDcComponent', new MyClass( myElement ) );
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
- After you added a micro component using this function, the **HTMLElement will contain a property `_mc`** which contains the external MC instances.
|
|
97
|
+
- Also the **HTMLElement then has an attribute '_mc'** which will indicate that at least one micro component is attached to this dom element.
|
|
98
|
+
|
|
99
|
+
# Removing a top level Micro Component from a DOM element
|
|
100
|
+
|
|
101
|
+
Micro components can be removed using the `DC.remove()` static method.
|
|
102
|
+
|
|
103
|
+
```javascript
|
|
104
|
+
DC.remove( myDomElement, 'myComponent');
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**When all micro components are removed** (the _mc object has no more properties), the **`_mc` attribute is also removed** from the HTML element.
|
|
108
|
+
|
|
109
|
+
# Retrieve all top level Micro Components from a DOM element
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
const target = document.querySelector( 'div' );
|
|
113
|
+
console.log(target._mc);
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
To retrieve a specific micro component by its key:
|
|
117
|
+
```javascript
|
|
118
|
+
const target = document.querySelector( 'div' );
|
|
119
|
+
const specificInstance = target._mc?.myPublicComponent;
|
|
120
|
+
console.log(specificInstance);
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Trigger an Event on all DCs
|
|
124
|
+
|
|
125
|
+
```javascript
|
|
126
|
+
const target = document.querySelector( 'div' );
|
|
127
|
+
DC.trigger( target, '<eventName>', data | null, bubble );
|
|
128
|
+
|
|
129
|
+
// bubble is any combination of 'lud', meaning [local|up|down]
|
|
130
|
+
// local is only "this", "up" traverses towards root, "down" traverses the inner DOM.
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
# Methods you can use in your Micro Component Instances
|
|
134
|
+
|
|
135
|
+
## Retrieving Inner Micro Components
|
|
136
|
+
|
|
137
|
+
You can retrieve an inner micro component by using the ._mc property.
|
|
138
|
+
|
|
139
|
+
```javascript
|
|
140
|
+
const innerComponent = this._mc.myInnerComponent;
|
|
141
|
+
console.log(innerComponent);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
**The following methods hop over HTMLElements that DO NOT contain micro components.**
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
## Navigating Parent and Ancestor Micro Components
|
|
148
|
+
|
|
149
|
+
The `.parent()` and `.ancestors()` methods allow you to retrieve micro components attached to parent elements.
|
|
150
|
+
|
|
151
|
+
```javascript
|
|
152
|
+
const parentMcs = this.parent();
|
|
153
|
+
console.log(parentMcs); // all micro components of the closest ancestor that has an _mc attribute
|
|
154
|
+
|
|
155
|
+
const allAncestorsMcs = this.ancestors();
|
|
156
|
+
console.log(allAncestorsMcs); // all ancestor micro components up to document root.
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
To retrieve specific micro component(s) attached to ancestors:
|
|
160
|
+
```javascript
|
|
161
|
+
const specificAncestorMc = this.ancestors('myComponent');
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Retrieving Child and Descendant Micro Components
|
|
165
|
+
|
|
166
|
+
The `.children()` and `.descendants()` methods retrieve micro components attached to child elements or any descendants.
|
|
167
|
+
```javascript
|
|
168
|
+
const childComponents = this.children();
|
|
169
|
+
console.log(childComponents); // an array of nearest micro components in the inner DOM
|
|
170
|
+
|
|
171
|
+
const descendantComponents = this.descendants();
|
|
172
|
+
console.log(descendantComponents); // an array of all descendant micro components in the inner DOM
|
|
173
|
+
|
|
174
|
+
//To search for a specific micro component by key:
|
|
175
|
+
const specificMcs = this.descenants('specificMc');
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Trigger Events on MCs
|
|
179
|
+
```javascript
|
|
180
|
+
// trigger an event on yourself
|
|
181
|
+
this
|
|
182
|
+
.trigger('myEvent', data); // calls the "onMyEvent" callback
|
|
183
|
+
|
|
184
|
+
// trigger an event on your external siblings
|
|
185
|
+
DC
|
|
186
|
+
.trigger( this.target, 'myEvent', data); // calls the "onMyEvent" callback on all externalh MCs that listen to it
|
|
187
|
+
|
|
188
|
+
// trigger an event on some remote DOM instance(s)
|
|
189
|
+
DC
|
|
190
|
+
.trigger(
|
|
191
|
+
this.target, // the DOM node your are in
|
|
192
|
+
'myEvent', // event name
|
|
193
|
+
null, // no data
|
|
194
|
+
'd' // into descendants
|
|
195
|
+
); // calls the "onMyEvent" callback
|
|
196
|
+
|
|
197
|
+
// trigger an event on some remote DC instance that you know the name of
|
|
198
|
+
this
|
|
199
|
+
.descendants('myRemoteInstance') // into my inner HTML
|
|
200
|
+
?.[0] // hopefully we found one
|
|
201
|
+
.trigger(
|
|
202
|
+
'myEvent', // event name
|
|
203
|
+
null, // no data
|
|
204
|
+
);
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
## Automatically attach Listener Methods to the DOM
|
|
208
|
+
|
|
209
|
+
On any **DC** instance, you can call **.autoAttachListeners()** in the constructor.
|
|
210
|
+
|
|
211
|
+
Any methods you define in your code that start with **"on"** or **"one"**, and also match DOM event names, will be called accordingly:
|
|
212
|
+
|
|
213
|
+
```javascript
|
|
214
|
+
class MyEventTarget extends MC {
|
|
215
|
+
constructor(target) {
|
|
216
|
+
super(target);
|
|
217
|
+
this.autoAttachListeners();
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
onClick(ev) {
|
|
221
|
+
console.log("onClick", ev);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
let myFirstDiv = document.querySelector('div');
|
|
226
|
+
DC.add( myFirstDiv, 'myEventTarget', new MyEventTarget( myFirstDiv ) );
|
|
227
|
+
// now wait for somebody to click on that <div>
|
|
228
|
+
```
|
package/assets/test.html
CHANGED
|
@@ -4,8 +4,12 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>Micro Components Manual Test</title>
|
|
7
|
+
<link rel="icon" type="image/svg+xml" sizes="any" href="MicroComponents.svg" />
|
|
8
|
+
<link href="./my-tag.css" rel="stylesheet" />
|
|
9
|
+
<script type="module" src="./test.js"></script>
|
|
10
|
+
<script src="./customSelectors.min.js"></script>
|
|
7
11
|
</head>
|
|
8
12
|
<body>
|
|
9
|
-
|
|
13
|
+
Open the debugger, read console, then:
|
|
10
14
|
</body>
|
|
11
15
|
</html>
|
package/dist/MC.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { LooseObject } from './helpers.js';
|
|
2
|
+
import { McEvent } from './McEvent.js';
|
|
3
|
+
export interface HTMLMcElement extends HTMLElement {
|
|
4
|
+
_mc: LooseObject;
|
|
5
|
+
}
|
|
6
|
+
declare function addListener(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject | null, capture?: boolean, once?: boolean): void;
|
|
7
|
+
declare function removeListener(domNode: Node, eventName: string, handler: EventListenerOrEventListenerObject | null): void;
|
|
8
|
+
declare class McBase {
|
|
9
|
+
#private;
|
|
10
|
+
constructor(target: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
});
|
|
13
|
+
get target(): any;
|
|
14
|
+
}
|
|
15
|
+
declare class MC extends McBase {
|
|
16
|
+
constructor(target: any);
|
|
17
|
+
trigger(ev: McEvent | string, data?: any, bubble?: string): this | undefined;
|
|
18
|
+
}
|
|
19
|
+
declare class DC extends MC {
|
|
20
|
+
constructor(target: HTMLElement);
|
|
21
|
+
static debug: boolean;
|
|
22
|
+
static add: Function;
|
|
23
|
+
static remove: Function;
|
|
24
|
+
static trigger: Function;
|
|
25
|
+
parent(search?: string): any[];
|
|
26
|
+
ancestors(search?: string): any[];
|
|
27
|
+
children(search?: string): any[];
|
|
28
|
+
descendants(search?: string): any[];
|
|
29
|
+
autoAttachListeners(): void;
|
|
30
|
+
}
|
|
31
|
+
export { addListener, removeListener, McBase, MC, DC, McEvent };
|
|
32
|
+
//# sourceMappingURL=MC.d.ts.map
|
package/dist/MC.d.ts.map
ADDED
|
@@ -0,0 +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;AAWvC,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,GAAG,EAAE,WAAW,CAAC;CACjB;AA6CD,iBAAS,WAAW,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,GAAG,IAAI,EAAE,OAAO,GAAE,OAAe,EAAE,IAAI,GAAE,OAAe,QAe1J;AAED,iBAAS,cAAc,CAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,kCAAkC,GAAG,IAAI,QAE5G;AA2DD,cAAM,MAAM;;gBAME,MAAM,EAAE;QAAE,CAAC,GAAG,EAAC,MAAM,GAAG,GAAG,CAAA;KAAE;IAc1C,IAAI,MAAM,IAAI,GAAG,CAEhB;CAED;AAED,cAAM,EAAG,SAAQ,MAAM;gBACV,MAAM,EAAE,GAAG;IAYvB,OAAO,CAAE,EAAE,EAAE,OAAO,GAAG,MAAM,EAAE,IAAI,GAAE,GAAQ,EAAE,MAAM,CAAC,EAAE,MAAM;CAgF9D;AAED,cAAM,EAAG,SAAQ,EAAE;gBACN,MAAM,EAAE,WAAW;IAI/B,MAAM,CAAC,KAAK,EAAE,OAAO,CAAS;IAE9B,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAO;IAC3B,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAU;IACjC,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAW;IAEnC,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;IAOvC,mBAAmB;CA6CnB;AAED,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC"}
|