@zag-js/interact-outside 1.34.0 → 1.35.0
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/dist/frame-utils.d.mts +11 -0
- package/dist/frame-utils.d.ts +11 -0
- package/dist/frame-utils.js +87 -0
- package/dist/frame-utils.mjs +61 -0
- package/dist/index.js +55 -90
- package/dist/index.mjs +17 -65
- package/package.json +3 -3
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function getWindowFrames(win: Window): {
|
|
2
|
+
each(cb: (win: Window) => void): void;
|
|
3
|
+
addEventListener(event: string, listener: any, options?: any): () => void;
|
|
4
|
+
removeEventListener(event: string, listener: any, options?: any): void;
|
|
5
|
+
};
|
|
6
|
+
declare function getParentWindow(win: Window): {
|
|
7
|
+
addEventListener: (event: string, listener: any, options?: any) => () => void;
|
|
8
|
+
removeEventListener: (event: string, listener: any, options?: any) => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { getParentWindow, getWindowFrames };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare function getWindowFrames(win: Window): {
|
|
2
|
+
each(cb: (win: Window) => void): void;
|
|
3
|
+
addEventListener(event: string, listener: any, options?: any): () => void;
|
|
4
|
+
removeEventListener(event: string, listener: any, options?: any): void;
|
|
5
|
+
};
|
|
6
|
+
declare function getParentWindow(win: Window): {
|
|
7
|
+
addEventListener: (event: string, listener: any, options?: any) => () => void;
|
|
8
|
+
removeEventListener: (event: string, listener: any, options?: any) => void;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { getParentWindow, getWindowFrames };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/frame-utils.ts
|
|
21
|
+
var frame_utils_exports = {};
|
|
22
|
+
__export(frame_utils_exports, {
|
|
23
|
+
getParentWindow: () => getParentWindow,
|
|
24
|
+
getWindowFrames: () => getWindowFrames
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(frame_utils_exports);
|
|
27
|
+
function getWindowFrames(win) {
|
|
28
|
+
const frames = {
|
|
29
|
+
each(cb) {
|
|
30
|
+
for (let i = 0; i < win.frames?.length; i += 1) {
|
|
31
|
+
const frame = win.frames[i];
|
|
32
|
+
if (frame) cb(frame);
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
addEventListener(event, listener, options) {
|
|
36
|
+
frames.each((frame) => {
|
|
37
|
+
try {
|
|
38
|
+
frame.document.addEventListener(event, listener, options);
|
|
39
|
+
} catch {
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return () => {
|
|
43
|
+
try {
|
|
44
|
+
frames.removeEventListener(event, listener, options);
|
|
45
|
+
} catch {
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
removeEventListener(event, listener, options) {
|
|
50
|
+
frames.each((frame) => {
|
|
51
|
+
try {
|
|
52
|
+
frame.document.removeEventListener(event, listener, options);
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return frames;
|
|
59
|
+
}
|
|
60
|
+
function getParentWindow(win) {
|
|
61
|
+
const parent = win.frameElement != null ? win.parent : null;
|
|
62
|
+
return {
|
|
63
|
+
addEventListener: (event, listener, options) => {
|
|
64
|
+
try {
|
|
65
|
+
parent?.addEventListener(event, listener, options);
|
|
66
|
+
} catch {
|
|
67
|
+
}
|
|
68
|
+
return () => {
|
|
69
|
+
try {
|
|
70
|
+
parent?.removeEventListener(event, listener, options);
|
|
71
|
+
} catch {
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
removeEventListener: (event, listener, options) => {
|
|
76
|
+
try {
|
|
77
|
+
parent?.removeEventListener(event, listener, options);
|
|
78
|
+
} catch {
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
getParentWindow,
|
|
86
|
+
getWindowFrames
|
|
87
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// src/frame-utils.ts
|
|
2
|
+
function getWindowFrames(win) {
|
|
3
|
+
const frames = {
|
|
4
|
+
each(cb) {
|
|
5
|
+
for (let i = 0; i < win.frames?.length; i += 1) {
|
|
6
|
+
const frame = win.frames[i];
|
|
7
|
+
if (frame) cb(frame);
|
|
8
|
+
}
|
|
9
|
+
},
|
|
10
|
+
addEventListener(event, listener, options) {
|
|
11
|
+
frames.each((frame) => {
|
|
12
|
+
try {
|
|
13
|
+
frame.document.addEventListener(event, listener, options);
|
|
14
|
+
} catch {
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return () => {
|
|
18
|
+
try {
|
|
19
|
+
frames.removeEventListener(event, listener, options);
|
|
20
|
+
} catch {
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
removeEventListener(event, listener, options) {
|
|
25
|
+
frames.each((frame) => {
|
|
26
|
+
try {
|
|
27
|
+
frame.document.removeEventListener(event, listener, options);
|
|
28
|
+
} catch {
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
return frames;
|
|
34
|
+
}
|
|
35
|
+
function getParentWindow(win) {
|
|
36
|
+
const parent = win.frameElement != null ? win.parent : null;
|
|
37
|
+
return {
|
|
38
|
+
addEventListener: (event, listener, options) => {
|
|
39
|
+
try {
|
|
40
|
+
parent?.addEventListener(event, listener, options);
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
return () => {
|
|
44
|
+
try {
|
|
45
|
+
parent?.removeEventListener(event, listener, options);
|
|
46
|
+
} catch {
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
},
|
|
50
|
+
removeEventListener: (event, listener, options) => {
|
|
51
|
+
try {
|
|
52
|
+
parent?.removeEventListener(event, listener, options);
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
export {
|
|
59
|
+
getParentWindow,
|
|
60
|
+
getWindowFrames
|
|
61
|
+
};
|
package/dist/index.js
CHANGED
|
@@ -1,74 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
frame.document.addEventListener(event, listener, options);
|
|
21
|
-
} catch {
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return () => {
|
|
25
|
-
try {
|
|
26
|
-
frames.removeEventListener(event, listener, options);
|
|
27
|
-
} catch {
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
removeEventListener(event, listener, options) {
|
|
32
|
-
frames.each((frame) => {
|
|
33
|
-
try {
|
|
34
|
-
frame.document.removeEventListener(event, listener, options);
|
|
35
|
-
} catch {
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
return frames;
|
|
41
|
-
}
|
|
42
|
-
function getParentWindow(win) {
|
|
43
|
-
const parent = win.frameElement != null ? win.parent : null;
|
|
44
|
-
return {
|
|
45
|
-
addEventListener: (event, listener, options) => {
|
|
46
|
-
try {
|
|
47
|
-
parent?.addEventListener(event, listener, options);
|
|
48
|
-
} catch {
|
|
49
|
-
}
|
|
50
|
-
return () => {
|
|
51
|
-
try {
|
|
52
|
-
parent?.removeEventListener(event, listener, options);
|
|
53
|
-
} catch {
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
},
|
|
57
|
-
removeEventListener: (event, listener, options) => {
|
|
58
|
-
try {
|
|
59
|
-
parent?.removeEventListener(event, listener, options);
|
|
60
|
-
} catch {
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
65
19
|
|
|
66
20
|
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
trackInteractOutside: () => trackInteractOutside
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
var import_dom_query = require("@zag-js/dom-query");
|
|
27
|
+
var import_dom_query2 = require("@zag-js/dom-query");
|
|
28
|
+
var import_utils = require("@zag-js/utils");
|
|
29
|
+
var import_frame_utils = require("./frame-utils.cjs");
|
|
67
30
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
68
31
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
69
32
|
function isComposedPathFocusable(composedPath) {
|
|
70
33
|
for (const node of composedPath) {
|
|
71
|
-
if (
|
|
34
|
+
if ((0, import_dom_query2.isHTMLElement)(node) && (0, import_dom_query2.isFocusable)(node)) return true;
|
|
72
35
|
}
|
|
73
36
|
return false;
|
|
74
37
|
}
|
|
@@ -111,37 +74,37 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
111
74
|
followControlledElements = true
|
|
112
75
|
} = options;
|
|
113
76
|
if (!node) return;
|
|
114
|
-
const doc =
|
|
115
|
-
const win =
|
|
116
|
-
const frames = getWindowFrames(win);
|
|
117
|
-
const parentWin = getParentWindow(win);
|
|
77
|
+
const doc = (0, import_dom_query2.getDocument)(node);
|
|
78
|
+
const win = (0, import_dom_query2.getWindow)(node);
|
|
79
|
+
const frames = (0, import_frame_utils.getWindowFrames)(win);
|
|
80
|
+
const parentWin = (0, import_frame_utils.getParentWindow)(win);
|
|
118
81
|
function isEventOutside(event, target) {
|
|
119
|
-
if (!
|
|
82
|
+
if (!(0, import_dom_query2.isHTMLElement)(target)) return false;
|
|
120
83
|
if (!target.isConnected) return false;
|
|
121
|
-
if (
|
|
84
|
+
if ((0, import_dom_query2.contains)(node, target)) return false;
|
|
122
85
|
if (isEventPointWithin(node, event)) return false;
|
|
123
|
-
if (followControlledElements &&
|
|
86
|
+
if (followControlledElements && (0, import_dom_query2.isControlledElement)(node, target)) return false;
|
|
124
87
|
const triggerEl = doc.querySelector(`[aria-controls="${node.id}"]`);
|
|
125
88
|
if (triggerEl) {
|
|
126
|
-
const triggerAncestor =
|
|
89
|
+
const triggerAncestor = (0, import_dom_query2.getNearestOverflowAncestor)(triggerEl);
|
|
127
90
|
if (isEventWithinScrollbar(event, triggerAncestor)) return false;
|
|
128
91
|
}
|
|
129
|
-
const nodeAncestor =
|
|
92
|
+
const nodeAncestor = (0, import_dom_query2.getNearestOverflowAncestor)(node);
|
|
130
93
|
if (isEventWithinScrollbar(event, nodeAncestor)) return false;
|
|
131
94
|
return !exclude?.(target);
|
|
132
95
|
}
|
|
133
96
|
const pointerdownCleanups = /* @__PURE__ */ new Set();
|
|
134
|
-
const isInShadowRoot =
|
|
97
|
+
const isInShadowRoot = (0, import_dom_query.isShadowRoot)(node?.getRootNode());
|
|
135
98
|
function onPointerDown(event) {
|
|
136
99
|
function handler(clickEvent) {
|
|
137
|
-
const func = defer && !
|
|
100
|
+
const func = defer && !(0, import_dom_query.isTouchDevice)() ? import_dom_query2.raf : (v) => v();
|
|
138
101
|
const evt = clickEvent ?? event;
|
|
139
102
|
const composedPath = evt?.composedPath?.() ?? [evt?.target];
|
|
140
103
|
func(() => {
|
|
141
|
-
const target = isInShadowRoot ? composedPath[0] :
|
|
104
|
+
const target = isInShadowRoot ? composedPath[0] : (0, import_dom_query2.getEventTarget)(event);
|
|
142
105
|
if (!node || !isEventOutside(event, target)) return;
|
|
143
106
|
if (onPointerDownOutside || onInteractOutside) {
|
|
144
|
-
const handler2 =
|
|
107
|
+
const handler2 = (0, import_utils.callAll)(onPointerDownOutside, onInteractOutside);
|
|
145
108
|
node.addEventListener(POINTER_OUTSIDE_EVENT, handler2, { once: true });
|
|
146
109
|
}
|
|
147
110
|
fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
|
|
@@ -149,7 +112,7 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
149
112
|
cancelable: true,
|
|
150
113
|
detail: {
|
|
151
114
|
originalEvent: evt,
|
|
152
|
-
contextmenu:
|
|
115
|
+
contextmenu: (0, import_dom_query.isContextMenuEvent)(evt),
|
|
153
116
|
focusable: isComposedPathFocusable(composedPath),
|
|
154
117
|
target
|
|
155
118
|
}
|
|
@@ -158,7 +121,7 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
158
121
|
}
|
|
159
122
|
if (event.pointerType === "touch") {
|
|
160
123
|
pointerdownCleanups.forEach((fn) => fn());
|
|
161
|
-
pointerdownCleanups.add(
|
|
124
|
+
pointerdownCleanups.add((0, import_dom_query.addDomEvent)(doc, "click", handler, { once: true }));
|
|
162
125
|
pointerdownCleanups.add(parentWin.addEventListener("click", handler, { once: true }));
|
|
163
126
|
pointerdownCleanups.add(frames.addEventListener("click", handler, { once: true }));
|
|
164
127
|
} else {
|
|
@@ -167,18 +130,18 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
167
130
|
}
|
|
168
131
|
const cleanups = /* @__PURE__ */ new Set();
|
|
169
132
|
const timer = setTimeout(() => {
|
|
170
|
-
cleanups.add(
|
|
133
|
+
cleanups.add((0, import_dom_query.addDomEvent)(doc, "pointerdown", onPointerDown, true));
|
|
171
134
|
cleanups.add(parentWin.addEventListener("pointerdown", onPointerDown, true));
|
|
172
135
|
cleanups.add(frames.addEventListener("pointerdown", onPointerDown, true));
|
|
173
136
|
}, 0);
|
|
174
137
|
function onFocusin(event) {
|
|
175
|
-
const func = defer ?
|
|
138
|
+
const func = defer ? import_dom_query2.raf : (v) => v();
|
|
176
139
|
func(() => {
|
|
177
140
|
const composedPath = event?.composedPath?.() ?? [event?.target];
|
|
178
|
-
const target = isInShadowRoot ? composedPath[0] :
|
|
141
|
+
const target = isInShadowRoot ? composedPath[0] : (0, import_dom_query2.getEventTarget)(event);
|
|
179
142
|
if (!node || !isEventOutside(event, target)) return;
|
|
180
143
|
if (onFocusOutside || onInteractOutside) {
|
|
181
|
-
const handler =
|
|
144
|
+
const handler = (0, import_utils.callAll)(onFocusOutside, onInteractOutside);
|
|
182
145
|
node.addEventListener(FOCUS_OUTSIDE_EVENT, handler, { once: true });
|
|
183
146
|
}
|
|
184
147
|
fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
|
|
@@ -187,14 +150,14 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
187
150
|
detail: {
|
|
188
151
|
originalEvent: event,
|
|
189
152
|
contextmenu: false,
|
|
190
|
-
focusable:
|
|
153
|
+
focusable: (0, import_dom_query2.isFocusable)(target),
|
|
191
154
|
target
|
|
192
155
|
}
|
|
193
156
|
});
|
|
194
157
|
});
|
|
195
158
|
}
|
|
196
|
-
if (!
|
|
197
|
-
cleanups.add(
|
|
159
|
+
if (!(0, import_dom_query.isTouchDevice)()) {
|
|
160
|
+
cleanups.add((0, import_dom_query.addDomEvent)(doc, "focusin", onFocusin, true));
|
|
198
161
|
cleanups.add(parentWin.addEventListener("focusin", onFocusin, true));
|
|
199
162
|
cleanups.add(frames.addEventListener("focusin", onFocusin, true));
|
|
200
163
|
}
|
|
@@ -206,7 +169,7 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
206
169
|
}
|
|
207
170
|
function trackInteractOutside(nodeOrFn, options) {
|
|
208
171
|
const { defer } = options;
|
|
209
|
-
const func = defer ?
|
|
172
|
+
const func = defer ? import_dom_query2.raf : (v) => v();
|
|
210
173
|
const cleanups = [];
|
|
211
174
|
cleanups.push(
|
|
212
175
|
func(() => {
|
|
@@ -223,5 +186,7 @@ function fireCustomEvent(el, type, init) {
|
|
|
223
186
|
const event = new win.CustomEvent(type, init);
|
|
224
187
|
return el.dispatchEvent(event);
|
|
225
188
|
}
|
|
226
|
-
|
|
227
|
-
exports
|
|
189
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
190
|
+
0 && (module.exports = {
|
|
191
|
+
trackInteractOutside
|
|
192
|
+
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,67 +1,18 @@
|
|
|
1
|
-
import { raf, getDocument, getWindow, isShadowRoot, addDomEvent, isTouchDevice, getEventTarget, isFocusable, isContextMenuEvent, isHTMLElement, contains, isControlledElement, getNearestOverflowAncestor } from '@zag-js/dom-query';
|
|
2
|
-
import { callAll } from '@zag-js/utils';
|
|
3
|
-
|
|
4
|
-
// src/index.ts
|
|
5
|
-
|
|
6
|
-
// src/frame-utils.ts
|
|
7
|
-
function getWindowFrames(win) {
|
|
8
|
-
const frames = {
|
|
9
|
-
each(cb) {
|
|
10
|
-
for (let i = 0; i < win.frames?.length; i += 1) {
|
|
11
|
-
const frame = win.frames[i];
|
|
12
|
-
if (frame) cb(frame);
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
addEventListener(event, listener, options) {
|
|
16
|
-
frames.each((frame) => {
|
|
17
|
-
try {
|
|
18
|
-
frame.document.addEventListener(event, listener, options);
|
|
19
|
-
} catch {
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
return () => {
|
|
23
|
-
try {
|
|
24
|
-
frames.removeEventListener(event, listener, options);
|
|
25
|
-
} catch {
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
},
|
|
29
|
-
removeEventListener(event, listener, options) {
|
|
30
|
-
frames.each((frame) => {
|
|
31
|
-
try {
|
|
32
|
-
frame.document.removeEventListener(event, listener, options);
|
|
33
|
-
} catch {
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
return frames;
|
|
39
|
-
}
|
|
40
|
-
function getParentWindow(win) {
|
|
41
|
-
const parent = win.frameElement != null ? win.parent : null;
|
|
42
|
-
return {
|
|
43
|
-
addEventListener: (event, listener, options) => {
|
|
44
|
-
try {
|
|
45
|
-
parent?.addEventListener(event, listener, options);
|
|
46
|
-
} catch {
|
|
47
|
-
}
|
|
48
|
-
return () => {
|
|
49
|
-
try {
|
|
50
|
-
parent?.removeEventListener(event, listener, options);
|
|
51
|
-
} catch {
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
},
|
|
55
|
-
removeEventListener: (event, listener, options) => {
|
|
56
|
-
try {
|
|
57
|
-
parent?.removeEventListener(event, listener, options);
|
|
58
|
-
} catch {
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
1
|
// src/index.ts
|
|
2
|
+
import { addDomEvent, isContextMenuEvent, isShadowRoot, isTouchDevice } from "@zag-js/dom-query";
|
|
3
|
+
import {
|
|
4
|
+
contains,
|
|
5
|
+
getDocument,
|
|
6
|
+
getEventTarget,
|
|
7
|
+
getNearestOverflowAncestor,
|
|
8
|
+
getWindow,
|
|
9
|
+
isControlledElement,
|
|
10
|
+
isFocusable,
|
|
11
|
+
isHTMLElement,
|
|
12
|
+
raf
|
|
13
|
+
} from "@zag-js/dom-query";
|
|
14
|
+
import { callAll } from "@zag-js/utils";
|
|
15
|
+
import { getParentWindow, getWindowFrames } from "./frame-utils.mjs";
|
|
65
16
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
66
17
|
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
67
18
|
function isComposedPathFocusable(composedPath) {
|
|
@@ -221,5 +172,6 @@ function fireCustomEvent(el, type, init) {
|
|
|
221
172
|
const event = new win.CustomEvent(type, init);
|
|
222
173
|
return el.dispatchEvent(event);
|
|
223
174
|
}
|
|
224
|
-
|
|
225
|
-
|
|
175
|
+
export {
|
|
176
|
+
trackInteractOutside
|
|
177
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/interact-outside",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.35.0",
|
|
4
4
|
"description": "Track interactions or focus outside an element",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@zag-js/
|
|
20
|
-
"@zag-js/
|
|
19
|
+
"@zag-js/utils": "1.35.0",
|
|
20
|
+
"@zag-js/dom-query": "1.35.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"clean-package": "2.2.0"
|