@zag-js/popover 0.1.10 → 0.1.13
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 +269 -288
- package/dist/index.mjs +264 -291
- package/package.json +16 -15
- package/dist/popover.connect.d.ts +0 -17
- package/dist/popover.dom.d.ts +0 -41
- package/dist/popover.machine.d.ts +0 -2
- package/dist/popover.types.d.ts +0 -101
package/dist/index.mjs
CHANGED
|
@@ -1,46 +1,10 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defProps = Object.defineProperties;
|
|
3
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
1
|
// ../../utilities/dom/dist/index.mjs
|
|
22
|
-
var __defProp2 = Object.defineProperty;
|
|
23
|
-
var __getOwnPropSymbols2 = Object.getOwnPropertySymbols;
|
|
24
|
-
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
25
|
-
var __propIsEnum2 = Object.prototype.propertyIsEnumerable;
|
|
26
|
-
var __defNormalProp2 = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
27
|
-
var __spreadValues2 = (a, b) => {
|
|
28
|
-
for (var prop in b || (b = {}))
|
|
29
|
-
if (__hasOwnProp2.call(b, prop))
|
|
30
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
31
|
-
if (__getOwnPropSymbols2)
|
|
32
|
-
for (var prop of __getOwnPropSymbols2(b)) {
|
|
33
|
-
if (__propIsEnum2.call(b, prop))
|
|
34
|
-
__defNormalProp2(a, prop, b[prop]);
|
|
35
|
-
}
|
|
36
|
-
return a;
|
|
37
|
-
};
|
|
38
2
|
var dataAttr = (guard) => {
|
|
39
3
|
return guard ? "" : void 0;
|
|
40
4
|
};
|
|
41
5
|
var runIfFn = (v, ...a) => {
|
|
42
6
|
const res = typeof v === "function" ? v(...a) : v;
|
|
43
|
-
return res
|
|
7
|
+
return res ?? void 0;
|
|
44
8
|
};
|
|
45
9
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
46
10
|
function isDocument(el) {
|
|
@@ -53,28 +17,27 @@ function isFrame(element) {
|
|
|
53
17
|
return element.localName === "iframe";
|
|
54
18
|
}
|
|
55
19
|
function getDocument(el) {
|
|
56
|
-
var _a;
|
|
57
20
|
if (isWindow(el))
|
|
58
21
|
return el.document;
|
|
59
22
|
if (isDocument(el))
|
|
60
23
|
return el;
|
|
61
|
-
return (
|
|
24
|
+
return (el == null ? void 0 : el.ownerDocument) ?? document;
|
|
62
25
|
}
|
|
63
26
|
function defineDomHelpers(helpers) {
|
|
64
27
|
const dom2 = {
|
|
65
28
|
getRootNode: (ctx) => {
|
|
66
|
-
var _a, _b;
|
|
67
|
-
return (_b = (_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) != null ? _b : document;
|
|
68
|
-
},
|
|
69
|
-
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
70
|
-
getWin: (ctx) => {
|
|
71
29
|
var _a;
|
|
72
|
-
return (_a =
|
|
30
|
+
return ((_a = ctx.getRootNode) == null ? void 0 : _a.call(ctx)) ?? document;
|
|
73
31
|
},
|
|
32
|
+
getDoc: (ctx) => getDocument(dom2.getRootNode(ctx)),
|
|
33
|
+
getWin: (ctx) => dom2.getDoc(ctx).defaultView ?? window,
|
|
74
34
|
getActiveElement: (ctx) => dom2.getDoc(ctx).activeElement,
|
|
75
35
|
getById: (ctx, id) => dom2.getRootNode(ctx).getElementById(id)
|
|
76
36
|
};
|
|
77
|
-
return
|
|
37
|
+
return {
|
|
38
|
+
...dom2,
|
|
39
|
+
...helpers
|
|
40
|
+
};
|
|
78
41
|
}
|
|
79
42
|
function contains(parent, child) {
|
|
80
43
|
if (!parent)
|
|
@@ -198,37 +161,37 @@ function next(v, idx, opts = {}) {
|
|
|
198
161
|
}
|
|
199
162
|
var runIfFn2 = (v, ...a) => {
|
|
200
163
|
const res = typeof v === "function" ? v(...a) : v;
|
|
201
|
-
return res
|
|
164
|
+
return res ?? void 0;
|
|
202
165
|
};
|
|
203
166
|
|
|
204
167
|
// src/popover.dom.ts
|
|
205
168
|
var dom = defineDomHelpers({
|
|
206
169
|
getActiveEl: (ctx) => dom.getDoc(ctx).activeElement,
|
|
207
170
|
getAnchorId: (ctx) => {
|
|
208
|
-
var _a
|
|
209
|
-
return (
|
|
171
|
+
var _a;
|
|
172
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.anchor) ?? `popover:${ctx.id}:anchor`;
|
|
210
173
|
},
|
|
211
174
|
getTriggerId: (ctx) => {
|
|
212
|
-
var _a
|
|
213
|
-
return (
|
|
175
|
+
var _a;
|
|
176
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.trigger) ?? `popover:${ctx.id}:trigger`;
|
|
214
177
|
},
|
|
215
178
|
getContentId: (ctx) => {
|
|
216
|
-
var _a
|
|
217
|
-
return (
|
|
179
|
+
var _a;
|
|
180
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.content) ?? `popover:${ctx.id}:content`;
|
|
218
181
|
},
|
|
219
182
|
getPositionerId: (ctx) => `popover:${ctx.id}:popper`,
|
|
220
183
|
getArrowId: (ctx) => `popover:${ctx.id}:arrow`,
|
|
221
184
|
getTitleId: (ctx) => {
|
|
222
|
-
var _a
|
|
223
|
-
return (
|
|
185
|
+
var _a;
|
|
186
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.title) ?? `popover:${ctx.id}:title`;
|
|
224
187
|
},
|
|
225
188
|
getDescriptionId: (ctx) => {
|
|
226
|
-
var _a
|
|
227
|
-
return (
|
|
189
|
+
var _a;
|
|
190
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.description) ?? `popover:${ctx.id}:desc`;
|
|
228
191
|
},
|
|
229
192
|
getCloseButtonId: (ctx) => {
|
|
230
|
-
var _a
|
|
231
|
-
return (
|
|
193
|
+
var _a;
|
|
194
|
+
return ((_a = ctx.ids) == null ? void 0 : _a.closeBtn) ?? `popover:${ctx.id}:close-button`;
|
|
232
195
|
},
|
|
233
196
|
getAnchorEl: (ctx) => dom.getById(ctx, dom.getAnchorId(ctx)),
|
|
234
197
|
getTriggerEl: (ctx) => dom.getById(ctx, dom.getTriggerId(ctx)),
|
|
@@ -345,260 +308,270 @@ import { preventBodyScroll } from "@zag-js/remove-scroll";
|
|
|
345
308
|
import { createFocusTrap } from "focus-trap";
|
|
346
309
|
var { and, or, not } = guards;
|
|
347
310
|
function machine(ctx) {
|
|
348
|
-
return createMachine(
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
computed: {
|
|
369
|
-
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
370
|
-
},
|
|
371
|
-
states: {
|
|
372
|
-
unknown: {
|
|
373
|
-
on: {
|
|
374
|
-
SETUP: {
|
|
375
|
-
target: ctx.defaultOpen ? "open" : "closed",
|
|
376
|
-
actions: "checkRenderedElements"
|
|
377
|
-
}
|
|
311
|
+
return createMachine(
|
|
312
|
+
{
|
|
313
|
+
id: "popover",
|
|
314
|
+
initial: "unknown",
|
|
315
|
+
context: {
|
|
316
|
+
closeOnInteractOutside: true,
|
|
317
|
+
closeOnEsc: true,
|
|
318
|
+
autoFocus: true,
|
|
319
|
+
modal: false,
|
|
320
|
+
positioning: {
|
|
321
|
+
placement: "bottom",
|
|
322
|
+
...ctx.positioning
|
|
323
|
+
},
|
|
324
|
+
currentPlacement: void 0,
|
|
325
|
+
...ctx,
|
|
326
|
+
focusTriggerOnClose: true,
|
|
327
|
+
renderedElements: {
|
|
328
|
+
title: true,
|
|
329
|
+
description: true,
|
|
330
|
+
anchor: false
|
|
378
331
|
}
|
|
379
332
|
},
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
on: {
|
|
383
|
-
TOGGLE: "open",
|
|
384
|
-
OPEN: "open"
|
|
385
|
-
}
|
|
333
|
+
computed: {
|
|
334
|
+
currentPortalled: (ctx2) => !!ctx2.modal || !!ctx2.portalled
|
|
386
335
|
},
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
"trackInteractionOutside",
|
|
394
|
-
"trackTabKeyDown"
|
|
395
|
-
],
|
|
396
|
-
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
397
|
-
on: {
|
|
398
|
-
CLOSE: "closed",
|
|
399
|
-
REQUEST_CLOSE: {
|
|
400
|
-
target: "closed",
|
|
401
|
-
actions: "focusTriggerIfNeeded"
|
|
402
|
-
},
|
|
403
|
-
TOGGLE: "closed",
|
|
404
|
-
TRIGGER_BLUR: {
|
|
405
|
-
guard: not("isRelatedTargetWithinContent"),
|
|
406
|
-
target: "closed"
|
|
407
|
-
},
|
|
408
|
-
TAB: [
|
|
409
|
-
{
|
|
410
|
-
guard: and("isTriggerFocused", "portalled"),
|
|
411
|
-
actions: "focusFirstTabbableElement"
|
|
412
|
-
},
|
|
413
|
-
{
|
|
414
|
-
guard: and("isLastTabbableElement", "closeOnInteractOutside", "portalled"),
|
|
415
|
-
target: "closed",
|
|
416
|
-
actions: "focusNextTabbableElementAfterTrigger"
|
|
336
|
+
states: {
|
|
337
|
+
unknown: {
|
|
338
|
+
on: {
|
|
339
|
+
SETUP: {
|
|
340
|
+
target: ctx.defaultOpen ? "open" : "closed",
|
|
341
|
+
actions: "checkRenderedElements"
|
|
417
342
|
}
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
closed: {
|
|
346
|
+
entry: "invokeOnClose",
|
|
347
|
+
on: {
|
|
348
|
+
TOGGLE: "open",
|
|
349
|
+
OPEN: "open"
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
open: {
|
|
353
|
+
activities: [
|
|
354
|
+
"trapFocus",
|
|
355
|
+
"preventScroll",
|
|
356
|
+
"hideContentBelow",
|
|
357
|
+
"computePlacement",
|
|
358
|
+
"trackInteractionOutside",
|
|
359
|
+
"trackTabKeyDown"
|
|
418
360
|
],
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
361
|
+
entry: ["setInitialFocus", "invokeOnOpen"],
|
|
362
|
+
on: {
|
|
363
|
+
CLOSE: "closed",
|
|
364
|
+
REQUEST_CLOSE: {
|
|
365
|
+
target: "closed",
|
|
366
|
+
actions: "focusTriggerIfNeeded"
|
|
367
|
+
},
|
|
368
|
+
TOGGLE: "closed",
|
|
369
|
+
TRIGGER_BLUR: {
|
|
370
|
+
guard: not("isRelatedTargetWithinContent"),
|
|
371
|
+
target: "closed"
|
|
372
|
+
},
|
|
373
|
+
TAB: [
|
|
374
|
+
{
|
|
375
|
+
guard: and("isTriggerFocused", "portalled"),
|
|
376
|
+
actions: "focusFirstTabbableElement"
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
guard: and("isLastTabbableElement", "closeOnInteractOutside", "portalled"),
|
|
380
|
+
target: "closed",
|
|
381
|
+
actions: "focusNextTabbableElementAfterTrigger"
|
|
382
|
+
}
|
|
383
|
+
],
|
|
384
|
+
SHIFT_TAB: {
|
|
385
|
+
guard: and(or("isFirstTabbableElement", "isContentFocused"), "portalled"),
|
|
386
|
+
actions: "focusTriggerIfNeeded"
|
|
387
|
+
}
|
|
422
388
|
}
|
|
423
389
|
}
|
|
424
390
|
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
}));
|
|
441
|
-
},
|
|
442
|
-
trackInteractionOutside(ctx2, _evt, { send }) {
|
|
443
|
-
return trackDismissableElement(dom.getContentEl(ctx2), {
|
|
444
|
-
pointerBlocking: ctx2.modal,
|
|
445
|
-
exclude: dom.getTriggerEl(ctx2),
|
|
446
|
-
onEscapeKeyDown(event) {
|
|
447
|
-
var _a;
|
|
448
|
-
(_a = ctx2.onEscapeKeyDown) == null ? void 0 : _a.call(ctx2, event);
|
|
449
|
-
if (ctx2.closeOnEsc)
|
|
450
|
-
return;
|
|
451
|
-
ctx2.focusTriggerOnClose = true;
|
|
452
|
-
event.preventDefault();
|
|
453
|
-
},
|
|
454
|
-
onInteractOutside(event) {
|
|
455
|
-
var _a;
|
|
456
|
-
(_a = ctx2.onInteractOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
457
|
-
if (event.defaultPrevented)
|
|
458
|
-
return;
|
|
459
|
-
ctx2.focusTriggerOnClose = !(event.detail.focusable || event.detail.contextmenu);
|
|
460
|
-
if (!ctx2.closeOnInteractOutside) {
|
|
461
|
-
event.preventDefault();
|
|
391
|
+
},
|
|
392
|
+
{
|
|
393
|
+
activities: {
|
|
394
|
+
computePlacement(ctx2) {
|
|
395
|
+
ctx2.currentPlacement = ctx2.positioning.placement;
|
|
396
|
+
const anchorEl = ctx2.renderedElements.anchor ? dom.getAnchorEl(ctx2) : dom.getTriggerEl(ctx2);
|
|
397
|
+
return getPlacement(anchorEl, dom.getPositionerEl(ctx2), {
|
|
398
|
+
...ctx2.positioning,
|
|
399
|
+
onComplete(data) {
|
|
400
|
+
ctx2.currentPlacement = data.placement;
|
|
401
|
+
ctx2.isPlacementComplete = true;
|
|
402
|
+
},
|
|
403
|
+
onCleanup() {
|
|
404
|
+
ctx2.currentPlacement = void 0;
|
|
405
|
+
ctx2.isPlacementComplete = false;
|
|
462
406
|
}
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
407
|
+
});
|
|
408
|
+
},
|
|
409
|
+
trackInteractionOutside(ctx2, _evt, { send }) {
|
|
410
|
+
return trackDismissableElement(dom.getContentEl(ctx2), {
|
|
411
|
+
pointerBlocking: ctx2.modal,
|
|
412
|
+
exclude: dom.getTriggerEl(ctx2),
|
|
413
|
+
onEscapeKeyDown(event) {
|
|
414
|
+
var _a;
|
|
415
|
+
(_a = ctx2.onEscapeKeyDown) == null ? void 0 : _a.call(ctx2, event);
|
|
416
|
+
if (ctx2.closeOnEsc)
|
|
417
|
+
return;
|
|
418
|
+
ctx2.focusTriggerOnClose = true;
|
|
472
419
|
event.preventDefault();
|
|
420
|
+
},
|
|
421
|
+
onInteractOutside(event) {
|
|
422
|
+
var _a;
|
|
423
|
+
(_a = ctx2.onInteractOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
424
|
+
if (event.defaultPrevented)
|
|
425
|
+
return;
|
|
426
|
+
ctx2.focusTriggerOnClose = !(event.detail.focusable || event.detail.contextmenu);
|
|
427
|
+
if (!ctx2.closeOnInteractOutside) {
|
|
428
|
+
event.preventDefault();
|
|
429
|
+
}
|
|
430
|
+
},
|
|
431
|
+
onPointerDownOutside(event) {
|
|
432
|
+
var _a;
|
|
433
|
+
(_a = ctx2.onPointerDownOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
434
|
+
},
|
|
435
|
+
onFocusOutside(event) {
|
|
436
|
+
var _a;
|
|
437
|
+
(_a = ctx2.onFocusOutside) == null ? void 0 : _a.call(ctx2, event);
|
|
438
|
+
if (ctx2.currentPortalled) {
|
|
439
|
+
event.preventDefault();
|
|
440
|
+
}
|
|
441
|
+
},
|
|
442
|
+
onDismiss() {
|
|
443
|
+
send({ type: "REQUEST_CLOSE", src: "#interact-outside" });
|
|
473
444
|
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
445
|
+
});
|
|
446
|
+
},
|
|
447
|
+
trackTabKeyDown(ctx2, _evt, { send }) {
|
|
448
|
+
if (ctx2.modal)
|
|
449
|
+
return;
|
|
450
|
+
return addDomEvent(
|
|
451
|
+
dom.getWin(ctx2),
|
|
452
|
+
"keydown",
|
|
453
|
+
(event) => {
|
|
454
|
+
const isTabKey = event.key === "Tab" && !isModifiedEvent(event);
|
|
455
|
+
if (!isTabKey)
|
|
456
|
+
return;
|
|
457
|
+
send({
|
|
458
|
+
type: event.shiftKey ? "SHIFT_TAB" : "TAB",
|
|
459
|
+
preventDefault: () => event.preventDefault()
|
|
460
|
+
});
|
|
461
|
+
},
|
|
462
|
+
true
|
|
463
|
+
);
|
|
464
|
+
},
|
|
465
|
+
hideContentBelow(ctx2) {
|
|
466
|
+
if (!ctx2.modal)
|
|
486
467
|
return;
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
468
|
+
let cleanup;
|
|
469
|
+
nextTick(() => {
|
|
470
|
+
cleanup = ariaHidden([dom.getContentEl(ctx2), dom.getTriggerEl(ctx2)]);
|
|
490
471
|
});
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
472
|
+
return () => cleanup == null ? void 0 : cleanup();
|
|
473
|
+
},
|
|
474
|
+
preventScroll(ctx2) {
|
|
475
|
+
if (!ctx2.modal)
|
|
476
|
+
return;
|
|
477
|
+
return preventBodyScroll(dom.getDoc(ctx2));
|
|
478
|
+
},
|
|
479
|
+
trapFocus(ctx2) {
|
|
480
|
+
if (!ctx2.modal)
|
|
481
|
+
return;
|
|
482
|
+
let trap;
|
|
483
|
+
nextTick(() => {
|
|
484
|
+
const el = dom.getContentEl(ctx2);
|
|
485
|
+
if (!el)
|
|
486
|
+
return;
|
|
487
|
+
trap = createFocusTrap(el, {
|
|
488
|
+
escapeDeactivates: false,
|
|
489
|
+
allowOutsideClick: true,
|
|
490
|
+
returnFocusOnDeactivate: true,
|
|
491
|
+
document: dom.getDoc(ctx2),
|
|
492
|
+
fallbackFocus: el,
|
|
493
|
+
initialFocus: runIfFn2(ctx2.initialFocusEl)
|
|
494
|
+
});
|
|
495
|
+
try {
|
|
496
|
+
trap.activate();
|
|
497
|
+
} catch {
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
return () => trap == null ? void 0 : trap.deactivate();
|
|
501
|
+
}
|
|
501
502
|
},
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
503
|
+
guards: {
|
|
504
|
+
portalled: (ctx2) => ctx2.currentPortalled,
|
|
505
|
+
isRelatedTargetWithinContent: (ctx2, evt) => contains(dom.getContentEl(ctx2), evt.target),
|
|
506
|
+
closeOnInteractOutside: (ctx2) => !!ctx2.closeOnInteractOutside,
|
|
507
|
+
isContentFocused: (ctx2) => dom.getContentEl(ctx2) === dom.getActiveEl(ctx2),
|
|
508
|
+
isTriggerFocused: (ctx2) => dom.getTriggerEl(ctx2) === dom.getActiveEl(ctx2),
|
|
509
|
+
isFirstTabbableElement: (ctx2) => dom.getFirstTabbableEl(ctx2) === dom.getActiveEl(ctx2),
|
|
510
|
+
isLastTabbableElement: (ctx2) => dom.getLastTabbableEl(ctx2) === dom.getActiveEl(ctx2)
|
|
506
511
|
},
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
trap = createFocusTrap(el, {
|
|
516
|
-
escapeDeactivates: false,
|
|
517
|
-
allowOutsideClick: true,
|
|
518
|
-
returnFocusOnDeactivate: true,
|
|
519
|
-
document: dom.getDoc(ctx2),
|
|
520
|
-
fallbackFocus: el,
|
|
521
|
-
initialFocus: runIfFn2(ctx2.initialFocusEl)
|
|
512
|
+
actions: {
|
|
513
|
+
checkRenderedElements(ctx2) {
|
|
514
|
+
raf(() => {
|
|
515
|
+
Object.assign(ctx2.renderedElements, {
|
|
516
|
+
title: !!dom.getTitleEl(ctx2),
|
|
517
|
+
description: !!dom.getDescriptionEl(ctx2),
|
|
518
|
+
anchor: !!dom.getAnchorEl(ctx2)
|
|
519
|
+
});
|
|
522
520
|
});
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
return () => trap == null ? void 0 : trap.deactivate();
|
|
529
|
-
}
|
|
530
|
-
},
|
|
531
|
-
guards: {
|
|
532
|
-
portalled: (ctx2) => ctx2.currentPortalled,
|
|
533
|
-
isRelatedTargetWithinContent: (ctx2, evt) => contains(dom.getContentEl(ctx2), evt.target),
|
|
534
|
-
closeOnInteractOutside: (ctx2) => !!ctx2.closeOnInteractOutside,
|
|
535
|
-
isContentFocused: (ctx2) => dom.getContentEl(ctx2) === dom.getActiveEl(ctx2),
|
|
536
|
-
isTriggerFocused: (ctx2) => dom.getTriggerEl(ctx2) === dom.getActiveEl(ctx2),
|
|
537
|
-
isFirstTabbableElement: (ctx2) => dom.getFirstTabbableEl(ctx2) === dom.getActiveEl(ctx2),
|
|
538
|
-
isLastTabbableElement: (ctx2) => dom.getLastTabbableEl(ctx2) === dom.getActiveEl(ctx2)
|
|
539
|
-
},
|
|
540
|
-
actions: {
|
|
541
|
-
checkRenderedElements(ctx2) {
|
|
542
|
-
raf(() => {
|
|
543
|
-
Object.assign(ctx2.renderedElements, {
|
|
544
|
-
title: !!dom.getTitleEl(ctx2),
|
|
545
|
-
description: !!dom.getDescriptionEl(ctx2),
|
|
546
|
-
anchor: !!dom.getAnchorEl(ctx2)
|
|
521
|
+
},
|
|
522
|
+
setInitialFocus(ctx2) {
|
|
523
|
+
raf(() => {
|
|
524
|
+
var _a;
|
|
525
|
+
(_a = dom.getInitialFocusEl(ctx2)) == null ? void 0 : _a.focus();
|
|
547
526
|
});
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
527
|
+
},
|
|
528
|
+
focusTriggerIfNeeded(ctx2) {
|
|
529
|
+
if (!ctx2.focusTriggerOnClose)
|
|
530
|
+
return;
|
|
531
|
+
raf(() => {
|
|
532
|
+
var _a;
|
|
533
|
+
return (_a = dom.getTriggerEl(ctx2)) == null ? void 0 : _a.focus();
|
|
534
|
+
});
|
|
535
|
+
},
|
|
536
|
+
focusFirstTabbableElement(ctx2, evt) {
|
|
552
537
|
var _a;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
if (!ctx2.focusTriggerOnClose)
|
|
558
|
-
return;
|
|
559
|
-
raf(() => {
|
|
538
|
+
evt.preventDefault();
|
|
539
|
+
(_a = dom.getFirstTabbableEl(ctx2)) == null ? void 0 : _a.focus();
|
|
540
|
+
},
|
|
541
|
+
invokeOnOpen(ctx2, evt) {
|
|
560
542
|
var _a;
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
let tabbables = dom.getDocTabbableEls(ctx2);
|
|
590
|
-
let elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
591
|
-
if (elementAfterTrigger === content) {
|
|
592
|
-
tabbables = tabbables.filter((el) => !contains(content, el));
|
|
593
|
-
elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
543
|
+
if (evt.type !== "SETUP") {
|
|
544
|
+
(_a = ctx2.onOpenChange) == null ? void 0 : _a.call(ctx2, true);
|
|
545
|
+
}
|
|
546
|
+
},
|
|
547
|
+
invokeOnClose(ctx2, evt) {
|
|
548
|
+
var _a;
|
|
549
|
+
if (evt.type !== "SETUP") {
|
|
550
|
+
(_a = ctx2.onOpenChange) == null ? void 0 : _a.call(ctx2, false);
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
focusNextTabbableElementAfterTrigger(ctx2, evt) {
|
|
554
|
+
const content = dom.getContentEl(ctx2);
|
|
555
|
+
const button = dom.getTriggerEl(ctx2);
|
|
556
|
+
if (!content || !button)
|
|
557
|
+
return;
|
|
558
|
+
const lastTabbable = dom.getLastTabbableEl(ctx2);
|
|
559
|
+
if (lastTabbable !== dom.getActiveEl(ctx2))
|
|
560
|
+
return;
|
|
561
|
+
let tabbables = dom.getDocTabbableEls(ctx2);
|
|
562
|
+
let elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
563
|
+
if (elementAfterTrigger === content) {
|
|
564
|
+
tabbables = tabbables.filter((el) => !contains(content, el));
|
|
565
|
+
elementAfterTrigger = next(tabbables, tabbables.indexOf(button), { loop: false });
|
|
566
|
+
}
|
|
567
|
+
if (!elementAfterTrigger || elementAfterTrigger === button)
|
|
568
|
+
return;
|
|
569
|
+
evt.preventDefault();
|
|
570
|
+
raf(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
|
|
594
571
|
}
|
|
595
|
-
if (!elementAfterTrigger || elementAfterTrigger === button)
|
|
596
|
-
return;
|
|
597
|
-
evt.preventDefault();
|
|
598
|
-
raf(() => elementAfterTrigger == null ? void 0 : elementAfterTrigger.focus());
|
|
599
572
|
}
|
|
600
573
|
}
|
|
601
|
-
|
|
574
|
+
);
|
|
602
575
|
}
|
|
603
576
|
export {
|
|
604
577
|
connect,
|