@zag-js/popover 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/index.d.mts +7 -10
- package/dist/index.d.ts +7 -10
- package/dist/index.js +12 -38
- package/dist/index.mjs +2 -7
- package/dist/popover.anatomy.d.mts +2 -6
- package/dist/popover.anatomy.d.ts +2 -6
- package/dist/popover.anatomy.js +8 -44
- package/dist/popover.anatomy.mjs +4 -18
- package/dist/popover.connect.d.mts +3 -9
- package/dist/popover.connect.d.ts +3 -9
- package/dist/popover.connect.js +164 -187
- package/dist/popover.connect.mjs +158 -150
- package/dist/popover.dom.d.mts +19 -22
- package/dist/popover.dom.d.ts +19 -22
- package/dist/popover.dom.js +47 -89
- package/dist/popover.dom.mjs +25 -46
- package/dist/popover.machine.d.mts +2 -9
- package/dist/popover.machine.d.ts +2 -9
- package/dist/popover.machine.js +299 -335
- package/dist/popover.machine.mjs +291 -296
- package/dist/popover.props.d.mts +3 -10
- package/dist/popover.props.d.ts +3 -10
- package/dist/popover.props.js +35 -60
- package/dist/popover.props.mjs +31 -34
- package/dist/popover.types.d.mts +185 -188
- package/dist/popover.types.d.ts +185 -188
- package/dist/popover.types.js +4 -18
- package/dist/popover.types.mjs +1 -0
- package/package.json +13 -13
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
import '@zag-js/dismissable';
|
|
4
|
-
import '@zag-js/popper';
|
|
5
|
-
import '@zag-js/types';
|
|
6
|
-
|
|
7
|
-
declare const machine: _zag_js_core.Machine<PopoverSchema>;
|
|
8
|
-
|
|
9
|
-
export { machine };
|
|
1
|
+
import { PopoverSchema } from "./popover.types.js";
|
|
2
|
+
export declare const machine: import("@zag-js/core").Machine<PopoverSchema>;
|
package/dist/popover.machine.js
CHANGED
|
@@ -1,337 +1,301 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/popover.machine.ts
|
|
31
|
-
var popover_machine_exports = {};
|
|
32
|
-
__export(popover_machine_exports, {
|
|
33
|
-
machine: () => machine
|
|
34
|
-
});
|
|
35
|
-
module.exports = __toCommonJS(popover_machine_exports);
|
|
36
|
-
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
37
|
-
var import_core = require("@zag-js/core");
|
|
38
|
-
var import_dismissable = require("@zag-js/dismissable");
|
|
39
|
-
var import_dom_query = require("@zag-js/dom-query");
|
|
40
|
-
var import_focus_trap = require("@zag-js/focus-trap");
|
|
41
|
-
var import_popper = require("@zag-js/popper");
|
|
42
|
-
var import_remove_scroll = require("@zag-js/remove-scroll");
|
|
43
|
-
var dom = __toESM(require("./popover.dom.js"));
|
|
44
|
-
var machine = (0, import_core.createMachine)({
|
|
45
|
-
props({ props }) {
|
|
46
|
-
return {
|
|
47
|
-
closeOnInteractOutside: true,
|
|
48
|
-
closeOnEscape: true,
|
|
49
|
-
autoFocus: true,
|
|
50
|
-
modal: false,
|
|
51
|
-
portalled: true,
|
|
52
|
-
restoreFocus: true,
|
|
53
|
-
...props,
|
|
54
|
-
positioning: {
|
|
55
|
-
placement: "bottom",
|
|
56
|
-
...props.positioning
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
initialState({ prop }) {
|
|
61
|
-
const open = prop("open") || prop("defaultOpen");
|
|
62
|
-
return open ? "open" : "closed";
|
|
63
|
-
},
|
|
64
|
-
context({ bindable, prop, scope }) {
|
|
65
|
-
return {
|
|
66
|
-
currentPlacement: bindable(() => ({
|
|
67
|
-
defaultValue: void 0
|
|
68
|
-
})),
|
|
69
|
-
renderedElements: bindable(() => ({
|
|
70
|
-
defaultValue: { title: true, description: true }
|
|
71
|
-
})),
|
|
72
|
-
triggerValue: bindable(() => ({
|
|
73
|
-
defaultValue: prop("defaultTriggerValue") ?? null,
|
|
74
|
-
value: prop("triggerValue"),
|
|
75
|
-
onChange(value) {
|
|
76
|
-
const onTriggerValueChange = prop("onTriggerValueChange");
|
|
77
|
-
if (!onTriggerValueChange) return;
|
|
78
|
-
const triggerElement = dom.getActiveTriggerEl(scope, value);
|
|
79
|
-
onTriggerValueChange({ value, triggerElement });
|
|
80
|
-
}
|
|
81
|
-
}))
|
|
82
|
-
};
|
|
83
|
-
},
|
|
84
|
-
computed: {
|
|
85
|
-
currentPortalled: ({ prop }) => !!prop("modal") || !!prop("portalled")
|
|
86
|
-
},
|
|
87
|
-
watch({ track, prop, action }) {
|
|
88
|
-
track([() => prop("open")], () => {
|
|
89
|
-
action(["toggleVisibility"]);
|
|
90
|
-
});
|
|
91
|
-
},
|
|
92
|
-
entry: ["checkRenderedElements"],
|
|
93
|
-
on: {
|
|
94
|
-
"TRIGGER_VALUE.SET": {
|
|
95
|
-
actions: ["setTriggerValue", "reposition"]
|
|
96
|
-
}
|
|
97
|
-
},
|
|
98
|
-
states: {
|
|
99
|
-
closed: {
|
|
100
|
-
on: {
|
|
101
|
-
"CONTROLLED.OPEN": {
|
|
102
|
-
target: "open",
|
|
103
|
-
actions: ["setInitialFocus"]
|
|
104
|
-
},
|
|
105
|
-
TOGGLE: [
|
|
106
|
-
{
|
|
107
|
-
guard: "isOpenControlled",
|
|
108
|
-
actions: ["invokeOnOpen", "setTriggerValue"]
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
target: "open",
|
|
112
|
-
actions: ["invokeOnOpen", "setTriggerValue", "setInitialFocus"]
|
|
113
|
-
}
|
|
114
|
-
],
|
|
115
|
-
OPEN: [
|
|
116
|
-
{
|
|
117
|
-
guard: "isOpenControlled",
|
|
118
|
-
actions: ["invokeOnOpen", "setTriggerValue"]
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
target: "open",
|
|
122
|
-
actions: ["invokeOnOpen", "setTriggerValue", "setInitialFocus"]
|
|
123
|
-
}
|
|
124
|
-
]
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
open: {
|
|
128
|
-
entry: ["checkRenderedElements"],
|
|
129
|
-
effects: [
|
|
130
|
-
"trapFocus",
|
|
131
|
-
"preventScroll",
|
|
132
|
-
"hideContentBelow",
|
|
133
|
-
"trackDismissableElement",
|
|
134
|
-
"trackPositioning",
|
|
135
|
-
"proxyTabFocus"
|
|
136
|
-
],
|
|
137
|
-
on: {
|
|
138
|
-
"CONTROLLED.CLOSE": {
|
|
139
|
-
target: "closed",
|
|
140
|
-
actions: ["setFinalFocus"]
|
|
141
|
-
},
|
|
142
|
-
CLOSE: [
|
|
143
|
-
{
|
|
144
|
-
guard: "isOpenControlled",
|
|
145
|
-
actions: ["invokeOnClose"]
|
|
146
|
-
},
|
|
147
|
-
{
|
|
148
|
-
target: "closed",
|
|
149
|
-
actions: ["invokeOnClose", "setFinalFocus"]
|
|
150
|
-
}
|
|
151
|
-
],
|
|
152
|
-
TOGGLE: [
|
|
153
|
-
{
|
|
154
|
-
guard: "isOpenControlled",
|
|
155
|
-
actions: ["invokeOnClose"]
|
|
156
|
-
},
|
|
157
|
-
{
|
|
158
|
-
target: "closed",
|
|
159
|
-
actions: ["invokeOnClose"]
|
|
160
|
-
}
|
|
161
|
-
],
|
|
162
|
-
"POSITIONING.SET": {
|
|
163
|
-
actions: ["reposition"]
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
implementations: {
|
|
169
|
-
guards: {
|
|
170
|
-
isOpenControlled: ({ prop }) => prop("open") != void 0
|
|
171
|
-
},
|
|
172
|
-
effects: {
|
|
173
|
-
trackPositioning({ context, prop, scope }) {
|
|
174
|
-
context.set("currentPlacement", prop("positioning").placement);
|
|
175
|
-
const anchorEl = dom.getAnchorEl(scope);
|
|
176
|
-
const getPositionerEl2 = () => dom.getPositionerEl(scope);
|
|
177
|
-
const getTriggerEl2 = () => anchorEl ?? dom.getActiveTriggerEl(scope, context.get("triggerValue"));
|
|
178
|
-
return (0, import_popper.getPlacement)(getTriggerEl2, getPositionerEl2, {
|
|
179
|
-
...prop("positioning"),
|
|
180
|
-
defer: true,
|
|
181
|
-
onComplete(data) {
|
|
182
|
-
context.set("currentPlacement", data.placement);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
},
|
|
186
|
-
trackDismissableElement({ send, prop, scope }) {
|
|
187
|
-
const getContentEl2 = () => dom.getContentEl(scope);
|
|
188
|
-
let restoreFocus = true;
|
|
189
|
-
return (0, import_dismissable.trackDismissableElement)(getContentEl2, {
|
|
190
|
-
type: "popover",
|
|
191
|
-
pointerBlocking: prop("modal"),
|
|
192
|
-
exclude: [dom.getTriggerEl(scope), ...dom.getTriggerEls(scope)].filter(Boolean),
|
|
193
|
-
defer: true,
|
|
194
|
-
layerStyleTargets: [() => dom.getPositionerEl(scope)],
|
|
195
|
-
onEscapeKeyDown(event) {
|
|
196
|
-
prop("onEscapeKeyDown")?.(event);
|
|
197
|
-
if (prop("closeOnEscape")) return;
|
|
198
|
-
event.preventDefault();
|
|
199
|
-
},
|
|
200
|
-
onInteractOutside(event) {
|
|
201
|
-
prop("onInteractOutside")?.(event);
|
|
202
|
-
if (event.defaultPrevented) return;
|
|
203
|
-
restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
204
|
-
if (!prop("closeOnInteractOutside")) {
|
|
205
|
-
event.preventDefault();
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
onPointerDownOutside: prop("onPointerDownOutside"),
|
|
209
|
-
onFocusOutside: prop("onFocusOutside"),
|
|
210
|
-
persistentElements: prop("persistentElements"),
|
|
211
|
-
onRequestDismiss: prop("onRequestDismiss"),
|
|
212
|
-
onDismiss() {
|
|
213
|
-
send({ type: "CLOSE", src: "interact-outside", restoreFocus });
|
|
214
|
-
}
|
|
215
|
-
});
|
|
216
|
-
},
|
|
217
|
-
proxyTabFocus({ prop, scope, context }) {
|
|
218
|
-
if (prop("modal") || !prop("portalled")) return;
|
|
219
|
-
const getContentEl2 = () => dom.getContentEl(scope);
|
|
220
|
-
return (0, import_dom_query.proxyTabFocus)(getContentEl2, {
|
|
221
|
-
triggerElement: dom.getActiveTriggerEl(scope, context.get("triggerValue")),
|
|
222
|
-
defer: true,
|
|
223
|
-
getShadowRoot: true,
|
|
224
|
-
onFocus(el) {
|
|
225
|
-
el.focus({ preventScroll: true });
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
},
|
|
229
|
-
hideContentBelow({ prop, scope, context }) {
|
|
230
|
-
if (!prop("modal")) return;
|
|
231
|
-
const getElements = () => [dom.getContentEl(scope), dom.getActiveTriggerEl(scope, context.get("triggerValue"))];
|
|
232
|
-
return (0, import_aria_hidden.ariaHidden)(getElements, { defer: true });
|
|
233
|
-
},
|
|
234
|
-
preventScroll({ prop, scope }) {
|
|
235
|
-
if (!prop("modal")) return;
|
|
236
|
-
return (0, import_remove_scroll.preventBodyScroll)(scope.getDoc());
|
|
237
|
-
},
|
|
238
|
-
trapFocus({ prop, scope, context }) {
|
|
239
|
-
if (!prop("modal")) return;
|
|
240
|
-
const contentEl = () => dom.getContentEl(scope);
|
|
241
|
-
return (0, import_focus_trap.trapFocus)(contentEl, {
|
|
242
|
-
preventScroll: true,
|
|
243
|
-
returnFocusOnDeactivate: !!prop("restoreFocus"),
|
|
244
|
-
initialFocus: () => (0, import_dom_query.getInitialFocus)({
|
|
245
|
-
root: dom.getContentEl(scope),
|
|
246
|
-
getInitialEl: prop("initialFocusEl"),
|
|
247
|
-
enabled: prop("autoFocus")
|
|
248
|
-
}),
|
|
249
|
-
setReturnFocus: (el) => {
|
|
250
|
-
const finalFocusEl = prop("finalFocusEl")?.();
|
|
251
|
-
if (finalFocusEl) return finalFocusEl;
|
|
252
|
-
const triggerValue = context.get("triggerValue");
|
|
253
|
-
if (triggerValue) {
|
|
254
|
-
const activeTriggerEl = dom.getActiveTriggerEl(scope, triggerValue);
|
|
255
|
-
if (activeTriggerEl) return activeTriggerEl;
|
|
256
|
-
}
|
|
257
|
-
const fallbackTrigger = dom.getTriggerEls(scope)[0];
|
|
258
|
-
if (fallbackTrigger) return fallbackTrigger;
|
|
259
|
-
return el;
|
|
260
|
-
},
|
|
261
|
-
getShadowRoot: true
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
actions: {
|
|
266
|
-
reposition({ event, prop, scope, context }) {
|
|
267
|
-
const anchorEl = dom.getAnchorEl(scope);
|
|
268
|
-
const getPositionerEl2 = () => dom.getPositionerEl(scope);
|
|
269
|
-
const getTriggerEl2 = () => anchorEl ?? dom.getActiveTriggerEl(scope, context.get("triggerValue"));
|
|
270
|
-
(0, import_popper.getPlacement)(getTriggerEl2, getPositionerEl2, {
|
|
271
|
-
...prop("positioning"),
|
|
272
|
-
...event.options,
|
|
273
|
-
defer: true,
|
|
274
|
-
listeners: false,
|
|
275
|
-
onComplete(data) {
|
|
276
|
-
context.set("currentPlacement", data.placement);
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
},
|
|
280
|
-
setTriggerValue({ context, event }) {
|
|
281
|
-
if (event.value === void 0) return;
|
|
282
|
-
context.set("triggerValue", event.value);
|
|
283
|
-
},
|
|
284
|
-
checkRenderedElements({ context, scope }) {
|
|
285
|
-
(0, import_dom_query.raf)(() => {
|
|
286
|
-
context.set("renderedElements", {
|
|
287
|
-
title: !!dom.getTitleEl(scope),
|
|
288
|
-
description: !!dom.getDescriptionEl(scope)
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
},
|
|
292
|
-
setInitialFocus({ prop, scope }) {
|
|
293
|
-
if (prop("modal")) return;
|
|
294
|
-
(0, import_dom_query.raf)(() => {
|
|
295
|
-
const element = (0, import_dom_query.getInitialFocus)({
|
|
296
|
-
root: dom.getContentEl(scope),
|
|
297
|
-
getInitialEl: prop("initialFocusEl"),
|
|
298
|
-
enabled: prop("autoFocus")
|
|
299
|
-
});
|
|
300
|
-
if (!element) return;
|
|
301
|
-
element.focus({ preventScroll: true });
|
|
302
|
-
});
|
|
303
|
-
},
|
|
304
|
-
setFinalFocus({ event, prop, scope, context }) {
|
|
305
|
-
const eventRestoreFocus = event.restoreFocus ?? event.previousEvent?.restoreFocus;
|
|
306
|
-
if (eventRestoreFocus != null && !eventRestoreFocus) return;
|
|
307
|
-
if (!prop("restoreFocus")) return;
|
|
308
|
-
(0, import_dom_query.raf)(() => {
|
|
309
|
-
const finalFocusEl = prop("finalFocusEl")?.();
|
|
310
|
-
if (finalFocusEl) {
|
|
311
|
-
finalFocusEl.focus({ preventScroll: true });
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
const element = dom.getActiveTriggerEl(scope, context.get("triggerValue"));
|
|
315
|
-
element?.focus({ preventScroll: true });
|
|
316
|
-
});
|
|
317
|
-
},
|
|
318
|
-
invokeOnOpen({ prop, flush }) {
|
|
319
|
-
flush(() => {
|
|
320
|
-
prop("onOpenChange")?.({ open: true });
|
|
321
|
-
});
|
|
322
|
-
},
|
|
323
|
-
invokeOnClose({ prop, flush }) {
|
|
324
|
-
flush(() => {
|
|
325
|
-
prop("onOpenChange")?.({ open: false });
|
|
326
|
-
});
|
|
327
|
-
},
|
|
328
|
-
toggleVisibility({ event, send, prop }) {
|
|
329
|
-
send({ type: prop("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE", previousEvent: event });
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
}
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
333
4
|
});
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
5
|
+
const require_popover_dom = require("./popover.dom.js");
|
|
6
|
+
let _zag_js_dom_query = require("@zag-js/dom-query");
|
|
7
|
+
let _zag_js_popper = require("@zag-js/popper");
|
|
8
|
+
let _zag_js_aria_hidden = require("@zag-js/aria-hidden");
|
|
9
|
+
let _zag_js_core = require("@zag-js/core");
|
|
10
|
+
let _zag_js_dismissable = require("@zag-js/dismissable");
|
|
11
|
+
let _zag_js_focus_trap = require("@zag-js/focus-trap");
|
|
12
|
+
let _zag_js_remove_scroll = require("@zag-js/remove-scroll");
|
|
13
|
+
// src/popover.machine.ts
|
|
14
|
+
const machine = (0, _zag_js_core.createMachine)({
|
|
15
|
+
props({ props }) {
|
|
16
|
+
return {
|
|
17
|
+
closeOnInteractOutside: true,
|
|
18
|
+
closeOnEscape: true,
|
|
19
|
+
autoFocus: true,
|
|
20
|
+
modal: false,
|
|
21
|
+
portalled: true,
|
|
22
|
+
restoreFocus: true,
|
|
23
|
+
...props,
|
|
24
|
+
positioning: {
|
|
25
|
+
placement: "bottom",
|
|
26
|
+
...props.positioning
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
initialState({ prop }) {
|
|
31
|
+
return prop("open") || prop("defaultOpen") ? "open" : "closed";
|
|
32
|
+
},
|
|
33
|
+
context({ bindable, prop, scope }) {
|
|
34
|
+
return {
|
|
35
|
+
currentPlacement: bindable(() => ({ defaultValue: void 0 })),
|
|
36
|
+
renderedElements: bindable(() => ({ defaultValue: {
|
|
37
|
+
title: true,
|
|
38
|
+
description: true
|
|
39
|
+
} })),
|
|
40
|
+
triggerValue: bindable(() => ({
|
|
41
|
+
defaultValue: prop("defaultTriggerValue") ?? null,
|
|
42
|
+
value: prop("triggerValue"),
|
|
43
|
+
onChange(value) {
|
|
44
|
+
const onTriggerValueChange = prop("onTriggerValueChange");
|
|
45
|
+
if (!onTriggerValueChange) return;
|
|
46
|
+
onTriggerValueChange({
|
|
47
|
+
value,
|
|
48
|
+
triggerElement: require_popover_dom.getActiveTriggerEl(scope, value)
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
}))
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
computed: { currentPortalled: ({ prop }) => !!prop("modal") || !!prop("portalled") },
|
|
55
|
+
watch({ track, prop, action }) {
|
|
56
|
+
track([() => prop("open")], () => {
|
|
57
|
+
action(["toggleVisibility"]);
|
|
58
|
+
});
|
|
59
|
+
},
|
|
60
|
+
entry: ["checkRenderedElements"],
|
|
61
|
+
on: { "TRIGGER_VALUE.SET": { actions: ["setTriggerValue", "reposition"] } },
|
|
62
|
+
states: {
|
|
63
|
+
closed: { on: {
|
|
64
|
+
"CONTROLLED.OPEN": {
|
|
65
|
+
target: "open",
|
|
66
|
+
actions: ["setInitialFocus"]
|
|
67
|
+
},
|
|
68
|
+
TOGGLE: [{
|
|
69
|
+
guard: "isOpenControlled",
|
|
70
|
+
actions: ["invokeOnOpen", "setTriggerValue"]
|
|
71
|
+
}, {
|
|
72
|
+
target: "open",
|
|
73
|
+
actions: [
|
|
74
|
+
"invokeOnOpen",
|
|
75
|
+
"setTriggerValue",
|
|
76
|
+
"setInitialFocus"
|
|
77
|
+
]
|
|
78
|
+
}],
|
|
79
|
+
OPEN: [{
|
|
80
|
+
guard: "isOpenControlled",
|
|
81
|
+
actions: ["invokeOnOpen", "setTriggerValue"]
|
|
82
|
+
}, {
|
|
83
|
+
target: "open",
|
|
84
|
+
actions: [
|
|
85
|
+
"invokeOnOpen",
|
|
86
|
+
"setTriggerValue",
|
|
87
|
+
"setInitialFocus"
|
|
88
|
+
]
|
|
89
|
+
}]
|
|
90
|
+
} },
|
|
91
|
+
open: {
|
|
92
|
+
entry: ["checkRenderedElements"],
|
|
93
|
+
effects: [
|
|
94
|
+
"trapFocus",
|
|
95
|
+
"preventScroll",
|
|
96
|
+
"hideContentBelow",
|
|
97
|
+
"trackDismissableElement",
|
|
98
|
+
"trackPositioning",
|
|
99
|
+
"proxyTabFocus"
|
|
100
|
+
],
|
|
101
|
+
on: {
|
|
102
|
+
"CONTROLLED.CLOSE": {
|
|
103
|
+
target: "closed",
|
|
104
|
+
actions: ["setFinalFocus"]
|
|
105
|
+
},
|
|
106
|
+
CLOSE: [{
|
|
107
|
+
guard: "isOpenControlled",
|
|
108
|
+
actions: ["invokeOnClose"]
|
|
109
|
+
}, {
|
|
110
|
+
target: "closed",
|
|
111
|
+
actions: ["invokeOnClose", "setFinalFocus"]
|
|
112
|
+
}],
|
|
113
|
+
TOGGLE: [{
|
|
114
|
+
guard: "isOpenControlled",
|
|
115
|
+
actions: ["invokeOnClose"]
|
|
116
|
+
}, {
|
|
117
|
+
target: "closed",
|
|
118
|
+
actions: ["invokeOnClose"]
|
|
119
|
+
}],
|
|
120
|
+
"POSITIONING.SET": { actions: ["reposition"] }
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
implementations: {
|
|
125
|
+
guards: { isOpenControlled: ({ prop }) => prop("open") != void 0 },
|
|
126
|
+
effects: {
|
|
127
|
+
trackPositioning({ context, prop, scope }) {
|
|
128
|
+
context.set("currentPlacement", prop("positioning").placement);
|
|
129
|
+
const anchorEl = require_popover_dom.getAnchorEl(scope);
|
|
130
|
+
const getPositionerEl$2 = () => require_popover_dom.getPositionerEl(scope);
|
|
131
|
+
const getTriggerEl = () => anchorEl ?? require_popover_dom.getActiveTriggerEl(scope, context.get("triggerValue"));
|
|
132
|
+
return (0, _zag_js_popper.getPlacement)(getTriggerEl, getPositionerEl$2, {
|
|
133
|
+
...prop("positioning"),
|
|
134
|
+
defer: true,
|
|
135
|
+
onComplete(data) {
|
|
136
|
+
context.set("currentPlacement", data.placement);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
trackDismissableElement({ send, prop, scope }) {
|
|
141
|
+
const getContentEl$1 = () => require_popover_dom.getContentEl(scope);
|
|
142
|
+
let restoreFocus = true;
|
|
143
|
+
return (0, _zag_js_dismissable.trackDismissableElement)(getContentEl$1, {
|
|
144
|
+
type: "popover",
|
|
145
|
+
pointerBlocking: prop("modal"),
|
|
146
|
+
exclude: [require_popover_dom.getTriggerEl(scope), ...require_popover_dom.getTriggerEls(scope)].filter(Boolean),
|
|
147
|
+
defer: true,
|
|
148
|
+
getRootNode: scope.getRootNode,
|
|
149
|
+
layerStyleTargets: [() => require_popover_dom.getPositionerEl(scope)],
|
|
150
|
+
onEscapeKeyDown(event) {
|
|
151
|
+
prop("onEscapeKeyDown")?.(event);
|
|
152
|
+
if (prop("closeOnEscape")) return;
|
|
153
|
+
event.preventDefault();
|
|
154
|
+
},
|
|
155
|
+
onInteractOutside(event) {
|
|
156
|
+
prop("onInteractOutside")?.(event);
|
|
157
|
+
if (event.defaultPrevented) return;
|
|
158
|
+
restoreFocus = !(event.detail.focusable || event.detail.contextmenu);
|
|
159
|
+
if (!prop("closeOnInteractOutside")) event.preventDefault();
|
|
160
|
+
},
|
|
161
|
+
onPointerDownOutside: prop("onPointerDownOutside"),
|
|
162
|
+
onFocusOutside: prop("onFocusOutside"),
|
|
163
|
+
persistentElements: prop("persistentElements"),
|
|
164
|
+
onRequestDismiss: prop("onRequestDismiss"),
|
|
165
|
+
onDismiss(event) {
|
|
166
|
+
send({
|
|
167
|
+
type: "CLOSE",
|
|
168
|
+
src: "interact-outside",
|
|
169
|
+
restoreFocus,
|
|
170
|
+
focusVisible: event?.type === "keydown"
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
},
|
|
175
|
+
proxyTabFocus({ prop, scope, context }) {
|
|
176
|
+
if (prop("modal") || !prop("portalled")) return;
|
|
177
|
+
const getContentEl$2 = () => require_popover_dom.getContentEl(scope);
|
|
178
|
+
return (0, _zag_js_dom_query.proxyTabFocus)(getContentEl$2, {
|
|
179
|
+
triggerElement: require_popover_dom.getActiveTriggerEl(scope, context.get("triggerValue")),
|
|
180
|
+
defer: true,
|
|
181
|
+
getShadowRoot: true,
|
|
182
|
+
onFocus(el) {
|
|
183
|
+
el.focus({ preventScroll: true });
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
hideContentBelow({ prop, scope, context }) {
|
|
188
|
+
if (!prop("modal")) return;
|
|
189
|
+
const getElements = () => [require_popover_dom.getContentEl(scope), require_popover_dom.getActiveTriggerEl(scope, context.get("triggerValue"))];
|
|
190
|
+
return (0, _zag_js_aria_hidden.ariaHidden)(getElements, { defer: true });
|
|
191
|
+
},
|
|
192
|
+
preventScroll({ prop, scope }) {
|
|
193
|
+
if (!prop("modal")) return;
|
|
194
|
+
return (0, _zag_js_remove_scroll.preventBodyScroll)(scope.getDoc());
|
|
195
|
+
},
|
|
196
|
+
trapFocus({ prop, scope, context }) {
|
|
197
|
+
if (!prop("modal")) return;
|
|
198
|
+
const contentEl = () => require_popover_dom.getContentEl(scope);
|
|
199
|
+
return (0, _zag_js_focus_trap.trapFocus)(contentEl, {
|
|
200
|
+
preventScroll: true,
|
|
201
|
+
returnFocusOnDeactivate: !!prop("restoreFocus"),
|
|
202
|
+
initialFocus: () => (0, _zag_js_dom_query.getInitialFocus)({
|
|
203
|
+
root: require_popover_dom.getContentEl(scope),
|
|
204
|
+
getInitialEl: prop("initialFocusEl"),
|
|
205
|
+
enabled: prop("autoFocus")
|
|
206
|
+
}),
|
|
207
|
+
setReturnFocus: (el) => {
|
|
208
|
+
const finalFocusEl = prop("finalFocusEl")?.();
|
|
209
|
+
if (finalFocusEl) return finalFocusEl;
|
|
210
|
+
const triggerValue = context.get("triggerValue");
|
|
211
|
+
if (triggerValue) {
|
|
212
|
+
const activeTriggerEl = require_popover_dom.getActiveTriggerEl(scope, triggerValue);
|
|
213
|
+
if (activeTriggerEl) return activeTriggerEl;
|
|
214
|
+
}
|
|
215
|
+
const fallbackTrigger = require_popover_dom.getTriggerEls(scope)[0];
|
|
216
|
+
if (fallbackTrigger) return fallbackTrigger;
|
|
217
|
+
return el;
|
|
218
|
+
},
|
|
219
|
+
getShadowRoot: true
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
},
|
|
223
|
+
actions: {
|
|
224
|
+
reposition({ event, prop, scope, context }) {
|
|
225
|
+
const anchorEl = require_popover_dom.getAnchorEl(scope);
|
|
226
|
+
const getPositionerEl$1 = () => require_popover_dom.getPositionerEl(scope);
|
|
227
|
+
const getTriggerEl = () => anchorEl ?? require_popover_dom.getActiveTriggerEl(scope, context.get("triggerValue"));
|
|
228
|
+
(0, _zag_js_popper.getPlacement)(getTriggerEl, getPositionerEl$1, {
|
|
229
|
+
...prop("positioning"),
|
|
230
|
+
...event.options,
|
|
231
|
+
defer: true,
|
|
232
|
+
listeners: false,
|
|
233
|
+
onComplete(data) {
|
|
234
|
+
context.set("currentPlacement", data.placement);
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
},
|
|
238
|
+
setTriggerValue({ context, event }) {
|
|
239
|
+
if (event.value === void 0) return;
|
|
240
|
+
context.set("triggerValue", event.value);
|
|
241
|
+
},
|
|
242
|
+
checkRenderedElements({ context, scope }) {
|
|
243
|
+
(0, _zag_js_dom_query.raf)(() => {
|
|
244
|
+
context.set("renderedElements", {
|
|
245
|
+
title: !!require_popover_dom.getTitleEl(scope),
|
|
246
|
+
description: !!require_popover_dom.getDescriptionEl(scope)
|
|
247
|
+
});
|
|
248
|
+
});
|
|
249
|
+
},
|
|
250
|
+
setInitialFocus({ prop, scope }) {
|
|
251
|
+
if (prop("modal")) return;
|
|
252
|
+
(0, _zag_js_dom_query.raf)(() => {
|
|
253
|
+
const element = (0, _zag_js_dom_query.getInitialFocus)({
|
|
254
|
+
root: require_popover_dom.getContentEl(scope),
|
|
255
|
+
getInitialEl: prop("initialFocusEl"),
|
|
256
|
+
enabled: prop("autoFocus")
|
|
257
|
+
});
|
|
258
|
+
if (!element) return;
|
|
259
|
+
element.focus({ preventScroll: true });
|
|
260
|
+
});
|
|
261
|
+
},
|
|
262
|
+
setFinalFocus({ event, prop, scope, context }) {
|
|
263
|
+
const eventRestoreFocus = event.restoreFocus ?? event.previousEvent?.restoreFocus;
|
|
264
|
+
if (eventRestoreFocus != null && !eventRestoreFocus) return;
|
|
265
|
+
if (!prop("restoreFocus")) return;
|
|
266
|
+
const focusOptions = getReturnFocusOptions(event);
|
|
267
|
+
(0, _zag_js_dom_query.raf)(() => {
|
|
268
|
+
const finalFocusEl = prop("finalFocusEl")?.();
|
|
269
|
+
if (finalFocusEl) {
|
|
270
|
+
finalFocusEl.focus(focusOptions);
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
require_popover_dom.getActiveTriggerEl(scope, context.get("triggerValue"))?.focus(focusOptions);
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
invokeOnOpen({ prop, flush }) {
|
|
277
|
+
flush(() => {
|
|
278
|
+
prop("onOpenChange")?.({ open: true });
|
|
279
|
+
});
|
|
280
|
+
},
|
|
281
|
+
invokeOnClose({ prop, flush }) {
|
|
282
|
+
flush(() => {
|
|
283
|
+
prop("onOpenChange")?.({ open: false });
|
|
284
|
+
});
|
|
285
|
+
},
|
|
286
|
+
toggleVisibility({ event, send, prop }) {
|
|
287
|
+
send({
|
|
288
|
+
type: prop("open") ? "CONTROLLED.OPEN" : "CONTROLLED.CLOSE",
|
|
289
|
+
previousEvent: event
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
337
294
|
});
|
|
295
|
+
function getReturnFocusOptions(event) {
|
|
296
|
+
return event.focusVisible ?? event.previousEvent?.focusVisible ? {
|
|
297
|
+
preventScroll: true,
|
|
298
|
+
focusVisible: true
|
|
299
|
+
} : { preventScroll: true };
|
|
300
|
+
}
|
|
301
|
+
exports.machine = machine;
|