@twobirds/microcomponents 0.0.76 → 0.0.77
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/dist/formValues.min.js +1 -0
- package/dist/microcomponents.min.js +1 -1
- package/dist/observables.d.ts +1 -0
- package/dist/observables.d.ts.map +1 -1
- package/dist/observables.min.js +1 -1
- package/dist/observables.ts +189 -169
- package/package.json +1 -1
- package/public/formValues.min.js +1 -0
- package/public/microcomponents.min.js +1 -1
- package/public/observables.d.ts +1 -0
- package/public/observables.d.ts.map +1 -1
- package/public/observables.js +117 -118
- package/public/observables.js.map +1 -1
- package/public/observables.min.js +1 -1
- package/public/observables.ts +189 -169
- package/public/src/observables.ts +189 -169
- package/public/test/microcomponents.min.js +1 -1
- package/public/test/observables.d.ts +1 -0
- package/public/test/observables.d.ts.map +1 -1
- package/public/test/observables.js +117 -118
- package/public/test/observables.js.map +1 -1
- package/public/test/observables.ts +189 -169
- package/public/test/test/testform.js +1 -1
- package/public/typedoc/assets/search.js +1 -1
- package/public/typedoc/classes/MC.DC.html +2 -2
- package/public/typedoc/classes/MC.MC.html +2 -2
- package/public/typedoc/classes/MC.McBase.html +2 -2
- package/public/typedoc/classes/MC.McEvent.html +2 -2
- package/public/typedoc/functions/MC.addListener.html +1 -1
- package/public/typedoc/functions/MC.autoload.html +1 -1
- package/public/typedoc/functions/MC.removeListener.html +1 -1
- 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 +1 -1
- 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/observables.ts +189 -169
- package/webpack.config.js +1 -1
- package/dist/formvValues.min.js +0 -1
- package/public/formvValues.min.js +0 -1
|
@@ -194,207 +194,227 @@ function makePlaceholders(
|
|
|
194
194
|
export type Observable = {
|
|
195
195
|
observe: (cb: Callback) => void;
|
|
196
196
|
notify: () => void;
|
|
197
|
-
bind: (target: HTMLElement | DocumentFragment | ShadowRoot) => void;
|
|
197
|
+
bind: (target: HTMLElement | DocumentFragment | ShadowRoot ) => void;
|
|
198
|
+
callbacks: Array<Function>;
|
|
198
199
|
};
|
|
199
200
|
|
|
200
|
-
|
|
201
|
-
target: LooseObject,
|
|
202
|
-
propertyName?: string
|
|
203
|
-
): LooseObject => {
|
|
204
|
-
let keys = !propertyName
|
|
205
|
-
? [...Object.getOwnPropertyNames(target)]
|
|
206
|
-
: [propertyName];
|
|
201
|
+
type Class<T> = new (...args: any[]) => T;
|
|
207
202
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
Constructor = Object;
|
|
230
|
-
}
|
|
231
|
-
break;
|
|
232
|
-
default:
|
|
233
|
-
return;
|
|
203
|
+
// repository for observable class wrappers
|
|
204
|
+
const classRepo: LooseObject = {};
|
|
205
|
+
|
|
206
|
+
// creates a new observable class wrapper
|
|
207
|
+
function makeObservable(val: any): Class<typeof val>{
|
|
208
|
+
|
|
209
|
+
const Constructor = val.constructor,
|
|
210
|
+
ConstructorName: string = Constructor.name;
|
|
211
|
+
|
|
212
|
+
let ObservableClass = class extends Constructor {
|
|
213
|
+
#notify: boolean = true;
|
|
214
|
+
#callbacks: Array<Function> = [];
|
|
215
|
+
|
|
216
|
+
constructor(val: any) {
|
|
217
|
+
super(val);
|
|
218
|
+
(this.constructor as LooseObject).callbacks = [];
|
|
219
|
+
if (isObservableObject(val)) {
|
|
220
|
+
// you cannot bind native values to the dom
|
|
221
|
+
Object.getOwnPropertyNames(val).forEach((key) => {
|
|
222
|
+
this[key] = val[key];
|
|
223
|
+
});
|
|
234
224
|
}
|
|
235
225
|
}
|
|
236
226
|
|
|
237
|
-
|
|
238
|
-
|
|
227
|
+
get callbacks(): Array<Function> {
|
|
228
|
+
return this.#callbacks
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
set callbacks( callbacks: Array<Function> ){
|
|
232
|
+
this.#callbacks = callbacks
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
observe(f: Function) {
|
|
236
|
+
//console.log('observe');
|
|
237
|
+
this.#callbacks.push(f);
|
|
238
|
+
return this;
|
|
239
|
+
}
|
|
239
240
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
(
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
241
|
+
bind(target: HTMLElement | DocumentFragment | ShadowRoot) {
|
|
242
|
+
const that = this,
|
|
243
|
+
iso = isObservableObject(that.valueOf());
|
|
244
|
+
//console.log('bind', iso, target);
|
|
245
|
+
|
|
246
|
+
if (iso) {
|
|
247
|
+
makePlaceholders(target);
|
|
248
|
+
const placeholders: unknown = [
|
|
249
|
+
...target.querySelectorAll('[_mc]'),
|
|
250
|
+
].filter((e) => !!(e as LooseObject)?._mc?._placeholders);
|
|
251
|
+
//console.log('placeholders:', target, placeholders);
|
|
252
|
+
const func = function callback(data: LooseObject) {
|
|
253
|
+
// avoid bubbling for speed
|
|
254
|
+
let d = flattenObject(data);
|
|
255
|
+
//console.log('inside callback', target, d);
|
|
256
|
+
(placeholders as DC[]).forEach((e) => {
|
|
257
|
+
// console.log('trigger callback', e);
|
|
258
|
+
if (!e) return;
|
|
259
|
+
(e as any)._mc.trigger('data', d);
|
|
247
260
|
});
|
|
248
|
-
}
|
|
261
|
+
};
|
|
262
|
+
(that as any).#callbacks.push(func);
|
|
263
|
+
that.notify();
|
|
264
|
+
} else {
|
|
265
|
+
console.warn(
|
|
266
|
+
'IGNORED - cannot bind a non-Object to the dom, IS:',
|
|
267
|
+
typeof that.valueOf(),
|
|
268
|
+
that
|
|
269
|
+
);
|
|
249
270
|
}
|
|
250
271
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
272
|
+
return this;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
notify(notify?: boolean) {
|
|
276
|
+
let that = this,
|
|
277
|
+
data =
|
|
278
|
+
isObservableObject(that.valueOf()) &&
|
|
279
|
+
that.valueOf() instanceof Array === false
|
|
280
|
+
? structuredClone(Object.assign({}, that))
|
|
281
|
+
: that.valueOf();
|
|
282
|
+
|
|
283
|
+
if (notify !== undefined) {
|
|
284
|
+
that.#notify = notify;
|
|
285
|
+
// return;
|
|
255
286
|
}
|
|
256
287
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
//console.log('placeholders:', target, placeholders);
|
|
268
|
-
const func = function callback(data: LooseObject) {
|
|
269
|
-
// avoid bubbling for speed
|
|
270
|
-
let d = flattenObject(data);
|
|
271
|
-
//console.log('inside callback', target, d);
|
|
272
|
-
(placeholders as DC[]).forEach((e) => {
|
|
273
|
-
// console.log('trigger callback', e);
|
|
274
|
-
if (!e) return;
|
|
275
|
-
(e as any)._mc.trigger('data', d);
|
|
276
|
-
});
|
|
277
|
-
};
|
|
278
|
-
(that.constructor as any).callbacks.push(func);
|
|
279
|
-
that.notify();
|
|
280
|
-
} else {
|
|
281
|
-
console.warn(
|
|
282
|
-
'IGNORED - cannot bind a non-Object to the dom, IS:',
|
|
283
|
-
typeof that.valueOf(),
|
|
284
|
-
that
|
|
285
|
-
);
|
|
286
|
-
}
|
|
288
|
+
//if (that.#notify) console.log('notify', this, data);
|
|
289
|
+
(that as any).#callbacks.forEach((f: Function) => {
|
|
290
|
+
// console.log(
|
|
291
|
+
// (this.constructor as any).callbacks,
|
|
292
|
+
// 'notify: exec callback',
|
|
293
|
+
// f,
|
|
294
|
+
// data
|
|
295
|
+
// );
|
|
296
|
+
f(data);
|
|
297
|
+
});
|
|
287
298
|
|
|
288
|
-
|
|
289
|
-
|
|
299
|
+
return that;
|
|
300
|
+
}
|
|
301
|
+
};
|
|
290
302
|
|
|
291
|
-
|
|
292
|
-
let that = this,
|
|
293
|
-
data =
|
|
294
|
-
isObservableObject(that.valueOf()) &&
|
|
295
|
-
that.valueOf() instanceof Array === false
|
|
296
|
-
? structuredClone(Object.assign({}, that))
|
|
297
|
-
: that.valueOf();
|
|
298
|
-
|
|
299
|
-
if (notify !== undefined) {
|
|
300
|
-
that.#notify = notify;
|
|
301
|
-
// return;
|
|
302
|
-
}
|
|
303
|
+
(classRepo as any)[ConstructorName] = ObservableClass;
|
|
303
304
|
|
|
304
|
-
|
|
305
|
-
(that.constructor as any).callbacks.forEach((f: Function) => {
|
|
306
|
-
// console.log(
|
|
307
|
-
// (this.constructor as any).callbacks,
|
|
308
|
-
// 'notify: exec callback',
|
|
309
|
-
// f,
|
|
310
|
-
// data
|
|
311
|
-
// );
|
|
312
|
-
f(data);
|
|
313
|
-
});
|
|
305
|
+
// console.log( 'classRepo:', classRepo );
|
|
314
306
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
};
|
|
307
|
+
return ObservableClass;
|
|
308
|
+
}
|
|
318
309
|
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
get() {
|
|
324
|
-
if (isObservableObject(o.valueOf())) {
|
|
325
|
-
let check = structuredClone(Object.assign({}, o));
|
|
326
|
-
setTimeout(
|
|
327
|
-
debounce(function checkChanges() {
|
|
328
|
-
let state = structuredClone(Object.assign({}, o));
|
|
329
|
-
//console.log( 'check changes', state, check );
|
|
330
|
-
if (!deepEqual(state, check)) {
|
|
331
|
-
//console.log( '-> not equal!' );
|
|
332
|
-
o.notify();
|
|
333
|
-
}
|
|
334
|
-
}, 0),
|
|
335
|
-
0
|
|
336
|
-
);
|
|
337
|
-
}
|
|
338
|
-
return o;
|
|
339
|
-
},
|
|
340
|
-
set(val: any) {
|
|
341
|
-
//console.log( 'SET:', isObservableObject( val.valueOf() ), 'set:', val, 'to', isObservableObject( o.valueOf() ), o, );
|
|
342
|
-
if (typeof val === typeof o.valueOf()) {
|
|
343
|
-
let iso =
|
|
344
|
-
isObservableObject(o.valueOf()) &&
|
|
345
|
-
o.valueOf() instanceof Array === false;
|
|
346
|
-
//console.log('target iso:', iso);
|
|
347
|
-
if (iso) {
|
|
348
|
-
let old = structuredClone(Object.assign({}, o));
|
|
349
|
-
//val = structuredClone(Object.assign({}, val));
|
|
350
|
-
|
|
351
|
-
//let callbacks = (o.constructor as LooseObject).callbacks;
|
|
352
|
-
if (o instanceof Observable === false) {
|
|
353
|
-
o = new Observable(structuredClone(Object.assign({}, val)));
|
|
354
|
-
copyGettersSetters(val, o);
|
|
355
|
-
o.seal();
|
|
356
|
-
}
|
|
357
|
-
Object.assign(o, val);
|
|
310
|
+
function getConstructor( val: any ): Class<typeof val> {
|
|
311
|
+
let key: string = val.constructor.name;
|
|
312
|
+
return classRepo[key] || makeObservable( val );
|
|
313
|
+
}
|
|
358
314
|
|
|
359
|
-
|
|
360
|
-
|
|
315
|
+
export const observe = (
|
|
316
|
+
target: LooseObject,
|
|
317
|
+
propertyName?: string
|
|
318
|
+
): LooseObject => {
|
|
319
|
+
let keys = !propertyName
|
|
320
|
+
? [...Object.getOwnPropertyNames(target)]
|
|
321
|
+
: [propertyName];
|
|
361
322
|
|
|
323
|
+
keys.forEach((key) => {
|
|
324
|
+
if (
|
|
325
|
+
target.hasOwnProperty(key)
|
|
326
|
+
&& typeof target[key] !== 'function'
|
|
327
|
+
&& !target?.[key]?.constructor?.prototype?.observe
|
|
328
|
+
) {
|
|
329
|
+
|
|
330
|
+
// console.log( 'co propname', key, typeof target[key], target[key] );
|
|
331
|
+
if (key[0] === '_' || target?.[key] === undefined) return target;
|
|
332
|
+
let val: any = target[key];
|
|
333
|
+
|
|
334
|
+
let o = new ( getConstructor(val) as Class<typeof val> )( val );
|
|
335
|
+
|
|
336
|
+
Object.defineProperty(target, key, {
|
|
337
|
+
enumerable: true,
|
|
338
|
+
get() {
|
|
339
|
+
if (isObservableObject(o.valueOf())) {
|
|
340
|
+
let check = structuredClone(Object.assign({}, o));
|
|
362
341
|
setTimeout(
|
|
363
|
-
// check for changes
|
|
364
342
|
debounce(function checkChanges() {
|
|
365
343
|
let state = structuredClone(Object.assign({}, o));
|
|
366
344
|
//console.log( 'check changes', state, check );
|
|
367
|
-
if (!deepEqual(state,
|
|
345
|
+
if (!deepEqual(state, check)) {
|
|
368
346
|
//console.log( '-> not equal!' );
|
|
369
347
|
o.notify();
|
|
370
348
|
}
|
|
371
349
|
}, 0),
|
|
372
350
|
0
|
|
373
351
|
);
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
o.
|
|
352
|
+
}
|
|
353
|
+
return o;
|
|
354
|
+
},
|
|
355
|
+
set(val: any) {
|
|
356
|
+
//console.log( 'SET:', isObservableObject( val.valueOf() ), 'set:', val, 'to', isObservableObject( o.valueOf() ), o, );
|
|
357
|
+
if (typeof val === typeof o.valueOf()) {
|
|
358
|
+
let iso =
|
|
359
|
+
isObservableObject(o.valueOf()) &&
|
|
360
|
+
o.valueOf() instanceof Array === false;
|
|
361
|
+
//console.log('target iso:', iso);
|
|
362
|
+
if (iso) {
|
|
363
|
+
let old = structuredClone(Object.assign({}, o));
|
|
364
|
+
//val = structuredClone(Object.assign({}, val));
|
|
365
|
+
|
|
366
|
+
//let callbacks = (o.constructor as LooseObject).callbacks;
|
|
367
|
+
if (o?.constructor?.prototype?.observe === undefined ) {
|
|
368
|
+
o = new ( getConstructor(val) as Class<typeof val> )( structuredClone(Object.assign({}, val)) );
|
|
369
|
+
copyGettersSetters(val, o);
|
|
370
|
+
o.seal();
|
|
371
|
+
}
|
|
372
|
+
Object.assign(o, val);
|
|
373
|
+
|
|
374
|
+
// console.log('after set o=', o, 'check', old);
|
|
375
|
+
// (o.constructor as LooseObject).callbacks = callbacks;
|
|
376
|
+
|
|
377
|
+
setTimeout(
|
|
378
|
+
// check for changes
|
|
379
|
+
debounce(function checkChanges() {
|
|
380
|
+
let state = structuredClone(Object.assign({}, o));
|
|
381
|
+
//console.log( 'check changes', state, check );
|
|
382
|
+
if (!deepEqual(state, old)) {
|
|
383
|
+
//console.log( '-> not equal!' );
|
|
384
|
+
o.notify();
|
|
385
|
+
}
|
|
386
|
+
}, 0),
|
|
387
|
+
0
|
|
388
|
+
);
|
|
389
|
+
} else {
|
|
390
|
+
// simple native var
|
|
391
|
+
let old = o.valueOf(),
|
|
392
|
+
callbacks = (o as Observable).callbacks;
|
|
393
|
+
|
|
394
|
+
// console.log( 'sO', o, o.valueOf(), 'val', val );
|
|
395
|
+
if (val !== old) {
|
|
396
|
+
// console.log( '-> sO new val', val );
|
|
397
|
+
o = new ( getConstructor(val) as Class<typeof val> )( val );
|
|
398
|
+
(o as Observable).callbacks = callbacks;
|
|
399
|
+
o.notify();
|
|
400
|
+
}
|
|
382
401
|
}
|
|
402
|
+
} else {
|
|
403
|
+
console.warn(
|
|
404
|
+
'IGNORED - cannot change observable types, IS:',
|
|
405
|
+
typeof o.valueOf(),
|
|
406
|
+
o,
|
|
407
|
+
'- CANNOT BECOME:',
|
|
408
|
+
typeof val
|
|
409
|
+
);
|
|
383
410
|
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
typeof val
|
|
391
|
-
);
|
|
392
|
-
}
|
|
393
|
-
},
|
|
394
|
-
});
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
// replace old property with proxy (observable)
|
|
415
|
+
target[key] = val;
|
|
416
|
+
};
|
|
395
417
|
|
|
396
|
-
// replace old property with proxy (observable)
|
|
397
|
-
target[key] = val;
|
|
398
418
|
});
|
|
399
419
|
|
|
400
420
|
return target;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TestTestform=t():e.TestTestform=t()}(self,(()=>(()=>{"use strict";var e=new Function("try {return this===window;}catch(e){ return false;}");let t=new Set;e()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>t.add(e)));class n{#e;#t=!1;#n=!1;constructor(e,t={},n="l"){this.#e=e,this.data=t,this.bubble=n}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#n}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#n=!0}}var r=new Function("try {return this===window;}catch(e){ return false;}");let a=new Set;function l(e,t){let n=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const r=e?._mc;!t&&r?n=n.concat(Object.values(e._mc)):t&&r&&r[t]&&n.push(r[t])}})),n}function o(e,t,n=!0){let r=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&r.push(e._mc[t]):r=r.concat(Object.values(e._mc)),n))return r;e=e.parentNode}return r}function s(e){return e&&e instanceof HTMLElement}function i(e,t,n,r=!1,a=!1){let l={once:!1};r&&(l.capture=r),a&&(l.once=a),e.addEventListener(t,n,l)}function c(e,t,n={}){let r=e;if(!r._mc){let t=f?.debug;f.debug=!1,r._mc=new f(e),f.debug=t,delete r._mc._mc}const a=r._mc;return t.length&&!a[t]&&(a[t]=n,e instanceof HTMLElement&&!e.getAttribute("_mc")&&e.setAttribute("_mc","")),n}function u(e,t){if(!t)return;const n=e?._mc||{};n&&n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function p(e,t,r={},a="l"){let l=e?._mc;if(!l)return;let o=t instanceof n?new n(t.type,t.data,"l"):new n(t,r,"l"),s="string"!=typeof t?t:new n(t,r,a);[...Object.values(l)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(o)})),/[ud]/.test(s.bubble)&&d(e,s)}function d(e,t){/[ud]/.test(t.bubble)&&setTimeout((()=>{if(-1===t.bubble.indexOf("l")&&(t.bubble+="l"),t.bubble.indexOf("u")>-1){let n=o(e,"",!0)?.[0].target;n&&f.trigger(n,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&f.trigger(e,t)}))}),0)}r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>a.add(e)));class b{#r;constructor(e,t=!1){var n;this.#r=new WeakRef(e||{}),(n=this).constructor!==f&&setTimeout((()=>{n.trigger("Init")}),0),function(e){if(!r()||e.constructor===f)return;const t=e.target;if(t instanceof HTMLElement){let n=e;Object.getOwnPropertyNames(n.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof n.constructor.prototype[e])).forEach((r=>{let l=/^one/.test(r),o=r.replace(/^on[e]{0,1}/,""),s=o.toLowerCase();l&&Object.defineProperty(e,"on"+o,{configurable:!0,enumerable:!1,writable:!0,value:e=>{n.constructor.prototype[r].bind(n)(e)}}),a.has("on"+s)&&i(t,s,(e=>{n.trigger(o,e)}),!1,l)}))}}(this)}get target(){return this.#r.deref()}}class m extends b{_mc={};constructor(e){super(e)}static trigger=p;trigger(e,t={},r="l"){let a=this;if(a.constructor===m||a.constructor===f){let l=e instanceof n?new n(e.type,e.data,"l"):new n(e,t,"l"),o="string"!=typeof e?e:new n(e,t,r);return[...Object.getOwnPropertyNames(a)].forEach((e=>{a[e]?.trigger&&"function"==typeof a[e]?.trigger&&a[e]?.trigger(l)})),void(/[ud]/.test(o.bubble)&&d(a.target,o))}if(a instanceof m||a instanceof f){const a=this,l="string"!=typeof e?e:new n(e,t,r),o="on"+l.type[0].toUpperCase()+l.type.slice(1);if(l.bubble.indexOf("l")>-1&&(l.immediateStopped||"function"!=typeof a[o]||(a[o](l),a.hasOwnProperty(o)&&delete a[o])),l.stopped||"l"===l.bubble)return a;/[ud]/.test(l.bubble)&&d(a.target,l)}}}class f extends b{_mc={};constructor(e,t=!1){super(e)}static add=c;static remove=u;static trigger=p;trigger(e,t={},n){m.prototype.trigger.call(this,e,t,n)}parent(e=""){let t=this.target;return s(t)?o(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return s(t)?o(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!s(t))return[];const n=Math.random().toString().replace(".",""),r='[_mc]:not([temp_id="'+n+'"] [_mc] [_mc])';t.setAttribute("temp_id",n);const a=l([...t.querySelectorAll(r)],e);return t.removeAttribute("temp_id"),a}descendants(e=""){let t=this?.target;return s(t)?l([...t.querySelectorAll("*[_mc]")],e):[]}}const g=new Map,h=new Map;function y(e){const t="./"+e.split("-").join("/")+".js",n=document.createElement("script");return n.setAttribute("src",t),n.setAttribute("blocking","render"),n.async=!0,n.setAttribute("type","module"),n.setAttribute("name",e),n.setAttribute("loading",""),i(n,"load",(e=>{n.removeAttribute("loading"),n.setAttribute("loaded","")})),i(n,"error",(e=>{console.error("could not load Custom Element code from",t)})),n}function v(){[...document.querySelectorAll(":not(:defined)")].filter((e=>!!e&&!customElements.get(e.tagName.toLowerCase())&&!g.has(e.tagName.toLowerCase()))).forEach((e=>{const t=e.tagName.toLowerCase(),n=(t.split("-").join("/"),y(t));i(n,"load",(()=>{g.set(t,customElements.get(e.tagName.toLowerCase()))})),g.set(t,"loading"),document.head.append(n)})),[...document.querySelectorAll('[_mc]:not([_mc=""]')].filter((e=>!!e)).forEach((e=>{const t=e.getAttribute("_mc")?.split(" ").filter((e=>!!e))||[],n=t.filter((e=>!h.has(e)));n?.forEach((e=>{const t=y(e);i(t,"load",(()=>{return t=document.head.querySelector(`script[name="${e}"]`),void setTimeout((function(){const e=t.getAttribute("src"),n=t.getAttribute("name"),r=document.createElement("script");r.async=!0,r.setAttribute("type","module");const a=`\n\n\t\t\timport _ from "${e}";\n\t\t\timport { DC } from "./microcomponents.js";\n\n\t\t\tconst elements = Array.from(document.querySelectorAll('[_mc*="${n}"]')).filter( element => element instanceof HTMLElement );\n\n\t\t\telements.forEach((element) => {\n\t\t\t\t// add class to MCs repository\n\t\t\t\tautoload.state.MCs.set( '${n}', _ );\n\t\t\t\t// add instance to HTMLElement \n\t\t\t\tDC.add(element, _.name, new _(element));\n\t\t\t\t// remove instance name from elements "_mc" attribute\n\t\t\t\telement.setAttribute('_mc', element.getAttribute('_mc').replace('${n}', '').replace( /ww/g, ' ').trim()); \n\t\t\t});\n\n\t\t\tsetTimeout( () => {\n\t\t\t\tdocument.body.querySelector('script[name="${n}]"')?.remove();\n\t\t\t},0);\n\n\t\t`;r.innerHTML=a,document.body.append(r)}),0);var t})),h.set(e,"loading"),document.head.append(t)}));const r=t.filter((e=>h.has(e)&&!h.get(e).length));r?.forEach((t=>{setTimeout((()=>{f.add(e,t,new(E.state.MCs.get(t))(e)),e.getAttribute("_mc").replace("${elementName}","").replace(/\w\w/g," ").trim(),e.setAttribute("_mc")}),5)}))}))}let w=!1,O=null;function E(e=!0){return e?(w=e,O=new MutationObserver(v),setTimeout((()=>{O.observe(document.body,{childList:!0,subtree:!0}),v()}),5),window.autoload=window.autoload||E,w):(O?.disconnect(),O=null,w)}function A(e){let t={};return[...Object.keys(e)].sort().forEach((n=>{var r;(r=e[n])&&r.constructor&&r.constructor===Object?t[n]=A(e[n]):t[n]=e[n]})),t}function x(e,t=!0){let n={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const r=x(e[t],!1);for(const e in r)n[t+"."+e]=r[e]}else n[t]=e[t]})),t?A(n):n}function _(e,t){return JSON.stringify(x(e))===JSON.stringify(x(t))}function j(e,t){let n;return()=>{clearTimeout(n),n=setTimeout((function(){e(...arguments)}),t)}}function k(e,t){const n=Object.getOwnPropertyDescriptors(e);for(const[e,r]of Object.entries(n))("get"in r||"set"in r)&&Object.defineProperty(t,e,r)}E.state={CEs:g,MCs:h};class S extends HTMLElement{constructor(){super()}connectedCallback(){f.trigger(this,"Connected")}disconnectedCallback(){f.trigger(this,"Disconnected")}adoptedCallback(){f.trigger(this,"Adopted")}attributeChangedCallback(e,t,n){f.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:n})}}function C(e){return null!=e&&"object"==typeof e}function T(e){let t=new Set,n=/\{[^\{\}]*\}/g;return e.getAttributeNames().filter((t=>e.getAttribute(t)?.match(n))).forEach((r=>{new Set(e.getAttribute(r)?.match(n)).forEach((e=>t.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(n))).forEach((e=>{(e.nodeValue||"").match(n).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const N=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class L extends f{data={};oldDisplay="";constructor(e){super(e);let t=this;T(e).forEach((e=>t.data[e]="")),M(t),t.#a(),delete t._mc}#a(){let e=this,t=e.target,n=!1;t.getAttributeNames().filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((n=>{let r=new Set(t.getAttribute(n)?.match(/\{[^\{\}]*\}/g));var a;e.data.observe((a=t.getAttribute(n),e=>{let l=a;r.forEach((t=>{l=l.replace(t,e[t.replace(/[\{\}]/g,"")])})),t.setAttribute(n,l)}))})),[...t.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((r=>{n=!0;let a=new Set(r.nodeValue.match(/\{[^\{\}]*\}/g));var l;e.data.observe((l=r.nodeValue,n=>{let o=l;a.forEach((e=>{o=o.replace(e,n[e.replace(/[\{\}]/g,"")])})),Object.keys(n).some((e=>!!n[e]))&&(e.oldDisplay?t.style=e.oldDisplay:t.removeAttribute("style"),delete e.oldDisplay),r.nodeValue=o})),e.oldDisplay=t.getAttribute("style)")||"",n&&!N.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(e){let t=this,n={};Object.keys(e.data).forEach((r=>{t.data.hasOwnProperty(r)&&(n[r]=e.data[r])})),JSON.stringify(n)!==JSON.stringify(t.data)&&Object.assign(t.data,n)}}const M=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if("_"===t[0]||void 0===e?.[t])return e;let n,r=e[t];if(!r.prototype)switch(typeof r){case"string":n=String;break;case"number":n=Number;break;case"boolean":n=Boolean;break;case"object":n=r instanceof Array?Array:Object;break;default:return}let a=class extends n{#l=!0;constructor(e){super(e),this.constructor.callbacks=[],C(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}observe(e){return this.constructor.callbacks.push(e),this}bind(e){const t=this;if(C(t.valueOf())){!function(e){var t;(t=e,(t instanceof HTMLElement?[t]:[]).concat([...t.querySelectorAll("*")]).filter((e=>!!T(e).length)).filter((e=>"STYLE"!==e.tagName))).forEach((e=>{e?._mc?._placeholders||f.add(e,"_placeholders",new L(e))}))}(e);const n=[...e.querySelectorAll("[_mc]")].filter((e=>!!e?._mc?._placeholders)),r=function(e){let t=x(e);n.forEach((e=>{e&&e._mc.trigger("data",t)}))};t.constructor.callbacks.push(r),t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf(),t);return this}notify(e){let t=this,n=C(t.valueOf())&&t.valueOf()instanceof Array==0?structuredClone(Object.assign({},t)):t.valueOf();return void 0!==e&&(t.#l=e),t.constructor.callbacks.forEach((e=>{e(n)})),t}},l=new a(r);Object.defineProperty(e,t,{enumerable:!0,get(){if(C(l.valueOf())){let e=structuredClone(Object.assign({},l));setTimeout(j((function(){_(structuredClone(Object.assign({},l)),e)||l.notify()}),0),0)}return l},set(e){if(typeof e==typeof l.valueOf())if(C(l.valueOf())&&l.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},l));l instanceof a==0&&(l=new a(structuredClone(Object.assign({},e))),k(e,l),l.seal()),Object.assign(l,e),setTimeout(j((function(){_(structuredClone(Object.assign({},l)),t)||l.notify()}),0),0)}else{let t=l.valueOf(),n=l.constructor.callbacks;l=new a(e),l.constructor.callbacks=n,e!==t&&l.notify()}else console.warn("IGNORED - cannot change observable types, IS:",typeof l.valueOf(),l,"- CANNOT BECOME:",typeof e)}}),e[t]=r})),e);class I{constructor(e){}}class H extends I{#o;constructor(e){super(e),this.#o=e}get val(){return new FormData(this.#o.form).get(this.#o.name)}set val(e){[...this.#o.form.querySelectorAll(`input[type="radio"][name="${this.#o.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class P extends I{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.checked}set val(e){this.#o.checked=e}}class D extends I{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.value}set val(e){this.#o.value=e}}class q extends I{#o;#s=!1;constructor(e){super(e),this.#o=e,this.#s=e.multiple}get val(){const e=[];return[...this.#o.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#s?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#o.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class $ extends I{#o;constructor(e){super(e),this.#o=e}get val(){return this.#o.value||""}set val(e){this.#o.value=e}}return function(e,t,n=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(r,class extends S{instance;constructor(e){super();let n=new t(this,e);f.add(this,r,n)}static get observedAttributes(){return n}}))}("test-testform",class extends f{data;constructor(e){super(e);const t=this;delete t._mc;let n=t.target.attachShadow({mode:"open"});n.innerHTML=`<style>${t.css}</style>${t.template}`,function(e,t,n){let r=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],n={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let r=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":r=new H(e);break;case"checkbox":r=new P(e);break;default:r=new D(e)}break;case"select":r=new q(e);break;case"textarea":r=new $(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}r&&(f.add(e,t,r),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>r.val,set:e=>{r.val!==e&&(r.val=e)}}))}})),n})(n);e[t]=Object.assign({},r),M(e,t),k(r,e[t]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{i(n,"input",(n=>{e[t].notify()}))}))}(t,"data",n),t.data.bind(n),fetch("./testform.json").then((e=>e.json())).then((e=>{t.data=e}))}get template(){return'\n <form>\n \x3c!-- sample form to start with --\x3e\n <fieldset>\n <legend>Inputs</legend>\n <label>text</label><input type="text" name="textInput" value="Hallo" /> <strong>2wB: </strong>{textInput}<br />\n <label>color</label><input type="color" name="colorInput" value="#000000" /><br />\n <label>date</label><input type="date" name="dateInput" value="" /><br />\n <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" /><br />\n <label>email</label><input type="email" name="email" value="" /><br />\n <label>file</label><input type="file" name="fileInput" value="" /><br />\n <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" /><br />\n <label>month</label><input type="month" name="month" value="" /><br />\n <label>number</label><input type="number" name="number" value="" /><br />\n <label>password</label><input type="password" name="passInput" value="" /><br />\n <label>range</label><input type="range" name="rangeInput" value="" /><br />\n <label>search</label><input type="search" name="searchInput" value="" /><br />\n <label>tel</label><input type="tel" name="telInput" value="" /><br />\n <label>time</label><input type="time" name="timeInput" value="" /><br />\n <label>url</label><input type="url" name="urlInput" value="" /><br />\n <label>week</label><input type="week" name="weekInput" value="" /><br />\n </fieldset>\n\n <fieldset>\n <legend>Selects <strong>2wB: </strong> <span>"{singleSelect}"</span> <span>[{multiSelect}]</span></legend>\n\n <label>singleSelect</label>\n <select name="singleSelect">\n <option disabled selected value> -- select -- </option>\n <option value="1">Option 1</option>\n <option value="2">Option 2</option>\n <option value="3">Option 3</option>\n <option value="4">Option 4</option>\n </select><br />\n\n <label>multiSelect</label>\n <select name="multiSelect" multiple="multiple" type="select-multiple">\n <option value="1">Option 1</option>\n <option value="2" selected=true>Option 2</option>\n <option value="3">Option 3</option>\n <option value="4" selected=true>Option 4</option>\n </select>\n\n </fieldset>\n\n <fieldset>\n <legend>Radiobuttons <strong>2wB: </strong><span>"{myRadio}"</span></legend>\n\n <label>radio1</label><input type="radio" name="myRadio" value="radio1"><br />\n <label>radio2</label><input type="radio" name="myRadio" value="radio2"><br />\n <label>radio3</label><input type="radio" name="myRadio" value="radio3"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>Checkboxes</legend>\n <label>cb1</label><input type="checkbox" name="cb1"><br />\n <label>cb2</label><input type="checkbox" name="cb2"><br />\n <label>cb3</label><input type="checkbox" name="cb3"><br />\n <label>cb4</label><input type="checkbox" name="cb4"><br />\n <label>cb5</label><input type="checkbox" name="cb5"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>TextArea</legend>\n <label>textArea</label>\n <textarea name="textArea">abc</textarea>\n </fieldset>\n\n </form>\n '}get css(){return'\nlegend {\n display: inherit;\n margin: inherit;\n vertical-align: inherit;\n font-weight: bold;\n}\n\nlabel {\n display: inline-block;\n margin-top: 1em;\n margin-left: 5px;\n vertical-align: top;\n min-width:10em;\n text-align: right;\n}\n\nform input,\nform select,\nform textarea {\n display: inline-block;\n margin-left: 5px;\n margin-top: 1.1em;\n}\n\ninput[type="radio"],\ninput[type="checkbox"] {\n margin-top: 1.3em;\n}\n\nbody > form {\n display: block;\n}\n\nform fieldset {\n border: 1px solid #aaaaaa;\n border-radius: 3px;\n margin: 0.5em 0;\n}\n '}}),{}})()));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.TestTestform=t():e.TestTestform=t()}(self,(()=>(()=>{"use strict";var e=new Function("try {return this===window;}catch(e){ return false;}");let t=new Set;e()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>t.add(e)));class n{#e;#t=!1;#n=!1;constructor(e,t={},n="l"){this.#e=e,this.data=t,this.bubble=n}get type(){return this.#e}get stopped(){return this.#t}get immediateStopped(){return this.#n}stopPropagation(){this.#t=!0}stopImmediatePropagation(){this.stopPropagation(),this.#n=!0}}var r=new Function("try {return this===window;}catch(e){ return false;}");let a=new Set;function l(e,t){let n=[];return e.forEach((e=>{if(e&&e instanceof HTMLElement){const r=e?._mc;!t&&r?n=n.concat(Object.values(e._mc)):t&&r&&r[t]&&n.push(r[t])}})),n}function o(e,t,n=!0){let r=[];for(;e;){if(e._mc&&(t?t&&e._mc[t]&&r.push(e._mc[t]):r=r.concat(Object.values(e._mc)),n))return r;e=e.parentNode}return r}function s(e){return e&&e instanceof HTMLElement}function i(e,t,n,r=!1,a=!1){let l={once:!1};r&&(l.capture=r),a&&(l.once=a),e.addEventListener(t,n,l)}function c(e,t,n={}){let r=e;if(!r._mc){let t=f?.debug;f.debug=!1,r._mc=new f(e),f.debug=t,delete r._mc._mc}const a=r._mc;return t.length&&!a[t]&&(a[t]=n,e instanceof HTMLElement&&!e.getAttribute("_mc")&&e.setAttribute("_mc","")),n}function u(e,t){if(!t)return;const n=e?._mc||{};n&&n[t]&&delete n[t],!Object.keys(n).length&&e instanceof HTMLElement&&e.hasAttribute("_mc")&&e.removeAttribute("_mc")}function p(e,t,r={},a="l"){let l=e?._mc;if(!l)return;let o=t instanceof n?new n(t.type,t.data,"l"):new n(t,r,"l"),s="string"!=typeof t?t:new n(t,r,a);[...Object.values(l)].forEach((e=>{e?.trigger&&"function"==typeof e?.trigger&&e?.trigger(o)})),/[ud]/.test(s.bubble)&&d(e,s)}function d(e,t){/[ud]/.test(t.bubble)&&setTimeout((()=>{if(-1===t.bubble.indexOf("l")&&(t.bubble+="l"),t.bubble.indexOf("u")>-1){let n=o(e,"",!0)?.[0].target;n&&f.trigger(n,t)}t.bubble.indexOf("d")>-1&&new Set(e._mc.children().map((e=>e?.target))).forEach((e=>{e&&f.trigger(e,t)}))}),0)}r()&&Object.keys(HTMLElement.prototype).filter((e=>/^on/.test(e))).forEach((e=>a.add(e)));class m{#r;constructor(e,t=!1){var n;this.#r=new WeakRef(e||{}),(n=this).constructor!==f&&setTimeout((()=>{n.trigger("Init")}),0),function(e){if(!r()||e.constructor===f)return;const t=e.target;if(t instanceof HTMLElement){let n=e;Object.getOwnPropertyNames(n.constructor.prototype).filter((e=>/^on[A-Z]|one[A-Z]/.test(e)&&"function"==typeof n.constructor.prototype[e])).forEach((r=>{let l=/^one/.test(r),o=r.replace(/^on[e]{0,1}/,""),s=o.toLowerCase();l&&Object.defineProperty(e,"on"+o,{configurable:!0,enumerable:!1,writable:!0,value:e=>{n.constructor.prototype[r].bind(n)(e)}}),a.has("on"+s)&&i(t,s,(e=>{n.trigger(o,e)}),!1,l)}))}}(this)}get target(){return this.#r.deref()}}class b extends m{_mc={};constructor(e){super(e)}static trigger=p;trigger(e,t={},r="l"){let a=this;if(a.constructor===b||a.constructor===f){let l=e instanceof n?new n(e.type,e.data,"l"):new n(e,t,"l"),o="string"!=typeof e?e:new n(e,t,r);return[...Object.getOwnPropertyNames(a)].forEach((e=>{a[e]?.trigger&&"function"==typeof a[e]?.trigger&&a[e]?.trigger(l)})),void(/[ud]/.test(o.bubble)&&d(a.target,o))}if(a instanceof b||a instanceof f){const a=this,l="string"!=typeof e?e:new n(e,t,r),o="on"+l.type[0].toUpperCase()+l.type.slice(1);if(l.bubble.indexOf("l")>-1&&(l.immediateStopped||"function"!=typeof a[o]||(a[o](l),a.hasOwnProperty(o)&&delete a[o])),l.stopped||"l"===l.bubble)return a;/[ud]/.test(l.bubble)&&d(a.target,l)}}}class f extends m{_mc={};constructor(e,t=!1){super(e)}static add=c;static remove=u;static trigger=p;trigger(e,t={},n){b.prototype.trigger.call(this,e,t,n)}parent(e=""){let t=this.target;return s(t)?o(t.parentNode,e,!0):[]}ancestors(e=""){let t=this?.target;return s(t)?o(this.target.parentNode,e,!1):[]}children(e=""){let t=this?.target;if(!s(t))return[];const n=Math.random().toString().replace(".",""),r='[_mc]:not([temp_id="'+n+'"] [_mc] [_mc])';t.setAttribute("temp_id",n);const a=l([...t.querySelectorAll(r)],e);return t.removeAttribute("temp_id"),a}descendants(e=""){let t=this?.target;return s(t)?l([...t.querySelectorAll("*[_mc]")],e):[]}}const g=new Map,h=new Map;function y(e){const t="./"+e.split("-").join("/")+".js",n=document.createElement("script");return n.setAttribute("src",t),n.setAttribute("blocking","render"),n.async=!0,n.setAttribute("type","module"),n.setAttribute("name",e),n.setAttribute("loading",""),i(n,"load",(e=>{n.removeAttribute("loading"),n.setAttribute("loaded","")})),i(n,"error",(e=>{console.error("could not load Custom Element code from",t)})),n}function v(){[...document.querySelectorAll(":not(:defined)")].filter((e=>!!e&&!customElements.get(e.tagName.toLowerCase())&&!g.has(e.tagName.toLowerCase()))).forEach((e=>{const t=e.tagName.toLowerCase(),n=(t.split("-").join("/"),y(t));i(n,"load",(()=>{g.set(t,customElements.get(e.tagName.toLowerCase()))})),g.set(t,"loading"),document.head.append(n)})),[...document.querySelectorAll('[_mc]:not([_mc=""]')].filter((e=>!!e)).forEach((e=>{const t=e.getAttribute("_mc")?.split(" ").filter((e=>!!e))||[],n=t.filter((e=>!h.has(e)));n?.forEach((e=>{const t=y(e);i(t,"load",(()=>{return t=document.head.querySelector(`script[name="${e}"]`),void setTimeout((function(){const e=t.getAttribute("src"),n=t.getAttribute("name"),r=document.createElement("script");r.async=!0,r.setAttribute("type","module");const a=`\n\n\t\t\timport _ from "${e}";\n\t\t\timport { DC } from "./microcomponents.js";\n\n\t\t\tconst elements = Array.from(document.querySelectorAll('[_mc*="${n}"]')).filter( element => element instanceof HTMLElement );\n\n\t\t\telements.forEach((element) => {\n\t\t\t\t// add class to MCs repository\n\t\t\t\tautoload.state.MCs.set( '${n}', _ );\n\t\t\t\t// add instance to HTMLElement \n\t\t\t\tDC.add(element, _.name, new _(element));\n\t\t\t\t// remove instance name from elements "_mc" attribute\n\t\t\t\telement.setAttribute('_mc', element.getAttribute('_mc').replace('${n}', '').replace( /ww/g, ' ').trim()); \n\t\t\t});\n\n\t\t\tsetTimeout( () => {\n\t\t\t\tdocument.body.querySelector('script[name="${n}]"')?.remove();\n\t\t\t},0);\n\n\t\t`;r.innerHTML=a,document.body.append(r)}),0);var t})),h.set(e,"loading"),document.head.append(t)}));const r=t.filter((e=>h.has(e)&&!h.get(e).length));r?.forEach((t=>{setTimeout((()=>{f.add(e,t,new(E.state.MCs.get(t))(e)),e.getAttribute("_mc").replace("${elementName}","").replace(/\w\w/g," ").trim(),e.setAttribute("_mc")}),5)}))}))}let w=!1,O=null;function E(e=!0){return e?(w=e,O=new MutationObserver(v),setTimeout((()=>{O.observe(document.body,{childList:!0,subtree:!0}),v()}),5),window.autoload=window.autoload||E,w):(O?.disconnect(),O=null,w)}function A(e){let t={};return[...Object.keys(e)].sort().forEach((n=>{var r;(r=e[n])&&r.constructor&&r.constructor===Object?t[n]=A(e[n]):t[n]=e[n]})),t}function x(e,t=!0){let n={};return[...Object.getOwnPropertyNames(e)].forEach((t=>{if(e[t]&&e[t].constructor&&e[t].constructor===Object){const r=x(e[t],!1);for(const e in r)n[t+"."+e]=r[e]}else n[t]=e[t]})),t?A(n):n}function _(e,t){return JSON.stringify(x(e))===JSON.stringify(x(t))}function k(e,t){let n;return()=>{clearTimeout(n),n=setTimeout((function(){e(...arguments)}),t)}}function j(e,t){const n=Object.getOwnPropertyDescriptors(e);for(const[e,r]of Object.entries(n))("get"in r||"set"in r)&&Object.defineProperty(t,e,r)}E.state={CEs:g,MCs:h};class S extends HTMLElement{constructor(){super()}connectedCallback(){f.trigger(this,"Connected")}disconnectedCallback(){f.trigger(this,"Disconnected")}adoptedCallback(){f.trigger(this,"Adopted")}attributeChangedCallback(e,t,n){f.trigger(this,"AttributeChanged",{name:e,oldValue:t,newValue:n})}}function C(e){return null!=e&&"object"==typeof e}function T(e){let t=new Set,n=/\{[^\{\}]*\}/g;return e.getAttributeNames().filter((t=>e.getAttribute(t)?.match(n))).forEach((r=>{new Set(e.getAttribute(r)?.match(n)).forEach((e=>t.add(e.replace(/[\{\}]/g,""))))})),[...e.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(n))).forEach((e=>{(e.nodeValue||"").match(n).forEach((e=>{t.add(e.replace(/[\{\}]/g,""))}))})),[...t].map((e=>e.replace(/[\{\}]/g,"")))}const N=[HTMLInputElement,HTMLSelectElement,HTMLTextAreaElement];class L extends f{data={};oldDisplay="";constructor(e){super(e);let t=this;T(e).forEach((e=>t.data[e]="")),H(t),t.#a(),delete t._mc}#a(){let e=this,t=e.target,n=!1;t.getAttributeNames().filter((e=>t.getAttribute(e)?.match(/\{[^\{\}]*\}/g))).forEach((n=>{let r=new Set(t.getAttribute(n)?.match(/\{[^\{\}]*\}/g));var a;e.data.observe((a=t.getAttribute(n),e=>{let l=a;r.forEach((t=>{l=l.replace(t,e[t.replace(/[\{\}]/g,"")])})),t.setAttribute(n,l)}))})),[...t.childNodes].filter((e=>3===e.nodeType&&(e.nodeValue||"").match(/\{[^\{\}]*\}/g))).forEach((r=>{n=!0;let a=new Set(r.nodeValue.match(/\{[^\{\}]*\}/g));var l;e.data.observe((l=r.nodeValue,n=>{let o=l;a.forEach((e=>{o=o.replace(e,n[e.replace(/[\{\}]/g,"")])})),Object.keys(n).some((e=>!!n[e]))&&(e.oldDisplay?t.style=e.oldDisplay:t.removeAttribute("style"),delete e.oldDisplay),r.nodeValue=o})),e.oldDisplay=t.getAttribute("style)")||"",n&&!N.includes(t.constructor)&&"FIELDSET"!==t.tagName&&(t.style.display="none")}))}onData(e){let t=this,n={};Object.keys(e.data).forEach((r=>{t.data.hasOwnProperty(r)&&(n[r]=e.data[r])})),JSON.stringify(n)!==JSON.stringify(t.data)&&Object.assign(t.data,n)}}const M={};function I(e){let t=e.constructor.name;return M[t]||function(e){const t=e.constructor,n=t.name;let r=class extends t{#l=!0;#o=[];constructor(e){super(e),this.constructor.callbacks=[],C(e)&&Object.getOwnPropertyNames(e).forEach((t=>{this[t]=e[t]}))}get callbacks(){return this.#o}set callbacks(e){this.#o=e}observe(e){return this.#o.push(e),this}bind(e){const t=this;if(C(t.valueOf())){!function(e){var t;(t=e,(t instanceof HTMLElement?[t]:[]).concat([...t.querySelectorAll("*")]).filter((e=>!!T(e).length)).filter((e=>"STYLE"!==e.tagName))).forEach((e=>{e?._mc?._placeholders||f.add(e,"_placeholders",new L(e))}))}(e);const n=[...e.querySelectorAll("[_mc]")].filter((e=>!!e?._mc?._placeholders)),r=function(e){let t=x(e);n.forEach((e=>{e&&e._mc.trigger("data",t)}))};t.#o.push(r),t.notify()}else console.warn("IGNORED - cannot bind a non-Object to the dom, IS:",typeof t.valueOf(),t);return this}notify(e){let t=this,n=C(t.valueOf())&&t.valueOf()instanceof Array==0?structuredClone(Object.assign({},t)):t.valueOf();return void 0!==e&&(t.#l=e),t.#o.forEach((e=>{e(n)})),t}};return M[n]=r,r}(e)}const H=(e,t)=>((t?[t]:[...Object.getOwnPropertyNames(e)]).forEach((t=>{if(e.hasOwnProperty(t)&&"function"!=typeof e[t]&&!e?.[t]?.constructor?.prototype?.observe){if("_"===t[0]||void 0===e?.[t])return e;let n=e[t],r=new(I(n))(n);Object.defineProperty(e,t,{enumerable:!0,get(){if(C(r.valueOf())){let e=structuredClone(Object.assign({},r));setTimeout(k((function(){_(structuredClone(Object.assign({},r)),e)||r.notify()}),0),0)}return r},set(e){if(typeof e==typeof r.valueOf())if(C(r.valueOf())&&r.valueOf()instanceof Array==0){let t=structuredClone(Object.assign({},r));void 0===r?.constructor?.prototype?.observe&&(r=new(I(e))(structuredClone(Object.assign({},e))),j(e,r),r.seal()),Object.assign(r,e),setTimeout(k((function(){_(structuredClone(Object.assign({},r)),t)||r.notify()}),0),0)}else{let t=r.valueOf(),n=r.callbacks;e!==t&&(r=new(I(e))(e),r.callbacks=n,r.notify())}else console.warn("IGNORED - cannot change observable types, IS:",typeof r.valueOf(),r,"- CANNOT BECOME:",typeof e)}}),e[t]=n}})),e);class P{constructor(e){}}class D extends P{#s;constructor(e){super(e),this.#s=e}get val(){return new FormData(this.#s.form).get(this.#s.name)}set val(e){[...this.#s.form.querySelectorAll(`input[type="radio"][name="${this.#s.name}"]`)].filter((t=>t.getAttribute("value")===e)).shift().checked=!0}}class q extends P{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.checked}set val(e){this.#s.checked=e}}class $ extends P{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.value}set val(e){this.#s.value=e}}class R extends P{#s;#i=!1;constructor(e){super(e),this.#s=e,this.#i=e.multiple}get val(){const e=[];return[...this.#s.querySelectorAll("option")].filter((e=>e.selected)).forEach((t=>{e.push(t.value)})),this.#i?e:e.length?e[0]:""}set val(e){e="string"==typeof e?[e]:e,[...this.#s.querySelectorAll("option")].forEach((t=>{e.indexOf(t.value)>-1?t.selected=!0:t.selected=!1}))}}class V extends P{#s;constructor(e){super(e),this.#s=e}get val(){return this.#s.value||""}set val(e){this.#s.value=e}}return function(e,t,n=[]){if(customElements.get(e))return void console.warn(`IGNORED: Custom element "${e}" is already defined!`);if(!e.includes("-"))throw new Error('createCustomElement: tagName must contain at least one hyphen ("-").');let r=e.split("-").map((e=>e.charAt(0).toUpperCase()+e.slice(1))).join("");customElements.define(e,function(e,t){return Object.defineProperty(t,"name",{value:e})}(r,class extends S{instance;constructor(e){super();let n=new t(this,e);f.add(this,r,n)}static get observedAttributes(){return n}}))}("test-testform",class extends f{data;constructor(e){super(e);const t=this;delete t._mc;let n=t.target.attachShadow({mode:"open"});n.innerHTML=`<style>${t.css}</style>${t.template}`,function(e,t,n){let r=(e=>{let t=[...(e||document).querySelectorAll("input,select,textarea")],n={};return t.forEach((e=>{const t=e.getAttribute("name");if(t){let r=!1;switch((e=>e.tagName.toLowerCase())(e)){case"input":switch(e.type){case"radio":r=new D(e);break;case"checkbox":r=new q(e);break;default:r=new $(e)}break;case"select":r=new R(e);break;case"textarea":r=new V(e);break;default:console.warn("handler missing:",t,"for",e.tagName.toLowerCase(),e)}r&&(f.add(e,t,r),Object.defineProperty(n,t,{enumerable:!0,configurable:!0,get:()=>r.val,set:e=>{r.val!==e&&(r.val=e)}}))}})),n})(n);e[t]=Object.assign({},r),H(e,t),j(r,e[t]),[...n.querySelectorAll("input, textarea, select")].forEach((n=>{i(n,"input",(n=>{e[t].notify()}))}))}(t,"data",n),t.data.bind(n),fetch("./testform.json").then((e=>e.json())).then((e=>{t.data=e}))}get template(){return'\n <form>\n \x3c!-- sample form to start with --\x3e\n <fieldset>\n <legend>Inputs</legend>\n <label>text</label><input type="text" name="textInput" value="Hallo" /> <strong>2wB: </strong>{textInput}<br />\n <label>color</label><input type="color" name="colorInput" value="#000000" /><br />\n <label>date</label><input type="date" name="dateInput" value="" /><br />\n <label>datetime-local</label><input type="datetime-local" name="dtlInput" value="" /><br />\n <label>email</label><input type="email" name="email" value="" /><br />\n <label>file</label><input type="file" name="fileInput" value="" /><br />\n <label>hidden</label><input type="hidden" name="hiddenInput" value="hiddenVal" /><br />\n <label>month</label><input type="month" name="month" value="" /><br />\n <label>number</label><input type="number" name="number" value="" /><br />\n <label>password</label><input type="password" name="passInput" value="" /><br />\n <label>range</label><input type="range" name="rangeInput" value="" /><br />\n <label>search</label><input type="search" name="searchInput" value="" /><br />\n <label>tel</label><input type="tel" name="telInput" value="" /><br />\n <label>time</label><input type="time" name="timeInput" value="" /><br />\n <label>url</label><input type="url" name="urlInput" value="" /><br />\n <label>week</label><input type="week" name="weekInput" value="" /><br />\n </fieldset>\n\n <fieldset>\n <legend>Selects <strong>2wB: </strong> <span>"{singleSelect}"</span> <span>[{multiSelect}]</span></legend>\n\n <label>singleSelect</label>\n <select name="singleSelect">\n <option disabled selected value> -- select -- </option>\n <option value="1">Option 1</option>\n <option value="2">Option 2</option>\n <option value="3">Option 3</option>\n <option value="4">Option 4</option>\n </select><br />\n\n <label>multiSelect</label>\n <select name="multiSelect" multiple="multiple" type="select-multiple">\n <option value="1">Option 1</option>\n <option value="2" selected=true>Option 2</option>\n <option value="3">Option 3</option>\n <option value="4" selected=true>Option 4</option>\n </select>\n\n </fieldset>\n\n <fieldset>\n <legend>Radiobuttons <strong>2wB: </strong><span>"{myRadio}"</span></legend>\n\n <label>radio1</label><input type="radio" name="myRadio" value="radio1"><br />\n <label>radio2</label><input type="radio" name="myRadio" value="radio2"><br />\n <label>radio3</label><input type="radio" name="myRadio" value="radio3"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>Checkboxes</legend>\n <label>cb1</label><input type="checkbox" name="cb1"><br />\n <label>cb2</label><input type="checkbox" name="cb2"><br />\n <label>cb3</label><input type="checkbox" name="cb3"><br />\n <label>cb4</label><input type="checkbox" name="cb4"><br />\n <label>cb5</label><input type="checkbox" name="cb5"><br />\n\n </fieldset>\n\n <fieldset>\n <legend>TextArea</legend>\n <label>textArea</label>\n <textarea name="textArea">abc</textarea>\n </fieldset>\n\n </form>\n '}get css(){return'\nlegend {\n display: inherit;\n margin: inherit;\n vertical-align: inherit;\n font-weight: bold;\n}\n\nlabel {\n display: inline-block;\n margin-top: 1em;\n margin-left: 5px;\n vertical-align: top;\n min-width:10em;\n text-align: right;\n}\n\nform input,\nform select,\nform textarea {\n display: inline-block;\n margin-left: 5px;\n margin-top: 1.1em;\n}\n\ninput[type="radio"],\ninput[type="checkbox"] {\n margin-top: 1.3em;\n}\n\nbody > form {\n display: block;\n}\n\nform fieldset {\n border: 1px solid #aaaaaa;\n border-radius: 3px;\n margin: 0.5em 0;\n}\n '}}),{}})()));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
window.searchData = "data:application/octet-stream;base64,
|
|
1
|
+
window.searchData = "data:application/octet-stream;base64,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";
|