@twobirds/microcomponents 0.0.84 → 0.0.86
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 +22 -6
- package/assets/documentation/MC.md +60 -81
- package/assets/documentation/elements.md +6 -9
- package/assets/documentation/observables.md +97 -11
- package/assets/test/{my-tag.css → myButton.css} +4 -4
- package/assets/test/test.html +1 -1
- package/dist/MC.d.ts +6 -9
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.js +40 -73
- package/dist/MC.min.js +40 -73
- package/dist/MC.ts +67 -114
- package/dist/elements.min.js +1 -1
- package/dist/formValues.min.js +1 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.min.js +1 -1
- package/package.json +2 -2
- package/public/MC.d.ts +6 -9
- package/public/MC.d.ts.map +1 -1
- package/public/MC.js +40 -73
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +40 -73
- package/public/MC.ts +67 -114
- package/public/documentation/MC.md +60 -81
- package/public/documentation/elements.md +6 -9
- package/public/documentation/observables.md +97 -11
- package/public/elements.min.js +1 -1
- package/public/formValues.min.js +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/observables.min.js +1 -1
- package/public/src/MC.d.ts +6 -9
- package/public/src/MC.d.ts.map +1 -1
- package/public/src/MC.js +40 -73
- package/public/src/MC.js.map +1 -1
- package/public/src/MC.ts +67 -114
- package/public/src/test/test/grandparent.js +1 -1
- package/public/src/test/test/testform.js +1 -1
- package/public/src/test/test.js +23 -31
- package/public/src/test/test.js.map +1 -1
- package/public/src/test/test.ts +61 -72
- package/public/test/MC.d.ts +6 -9
- package/public/test/MC.d.ts.map +1 -1
- package/public/test/MC.js +40 -73
- package/public/test/MC.min.js +40 -73
- package/public/test/MC.ts +67 -114
- package/public/test/elements.min.js +1 -1
- package/public/test/formValues.min.js +1 -1
- package/public/test/microcomponents.min.js +1 -1
- package/public/test/{my-tag.css → myButton.css} +4 -4
- package/public/test/observables.min.js +1 -1
- package/public/test/test/grandparent.js +1 -1
- package/public/test/test/testform.js +1 -1
- package/public/test/test.html +1 -1
- package/public/test/test.js +23 -31
- package/public/test/test.js.map +1 -1
- package/public/test/test.ts +61 -72
- package/public/typedoc/assets/navigation.js +1 -1
- package/public/typedoc/assets/search.js +1 -1
- package/public/typedoc/classes/MC.DC.html +3 -4
- package/public/typedoc/classes/MC.MC.html +2 -4
- package/public/typedoc/classes/MC.McBase.html +2 -2
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.off.html +1 -1
- package/public/typedoc/functions/MC.on.html +1 -1
- package/public/typedoc/functions/MC.one.html +1 -1
- package/public/typedoc/functions/MC.trigger.html +1 -0
- 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 +21 -10
- package/public/typedoc/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/typedoc/modules/MC.html +3 -3
- 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/types/observables.Observable.html +1 -1
- package/src/MC.ts +67 -114
- package/src/test/test.ts +61 -72
package/src/test/test.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
getCE,
|
|
6
6
|
observe,
|
|
7
7
|
Observable,
|
|
8
|
+
HTMLMcElement,
|
|
8
9
|
} from '../microcomponents.js';
|
|
9
10
|
|
|
10
11
|
class Translator extends DC {
|
|
@@ -39,83 +40,71 @@ class Translator extends DC {
|
|
|
39
40
|
|
|
40
41
|
(that.Translation as Observable).bind(translationTargetObject);
|
|
41
42
|
|
|
42
|
-
that.target.setAttribute('language', 'en');
|
|
43
|
-
|
|
44
43
|
(that.Language as Observable).notify();
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
class MyButton extends DC {
|
|
49
|
+
#template: string = '{lang.click} {counter}';
|
|
50
|
+
|
|
51
|
+
#languages = {
|
|
52
|
+
en: {
|
|
53
|
+
click: 'click me',
|
|
54
|
+
},
|
|
55
|
+
de: {
|
|
56
|
+
click: 'klick mich',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
Dom: LooseObject = {};
|
|
61
|
+
|
|
62
|
+
constructor(target: HTMLElement) {
|
|
63
|
+
super(target);
|
|
64
|
+
|
|
65
|
+
// render
|
|
66
|
+
target.innerHTML = this.#template;
|
|
67
|
+
|
|
68
|
+
// state
|
|
69
|
+
this.Dom = { counter: 0 };
|
|
70
|
+
|
|
71
|
+
// state: convert all props defined so far into observables
|
|
72
|
+
observe(this);
|
|
73
|
+
|
|
74
|
+
// add translator
|
|
75
|
+
DC.add(
|
|
76
|
+
target,
|
|
77
|
+
'Translator',
|
|
78
|
+
new Translator(target, this.#languages, target)
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// bind Dom to target
|
|
82
|
+
(this.Dom as Observable).bind(this.target);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
onClick(ev: Event) {
|
|
86
|
+
// console.log('button.myButton onClick()');
|
|
87
|
+
const c = this.Dom.counter++;
|
|
88
|
+
ev.stopPropagation();
|
|
89
|
+
(this.target as HTMLElement).classList.remove('clicked');
|
|
90
|
+
(this.target as HTMLElement).classList.add( this.Dom.counter > 9 ? 'overClicked' : 'clicked' );
|
|
55
91
|
}
|
|
56
92
|
}
|
|
57
93
|
|
|
94
|
+
function makeButton(): HTMLMcElement {
|
|
95
|
+
const
|
|
96
|
+
button = document.createElement('button');
|
|
97
|
+
button.classList.add('myButton');
|
|
98
|
+
DC.add( button, 'MyButton', new MyButton(button) );
|
|
99
|
+
return button as unknown as HTMLMcElement;
|
|
100
|
+
}
|
|
101
|
+
|
|
58
102
|
defineCE(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
class MyTag extends DC {
|
|
62
|
-
#template: string = '<button>{lang.click} {counter}</button>';
|
|
63
|
-
|
|
64
|
-
#languages = {
|
|
65
|
-
en: {
|
|
66
|
-
click: 'click me',
|
|
67
|
-
},
|
|
68
|
-
de: {
|
|
69
|
-
click: 'klick mich',
|
|
70
|
-
},
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
Dom: LooseObject = {};
|
|
74
|
-
|
|
75
|
-
constructor(target: HTMLElement) {
|
|
76
|
-
super(target);
|
|
77
|
-
|
|
78
|
-
let that = this; // minifier help
|
|
79
|
-
|
|
80
|
-
// render
|
|
81
|
-
target.innerHTML = this.#template;
|
|
82
|
-
|
|
83
|
-
// add translator
|
|
84
|
-
DC.add(
|
|
85
|
-
target,
|
|
86
|
-
'translator',
|
|
87
|
-
new Translator(target, that.#languages, target)
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
oneInit(ev: CustomEvent) {
|
|
92
|
-
let that = this;
|
|
93
|
-
|
|
94
|
-
// state
|
|
95
|
-
that.Dom = { counter: 0 };
|
|
96
|
-
|
|
97
|
-
// state: convert all props defined so far into observables
|
|
98
|
-
observe(that);
|
|
99
|
-
|
|
100
|
-
// bind Dom to target
|
|
101
|
-
(that.Dom as Observable).bind(that.target);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
onClick(ev: CustomEvent) {
|
|
105
|
-
const that = this,
|
|
106
|
-
c = that.Dom.counter++;
|
|
107
|
-
(ev.detail.data as PointerEvent).stopPropagation();
|
|
108
|
-
(that.target as HTMLElement).classList.remove('clicked');
|
|
109
|
-
(that.target as HTMLElement).classList.add(
|
|
110
|
-
that.Dom.counter > 9 ? 'overClicked' : 'clicked'
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
},
|
|
114
|
-
['language']
|
|
103
|
+
'make-button',
|
|
104
|
+
makeButton
|
|
115
105
|
);
|
|
116
106
|
|
|
117
|
-
let
|
|
118
|
-
fragment = new DocumentFragment();
|
|
107
|
+
let fragment = new DocumentFragment();
|
|
119
108
|
|
|
120
109
|
/*
|
|
121
110
|
stress test
|
|
@@ -126,7 +115,7 @@ let start = new Date().getTime(),
|
|
|
126
115
|
|
|
127
116
|
// create 1000 elements
|
|
128
117
|
for (let x = 0; x < max; x++) {
|
|
129
|
-
fragment.append(
|
|
118
|
+
fragment.append( (getCE('make-button') as Function)());
|
|
130
119
|
}
|
|
131
120
|
|
|
132
121
|
let end = new Date().getTime();
|
|
@@ -148,14 +137,14 @@ setTimeout(() => {
|
|
|
148
137
|
'font-weight: bold; color: black;',
|
|
149
138
|
'font-weight: normal;',
|
|
150
139
|
max,
|
|
151
|
-
max *
|
|
140
|
+
max * 2,
|
|
152
141
|
'font-weight: bold; color: blue;',
|
|
153
142
|
end - start
|
|
154
143
|
);
|
|
155
144
|
|
|
156
145
|
//document.body.appendChild(new MyTag());
|
|
157
146
|
|
|
158
|
-
let element = document.querySelector('
|
|
147
|
+
let element = document.querySelector('button');
|
|
159
148
|
|
|
160
149
|
console.log(
|
|
161
150
|
"\n\n%cInspect this tag:%c \n( ...to see the inner structure in the '._mc' property )\n\n %O %c %s",
|
|
@@ -184,5 +173,5 @@ setTimeout(() => {
|
|
|
184
173
|
);
|
|
185
174
|
|
|
186
175
|
// will trigger the event on all micro components contained in <my-tag>
|
|
187
|
-
|
|
176
|
+
( element as unknown as HTMLMcElement )._mc?.trigger('doSomething');
|
|
188
177
|
}, 1000);
|