mount-observer 0.0.105 → 0.0.106
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/Events.js +42 -0
- package/Events.ts +45 -0
- package/MountObserver.js +62 -94
- package/MountObserver.ts +63 -87
- package/package.json +5 -1
- package/readAttrs.ts +60 -0
- package/refid/ism.js +80 -0
- package/refid/ism.ts +82 -0
- package/refid/stdVal.js +15 -0
- package/refid/stdVal.ts +15 -0
- package/ts-refs/be-consoling/types.d.ts +25 -0
- package/ts-refs/be-evanescent/types.d.ts +20 -0
- package/ts-refs/be-fetching/types.d.ts +73 -0
- package/ts-refs/be-gone/types.d.ts +24 -0
- package/ts-refs/be-intersectional/types.d.ts +37 -0
- package/ts-refs/be-lazy/types.d.ts +29 -0
- package/ts-refs/be-parsing/types.d.ts +37 -0
- package/ts-refs/do-invoke/types.d.ts +3 -3
- package/ts-refs/fetch-for/types.d.ts +37 -0
- package/ts-refs/for-fetch/doc.d.ts +98 -0
- package/ts-refs/for-fetch/types.d.ts +4 -96
- package/ts-refs/soak-up/types.d.ts +36 -0
- package/ts-refs/trans-render/froop/types.d.ts +14 -5
- package/ts-refs/trans-render/types.d.ts +4 -3
- package/ts-refs/wc-info/SimpleWCInfo.d.ts +15 -0
package/Events.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
//TODO: make thes external
|
|
2
|
+
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
|
3
|
+
/**
|
|
4
|
+
* The `mutation-event` event represents something that happened.
|
|
5
|
+
* We can document it here.
|
|
6
|
+
*/
|
|
7
|
+
export class MountEvent extends Event {
|
|
8
|
+
mountedElement;
|
|
9
|
+
initializing;
|
|
10
|
+
static eventName = 'mount';
|
|
11
|
+
constructor(mountedElement, initializing) {
|
|
12
|
+
super(MountEvent.eventName);
|
|
13
|
+
this.mountedElement = mountedElement;
|
|
14
|
+
this.initializing = initializing;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class DismountEvent extends Event {
|
|
18
|
+
dismountedElement;
|
|
19
|
+
static eventName = 'dismount';
|
|
20
|
+
constructor(dismountedElement) {
|
|
21
|
+
super(DismountEvent.eventName);
|
|
22
|
+
this.dismountedElement = dismountedElement;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export class DisconnectEvent extends Event {
|
|
26
|
+
disconnectedElement;
|
|
27
|
+
static eventName = 'disconnect';
|
|
28
|
+
constructor(disconnectedElement) {
|
|
29
|
+
super(DisconnectEvent.eventName);
|
|
30
|
+
this.disconnectedElement = disconnectedElement;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export class AttrChangeEvent extends Event {
|
|
34
|
+
mountedElement;
|
|
35
|
+
attrChangeInfos;
|
|
36
|
+
static eventName = 'attrChange';
|
|
37
|
+
constructor(mountedElement, attrChangeInfos) {
|
|
38
|
+
super(AttrChangeEvent.eventName);
|
|
39
|
+
this.mountedElement = mountedElement;
|
|
40
|
+
this.attrChangeInfos = attrChangeInfos;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/Events.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {MountInit, IMountObserver, AddMutationEventListener,
|
|
2
|
+
MutationEvent, dismountEventName, mountEventName, IMountEvent, IDismountEvent,
|
|
3
|
+
disconnectedEventName, IDisconnectEvent, IAttrChangeEvent, attrChangeEventName, AttrChangeInfo, loadEventName, ILoadEvent,
|
|
4
|
+
AttrParts,
|
|
5
|
+
MOSE, WeakDual,
|
|
6
|
+
MountObserverOptions,
|
|
7
|
+
Assigner,
|
|
8
|
+
RefType
|
|
9
|
+
} from './ts-refs/mount-observer/types';
|
|
10
|
+
//TODO: make thes external
|
|
11
|
+
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
|
12
|
+
/**
|
|
13
|
+
* The `mutation-event` event represents something that happened.
|
|
14
|
+
* We can document it here.
|
|
15
|
+
*/
|
|
16
|
+
export class MountEvent extends Event implements IMountEvent {
|
|
17
|
+
static eventName: mountEventName = 'mount';
|
|
18
|
+
|
|
19
|
+
constructor(public mountedElement: Element, public initializing: boolean) {
|
|
20
|
+
super(MountEvent.eventName);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class DismountEvent extends Event implements IDismountEvent{
|
|
25
|
+
static eventName: dismountEventName = 'dismount';
|
|
26
|
+
|
|
27
|
+
constructor(public dismountedElement: Element){
|
|
28
|
+
super(DismountEvent.eventName);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export class DisconnectEvent extends Event implements IDisconnectEvent{
|
|
33
|
+
static eventName: disconnectedEventName = 'disconnect';
|
|
34
|
+
|
|
35
|
+
constructor(public disconnectedElement: Element){
|
|
36
|
+
super(DisconnectEvent.eventName);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export class AttrChangeEvent extends Event implements IAttrChangeEvent{
|
|
41
|
+
static eventName: attrChangeEventName = 'attrChange';
|
|
42
|
+
constructor(public mountedElement: Element, public attrChangeInfos: Array<AttrChangeInfo>){
|
|
43
|
+
super(AttrChangeEvent.eventName);
|
|
44
|
+
}
|
|
45
|
+
}
|
package/MountObserver.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { RootMutObs } from './RootMutObs.js';
|
|
2
2
|
import { bindish, bindishIt } from './bindish.js';
|
|
3
|
-
import './refid/hostish.js';
|
|
3
|
+
import './refid/hostish.js'; // gets embedded even if not used
|
|
4
4
|
export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
|
|
5
5
|
export const wasItemReffed = Symbol.for('8aA6xB8+PkScmivaslBk5Q');
|
|
6
6
|
export const mutationObserverLookup = new WeakMap();
|
|
@@ -73,6 +73,7 @@ export class MountObserver extends EventTarget {
|
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
async #compose(el, level) {
|
|
76
|
+
//[TODO]: load async, not used often
|
|
76
77
|
const src = el.getAttribute('src');
|
|
77
78
|
if (src === null || src.length < 2)
|
|
78
79
|
return;
|
|
@@ -84,6 +85,7 @@ export class MountObserver extends EventTarget {
|
|
|
84
85
|
}
|
|
85
86
|
#templLookUp = new Map();
|
|
86
87
|
#searchForComment(refName, fragment) {
|
|
88
|
+
//get rid of
|
|
87
89
|
const iterator = document.evaluate(`//comment()[.="${refName}"]`, fragment, null, XPathResult.ANY_TYPE, null);
|
|
88
90
|
//console.log({xpathResult})
|
|
89
91
|
try {
|
|
@@ -94,7 +96,9 @@ export class MountObserver extends EventTarget {
|
|
|
94
96
|
return null;
|
|
95
97
|
}
|
|
96
98
|
}
|
|
97
|
-
async findByID(
|
|
99
|
+
async findByID(
|
|
100
|
+
//[TODO]: make external, not always used
|
|
101
|
+
refName, fragment, refType) {
|
|
98
102
|
if (this.#templLookUp.has(refName))
|
|
99
103
|
return this.#templLookUp.get(refName);
|
|
100
104
|
let templ = null;
|
|
@@ -262,6 +266,7 @@ export class MountObserver extends EventTarget {
|
|
|
262
266
|
elsToInspect.push(target);
|
|
263
267
|
}
|
|
264
268
|
const deletedElements = Array.from(removedNodes).filter(x => x instanceof Element);
|
|
269
|
+
const { DisconnectEvent } = await import('./Events.js');
|
|
265
270
|
for (const deletedElement of deletedElements) {
|
|
266
271
|
this.#disconnected.add(deletedElement);
|
|
267
272
|
if (doDisconnect !== undefined) {
|
|
@@ -271,6 +276,7 @@ export class MountObserver extends EventTarget {
|
|
|
271
276
|
}
|
|
272
277
|
}
|
|
273
278
|
if (attrChangeInfosMap !== undefined) {
|
|
279
|
+
const { AttrChangeEvent } = await import('./Events.js');
|
|
274
280
|
for (const [key, value] of attrChangeInfosMap) {
|
|
275
281
|
this.dispatchEvent(new AttrChangeEvent(key, value));
|
|
276
282
|
}
|
|
@@ -283,6 +289,7 @@ export class MountObserver extends EventTarget {
|
|
|
283
289
|
await this.#inspectWithin(within, true);
|
|
284
290
|
}
|
|
285
291
|
static synthesize(within, customElement, mose) {
|
|
292
|
+
//TODO: make external
|
|
286
293
|
mose.type = 'mountobserver';
|
|
287
294
|
const name = customElements.getName(customElement);
|
|
288
295
|
if (name === null)
|
|
@@ -350,65 +357,65 @@ export class MountObserver extends EventTarget {
|
|
|
350
357
|
}
|
|
351
358
|
match[guid].add(this);
|
|
352
359
|
}
|
|
360
|
+
const { MountEvent } = await import('./Events.js');
|
|
353
361
|
this.dispatchEvent(new MountEvent(match, initializing));
|
|
354
362
|
//should we automatically call readAttrs?
|
|
355
363
|
//the thinking is it might make more sense to call that after mounting
|
|
356
364
|
this.#mountedList?.push(new WeakRef(match));
|
|
357
365
|
}
|
|
358
366
|
}
|
|
359
|
-
readAttrs(match, branchIndexes)
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
return attrChangeInfos;
|
|
409
|
-
}
|
|
367
|
+
// readAttrs(match: Element, branchIndexes?: Set<number>){
|
|
368
|
+
// //TODO: externalize
|
|
369
|
+
// const fullListOfAttrs = this.#fullListOfEnhancementAttrs;
|
|
370
|
+
// const attrChangeInfos: Array<AttrChangeInfo> = [];
|
|
371
|
+
// const oldValue = null;
|
|
372
|
+
// if(fullListOfAttrs !== undefined){
|
|
373
|
+
// const attrParts = this.#attrParts
|
|
374
|
+
// for(let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++){
|
|
375
|
+
// const parts = attrParts![idx];
|
|
376
|
+
// const {branchIdx} = parts;
|
|
377
|
+
// if(branchIndexes !== undefined){
|
|
378
|
+
// if(!branchIndexes.has(branchIdx)) continue;
|
|
379
|
+
// }
|
|
380
|
+
// const name = fullListOfAttrs[idx];
|
|
381
|
+
// const newValue = match.getAttribute(name);
|
|
382
|
+
// attrChangeInfos.push({
|
|
383
|
+
// idx,
|
|
384
|
+
// isSOfTAttr: false,
|
|
385
|
+
// newValue,
|
|
386
|
+
// oldValue,
|
|
387
|
+
// name,
|
|
388
|
+
// parts
|
|
389
|
+
// });
|
|
390
|
+
// }
|
|
391
|
+
// }
|
|
392
|
+
// const {observedAttrsWhenMounted} = this.#mountInit;
|
|
393
|
+
// if(observedAttrsWhenMounted !== undefined){
|
|
394
|
+
// for(const observedAttr of observedAttrsWhenMounted){
|
|
395
|
+
// const attrIsString = typeof observedAttr === 'string';
|
|
396
|
+
// const name = attrIsString ? observedAttr : observedAttr.name;
|
|
397
|
+
// let mapsTo: string | undefined;
|
|
398
|
+
// let newValue = match.getAttribute(name);
|
|
399
|
+
// if(!attrIsString){
|
|
400
|
+
// const {customParser, instanceOf, mapsTo: mt, valIfNull} = observedAttr;
|
|
401
|
+
// if(instanceOf || customParser) throw 'NI';
|
|
402
|
+
// if(newValue === null) newValue = valIfNull;
|
|
403
|
+
// mapsTo = mt;
|
|
404
|
+
// }
|
|
405
|
+
// attrChangeInfos.push({
|
|
406
|
+
// isSOfTAttr: true,
|
|
407
|
+
// newValue,
|
|
408
|
+
// oldValue,
|
|
409
|
+
// name,
|
|
410
|
+
// mapsTo
|
|
411
|
+
// });
|
|
412
|
+
// }
|
|
413
|
+
// }
|
|
414
|
+
// return attrChangeInfos;
|
|
415
|
+
// }
|
|
410
416
|
async #dismount(unmatching) {
|
|
411
417
|
const onDismount = this.#mountInit.do?.dismount;
|
|
418
|
+
const { DismountEvent } = await import('./Events.js');
|
|
412
419
|
for (const unmatch of unmatching) {
|
|
413
420
|
if (onDismount !== undefined) {
|
|
414
421
|
onDismount(unmatch, this, {});
|
|
@@ -519,6 +526,7 @@ export class MountObserver extends EventTarget {
|
|
|
519
526
|
this.#filterAndMount(els, within, false, initializing);
|
|
520
527
|
}
|
|
521
528
|
}
|
|
529
|
+
//ToDO: make external
|
|
522
530
|
export function waitForIdleNodes(nodes, idleTimeout) {
|
|
523
531
|
const mountInit = {
|
|
524
532
|
idleTimeout
|
|
@@ -550,6 +558,7 @@ export function waitForIdleNodes(nodes, idleTimeout) {
|
|
|
550
558
|
}
|
|
551
559
|
});
|
|
552
560
|
}
|
|
561
|
+
//make external
|
|
553
562
|
function areAllIdle(mutObs) {
|
|
554
563
|
for (const mo of mutObs) {
|
|
555
564
|
if (!mo.isIdle)
|
|
@@ -559,45 +568,4 @@ function areAllIdle(mutObs) {
|
|
|
559
568
|
}
|
|
560
569
|
const refCountErr = 'mount-observer ref count mismatch';
|
|
561
570
|
export const inclTemplQry = 'template[src^="#"]:not([hidden]),template[src^="!"]:not([hidden])';
|
|
562
|
-
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
|
563
|
-
/**
|
|
564
|
-
* The `mutation-event` event represents something that happened.
|
|
565
|
-
* We can document it here.
|
|
566
|
-
*/
|
|
567
|
-
export class MountEvent extends Event {
|
|
568
|
-
mountedElement;
|
|
569
|
-
initializing;
|
|
570
|
-
static eventName = 'mount';
|
|
571
|
-
constructor(mountedElement, initializing) {
|
|
572
|
-
super(MountEvent.eventName);
|
|
573
|
-
this.mountedElement = mountedElement;
|
|
574
|
-
this.initializing = initializing;
|
|
575
|
-
}
|
|
576
|
-
}
|
|
577
|
-
export class DismountEvent extends Event {
|
|
578
|
-
dismountedElement;
|
|
579
|
-
static eventName = 'dismount';
|
|
580
|
-
constructor(dismountedElement) {
|
|
581
|
-
super(DismountEvent.eventName);
|
|
582
|
-
this.dismountedElement = dismountedElement;
|
|
583
|
-
}
|
|
584
|
-
}
|
|
585
|
-
export class DisconnectEvent extends Event {
|
|
586
|
-
disconnectedElement;
|
|
587
|
-
static eventName = 'disconnect';
|
|
588
|
-
constructor(disconnectedElement) {
|
|
589
|
-
super(DisconnectEvent.eventName);
|
|
590
|
-
this.disconnectedElement = disconnectedElement;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
export class AttrChangeEvent extends Event {
|
|
594
|
-
mountedElement;
|
|
595
|
-
attrChangeInfos;
|
|
596
|
-
static eventName = 'attrChange';
|
|
597
|
-
constructor(mountedElement, attrChangeInfos) {
|
|
598
|
-
super(AttrChangeEvent.eventName);
|
|
599
|
-
this.mountedElement = mountedElement;
|
|
600
|
-
this.attrChangeInfos = attrChangeInfos;
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
571
|
//const hasRootInDefault = ['data', 'enh', 'data-enh']
|
package/MountObserver.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {MountInit, IMountObserver, AddMutationEventListener,
|
|
|
9
9
|
} from './ts-refs/mount-observer/types';
|
|
10
10
|
import {RootMutObs} from './RootMutObs.js';
|
|
11
11
|
import {bindish, bindishIt} from './bindish.js';
|
|
12
|
-
import './refid/hostish.js';
|
|
12
|
+
import './refid/hostish.js'; // gets embedded even if not used
|
|
13
13
|
export {MOSE} from './ts-refs/mount-observer/types';
|
|
14
14
|
export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
|
|
15
15
|
export const wasItemReffed = Symbol.for('8aA6xB8+PkScmivaslBk5Q');
|
|
@@ -88,6 +88,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
88
88
|
|
|
89
89
|
|
|
90
90
|
async #compose(el: HTMLTemplateElement, level: number){
|
|
91
|
+
//[TODO]: load async, not used often
|
|
91
92
|
const src = el.getAttribute('src');
|
|
92
93
|
if(src === null || src.length < 2) return;
|
|
93
94
|
const refType = src[0] as RefType;
|
|
@@ -99,6 +100,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
99
100
|
}
|
|
100
101
|
#templLookUp: Map<string, HTMLElement> = new Map();
|
|
101
102
|
#searchForComment(refName: string, fragment: Node){
|
|
103
|
+
//get rid of
|
|
102
104
|
const iterator = document.evaluate(
|
|
103
105
|
`//comment()[.="${refName}"]`,
|
|
104
106
|
fragment,
|
|
@@ -115,6 +117,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
115
117
|
}
|
|
116
118
|
}
|
|
117
119
|
async findByID(
|
|
120
|
+
//[TODO]: make external, not always used
|
|
118
121
|
refName: string, fragment: DocumentFragment,
|
|
119
122
|
refType: RefType): Promise<HTMLElement | DocumentFragment | null>{
|
|
120
123
|
if(this.#templLookUp.has(refName)) return this.#templLookUp.get(refName)!;
|
|
@@ -288,6 +291,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
288
291
|
}
|
|
289
292
|
|
|
290
293
|
const deletedElements = Array.from(removedNodes).filter(x => x instanceof Element) as Array<Element>;
|
|
294
|
+
const {DisconnectEvent} = await import('./Events.js');
|
|
291
295
|
for(const deletedElement of deletedElements){
|
|
292
296
|
this.#disconnected.add(deletedElement);
|
|
293
297
|
if(doDisconnect !== undefined){
|
|
@@ -298,6 +302,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
298
302
|
|
|
299
303
|
}
|
|
300
304
|
if(attrChangeInfosMap !== undefined){
|
|
305
|
+
const {AttrChangeEvent} = await import('./Events.js');
|
|
301
306
|
for(const [key, value] of attrChangeInfosMap){
|
|
302
307
|
this.dispatchEvent(new AttrChangeEvent(key, value))
|
|
303
308
|
}
|
|
@@ -312,6 +317,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
312
317
|
}
|
|
313
318
|
|
|
314
319
|
static synthesize(within: Document | ShadowRoot, customElement: {new(): HTMLElement}, mose: MOSE){
|
|
320
|
+
//TODO: make external
|
|
315
321
|
mose.type = 'mountobserver';
|
|
316
322
|
const name = customElements.getName(customElement);
|
|
317
323
|
if(name === null) throw 400;
|
|
@@ -377,6 +383,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
377
383
|
}
|
|
378
384
|
(<any>match)[guid].add(this);
|
|
379
385
|
}
|
|
386
|
+
const {MountEvent} = await import('./Events.js');
|
|
380
387
|
this.dispatchEvent(new MountEvent(match, initializing));
|
|
381
388
|
//should we automatically call readAttrs?
|
|
382
389
|
//the thinking is it might make more sense to call that after mounting
|
|
@@ -385,62 +392,64 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
385
392
|
}
|
|
386
393
|
}
|
|
387
394
|
|
|
388
|
-
readAttrs(match: Element, branchIndexes?: Set<number>){
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
395
|
+
// readAttrs(match: Element, branchIndexes?: Set<number>){
|
|
396
|
+
// //TODO: externalize
|
|
397
|
+
// const fullListOfAttrs = this.#fullListOfEnhancementAttrs;
|
|
398
|
+
// const attrChangeInfos: Array<AttrChangeInfo> = [];
|
|
399
|
+
// const oldValue = null;
|
|
400
|
+
// if(fullListOfAttrs !== undefined){
|
|
401
|
+
// const attrParts = this.#attrParts
|
|
394
402
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
403
|
+
// for(let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++){
|
|
404
|
+
// const parts = attrParts![idx];
|
|
405
|
+
// const {branchIdx} = parts;
|
|
406
|
+
// if(branchIndexes !== undefined){
|
|
407
|
+
// if(!branchIndexes.has(branchIdx)) continue;
|
|
408
|
+
// }
|
|
409
|
+
// const name = fullListOfAttrs[idx];
|
|
402
410
|
|
|
403
|
-
|
|
411
|
+
// const newValue = match.getAttribute(name);
|
|
404
412
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}
|
|
413
|
+
// attrChangeInfos.push({
|
|
414
|
+
// idx,
|
|
415
|
+
// isSOfTAttr: false,
|
|
416
|
+
// newValue,
|
|
417
|
+
// oldValue,
|
|
418
|
+
// name,
|
|
419
|
+
// parts
|
|
420
|
+
// });
|
|
421
|
+
// }
|
|
422
|
+
|
|
423
|
+
// }
|
|
424
|
+
// const {observedAttrsWhenMounted} = this.#mountInit;
|
|
425
|
+
// if(observedAttrsWhenMounted !== undefined){
|
|
426
|
+
// for(const observedAttr of observedAttrsWhenMounted){
|
|
427
|
+
// const attrIsString = typeof observedAttr === 'string';
|
|
428
|
+
// const name = attrIsString ? observedAttr : observedAttr.name;
|
|
429
|
+
// let mapsTo: string | undefined;
|
|
430
|
+
// let newValue = match.getAttribute(name);
|
|
431
|
+
// if(!attrIsString){
|
|
432
|
+
// const {customParser, instanceOf, mapsTo: mt, valIfNull} = observedAttr;
|
|
433
|
+
// if(instanceOf || customParser) throw 'NI';
|
|
434
|
+
// if(newValue === null) newValue = valIfNull;
|
|
435
|
+
// mapsTo = mt;
|
|
436
|
+
// }
|
|
437
|
+
// attrChangeInfos.push({
|
|
438
|
+
// isSOfTAttr: true,
|
|
439
|
+
// newValue,
|
|
440
|
+
// oldValue,
|
|
441
|
+
// name,
|
|
442
|
+
// mapsTo
|
|
443
|
+
// });
|
|
444
|
+
// }
|
|
445
|
+
// }
|
|
446
|
+
|
|
447
|
+
// return attrChangeInfos;
|
|
448
|
+
// }
|
|
441
449
|
|
|
442
450
|
async #dismount(unmatching: Array<Element>){
|
|
443
|
-
const onDismount = this.#mountInit.do?.dismount
|
|
451
|
+
const onDismount = this.#mountInit.do?.dismount;
|
|
452
|
+
const {DismountEvent} = await import('./Events.js');
|
|
444
453
|
for(const unmatch of unmatching){
|
|
445
454
|
if(onDismount !== undefined){
|
|
446
455
|
onDismount(unmatch, this, {});
|
|
@@ -552,6 +561,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
552
561
|
|
|
553
562
|
}
|
|
554
563
|
|
|
564
|
+
//ToDO: make external
|
|
555
565
|
export function waitForIdleNodes(nodes: Array<Node>, idleTimeout?: number): Promise<void>{
|
|
556
566
|
const mountInit: MountInit = {
|
|
557
567
|
idleTimeout
|
|
@@ -583,6 +593,7 @@ export function waitForIdleNodes(nodes: Array<Node>, idleTimeout?: number): Prom
|
|
|
583
593
|
});
|
|
584
594
|
}
|
|
585
595
|
|
|
596
|
+
//make external
|
|
586
597
|
function areAllIdle(mutObs: Array<RootMutObs>){
|
|
587
598
|
for(const mo of mutObs){
|
|
588
599
|
if(!mo.isIdle) return false;
|
|
@@ -596,41 +607,6 @@ export const inclTemplQry = 'template[src^="#"]:not([hidden]),template[src^="!"]
|
|
|
596
607
|
|
|
597
608
|
export interface MountObserver extends IMountObserver{}
|
|
598
609
|
|
|
599
|
-
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
|
600
|
-
/**
|
|
601
|
-
* The `mutation-event` event represents something that happened.
|
|
602
|
-
* We can document it here.
|
|
603
|
-
*/
|
|
604
|
-
export class MountEvent extends Event implements IMountEvent {
|
|
605
|
-
static eventName: mountEventName = 'mount';
|
|
606
|
-
|
|
607
|
-
constructor(public mountedElement: Element, public initializing: boolean) {
|
|
608
|
-
super(MountEvent.eventName);
|
|
609
|
-
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
export class DismountEvent extends Event implements IDismountEvent{
|
|
613
|
-
static eventName: dismountEventName = 'dismount';
|
|
614
|
-
|
|
615
|
-
constructor(public dismountedElement: Element){
|
|
616
|
-
super(DismountEvent.eventName);
|
|
617
|
-
}
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
export class DisconnectEvent extends Event implements IDisconnectEvent{
|
|
621
|
-
static eventName: disconnectedEventName = 'disconnect';
|
|
622
|
-
|
|
623
|
-
constructor(public disconnectedElement: Element){
|
|
624
|
-
super(DisconnectEvent.eventName);
|
|
625
|
-
}
|
|
626
|
-
}
|
|
627
|
-
|
|
628
|
-
export class AttrChangeEvent extends Event implements IAttrChangeEvent{
|
|
629
|
-
static eventName: attrChangeEventName = 'attrChange';
|
|
630
|
-
constructor(public mountedElement: Element, public attrChangeInfos: Array<AttrChangeInfo>){
|
|
631
|
-
super(AttrChangeEvent.eventName);
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
610
|
|
|
635
611
|
|
|
636
612
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.106",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
@@ -69,6 +69,10 @@
|
|
|
69
69
|
"default": "./refid/getCount.js",
|
|
70
70
|
"types": "./refid/getCount.ts"
|
|
71
71
|
},
|
|
72
|
+
"./refid/ism.js": {
|
|
73
|
+
"default": "./refid/ism.js",
|
|
74
|
+
"types": "./refid/ism.ts"
|
|
75
|
+
},
|
|
72
76
|
"./refid/itemprops.js": {
|
|
73
77
|
"default": "./refid/itemprops.js",
|
|
74
78
|
"types": "./refid/itemprops.ts"
|
package/readAttrs.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { AttrChangeInfo, AttrParts, MountInit } from "./ts-refs/mount-observer/types";
|
|
2
|
+
|
|
3
|
+
export function readAttrs(
|
|
4
|
+
match: Element, mountInit: MountInit, branchIndexes?: Set<number>,
|
|
5
|
+
fullListOfEnhancementAttrs?: string[],
|
|
6
|
+
attrParts?: AttrParts[],
|
|
7
|
+
){
|
|
8
|
+
//TODO: externalize
|
|
9
|
+
const fullListOfAttrs = fullListOfEnhancementAttrs;
|
|
10
|
+
const attrChangeInfos: Array<AttrChangeInfo> = [];
|
|
11
|
+
const oldValue = null;
|
|
12
|
+
if(fullListOfAttrs !== undefined){
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
for(let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++){
|
|
16
|
+
const parts = attrParts![idx];
|
|
17
|
+
const {branchIdx} = parts;
|
|
18
|
+
if(branchIndexes !== undefined){
|
|
19
|
+
if(!branchIndexes.has(branchIdx)) continue;
|
|
20
|
+
}
|
|
21
|
+
const name = fullListOfAttrs[idx];
|
|
22
|
+
|
|
23
|
+
const newValue = match.getAttribute(name);
|
|
24
|
+
|
|
25
|
+
attrChangeInfos.push({
|
|
26
|
+
idx,
|
|
27
|
+
isSOfTAttr: false,
|
|
28
|
+
newValue,
|
|
29
|
+
oldValue,
|
|
30
|
+
name,
|
|
31
|
+
parts
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
36
|
+
const {observedAttrsWhenMounted} = mountInit;
|
|
37
|
+
if(observedAttrsWhenMounted !== undefined){
|
|
38
|
+
for(const observedAttr of observedAttrsWhenMounted){
|
|
39
|
+
const attrIsString = typeof observedAttr === 'string';
|
|
40
|
+
const name = attrIsString ? observedAttr : observedAttr.name;
|
|
41
|
+
let mapsTo: string | undefined;
|
|
42
|
+
let newValue = match.getAttribute(name);
|
|
43
|
+
if(!attrIsString){
|
|
44
|
+
const {customParser, instanceOf, mapsTo: mt, valIfNull} = observedAttr;
|
|
45
|
+
if(instanceOf || customParser) throw 'NI';
|
|
46
|
+
if(newValue === null) newValue = valIfNull;
|
|
47
|
+
mapsTo = mt;
|
|
48
|
+
}
|
|
49
|
+
attrChangeInfos.push({
|
|
50
|
+
isSOfTAttr: true,
|
|
51
|
+
newValue,
|
|
52
|
+
oldValue,
|
|
53
|
+
name,
|
|
54
|
+
mapsTo
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return attrChangeInfos;
|
|
60
|
+
}
|