@zag-js/interact-outside 0.6.0 → 0.9.1
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.d.ts +4 -1
- package/dist/index.js +15 -1
- package/dist/index.mjs +16 -2
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ type InteractOutsideHandlers = {
|
|
|
5
5
|
};
|
|
6
6
|
type InteractOutsideOptions = InteractOutsideHandlers & {
|
|
7
7
|
exclude?: (target: HTMLElement) => boolean;
|
|
8
|
+
defer?: boolean;
|
|
8
9
|
};
|
|
9
10
|
type EventDetails<T> = {
|
|
10
11
|
originalEvent: T;
|
|
@@ -14,6 +15,8 @@ type EventDetails<T> = {
|
|
|
14
15
|
type PointerDownOutsideEvent = CustomEvent<EventDetails<PointerEvent>>;
|
|
15
16
|
type FocusOutsideEvent = CustomEvent<EventDetails<FocusEvent>>;
|
|
16
17
|
type InteractOutsideEvent = PointerDownOutsideEvent | FocusOutsideEvent;
|
|
17
|
-
|
|
18
|
+
type MaybeElement = HTMLElement | null | undefined;
|
|
19
|
+
type NodeOrFn = MaybeElement | (() => MaybeElement);
|
|
20
|
+
declare function trackInteractOutside(nodeOrFn: NodeOrFn, options: InteractOutsideOptions): () => void;
|
|
18
21
|
|
|
19
22
|
export { FocusOutsideEvent, InteractOutsideEvent, InteractOutsideHandlers, InteractOutsideOptions, PointerDownOutsideEvent, trackInteractOutside };
|
package/dist/index.js
CHANGED
|
@@ -78,7 +78,7 @@ function isComposedPathFocusable(event) {
|
|
|
78
78
|
}
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
|
-
function
|
|
81
|
+
function trackInteractOutsideImpl(node, options) {
|
|
82
82
|
const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
|
|
83
83
|
if (!node)
|
|
84
84
|
return;
|
|
@@ -157,6 +157,20 @@ function trackInteractOutside(node, options) {
|
|
|
157
157
|
cleanups.forEach((fn) => fn());
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
|
+
function trackInteractOutside(nodeOrFn, options) {
|
|
161
|
+
const { defer } = options;
|
|
162
|
+
const func = defer ? import_dom_query.raf : (v) => v();
|
|
163
|
+
const cleanups = [];
|
|
164
|
+
cleanups.push(
|
|
165
|
+
func(() => {
|
|
166
|
+
const node = typeof nodeOrFn === "function" ? nodeOrFn() : nodeOrFn;
|
|
167
|
+
cleanups.push(trackInteractOutsideImpl(node, options));
|
|
168
|
+
})
|
|
169
|
+
);
|
|
170
|
+
return () => {
|
|
171
|
+
cleanups.forEach((fn) => fn?.());
|
|
172
|
+
};
|
|
173
|
+
}
|
|
160
174
|
// Annotate the CommonJS export names for ESM import in node:
|
|
161
175
|
0 && (module.exports = {
|
|
162
176
|
trackInteractOutside
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/index.ts
|
|
6
6
|
import { addDomEvent, fireCustomEvent, isContextMenuEvent } from "@zag-js/dom-event";
|
|
7
|
-
import { contains, getDocument, getEventTarget, getWindow, isHTMLElement } from "@zag-js/dom-query";
|
|
7
|
+
import { contains, getDocument, getEventTarget, getWindow, isHTMLElement, raf } from "@zag-js/dom-query";
|
|
8
8
|
import { isFocusable } from "@zag-js/tabbable";
|
|
9
9
|
import { callAll } from "@zag-js/utils";
|
|
10
10
|
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
@@ -17,7 +17,7 @@ function isComposedPathFocusable(event) {
|
|
|
17
17
|
}
|
|
18
18
|
return false;
|
|
19
19
|
}
|
|
20
|
-
function
|
|
20
|
+
function trackInteractOutsideImpl(node, options) {
|
|
21
21
|
const { exclude, onFocusOutside, onPointerDownOutside, onInteractOutside } = options;
|
|
22
22
|
if (!node)
|
|
23
23
|
return;
|
|
@@ -96,6 +96,20 @@ function trackInteractOutside(node, options) {
|
|
|
96
96
|
cleanups.forEach((fn) => fn());
|
|
97
97
|
};
|
|
98
98
|
}
|
|
99
|
+
function trackInteractOutside(nodeOrFn, options) {
|
|
100
|
+
const { defer } = options;
|
|
101
|
+
const func = defer ? raf : (v) => v();
|
|
102
|
+
const cleanups = [];
|
|
103
|
+
cleanups.push(
|
|
104
|
+
func(() => {
|
|
105
|
+
const node = typeof nodeOrFn === "function" ? nodeOrFn() : nodeOrFn;
|
|
106
|
+
cleanups.push(trackInteractOutsideImpl(node, options));
|
|
107
|
+
})
|
|
108
|
+
);
|
|
109
|
+
return () => {
|
|
110
|
+
cleanups.forEach((fn) => fn?.());
|
|
111
|
+
};
|
|
112
|
+
}
|
|
99
113
|
export {
|
|
100
114
|
trackInteractOutside
|
|
101
115
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/interact-outside",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.1",
|
|
4
4
|
"description": "Track interations or focus outside an element",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"dist/**/*"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@zag-js/dom-query": "0.1
|
|
20
|
-
"@zag-js/dom-event": "0.
|
|
21
|
-
"@zag-js/tabbable": "0.
|
|
22
|
-
"@zag-js/utils": "0.
|
|
19
|
+
"@zag-js/dom-query": "0.9.1",
|
|
20
|
+
"@zag-js/dom-event": "0.9.1",
|
|
21
|
+
"@zag-js/tabbable": "0.9.1",
|
|
22
|
+
"@zag-js/utils": "0.9.1"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"clean-package": "2.2.0"
|