@zag-js/dismissable 2.0.0-next.3 → 2.0.0-next.4
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/dismiss-reason.d.mts +4 -0
- package/dist/dismiss-reason.d.ts +4 -0
- package/dist/dismiss-reason.js +12 -0
- package/dist/dismiss-reason.mjs +8 -0
- package/dist/dismissable-layer.d.mts +63 -61
- package/dist/dismissable-layer.d.ts +63 -61
- package/dist/dismissable-layer.js +96 -120
- package/dist/dismissable-layer.mjs +89 -98
- 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 +7 -6
- package/dist/index.d.ts +7 -6
- package/dist/index.js +14 -34
- package/dist/index.mjs +4 -6
- package/dist/layer-props.d.mts +17 -27
- package/dist/layer-props.d.ts +17 -27
- package/dist/layer-props.js +17 -44
- package/dist/layer-props.mjs +12 -18
- package/dist/layer-stack.d.mts +72 -71
- package/dist/layer-stack.d.ts +72 -71
- package/dist/layer-stack.js +219 -230
- package/dist/layer-stack.mjs +213 -203
- package/dist/pointer-event-outside.d.mts +2 -4
- package/dist/pointer-event-outside.d.ts +2 -4
- package/dist/pointer-event-outside.js +53 -75
- package/dist/pointer-event-outside.mjs +48 -49
- package/package.json +5 -5
package/dist/layer-stack.mjs
CHANGED
|
@@ -1,212 +1,222 @@
|
|
|
1
|
-
// src/layer-stack.ts
|
|
2
1
|
import { contains, nextTick } from "@zag-js/dom-query";
|
|
3
2
|
import { isEqual } from "@zag-js/utils";
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
// src/layer-stack.ts
|
|
4
|
+
const LAYER_REQUEST_DISMISS_EVENT = "layer:request-dismiss";
|
|
5
|
+
let layerId = 0;
|
|
6
|
+
let cancelClosingAncestors;
|
|
7
|
+
/** Resolved on read, so a layer's blocking can change without re-registering it. */
|
|
6
8
|
function isPointerBlocking(layer) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
+
const value = layer.pointerBlocking;
|
|
10
|
+
return typeof value === "function" ? value() : !!value;
|
|
11
|
+
}
|
|
12
|
+
function indexById(layers) {
|
|
13
|
+
const byId = /* @__PURE__ */ new Map();
|
|
14
|
+
for (const layer of layers) if (layer.id && !byId.has(layer.id)) byId.set(layer.id, layer);
|
|
15
|
+
return byId;
|
|
9
16
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
17
|
+
/** Ancestor ids, nearest first. Stops at a cycle. */
|
|
18
|
+
function* ancestorIds(layer, byId) {
|
|
19
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20
|
+
let parentId = layer.parentId;
|
|
21
|
+
while (parentId && !seen.has(parentId)) {
|
|
22
|
+
seen.add(parentId);
|
|
23
|
+
yield parentId;
|
|
24
|
+
parentId = byId.get(parentId)?.parentId;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const layerStack = {
|
|
28
|
+
layers: [],
|
|
29
|
+
branches: [],
|
|
30
|
+
/** Ids of layers whose descendant just closed. */
|
|
31
|
+
closingAncestors: /* @__PURE__ */ new Set(),
|
|
32
|
+
/** Descendants queued to close with their ancestor. A new layer can't nest in them. */
|
|
33
|
+
dismissing: /* @__PURE__ */ new WeakSet(),
|
|
34
|
+
pendingReattach: /* @__PURE__ */ new Map(),
|
|
35
|
+
count() {
|
|
36
|
+
return this.layers.length;
|
|
37
|
+
},
|
|
38
|
+
topMostPointerBlockingIndex() {
|
|
39
|
+
for (let i = this.count() - 1; i >= 0; i--) if (isPointerBlocking(this.layers[i])) return i;
|
|
40
|
+
return -1;
|
|
41
|
+
},
|
|
42
|
+
topMostPointerBlockingLayer() {
|
|
43
|
+
return this.layers[this.topMostPointerBlockingIndex()];
|
|
44
|
+
},
|
|
45
|
+
hasPointerBlockingLayer() {
|
|
46
|
+
return this.topMostPointerBlockingIndex() !== -1;
|
|
47
|
+
},
|
|
48
|
+
isBelowPointerBlockingLayer(node) {
|
|
49
|
+
return this.indexOf(node) < this.topMostPointerBlockingIndex();
|
|
50
|
+
},
|
|
51
|
+
isTopMost(node) {
|
|
52
|
+
return this.layers[this.count() - 1]?.node === node;
|
|
53
|
+
},
|
|
54
|
+
layerFor(node) {
|
|
55
|
+
return this.layers.find((layer) => layer.node === node);
|
|
56
|
+
},
|
|
57
|
+
parentFor(layer) {
|
|
58
|
+
const origins = layer.origins?.filter(Boolean);
|
|
59
|
+
for (let i = this.count() - 1; i >= 0; i--) {
|
|
60
|
+
const candidate = this.layers[i];
|
|
61
|
+
if (this.dismissing.has(candidate.node)) continue;
|
|
62
|
+
if (!origins || origins.some((origin) => contains(candidate.node, origin))) return candidate;
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
/** Top-level layers that opened from inside the new layer become its children. */
|
|
66
|
+
adopt(layer) {
|
|
67
|
+
if (!layer.origins) return [];
|
|
68
|
+
const adopted = this.layers.filter((other) => !other.parentId && other.origins?.some((origin) => origin && origin !== layer.node && contains(layer.node, origin)));
|
|
69
|
+
adopted.forEach((child) => child.parentId = layer.id);
|
|
70
|
+
return adopted;
|
|
71
|
+
},
|
|
72
|
+
/** The most recently added layer in the same group, if any. */
|
|
73
|
+
peerFor(group) {
|
|
74
|
+
for (let i = this.count() - 1; i >= 0; i--) if (this.layers[i].group === group) return this.layers[i];
|
|
75
|
+
},
|
|
76
|
+
/** Descendants, shallowest first, so a cascade dismisses parents before their own children. */
|
|
77
|
+
getNestedLayers(node) {
|
|
78
|
+
const id = this.layerFor(node)?.id;
|
|
79
|
+
if (!id) return [];
|
|
80
|
+
const byId = indexById(this.layers);
|
|
81
|
+
const depth = /* @__PURE__ */ new Map();
|
|
82
|
+
for (const layer of this.layers) {
|
|
83
|
+
let level = 0;
|
|
84
|
+
for (const ancestorId of ancestorIds(layer, byId)) {
|
|
85
|
+
level++;
|
|
86
|
+
if (ancestorId !== id) continue;
|
|
87
|
+
depth.set(layer, level);
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return [...depth.keys()].sort((a, b) => depth.get(a) - depth.get(b));
|
|
92
|
+
},
|
|
93
|
+
isInNestedLayer(node, target) {
|
|
94
|
+
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
|
|
95
|
+
},
|
|
96
|
+
/** Focus leaving a closing descendant shouldn't dismiss its ancestors. */
|
|
97
|
+
isClosingAncestor(node) {
|
|
98
|
+
const id = this.layerFor(node)?.id;
|
|
99
|
+
return !!id && this.closingAncestors.has(id);
|
|
100
|
+
},
|
|
101
|
+
isInBranch(target) {
|
|
102
|
+
return Array.from(this.branches).some((branch) => contains(branch, target));
|
|
103
|
+
},
|
|
104
|
+
add(layer) {
|
|
105
|
+
const existingIndex = this.indexOf(layer.node);
|
|
106
|
+
const existing = existingIndex !== -1 ? this.layers[existingIndex] : void 0;
|
|
107
|
+
const pending = this.pendingReattach.get(layer.node);
|
|
108
|
+
if (existing) {
|
|
109
|
+
layer.id ?? (layer.id = existing.id);
|
|
110
|
+
layer.parentId = existing.parentId;
|
|
111
|
+
} else if (pending) {
|
|
112
|
+
layer.id ?? (layer.id = pending.id);
|
|
113
|
+
layer.parentId = pending.parentId;
|
|
114
|
+
} else {
|
|
115
|
+
layer.id ?? (layer.id = `layer-${++layerId}`);
|
|
116
|
+
const peer = layer.group ? this.peerFor(layer.group) : void 0;
|
|
117
|
+
layer.parentId = peer ? peer.parentId : layer.parentId ?? this.parentFor(layer)?.id;
|
|
118
|
+
}
|
|
119
|
+
const adopted = existing || pending ? [] : this.adopt(layer);
|
|
120
|
+
if (existing) this.layers[existingIndex] = layer;
|
|
121
|
+
else if (pending) {
|
|
122
|
+
this.pendingReattach.delete(layer.node);
|
|
123
|
+
this.layers.splice(Math.min(pending.index, this.count()), 0, layer);
|
|
124
|
+
} else if (adopted.length) this.layers.splice(this.indexOf(adopted[0].node), 0, layer);
|
|
125
|
+
else this.layers.push(layer);
|
|
126
|
+
this.syncLayers();
|
|
127
|
+
},
|
|
128
|
+
addBranch(node) {
|
|
129
|
+
this.branches.push(node);
|
|
130
|
+
},
|
|
131
|
+
remove(node, options) {
|
|
132
|
+
const index = this.indexOf(node);
|
|
133
|
+
if (index < 0) return;
|
|
134
|
+
const layer = this.layers[index];
|
|
135
|
+
if (options?.reattach) this.pendingReattach.set(node, {
|
|
136
|
+
id: layer.id,
|
|
137
|
+
parentId: layer.parentId,
|
|
138
|
+
index
|
|
139
|
+
});
|
|
140
|
+
else {
|
|
141
|
+
for (const id of ancestorIds(layer, indexById(this.layers))) this.closingAncestors.add(id);
|
|
142
|
+
cancelClosingAncestors?.();
|
|
143
|
+
cancelClosingAncestors = nextTick(() => {
|
|
144
|
+
cancelClosingAncestors = void 0;
|
|
145
|
+
this.closingAncestors.clear();
|
|
146
|
+
});
|
|
147
|
+
this.dismissing.delete(node);
|
|
148
|
+
const nested = this.getNestedLayers(node);
|
|
149
|
+
nested.forEach((layer) => this.dismissing.add(layer.node));
|
|
150
|
+
if (nested.length) queueMicrotask(() => nested.forEach((layer) => this.dismiss(layer.node, node)));
|
|
151
|
+
for (const child of this.layers) if (child.parentId === layer.id) child.parentId = layer.parentId;
|
|
152
|
+
}
|
|
153
|
+
this.layers.splice(index, 1);
|
|
154
|
+
if (layer.snapshot) publishSnapshot(layer, {
|
|
155
|
+
...layer.snapshot,
|
|
156
|
+
active: false,
|
|
157
|
+
blocked: false
|
|
158
|
+
});
|
|
159
|
+
this.syncLayers();
|
|
160
|
+
},
|
|
161
|
+
removeBranch(node) {
|
|
162
|
+
const index = this.branches.indexOf(node);
|
|
163
|
+
if (index >= 0) this.branches.splice(index, 1);
|
|
164
|
+
},
|
|
165
|
+
syncLayers() {
|
|
166
|
+
const byId = indexById(this.layers);
|
|
167
|
+
const nestedCounts = /* @__PURE__ */ new Map();
|
|
168
|
+
const nestedInSameType = /* @__PURE__ */ new Set();
|
|
169
|
+
for (const layer of this.layers) for (const parentId of ancestorIds(layer, byId)) {
|
|
170
|
+
const parent = byId.get(parentId);
|
|
171
|
+
if (!parent) break;
|
|
172
|
+
if (parent.type !== layer.type) continue;
|
|
173
|
+
nestedCounts.set(parentId, (nestedCounts.get(parentId) ?? 0) + 1);
|
|
174
|
+
nestedInSameType.add(layer);
|
|
175
|
+
}
|
|
176
|
+
const highestBlockingIndex = this.topMostPointerBlockingIndex();
|
|
177
|
+
this.layers.forEach((layer, index) => {
|
|
178
|
+
const nestedCount = nestedCounts.get(layer.id) ?? 0;
|
|
179
|
+
const snapshot = {
|
|
180
|
+
active: true,
|
|
181
|
+
type: layer.type,
|
|
182
|
+
index,
|
|
183
|
+
nested: nestedInSameType.has(layer),
|
|
184
|
+
hasNested: nestedCount > 0,
|
|
185
|
+
nestedCount,
|
|
186
|
+
blocked: index < highestBlockingIndex
|
|
187
|
+
};
|
|
188
|
+
if (!isEqual(layer.snapshot, snapshot)) publishSnapshot(layer, snapshot);
|
|
189
|
+
});
|
|
190
|
+
},
|
|
191
|
+
indexOf(node) {
|
|
192
|
+
return this.layers.findIndex((layer) => layer.node === node);
|
|
193
|
+
},
|
|
194
|
+
dismiss(node, parent) {
|
|
195
|
+
const index = this.indexOf(node);
|
|
196
|
+
if (index === -1) return;
|
|
197
|
+
const layer = this.layers[index];
|
|
198
|
+
const event = fireCustomEvent(node, LAYER_REQUEST_DISMISS_EVENT, {
|
|
199
|
+
originalLayer: node,
|
|
200
|
+
targetLayer: parent,
|
|
201
|
+
originalIndex: index,
|
|
202
|
+
targetIndex: parent ? this.indexOf(parent) : -1
|
|
203
|
+
});
|
|
204
|
+
layer.requestDismiss?.(event);
|
|
205
|
+
if (event.defaultPrevented) this.dismissing.delete(node);
|
|
206
|
+
else layer.dismiss();
|
|
207
|
+
}
|
|
196
208
|
};
|
|
197
209
|
function publishSnapshot(layer, snapshot) {
|
|
198
|
-
|
|
199
|
-
|
|
210
|
+
layer.snapshot = snapshot;
|
|
211
|
+
layer.onLayerChange?.(snapshot);
|
|
200
212
|
}
|
|
201
213
|
function fireCustomEvent(el, type, detail) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
214
|
+
const event = new (el.ownerDocument.defaultView || window).CustomEvent(type, {
|
|
215
|
+
cancelable: true,
|
|
216
|
+
bubbles: true,
|
|
217
|
+
detail
|
|
218
|
+
});
|
|
219
|
+
el.dispatchEvent(event);
|
|
220
|
+
return event;
|
|
208
221
|
}
|
|
209
|
-
export {
|
|
210
|
-
isPointerBlocking,
|
|
211
|
-
layerStack
|
|
212
|
-
};
|
|
222
|
+
export { isPointerBlocking, layerStack };
|
|
@@ -2,7 +2,5 @@
|
|
|
2
2
|
* Re-derives pointer blocking from the stack. Needed after a layer's `pointerBlocking` getter
|
|
3
3
|
* changes value, since nothing was added or removed to trigger the usual sync.
|
|
4
4
|
*/
|
|
5
|
-
declare function syncPointerEvents(node: HTMLElement): void;
|
|
6
|
-
declare function disablePointerEventsOutside(node: HTMLElement, persistentElements?: Array<() => Element | null>): () => void;
|
|
7
|
-
|
|
8
|
-
export { disablePointerEventsOutside, syncPointerEvents };
|
|
5
|
+
export declare function syncPointerEvents(node: HTMLElement): void;
|
|
6
|
+
export declare function disablePointerEventsOutside(node: HTMLElement, persistentElements?: Array<() => Element | null>): () => void;
|
|
@@ -2,7 +2,5 @@
|
|
|
2
2
|
* Re-derives pointer blocking from the stack. Needed after a layer's `pointerBlocking` getter
|
|
3
3
|
* changes value, since nothing was added or removed to trigger the usual sync.
|
|
4
4
|
*/
|
|
5
|
-
declare function syncPointerEvents(node: HTMLElement): void;
|
|
6
|
-
declare function disablePointerEventsOutside(node: HTMLElement, persistentElements?: Array<() => Element | null>): () => void;
|
|
7
|
-
|
|
8
|
-
export { disablePointerEventsOutside, syncPointerEvents };
|
|
5
|
+
export declare function syncPointerEvents(node: HTMLElement): void;
|
|
6
|
+
export declare function disablePointerEventsOutside(node: HTMLElement, persistentElements?: Array<() => Element | null>): () => void;
|
|
@@ -1,82 +1,60 @@
|
|
|
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/pointer-event-outside.ts
|
|
21
|
-
var pointer_event_outside_exports = {};
|
|
22
|
-
__export(pointer_event_outside_exports, {
|
|
23
|
-
disablePointerEventsOutside: () => disablePointerEventsOutside,
|
|
24
|
-
syncPointerEvents: () => syncPointerEvents
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
25
4
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
5
|
+
const require_layer_stack = require("./layer-stack.js");
|
|
6
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
7
|
+
// src/pointer-event-outside.ts
|
|
8
|
+
const originalBodyPointerEvents = /* @__PURE__ */ new WeakMap();
|
|
9
|
+
const scheduled = /* @__PURE__ */ new WeakSet();
|
|
10
|
+
/** Applies or restores body blocking from the current stack state, once per microtask. */
|
|
30
11
|
function syncBodyPointerEvents(doc) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
});
|
|
12
|
+
if (scheduled.has(doc)) return;
|
|
13
|
+
scheduled.add(doc);
|
|
14
|
+
queueMicrotask(() => {
|
|
15
|
+
scheduled.delete(doc);
|
|
16
|
+
const body = doc.body;
|
|
17
|
+
if (!body) return;
|
|
18
|
+
const shouldBlock = require_layer_stack.layerStack.hasPointerBlockingLayer();
|
|
19
|
+
if (shouldBlock === body.hasAttribute("data-inert")) return;
|
|
20
|
+
if (shouldBlock) {
|
|
21
|
+
originalBodyPointerEvents.set(body, body.style.pointerEvents);
|
|
22
|
+
body.style.pointerEvents = "none";
|
|
23
|
+
body.setAttribute("data-inert", "");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const original = originalBodyPointerEvents.get(body);
|
|
27
|
+
if (original !== void 0) {
|
|
28
|
+
body.style.pointerEvents = original;
|
|
29
|
+
originalBodyPointerEvents.delete(body);
|
|
30
|
+
}
|
|
31
|
+
body.removeAttribute("data-inert");
|
|
32
|
+
if (body.style.length === 0) body.removeAttribute("style");
|
|
33
|
+
});
|
|
54
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Re-derives pointer blocking from the stack. Needed after a layer's `pointerBlocking` getter
|
|
37
|
+
* changes value, since nothing was added or removed to trigger the usual sync.
|
|
38
|
+
*/
|
|
55
39
|
function syncPointerEvents(node) {
|
|
56
|
-
|
|
40
|
+
syncBodyPointerEvents((0, _zag_js_dom_query.getDocument)(node));
|
|
57
41
|
}
|
|
58
42
|
function disablePointerEventsOutside(node, persistentElements) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
syncBodyPointerEvents(doc);
|
|
75
|
-
cleanups.forEach((fn) => fn());
|
|
76
|
-
};
|
|
43
|
+
const doc = (0, _zag_js_dom_query.getDocument)(node);
|
|
44
|
+
const cleanups = [];
|
|
45
|
+
syncBodyPointerEvents(doc);
|
|
46
|
+
persistentElements?.forEach((el) => {
|
|
47
|
+
const [promise, abort] = (0, _zag_js_dom_query.waitForElement)(() => {
|
|
48
|
+
const node = el();
|
|
49
|
+
return (0, _zag_js_dom_query.isHTMLElement)(node) ? node : null;
|
|
50
|
+
}, { timeout: 1e3 });
|
|
51
|
+
promise.then((el) => cleanups.push((0, _zag_js_dom_query.setStyle)(el, { pointerEvents: "auto" })));
|
|
52
|
+
cleanups.push(abort);
|
|
53
|
+
});
|
|
54
|
+
return () => {
|
|
55
|
+
syncBodyPointerEvents(doc);
|
|
56
|
+
cleanups.forEach((fn) => fn());
|
|
57
|
+
};
|
|
77
58
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
disablePointerEventsOutside,
|
|
81
|
-
syncPointerEvents
|
|
82
|
-
});
|
|
59
|
+
exports.disablePointerEventsOutside = disablePointerEventsOutside;
|
|
60
|
+
exports.syncPointerEvents = syncPointerEvents;
|