mount-observer 0.0.59 → 0.0.61
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 +6 -6
- package/MountObserver.ts +6 -6
- package/Newish.js +4 -4
- package/Newish.ts +10 -4
- package/bindish.js +4 -4
- package/bindish.ts +8 -4
- package/package.json +1 -1
- package/refid/getIsh.js +15 -4
- package/refid/getIsh.ts +16 -4
- package/refid/regIsh.js +3 -1
- package/refid/regIsh.ts +3 -1
- package/ts-refs/trans-render/types.d.ts +1 -1
package/MountObserver.js
CHANGED
|
@@ -219,7 +219,7 @@ export class MountObserver extends EventTarget {
|
|
|
219
219
|
this.dispatchEvent(new AttrChangeEvent(key, value));
|
|
220
220
|
}
|
|
221
221
|
}
|
|
222
|
-
this.#filterAndMount(elsToInspect, true, false);
|
|
222
|
+
this.#filterAndMount(elsToInspect, within, true, false);
|
|
223
223
|
for (const el of elsToInspect) {
|
|
224
224
|
await this.#inspectWithin(el, false);
|
|
225
225
|
}
|
|
@@ -371,7 +371,7 @@ export class MountObserver extends EventTarget {
|
|
|
371
371
|
const { whereSatisfies, whereInstanceOf } = this.#mountInit;
|
|
372
372
|
const match = await this.#selector();
|
|
373
373
|
const els = Array.from(document.querySelectorAll(match));
|
|
374
|
-
this.#filterAndMount(els, false, true);
|
|
374
|
+
this.#filterAndMount(els, document.body, false, true);
|
|
375
375
|
}
|
|
376
376
|
async #filterAndDismount() {
|
|
377
377
|
const returnSet = new Set();
|
|
@@ -396,7 +396,7 @@ export class MountObserver extends EventTarget {
|
|
|
396
396
|
this.#mountedList = Array.from(returnSet).map(x => new WeakRef(x));
|
|
397
397
|
return returnSet;
|
|
398
398
|
}
|
|
399
|
-
async #filterAndMount(els, checkMatch, initializing) {
|
|
399
|
+
async #filterAndMount(els, target, checkMatch, initializing) {
|
|
400
400
|
const { whereSatisfies, whereInstanceOf, assigner } = this.#mountInit;
|
|
401
401
|
const match = await this.#selector();
|
|
402
402
|
const elsToMount = els.filter(x => {
|
|
@@ -419,15 +419,15 @@ 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, target, { assigner });
|
|
423
423
|
this.#mount(elsToMount, initializing);
|
|
424
424
|
}
|
|
425
425
|
async #inspectWithin(within, initializing) {
|
|
426
|
-
await bindish(within, { assigner: this.#mountInit.assigner });
|
|
426
|
+
await bindish(within, 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
|
-
this.#filterAndMount(els, false, initializing);
|
|
430
|
+
this.#filterAndMount(els, within, false, initializing);
|
|
431
431
|
}
|
|
432
432
|
}
|
|
433
433
|
export function waitForIdleNodes(nodes, idleTimeout) {
|
package/MountObserver.ts
CHANGED
|
@@ -234,7 +234,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
234
234
|
this.dispatchEvent(new AttrChangeEvent(key, value))
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
-
this.#filterAndMount(elsToInspect, true, false);
|
|
237
|
+
this.#filterAndMount(elsToInspect, within, true, false);
|
|
238
238
|
for(const el of elsToInspect){
|
|
239
239
|
await this.#inspectWithin(el, false);
|
|
240
240
|
}
|
|
@@ -392,7 +392,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
392
392
|
const {whereSatisfies, whereInstanceOf} = this.#mountInit;
|
|
393
393
|
const match = await this.#selector();
|
|
394
394
|
const els = Array.from(document.querySelectorAll(match));
|
|
395
|
-
this.#filterAndMount(els, false, true);
|
|
395
|
+
this.#filterAndMount(els, document.body, false, true);
|
|
396
396
|
}
|
|
397
397
|
|
|
398
398
|
async #filterAndDismount(): Promise<Set<Element>>{
|
|
@@ -416,7 +416,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
416
416
|
return returnSet;
|
|
417
417
|
}
|
|
418
418
|
|
|
419
|
-
async #filterAndMount(els: Array<Element>, checkMatch: boolean, initializing: boolean){
|
|
419
|
+
async #filterAndMount(els: Array<Element>, target: Node, checkMatch: boolean, initializing: boolean){
|
|
420
420
|
const {whereSatisfies, whereInstanceOf, assigner} = this.#mountInit;
|
|
421
421
|
const match = await this.#selector();
|
|
422
422
|
const elsToMount = els.filter(x => {
|
|
@@ -437,16 +437,16 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
437
437
|
}
|
|
438
438
|
|
|
439
439
|
}
|
|
440
|
-
await bindishIt(els, {assigner});
|
|
440
|
+
await bindishIt(els, target, {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, {assigner: this.#mountInit.assigner});
|
|
445
|
+
await bindish(within as DocumentFragment, within, {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));
|
|
449
|
-
this.#filterAndMount(els, false, initializing);
|
|
449
|
+
this.#filterAndMount(els, within, false, initializing);
|
|
450
450
|
}
|
|
451
451
|
|
|
452
452
|
}
|
package/Newish.js
CHANGED
|
@@ -10,10 +10,10 @@ export class Newish {
|
|
|
10
10
|
#ref;
|
|
11
11
|
//#assigner: undefined | Assigner = undefined;
|
|
12
12
|
#options;
|
|
13
|
-
constructor(enhancedElement, itemscope, options) {
|
|
13
|
+
constructor(enhancedElement, target, itemscope, options) {
|
|
14
14
|
this.#options = options || { assigner: Object.assign };
|
|
15
15
|
this.#ref = new WeakRef(enhancedElement);
|
|
16
|
-
this.#do(enhancedElement, itemscope);
|
|
16
|
+
this.#do(enhancedElement, target, itemscope);
|
|
17
17
|
}
|
|
18
18
|
handleEvent(event) {
|
|
19
19
|
const enhancedElement = this.#ref.deref();
|
|
@@ -21,11 +21,11 @@ export class Newish {
|
|
|
21
21
|
return;
|
|
22
22
|
this.#attachItemrefs(enhancedElement);
|
|
23
23
|
}
|
|
24
|
-
async #do(enhancedElement, itemscope) {
|
|
24
|
+
async #do(enhancedElement, target, itemscope) {
|
|
25
25
|
if (enhancedElement[attached] === true)
|
|
26
26
|
return;
|
|
27
27
|
enhancedElement[attached] = true;
|
|
28
|
-
const ctr = getIsh(enhancedElement, itemscope);
|
|
28
|
+
const ctr = await getIsh(enhancedElement.isConnected ? enhancedElement : target, itemscope);
|
|
29
29
|
const initPropVals = enhancedElement['ish'];
|
|
30
30
|
if (enhancedElement instanceof HTMLElement) {
|
|
31
31
|
if (enhancedElement.dataset.ish) {
|
package/Newish.ts
CHANGED
|
@@ -14,10 +14,12 @@ export class Newish implements EventListenerObject {
|
|
|
14
14
|
//#assigner: undefined | Assigner = undefined;
|
|
15
15
|
#options: BindishOptions;
|
|
16
16
|
|
|
17
|
-
constructor(enhancedElement: Element,
|
|
17
|
+
constructor(enhancedElement: Element,
|
|
18
|
+
target: Node,
|
|
19
|
+
itemscope: string, options?: BindishOptions){
|
|
18
20
|
this.#options = options || {assigner: Object.assign};
|
|
19
21
|
this.#ref = new WeakRef(enhancedElement);
|
|
20
|
-
this.#do(enhancedElement, itemscope);
|
|
22
|
+
this.#do(enhancedElement, target, itemscope);
|
|
21
23
|
}
|
|
22
24
|
handleEvent(event: Event): void {
|
|
23
25
|
const enhancedElement = this.#ref.deref();
|
|
@@ -25,10 +27,14 @@ export class Newish implements EventListenerObject {
|
|
|
25
27
|
this.#attachItemrefs(enhancedElement);
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
async #do(
|
|
30
|
+
async #do(
|
|
31
|
+
enhancedElement: Element,
|
|
32
|
+
target: Node,
|
|
33
|
+
itemscope: string
|
|
34
|
+
){
|
|
29
35
|
if((<any>enhancedElement)[attached] === true) return;
|
|
30
36
|
(<any>enhancedElement)[attached] = true;
|
|
31
|
-
const ctr = getIsh(enhancedElement, itemscope)! as any;
|
|
37
|
+
const ctr = await getIsh(enhancedElement.isConnected ? enhancedElement :target, itemscope)! as any;
|
|
32
38
|
|
|
33
39
|
const initPropVals = (<any>enhancedElement)['ish'];
|
|
34
40
|
if(enhancedElement instanceof HTMLElement){
|
package/bindish.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export const itemscopeQry = '[itemscope]:not([itemscope=""])';
|
|
2
|
-
export async function bindish(fragment, options) {
|
|
2
|
+
export async function bindish(fragment, target, options) {
|
|
3
3
|
const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
|
|
4
|
-
await bindishIt(scopes, options);
|
|
4
|
+
await bindishIt(scopes, target, options);
|
|
5
5
|
}
|
|
6
|
-
export async function bindishIt(scopes, options) {
|
|
6
|
+
export async function bindishIt(scopes, target, options) {
|
|
7
7
|
for (const scope of scopes) {
|
|
8
8
|
const itemscope = scope.getAttribute('itemscope');
|
|
9
9
|
if (itemscope && !(scope.ish instanceof HTMLElement)) {
|
|
10
10
|
const { Newish } = await import('./Newish.js');
|
|
11
|
-
new Newish(scope, itemscope, options);
|
|
11
|
+
new Newish(scope, target, itemscope, options);
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
package/bindish.ts
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import { Assigner, BindishOptions } from './ts-refs/mount-observer/types.js';
|
|
2
2
|
|
|
3
3
|
export const itemscopeQry = '[itemscope]:not([itemscope=""])';
|
|
4
|
-
export async function bindish(
|
|
4
|
+
export async function bindish(
|
|
5
|
+
fragment: DocumentFragment,
|
|
6
|
+
target: Node,
|
|
7
|
+
options?: BindishOptions
|
|
8
|
+
){
|
|
5
9
|
const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
|
|
6
|
-
await bindishIt(scopes, options);
|
|
10
|
+
await bindishIt(scopes, target, options);
|
|
7
11
|
}
|
|
8
12
|
|
|
9
|
-
export async function bindishIt(scopes: Array<Element>, options?: BindishOptions){
|
|
13
|
+
export async function bindishIt(scopes: Array<Element>, target: Node, options?: BindishOptions){
|
|
10
14
|
for(const scope of scopes){
|
|
11
15
|
const itemscope = scope.getAttribute('itemscope');
|
|
12
16
|
if(itemscope && !((<any>scope).ish instanceof HTMLElement)){
|
|
13
17
|
const {Newish} = await import('./Newish.js');
|
|
14
|
-
new Newish(scope, itemscope, options);
|
|
18
|
+
new Newish(scope, target, itemscope, options);
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
21
|
}
|
package/package.json
CHANGED
package/refid/getIsh.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { sym } from './regIsh.js';
|
|
2
|
-
export function getIsh(scope, name) {
|
|
1
|
+
import { sym, guid } from './regIsh.js';
|
|
2
|
+
export async function getIsh(scope, name) {
|
|
3
3
|
let test = scope;
|
|
4
4
|
while (true) {
|
|
5
5
|
const map = test[sym];
|
|
@@ -8,8 +8,9 @@ export function getIsh(scope, name) {
|
|
|
8
8
|
return map.get(name);
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
if (test === document)
|
|
12
|
-
|
|
11
|
+
if (test === document) {
|
|
12
|
+
return await watch(scope, name);
|
|
13
|
+
}
|
|
13
14
|
if (test instanceof ShadowRoot) {
|
|
14
15
|
test = test.host;
|
|
15
16
|
continue;
|
|
@@ -19,6 +20,16 @@ export function getIsh(scope, name) {
|
|
|
19
20
|
test = newTest;
|
|
20
21
|
continue;
|
|
21
22
|
}
|
|
23
|
+
const lastTest = test;
|
|
22
24
|
test = test.getRootNode();
|
|
25
|
+
if (test === lastTest) {
|
|
26
|
+
return await watch(scope, name);
|
|
27
|
+
}
|
|
28
|
+
;
|
|
23
29
|
}
|
|
24
30
|
}
|
|
31
|
+
async function watch(scope, name) {
|
|
32
|
+
const { waitForEvent } = await import('../waitForEvent.js');
|
|
33
|
+
await waitForEvent(document, guid);
|
|
34
|
+
return await getIsh(scope, name);
|
|
35
|
+
}
|
package/refid/getIsh.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import {sym} from './regIsh.js';
|
|
1
|
+
import {sym, guid} from './regIsh.js';
|
|
2
2
|
import {IshCtr} from '../ts-refs/mount-observer/types.js';
|
|
3
|
-
export function getIsh(scope: Element | ShadowRoot | Document, name: string){
|
|
3
|
+
export async function getIsh(scope: Element | ShadowRoot | Document | Node, name: string): Promise<IshCtr>{
|
|
4
4
|
let test = scope as any;
|
|
5
5
|
|
|
6
6
|
while(true){
|
|
7
7
|
const map = test[sym] as Map<string, IshCtr>;
|
|
8
8
|
if(map !== undefined){
|
|
9
9
|
if(map.has(name)){
|
|
10
|
-
return map.get(name)
|
|
10
|
+
return map.get(name)!;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
if(test === document)
|
|
13
|
+
if(test === document){
|
|
14
|
+
return await watch(scope, name);
|
|
15
|
+
}
|
|
14
16
|
if(test instanceof ShadowRoot){
|
|
15
17
|
test = test.host;
|
|
16
18
|
continue;
|
|
@@ -20,6 +22,16 @@ export function getIsh(scope: Element | ShadowRoot | Document, name: string){
|
|
|
20
22
|
test = newTest;
|
|
21
23
|
continue;
|
|
22
24
|
}
|
|
25
|
+
const lastTest = test;
|
|
23
26
|
test = test.getRootNode();
|
|
27
|
+
if(test === lastTest) {
|
|
28
|
+
return await watch(scope, name);
|
|
29
|
+
};
|
|
24
30
|
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async function watch(scope: Element | ShadowRoot | Document | Node, name: string){
|
|
34
|
+
const {waitForEvent} = await import('../waitForEvent.js');
|
|
35
|
+
await waitForEvent(document, guid);
|
|
36
|
+
return await getIsh(scope, name);
|
|
25
37
|
}
|
package/refid/regIsh.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const guid = 'La8Cx9vHsUOd03WomqdnPw';
|
|
2
|
+
export const sym = Symbol.for(guid);
|
|
2
3
|
export function regIsh(scope, name, ctr) {
|
|
3
4
|
let map = scope[sym];
|
|
4
5
|
if (map === undefined) {
|
|
@@ -9,4 +10,5 @@ export function regIsh(scope, name, ctr) {
|
|
|
9
10
|
throw 403;
|
|
10
11
|
}
|
|
11
12
|
map.set(name, ctr);
|
|
13
|
+
document.dispatchEvent(new Event(guid));
|
|
12
14
|
}
|
package/refid/regIsh.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {IshCtr} from '../ts-refs/mount-observer/types';
|
|
2
|
-
export const
|
|
2
|
+
export const guid = 'La8Cx9vHsUOd03WomqdnPw'
|
|
3
|
+
export const sym = Symbol.for(guid);
|
|
3
4
|
|
|
4
5
|
export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr:IshCtr){
|
|
5
6
|
let map = (<any>scope)[sym] as Map<string, IshCtr>;
|
|
@@ -11,4 +12,5 @@ export function regIsh(scope: Element | ShadowRoot | Document, name: string, ctr
|
|
|
11
12
|
throw 403;
|
|
12
13
|
}
|
|
13
14
|
map.set(name, ctr);
|
|
15
|
+
document.dispatchEvent(new Event(guid));
|
|
14
16
|
}
|
|
@@ -57,7 +57,7 @@ export type DerivationCriteria<TProps, TMethods> = {
|
|
|
57
57
|
//TODO - applicable to arrays
|
|
58
58
|
filter?: keyof TModhods & string | ((val: any) => boolean),
|
|
59
59
|
//TODO
|
|
60
|
-
map?: keyof TModhods & string | ((val: any) => any,
|
|
60
|
+
//map?: keyof TModhods & string | ((val: any) => any,
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
export interface TransformOptions{
|