@zag-js/dismissable 1.42.0 → 1.43.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.
|
@@ -59,9 +59,9 @@ interface DismissableElementOptions extends DismissableElementHandlers, Persiste
|
|
|
59
59
|
*/
|
|
60
60
|
type?: LayerType | undefined;
|
|
61
61
|
}
|
|
62
|
-
declare function trackDismissableElement(nodeOrFn: NodeOrFn, options: DismissableElementOptions):
|
|
62
|
+
declare function trackDismissableElement(nodeOrFn: NodeOrFn, options: DismissableElementOptions): VoidFunction;
|
|
63
63
|
declare function trackDismissableBranch(nodeOrFn: NodeOrFn, options?: {
|
|
64
64
|
defer?: boolean | undefined;
|
|
65
|
-
}):
|
|
65
|
+
}): VoidFunction;
|
|
66
66
|
|
|
67
67
|
export { type DismissableElementHandlers, type DismissableElementOptions, type PersistentElementOptions, trackDismissableBranch, trackDismissableElement };
|
|
@@ -59,9 +59,9 @@ interface DismissableElementOptions extends DismissableElementHandlers, Persiste
|
|
|
59
59
|
*/
|
|
60
60
|
type?: LayerType | undefined;
|
|
61
61
|
}
|
|
62
|
-
declare function trackDismissableElement(nodeOrFn: NodeOrFn, options: DismissableElementOptions):
|
|
62
|
+
declare function trackDismissableElement(nodeOrFn: NodeOrFn, options: DismissableElementOptions): VoidFunction;
|
|
63
63
|
declare function trackDismissableBranch(nodeOrFn: NodeOrFn, options?: {
|
|
64
64
|
defer?: boolean | undefined;
|
|
65
|
-
}):
|
|
65
|
+
}): VoidFunction;
|
|
66
66
|
|
|
67
67
|
export { type DismissableElementHandlers, type DismissableElementOptions, type PersistentElementOptions, trackDismissableBranch, trackDismissableElement };
|
|
@@ -31,14 +31,6 @@ var import_escape_keydown = require("./escape-keydown.js");
|
|
|
31
31
|
var import_layer_stack = require("./layer-stack.js");
|
|
32
32
|
var import_pointer_event_outside = require("./pointer-event-outside.js");
|
|
33
33
|
function trackDismissableElementImpl(node, options) {
|
|
34
|
-
const { warnOnMissingNode = true } = options;
|
|
35
|
-
if (warnOnMissingNode && !node) {
|
|
36
|
-
(0, import_utils.warn)("[@zag-js/dismissable] node is `null` or `undefined`");
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
if (!node) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
34
|
const {
|
|
43
35
|
onDismiss,
|
|
44
36
|
onRequestDismiss,
|
|
@@ -89,7 +81,6 @@ function trackDismissableElementImpl(node, options) {
|
|
|
89
81
|
}
|
|
90
82
|
}
|
|
91
83
|
function exclude(target) {
|
|
92
|
-
if (!node) return false;
|
|
93
84
|
const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
|
|
94
85
|
const _containers = Array.isArray(containers) ? containers : [containers];
|
|
95
86
|
const persistentElements = options.persistentElements?.map((fn) => fn()).filter(import_dom_query.isHTMLElement);
|
|
@@ -109,39 +100,26 @@ function trackDismissableElementImpl(node, options) {
|
|
|
109
100
|
};
|
|
110
101
|
}
|
|
111
102
|
function trackDismissableElement(nodeOrFn, options) {
|
|
112
|
-
const {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
const node = (0, import_utils.isFunction)(nodeOrFn) ? nodeOrFn() : nodeOrFn;
|
|
118
|
-
cleanups.push(trackDismissableElementImpl(node, options));
|
|
119
|
-
})
|
|
120
|
-
);
|
|
121
|
-
return () => {
|
|
122
|
-
cleanups.forEach((fn) => fn?.());
|
|
123
|
-
};
|
|
103
|
+
const { warnOnMissingNode = true } = options;
|
|
104
|
+
return (0, import_dom_query.whenNode)(nodeOrFn, (node) => trackDismissableElementImpl(node, options), {
|
|
105
|
+
defer: options.defer,
|
|
106
|
+
onMissing: warnOnMissingNode ? () => (0, import_utils.warn)("[@zag-js/dismissable] node is `null` or `undefined`") : void 0
|
|
107
|
+
});
|
|
124
108
|
}
|
|
125
109
|
function trackDismissableBranch(nodeOrFn, options = {}) {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
cleanups.push(
|
|
130
|
-
func(() => {
|
|
131
|
-
const node = (0, import_utils.isFunction)(nodeOrFn) ? nodeOrFn() : nodeOrFn;
|
|
132
|
-
if (!node) {
|
|
133
|
-
(0, import_utils.warn)("[@zag-js/dismissable] branch node is `null` or `undefined`");
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
110
|
+
return (0, import_dom_query.whenNode)(
|
|
111
|
+
nodeOrFn,
|
|
112
|
+
(node) => {
|
|
136
113
|
import_layer_stack.layerStack.addBranch(node);
|
|
137
|
-
|
|
114
|
+
return () => {
|
|
138
115
|
import_layer_stack.layerStack.removeBranch(node);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
116
|
+
};
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
defer: options.defer,
|
|
120
|
+
onMissing: () => (0, import_utils.warn)("[@zag-js/dismissable] branch node is `null` or `undefined`")
|
|
121
|
+
}
|
|
141
122
|
);
|
|
142
|
-
return () => {
|
|
143
|
-
cleanups.forEach((fn) => fn?.());
|
|
144
|
-
};
|
|
145
123
|
}
|
|
146
124
|
// Annotate the CommonJS export names for ESM import in node:
|
|
147
125
|
0 && (module.exports = {
|
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
// src/dismissable-layer.ts
|
|
2
|
-
import { contains, getEventTarget, isHTMLElement,
|
|
2
|
+
import { contains, getEventTarget, isHTMLElement, whenNode } from "@zag-js/dom-query";
|
|
3
3
|
import {
|
|
4
4
|
trackInteractOutside
|
|
5
5
|
} from "@zag-js/interact-outside";
|
|
6
|
-
import {
|
|
6
|
+
import { warn } from "@zag-js/utils";
|
|
7
7
|
import { trackEscapeKeydown } from "./escape-keydown.mjs";
|
|
8
8
|
import { layerStack } from "./layer-stack.mjs";
|
|
9
9
|
import { assignPointerEventToLayers, clearPointerEvent, disablePointerEventsOutside } from "./pointer-event-outside.mjs";
|
|
10
10
|
function trackDismissableElementImpl(node, options) {
|
|
11
|
-
const { warnOnMissingNode = true } = options;
|
|
12
|
-
if (warnOnMissingNode && !node) {
|
|
13
|
-
warn("[@zag-js/dismissable] node is `null` or `undefined`");
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
if (!node) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
11
|
const {
|
|
20
12
|
onDismiss,
|
|
21
13
|
onRequestDismiss,
|
|
@@ -66,7 +58,6 @@ function trackDismissableElementImpl(node, options) {
|
|
|
66
58
|
}
|
|
67
59
|
}
|
|
68
60
|
function exclude(target) {
|
|
69
|
-
if (!node) return false;
|
|
70
61
|
const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
|
|
71
62
|
const _containers = Array.isArray(containers) ? containers : [containers];
|
|
72
63
|
const persistentElements = options.persistentElements?.map((fn) => fn()).filter(isHTMLElement);
|
|
@@ -86,39 +77,26 @@ function trackDismissableElementImpl(node, options) {
|
|
|
86
77
|
};
|
|
87
78
|
}
|
|
88
79
|
function trackDismissableElement(nodeOrFn, options) {
|
|
89
|
-
const {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const node = isFunction(nodeOrFn) ? nodeOrFn() : nodeOrFn;
|
|
95
|
-
cleanups.push(trackDismissableElementImpl(node, options));
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
return () => {
|
|
99
|
-
cleanups.forEach((fn) => fn?.());
|
|
100
|
-
};
|
|
80
|
+
const { warnOnMissingNode = true } = options;
|
|
81
|
+
return whenNode(nodeOrFn, (node) => trackDismissableElementImpl(node, options), {
|
|
82
|
+
defer: options.defer,
|
|
83
|
+
onMissing: warnOnMissingNode ? () => warn("[@zag-js/dismissable] node is `null` or `undefined`") : void 0
|
|
84
|
+
});
|
|
101
85
|
}
|
|
102
86
|
function trackDismissableBranch(nodeOrFn, options = {}) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
cleanups.push(
|
|
107
|
-
func(() => {
|
|
108
|
-
const node = isFunction(nodeOrFn) ? nodeOrFn() : nodeOrFn;
|
|
109
|
-
if (!node) {
|
|
110
|
-
warn("[@zag-js/dismissable] branch node is `null` or `undefined`");
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
87
|
+
return whenNode(
|
|
88
|
+
nodeOrFn,
|
|
89
|
+
(node) => {
|
|
113
90
|
layerStack.addBranch(node);
|
|
114
|
-
|
|
91
|
+
return () => {
|
|
115
92
|
layerStack.removeBranch(node);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
93
|
+
};
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
defer: options.defer,
|
|
97
|
+
onMissing: () => warn("[@zag-js/dismissable] branch node is `null` or `undefined`")
|
|
98
|
+
}
|
|
118
99
|
);
|
|
119
|
-
return () => {
|
|
120
|
-
cleanups.forEach((fn) => fn?.());
|
|
121
|
-
};
|
|
122
100
|
}
|
|
123
101
|
export {
|
|
124
102
|
trackDismissableBranch,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/dismissable",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.43.1",
|
|
4
4
|
"description": "Dismissable layer utilities for the DOM",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -26,9 +26,9 @@
|
|
|
26
26
|
"access": "public"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@zag-js/interact-outside": "1.
|
|
30
|
-
"@zag-js/dom-query": "1.
|
|
31
|
-
"@zag-js/utils": "1.
|
|
29
|
+
"@zag-js/interact-outside": "1.43.1",
|
|
30
|
+
"@zag-js/dom-query": "1.43.1",
|
|
31
|
+
"@zag-js/utils": "1.43.1"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"clean-package": "2.2.0"
|