@zag-js/interact-outside 0.80.0 → 0.81.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/index.js +11 -7
- package/dist/index.mjs +6 -2
- package/package.json +3 -4
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var domEvent = require('@zag-js/dom-event');
|
|
4
3
|
var domQuery = require('@zag-js/dom-query');
|
|
5
4
|
var utils = require('@zag-js/utils');
|
|
6
5
|
|
|
@@ -135,12 +134,12 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
135
134
|
const handler2 = utils.callAll(onPointerDownOutside, onInteractOutside);
|
|
136
135
|
node.addEventListener(POINTER_OUTSIDE_EVENT, handler2, { once: true });
|
|
137
136
|
}
|
|
138
|
-
|
|
137
|
+
fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
|
|
139
138
|
bubbles: false,
|
|
140
139
|
cancelable: true,
|
|
141
140
|
detail: {
|
|
142
141
|
originalEvent: event,
|
|
143
|
-
contextmenu:
|
|
142
|
+
contextmenu: domQuery.isContextMenuEvent(event),
|
|
144
143
|
focusable: isComposedPathFocusable(composedPath)
|
|
145
144
|
}
|
|
146
145
|
});
|
|
@@ -148,7 +147,7 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
148
147
|
}
|
|
149
148
|
if (event.pointerType === "touch") {
|
|
150
149
|
pointerdownCleanups.forEach((fn) => fn());
|
|
151
|
-
pointerdownCleanups.add(
|
|
150
|
+
pointerdownCleanups.add(domQuery.addDomEvent(doc, "click", handler, { once: true }));
|
|
152
151
|
pointerdownCleanups.add(parentWin.addEventListener("click", handler, { once: true }));
|
|
153
152
|
pointerdownCleanups.add(frames.addEventListener("click", handler, { once: true }));
|
|
154
153
|
} else {
|
|
@@ -157,7 +156,7 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
157
156
|
}
|
|
158
157
|
const cleanups = /* @__PURE__ */ new Set();
|
|
159
158
|
const timer = setTimeout(() => {
|
|
160
|
-
cleanups.add(
|
|
159
|
+
cleanups.add(domQuery.addDomEvent(doc, "pointerdown", onPointerDown, true));
|
|
161
160
|
cleanups.add(parentWin.addEventListener("pointerdown", onPointerDown, true));
|
|
162
161
|
cleanups.add(frames.addEventListener("pointerdown", onPointerDown, true));
|
|
163
162
|
}, 0);
|
|
@@ -169,7 +168,7 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
169
168
|
const handler = utils.callAll(onFocusOutside, onInteractOutside);
|
|
170
169
|
node.addEventListener(FOCUS_OUTSIDE_EVENT, handler, { once: true });
|
|
171
170
|
}
|
|
172
|
-
|
|
171
|
+
fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
|
|
173
172
|
bubbles: false,
|
|
174
173
|
cancelable: true,
|
|
175
174
|
detail: {
|
|
@@ -180,7 +179,7 @@ function trackInteractOutsideImpl(node, options) {
|
|
|
180
179
|
});
|
|
181
180
|
});
|
|
182
181
|
}
|
|
183
|
-
cleanups.add(
|
|
182
|
+
cleanups.add(domQuery.addDomEvent(doc, "focusin", onFocusin, true));
|
|
184
183
|
cleanups.add(parentWin.addEventListener("focusin", onFocusin, true));
|
|
185
184
|
cleanups.add(frames.addEventListener("focusin", onFocusin, true));
|
|
186
185
|
return () => {
|
|
@@ -203,5 +202,10 @@ function trackInteractOutside(nodeOrFn, options) {
|
|
|
203
202
|
cleanups.forEach((fn) => fn?.());
|
|
204
203
|
};
|
|
205
204
|
}
|
|
205
|
+
function fireCustomEvent(el, type, init) {
|
|
206
|
+
const win = el.ownerDocument.defaultView || window;
|
|
207
|
+
const event = new win.CustomEvent(type, init);
|
|
208
|
+
return el.dispatchEvent(event);
|
|
209
|
+
}
|
|
206
210
|
|
|
207
211
|
exports.trackInteractOutside = trackInteractOutside;
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { addDomEvent,
|
|
2
|
-
import { getDocument, getWindow, raf, isFocusable, getEventTarget, isHTMLElement, contains, getNearestOverflowAncestor } from '@zag-js/dom-query';
|
|
1
|
+
import { getDocument, getWindow, addDomEvent, raf, isFocusable, getEventTarget, isHTMLElement, contains, getNearestOverflowAncestor, isContextMenuEvent } from '@zag-js/dom-query';
|
|
3
2
|
import { callAll } from '@zag-js/utils';
|
|
4
3
|
|
|
5
4
|
// src/index.ts
|
|
@@ -201,5 +200,10 @@ function trackInteractOutside(nodeOrFn, options) {
|
|
|
201
200
|
cleanups.forEach((fn) => fn?.());
|
|
202
201
|
};
|
|
203
202
|
}
|
|
203
|
+
function fireCustomEvent(el, type, init) {
|
|
204
|
+
const win = el.ownerDocument.defaultView || window;
|
|
205
|
+
const event = new win.CustomEvent(type, init);
|
|
206
|
+
return el.dispatchEvent(event);
|
|
207
|
+
}
|
|
204
208
|
|
|
205
209
|
export { trackInteractOutside };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/interact-outside",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.81.0",
|
|
4
4
|
"description": "Track interactions or focus outside an element",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@zag-js/dom-query": "0.
|
|
20
|
-
"@zag-js/
|
|
21
|
-
"@zag-js/utils": "0.80.0"
|
|
19
|
+
"@zag-js/dom-query": "0.81.0",
|
|
20
|
+
"@zag-js/utils": "0.81.0"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"clean-package": "2.2.0"
|