@twobirds/microcomponents 0.0.34 → 0.0.39
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 +40 -27
- package/assets/documentation/{MicroComponents.md → MC.md} +17 -17
- package/assets/documentation/comparision.md +0 -0
- package/assets/documentation/elements.md +276 -0
- package/assets/documentation/magic.md +10 -68
- package/assets/my-tag.css +6 -2
- package/dist/MC.d.ts +3 -4
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.min.js +89 -66
- package/dist/MC.ts +213 -178
- package/dist/autoloader.ts +1 -1
- package/dist/{customElements.d.ts → elements.d.ts} +1 -1
- package/dist/elements.d.ts.map +1 -0
- package/dist/elements.min.js +1 -0
- package/dist/{customElements.ts → elements.ts} +23 -14
- package/dist/helpers.d.ts +6 -4
- package/dist/helpers.d.ts.map +1 -1
- package/dist/helpers.ts +95 -128
- package/dist/microcomponents.d.ts +3 -3
- package/dist/microcomponents.d.ts.map +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/microcomponents.ts +3 -3
- package/dist/{customObservables.d.ts → observables.d.ts} +3 -3
- package/dist/observables.d.ts.map +1 -0
- package/dist/observables.min.js +1 -0
- package/dist/observables.ts +353 -0
- package/dist/{customSelectors.d.ts → selectors.d.ts} +1 -1
- package/dist/selectors.d.ts.map +1 -0
- package/dist/selectors.min.js +1 -0
- package/dist/test.ts +135 -156
- package/klemmstein.png +0 -0
- package/package.json +52 -52
- package/public/MC.js +90 -67
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +89 -66
- package/public/assets/search.js +1 -1
- package/public/autoloader.js +1 -1
- package/public/autoloader.js.map +1 -1
- package/public/classes/{DC.html → MC.DC.html} +60 -59
- package/public/classes/{MC.html → MC.MC.html} +41 -35
- package/public/classes/{McBase.html → MC.McBase.html} +28 -20
- package/public/classes/{McEvent.html → MC.McEvent.html} +48 -42
- package/public/documentation/{MicroComponents.md → MC.md} +17 -17
- package/public/documentation/comparision.md +0 -0
- package/public/documentation/elements.md +276 -0
- package/public/documentation/magic.md +10 -68
- package/public/{customElements.js → elements.js} +9 -10
- package/public/elements.js.map +1 -0
- package/public/elements.min.js +1 -0
- package/public/functions/{addListener.html → MC.addListener.html} +18 -12
- package/public/functions/{removeListener.html → MC.removeListener.html} +18 -12
- package/public/functions/elements.defineCE.html +78 -0
- package/public/functions/elements.getCE.html +63 -0
- package/public/functions/formValues.formValues.html +68 -0
- package/public/functions/observables.observe.html +65 -0
- package/public/functions/selectors._d.html +69 -0
- package/public/functions/selectors._t.html +69 -0
- package/public/helpers.js +66 -89
- package/public/helpers.js.map +1 -1
- package/public/index.html +48 -33
- package/public/interfaces/{HTMLMcElement.html → MC.HTMLMcElement.html} +601 -595
- package/public/interfaces/selectors.DSelector.html +1013 -0
- package/public/interfaces/selectors.TSelector.html +712 -0
- package/public/microcomponents.js +3 -3
- package/public/microcomponents.js.map +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/modules/MC.html +78 -0
- package/public/modules/elements.html +62 -0
- package/public/modules/formValues.html +60 -0
- package/public/modules/observables.html +65 -0
- package/public/modules/selectors.html +76 -0
- package/public/modules.html +11 -23
- package/public/my-tag.css +6 -2
- package/public/observables.js +259 -0
- package/public/observables.js.map +1 -0
- package/public/observables.min.js +1 -0
- package/public/{customSelectors.js → selectors.js} +1 -1
- package/public/selectors.js.map +1 -0
- package/public/selectors.min.js +1 -0
- package/public/src/MC.ts +413 -0
- package/public/src/McEvent.ts +96 -0
- package/public/src/autoloader.ts +98 -0
- package/{src/customElements.ts → public/src/elements.ts} +23 -14
- package/public/src/formValues.ts +275 -0
- package/public/src/helpers.ts +140 -0
- package/public/src/microcomponents.ts +8 -0
- package/public/src/observables.ts +353 -0
- package/public/src/test.ts +190 -0
- package/public/test.js +93 -118
- package/public/test.js.map +1 -1
- package/public/types/observables.Observable.html +91 -0
- package/public/types/selectors.selection.html +58 -0
- package/public/types/selectors.singleSelector.html +58 -0
- package/src/MC.ts +213 -178
- package/src/autoloader.ts +1 -1
- package/src/elements.ts +76 -0
- package/src/helpers.ts +95 -128
- package/src/microcomponents.ts +3 -3
- package/src/observables.ts +353 -0
- package/src/selectors.ts +1634 -0
- package/src/test.ts +135 -156
- package/typedoc.json +1 -1
- package/webpack.config.js +9 -9
- package/dist/customElements.d.ts.map +0 -1
- package/dist/customElements.min.js +0 -1
- package/dist/customObservables.d.ts.map +0 -1
- package/dist/customObservables.min.js +0 -1
- package/dist/customObservables.ts +0 -348
- package/dist/customSelectors.d.ts.map +0 -1
- package/dist/customSelectors.min.js +0 -1
- package/public/customElements.js.map +0 -1
- package/public/customElements.min.js +0 -1
- package/public/customObservables.js +0 -256
- package/public/customObservables.js.map +0 -1
- package/public/customObservables.min.js +0 -1
- package/public/customSelectors.js.map +0 -1
- package/public/customSelectors.min.js +0 -1
- package/src/customObservables.ts +0 -348
- /package/dist/{customSelectors.ts → selectors.ts} +0 -0
- /package/{src/customSelectors.ts → public/src/selectors.ts} +0 -0
package/dist/test.ts
CHANGED
|
@@ -1,211 +1,190 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
LooseObject,
|
|
5
|
+
MC,
|
|
6
|
+
DC,
|
|
7
|
+
McEvent,
|
|
8
|
+
defineCE,
|
|
9
|
+
getCE,
|
|
10
|
+
observe,
|
|
11
|
+
Observable,
|
|
12
|
+
} from './microcomponents.js';
|
|
13
|
+
|
|
14
|
+
//import { MC, DC, McEvent } from "./MC.js";
|
|
15
|
+
//import { defineCE, getCE } from "./elements.js";
|
|
16
|
+
//import { observe } from "./observables.js";
|
|
8
17
|
|
|
9
18
|
//MC.debug = true;
|
|
10
19
|
|
|
11
|
-
class
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
sum(...numbers: number[]): number {
|
|
15
|
-
return numbers.reduce((acc: number, curr: number) => acc + curr, 0);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
20
|
+
class Translator extends DC {
|
|
21
|
+
#translations: LooseObject = {};
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
super(target);
|
|
22
|
-
}
|
|
23
|
+
Language: unknown = 'en';
|
|
24
|
+
Translation: unknown = {};
|
|
23
25
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
constructor(
|
|
27
|
+
target: HTMLElement | ShadowRoot | DocumentFragment,
|
|
28
|
+
translations: LooseObject,
|
|
29
|
+
translationTargetObject: HTMLElement
|
|
30
|
+
) {
|
|
31
|
+
super(target as HTMLElement);
|
|
32
|
+
let that = this; // minifier help
|
|
29
33
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
+
// state
|
|
35
|
+
that.Language = 'en';
|
|
36
|
+
that.Translation = {};
|
|
34
37
|
|
|
35
|
-
|
|
36
|
-
let logger = this.target?.target?._mc?.logger;
|
|
37
|
-
logger?.log("onCustomEvent", ev);
|
|
38
|
-
}
|
|
38
|
+
observe(that);
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
_mc = that._mc!,
|
|
43
|
-
logger = this.target?.target?._mc?.logger;
|
|
40
|
+
// setup
|
|
41
|
+
that.#translations = translations;
|
|
44
42
|
|
|
45
|
-
//
|
|
43
|
+
// state
|
|
44
|
+
(that.Language as Observable).observe((lang) => {
|
|
45
|
+
if (that.#translations.hasOwnProperty(lang)) {
|
|
46
|
+
that.Translation = { lang: that.#translations[lang] }; // set translation
|
|
47
|
+
}
|
|
48
|
+
});
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
+
(that.Translation as Observable).bind(translationTargetObject);
|
|
50
51
|
|
|
51
|
-
|
|
52
|
+
this.target.setAttribute('language', 'en');
|
|
52
53
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
stdOut: typeof console = console;
|
|
56
|
-
|
|
57
|
-
constructor(target: HTMLElement, logger: typeof console, prefix: string) {
|
|
58
|
-
// logger must implement the console interface
|
|
59
|
-
super(target);
|
|
60
|
-
|
|
61
|
-
let that = this; // scoping and minifier help
|
|
62
|
-
|
|
63
|
-
that.prefix = prefix;
|
|
64
|
-
|
|
65
|
-
// instance that handles logging, depency injection
|
|
66
|
-
that.stdOut = logger;
|
|
54
|
+
(this.Language as Observable).notify();
|
|
67
55
|
}
|
|
68
56
|
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
oneInit() {
|
|
58
|
+
//(this.Language as Observable).notify(); // trigger translation
|
|
71
59
|
}
|
|
72
60
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
61
|
+
onAttributeChanged(ev: McEvent) {
|
|
62
|
+
if (!ev.data.newValue) return;
|
|
63
|
+
|
|
64
|
+
let that = this;
|
|
65
|
+
|
|
66
|
+
switch (ev.data.name) {
|
|
67
|
+
case 'language':
|
|
68
|
+
that.Language = ev.data.newValue;
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
78
71
|
}
|
|
79
72
|
}
|
|
80
73
|
|
|
81
74
|
defineCE(
|
|
82
75
|
// equivalent to custom element registry .define()
|
|
83
|
-
|
|
76
|
+
'my-tag',
|
|
84
77
|
class MyTag extends DC {
|
|
78
|
+
#template: string = '<button>{lang.click} {counter}</button>';
|
|
85
79
|
|
|
86
|
-
|
|
80
|
+
#languages = {
|
|
81
|
+
en: {
|
|
82
|
+
click: 'click me',
|
|
83
|
+
},
|
|
84
|
+
de: {
|
|
85
|
+
click: 'klick mich',
|
|
86
|
+
},
|
|
87
|
+
};
|
|
87
88
|
|
|
88
|
-
|
|
89
|
+
Dom: LooseObject = {};
|
|
89
90
|
|
|
90
|
-
constructor(target: HTMLElement
|
|
91
|
+
constructor(target: HTMLElement) {
|
|
91
92
|
super(target);
|
|
92
93
|
|
|
93
94
|
let that = this; // minifier help
|
|
94
95
|
|
|
95
|
-
//
|
|
96
|
-
|
|
97
|
-
that.Counter = 0;
|
|
98
|
-
|
|
99
|
-
// convert all props defined so far into custom observables
|
|
100
|
-
observe(that);
|
|
101
|
-
|
|
102
|
-
DC.add(target, "logger", new Logger(target, console, "[logger]"));
|
|
96
|
+
// hide
|
|
97
|
+
target.setAttribute('style', 'display:none');
|
|
103
98
|
|
|
104
99
|
// render
|
|
105
|
-
target.innerHTML =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
//this.target._mc?.logger.info("onConnected handler", ev);
|
|
100
|
+
target.innerHTML = this.#template;
|
|
101
|
+
|
|
102
|
+
// add public translator
|
|
103
|
+
DC.add(
|
|
104
|
+
target,
|
|
105
|
+
'translator',
|
|
106
|
+
new Translator(target, that.#languages, target)
|
|
107
|
+
);
|
|
114
108
|
}
|
|
115
109
|
|
|
116
|
-
|
|
117
|
-
let
|
|
118
|
-
//logger?.info("onAttributeChanged handler", ev);
|
|
119
|
-
}
|
|
110
|
+
oneInit(ev: McEvent) {
|
|
111
|
+
let that = this;
|
|
120
112
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
*/
|
|
124
|
-
oneClick(ev: typeof McEvent) {
|
|
125
|
-
let logger = this.target._mc?.logger;
|
|
113
|
+
// state
|
|
114
|
+
that.Dom = { counter: 0 };
|
|
126
115
|
|
|
127
|
-
|
|
116
|
+
// state: convert all props defined so far into observables
|
|
117
|
+
observe(that);
|
|
128
118
|
|
|
129
|
-
|
|
119
|
+
// bind Dom to target
|
|
120
|
+
(that.Dom as Observable).bind(that.target);
|
|
130
121
|
|
|
131
|
-
|
|
122
|
+
// show
|
|
123
|
+
setTimeout(() => that.target.removeAttribute('style'), 100);
|
|
132
124
|
}
|
|
133
125
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
logger?.info("onClick handler", ev);
|
|
138
|
-
|
|
139
|
-
this.Counter++;
|
|
126
|
+
onAttributeChanged(ev: McEvent) {
|
|
127
|
+
//console.log(ev);
|
|
128
|
+
this.target._mc.translator.Language = ev.data.newValue;
|
|
140
129
|
}
|
|
141
130
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
oneInit(ev: typeof McEvent) {
|
|
146
|
-
let that = this,
|
|
147
|
-
_mc = that._mc;
|
|
148
|
-
|
|
149
|
-
let logger = that.target._mc.logger;
|
|
150
|
-
|
|
151
|
-
//logger.warn("oneInit handler", ev);
|
|
152
|
-
|
|
153
|
-
// add a private event target
|
|
154
|
-
_mc.customEventTarget = new EvTarget(that);
|
|
155
|
-
|
|
156
|
-
// add a private adder
|
|
157
|
-
_mc.Adder = new Adder();
|
|
158
|
-
|
|
159
|
-
// add callback for this.Counter changes
|
|
160
|
-
( that.Counter as any).observe((value: number) => {
|
|
161
|
-
logger.log("Counter has changed to: " + value);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
//logger.log("add 1,2,3 =", _mc.Adder.sum(1, 2, 3));
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
onDoSomething(ev: typeof McEvent) {
|
|
168
|
-
let logger = this.target._mc?.logger;
|
|
169
|
-
logger?.log(".onDoSomething(ev): something done...", ev);
|
|
131
|
+
onClick(ev: McEvent) {
|
|
132
|
+
this.Dom.counter++;
|
|
133
|
+
(this.target as HTMLElement).classList.add('clicked');
|
|
170
134
|
}
|
|
171
135
|
},
|
|
172
|
-
[
|
|
136
|
+
['language']
|
|
173
137
|
);
|
|
174
138
|
|
|
175
|
-
let MyTag: CustomElementConstructor = getCE(
|
|
139
|
+
let MyTag: CustomElementConstructor = getCE('my-tag')!,
|
|
176
140
|
fragment = new DocumentFragment();
|
|
177
141
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
142
|
+
/*
|
|
143
|
+
stress test
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
let start = new Date().getTime();
|
|
147
|
+
|
|
148
|
+
// create 100 elements
|
|
149
|
+
for (let x = 0; x < 100; x++) {
|
|
150
|
+
fragment.append(new MyTag());
|
|
183
151
|
}
|
|
184
|
-
document.body.appendChild( fragment );
|
|
185
152
|
|
|
186
|
-
|
|
187
|
-
'%c \n\nStress Test:\n\n %cInstancing 1000 classes and putting them in the DOM took (ms):',
|
|
188
|
-
"font-weight: bold; color: black;",
|
|
189
|
-
"color: black;"
|
|
190
|
-
);
|
|
191
|
-
console.timeEnd("Instancing");
|
|
153
|
+
let end = new Date().getTime();
|
|
192
154
|
|
|
193
|
-
|
|
155
|
+
// and put them into the DOM
|
|
156
|
+
document.body.appendChild(fragment);
|
|
194
157
|
|
|
195
|
-
//
|
|
158
|
+
//document.querySelectorAll('my-tag').forEach((e) => e.remove());
|
|
196
159
|
|
|
197
|
-
|
|
160
|
+
/*
|
|
161
|
+
console test
|
|
162
|
+
*/
|
|
198
163
|
|
|
199
|
-
|
|
164
|
+
setTimeout(() => {
|
|
165
|
+
console.clear();
|
|
200
166
|
|
|
201
|
-
console.log(
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
167
|
+
console.log(
|
|
168
|
+
'%c \n\nStress Test:\n\n %cInstancing 100 web components: %c %s ms.',
|
|
169
|
+
'font-weight: bold; color: black;',
|
|
170
|
+
'font-weight: normal;',
|
|
171
|
+
'font-weight: bold; color: blue;',
|
|
172
|
+
end - start
|
|
173
|
+
);
|
|
174
|
+
|
|
175
|
+
document.body.appendChild(new MyTag());
|
|
176
|
+
|
|
177
|
+
let element = document.querySelector('my-tag');
|
|
178
|
+
|
|
179
|
+
console.log(
|
|
180
|
+
"\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
|
|
181
|
+
'font-weight: bold;',
|
|
182
|
+
'font-weight: normal;',
|
|
183
|
+
element,
|
|
184
|
+
'font-weight: bold;',
|
|
185
|
+
'\n\nLook up code in the debugger: test.js\n\n'
|
|
186
|
+
);
|
|
209
187
|
|
|
210
|
-
// will trigger the event on all micro components contained in <my-tag>
|
|
211
|
-
DC.trigger(element,
|
|
188
|
+
// will trigger the event on all micro components contained in <my-tag>
|
|
189
|
+
DC.trigger(element, 'doSomething');
|
|
190
|
+
}, 500);
|
package/klemmstein.png
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
2
|
+
"name": "@twobirds/microcomponents",
|
|
3
|
+
"version": "0.0.39",
|
|
4
|
+
"description": "Micro Components Organization Class",
|
|
5
|
+
"main": "./dist/microcomponents.ts",
|
|
6
|
+
"types": "./dist/microcomponents.d.ts",
|
|
7
|
+
"sideEffects": false,
|
|
8
|
+
"scripts": {
|
|
9
|
+
"typedoc": "typedoc",
|
|
10
|
+
"webpack": "webpack",
|
|
11
|
+
"clean": "rm -rf build/*; rm -rf dist/*;",
|
|
12
|
+
"prep": "cp -R assets/* public || true; cp src/* build || true;",
|
|
13
|
+
"build": "npm run clean; npm run prep; tsc; npm run copyToDist; npm run webpack; cp dist/*.js public; cp dist/microcomponents.js build; cp build/*.js public; cp build/*.js.map public;",
|
|
14
|
+
"copyToDist": "mkdir public/src || true; cp src/*.ts public/src || true; cp -R assets/* public || true; cp build/*.ts* dist; cp *.svg dist; cp *.svg public/fiddle; cp dist/MicroComponents.svg public; cp dist/microcomponents.js public;"
|
|
15
|
+
},
|
|
16
|
+
"author": "",
|
|
17
|
+
"license": "ISC",
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"jsmin": "^1.0.1",
|
|
20
|
+
"ts-loader": "^9.5.2",
|
|
21
|
+
"typedoc": "^0.26.11",
|
|
22
|
+
"typescript": "^5.5.4",
|
|
23
|
+
"webpack": "^5.97.1",
|
|
24
|
+
"webpack-cli": "^6.0.1"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"javascript",
|
|
28
|
+
"library",
|
|
29
|
+
"native",
|
|
30
|
+
"DOM manipulation",
|
|
31
|
+
"lightweight",
|
|
32
|
+
"standalone",
|
|
33
|
+
"SPA",
|
|
34
|
+
"PWA",
|
|
35
|
+
"ES3",
|
|
36
|
+
"ES5",
|
|
37
|
+
"ES6",
|
|
38
|
+
"ES7",
|
|
39
|
+
"ES2015",
|
|
40
|
+
"ES2016",
|
|
41
|
+
"client",
|
|
42
|
+
"API"
|
|
43
|
+
],
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://gitlab.com/twoBirds/microcomponents"
|
|
47
|
+
},
|
|
48
|
+
"contributors": [
|
|
49
|
+
{
|
|
50
|
+
"name": "Frank Thürigen",
|
|
51
|
+
"email": "fthuerigen@gmail.com"
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
54
|
}
|