mount-observer 0.0.40 → 0.0.42

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,8 +1,10 @@
1
1
  import { RootMutObs } from './RootMutObs.js';
2
+ export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
2
3
  const mutationObserverLookup = new WeakMap();
3
4
  const refCount = new WeakMap();
4
5
  export class MountObserver extends EventTarget {
5
6
  #mountInit;
7
+ #options;
6
8
  //#rootMutObs: RootMutObs | undefined;
7
9
  #abortController;
8
10
  mountedElements;
@@ -21,7 +23,7 @@ export class MountObserver extends EventTarget {
21
23
  isComplex = reducedMatch.includes(' ') || (reducedMatch.includes(':') && reducedMatch.includes('('));
22
24
  }
23
25
  this.#isComplex = isComplex;
24
- if (whereElementIntersectsWith || whereMediaMatches)
26
+ if (whereElementIntersectsWith)
25
27
  throw 'NI'; //not implemented
26
28
  this.#mountInit = init;
27
29
  this.#abortController = new AbortController();
@@ -111,7 +113,35 @@ export class MountObserver extends EventTarget {
111
113
  }
112
114
  this.dispatchEvent(new Event('disconnectedCallback'));
113
115
  }
114
- async observe(within) {
116
+ async observe(within, options) {
117
+ this.#options = options;
118
+ const init = this.#mountInit;
119
+ const { whereMediaMatches } = init;
120
+ if (whereMediaMatches === undefined) {
121
+ await this.#observe2(within);
122
+ return;
123
+ }
124
+ const mql = window.matchMedia(whereMediaMatches);
125
+ if (mql.matches) {
126
+ await this.#observe2(within);
127
+ }
128
+ mql.addEventListener('change', async (e) => {
129
+ if (e.matches) {
130
+ if (this.objNde === undefined) {
131
+ await this.#observe2(within);
132
+ }
133
+ else {
134
+ await this.#mountAll();
135
+ }
136
+ }
137
+ else {
138
+ if (this.objNde !== undefined) {
139
+ await this.#dismountAll();
140
+ }
141
+ }
142
+ });
143
+ }
144
+ async #observe2(within) {
115
145
  await this.#selector();
116
146
  this.objNde = new WeakRef(within);
117
147
  const nodeToMonitor = this.#isComplex ? (within instanceof ShadowRoot ? within : within.getRootNode()) : within;
@@ -222,6 +252,7 @@ export class MountObserver extends EventTarget {
222
252
  const mount = this.#mountInit.do?.mount;
223
253
  const { import: imp } = this.#mountInit;
224
254
  const me = this.mountedElements;
255
+ const options = this.#options;
225
256
  for (const match of matching) {
226
257
  if (alreadyMounted.has(match))
227
258
  continue;
@@ -253,6 +284,12 @@ export class MountObserver extends EventTarget {
253
284
  initializing
254
285
  });
255
286
  }
287
+ if (options?.LeaveBreadcrumb) {
288
+ if (match[guid] === undefined) {
289
+ match[guid] = new Set();
290
+ }
291
+ match[guid].add(this);
292
+ }
256
293
  this.dispatchEvent(new MountEvent(match, initializing));
257
294
  //should we automatically call readAttrs?
258
295
  //the thinking is it might make more sense to call that after mounting
@@ -319,6 +356,19 @@ export class MountObserver extends EventTarget {
319
356
  this.dispatchEvent(new DismountEvent(unmatch));
320
357
  }
321
358
  }
359
+ async #dismountAll() {
360
+ const mounted = this.#mountedList;
361
+ if (mounted === undefined)
362
+ return;
363
+ this.#dismount(mounted.map(x => x.deref()).filter(x => x !== undefined));
364
+ }
365
+ async #mountAll() {
366
+ //TODO: copilot created, check if needed
367
+ const { whereSatisfies, whereInstanceOf } = this.#mountInit;
368
+ const match = await this.#selector();
369
+ const els = Array.from(document.querySelectorAll(match));
370
+ this.#filterAndMount(els, false, true);
371
+ }
322
372
  async #filterAndDismount() {
323
373
  const returnSet = new Set();
324
374
  if (this.#mountedList !== undefined) {
package/MountObserver.ts CHANGED
@@ -2,16 +2,19 @@ import {MountInit, IMountObserver, AddMutationEventListener,
2
2
  MutationEvent, dismountEventName, mountEventName, IMountEvent, IDismountEvent,
3
3
  disconnectedEventName, IDisconnectEvent, IAttrChangeEvent, attrChangeEventName, AttrChangeInfo, loadEventName, ILoadEvent,
4
4
  AttrParts,
5
- MOSE, WeakDual
5
+ MOSE, WeakDual,
6
+ MountObserverOptions
6
7
  } from './ts-refs/mount-observer/types';
7
8
  import {RootMutObs} from './RootMutObs.js';
8
9
  export {MOSE} from './ts-refs/mount-observer/types';
10
+ export const guid = '5Pv6bHOVH0ae07opRZ8N/g';
9
11
 
10
12
  const mutationObserverLookup = new WeakMap<Node, RootMutObs>();
11
13
  const refCount = new WeakMap<Node, number>();
12
14
  export class MountObserver extends EventTarget implements IMountObserver{
13
15
 
14
16
  #mountInit: MountInit;
17
+ #options: MountObserverOptions | undefined;
15
18
  //#rootMutObs: RootMutObs | undefined;
16
19
  #abortController: AbortController;
17
20
  mountedElements: WeakDual<Element>;
@@ -31,7 +34,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
31
34
  isComplex = reducedMatch.includes(' ') || (reducedMatch.includes(':') && reducedMatch.includes('('));
32
35
  }
33
36
  this.#isComplex = isComplex;
34
- if(whereElementIntersectsWith || whereMediaMatches) throw 'NI'; //not implemented
37
+ if(whereElementIntersectsWith) throw 'NI'; //not implemented
35
38
  this.#mountInit = init;
36
39
  this.#abortController = new AbortController();
37
40
  this.mountedElements = {
@@ -120,7 +123,34 @@ export class MountObserver extends EventTarget implements IMountObserver{
120
123
 
121
124
  }
122
125
 
123
- async observe(within: Node){
126
+ async observe(within: Node, options?: MountObserverOptions){
127
+ this.#options = options;
128
+ const init = this.#mountInit;
129
+ const {whereMediaMatches} = init;
130
+ if(whereMediaMatches === undefined){
131
+ await this.#observe2(within);
132
+ return;
133
+ }
134
+ const mql = window.matchMedia(whereMediaMatches);
135
+ if(mql.matches){
136
+ await this.#observe2(within);
137
+ }
138
+ mql.addEventListener('change', async (e) => {
139
+ if(e.matches){
140
+ if(this.objNde === undefined){
141
+ await this.#observe2(within);
142
+ }else{
143
+ await this.#mountAll();
144
+ }
145
+ }else{
146
+ if(this.objNde !== undefined){
147
+ await this.#dismountAll();
148
+ }
149
+ }
150
+ });
151
+ }
152
+
153
+ async #observe2(within: Node){
124
154
  await this.#selector();
125
155
  this.objNde = new WeakRef(within);
126
156
  const nodeToMonitor = this.#isComplex ? (within instanceof ShadowRoot ? within : within.getRootNode()) : within;
@@ -204,7 +234,6 @@ export class MountObserver extends EventTarget implements IMountObserver{
204
234
  }, {signal: this.#abortController.signal});
205
235
 
206
236
  await this.#inspectWithin(within, true);
207
-
208
237
  }
209
238
 
210
239
  static synthesize(within: Document | ShadowRoot, customElement: {new(): HTMLElement}, mose: MOSE){
@@ -236,6 +265,7 @@ export class MountObserver extends EventTarget implements IMountObserver{
236
265
  const mount = this.#mountInit.do?.mount;
237
266
  const {import: imp} = this.#mountInit;
238
267
  const me = this.mountedElements;
268
+ const options = this.#options;
239
269
  for(const match of matching){
240
270
  if(alreadyMounted.has(match)) continue;
241
271
  if(!me.weakSet.has(match)){
@@ -266,6 +296,12 @@ export class MountObserver extends EventTarget implements IMountObserver{
266
296
  initializing
267
297
  })
268
298
  }
299
+ if(options?.LeaveBreadcrumb){
300
+ if((<any>match)[guid] === undefined){
301
+ (<any>match)[guid] = new Set();
302
+ }
303
+ (<any>match)[guid].add(this);
304
+ }
269
305
  this.dispatchEvent(new MountEvent(match, initializing));
270
306
  //should we automatically call readAttrs?
271
307
  //the thinking is it might make more sense to call that after mounting
@@ -338,6 +374,20 @@ export class MountObserver extends EventTarget implements IMountObserver{
338
374
  }
339
375
  }
340
376
 
377
+ async #dismountAll(){
378
+ const mounted = this.#mountedList;
379
+ if(mounted === undefined) return;
380
+ this.#dismount(mounted.map(x => x.deref()).filter(x => x !== undefined) as Array<Element>);
381
+ }
382
+
383
+ async #mountAll(){
384
+ //TODO: copilot created, check if needed
385
+ const {whereSatisfies, whereInstanceOf} = this.#mountInit;
386
+ const match = await this.#selector();
387
+ const els = Array.from(document.querySelectorAll(match));
388
+ this.#filterAndMount(els, false, true);
389
+ }
390
+
341
391
  async #filterAndDismount(): Promise<Set<Element>>{
342
392
  const returnSet = new Set<Element>();
343
393
  if(this.#mountedList !== undefined){
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.0.40",
3
+ "version": "0.0.42",
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.49.1",
8
+ "@playwright/test": "1.50.0",
9
9
  "ssi-server": "0.0.1"
10
10
  },
11
11
  "exports": {
@@ -26,6 +26,7 @@ export interface EndUserProps extends IEnhancement<HTMLTemplateElement>{
26
26
  */
27
27
  beOosoom?: string;
28
28
  js?: string;
29
+ transitional: boolean;
29
30
  }
30
31
 
31
32
  export interface AllProps extends EndUserProps{
@@ -69,9 +70,15 @@ export interface TwoValueSwitch{
69
70
  withinSpecifier?: Specifier,
70
71
  req?: boolean,
71
72
  op?: Op,
72
- negate?: boolean,
73
+ //negate?: boolean,
73
74
  lhs?: ISide,
74
75
  rhs?: ISide,
76
+ onOrOff:
77
+ | 'on'
78
+ | 'On'
79
+ | 'off'
80
+ | 'Off',
81
+
75
82
  }
76
83
 
77
84
  export interface Dependency extends Specifier{}
@@ -128,12 +135,12 @@ export interface Elevate {
128
135
 
129
136
  export interface EventForNValueSwitch {
130
137
  ctx: NValueScriptSwitch,
131
- factors: {[key: string] : SignalRefType},
138
+ factors: {[key: string] : any},
132
139
  switchOn?: boolean,
133
140
  elevate?: Elevate
134
141
  }
135
142
 
136
- export interface SignalAndEvent {
137
- signal?: WeakRef<SignalRefType>,
138
- eventSuggestion?: string
139
- }
143
+ // export interface SignalAndEvent {
144
+ // signal?: WeakRef<SignalRefType>,
145
+ // eventSuggestion?: string
146
+ // }
@@ -32,6 +32,10 @@ export interface MountInit extends JSONSerializableMountInit{
32
32
  // readonly ignoreInitialMatches?: boolean,
33
33
  }
34
34
 
35
+ export interface MountObserverOptions{
36
+ LeaveBreadcrumb?: boolean,
37
+ }
38
+
35
39
  export interface MountObserverCallbacks{
36
40
  readonly mount?: PipelineProcessor,
37
41
  readonly dismount?: PipelineProcessor,
@@ -131,7 +135,7 @@ interface AttrChangeInfo{
131
135
 
132
136
  //#region mount event
133
137
  export type mountEventName = 'mount';
134
- export interface IMountEvent{
138
+ export interface IMountEvent extends Event{
135
139
  mountedElement: Element,
136
140
  }
137
141
  export type mountEventHandler = (e: IMountEvent) => void;
@@ -0,0 +1,21 @@
1
+ import {IEnhancement, BEAllProps} from '../trans-render/be/types';
2
+
3
+ export interface EndUserProps extends IEnhancement{
4
+ doEval: boolean;
5
+ }
6
+
7
+ export interface AllProps extends EndUserProps{
8
+ //enhKey: string;
9
+ }
10
+
11
+ export type AP = AllProps;
12
+
13
+ export type PAP = Partial<AP>;
14
+
15
+ export type ProPAP = Promise<PAP>;
16
+
17
+ export type BAP = AP & BEAllProps;
18
+
19
+ export interface Actions{
20
+ hydrate(self: BAP): ProPAP;
21
+ }
@@ -356,8 +356,7 @@ export type roundaboutOptions<TProps = any, TActions = TProps, ETProps = TProps>
356
356
  //onsets?: Onsets<TProps, TActions>,
357
357
  handlers?: Handlers<ETProps, TActions>,
358
358
  hitch?: Hitches<TProps, TActions>,
359
- positractions?: Positractions<TProps>
360
- //do?: Partial<{[key in `${keyof TActions & string}_on`]: Keysh<TProps> }>
359
+ positractions?: Positractions<TProps>,
361
360
  }
362
361
 
363
362
  export type PropsToPartialProps<TProps = any> =
@@ -60,6 +60,7 @@ export interface TransformOptions{
60
60
  propagator?: MarkedUpEventTarget,
61
61
  propagatorIsReady?: boolean,
62
62
  skipInit?: boolean,
63
+ useViewTransition?: boolean,
63
64
  }
64
65
 
65
66
  export type Derivative<TProps, TMethods, TElement = {}> =
@@ -467,11 +468,19 @@ export interface MntCfg<TProps = any, TActions = TProps, ETProps = TProps> exten
467
468
  */
468
469
  lcXform?: XForm<TProps, TActions>,
469
470
 
471
+
472
+ /**
473
+ * transforms within ShadowRoot if applicable that uses view transitions
474
+ */
475
+ xxform?: XForm<TProps, TActions>
476
+
470
477
  styles?: /*CSSStyleSheet[] |*/ string | string[] | CSSStyleSheet | Array<CSSStyleSheet>;
471
478
 
472
479
  shadowRootInit?: ShadowRootInit,
473
480
 
474
- assumeCSR?: boolean
481
+ assumeCSR?: boolean,
482
+
483
+
475
484
  }
476
485
 
477
486
  export interface MountProps<TProps = any, TActions = TProps, ETProps = TProps>{
@@ -480,7 +489,7 @@ export interface MountProps<TProps = any, TActions = TProps, ETProps = TProps>{
480
489
  readonly hydrated?: boolean;
481
490
  readonly csr?: boolean;
482
491
  readonly xform?: XForm<TProps, TActions>,
483
-
492
+ readonly xxform?: XForm<TProps, TActions>,
484
493
  }
485
494
  export type PMP<TProps = any, TActions = TProps, ETProps = TProps> = Partial<MountProps<TProps, TActions, ETProps>>;
486
495
  export type ProPMP<TProps = any, TActions = TProps, ETProps = TProps> = Promise<PMP<TProps, TActions, ETProps>>