@zag-js/popover 0.1.9 → 0.1.12
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/LICENSE +21 -0
- package/dist/index.d.ts +103 -3
- package/dist/index.js +294 -621
- package/dist/index.mjs +290 -625
- package/package.json +18 -14
- package/dist/popover.connect.d.ts +0 -17
- package/dist/popover.dom.d.ts +0 -28
- package/dist/popover.machine.d.ts +0 -2
- package/dist/popover.types.d.ts +0 -101
package/dist/index.js
CHANGED
|
@@ -1,25 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
-
var __spreadValues = (a, b) => {
|
|
12
|
-
for (var prop in b || (b = {}))
|
|
13
|
-
if (__hasOwnProp.call(b, prop))
|
|
14
|
-
__defNormalProp(a, prop, b[prop]);
|
|
15
|
-
if (__getOwnPropSymbols)
|
|
16
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
-
if (__propIsEnum.call(b, prop))
|
|
18
|
-
__defNormalProp(a, prop, b[prop]);
|
|
19
|
-
}
|
|
20
|
-
return a;
|
|
21
|
-
};
|
|
22
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
6
|
var __export = (target, all) => {
|
|
24
7
|
for (var name in all)
|
|
25
8
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -48,9 +31,12 @@ var dataAttr = (guard) => {
|
|
|
48
31
|
};
|
|
49
32
|
var runIfFn = (v, ...a) => {
|
|
50
33
|
const res = typeof v === "function" ? v(...a) : v;
|
|
51
|
-
return res
|
|
34
|
+
return res ?? void 0;
|
|
52
35
|
};
|
|
53
36
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
37
|
+
function isDocument(el) {
|
|
38
|
+
return el.nodeType === Node.DOCUMENT_NODE;
|
|
39
|
+
}
|
|
54
40
|
function isWindow(value) {
|
|
55
41
|
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
56
42
|
}
|
|
@@ -58,14 +44,27 @@ function isFrame(element) {
|
|
|
58
44
|
return element.localName === "iframe";
|
|
59
45
|
}
|
|
60
46
|
function getDocument(el) {
|
|
61
|
-
var _a;
|
|
62
47
|
if (isWindow(el))
|
|
63
48
|
return el.document;
|
|
64
|
-
|
|
49
|
+
if (isDocument(el))
|
|
50
|
+
return el;
|
|
51
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
65
52
|
}
|
|
66
|
-
function
|
|
67
|
-
|
|
68
|
-
|
|
53
|
+
function defineDomHelpers(helpers) {
|
|
54
|
+
const dom2 = {
|
|
55
|
+
getRootNode: (ctx) => {
|
|
56
|
+
var _a;
|
|
57
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
58
|
+
},
|
|
59
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
60
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
61
|
+
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
62
|
+
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
63
|
+
};
|
|
64
|
+
return {
|
|
65
|
+
...dom2,
|
|
66
|
+
...helpers
|
|
67
|
+
};
|
|
69
68
|
}
|
|
70
69
|
function contains(parent, child) {
|
|
71
70
|
if (!parent)
|
|
@@ -189,56 +188,44 @@ function next(v, idx, opts = {}) {
|
|
|
189
188
|
}
|
|
190
189
|
var runIfFn2 = (v, ...a) => {
|
|
191
190
|
const res = typeof v === "function" ? v(...a) : v;
|
|
192
|
-
return res
|
|
191
|
+
return res ?? void 0;
|
|
193
192
|
};
|
|
194
193
|
|
|
195
194
|
// src/popover.dom.ts
|
|
196
|
-
var dom = {
|
|
197
|
-
getDoc: (ctx) => {
|
|
198
|
-
var _a;
|
|
199
|
-
return (_a = ctx.doc) != null ? _a : document;
|
|
200
|
-
},
|
|
201
|
-
getWin: (ctx) => {
|
|
202
|
-
var _a;
|
|
203
|
-
return (_a = dom.getDoc(ctx).defaultView) != null ? _a : window;
|
|
204
|
-
},
|
|
195
|
+
var dom = defineDomHelpers({
|
|
205
196
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
206
|
-
getRootNode: (ctx) => {
|
|
207
|
-
var _a;
|
|
208
|
-
return (_a = ctx.rootNode) != null ? _a : dom.getDoc(ctx);
|
|
209
|
-
},
|
|
210
197
|
getAnchorId: (ctx) => {
|
|
211
|
-
var _a
|
|
212
|
-
return (
|
|
198
|
+
var _a;
|
|
199
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.anchor) ?? `popover:${ctx.id}:anchor`;
|
|
213
200
|
},
|
|
214
201
|
getTriggerId: (ctx) => {
|
|
215
|
-
var _a
|
|
216
|
-
return (
|
|
202
|
+
var _a;
|
|
203
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.trigger) ?? `popover:${ctx.id}:trigger`;
|
|
217
204
|
},
|
|
218
205
|
getContentId: (ctx) => {
|
|
219
|
-
var _a
|
|
220
|
-
return (
|
|
206
|
+
var _a;
|
|
207
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.content) ?? `popover:${ctx.id}:content`;
|
|
221
208
|
},
|
|
222
|
-
getPositionerId: (ctx) => `popover:${ctx.
|
|
223
|
-
getArrowId: (ctx) => `popover:${ctx.
|
|
209
|
+
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
210
|
+
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
224
211
|
getTitleId: (ctx) => {
|
|
225
|
-
var _a
|
|
226
|
-
return (
|
|
212
|
+
var _a;
|
|
213
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.title) ?? `popover:${ctx.id}:title`;
|
|
227
214
|
},
|
|
228
215
|
getDescriptionId: (ctx) => {
|
|
229
|
-
var _a
|
|
230
|
-
return (
|
|
216
|
+
var _a;
|
|
217
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.description) ?? `popover:${ctx.id}:desc`;
|
|
231
218
|
},
|
|
232
219
|
getCloseButtonId: (ctx) => {
|
|
233
|
-
var _a
|
|
234
|
-
return (
|
|
220
|
+
var _a;
|
|
221
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.closeBtn) ?? `popover:${ctx.id}:close-button`;
|
|
235
222
|
},
|
|
236
|
-
getAnchorEl: (ctx) => dom.
|
|
237
|
-
getTriggerEl: (ctx) => dom.
|
|
238
|
-
getContentEl: (ctx) => dom.
|
|
239
|
-
getPositionerEl: (ctx) => dom.
|
|
240
|
-
getTitleEl: (ctx) => dom.
|
|
241
|
-
getDescriptionEl: (ctx) => dom.
|
|
223
|
+
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
224
|
+
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
225
|
+
getContentEl: (ctx) => dom.getById(ctx, dom.getContentId(ctx)),
|
|
226
|
+
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
227
|
+
getTitleEl: (ctx) => dom.getById(ctx, dom.getTitleId(ctx)),
|
|
228
|
+
getDescriptionEl: (ctx) => dom.getById(ctx, dom.getDescriptionId(ctx)),
|
|
242
229
|
getFocusableEls: (ctx) => getFocusables(dom.getContentEl(ctx)),
|
|
243
230
|
getFirstFocusableEl: (ctx) => dom.getFocusableEls(ctx)[0],
|
|
244
231
|
getDocTabbableEls: (ctx) => getTabbables(dom.getDoc(ctx).body),
|
|
@@ -253,7 +240,7 @@ var dom = {
|
|
|
253
240
|
el = dom.getContentEl(ctx);
|
|
254
241
|
return el;
|
|
255
242
|
}
|
|
256
|
-
};
|
|
243
|
+
});
|
|
257
244
|
|
|
258
245
|
// src/popover.connect.ts
|
|
259
246
|
function connect(state, send, normalize) {
|
|
@@ -342,593 +329,279 @@ function connect(state, send, normalize) {
|
|
|
342
329
|
// src/popover.machine.ts
|
|
343
330
|
var import_aria_hidden = require("@zag-js/aria-hidden");
|
|
344
331
|
var import_core = require("@zag-js/core");
|
|
345
|
-
|
|
346
|
-
// ../../utilities/interact-outside/dist/index.mjs
|
|
347
|
-
var runIfFn3 = (v, ...a) => {
|
|
348
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
349
|
-
return res != null ? res : void 0;
|
|
350
|
-
};
|
|
351
|
-
var hasProp2 = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
352
|
-
var isDom = () => typeof window !== "undefined";
|
|
353
|
-
function getPlatform() {
|
|
354
|
-
var _a;
|
|
355
|
-
const agent = navigator.userAgentData;
|
|
356
|
-
return (_a = agent == null ? void 0 : agent.platform) != null ? _a : navigator.platform;
|
|
357
|
-
}
|
|
358
|
-
var pt = (v) => isDom() && v.test(getPlatform());
|
|
359
|
-
var isTouchDevice = () => isDom() && !!navigator.maxTouchPoints;
|
|
360
|
-
var isMac = () => pt(/^Mac/) && !isTouchDevice;
|
|
361
|
-
function isWindow2(value) {
|
|
362
|
-
return (value == null ? void 0 : value.toString()) === "[object Window]";
|
|
363
|
-
}
|
|
364
|
-
function getDocument2(el) {
|
|
365
|
-
var _a;
|
|
366
|
-
if (isWindow2(el))
|
|
367
|
-
return el.document;
|
|
368
|
-
return (_a = el == null ? void 0 : el.ownerDocument) != null ? _a : document;
|
|
369
|
-
}
|
|
370
|
-
function getWindow(el) {
|
|
371
|
-
var _a;
|
|
372
|
-
return (_a = el == null ? void 0 : el.ownerDocument.defaultView) != null ? _a : window;
|
|
373
|
-
}
|
|
374
|
-
function getEventTarget2(event) {
|
|
375
|
-
var _a, _b;
|
|
376
|
-
return (_b = (_a = event.composedPath) == null ? void 0 : _a.call(event)[0]) != null ? _b : event.target;
|
|
377
|
-
}
|
|
378
|
-
function contains2(parent, child) {
|
|
379
|
-
if (!parent)
|
|
380
|
-
return false;
|
|
381
|
-
return parent === child || isHTMLElement2(parent) && isHTMLElement2(child) && parent.contains(child);
|
|
382
|
-
}
|
|
383
|
-
function isHTMLElement2(v) {
|
|
384
|
-
return typeof v === "object" && (v == null ? void 0 : v.nodeType) === Node.ELEMENT_NODE && typeof (v == null ? void 0 : v.nodeName) === "string";
|
|
385
|
-
}
|
|
386
|
-
function isVisible2(el) {
|
|
387
|
-
if (!isHTMLElement2(el))
|
|
388
|
-
return false;
|
|
389
|
-
return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0;
|
|
390
|
-
}
|
|
391
|
-
var isContextMenuEvent = (e) => {
|
|
392
|
-
return e.button === 2 || isCtrlKey(e) && e.button === 0;
|
|
393
|
-
};
|
|
394
|
-
var isCtrlKey = (v) => isMac() ? v.metaKey && !v.ctrlKey : v.ctrlKey && !v.metaKey;
|
|
395
|
-
function fireCustomEvent(el, type, init) {
|
|
396
|
-
if (!el)
|
|
397
|
-
return;
|
|
398
|
-
const win = getWindow(el);
|
|
399
|
-
const event = new win.CustomEvent(type, init);
|
|
400
|
-
return el.dispatchEvent(event);
|
|
401
|
-
}
|
|
402
|
-
var focusableSelector2 = "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";
|
|
403
|
-
function isFocusable2(element) {
|
|
404
|
-
if (!element)
|
|
405
|
-
return false;
|
|
406
|
-
return element.matches(focusableSelector2) && isVisible2(element);
|
|
407
|
-
}
|
|
408
|
-
var isRef2 = (v) => hasProp2(v, "current");
|
|
409
|
-
function addDomEvent2(target, eventName, handler, options) {
|
|
410
|
-
const node = isRef2(target) ? target.current : runIfFn3(target);
|
|
411
|
-
node == null ? void 0 : node.addEventListener(eventName, handler, options);
|
|
412
|
-
return () => {
|
|
413
|
-
node == null ? void 0 : node.removeEventListener(eventName, handler, options);
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
var POINTER_OUTSIDE_EVENT = "pointerdown.outside";
|
|
417
|
-
var FOCUS_OUTSIDE_EVENT = "focus.outside";
|
|
418
|
-
function trackInteractOutside(node, options) {
|
|
419
|
-
const { exclude, onFocusOutside, onPointerDownOutside } = options;
|
|
420
|
-
if (!node)
|
|
421
|
-
return;
|
|
422
|
-
const doc = getDocument2(node);
|
|
423
|
-
const win = getWindow(node);
|
|
424
|
-
function isEventOutside(event) {
|
|
425
|
-
const target = getEventTarget2(event);
|
|
426
|
-
if (!(target instanceof win.HTMLElement)) {
|
|
427
|
-
return false;
|
|
428
|
-
}
|
|
429
|
-
if (!contains2(doc.documentElement, target)) {
|
|
430
|
-
return false;
|
|
431
|
-
}
|
|
432
|
-
if (contains2(node, target)) {
|
|
433
|
-
return false;
|
|
434
|
-
}
|
|
435
|
-
return !(exclude == null ? void 0 : exclude(target));
|
|
436
|
-
}
|
|
437
|
-
let clickHandler;
|
|
438
|
-
function onPointerDown(event) {
|
|
439
|
-
function handler() {
|
|
440
|
-
if (!node || !isEventOutside(event))
|
|
441
|
-
return;
|
|
442
|
-
if (onPointerDownOutside) {
|
|
443
|
-
node.addEventListener(POINTER_OUTSIDE_EVENT, onPointerDownOutside, { once: true });
|
|
444
|
-
}
|
|
445
|
-
fireCustomEvent(node, POINTER_OUTSIDE_EVENT, {
|
|
446
|
-
bubbles: false,
|
|
447
|
-
cancelable: true,
|
|
448
|
-
detail: {
|
|
449
|
-
originalEvent: event,
|
|
450
|
-
contextmenu: isContextMenuEvent(event),
|
|
451
|
-
focusable: isFocusable2(getEventTarget2(event))
|
|
452
|
-
}
|
|
453
|
-
});
|
|
454
|
-
}
|
|
455
|
-
if (event.pointerType === "touch") {
|
|
456
|
-
doc.removeEventListener("click", handler);
|
|
457
|
-
clickHandler = handler;
|
|
458
|
-
doc.addEventListener("click", handler, { once: true });
|
|
459
|
-
} else {
|
|
460
|
-
handler();
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
const cleanups = /* @__PURE__ */ new Set();
|
|
464
|
-
const timer = setTimeout(() => {
|
|
465
|
-
cleanups.add(addDomEvent2(doc, "pointerdown", onPointerDown, true));
|
|
466
|
-
}, 0);
|
|
467
|
-
function onFocusin(event) {
|
|
468
|
-
if (!node || !isEventOutside(event))
|
|
469
|
-
return;
|
|
470
|
-
if (onFocusOutside) {
|
|
471
|
-
node.addEventListener(FOCUS_OUTSIDE_EVENT, onFocusOutside, { once: true });
|
|
472
|
-
}
|
|
473
|
-
fireCustomEvent(node, FOCUS_OUTSIDE_EVENT, {
|
|
474
|
-
bubbles: false,
|
|
475
|
-
cancelable: true,
|
|
476
|
-
detail: {
|
|
477
|
-
originalEvent: event,
|
|
478
|
-
contextmenu: false,
|
|
479
|
-
focusable: isFocusable2(getEventTarget2(event))
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
}
|
|
483
|
-
cleanups.add(addDomEvent2(doc, "focusin", onFocusin, true));
|
|
484
|
-
return () => {
|
|
485
|
-
clearTimeout(timer);
|
|
486
|
-
if (clickHandler)
|
|
487
|
-
doc.removeEventListener("click", clickHandler);
|
|
488
|
-
cleanups.forEach((fn) => fn());
|
|
489
|
-
};
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// ../../utilities/dismissable/src/escape-keydown.ts
|
|
493
|
-
function trackEscapeKeydown(fn) {
|
|
494
|
-
const handleKeyDown = (event) => {
|
|
495
|
-
if (event.key === "Escape")
|
|
496
|
-
fn == null ? void 0 : fn(event);
|
|
497
|
-
};
|
|
498
|
-
return addDomEvent(document, "keydown", handleKeyDown);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// ../../utilities/dismissable/src/layer-stack.ts
|
|
502
|
-
var layerStack = {
|
|
503
|
-
layers: [],
|
|
504
|
-
branches: [],
|
|
505
|
-
count() {
|
|
506
|
-
return this.layers.length;
|
|
507
|
-
},
|
|
508
|
-
pointerBlockingLayers() {
|
|
509
|
-
return this.layers.filter((layer) => layer.pointerBlocking);
|
|
510
|
-
},
|
|
511
|
-
topMostPointerBlockingLayer() {
|
|
512
|
-
return [...this.pointerBlockingLayers()].slice(-1)[0];
|
|
513
|
-
},
|
|
514
|
-
hasPointerBlockingLayer() {
|
|
515
|
-
return this.pointerBlockingLayers().length > 0;
|
|
516
|
-
},
|
|
517
|
-
isBelowPointerBlockingLayer(node) {
|
|
518
|
-
var _a;
|
|
519
|
-
const index = this.indexOf(node);
|
|
520
|
-
const highestBlockingIndex = this.topMostPointerBlockingLayer() ? this.indexOf((_a = this.topMostPointerBlockingLayer()) == null ? void 0 : _a.node) : -1;
|
|
521
|
-
return index < highestBlockingIndex;
|
|
522
|
-
},
|
|
523
|
-
isTopMost(node) {
|
|
524
|
-
const layer = this.layers[this.count() - 1];
|
|
525
|
-
return (layer == null ? void 0 : layer.node) === node;
|
|
526
|
-
},
|
|
527
|
-
getNestedLayers(node) {
|
|
528
|
-
return Array.from(this.layers).slice(this.indexOf(node) + 1);
|
|
529
|
-
},
|
|
530
|
-
isInNestedLayer(node, target) {
|
|
531
|
-
return this.getNestedLayers(node).some((layer) => contains(layer.node, target));
|
|
532
|
-
},
|
|
533
|
-
isInBranch(target) {
|
|
534
|
-
return Array.from(this.branches).some((branch) => contains(branch, target));
|
|
535
|
-
},
|
|
536
|
-
add(layer) {
|
|
537
|
-
this.layers.push(layer);
|
|
538
|
-
},
|
|
539
|
-
addBranch(node) {
|
|
540
|
-
this.branches.push(node);
|
|
541
|
-
},
|
|
542
|
-
remove(node) {
|
|
543
|
-
const index = this.indexOf(node);
|
|
544
|
-
if (index < 0)
|
|
545
|
-
return;
|
|
546
|
-
if (index < this.count() - 1) {
|
|
547
|
-
const _layers = this.getNestedLayers(node);
|
|
548
|
-
_layers.forEach((layer) => layer.dismiss());
|
|
549
|
-
}
|
|
550
|
-
this.layers.splice(index, 1);
|
|
551
|
-
},
|
|
552
|
-
removeBranch(node) {
|
|
553
|
-
const index = this.branches.indexOf(node);
|
|
554
|
-
if (index >= 0)
|
|
555
|
-
this.branches.splice(index, 1);
|
|
556
|
-
},
|
|
557
|
-
indexOf(node) {
|
|
558
|
-
return this.layers.findIndex((layer) => layer.node === node);
|
|
559
|
-
},
|
|
560
|
-
dismiss(node) {
|
|
561
|
-
var _a;
|
|
562
|
-
(_a = this.layers[this.indexOf(node)]) == null ? void 0 : _a.dismiss();
|
|
563
|
-
},
|
|
564
|
-
clear() {
|
|
565
|
-
this.remove(this.layers[0].node);
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
|
|
569
|
-
// ../../utilities/dismissable/src/pointer-event-outside.ts
|
|
570
|
-
var originalBodyPointerEvents;
|
|
571
|
-
function assignPointerEventToLayers() {
|
|
572
|
-
layerStack.layers.forEach(({ node }) => {
|
|
573
|
-
node.style.pointerEvents = layerStack.isBelowPointerBlockingLayer(node) ? "none" : "auto";
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
function clearPointerEvent(node) {
|
|
577
|
-
node.style.pointerEvents = "";
|
|
578
|
-
}
|
|
579
|
-
var DATA_ATTR = "data-inert";
|
|
580
|
-
function disablePointerEventsOutside(node) {
|
|
581
|
-
const doc = getDocument(node);
|
|
582
|
-
if (layerStack.hasPointerBlockingLayer() && !doc.body.hasAttribute(DATA_ATTR)) {
|
|
583
|
-
originalBodyPointerEvents = document.body.style.pointerEvents;
|
|
584
|
-
doc.body.style.pointerEvents = "none";
|
|
585
|
-
doc.body.setAttribute(DATA_ATTR, "");
|
|
586
|
-
}
|
|
587
|
-
return () => {
|
|
588
|
-
if (layerStack.hasPointerBlockingLayer())
|
|
589
|
-
return;
|
|
590
|
-
doc.body.style.pointerEvents = originalBodyPointerEvents;
|
|
591
|
-
doc.body.removeAttribute(DATA_ATTR);
|
|
592
|
-
if (doc.body.style.length === 0)
|
|
593
|
-
doc.body.removeAttribute("style");
|
|
594
|
-
};
|
|
595
|
-
}
|
|
596
|
-
|
|
597
|
-
// ../../utilities/dismissable/src/dismissable-layer.ts
|
|
598
|
-
function trackDismissableElement(node, options) {
|
|
599
|
-
if (!node)
|
|
600
|
-
return;
|
|
601
|
-
const { onDismiss, pointerBlocking, exclude: excludeContainers, debug } = options;
|
|
602
|
-
const layer = { dismiss: onDismiss, node, pointerBlocking };
|
|
603
|
-
layerStack.add(layer);
|
|
604
|
-
assignPointerEventToLayers();
|
|
605
|
-
function onPointerDownOutside(event) {
|
|
606
|
-
var _a, _b;
|
|
607
|
-
const target = getEventTarget(event.detail.originalEvent);
|
|
608
|
-
if (layerStack.isBelowPointerBlockingLayer(node) || layerStack.isInBranch(target))
|
|
609
|
-
return;
|
|
610
|
-
(_a = options.onPointerDownOutside) == null ? void 0 : _a.call(options, event);
|
|
611
|
-
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
612
|
-
if (event.defaultPrevented)
|
|
613
|
-
return;
|
|
614
|
-
if (debug) {
|
|
615
|
-
console.log("onPointerDownOutside:", event.detail.originalEvent);
|
|
616
|
-
}
|
|
617
|
-
onDismiss == null ? void 0 : onDismiss();
|
|
618
|
-
}
|
|
619
|
-
function onFocusOutside(event) {
|
|
620
|
-
var _a, _b;
|
|
621
|
-
const target = getEventTarget(event.detail.originalEvent);
|
|
622
|
-
if (layerStack.isInBranch(target))
|
|
623
|
-
return;
|
|
624
|
-
(_a = options.onFocusOutside) == null ? void 0 : _a.call(options, event);
|
|
625
|
-
(_b = options.onInteractOutside) == null ? void 0 : _b.call(options, event);
|
|
626
|
-
if (event.defaultPrevented)
|
|
627
|
-
return;
|
|
628
|
-
if (debug) {
|
|
629
|
-
console.log("onFocusOutside:", event.detail.originalEvent);
|
|
630
|
-
}
|
|
631
|
-
onDismiss == null ? void 0 : onDismiss();
|
|
632
|
-
}
|
|
633
|
-
function onEscapeKeyDown(event) {
|
|
634
|
-
var _a;
|
|
635
|
-
if (!layerStack.isTopMost(node))
|
|
636
|
-
return;
|
|
637
|
-
(_a = options.onEscapeKeyDown) == null ? void 0 : _a.call(options, event);
|
|
638
|
-
if (!event.defaultPrevented && onDismiss) {
|
|
639
|
-
event.preventDefault();
|
|
640
|
-
onDismiss();
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
function exclude(target) {
|
|
644
|
-
if (!node)
|
|
645
|
-
return false;
|
|
646
|
-
const containers = typeof excludeContainers === "function" ? excludeContainers() : excludeContainers;
|
|
647
|
-
const _containers = Array.isArray(containers) ? containers : [containers];
|
|
648
|
-
return _containers.some((node2) => contains(node2, target)) || layerStack.isInNestedLayer(node, target);
|
|
649
|
-
}
|
|
650
|
-
const cleanups = [
|
|
651
|
-
pointerBlocking ? disablePointerEventsOutside(node) : void 0,
|
|
652
|
-
trackEscapeKeydown(onEscapeKeyDown),
|
|
653
|
-
trackInteractOutside(node, { exclude, onFocusOutside, onPointerDownOutside })
|
|
654
|
-
];
|
|
655
|
-
return () => {
|
|
656
|
-
layerStack.remove(node);
|
|
657
|
-
assignPointerEventToLayers();
|
|
658
|
-
clearPointerEvent(node);
|
|
659
|
-
cleanups.forEach((fn) => fn == null ? void 0 : fn());
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
// src/popover.machine.ts
|
|
332
|
+
var import_dismissable = require("@zag-js/dismissable");
|
|
664
333
|
var import_popper2 = require("@zag-js/popper");
|
|
665
334
|
var import_remove_scroll = require("@zag-js/remove-scroll");
|
|
666
335
|
var import_focus_trap = require("focus-trap");
|
|
667
336
|
var { and, or, not } = import_core.guards;
|
|
668
|
-
function machine(ctx
|
|
669
|
-
return (0, import_core.createMachine)(
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
}),
|
|
690
|
-
computed: {
|
|
691
|
-
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
692
|
-
},
|
|
693
|
-
states: {
|
|
694
|
-
unknown: {
|
|
695
|
-
on: {
|
|
696
|
-
SETUP: {
|
|
697
|
-
target: ctx.defaultOpen ? "open" : "closed",
|
|
698
|
-
actions: ["setupDocument", "checkRenderedElements"]
|
|
699
|
-
}
|
|
337
|
+
function machine(ctx) {
|
|
338
|
+
return (0, import_core.createMachine)(
|
|
339
|
+
{
|
|
340
|
+
id: "popover",
|
|
341
|
+
initial: "unknown",
|
|
342
|
+
context: {
|
|
343
|
+
closeOnInteractOutside: true,
|
|
344
|
+
closeOnEsc: true,
|
|
345
|
+
autoFocus: true,
|
|
346
|
+
modal: false,
|
|
347
|
+
positioning: {
|
|
348
|
+
placement: "bottom",
|
|
349
|
+
...ctx.positioning
|
|
350
|
+
},
|
|
351
|
+
currentPlacement: void 0,
|
|
352
|
+
...ctx,
|
|
353
|
+
focusTriggerOnClose: true,
|
|
354
|
+
renderedElements: {
|
|
355
|
+
title: true,
|
|
356
|
+
description: true,
|
|
357
|
+
anchor: false
|
|
700
358
|
}
|
|
701
359
|
},
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
on: {
|
|
705
|
-
TOGGLE: "open",
|
|
706
|
-
OPEN: "open"
|
|
707
|
-
}
|
|
360
|
+
computed: {
|
|
361
|
+
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
708
362
|
},
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
"trackInteractionOutside",
|
|
716
|
-
"trackTabKeyDown"
|
|
717
|
-
],
|
|
718
|
-
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
719
|
-
on: {
|
|
720
|
-
CLOSE: "closed",
|
|
721
|
-
REQUEST_CLOSE: {
|
|
722
|
-
target: "closed",
|
|
723
|
-
actions: "focusTriggerIfNeeded"
|
|
724
|
-
},
|
|
725
|
-
TOGGLE: "closed",
|
|
726
|
-
TRIGGER_BLUR: {
|
|
727
|
-
guard: not("isRelatedTargetWithinContent"),
|
|
728
|
-
target: "closed"
|
|
729
|
-
},
|
|
730
|
-
TAB: [
|
|
731
|
-
{
|
|
732
|
-
guard: and("isTriggerFocused", "portalled"),
|
|
733
|
-
actions: "focusFirstTabbableElement"
|
|
734
|
-
},
|
|
735
|
-
{
|
|
736
|
-
guard: and("isLastTabbableElement", "closeOnInteractOutside", "portalled"),
|
|
737
|
-
target: "closed",
|
|
738
|
-
actions: "focusNextTabbableElementAfterTrigger"
|
|
363
|
+
states: {
|
|
364
|
+
unknown: {
|
|
365
|
+
on: {
|
|
366
|
+
SETUP: {
|
|
367
|
+
target: ctx.defaultOpen ? "open" : "closed",
|
|
368
|
+
actions: "checkRenderedElements"
|
|
739
369
|
}
|
|
370
|
+
}
|
|
371
|
+
},
|
|
372
|
+
closed: {
|
|
373
|
+
entry: "invokeOnClose",
|
|
374
|
+
on: {
|
|
375
|
+
TOGGLE: "open",
|
|
376
|
+
OPEN: "open"
|
|
377
|
+
}
|
|
378
|
+
},
|
|
379
|
+
open: {
|
|
380
|
+
activities: [
|
|
381
|
+
"trapFocus",
|
|
382
|
+
"preventScroll",
|
|
383
|
+
"hideContentBelow",
|
|
384
|
+
"computePlacement",
|
|
385
|
+
"trackInteractionOutside",
|
|
386
|
+
"trackTabKeyDown"
|
|
740
387
|
],
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
388
|
+
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
389
|
+
on: {
|
|
390
|
+
CLOSE: "closed",
|
|
391
|
+
REQUEST_CLOSE: {
|
|
392
|
+
target: "closed",
|
|
393
|
+
actions: "focusTriggerIfNeeded"
|
|
394
|
+
},
|
|
395
|
+
TOGGLE: "closed",
|
|
396
|
+
TRIGGER_BLUR: {
|
|
397
|
+
guard: not("isRelatedTargetWithinContent"),
|
|
398
|
+
target: "closed"
|
|
399
|
+
},
|
|
400
|
+
TAB: [
|
|
401
|
+
{
|
|
402
|
+
guard: and("isTriggerFocused", "portalled"),
|
|
403
|
+
actions: "focusFirstTabbableElement"
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
guard: and("isLastTabbableElement", "closeOnInteractOutside", "portalled"),
|
|
407
|
+
target: "closed",
|
|
408
|
+
actions: "focusNextTabbableElementAfterTrigger"
|
|
409
|
+
}
|
|
410
|
+
],
|
|
411
|
+
SHIFT_TAB: {
|
|
412
|
+
guard: and(or("isFirstTabbableElement", "isContentFocused"), "portalled"),
|
|
413
|
+
actions: "focusTriggerIfNeeded"
|
|
414
|
+
}
|
|
744
415
|
}
|
|
745
416
|
}
|
|
746
417
|
}
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
}));
|
|
763
|
-
},
|
|
764
|
-
trackInteractionOutside(ctx2, _evt, { send }) {
|
|
765
|
-
return trackDismissableElement(dom.getContentEl(ctx2), {
|
|
766
|
-
pointerBlocking: ctx2.modal,
|
|
767
|
-
exclude: dom.getTriggerEl(ctx2),
|
|
768
|
-
onEscapeKeyDown(event) {
|
|
769
|
-
var _a;
|
|
770
|
-
(_a = ctx2.onEscapeKeyDown) == null ? void 0 : _a.call(ctx2, event);
|
|
771
|
-
if (ctx2.closeOnEsc)
|
|
772
|
-
return;
|
|
773
|
-
ctx2.focusTriggerOnClose = true;
|
|
774
|
-
event.preventDefault();
|
|
775
|
-
},
|
|
776
|
-
onInteractOutside(event) {
|
|
777
|
-
var _a;
|
|
778
|
-
(_a = ctx2.onInteractOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
779
|
-
if (event.defaultPrevented)
|
|
780
|
-
return;
|
|
781
|
-
ctx2.focusTriggerOnClose = !(event.detail.focusable || event.detail.contextmenu);
|
|
782
|
-
if (!ctx2.closeOnInteractOutside) {
|
|
783
|
-
event.preventDefault();
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
activities: {
|
|
421
|
+
computePlacement(ctx2) {
|
|
422
|
+
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
423
|
+
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
424
|
+
return (0, import_popper2.getPlacement)(anchorEl, dom.getPositionerEl(ctx2), {
|
|
425
|
+
...ctx2.positioning,
|
|
426
|
+
onComplete(data) {
|
|
427
|
+
ctx2.currentPlacement = data.placement;
|
|
428
|
+
ctx2.isPlacementComplete = true;
|
|
429
|
+
},
|
|
430
|
+
onCleanup() {
|
|
431
|
+
ctx2.currentPlacement = void 0;
|
|
432
|
+
ctx2.isPlacementComplete = false;
|
|
784
433
|
}
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
434
|
+
});
|
|
435
|
+
},
|
|
436
|
+
trackInteractionOutside(ctx2, _evt, { send }) {
|
|
437
|
+
return (0, import_dismissable.trackDismissableElement)(dom.getContentEl(ctx2), {
|
|
438
|
+
pointerBlocking: ctx2.modal,
|
|
439
|
+
exclude: dom.getTriggerEl(ctx2),
|
|
440
|
+
onEscapeKeyDown(event) {
|
|
441
|
+
var _a;
|
|
442
|
+
(_a = ctx2.onEscapeKeyDown) == null ? void 0 : _a.call(ctx2, event);
|
|
443
|
+
if (ctx2.closeOnEsc)
|
|
444
|
+
return;
|
|
445
|
+
ctx2.focusTriggerOnClose = true;
|
|
794
446
|
event.preventDefault();
|
|
447
|
+
},
|
|
448
|
+
onInteractOutside(event) {
|
|
449
|
+
var _a;
|
|
450
|
+
(_a = ctx2.onInteractOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
451
|
+
if (event.defaultPrevented)
|
|
452
|
+
return;
|
|
453
|
+
ctx2.focusTriggerOnClose = !(event.detail.focusable || event.detail.contextmenu);
|
|
454
|
+
if (!ctx2.closeOnInteractOutside) {
|
|
455
|
+
event.preventDefault();
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
onPointerDownOutside(event) {
|
|
459
|
+
var _a;
|
|
460
|
+
(_a = ctx2.onPointerDownOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
461
|
+
},
|
|
462
|
+
onFocusOutside(event) {
|
|
463
|
+
var _a;
|
|
464
|
+
(_a = ctx2.onFocusOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
465
|
+
if (ctx2.currentPortalled) {
|
|
466
|
+
event.preventDefault();
|
|
467
|
+
}
|
|
468
|
+
},
|
|
469
|
+
onDismiss() {
|
|
470
|
+
send({ type: "REQUEST_CLOSE", src: "#interact-outside" });
|
|
795
471
|
}
|
|
796
|
-
},
|
|
797
|
-
onDismiss() {
|
|
798
|
-
send({ type: "REQUEST_CLOSE", src: "#interact-outside" });
|
|
799
|
-
}
|
|
800
|
-
});
|
|
801
|
-
},
|
|
802
|
-
trackTabKeyDown(ctx2, _evt, { send }) {
|
|
803
|
-
if (ctx2.modal)
|
|
804
|
-
return;
|
|
805
|
-
return addDomEvent(dom.getWin(ctx2), "keydown", (event) => {
|
|
806
|
-
const isTabKey = event.key === "Tab" && !isModifiedEvent(event);
|
|
807
|
-
if (!isTabKey)
|
|
808
|
-
return;
|
|
809
|
-
send({
|
|
810
|
-
type: event.shiftKey ? "SHIFT_TAB" : "TAB",
|
|
811
|
-
preventDefault: () => event.preventDefault()
|
|
812
472
|
});
|
|
813
|
-
},
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
if (!ctx2.modal)
|
|
817
|
-
return;
|
|
818
|
-
let cleanup;
|
|
819
|
-
nextTick(() => {
|
|
820
|
-
cleanup = (0, import_aria_hidden.ariaHidden)([dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)]);
|
|
821
|
-
});
|
|
822
|
-
return () => cleanup == null ? void 0 : cleanup();
|
|
823
|
-
},
|
|
824
|
-
preventScroll(ctx2) {
|
|
825
|
-
if (!ctx2.modal)
|
|
826
|
-
return;
|
|
827
|
-
return (0, import_remove_scroll.preventBodyScroll)(dom.getDoc(ctx2));
|
|
828
|
-
},
|
|
829
|
-
trapFocus(ctx2) {
|
|
830
|
-
if (!ctx2.modal)
|
|
831
|
-
return;
|
|
832
|
-
let trap;
|
|
833
|
-
nextTick(() => {
|
|
834
|
-
const el = dom.getContentEl(ctx2);
|
|
835
|
-
if (!el)
|
|
473
|
+
},
|
|
474
|
+
trackTabKeyDown(ctx2, _evt, { send }) {
|
|
475
|
+
if (ctx2.modal)
|
|
836
476
|
return;
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
477
|
+
return addDomEvent(
|
|
478
|
+
dom.getWin(ctx2),
|
|
479
|
+
"keydown",
|
|
480
|
+
(event) => {
|
|
481
|
+
const isTabKey = event.key === "Tab" && !isModifiedEvent(event);
|
|
482
|
+
if (!isTabKey)
|
|
483
|
+
return;
|
|
484
|
+
send({
|
|
485
|
+
type: event.shiftKey ? "SHIFT_TAB" : "TAB",
|
|
486
|
+
preventDefault: () => event.preventDefault()
|
|
487
|
+
});
|
|
488
|
+
},
|
|
489
|
+
true
|
|
490
|
+
);
|
|
491
|
+
},
|
|
492
|
+
hideContentBelow(ctx2) {
|
|
493
|
+
if (!ctx2.modal)
|
|
494
|
+
return;
|
|
495
|
+
let cleanup;
|
|
496
|
+
nextTick(() => {
|
|
497
|
+
cleanup = (0, import_aria_hidden.ariaHidden)([dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)]);
|
|
844
498
|
});
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
499
|
+
return () => cleanup == null ? void 0 : cleanup();
|
|
500
|
+
},
|
|
501
|
+
preventScroll(ctx2) {
|
|
502
|
+
if (!ctx2.modal)
|
|
503
|
+
return;
|
|
504
|
+
return (0, import_remove_scroll.preventBodyScroll)(dom.getDoc(ctx2));
|
|
505
|
+
},
|
|
506
|
+
trapFocus(ctx2) {
|
|
507
|
+
if (!ctx2.modal)
|
|
508
|
+
return;
|
|
509
|
+
let trap;
|
|
510
|
+
nextTick(() => {
|
|
511
|
+
const el = dom.getContentEl(ctx2);
|
|
512
|
+
if (!el)
|
|
513
|
+
return;
|
|
514
|
+
trap = (0, import_focus_trap.createFocusTrap)(el, {
|
|
515
|
+
escapeDeactivates: false,
|
|
516
|
+
allowOutsideClick: true,
|
|
517
|
+
returnFocusOnDeactivate: true,
|
|
518
|
+
document: dom.getDoc(ctx2),
|
|
519
|
+
fallbackFocus: el,
|
|
520
|
+
initialFocus: runIfFn2(ctx2.initialFocusEl)
|
|
521
|
+
});
|
|
522
|
+
try {
|
|
523
|
+
trap.activate();
|
|
524
|
+
} catch {
|
|
525
|
+
}
|
|
869
526
|
});
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
setupDocument(ctx2, evt) {
|
|
873
|
-
if (evt.doc)
|
|
874
|
-
ctx2.doc = (0, import_core.ref)(evt.doc);
|
|
875
|
-
if (evt.root)
|
|
876
|
-
ctx2.rootNode = (0, import_core.ref)(evt.root);
|
|
877
|
-
ctx2.uid = evt.id;
|
|
527
|
+
return () => trap == null ? void 0 : trap.deactivate();
|
|
528
|
+
}
|
|
878
529
|
},
|
|
879
|
-
|
|
880
|
-
ctx2
|
|
530
|
+
guards: {
|
|
531
|
+
portalled: (ctx2) => ctx2.currentPortalled,
|
|
532
|
+
isRelatedTargetWithinContent: (ctx2, evt) => contains(dom.getContentEl(ctx2), evt.target),
|
|
533
|
+
closeOnInteractOutside: (ctx2) => !!ctx2.closeOnInteractOutside,
|
|
534
|
+
isContentFocused: (ctx2) => dom.getContentEl(ctx2) === dom.getActiveEl(ctx2),
|
|
535
|
+
isTriggerFocused: (ctx2) => dom.getTriggerEl(ctx2) === dom.getActiveEl(ctx2),
|
|
536
|
+
isFirstTabbableElement: (ctx2) => dom.getFirstTabbableEl(ctx2) === dom.getActiveEl(ctx2),
|
|
537
|
+
isLastTabbableElement: (ctx2) => dom.getLastTabbableEl(ctx2) === dom.getActiveEl(ctx2)
|
|
881
538
|
},
|
|
882
|
-
|
|
883
|
-
|
|
539
|
+
actions: {
|
|
540
|
+
checkRenderedElements(ctx2) {
|
|
541
|
+
raf(() => {
|
|
542
|
+
Object.assign(ctx2.renderedElements, {
|
|
543
|
+
title: !!dom.getTitleEl(ctx2),
|
|
544
|
+
description: !!dom.getDescriptionEl(ctx2),
|
|
545
|
+
anchor: !!dom.getAnchorEl(ctx2)
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
},
|
|
549
|
+
setInitialFocus(ctx2) {
|
|
550
|
+
raf(() => {
|
|
551
|
+
var _a;
|
|
552
|
+
(_a = dom.getInitialFocusEl(ctx2)) == null ? void 0 : _a.focus();
|
|
553
|
+
});
|
|
554
|
+
},
|
|
555
|
+
focusTriggerIfNeeded(ctx2) {
|
|
556
|
+
if (!ctx2.focusTriggerOnClose)
|
|
557
|
+
return;
|
|
558
|
+
raf(() => {
|
|
559
|
+
var _a;
|
|
560
|
+
return (_a = dom.getTriggerEl(ctx2)) == null ? void 0 : _a.focus();
|
|
561
|
+
});
|
|
562
|
+
},
|
|
563
|
+
focusFirstTabbableElement(ctx2, evt) {
|
|
884
564
|
var _a;
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
if (!ctx2.focusTriggerOnClose)
|
|
890
|
-
return;
|
|
891
|
-
raf(() => {
|
|
565
|
+
evt.preventDefault();
|
|
566
|
+
(_a = dom.getFirstTabbableEl(ctx2)) == null ? void 0 : _a.focus();
|
|
567
|
+
},
|
|
568
|
+
invokeOnOpen(ctx2, evt) {
|
|
892
569
|
var _a;
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
let tabbables = dom.getDocTabbableEls(ctx2);
|
|
922
|
-
let elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
923
|
-
if (elementAfterTrigger === content) {
|
|
924
|
-
tabbables = tabbables.filter((el) => !contains(content, el));
|
|
925
|
-
elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
570
|
+
if (evt.type !== "SETUP") {
|
|
571
|
+
(_a = ctx2.onOpenChange) == null ? void 0 : _a.call(ctx2, true);
|
|
572
|
+
}
|
|
573
|
+
},
|
|
574
|
+
invokeOnClose(ctx2, evt) {
|
|
575
|
+
var _a;
|
|
576
|
+
if (evt.type !== "SETUP") {
|
|
577
|
+
(_a = ctx2.onOpenChange) == null ? void 0 : _a.call(ctx2, false);
|
|
578
|
+
}
|
|
579
|
+
},
|
|
580
|
+
focusNextTabbableElementAfterTrigger(ctx2, evt) {
|
|
581
|
+
const content = dom.getContentEl(ctx2);
|
|
582
|
+
const button = dom.getTriggerEl(ctx2);
|
|
583
|
+
if (!content || !button)
|
|
584
|
+
return;
|
|
585
|
+
const lastTabbable = dom.getLastTabbableEl(ctx2);
|
|
586
|
+
if (lastTabbable !== dom.getActiveEl(ctx2))
|
|
587
|
+
return;
|
|
588
|
+
let tabbables = dom.getDocTabbableEls(ctx2);
|
|
589
|
+
let elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
590
|
+
if (elementAfterTrigger === content) {
|
|
591
|
+
tabbables = tabbables.filter((el) => !contains(content, el));
|
|
592
|
+
elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
593
|
+
}
|
|
594
|
+
if (!elementAfterTrigger || elementAfterTrigger === button)
|
|
595
|
+
return;
|
|
596
|
+
evt.preventDefault();
|
|
597
|
+
raf(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
|
|
926
598
|
}
|
|
927
|
-
if (!elementAfterTrigger || elementAfterTrigger === button)
|
|
928
|
-
return;
|
|
929
|
-
evt.preventDefault();
|
|
930
|
-
raf(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
|
|
931
599
|
}
|
|
932
600
|
}
|
|
933
|
-
|
|
601
|
+
);
|
|
934
602
|
}
|
|
603
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
604
|
+
0 && (module.exports = {
|
|
605
|
+
connect,
|
|
606
|
+
machine
|
|
607
|
+
});
|