mount-observer 0.0.52 → 0.0.54
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/MountObserver.js +38 -3
- package/MountObserver.ts +37 -3
- package/Newish.js +61 -52
- package/Newish.ts +65 -51
- package/ObsAttr.js +18 -0
- package/ObsAttr.ts +18 -0
- package/RootMutObs.js +16 -0
- package/RootMutObs.ts +20 -2
- package/bindish.js +4 -4
- package/bindish.ts +5 -5
- package/package.json +5 -1
- package/ts-refs/be-scoped/types.d.ts +23 -0
- package/ts-refs/mount-observer/types.d.ts +5 -1
- package/ts-refs/per-each/types.d.ts +2 -0
- package/ts-refs/trans-render/be/types.d.ts +2 -0
- package/ts-refs/trans-render/froop/types.d.ts +2 -2
package/MountObserver.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RootMutObs } from './RootMutObs.js';
|
|
2
2
|
import { bindish, bindishIt } from './bindish.js';
|
|
3
3
|
export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
|
|
4
|
-
const mutationObserverLookup = new WeakMap();
|
|
4
|
+
export const mutationObserverLookup = new WeakMap();
|
|
5
5
|
const refCount = new WeakMap();
|
|
6
6
|
export class MountObserver extends EventTarget {
|
|
7
7
|
#mountInit;
|
|
@@ -419,17 +419,52 @@ export class MountObserver extends EventTarget {
|
|
|
419
419
|
await this.#compose(elToMount, 0);
|
|
420
420
|
}
|
|
421
421
|
}
|
|
422
|
-
await bindishIt(els, assigner);
|
|
422
|
+
await bindishIt(els, { assigner });
|
|
423
423
|
this.#mount(elsToMount, initializing);
|
|
424
424
|
}
|
|
425
425
|
async #inspectWithin(within, initializing) {
|
|
426
|
-
await bindish(within, this.#mountInit.assigner);
|
|
426
|
+
await bindish(within, { assigner: this.#mountInit.assigner });
|
|
427
427
|
await this.composeFragment(within, 0);
|
|
428
428
|
const match = await this.#selector();
|
|
429
429
|
const els = Array.from(within.querySelectorAll(match));
|
|
430
430
|
this.#filterAndMount(els, false, initializing);
|
|
431
431
|
}
|
|
432
432
|
}
|
|
433
|
+
export function waitForIdleNodes(nodes) {
|
|
434
|
+
return new Promise((resolve) => {
|
|
435
|
+
const mutObservers = [];
|
|
436
|
+
for (const node of nodes) {
|
|
437
|
+
const mutObs = mutationObserverLookup.get(node);
|
|
438
|
+
if (mutObs !== undefined) {
|
|
439
|
+
mutObservers.push(mutObs);
|
|
440
|
+
}
|
|
441
|
+
else {
|
|
442
|
+
const currentCount = refCount.get(node) || 0;
|
|
443
|
+
const newMutObs = new RootMutObs(node);
|
|
444
|
+
mutationObserverLookup.set(node, newMutObs);
|
|
445
|
+
refCount.set(node, currentCount + 1);
|
|
446
|
+
mutObservers.push(newMutObs);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (areAllIdle(mutObservers)) {
|
|
450
|
+
resolve();
|
|
451
|
+
}
|
|
452
|
+
for (const obs of mutObservers) {
|
|
453
|
+
obs.addEventListener('is-idle', () => {
|
|
454
|
+
if (areAllIdle(mutObservers)) {
|
|
455
|
+
resolve();
|
|
456
|
+
}
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
}
|
|
461
|
+
function areAllIdle(mutObs) {
|
|
462
|
+
for (const mo of mutObs) {
|
|
463
|
+
if (!mo.isIdle)
|
|
464
|
+
return false;
|
|
465
|
+
}
|
|
466
|
+
return true;
|
|
467
|
+
}
|
|
433
468
|
const refCountErr = 'mount-observer ref count mismatch';
|
|
434
469
|
export const inclTemplQry = 'template[src^="#"]:not([hidden])';
|
|
435
470
|
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
package/MountObserver.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {bindish, bindishIt} from './bindish.js';
|
|
|
11
11
|
export {MOSE} from './ts-refs/mount-observer/types';
|
|
12
12
|
export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
|
|
13
13
|
|
|
14
|
-
const mutationObserverLookup = new WeakMap<Node, RootMutObs>();
|
|
14
|
+
export const mutationObserverLookup = new WeakMap<Node, RootMutObs>();
|
|
15
15
|
const refCount = new WeakMap<Node, number>();
|
|
16
16
|
export class MountObserver extends EventTarget implements IMountObserver{
|
|
17
17
|
|
|
@@ -437,12 +437,12 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
}
|
|
440
|
-
await bindishIt(els, assigner);
|
|
440
|
+
await bindishIt(els, {assigner});
|
|
441
441
|
this.#mount(elsToMount, initializing);
|
|
442
442
|
}
|
|
443
443
|
|
|
444
444
|
async #inspectWithin(within: Node, initializing: boolean){
|
|
445
|
-
await bindish(within as DocumentFragment, this.#mountInit.assigner);
|
|
445
|
+
await bindish(within as DocumentFragment, {assigner: this.#mountInit.assigner});
|
|
446
446
|
await this.composeFragment(within as DocumentFragment, 0);
|
|
447
447
|
const match = await this.#selector();
|
|
448
448
|
const els = Array.from((within as Element).querySelectorAll(match));
|
|
@@ -451,6 +451,40 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
451
451
|
|
|
452
452
|
}
|
|
453
453
|
|
|
454
|
+
export function waitForIdleNodes(nodes: Array<Node>): Promise<void>{
|
|
455
|
+
return new Promise((resolve) => {
|
|
456
|
+
const mutObservers: Array<RootMutObs> = [];
|
|
457
|
+
for(const node of nodes){
|
|
458
|
+
const mutObs = mutationObserverLookup.get(node);
|
|
459
|
+
if(mutObs !== undefined){
|
|
460
|
+
mutObservers.push(mutObs);
|
|
461
|
+
}else{
|
|
462
|
+
const currentCount = refCount.get(node) || 0;
|
|
463
|
+
const newMutObs = new RootMutObs(node);
|
|
464
|
+
mutationObserverLookup.set(node, newMutObs);
|
|
465
|
+
refCount.set(node, currentCount + 1);
|
|
466
|
+
mutObservers.push(newMutObs);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if(areAllIdle(mutObservers)){
|
|
470
|
+
resolve();
|
|
471
|
+
}
|
|
472
|
+
for(const obs of mutObservers){
|
|
473
|
+
obs.addEventListener('is-idle', () => {
|
|
474
|
+
if(areAllIdle(mutObservers)){
|
|
475
|
+
resolve();
|
|
476
|
+
}
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
function areAllIdle(mutObs: Array<RootMutObs>){
|
|
483
|
+
for(const mo of mutObs){
|
|
484
|
+
if(!mo.isIdle) return false;
|
|
485
|
+
}
|
|
486
|
+
return true;
|
|
487
|
+
}
|
|
454
488
|
|
|
455
489
|
|
|
456
490
|
const refCountErr = 'mount-observer ref count mismatch';
|
package/Newish.js
CHANGED
|
@@ -1,74 +1,87 @@
|
|
|
1
1
|
export { waitForEvent } from './waitForEvent.js';
|
|
2
|
+
import { ObsAttr } from './ObsAttr.js';
|
|
3
|
+
export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
|
|
2
4
|
export class Newish {
|
|
3
5
|
queue = [];
|
|
4
6
|
isResolved = false;
|
|
5
7
|
#ce;
|
|
6
|
-
#
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
#ref;
|
|
9
|
+
//#assigner: undefined | Assigner = undefined;
|
|
10
|
+
#options;
|
|
11
|
+
constructor(enhancedElement, itemscope, options) {
|
|
12
|
+
this.#options = options || { assigner: Object.assign };
|
|
13
|
+
this.#ref = new WeakRef(enhancedElement);
|
|
9
14
|
this.#do(enhancedElement, itemscope);
|
|
10
15
|
}
|
|
16
|
+
handleEvent(event) {
|
|
17
|
+
const enhancedElement = this.#ref.deref();
|
|
18
|
+
if (!enhancedElement)
|
|
19
|
+
return;
|
|
20
|
+
this.#attachItemrefs(enhancedElement);
|
|
21
|
+
}
|
|
11
22
|
async #do(enhancedElement, itemscope) {
|
|
12
|
-
|
|
23
|
+
if (enhancedElement[attached] === true)
|
|
24
|
+
return;
|
|
25
|
+
enhancedElement[attached] = true;
|
|
13
26
|
await customElements.whenDefined(itemscope);
|
|
14
27
|
const initPropVals = enhancedElement['ish'];
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
|
|
20
|
-
this.queue.push(parsedHostProps);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (initPropVals !== undefined)
|
|
24
|
-
this.queue.push(initPropVals);
|
|
25
|
-
const ce = document.createElement(itemscope);
|
|
26
|
-
if ('attachedCallback' in ce && typeof ce.attachedCallback === 'function') {
|
|
27
|
-
await ce.attachedCallback(enhancedElement);
|
|
28
|
+
if (enhancedElement instanceof HTMLElement) {
|
|
29
|
+
if (enhancedElement.dataset.ish) {
|
|
30
|
+
const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
|
|
31
|
+
this.queue.push(parsedHostProps);
|
|
28
32
|
}
|
|
29
|
-
this.#ce = ce;
|
|
30
|
-
const self = this;
|
|
31
|
-
Object.defineProperty(enhancedElement, 'ish', {
|
|
32
|
-
get() {
|
|
33
|
-
return self.#ce;
|
|
34
|
-
},
|
|
35
|
-
set(nv) {
|
|
36
|
-
self.queue.push(nv);
|
|
37
|
-
self.#assignGingerly();
|
|
38
|
-
},
|
|
39
|
-
enumerable: true,
|
|
40
|
-
configurable: true,
|
|
41
|
-
});
|
|
42
|
-
this.#assignGingerly();
|
|
43
33
|
}
|
|
34
|
+
if (initPropVals !== undefined)
|
|
35
|
+
this.queue.push(initPropVals);
|
|
36
|
+
const ce = document.createElement(itemscope);
|
|
37
|
+
if ('attachedCallback' in ce && typeof ce.attachedCallback === 'function') {
|
|
38
|
+
await ce.attachedCallback(enhancedElement);
|
|
39
|
+
}
|
|
40
|
+
this.#ce = ce;
|
|
41
|
+
const self = this;
|
|
42
|
+
Object.defineProperty(enhancedElement, 'ish', {
|
|
43
|
+
get() {
|
|
44
|
+
return self.#ce;
|
|
45
|
+
},
|
|
46
|
+
set(nv) {
|
|
47
|
+
self.queue.push(nv);
|
|
48
|
+
self.#assignGingerly();
|
|
49
|
+
},
|
|
50
|
+
enumerable: true,
|
|
51
|
+
configurable: true,
|
|
52
|
+
});
|
|
53
|
+
this.#assignGingerly();
|
|
44
54
|
//attach any itemref references
|
|
55
|
+
this.#attachItemrefs(enhancedElement);
|
|
56
|
+
const et = ObsAttr(enhancedElement, 'itemref');
|
|
57
|
+
et.addEventListener('attr-changed', this);
|
|
58
|
+
this.isResolved = true;
|
|
59
|
+
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
60
|
+
}
|
|
61
|
+
#alreadyAttached = new Set();
|
|
62
|
+
#attachItemrefs(enhancedElement) {
|
|
63
|
+
//TODO: watch for already attached itemrefs to be removed and remove them from the set
|
|
64
|
+
// and call outOfScopeCallback on them
|
|
45
65
|
if (enhancedElement.hasAttribute('itemref')) {
|
|
46
66
|
const itemref = enhancedElement.getAttribute('itemref');
|
|
47
67
|
const itemrefList = itemref.split(' ');
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
68
|
+
const rn = enhancedElement.getRootNode();
|
|
69
|
+
for (const id of itemrefList) {
|
|
70
|
+
if (this.#alreadyAttached.has(id))
|
|
71
|
+
continue;
|
|
72
|
+
const itemrefElement = rn.getElementById(id);
|
|
73
|
+
if (itemrefElement) {
|
|
74
|
+
this.#ce.inScopeCallback(itemrefElement);
|
|
75
|
+
this.#alreadyAttached.add(id);
|
|
53
76
|
}
|
|
54
|
-
if (itemrefList.length === 0)
|
|
55
|
-
break;
|
|
56
|
-
nextSibling = nextSibling.nextElementSibling;
|
|
57
|
-
}
|
|
58
|
-
if (itemrefList.length > 0) {
|
|
59
|
-
//TODO add an observer queue for the id found elsewhere
|
|
60
|
-
throw 'NI';
|
|
61
77
|
}
|
|
62
78
|
}
|
|
63
|
-
this.isResolved = true;
|
|
64
|
-
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
65
79
|
}
|
|
66
80
|
async #assignGingerly() {
|
|
67
81
|
let ce = this.#ce;
|
|
68
82
|
if (ce === undefined) {
|
|
69
83
|
throw 500;
|
|
70
84
|
}
|
|
71
|
-
//const {assignGingerly} = await import('../lib/assignGingerly.js');
|
|
72
85
|
while (this.queue.length > 0) {
|
|
73
86
|
const fi = this.queue.shift();
|
|
74
87
|
//TODO: Provide support for a virtual slice of a very large list
|
|
@@ -76,12 +89,8 @@ export class Newish {
|
|
|
76
89
|
ce.$ = fi;
|
|
77
90
|
}
|
|
78
91
|
else {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
Object.assign(ce, fi);
|
|
84
|
-
}
|
|
92
|
+
const { assigner } = this.#options;
|
|
93
|
+
await assigner(ce, fi);
|
|
85
94
|
}
|
|
86
95
|
}
|
|
87
96
|
}
|
package/Newish.ts
CHANGED
|
@@ -1,70 +1,87 @@
|
|
|
1
|
-
import { Assigner } from './ts-refs/mount-observer/types.js';
|
|
1
|
+
import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
|
|
2
2
|
|
|
3
3
|
export {waitForEvent} from './waitForEvent.js';
|
|
4
|
-
|
|
4
|
+
import {ObsAttr} from './ObsAttr.js';
|
|
5
|
+
export const attached = Symbol.for('xyyspnstnU+CDrNVa0VnxA');
|
|
6
|
+
export class Newish implements EventListenerObject {
|
|
5
7
|
queue: Array<any> = [];
|
|
6
8
|
isResolved = false;
|
|
7
9
|
#ce: HTMLElement | undefined;
|
|
10
|
+
#ref: WeakRef<Element>;
|
|
8
11
|
|
|
9
|
-
|
|
12
|
+
//#assigner: undefined | Assigner = undefined;
|
|
13
|
+
#options: BindishOptions;
|
|
10
14
|
|
|
11
|
-
constructor(enhancedElement: Element, itemscope: string,
|
|
12
|
-
this.#
|
|
15
|
+
constructor(enhancedElement: Element, itemscope: string, options?: BindishOptions){
|
|
16
|
+
this.#options = options || {assigner: Object.assign};
|
|
17
|
+
this.#ref = new WeakRef(enhancedElement);
|
|
13
18
|
this.#do(enhancedElement, itemscope);
|
|
14
19
|
}
|
|
20
|
+
handleEvent(event: Event): void {
|
|
21
|
+
const enhancedElement = this.#ref.deref();
|
|
22
|
+
if(!enhancedElement) return;
|
|
23
|
+
this.#attachItemrefs(enhancedElement);
|
|
24
|
+
}
|
|
15
25
|
|
|
16
26
|
async #do(enhancedElement: Element, itemscope: string){
|
|
17
|
-
|
|
27
|
+
if((<any>enhancedElement)[attached] === true) return;
|
|
28
|
+
(<any>enhancedElement)[attached] = true;
|
|
18
29
|
await customElements.whenDefined(itemscope);
|
|
19
30
|
const initPropVals = (<any>enhancedElement)['ish'];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
|
|
25
|
-
this.queue.push(parsedHostProps);
|
|
26
|
-
}
|
|
31
|
+
if(enhancedElement instanceof HTMLElement){
|
|
32
|
+
if(enhancedElement.dataset.ish){
|
|
33
|
+
const parsedHostProps = JSON.parse(enhancedElement.dataset.ish);
|
|
34
|
+
this.queue.push(parsedHostProps);
|
|
27
35
|
}
|
|
28
|
-
if(initPropVals !== undefined) this.queue.push(initPropVals);
|
|
29
|
-
const ce = document.createElement(itemscope);
|
|
30
|
-
if('attachedCallback' in ce && typeof ce.attachedCallback === 'function'){
|
|
31
|
-
await ce.attachedCallback(enhancedElement)
|
|
32
|
-
}
|
|
33
|
-
this.#ce = ce;
|
|
34
|
-
const self = this;
|
|
35
|
-
Object.defineProperty(enhancedElement, 'ish', {
|
|
36
|
-
get(){
|
|
37
|
-
return self.#ce;
|
|
38
|
-
},
|
|
39
|
-
set(nv: any){
|
|
40
|
-
self.queue.push(nv);
|
|
41
|
-
self.#assignGingerly();
|
|
42
|
-
},
|
|
43
|
-
enumerable: true,
|
|
44
|
-
configurable: true,
|
|
45
|
-
});
|
|
46
|
-
this.#assignGingerly();
|
|
47
36
|
}
|
|
37
|
+
if(initPropVals !== undefined) this.queue.push(initPropVals);
|
|
38
|
+
const ce = document.createElement(itemscope);
|
|
39
|
+
if('attachedCallback' in ce && typeof ce.attachedCallback === 'function'){
|
|
40
|
+
await ce.attachedCallback(enhancedElement)
|
|
41
|
+
}
|
|
42
|
+
this.#ce = ce;
|
|
43
|
+
const self = this;
|
|
44
|
+
Object.defineProperty(enhancedElement, 'ish', {
|
|
45
|
+
get(){
|
|
46
|
+
return self.#ce;
|
|
47
|
+
},
|
|
48
|
+
set(nv: any){
|
|
49
|
+
self.queue.push(nv);
|
|
50
|
+
self.#assignGingerly();
|
|
51
|
+
},
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
});
|
|
55
|
+
this.#assignGingerly();
|
|
48
56
|
//attach any itemref references
|
|
57
|
+
this.#attachItemrefs(enhancedElement);
|
|
58
|
+
const et = ObsAttr(enhancedElement, 'itemref');
|
|
59
|
+
et.addEventListener('attr-changed', this);
|
|
60
|
+
this.isResolved = true;
|
|
61
|
+
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
#alreadyAttached = new Set<string>();
|
|
67
|
+
|
|
68
|
+
#attachItemrefs(enhancedElement: Element){
|
|
69
|
+
//TODO: watch for already attached itemrefs to be removed and remove them from the set
|
|
70
|
+
// and call outOfScopeCallback on them
|
|
49
71
|
if(enhancedElement.hasAttribute('itemref')){
|
|
50
72
|
const itemref = enhancedElement.getAttribute('itemref')!;
|
|
51
73
|
const itemrefList = itemref.split(' ');
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if(
|
|
55
|
-
|
|
56
|
-
|
|
74
|
+
const rn = enhancedElement.getRootNode() as Document | ShadowRoot;
|
|
75
|
+
for(const id of itemrefList){
|
|
76
|
+
if(this.#alreadyAttached.has(id)) continue;
|
|
77
|
+
const itemrefElement = rn.getElementById(id);
|
|
78
|
+
if(itemrefElement){
|
|
79
|
+
(<any>this.#ce).inScopeCallback(itemrefElement);
|
|
80
|
+
this.#alreadyAttached.add(id);
|
|
57
81
|
}
|
|
58
|
-
if(itemrefList.length === 0) break;
|
|
59
|
-
nextSibling = nextSibling.nextElementSibling;
|
|
60
|
-
}
|
|
61
|
-
if(itemrefList.length > 0){
|
|
62
|
-
//TODO add an observer queue for the id found elsewhere
|
|
63
|
-
throw 'NI';
|
|
64
82
|
}
|
|
65
83
|
}
|
|
66
|
-
|
|
67
|
-
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
84
|
+
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
async #assignGingerly(){
|
|
@@ -72,18 +89,15 @@ export class Newish{
|
|
|
72
89
|
if(ce === undefined){
|
|
73
90
|
throw 500;
|
|
74
91
|
}
|
|
75
|
-
//const {assignGingerly} = await import('../lib/assignGingerly.js');
|
|
76
92
|
while(this.queue.length > 0 ){
|
|
77
93
|
const fi = this.queue.shift();
|
|
78
94
|
//TODO: Provide support for a virtual slice of a very large list
|
|
79
95
|
if(Array.isArray(fi)){
|
|
80
96
|
(<any>ce).$ = fi;
|
|
81
97
|
}else{
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
Object.assign(ce, fi);
|
|
86
|
-
}
|
|
98
|
+
const {assigner} = this.#options;
|
|
99
|
+
await assigner!(ce, fi);
|
|
100
|
+
|
|
87
101
|
}
|
|
88
102
|
|
|
89
103
|
}
|
package/ObsAttr.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function ObsAttr(element, attr) {
|
|
2
|
+
const eventTarget = new EventTarget();
|
|
3
|
+
const obs = new MutationObserver((mutations) => {
|
|
4
|
+
eventTarget.dispatchEvent(new Event('attr-changed'));
|
|
5
|
+
// for(const mutation of mutations){
|
|
6
|
+
// if(mutation.type === 'attributes' && mutation.attributeName === attr){
|
|
7
|
+
// obs.disconnect();
|
|
8
|
+
// eventTarget.dispatchEvent(new Event('obsAttr'));
|
|
9
|
+
// break;
|
|
10
|
+
// }
|
|
11
|
+
// }
|
|
12
|
+
});
|
|
13
|
+
obs.observe(element, {
|
|
14
|
+
attributes: true,
|
|
15
|
+
attributeFilter: [attr],
|
|
16
|
+
});
|
|
17
|
+
return eventTarget;
|
|
18
|
+
}
|
package/ObsAttr.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function ObsAttr(element: Element, attr: string): EventTarget{
|
|
2
|
+
const eventTarget = new EventTarget();
|
|
3
|
+
const obs = new MutationObserver((mutations) => {
|
|
4
|
+
eventTarget.dispatchEvent(new Event('attr-changed'));
|
|
5
|
+
// for(const mutation of mutations){
|
|
6
|
+
// if(mutation.type === 'attributes' && mutation.attributeName === attr){
|
|
7
|
+
// obs.disconnect();
|
|
8
|
+
// eventTarget.dispatchEvent(new Event('obsAttr'));
|
|
9
|
+
// break;
|
|
10
|
+
// }
|
|
11
|
+
// }
|
|
12
|
+
});
|
|
13
|
+
obs.observe(element, {
|
|
14
|
+
attributes: true,
|
|
15
|
+
attributeFilter: [attr],
|
|
16
|
+
});
|
|
17
|
+
return eventTarget;
|
|
18
|
+
}
|
package/RootMutObs.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
export class RootMutObs extends EventTarget {
|
|
2
|
+
#idleTimeout = 20; //TODO: make this configurable
|
|
3
|
+
#idlePointer = 0;
|
|
2
4
|
constructor(rootNode) {
|
|
3
5
|
super();
|
|
4
6
|
this.#mutationObserver = new MutationObserver(mutationRecords => {
|
|
5
7
|
this.dispatchEvent(new MutationEvent(mutationRecords));
|
|
8
|
+
this.#triggerIsIdle();
|
|
6
9
|
});
|
|
7
10
|
this.#mutationObserver.observe(rootNode, {
|
|
8
11
|
subtree: true,
|
|
@@ -10,6 +13,19 @@ export class RootMutObs extends EventTarget {
|
|
|
10
13
|
attributes: true,
|
|
11
14
|
attributeOldValue: true,
|
|
12
15
|
});
|
|
16
|
+
this.#triggerIsIdle();
|
|
17
|
+
}
|
|
18
|
+
#isIdle = false;
|
|
19
|
+
get isIdle() {
|
|
20
|
+
return this.#isIdle;
|
|
21
|
+
}
|
|
22
|
+
#triggerIsIdle() {
|
|
23
|
+
this.#isIdle = false;
|
|
24
|
+
clearTimeout(this.#idlePointer);
|
|
25
|
+
this.#idlePointer = setTimeout(() => {
|
|
26
|
+
this.#isIdle = true;
|
|
27
|
+
this.dispatchEvent(new Event('is-idle'));
|
|
28
|
+
}, this.#idleTimeout);
|
|
13
29
|
}
|
|
14
30
|
#mutationObserver;
|
|
15
31
|
disconnect() {
|
package/RootMutObs.ts
CHANGED
|
@@ -1,17 +1,34 @@
|
|
|
1
1
|
import {mutationEventName, AddMutationEventListener} from './ts-refs/mount-observer/types';
|
|
2
2
|
|
|
3
3
|
export class RootMutObs extends EventTarget{
|
|
4
|
+
#idleTimeout = 20; //TODO: make this configurable
|
|
5
|
+
#idlePointer = 0;
|
|
4
6
|
constructor(rootNode: Node ){
|
|
5
7
|
super();
|
|
8
|
+
|
|
6
9
|
this.#mutationObserver = new MutationObserver(mutationRecords => {
|
|
7
|
-
this.dispatchEvent(new MutationEvent(mutationRecords))
|
|
8
|
-
|
|
10
|
+
this.dispatchEvent(new MutationEvent(mutationRecords));
|
|
11
|
+
this.#triggerIsIdle();
|
|
12
|
+
});
|
|
9
13
|
this.#mutationObserver.observe(rootNode, {
|
|
10
14
|
subtree: true,
|
|
11
15
|
childList: true,
|
|
12
16
|
attributes: true,
|
|
13
17
|
attributeOldValue: true,
|
|
14
18
|
});
|
|
19
|
+
this.#triggerIsIdle();
|
|
20
|
+
}
|
|
21
|
+
#isIdle = false;
|
|
22
|
+
get isIdle(){
|
|
23
|
+
return this.#isIdle;
|
|
24
|
+
}
|
|
25
|
+
#triggerIsIdle(){
|
|
26
|
+
this.#isIdle = false;
|
|
27
|
+
clearTimeout(this.#idlePointer);
|
|
28
|
+
this.#idlePointer = setTimeout(()=>{
|
|
29
|
+
this.#isIdle = true;
|
|
30
|
+
this.dispatchEvent(new Event('is-idle'));
|
|
31
|
+
}, this.#idleTimeout)
|
|
15
32
|
}
|
|
16
33
|
#mutationObserver: MutationObserver;
|
|
17
34
|
disconnect(){
|
|
@@ -38,3 +55,4 @@ export class MutationEvent extends Event implements MutationEvent {
|
|
|
38
55
|
|
|
39
56
|
|
|
40
57
|
|
|
58
|
+
|
package/bindish.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export const itemscopeQry = '[itemscope*="-"]';
|
|
2
|
-
export async function bindish(fragment,
|
|
2
|
+
export async function bindish(fragment, options) {
|
|
3
3
|
const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
|
|
4
|
-
await bindishIt(scopes,
|
|
4
|
+
await bindishIt(scopes, options);
|
|
5
5
|
}
|
|
6
|
-
export async function bindishIt(scopes,
|
|
6
|
+
export async function bindishIt(scopes, options) {
|
|
7
7
|
for (const scope of scopes) {
|
|
8
8
|
const itemscope = scope.getAttribute('itemscope');
|
|
9
9
|
if (itemscope && itemscope.includes('-') && !(scope.ish instanceof HTMLElement)) {
|
|
10
10
|
const { Newish } = await import('./Newish.js');
|
|
11
|
-
new Newish(scope, itemscope,
|
|
11
|
+
new Newish(scope, itemscope, options);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
package/bindish.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { Assigner } from './ts-refs/mount-observer/types.js';
|
|
1
|
+
import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
|
|
2
2
|
|
|
3
3
|
export const itemscopeQry = '[itemscope*="-"]';
|
|
4
|
-
export async function bindish(fragment: DocumentFragment,
|
|
4
|
+
export async function bindish(fragment: DocumentFragment, options?: BindishOptions){
|
|
5
5
|
const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
|
|
6
|
-
await bindishIt(scopes,
|
|
6
|
+
await bindishIt(scopes, options);
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export async function bindishIt(scopes: Array<Element>,
|
|
9
|
+
export async function bindishIt(scopes: Array<Element>, options?: BindishOptions){
|
|
10
10
|
for(const scope of scopes){
|
|
11
11
|
const itemscope = scope.getAttribute('itemscope');
|
|
12
12
|
if(itemscope && itemscope.includes('-') && !((<any>scope).ish instanceof HTMLElement)){
|
|
13
13
|
const {Newish} = await import('./Newish.js');
|
|
14
|
-
new Newish(scope, itemscope,
|
|
14
|
+
new Newish(scope, itemscope, options);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.54",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
@@ -21,6 +21,10 @@
|
|
|
21
21
|
"default": "./Newish.js",
|
|
22
22
|
"types": "./Newish.ts"
|
|
23
23
|
},
|
|
24
|
+
"./ObsAttr.js": {
|
|
25
|
+
"default": "./ObsAttr.js",
|
|
26
|
+
"types": "./ObsAttr.ts"
|
|
27
|
+
},
|
|
24
28
|
"./Synthesizer.js": {
|
|
25
29
|
"default": "./Synthesizer.js",
|
|
26
30
|
"types": "./Synthesizer.ts"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import {IEnhancement, BEAllProps} from '../trans-render/be/types';
|
|
2
|
+
|
|
3
|
+
export interface EndUserProps extends IEnhancement{
|
|
4
|
+
names: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export interface AllProps extends EndUserProps{
|
|
8
|
+
parsedNames: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type AP = AllProps;
|
|
12
|
+
|
|
13
|
+
export type PAP = Partial<AP>;
|
|
14
|
+
|
|
15
|
+
export type ProPAP = Promise<PAP>;
|
|
16
|
+
|
|
17
|
+
export type BAP = AP & BEAllProps;
|
|
18
|
+
|
|
19
|
+
export interface Actions{
|
|
20
|
+
parse(self: BAP): PAP;
|
|
21
|
+
hydrate(self: BAP): ProPAP;
|
|
22
|
+
retire(self: BAP): void;
|
|
23
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//import { MountObserver } from "./MountObserver";
|
|
2
1
|
|
|
3
2
|
export interface JSONSerializableMountInit{
|
|
4
3
|
readonly on?: CSSMatch,
|
|
@@ -208,6 +207,11 @@ export interface MOSE<TSynConfig=any>
|
|
|
208
207
|
|
|
209
208
|
}
|
|
210
209
|
|
|
210
|
+
export interface BindishOptions{
|
|
211
|
+
assigner?: Assigner,
|
|
212
|
+
waitFor?: string,
|
|
213
|
+
}
|
|
214
|
+
|
|
211
215
|
//#endregion
|
|
212
216
|
|
|
213
217
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IMountObserver } from '../../mount-observer/types';
|
|
2
2
|
import { Scope} from '../lib/types';
|
|
3
3
|
import { WrapperConfig } from '../XV/types';
|
|
4
|
-
import {XForm} from '../types';
|
|
4
|
+
import {CSSQuery, XForm} from '../types';
|
|
5
5
|
|
|
6
6
|
export interface IEventConfig<MCProps = any, MCActions = MCProps, TAction = Action>{
|
|
7
7
|
on?: string,
|
|
@@ -189,7 +189,7 @@ export interface IshConfig<TProps = any, TActions = TProps, ETProps = TProps>{
|
|
|
189
189
|
|
|
190
190
|
isSleepless?: boolean;
|
|
191
191
|
xform?: XForm<TProps, TActions>;
|
|
192
|
-
inScopeXForms?:
|
|
192
|
+
inScopeXForms?: {[key: CSSQuery]: XForm<TProps, TActions>};
|
|
193
193
|
}
|
|
194
194
|
export interface OConfig<TProps = any, TActions = TProps, ETProps = TProps> extends IshConfig<TProps, TActions, ETProps>{
|
|
195
195
|
mainTemplate?: string | HTMLTemplateElement;
|