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 CHANGED
@@ -364,55 +364,58 @@ export class MountObserver extends EventTarget {
364
364
  this.#mountedList?.push(new WeakRef(match));
365
365
  }
366
366
  }
367
- // readAttrs(match: Element, branchIndexes?: Set<number>){
368
- // //TODO: externalize
369
- // const fullListOfAttrs = this.#fullListOfEnhancementAttrs;
370
- // const attrChangeInfos: Array<AttrChangeInfo> = [];
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)) continue;
379
- // }
380
- // const name = fullListOfAttrs[idx];
381
- // const newValue = match.getAttribute(name);
382
- // attrChangeInfos.push({
383
- // idx,
384
- // isSOfTAttr: false,
385
- // newValue,
386
- // oldValue,
387
- // name,
388
- // parts
389
- // });
390
- // }
391
- // }
392
- // const {observedAttrsWhenMounted} = this.#mountInit;
393
- // if(observedAttrsWhenMounted !== undefined){
394
- // for(const observedAttr of observedAttrsWhenMounted){
395
- // const attrIsString = typeof observedAttr === 'string';
396
- // const name = attrIsString ? observedAttr : observedAttr.name;
397
- // let mapsTo: string | undefined;
398
- // let newValue = match.getAttribute(name);
399
- // if(!attrIsString){
400
- // const {customParser, instanceOf, mapsTo: mt, valIfNull} = observedAttr;
401
- // if(instanceOf || customParser) throw 'NI';
402
- // if(newValue === null) newValue = valIfNull;
403
- // mapsTo = mt;
404
- // }
405
- // attrChangeInfos.push({
406
- // isSOfTAttr: true,
407
- // newValue,
408
- // oldValue,
409
- // name,
410
- // mapsTo
411
- // });
412
- // }
413
- // }
414
- // return attrChangeInfos;
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
- // 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
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
- // 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];
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
- // const newValue = match.getAttribute(name);
411
+ const newValue = match.getAttribute(name);
412
412
 
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
- // }
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.106",
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.55.1",
9
- "spa-ssi": "0.0.23"
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, 'ishm', {
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 objToPass = child.hasAttribute('itemscope') ? {} : obj;
62
- parse(child, objToPass);
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, 'ishm', {
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 itemscopeMap: {[key: string] : any[]} | undefined;
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 objToPass = child.hasAttribute('itemscope') ? {} : obj;
65
- parse(child, objToPass);
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);