@zag-js/dismissable 0.5.0 → 0.8.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.
|
@@ -11,12 +11,12 @@ import {
|
|
|
11
11
|
} from "./chunk-G4GHYT27.mjs";
|
|
12
12
|
|
|
13
13
|
// src/dismissable-layer.ts
|
|
14
|
-
import { contains, getEventTarget } from "@zag-js/dom-query";
|
|
14
|
+
import { contains, getEventTarget, raf } from "@zag-js/dom-query";
|
|
15
15
|
import {
|
|
16
16
|
trackInteractOutside
|
|
17
17
|
} from "@zag-js/interact-outside";
|
|
18
18
|
import { warn } from "@zag-js/utils";
|
|
19
|
-
function
|
|
19
|
+
function trackDismissableElementImpl(node, options) {
|
|
20
20
|
if (!node) {
|
|
21
21
|
warn("[@zag-js/dismissable] node is `null` or `undefined`");
|
|
22
22
|
return;
|
|
@@ -79,6 +79,20 @@ function trackDismissableElement(node, options) {
|
|
|
79
79
|
cleanups.forEach((fn) => fn?.());
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
|
+
function trackDismissableElement(nodeOrFn, options) {
|
|
83
|
+
const { defer } = options;
|
|
84
|
+
const func = defer ? raf : (v) => v();
|
|
85
|
+
const cleanups = [];
|
|
86
|
+
cleanups.push(
|
|
87
|
+
func(() => {
|
|
88
|
+
const node = typeof nodeOrFn === "function" ? nodeOrFn() : nodeOrFn;
|
|
89
|
+
cleanups.push(trackDismissableElementImpl(node, options));
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
return () => {
|
|
93
|
+
cleanups.forEach((fn) => fn?.());
|
|
94
|
+
};
|
|
95
|
+
}
|
|
82
96
|
|
|
83
97
|
export {
|
|
84
98
|
trackDismissableElement
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { InteractOutsideHandlers } from '@zag-js/interact-outside';
|
|
2
2
|
|
|
3
|
-
type
|
|
3
|
+
type MaybeElement = HTMLElement | null;
|
|
4
|
+
type Container = MaybeElement | Array<MaybeElement>;
|
|
5
|
+
type NodeOrFn = MaybeElement | (() => MaybeElement);
|
|
4
6
|
type DismissableElementHandlers = InteractOutsideHandlers & {
|
|
5
7
|
onEscapeKeyDown?: (event: KeyboardEvent) => void;
|
|
6
8
|
};
|
|
@@ -9,7 +11,8 @@ type DismissableElementOptions = DismissableElementHandlers & {
|
|
|
9
11
|
pointerBlocking?: boolean;
|
|
10
12
|
onDismiss: () => void;
|
|
11
13
|
exclude?: Container | (() => Container);
|
|
14
|
+
defer?: boolean;
|
|
12
15
|
};
|
|
13
|
-
declare function trackDismissableElement(
|
|
16
|
+
declare function trackDismissableElement(nodeOrFn: NodeOrFn, options: DismissableElementOptions): () => void;
|
|
14
17
|
|
|
15
18
|
export { DismissableElementHandlers, DismissableElementOptions, trackDismissableElement };
|
|
@@ -135,7 +135,7 @@ function disablePointerEventsOutside(node) {
|
|
|
135
135
|
}
|
|
136
136
|
|
|
137
137
|
// src/dismissable-layer.ts
|
|
138
|
-
function
|
|
138
|
+
function trackDismissableElementImpl(node, options) {
|
|
139
139
|
if (!node) {
|
|
140
140
|
(0, import_utils.warn)("[@zag-js/dismissable] node is `null` or `undefined`");
|
|
141
141
|
return;
|
|
@@ -198,6 +198,20 @@ function trackDismissableElement(node, options) {
|
|
|
198
198
|
cleanups.forEach((fn) => fn?.());
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
+
function trackDismissableElement(nodeOrFn, options) {
|
|
202
|
+
const { defer } = options;
|
|
203
|
+
const func = defer ? import_dom_query4.raf : (v) => v();
|
|
204
|
+
const cleanups = [];
|
|
205
|
+
cleanups.push(
|
|
206
|
+
func(() => {
|
|
207
|
+
const node = typeof nodeOrFn === "function" ? nodeOrFn() : nodeOrFn;
|
|
208
|
+
cleanups.push(trackDismissableElementImpl(node, options));
|
|
209
|
+
})
|
|
210
|
+
);
|
|
211
|
+
return () => {
|
|
212
|
+
cleanups.forEach((fn) => fn?.());
|
|
213
|
+
};
|
|
214
|
+
}
|
|
201
215
|
// Annotate the CommonJS export names for ESM import in node:
|
|
202
216
|
0 && (module.exports = {
|
|
203
217
|
trackDismissableElement
|
package/dist/index.js
CHANGED
|
@@ -137,7 +137,7 @@ function disablePointerEventsOutside(node) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
// src/dismissable-layer.ts
|
|
140
|
-
function
|
|
140
|
+
function trackDismissableElementImpl(node, options) {
|
|
141
141
|
if (!node) {
|
|
142
142
|
(0, import_utils.warn)("[@zag-js/dismissable] node is `null` or `undefined`");
|
|
143
143
|
return;
|
|
@@ -200,6 +200,20 @@ function trackDismissableElement(node, options) {
|
|
|
200
200
|
cleanups.forEach((fn) => fn?.());
|
|
201
201
|
};
|
|
202
202
|
}
|
|
203
|
+
function trackDismissableElement(nodeOrFn, options) {
|
|
204
|
+
const { defer } = options;
|
|
205
|
+
const func = defer ? import_dom_query4.raf : (v) => v();
|
|
206
|
+
const cleanups = [];
|
|
207
|
+
cleanups.push(
|
|
208
|
+
func(() => {
|
|
209
|
+
const node = typeof nodeOrFn === "function" ? nodeOrFn() : nodeOrFn;
|
|
210
|
+
cleanups.push(trackDismissableElementImpl(node, options));
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
return () => {
|
|
214
|
+
cleanups.forEach((fn) => fn?.());
|
|
215
|
+
};
|
|
216
|
+
}
|
|
203
217
|
// Annotate the CommonJS export names for ESM import in node:
|
|
204
218
|
0 && (module.exports = {
|
|
205
219
|
trackDismissableElement
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/dismissable",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Dismissable layer utilities for the DOM",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@zag-js/interact-outside": "0.5.0",
|
|
27
26
|
"@zag-js/dom-query": "0.1.4",
|
|
28
|
-
"@zag-js/dom-event": "0.
|
|
27
|
+
"@zag-js/dom-event": "0.8.0",
|
|
28
|
+
"@zag-js/interact-outside": "0.8.0",
|
|
29
29
|
"@zag-js/utils": "0.3.4"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|