mount-observer 0.0.49 → 0.0.50
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 +4 -13
- package/MountObserver.ts +9 -15
- package/Newish.ts +4 -2
- package/bindish.js +14 -0
- package/bindish.ts +17 -0
- package/package.json +6 -2
- package/ts-refs/mount-observer/types.d.ts +3 -1
package/MountObserver.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RootMutObs } from './RootMutObs.js';
|
|
2
|
+
import { bindish, bindishIt } from './bindish.js';
|
|
2
3
|
export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
|
|
3
4
|
const mutationObserverLookup = new WeakMap();
|
|
4
5
|
const refCount = new WeakMap();
|
|
@@ -59,7 +60,7 @@ export class MountObserver extends EventTarget {
|
|
|
59
60
|
}
|
|
60
61
|
//This method is called publicly from outside mount-observer -- keep it public
|
|
61
62
|
async composeFragment(fragment, level) {
|
|
62
|
-
const bis = fragment.querySelectorAll(`${inclTemplQry}
|
|
63
|
+
const bis = fragment.querySelectorAll(`${inclTemplQry}`);
|
|
63
64
|
for (const bi of bis) {
|
|
64
65
|
await this.#compose(bi, level);
|
|
65
66
|
}
|
|
@@ -69,11 +70,6 @@ export class MountObserver extends EventTarget {
|
|
|
69
70
|
const { compose } = await import('./compose.js');
|
|
70
71
|
await compose(this, el, level);
|
|
71
72
|
}
|
|
72
|
-
const itemscope = el.getAttribute('itemscope');
|
|
73
|
-
if (itemscope && itemscope.includes('-')) {
|
|
74
|
-
const { Newish } = await import('./Newish.js');
|
|
75
|
-
new Newish(el, itemscope, this.#mountInit.assigner);
|
|
76
|
-
}
|
|
77
73
|
}
|
|
78
74
|
#templLookUp = new Map();
|
|
79
75
|
findByID(id, fragment) {
|
|
@@ -420,15 +416,11 @@ export class MountObserver extends EventTarget {
|
|
|
420
416
|
await this.#compose(elToMount, 0);
|
|
421
417
|
}
|
|
422
418
|
}
|
|
423
|
-
|
|
424
|
-
if (el.matches(itemscopeQry)) {
|
|
425
|
-
const { Newish } = await import('./Newish.js');
|
|
426
|
-
new Newish(el, el.getAttribute('itemscope'), assigner);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
419
|
+
await bindishIt(els, assigner);
|
|
429
420
|
this.#mount(elsToMount, initializing);
|
|
430
421
|
}
|
|
431
422
|
async #inspectWithin(within, initializing) {
|
|
423
|
+
await bindish(within, this.#mountInit.assigner);
|
|
432
424
|
await this.composeFragment(within, 0);
|
|
433
425
|
const els = Array.from(within.querySelectorAll(await this.#selector()));
|
|
434
426
|
this.#filterAndMount(els, false, initializing);
|
|
@@ -436,7 +428,6 @@ export class MountObserver extends EventTarget {
|
|
|
436
428
|
}
|
|
437
429
|
const refCountErr = 'mount-observer ref count mismatch';
|
|
438
430
|
export const inclTemplQry = 'template[src^="#"]:not([hidden])';
|
|
439
|
-
export const itemscopeQry = '[itemscope*="-"]';
|
|
440
431
|
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
|
441
432
|
/**
|
|
442
433
|
* The `mutation-event` event represents something that happened.
|
package/MountObserver.ts
CHANGED
|
@@ -3,9 +3,11 @@ import {MountInit, IMountObserver, AddMutationEventListener,
|
|
|
3
3
|
disconnectedEventName, IDisconnectEvent, IAttrChangeEvent, attrChangeEventName, AttrChangeInfo, loadEventName, ILoadEvent,
|
|
4
4
|
AttrParts,
|
|
5
5
|
MOSE, WeakDual,
|
|
6
|
-
MountObserverOptions
|
|
6
|
+
MountObserverOptions,
|
|
7
|
+
Assigner
|
|
7
8
|
} from './ts-refs/mount-observer/types';
|
|
8
9
|
import {RootMutObs} from './RootMutObs.js';
|
|
10
|
+
import {bindish, bindishIt} from './bindish.js';
|
|
9
11
|
export {MOSE} from './ts-refs/mount-observer/types';
|
|
10
12
|
export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
|
|
11
13
|
|
|
@@ -70,7 +72,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
70
72
|
|
|
71
73
|
//This method is called publicly from outside mount-observer -- keep it public
|
|
72
74
|
async composeFragment(fragment: DocumentFragment, level: number){
|
|
73
|
-
const bis = fragment.querySelectorAll(`${inclTemplQry}
|
|
75
|
+
const bis = fragment.querySelectorAll(`${inclTemplQry}`) as NodeListOf<HTMLTemplateElement>;
|
|
74
76
|
for(const bi of bis){
|
|
75
77
|
await this.#compose(bi, level);
|
|
76
78
|
}
|
|
@@ -82,11 +84,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
82
84
|
const {compose} = await import('./compose.js');
|
|
83
85
|
await compose(this, el, level);
|
|
84
86
|
}
|
|
85
|
-
|
|
86
|
-
if(itemscope && itemscope.includes('-')){
|
|
87
|
-
const {Newish} = await import('./Newish.js');
|
|
88
|
-
new Newish(el, itemscope, this.#mountInit.assigner);
|
|
89
|
-
}
|
|
87
|
+
|
|
90
88
|
}
|
|
91
89
|
#templLookUp: Map<string, HTMLElement> = new Map();
|
|
92
90
|
findByID(id: string, fragment: DocumentFragment): HTMLElement | null{
|
|
@@ -436,28 +434,24 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
436
434
|
}
|
|
437
435
|
|
|
438
436
|
}
|
|
439
|
-
|
|
440
|
-
if(el.matches(itemscopeQry)){
|
|
441
|
-
const {Newish} = await import('./Newish.js');
|
|
442
|
-
new Newish(el, el.getAttribute('itemscope')!, assigner);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
437
|
+
await bindishIt(els, assigner);
|
|
445
438
|
this.#mount(elsToMount, initializing);
|
|
446
439
|
}
|
|
447
440
|
|
|
448
441
|
async #inspectWithin(within: Node, initializing: boolean){
|
|
442
|
+
await bindish(within as DocumentFragment, this.#mountInit.assigner);
|
|
449
443
|
await this.composeFragment(within as DocumentFragment, 0);
|
|
450
444
|
const els = Array.from((within as Element).querySelectorAll(await this.#selector()));
|
|
451
445
|
this.#filterAndMount(els, false, initializing);
|
|
452
446
|
}
|
|
453
447
|
|
|
448
|
+
}
|
|
454
449
|
|
|
455
450
|
|
|
456
|
-
}
|
|
457
451
|
|
|
458
452
|
const refCountErr = 'mount-observer ref count mismatch';
|
|
459
453
|
export const inclTemplQry = 'template[src^="#"]:not([hidden])';
|
|
460
|
-
|
|
454
|
+
|
|
461
455
|
export interface MountObserver extends IMountObserver{}
|
|
462
456
|
|
|
463
457
|
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
package/Newish.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import { Assigner } from './ts-refs/mount-observer/types.js';
|
|
2
|
+
|
|
1
3
|
export {waitForEvent} from './waitForEvent.js';
|
|
2
4
|
export class Newish{
|
|
3
5
|
queue: Array<any> = [];
|
|
4
6
|
isResolved = false;
|
|
5
7
|
#ce: HTMLElement | undefined;
|
|
6
8
|
|
|
7
|
-
#assigner: undefined |
|
|
9
|
+
#assigner: undefined | Assigner = undefined;
|
|
8
10
|
|
|
9
|
-
constructor(enhancedElement: Element, itemscope: string, assigner?:
|
|
11
|
+
constructor(enhancedElement: Element, itemscope: string, assigner?: Assigner){
|
|
10
12
|
this.#assigner = assigner;
|
|
11
13
|
this.#do(enhancedElement, itemscope);
|
|
12
14
|
}
|
package/bindish.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const itemscopeQry = '[itemscope*="-"]';
|
|
2
|
+
export async function bindish(fragment, assigner) {
|
|
3
|
+
const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
|
|
4
|
+
await bindishIt(scopes, assigner);
|
|
5
|
+
}
|
|
6
|
+
export async function bindishIt(scopes, assigner) {
|
|
7
|
+
for (const scope of scopes) {
|
|
8
|
+
const itemscope = scope.getAttribute('itemscope');
|
|
9
|
+
if (itemscope && itemscope.includes('-') && !(scope.ish instanceof HTMLElement)) {
|
|
10
|
+
const { Newish } = await import('./Newish.js');
|
|
11
|
+
new Newish(scope, itemscope, assigner);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
package/bindish.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Assigner } from './ts-refs/mount-observer/types.js';
|
|
2
|
+
|
|
3
|
+
export const itemscopeQry = '[itemscope*="-"]';
|
|
4
|
+
export async function bindish(fragment: DocumentFragment, assigner?: Assigner){
|
|
5
|
+
const scopes = Array.from(fragment.querySelectorAll(`${itemscopeQry}`));
|
|
6
|
+
await bindishIt(scopes, assigner);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export async function bindishIt(scopes: Array<Element>, assigner?: Assigner){
|
|
10
|
+
for(const scope of scopes){
|
|
11
|
+
const itemscope = scope.getAttribute('itemscope');
|
|
12
|
+
if(itemscope && itemscope.includes('-') && !((<any>scope).ish instanceof HTMLElement)){
|
|
13
|
+
const {Newish} = await import('./Newish.js');
|
|
14
|
+
new Newish(scope, itemscope, assigner);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.50",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
7
7
|
"devDependencies": {
|
|
8
|
-
"@playwright/test": "1.
|
|
8
|
+
"@playwright/test": "1.52.0",
|
|
9
9
|
"ssi-server": "0.0.1"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
@@ -25,6 +25,10 @@
|
|
|
25
25
|
"default": "./Synthesizer.js",
|
|
26
26
|
"types": "./Synthesizer.ts"
|
|
27
27
|
},
|
|
28
|
+
"./bindish.js": {
|
|
29
|
+
"default": "./bindish.js",
|
|
30
|
+
"types": "./bindish.ts"
|
|
31
|
+
},
|
|
28
32
|
"./compose.js": {
|
|
29
33
|
"default": "./compose.js",
|
|
30
34
|
"types": "./compose.ts"
|
|
@@ -19,13 +19,15 @@ export interface ObservedSourceOfTruthAttribute<TProps = any> {
|
|
|
19
19
|
customParser?: (newValue: string | null, oldValue: string | null, instance: Element) => any
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
export type Assigner = (target: any, source: any) => Promise<void> | void;
|
|
23
|
+
|
|
22
24
|
export interface MountInit extends JSONSerializableMountInit{
|
|
23
25
|
|
|
24
26
|
readonly withTargetShadowRoot?: ShadowRoot,
|
|
25
27
|
readonly whereInstanceOf?: Array<{new(): Element}>,
|
|
26
28
|
readonly whereSatisfies?: PipelineProcessor<boolean>,
|
|
27
29
|
readonly do?: MountObserverCallbacks,
|
|
28
|
-
readonly assigner?:
|
|
30
|
+
readonly assigner?: Assigner,
|
|
29
31
|
// /**
|
|
30
32
|
// * Purpose -- there are scenarios where we may only want to affect changes that occur after the initial
|
|
31
33
|
// * server rendering, so we only want to mount elements that appear
|