@zag-js/dismissable 1.46.0 → 1.48.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/dismissable-layer.d.mts +61 -61
- package/dist/dismissable-layer.d.ts +61 -61
- package/dist/dismissable-layer.js +93 -121
- package/dist/dismissable-layer.mjs +86 -95
- package/dist/escape-keydown.d.mts +1 -3
- package/dist/escape-keydown.d.ts +1 -3
- package/dist/escape-keydown.js +12 -35
- package/dist/escape-keydown.mjs +8 -10
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +6 -23
- package/dist/index.mjs +1 -2
- package/dist/layer-stack.d.mts +45 -43
- package/dist/layer-stack.d.ts +45 -43
- package/dist/layer-stack.js +155 -173
- package/dist/layer-stack.mjs +151 -148
- package/dist/pointer-event-outside.d.mts +3 -5
- package/dist/pointer-event-outside.d.ts +3 -5
- package/dist/pointer-event-outside.js +70 -97
- package/dist/pointer-event-outside.mjs +64 -70
- package/package.json +6 -6
package/dist/layer-stack.js
CHANGED
|
@@ -1,183 +1,165 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
5
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
6
|
+
// src/layer-stack.ts
|
|
7
|
+
const LAYER_REQUEST_DISMISS_EVENT = "layer:request-dismiss";
|
|
8
|
+
const layerStack = {
|
|
9
|
+
layers: [],
|
|
10
|
+
branches: [],
|
|
11
|
+
recentlyRemoved: /* @__PURE__ */ new Set(),
|
|
12
|
+
count() {
|
|
13
|
+
return this.layers.length;
|
|
14
|
+
},
|
|
15
|
+
pointerBlockingLayers() {
|
|
16
|
+
return this.layers.filter((layer) => layer.pointerBlocking);
|
|
17
|
+
},
|
|
18
|
+
topMostPointerBlockingLayer() {
|
|
19
|
+
return [...this.pointerBlockingLayers()].slice(-1)[0];
|
|
20
|
+
},
|
|
21
|
+
hasPointerBlockingLayer() {
|
|
22
|
+
return this.pointerBlockingLayers().length > 0;
|
|
23
|
+
},
|
|
24
|
+
isBelowPointerBlockingLayer(node) {
|
|
25
|
+
return this.indexOf(node) < (this.topMostPointerBlockingLayer() ? this.indexOf(this.topMostPointerBlockingLayer()?.node) : -1);
|
|
26
|
+
},
|
|
27
|
+
isTopMost(node) {
|
|
28
|
+
return this.layers[this.count() - 1]?.node === node;
|
|
29
|
+
},
|
|
30
|
+
getNestedLayers(node) {
|
|
31
|
+
const nested = /* @__PURE__ */ new Set([node]);
|
|
32
|
+
return this.layers.slice(this.indexOf(node) + 1).filter((layer) => {
|
|
33
|
+
if (!layer.parent || !nested.has(layer.parent)) return false;
|
|
34
|
+
nested.add(layer.node);
|
|
35
|
+
return true;
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
getLayersByType(type) {
|
|
39
|
+
return this.layers.filter((layer) => layer.type === type);
|
|
40
|
+
},
|
|
41
|
+
getNestedLayersByType(node, type) {
|
|
42
|
+
if (this.indexOf(node) === -1) return [];
|
|
43
|
+
return this.getNestedLayers(node).filter((layer) => layer.type === type);
|
|
44
|
+
},
|
|
45
|
+
getParentLayerOfType(node, type) {
|
|
46
|
+
let parent = this.layers[this.indexOf(node)]?.parent;
|
|
47
|
+
while (parent) {
|
|
48
|
+
const layer = this.layers[this.indexOf(parent)];
|
|
49
|
+
if (layer?.type === type) return layer;
|
|
50
|
+
parent = layer?.parent;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
countNestedLayersOfType(node, type) {
|
|
54
|
+
return this.getNestedLayersByType(node, type).length;
|
|
55
|
+
},
|
|
56
|
+
isInNestedLayer(node, target) {
|
|
57
|
+
if (this.getNestedLayers(node).some((layer) => (0, _zag_js_dom_query.contains)(layer.node, target))) return true;
|
|
58
|
+
if (this.recentlyRemoved.size > 0) return true;
|
|
59
|
+
return false;
|
|
60
|
+
},
|
|
61
|
+
isInBranch(target) {
|
|
62
|
+
return Array.from(this.branches).some((branch) => (0, _zag_js_dom_query.contains)(branch, target));
|
|
63
|
+
},
|
|
64
|
+
add(layer) {
|
|
65
|
+
const existingIndex = this.indexOf(layer.node);
|
|
66
|
+
if (existingIndex !== -1) {
|
|
67
|
+
layer.parent = this.layers[existingIndex].parent;
|
|
68
|
+
this.layers[existingIndex] = layer;
|
|
69
|
+
} else {
|
|
70
|
+
layer.parent = this.getParentNode(layer);
|
|
71
|
+
this.layers.push(layer);
|
|
72
|
+
}
|
|
73
|
+
this.syncLayers();
|
|
74
|
+
},
|
|
75
|
+
getParentNode(layer) {
|
|
76
|
+
const origins = layer.origins?.filter((origin) => origin?.isConnected);
|
|
77
|
+
if (!origins?.length) return this.layers[this.count() - 1]?.node;
|
|
78
|
+
return [...this.layers].reverse().find(({ node }) => origins.some((origin) => (0, _zag_js_dom_query.contains)(node, origin)))?.node;
|
|
79
|
+
},
|
|
80
|
+
addBranch(node) {
|
|
81
|
+
this.branches.push(node);
|
|
82
|
+
},
|
|
83
|
+
remove(node) {
|
|
84
|
+
const index = this.indexOf(node);
|
|
85
|
+
if (index < 0) return;
|
|
86
|
+
const layer = this.layers[index];
|
|
87
|
+
layer.styleTargets?.forEach((getTarget) => {
|
|
88
|
+
const target = getTarget();
|
|
89
|
+
if (target) clearLayerStyleMirror(target);
|
|
90
|
+
});
|
|
91
|
+
this.recentlyRemoved.add(node);
|
|
92
|
+
(0, _zag_js_dom_query.nextTick)(() => this.recentlyRemoved.delete(node));
|
|
93
|
+
if (index < this.count() - 1) this.getNestedLayers(node).forEach((layer) => layerStack.dismiss(layer.node, node));
|
|
94
|
+
this.layers.forEach((child) => {
|
|
95
|
+
if (child.parent === node) child.parent = layer.parent;
|
|
96
|
+
});
|
|
97
|
+
this.layers.splice(index, 1);
|
|
98
|
+
this.syncLayers();
|
|
99
|
+
},
|
|
100
|
+
removeBranch(node) {
|
|
101
|
+
const index = this.branches.indexOf(node);
|
|
102
|
+
if (index >= 0) this.branches.splice(index, 1);
|
|
103
|
+
},
|
|
104
|
+
syncLayers() {
|
|
105
|
+
this.layers.forEach((layer, index) => {
|
|
106
|
+
applyLayerStackMetadata(layer, index, layer.node);
|
|
107
|
+
layer.styleTargets?.forEach((getTarget) => {
|
|
108
|
+
const target = getTarget();
|
|
109
|
+
if (!target || target === layer.node) return;
|
|
110
|
+
applyLayerStackMetadata(layer, index, target);
|
|
111
|
+
const { zIndex } = (0, _zag_js_dom_query.getComputedStyle)(layer.node);
|
|
112
|
+
target.style.setProperty("--z-index", zIndex);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
indexOf(node) {
|
|
117
|
+
return this.layers.findIndex((layer) => layer.node === node);
|
|
118
|
+
},
|
|
119
|
+
dismiss(node, parent) {
|
|
120
|
+
const index = this.indexOf(node);
|
|
121
|
+
if (index === -1) return;
|
|
122
|
+
const layer = this.layers[index];
|
|
123
|
+
addListenerOnce(node, LAYER_REQUEST_DISMISS_EVENT, (event) => {
|
|
124
|
+
layer.requestDismiss?.(event);
|
|
125
|
+
if (!event.defaultPrevented) layer?.dismiss();
|
|
126
|
+
});
|
|
127
|
+
fireCustomEvent(node, LAYER_REQUEST_DISMISS_EVENT, {
|
|
128
|
+
originalLayer: node,
|
|
129
|
+
targetLayer: parent,
|
|
130
|
+
originalIndex: index,
|
|
131
|
+
targetIndex: parent ? this.indexOf(parent) : -1
|
|
132
|
+
});
|
|
133
|
+
this.syncLayers();
|
|
134
|
+
},
|
|
135
|
+
clear() {
|
|
136
|
+
this.remove(this.layers[0].node);
|
|
137
|
+
}
|
|
151
138
|
};
|
|
152
139
|
function applyLayerStackMetadata(layer, index, el) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const nestedCount = layerStack.countNestedLayersOfType(layer.node, layer.type);
|
|
161
|
-
if (nestedCount > 0) {
|
|
162
|
-
el.setAttribute("data-has-nested", layer.type);
|
|
163
|
-
}
|
|
164
|
-
el.style.setProperty("--nested-layer-count", `${nestedCount}`);
|
|
140
|
+
el.style.setProperty("--layer-index", `${index}`);
|
|
141
|
+
el.removeAttribute("data-nested");
|
|
142
|
+
el.removeAttribute("data-has-nested");
|
|
143
|
+
if (layerStack.getParentLayerOfType(layer.node, layer.type)) el.setAttribute("data-nested", layer.type);
|
|
144
|
+
const nestedCount = layerStack.countNestedLayersOfType(layer.node, layer.type);
|
|
145
|
+
if (nestedCount > 0) el.setAttribute("data-has-nested", layer.type);
|
|
146
|
+
el.style.setProperty("--nested-layer-count", `${nestedCount}`);
|
|
165
147
|
}
|
|
166
148
|
function clearLayerStyleMirror(el) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
149
|
+
el.style.removeProperty("--layer-index");
|
|
150
|
+
el.style.removeProperty("--nested-layer-count");
|
|
151
|
+
el.removeAttribute("data-nested");
|
|
152
|
+
el.removeAttribute("data-has-nested");
|
|
171
153
|
}
|
|
172
154
|
function fireCustomEvent(el, type, detail) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
155
|
+
const event = new (el.ownerDocument.defaultView || window).CustomEvent(type, {
|
|
156
|
+
cancelable: true,
|
|
157
|
+
bubbles: true,
|
|
158
|
+
detail
|
|
159
|
+
});
|
|
160
|
+
return el.dispatchEvent(event);
|
|
176
161
|
}
|
|
177
162
|
function addListenerOnce(el, type, callback) {
|
|
178
|
-
|
|
163
|
+
el.addEventListener(type, callback, { once: true });
|
|
179
164
|
}
|
|
180
|
-
|
|
181
|
-
0 && (module.exports = {
|
|
182
|
-
layerStack
|
|
183
|
-
});
|
|
165
|
+
exports.layerStack = layerStack;
|