@dialpad/dialtone-vue 3.73.0 → 3.73.2

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.
@@ -0,0 +1,975 @@
1
+ import { _ as C, D as w, b as S, W as k, h as L, d as x, g as O, X as F, Y as B, Z as H } from "./index-a257a50a.js";
2
+ import { resolveComponent as d, openBlock as r, createBlock as a, withKeys as p, withModifiers as v, withCtx as u, createVNode as g, createElementBlock as E, normalizeClass as h, renderSlot as y, createCommentVNode as f, mergeProps as A, Teleport as I, createElementVNode as b, resolveDynamicComponent as D, toHandlers as R } from "vue";
3
+ const V = {
4
+ props: {
5
+ /**
6
+ * If true, a hidden close button is included for screen readers
7
+ * @values true, false
8
+ */
9
+ visuallyHiddenClose: {
10
+ type: Boolean,
11
+ default: !1
12
+ },
13
+ /**
14
+ * Label for the visually hidden close button
15
+ * Required if visuallyHiddenClose is set to `true`
16
+ */
17
+ visuallyHiddenCloseLabel: {
18
+ type: String,
19
+ default: null
20
+ }
21
+ },
22
+ watch: {
23
+ $props: {
24
+ immediate: !0,
25
+ deep: !0,
26
+ handler() {
27
+ this.validateVisuallyHiddenCloseProps();
28
+ }
29
+ }
30
+ },
31
+ computed: {
32
+ showVisuallyHiddenClose() {
33
+ return this.visuallyHiddenClose && this.visuallyHiddenCloseLabel != null;
34
+ }
35
+ },
36
+ methods: {
37
+ validateVisuallyHiddenCloseProps() {
38
+ this.visuallyHiddenClose && !this.visuallyHiddenCloseLabel && console.error(`If visuallyHiddenClose prop is true, the component includes
39
+ a visually hidden close button and you must set the visuallyHiddenCloseLabel prop.`);
40
+ }
41
+ }
42
+ }, N = {
43
+ name: "SrOnlyCloseButton",
44
+ components: {
45
+ DtIcon: w,
46
+ DtButton: S
47
+ },
48
+ props: {
49
+ /**
50
+ * Label for the visually hidden close button
51
+ * Required if visuallyHiddenClose is set to `true`
52
+ */
53
+ visuallyHiddenCloseLabel: {
54
+ type: String,
55
+ default: null
56
+ }
57
+ },
58
+ emits: ["close"],
59
+ methods: {
60
+ close() {
61
+ this.$emit("close");
62
+ }
63
+ }
64
+ };
65
+ function K(e, t, o, s, i, n) {
66
+ const c = d("dt-icon"), m = d("dt-button");
67
+ return r(), a(m, {
68
+ id: "sr-only-close-button",
69
+ "data-qa": "dt-sr-only-close-button",
70
+ class: "d-vi-visible-sr",
71
+ "aria-label": o.visuallyHiddenCloseLabel,
72
+ onClick: n.close,
73
+ onKeydown: p(v(n.close, ["prevent", "stop"]), ["space"])
74
+ }, {
75
+ default: u(() => [
76
+ g(c, { name: "close" })
77
+ ]),
78
+ _: 1
79
+ }, 8, ["aria-label", "onClick", "onKeydown"]);
80
+ }
81
+ const q = /* @__PURE__ */ C(N, [["render", K]]), T = ':not(:disabled):not([aria-disabled="true"]):not([role="presentation"])', W = `${T}:not([tabindex="-1"])`, z = "button,[href],input,select,textarea,details,[tabindex]", M = {
82
+ methods: {
83
+ /**
84
+ * get the first focusable element in your component, includes tabindex="-1".
85
+ * @param {object} el - optional - ref of dom element to trap focus on.
86
+ * will default to the root node of the vue component
87
+ */
88
+ async getFirstFocusableElement(e) {
89
+ await this.$nextTick();
90
+ const t = this._getFocusableElements(e, !0);
91
+ return this._getFirstFocusElement(t);
92
+ },
93
+ /**
94
+ * set focus to the first focusable element in your component, includes tabindex="-1".
95
+ * @param {object} el - optional - ref of dom element to trap focus on.
96
+ * will default to the root node of the vue component
97
+ */
98
+ async focusFirstElement(e) {
99
+ const t = await this.getFirstFocusableElement(e);
100
+ t == null || t.focus({ preventScroll: !0 });
101
+ },
102
+ /**
103
+ * internal use only.
104
+ *
105
+ * @param focusableElements - list of focusable elements
106
+ * @returns {*} - first DOM element that is focusable.
107
+ * @private
108
+ */
109
+ _getFirstFocusElement(e) {
110
+ if (!e.length)
111
+ return;
112
+ let t = e[0];
113
+ return t.matches('[type="radio"]:not(:checked)') && (t = e.find((o) => o.checked && o.name === t.name) || t), t;
114
+ },
115
+ /**
116
+ * internal use only.
117
+ *
118
+ * gets all the focusable elements within the component
119
+ * and sets the first and last of those elements.
120
+ *
121
+ * @param {object} el - the root dom element to find focusable elements in.
122
+ * @param {bool} includeNegativeTabIndex - will include tabindex="-1" in the list of focusable elements.
123
+ */
124
+ _getFocusableElements(e = this.$el, t = !1) {
125
+ return e ? [...e.querySelectorAll(z)].filter((s) => {
126
+ const i = window.getComputedStyle(s);
127
+ return i.getPropertyValue("display") !== "none" && i.getPropertyValue("visibility") !== "hidden" && s.matches(t ? T : W);
128
+ }) : [];
129
+ },
130
+ /**
131
+ * tabs to the next element contained within your component, does not include tabindex="-1".
132
+ * @param {object} e - keypress event
133
+ * @param {object} el - optional - ref of dom element to trap focus on.
134
+ * will default to the root node of the vue component
135
+ */
136
+ focusTrappedTabPress(e, t) {
137
+ if (!(e.key === "Tab"))
138
+ return;
139
+ const s = this._getFocusableElements(t);
140
+ if (!s.length) {
141
+ e.preventDefault();
142
+ return;
143
+ }
144
+ const i = this._getFirstFocusElement(s), n = s[s.length - 1];
145
+ e.shiftKey ? document.activeElement === i && (n.focus(), e.preventDefault()) : document.activeElement === n && (i.focus(), e.preventDefault());
146
+ }
147
+ }
148
+ }, P = {
149
+ none: void 0,
150
+ small: "d-p4",
151
+ medium: "d-p8",
152
+ large: "d-p16"
153
+ }, j = {
154
+ none: void 0,
155
+ small: "d-pl4",
156
+ medium: "d-pl8",
157
+ large: "d-pl16"
158
+ }, G = ["dialog", "menu", "listbox", "tree", "grid"], U = ["", "anchor"], Y = ["none", "dialog", "first"], Z = ["parent", "body"], X = [
159
+ ...k
160
+ ], $ = {
161
+ name: "PopoverHeaderFooter",
162
+ components: {
163
+ DtButton: S,
164
+ DtIcon: w
165
+ },
166
+ props: {
167
+ // eslint-disable-next-line vue/require-default-prop
168
+ type: {
169
+ type: String,
170
+ validator: function(e) {
171
+ return ["header", "footer"].includes(e);
172
+ }
173
+ },
174
+ /**
175
+ * Additional class name for the content wrapper element.
176
+ */
177
+ contentClass: {
178
+ type: [String, Array, Object],
179
+ default: ""
180
+ },
181
+ /**
182
+ * Determines visibility for close button
183
+ * @values true, false
184
+ */
185
+ showCloseButton: {
186
+ type: Boolean,
187
+ default: !1
188
+ },
189
+ /**
190
+ * A set of props to be passed into the popover's header close button.
191
+ * Requires an 'ariaLabel' property.
192
+ */
193
+ closeButtonProps: {
194
+ type: Object,
195
+ default: () => {
196
+ }
197
+ }
198
+ },
199
+ emits: [
200
+ /**
201
+ * Emitted when popover is closed
202
+ *
203
+ * @event close
204
+ * @type { Boolean }
205
+ */
206
+ "close"
207
+ ],
208
+ data() {
209
+ return {
210
+ hasSlotContent: L
211
+ };
212
+ },
213
+ methods: {
214
+ focusCloseButton() {
215
+ var t;
216
+ const e = (t = this.$refs["popover__close-button"]) == null ? void 0 : t.$el;
217
+ e == null || e.focus();
218
+ }
219
+ }
220
+ };
221
+ function J(e, t, o, s, i, n) {
222
+ const c = d("dt-icon"), m = d("dt-button");
223
+ return r(), E("div", {
224
+ "data-qa": "dt-popover-header-footer",
225
+ class: h({
226
+ "d-popover__header": o.type === "header",
227
+ "d-popover__footer": o.type === "footer"
228
+ })
229
+ }, [
230
+ i.hasSlotContent(e.$slots.content) ? (r(), E("div", {
231
+ key: 0,
232
+ "data-qa": "dt-popover-header-footer-content",
233
+ class: h(["d-to-ellipsis", "d-w100p", o.contentClass])
234
+ }, [
235
+ y(e.$slots, "content")
236
+ ], 2)) : f("", !0),
237
+ o.showCloseButton ? (r(), a(m, A({
238
+ key: 1,
239
+ ref: "popover__close-button",
240
+ "data-qa": "dt-popover-close",
241
+ class: "d-p6 d-mr6 d-bc-transparent",
242
+ importance: "outlined",
243
+ kind: "muted",
244
+ circle: ""
245
+ }, o.closeButtonProps, {
246
+ onClick: t[0] || (t[0] = (_) => e.$emit("close"))
247
+ }), {
248
+ icon: u(() => [
249
+ g(c, {
250
+ name: "close",
251
+ size: "300"
252
+ })
253
+ ]),
254
+ _: 1
255
+ }, 16)) : f("", !0)
256
+ ], 2);
257
+ }
258
+ const Q = /* @__PURE__ */ C($, [["render", J]]);
259
+ const ee = {
260
+ name: "DtPopover",
261
+ /********************
262
+ * CHILD COMPONENTS *
263
+ ********************/
264
+ components: {
265
+ SrOnlyCloseButton: q,
266
+ DtLazyShow: x,
267
+ PopoverHeaderFooter: Q
268
+ },
269
+ mixins: [M, V],
270
+ props: {
271
+ /**
272
+ * Controls whether the popover is shown. Leaving this null will have the popover trigger on click by default.
273
+ * If you set this value, the default trigger behavior will be disabled, and you can control it as you need.
274
+ * Supports v-model
275
+ * @values null, true, false
276
+ */
277
+ open: {
278
+ type: Boolean,
279
+ default: null
280
+ },
281
+ /**
282
+ * Opens the popover on right click (context menu). If you set this value to `true`,
283
+ * the default trigger behavior will be disabled.
284
+ * @values true, false
285
+ */
286
+ openOnContext: {
287
+ type: Boolean,
288
+ default: !1
289
+ },
290
+ /**
291
+ * Element type (tag name) of the root element of the component.
292
+ */
293
+ elementType: {
294
+ type: String,
295
+ default: "div"
296
+ },
297
+ /**
298
+ * Named transition when the content display is toggled.
299
+ * @see DtLazyShow
300
+ */
301
+ transition: {
302
+ type: String,
303
+ default: "fade"
304
+ },
305
+ /**
306
+ * ARIA role for the content of the popover. Defaults to "dialog".
307
+ * <a class="d-link" href="https://www.w3.org/TR/wai-aria/#aria-haspopup" target="_blank">aria-haspopup</a>
308
+ */
309
+ role: {
310
+ type: String,
311
+ default: "dialog",
312
+ validator: (e) => G.includes(e)
313
+ },
314
+ /**
315
+ * ID of the element that serves as the label for the popover content.
316
+ * Defaults to the "anchor" element; this exists to provide a different
317
+ * ID of the label element if, for example, the anchor slot contains
318
+ * other items that do not serve as a label. You should provide this
319
+ * or ariaLabel, but not both.
320
+ */
321
+ ariaLabelledby: {
322
+ type: String,
323
+ default: null
324
+ },
325
+ /**
326
+ * Descriptive label for the popover content. You should provide this
327
+ * or ariaLabelledby, but not both.
328
+ */
329
+ ariaLabel: {
330
+ type: String,
331
+ default: null
332
+ },
333
+ /**
334
+ * A set of props to be passed into the popover's header close button.
335
+ * Requires an 'ariaLabel' property, when the header popover is visible
336
+ */
337
+ closeButtonProps: {
338
+ type: Object,
339
+ default: () => ({})
340
+ },
341
+ /**
342
+ * Padding size class for the popover content.
343
+ * @values none, small, medium, large
344
+ */
345
+ padding: {
346
+ type: String,
347
+ default: "large",
348
+ validator: (e) => Object.keys(P).some((t) => t === e)
349
+ },
350
+ /**
351
+ * Additional class name for the content wrapper element.
352
+ */
353
+ contentClass: {
354
+ type: [String, Array, Object],
355
+ default: ""
356
+ },
357
+ /**
358
+ * Width configuration for the popover content. When its value is 'anchor',
359
+ * the popover content will have the same width as the anchor.
360
+ * @values null, anchor
361
+ */
362
+ contentWidth: {
363
+ type: String,
364
+ default: "",
365
+ validator: (e) => U.includes(e)
366
+ },
367
+ /**
368
+ * Whether to apply transition on initial render in the content lazy show component.
369
+ */
370
+ contentAppear: {
371
+ type: Boolean,
372
+ default: null
373
+ },
374
+ /**
375
+ * Tabindex value for the content. Passing null, no tabindex attribute will be set.
376
+ */
377
+ contentTabindex: {
378
+ type: Number || null,
379
+ default: -1
380
+ },
381
+ /**
382
+ * External anchor id to use in those cases the anchor can't be provided via the slot.
383
+ * For instance, using the combobox's input as the anchor for the popover.
384
+ */
385
+ externalAnchor: {
386
+ type: String,
387
+ default: ""
388
+ },
389
+ /**
390
+ * The id of the tooltip
391
+ */
392
+ id: {
393
+ type: String,
394
+ default() {
395
+ return O();
396
+ }
397
+ },
398
+ /**
399
+ * Displaces the content box from its anchor element
400
+ * by the specified number of pixels.
401
+ * <a
402
+ * class="d-link"
403
+ * href="https://atomiks.github.io/tippyjs/v6/all-props/#offset"
404
+ * target="_blank"
405
+ * >
406
+ * Tippy.js docs
407
+ * </a>
408
+ */
409
+ offset: {
410
+ type: Array,
411
+ default: () => [0, 4]
412
+ },
413
+ /**
414
+ * Determines if the popover hides upon clicking the
415
+ * anchor or outside the content box.
416
+ * @values true, false
417
+ */
418
+ hideOnClick: {
419
+ type: Boolean,
420
+ default: !0
421
+ },
422
+ /**
423
+ * Determines modal state. If enabled popover has a modal overlay
424
+ * preventing interaction with elements below it, but it is invisible.
425
+ * @values true, false
426
+ */
427
+ modal: {
428
+ type: Boolean,
429
+ default: !0
430
+ },
431
+ /**
432
+ * If the popover does not fit in the direction described by "placement",
433
+ * it will attempt to change its direction to the "fallbackPlacements".
434
+ * <a
435
+ * class="d-link"
436
+ * href="https://popper.js.org/docs/v2/modifiers/flip/#fallbackplacements"
437
+ * target="_blank"
438
+ * >
439
+ * Popper.js docs
440
+ * </a>
441
+ * */
442
+ fallbackPlacements: {
443
+ type: Array,
444
+ default: () => ["auto"]
445
+ },
446
+ /**
447
+ * The direction the popover displays relative to the anchor.
448
+ * <a
449
+ * class="d-link"
450
+ * href="https://atomiks.github.io/tippyjs/v6/all-props/#placement"
451
+ * target="_blank"
452
+ * >
453
+ * Tippy.js docs
454
+ * </a>
455
+ * @values top, top-start, top-end,
456
+ * right, right-start, right-end,
457
+ * left, left-start, left-end,
458
+ * bottom, bottom-start, bottom-end,
459
+ * auto, auto-start, auto-end
460
+ */
461
+ placement: {
462
+ type: String,
463
+ default: "bottom-end"
464
+ },
465
+ /**
466
+ * If set to false the dialog will display over top of the anchor when there is insufficient space.
467
+ * If set to true it will never move from its position relative to the anchor and will clip instead.
468
+ * <a
469
+ * class="d-link"
470
+ * href="https://popper.js.org/docs/v2/modifiers/prevent-overflow/#tether"
471
+ * target="_blank"
472
+ * >
473
+ * Popper.js docs
474
+ * </a>
475
+ * @values true, false
476
+ */
477
+ tether: {
478
+ type: Boolean,
479
+ default: !0
480
+ },
481
+ /**
482
+ * If the popover sticks to the anchor. This is usually not needed, but can be needed
483
+ * if the reference element's position is animating, or to automatically update the popover
484
+ * position in those cases the DOM layout changes the reference element's position.
485
+ * `true` enables it, `reference` only checks the "reference" rect for changes and `popper` only
486
+ * checks the "popper" rect for changes.
487
+ * <a
488
+ * class="d-link"
489
+ * href="https://atomiks.github.io/tippyjs/v6/all-props/#sticky"
490
+ * target="_blank"
491
+ * >
492
+ * Tippy.js docs
493
+ * </a>
494
+ * @values true, false, reference, popper
495
+ */
496
+ sticky: {
497
+ type: [Boolean, String],
498
+ default: !1,
499
+ validator: (e) => X.includes(e)
500
+ },
501
+ /**
502
+ * Determines maximum height for the popover before overflow.
503
+ * Possible units rem|px|em
504
+ */
505
+ maxHeight: {
506
+ type: String,
507
+ default: ""
508
+ },
509
+ /**
510
+ * Determines maximum width for the popover before overflow.
511
+ * Possible units rem|px|%|em
512
+ */
513
+ maxWidth: {
514
+ type: String,
515
+ default: ""
516
+ },
517
+ /**
518
+ * Determines visibility for close button
519
+ * @values true, false
520
+ */
521
+ showCloseButton: {
522
+ type: Boolean,
523
+ default: !1
524
+ },
525
+ /**
526
+ * Additional class name for the header content wrapper element.
527
+ */
528
+ headerClass: {
529
+ type: [String, Array, Object],
530
+ default: ""
531
+ },
532
+ /**
533
+ * Additional class name for the footer content wrapper element.
534
+ */
535
+ footerClass: {
536
+ type: [String, Array, Object],
537
+ default: ""
538
+ },
539
+ /**
540
+ * Additional class name for the dialog element.
541
+ */
542
+ dialogClass: {
543
+ type: [String, Array, Object],
544
+ default: ""
545
+ },
546
+ /**
547
+ * The element that is focused when the popover is opened. This can be an
548
+ * HTMLElement within the popover, a string starting with '#' which will
549
+ * find the element by ID. 'first' which will automatically focus
550
+ * the first element, or 'dialog' which will focus the dialog window itself.
551
+ * If the dialog is modal this prop cannot be 'none'.
552
+ * @values none, dialog, first
553
+ */
554
+ initialFocusElement: {
555
+ type: [String, HTMLElement],
556
+ default: "first",
557
+ validator: (e) => Y.includes(e) || e instanceof HTMLElement || e.startsWith("#")
558
+ },
559
+ /**
560
+ * If the popover should open pressing up or down arrow key on the anchor element.
561
+ * This can be set when not passing open prop.
562
+ * @values true, false
563
+ */
564
+ openWithArrowKeys: {
565
+ type: Boolean,
566
+ default: !1
567
+ },
568
+ /**
569
+ * Sets the element to which the popover is going to append to.
570
+ * 'body' will append to the nearest body (supports shadow DOM).
571
+ * @values 'body', 'parent', HTMLElement,
572
+ */
573
+ appendTo: {
574
+ type: [HTMLElement, String],
575
+ default: "body",
576
+ validator: (e) => Z.includes(e) || e instanceof HTMLElement
577
+ }
578
+ },
579
+ emits: [
580
+ /**
581
+ * Native keydown event
582
+ *
583
+ * @event keydown
584
+ * @type {KeyboardEvent}
585
+ */
586
+ "keydown",
587
+ /**
588
+ * Event fired to sync the open prop with the parent component
589
+ * @event update:open
590
+ */
591
+ "update:open",
592
+ /**
593
+ * Emitted when popover is shown or hidden
594
+ *
595
+ * @event opened
596
+ * @type {Boolean | Array}
597
+ */
598
+ "opened"
599
+ ],
600
+ data() {
601
+ return {
602
+ POPOVER_PADDING_CLASSES: P,
603
+ POPOVER_HEADER_FOOTER_PADDING_CLASSES: j,
604
+ intersectionObserver: null,
605
+ isOutsideViewport: !1,
606
+ isOpen: !1,
607
+ toAppear: !1,
608
+ anchorEl: null,
609
+ popoverContentEl: null,
610
+ hasSlotContent: L
611
+ };
612
+ },
613
+ computed: {
614
+ popoverListeners() {
615
+ return {
616
+ keydown: (e) => {
617
+ this.onKeydown(e);
618
+ },
619
+ "after-leave": (e) => {
620
+ this.onLeaveTransitionComplete();
621
+ },
622
+ "after-enter": (e) => {
623
+ this.onEnterTransitionComplete();
624
+ }
625
+ };
626
+ },
627
+ calculatedMaxHeight() {
628
+ return this.isOutsideViewport && this.modal ? "calc(100vh - var(--space-300))" : this.maxHeight;
629
+ },
630
+ labelledBy() {
631
+ return this.ariaLabelledby || !this.ariaLabel && O("DtPopover__anchor");
632
+ }
633
+ },
634
+ watch: {
635
+ $props: {
636
+ immediate: !0,
637
+ deep: !0,
638
+ handler() {
639
+ this.validateProps();
640
+ }
641
+ },
642
+ modal(e) {
643
+ var t;
644
+ (t = this.tip) == null || t.setProps({
645
+ zIndex: e ? 650 : this.calculateAnchorZindex()
646
+ });
647
+ },
648
+ offset(e) {
649
+ var t;
650
+ (t = this.tip) == null || t.setProps({
651
+ offset: e
652
+ });
653
+ },
654
+ sticky(e) {
655
+ var t;
656
+ (t = this.tip) == null || t.setProps({
657
+ sticky: e
658
+ });
659
+ },
660
+ fallbackPlacements() {
661
+ var e;
662
+ (e = this.tip) == null || e.setProps({
663
+ popperOptions: this.popperOptions()
664
+ });
665
+ },
666
+ tether() {
667
+ var e;
668
+ (e = this.tip) == null || e.setProps({
669
+ popperOptions: this.popperOptions()
670
+ });
671
+ },
672
+ placement(e) {
673
+ var t;
674
+ (t = this.tip) == null || t.setProps({
675
+ placement: e
676
+ });
677
+ },
678
+ open: {
679
+ handler: function(e) {
680
+ e !== null && (this.isOpen = e), e === !0 && (this.toAppear = !0);
681
+ },
682
+ immediate: !0
683
+ },
684
+ contentAppear: {
685
+ handler: function(e) {
686
+ e !== null && (this.toAppear = e);
687
+ }
688
+ },
689
+ isOpen(e, t) {
690
+ e ? (this.initTippyInstance(), this.tip.show()) : !e && t !== e && (this.removeEventListeners(), this.tip.hide());
691
+ }
692
+ },
693
+ mounted() {
694
+ const e = this.externalAnchor ? this.$refs.anchor.getRootNode().querySelector(`#${this.externalAnchor}`) : null;
695
+ this.anchorEl = e ?? this.$refs.anchor.children[0], this.popoverContentEl = this.$refs.content.$el, this.isOpen && (this.initTippyInstance(), this.tip.show()), this.intersectionObserver = new IntersectionObserver(this.hasIntersectedViewport), this.intersectionObserver.observe(this.popoverContentEl);
696
+ },
697
+ beforeUnmount() {
698
+ var e;
699
+ (e = this.tip) == null || e.destroy(), this.intersectionObserver.disconnect(), this.removeReferences(), this.removeEventListeners();
700
+ },
701
+ /******************
702
+ * METHODS *
703
+ ******************/
704
+ methods: {
705
+ hasIntersectedViewport(e) {
706
+ var s;
707
+ const t = (s = e == null ? void 0 : e[0]) == null ? void 0 : s.target;
708
+ if (!t)
709
+ return;
710
+ const o = F(t);
711
+ this.isOutsideViewport = o.bottom || o.top;
712
+ },
713
+ popperOptions() {
714
+ return B({
715
+ fallbackPlacements: this.fallbackPlacements,
716
+ tether: this.tether,
717
+ hasHideModifierEnabled: !0
718
+ });
719
+ },
720
+ validateProps() {
721
+ this.modal && this.initialFocusElement === "none" && console.error('If the popover is modal you must set the initialFocusElement prop. Possible values: "dialog", "first", HTMLElement');
722
+ },
723
+ calculateAnchorZindex() {
724
+ var e;
725
+ return this.$el.getRootNode().querySelector('.d-modal[aria-hidden="false"], .d-modal--transparent[aria-hidden="false"]') || // Special case because we don't have any dialtone drawer component yet. Render at 650 when
726
+ // anchor of popover is within a drawer.
727
+ (e = this.anchorEl) != null && e.closest(".d-zi-drawer") ? 650 : 300;
728
+ },
729
+ defaultToggleOpen(e) {
730
+ var t, o, s;
731
+ if (!this.openOnContext && (this.open === null || this.open === void 0)) {
732
+ if (!((t = this.anchorEl) != null && t.contains(e.target)) && !((o = this.anchorEl) != null && o.isEqualNode(e.target)) || (s = this.anchorEl) != null && s.disabled)
733
+ return;
734
+ this.toggleOpen();
735
+ }
736
+ },
737
+ async onContext(e) {
738
+ this.openOnContext && (e.preventDefault(), this.isOpen = !0, await this.$nextTick(), this.tip.setProps({
739
+ placement: "right-start",
740
+ getReferenceClientRect: () => ({
741
+ width: 0,
742
+ height: 0,
743
+ top: e.clientY,
744
+ bottom: e.clientY,
745
+ left: e.clientX,
746
+ right: e.clientX
747
+ })
748
+ }));
749
+ },
750
+ toggleOpen() {
751
+ this.isOpen = !this.isOpen;
752
+ },
753
+ onArrowKeyPress(e) {
754
+ var t;
755
+ this.open === null && (this.openWithArrowKeys && ((t = this.anchorEl) != null && t.contains(e.target)) && (this.isOpen || (this.isOpen = !0)), this.$emit("keydown", e));
756
+ },
757
+ addEventListeners() {
758
+ window.addEventListener("dt-popover-close", this.closePopover), this.contentWidth === "anchor" && window.addEventListener("resize", this.onResize);
759
+ },
760
+ removeEventListeners() {
761
+ window.removeEventListener("dt-popover-close", this.closePopover), this.contentWidth === "anchor" && window.removeEventListener("resize", this.onResize);
762
+ },
763
+ closePopover() {
764
+ this.isOpen = !1;
765
+ },
766
+ /*
767
+ * Prevents scrolling outside of the currently opened modal popover by:
768
+ * - when anchor is not within another popover: setting the body to overflow: hidden
769
+ * - when anchor is within another popover: set the popover dialog container to it's non-modal z-index
770
+ * since it is no longer the active modal. This puts it underneath the overlay and prevents scrolling.
771
+ **/
772
+ preventScrolling() {
773
+ var e;
774
+ if (this.modal) {
775
+ const t = (e = this.anchorEl) == null ? void 0 : e.closest("body, .tippy-box");
776
+ t.tagName.toLowerCase() === "body" ? (t.classList.add("d-of-hidden"), this.tip.setProps({ offset: this.offset })) : t.classList.add("d-zi-popover");
777
+ }
778
+ },
779
+ /*
780
+ * Resets the prevent scrolling properties set in preventScrolling() back to normal.
781
+ **/
782
+ enableScrolling() {
783
+ var t, o;
784
+ const e = (t = this.anchorEl) == null ? void 0 : t.closest("body, .tippy-box");
785
+ e && (((o = e.tagName) == null ? void 0 : o.toLowerCase()) === "body" ? (e.classList.remove("d-of-hidden"), this.tip.setProps({ offset: this.offset })) : e.classList.remove("d-zi-popover"));
786
+ },
787
+ removeReferences() {
788
+ this.anchorEl = null, this.popoverContentEl = null, this.tip = null;
789
+ },
790
+ async onShow() {
791
+ this.contentWidth === "anchor" && await this.setPopoverContentAnchorWidth(), this.contentWidth === null && (this.popoverContentEl.style.width = "auto"), this.addEventListeners();
792
+ },
793
+ async onLeaveTransitionComplete() {
794
+ var e;
795
+ this.modal && (await this.focusFirstElement(this.$refs.anchor), await this.$nextTick(), this.enableScrolling()), (e = this.tip) == null || e.unmount(), this.$emit("opened", !1), this.open !== null && this.$emit("update:open", !1);
796
+ },
797
+ async onEnterTransitionComplete() {
798
+ this.focusInitialElement(), await this.$nextTick(), this.preventScrolling(), this.$emit("opened", !0, this.$refs.popover__content), this.open !== null && this.$emit("update:open", !0);
799
+ },
800
+ focusInitialElement() {
801
+ this.initialFocusElement === "dialog" && this.$refs.content.$el.focus(), this.initialFocusElement.startsWith("#") && this.focusInitialElementById(), this.initialFocusElement === "first" && this.focusFirstElementIfNeeded(this.$refs.popover__content), this.initialFocusElement instanceof HTMLElement && this.initialFocusElement.focus();
802
+ },
803
+ focusInitialElementById() {
804
+ var t, o, s;
805
+ const e = (o = (t = this.$refs.content) == null ? void 0 : t.$el) == null ? void 0 : o.querySelector(this.initialFocusElement);
806
+ e ? e.focus() : console.warn('Could not find the element specified in dt-popover prop "initialFocusElement". Defaulting to focusing the dialog.'), e ? e.focus() : (s = this.$refs.content) == null || s.$el.focus();
807
+ },
808
+ onResize() {
809
+ this.closePopover();
810
+ },
811
+ onClickOutside() {
812
+ if (!this.hideOnClick)
813
+ return;
814
+ this.popoverContentEl.querySelector(".d-popover__anchor--opened") || this.closePopover();
815
+ },
816
+ onKeydown(e) {
817
+ e.key === "Tab" && this.modal && this.focusTrappedTabPress(e, this.popoverContentEl), e.key === "Escape" && this.closePopover(), this.$emit("keydown", e);
818
+ },
819
+ async setPopoverContentAnchorWidth() {
820
+ var e;
821
+ await this.$nextTick(), this.popoverContentEl.style.width = `${(e = this.anchorEl) == null ? void 0 : e.clientWidth}px`;
822
+ },
823
+ focusFirstElementIfNeeded(e) {
824
+ var o, s;
825
+ this._getFocusableElements(e, !0).length !== 0 ? this.focusFirstElement(e) : this.showCloseButton ? (o = this.$refs.popover__header) == null || o.focusCloseButton() : (s = this.$refs.content) == null || s.$el.focus();
826
+ },
827
+ initTippyInstance() {
828
+ var e, t;
829
+ this.tip = H(this.anchorEl, {
830
+ popperOptions: this.popperOptions(),
831
+ contentElement: this.popoverContentEl,
832
+ placement: this.placement,
833
+ offset: this.offset,
834
+ sticky: this.sticky,
835
+ appendTo: this.appendTo === "body" ? (t = (e = this.anchorEl) == null ? void 0 : e.getRootNode()) == null ? void 0 : t.querySelector("body") : this.appendTo,
836
+ interactive: !0,
837
+ trigger: "manual",
838
+ // We have to manage hideOnClick functionality manually to handle
839
+ // popover within popover situations.
840
+ hideOnClick: !1,
841
+ zIndex: this.modal ? 650 : this.calculateAnchorZindex(),
842
+ onClickOutside: this.onClickOutside,
843
+ onShow: this.onShow
844
+ });
845
+ }
846
+ }
847
+ }, te = ["aria-hidden"], oe = ["id", "tabindex"];
848
+ function ne(e, t, o, s, i, n) {
849
+ const c = d("popover-header-footer"), m = d("sr-only-close-button"), _ = d("dt-lazy-show");
850
+ return r(), E("div", null, [
851
+ o.modal && i.isOpen ? (r(), a(I, {
852
+ key: 0,
853
+ to: "body"
854
+ }, [
855
+ b("div", {
856
+ class: "d-modal--transparent",
857
+ "aria-hidden": o.modal && i.isOpen ? "false" : "true",
858
+ onClick: t[0] || (t[0] = v(() => {
859
+ }, ["prevent", "stop"]))
860
+ }, null, 8, te)
861
+ ])) : f("", !0),
862
+ (r(), a(D(o.elementType), {
863
+ ref: "popover",
864
+ class: h(["d-popover", { "d-popover__anchor--opened": i.isOpen }]),
865
+ "data-qa": "dt-popover-container"
866
+ }, {
867
+ default: u(() => [
868
+ b("div", {
869
+ id: !o.ariaLabelledby && n.labelledBy,
870
+ ref: "anchor",
871
+ "data-qa": "dt-popover-anchor",
872
+ tabindex: o.openOnContext ? 0 : void 0,
873
+ onClickCapture: t[1] || (t[1] = (...l) => n.defaultToggleOpen && n.defaultToggleOpen(...l)),
874
+ onContextmenu: t[2] || (t[2] = (...l) => n.onContext && n.onContext(...l)),
875
+ onKeydown: [
876
+ t[3] || (t[3] = p(v((...l) => n.onArrowKeyPress && n.onArrowKeyPress(...l), ["prevent"]), ["up"])),
877
+ t[4] || (t[4] = p(v((...l) => n.onArrowKeyPress && n.onArrowKeyPress(...l), ["prevent"]), ["down"])),
878
+ t[6] || (t[6] = p((l) => e.$emit("keydown", l), ["enter"])),
879
+ t[7] || (t[7] = p((l) => e.$emit("keydown", l), ["space"]))
880
+ ],
881
+ onKeydownCapture: t[5] || (t[5] = p((...l) => n.closePopover && n.closePopover(...l), ["escape"]))
882
+ }, [
883
+ y(e.$slots, "anchor", {
884
+ attrs: {
885
+ "aria-expanded": i.isOpen.toString(),
886
+ "aria-controls": o.id,
887
+ "aria-haspopup": o.role
888
+ }
889
+ })
890
+ ], 40, oe),
891
+ g(_, A({
892
+ id: o.id,
893
+ ref: "content",
894
+ role: o.role,
895
+ "data-qa": "dt-popover",
896
+ "aria-hidden": `${!i.isOpen}`,
897
+ "aria-labelledby": n.labelledBy,
898
+ "aria-label": o.ariaLabel,
899
+ "aria-modal": `${!o.modal}`,
900
+ transition: o.transition,
901
+ show: i.isOpen,
902
+ appear: i.toAppear,
903
+ class: ["d-popover__dialog", { "d-popover__dialog--modal": o.modal }, o.dialogClass],
904
+ style: {
905
+ "max-height": n.calculatedMaxHeight,
906
+ "max-width": o.maxWidth
907
+ },
908
+ css: e.$attrs.css,
909
+ tabindex: o.contentTabindex
910
+ }, R(n.popoverListeners)), {
911
+ default: u(() => [
912
+ i.hasSlotContent(e.$slots.headerContent) || o.showCloseButton ? (r(), a(c, {
913
+ key: 0,
914
+ ref: "popover__header",
915
+ class: h(i.POPOVER_HEADER_FOOTER_PADDING_CLASSES[o.padding]),
916
+ "content-class": o.headerClass,
917
+ type: "header",
918
+ "show-close-button": o.showCloseButton,
919
+ "close-button-props": o.closeButtonProps,
920
+ onClose: n.closePopover
921
+ }, {
922
+ content: u(() => [
923
+ y(e.$slots, "headerContent", { close: n.closePopover })
924
+ ]),
925
+ _: 3
926
+ }, 8, ["class", "content-class", "show-close-button", "close-button-props", "onClose"])) : f("", !0),
927
+ b("div", {
928
+ ref: "popover__content",
929
+ "data-qa": "dt-popover-content",
930
+ class: h([
931
+ "d-popover__content",
932
+ i.POPOVER_PADDING_CLASSES[o.padding],
933
+ o.contentClass
934
+ ])
935
+ }, [
936
+ y(e.$slots, "content", { close: n.closePopover })
937
+ ], 2),
938
+ i.hasSlotContent(e.$slots.footerContent) ? (r(), a(c, {
939
+ key: 1,
940
+ ref: "popover__footer",
941
+ type: "footer",
942
+ class: h(i.POPOVER_HEADER_FOOTER_PADDING_CLASSES[o.padding]),
943
+ "content-class": o.footerClass
944
+ }, {
945
+ content: u(() => [
946
+ y(e.$slots, "footerContent", { close: n.closePopover })
947
+ ]),
948
+ _: 3
949
+ }, 8, ["class", "content-class"])) : f("", !0),
950
+ e.showVisuallyHiddenClose ? (r(), a(m, {
951
+ key: 2,
952
+ "visually-hidden-close-label": e.visuallyHiddenCloseLabel,
953
+ onClose: n.closePopover
954
+ }, null, 8, ["visually-hidden-close-label", "onClose"])) : f("", !0)
955
+ ]),
956
+ _: 3
957
+ }, 16, ["id", "role", "aria-hidden", "aria-labelledby", "aria-label", "aria-modal", "transition", "show", "appear", "class", "style", "css", "tabindex"])
958
+ ]),
959
+ _: 3
960
+ }, 8, ["class"]))
961
+ ]);
962
+ }
963
+ const le = /* @__PURE__ */ C(ee, [["render", ne]]);
964
+ export {
965
+ le as D,
966
+ M,
967
+ Z as P,
968
+ q as S,
969
+ V as a,
970
+ U as b,
971
+ P as c,
972
+ j as d,
973
+ G as e,
974
+ Y as f
975
+ };