mount-observer 0.1.1 → 0.1.3

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/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "mount-observer",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Observe and act on css matches.",
5
5
  "main": "MountObserver.js",
6
6
  "module": "MountObserver.js",
7
7
  "dependencies": {
8
- "assign-gingerly": "0.0.2"
8
+ "assign-gingerly": "0.0.6"
9
9
  },
10
10
  "devDependencies": {
11
- "@playwright/test": "1.58.0",
11
+ "@playwright/test": "1.58.2",
12
12
  "spa-ssi": "0.0.26"
13
13
  },
14
14
  "exports": {
@@ -19,6 +19,30 @@
19
19
  "./MountObserver.js": {
20
20
  "default": "./MountObserver.js",
21
21
  "types": "./MountObserver.ts"
22
+ },
23
+ "./whereOutside.js": {
24
+ "default": "./whereOutside.js",
25
+ "types": "./whereOutside.ts"
26
+ },
27
+ "./emitEvents.js": {
28
+ "default": "./emitEvents.js",
29
+ "types": "./emitEvents.ts"
30
+ },
31
+ "./attrChanges.js": {
32
+ "default": "./attrChanges.js",
33
+ "types": "./attrChanges.ts"
34
+ },
35
+ "./arr.js": {
36
+ "default": "./arr.js",
37
+ "types": "./arr.ts"
38
+ },
39
+ "./EvtRt.js": {
40
+ "default": "./EvtRt.js",
41
+ "types": "./EvtRt.ts"
42
+ },
43
+ "./DefineCustomElementHandler.js": {
44
+ "default": "./DefineCustomElementHandler.js",
45
+ "types": "./DefineCustomElementHandler.ts"
22
46
  }
23
47
  },
24
48
  "files": [
package/types.d.ts CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  export type Constructor = new (...args: any[]) => any;
4
4
 
5
+ export type EventConstructor = {new(...args: any[]): Event};
6
+
7
+ export interface EventConfig {
8
+ event: string | EventConstructor;
9
+ args?: any | any[];
10
+ eventProps?: Record<string, any>;
11
+ oncePerMountedElement?: boolean;
12
+ }
13
+
5
14
  export type DismountReason =
6
15
  | 'media-query-failed'
7
16
  | 'where-element-matches-failed';
@@ -11,12 +20,19 @@ export interface MountInit {
11
20
  whereAttr?: WhereAttr;
12
21
  whereInstanceOf?: Constructor | Constructor[];
13
22
  whereMediaMatches?: string | MediaQueryList;
23
+ whereOutside?: string;
14
24
  import?: string | ImportSpec | Array<string | ImportSpec>;
15
- do?: DoCallback | DoCallbacks;
25
+ do?: string | DoCallback | (string | DoCallback)[];
16
26
  loadingEagerness?: 'eager' | 'lazy';
17
- assignGingerly?: Record<string, any>;
27
+ assignOnMount?: Record<string, any>;
28
+ assignOnDismount?: Record<string, any>;
18
29
  map?: MapConfig;
19
30
  getPlayByPlay?: boolean;
31
+ mountedElemEmits?: EventConfig | EventConfig[];
32
+ reference?: number | number[];
33
+ //allow handler classes or functions
34
+ //to be passed some custom information
35
+ customData?: unknown;
20
36
  }
21
37
 
22
38
  export interface MapConfig {
@@ -51,40 +67,47 @@ export interface ImportSpec {
51
67
  export interface MountContext {
52
68
  modules: any[];
53
69
  observer: IMountObserver;
54
- observeInfo: ObserveInfo;
55
- }
56
-
57
- export interface ObserveInfo {
58
70
  rootNode: Node;
71
+ mountInit: MountInit
59
72
  }
60
73
 
61
- export type DoCallback = (matchingElement: Element, context: MountContext) => void;
62
74
 
63
- export interface DoCallbacks {
64
- mount?: (matchingElement: Element, context: MountContext) => void;
65
- dismount?: (matchingElement: Element, context: MountContext) => void;
66
- disconnect?: (matchingElement: Element, context: MountContext) => void;
67
- reconnect?: (matchingElement: Element, context: MountContext) => void;
68
- }
75
+
76
+ export type DoCallback = (mountedElement: Element, context: MountContext) => void;
77
+
78
+ // export interface DoCallbacks {
79
+ // mount?: (mountedElement: Element, context: MountContext) => void;
80
+ // dismount?: (mountedElement: Element, context: MountContext) => void;
81
+ // disconnect?: (mountedElement: Element, context: MountContext) => void;
82
+ // reconnect?: (mountedElement: Element, context: MountContext) => void;
83
+ // }
69
84
 
70
85
  export interface MountObserverOptions {
71
86
  disconnectedSignal?: AbortSignal;
72
87
  }
73
88
 
89
+ export interface WeakDual<T extends Object>{
90
+ weakSet: WeakSet<T>,
91
+ setWeak: Set<WeakRef<T>>
92
+ }
93
+
74
94
  export interface IMountObserver extends EventTarget {
75
95
  observe(rootNode: Node): Promise<void>;
76
96
  disconnect(): void;
77
97
  disconnectedSignal: AbortSignal;
98
+ assignGingerly(config: Record<string, any> | undefined): Promise<void>;
99
+ getNotifier(element: Element): EventTarget;
78
100
  }
79
101
 
80
102
  export interface IMountEvent extends Event {
81
- matchingElement: Element;
103
+ mountedElement: Element;
82
104
  modules: any[];
83
105
  mountInit: MountInit;
106
+ mountContext: MountContext;
84
107
  }
85
108
 
86
109
  export interface IDismountEvent extends Event {
87
- matchingElement: Element;
110
+ mountedElement: Element;
88
111
  reason: DismountReason;
89
112
  mountInit: MountInit;
90
113
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Check if an element is outside (not inside) any ancestor matching a selector.
3
+ * This implements "donut hole" scoping.
4
+ *
5
+ * @param rootNode - The root node to stop traversal at (not checked against selector)
6
+ * @param matchCandidate - The element to check
7
+ * @param outside - CSS selector for excluding ancestors
8
+ * @returns true if element is outside all matching ancestors, false otherwise
9
+ */
10
+ export function whereOutside(rootNode, matchCandidate, outside) {
11
+ let current = matchCandidate.parentElement;
12
+ while (current && current !== rootNode) {
13
+ if (current.matches(outside)) {
14
+ return false; // Found an excluding ancestor
15
+ }
16
+ current = current.parentElement;
17
+ }
18
+ return true; // No excluding ancestors found
19
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Check if an element is outside (not inside) any ancestor matching a selector.
3
+ * This implements "donut hole" scoping.
4
+ *
5
+ * @param rootNode - The root node to stop traversal at (not checked against selector)
6
+ * @param matchCandidate - The element to check
7
+ * @param outside - CSS selector for excluding ancestors
8
+ * @returns true if element is outside all matching ancestors, false otherwise
9
+ */
10
+ export function whereOutside(
11
+ rootNode: Node,
12
+ matchCandidate: Element,
13
+ outside: string
14
+ ): boolean {
15
+ let current = matchCandidate.parentElement;
16
+
17
+ while (current && current !== rootNode) {
18
+ if (current.matches(outside)) {
19
+ return false; // Found an excluding ancestor
20
+ }
21
+ current = current.parentElement;
22
+ }
23
+
24
+ return true; // No excluding ancestors found
25
+ }