mount-observer 0.1.0 → 0.1.2

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/types.d.ts CHANGED
@@ -1,13 +1,33 @@
1
1
  // Core types for MountObserver v2 - Polyfill Supported Scenario I
2
2
 
3
+ export type Constructor = new (...args: any[]) => any;
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
+
14
+ export type DismountReason =
15
+ | 'media-query-failed'
16
+ | 'where-element-matches-failed';
17
+
3
18
  export interface MountInit {
4
19
  whereElementMatches: string;
5
20
  whereAttr?: WhereAttr;
21
+ whereInstanceOf?: Constructor | Constructor[];
22
+ whereMediaMatches?: string | MediaQueryList;
23
+ whereOutside?: string;
6
24
  import?: string | ImportSpec | Array<string | ImportSpec>;
7
25
  do?: DoCallback | DoCallbacks;
8
26
  loadingEagerness?: 'eager' | 'lazy';
9
27
  assignGingerly?: Record<string, any>;
10
28
  map?: MapConfig;
29
+ getPlayByPlay?: boolean;
30
+ mountedElemEmits?: EventConfig | EventConfig[];
11
31
  }
12
32
 
13
33
  export interface MapConfig {
@@ -17,6 +37,11 @@ export interface MapConfig {
17
37
  export interface MapEntry {
18
38
  instanceOf?: string;
19
39
  mapsTo?: string;
40
+ /**
41
+ * Only notify the presence of this attribute
42
+ * the first time it is seen
43
+ */
44
+ once?: boolean;
20
45
  [key: string]: any;
21
46
  }
22
47
 
@@ -57,23 +82,33 @@ export interface MountObserverOptions {
57
82
  disconnectedSignal?: AbortSignal;
58
83
  }
59
84
 
85
+ export interface WeakDual<T extends Object>{
86
+ weakSet: WeakSet<T>,
87
+ setWeak: Set<WeakRef<T>>
88
+ }
89
+
60
90
  export interface IMountObserver extends EventTarget {
61
91
  observe(rootNode: Node): Promise<void>;
62
92
  disconnect(): void;
63
93
  disconnectedSignal: AbortSignal;
94
+ assignGingerly(config: Record<string, any> | undefined): Promise<void>;
64
95
  }
65
96
 
66
97
  export interface IMountEvent extends Event {
67
98
  matchingElement: Element;
68
99
  modules: any[];
100
+ mountInit: MountInit;
69
101
  }
70
102
 
71
103
  export interface IDismountEvent extends Event {
72
104
  matchingElement: Element;
105
+ reason: DismountReason;
106
+ mountInit: MountInit;
73
107
  }
74
108
 
75
109
  export interface IAttrChangeEvent extends Event {
76
110
  changes: AttrChange[];
111
+ mountInit: MountInit;
77
112
  }
78
113
 
79
114
  export interface AttrChange {
@@ -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
+ }
package/constants.js DELETED
@@ -1,6 +0,0 @@
1
- // Constants for MountObserver
2
- export const loadEventName = 'load';
3
- export const mountEventName = 'mount';
4
- export const dismountEventName = 'dismount';
5
- export const disconnectEventName = 'disconnect';
6
- export const attrchangeEventName = 'attrchange';
package/constants.ts DELETED
@@ -1,7 +0,0 @@
1
- // Constants for MountObserver
2
-
3
- export const loadEventName = 'load';
4
- export const mountEventName = 'mount';
5
- export const dismountEventName = 'dismount';
6
- export const disconnectEventName = 'disconnect';
7
- export const attrchangeEventName = 'attrchange';