@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.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) => {
|
|
@@ -620,6 +383,8 @@ function nextIndex(v, idx, opts = {}) {
|
|
|
620
383
|
function next(v, idx, opts = {}) {
|
|
621
384
|
return v[nextIndex(v, idx, opts)];
|
|
622
385
|
}
|
|
386
|
+
var isDom2 = () => typeof window !== "undefined";
|
|
387
|
+
var isTouchDevice2 = isDom2() && !!navigator.maxTouchPoints;
|
|
623
388
|
var runIfFn2 = (v, ...a) => {
|
|
624
389
|
const res = typeof v === "function" ? v(...a) : v;
|
|
625
390
|
return res != null ? res : void 0;
|
|
@@ -672,15 +437,16 @@ var dom = {
|
|
|
672
437
|
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
673
438
|
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
674
439
|
getDocTabbableEls: (ctx) => getTabbables(cast(dom.getDoc(ctx))),
|
|
675
|
-
getTabbableEls: (ctx) =>
|
|
676
|
-
const el = dom.getContentEl(ctx);
|
|
677
|
-
return el ? getTabbables(el) : [];
|
|
678
|
-
},
|
|
440
|
+
getTabbableEls: (ctx) => getTabbables(dom.getContentEl(ctx), "if-empty"),
|
|
679
441
|
getFirstTabbableEl: (ctx) => first(dom.getTabbableEls(ctx)),
|
|
680
442
|
getLastTabbableEl: (ctx) => last(dom.getTabbableEls(ctx)),
|
|
681
443
|
getInitialFocusEl: (ctx) => {
|
|
682
|
-
|
|
683
|
-
|
|
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;
|
|
684
450
|
}
|
|
685
451
|
};
|
|
686
452
|
|
|
@@ -688,9 +454,10 @@ var dom = {
|
|
|
688
454
|
function connect(state, send, normalize = normalizeProp) {
|
|
689
455
|
const isOpen = state.matches("open");
|
|
690
456
|
const pointerdownNode = state.context.pointerdownNode;
|
|
457
|
+
const currentPlacement = state.context.currentPlacement;
|
|
691
458
|
const popperStyles = (0, import_popper.getPlacementStyles)({
|
|
692
459
|
measured: !!state.context.isPlacementComplete,
|
|
693
|
-
placement:
|
|
460
|
+
placement: currentPlacement
|
|
694
461
|
});
|
|
695
462
|
return {
|
|
696
463
|
portalled: state.context.currentPortalled,
|
|
@@ -717,7 +484,7 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
717
484
|
triggerProps: normalize.button({
|
|
718
485
|
"data-part": "trigger",
|
|
719
486
|
type: "button",
|
|
720
|
-
"data-placement":
|
|
487
|
+
"data-placement": currentPlacement,
|
|
721
488
|
id: dom.getTriggerId(state.context),
|
|
722
489
|
"aria-haspopup": "dialog",
|
|
723
490
|
"aria-expanded": isOpen,
|
|
@@ -725,6 +492,11 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
725
492
|
"aria-controls": dom.getContentId(state.context),
|
|
726
493
|
onClick() {
|
|
727
494
|
send("TRIGGER_CLICK");
|
|
495
|
+
},
|
|
496
|
+
onKeyDown(event) {
|
|
497
|
+
if (event.key === "Escape") {
|
|
498
|
+
send("ESCAPE");
|
|
499
|
+
}
|
|
728
500
|
}
|
|
729
501
|
}),
|
|
730
502
|
positionerProps: normalize.element({
|
|
@@ -739,9 +511,9 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
739
511
|
role: "dialog",
|
|
740
512
|
hidden: !isOpen,
|
|
741
513
|
"data-expanded": dataAttr(isOpen),
|
|
742
|
-
"aria-labelledby": state.context.
|
|
743
|
-
"aria-describedby": state.context.
|
|
744
|
-
"data-placement":
|
|
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,
|
|
745
517
|
onKeyDown(event) {
|
|
746
518
|
const keyMap = {
|
|
747
519
|
Escape(event2) {
|
|
@@ -789,19 +561,17 @@ function connect(state, send, normalize = normalizeProp) {
|
|
|
789
561
|
}
|
|
790
562
|
|
|
791
563
|
// src/popover.machine.ts
|
|
564
|
+
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
792
565
|
var import_core = require("@zag-js/core");
|
|
793
566
|
var import_popper2 = require("@zag-js/popper");
|
|
794
|
-
var
|
|
567
|
+
var import_remove_scroll = require("@zag-js/remove-scroll");
|
|
795
568
|
var import_focus_trap = require("focus-trap");
|
|
796
569
|
var { and, or } = import_core.guards;
|
|
797
570
|
function machine(ctx = {}) {
|
|
798
571
|
return (0, import_core.createMachine)({
|
|
799
572
|
id: "popover",
|
|
800
573
|
initial: "unknown",
|
|
801
|
-
context: __spreadValues({
|
|
802
|
-
isTitleRendered: true,
|
|
803
|
-
isDescriptionRendered: true,
|
|
804
|
-
isAnchorRendered: false,
|
|
574
|
+
context: __spreadProps(__spreadValues({
|
|
805
575
|
uid: "",
|
|
806
576
|
closeOnBlur: true,
|
|
807
577
|
closeOnEsc: true,
|
|
@@ -811,7 +581,13 @@ function machine(ctx = {}) {
|
|
|
811
581
|
placement: "bottom"
|
|
812
582
|
}, ctx.positioning),
|
|
813
583
|
currentPlacement: void 0
|
|
814
|
-
}, ctx),
|
|
584
|
+
}, ctx), {
|
|
585
|
+
renderedElements: {
|
|
586
|
+
title: true,
|
|
587
|
+
description: true,
|
|
588
|
+
anchor: false
|
|
589
|
+
}
|
|
590
|
+
}),
|
|
815
591
|
computed: {
|
|
816
592
|
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
817
593
|
},
|
|
@@ -819,7 +595,7 @@ function machine(ctx = {}) {
|
|
|
819
595
|
unknown: {
|
|
820
596
|
on: {
|
|
821
597
|
SETUP: {
|
|
822
|
-
target: "closed",
|
|
598
|
+
target: ctx.open ? "open" : "closed",
|
|
823
599
|
actions: ["setupDocument", "checkRenderedElements"]
|
|
824
600
|
}
|
|
825
601
|
}
|
|
@@ -840,13 +616,7 @@ function machine(ctx = {}) {
|
|
|
840
616
|
"disableOutsidePointerEvents",
|
|
841
617
|
"computePlacement"
|
|
842
618
|
],
|
|
843
|
-
entry:
|
|
844
|
-
{
|
|
845
|
-
guard: "autoFocus",
|
|
846
|
-
actions: ["setInitialFocus", "invokeOnOpen"]
|
|
847
|
-
},
|
|
848
|
-
{ actions: ["focusContent", "invokeOnOpen"] }
|
|
849
|
-
]),
|
|
619
|
+
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
850
620
|
on: {
|
|
851
621
|
CLOSE: {
|
|
852
622
|
target: "closed",
|
|
@@ -889,7 +659,7 @@ function machine(ctx = {}) {
|
|
|
889
659
|
activities: {
|
|
890
660
|
computePlacement(ctx2) {
|
|
891
661
|
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
892
|
-
const anchorEl = ctx2.
|
|
662
|
+
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
893
663
|
return (0, import_popper2.getPlacement)(anchorEl, dom.getPositionerEl(ctx2), __spreadProps(__spreadValues({}, ctx2.positioning), {
|
|
894
664
|
onComplete(data) {
|
|
895
665
|
ctx2.currentPlacement = data.placement;
|
|
@@ -923,8 +693,7 @@ function machine(ctx = {}) {
|
|
|
923
693
|
return () => unhide == null ? void 0 : unhide();
|
|
924
694
|
},
|
|
925
695
|
preventScroll(ctx2) {
|
|
926
|
-
return preventBodyScroll({
|
|
927
|
-
allowPinchZoom: true,
|
|
696
|
+
return (0, import_remove_scroll.preventBodyScroll)({
|
|
928
697
|
disabled: !ctx2.modal,
|
|
929
698
|
document: dom.getDoc(ctx2)
|
|
930
699
|
});
|
|
@@ -947,7 +716,7 @@ function machine(ctx = {}) {
|
|
|
947
716
|
});
|
|
948
717
|
try {
|
|
949
718
|
trap.activate();
|
|
950
|
-
} catch (
|
|
719
|
+
} catch (e) {
|
|
951
720
|
}
|
|
952
721
|
});
|
|
953
722
|
return () => trap == null ? void 0 : trap.deactivate();
|
|
@@ -967,9 +736,11 @@ function machine(ctx = {}) {
|
|
|
967
736
|
actions: {
|
|
968
737
|
checkRenderedElements(ctx2) {
|
|
969
738
|
raf(() => {
|
|
970
|
-
ctx2.
|
|
971
|
-
|
|
972
|
-
|
|
739
|
+
Object.assign(ctx2.renderedElements, {
|
|
740
|
+
title: !!dom.getTitleEl(ctx2),
|
|
741
|
+
description: !!dom.getDescriptionEl(ctx2),
|
|
742
|
+
anchor: !!dom.getAnchorEl(ctx2)
|
|
743
|
+
});
|
|
973
744
|
});
|
|
974
745
|
},
|
|
975
746
|
setupDocument(ctx2, evt) {
|
|
@@ -982,12 +753,6 @@ function machine(ctx = {}) {
|
|
|
982
753
|
clearPointerDown(ctx2) {
|
|
983
754
|
ctx2.pointerdownNode = null;
|
|
984
755
|
},
|
|
985
|
-
focusContent(ctx2) {
|
|
986
|
-
raf(() => {
|
|
987
|
-
var _a;
|
|
988
|
-
(_a = dom.getContentEl(ctx2)) == null ? void 0 : _a.focus();
|
|
989
|
-
});
|
|
990
|
-
},
|
|
991
756
|
setInitialFocus(ctx2) {
|
|
992
757
|
raf(() => {
|
|
993
758
|
var _a;
|