@zag-js/popover 0.1.6 → 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 +55 -290
- package/dist/index.js.map +3 -3
- package/dist/index.mjs +55 -290
- 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.mjs
CHANGED
|
@@ -18,115 +18,6 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
20
|
|
|
21
|
-
// ../../../node_modules/compute-scroll-into-view/dist/index.module.js
|
|
22
|
-
function t(t3) {
|
|
23
|
-
return typeof t3 == "object" && t3 != null && t3.nodeType === 1;
|
|
24
|
-
}
|
|
25
|
-
function e(t3, e2) {
|
|
26
|
-
return (!e2 || t3 !== "hidden") && t3 !== "visible" && t3 !== "clip";
|
|
27
|
-
}
|
|
28
|
-
function n(t3, n2) {
|
|
29
|
-
if (t3.clientHeight < t3.scrollHeight || t3.clientWidth < t3.scrollWidth) {
|
|
30
|
-
var r2 = getComputedStyle(t3, null);
|
|
31
|
-
return e(r2.overflowY, n2) || e(r2.overflowX, n2) || function(t4) {
|
|
32
|
-
var e2 = function(t5) {
|
|
33
|
-
if (!t5.ownerDocument || !t5.ownerDocument.defaultView)
|
|
34
|
-
return null;
|
|
35
|
-
try {
|
|
36
|
-
return t5.ownerDocument.defaultView.frameElement;
|
|
37
|
-
} catch (t6) {
|
|
38
|
-
return null;
|
|
39
|
-
}
|
|
40
|
-
}(t4);
|
|
41
|
-
return !!e2 && (e2.clientHeight < t4.scrollHeight || e2.clientWidth < t4.scrollWidth);
|
|
42
|
-
}(t3);
|
|
43
|
-
}
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
function r(t3, e2, n2, r2, i, o, l, d) {
|
|
47
|
-
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;
|
|
48
|
-
}
|
|
49
|
-
function index_module_default(e2, i) {
|
|
50
|
-
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) {
|
|
51
|
-
return t3 !== h;
|
|
52
|
-
};
|
|
53
|
-
if (!t(e2))
|
|
54
|
-
throw new TypeError("Invalid target");
|
|
55
|
-
for (var f = document.scrollingElement || document.documentElement, s = [], p = e2; t(p) && c(p); ) {
|
|
56
|
-
if ((p = p.parentElement) === f) {
|
|
57
|
-
s.push(p);
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
p != null && p === document.body && n(p) && !n(document.documentElement) || p != null && n(p, a) && s.push(p);
|
|
61
|
-
}
|
|
62
|
-
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++) {
|
|
63
|
-
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;
|
|
64
|
-
if (l === "if-needed" && y >= 0 && V >= 0 && M <= g && E <= m && y >= R && M <= Y && V >= L && E <= X)
|
|
65
|
-
return C;
|
|
66
|
-
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;
|
|
67
|
-
if (f === k)
|
|
68
|
-
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);
|
|
69
|
-
else {
|
|
70
|
-
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);
|
|
71
|
-
var N = k.scrollLeft, P = k.scrollTop;
|
|
72
|
-
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)));
|
|
73
|
-
}
|
|
74
|
-
C.push({ el: k, top: F, left: G });
|
|
75
|
-
}
|
|
76
|
-
return C;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ../../utilities/dom/node_modules/scroll-into-view-if-needed/es/index.js
|
|
80
|
-
function isOptionsObject(options) {
|
|
81
|
-
return options === Object(options) && Object.keys(options).length !== 0;
|
|
82
|
-
}
|
|
83
|
-
function defaultBehavior(actions, behavior) {
|
|
84
|
-
if (behavior === void 0) {
|
|
85
|
-
behavior = "auto";
|
|
86
|
-
}
|
|
87
|
-
var canSmoothScroll = "scrollBehavior" in document.body.style;
|
|
88
|
-
actions.forEach(function(_ref) {
|
|
89
|
-
var el = _ref.el, top = _ref.top, left = _ref.left;
|
|
90
|
-
if (el.scroll && canSmoothScroll) {
|
|
91
|
-
el.scroll({
|
|
92
|
-
top,
|
|
93
|
-
left,
|
|
94
|
-
behavior
|
|
95
|
-
});
|
|
96
|
-
} else {
|
|
97
|
-
el.scrollTop = top;
|
|
98
|
-
el.scrollLeft = left;
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
function getOptions(options) {
|
|
103
|
-
if (options === false) {
|
|
104
|
-
return {
|
|
105
|
-
block: "end",
|
|
106
|
-
inline: "nearest"
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
if (isOptionsObject(options)) {
|
|
110
|
-
return options;
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
block: "start",
|
|
114
|
-
inline: "nearest"
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
function scrollIntoView(target, options) {
|
|
118
|
-
var isTargetAttached = target.isConnected || target.ownerDocument.documentElement.contains(target);
|
|
119
|
-
if (isOptionsObject(options) && typeof options.behavior === "function") {
|
|
120
|
-
return options.behavior(isTargetAttached ? index_module_default(target, options) : []);
|
|
121
|
-
}
|
|
122
|
-
if (!isTargetAttached) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
125
|
-
var computeOptions = getOptions(options);
|
|
126
|
-
return defaultBehavior(index_module_default(target, computeOptions), computeOptions.behavior);
|
|
127
|
-
}
|
|
128
|
-
var es_default = scrollIntoView;
|
|
129
|
-
|
|
130
21
|
// ../../utilities/dom/dist/index.mjs
|
|
131
22
|
var dataAttr = (guard) => {
|
|
132
23
|
return guard ? "" : void 0;
|
|
@@ -168,16 +59,17 @@ function raf(fn) {
|
|
|
168
59
|
globalThis.cancelAnimationFrame(id);
|
|
169
60
|
};
|
|
170
61
|
}
|
|
62
|
+
var isDom = () => typeof window !== "undefined";
|
|
63
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
64
|
+
var isTouchDevice = isDom() && !!navigator.maxTouchPoints;
|
|
65
|
+
var isLeftClick = (v) => v.button === 0;
|
|
66
|
+
var runIfFn = (v, ...a) => {
|
|
67
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
68
|
+
return res != null ? res : void 0;
|
|
69
|
+
};
|
|
171
70
|
var noop = () => {
|
|
172
71
|
};
|
|
173
72
|
var pipe = (...fns) => (v) => fns.reduce((a, b) => b(a), v);
|
|
174
|
-
var platform = (v) => isDom() && v.test(navigator.platform);
|
|
175
|
-
var isDom = () => !!(typeof window !== "undefined");
|
|
176
|
-
var isMac = () => platform(/^Mac/);
|
|
177
|
-
var isIPhone = () => platform(/^iPhone/);
|
|
178
|
-
var isIPad = () => platform(/^iPad/) || isMac() && navigator.maxTouchPoints > 1;
|
|
179
|
-
var isIos = () => isIPhone() || isIPad();
|
|
180
|
-
var isLeftClick = (v) => v.button === 0;
|
|
181
73
|
function getListenerElements() {
|
|
182
74
|
;
|
|
183
75
|
globalThis.__listenerElements__ = globalThis.__listenerElements__ || /* @__PURE__ */ new Map();
|
|
@@ -188,7 +80,7 @@ function getListenerCache() {
|
|
|
188
80
|
globalThis.__listenerCache__ = globalThis.__listenerCache__ || /* @__PURE__ */ new Map();
|
|
189
81
|
return globalThis.__listenerCache__;
|
|
190
82
|
}
|
|
191
|
-
function
|
|
83
|
+
function addGlobalEventListener(node, type, handler, options) {
|
|
192
84
|
var _a;
|
|
193
85
|
if (!node)
|
|
194
86
|
return noop;
|
|
@@ -240,12 +132,10 @@ function globalEventBus(node, type, handler, options) {
|
|
|
240
132
|
}
|
|
241
133
|
};
|
|
242
134
|
}
|
|
243
|
-
var
|
|
244
|
-
var isRef = (v) => t2(v) === "Object" && "current" in v;
|
|
245
|
-
var runIfFn = (fn) => t2(fn) === "Function" ? fn() : fn;
|
|
135
|
+
var isRef = (v) => hasProp(v, "current");
|
|
246
136
|
function addDomEvent(target, event, listener, options) {
|
|
247
137
|
const node = isRef(target) ? target.current : runIfFn(target);
|
|
248
|
-
return
|
|
138
|
+
return addGlobalEventListener(node, event, listener, options);
|
|
249
139
|
}
|
|
250
140
|
var changeCount = 0;
|
|
251
141
|
var originalBodyPointerEvents;
|
|
@@ -305,21 +195,6 @@ function preventBodyPointerEvents(el, opts = {}) {
|
|
|
305
195
|
cleanups.forEach((cleanup) => cleanup == null ? void 0 : cleanup());
|
|
306
196
|
};
|
|
307
197
|
}
|
|
308
|
-
function getOwnerDocument(el) {
|
|
309
|
-
var _a;
|
|
310
|
-
if (isWindow(el))
|
|
311
|
-
return el.document;
|
|
312
|
-
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
313
|
-
}
|
|
314
|
-
function getNodeName(node) {
|
|
315
|
-
return isWindow(node) ? "" : node ? node.localName || "" : "";
|
|
316
|
-
}
|
|
317
|
-
function getParent(el) {
|
|
318
|
-
const doc = getOwnerDocument(el);
|
|
319
|
-
if (getNodeName(el) === "html")
|
|
320
|
-
return el;
|
|
321
|
-
return el.assignedSlot || el.parentElement || doc.documentElement;
|
|
322
|
-
}
|
|
323
198
|
function contains(parent, child) {
|
|
324
199
|
if (!parent)
|
|
325
200
|
return false;
|
|
@@ -328,124 +203,9 @@ function contains(parent, child) {
|
|
|
328
203
|
function isHTMLElement(v) {
|
|
329
204
|
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
330
205
|
}
|
|
331
|
-
function isWindow(value) {
|
|
332
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
333
|
-
}
|
|
334
206
|
var isDisabled = (el) => {
|
|
335
207
|
return (el == null ? void 0 : el.getAttribute("disabled")) != null || !!(el == null ? void 0 : el.getAttribute("aria-disabled")) === true;
|
|
336
208
|
};
|
|
337
|
-
function isScrollParent(el) {
|
|
338
|
-
const { overflow, overflowX, overflowY } = getComputedStyle2(el);
|
|
339
|
-
return /auto|scroll|overlay|hidden/.test(overflow + overflowY + overflowX);
|
|
340
|
-
}
|
|
341
|
-
function getScrollParent(el) {
|
|
342
|
-
if (["html", "body", "#document"].includes(getNodeName(el))) {
|
|
343
|
-
return getOwnerDocument(el).body;
|
|
344
|
-
}
|
|
345
|
-
if (isHTMLElement(el) && isScrollParent(el)) {
|
|
346
|
-
return el;
|
|
347
|
-
}
|
|
348
|
-
return getScrollParent(getParent(el));
|
|
349
|
-
}
|
|
350
|
-
var nonTextInputTypes = /* @__PURE__ */ new Set(["checkbox", "radio", "range", "color", "file", "image", "button", "submit", "reset"]);
|
|
351
|
-
function preventBodyScroll(opts) {
|
|
352
|
-
var _a;
|
|
353
|
-
const { document: docProp, disabled = false, allowPinchZoom } = opts != null ? opts : {};
|
|
354
|
-
const doc = docProp != null ? docProp : document;
|
|
355
|
-
const win = (_a = doc == null ? void 0 : doc.defaultView) != null ? _a : window;
|
|
356
|
-
const viewport = isDom() ? win.visualViewport : null;
|
|
357
|
-
const docEl = doc.documentElement;
|
|
358
|
-
function preventScrollStandard() {
|
|
359
|
-
if (docEl.hasAttribute("scroll-lock"))
|
|
360
|
-
return;
|
|
361
|
-
const fn = pipe(setStyle(docEl, "paddingRight", `${win.innerWidth - docEl.clientWidth}px`), setStyle(docEl, "overflow", "hidden"), () => docEl.setAttribute("scroll-lock", "true"));
|
|
362
|
-
return pipe(fn, () => docEl.removeAttribute("scroll-lock"));
|
|
363
|
-
}
|
|
364
|
-
function preventScrollMobileSafari() {
|
|
365
|
-
if (docEl.hasAttribute("scroll-lock"))
|
|
366
|
-
return;
|
|
367
|
-
let scrollable;
|
|
368
|
-
let lastY = 0;
|
|
369
|
-
let onTouchStart = (e2) => {
|
|
370
|
-
scrollable = getScrollParent(e2.target);
|
|
371
|
-
if (scrollable === docEl && scrollable === doc.body) {
|
|
372
|
-
return;
|
|
373
|
-
}
|
|
374
|
-
lastY = e2.changedTouches[0].pageY;
|
|
375
|
-
};
|
|
376
|
-
let onTouchMove = (e2) => {
|
|
377
|
-
if (e2.touches.length === 2 && allowPinchZoom)
|
|
378
|
-
return;
|
|
379
|
-
if (!scrollable || scrollable === docEl || scrollable === doc.body) {
|
|
380
|
-
e2.preventDefault();
|
|
381
|
-
return;
|
|
382
|
-
}
|
|
383
|
-
let y = e2.changedTouches[0].pageY;
|
|
384
|
-
let scrollTop = scrollable.scrollTop;
|
|
385
|
-
let bottom = scrollable.scrollHeight - scrollable.clientHeight;
|
|
386
|
-
if (scrollTop <= 0 && y > lastY || scrollTop >= bottom && y < lastY) {
|
|
387
|
-
e2.preventDefault();
|
|
388
|
-
}
|
|
389
|
-
lastY = y;
|
|
390
|
-
};
|
|
391
|
-
let onTouchEnd = (e2) => {
|
|
392
|
-
let target = e2.target;
|
|
393
|
-
if (target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target.type)) {
|
|
394
|
-
e2.preventDefault();
|
|
395
|
-
target.style.transform = "translateY(-2000px)";
|
|
396
|
-
target.focus();
|
|
397
|
-
win.requestAnimationFrame(() => {
|
|
398
|
-
target.style.transform = "";
|
|
399
|
-
});
|
|
400
|
-
}
|
|
401
|
-
};
|
|
402
|
-
let onFocus = (e2) => {
|
|
403
|
-
let target = e2.target;
|
|
404
|
-
if (target instanceof win.HTMLInputElement && !nonTextInputTypes.has(target.type)) {
|
|
405
|
-
target.style.transform = "translateY(-2000px)";
|
|
406
|
-
win.requestAnimationFrame(() => {
|
|
407
|
-
target.style.transform = "";
|
|
408
|
-
if (!viewport)
|
|
409
|
-
return;
|
|
410
|
-
if (viewport.height < win.innerHeight) {
|
|
411
|
-
win.requestAnimationFrame(function() {
|
|
412
|
-
es_default(target, { scrollMode: "if-needed" });
|
|
413
|
-
});
|
|
414
|
-
} else {
|
|
415
|
-
const onResize = () => {
|
|
416
|
-
es_default(target, { scrollMode: "if-needed" });
|
|
417
|
-
};
|
|
418
|
-
addDomEvent(viewport, "resize", onResize, { once: true });
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
let onWindowScroll = () => {
|
|
424
|
-
win.scrollTo(0, 0);
|
|
425
|
-
};
|
|
426
|
-
let scrollX = win.scrollX;
|
|
427
|
-
let scrollY = win.scrollY;
|
|
428
|
-
let restoreStyles = pipe(setStyle(docEl, "paddingRight", `${win.innerWidth - docEl.clientWidth}px`), setStyle(docEl, "overflow", "hidden"), setStyle(doc.body, "marginTop", `-${scrollY}px`));
|
|
429
|
-
win.scrollTo(0, 0);
|
|
430
|
-
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"));
|
|
431
|
-
return () => {
|
|
432
|
-
restoreStyles();
|
|
433
|
-
removeEvents();
|
|
434
|
-
win.scrollTo(scrollX, scrollY);
|
|
435
|
-
docEl.removeAttribute("scroll-lock");
|
|
436
|
-
};
|
|
437
|
-
}
|
|
438
|
-
if (disabled)
|
|
439
|
-
return noop;
|
|
440
|
-
return isIos() ? preventScrollMobileSafari() : preventScrollStandard();
|
|
441
|
-
}
|
|
442
|
-
function setStyle(el, key, value) {
|
|
443
|
-
let cur = el.style[key];
|
|
444
|
-
el.style[key] = value;
|
|
445
|
-
return () => {
|
|
446
|
-
el.style[key] = cur;
|
|
447
|
-
};
|
|
448
|
-
}
|
|
449
209
|
function validateBlur(event, opts) {
|
|
450
210
|
var _a;
|
|
451
211
|
const exclude = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
@@ -486,7 +246,8 @@ var getFocusables = (el, includeContainer = false) => {
|
|
|
486
246
|
if (!el)
|
|
487
247
|
return [];
|
|
488
248
|
let els = Array.from(el.querySelectorAll(focusableSelector));
|
|
489
|
-
|
|
249
|
+
const shouldAddContainer = includeContainer == true || includeContainer == "if-empty" && els.length === 0;
|
|
250
|
+
if (shouldAddContainer && isHTMLElement(el)) {
|
|
490
251
|
els.unshift(el);
|
|
491
252
|
}
|
|
492
253
|
return els.filter((el2) => isFocusable(el2) && !isHidden(el2));
|
|
@@ -497,6 +258,8 @@ var isFocusable = (el) => {
|
|
|
497
258
|
return el == null ? void 0 : el.matches(focusableSelector);
|
|
498
259
|
};
|
|
499
260
|
var getTabbables = (el, includeContainer = false) => {
|
|
261
|
+
if (!el)
|
|
262
|
+
return [];
|
|
500
263
|
return getFocusables(el, includeContainer).filter(isTabbable);
|
|
501
264
|
};
|
|
502
265
|
var isTabbable = (el) => {
|
|
@@ -597,6 +360,8 @@ function nextIndex(v, idx, opts = {}) {
|
|
|
597
360
|
function next(v, idx, opts = {}) {
|
|
598
361
|
return v[nextIndex(v, idx, opts)];
|
|
599
362
|
}
|
|
363
|
+
var isDom2 = () => typeof window !== "undefined";
|
|
364
|
+
var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
|
|
600
365
|
var runIfFn2 = (v, ...a) => {
|
|
601
366
|
const res = typeof v === "function" ? v(...a) : v;
|
|
602
367
|
return res != null ? res : void 0;
|
|
@@ -649,15 +414,16 @@ var dom = {
|
|
|
649
414
|
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
650
415
|
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
651
416
|
getDocTabbableEls: (ctx) => getTabbables(cast(dom.getDoc(ctx))),
|
|
652
|
-
getTabbableEls: (ctx) =>
|
|
653
|
-
const el = dom.getContentEl(ctx);
|
|
654
|
-
return el ? getTabbables(el) : [];
|
|
655
|
-
},
|
|
417
|
+
getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
|
|
656
418
|
getFirstTabbableEl: (ctx) => first(dom.getTabbableEls(ctx)),
|
|
657
419
|
getLastTabbableEl: (ctx) => last(dom.getTabbableEls(ctx)),
|
|
658
420
|
getInitialFocusEl: (ctx) => {
|
|
659
|
-
|
|
660
|
-
|
|
421
|
+
let el = runIfFn2(ctx.initialFocusEl);
|
|
422
|
+
if (!el && ctx.autoFocus)
|
|
423
|
+
el = dom.getFirstFocusableEl(ctx);
|
|
424
|
+
if (!el)
|
|
425
|
+
el = dom.getContentEl(ctx);
|
|
426
|
+
return el;
|
|
661
427
|
}
|
|
662
428
|
};
|
|
663
429
|
|
|
@@ -665,9 +431,10 @@ var dom = {
|
|
|
665
431
|
function connect(state, send, normalize = normalizeProp) {
|
|
666
432
|
const isOpen = state.matches("open");
|
|
667
433
|
const pointerdownNode = state.context.pointerdownNode;
|
|
434
|
+
const currentPlacement = state.context.currentPlacement;
|
|
668
435
|
const popperStyles = getPlacementStyles({
|
|
669
436
|
measured: !!state.context.isPlacementComplete,
|
|
670
|
-
placement:
|
|
437
|
+
placement: currentPlacement
|
|
671
438
|
});
|
|
672
439
|
return {
|
|
673
440
|
portalled: state.context.currentPortalled,
|
|
@@ -694,7 +461,7 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
694
461
|
triggerProps: normalize.button({
|
|
695
462
|
"data-part": "trigger",
|
|
696
463
|
type: "button",
|
|
697
|
-
"data-placement":
|
|
464
|
+
"data-placement": currentPlacement,
|
|
698
465
|
id: dom.getTriggerId(state.context),
|
|
699
466
|
"aria-haspopup": "dialog",
|
|
700
467
|
"aria-expanded": isOpen,
|
|
@@ -702,6 +469,11 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
702
469
|
"aria-controls": dom.getContentId(state.context),
|
|
703
470
|
onClick() {
|
|
704
471
|
send("TRIGGER_CLICK");
|
|
472
|
+
},
|
|
473
|
+
onKeyDown(event) {
|
|
474
|
+
if (event.key === "Escape") {
|
|
475
|
+
send("ESCAPE");
|
|
476
|
+
}
|
|
705
477
|
}
|
|
706
478
|
}),
|
|
707
479
|
positionerProps: normalize.element({
|
|
@@ -716,9 +488,9 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
716
488
|
role: "dialog",
|
|
717
489
|
hidden: !isOpen,
|
|
718
490
|
"data-expanded": dataAttr(isOpen),
|
|
719
|
-
"aria-labelledby": state.context.
|
|
720
|
-
"aria-describedby": state.context.
|
|
721
|
-
"data-placement":
|
|
491
|
+
"aria-labelledby": state.context.renderedElements.title ? dom.getTitleId(state.context) : void 0,
|
|
492
|
+
"aria-describedby": state.context.renderedElements.description ? dom.getDescriptionId(state.context) : void 0,
|
|
493
|
+
"data-placement": currentPlacement,
|
|
722
494
|
onKeyDown(event) {
|
|
723
495
|
const keyMap = {
|
|
724
496
|
Escape(event2) {
|
|
@@ -766,19 +538,17 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
766
538
|
}
|
|
767
539
|
|
|
768
540
|
// src/popover.machine.ts
|
|
769
|
-
import { choose, createMachine, guards, ref } from "@zag-js/core";
|
|
770
|
-
import { getPlacement } from "@zag-js/popper";
|
|
771
541
|
import { ariaHidden } from "@zag-js/aria-hidden";
|
|
542
|
+
import { createMachine, guards, ref } from "@zag-js/core";
|
|
543
|
+
import { getPlacement } from "@zag-js/popper";
|
|
544
|
+
import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
772
545
|
import { createFocusTrap } from "focus-trap";
|
|
773
546
|
var { and, or } = guards;
|
|
774
547
|
function machine(ctx = {}) {
|
|
775
548
|
return createMachine({
|
|
776
549
|
id: "popover",
|
|
777
550
|
initial: "unknown",
|
|
778
|
-
context: __spreadValues({
|
|
779
|
-
isTitleRendered: true,
|
|
780
|
-
isDescriptionRendered: true,
|
|
781
|
-
isAnchorRendered: false,
|
|
551
|
+
context: __spreadProps(__spreadValues({
|
|
782
552
|
uid: "",
|
|
783
553
|
closeOnBlur: true,
|
|
784
554
|
closeOnEsc: true,
|
|
@@ -788,7 +558,13 @@ function machine(ctx = {}) {
|
|
|
788
558
|
placement: "bottom"
|
|
789
559
|
}, ctx.positioning),
|
|
790
560
|
currentPlacement: void 0
|
|
791
|
-
}, ctx),
|
|
561
|
+
}, ctx), {
|
|
562
|
+
renderedElements: {
|
|
563
|
+
title: true,
|
|
564
|
+
description: true,
|
|
565
|
+
anchor: false
|
|
566
|
+
}
|
|
567
|
+
}),
|
|
792
568
|
computed: {
|
|
793
569
|
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
794
570
|
},
|
|
@@ -796,7 +572,7 @@ function machine(ctx = {}) {
|
|
|
796
572
|
unknown: {
|
|
797
573
|
on: {
|
|
798
574
|
SETUP: {
|
|
799
|
-
target: "closed",
|
|
575
|
+
target: ctx.open ? "open" : "closed",
|
|
800
576
|
actions: ["setupDocument", "checkRenderedElements"]
|
|
801
577
|
}
|
|
802
578
|
}
|
|
@@ -817,13 +593,7 @@ function machine(ctx = {}) {
|
|
|
817
593
|
"disableOutsidePointerEvents",
|
|
818
594
|
"computePlacement"
|
|
819
595
|
],
|
|
820
|
-
entry:
|
|
821
|
-
{
|
|
822
|
-
guard: "autoFocus",
|
|
823
|
-
actions: ["setInitialFocus", "invokeOnOpen"]
|
|
824
|
-
},
|
|
825
|
-
{ actions: ["focusContent", "invokeOnOpen"] }
|
|
826
|
-
]),
|
|
596
|
+
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
827
597
|
on: {
|
|
828
598
|
CLOSE: {
|
|
829
599
|
target: "closed",
|
|
@@ -866,7 +636,7 @@ function machine(ctx = {}) {
|
|
|
866
636
|
activities: {
|
|
867
637
|
computePlacement(ctx2) {
|
|
868
638
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
869
|
-
const anchorEl = ctx2.
|
|
639
|
+
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
870
640
|
return getPlacement(anchorEl, dom.getPositionerEl(ctx2), __spreadProps(__spreadValues({}, ctx2.positioning), {
|
|
871
641
|
onComplete(data) {
|
|
872
642
|
ctx2.currentPlacement = data.placement;
|
|
@@ -901,7 +671,6 @@ function machine(ctx = {}) {
|
|
|
901
671
|
},
|
|
902
672
|
preventScroll(ctx2) {
|
|
903
673
|
return preventBodyScroll({
|
|
904
|
-
allowPinchZoom: true,
|
|
905
674
|
disabled: !ctx2.modal,
|
|
906
675
|
document: dom.getDoc(ctx2)
|
|
907
676
|
});
|
|
@@ -924,7 +693,7 @@ function machine(ctx = {}) {
|
|
|
924
693
|
});
|
|
925
694
|
try {
|
|
926
695
|
trap.activate();
|
|
927
|
-
} catch (
|
|
696
|
+
} catch (e) {
|
|
928
697
|
}
|
|
929
698
|
});
|
|
930
699
|
return () => trap == null ? void 0 : trap.deactivate();
|
|
@@ -944,9 +713,11 @@ function machine(ctx = {}) {
|
|
|
944
713
|
actions: {
|
|
945
714
|
checkRenderedElements(ctx2) {
|
|
946
715
|
raf(() => {
|
|
947
|
-
ctx2.
|
|
948
|
-
|
|
949
|
-
|
|
716
|
+
Object.assign(ctx2.renderedElements, {
|
|
717
|
+
title: !!dom.getTitleEl(ctx2),
|
|
718
|
+
description: !!dom.getDescriptionEl(ctx2),
|
|
719
|
+
anchor: !!dom.getAnchorEl(ctx2)
|
|
720
|
+
});
|
|
950
721
|
});
|
|
951
722
|
},
|
|
952
723
|
setupDocument(ctx2, evt) {
|
|
@@ -959,12 +730,6 @@ function machine(ctx = {}) {
|
|
|
959
730
|
clearPointerDown(ctx2) {
|
|
960
731
|
ctx2.pointerdownNode = null;
|
|
961
732
|
},
|
|
962
|
-
focusContent(ctx2) {
|
|
963
|
-
raf(() => {
|
|
964
|
-
var _a;
|
|
965
|
-
(_a = dom.getContentEl(ctx2)) == null ? void 0 : _a.focus();
|
|
966
|
-
});
|
|
967
|
-
},
|
|
968
733
|
setInitialFocus(ctx2) {
|
|
969
734
|
raf(() => {
|
|
970
735
|
var _a;
|