@zag-js/dismissable 0.1.6 → 0.2.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.
@@ -0,0 +1,31 @@
1
+ // ../core/src/functions.ts
2
+ var runIfFn = (v, ...a) => {
3
+ const res = typeof v === "function" ? v(...a) : v;
4
+ return res != null ? res : void 0;
5
+ };
6
+
7
+ // ../core/src/guard.ts
8
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
9
+
10
+ // ../dom/src/listener.ts
11
+ var isRef = (v) => hasProp(v, "current");
12
+ function addDomEvent(target, eventName, handler, options) {
13
+ const node = isRef(target) ? target.current : runIfFn(target);
14
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
15
+ return () => {
16
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
17
+ };
18
+ }
19
+
20
+ // src/escape-keydown.ts
21
+ function trackEscapeKeydown(fn) {
22
+ const handleKeyDown = (event) => {
23
+ if (event.key === "Escape")
24
+ fn == null ? void 0 : fn(event);
25
+ };
26
+ return addDomEvent(document, "keydown", handleKeyDown);
27
+ }
28
+
29
+ export {
30
+ trackEscapeKeydown
31
+ };
@@ -0,0 +1,38 @@
1
+ import {
2
+ getDocument,
3
+ layerStack
4
+ } from "./chunk-PFLX3TD5.mjs";
5
+
6
+ // src/pointer-event-outside.ts
7
+ var originalBodyPointerEvents;
8
+ function assignPointerEventToLayers() {
9
+ layerStack.layers.forEach(({ node }) => {
10
+ node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
11
+ });
12
+ }
13
+ function clearPointerEvent(node) {
14
+ node.style.pointerEvents = "";
15
+ }
16
+ var DATA_ATTR = "data-inert";
17
+ function disablePointerEventsOutside(node) {
18
+ const doc = getDocument(node);
19
+ if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
20
+ originalBodyPointerEvents = document.body.style.pointerEvents;
21
+ doc.body.style.pointerEvents = "none";
22
+ doc.body.setAttribute(DATA_ATTR, "");
23
+ }
24
+ return () => {
25
+ if (layerStack.hasPointerBlockingLayer())
26
+ return;
27
+ doc.body.style.pointerEvents = originalBodyPointerEvents;
28
+ doc.body.removeAttribute(DATA_ATTR);
29
+ if (doc.body.style.length === 0)
30
+ doc.body.removeAttribute("style");
31
+ };
32
+ }
33
+
34
+ export {
35
+ assignPointerEventToLayers,
36
+ clearPointerEvent,
37
+ disablePointerEventsOutside
38
+ };
@@ -0,0 +1,102 @@
1
+ // ../dom/src/query.ts
2
+ function isDocument(el) {
3
+ return el.nodeType === Node.DOCUMENT_NODE;
4
+ }
5
+ function isWindow(value) {
6
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
7
+ }
8
+ function getDocument(el) {
9
+ var _a;
10
+ if (isWindow(el))
11
+ return el.document;
12
+ if (isDocument(el))
13
+ return el;
14
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
15
+ }
16
+ function getEventTarget(event) {
17
+ var _a, _b;
18
+ return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
19
+ }
20
+ function contains(parent, child) {
21
+ if (!parent)
22
+ return false;
23
+ return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
24
+ }
25
+ function isHTMLElement(v) {
26
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
27
+ }
28
+
29
+ // src/layer-stack.ts
30
+ var layerStack = {
31
+ layers: [],
32
+ branches: [],
33
+ count() {
34
+ return this.layers.length;
35
+ },
36
+ pointerBlockingLayers() {
37
+ return this.layers.filter((layer) => layer.pointerBlocking);
38
+ },
39
+ topMostPointerBlockingLayer() {
40
+ return [...this.pointerBlockingLayers()].slice(-1)[0];
41
+ },
42
+ hasPointerBlockingLayer() {
43
+ return this.pointerBlockingLayers().length > 0;
44
+ },
45
+ isBelowPointerBlockingLayer(node) {
46
+ var _a;
47
+ const index = this.indexOf(node);
48
+ const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
49
+ return index < highestBlockingIndex;
50
+ },
51
+ isTopMost(node) {
52
+ const layer = this.layers[this.count() - 1];
53
+ return (layer == null ? void 0 : layer.node) === node;
54
+ },
55
+ getNestedLayers(node) {
56
+ return Array.from(this.layers).slice(this.indexOf(node) + 1);
57
+ },
58
+ isInNestedLayer(node, target) {
59
+ return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
60
+ },
61
+ isInBranch(target) {
62
+ return Array.from(this.branches).some((branch) => contains(branch, target));
63
+ },
64
+ add(layer) {
65
+ this.layers.push(layer);
66
+ },
67
+ addBranch(node) {
68
+ this.branches.push(node);
69
+ },
70
+ remove(node) {
71
+ const index = this.indexOf(node);
72
+ if (index < 0)
73
+ return;
74
+ if (index < this.count() - 1) {
75
+ const _layers = this.getNestedLayers(node);
76
+ _layers.forEach((layer) => layer.dismiss());
77
+ }
78
+ this.layers.splice(index, 1);
79
+ },
80
+ removeBranch(node) {
81
+ const index = this.branches.indexOf(node);
82
+ if (index >= 0)
83
+ this.branches.splice(index, 1);
84
+ },
85
+ indexOf(node) {
86
+ return this.layers.findIndex((layer) => layer.node === node);
87
+ },
88
+ dismiss(node) {
89
+ var _a;
90
+ (_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
91
+ },
92
+ clear() {
93
+ this.remove(this.layers[0].node);
94
+ }
95
+ };
96
+
97
+ export {
98
+ getDocument,
99
+ getEventTarget,
100
+ contains,
101
+ layerStack
102
+ };
@@ -0,0 +1,97 @@
1
+ import {
2
+ trackEscapeKeydown
3
+ } from "./chunk-3ZVQOINJ.mjs";
4
+ import {
5
+ assignPointerEventToLayers,
6
+ clearPointerEvent,
7
+ disablePointerEventsOutside
8
+ } from "./chunk-6YFBZALL.mjs";
9
+ import {
10
+ contains,
11
+ getEventTarget,
12
+ layerStack
13
+ } from "./chunk-PFLX3TD5.mjs";
14
+
15
+ // ../core/src/warning.ts
16
+ function warn(...a) {
17
+ const m = a.length === 1 ? a[0] : a[1];
18
+ const c = a.length === 2 ? a[0] : true;
19
+ if (c && process.env.NODE_ENV !== "production") {
20
+ console.warn(m);
21
+ }
22
+ }
23
+
24
+ // src/dismissable-layer.ts
25
+ import {
26
+ trackInteractOutside
27
+ } from "@zag-js/interact-outside";
28
+ function trackDismissableElement(node, options) {
29
+ if (!node) {
30
+ warn("[@zag-js/dismissable] node is `null` or `undefined`");
31
+ return;
32
+ }
33
+ const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
34
+ const layer = { dismiss: onDismiss, node, pointerBlocking };
35
+ layerStack.add(layer);
36
+ assignPointerEventToLayers();
37
+ function onPointerDownOutside(event) {
38
+ var _a, _b;
39
+ const target = getEventTarget(event.detail.originalEvent);
40
+ if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
41
+ return;
42
+ (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
43
+ (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
44
+ if (event.defaultPrevented)
45
+ return;
46
+ if (debug) {
47
+ console.log("onPointerDownOutside:", event.detail.originalEvent);
48
+ }
49
+ onDismiss == null ? void 0 : onDismiss();
50
+ }
51
+ function onFocusOutside(event) {
52
+ var _a, _b;
53
+ const target = getEventTarget(event.detail.originalEvent);
54
+ if (layerStack.isInBranch(target))
55
+ return;
56
+ (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
57
+ (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
58
+ if (event.defaultPrevented)
59
+ return;
60
+ if (debug) {
61
+ console.log("onFocusOutside:", event.detail.originalEvent);
62
+ }
63
+ onDismiss == null ? void 0 : onDismiss();
64
+ }
65
+ function onEscapeKeyDown(event) {
66
+ var _a;
67
+ if (!layerStack.isTopMost(node))
68
+ return;
69
+ (_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event);
70
+ if (!event.defaultPrevented && onDismiss) {
71
+ event.preventDefault();
72
+ onDismiss();
73
+ }
74
+ }
75
+ function exclude(target) {
76
+ if (!node)
77
+ return false;
78
+ const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
79
+ const _containers = Array.isArray(containers) ? containers : [containers];
80
+ return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
81
+ }
82
+ const cleanups = [
83
+ pointerBlocking ? disablePointerEventsOutside(node) : void 0,
84
+ trackEscapeKeydown(onEscapeKeyDown),
85
+ trackInteractOutside(node, { exclude, onFocusOutside, onPointerDownOutside })
86
+ ];
87
+ return () => {
88
+ layerStack.remove(node);
89
+ assignPointerEventToLayers();
90
+ clearPointerEvent(node);
91
+ cleanups.forEach((fn) => fn == null ? void 0 : fn());
92
+ };
93
+ }
94
+
95
+ export {
96
+ trackDismissableElement
97
+ };
@@ -0,0 +1,15 @@
1
+ import { InteractOutsideHandlers } from '@zag-js/interact-outside';
2
+
3
+ type Container = HTMLElement | null | Array<HTMLElement | null>;
4
+ type DismissableElementHandlers = InteractOutsideHandlers & {
5
+ onEscapeKeyDown?: (event: KeyboardEvent) => void;
6
+ };
7
+ type DismissableElementOptions = DismissableElementHandlers & {
8
+ debug?: boolean;
9
+ pointerBlocking?: boolean;
10
+ onDismiss: () => void;
11
+ exclude?: Container | (() => Container);
12
+ };
13
+ declare function trackDismissableElement(node: HTMLElement | null, options: DismissableElementOptions): (() => void) | undefined;
14
+
15
+ export { DismissableElementHandlers, DismissableElementOptions, trackDismissableElement };
@@ -0,0 +1,261 @@
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/dismissable-layer.ts
21
+ var dismissable_layer_exports = {};
22
+ __export(dismissable_layer_exports, {
23
+ trackDismissableElement: () => trackDismissableElement
24
+ });
25
+ module.exports = __toCommonJS(dismissable_layer_exports);
26
+
27
+ // ../core/src/functions.ts
28
+ var runIfFn = (v, ...a) => {
29
+ const res = typeof v === "function" ? v(...a) : v;
30
+ return res != null ? res : void 0;
31
+ };
32
+
33
+ // ../core/src/guard.ts
34
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
35
+
36
+ // ../core/src/warning.ts
37
+ function warn(...a) {
38
+ const m = a.length === 1 ? a[0] : a[1];
39
+ const c = a.length === 2 ? a[0] : true;
40
+ if (c && process.env.NODE_ENV !== "production") {
41
+ console.warn(m);
42
+ }
43
+ }
44
+
45
+ // ../dom/src/query.ts
46
+ function isDocument(el) {
47
+ return el.nodeType === Node.DOCUMENT_NODE;
48
+ }
49
+ function isWindow(value) {
50
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
51
+ }
52
+ function getDocument(el) {
53
+ var _a;
54
+ if (isWindow(el))
55
+ return el.document;
56
+ if (isDocument(el))
57
+ return el;
58
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
59
+ }
60
+ function getEventTarget(event) {
61
+ var _a, _b;
62
+ return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
63
+ }
64
+ function contains(parent, child) {
65
+ if (!parent)
66
+ return false;
67
+ return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
68
+ }
69
+ function isHTMLElement(v) {
70
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
71
+ }
72
+
73
+ // ../dom/src/listener.ts
74
+ var isRef = (v) => hasProp(v, "current");
75
+ function addDomEvent(target, eventName, handler, options) {
76
+ const node = isRef(target) ? target.current : runIfFn(target);
77
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
78
+ return () => {
79
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
80
+ };
81
+ }
82
+
83
+ // src/dismissable-layer.ts
84
+ var import_interact_outside = require("@zag-js/interact-outside");
85
+
86
+ // src/escape-keydown.ts
87
+ function trackEscapeKeydown(fn) {
88
+ const handleKeyDown = (event) => {
89
+ if (event.key === "Escape")
90
+ fn == null ? void 0 : fn(event);
91
+ };
92
+ return addDomEvent(document, "keydown", handleKeyDown);
93
+ }
94
+
95
+ // src/layer-stack.ts
96
+ var layerStack = {
97
+ layers: [],
98
+ branches: [],
99
+ count() {
100
+ return this.layers.length;
101
+ },
102
+ pointerBlockingLayers() {
103
+ return this.layers.filter((layer) => layer.pointerBlocking);
104
+ },
105
+ topMostPointerBlockingLayer() {
106
+ return [...this.pointerBlockingLayers()].slice(-1)[0];
107
+ },
108
+ hasPointerBlockingLayer() {
109
+ return this.pointerBlockingLayers().length > 0;
110
+ },
111
+ isBelowPointerBlockingLayer(node) {
112
+ var _a;
113
+ const index = this.indexOf(node);
114
+ const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
115
+ return index < highestBlockingIndex;
116
+ },
117
+ isTopMost(node) {
118
+ const layer = this.layers[this.count() - 1];
119
+ return (layer == null ? void 0 : layer.node) === node;
120
+ },
121
+ getNestedLayers(node) {
122
+ return Array.from(this.layers).slice(this.indexOf(node) + 1);
123
+ },
124
+ isInNestedLayer(node, target) {
125
+ return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
126
+ },
127
+ isInBranch(target) {
128
+ return Array.from(this.branches).some((branch) => contains(branch, target));
129
+ },
130
+ add(layer) {
131
+ this.layers.push(layer);
132
+ },
133
+ addBranch(node) {
134
+ this.branches.push(node);
135
+ },
136
+ remove(node) {
137
+ const index = this.indexOf(node);
138
+ if (index < 0)
139
+ return;
140
+ if (index < this.count() - 1) {
141
+ const _layers = this.getNestedLayers(node);
142
+ _layers.forEach((layer) => layer.dismiss());
143
+ }
144
+ this.layers.splice(index, 1);
145
+ },
146
+ removeBranch(node) {
147
+ const index = this.branches.indexOf(node);
148
+ if (index >= 0)
149
+ this.branches.splice(index, 1);
150
+ },
151
+ indexOf(node) {
152
+ return this.layers.findIndex((layer) => layer.node === node);
153
+ },
154
+ dismiss(node) {
155
+ var _a;
156
+ (_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
157
+ },
158
+ clear() {
159
+ this.remove(this.layers[0].node);
160
+ }
161
+ };
162
+
163
+ // src/pointer-event-outside.ts
164
+ var originalBodyPointerEvents;
165
+ function assignPointerEventToLayers() {
166
+ layerStack.layers.forEach(({ node }) => {
167
+ node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
168
+ });
169
+ }
170
+ function clearPointerEvent(node) {
171
+ node.style.pointerEvents = "";
172
+ }
173
+ var DATA_ATTR = "data-inert";
174
+ function disablePointerEventsOutside(node) {
175
+ const doc = getDocument(node);
176
+ if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
177
+ originalBodyPointerEvents = document.body.style.pointerEvents;
178
+ doc.body.style.pointerEvents = "none";
179
+ doc.body.setAttribute(DATA_ATTR, "");
180
+ }
181
+ return () => {
182
+ if (layerStack.hasPointerBlockingLayer())
183
+ return;
184
+ doc.body.style.pointerEvents = originalBodyPointerEvents;
185
+ doc.body.removeAttribute(DATA_ATTR);
186
+ if (doc.body.style.length === 0)
187
+ doc.body.removeAttribute("style");
188
+ };
189
+ }
190
+
191
+ // src/dismissable-layer.ts
192
+ function trackDismissableElement(node, options) {
193
+ if (!node) {
194
+ warn("[@zag-js/dismissable] node is `null` or `undefined`");
195
+ return;
196
+ }
197
+ const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
198
+ const layer = { dismiss: onDismiss, node, pointerBlocking };
199
+ layerStack.add(layer);
200
+ assignPointerEventToLayers();
201
+ function onPointerDownOutside(event) {
202
+ var _a, _b;
203
+ const target = getEventTarget(event.detail.originalEvent);
204
+ if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
205
+ return;
206
+ (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
207
+ (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
208
+ if (event.defaultPrevented)
209
+ return;
210
+ if (debug) {
211
+ console.log("onPointerDownOutside:", event.detail.originalEvent);
212
+ }
213
+ onDismiss == null ? void 0 : onDismiss();
214
+ }
215
+ function onFocusOutside(event) {
216
+ var _a, _b;
217
+ const target = getEventTarget(event.detail.originalEvent);
218
+ if (layerStack.isInBranch(target))
219
+ return;
220
+ (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
221
+ (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
222
+ if (event.defaultPrevented)
223
+ return;
224
+ if (debug) {
225
+ console.log("onFocusOutside:", event.detail.originalEvent);
226
+ }
227
+ onDismiss == null ? void 0 : onDismiss();
228
+ }
229
+ function onEscapeKeyDown(event) {
230
+ var _a;
231
+ if (!layerStack.isTopMost(node))
232
+ return;
233
+ (_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event);
234
+ if (!event.defaultPrevented && onDismiss) {
235
+ event.preventDefault();
236
+ onDismiss();
237
+ }
238
+ }
239
+ function exclude(target) {
240
+ if (!node)
241
+ return false;
242
+ const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
243
+ const _containers = Array.isArray(containers) ? containers : [containers];
244
+ return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
245
+ }
246
+ const cleanups = [
247
+ pointerBlocking ? disablePointerEventsOutside(node) : void 0,
248
+ trackEscapeKeydown(onEscapeKeyDown),
249
+ (0, import_interact_outside.trackInteractOutside)(node, { exclude, onFocusOutside, onPointerDownOutside })
250
+ ];
251
+ return () => {
252
+ layerStack.remove(node);
253
+ assignPointerEventToLayers();
254
+ clearPointerEvent(node);
255
+ cleanups.forEach((fn) => fn == null ? void 0 : fn());
256
+ };
257
+ }
258
+ // Annotate the CommonJS export names for ESM import in node:
259
+ 0 && (module.exports = {
260
+ trackDismissableElement
261
+ });
@@ -0,0 +1,9 @@
1
+ import {
2
+ trackDismissableElement
3
+ } from "./chunk-PYR5T5VL.mjs";
4
+ import "./chunk-3ZVQOINJ.mjs";
5
+ import "./chunk-6YFBZALL.mjs";
6
+ import "./chunk-PFLX3TD5.mjs";
7
+ export {
8
+ trackDismissableElement
9
+ };
@@ -0,0 +1,3 @@
1
+ declare function trackEscapeKeydown(fn?: (event: KeyboardEvent) => void): () => void;
2
+
3
+ export { trackEscapeKeydown };
@@ -0,0 +1,57 @@
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/escape-keydown.ts
21
+ var escape_keydown_exports = {};
22
+ __export(escape_keydown_exports, {
23
+ trackEscapeKeydown: () => trackEscapeKeydown
24
+ });
25
+ module.exports = __toCommonJS(escape_keydown_exports);
26
+
27
+ // ../core/src/functions.ts
28
+ var runIfFn = (v, ...a) => {
29
+ const res = typeof v === "function" ? v(...a) : v;
30
+ return res != null ? res : void 0;
31
+ };
32
+
33
+ // ../core/src/guard.ts
34
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
35
+
36
+ // ../dom/src/listener.ts
37
+ var isRef = (v) => hasProp(v, "current");
38
+ function addDomEvent(target, eventName, handler, options) {
39
+ const node = isRef(target) ? target.current : runIfFn(target);
40
+ node == null ? void 0 : node.addEventListener(eventName, handler, options);
41
+ return () => {
42
+ node == null ? void 0 : node.removeEventListener(eventName, handler, options);
43
+ };
44
+ }
45
+
46
+ // src/escape-keydown.ts
47
+ function trackEscapeKeydown(fn) {
48
+ const handleKeyDown = (event) => {
49
+ if (event.key === "Escape")
50
+ fn == null ? void 0 : fn(event);
51
+ };
52
+ return addDomEvent(document, "keydown", handleKeyDown);
53
+ }
54
+ // Annotate the CommonJS export names for ESM import in node:
55
+ 0 && (module.exports = {
56
+ trackEscapeKeydown
57
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ trackEscapeKeydown
3
+ } from "./chunk-3ZVQOINJ.mjs";
4
+ export {
5
+ trackEscapeKeydown
6
+ };
package/dist/index.d.ts CHANGED
@@ -1,15 +1,2 @@
1
- import { InteractOutsideHandlers } from '@zag-js/interact-outside';
2
-
3
- declare type Container = HTMLElement | null | Array<HTMLElement | null>;
4
- declare type DismissableElementHandlers = InteractOutsideHandlers & {
5
- onEscapeKeyDown?: (event: KeyboardEvent) => void;
6
- };
7
- declare type DismissableElementOptions = DismissableElementHandlers & {
8
- debug?: boolean;
9
- pointerBlocking?: boolean;
10
- onDismiss: () => void;
11
- exclude?: Container | (() => Container);
12
- };
13
- declare function trackDismissableElement(node: HTMLElement | null, options: DismissableElementOptions): (() => void) | undefined;
14
-
15
- export { DismissableElementHandlers, DismissableElementOptions, trackDismissableElement };
1
+ export { DismissableElementHandlers, DismissableElementOptions, trackDismissableElement } from './dismissable-layer.js';
2
+ import '@zag-js/interact-outside';
package/dist/index.js CHANGED
@@ -24,12 +24,25 @@ __export(src_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(src_exports);
26
26
 
27
- // ../dom/dist/index.mjs
27
+ // ../core/src/functions.ts
28
28
  var runIfFn = (v, ...a) => {
29
29
  const res = typeof v === "function" ? v(...a) : v;
30
- return res ?? void 0;
30
+ return res != null ? res : void 0;
31
31
  };
32
+
33
+ // ../core/src/guard.ts
32
34
  var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
35
+
36
+ // ../core/src/warning.ts
37
+ function warn(...a) {
38
+ const m = a.length === 1 ? a[0] : a[1];
39
+ const c = a.length === 2 ? a[0] : true;
40
+ if (c && process.env.NODE_ENV !== "production") {
41
+ console.warn(m);
42
+ }
43
+ }
44
+
45
+ // ../dom/src/query.ts
33
46
  function isDocument(el) {
34
47
  return el.nodeType === Node.DOCUMENT_NODE;
35
48
  }
@@ -37,15 +50,16 @@ function isWindow(value) {
37
50
  return (value == null ? void 0 : value.toString()) === "[object Window]";
38
51
  }
39
52
  function getDocument(el) {
53
+ var _a;
40
54
  if (isWindow(el))
41
55
  return el.document;
42
56
  if (isDocument(el))
43
57
  return el;
44
- return (el == null ? void 0 : el.ownerDocument) ?? document;
58
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
45
59
  }
46
60
  function getEventTarget(event) {
47
- var _a;
48
- return ((_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) ?? event.target;
61
+ var _a, _b;
62
+ return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
49
63
  }
50
64
  function contains(parent, child) {
51
65
  if (!parent)
@@ -55,6 +69,8 @@ function contains(parent, child) {
55
69
  function isHTMLElement(v) {
56
70
  return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
57
71
  }
72
+
73
+ // ../dom/src/listener.ts
58
74
  var isRef = (v) => hasProp(v, "current");
59
75
  function addDomEvent(target, eventName, handler, options) {
60
76
  const node = isRef(target) ? target.current : runIfFn(target);
@@ -67,15 +83,6 @@ function addDomEvent(target, eventName, handler, options) {
67
83
  // src/dismissable-layer.ts
68
84
  var import_interact_outside = require("@zag-js/interact-outside");
69
85
 
70
- // ../core/dist/index.mjs
71
- function warn(...a) {
72
- const m = a.length === 1 ? a[0] : a[1];
73
- const c = a.length === 2 ? a[0] : true;
74
- if (c && process.env.NODE_ENV !== "production") {
75
- console.warn(m);
76
- }
77
- }
78
-
79
86
  // src/escape-keydown.ts
80
87
  function trackEscapeKeydown(fn) {
81
88
  const handleKeyDown = (event) => {
package/dist/index.mjs CHANGED
@@ -1,229 +1,9 @@
1
- // ../dom/dist/index.mjs
2
- var runIfFn = (v, ...a) => {
3
- const res = typeof v === "function" ? v(...a) : v;
4
- return res ?? void 0;
5
- };
6
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
7
- function isDocument(el) {
8
- return el.nodeType === Node.DOCUMENT_NODE;
9
- }
10
- function isWindow(value) {
11
- return (value == null ? void 0 : value.toString()) === "[object Window]";
12
- }
13
- function getDocument(el) {
14
- if (isWindow(el))
15
- return el.document;
16
- if (isDocument(el))
17
- return el;
18
- return (el == null ? void 0 : el.ownerDocument) ?? document;
19
- }
20
- function getEventTarget(event) {
21
- var _a;
22
- return ((_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) ?? event.target;
23
- }
24
- function contains(parent, child) {
25
- if (!parent)
26
- return false;
27
- return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
28
- }
29
- function isHTMLElement(v) {
30
- return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
31
- }
32
- var isRef = (v) => hasProp(v, "current");
33
- function addDomEvent(target, eventName, handler, options) {
34
- const node = isRef(target) ? target.current : runIfFn(target);
35
- node == null ? void 0 : node.addEventListener(eventName, handler, options);
36
- return () => {
37
- node == null ? void 0 : node.removeEventListener(eventName, handler, options);
38
- };
39
- }
40
-
41
- // src/dismissable-layer.ts
42
1
  import {
43
- trackInteractOutside
44
- } from "@zag-js/interact-outside";
45
-
46
- // ../core/dist/index.mjs
47
- function warn(...a) {
48
- const m = a.length === 1 ? a[0] : a[1];
49
- const c = a.length === 2 ? a[0] : true;
50
- if (c && process.env.NODE_ENV !== "production") {
51
- console.warn(m);
52
- }
53
- }
54
-
55
- // src/escape-keydown.ts
56
- function trackEscapeKeydown(fn) {
57
- const handleKeyDown = (event) => {
58
- if (event.key === "Escape")
59
- fn == null ? void 0 : fn(event);
60
- };
61
- return addDomEvent(document, "keydown", handleKeyDown);
62
- }
63
-
64
- // src/layer-stack.ts
65
- var layerStack = {
66
- layers: [],
67
- branches: [],
68
- count() {
69
- return this.layers.length;
70
- },
71
- pointerBlockingLayers() {
72
- return this.layers.filter((layer) => layer.pointerBlocking);
73
- },
74
- topMostPointerBlockingLayer() {
75
- return [...this.pointerBlockingLayers()].slice(-1)[0];
76
- },
77
- hasPointerBlockingLayer() {
78
- return this.pointerBlockingLayers().length > 0;
79
- },
80
- isBelowPointerBlockingLayer(node) {
81
- var _a;
82
- const index = this.indexOf(node);
83
- const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
84
- return index < highestBlockingIndex;
85
- },
86
- isTopMost(node) {
87
- const layer = this.layers[this.count() - 1];
88
- return (layer == null ? void 0 : layer.node) === node;
89
- },
90
- getNestedLayers(node) {
91
- return Array.from(this.layers).slice(this.indexOf(node) + 1);
92
- },
93
- isInNestedLayer(node, target) {
94
- return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
95
- },
96
- isInBranch(target) {
97
- return Array.from(this.branches).some((branch) => contains(branch, target));
98
- },
99
- add(layer) {
100
- this.layers.push(layer);
101
- },
102
- addBranch(node) {
103
- this.branches.push(node);
104
- },
105
- remove(node) {
106
- const index = this.indexOf(node);
107
- if (index < 0)
108
- return;
109
- if (index < this.count() - 1) {
110
- const _layers = this.getNestedLayers(node);
111
- _layers.forEach((layer) => layer.dismiss());
112
- }
113
- this.layers.splice(index, 1);
114
- },
115
- removeBranch(node) {
116
- const index = this.branches.indexOf(node);
117
- if (index >= 0)
118
- this.branches.splice(index, 1);
119
- },
120
- indexOf(node) {
121
- return this.layers.findIndex((layer) => layer.node === node);
122
- },
123
- dismiss(node) {
124
- var _a;
125
- (_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
126
- },
127
- clear() {
128
- this.remove(this.layers[0].node);
129
- }
130
- };
131
-
132
- // src/pointer-event-outside.ts
133
- var originalBodyPointerEvents;
134
- function assignPointerEventToLayers() {
135
- layerStack.layers.forEach(({ node }) => {
136
- node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
137
- });
138
- }
139
- function clearPointerEvent(node) {
140
- node.style.pointerEvents = "";
141
- }
142
- var DATA_ATTR = "data-inert";
143
- function disablePointerEventsOutside(node) {
144
- const doc = getDocument(node);
145
- if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
146
- originalBodyPointerEvents = document.body.style.pointerEvents;
147
- doc.body.style.pointerEvents = "none";
148
- doc.body.setAttribute(DATA_ATTR, "");
149
- }
150
- return () => {
151
- if (layerStack.hasPointerBlockingLayer())
152
- return;
153
- doc.body.style.pointerEvents = originalBodyPointerEvents;
154
- doc.body.removeAttribute(DATA_ATTR);
155
- if (doc.body.style.length === 0)
156
- doc.body.removeAttribute("style");
157
- };
158
- }
159
-
160
- // src/dismissable-layer.ts
161
- function trackDismissableElement(node, options) {
162
- if (!node) {
163
- warn("[@zag-js/dismissable] node is `null` or `undefined`");
164
- return;
165
- }
166
- const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
167
- const layer = { dismiss: onDismiss, node, pointerBlocking };
168
- layerStack.add(layer);
169
- assignPointerEventToLayers();
170
- function onPointerDownOutside(event) {
171
- var _a, _b;
172
- const target = getEventTarget(event.detail.originalEvent);
173
- if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
174
- return;
175
- (_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
176
- (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
177
- if (event.defaultPrevented)
178
- return;
179
- if (debug) {
180
- console.log("onPointerDownOutside:", event.detail.originalEvent);
181
- }
182
- onDismiss == null ? void 0 : onDismiss();
183
- }
184
- function onFocusOutside(event) {
185
- var _a, _b;
186
- const target = getEventTarget(event.detail.originalEvent);
187
- if (layerStack.isInBranch(target))
188
- return;
189
- (_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
190
- (_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
191
- if (event.defaultPrevented)
192
- return;
193
- if (debug) {
194
- console.log("onFocusOutside:", event.detail.originalEvent);
195
- }
196
- onDismiss == null ? void 0 : onDismiss();
197
- }
198
- function onEscapeKeyDown(event) {
199
- var _a;
200
- if (!layerStack.isTopMost(node))
201
- return;
202
- (_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event);
203
- if (!event.defaultPrevented && onDismiss) {
204
- event.preventDefault();
205
- onDismiss();
206
- }
207
- }
208
- function exclude(target) {
209
- if (!node)
210
- return false;
211
- const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
212
- const _containers = Array.isArray(containers) ? containers : [containers];
213
- return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
214
- }
215
- const cleanups = [
216
- pointerBlocking ? disablePointerEventsOutside(node) : void 0,
217
- trackEscapeKeydown(onEscapeKeyDown),
218
- trackInteractOutside(node, { exclude, onFocusOutside, onPointerDownOutside })
219
- ];
220
- return () => {
221
- layerStack.remove(node);
222
- assignPointerEventToLayers();
223
- clearPointerEvent(node);
224
- cleanups.forEach((fn) => fn == null ? void 0 : fn());
225
- };
226
- }
2
+ trackDismissableElement
3
+ } from "./chunk-PYR5T5VL.mjs";
4
+ import "./chunk-3ZVQOINJ.mjs";
5
+ import "./chunk-6YFBZALL.mjs";
6
+ import "./chunk-PFLX3TD5.mjs";
227
7
  export {
228
8
  trackDismissableElement
229
9
  };
@@ -0,0 +1,27 @@
1
+ type Layer = {
2
+ dismiss: VoidFunction;
3
+ node: HTMLElement;
4
+ pointerBlocking?: boolean;
5
+ };
6
+ declare const layerStack: {
7
+ layers: Layer[];
8
+ branches: HTMLElement[];
9
+ count(): number;
10
+ pointerBlockingLayers(): Layer[];
11
+ topMostPointerBlockingLayer(): Layer | undefined;
12
+ hasPointerBlockingLayer(): boolean;
13
+ isBelowPointerBlockingLayer(node: HTMLElement): boolean;
14
+ isTopMost(node: HTMLElement | null): boolean;
15
+ getNestedLayers(node: HTMLElement): Layer[];
16
+ isInNestedLayer(node: HTMLElement, target: HTMLElement | EventTarget | null): boolean;
17
+ isInBranch(target: HTMLElement | EventTarget | null): boolean;
18
+ add(layer: Layer): void;
19
+ addBranch(node: HTMLElement): void;
20
+ remove(node: HTMLElement): void;
21
+ removeBranch(node: HTMLElement): void;
22
+ indexOf(node: HTMLElement | undefined): number;
23
+ dismiss(node: HTMLElement): void;
24
+ clear(): void;
25
+ };
26
+
27
+ export { Layer, layerStack };
@@ -0,0 +1,107 @@
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/layer-stack.ts
21
+ var layer_stack_exports = {};
22
+ __export(layer_stack_exports, {
23
+ layerStack: () => layerStack
24
+ });
25
+ module.exports = __toCommonJS(layer_stack_exports);
26
+
27
+ // ../dom/src/query.ts
28
+ function contains(parent, child) {
29
+ if (!parent)
30
+ return false;
31
+ return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
32
+ }
33
+ function isHTMLElement(v) {
34
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
35
+ }
36
+
37
+ // src/layer-stack.ts
38
+ var layerStack = {
39
+ layers: [],
40
+ branches: [],
41
+ count() {
42
+ return this.layers.length;
43
+ },
44
+ pointerBlockingLayers() {
45
+ return this.layers.filter((layer) => layer.pointerBlocking);
46
+ },
47
+ topMostPointerBlockingLayer() {
48
+ return [...this.pointerBlockingLayers()].slice(-1)[0];
49
+ },
50
+ hasPointerBlockingLayer() {
51
+ return this.pointerBlockingLayers().length > 0;
52
+ },
53
+ isBelowPointerBlockingLayer(node) {
54
+ var _a;
55
+ const index = this.indexOf(node);
56
+ const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
57
+ return index < highestBlockingIndex;
58
+ },
59
+ isTopMost(node) {
60
+ const layer = this.layers[this.count() - 1];
61
+ return (layer == null ? void 0 : layer.node) === node;
62
+ },
63
+ getNestedLayers(node) {
64
+ return Array.from(this.layers).slice(this.indexOf(node) + 1);
65
+ },
66
+ isInNestedLayer(node, target) {
67
+ return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
68
+ },
69
+ isInBranch(target) {
70
+ return Array.from(this.branches).some((branch) => contains(branch, target));
71
+ },
72
+ add(layer) {
73
+ this.layers.push(layer);
74
+ },
75
+ addBranch(node) {
76
+ this.branches.push(node);
77
+ },
78
+ remove(node) {
79
+ const index = this.indexOf(node);
80
+ if (index < 0)
81
+ return;
82
+ if (index < this.count() - 1) {
83
+ const _layers = this.getNestedLayers(node);
84
+ _layers.forEach((layer) => layer.dismiss());
85
+ }
86
+ this.layers.splice(index, 1);
87
+ },
88
+ removeBranch(node) {
89
+ const index = this.branches.indexOf(node);
90
+ if (index >= 0)
91
+ this.branches.splice(index, 1);
92
+ },
93
+ indexOf(node) {
94
+ return this.layers.findIndex((layer) => layer.node === node);
95
+ },
96
+ dismiss(node) {
97
+ var _a;
98
+ (_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
99
+ },
100
+ clear() {
101
+ this.remove(this.layers[0].node);
102
+ }
103
+ };
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ layerStack
107
+ });
@@ -0,0 +1,6 @@
1
+ import {
2
+ layerStack
3
+ } from "./chunk-PFLX3TD5.mjs";
4
+ export {
5
+ layerStack
6
+ };
@@ -0,0 +1,5 @@
1
+ declare function assignPointerEventToLayers(): void;
2
+ declare function clearPointerEvent(node: HTMLElement): void;
3
+ declare function disablePointerEventsOutside(node: HTMLElement): () => void;
4
+
5
+ export { assignPointerEventToLayers, clearPointerEvent, disablePointerEventsOutside };
@@ -0,0 +1,153 @@
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/pointer-event-outside.ts
21
+ var pointer_event_outside_exports = {};
22
+ __export(pointer_event_outside_exports, {
23
+ assignPointerEventToLayers: () => assignPointerEventToLayers,
24
+ clearPointerEvent: () => clearPointerEvent,
25
+ disablePointerEventsOutside: () => disablePointerEventsOutside
26
+ });
27
+ module.exports = __toCommonJS(pointer_event_outside_exports);
28
+
29
+ // ../dom/src/query.ts
30
+ function isDocument(el) {
31
+ return el.nodeType === Node.DOCUMENT_NODE;
32
+ }
33
+ function isWindow(value) {
34
+ return (value == null ? void 0 : value.toString()) === "[object Window]";
35
+ }
36
+ function getDocument(el) {
37
+ var _a;
38
+ if (isWindow(el))
39
+ return el.document;
40
+ if (isDocument(el))
41
+ return el;
42
+ return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
43
+ }
44
+ function contains(parent, child) {
45
+ if (!parent)
46
+ return false;
47
+ return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
48
+ }
49
+ function isHTMLElement(v) {
50
+ return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
51
+ }
52
+
53
+ // src/layer-stack.ts
54
+ var layerStack = {
55
+ layers: [],
56
+ branches: [],
57
+ count() {
58
+ return this.layers.length;
59
+ },
60
+ pointerBlockingLayers() {
61
+ return this.layers.filter((layer) => layer.pointerBlocking);
62
+ },
63
+ topMostPointerBlockingLayer() {
64
+ return [...this.pointerBlockingLayers()].slice(-1)[0];
65
+ },
66
+ hasPointerBlockingLayer() {
67
+ return this.pointerBlockingLayers().length > 0;
68
+ },
69
+ isBelowPointerBlockingLayer(node) {
70
+ var _a;
71
+ const index = this.indexOf(node);
72
+ const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
73
+ return index < highestBlockingIndex;
74
+ },
75
+ isTopMost(node) {
76
+ const layer = this.layers[this.count() - 1];
77
+ return (layer == null ? void 0 : layer.node) === node;
78
+ },
79
+ getNestedLayers(node) {
80
+ return Array.from(this.layers).slice(this.indexOf(node) + 1);
81
+ },
82
+ isInNestedLayer(node, target) {
83
+ return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
84
+ },
85
+ isInBranch(target) {
86
+ return Array.from(this.branches).some((branch) => contains(branch, target));
87
+ },
88
+ add(layer) {
89
+ this.layers.push(layer);
90
+ },
91
+ addBranch(node) {
92
+ this.branches.push(node);
93
+ },
94
+ remove(node) {
95
+ const index = this.indexOf(node);
96
+ if (index < 0)
97
+ return;
98
+ if (index < this.count() - 1) {
99
+ const _layers = this.getNestedLayers(node);
100
+ _layers.forEach((layer) => layer.dismiss());
101
+ }
102
+ this.layers.splice(index, 1);
103
+ },
104
+ removeBranch(node) {
105
+ const index = this.branches.indexOf(node);
106
+ if (index >= 0)
107
+ this.branches.splice(index, 1);
108
+ },
109
+ indexOf(node) {
110
+ return this.layers.findIndex((layer) => layer.node === node);
111
+ },
112
+ dismiss(node) {
113
+ var _a;
114
+ (_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
115
+ },
116
+ clear() {
117
+ this.remove(this.layers[0].node);
118
+ }
119
+ };
120
+
121
+ // src/pointer-event-outside.ts
122
+ var originalBodyPointerEvents;
123
+ function assignPointerEventToLayers() {
124
+ layerStack.layers.forEach(({ node }) => {
125
+ node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
126
+ });
127
+ }
128
+ function clearPointerEvent(node) {
129
+ node.style.pointerEvents = "";
130
+ }
131
+ var DATA_ATTR = "data-inert";
132
+ function disablePointerEventsOutside(node) {
133
+ const doc = getDocument(node);
134
+ if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
135
+ originalBodyPointerEvents = document.body.style.pointerEvents;
136
+ doc.body.style.pointerEvents = "none";
137
+ doc.body.setAttribute(DATA_ATTR, "");
138
+ }
139
+ return () => {
140
+ if (layerStack.hasPointerBlockingLayer())
141
+ return;
142
+ doc.body.style.pointerEvents = originalBodyPointerEvents;
143
+ doc.body.removeAttribute(DATA_ATTR);
144
+ if (doc.body.style.length === 0)
145
+ doc.body.removeAttribute("style");
146
+ };
147
+ }
148
+ // Annotate the CommonJS export names for ESM import in node:
149
+ 0 && (module.exports = {
150
+ assignPointerEventToLayers,
151
+ clearPointerEvent,
152
+ disablePointerEventsOutside
153
+ });
@@ -0,0 +1,11 @@
1
+ import {
2
+ assignPointerEventToLayers,
3
+ clearPointerEvent,
4
+ disablePointerEventsOutside
5
+ } from "./chunk-6YFBZALL.mjs";
6
+ import "./chunk-PFLX3TD5.mjs";
7
+ export {
8
+ assignPointerEventToLayers,
9
+ clearPointerEvent,
10
+ disablePointerEventsOutside
11
+ };
package/package.json CHANGED
@@ -1,10 +1,7 @@
1
1
  {
2
2
  "name": "@zag-js/dismissable",
3
- "version": "0.1.6",
3
+ "version": "0.2.1",
4
4
  "description": "Dismissable layer utilities for the DOM",
5
- "main": "dist/index.js",
6
- "module": "dist/index.mjs",
7
- "types": "dist/index.d.ts",
8
5
  "keywords": [
9
6
  "js",
10
7
  "utils",
@@ -26,19 +23,32 @@
26
23
  "access": "public"
27
24
  },
28
25
  "dependencies": {
29
- "@zag-js/interact-outside": "0.1.6"
26
+ "@zag-js/interact-outside": "0.2.1"
30
27
  },
31
28
  "devDependencies": {
32
- "@zag-js/dom-utils": "0.1.13",
33
- "@zag-js/utils": "0.1.6"
29
+ "clean-package": "2.2.0",
30
+ "@zag-js/dom-utils": "0.2.2",
31
+ "@zag-js/utils": "0.3.2"
34
32
  },
35
33
  "bugs": {
36
34
  "url": "https://github.com/chakra-ui/zag/issues"
37
35
  },
36
+ "clean-package": "../../../clean-package.config.json",
37
+ "main": "dist/index.js",
38
+ "module": "dist/index.mjs",
39
+ "types": "dist/index.d.ts",
40
+ "exports": {
41
+ ".": {
42
+ "types": "./dist/index.d.ts",
43
+ "import": "./dist/index.mjs",
44
+ "require": "./dist/index.js"
45
+ },
46
+ "./package.json": "./package.json"
47
+ },
38
48
  "scripts": {
39
- "build-fast": "tsup src/index.ts --format=esm,cjs",
49
+ "build-fast": "tsup src",
40
50
  "start": "pnpm build --watch",
41
- "build": "tsup src/index.ts --format=esm,cjs --dts",
51
+ "build": "tsup src --dts",
42
52
  "test": "jest --config ../../../jest.config.js --rootDir tests",
43
53
  "lint": "eslint src --ext .ts,.tsx",
44
54
  "test-ci": "pnpm test --ci --runInBand -u",