@twobirds/microcomponents 0.0.83 → 0.0.84
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/assets/test/test.html +1 -1
- package/dist/MC.d.ts +10 -9
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.js +126 -158
- package/dist/MC.min.js +146 -254
- package/dist/MC.ts +182 -241
- package/dist/elements.d.ts.map +1 -1
- package/dist/elements.js +10 -4
- package/dist/elements.min.js +1 -1
- package/dist/elements.ts +17 -4
- package/dist/formValues.js +2 -2
- package/dist/formValues.min.js +1 -1
- package/dist/formValues.ts +3 -3
- package/dist/microcomponents.d.ts +0 -1
- package/dist/microcomponents.d.ts.map +1 -1
- package/dist/microcomponents.js +0 -1
- package/dist/microcomponents.min.js +1 -1
- package/dist/microcomponents.ts +1 -1
- package/dist/observables.d.ts.map +1 -1
- package/dist/observables.js +14 -12
- package/dist/observables.min.js +1 -1
- package/dist/observables.ts +32 -32
- package/package.json +1 -1
- package/public/MC.d.ts +10 -9
- package/public/MC.d.ts.map +1 -1
- package/public/MC.js +126 -158
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +146 -254
- package/public/MC.ts +182 -241
- package/public/elements.d.ts.map +1 -1
- package/public/elements.js +10 -4
- package/public/elements.js.map +1 -1
- package/public/elements.min.js +1 -1
- package/public/elements.ts +17 -4
- package/public/formValues.js +2 -2
- package/public/formValues.js.map +1 -1
- package/public/formValues.min.js +1 -1
- package/public/formValues.ts +3 -3
- package/public/microcomponents.d.ts +0 -1
- package/public/microcomponents.d.ts.map +1 -1
- package/public/microcomponents.js +0 -1
- package/public/microcomponents.js.map +1 -1
- package/public/microcomponents.min.js +1 -1
- package/public/microcomponents.ts +1 -1
- package/public/observables.d.ts.map +1 -1
- package/public/observables.js +14 -12
- package/public/observables.js.map +1 -1
- package/public/observables.min.js +1 -1
- package/public/observables.ts +32 -32
- package/public/src/MC.d.ts +10 -9
- package/public/src/MC.d.ts.map +1 -1
- package/public/src/MC.js +126 -158
- package/public/src/MC.js.map +1 -1
- package/public/src/MC.ts +182 -241
- package/public/src/elements.d.ts.map +1 -1
- package/public/src/elements.js +10 -4
- package/public/src/elements.js.map +1 -1
- package/public/src/elements.ts +17 -4
- package/public/src/formValues.js +2 -2
- package/public/src/formValues.js.map +1 -1
- package/public/src/formValues.ts +3 -3
- package/public/src/microcomponents.d.ts +0 -1
- package/public/src/microcomponents.d.ts.map +1 -1
- package/public/src/microcomponents.js +0 -1
- package/public/src/microcomponents.js.map +1 -1
- package/public/src/microcomponents.ts +1 -1
- package/public/src/observables.d.ts.map +1 -1
- package/public/src/observables.js +14 -12
- package/public/src/observables.js.map +1 -1
- package/public/src/observables.ts +32 -32
- package/public/src/test/test/grandparent.d.ts.map +1 -1
- package/public/src/test/test/grandparent.js +1 -1
- package/public/src/test/test/grandparent.js.map +1 -1
- package/public/src/test/test/grandparent.ts +12 -4
- package/public/src/test/test/testform.js +1 -1
- package/public/src/test/test/testform.js.map +1 -1
- package/public/src/test/test/testform.ts +6 -8
- package/public/src/test/test.js +5 -4
- package/public/src/test/test.js.map +1 -1
- package/public/src/test/test.ts +8 -8
- package/public/test/MC.d.ts +10 -9
- package/public/test/MC.d.ts.map +1 -1
- package/public/test/MC.js +126 -158
- package/public/test/MC.min.js +146 -254
- package/public/test/MC.ts +182 -241
- package/public/test/elements.d.ts.map +1 -1
- package/public/test/elements.js +10 -4
- package/public/test/elements.min.js +1 -1
- package/public/test/elements.ts +17 -4
- package/public/test/formValues.js +2 -2
- package/public/test/formValues.min.js +1 -1
- package/public/test/formValues.ts +3 -3
- package/public/test/microcomponents.d.ts +0 -1
- package/public/test/microcomponents.d.ts.map +1 -1
- package/public/test/microcomponents.js +0 -1
- package/public/test/microcomponents.min.js +1 -1
- package/public/test/microcomponents.ts +1 -1
- package/public/test/observables.d.ts.map +1 -1
- package/public/test/observables.js +14 -12
- package/public/test/observables.min.js +1 -1
- package/public/test/observables.ts +32 -32
- package/public/test/test/grandparent.d.ts.map +1 -1
- package/public/test/test/grandparent.js +1 -1
- package/public/test/test/grandparent.js.map +1 -1
- package/public/test/test/grandparent.ts +12 -4
- package/public/test/test/testform.js +1 -1
- package/public/test/test/testform.js.map +1 -1
- package/public/test/test/testform.ts +6 -8
- package/public/test/test.html +1 -1
- package/public/test/test.js +5 -4
- package/public/test/test.js.map +1 -1
- package/public/test/test.ts +8 -8
- package/public/typedoc/assets/navigation.js +1 -1
- package/public/typedoc/assets/search.js +1 -1
- package/public/typedoc/classes/MC.DC.html +6 -4
- package/public/typedoc/classes/MC.MC.html +3 -4
- package/public/typedoc/classes/MC.McBase.html +3 -4
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.off.html +1 -0
- package/public/typedoc/functions/MC.on.html +1 -0
- package/public/typedoc/functions/MC.one.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/interfaces/MC.HTMLMcElement.html +2 -2
- package/public/typedoc/modules/MC.html +7 -6
- 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 +182 -241
- package/src/elements.ts +17 -4
- package/src/formValues.ts +3 -3
- package/src/microcomponents.ts +1 -1
- package/src/observables.ts +32 -32
- package/src/test/test/grandparent.ts +12 -4
- package/src/test/test/testform.ts +6 -8
- package/src/test/test.ts +8 -8
- package/tsconfig.json +2 -2
- package/typedoc.json +1 -1
- package/webpack.config.js +2 -2
- package/dist/McEvent.d.ts +0 -15
- package/dist/McEvent.d.ts.map +0 -1
- package/dist/McEvent.js +0 -71
- package/dist/selectors.d.ts +0 -106
- package/dist/selectors.d.ts.map +0 -1
- package/dist/selectors.js +0 -759
- package/dist/selectors.min.js +0 -1
- package/public/McEvent.d.ts +0 -15
- package/public/McEvent.d.ts.map +0 -1
- package/public/McEvent.js +0 -71
- package/public/McEvent.js.map +0 -1
- package/public/selectors.d.ts +0 -106
- package/public/selectors.d.ts.map +0 -1
- package/public/selectors.js +0 -759
- package/public/selectors.js.map +0 -1
- package/public/selectors.min.js +0 -1
- package/public/src/McEvent.d.ts +0 -15
- package/public/src/McEvent.d.ts.map +0 -1
- package/public/src/McEvent.js +0 -71
- package/public/src/McEvent.js.map +0 -1
- package/public/src/selectors.d.ts +0 -106
- package/public/src/selectors.d.ts.map +0 -1
- package/public/src/selectors.js +0 -759
- package/public/src/selectors.js.map +0 -1
- package/public/test/McEvent.d.ts +0 -15
- package/public/test/McEvent.d.ts.map +0 -1
- package/public/test/McEvent.js +0 -71
- package/public/test/McEvent.ts +0 -96
- package/public/test/selectors.d.ts +0 -106
- package/public/test/selectors.d.ts.map +0 -1
- package/public/test/selectors.js +0 -759
- package/public/test/selectors.min.js +0 -1
- package/public/test/selectors.ts +0 -1269
- package/public/typedoc/classes/MC.McEvent.html +0 -9
- package/public/typedoc/functions/MC.addListener.html +0 -1
- package/public/typedoc/functions/MC.removeListener.html +0 -1
- 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 -48
- 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/McEvent.ts +0 -96
- package/src/selectors.ts +0 -1269
- /package/{dist/McEvent.ts → public/McEvent._ts} +0 -0
- /package/{dist/selectors.ts → public/selectors._ts} +0 -0
- /package/public/{McEvent.ts → src/McEvent._ts} +0 -0
- /package/public/{selectors.ts → src/selectors._ts} +0 -0
- /package/{public/src/McEvent.ts → src/McEvent._ts} +0 -0
- /package/{public/src/selectors.ts → src/selectors._ts} +0 -0
package/public/MC.min.js
CHANGED
|
@@ -44,103 +44,29 @@ return /******/ (() => { // webpackBootstrap
|
|
|
44
44
|
/******/
|
|
45
45
|
/************************************************************************/
|
|
46
46
|
var __webpack_exports__ = {};
|
|
47
|
-
// ESM COMPAT FLAG
|
|
48
47
|
__webpack_require__.r(__webpack_exports__);
|
|
48
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
49
|
+
/* harmony export */ DC: () => (/* binding */ DC),
|
|
50
|
+
/* harmony export */ MC: () => (/* binding */ MC),
|
|
51
|
+
/* harmony export */ McBase: () => (/* binding */ McBase),
|
|
52
|
+
/* harmony export */ autoload: () => (/* binding */ autoload),
|
|
53
|
+
/* harmony export */ off: () => (/* binding */ off),
|
|
54
|
+
/* harmony export */ on: () => (/* binding */ on),
|
|
55
|
+
/* harmony export */ one: () => (/* binding */ one),
|
|
56
|
+
/* harmony export */ trigger: () => (/* binding */ trigger)
|
|
57
|
+
/* harmony export */ });
|
|
49
58
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
autoload: () => (/* binding */ autoload),
|
|
58
|
-
removeListener: () => (/* binding */ removeListener)
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
;// ./build/McEvent.js
|
|
62
|
-
|
|
63
|
-
var isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
|
|
64
|
-
let nativeEventNames = new Set();
|
|
65
|
-
if (isBrowser()) {
|
|
66
|
-
Object.keys(HTMLElement.prototype).filter(key => /^on/.test(key)).forEach(eventName => nativeEventNames.add(eventName));
|
|
67
|
-
}
|
|
68
|
-
function isDOM(element) {
|
|
69
|
-
return element && element instanceof HTMLElement;
|
|
70
|
-
}
|
|
71
|
-
class McEvent {
|
|
72
|
-
#type;
|
|
73
|
-
#stopped = false;
|
|
74
|
-
#immediateStopped = false;
|
|
75
|
-
constructor(type, data = {}, bubble = 'l') {
|
|
76
|
-
this.#type = type;
|
|
77
|
-
this.data = data;
|
|
78
|
-
this.bubble = bubble;
|
|
79
|
-
}
|
|
80
|
-
get type() {
|
|
81
|
-
return this.#type;
|
|
82
|
-
}
|
|
83
|
-
get stopped() {
|
|
84
|
-
return this.#stopped;
|
|
85
|
-
}
|
|
86
|
-
get immediateStopped() {
|
|
87
|
-
return this.#immediateStopped;
|
|
88
|
-
}
|
|
89
|
-
stopPropagation() {
|
|
90
|
-
this.#stopped = true;
|
|
91
|
-
}
|
|
92
|
-
stopImmediatePropagation() {
|
|
93
|
-
this.stopPropagation();
|
|
94
|
-
this.#immediateStopped = true;
|
|
59
|
+
var isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
|
|
60
|
+
function getNativeEventNames(domNode) {
|
|
61
|
+
let nativeEventNames = [];
|
|
62
|
+
if (isBrowser()) {
|
|
63
|
+
Object.keys(HTMLElement.prototype)
|
|
64
|
+
.filter((key) => /^on/.test(key))
|
|
65
|
+
.forEach((eventName) => nativeEventNames.push(eventName));
|
|
95
66
|
}
|
|
67
|
+
return nativeEventNames;
|
|
96
68
|
}
|
|
97
69
|
function getMicroComponents(elements, search) {
|
|
98
|
-
let mcValues = [];
|
|
99
|
-
elements.forEach(e => {
|
|
100
|
-
if (e) {
|
|
101
|
-
if (e instanceof HTMLElement) {
|
|
102
|
-
const _mc = e?._mc;
|
|
103
|
-
if (!search && _mc) {
|
|
104
|
-
mcValues = mcValues.concat(Object.values(e._mc));
|
|
105
|
-
}
|
|
106
|
-
else if (search && _mc && _mc[search]) {
|
|
107
|
-
mcValues.push(_mc[search]);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
return mcValues;
|
|
113
|
-
}
|
|
114
|
-
function traverseNodes(node, search, firstonly = true) {
|
|
115
|
-
let mcValues = [];
|
|
116
|
-
while (node) {
|
|
117
|
-
if (node._mc) {
|
|
118
|
-
if (!search) {
|
|
119
|
-
mcValues = mcValues.concat(Object.values(node._mc));
|
|
120
|
-
}
|
|
121
|
-
else if (search && node._mc[search]) {
|
|
122
|
-
mcValues.push(node._mc[search]);
|
|
123
|
-
}
|
|
124
|
-
if (firstonly)
|
|
125
|
-
return mcValues;
|
|
126
|
-
}
|
|
127
|
-
node = node.parentNode;
|
|
128
|
-
}
|
|
129
|
-
return mcValues;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
;// ./build/MC.js
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
var MC_isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
|
|
137
|
-
let MC_nativeEventNames = new Set();
|
|
138
|
-
if (MC_isBrowser()) {
|
|
139
|
-
Object.keys(HTMLElement.prototype)
|
|
140
|
-
.filter((key) => /^on/.test(key))
|
|
141
|
-
.forEach((eventName) => MC_nativeEventNames.add(eventName));
|
|
142
|
-
}
|
|
143
|
-
function MC_getMicroComponents(elements, search) {
|
|
144
70
|
let mcValues = [];
|
|
145
71
|
elements.forEach((e) => {
|
|
146
72
|
if (e) {
|
|
@@ -157,7 +83,7 @@ function MC_getMicroComponents(elements, search) {
|
|
|
157
83
|
});
|
|
158
84
|
return mcValues;
|
|
159
85
|
}
|
|
160
|
-
function
|
|
86
|
+
function traverseNodes(node, search, firstonly = true) {
|
|
161
87
|
let mcValues = [];
|
|
162
88
|
while (node) {
|
|
163
89
|
if (node._mc) {
|
|
@@ -174,22 +100,9 @@ function MC_traverseNodes(node, search, firstonly = true) {
|
|
|
174
100
|
}
|
|
175
101
|
return mcValues;
|
|
176
102
|
}
|
|
177
|
-
function
|
|
103
|
+
function isDOM(element) {
|
|
178
104
|
return element && element instanceof HTMLElement;
|
|
179
105
|
}
|
|
180
|
-
function addListener(domNode, eventName, handler, capture = false, once = false) {
|
|
181
|
-
let options = { once: false };
|
|
182
|
-
if (capture) {
|
|
183
|
-
options.capture = capture;
|
|
184
|
-
}
|
|
185
|
-
if (once) {
|
|
186
|
-
options.once = once;
|
|
187
|
-
}
|
|
188
|
-
domNode.addEventListener(eventName, handler, options);
|
|
189
|
-
}
|
|
190
|
-
function removeListener(domNode, eventName, handler) {
|
|
191
|
-
domNode.removeEventListener(eventName, handler);
|
|
192
|
-
}
|
|
193
106
|
function add(target, key, element = {}) {
|
|
194
107
|
let node = target;
|
|
195
108
|
if (!node._mc) {
|
|
@@ -202,8 +115,8 @@ function add(target, key, element = {}) {
|
|
|
202
115
|
const _mc = node._mc;
|
|
203
116
|
if (key.length && !_mc[key]) {
|
|
204
117
|
_mc[key] = element;
|
|
205
|
-
if (target instanceof HTMLElement && !target.getAttribute('
|
|
206
|
-
target.setAttribute('
|
|
118
|
+
if (target instanceof HTMLElement && !target.getAttribute('data-mc')) {
|
|
119
|
+
target.setAttribute('data-mc', '');
|
|
207
120
|
}
|
|
208
121
|
}
|
|
209
122
|
return element;
|
|
@@ -217,25 +130,8 @@ function remove(target, key) {
|
|
|
217
130
|
}
|
|
218
131
|
if (!Object.keys(_mc).length &&
|
|
219
132
|
target instanceof HTMLElement &&
|
|
220
|
-
target.hasAttribute('
|
|
221
|
-
target.removeAttribute('
|
|
222
|
-
}
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
function trigger(target, ev, data = {}, bubble = 'l') {
|
|
226
|
-
let _mc = target?._mc;
|
|
227
|
-
if (!_mc)
|
|
228
|
-
return;
|
|
229
|
-
let event = ev instanceof McEvent
|
|
230
|
-
? new McEvent(ev.type, ev.data, 'l')
|
|
231
|
-
: new McEvent(ev, data, 'l'), mcEvent = typeof ev !== 'string' ? ev : new McEvent(ev, data, bubble);
|
|
232
|
-
[...Object.values(_mc)].forEach((mc) => {
|
|
233
|
-
if (mc?.trigger && typeof mc?.trigger === 'function') {
|
|
234
|
-
mc?.trigger(event);
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
if (/[ud]/.test(mcEvent.bubble)) {
|
|
238
|
-
bubbleEvent(target, mcEvent);
|
|
133
|
+
target.hasAttribute('data-mc')) {
|
|
134
|
+
target.removeAttribute('data-mc');
|
|
239
135
|
}
|
|
240
136
|
return;
|
|
241
137
|
}
|
|
@@ -246,8 +142,50 @@ function init(element) {
|
|
|
246
142
|
element.trigger('Init');
|
|
247
143
|
}, 0);
|
|
248
144
|
}
|
|
145
|
+
function getMcEventName(eventName) {
|
|
146
|
+
return '_mc' + eventName[0].toUpperCase() + eventName.substring(1);
|
|
147
|
+
}
|
|
148
|
+
function off(domNode, eventName, handler) {
|
|
149
|
+
domNode.removeEventListener(getMcEventName(eventName), handler);
|
|
150
|
+
}
|
|
151
|
+
function on(domNode, eventName, handler, once = false) {
|
|
152
|
+
domNode.addEventListener(getMcEventName(eventName), handler, { capture: false, once });
|
|
153
|
+
}
|
|
154
|
+
function one(domNode, eventName, handler) {
|
|
155
|
+
on(domNode, eventName, handler, true);
|
|
156
|
+
}
|
|
157
|
+
function trigger(domNode, event, data = {}, bubble = 'l') {
|
|
158
|
+
const ev = typeof event === 'string'
|
|
159
|
+
? new CustomEvent(getMcEventName(event), { detail: { data, bubble } })
|
|
160
|
+
: event;
|
|
161
|
+
if (bubble.length && bubble.indexOf('l') > -1) {
|
|
162
|
+
domNode.dispatchEvent(ev);
|
|
163
|
+
}
|
|
164
|
+
if (/[u|d]/.test(bubble)) {
|
|
165
|
+
bubbleEvent(domNode, ev);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
function bubbleEvent(domNode, ev) {
|
|
169
|
+
setTimeout(() => {
|
|
170
|
+
if (ev.detail.bubble.indexOf('l') === -1) {
|
|
171
|
+
ev.detail.bubble += 'l';
|
|
172
|
+
}
|
|
173
|
+
if (ev.detail.bubble.indexOf('u') > -1) {
|
|
174
|
+
domNode.closest('[data-mc]')?.dispatchEvent(ev);
|
|
175
|
+
}
|
|
176
|
+
if (ev.detail.bubble.indexOf('d') > -1) {
|
|
177
|
+
let targets = new Set(domNode._mc
|
|
178
|
+
.children()
|
|
179
|
+
.map((c) => c?.target));
|
|
180
|
+
targets.forEach((target) => {
|
|
181
|
+
if (target)
|
|
182
|
+
DC.trigger(target, ev);
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}, 0);
|
|
186
|
+
}
|
|
249
187
|
function autoAttachListeners(element) {
|
|
250
|
-
if (!
|
|
188
|
+
if (!isBrowser() || element.constructor === DC)
|
|
251
189
|
return;
|
|
252
190
|
const target = element.target;
|
|
253
191
|
if (target instanceof HTMLElement) {
|
|
@@ -256,53 +194,31 @@ function autoAttachListeners(element) {
|
|
|
256
194
|
.filter((key) => /^on[A-Z]|one[A-Z]/.test(key) &&
|
|
257
195
|
typeof that.constructor.prototype[key] === 'function')
|
|
258
196
|
.forEach((key) => {
|
|
259
|
-
let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), nativeEventName = withoutOnOne.toLowerCase()
|
|
260
|
-
|
|
197
|
+
let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), nativeEventName = withoutOnOne.toLowerCase();
|
|
198
|
+
let listener = (ev) => {
|
|
199
|
+
that[key](ev);
|
|
261
200
|
};
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
configurable: true,
|
|
265
|
-
enumerable: false,
|
|
266
|
-
writable: true,
|
|
267
|
-
value: (ev) => {
|
|
268
|
-
that.constructor.prototype[key].bind(that)(ev);
|
|
269
|
-
},
|
|
270
|
-
});
|
|
201
|
+
if (!!target['on' + nativeEventName]) {
|
|
202
|
+
target.addEventListener(nativeEventName, listener);
|
|
271
203
|
}
|
|
272
|
-
|
|
273
|
-
|
|
204
|
+
else {
|
|
205
|
+
on(target, withoutOnOne, listener, once);
|
|
274
206
|
}
|
|
275
207
|
});
|
|
276
208
|
}
|
|
277
209
|
}
|
|
278
|
-
function
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
let parent = MC_traverseNodes(target, '', true)?.[0].target;
|
|
286
|
-
if (parent)
|
|
287
|
-
DC.trigger(parent, ev);
|
|
288
|
-
}
|
|
289
|
-
if (ev.bubble.indexOf('d') > -1) {
|
|
290
|
-
let targets = new Set(target._mc
|
|
291
|
-
.children()
|
|
292
|
-
.map((c) => c?.target));
|
|
293
|
-
targets.forEach((target) => {
|
|
294
|
-
if (target)
|
|
295
|
-
DC.trigger(target, ev);
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}, 0);
|
|
299
|
-
}
|
|
210
|
+
function getMcChildNodes(domNode) {
|
|
211
|
+
const id = Math.random().toString().replace('.', '');
|
|
212
|
+
const selector = '[data-mc]:not([temp_id="' + id + '"] [data-mc] [data-mc])';
|
|
213
|
+
domNode.setAttribute('temp_id', id);
|
|
214
|
+
const myDomElements = domNode.querySelectorAll(selector);
|
|
215
|
+
domNode.removeAttribute('temp_id');
|
|
216
|
+
return myDomElements;
|
|
300
217
|
}
|
|
301
218
|
class McBase {
|
|
302
219
|
_target;
|
|
303
|
-
__mc = {};
|
|
304
220
|
constructor(target, debug = false) {
|
|
305
|
-
let
|
|
221
|
+
let element = this;
|
|
306
222
|
this._target = new WeakRef(target || {});
|
|
307
223
|
init(element);
|
|
308
224
|
autoAttachListeners(element);
|
|
@@ -310,9 +226,6 @@ class McBase {
|
|
|
310
226
|
get target() {
|
|
311
227
|
return this._target.deref();
|
|
312
228
|
}
|
|
313
|
-
get _mc() {
|
|
314
|
-
return this.__mc;
|
|
315
|
-
}
|
|
316
229
|
}
|
|
317
230
|
class MC extends McBase {
|
|
318
231
|
constructor(target) {
|
|
@@ -320,44 +233,6 @@ class MC extends McBase {
|
|
|
320
233
|
}
|
|
321
234
|
static trigger = trigger;
|
|
322
235
|
trigger(ev, data = {}, bubble = 'l') {
|
|
323
|
-
let that = this;
|
|
324
|
-
if (that.constructor === MC || that.constructor === DC) {
|
|
325
|
-
let event = ev instanceof McEvent
|
|
326
|
-
? new McEvent(ev.type, ev.data, 'l')
|
|
327
|
-
: new McEvent(ev, data, 'l'), mcEvent = typeof ev !== 'string'
|
|
328
|
-
? ev
|
|
329
|
-
: new McEvent(ev, data, bubble);
|
|
330
|
-
[...Object.getOwnPropertyNames(that)].forEach((mc) => {
|
|
331
|
-
if (that[mc]?.trigger &&
|
|
332
|
-
typeof that[mc]?.trigger === 'function') {
|
|
333
|
-
that[mc]?.trigger(event);
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
if (/[ud]/.test(mcEvent.bubble)) {
|
|
337
|
-
bubbleEvent(that.target, mcEvent);
|
|
338
|
-
}
|
|
339
|
-
return;
|
|
340
|
-
}
|
|
341
|
-
if (that instanceof MC || that instanceof DC) {
|
|
342
|
-
const that = this, mcEvent = typeof ev !== 'string'
|
|
343
|
-
? ev
|
|
344
|
-
: new McEvent(ev, data, bubble), handlerName = 'on' + mcEvent.type[0].toUpperCase() + mcEvent.type.slice(1);
|
|
345
|
-
if (mcEvent.bubble.indexOf('l') > -1) {
|
|
346
|
-
if (!mcEvent.immediateStopped &&
|
|
347
|
-
typeof that[handlerName] === 'function') {
|
|
348
|
-
that[handlerName](mcEvent);
|
|
349
|
-
if (that.hasOwnProperty(handlerName)) {
|
|
350
|
-
delete that[handlerName];
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
if (mcEvent.stopped || mcEvent.bubble === 'l') {
|
|
355
|
-
return that;
|
|
356
|
-
}
|
|
357
|
-
if (/[ud]/.test(mcEvent.bubble)) {
|
|
358
|
-
bubbleEvent(that.target, mcEvent);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
236
|
}
|
|
362
237
|
}
|
|
363
238
|
class DC extends McBase {
|
|
@@ -367,58 +242,52 @@ class DC extends McBase {
|
|
|
367
242
|
static add = add;
|
|
368
243
|
static remove = remove;
|
|
369
244
|
static trigger = trigger;
|
|
370
|
-
|
|
371
|
-
|
|
245
|
+
off(eventName, handler) {
|
|
246
|
+
off(this.target, eventName, handler);
|
|
247
|
+
}
|
|
248
|
+
on(eventName, handler) {
|
|
249
|
+
on(this.target, eventName, handler);
|
|
250
|
+
}
|
|
251
|
+
one(eventName, handler) {
|
|
252
|
+
one(this.target, eventName, handler);
|
|
253
|
+
}
|
|
254
|
+
trigger(ev, data = {}, bubble = 'l') {
|
|
255
|
+
if (typeof ev === 'string') {
|
|
256
|
+
}
|
|
372
257
|
}
|
|
373
258
|
parent(search = '') {
|
|
374
259
|
let target = this.target;
|
|
375
|
-
if (!
|
|
260
|
+
if (!isDOM(target))
|
|
376
261
|
return [];
|
|
377
|
-
return
|
|
262
|
+
return traverseNodes(target.parentNode, search, true);
|
|
378
263
|
}
|
|
379
264
|
ancestors(search = '') {
|
|
380
265
|
let target = this?.target;
|
|
381
|
-
if (!
|
|
266
|
+
if (!isDOM(target))
|
|
382
267
|
return [];
|
|
383
|
-
return
|
|
268
|
+
return traverseNodes(this.target.parentNode, search, false);
|
|
384
269
|
}
|
|
385
270
|
children(search = '') {
|
|
386
271
|
let target = this?.target;
|
|
387
|
-
if (!
|
|
272
|
+
if (!isDOM(target))
|
|
388
273
|
return [];
|
|
389
|
-
const
|
|
390
|
-
const
|
|
391
|
-
target.setAttribute('temp_id', id);
|
|
392
|
-
const myDomElements = target.querySelectorAll(selector);
|
|
393
|
-
const mcValues = MC_getMicroComponents([...myDomElements], search);
|
|
394
|
-
target.removeAttribute('temp_id');
|
|
274
|
+
const myDomElements = getMcChildNodes(target);
|
|
275
|
+
const mcValues = getMicroComponents([...myDomElements], search);
|
|
395
276
|
return mcValues;
|
|
396
277
|
}
|
|
397
278
|
descendants(search = '') {
|
|
398
279
|
let target = this?.target;
|
|
399
|
-
if (!
|
|
280
|
+
if (!isDOM(target))
|
|
400
281
|
return [];
|
|
401
|
-
const myDomElements = target.querySelectorAll('*[
|
|
402
|
-
return
|
|
282
|
+
const myDomElements = target.querySelectorAll('*[data-mc]');
|
|
283
|
+
return getMicroComponents([...myDomElements], search);
|
|
403
284
|
}
|
|
404
285
|
}
|
|
405
|
-
const
|
|
406
|
-
function
|
|
407
|
-
|
|
408
|
-
return;
|
|
409
|
-
loadingMCs.add(element);
|
|
410
|
-
const fileName = './' + element.split('-').join('/') + '.js';
|
|
411
|
-
const se = document.createElement('script');
|
|
412
|
-
se.setAttribute('src', fileName);
|
|
413
|
-
se.setAttribute('blocking', 'render');
|
|
414
|
-
se.async = true;
|
|
415
|
-
se.setAttribute('type', 'module');
|
|
416
|
-
se.setAttribute('data-name', element);
|
|
417
|
-
se.setAttribute('loading', '');
|
|
418
|
-
const loadedPromise = customElements.whenDefined(element);
|
|
419
|
-
loadedPromise.then(() => {
|
|
286
|
+
const loadingDCs = new Set();
|
|
287
|
+
function attachDC(element) {
|
|
288
|
+
return () => {
|
|
420
289
|
const elements = Array
|
|
421
|
-
.from(document.querySelectorAll(`[
|
|
290
|
+
.from(document.querySelectorAll(`[data-mc*="${element}"]`))
|
|
422
291
|
.filter(element => element instanceof HTMLElement);
|
|
423
292
|
if (elements.length === 0)
|
|
424
293
|
return;
|
|
@@ -426,19 +295,36 @@ function makeLoadScript(element) {
|
|
|
426
295
|
elements.forEach((node) => {
|
|
427
296
|
DC.add(node, klass.name, new klass(node));
|
|
428
297
|
const new_mc = node
|
|
429
|
-
.getAttribute('
|
|
298
|
+
.getAttribute('data-mc')
|
|
430
299
|
.split(' ')
|
|
431
300
|
.filter((name) => name !== element && name !== '')
|
|
432
|
-
.join(' ')
|
|
433
|
-
|
|
301
|
+
.join(' ')
|
|
302
|
+
.trim();
|
|
303
|
+
node.setAttribute('data-mc', new_mc);
|
|
434
304
|
});
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
;
|
|
308
|
+
function makeLoadScript(element) {
|
|
309
|
+
if (loadingDCs.has(element))
|
|
310
|
+
return;
|
|
311
|
+
loadingDCs.add(element);
|
|
312
|
+
const fileName = './' + element.split('-').join('/') + '.js';
|
|
313
|
+
const se = document.createElement('script');
|
|
314
|
+
se.setAttribute('src', fileName);
|
|
315
|
+
se.setAttribute('blocking', 'render');
|
|
316
|
+
se.async = true;
|
|
317
|
+
se.setAttribute('type', 'module');
|
|
318
|
+
se.setAttribute('data-name', element);
|
|
319
|
+
se.setAttribute('loading', '');
|
|
320
|
+
const loadedPromise = customElements.whenDefined(element);
|
|
321
|
+
loadedPromise.then(attachDC(element));
|
|
322
|
+
se.addEventListener('load', (ev) => {
|
|
323
|
+
loadingDCs.delete(element);
|
|
324
|
+
document.head.querySelector(`script[data-name="${element}"]`)?.remove();
|
|
439
325
|
});
|
|
440
|
-
|
|
441
|
-
console.error('could not load
|
|
326
|
+
se.addEventListener('error', (ev) => {
|
|
327
|
+
console.error('could not load DC code from', fileName);
|
|
442
328
|
});
|
|
443
329
|
document.head.append(se);
|
|
444
330
|
}
|
|
@@ -446,16 +332,22 @@ function loadUndefinedMCs() {
|
|
|
446
332
|
[...document.querySelectorAll(':not(:defined)')]
|
|
447
333
|
.filter((element) => !!element
|
|
448
334
|
&& !customElements.get(element.tagName.toLowerCase())
|
|
449
|
-
&& !
|
|
335
|
+
&& !loadingDCs.has(element.tagName.toLowerCase()))
|
|
450
336
|
.forEach((el) => {
|
|
451
337
|
makeLoadScript(el.tagName.toLowerCase());
|
|
452
338
|
});
|
|
453
|
-
[...document.querySelectorAll('[
|
|
339
|
+
[...document.querySelectorAll('[data-mc]:not([data-mc=""]')]
|
|
454
340
|
.filter((element) => !!element)
|
|
455
341
|
.forEach((el) => {
|
|
456
|
-
const _mc = el.getAttribute('
|
|
457
|
-
_mc?.forEach(
|
|
458
|
-
|
|
342
|
+
const _mc = el.getAttribute('data-mc')?.split(' ').filter(name => name !== '');
|
|
343
|
+
_mc?.forEach(element => {
|
|
344
|
+
const isDefined = customElements.get(element);
|
|
345
|
+
if (!loadingDCs.has(element) && !isDefined) {
|
|
346
|
+
makeLoadScript(element);
|
|
347
|
+
}
|
|
348
|
+
else if (isDefined) {
|
|
349
|
+
attachDC(element)();
|
|
350
|
+
}
|
|
459
351
|
});
|
|
460
352
|
});
|
|
461
353
|
}
|
|
@@ -476,7 +368,7 @@ function autoload(enable = true) {
|
|
|
476
368
|
window.autoload = window.autoload || autoload;
|
|
477
369
|
return autoloadEnabled;
|
|
478
370
|
}
|
|
479
|
-
autoload.state =
|
|
371
|
+
autoload.state = loadingDCs;
|
|
480
372
|
|
|
481
373
|
|
|
482
374
|
/******/ return __webpack_exports__;
|