@zag-js/popover 0.1.4 → 0.1.7
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.js +61 -291
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +61 -291
- package/dist/index.mjs.map +3 -3
- package/dist/popover.connect.d.ts.map +1 -1
- package/dist/popover.dom.d.ts.map +1 -1
- package/dist/popover.machine.d.ts.map +1 -1
- package/dist/popover.types.d.ts +10 -13
- package/dist/popover.types.d.ts.map +1 -1
- package/package.json +7 -6
package/dist/index.js
CHANGED
|
@@ -41,115 +41,6 @@ __export(src_exports, {
|
|
|
41
41
|
});
|
|
42
42
|
module.exports = __toCommonJS(src_exports);
|
|
43
43
|
|
|
44
|
-
// ../../../node_modules/compute-scroll-into-view/dist/index.module.js
|
|
45
|
-
function t(t3) {
|
|
46
|
-
return typeof t3 == "object" && t3 != null && t3.nodeType === 1;
|
|
47
|
-
}
|
|
48
|
-
function e(t3, e2) {
|
|
49
|
-
return (!e2 || t3 !== "hidden") && t3 !== "visible" && t3 !== "clip";
|
|
50
|
-
}
|
|
51
|
-
function n(t3, n2) {
|
|
52
|
-
if (t3.clientHeight < t3.scrollHeight || t3.clientWidth < t3.scrollWidth) {
|
|
53
|
-
var r2 = getComputedStyle(t3, null);
|
|
54
|
-
return e(r2.overflowY, n2) || e(r2.overflowX, n2) || function(t4) {
|
|
55
|
-
var e2 = function(t5) {
|
|
56
|
-
if (!t5.ownerDocument || !t5.ownerDocument.defaultView)
|
|
57
|
-
return null;
|
|
58
|
-
try {
|
|
59
|
-
return t5.ownerDocument.defaultView.frameElement;
|
|
60
|
-
} catch (t6) {
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
}(t4);
|
|
64
|
-
return !!e2 && (e2.clientHeight < t4.scrollHeight || e2.clientWidth < t4.scrollWidth);
|
|
65
|
-
}(t3);
|
|
66
|
-
}
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
function r(t3, e2, n2, r2, i, o, l, d) {
|
|
70
|
-
return o < t3 && l > e2 || o > t3 && l < e2 ? 0 : o <= t3 && d <= n2 || l >= e2 && d >= n2 ? o - t3 - r2 : l > e2 && d < n2 || o < t3 && d > n2 ? l - e2 + i : 0;
|
|
71
|
-
}
|
|
72
|
-
function index_module_default(e2, i) {
|
|
73
|
-
var o = window, l = i.scrollMode, d = i.block, u = i.inline, h = i.boundary, a = i.skipOverflowHiddenElements, c = typeof h == "function" ? h : function(t3) {
|
|
74
|
-
return t3 !== h;
|
|
75
|
-
};
|
|
76
|
-
if (!t(e2))
|
|
77
|
-
throw new TypeError("Invalid target");
|
|
78
|
-
for (var f = document.scrollingElement || document.documentElement, s = [], p = e2; t(p) && c(p); ) {
|
|
79
|
-
if ((p = p.parentElement) === f) {
|
|
80
|
-
s.push(p);
|
|
81
|
-
break;
|
|
82
|
-
}
|
|
83
|
-
p != null && p === document.body && n(p) && !n(document.documentElement) || p != null && n(p, a) && s.push(p);
|
|
84
|
-
}
|
|
85
|
-
for (var m = o.visualViewport ? o.visualViewport.width : innerWidth, g = o.visualViewport ? o.visualViewport.height : innerHeight, w = window.scrollX || pageXOffset, v = window.scrollY || pageYOffset, W = e2.getBoundingClientRect(), b = W.height, H = W.width, y = W.top, E = W.right, M = W.bottom, V = W.left, x = d === "start" || d === "nearest" ? y : d === "end" ? M : y + b / 2, I = u === "center" ? V + H / 2 : u === "end" ? E : V, C = [], T = 0; T < s.length; T++) {
|
|
86
|
-
var k = s[T], B = k.getBoundingClientRect(), D = B.height, O = B.width, R = B.top, X = B.right, Y = B.bottom, L = B.left;
|
|
87
|
-
if (l === "if-needed" && y >= 0 && V >= 0 && M <= g && E <= m && y >= R && M <= Y && V >= L && E <= X)
|
|
88
|
-
return C;
|
|
89
|
-
var S = getComputedStyle(k), j = parseInt(S.borderLeftWidth, 10), q = parseInt(S.borderTopWidth, 10), z = parseInt(S.borderRightWidth, 10), A = parseInt(S.borderBottomWidth, 10), F = 0, G = 0, J = "offsetWidth" in k ? k.offsetWidth - k.clientWidth - j - z : 0, K = "offsetHeight" in k ? k.offsetHeight - k.clientHeight - q - A : 0;
|
|
90
|
-
if (f === k)
|
|
91
|
-
F = d === "start" ? x : d === "end" ? x - g : d === "nearest" ? r(v, v + g, g, q, A, v + x, v + x + b, b) : x - g / 2, G = u === "start" ? I : u === "center" ? I - m / 2 : u === "end" ? I - m : r(w, w + m, m, j, z, w + I, w + I + H, H), F = Math.max(0, F + v), G = Math.max(0, G + w);
|
|
92
|
-
else {
|
|
93
|
-
F = d === "start" ? x - R - q : d === "end" ? x - Y + A + K : d === "nearest" ? r(R, Y, D, q, A + K, x, x + b, b) : x - (R + D / 2) + K / 2, G = u === "start" ? I - L - j : u === "center" ? I - (L + O / 2) + J / 2 : u === "end" ? I - X + z + J : r(L, X, O, j, z + J, I, I + H, H);
|
|
94
|
-
var N = k.scrollLeft, P = k.scrollTop;
|
|
95
|
-
x += P - (F = Math.max(0, Math.min(P + F, k.scrollHeight - D + K))), I += N - (G = Math.max(0, Math.min(N + G, k.scrollWidth - O + J)));
|
|
96
|
-
}
|
|
97
|
-
C.push({ el: k, top: F, left: G });
|
|
98
|
-
}
|
|
99
|
-
return C;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// ../../utilities/dom/node_modules/scroll-into-view-if-needed/es/index.js
|
|
103
|
-
function isOptionsObject(options) {
|
|
104
|
-
return options === Object(options) && Object.keys(options).length !== 0;
|
|
105
|
-
}
|
|
106
|
-
function defaultBehavior(actions, behavior) {
|
|
107
|
-
if (behavior === void 0) {
|
|
108
|
-
behavior = "auto";
|
|
109
|
-
}
|
|
110
|
-
var canSmoothScroll = "scrollBehavior" in document.body.style;
|
|
111
|
-
actions.forEach(function(_ref) {
|
|
112
|
-
var el = _ref.el, top = _ref.top, left = _ref.left;
|
|
113
|
-
if (el.scroll && canSmoothScroll) {
|
|
114
|
-
el.scroll({
|
|
115
|
-
top,
|
|
116
|
-
left,
|
|
117
|
-
behavior
|
|
118
|
-
});
|
|
119
|
-
} else {
|
|
120
|
-
el.scrollTop = top;
|
|
121
|
-
el.scrollLeft = left;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
function getOptions(options) {
|
|
126
|
-
if (options === false) {
|
|
127
|
-
return {
|
|
128
|
-
block: "end",
|
|
129
|
-
inline: "nearest"
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
if (isOptionsObject(options)) {
|
|
133
|
-
return options;
|
|
134
|
-
}
|
|
135
|
-
return {
|
|
136
|
-
block: "start",
|
|
137
|
-
inline: "nearest"
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
function scrollIntoView(target, options) {
|
|
141
|
-
var isTargetAttached = target.isConnected || target.ownerDocument.documentElement.contains(target);
|
|
142
|
-
if (isOptionsObject(options) && typeof options.behavior === "function") {
|
|
143
|
-
return options.behavior(isTargetAttached ? index_module_default(target, options) : []);
|
|
144
|
-
}
|
|
145
|
-
if (!isTargetAttached) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
var computeOptions = getOptions(options);
|
|
149
|
-
return defaultBehavior(index_module_default(target, computeOptions), computeOptions.behavior);
|
|
150
|
-
}
|
|
151
|
-
var es_default = scrollIntoView;
|
|
152
|
-
|
|
153
44
|
// ../../utilities/dom/dist/index.mjs
|
|
154
45
|
var dataAttr = (guard) => {
|
|
155
46
|
return guard ? "" : void 0;
|
|
@@ -191,16 +82,17 @@ function raf(fn) {
|
|
|
191
82
|
globalThis.cancelAnimationFrame(id);
|
|
192
83
|
};
|
|
193
84
|
}
|
|
85
|
+
var isDom = () => typeof window !== "undefined";
|
|
86
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
87
|
+
var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
|
|
88
|
+
var isLeftClick = (v) => v.button === 0;
|
|
89
|
+
var runIfFn = (v, ...a) => {
|
|
90
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
91
|
+
return res != null ? res : void 0;
|
|
92
|
+
};
|
|
194
93
|
var noop = () => {
|
|
195
94
|
};
|
|
196
95
|
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
197
|
-
var platform = (v) => isDom() && v.test(navigator.platform);
|
|
198
|
-
var isDom = () => !!(typeof window !== "undefined");
|
|
199
|
-
var isMac = () => platform(/^Mac/);
|
|
200
|
-
var isIPhone = () => platform(/^iPhone/);
|
|
201
|
-
var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
|
|
202
|
-
var isIos = () => isIPhone() || isIPad();
|
|
203
|
-
var isLeftClick = (v) => v.button === 0;
|
|
204
96
|
function getListenerElements() {
|
|
205
97
|
;
|
|
206
98
|
globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
|
|
@@ -211,7 +103,7 @@ function getListenerCache() {
|
|
|
211
103
|
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
|
|
212
104
|
return globalThis.__listenerCache__;
|
|
213
105
|
}
|
|
214
|
-
function
|
|
106
|
+
function addGlobalEventListener(node, type, handler, options) {
|
|
215
107
|
var _a;
|
|
216
108
|
if (!node)
|
|
217
109
|
return noop;
|
|
@@ -263,12 +155,10 @@ function globalEventBus(node, type, handler, options) {
|
|
|
263
155
|
}
|
|
264
156
|
};
|
|
265
157
|
}
|
|
266
|
-
var
|
|
267
|
-
var isRef = (v) => t2(v) === "Object" && "current" in v;
|
|
268
|
-
var runIfFn = (fn) => t2(fn) === "Function" ? fn() : fn;
|
|
158
|
+
var isRef = (v) => hasProp(v, "current");
|
|
269
159
|
function addDomEvent(target, event, listener, options) {
|
|
270
160
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
271
|
-
return
|
|
161
|
+
return addGlobalEventListener(node, event, listener, options);
|
|
272
162
|
}
|
|
273
163
|
var changeCount = 0;
|
|
274
164
|
var originalBodyPointerEvents;
|
|
@@ -328,21 +218,6 @@ function preventBodyPointerEvents(el, opts = {}) {
|
|
|
328
218
|
cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
|
|
329
219
|
};
|
|
330
220
|
}
|
|
331
|
-
function getOwnerDocument(el) {
|
|
332
|
-
var _a;
|
|
333
|
-
if (isWindow(el))
|
|
334
|
-
return el.document;
|
|
335
|
-
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
336
|
-
}
|
|
337
|
-
function getNodeName(node) {
|
|
338
|
-
return isWindow(node) ? "" : node ? node.localName || "" : "";
|
|
339
|
-
}
|
|
340
|
-
function getParent(el) {
|
|
341
|
-
const doc = getOwnerDocument(el);
|
|
342
|
-
if (getNodeName(el) === "html")
|
|
343
|
-
return el;
|
|
344
|
-
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
345
|
-
}
|
|
346
221
|
function contains(parent, child) {
|
|
347
222
|
if (!parent)
|
|
348
223
|
return false;
|
|
@@ -351,124 +226,9 @@ function contains(parent, child) {
|
|
|
351
226
|
function isHTMLElement(v) {
|
|
352
227
|
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
353
228
|
}
|
|
354
|
-
function isWindow(value) {
|
|
355
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
356
|
-
}
|
|
357
229
|
var isDisabled = (el) => {
|
|
358
230
|
return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true;
|
|
359
231
|
};
|
|
360
|
-
function isScrollParent(el) {
|
|
361
|
-
const { overflow, overflowX, overflowY } = getComputedStyle2(el);
|
|
362
|
-
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
363
|
-
}
|
|
364
|
-
function getScrollParent(el) {
|
|
365
|
-
if (["html", "body", "#document"].includes(getNodeName(el))) {
|
|
366
|
-
return getOwnerDocument(el).body;
|
|
367
|
-
}
|
|
368
|
-
if (isHTMLElement(el) && isScrollParent(el)) {
|
|
369
|
-
return el;
|
|
370
|
-
}
|
|
371
|
-
return getScrollParent(getParent(el));
|
|
372
|
-
}
|
|
373
|
-
var nonTextInputTypes = /* @__PURE__ */ new Set(["checkbox", "radio", "range", "color", "file", "image", "button", "submit", "reset"]);
|
|
374
|
-
function preventBodyScroll(opts) {
|
|
375
|
-
var _a;
|
|
376
|
-
const { document: docProp, disabled = false, allowPinchZoom } = opts != null ? opts : {};
|
|
377
|
-
const doc = docProp != null ? docProp : document;
|
|
378
|
-
const win = (_a = doc == null ? void 0 : doc.defaultView) != null ? _a : window;
|
|
379
|
-
const viewport = isDom() ? win.visualViewport : null;
|
|
380
|
-
const docEl = doc.documentElement;
|
|
381
|
-
function preventScrollStandard() {
|
|
382
|
-
if (docEl.hasAttribute("scroll-lock"))
|
|
383
|
-
return;
|
|
384
|
-
const fn = pipe(setStyle(docEl, "paddingRight", `${win.innerWidth - docEl.clientWidth}px`), setStyle(docEl, "overflow", "hidden"), () => docEl.setAttribute("scroll-lock", "true"));
|
|
385
|
-
return pipe(fn, () => docEl.removeAttribute("scroll-lock"));
|
|
386
|
-
}
|
|
387
|
-
function preventScrollMobileSafari() {
|
|
388
|
-
if (docEl.hasAttribute("scroll-lock"))
|
|
389
|
-
return;
|
|
390
|
-
let scrollable;
|
|
391
|
-
let lastY = 0;
|
|
392
|
-
let onTouchStart = (e2) => {
|
|
393
|
-
scrollable = getScrollParent(e2.target);
|
|
394
|
-
if (scrollable === docEl && scrollable === doc.body) {
|
|
395
|
-
return;
|
|
396
|
-
}
|
|
397
|
-
lastY = e2.changedTouches[0].pageY;
|
|
398
|
-
};
|
|
399
|
-
let onTouchMove = (e2) => {
|
|
400
|
-
if (e2.touches.length === 2 && allowPinchZoom)
|
|
401
|
-
return;
|
|
402
|
-
if (!scrollable || scrollable === docEl || scrollable === doc.body) {
|
|
403
|
-
e2.preventDefault();
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
let y = e2.changedTouches[0].pageY;
|
|
407
|
-
let scrollTop = scrollable.scrollTop;
|
|
408
|
-
let bottom = scrollable.scrollHeight - scrollable.clientHeight;
|
|
409
|
-
if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) {
|
|
410
|
-
e2.preventDefault();
|
|
411
|
-
}
|
|
412
|
-
lastY = y;
|
|
413
|
-
};
|
|
414
|
-
let onTouchEnd = (e2) => {
|
|
415
|
-
let target = e2.target;
|
|
416
|
-
if (target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target.type)) {
|
|
417
|
-
e2.preventDefault();
|
|
418
|
-
target.style.transform = "translateY(-2000px)";
|
|
419
|
-
target.focus();
|
|
420
|
-
win.requestAnimationFrame(() => {
|
|
421
|
-
target.style.transform = "";
|
|
422
|
-
});
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
let onFocus = (e2) => {
|
|
426
|
-
let target = e2.target;
|
|
427
|
-
if (target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target.type)) {
|
|
428
|
-
target.style.transform = "translateY(-2000px)";
|
|
429
|
-
win.requestAnimationFrame(() => {
|
|
430
|
-
target.style.transform = "";
|
|
431
|
-
if (!viewport)
|
|
432
|
-
return;
|
|
433
|
-
if (viewport.height < win.innerHeight) {
|
|
434
|
-
win.requestAnimationFrame(function() {
|
|
435
|
-
es_default(target, { scrollMode: "if-needed" });
|
|
436
|
-
});
|
|
437
|
-
} else {
|
|
438
|
-
const onResize = () => {
|
|
439
|
-
es_default(target, { scrollMode: "if-needed" });
|
|
440
|
-
};
|
|
441
|
-
addDomEvent(viewport, "resize", onResize, { once: true });
|
|
442
|
-
}
|
|
443
|
-
});
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
let onWindowScroll = () => {
|
|
447
|
-
win.scrollTo(0, 0);
|
|
448
|
-
};
|
|
449
|
-
let scrollX = win.scrollX;
|
|
450
|
-
let scrollY = win.scrollY;
|
|
451
|
-
let restoreStyles = pipe(setStyle(docEl, "paddingRight", `${win.innerWidth - docEl.clientWidth}px`), setStyle(docEl, "overflow", "hidden"), setStyle(doc.body, "marginTop", `-${scrollY}px`));
|
|
452
|
-
win.scrollTo(0, 0);
|
|
453
|
-
let removeEvents = pipe(addDomEvent(doc, "touchstart", onTouchStart, { passive: false, capture: true }), addDomEvent(doc, "touchmove", onTouchMove, { passive: false, capture: true }), addDomEvent(doc, "touchend", onTouchEnd, { passive: false, capture: true }), addDomEvent(doc, "focus", onFocus, true), addDomEvent(win, "scroll", onWindowScroll), () => docEl.setAttribute("scroll-lock", "true"));
|
|
454
|
-
return () => {
|
|
455
|
-
restoreStyles();
|
|
456
|
-
removeEvents();
|
|
457
|
-
win.scrollTo(scrollX, scrollY);
|
|
458
|
-
docEl.removeAttribute("scroll-lock");
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
if (disabled)
|
|
462
|
-
return noop;
|
|
463
|
-
return isIos() ? preventScrollMobileSafari() : preventScrollStandard();
|
|
464
|
-
}
|
|
465
|
-
function setStyle(el, key, value) {
|
|
466
|
-
let cur = el.style[key];
|
|
467
|
-
el.style[key] = value;
|
|
468
|
-
return () => {
|
|
469
|
-
el.style[key] = cur;
|
|
470
|
-
};
|
|
471
|
-
}
|
|
472
232
|
function validateBlur(event, opts) {
|
|
473
233
|
var _a;
|
|
474
234
|
const exclude = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
@@ -509,7 +269,8 @@ var getFocusables = (el, includeContainer = false) => {
|
|
|
509
269
|
if (!el)
|
|
510
270
|
return [];
|
|
511
271
|
let els = Array.from(el.querySelectorAll(focusableSelector));
|
|
512
|
-
|
|
272
|
+
const shouldAddContainer = includeContainer == true || includeContainer == "if-empty" && els.length === 0;
|
|
273
|
+
if (shouldAddContainer && isHTMLElement(el)) {
|
|
513
274
|
els.unshift(el);
|
|
514
275
|
}
|
|
515
276
|
return els.filter((el2) => isFocusable(el2) && !isHidden(el2));
|
|
@@ -520,6 +281,8 @@ var isFocusable = (el) => {
|
|
|
520
281
|
return el == null ? void 0 : el.matches(focusableSelector);
|
|
521
282
|
};
|
|
522
283
|
var getTabbables = (el, includeContainer = false) => {
|
|
284
|
+
if (!el)
|
|
285
|
+
return [];
|
|
523
286
|
return getFocusables(el, includeContainer).filter(isTabbable);
|
|
524
287
|
};
|
|
525
288
|
var isTabbable = (el) => {
|
|
@@ -593,7 +356,11 @@ var import_popper = require("@zag-js/popper");
|
|
|
593
356
|
|
|
594
357
|
// ../../types/dist/index.mjs
|
|
595
358
|
function createNormalizer(fn) {
|
|
596
|
-
return {
|
|
359
|
+
return new Proxy({}, {
|
|
360
|
+
get() {
|
|
361
|
+
return fn;
|
|
362
|
+
}
|
|
363
|
+
});
|
|
597
364
|
}
|
|
598
365
|
var normalizeProp = createNormalizer((v) => v);
|
|
599
366
|
|
|
@@ -616,6 +383,8 @@ function nextIndex(v, idx, opts = {}) {
|
|
|
616
383
|
function next(v, idx, opts = {}) {
|
|
617
384
|
return v[nextIndex(v, idx, opts)];
|
|
618
385
|
}
|
|
386
|
+
var isDom2 = () => typeof window !== "undefined";
|
|
387
|
+
var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
|
|
619
388
|
var runIfFn2 = (v, ...a) => {
|
|
620
389
|
const res = typeof v === "function" ? v(...a) : v;
|
|
621
390
|
return res != null ? res : void 0;
|
|
@@ -668,15 +437,16 @@ var dom = {
|
|
|
668
437
|
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
669
438
|
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
670
439
|
getDocTabbableEls: (ctx) => getTabbables(cast(dom.getDoc(ctx))),
|
|
671
|
-
getTabbableEls: (ctx) =>
|
|
672
|
-
const el = dom.getContentEl(ctx);
|
|
673
|
-
return el ? getTabbables(el) : [];
|
|
674
|
-
},
|
|
440
|
+
getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
|
|
675
441
|
getFirstTabbableEl: (ctx) => first(dom.getTabbableEls(ctx)),
|
|
676
442
|
getLastTabbableEl: (ctx) => last(dom.getTabbableEls(ctx)),
|
|
677
443
|
getInitialFocusEl: (ctx) => {
|
|
678
|
-
|
|
679
|
-
|
|
444
|
+
let el = runIfFn2(ctx.initialFocusEl);
|
|
445
|
+
if (!el && ctx.autoFocus)
|
|
446
|
+
el = dom.getFirstFocusableEl(ctx);
|
|
447
|
+
if (!el)
|
|
448
|
+
el = dom.getContentEl(ctx);
|
|
449
|
+
return el;
|
|
680
450
|
}
|
|
681
451
|
};
|
|
682
452
|
|
|
@@ -684,9 +454,10 @@ var dom = {
|
|
|
684
454
|
function connect(state, send, normalize = normalizeProp) {
|
|
685
455
|
const isOpen = state.matches("open");
|
|
686
456
|
const pointerdownNode = state.context.pointerdownNode;
|
|
457
|
+
const currentPlacement = state.context.currentPlacement;
|
|
687
458
|
const popperStyles = (0, import_popper.getPlacementStyles)({
|
|
688
459
|
measured: !!state.context.isPlacementComplete,
|
|
689
|
-
placement:
|
|
460
|
+
placement: currentPlacement
|
|
690
461
|
});
|
|
691
462
|
return {
|
|
692
463
|
portalled: state.context.currentPortalled,
|
|
@@ -713,7 +484,7 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
713
484
|
triggerProps: normalize.button({
|
|
714
485
|
"data-part": "trigger",
|
|
715
486
|
type: "button",
|
|
716
|
-
"data-placement":
|
|
487
|
+
"data-placement": currentPlacement,
|
|
717
488
|
id: dom.getTriggerId(state.context),
|
|
718
489
|
"aria-haspopup": "dialog",
|
|
719
490
|
"aria-expanded": isOpen,
|
|
@@ -721,6 +492,11 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
721
492
|
"aria-controls": dom.getContentId(state.context),
|
|
722
493
|
onClick() {
|
|
723
494
|
send("TRIGGER_CLICK");
|
|
495
|
+
},
|
|
496
|
+
onKeyDown(event) {
|
|
497
|
+
if (event.key === "Escape") {
|
|
498
|
+
send("ESCAPE");
|
|
499
|
+
}
|
|
724
500
|
}
|
|
725
501
|
}),
|
|
726
502
|
positionerProps: normalize.element({
|
|
@@ -734,9 +510,10 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
734
510
|
tabIndex: -1,
|
|
735
511
|
role: "dialog",
|
|
736
512
|
hidden: !isOpen,
|
|
737
|
-
"
|
|
738
|
-
"aria-
|
|
739
|
-
"
|
|
513
|
+
"data-expanded": dataAttr(isOpen),
|
|
514
|
+
"aria-labelledby": state.context.renderedElements.title ? dom.getTitleId(state.context) : void 0,
|
|
515
|
+
"aria-describedby": state.context.renderedElements.description ? dom.getDescriptionId(state.context) : void 0,
|
|
516
|
+
"data-placement": currentPlacement,
|
|
740
517
|
onKeyDown(event) {
|
|
741
518
|
const keyMap = {
|
|
742
519
|
Escape(event2) {
|
|
@@ -784,19 +561,17 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
784
561
|
}
|
|
785
562
|
|
|
786
563
|
// src/popover.machine.ts
|
|
564
|
+
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
787
565
|
var import_core = require("@zag-js/core");
|
|
788
566
|
var import_popper2 = require("@zag-js/popper");
|
|
789
|
-
var
|
|
567
|
+
var import_remove_scroll = require("@zag-js/remove-scroll");
|
|
790
568
|
var import_focus_trap = require("focus-trap");
|
|
791
569
|
var { and, or } = import_core.guards;
|
|
792
570
|
function machine(ctx = {}) {
|
|
793
571
|
return (0, import_core.createMachine)({
|
|
794
572
|
id: "popover",
|
|
795
573
|
initial: "unknown",
|
|
796
|
-
context: __spreadValues({
|
|
797
|
-
isTitleRendered: true,
|
|
798
|
-
isDescriptionRendered: true,
|
|
799
|
-
isAnchorRendered: false,
|
|
574
|
+
context: __spreadProps(__spreadValues({
|
|
800
575
|
uid: "",
|
|
801
576
|
closeOnBlur: true,
|
|
802
577
|
closeOnEsc: true,
|
|
@@ -806,7 +581,13 @@ function machine(ctx = {}) {
|
|
|
806
581
|
placement: "bottom"
|
|
807
582
|
}, ctx.positioning),
|
|
808
583
|
currentPlacement: void 0
|
|
809
|
-
}, ctx),
|
|
584
|
+
}, ctx), {
|
|
585
|
+
renderedElements: {
|
|
586
|
+
title: true,
|
|
587
|
+
description: true,
|
|
588
|
+
anchor: false
|
|
589
|
+
}
|
|
590
|
+
}),
|
|
810
591
|
computed: {
|
|
811
592
|
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
812
593
|
},
|
|
@@ -814,7 +595,7 @@ function machine(ctx = {}) {
|
|
|
814
595
|
unknown: {
|
|
815
596
|
on: {
|
|
816
597
|
SETUP: {
|
|
817
|
-
target: "closed",
|
|
598
|
+
target: ctx.open ? "open" : "closed",
|
|
818
599
|
actions: ["setupDocument", "checkRenderedElements"]
|
|
819
600
|
}
|
|
820
601
|
}
|
|
@@ -835,13 +616,7 @@ function machine(ctx = {}) {
|
|
|
835
616
|
"disableOutsidePointerEvents",
|
|
836
617
|
"computePlacement"
|
|
837
618
|
],
|
|
838
|
-
entry:
|
|
839
|
-
{
|
|
840
|
-
guard: "autoFocus",
|
|
841
|
-
actions: ["setInitialFocus", "invokeOnOpen"]
|
|
842
|
-
},
|
|
843
|
-
{ actions: ["focusContent", "invokeOnOpen"] }
|
|
844
|
-
]),
|
|
619
|
+
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
845
620
|
on: {
|
|
846
621
|
CLOSE: {
|
|
847
622
|
target: "closed",
|
|
@@ -884,7 +659,7 @@ function machine(ctx = {}) {
|
|
|
884
659
|
activities: {
|
|
885
660
|
computePlacement(ctx2) {
|
|
886
661
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
887
|
-
const anchorEl = ctx2.
|
|
662
|
+
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
888
663
|
return (0, import_popper2.getPlacement)(anchorEl, dom.getPositionerEl(ctx2), __spreadProps(__spreadValues({}, ctx2.positioning), {
|
|
889
664
|
onComplete(data) {
|
|
890
665
|
ctx2.currentPlacement = data.placement;
|
|
@@ -918,8 +693,7 @@ function machine(ctx = {}) {
|
|
|
918
693
|
return () => unhide == null ? void 0 : unhide();
|
|
919
694
|
},
|
|
920
695
|
preventScroll(ctx2) {
|
|
921
|
-
return preventBodyScroll({
|
|
922
|
-
allowPinchZoom: true,
|
|
696
|
+
return (0, import_remove_scroll.preventBodyScroll)({
|
|
923
697
|
disabled: !ctx2.modal,
|
|
924
698
|
document: dom.getDoc(ctx2)
|
|
925
699
|
});
|
|
@@ -942,7 +716,7 @@ function machine(ctx = {}) {
|
|
|
942
716
|
});
|
|
943
717
|
try {
|
|
944
718
|
trap.activate();
|
|
945
|
-
} catch (
|
|
719
|
+
} catch (e) {
|
|
946
720
|
}
|
|
947
721
|
});
|
|
948
722
|
return () => trap == null ? void 0 : trap.deactivate();
|
|
@@ -962,9 +736,11 @@ function machine(ctx = {}) {
|
|
|
962
736
|
actions: {
|
|
963
737
|
checkRenderedElements(ctx2) {
|
|
964
738
|
raf(() => {
|
|
965
|
-
ctx2.
|
|
966
|
-
|
|
967
|
-
|
|
739
|
+
Object.assign(ctx2.renderedElements, {
|
|
740
|
+
title: !!dom.getTitleEl(ctx2),
|
|
741
|
+
description: !!dom.getDescriptionEl(ctx2),
|
|
742
|
+
anchor: !!dom.getAnchorEl(ctx2)
|
|
743
|
+
});
|
|
968
744
|
});
|
|
969
745
|
},
|
|
970
746
|
setupDocument(ctx2, evt) {
|
|
@@ -977,12 +753,6 @@ function machine(ctx = {}) {
|
|
|
977
753
|
clearPointerDown(ctx2) {
|
|
978
754
|
ctx2.pointerdownNode = null;
|
|
979
755
|
},
|
|
980
|
-
focusContent(ctx2) {
|
|
981
|
-
raf(() => {
|
|
982
|
-
var _a;
|
|
983
|
-
(_a = dom.getContentEl(ctx2)) == null ? void 0 : _a.focus();
|
|
984
|
-
});
|
|
985
|
-
},
|
|
986
756
|
setInitialFocus(ctx2) {
|
|
987
757
|
raf(() => {
|
|
988
758
|
var _a;
|