mount-observer 0.0.104 → 0.0.106

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/Events.js ADDED
@@ -0,0 +1,42 @@
1
+ //TODO: make thes external
2
+ // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
3
+ /**
4
+ * The `mutation-event` event represents something that happened.
5
+ * We can document it here.
6
+ */
7
+ export class MountEvent extends Event {
8
+ mountedElement;
9
+ initializing;
10
+ static eventName = 'mount';
11
+ constructor(mountedElement, initializing) {
12
+ super(MountEvent.eventName);
13
+ this.mountedElement = mountedElement;
14
+ this.initializing = initializing;
15
+ }
16
+ }
17
+ export class DismountEvent extends Event {
18
+ dismountedElement;
19
+ static eventName = 'dismount';
20
+ constructor(dismountedElement) {
21
+ super(DismountEvent.eventName);
22
+ this.dismountedElement = dismountedElement;
23
+ }
24
+ }
25
+ export class DisconnectEvent extends Event {
26
+ disconnectedElement;
27
+ static eventName = 'disconnect';
28
+ constructor(disconnectedElement) {
29
+ super(DisconnectEvent.eventName);
30
+ this.disconnectedElement = disconnectedElement;
31
+ }
32
+ }
33
+ export class AttrChangeEvent extends Event {
34
+ mountedElement;
35
+ attrChangeInfos;
36
+ static eventName = 'attrChange';
37
+ constructor(mountedElement, attrChangeInfos) {
38
+ super(AttrChangeEvent.eventName);
39
+ this.mountedElement = mountedElement;
40
+ this.attrChangeInfos = attrChangeInfos;
41
+ }
42
+ }
package/Events.ts ADDED
@@ -0,0 +1,45 @@
1
+ import {MountInit, IMountObserver, AddMutationEventListener,
2
+ MutationEvent, dismountEventName, mountEventName, IMountEvent, IDismountEvent,
3
+ disconnectedEventName, IDisconnectEvent, IAttrChangeEvent, attrChangeEventName, AttrChangeInfo, loadEventName, ILoadEvent,
4
+ AttrParts,
5
+ MOSE, WeakDual,
6
+ MountObserverOptions,
7
+ Assigner,
8
+ RefType
9
+ } from './ts-refs/mount-observer/types';
10
+ //TODO: make thes external
11
+ // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
12
+ /**
13
+ * The `mutation-event` event represents something that happened.
14
+ * We can document it here.
15
+ */
16
+ export class MountEvent extends Event implements IMountEvent {
17
+ static eventName: mountEventName = 'mount';
18
+
19
+ constructor(public mountedElement: Element, public initializing: boolean) {
20
+ super(MountEvent.eventName);
21
+ }
22
+ }
23
+
24
+ export class DismountEvent extends Event implements IDismountEvent{
25
+ static eventName: dismountEventName = 'dismount';
26
+
27
+ constructor(public dismountedElement: Element){
28
+ super(DismountEvent.eventName);
29
+ }
30
+ }
31
+
32
+ export class DisconnectEvent extends Event implements IDisconnectEvent{
33
+ static eventName: disconnectedEventName = 'disconnect';
34
+
35
+ constructor(public disconnectedElement: Element){
36
+ super(DisconnectEvent.eventName);
37
+ }
38
+ }
39
+
40
+ export class AttrChangeEvent extends Event implements IAttrChangeEvent{
41
+ static eventName: attrChangeEventName = 'attrChange';
42
+ constructor(public mountedElement: Element, public attrChangeInfos: Array<AttrChangeInfo>){
43
+ super(AttrChangeEvent.eventName);
44
+ }
45
+ }
package/MountObserver.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { RootMutObs } from './RootMutObs.js';
2
2
  import { bindish, bindishIt } from './bindish.js';
3
- import './refid/hostish.js';
3
+ import './refid/hostish.js'; // gets embedded even if not used
4
4
  export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
5
5
  export const wasItemReffed = Symbol.for('8aA6xB8+PkScmivaslBk5Q');
6
6
  export const mutationObserverLookup = new WeakMap();
@@ -73,6 +73,7 @@ export class MountObserver extends EventTarget {
73
73
  }
74
74
  }
75
75
  async #compose(el, level) {
76
+ //[TODO]: load async, not used often
76
77
  const src = el.getAttribute('src');
77
78
  if (src === null || src.length < 2)
78
79
  return;
@@ -84,6 +85,7 @@ export class MountObserver extends EventTarget {
84
85
  }
85
86
  #templLookUp = new Map();
86
87
  #searchForComment(refName, fragment) {
88
+ //get rid of
87
89
  const iterator = document.evaluate(`//comment()[.="${refName}"]`, fragment, null, XPathResult.ANY_TYPE, null);
88
90
  //console.log({xpathResult})
89
91
  try {
@@ -94,7 +96,9 @@ export class MountObserver extends EventTarget {
94
96
  return null;
95
97
  }
96
98
  }
97
- async findByID(refName, fragment, refType) {
99
+ async findByID(
100
+ //[TODO]: make external, not always used
101
+ refName, fragment, refType) {
98
102
  if (this.#templLookUp.has(refName))
99
103
  return this.#templLookUp.get(refName);
100
104
  let templ = null;
@@ -262,6 +266,7 @@ export class MountObserver extends EventTarget {
262
266
  elsToInspect.push(target);
263
267
  }
264
268
  const deletedElements = Array.from(removedNodes).filter(x => x instanceof Element);
269
+ const { DisconnectEvent } = await import('./Events.js');
265
270
  for (const deletedElement of deletedElements) {
266
271
  this.#disconnected.add(deletedElement);
267
272
  if (doDisconnect !== undefined) {
@@ -271,6 +276,7 @@ export class MountObserver extends EventTarget {
271
276
  }
272
277
  }
273
278
  if (attrChangeInfosMap !== undefined) {
279
+ const { AttrChangeEvent } = await import('./Events.js');
274
280
  for (const [key, value] of attrChangeInfosMap) {
275
281
  this.dispatchEvent(new AttrChangeEvent(key, value));
276
282
  }
@@ -283,6 +289,7 @@ export class MountObserver extends EventTarget {
283
289
  await this.#inspectWithin(within, true);
284
290
  }
285
291
  static synthesize(within, customElement, mose) {
292
+ //TODO: make external
286
293
  mose.type = 'mountobserver';
287
294
  const name = customElements.getName(customElement);
288
295
  if (name === null)
@@ -350,65 +357,65 @@ export class MountObserver extends EventTarget {
350
357
  }
351
358
  match[guid].add(this);
352
359
  }
360
+ const { MountEvent } = await import('./Events.js');
353
361
  this.dispatchEvent(new MountEvent(match, initializing));
354
362
  //should we automatically call readAttrs?
355
363
  //the thinking is it might make more sense to call that after mounting
356
364
  this.#mountedList?.push(new WeakRef(match));
357
365
  }
358
366
  }
359
- readAttrs(match, branchIndexes) {
360
- const fullListOfAttrs = this.#fullListOfEnhancementAttrs;
361
- const attrChangeInfos = [];
362
- const oldValue = null;
363
- if (fullListOfAttrs !== undefined) {
364
- const attrParts = this.#attrParts;
365
- for (let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++) {
366
- const parts = attrParts[idx];
367
- const { branchIdx } = parts;
368
- if (branchIndexes !== undefined) {
369
- if (!branchIndexes.has(branchIdx))
370
- continue;
371
- }
372
- const name = fullListOfAttrs[idx];
373
- const newValue = match.getAttribute(name);
374
- attrChangeInfos.push({
375
- idx,
376
- isSOfTAttr: false,
377
- newValue,
378
- oldValue,
379
- name,
380
- parts
381
- });
382
- }
383
- }
384
- const { observedAttrsWhenMounted } = this.#mountInit;
385
- if (observedAttrsWhenMounted !== undefined) {
386
- for (const observedAttr of observedAttrsWhenMounted) {
387
- const attrIsString = typeof observedAttr === 'string';
388
- const name = attrIsString ? observedAttr : observedAttr.name;
389
- let mapsTo;
390
- let newValue = match.getAttribute(name);
391
- if (!attrIsString) {
392
- const { customParser, instanceOf, mapsTo: mt, valIfNull } = observedAttr;
393
- if (instanceOf || customParser)
394
- throw 'NI';
395
- if (newValue === null)
396
- newValue = valIfNull;
397
- mapsTo = mt;
398
- }
399
- attrChangeInfos.push({
400
- isSOfTAttr: true,
401
- newValue,
402
- oldValue,
403
- name,
404
- mapsTo
405
- });
406
- }
407
- }
408
- return attrChangeInfos;
409
- }
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
+ // }
410
416
  async #dismount(unmatching) {
411
417
  const onDismount = this.#mountInit.do?.dismount;
418
+ const { DismountEvent } = await import('./Events.js');
412
419
  for (const unmatch of unmatching) {
413
420
  if (onDismount !== undefined) {
414
421
  onDismount(unmatch, this, {});
@@ -519,6 +526,7 @@ export class MountObserver extends EventTarget {
519
526
  this.#filterAndMount(els, within, false, initializing);
520
527
  }
521
528
  }
529
+ //ToDO: make external
522
530
  export function waitForIdleNodes(nodes, idleTimeout) {
523
531
  const mountInit = {
524
532
  idleTimeout
@@ -550,6 +558,7 @@ export function waitForIdleNodes(nodes, idleTimeout) {
550
558
  }
551
559
  });
552
560
  }
561
+ //make external
553
562
  function areAllIdle(mutObs) {
554
563
  for (const mo of mutObs) {
555
564
  if (!mo.isIdle)
@@ -559,45 +568,4 @@ function areAllIdle(mutObs) {
559
568
  }
560
569
  const refCountErr = 'mount-observer ref count mismatch';
561
570
  export const inclTemplQry = 'template[src^="#"]:not([hidden]),template[src^="!"]:not([hidden])';
562
- // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
563
- /**
564
- * The `mutation-event` event represents something that happened.
565
- * We can document it here.
566
- */
567
- export class MountEvent extends Event {
568
- mountedElement;
569
- initializing;
570
- static eventName = 'mount';
571
- constructor(mountedElement, initializing) {
572
- super(MountEvent.eventName);
573
- this.mountedElement = mountedElement;
574
- this.initializing = initializing;
575
- }
576
- }
577
- export class DismountEvent extends Event {
578
- dismountedElement;
579
- static eventName = 'dismount';
580
- constructor(dismountedElement) {
581
- super(DismountEvent.eventName);
582
- this.dismountedElement = dismountedElement;
583
- }
584
- }
585
- export class DisconnectEvent extends Event {
586
- disconnectedElement;
587
- static eventName = 'disconnect';
588
- constructor(disconnectedElement) {
589
- super(DisconnectEvent.eventName);
590
- this.disconnectedElement = disconnectedElement;
591
- }
592
- }
593
- export class AttrChangeEvent extends Event {
594
- mountedElement;
595
- attrChangeInfos;
596
- static eventName = 'attrChange';
597
- constructor(mountedElement, attrChangeInfos) {
598
- super(AttrChangeEvent.eventName);
599
- this.mountedElement = mountedElement;
600
- this.attrChangeInfos = attrChangeInfos;
601
- }
602
- }
603
571
  //const hasRootInDefault = ['data', 'enh', 'data-enh']
package/MountObserver.ts CHANGED
@@ -9,7 +9,7 @@ import {MountInit, IMountObserver, AddMutationEventListener,
9
9
  } from './ts-refs/mount-observer/types';
10
10
  import {RootMutObs} from './RootMutObs.js';
11
11
  import {bindish, bindishIt} from './bindish.js';
12
- import './refid/hostish.js';
12
+ import './refid/hostish.js'; // gets embedded even if not used
13
13
  export {MOSE} from './ts-refs/mount-observer/types';
14
14
  export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
15
15
  export const wasItemReffed = Symbol.for('8aA6xB8+PkScmivaslBk5Q');
@@ -88,6 +88,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
88
88
 
89
89
 
90
90
  async #compose(el: HTMLTemplateElement, level: number){
91
+ //[TODO]: load async, not used often
91
92
  const src = el.getAttribute('src');
92
93
  if(src === null || src.length < 2) return;
93
94
  const refType = src[0] as RefType;
@@ -99,6 +100,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
99
100
  }
100
101
  #templLookUp: Map<string, HTMLElement> = new Map();
101
102
  #searchForComment(refName: string, fragment: Node){
103
+ //get rid of
102
104
  const iterator = document.evaluate(
103
105
  `//comment()[.="${refName}"]`,
104
106
  fragment,
@@ -115,6 +117,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
115
117
  }
116
118
  }
117
119
  async findByID(
120
+ //[TODO]: make external, not always used
118
121
  refName: string, fragment: DocumentFragment,
119
122
  refType: RefType): Promise<HTMLElement | DocumentFragment | null>{
120
123
  if(this.#templLookUp.has(refName)) return this.#templLookUp.get(refName)!;
@@ -288,6 +291,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
288
291
  }
289
292
 
290
293
  const deletedElements = Array.from(removedNodes).filter(x => x instanceof Element) as Array<Element>;
294
+ const {DisconnectEvent} = await import('./Events.js');
291
295
  for(const deletedElement of deletedElements){
292
296
  this.#disconnected.add(deletedElement);
293
297
  if(doDisconnect !== undefined){
@@ -298,6 +302,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
298
302
 
299
303
  }
300
304
  if(attrChangeInfosMap !== undefined){
305
+ const {AttrChangeEvent} = await import('./Events.js');
301
306
  for(const [key, value] of attrChangeInfosMap){
302
307
  this.dispatchEvent(new AttrChangeEvent(key, value))
303
308
  }
@@ -312,6 +317,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
312
317
  }
313
318
 
314
319
  static synthesize(within: Document | ShadowRoot, customElement: {new(): HTMLElement}, mose: MOSE){
320
+ //TODO: make external
315
321
  mose.type = 'mountobserver';
316
322
  const name = customElements.getName(customElement);
317
323
  if(name === null) throw 400;
@@ -377,6 +383,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
377
383
  }
378
384
  (<any>match)[guid].add(this);
379
385
  }
386
+ const {MountEvent} = await import('./Events.js');
380
387
  this.dispatchEvent(new MountEvent(match, initializing));
381
388
  //should we automatically call readAttrs?
382
389
  //the thinking is it might make more sense to call that after mounting
@@ -385,62 +392,64 @@ export class MountObserver extends EventTarget implements IMountObserver{
385
392
  }
386
393
  }
387
394
 
388
- readAttrs(match: Element, branchIndexes?: Set<number>){
389
- const fullListOfAttrs = this.#fullListOfEnhancementAttrs;
390
- const attrChangeInfos: Array<AttrChangeInfo> = [];
391
- const oldValue = null;
392
- if(fullListOfAttrs !== undefined){
393
- 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
394
402
 
395
- for(let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++){
396
- const parts = attrParts![idx];
397
- const {branchIdx} = parts;
398
- if(branchIndexes !== undefined){
399
- if(!branchIndexes.has(branchIdx)) continue;
400
- }
401
- 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];
402
410
 
403
- const newValue = match.getAttribute(name);
411
+ // const newValue = match.getAttribute(name);
404
412
 
405
- attrChangeInfos.push({
406
- idx,
407
- isSOfTAttr: false,
408
- newValue,
409
- oldValue,
410
- name,
411
- parts
412
- });
413
- }
414
-
415
- }
416
- const {observedAttrsWhenMounted} = this.#mountInit;
417
- if(observedAttrsWhenMounted !== undefined){
418
- for(const observedAttr of observedAttrsWhenMounted){
419
- const attrIsString = typeof observedAttr === 'string';
420
- const name = attrIsString ? observedAttr : observedAttr.name;
421
- let mapsTo: string | undefined;
422
- let newValue = match.getAttribute(name);
423
- if(!attrIsString){
424
- const {customParser, instanceOf, mapsTo: mt, valIfNull} = observedAttr;
425
- if(instanceOf || customParser) throw 'NI';
426
- if(newValue === null) newValue = valIfNull;
427
- mapsTo = mt;
428
- }
429
- attrChangeInfos.push({
430
- isSOfTAttr: true,
431
- newValue,
432
- oldValue,
433
- name,
434
- mapsTo
435
- });
436
- }
437
- }
438
-
439
- return attrChangeInfos;
440
- }
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
+ // }
441
449
 
442
450
  async #dismount(unmatching: Array<Element>){
443
- const onDismount = this.#mountInit.do?.dismount
451
+ const onDismount = this.#mountInit.do?.dismount;
452
+ const {DismountEvent} = await import('./Events.js');
444
453
  for(const unmatch of unmatching){
445
454
  if(onDismount !== undefined){
446
455
  onDismount(unmatch, this, {});
@@ -552,6 +561,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
552
561
 
553
562
  }
554
563
 
564
+ //ToDO: make external
555
565
  export function waitForIdleNodes(nodes: Array<Node>, idleTimeout?: number): Promise<void>{
556
566
  const mountInit: MountInit = {
557
567
  idleTimeout
@@ -583,6 +593,7 @@ export function waitForIdleNodes(nodes: Array<Node>, idleTimeout?: number): Prom
583
593
  });
584
594
  }
585
595
 
596
+ //make external
586
597
  function areAllIdle(mutObs: Array<RootMutObs>){
587
598
  for(const mo of mutObs){
588
599
  if(!mo.isIdle) return false;
@@ -596,41 +607,6 @@ export const inclTemplQry = 'template[src^="#"]:not([hidden]),template[src^="!"]
596
607
 
597
608
  export interface MountObserver extends IMountObserver{}
598
609
 
599
- // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
600
- /**
601
- * The `mutation-event` event represents something that happened.
602
- * We can document it here.
603
- */
604
- export class MountEvent extends Event implements IMountEvent {
605
- static eventName: mountEventName = 'mount';
606
-
607
- constructor(public mountedElement: Element, public initializing: boolean) {
608
- super(MountEvent.eventName);
609
- }
610
- }
611
-
612
- export class DismountEvent extends Event implements IDismountEvent{
613
- static eventName: dismountEventName = 'dismount';
614
-
615
- constructor(public dismountedElement: Element){
616
- super(DismountEvent.eventName);
617
- }
618
- }
619
-
620
- export class DisconnectEvent extends Event implements IDisconnectEvent{
621
- static eventName: disconnectedEventName = 'disconnect';
622
-
623
- constructor(public disconnectedElement: Element){
624
- super(DisconnectEvent.eventName);
625
- }
626
- }
627
-
628
- export class AttrChangeEvent extends Event implements IAttrChangeEvent{
629
- static eventName: attrChangeEventName = 'attrChange';
630
- constructor(public mountedElement: Element, public attrChangeInfos: Array<AttrChangeInfo>){
631
- super(AttrChangeEvent.eventName);
632
- }
633
- }
634
610
 
635
611
 
636
612
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.104",
3
+ "version": "0.0.106",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
@@ -69,6 +69,10 @@
69
69
  "default": "./refid/getCount.js",
70
70
  "types": "./refid/getCount.ts"
71
71
  },
72
+ "./refid/ism.js": {
73
+ "default": "./refid/ism.js",
74
+ "types": "./refid/ism.ts"
75
+ },
72
76
  "./refid/itemprops.js": {
73
77
  "default": "./refid/itemprops.js",
74
78
  "types": "./refid/itemprops.ts"
package/readAttrs.ts ADDED
@@ -0,0 +1,60 @@
1
+ import { AttrChangeInfo, AttrParts, MountInit } from "./ts-refs/mount-observer/types";
2
+
3
+ export function readAttrs(
4
+ match: Element, mountInit: MountInit, branchIndexes?: Set<number>,
5
+ fullListOfEnhancementAttrs?: string[],
6
+ attrParts?: AttrParts[],
7
+ ){
8
+ //TODO: externalize
9
+ const fullListOfAttrs = fullListOfEnhancementAttrs;
10
+ const attrChangeInfos: Array<AttrChangeInfo> = [];
11
+ const oldValue = null;
12
+ if(fullListOfAttrs !== undefined){
13
+
14
+
15
+ for(let idx = 0, ii = fullListOfAttrs.length; idx < ii; idx++){
16
+ const parts = attrParts![idx];
17
+ const {branchIdx} = parts;
18
+ if(branchIndexes !== undefined){
19
+ if(!branchIndexes.has(branchIdx)) continue;
20
+ }
21
+ const name = fullListOfAttrs[idx];
22
+
23
+ const newValue = match.getAttribute(name);
24
+
25
+ attrChangeInfos.push({
26
+ idx,
27
+ isSOfTAttr: false,
28
+ newValue,
29
+ oldValue,
30
+ name,
31
+ parts
32
+ });
33
+ }
34
+
35
+ }
36
+ const {observedAttrsWhenMounted} = mountInit;
37
+ if(observedAttrsWhenMounted !== undefined){
38
+ for(const observedAttr of observedAttrsWhenMounted){
39
+ const attrIsString = typeof observedAttr === 'string';
40
+ const name = attrIsString ? observedAttr : observedAttr.name;
41
+ let mapsTo: string | undefined;
42
+ let newValue = match.getAttribute(name);
43
+ if(!attrIsString){
44
+ const {customParser, instanceOf, mapsTo: mt, valIfNull} = observedAttr;
45
+ if(instanceOf || customParser) throw 'NI';
46
+ if(newValue === null) newValue = valIfNull;
47
+ mapsTo = mt;
48
+ }
49
+ attrChangeInfos.push({
50
+ isSOfTAttr: true,
51
+ newValue,
52
+ oldValue,
53
+ name,
54
+ mapsTo
55
+ });
56
+ }
57
+ }
58
+
59
+ return attrChangeInfos;
60
+ }