mount-observer 0.0.106 → 0.0.108
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 +52 -49
- package/MountObserver.ts +51 -51
- package/package.json +3 -3
- package/refid/ism.js +11 -8
- package/refid/ism.ts +12 -8
package/MountObserver.js
CHANGED
|
@@ -364,55 +364,58 @@ export class MountObserver extends EventTarget {
|
|
|
364
364
|
this.#mountedList?.push(new WeakRef(match));
|
|
365
365
|
}
|
|
366
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
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
367
|
+
readAttrs(match, branchIndexes) {
|
|
368
|
+
//TODO: externalize
|
|
369
|
+
const fullListOfAttrs = this.#fullListOfEnhancementAttrs;
|
|
370
|
+
const attrChangeInfos = [];
|
|
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))
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
const name = fullListOfAttrs[idx];
|
|
382
|
+
const newValue = match.getAttribute(name);
|
|
383
|
+
attrChangeInfos.push({
|
|
384
|
+
idx,
|
|
385
|
+
isSOfTAttr: false,
|
|
386
|
+
newValue,
|
|
387
|
+
oldValue,
|
|
388
|
+
name,
|
|
389
|
+
parts
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
const { observedAttrsWhenMounted } = this.#mountInit;
|
|
394
|
+
if (observedAttrsWhenMounted !== undefined) {
|
|
395
|
+
for (const observedAttr of observedAttrsWhenMounted) {
|
|
396
|
+
const attrIsString = typeof observedAttr === 'string';
|
|
397
|
+
const name = attrIsString ? observedAttr : observedAttr.name;
|
|
398
|
+
let mapsTo;
|
|
399
|
+
let newValue = match.getAttribute(name);
|
|
400
|
+
if (!attrIsString) {
|
|
401
|
+
const { customParser, instanceOf, mapsTo: mt, valIfNull } = observedAttr;
|
|
402
|
+
if (instanceOf || customParser)
|
|
403
|
+
throw 'NI';
|
|
404
|
+
if (newValue === null)
|
|
405
|
+
newValue = valIfNull;
|
|
406
|
+
mapsTo = mt;
|
|
407
|
+
}
|
|
408
|
+
attrChangeInfos.push({
|
|
409
|
+
isSOfTAttr: true,
|
|
410
|
+
newValue,
|
|
411
|
+
oldValue,
|
|
412
|
+
name,
|
|
413
|
+
mapsTo
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return attrChangeInfos;
|
|
418
|
+
}
|
|
416
419
|
async #dismount(unmatching) {
|
|
417
420
|
const onDismount = this.#mountInit.do?.dismount;
|
|
418
421
|
const { DismountEvent } = await import('./Events.js');
|
package/MountObserver.ts
CHANGED
|
@@ -392,60 +392,60 @@ export class MountObserver extends EventTarget implements IMountObserver{
|
|
|
392
392
|
}
|
|
393
393
|
}
|
|
394
394
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
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
|
|
402
402
|
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
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];
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
const newValue = match.getAttribute(name);
|
|
412
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
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
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
|
+
}
|
|
449
449
|
|
|
450
450
|
async #dismount(unmatching: Array<Element>){
|
|
451
451
|
const onDismount = this.#mountInit.do?.dismount;
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mount-observer",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.108",
|
|
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.
|
|
9
|
-
"spa-ssi": "0.0.
|
|
8
|
+
"@playwright/test": "1.56.1",
|
|
9
|
+
"spa-ssi": "0.0.25"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
package/refid/ism.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { upShadowSearch } from '../upShadowSearch.js';
|
|
2
2
|
import { stdVal } from './stdVal.js';
|
|
3
|
-
Object.defineProperty(HTMLElement.prototype, '
|
|
3
|
+
Object.defineProperty(HTMLElement.prototype, 'ism', {
|
|
4
4
|
get() {
|
|
5
5
|
const el = this;
|
|
6
|
+
if (!el.hasAttribute('itemscope'))
|
|
7
|
+
return;
|
|
6
8
|
return parse(el);
|
|
7
9
|
}
|
|
8
10
|
});
|
|
9
11
|
const parsedItempropmaps = new WeakMap();
|
|
10
|
-
export function parse(el, obj = {}) {
|
|
12
|
+
export function parse(el, obj = {}, itemscopeMap = {}) {
|
|
11
13
|
const itemprop = el.getAttribute('itemprop');
|
|
12
14
|
if (itemprop) {
|
|
13
15
|
obj[itemprop] = stdVal(el); //TODO full logic
|
|
@@ -51,15 +53,16 @@ export function parse(el, obj = {}) {
|
|
|
51
53
|
//el.ish = obj;
|
|
52
54
|
const children = Array.from(el.children);
|
|
53
55
|
const isItemScoped = el.hasAttribute('itemscope');
|
|
54
|
-
let itemscopeMap;
|
|
55
|
-
if (isItemScoped) {
|
|
56
|
-
itemscopeMap = {};
|
|
57
|
-
}
|
|
56
|
+
let itemscopeMapToPass = itemscopeMap;
|
|
58
57
|
for (const child of children) {
|
|
59
58
|
if (!(child instanceof HTMLElement))
|
|
60
59
|
continue;
|
|
61
|
-
const
|
|
62
|
-
|
|
60
|
+
const childHasItemScopeAttr = child.hasAttribute('itemscope');
|
|
61
|
+
const objToPass = childHasItemScopeAttr ? {} : obj;
|
|
62
|
+
if (childHasItemScopeAttr) {
|
|
63
|
+
itemscopeMapToPass = {};
|
|
64
|
+
}
|
|
65
|
+
parse(child, objToPass, itemscopeMapToPass);
|
|
63
66
|
const isItemScopeAndChildHasBothItempropAndItemscope = itemscopeMap && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
64
67
|
if (isItemScopeAndChildHasBothItempropAndItemscope) {
|
|
65
68
|
const itemprops = child.getAttribute('itemprop').split(" ").filter(x => x);
|
package/refid/ism.ts
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import {upShadowSearch} from '../upShadowSearch.js';
|
|
2
2
|
import {stdVal} from './stdVal.js';
|
|
3
3
|
|
|
4
|
-
Object.defineProperty(HTMLElement.prototype, '
|
|
4
|
+
Object.defineProperty(HTMLElement.prototype, 'ism', {
|
|
5
5
|
get(){
|
|
6
6
|
const el = this as HTMLElement;
|
|
7
|
+
if(!el.hasAttribute('itemscope')) return;
|
|
7
8
|
return parse(el);
|
|
8
9
|
}
|
|
9
10
|
});
|
|
10
11
|
|
|
12
|
+
type ItemscopeMap = {[key: string] : any[]}
|
|
13
|
+
|
|
11
14
|
const parsedItempropmaps = new WeakMap<HTMLScriptElement, any>();
|
|
12
15
|
|
|
13
|
-
export function parse(el: HTMLElement, obj: any = {}){
|
|
16
|
+
export function parse(el: HTMLElement, obj: any = {}, itemscopeMap: ItemscopeMap = {}){
|
|
14
17
|
const itemprop = el.getAttribute('itemprop');
|
|
15
18
|
if(itemprop){
|
|
16
19
|
obj[itemprop] = stdVal(el); //TODO full logic
|
|
@@ -55,14 +58,15 @@ export function parse(el: HTMLElement, obj: any = {}){
|
|
|
55
58
|
//el.ish = obj;
|
|
56
59
|
const children = Array.from(el.children);
|
|
57
60
|
const isItemScoped = el.hasAttribute('itemscope');
|
|
58
|
-
let
|
|
59
|
-
if(isItemScoped){
|
|
60
|
-
itemscopeMap = {};
|
|
61
|
-
}
|
|
61
|
+
let itemscopeMapToPass = itemscopeMap;
|
|
62
62
|
for(const child of children){
|
|
63
63
|
if(!(child instanceof HTMLElement)) continue;
|
|
64
|
-
const
|
|
65
|
-
|
|
64
|
+
const childHasItemScopeAttr = child.hasAttribute('itemscope')
|
|
65
|
+
const objToPass = childHasItemScopeAttr ? {} : obj;
|
|
66
|
+
if(childHasItemScopeAttr) {
|
|
67
|
+
itemscopeMapToPass = {};
|
|
68
|
+
}
|
|
69
|
+
parse(child, objToPass, itemscopeMapToPass);
|
|
66
70
|
const isItemScopeAndChildHasBothItempropAndItemscope = itemscopeMap && child.hasAttribute('itemprop') && child.hasAttribute('itemscope');
|
|
67
71
|
if(isItemScopeAndChildHasBothItempropAndItemscope){
|
|
68
72
|
const itemprops = child.getAttribute('itemprop')!.split(" ").filter(x => x);
|