@twobirds/microcomponents 0.0.33 → 0.0.37
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/dist/MC.d.ts +2 -3
- package/dist/MC.d.ts.map +1 -1
- package/dist/MC.min.js +45 -43
- package/dist/MC.ts +173 -175
- 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 +354 -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 +133 -157
- package/klemmstein.png +0 -0
- package/package.json +52 -52
- package/public/MC.js +46 -44
- package/public/MC.js.map +1 -1
- package/public/MC.min.js +45 -43
- 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/observables.js +255 -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 +376 -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 +354 -0
- package/public/src/test.ts +187 -0
- package/public/test.js +99 -115
- 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 +173 -175
- 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 +354 -0
- package/src/selectors.ts +1634 -0
- package/src/test.ts +133 -157
- 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/MC.min.js
CHANGED
|
@@ -136,16 +136,18 @@ function traverseNodes(node, search, firstonly = true) {
|
|
|
136
136
|
;// ./build/MC.js
|
|
137
137
|
|
|
138
138
|
|
|
139
|
-
var MC_isBrowser = new Function(
|
|
139
|
+
var MC_isBrowser = new Function('try {return this===window;}catch(e){ return false;}');
|
|
140
140
|
let MC_nativeEventNames = new Set();
|
|
141
141
|
// HTMLElement native event names
|
|
142
142
|
if (MC_isBrowser()) {
|
|
143
|
-
Object.keys(HTMLElement.prototype)
|
|
143
|
+
Object.keys(HTMLElement.prototype)
|
|
144
|
+
.filter((key) => /^on/.test(key))
|
|
145
|
+
.forEach((eventName) => MC_nativeEventNames.add(eventName));
|
|
144
146
|
}
|
|
145
147
|
// get all microcomponents from a list of HTMLElements
|
|
146
148
|
function MC_getMicroComponents(elements, search) {
|
|
147
149
|
let mcValues = [];
|
|
148
|
-
elements.forEach(e => {
|
|
150
|
+
elements.forEach((e) => {
|
|
149
151
|
if (e) {
|
|
150
152
|
if (e instanceof HTMLElement) {
|
|
151
153
|
const _mc = e?._mc;
|
|
@@ -227,7 +229,9 @@ function remove(target, key) {
|
|
|
227
229
|
delete _mc[key];
|
|
228
230
|
}
|
|
229
231
|
// remove the _mc attribute if the DOM collection is empty
|
|
230
|
-
if (!Object.keys(_mc).length &&
|
|
232
|
+
if (!Object.keys(_mc).length &&
|
|
233
|
+
target instanceof HTMLElement &&
|
|
234
|
+
target.hasAttribute('_mc')) {
|
|
231
235
|
target.removeAttribute('_mc');
|
|
232
236
|
}
|
|
233
237
|
return;
|
|
@@ -245,26 +249,25 @@ function trigger(target, ev, data = {}) {
|
|
|
245
249
|
});
|
|
246
250
|
return;
|
|
247
251
|
}
|
|
248
|
-
// run the "init" lifecycle event on the
|
|
252
|
+
// run the "init" lifecycle event on the complete _mc structure
|
|
249
253
|
function init(element) {
|
|
250
254
|
if (element.constructor === DC)
|
|
251
255
|
return;
|
|
252
256
|
setTimeout(() => {
|
|
253
257
|
element.trigger('Init');
|
|
254
|
-
|
|
255
|
-
let keys = Object.keys(element?._mc);
|
|
256
|
-
if (keys.length)
|
|
258
|
+
/*
|
|
259
|
+
let keys = Object.keys( ( element as any)?._mc );
|
|
260
|
+
if ( keys.length ){
|
|
257
261
|
//console.log( 'inner Inits on [', mc.constructor.name, ']', keys );
|
|
258
|
-
keys?.forEach((key) => {
|
|
259
|
-
let mc = element?._mc?.[key];
|
|
262
|
+
keys?.forEach( (key: string) => {
|
|
263
|
+
let mc = ( element as any)?._mc?.[key];
|
|
260
264
|
//console.log( key, typeof mc?.oneInit, mc );
|
|
261
|
-
if (mc['oneInit'] &&
|
|
262
|
-
mc.oneInit(new McEvent('Init'));
|
|
265
|
+
if ( ( mc as any )['oneInit'] && typeof ( mc as any ).oneInit == 'function' ){
|
|
266
|
+
( mc as any ).oneInit( new McEvent('Init') );
|
|
263
267
|
}
|
|
264
268
|
});
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
}, 0);
|
|
269
|
+
};
|
|
270
|
+
*/
|
|
268
271
|
}, 0);
|
|
269
272
|
}
|
|
270
273
|
function autoAttachListeners(element) {
|
|
@@ -273,13 +276,14 @@ function autoAttachListeners(element) {
|
|
|
273
276
|
const target = element.target;
|
|
274
277
|
if (target instanceof HTMLElement) {
|
|
275
278
|
let that = element;
|
|
276
|
-
Object
|
|
277
|
-
.
|
|
278
|
-
|
|
279
|
-
.forEach(key => {
|
|
279
|
+
Object.getOwnPropertyNames(that.constructor.prototype)
|
|
280
|
+
.filter((key) => /^on[A-Z]|one[A-Z]/.test(key) &&
|
|
281
|
+
typeof that.constructor.prototype[key] === 'function')
|
|
282
|
+
.forEach((key) => {
|
|
280
283
|
let once = /^one/.test(key), withoutOnOne = key.replace(/^on[e]{0,1}/, ''), // preserves upper/lowercase for non-native events
|
|
281
|
-
nativeEventName = withoutOnOne.toLowerCase(), listener = (ev) => {
|
|
282
|
-
|
|
284
|
+
nativeEventName = withoutOnOne.toLowerCase(), listener = (ev) => {
|
|
285
|
+
that.trigger(withoutOnOne, ev);
|
|
286
|
+
};
|
|
283
287
|
if (once) {
|
|
284
288
|
// console.log( '...is only called once', that.constructor.prototype[key] );
|
|
285
289
|
Object.defineProperty(element, 'on' + withoutOnOne, {
|
|
@@ -288,11 +292,12 @@ function autoAttachListeners(element) {
|
|
|
288
292
|
writable: true,
|
|
289
293
|
value: (ev) => {
|
|
290
294
|
// console.log( 'onceHandler execute:', that.constructor.prototype[key] );
|
|
291
|
-
|
|
292
|
-
}
|
|
295
|
+
that.constructor.prototype[key].bind(that)(ev);
|
|
296
|
+
},
|
|
293
297
|
});
|
|
294
298
|
}
|
|
295
|
-
if (MC_nativeEventNames.has('on' + nativeEventName)) {
|
|
299
|
+
if (MC_nativeEventNames.has('on' + nativeEventName)) {
|
|
300
|
+
// native event defined in HTMLElement
|
|
296
301
|
// console.log('added as native listener', target, nativeEventName );
|
|
297
302
|
addListener(target, nativeEventName, listener, false, once);
|
|
298
303
|
}
|
|
@@ -301,7 +306,7 @@ function autoAttachListeners(element) {
|
|
|
301
306
|
}
|
|
302
307
|
class McBase {
|
|
303
308
|
#target; // avoid circular reference
|
|
304
|
-
constructor(target) {
|
|
309
|
+
constructor(target, debug = false) {
|
|
305
310
|
let that = this, element = that;
|
|
306
311
|
this.#target = new WeakRef(target || {});
|
|
307
312
|
init(element); // async lifecycle event
|
|
@@ -324,7 +329,8 @@ class MC extends McBase {
|
|
|
324
329
|
// run all triggers
|
|
325
330
|
if (that.constructor === MC || that.constructor === DC) {
|
|
326
331
|
[...Object.getOwnPropertyNames(that)].forEach((mc) => {
|
|
327
|
-
if (that[mc]?.trigger &&
|
|
332
|
+
if (that[mc]?.trigger &&
|
|
333
|
+
typeof that[mc]?.trigger === 'function') {
|
|
328
334
|
that[mc]?.trigger(ev, data, bubble);
|
|
329
335
|
}
|
|
330
336
|
});
|
|
@@ -332,15 +338,17 @@ class MC extends McBase {
|
|
|
332
338
|
}
|
|
333
339
|
// only this instance
|
|
334
340
|
if (that instanceof MC || that instanceof DC) {
|
|
335
|
-
const that = this, mcEvent = typeof ev !== 'string'
|
|
336
|
-
|
|
341
|
+
const that = this, mcEvent = typeof ev !== 'string'
|
|
342
|
+
? ev
|
|
343
|
+
: new McEvent(ev, data, bubble), handlerName = 'on' + mcEvent.type[0].toUpperCase() + mcEvent.type.slice(1);
|
|
337
344
|
// console.log('trigger', handlerName, mcEvent, data, bubble );
|
|
338
345
|
if (mcEvent.bubble.indexOf('l') > -1) {
|
|
339
|
-
if (!mcEvent.immediateStopped
|
|
340
|
-
|
|
346
|
+
if (!mcEvent.immediateStopped &&
|
|
347
|
+
typeof that[handlerName] === 'function') {
|
|
341
348
|
// console.log( 'execute handler:', handlerName );
|
|
342
349
|
that[handlerName](mcEvent);
|
|
343
|
-
if (that.hasOwnProperty(handlerName)) {
|
|
350
|
+
if (that.hasOwnProperty(handlerName)) {
|
|
351
|
+
// it is a once handler
|
|
344
352
|
delete that[handlerName]; // remove after first execution
|
|
345
353
|
}
|
|
346
354
|
}
|
|
@@ -351,7 +359,9 @@ class MC extends McBase {
|
|
|
351
359
|
}
|
|
352
360
|
// at this point, either 'u' or 'd' bubbling should be indicated
|
|
353
361
|
// mcEvent bubbling is asynchronous, and the order of target MC execution in case of multiple matches is not guaranteed!
|
|
354
|
-
if (MC_isBrowser() &&
|
|
362
|
+
if (MC_isBrowser() &&
|
|
363
|
+
/[ud]/.test(mcEvent.bubble) &&
|
|
364
|
+
that instanceof MC) {
|
|
355
365
|
setTimeout(() => {
|
|
356
366
|
// bubbling must include 'l' for local, or else no handlers are executed'
|
|
357
367
|
if (mcEvent.bubble.indexOf('l') === -1) {
|
|
@@ -359,17 +369,13 @@ class MC extends McBase {
|
|
|
359
369
|
}
|
|
360
370
|
// bubble up towards root
|
|
361
371
|
if (mcEvent.bubble.indexOf('u') > -1) {
|
|
362
|
-
that
|
|
363
|
-
.parent()
|
|
364
|
-
.forEach((mc) => {
|
|
372
|
+
that.parent().forEach((mc) => {
|
|
365
373
|
mc instanceof MC ? mc.trigger(mcEvent) : null;
|
|
366
374
|
});
|
|
367
375
|
}
|
|
368
376
|
// bubble down
|
|
369
377
|
if (mcEvent.bubble.indexOf('d') > -1) {
|
|
370
|
-
that
|
|
371
|
-
.children()
|
|
372
|
-
.forEach((mc) => {
|
|
378
|
+
that.children().forEach((mc) => {
|
|
373
379
|
mc instanceof MC ? mc.trigger(mcEvent) : null;
|
|
374
380
|
});
|
|
375
381
|
}
|
|
@@ -378,20 +384,17 @@ class MC extends McBase {
|
|
|
378
384
|
}
|
|
379
385
|
}
|
|
380
386
|
}
|
|
381
|
-
;
|
|
382
387
|
class DC extends McBase {
|
|
383
388
|
_mc = {};
|
|
384
|
-
constructor(target) {
|
|
389
|
+
constructor(target, debug = false) {
|
|
385
390
|
super(target);
|
|
386
391
|
}
|
|
387
|
-
static debug = false;
|
|
388
392
|
static add = add;
|
|
389
393
|
static remove = remove;
|
|
390
394
|
static trigger = trigger;
|
|
391
395
|
trigger(ev, data = {}, bubble) {
|
|
392
396
|
MC.prototype.trigger.call(this, ev, data, bubble);
|
|
393
397
|
}
|
|
394
|
-
;
|
|
395
398
|
parent(search = '') {
|
|
396
399
|
let target = this.target;
|
|
397
400
|
if (!MC_isDOM(target))
|
|
@@ -424,7 +427,6 @@ class DC extends McBase {
|
|
|
424
427
|
return MC_getMicroComponents([...myDomElements], search);
|
|
425
428
|
}
|
|
426
429
|
}
|
|
427
|
-
;
|
|
428
430
|
|
|
429
431
|
|
|
430
432
|
/******/ return __webpack_exports__;
|