mount-observer 0.0.49 → 0.0.51

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
@@ -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},${itemscopeQry}`);
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) {
@@ -224,6 +220,9 @@ export class MountObserver extends EventTarget {
224
220
  }
225
221
  }
226
222
  this.#filterAndMount(elsToInspect, true, false);
223
+ for (const el of elsToInspect) {
224
+ await this.#inspectWithin(el, false);
225
+ }
227
226
  }, { signal: this.#abortController.signal });
228
227
  await this.#inspectWithin(within, true);
229
228
  }
@@ -420,23 +419,19 @@ export class MountObserver extends EventTarget {
420
419
  await this.#compose(elToMount, 0);
421
420
  }
422
421
  }
423
- for (const el of els) {
424
- if (el.matches(itemscopeQry)) {
425
- const { Newish } = await import('./Newish.js');
426
- new Newish(el, el.getAttribute('itemscope'), assigner);
427
- }
428
- }
422
+ await bindishIt(els, assigner);
429
423
  this.#mount(elsToMount, initializing);
430
424
  }
431
425
  async #inspectWithin(within, initializing) {
426
+ await bindish(within, this.#mountInit.assigner);
432
427
  await this.composeFragment(within, 0);
433
- const els = Array.from(within.querySelectorAll(await this.#selector()));
428
+ const match = await this.#selector();
429
+ const els = Array.from(within.querySelectorAll(match));
434
430
  this.#filterAndMount(els, false, initializing);
435
431
  }
436
432
  }
437
433
  const refCountErr = 'mount-observer ref count mismatch';
438
434
  export const inclTemplQry = 'template[src^="#"]:not([hidden])';
439
- export const itemscopeQry = '[itemscope*="-"]';
440
435
  // https://github.com/webcomponents-cg/community-protocols/issues/12#issuecomment-872415080
441
436
  /**
442
437
  * 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},${itemscopeQry}`) as NodeListOf<HTMLTemplateElement>;
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
- const itemscope = el.getAttribute('itemscope');
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{
@@ -237,6 +235,9 @@ export class MountObserver extends EventTarget implements IMountObserver{
237
235
  }
238
236
  }
239
237
  this.#filterAndMount(elsToInspect, true, false);
238
+ for(const el of elsToInspect){
239
+ await this.#inspectWithin(el, false);
240
+ }
240
241
  }, {signal: this.#abortController.signal});
241
242
 
242
243
  await this.#inspectWithin(within, true);
@@ -436,28 +437,25 @@ export class MountObserver extends EventTarget implements IMountObserver{
436
437
  }
437
438
 
438
439
  }
439
- for(const el of els){
440
- if(el.matches(itemscopeQry)){
441
- const {Newish} = await import('./Newish.js');
442
- new Newish(el, el.getAttribute('itemscope')!, assigner);
443
- }
444
- }
440
+ await bindishIt(els, assigner);
445
441
  this.#mount(elsToMount, initializing);
446
442
  }
447
443
 
448
444
  async #inspectWithin(within: Node, initializing: boolean){
445
+ await bindish(within as DocumentFragment, this.#mountInit.assigner);
449
446
  await this.composeFragment(within as DocumentFragment, 0);
450
- const els = Array.from((within as Element).querySelectorAll(await this.#selector()));
447
+ const match = await this.#selector();
448
+ const els = Array.from((within as Element).querySelectorAll(match));
451
449
  this.#filterAndMount(els, false, initializing);
452
450
  }
453
451
 
452
+ }
454
453
 
455
454
 
456
- }
457
455
 
458
456
  const refCountErr = 'mount-observer ref count mismatch';
459
457
  export const inclTemplQry = 'template[src^="#"]:not([hidden])';
460
- export const itemscopeQry = '[itemscope*="-"]';
458
+
461
459
  export interface MountObserver extends IMountObserver{}
462
460
 
463
461
  // 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 | ((target: any, source: any) => Promise<void>) = undefined;
9
+ #assigner: undefined | Assigner = undefined;
8
10
 
9
- constructor(enhancedElement: Element, itemscope: string, assigner?: (target: any, source: any) => Promise<void>){
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.49",
3
+ "version": "0.0.51",
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.51.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?: (target: any, source: any) => Promise<void>,
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
@@ -1,4 +1,5 @@
1
1
  import {IEnhancement, BEAllProps} from '../trans-render/be/types';
2
+ import { HasIshList } from '../trans-render/dss/types';
2
3
 
3
4
  export interface EndUserProps extends IEnhancement{
4
5
  statement: string;
@@ -7,6 +8,8 @@ export interface EndUserProps extends IEnhancement{
7
8
  export interface AllProps extends EndUserProps{
8
9
  listProp: string;
9
10
  itemProp: string;
11
+ ish: EventTarget & HasIshList;
12
+ //updateCnt: number;
10
13
  }
11
14
 
12
15
  export type AP = AllProps;
@@ -19,6 +22,7 @@ export type BAP = AP & BEAllProps;
19
22
 
20
23
  export interface Actions{
21
24
  parse(self: BAP): PAP;
22
- hydrate(self: BAP): ProPAP;
25
+ init(self: BAP): ProPAP;
26
+ hydrate(self: BAP)
23
27
  }
24
28
 
@@ -184,6 +184,11 @@ export interface PIP<TProp = any, TElement = Element> extends EventListenerObjec
184
184
  readonly outEvtName: string;
185
185
  }
186
186
 
187
- export interface HasIshList extends HTMLElement{
187
+ //TODO: move to mount observer
188
+ export interface HasIsh {
189
+ ish: EventTarget;
190
+ }
191
+
192
+ export interface HasIshList {
188
193
  ishList: Array<any>;
189
194
  }
@@ -1,6 +1,7 @@
1
1
  import { IMountObserver } from '../../mount-observer/types';
2
2
  import { Scope} from '../lib/types';
3
3
  import { WrapperConfig } from '../XV/types';
4
+ import {XForm} from '../types';
4
5
 
5
6
  export interface IEventConfig<MCProps = any, MCActions = MCProps, TAction = Action>{
6
7
  on?: string,
@@ -215,7 +216,7 @@ export type Compacts<TProps = any, TActions = TProps> =
215
216
  | Partial<{[key in `pass_length_of_${keyof TProps & string}_to_${keyof TProps & string}`]: number}>
216
217
  | Partial<{[key in `echo_${keyof TProps & string}_to_${keyof TProps & string}`]: number}>
217
218
  | Partial<{[key in `echo_${keyof TProps & string}_to_${keyof TProps & string}_after`]: keyof TProps}>
218
- | Partial<{[key in `when_${keyof TProps & string}_changes_invoke_${keyof TActions & string}`]: number}>
219
+ | Partial<{[key in `when_${keyof TProps & string}_changes_call_${keyof TActions & string}`]: number}>
219
220
  | Partial<{[key in `when_${keyof TProps & string}_changes_toggle_${keyof TProps & string}`]: number}>
220
221
  | Partial<{[key in `when_${keyof TProps & string}_changes_inc_${keyof TProps & string}_by`]: number}>
221
222
  ;
@@ -454,7 +455,7 @@ export interface ICompact{
454
455
  interface CompactStatement {
455
456
  srcKey: string,
456
457
  destKey: string,
457
- op: 'toggle' | 'negate' | 'invoke' | 'pass_length' | 'echo' | 'inc',
458
+ op: 'toggle' | 'negate' | 'call' | 'pass_length' | 'echo' | 'inc',
458
459
  rhsIsDynamic: boolean
459
460
  }
460
461
 
package/waitForIsh.js CHANGED
@@ -2,7 +2,7 @@ export function waitForIsh(el) {
2
2
  return new Promise((resolve, reject) => {
3
3
  const ish = el['ish']; // [TODO] should we make this something that can
4
4
  // be passed in, more generic function -- waitForProperty?
5
- if (ish) {
5
+ if (ish instanceof EventTarget) {
6
6
  resolve(ish);
7
7
  }
8
8
  else {
package/waitForIsh.ts CHANGED
@@ -2,7 +2,7 @@ export function waitForIsh(el: Element){
2
2
  return new Promise((resolve, reject) => {
3
3
  const ish = (<any>el)['ish']; // [TODO] should we make this something that can
4
4
  // be passed in, more generic function -- waitForProperty?
5
- if (ish) {
5
+ if (ish instanceof EventTarget) {
6
6
  resolve(ish);
7
7
  } else {
8
8
  // If the element is not yet defined, wait for it to be defined