@zag-js/popover 0.2.5 → 0.2.6
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/chunk-3IPU3K2L.mjs +191 -0
- package/dist/chunk-B4ONYBLM.mjs +100 -0
- package/dist/chunk-CHAXY3HY.mjs +353 -0
- package/dist/chunk-KTOPDXGV.mjs +19 -0
- package/dist/index.d.ts +9 -952
- package/dist/index.js +46 -34
- package/dist/index.mjs +10 -622
- package/dist/popover.anatomy.d.ts +6 -0
- package/dist/popover.anatomy.js +44 -0
- package/dist/popover.anatomy.mjs +8 -0
- package/dist/popover.connect.d.ts +23 -0
- package/dist/popover.connect.js +317 -0
- package/dist/popover.connect.mjs +8 -0
- package/dist/popover.dom.d.ts +52 -0
- package/dist/popover.dom.js +210 -0
- package/dist/popover.dom.mjs +6 -0
- package/dist/popover.machine.d.ts +9 -0
- package/dist/popover.machine.js +559 -0
- package/dist/popover.machine.mjs +7 -0
- package/dist/popover.types.d.ts +84 -0
- package/dist/popover.types.js +18 -0
- package/dist/popover.types.mjs +0 -0
- package/package.json +25 -15
package/dist/index.mjs
CHANGED
|
@@ -1,625 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"description",
|
|
12
|
-
"closeTrigger"
|
|
13
|
-
);
|
|
14
|
-
var parts = anatomy.build();
|
|
15
|
-
|
|
16
|
-
// ../../utilities/dom/dist/index.mjs
|
|
17
|
-
var dataAttr = (guard) => {
|
|
18
|
-
return guard ? "" : void 0;
|
|
19
|
-
};
|
|
20
|
-
var runIfFn = (v, ...a) => {
|
|
21
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
22
|
-
return res != null ? res : void 0;
|
|
23
|
-
};
|
|
24
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
25
|
-
function isDocument(el) {
|
|
26
|
-
return el.nodeType === Node.DOCUMENT_NODE;
|
|
27
|
-
}
|
|
28
|
-
function isWindow(value) {
|
|
29
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
30
|
-
}
|
|
31
|
-
function isFrame(element) {
|
|
32
|
-
return element.localName === "iframe";
|
|
33
|
-
}
|
|
34
|
-
function getDocument(el) {
|
|
35
|
-
var _a;
|
|
36
|
-
if (isWindow(el))
|
|
37
|
-
return el.document;
|
|
38
|
-
if (isDocument(el))
|
|
39
|
-
return el;
|
|
40
|
-
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
41
|
-
}
|
|
42
|
-
function defineDomHelpers(helpers) {
|
|
43
|
-
const dom2 = {
|
|
44
|
-
getRootNode: (ctx) => {
|
|
45
|
-
var _a, _b;
|
|
46
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
47
|
-
},
|
|
48
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
49
|
-
getWin: (ctx) => {
|
|
50
|
-
var _a;
|
|
51
|
-
return (_a = dom2.getDoc(ctx).defaultView) != null ? _a : window;
|
|
52
|
-
},
|
|
53
|
-
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
54
|
-
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id),
|
|
55
|
-
createEmitter: (ctx, target) => {
|
|
56
|
-
const win = dom2.getWin(ctx);
|
|
57
|
-
return function emit(evt, detail, options) {
|
|
58
|
-
const { bubbles = true, cancelable, composed = true } = options != null ? options : {};
|
|
59
|
-
const eventName = `zag:${evt}`;
|
|
60
|
-
const init = { bubbles, cancelable, composed, detail };
|
|
61
|
-
const event = new win.CustomEvent(eventName, init);
|
|
62
|
-
target.dispatchEvent(event);
|
|
63
|
-
};
|
|
64
|
-
},
|
|
65
|
-
createListener: (target) => {
|
|
66
|
-
return function listen(evt, handler) {
|
|
67
|
-
const eventName = `zag:${evt}`;
|
|
68
|
-
const listener = (e) => handler(e);
|
|
69
|
-
target.addEventListener(eventName, listener);
|
|
70
|
-
return () => target.removeEventListener(eventName, listener);
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
return {
|
|
75
|
-
...dom2,
|
|
76
|
-
...helpers
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
function contains(parent, child) {
|
|
80
|
-
if (!parent)
|
|
81
|
-
return false;
|
|
82
|
-
return parent === child || isHTMLElement(parent) && isHTMLElement(child) && parent.contains(child);
|
|
83
|
-
}
|
|
84
|
-
function isHTMLElement(v) {
|
|
85
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
86
|
-
}
|
|
87
|
-
function isVisible(el) {
|
|
88
|
-
if (!isHTMLElement(el))
|
|
89
|
-
return false;
|
|
90
|
-
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
91
|
-
}
|
|
92
|
-
var isModifiedEvent = (v) => v.ctrlKey || v.altKey || v.metaKey;
|
|
93
|
-
function hasNegativeTabIndex(element) {
|
|
94
|
-
const tabIndex = parseInt(element.getAttribute("tabindex") || "0", 10);
|
|
95
|
-
return tabIndex < 0;
|
|
96
|
-
}
|
|
97
|
-
var focusableSelector = "input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], button:not([disabled]), [tabindex], iframe, object, embed, area[href], audio[controls], video[controls], [contenteditable]:not([contenteditable='false']), details > summary:first-of-type";
|
|
98
|
-
var getFocusables = (container, includeContainer = false) => {
|
|
99
|
-
if (!container)
|
|
100
|
-
return [];
|
|
101
|
-
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
102
|
-
const include = includeContainer == true || includeContainer == "if-empty" && elements.length === 0;
|
|
103
|
-
if (include && isHTMLElement(container) && isFocusable(container)) {
|
|
104
|
-
elements.unshift(container);
|
|
105
|
-
}
|
|
106
|
-
const focusableElements = elements.filter(isFocusable);
|
|
107
|
-
focusableElements.forEach((element, i) => {
|
|
108
|
-
if (isFrame(element) && element.contentDocument) {
|
|
109
|
-
const frameBody = element.contentDocument.body;
|
|
110
|
-
focusableElements.splice(i, 1, ...getFocusables(frameBody));
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
return focusableElements;
|
|
114
|
-
};
|
|
115
|
-
function isFocusable(element) {
|
|
116
|
-
if (!element)
|
|
117
|
-
return false;
|
|
118
|
-
return element.matches(focusableSelector) && isVisible(element);
|
|
119
|
-
}
|
|
120
|
-
function getTabbables(container, includeContainer) {
|
|
121
|
-
if (!container)
|
|
122
|
-
return [];
|
|
123
|
-
const elements = Array.from(container.querySelectorAll(focusableSelector));
|
|
124
|
-
const tabbableElements = elements.filter(isTabbable);
|
|
125
|
-
if (includeContainer && isTabbable(container)) {
|
|
126
|
-
tabbableElements.unshift(container);
|
|
127
|
-
}
|
|
128
|
-
tabbableElements.forEach((element, i) => {
|
|
129
|
-
if (isFrame(element) && element.contentDocument) {
|
|
130
|
-
const frameBody = element.contentDocument.body;
|
|
131
|
-
const allFrameTabbable = getTabbables(frameBody);
|
|
132
|
-
tabbableElements.splice(i, 1, ...allFrameTabbable);
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
if (!tabbableElements.length && includeContainer) {
|
|
136
|
-
return elements;
|
|
137
|
-
}
|
|
138
|
-
return tabbableElements;
|
|
139
|
-
}
|
|
140
|
-
function isTabbable(el) {
|
|
141
|
-
return isFocusable(el) && !hasNegativeTabIndex(el);
|
|
142
|
-
}
|
|
143
|
-
function getFirstTabbable(container, includeContainer) {
|
|
144
|
-
const [first] = getTabbables(container, includeContainer);
|
|
145
|
-
return first || null;
|
|
146
|
-
}
|
|
147
|
-
function getLastTabbable(container, includeContainer) {
|
|
148
|
-
const elements = getTabbables(container, includeContainer);
|
|
149
|
-
return elements[elements.length - 1] || null;
|
|
150
|
-
}
|
|
151
|
-
var isRef = (v) => hasProp(v, "current");
|
|
152
|
-
function addDomEvent(target, eventName, handler, options) {
|
|
153
|
-
const node = isRef(target) ? target.current : runIfFn(target);
|
|
154
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
155
|
-
return () => {
|
|
156
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
function nextTick(fn) {
|
|
160
|
-
const set = /* @__PURE__ */ new Set();
|
|
161
|
-
function raf2(fn2) {
|
|
162
|
-
const id = globalThis.requestAnimationFrame(fn2);
|
|
163
|
-
set.add(() => globalThis.cancelAnimationFrame(id));
|
|
164
|
-
}
|
|
165
|
-
raf2(() => raf2(fn));
|
|
166
|
-
return function cleanup() {
|
|
167
|
-
set.forEach(function(fn2) {
|
|
168
|
-
fn2();
|
|
169
|
-
});
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
function raf(fn) {
|
|
173
|
-
const id = globalThis.requestAnimationFrame(fn);
|
|
174
|
-
return function cleanup() {
|
|
175
|
-
globalThis.cancelAnimationFrame(id);
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// src/popover.connect.ts
|
|
180
|
-
import { getPlacementStyles } from "@zag-js/popper";
|
|
181
|
-
|
|
182
|
-
// ../../utilities/core/dist/index.mjs
|
|
183
|
-
function nextIndex(v, idx, opts = {}) {
|
|
184
|
-
const { step = 1, loop = true } = opts;
|
|
185
|
-
const next2 = idx + step;
|
|
186
|
-
const len = v.length;
|
|
187
|
-
const last2 = len - 1;
|
|
188
|
-
if (idx === -1)
|
|
189
|
-
return step > 0 ? 0 : last2;
|
|
190
|
-
if (next2 < 0)
|
|
191
|
-
return loop ? last2 : 0;
|
|
192
|
-
if (next2 >= len)
|
|
193
|
-
return loop ? 0 : idx > len ? len : idx;
|
|
194
|
-
return next2;
|
|
195
|
-
}
|
|
196
|
-
function next(v, idx, opts = {}) {
|
|
197
|
-
return v[nextIndex(v, idx, opts)];
|
|
198
|
-
}
|
|
199
|
-
var runIfFn2 = (v, ...a) => {
|
|
200
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
201
|
-
return res != null ? res : void 0;
|
|
202
|
-
};
|
|
203
|
-
var isArray = (v) => Array.isArray(v);
|
|
204
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
205
|
-
function compact(obj) {
|
|
206
|
-
if (obj === void 0)
|
|
207
|
-
return obj;
|
|
208
|
-
return Object.fromEntries(
|
|
209
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// src/popover.dom.ts
|
|
214
|
-
var dom = defineDomHelpers({
|
|
215
|
-
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
216
|
-
getAnchorId: (ctx) => {
|
|
217
|
-
var _a, _b;
|
|
218
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.anchor) != null ? _b : `popover:${ctx.id}:anchor`;
|
|
219
|
-
},
|
|
220
|
-
getTriggerId: (ctx) => {
|
|
221
|
-
var _a, _b;
|
|
222
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.trigger) != null ? _b : `popover:${ctx.id}:trigger`;
|
|
223
|
-
},
|
|
224
|
-
getContentId: (ctx) => {
|
|
225
|
-
var _a, _b;
|
|
226
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.content) != null ? _b : `popover:${ctx.id}:content`;
|
|
227
|
-
},
|
|
228
|
-
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
229
|
-
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
230
|
-
getTitleId: (ctx) => {
|
|
231
|
-
var _a, _b;
|
|
232
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.title) != null ? _b : `popover:${ctx.id}:title`;
|
|
233
|
-
},
|
|
234
|
-
getDescriptionId: (ctx) => {
|
|
235
|
-
var _a, _b;
|
|
236
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.description) != null ? _b : `popover:${ctx.id}:desc`;
|
|
237
|
-
},
|
|
238
|
-
getCloseTriggerId: (ctx) => {
|
|
239
|
-
var _a, _b;
|
|
240
|
-
return (_b = (_a = ctx.ids) == null ? void 0 : _a.closeTrigger) != null ? _b : `popover:${ctx.id}:close`;
|
|
241
|
-
},
|
|
242
|
-
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
243
|
-
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
244
|
-
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
245
|
-
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
246
|
-
getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
|
|
247
|
-
getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
|
|
248
|
-
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
249
|
-
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
250
|
-
getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
|
|
251
|
-
getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
|
|
252
|
-
getFirstTabbableEl: (ctx) => getFirstTabbable(dom.getContentEl(ctx), "if-empty"),
|
|
253
|
-
getLastTabbableEl: (ctx) => getLastTabbable(dom.getContentEl(ctx), "if-empty"),
|
|
254
|
-
getInitialFocusEl: (ctx) => {
|
|
255
|
-
let el = runIfFn2(ctx.initialFocusEl);
|
|
256
|
-
if (!el && ctx.autoFocus)
|
|
257
|
-
el = dom.getFirstFocusableEl(ctx);
|
|
258
|
-
if (!el)
|
|
259
|
-
el = dom.getContentEl(ctx);
|
|
260
|
-
return el;
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
// src/popover.connect.ts
|
|
265
|
-
function connect(state, send, normalize) {
|
|
266
|
-
const isOpen = state.matches("open");
|
|
267
|
-
const currentPlacement = state.context.currentPlacement;
|
|
268
|
-
const portalled = state.context.currentPortalled;
|
|
269
|
-
const rendered = state.context.renderedElements;
|
|
270
|
-
const popperStyles = getPlacementStyles({
|
|
271
|
-
measured: !!state.context.isPlacementComplete,
|
|
272
|
-
placement: currentPlacement
|
|
273
|
-
});
|
|
274
|
-
return {
|
|
275
|
-
portalled,
|
|
276
|
-
isOpen,
|
|
277
|
-
open() {
|
|
278
|
-
send("OPEN");
|
|
279
|
-
},
|
|
280
|
-
close() {
|
|
281
|
-
send("CLOSE");
|
|
282
|
-
},
|
|
283
|
-
arrowProps: normalize.element({
|
|
284
|
-
id: dom.getArrowId(state.context),
|
|
285
|
-
...parts.arrow.attrs,
|
|
286
|
-
style: popperStyles.arrow
|
|
287
|
-
}),
|
|
288
|
-
arrowTipProps: normalize.element({
|
|
289
|
-
...parts.arrowTip.attrs,
|
|
290
|
-
style: popperStyles.arrowTip
|
|
291
|
-
}),
|
|
292
|
-
anchorProps: normalize.element({
|
|
293
|
-
...parts.anchor.attrs,
|
|
294
|
-
id: dom.getAnchorId(state.context)
|
|
295
|
-
}),
|
|
296
|
-
triggerProps: normalize.button({
|
|
297
|
-
...parts.trigger.attrs,
|
|
298
|
-
type: "button",
|
|
299
|
-
"data-placement": currentPlacement,
|
|
300
|
-
id: dom.getTriggerId(state.context),
|
|
301
|
-
"aria-haspopup": "dialog",
|
|
302
|
-
"aria-expanded": isOpen,
|
|
303
|
-
"data-expanded": dataAttr(isOpen),
|
|
304
|
-
"aria-controls": dom.getContentId(state.context),
|
|
305
|
-
onClick() {
|
|
306
|
-
send("TOGGLE");
|
|
307
|
-
},
|
|
308
|
-
onBlur(event) {
|
|
309
|
-
send({ type: "TRIGGER_BLUR", target: event.relatedTarget });
|
|
310
|
-
}
|
|
311
|
-
}),
|
|
312
|
-
positionerProps: normalize.element({
|
|
313
|
-
id: dom.getPositionerId(state.context),
|
|
314
|
-
...parts.positioner.attrs,
|
|
315
|
-
style: popperStyles.floating
|
|
316
|
-
}),
|
|
317
|
-
contentProps: normalize.element({
|
|
318
|
-
...parts.content.attrs,
|
|
319
|
-
id: dom.getContentId(state.context),
|
|
320
|
-
tabIndex: -1,
|
|
321
|
-
role: "dialog",
|
|
322
|
-
hidden: !isOpen,
|
|
323
|
-
"data-expanded": dataAttr(isOpen),
|
|
324
|
-
"aria-labelledby": rendered.title ? dom.getTitleId(state.context) : void 0,
|
|
325
|
-
"aria-describedby": rendered.description ? dom.getDescriptionId(state.context) : void 0,
|
|
326
|
-
"data-placement": currentPlacement
|
|
327
|
-
}),
|
|
328
|
-
titleProps: normalize.element({
|
|
329
|
-
...parts.title.attrs,
|
|
330
|
-
id: dom.getTitleId(state.context)
|
|
331
|
-
}),
|
|
332
|
-
descriptionProps: normalize.element({
|
|
333
|
-
...parts.description.attrs,
|
|
334
|
-
id: dom.getDescriptionId(state.context)
|
|
335
|
-
}),
|
|
336
|
-
closeTriggerProps: normalize.button({
|
|
337
|
-
...parts.closeTrigger.attrs,
|
|
338
|
-
id: dom.getCloseTriggerId(state.context),
|
|
339
|
-
type: "button",
|
|
340
|
-
"aria-label": "close",
|
|
341
|
-
onClick() {
|
|
342
|
-
send("REQUEST_CLOSE");
|
|
343
|
-
}
|
|
344
|
-
})
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
// src/popover.machine.ts
|
|
349
|
-
import { ariaHidden } from "@zag-js/aria-hidden";
|
|
350
|
-
import { createMachine, guards } from "@zag-js/core";
|
|
351
|
-
import { trackDismissableElement } from "@zag-js/dismissable";
|
|
352
|
-
import { getPlacement } from "@zag-js/popper";
|
|
353
|
-
import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
354
|
-
import { createFocusTrap } from "focus-trap";
|
|
355
|
-
var { and, or, not } = guards;
|
|
356
|
-
function machine(userContext) {
|
|
357
|
-
const ctx = compact(userContext);
|
|
358
|
-
return createMachine(
|
|
359
|
-
{
|
|
360
|
-
id: "popover",
|
|
361
|
-
initial: "unknown",
|
|
362
|
-
context: {
|
|
363
|
-
closeOnInteractOutside: true,
|
|
364
|
-
closeOnEsc: true,
|
|
365
|
-
autoFocus: true,
|
|
366
|
-
modal: false,
|
|
367
|
-
positioning: {
|
|
368
|
-
placement: "bottom",
|
|
369
|
-
...ctx.positioning
|
|
370
|
-
},
|
|
371
|
-
currentPlacement: void 0,
|
|
372
|
-
...ctx,
|
|
373
|
-
focusTriggerOnClose: true,
|
|
374
|
-
renderedElements: {
|
|
375
|
-
title: true,
|
|
376
|
-
description: true,
|
|
377
|
-
anchor: false
|
|
378
|
-
}
|
|
379
|
-
},
|
|
380
|
-
computed: {
|
|
381
|
-
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
382
|
-
},
|
|
383
|
-
states: {
|
|
384
|
-
unknown: {
|
|
385
|
-
on: {
|
|
386
|
-
SETUP: {
|
|
387
|
-
target: ctx.defaultOpen ? "open" : "closed",
|
|
388
|
-
actions: "checkRenderedElements"
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
},
|
|
392
|
-
closed: {
|
|
393
|
-
entry: "invokeOnClose",
|
|
394
|
-
on: {
|
|
395
|
-
TOGGLE: "open",
|
|
396
|
-
OPEN: "open"
|
|
397
|
-
}
|
|
398
|
-
},
|
|
399
|
-
open: {
|
|
400
|
-
activities: [
|
|
401
|
-
"trapFocus",
|
|
402
|
-
"preventScroll",
|
|
403
|
-
"hideContentBelow",
|
|
404
|
-
"computePlacement",
|
|
405
|
-
"trackInteractionOutside",
|
|
406
|
-
"trackTabKeyDown"
|
|
407
|
-
],
|
|
408
|
-
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
409
|
-
on: {
|
|
410
|
-
CLOSE: "closed",
|
|
411
|
-
REQUEST_CLOSE: {
|
|
412
|
-
target: "closed",
|
|
413
|
-
actions: "focusTriggerIfNeeded"
|
|
414
|
-
},
|
|
415
|
-
TOGGLE: "closed",
|
|
416
|
-
TRIGGER_BLUR: {
|
|
417
|
-
guard: not("isRelatedTargetWithinContent"),
|
|
418
|
-
target: "closed"
|
|
419
|
-
},
|
|
420
|
-
TAB: [
|
|
421
|
-
{
|
|
422
|
-
guard: and("isTriggerFocused", "portalled"),
|
|
423
|
-
actions: "focusFirstTabbableElement"
|
|
424
|
-
},
|
|
425
|
-
{
|
|
426
|
-
guard: and("isLastTabbableElement", "closeOnInteractOutside", "portalled"),
|
|
427
|
-
target: "closed",
|
|
428
|
-
actions: "focusNextTabbableElementAfterTrigger"
|
|
429
|
-
}
|
|
430
|
-
],
|
|
431
|
-
SHIFT_TAB: {
|
|
432
|
-
guard: and(or("isFirstTabbableElement", "isContentFocused"), "portalled"),
|
|
433
|
-
actions: "focusTriggerIfNeeded"
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
},
|
|
439
|
-
{
|
|
440
|
-
activities: {
|
|
441
|
-
computePlacement(ctx2) {
|
|
442
|
-
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
443
|
-
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
444
|
-
return getPlacement(anchorEl, dom.getPositionerEl(ctx2), {
|
|
445
|
-
...ctx2.positioning,
|
|
446
|
-
onComplete(data) {
|
|
447
|
-
ctx2.currentPlacement = data.placement;
|
|
448
|
-
ctx2.isPlacementComplete = true;
|
|
449
|
-
},
|
|
450
|
-
onCleanup() {
|
|
451
|
-
ctx2.currentPlacement = void 0;
|
|
452
|
-
ctx2.isPlacementComplete = false;
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
},
|
|
456
|
-
trackInteractionOutside(ctx2, _evt, { send }) {
|
|
457
|
-
return trackDismissableElement(dom.getContentEl(ctx2), {
|
|
458
|
-
pointerBlocking: ctx2.modal,
|
|
459
|
-
exclude: dom.getTriggerEl(ctx2),
|
|
460
|
-
onEscapeKeyDown(event) {
|
|
461
|
-
var _a;
|
|
462
|
-
(_a = ctx2.onEscapeKeyDown) == null ? void 0 : _a.call(ctx2, event);
|
|
463
|
-
if (ctx2.closeOnEsc)
|
|
464
|
-
return;
|
|
465
|
-
ctx2.focusTriggerOnClose = true;
|
|
466
|
-
event.preventDefault();
|
|
467
|
-
},
|
|
468
|
-
onInteractOutside(event) {
|
|
469
|
-
var _a;
|
|
470
|
-
(_a = ctx2.onInteractOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
471
|
-
if (event.defaultPrevented)
|
|
472
|
-
return;
|
|
473
|
-
ctx2.focusTriggerOnClose = !(event.detail.focusable || event.detail.contextmenu);
|
|
474
|
-
if (!ctx2.closeOnInteractOutside) {
|
|
475
|
-
event.preventDefault();
|
|
476
|
-
}
|
|
477
|
-
},
|
|
478
|
-
onPointerDownOutside(event) {
|
|
479
|
-
var _a;
|
|
480
|
-
(_a = ctx2.onPointerDownOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
481
|
-
},
|
|
482
|
-
onFocusOutside(event) {
|
|
483
|
-
var _a;
|
|
484
|
-
(_a = ctx2.onFocusOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
485
|
-
if (ctx2.currentPortalled) {
|
|
486
|
-
event.preventDefault();
|
|
487
|
-
}
|
|
488
|
-
},
|
|
489
|
-
onDismiss() {
|
|
490
|
-
send({ type: "REQUEST_CLOSE", src: "#interact-outside" });
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
},
|
|
494
|
-
trackTabKeyDown(ctx2, _evt, { send }) {
|
|
495
|
-
if (ctx2.modal)
|
|
496
|
-
return;
|
|
497
|
-
return addDomEvent(
|
|
498
|
-
dom.getWin(ctx2),
|
|
499
|
-
"keydown",
|
|
500
|
-
(event) => {
|
|
501
|
-
const isTabKey = event.key === "Tab" && !isModifiedEvent(event);
|
|
502
|
-
if (!isTabKey)
|
|
503
|
-
return;
|
|
504
|
-
send({
|
|
505
|
-
type: event.shiftKey ? "SHIFT_TAB" : "TAB",
|
|
506
|
-
preventDefault: () => event.preventDefault()
|
|
507
|
-
});
|
|
508
|
-
},
|
|
509
|
-
true
|
|
510
|
-
);
|
|
511
|
-
},
|
|
512
|
-
hideContentBelow(ctx2) {
|
|
513
|
-
if (!ctx2.modal)
|
|
514
|
-
return;
|
|
515
|
-
let cleanup;
|
|
516
|
-
nextTick(() => {
|
|
517
|
-
cleanup = ariaHidden([dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)]);
|
|
518
|
-
});
|
|
519
|
-
return () => cleanup == null ? void 0 : cleanup();
|
|
520
|
-
},
|
|
521
|
-
preventScroll(ctx2) {
|
|
522
|
-
if (!ctx2.modal)
|
|
523
|
-
return;
|
|
524
|
-
return preventBodyScroll(dom.getDoc(ctx2));
|
|
525
|
-
},
|
|
526
|
-
trapFocus(ctx2) {
|
|
527
|
-
if (!ctx2.modal)
|
|
528
|
-
return;
|
|
529
|
-
let trap;
|
|
530
|
-
nextTick(() => {
|
|
531
|
-
const el = dom.getContentEl(ctx2);
|
|
532
|
-
if (!el)
|
|
533
|
-
return;
|
|
534
|
-
trap = createFocusTrap(el, {
|
|
535
|
-
escapeDeactivates: false,
|
|
536
|
-
allowOutsideClick: true,
|
|
537
|
-
returnFocusOnDeactivate: true,
|
|
538
|
-
document: dom.getDoc(ctx2),
|
|
539
|
-
fallbackFocus: el,
|
|
540
|
-
initialFocus: runIfFn2(ctx2.initialFocusEl)
|
|
541
|
-
});
|
|
542
|
-
try {
|
|
543
|
-
trap.activate();
|
|
544
|
-
} catch {
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
return () => trap == null ? void 0 : trap.deactivate();
|
|
548
|
-
}
|
|
549
|
-
},
|
|
550
|
-
guards: {
|
|
551
|
-
portalled: (ctx2) => ctx2.currentPortalled,
|
|
552
|
-
isRelatedTargetWithinContent: (ctx2, evt) => contains(dom.getContentEl(ctx2), evt.target),
|
|
553
|
-
closeOnInteractOutside: (ctx2) => !!ctx2.closeOnInteractOutside,
|
|
554
|
-
isContentFocused: (ctx2) => dom.getContentEl(ctx2) === dom.getActiveEl(ctx2),
|
|
555
|
-
isTriggerFocused: (ctx2) => dom.getTriggerEl(ctx2) === dom.getActiveEl(ctx2),
|
|
556
|
-
isFirstTabbableElement: (ctx2) => dom.getFirstTabbableEl(ctx2) === dom.getActiveEl(ctx2),
|
|
557
|
-
isLastTabbableElement: (ctx2) => dom.getLastTabbableEl(ctx2) === dom.getActiveEl(ctx2)
|
|
558
|
-
},
|
|
559
|
-
actions: {
|
|
560
|
-
checkRenderedElements(ctx2) {
|
|
561
|
-
raf(() => {
|
|
562
|
-
Object.assign(ctx2.renderedElements, {
|
|
563
|
-
title: !!dom.getTitleEl(ctx2),
|
|
564
|
-
description: !!dom.getDescriptionEl(ctx2),
|
|
565
|
-
anchor: !!dom.getAnchorEl(ctx2)
|
|
566
|
-
});
|
|
567
|
-
});
|
|
568
|
-
},
|
|
569
|
-
setInitialFocus(ctx2) {
|
|
570
|
-
raf(() => {
|
|
571
|
-
var _a;
|
|
572
|
-
(_a = dom.getInitialFocusEl(ctx2)) == null ? void 0 : _a.focus();
|
|
573
|
-
});
|
|
574
|
-
},
|
|
575
|
-
focusTriggerIfNeeded(ctx2) {
|
|
576
|
-
if (!ctx2.focusTriggerOnClose)
|
|
577
|
-
return;
|
|
578
|
-
raf(() => {
|
|
579
|
-
var _a;
|
|
580
|
-
return (_a = dom.getTriggerEl(ctx2)) == null ? void 0 : _a.focus();
|
|
581
|
-
});
|
|
582
|
-
},
|
|
583
|
-
focusFirstTabbableElement(ctx2, evt) {
|
|
584
|
-
var _a;
|
|
585
|
-
evt.preventDefault();
|
|
586
|
-
(_a = dom.getFirstTabbableEl(ctx2)) == null ? void 0 : _a.focus();
|
|
587
|
-
},
|
|
588
|
-
invokeOnOpen(ctx2, evt) {
|
|
589
|
-
var _a;
|
|
590
|
-
if (evt.type !== "SETUP") {
|
|
591
|
-
(_a = ctx2.onOpenChange) == null ? void 0 : _a.call(ctx2, true);
|
|
592
|
-
}
|
|
593
|
-
},
|
|
594
|
-
invokeOnClose(ctx2, evt) {
|
|
595
|
-
var _a;
|
|
596
|
-
if (evt.type !== "SETUP") {
|
|
597
|
-
(_a = ctx2.onOpenChange) == null ? void 0 : _a.call(ctx2, false);
|
|
598
|
-
}
|
|
599
|
-
},
|
|
600
|
-
focusNextTabbableElementAfterTrigger(ctx2, evt) {
|
|
601
|
-
const content = dom.getContentEl(ctx2);
|
|
602
|
-
const button = dom.getTriggerEl(ctx2);
|
|
603
|
-
if (!content || !button)
|
|
604
|
-
return;
|
|
605
|
-
const lastTabbable = dom.getLastTabbableEl(ctx2);
|
|
606
|
-
if (lastTabbable !== dom.getActiveEl(ctx2))
|
|
607
|
-
return;
|
|
608
|
-
let tabbables = dom.getDocTabbableEls(ctx2);
|
|
609
|
-
let elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
610
|
-
if (elementAfterTrigger === content) {
|
|
611
|
-
tabbables = tabbables.filter((el) => !contains(content, el));
|
|
612
|
-
elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
613
|
-
}
|
|
614
|
-
if (!elementAfterTrigger || elementAfterTrigger === button)
|
|
615
|
-
return;
|
|
616
|
-
evt.preventDefault();
|
|
617
|
-
raf(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
);
|
|
622
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
connect
|
|
3
|
+
} from "./chunk-B4ONYBLM.mjs";
|
|
4
|
+
import {
|
|
5
|
+
anatomy
|
|
6
|
+
} from "./chunk-KTOPDXGV.mjs";
|
|
7
|
+
import {
|
|
8
|
+
machine
|
|
9
|
+
} from "./chunk-CHAXY3HY.mjs";
|
|
10
|
+
import "./chunk-3IPU3K2L.mjs";
|
|
623
11
|
export {
|
|
624
12
|
anatomy,
|
|
625
13
|
connect,
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as _zag_js_anatomy from '@zag-js/anatomy';
|
|
2
|
+
|
|
3
|
+
declare const anatomy: _zag_js_anatomy.AnatomyInstance<"arrow" | "arrowTip" | "anchor" | "trigger" | "positioner" | "content" | "title" | "description" | "closeTrigger">;
|
|
4
|
+
declare const parts: Record<"arrow" | "arrowTip" | "anchor" | "trigger" | "positioner" | "content" | "title" | "description" | "closeTrigger", _zag_js_anatomy.AnatomyPart>;
|
|
5
|
+
|
|
6
|
+
export { anatomy, parts };
|
|
@@ -0,0 +1,44 @@
|
|
|
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/popover.anatomy.ts
|
|
21
|
+
var popover_anatomy_exports = {};
|
|
22
|
+
__export(popover_anatomy_exports, {
|
|
23
|
+
anatomy: () => anatomy,
|
|
24
|
+
parts: () => parts
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(popover_anatomy_exports);
|
|
27
|
+
var import_anatomy = require("@zag-js/anatomy");
|
|
28
|
+
var anatomy = (0, import_anatomy.createAnatomy)("popover").parts(
|
|
29
|
+
"arrow",
|
|
30
|
+
"arrowTip",
|
|
31
|
+
"anchor",
|
|
32
|
+
"trigger",
|
|
33
|
+
"positioner",
|
|
34
|
+
"content",
|
|
35
|
+
"title",
|
|
36
|
+
"description",
|
|
37
|
+
"closeTrigger"
|
|
38
|
+
);
|
|
39
|
+
var parts = anatomy.build();
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
anatomy,
|
|
43
|
+
parts
|
|
44
|
+
});
|