mount-observer 0.0.46 → 0.0.47
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 +5 -3
- package/MountObserver.ts +6 -3
- package/Newish.js +2 -3
- package/Newish.ts +2 -3
- package/package.json +5 -1
- package/waitForEvent.ts +1 -1
- package/waitForIsh.js +20 -0
- package/waitForIsh.ts +19 -0
package/MountObserver.js
CHANGED
|
@@ -418,9 +418,11 @@ export class MountObserver extends EventTarget {
|
|
|
418
418
|
if (elToMount.matches(inclTemplQry)) {
|
|
419
419
|
await this.#compose(elToMount, 0);
|
|
420
420
|
}
|
|
421
|
-
|
|
421
|
+
}
|
|
422
|
+
for (const el of els) {
|
|
423
|
+
if (el.matches(itemscopeQry)) {
|
|
422
424
|
const { Newish } = await import('./Newish.js');
|
|
423
|
-
new Newish(
|
|
425
|
+
new Newish(el, el.getAttribute('itemscope'), assigner);
|
|
424
426
|
}
|
|
425
427
|
}
|
|
426
428
|
this.#mount(elsToMount, initializing);
|
|
@@ -433,7 +435,7 @@ export class MountObserver extends EventTarget {
|
|
|
433
435
|
}
|
|
434
436
|
const refCountErr = 'mount-observer ref count mismatch';
|
|
435
437
|
export const inclTemplQry = 'template[src^="#"]:not([hidden])';
|
|
436
|
-
export const itemscopeQry = '[itemscope
|
|
438
|
+
export const itemscopeQry = '[itemscope*="-"]';
|
|
437
439
|
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
|
438
440
|
/**
|
|
439
441
|
* The `mutation-event` event represents something that happened.
|
package/MountObserver.ts
CHANGED
|
@@ -433,9 +433,12 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
433
433
|
if(elToMount.matches(inclTemplQry)){
|
|
434
434
|
await this.#compose(elToMount as HTMLTemplateElement, 0)
|
|
435
435
|
}
|
|
436
|
-
|
|
436
|
+
|
|
437
|
+
}
|
|
438
|
+
for(const el of els){
|
|
439
|
+
if(el.matches(itemscopeQry)){
|
|
437
440
|
const {Newish} = await import('./Newish.js');
|
|
438
|
-
new Newish(
|
|
441
|
+
new Newish(el, el.getAttribute('itemscope')!, assigner);
|
|
439
442
|
}
|
|
440
443
|
}
|
|
441
444
|
this.#mount(elsToMount, initializing);
|
|
@@ -453,7 +456,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
453
456
|
|
|
454
457
|
const refCountErr = 'mount-observer ref count mismatch';
|
|
455
458
|
export const inclTemplQry = 'template[src^="#"]:not([hidden])';
|
|
456
|
-
export const itemscopeQry = '[itemscope
|
|
459
|
+
export const itemscopeQry = '[itemscope*="-"]';
|
|
457
460
|
export interface MountObserver extends IMountObserver{}
|
|
458
461
|
|
|
459
462
|
// https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
|
package/Newish.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
export { waitForEvent } from './waitForEvent.js';
|
|
2
|
-
export class Newish
|
|
2
|
+
export class Newish {
|
|
3
3
|
queue = [];
|
|
4
4
|
isResolved = false;
|
|
5
5
|
#ce;
|
|
6
6
|
#assigner = undefined;
|
|
7
7
|
constructor(enhancedElement, itemscope, assigner) {
|
|
8
|
-
super();
|
|
9
8
|
this.#assigner = assigner;
|
|
10
9
|
this.#do(enhancedElement, itemscope);
|
|
11
10
|
}
|
|
@@ -43,7 +42,7 @@ export class Newish extends EventTarget {
|
|
|
43
42
|
this.#assignGingerly();
|
|
44
43
|
}
|
|
45
44
|
this.isResolved = true;
|
|
46
|
-
|
|
45
|
+
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
47
46
|
}
|
|
48
47
|
async #assignGingerly() {
|
|
49
48
|
let ce = this.#ce;
|
package/Newish.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export {waitForEvent} from './waitForEvent.js';
|
|
2
|
-
export class Newish
|
|
2
|
+
export class Newish{
|
|
3
3
|
queue: Array<any> = [];
|
|
4
4
|
isResolved = false;
|
|
5
5
|
#ce: HTMLElement | undefined;
|
|
@@ -7,7 +7,6 @@ export class Newish extends EventTarget{
|
|
|
7
7
|
#assigner: undefined | ((target: any, source: any) => Promise<void>) = undefined;
|
|
8
8
|
|
|
9
9
|
constructor(enhancedElement: Element, itemscope: string, assigner?: (target: any, source: any) => Promise<void>){
|
|
10
|
-
super();
|
|
11
10
|
this.#assigner = assigner;
|
|
12
11
|
this.#do(enhancedElement, itemscope);
|
|
13
12
|
}
|
|
@@ -46,7 +45,7 @@ export class Newish extends EventTarget{
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
this.isResolved = true;
|
|
49
|
-
|
|
48
|
+
enhancedElement.dispatchEvent(new Event('ishAttached'));
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
async #assignGingerly(){
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.47",
|
|
4
4
|
"description": "Observe and act on css matches.",
|
|
5
5
|
"main": "MountObserver.js",
|
|
6
6
|
"module": "MountObserver.js",
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"./waitForEvent.js": {
|
|
33
33
|
"default": "./waitForEvent.js",
|
|
34
34
|
"types": "./waitForEvent.ts"
|
|
35
|
+
},
|
|
36
|
+
"./waitForIsh.js": {
|
|
37
|
+
"default": "./waitForIsh.js",
|
|
38
|
+
"types": "./waitForIsh.ts"
|
|
35
39
|
}
|
|
36
40
|
},
|
|
37
41
|
"files": [
|
package/waitForEvent.ts
CHANGED
package/waitForIsh.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export function waitForIsh(el) {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const ish = el['ish'];
|
|
4
|
+
if (ish) {
|
|
5
|
+
resolve(ish);
|
|
6
|
+
}
|
|
7
|
+
else {
|
|
8
|
+
// If the element is not yet defined, wait for it to be defined
|
|
9
|
+
el.addEventListener('ishAttached', () => {
|
|
10
|
+
const ish = el['ish'];
|
|
11
|
+
if (ish) {
|
|
12
|
+
resolve(ish);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
reject(new Error('ish not found'));
|
|
16
|
+
}
|
|
17
|
+
}, { once: true });
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
package/waitForIsh.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function waitForIsh(el: Element){
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
const ish = (<any>el)['ish'];
|
|
4
|
+
if (ish) {
|
|
5
|
+
resolve(ish);
|
|
6
|
+
} else {
|
|
7
|
+
// If the element is not yet defined, wait for it to be defined
|
|
8
|
+
el.addEventListener('ishAttached', () => {
|
|
9
|
+
const ish = (<any>el)['ish'];
|
|
10
|
+
if (ish) {
|
|
11
|
+
resolve(ish);
|
|
12
|
+
} else {
|
|
13
|
+
reject(new Error('ish not found'));
|
|
14
|
+
}
|
|
15
|
+
}, { once: true });
|
|
16
|
+
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|