@aurodesignsystem-dev/auro-formkit 0.0.0-pr593.0
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/CHANGELOG.md +5 -0
- package/LICENSE +201 -0
- package/NOTICE +2 -0
- package/README.md +314 -0
- package/components/bibtemplate/dist/auro-bibtemplate.d.ts +39 -0
- package/components/bibtemplate/dist/headerVersion.d.ts +2 -0
- package/components/bibtemplate/dist/iconVersion.d.ts +2 -0
- package/components/bibtemplate/dist/index.d.ts +2 -0
- package/components/bibtemplate/dist/index.js +709 -0
- package/components/bibtemplate/dist/registered.js +709 -0
- package/components/bibtemplate/dist/styles/color-css.d.ts +2 -0
- package/components/bibtemplate/dist/styles/style-css.d.ts +2 -0
- package/components/bibtemplate/dist/styles/tokens-css.d.ts +2 -0
- package/components/checkbox/README.md +142 -0
- package/components/checkbox/demo/api.html +55 -0
- package/components/checkbox/demo/api.js +17 -0
- package/components/checkbox/demo/api.md +401 -0
- package/components/checkbox/demo/api.min.js +1833 -0
- package/components/checkbox/demo/index.html +51 -0
- package/components/checkbox/demo/index.js +8 -0
- package/components/checkbox/demo/index.md +327 -0
- package/components/checkbox/demo/index.min.js +1808 -0
- package/components/checkbox/demo/readme.html +50 -0
- package/components/checkbox/demo/readme.md +142 -0
- package/components/checkbox/dist/auro-checkbox-group.d.ts +166 -0
- package/components/checkbox/dist/auro-checkbox.d.ts +129 -0
- package/components/checkbox/dist/helptextVersion.d.ts +2 -0
- package/components/checkbox/dist/index.d.ts +3 -0
- package/components/checkbox/dist/index.js +1757 -0
- package/components/checkbox/dist/registered.js +1758 -0
- package/components/checkbox/dist/styles/auro-checkbox-css.d.ts +2 -0
- package/components/checkbox/dist/styles/auro-checkbox-group-css.d.ts +2 -0
- package/components/checkbox/dist/styles/color-css.d.ts +2 -0
- package/components/checkbox/dist/styles/colorGroup-css.d.ts +2 -0
- package/components/checkbox/dist/styles/tokens-css.d.ts +2 -0
- package/components/combobox/README.md +152 -0
- package/components/combobox/demo/api.html +57 -0
- package/components/combobox/demo/api.js +36 -0
- package/components/combobox/demo/api.md +1209 -0
- package/components/combobox/demo/api.min.js +15117 -0
- package/components/combobox/demo/index.html +56 -0
- package/components/combobox/demo/index.js +26 -0
- package/components/combobox/demo/index.md +621 -0
- package/components/combobox/demo/index.min.js +14971 -0
- package/components/combobox/demo/readme.html +50 -0
- package/components/combobox/demo/readme.md +152 -0
- package/components/combobox/dist/auro-combobox.d.ts +384 -0
- package/components/combobox/dist/bibtemplateVersion.d.ts +2 -0
- package/components/combobox/dist/dropdownVersion.d.ts +2 -0
- package/components/combobox/dist/index.d.ts +2 -0
- package/components/combobox/dist/index.js +13554 -0
- package/components/combobox/dist/inputVersion.d.ts +2 -0
- package/components/combobox/dist/registered.js +13556 -0
- package/components/combobox/dist/styles/style-css.d.ts +2 -0
- package/components/counter/README.md +146 -0
- package/components/counter/demo/api.html +54 -0
- package/components/counter/demo/api.js +20 -0
- package/components/counter/demo/api.md +584 -0
- package/components/counter/demo/api.min.js +7111 -0
- package/components/counter/demo/index.html +54 -0
- package/components/counter/demo/index.js +21 -0
- package/components/counter/demo/index.md +244 -0
- package/components/counter/demo/index.min.js +7075 -0
- package/components/counter/demo/readme.html +50 -0
- package/components/counter/demo/readme.md +146 -0
- package/components/counter/dist/auro-counter-button.d.ts +12 -0
- package/components/counter/dist/auro-counter-group.d.ts +235 -0
- package/components/counter/dist/auro-counter-wrapper.d.ts +22 -0
- package/components/counter/dist/auro-counter.d.ts +97 -0
- package/components/counter/dist/bibtemplateVersion.d.ts +2 -0
- package/components/counter/dist/dropdownVersion.d.ts +2 -0
- package/components/counter/dist/iconVersion.d.ts +2 -0
- package/components/counter/dist/index.d.ts +3 -0
- package/components/counter/dist/index.js +7018 -0
- package/components/counter/dist/registered.js +7019 -0
- package/components/counter/dist/styles/color-css.d.ts +2 -0
- package/components/counter/dist/styles/counter-button-color-css.d.ts +2 -0
- package/components/counter/dist/styles/counter-button-css.d.ts +2 -0
- package/components/counter/dist/styles/counter-group-css.d.ts +2 -0
- package/components/counter/dist/styles/counter-wrapper-color-css.d.ts +2 -0
- package/components/counter/dist/styles/counter-wrapper-css.d.ts +2 -0
- package/components/counter/dist/styles/style-css.d.ts +2 -0
- package/components/counter/dist/styles/tokens-css.d.ts +2 -0
- package/components/datepicker/README.md +140 -0
- package/components/datepicker/demo/api.html +57 -0
- package/components/datepicker/demo/api.js +35 -0
- package/components/datepicker/demo/api.md +1479 -0
- package/components/datepicker/demo/api.min.js +24534 -0
- package/components/datepicker/demo/index.html +56 -0
- package/components/datepicker/demo/index.js +19 -0
- package/components/datepicker/demo/index.md +112 -0
- package/components/datepicker/demo/index.min.js +24255 -0
- package/components/datepicker/demo/readme.html +50 -0
- package/components/datepicker/demo/readme.md +140 -0
- package/components/datepicker/dist/auro-calendar-cell.d.ts +163 -0
- package/components/datepicker/dist/auro-calendar-month.d.ts +20 -0
- package/components/datepicker/dist/auro-calendar.d.ts +133 -0
- package/components/datepicker/dist/auro-datepicker.d.ts +466 -0
- package/components/datepicker/dist/bibtemplateVersion.d.ts +2 -0
- package/components/datepicker/dist/buttonVersion.d.ts +2 -0
- package/components/datepicker/dist/dropdownVersion.d.ts +2 -0
- package/components/datepicker/dist/index.d.ts +2 -0
- package/components/datepicker/dist/index.js +24185 -0
- package/components/datepicker/dist/inputVersion.d.ts +2 -0
- package/components/datepicker/dist/popoverVersion.d.ts +2 -0
- package/components/datepicker/dist/registered.js +24185 -0
- package/components/datepicker/dist/styles/color-calendar-css.d.ts +2 -0
- package/components/datepicker/dist/styles/color-cell-css.d.ts +2 -0
- package/components/datepicker/dist/styles/color-css.d.ts +2 -0
- package/components/datepicker/dist/styles/color-month-css.d.ts +2 -0
- package/components/datepicker/dist/styles/style-auro-calendar-cell-css.d.ts +2 -0
- package/components/datepicker/dist/styles/style-auro-calendar-css.d.ts +2 -0
- package/components/datepicker/dist/styles/style-auro-calendar-month-css.d.ts +2 -0
- package/components/datepicker/dist/styles/style-css.d.ts +2 -0
- package/components/datepicker/dist/styles/tokens-css.d.ts +2 -0
- package/components/datepicker/dist/utilities.d.ts +78 -0
- package/components/datepicker/dist/utilitiesCalendar.d.ts +38 -0
- package/components/datepicker/dist/utilitiesCalendarRender.d.ts +50 -0
- package/components/datepicker/dist/vendor/wc-range-datepicker/day.d.ts +5 -0
- package/components/datepicker/dist/vendor/wc-range-datepicker/range-datepicker-calendar.d.ts +60 -0
- package/components/datepicker/dist/vendor/wc-range-datepicker/range-datepicker-cell.d.ts +1 -0
- package/components/datepicker/dist/vendor/wc-range-datepicker/range-datepicker.d.ts +57 -0
- package/components/dropdown/README.md +144 -0
- package/components/dropdown/demo/api.html +57 -0
- package/components/dropdown/demo/api.js +21 -0
- package/components/dropdown/demo/api.md +1434 -0
- package/components/dropdown/demo/api.min.js +3826 -0
- package/components/dropdown/demo/index.html +55 -0
- package/components/dropdown/demo/index.js +19 -0
- package/components/dropdown/demo/index.md +510 -0
- package/components/dropdown/demo/index.min.js +3789 -0
- package/components/dropdown/demo/readme.html +50 -0
- package/components/dropdown/demo/readme.md +144 -0
- package/components/dropdown/dist/auro-dropdown.d.ts +406 -0
- package/components/dropdown/dist/auro-dropdownBib.d.ts +46 -0
- package/components/dropdown/dist/dropdownVersion.d.ts +2 -0
- package/components/dropdown/dist/helptextVersion.d.ts +2 -0
- package/components/dropdown/dist/iconVersion.d.ts +2 -0
- package/components/dropdown/dist/index.d.ts +2 -0
- package/components/dropdown/dist/index.js +3734 -0
- package/components/dropdown/dist/registered.js +3734 -0
- package/components/dropdown/dist/styles/bibColors-css.d.ts +2 -0
- package/components/dropdown/dist/styles/bibStyles-css.d.ts +2 -0
- package/components/dropdown/dist/styles/color-css.d.ts +2 -0
- package/components/dropdown/dist/styles/style-css.d.ts +2 -0
- package/components/dropdown/dist/styles/tokens-css.d.ts +2 -0
- package/components/form/README.md +142 -0
- package/components/form/demo/api.html +49 -0
- package/components/form/demo/api.js +3 -0
- package/components/form/demo/api.md +51 -0
- package/components/form/demo/api.min.js +638 -0
- package/components/form/demo/autocomplete.html +15 -0
- package/components/form/demo/index.html +50 -0
- package/components/form/demo/index.js +4 -0
- package/components/form/demo/index.md +403 -0
- package/components/form/demo/index.min.js +639 -0
- package/components/form/demo/readme.html +50 -0
- package/components/form/demo/readme.md +142 -0
- package/components/form/demo/registerDemoDeps.js +23 -0
- package/components/form/demo/working.html +118 -0
- package/components/form/dist/auro-form.d.ts +223 -0
- package/components/form/dist/index.d.ts +2 -0
- package/components/form/dist/index.js +614 -0
- package/components/form/dist/registered.d.ts +1 -0
- package/components/form/dist/registered.js +614 -0
- package/components/form/dist/styles/style-css.d.ts +2 -0
- package/components/helptext/dist/auro-helptext.d.ts +61 -0
- package/components/helptext/dist/index.d.ts +2 -0
- package/components/helptext/dist/index.js +209 -0
- package/components/helptext/dist/registered.js +209 -0
- package/components/helptext/dist/styles/color-css.d.ts +2 -0
- package/components/helptext/dist/styles/style-css.d.ts +2 -0
- package/components/helptext/dist/styles/tokens-css.d.ts +2 -0
- package/components/input/README.md +135 -0
- package/components/input/demo/api.html +42 -0
- package/components/input/demo/api.js +29 -0
- package/components/input/demo/api.md +1252 -0
- package/components/input/demo/api.min.js +7238 -0
- package/components/input/demo/index.html +43 -0
- package/components/input/demo/index.js +20 -0
- package/components/input/demo/index.md +202 -0
- package/components/input/demo/index.min.js +7157 -0
- package/components/input/demo/readme.html +50 -0
- package/components/input/demo/readme.md +135 -0
- package/components/input/dist/auro-input.d.ts +31 -0
- package/components/input/dist/base-input.d.ts +512 -0
- package/components/input/dist/buttonVersion.d.ts +2 -0
- package/components/input/dist/helptextVersion.d.ts +2 -0
- package/components/input/dist/i18n.d.ts +18 -0
- package/components/input/dist/iconVersion.d.ts +2 -0
- package/components/input/dist/index.d.ts +2 -0
- package/components/input/dist/index.js +7063 -0
- package/components/input/dist/registered.js +7063 -0
- package/components/input/dist/styles/borders-css.d.ts +2 -0
- package/components/input/dist/styles/color-css.d.ts +2 -0
- package/components/input/dist/styles/input-css.d.ts +2 -0
- package/components/input/dist/styles/label-css.d.ts +2 -0
- package/components/input/dist/styles/mixins-css.d.ts +2 -0
- package/components/input/dist/styles/notificationIcons-css.d.ts +2 -0
- package/components/input/dist/styles/style-css.d.ts +2 -0
- package/components/input/dist/styles/tokens-css.d.ts +2 -0
- package/components/input/dist/utilities.d.ts +25 -0
- package/components/menu/README.md +145 -0
- package/components/menu/demo/api.html +55 -0
- package/components/menu/demo/api.js +27 -0
- package/components/menu/demo/api.md +954 -0
- package/components/menu/demo/api.min.js +1538 -0
- package/components/menu/demo/index.html +52 -0
- package/components/menu/demo/index.js +28 -0
- package/components/menu/demo/index.md +61 -0
- package/components/menu/demo/index.min.js +1484 -0
- package/components/menu/demo/readme.html +50 -0
- package/components/menu/demo/readme.md +145 -0
- package/components/menu/dist/auro-menu-utils.d.ts +42 -0
- package/components/menu/dist/auro-menu.d.ts +205 -0
- package/components/menu/dist/auro-menuoption.d.ts +63 -0
- package/components/menu/dist/dropdownVersion.d.ts +2 -0
- package/components/menu/dist/iconVersion.d.ts +2 -0
- package/components/menu/dist/index.d.ts +4 -0
- package/components/menu/dist/index.js +1426 -0
- package/components/menu/dist/registered.js +1427 -0
- package/components/menu/dist/styles/color-menu-css.d.ts +2 -0
- package/components/menu/dist/styles/color-menuoption-css.d.ts +2 -0
- package/components/menu/dist/styles/style-menu-css.d.ts +2 -0
- package/components/menu/dist/styles/style-menuoption-css.d.ts +2 -0
- package/components/menu/dist/styles/tokens-css.d.ts +2 -0
- package/components/radio/README.md +137 -0
- package/components/radio/demo/api.html +53 -0
- package/components/radio/demo/api.js +19 -0
- package/components/radio/demo/api.md +562 -0
- package/components/radio/demo/api.min.js +1944 -0
- package/components/radio/demo/index.html +50 -0
- package/components/radio/demo/index.js +8 -0
- package/components/radio/demo/index.md +150 -0
- package/components/radio/demo/index.min.js +1901 -0
- package/components/radio/demo/readme.html +50 -0
- package/components/radio/demo/readme.md +137 -0
- package/components/radio/dist/auro-radio-group.d.ts +194 -0
- package/components/radio/dist/auro-radio.d.ts +144 -0
- package/components/radio/dist/helptextVersion.d.ts +2 -0
- package/components/radio/dist/index.d.ts +3 -0
- package/components/radio/dist/index.js +1850 -0
- package/components/radio/dist/registered.js +1851 -0
- package/components/radio/dist/styles/auro-radio-group-css.d.ts +2 -0
- package/components/radio/dist/styles/color-css.d.ts +2 -0
- package/components/radio/dist/styles/groupColor-css.d.ts +2 -0
- package/components/radio/dist/styles/style-css.d.ts +2 -0
- package/components/radio/dist/styles/tokens-css.d.ts +2 -0
- package/components/select/README.md +144 -0
- package/components/select/demo/api.html +71 -0
- package/components/select/demo/api.js +35 -0
- package/components/select/demo/api.md +1313 -0
- package/components/select/demo/api.min.js +7763 -0
- package/components/select/demo/index.html +66 -0
- package/components/select/demo/index.js +9 -0
- package/components/select/demo/index.md +815 -0
- package/components/select/demo/index.min.js +7651 -0
- package/components/select/demo/readme.html +50 -0
- package/components/select/demo/readme.md +144 -0
- package/components/select/dist/auro-select.d.ts +359 -0
- package/components/select/dist/bibtemplateVersion.d.ts +2 -0
- package/components/select/dist/dropdownVersion.d.ts +2 -0
- package/components/select/dist/index.d.ts +2 -0
- package/components/select/dist/index.js +6300 -0
- package/components/select/dist/registered.js +6300 -0
- package/components/select/dist/styles/style-css.d.ts +2 -0
- package/package.json +217 -0
- package/packages/build-tools/src/postinstall.mjs +12 -0
|
@@ -0,0 +1,3734 @@
|
|
|
1
|
+
import { unsafeStatic, literal, html as html$1 } from 'lit/static-html.js';
|
|
2
|
+
import { LitElement, css, html } from 'lit';
|
|
3
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
4
|
+
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
5
|
+
|
|
6
|
+
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
7
|
+
// See LICENSE in the project root for license information.
|
|
8
|
+
|
|
9
|
+
// ---------------------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
/* eslint-disable line-comment-position, no-inline-comments, no-confusing-arrow, no-nested-ternary, implicit-arrow-linebreak */
|
|
12
|
+
|
|
13
|
+
let AuroLibraryRuntimeUtils$1 = class AuroLibraryRuntimeUtils {
|
|
14
|
+
|
|
15
|
+
/* eslint-disable jsdoc/require-param */
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* This will register a new custom element with the browser.
|
|
19
|
+
* @param {String} name - The name of the custom element.
|
|
20
|
+
* @param {Object} componentClass - The class to register as a custom element.
|
|
21
|
+
* @returns {void}
|
|
22
|
+
*/
|
|
23
|
+
registerComponent(name, componentClass) {
|
|
24
|
+
if (!customElements.get(name)) {
|
|
25
|
+
customElements.define(name, class extends componentClass {});
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Finds and returns the closest HTML Element based on a selector.
|
|
31
|
+
* @returns {void}
|
|
32
|
+
*/
|
|
33
|
+
closestElement(
|
|
34
|
+
selector, // selector like in .closest()
|
|
35
|
+
base = this, // extra functionality to skip a parent
|
|
36
|
+
__Closest = (el, found = el && el.closest(selector)) =>
|
|
37
|
+
!el || el === document || el === window
|
|
38
|
+
? null // standard .closest() returns null for non-found selectors also
|
|
39
|
+
: found
|
|
40
|
+
? found // found a selector INside this element
|
|
41
|
+
: __Closest(el.getRootNode().host) // recursion!! break out to parent DOM
|
|
42
|
+
) {
|
|
43
|
+
return __Closest(base);
|
|
44
|
+
}
|
|
45
|
+
/* eslint-enable jsdoc/require-param */
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* If the element passed is registered with a different tag name than what is passed in, the tag name is added as an attribute to the element.
|
|
49
|
+
* @param {Object} elem - The element to check.
|
|
50
|
+
* @param {String} tagName - The name of the Auro component to check for or add as an attribute.
|
|
51
|
+
* @returns {void}
|
|
52
|
+
*/
|
|
53
|
+
handleComponentTagRename(elem, tagName) {
|
|
54
|
+
const tag = tagName.toLowerCase();
|
|
55
|
+
const elemTag = elem.tagName.toLowerCase();
|
|
56
|
+
|
|
57
|
+
if (elemTag !== tag) {
|
|
58
|
+
elem.setAttribute(tag, true);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Validates if an element is a specific Auro component.
|
|
64
|
+
* @param {Object} elem - The element to validate.
|
|
65
|
+
* @param {String} tagName - The name of the Auro component to check against.
|
|
66
|
+
* @returns {Boolean} - Returns true if the element is the specified Auro component.
|
|
67
|
+
*/
|
|
68
|
+
elementMatch(elem, tagName) {
|
|
69
|
+
const tag = tagName.toLowerCase();
|
|
70
|
+
const elemTag = elem.tagName.toLowerCase();
|
|
71
|
+
|
|
72
|
+
return elemTag === tag || elem.hasAttribute(tag);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Custom positioning reference element.
|
|
78
|
+
* @see https://floating-ui.com/docs/virtual-elements
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
const sides = ['top', 'right', 'bottom', 'left'];
|
|
82
|
+
const alignments = ['start', 'end'];
|
|
83
|
+
const placements = /*#__PURE__*/sides.reduce((acc, side) => acc.concat(side, side + "-" + alignments[0], side + "-" + alignments[1]), []);
|
|
84
|
+
const min = Math.min;
|
|
85
|
+
const max = Math.max;
|
|
86
|
+
const round = Math.round;
|
|
87
|
+
const floor = Math.floor;
|
|
88
|
+
const createCoords = v => ({
|
|
89
|
+
x: v,
|
|
90
|
+
y: v
|
|
91
|
+
});
|
|
92
|
+
const oppositeSideMap = {
|
|
93
|
+
left: 'right',
|
|
94
|
+
right: 'left',
|
|
95
|
+
bottom: 'top',
|
|
96
|
+
top: 'bottom'
|
|
97
|
+
};
|
|
98
|
+
const oppositeAlignmentMap = {
|
|
99
|
+
start: 'end',
|
|
100
|
+
end: 'start'
|
|
101
|
+
};
|
|
102
|
+
function evaluate(value, param) {
|
|
103
|
+
return typeof value === 'function' ? value(param) : value;
|
|
104
|
+
}
|
|
105
|
+
function getSide(placement) {
|
|
106
|
+
return placement.split('-')[0];
|
|
107
|
+
}
|
|
108
|
+
function getAlignment(placement) {
|
|
109
|
+
return placement.split('-')[1];
|
|
110
|
+
}
|
|
111
|
+
function getOppositeAxis(axis) {
|
|
112
|
+
return axis === 'x' ? 'y' : 'x';
|
|
113
|
+
}
|
|
114
|
+
function getAxisLength(axis) {
|
|
115
|
+
return axis === 'y' ? 'height' : 'width';
|
|
116
|
+
}
|
|
117
|
+
function getSideAxis(placement) {
|
|
118
|
+
return ['top', 'bottom'].includes(getSide(placement)) ? 'y' : 'x';
|
|
119
|
+
}
|
|
120
|
+
function getAlignmentAxis(placement) {
|
|
121
|
+
return getOppositeAxis(getSideAxis(placement));
|
|
122
|
+
}
|
|
123
|
+
function getAlignmentSides(placement, rects, rtl) {
|
|
124
|
+
if (rtl === void 0) {
|
|
125
|
+
rtl = false;
|
|
126
|
+
}
|
|
127
|
+
const alignment = getAlignment(placement);
|
|
128
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
129
|
+
const length = getAxisLength(alignmentAxis);
|
|
130
|
+
let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
|
|
131
|
+
if (rects.reference[length] > rects.floating[length]) {
|
|
132
|
+
mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
|
|
133
|
+
}
|
|
134
|
+
return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
|
|
135
|
+
}
|
|
136
|
+
function getExpandedPlacements(placement) {
|
|
137
|
+
const oppositePlacement = getOppositePlacement(placement);
|
|
138
|
+
return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
|
|
139
|
+
}
|
|
140
|
+
function getOppositeAlignmentPlacement(placement) {
|
|
141
|
+
return placement.replace(/start|end/g, alignment => oppositeAlignmentMap[alignment]);
|
|
142
|
+
}
|
|
143
|
+
function getSideList(side, isStart, rtl) {
|
|
144
|
+
const lr = ['left', 'right'];
|
|
145
|
+
const rl = ['right', 'left'];
|
|
146
|
+
const tb = ['top', 'bottom'];
|
|
147
|
+
const bt = ['bottom', 'top'];
|
|
148
|
+
switch (side) {
|
|
149
|
+
case 'top':
|
|
150
|
+
case 'bottom':
|
|
151
|
+
if (rtl) return isStart ? rl : lr;
|
|
152
|
+
return isStart ? lr : rl;
|
|
153
|
+
case 'left':
|
|
154
|
+
case 'right':
|
|
155
|
+
return isStart ? tb : bt;
|
|
156
|
+
default:
|
|
157
|
+
return [];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
|
|
161
|
+
const alignment = getAlignment(placement);
|
|
162
|
+
let list = getSideList(getSide(placement), direction === 'start', rtl);
|
|
163
|
+
if (alignment) {
|
|
164
|
+
list = list.map(side => side + "-" + alignment);
|
|
165
|
+
if (flipAlignment) {
|
|
166
|
+
list = list.concat(list.map(getOppositeAlignmentPlacement));
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return list;
|
|
170
|
+
}
|
|
171
|
+
function getOppositePlacement(placement) {
|
|
172
|
+
return placement.replace(/left|right|bottom|top/g, side => oppositeSideMap[side]);
|
|
173
|
+
}
|
|
174
|
+
function expandPaddingObject(padding) {
|
|
175
|
+
return {
|
|
176
|
+
top: 0,
|
|
177
|
+
right: 0,
|
|
178
|
+
bottom: 0,
|
|
179
|
+
left: 0,
|
|
180
|
+
...padding
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
function getPaddingObject(padding) {
|
|
184
|
+
return typeof padding !== 'number' ? expandPaddingObject(padding) : {
|
|
185
|
+
top: padding,
|
|
186
|
+
right: padding,
|
|
187
|
+
bottom: padding,
|
|
188
|
+
left: padding
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function rectToClientRect(rect) {
|
|
192
|
+
const {
|
|
193
|
+
x,
|
|
194
|
+
y,
|
|
195
|
+
width,
|
|
196
|
+
height
|
|
197
|
+
} = rect;
|
|
198
|
+
return {
|
|
199
|
+
width,
|
|
200
|
+
height,
|
|
201
|
+
top: y,
|
|
202
|
+
left: x,
|
|
203
|
+
right: x + width,
|
|
204
|
+
bottom: y + height,
|
|
205
|
+
x,
|
|
206
|
+
y
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function computeCoordsFromPlacement(_ref, placement, rtl) {
|
|
211
|
+
let {
|
|
212
|
+
reference,
|
|
213
|
+
floating
|
|
214
|
+
} = _ref;
|
|
215
|
+
const sideAxis = getSideAxis(placement);
|
|
216
|
+
const alignmentAxis = getAlignmentAxis(placement);
|
|
217
|
+
const alignLength = getAxisLength(alignmentAxis);
|
|
218
|
+
const side = getSide(placement);
|
|
219
|
+
const isVertical = sideAxis === 'y';
|
|
220
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
221
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
222
|
+
const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
|
|
223
|
+
let coords;
|
|
224
|
+
switch (side) {
|
|
225
|
+
case 'top':
|
|
226
|
+
coords = {
|
|
227
|
+
x: commonX,
|
|
228
|
+
y: reference.y - floating.height
|
|
229
|
+
};
|
|
230
|
+
break;
|
|
231
|
+
case 'bottom':
|
|
232
|
+
coords = {
|
|
233
|
+
x: commonX,
|
|
234
|
+
y: reference.y + reference.height
|
|
235
|
+
};
|
|
236
|
+
break;
|
|
237
|
+
case 'right':
|
|
238
|
+
coords = {
|
|
239
|
+
x: reference.x + reference.width,
|
|
240
|
+
y: commonY
|
|
241
|
+
};
|
|
242
|
+
break;
|
|
243
|
+
case 'left':
|
|
244
|
+
coords = {
|
|
245
|
+
x: reference.x - floating.width,
|
|
246
|
+
y: commonY
|
|
247
|
+
};
|
|
248
|
+
break;
|
|
249
|
+
default:
|
|
250
|
+
coords = {
|
|
251
|
+
x: reference.x,
|
|
252
|
+
y: reference.y
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
switch (getAlignment(placement)) {
|
|
256
|
+
case 'start':
|
|
257
|
+
coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
|
|
258
|
+
break;
|
|
259
|
+
case 'end':
|
|
260
|
+
coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
return coords;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Computes the `x` and `y` coordinates that will place the floating element
|
|
268
|
+
* next to a given reference element.
|
|
269
|
+
*
|
|
270
|
+
* This export does not have any `platform` interface logic. You will need to
|
|
271
|
+
* write one for the platform you are using Floating UI with.
|
|
272
|
+
*/
|
|
273
|
+
const computePosition$1 = async (reference, floating, config) => {
|
|
274
|
+
const {
|
|
275
|
+
placement = 'bottom',
|
|
276
|
+
strategy = 'absolute',
|
|
277
|
+
middleware = [],
|
|
278
|
+
platform
|
|
279
|
+
} = config;
|
|
280
|
+
const validMiddleware = middleware.filter(Boolean);
|
|
281
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
|
|
282
|
+
let rects = await platform.getElementRects({
|
|
283
|
+
reference,
|
|
284
|
+
floating,
|
|
285
|
+
strategy
|
|
286
|
+
});
|
|
287
|
+
let {
|
|
288
|
+
x,
|
|
289
|
+
y
|
|
290
|
+
} = computeCoordsFromPlacement(rects, placement, rtl);
|
|
291
|
+
let statefulPlacement = placement;
|
|
292
|
+
let middlewareData = {};
|
|
293
|
+
let resetCount = 0;
|
|
294
|
+
for (let i = 0; i < validMiddleware.length; i++) {
|
|
295
|
+
const {
|
|
296
|
+
name,
|
|
297
|
+
fn
|
|
298
|
+
} = validMiddleware[i];
|
|
299
|
+
const {
|
|
300
|
+
x: nextX,
|
|
301
|
+
y: nextY,
|
|
302
|
+
data,
|
|
303
|
+
reset
|
|
304
|
+
} = await fn({
|
|
305
|
+
x,
|
|
306
|
+
y,
|
|
307
|
+
initialPlacement: placement,
|
|
308
|
+
placement: statefulPlacement,
|
|
309
|
+
strategy,
|
|
310
|
+
middlewareData,
|
|
311
|
+
rects,
|
|
312
|
+
platform,
|
|
313
|
+
elements: {
|
|
314
|
+
reference,
|
|
315
|
+
floating
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
x = nextX != null ? nextX : x;
|
|
319
|
+
y = nextY != null ? nextY : y;
|
|
320
|
+
middlewareData = {
|
|
321
|
+
...middlewareData,
|
|
322
|
+
[name]: {
|
|
323
|
+
...middlewareData[name],
|
|
324
|
+
...data
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
if (reset && resetCount <= 50) {
|
|
328
|
+
resetCount++;
|
|
329
|
+
if (typeof reset === 'object') {
|
|
330
|
+
if (reset.placement) {
|
|
331
|
+
statefulPlacement = reset.placement;
|
|
332
|
+
}
|
|
333
|
+
if (reset.rects) {
|
|
334
|
+
rects = reset.rects === true ? await platform.getElementRects({
|
|
335
|
+
reference,
|
|
336
|
+
floating,
|
|
337
|
+
strategy
|
|
338
|
+
}) : reset.rects;
|
|
339
|
+
}
|
|
340
|
+
({
|
|
341
|
+
x,
|
|
342
|
+
y
|
|
343
|
+
} = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
|
|
344
|
+
}
|
|
345
|
+
i = -1;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
return {
|
|
349
|
+
x,
|
|
350
|
+
y,
|
|
351
|
+
placement: statefulPlacement,
|
|
352
|
+
strategy,
|
|
353
|
+
middlewareData
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Resolves with an object of overflow side offsets that determine how much the
|
|
359
|
+
* element is overflowing a given clipping boundary on each side.
|
|
360
|
+
* - positive = overflowing the boundary by that number of pixels
|
|
361
|
+
* - negative = how many pixels left before it will overflow
|
|
362
|
+
* - 0 = lies flush with the boundary
|
|
363
|
+
* @see https://floating-ui.com/docs/detectOverflow
|
|
364
|
+
*/
|
|
365
|
+
async function detectOverflow(state, options) {
|
|
366
|
+
var _await$platform$isEle;
|
|
367
|
+
if (options === void 0) {
|
|
368
|
+
options = {};
|
|
369
|
+
}
|
|
370
|
+
const {
|
|
371
|
+
x,
|
|
372
|
+
y,
|
|
373
|
+
platform,
|
|
374
|
+
rects,
|
|
375
|
+
elements,
|
|
376
|
+
strategy
|
|
377
|
+
} = state;
|
|
378
|
+
const {
|
|
379
|
+
boundary = 'clippingAncestors',
|
|
380
|
+
rootBoundary = 'viewport',
|
|
381
|
+
elementContext = 'floating',
|
|
382
|
+
altBoundary = false,
|
|
383
|
+
padding = 0
|
|
384
|
+
} = evaluate(options, state);
|
|
385
|
+
const paddingObject = getPaddingObject(padding);
|
|
386
|
+
const altContext = elementContext === 'floating' ? 'reference' : 'floating';
|
|
387
|
+
const element = elements[altBoundary ? altContext : elementContext];
|
|
388
|
+
const clippingClientRect = rectToClientRect(await platform.getClippingRect({
|
|
389
|
+
element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
|
|
390
|
+
boundary,
|
|
391
|
+
rootBoundary,
|
|
392
|
+
strategy
|
|
393
|
+
}));
|
|
394
|
+
const rect = elementContext === 'floating' ? {
|
|
395
|
+
x,
|
|
396
|
+
y,
|
|
397
|
+
width: rects.floating.width,
|
|
398
|
+
height: rects.floating.height
|
|
399
|
+
} : rects.reference;
|
|
400
|
+
const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
|
|
401
|
+
const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
|
|
402
|
+
x: 1,
|
|
403
|
+
y: 1
|
|
404
|
+
} : {
|
|
405
|
+
x: 1,
|
|
406
|
+
y: 1
|
|
407
|
+
};
|
|
408
|
+
const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
409
|
+
elements,
|
|
410
|
+
rect,
|
|
411
|
+
offsetParent,
|
|
412
|
+
strategy
|
|
413
|
+
}) : rect);
|
|
414
|
+
return {
|
|
415
|
+
top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
|
|
416
|
+
bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
|
|
417
|
+
left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
|
|
418
|
+
right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function getPlacementList(alignment, autoAlignment, allowedPlacements) {
|
|
423
|
+
const allowedPlacementsSortedByAlignment = alignment ? [...allowedPlacements.filter(placement => getAlignment(placement) === alignment), ...allowedPlacements.filter(placement => getAlignment(placement) !== alignment)] : allowedPlacements.filter(placement => getSide(placement) === placement);
|
|
424
|
+
return allowedPlacementsSortedByAlignment.filter(placement => {
|
|
425
|
+
if (alignment) {
|
|
426
|
+
return getAlignment(placement) === alignment || (autoAlignment ? getOppositeAlignmentPlacement(placement) !== placement : false);
|
|
427
|
+
}
|
|
428
|
+
return true;
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
/**
|
|
432
|
+
* Optimizes the visibility of the floating element by choosing the placement
|
|
433
|
+
* that has the most space available automatically, without needing to specify a
|
|
434
|
+
* preferred placement. Alternative to `flip`.
|
|
435
|
+
* @see https://floating-ui.com/docs/autoPlacement
|
|
436
|
+
*/
|
|
437
|
+
const autoPlacement$1 = function (options) {
|
|
438
|
+
if (options === void 0) {
|
|
439
|
+
options = {};
|
|
440
|
+
}
|
|
441
|
+
return {
|
|
442
|
+
name: 'autoPlacement',
|
|
443
|
+
options,
|
|
444
|
+
async fn(state) {
|
|
445
|
+
var _middlewareData$autoP, _middlewareData$autoP2, _placementsThatFitOnE;
|
|
446
|
+
const {
|
|
447
|
+
rects,
|
|
448
|
+
middlewareData,
|
|
449
|
+
placement,
|
|
450
|
+
platform,
|
|
451
|
+
elements
|
|
452
|
+
} = state;
|
|
453
|
+
const {
|
|
454
|
+
crossAxis = false,
|
|
455
|
+
alignment,
|
|
456
|
+
allowedPlacements = placements,
|
|
457
|
+
autoAlignment = true,
|
|
458
|
+
...detectOverflowOptions
|
|
459
|
+
} = evaluate(options, state);
|
|
460
|
+
const placements$1 = alignment !== undefined || allowedPlacements === placements ? getPlacementList(alignment || null, autoAlignment, allowedPlacements) : allowedPlacements;
|
|
461
|
+
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
462
|
+
const currentIndex = ((_middlewareData$autoP = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP.index) || 0;
|
|
463
|
+
const currentPlacement = placements$1[currentIndex];
|
|
464
|
+
if (currentPlacement == null) {
|
|
465
|
+
return {};
|
|
466
|
+
}
|
|
467
|
+
const alignmentSides = getAlignmentSides(currentPlacement, rects, await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating)));
|
|
468
|
+
|
|
469
|
+
// Make `computeCoords` start from the right place.
|
|
470
|
+
if (placement !== currentPlacement) {
|
|
471
|
+
return {
|
|
472
|
+
reset: {
|
|
473
|
+
placement: placements$1[0]
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
const currentOverflows = [overflow[getSide(currentPlacement)], overflow[alignmentSides[0]], overflow[alignmentSides[1]]];
|
|
478
|
+
const allOverflows = [...(((_middlewareData$autoP2 = middlewareData.autoPlacement) == null ? void 0 : _middlewareData$autoP2.overflows) || []), {
|
|
479
|
+
placement: currentPlacement,
|
|
480
|
+
overflows: currentOverflows
|
|
481
|
+
}];
|
|
482
|
+
const nextPlacement = placements$1[currentIndex + 1];
|
|
483
|
+
|
|
484
|
+
// There are more placements to check.
|
|
485
|
+
if (nextPlacement) {
|
|
486
|
+
return {
|
|
487
|
+
data: {
|
|
488
|
+
index: currentIndex + 1,
|
|
489
|
+
overflows: allOverflows
|
|
490
|
+
},
|
|
491
|
+
reset: {
|
|
492
|
+
placement: nextPlacement
|
|
493
|
+
}
|
|
494
|
+
};
|
|
495
|
+
}
|
|
496
|
+
const placementsSortedByMostSpace = allOverflows.map(d => {
|
|
497
|
+
const alignment = getAlignment(d.placement);
|
|
498
|
+
return [d.placement, alignment && crossAxis ?
|
|
499
|
+
// Check along the mainAxis and main crossAxis side.
|
|
500
|
+
d.overflows.slice(0, 2).reduce((acc, v) => acc + v, 0) :
|
|
501
|
+
// Check only the mainAxis.
|
|
502
|
+
d.overflows[0], d.overflows];
|
|
503
|
+
}).sort((a, b) => a[1] - b[1]);
|
|
504
|
+
const placementsThatFitOnEachSide = placementsSortedByMostSpace.filter(d => d[2].slice(0,
|
|
505
|
+
// Aligned placements should not check their opposite crossAxis
|
|
506
|
+
// side.
|
|
507
|
+
getAlignment(d[0]) ? 2 : 3).every(v => v <= 0));
|
|
508
|
+
const resetPlacement = ((_placementsThatFitOnE = placementsThatFitOnEachSide[0]) == null ? void 0 : _placementsThatFitOnE[0]) || placementsSortedByMostSpace[0][0];
|
|
509
|
+
if (resetPlacement !== placement) {
|
|
510
|
+
return {
|
|
511
|
+
data: {
|
|
512
|
+
index: currentIndex + 1,
|
|
513
|
+
overflows: allOverflows
|
|
514
|
+
},
|
|
515
|
+
reset: {
|
|
516
|
+
placement: resetPlacement
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
}
|
|
520
|
+
return {};
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
/**
|
|
526
|
+
* Optimizes the visibility of the floating element by flipping the `placement`
|
|
527
|
+
* in order to keep it in view when the preferred placement(s) will overflow the
|
|
528
|
+
* clipping boundary. Alternative to `autoPlacement`.
|
|
529
|
+
* @see https://floating-ui.com/docs/flip
|
|
530
|
+
*/
|
|
531
|
+
const flip$1 = function (options) {
|
|
532
|
+
if (options === void 0) {
|
|
533
|
+
options = {};
|
|
534
|
+
}
|
|
535
|
+
return {
|
|
536
|
+
name: 'flip',
|
|
537
|
+
options,
|
|
538
|
+
async fn(state) {
|
|
539
|
+
var _middlewareData$arrow, _middlewareData$flip;
|
|
540
|
+
const {
|
|
541
|
+
placement,
|
|
542
|
+
middlewareData,
|
|
543
|
+
rects,
|
|
544
|
+
initialPlacement,
|
|
545
|
+
platform,
|
|
546
|
+
elements
|
|
547
|
+
} = state;
|
|
548
|
+
const {
|
|
549
|
+
mainAxis: checkMainAxis = true,
|
|
550
|
+
crossAxis: checkCrossAxis = true,
|
|
551
|
+
fallbackPlacements: specifiedFallbackPlacements,
|
|
552
|
+
fallbackStrategy = 'bestFit',
|
|
553
|
+
fallbackAxisSideDirection = 'none',
|
|
554
|
+
flipAlignment = true,
|
|
555
|
+
...detectOverflowOptions
|
|
556
|
+
} = evaluate(options, state);
|
|
557
|
+
|
|
558
|
+
// If a reset by the arrow was caused due to an alignment offset being
|
|
559
|
+
// added, we should skip any logic now since `flip()` has already done its
|
|
560
|
+
// work.
|
|
561
|
+
// https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
|
|
562
|
+
if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
563
|
+
return {};
|
|
564
|
+
}
|
|
565
|
+
const side = getSide(placement);
|
|
566
|
+
const initialSideAxis = getSideAxis(initialPlacement);
|
|
567
|
+
const isBasePlacement = getSide(initialPlacement) === initialPlacement;
|
|
568
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
569
|
+
const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
|
|
570
|
+
const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
|
|
571
|
+
if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
|
|
572
|
+
fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
|
|
573
|
+
}
|
|
574
|
+
const placements = [initialPlacement, ...fallbackPlacements];
|
|
575
|
+
const overflow = await detectOverflow(state, detectOverflowOptions);
|
|
576
|
+
const overflows = [];
|
|
577
|
+
let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
|
|
578
|
+
if (checkMainAxis) {
|
|
579
|
+
overflows.push(overflow[side]);
|
|
580
|
+
}
|
|
581
|
+
if (checkCrossAxis) {
|
|
582
|
+
const sides = getAlignmentSides(placement, rects, rtl);
|
|
583
|
+
overflows.push(overflow[sides[0]], overflow[sides[1]]);
|
|
584
|
+
}
|
|
585
|
+
overflowsData = [...overflowsData, {
|
|
586
|
+
placement,
|
|
587
|
+
overflows
|
|
588
|
+
}];
|
|
589
|
+
|
|
590
|
+
// One or more sides is overflowing.
|
|
591
|
+
if (!overflows.every(side => side <= 0)) {
|
|
592
|
+
var _middlewareData$flip2, _overflowsData$filter;
|
|
593
|
+
const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
|
|
594
|
+
const nextPlacement = placements[nextIndex];
|
|
595
|
+
if (nextPlacement) {
|
|
596
|
+
// Try next placement and re-run the lifecycle.
|
|
597
|
+
return {
|
|
598
|
+
data: {
|
|
599
|
+
index: nextIndex,
|
|
600
|
+
overflows: overflowsData
|
|
601
|
+
},
|
|
602
|
+
reset: {
|
|
603
|
+
placement: nextPlacement
|
|
604
|
+
}
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// First, find the candidates that fit on the mainAxis side of overflow,
|
|
609
|
+
// then find the placement that fits the best on the main crossAxis side.
|
|
610
|
+
let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
|
|
611
|
+
|
|
612
|
+
// Otherwise fallback.
|
|
613
|
+
if (!resetPlacement) {
|
|
614
|
+
switch (fallbackStrategy) {
|
|
615
|
+
case 'bestFit':
|
|
616
|
+
{
|
|
617
|
+
var _overflowsData$filter2;
|
|
618
|
+
const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
|
|
619
|
+
if (hasFallbackAxisSideDirection) {
|
|
620
|
+
const currentSideAxis = getSideAxis(d.placement);
|
|
621
|
+
return currentSideAxis === initialSideAxis ||
|
|
622
|
+
// Create a bias to the `y` side axis due to horizontal
|
|
623
|
+
// reading directions favoring greater width.
|
|
624
|
+
currentSideAxis === 'y';
|
|
625
|
+
}
|
|
626
|
+
return true;
|
|
627
|
+
}).map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
|
|
628
|
+
if (placement) {
|
|
629
|
+
resetPlacement = placement;
|
|
630
|
+
}
|
|
631
|
+
break;
|
|
632
|
+
}
|
|
633
|
+
case 'initialPlacement':
|
|
634
|
+
resetPlacement = initialPlacement;
|
|
635
|
+
break;
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (placement !== resetPlacement) {
|
|
639
|
+
return {
|
|
640
|
+
reset: {
|
|
641
|
+
placement: resetPlacement
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
return {};
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
// For type backwards-compatibility, the `OffsetOptions` type was also
|
|
652
|
+
// Derivable.
|
|
653
|
+
|
|
654
|
+
async function convertValueToCoords(state, options) {
|
|
655
|
+
const {
|
|
656
|
+
placement,
|
|
657
|
+
platform,
|
|
658
|
+
elements
|
|
659
|
+
} = state;
|
|
660
|
+
const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
|
|
661
|
+
const side = getSide(placement);
|
|
662
|
+
const alignment = getAlignment(placement);
|
|
663
|
+
const isVertical = getSideAxis(placement) === 'y';
|
|
664
|
+
const mainAxisMulti = ['left', 'top'].includes(side) ? -1 : 1;
|
|
665
|
+
const crossAxisMulti = rtl && isVertical ? -1 : 1;
|
|
666
|
+
const rawValue = evaluate(options, state);
|
|
667
|
+
|
|
668
|
+
// eslint-disable-next-line prefer-const
|
|
669
|
+
let {
|
|
670
|
+
mainAxis,
|
|
671
|
+
crossAxis,
|
|
672
|
+
alignmentAxis
|
|
673
|
+
} = typeof rawValue === 'number' ? {
|
|
674
|
+
mainAxis: rawValue,
|
|
675
|
+
crossAxis: 0,
|
|
676
|
+
alignmentAxis: null
|
|
677
|
+
} : {
|
|
678
|
+
mainAxis: rawValue.mainAxis || 0,
|
|
679
|
+
crossAxis: rawValue.crossAxis || 0,
|
|
680
|
+
alignmentAxis: rawValue.alignmentAxis
|
|
681
|
+
};
|
|
682
|
+
if (alignment && typeof alignmentAxis === 'number') {
|
|
683
|
+
crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
|
|
684
|
+
}
|
|
685
|
+
return isVertical ? {
|
|
686
|
+
x: crossAxis * crossAxisMulti,
|
|
687
|
+
y: mainAxis * mainAxisMulti
|
|
688
|
+
} : {
|
|
689
|
+
x: mainAxis * mainAxisMulti,
|
|
690
|
+
y: crossAxis * crossAxisMulti
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
/**
|
|
695
|
+
* Modifies the placement by translating the floating element along the
|
|
696
|
+
* specified axes.
|
|
697
|
+
* A number (shorthand for `mainAxis` or distance), or an axes configuration
|
|
698
|
+
* object may be passed.
|
|
699
|
+
* @see https://floating-ui.com/docs/offset
|
|
700
|
+
*/
|
|
701
|
+
const offset$1 = function (options) {
|
|
702
|
+
if (options === void 0) {
|
|
703
|
+
options = 0;
|
|
704
|
+
}
|
|
705
|
+
return {
|
|
706
|
+
name: 'offset',
|
|
707
|
+
options,
|
|
708
|
+
async fn(state) {
|
|
709
|
+
var _middlewareData$offse, _middlewareData$arrow;
|
|
710
|
+
const {
|
|
711
|
+
x,
|
|
712
|
+
y,
|
|
713
|
+
placement,
|
|
714
|
+
middlewareData
|
|
715
|
+
} = state;
|
|
716
|
+
const diffCoords = await convertValueToCoords(state, options);
|
|
717
|
+
|
|
718
|
+
// If the placement is the same and the arrow caused an alignment offset
|
|
719
|
+
// then we don't need to change the positioning coordinates.
|
|
720
|
+
if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
|
|
721
|
+
return {};
|
|
722
|
+
}
|
|
723
|
+
return {
|
|
724
|
+
x: x + diffCoords.x,
|
|
725
|
+
y: y + diffCoords.y,
|
|
726
|
+
data: {
|
|
727
|
+
...diffCoords,
|
|
728
|
+
placement
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
};
|
|
734
|
+
|
|
735
|
+
function hasWindow() {
|
|
736
|
+
return typeof window !== 'undefined';
|
|
737
|
+
}
|
|
738
|
+
function getNodeName(node) {
|
|
739
|
+
if (isNode(node)) {
|
|
740
|
+
return (node.nodeName || '').toLowerCase();
|
|
741
|
+
}
|
|
742
|
+
// Mocked nodes in testing environments may not be instances of Node. By
|
|
743
|
+
// returning `#document` an infinite loop won't occur.
|
|
744
|
+
// https://github.com/floating-ui/floating-ui/issues/2317
|
|
745
|
+
return '#document';
|
|
746
|
+
}
|
|
747
|
+
function getWindow(node) {
|
|
748
|
+
var _node$ownerDocument;
|
|
749
|
+
return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
|
|
750
|
+
}
|
|
751
|
+
function getDocumentElement(node) {
|
|
752
|
+
var _ref;
|
|
753
|
+
return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
|
|
754
|
+
}
|
|
755
|
+
function isNode(value) {
|
|
756
|
+
if (!hasWindow()) {
|
|
757
|
+
return false;
|
|
758
|
+
}
|
|
759
|
+
return value instanceof Node || value instanceof getWindow(value).Node;
|
|
760
|
+
}
|
|
761
|
+
function isElement(value) {
|
|
762
|
+
if (!hasWindow()) {
|
|
763
|
+
return false;
|
|
764
|
+
}
|
|
765
|
+
return value instanceof Element || value instanceof getWindow(value).Element;
|
|
766
|
+
}
|
|
767
|
+
function isHTMLElement(value) {
|
|
768
|
+
if (!hasWindow()) {
|
|
769
|
+
return false;
|
|
770
|
+
}
|
|
771
|
+
return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
|
|
772
|
+
}
|
|
773
|
+
function isShadowRoot(value) {
|
|
774
|
+
if (!hasWindow() || typeof ShadowRoot === 'undefined') {
|
|
775
|
+
return false;
|
|
776
|
+
}
|
|
777
|
+
return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
|
|
778
|
+
}
|
|
779
|
+
function isOverflowElement(element) {
|
|
780
|
+
const {
|
|
781
|
+
overflow,
|
|
782
|
+
overflowX,
|
|
783
|
+
overflowY,
|
|
784
|
+
display
|
|
785
|
+
} = getComputedStyle$1(element);
|
|
786
|
+
return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && !['inline', 'contents'].includes(display);
|
|
787
|
+
}
|
|
788
|
+
function isTableElement(element) {
|
|
789
|
+
return ['table', 'td', 'th'].includes(getNodeName(element));
|
|
790
|
+
}
|
|
791
|
+
function isTopLayer(element) {
|
|
792
|
+
return [':popover-open', ':modal'].some(selector => {
|
|
793
|
+
try {
|
|
794
|
+
return element.matches(selector);
|
|
795
|
+
} catch (e) {
|
|
796
|
+
return false;
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
function isContainingBlock(elementOrCss) {
|
|
801
|
+
const webkit = isWebKit();
|
|
802
|
+
const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
|
|
803
|
+
|
|
804
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
805
|
+
// https://drafts.csswg.org/css-transforms-2/#individual-transforms
|
|
806
|
+
return ['transform', 'translate', 'scale', 'rotate', 'perspective'].some(value => css[value] ? css[value] !== 'none' : false) || (css.containerType ? css.containerType !== 'normal' : false) || !webkit && (css.backdropFilter ? css.backdropFilter !== 'none' : false) || !webkit && (css.filter ? css.filter !== 'none' : false) || ['transform', 'translate', 'scale', 'rotate', 'perspective', 'filter'].some(value => (css.willChange || '').includes(value)) || ['paint', 'layout', 'strict', 'content'].some(value => (css.contain || '').includes(value));
|
|
807
|
+
}
|
|
808
|
+
function getContainingBlock(element) {
|
|
809
|
+
let currentNode = getParentNode(element);
|
|
810
|
+
while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
811
|
+
if (isContainingBlock(currentNode)) {
|
|
812
|
+
return currentNode;
|
|
813
|
+
} else if (isTopLayer(currentNode)) {
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
816
|
+
currentNode = getParentNode(currentNode);
|
|
817
|
+
}
|
|
818
|
+
return null;
|
|
819
|
+
}
|
|
820
|
+
function isWebKit() {
|
|
821
|
+
if (typeof CSS === 'undefined' || !CSS.supports) return false;
|
|
822
|
+
return CSS.supports('-webkit-backdrop-filter', 'none');
|
|
823
|
+
}
|
|
824
|
+
function isLastTraversableNode(node) {
|
|
825
|
+
return ['html', 'body', '#document'].includes(getNodeName(node));
|
|
826
|
+
}
|
|
827
|
+
function getComputedStyle$1(element) {
|
|
828
|
+
return getWindow(element).getComputedStyle(element);
|
|
829
|
+
}
|
|
830
|
+
function getNodeScroll(element) {
|
|
831
|
+
if (isElement(element)) {
|
|
832
|
+
return {
|
|
833
|
+
scrollLeft: element.scrollLeft,
|
|
834
|
+
scrollTop: element.scrollTop
|
|
835
|
+
};
|
|
836
|
+
}
|
|
837
|
+
return {
|
|
838
|
+
scrollLeft: element.scrollX,
|
|
839
|
+
scrollTop: element.scrollY
|
|
840
|
+
};
|
|
841
|
+
}
|
|
842
|
+
function getParentNode(node) {
|
|
843
|
+
if (getNodeName(node) === 'html') {
|
|
844
|
+
return node;
|
|
845
|
+
}
|
|
846
|
+
const result =
|
|
847
|
+
// Step into the shadow DOM of the parent of a slotted node.
|
|
848
|
+
node.assignedSlot ||
|
|
849
|
+
// DOM Element detected.
|
|
850
|
+
node.parentNode ||
|
|
851
|
+
// ShadowRoot detected.
|
|
852
|
+
isShadowRoot(node) && node.host ||
|
|
853
|
+
// Fallback.
|
|
854
|
+
getDocumentElement(node);
|
|
855
|
+
return isShadowRoot(result) ? result.host : result;
|
|
856
|
+
}
|
|
857
|
+
function getNearestOverflowAncestor(node) {
|
|
858
|
+
const parentNode = getParentNode(node);
|
|
859
|
+
if (isLastTraversableNode(parentNode)) {
|
|
860
|
+
return node.ownerDocument ? node.ownerDocument.body : node.body;
|
|
861
|
+
}
|
|
862
|
+
if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
|
|
863
|
+
return parentNode;
|
|
864
|
+
}
|
|
865
|
+
return getNearestOverflowAncestor(parentNode);
|
|
866
|
+
}
|
|
867
|
+
function getOverflowAncestors(node, list, traverseIframes) {
|
|
868
|
+
var _node$ownerDocument2;
|
|
869
|
+
if (list === void 0) {
|
|
870
|
+
list = [];
|
|
871
|
+
}
|
|
872
|
+
if (traverseIframes === void 0) {
|
|
873
|
+
traverseIframes = true;
|
|
874
|
+
}
|
|
875
|
+
const scrollableAncestor = getNearestOverflowAncestor(node);
|
|
876
|
+
const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
|
|
877
|
+
const win = getWindow(scrollableAncestor);
|
|
878
|
+
if (isBody) {
|
|
879
|
+
const frameElement = getFrameElement(win);
|
|
880
|
+
return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
|
|
881
|
+
}
|
|
882
|
+
return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
|
|
883
|
+
}
|
|
884
|
+
function getFrameElement(win) {
|
|
885
|
+
return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
function getCssDimensions(element) {
|
|
889
|
+
const css = getComputedStyle$1(element);
|
|
890
|
+
// In testing environments, the `width` and `height` properties are empty
|
|
891
|
+
// strings for SVG elements, returning NaN. Fallback to `0` in this case.
|
|
892
|
+
let width = parseFloat(css.width) || 0;
|
|
893
|
+
let height = parseFloat(css.height) || 0;
|
|
894
|
+
const hasOffset = isHTMLElement(element);
|
|
895
|
+
const offsetWidth = hasOffset ? element.offsetWidth : width;
|
|
896
|
+
const offsetHeight = hasOffset ? element.offsetHeight : height;
|
|
897
|
+
const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
|
|
898
|
+
if (shouldFallback) {
|
|
899
|
+
width = offsetWidth;
|
|
900
|
+
height = offsetHeight;
|
|
901
|
+
}
|
|
902
|
+
return {
|
|
903
|
+
width,
|
|
904
|
+
height,
|
|
905
|
+
$: shouldFallback
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
function unwrapElement(element) {
|
|
910
|
+
return !isElement(element) ? element.contextElement : element;
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
function getScale(element) {
|
|
914
|
+
const domElement = unwrapElement(element);
|
|
915
|
+
if (!isHTMLElement(domElement)) {
|
|
916
|
+
return createCoords(1);
|
|
917
|
+
}
|
|
918
|
+
const rect = domElement.getBoundingClientRect();
|
|
919
|
+
const {
|
|
920
|
+
width,
|
|
921
|
+
height,
|
|
922
|
+
$
|
|
923
|
+
} = getCssDimensions(domElement);
|
|
924
|
+
let x = ($ ? round(rect.width) : rect.width) / width;
|
|
925
|
+
let y = ($ ? round(rect.height) : rect.height) / height;
|
|
926
|
+
|
|
927
|
+
// 0, NaN, or Infinity should always fallback to 1.
|
|
928
|
+
|
|
929
|
+
if (!x || !Number.isFinite(x)) {
|
|
930
|
+
x = 1;
|
|
931
|
+
}
|
|
932
|
+
if (!y || !Number.isFinite(y)) {
|
|
933
|
+
y = 1;
|
|
934
|
+
}
|
|
935
|
+
return {
|
|
936
|
+
x,
|
|
937
|
+
y
|
|
938
|
+
};
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
const noOffsets = /*#__PURE__*/createCoords(0);
|
|
942
|
+
function getVisualOffsets(element) {
|
|
943
|
+
const win = getWindow(element);
|
|
944
|
+
if (!isWebKit() || !win.visualViewport) {
|
|
945
|
+
return noOffsets;
|
|
946
|
+
}
|
|
947
|
+
return {
|
|
948
|
+
x: win.visualViewport.offsetLeft,
|
|
949
|
+
y: win.visualViewport.offsetTop
|
|
950
|
+
};
|
|
951
|
+
}
|
|
952
|
+
function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
|
|
953
|
+
if (isFixed === void 0) {
|
|
954
|
+
isFixed = false;
|
|
955
|
+
}
|
|
956
|
+
if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
|
|
957
|
+
return false;
|
|
958
|
+
}
|
|
959
|
+
return isFixed;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
|
|
963
|
+
if (includeScale === void 0) {
|
|
964
|
+
includeScale = false;
|
|
965
|
+
}
|
|
966
|
+
if (isFixedStrategy === void 0) {
|
|
967
|
+
isFixedStrategy = false;
|
|
968
|
+
}
|
|
969
|
+
const clientRect = element.getBoundingClientRect();
|
|
970
|
+
const domElement = unwrapElement(element);
|
|
971
|
+
let scale = createCoords(1);
|
|
972
|
+
if (includeScale) {
|
|
973
|
+
if (offsetParent) {
|
|
974
|
+
if (isElement(offsetParent)) {
|
|
975
|
+
scale = getScale(offsetParent);
|
|
976
|
+
}
|
|
977
|
+
} else {
|
|
978
|
+
scale = getScale(element);
|
|
979
|
+
}
|
|
980
|
+
}
|
|
981
|
+
const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
|
|
982
|
+
let x = (clientRect.left + visualOffsets.x) / scale.x;
|
|
983
|
+
let y = (clientRect.top + visualOffsets.y) / scale.y;
|
|
984
|
+
let width = clientRect.width / scale.x;
|
|
985
|
+
let height = clientRect.height / scale.y;
|
|
986
|
+
if (domElement) {
|
|
987
|
+
const win = getWindow(domElement);
|
|
988
|
+
const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
|
|
989
|
+
let currentWin = win;
|
|
990
|
+
let currentIFrame = getFrameElement(currentWin);
|
|
991
|
+
while (currentIFrame && offsetParent && offsetWin !== currentWin) {
|
|
992
|
+
const iframeScale = getScale(currentIFrame);
|
|
993
|
+
const iframeRect = currentIFrame.getBoundingClientRect();
|
|
994
|
+
const css = getComputedStyle$1(currentIFrame);
|
|
995
|
+
const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
|
|
996
|
+
const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
|
|
997
|
+
x *= iframeScale.x;
|
|
998
|
+
y *= iframeScale.y;
|
|
999
|
+
width *= iframeScale.x;
|
|
1000
|
+
height *= iframeScale.y;
|
|
1001
|
+
x += left;
|
|
1002
|
+
y += top;
|
|
1003
|
+
currentWin = getWindow(currentIFrame);
|
|
1004
|
+
currentIFrame = getFrameElement(currentWin);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
return rectToClientRect({
|
|
1008
|
+
width,
|
|
1009
|
+
height,
|
|
1010
|
+
x,
|
|
1011
|
+
y
|
|
1012
|
+
});
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// If <html> has a CSS width greater than the viewport, then this will be
|
|
1016
|
+
// incorrect for RTL.
|
|
1017
|
+
function getWindowScrollBarX(element, rect) {
|
|
1018
|
+
const leftScroll = getNodeScroll(element).scrollLeft;
|
|
1019
|
+
if (!rect) {
|
|
1020
|
+
return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
|
|
1021
|
+
}
|
|
1022
|
+
return rect.left + leftScroll;
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
function getHTMLOffset(documentElement, scroll, ignoreScrollbarX) {
|
|
1026
|
+
if (ignoreScrollbarX === void 0) {
|
|
1027
|
+
ignoreScrollbarX = false;
|
|
1028
|
+
}
|
|
1029
|
+
const htmlRect = documentElement.getBoundingClientRect();
|
|
1030
|
+
const x = htmlRect.left + scroll.scrollLeft - (ignoreScrollbarX ? 0 :
|
|
1031
|
+
// RTL <body> scrollbar.
|
|
1032
|
+
getWindowScrollBarX(documentElement, htmlRect));
|
|
1033
|
+
const y = htmlRect.top + scroll.scrollTop;
|
|
1034
|
+
return {
|
|
1035
|
+
x,
|
|
1036
|
+
y
|
|
1037
|
+
};
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
|
|
1041
|
+
let {
|
|
1042
|
+
elements,
|
|
1043
|
+
rect,
|
|
1044
|
+
offsetParent,
|
|
1045
|
+
strategy
|
|
1046
|
+
} = _ref;
|
|
1047
|
+
const isFixed = strategy === 'fixed';
|
|
1048
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
1049
|
+
const topLayer = elements ? isTopLayer(elements.floating) : false;
|
|
1050
|
+
if (offsetParent === documentElement || topLayer && isFixed) {
|
|
1051
|
+
return rect;
|
|
1052
|
+
}
|
|
1053
|
+
let scroll = {
|
|
1054
|
+
scrollLeft: 0,
|
|
1055
|
+
scrollTop: 0
|
|
1056
|
+
};
|
|
1057
|
+
let scale = createCoords(1);
|
|
1058
|
+
const offsets = createCoords(0);
|
|
1059
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
1060
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
1061
|
+
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
1062
|
+
scroll = getNodeScroll(offsetParent);
|
|
1063
|
+
}
|
|
1064
|
+
if (isHTMLElement(offsetParent)) {
|
|
1065
|
+
const offsetRect = getBoundingClientRect(offsetParent);
|
|
1066
|
+
scale = getScale(offsetParent);
|
|
1067
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
1068
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll, true) : createCoords(0);
|
|
1072
|
+
return {
|
|
1073
|
+
width: rect.width * scale.x,
|
|
1074
|
+
height: rect.height * scale.y,
|
|
1075
|
+
x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
|
|
1076
|
+
y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
|
|
1077
|
+
};
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
function getClientRects(element) {
|
|
1081
|
+
return Array.from(element.getClientRects());
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
// Gets the entire size of the scrollable document area, even extending outside
|
|
1085
|
+
// of the `<html>` and `<body>` rect bounds if horizontally scrollable.
|
|
1086
|
+
function getDocumentRect(element) {
|
|
1087
|
+
const html = getDocumentElement(element);
|
|
1088
|
+
const scroll = getNodeScroll(element);
|
|
1089
|
+
const body = element.ownerDocument.body;
|
|
1090
|
+
const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
|
|
1091
|
+
const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
|
|
1092
|
+
let x = -scroll.scrollLeft + getWindowScrollBarX(element);
|
|
1093
|
+
const y = -scroll.scrollTop;
|
|
1094
|
+
if (getComputedStyle$1(body).direction === 'rtl') {
|
|
1095
|
+
x += max(html.clientWidth, body.clientWidth) - width;
|
|
1096
|
+
}
|
|
1097
|
+
return {
|
|
1098
|
+
width,
|
|
1099
|
+
height,
|
|
1100
|
+
x,
|
|
1101
|
+
y
|
|
1102
|
+
};
|
|
1103
|
+
}
|
|
1104
|
+
|
|
1105
|
+
function getViewportRect(element, strategy) {
|
|
1106
|
+
const win = getWindow(element);
|
|
1107
|
+
const html = getDocumentElement(element);
|
|
1108
|
+
const visualViewport = win.visualViewport;
|
|
1109
|
+
let width = html.clientWidth;
|
|
1110
|
+
let height = html.clientHeight;
|
|
1111
|
+
let x = 0;
|
|
1112
|
+
let y = 0;
|
|
1113
|
+
if (visualViewport) {
|
|
1114
|
+
width = visualViewport.width;
|
|
1115
|
+
height = visualViewport.height;
|
|
1116
|
+
const visualViewportBased = isWebKit();
|
|
1117
|
+
if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
|
|
1118
|
+
x = visualViewport.offsetLeft;
|
|
1119
|
+
y = visualViewport.offsetTop;
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
return {
|
|
1123
|
+
width,
|
|
1124
|
+
height,
|
|
1125
|
+
x,
|
|
1126
|
+
y
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// Returns the inner client rect, subtracting scrollbars if present.
|
|
1131
|
+
function getInnerBoundingClientRect(element, strategy) {
|
|
1132
|
+
const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
|
|
1133
|
+
const top = clientRect.top + element.clientTop;
|
|
1134
|
+
const left = clientRect.left + element.clientLeft;
|
|
1135
|
+
const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
|
|
1136
|
+
const width = element.clientWidth * scale.x;
|
|
1137
|
+
const height = element.clientHeight * scale.y;
|
|
1138
|
+
const x = left * scale.x;
|
|
1139
|
+
const y = top * scale.y;
|
|
1140
|
+
return {
|
|
1141
|
+
width,
|
|
1142
|
+
height,
|
|
1143
|
+
x,
|
|
1144
|
+
y
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
|
|
1148
|
+
let rect;
|
|
1149
|
+
if (clippingAncestor === 'viewport') {
|
|
1150
|
+
rect = getViewportRect(element, strategy);
|
|
1151
|
+
} else if (clippingAncestor === 'document') {
|
|
1152
|
+
rect = getDocumentRect(getDocumentElement(element));
|
|
1153
|
+
} else if (isElement(clippingAncestor)) {
|
|
1154
|
+
rect = getInnerBoundingClientRect(clippingAncestor, strategy);
|
|
1155
|
+
} else {
|
|
1156
|
+
const visualOffsets = getVisualOffsets(element);
|
|
1157
|
+
rect = {
|
|
1158
|
+
x: clippingAncestor.x - visualOffsets.x,
|
|
1159
|
+
y: clippingAncestor.y - visualOffsets.y,
|
|
1160
|
+
width: clippingAncestor.width,
|
|
1161
|
+
height: clippingAncestor.height
|
|
1162
|
+
};
|
|
1163
|
+
}
|
|
1164
|
+
return rectToClientRect(rect);
|
|
1165
|
+
}
|
|
1166
|
+
function hasFixedPositionAncestor(element, stopNode) {
|
|
1167
|
+
const parentNode = getParentNode(element);
|
|
1168
|
+
if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
|
|
1169
|
+
return false;
|
|
1170
|
+
}
|
|
1171
|
+
return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
// A "clipping ancestor" is an `overflow` element with the characteristic of
|
|
1175
|
+
// clipping (or hiding) child elements. This returns all clipping ancestors
|
|
1176
|
+
// of the given element up the tree.
|
|
1177
|
+
function getClippingElementAncestors(element, cache) {
|
|
1178
|
+
const cachedResult = cache.get(element);
|
|
1179
|
+
if (cachedResult) {
|
|
1180
|
+
return cachedResult;
|
|
1181
|
+
}
|
|
1182
|
+
let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
|
|
1183
|
+
let currentContainingBlockComputedStyle = null;
|
|
1184
|
+
const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
|
|
1185
|
+
let currentNode = elementIsFixed ? getParentNode(element) : element;
|
|
1186
|
+
|
|
1187
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
|
|
1188
|
+
while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
|
|
1189
|
+
const computedStyle = getComputedStyle$1(currentNode);
|
|
1190
|
+
const currentNodeIsContaining = isContainingBlock(currentNode);
|
|
1191
|
+
if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
|
|
1192
|
+
currentContainingBlockComputedStyle = null;
|
|
1193
|
+
}
|
|
1194
|
+
const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && ['absolute', 'fixed'].includes(currentContainingBlockComputedStyle.position) || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
|
|
1195
|
+
if (shouldDropCurrentNode) {
|
|
1196
|
+
// Drop non-containing blocks.
|
|
1197
|
+
result = result.filter(ancestor => ancestor !== currentNode);
|
|
1198
|
+
} else {
|
|
1199
|
+
// Record last containing block for next iteration.
|
|
1200
|
+
currentContainingBlockComputedStyle = computedStyle;
|
|
1201
|
+
}
|
|
1202
|
+
currentNode = getParentNode(currentNode);
|
|
1203
|
+
}
|
|
1204
|
+
cache.set(element, result);
|
|
1205
|
+
return result;
|
|
1206
|
+
}
|
|
1207
|
+
|
|
1208
|
+
// Gets the maximum area that the element is visible in due to any number of
|
|
1209
|
+
// clipping ancestors.
|
|
1210
|
+
function getClippingRect(_ref) {
|
|
1211
|
+
let {
|
|
1212
|
+
element,
|
|
1213
|
+
boundary,
|
|
1214
|
+
rootBoundary,
|
|
1215
|
+
strategy
|
|
1216
|
+
} = _ref;
|
|
1217
|
+
const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
|
|
1218
|
+
const clippingAncestors = [...elementClippingAncestors, rootBoundary];
|
|
1219
|
+
const firstClippingAncestor = clippingAncestors[0];
|
|
1220
|
+
const clippingRect = clippingAncestors.reduce((accRect, clippingAncestor) => {
|
|
1221
|
+
const rect = getClientRectFromClippingAncestor(element, clippingAncestor, strategy);
|
|
1222
|
+
accRect.top = max(rect.top, accRect.top);
|
|
1223
|
+
accRect.right = min(rect.right, accRect.right);
|
|
1224
|
+
accRect.bottom = min(rect.bottom, accRect.bottom);
|
|
1225
|
+
accRect.left = max(rect.left, accRect.left);
|
|
1226
|
+
return accRect;
|
|
1227
|
+
}, getClientRectFromClippingAncestor(element, firstClippingAncestor, strategy));
|
|
1228
|
+
return {
|
|
1229
|
+
width: clippingRect.right - clippingRect.left,
|
|
1230
|
+
height: clippingRect.bottom - clippingRect.top,
|
|
1231
|
+
x: clippingRect.left,
|
|
1232
|
+
y: clippingRect.top
|
|
1233
|
+
};
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1236
|
+
function getDimensions(element) {
|
|
1237
|
+
const {
|
|
1238
|
+
width,
|
|
1239
|
+
height
|
|
1240
|
+
} = getCssDimensions(element);
|
|
1241
|
+
return {
|
|
1242
|
+
width,
|
|
1243
|
+
height
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
|
|
1248
|
+
const isOffsetParentAnElement = isHTMLElement(offsetParent);
|
|
1249
|
+
const documentElement = getDocumentElement(offsetParent);
|
|
1250
|
+
const isFixed = strategy === 'fixed';
|
|
1251
|
+
const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
|
|
1252
|
+
let scroll = {
|
|
1253
|
+
scrollLeft: 0,
|
|
1254
|
+
scrollTop: 0
|
|
1255
|
+
};
|
|
1256
|
+
const offsets = createCoords(0);
|
|
1257
|
+
if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
|
|
1258
|
+
if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
|
|
1259
|
+
scroll = getNodeScroll(offsetParent);
|
|
1260
|
+
}
|
|
1261
|
+
if (isOffsetParentAnElement) {
|
|
1262
|
+
const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
|
|
1263
|
+
offsets.x = offsetRect.x + offsetParent.clientLeft;
|
|
1264
|
+
offsets.y = offsetRect.y + offsetParent.clientTop;
|
|
1265
|
+
} else if (documentElement) {
|
|
1266
|
+
// If the <body> scrollbar appears on the left (e.g. RTL systems). Use
|
|
1267
|
+
// Firefox with layout.scrollbar.side = 3 in about:config to test this.
|
|
1268
|
+
offsets.x = getWindowScrollBarX(documentElement);
|
|
1269
|
+
}
|
|
1270
|
+
}
|
|
1271
|
+
const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
|
|
1272
|
+
const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
|
|
1273
|
+
const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
|
|
1274
|
+
return {
|
|
1275
|
+
x,
|
|
1276
|
+
y,
|
|
1277
|
+
width: rect.width,
|
|
1278
|
+
height: rect.height
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function isStaticPositioned(element) {
|
|
1283
|
+
return getComputedStyle$1(element).position === 'static';
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
function getTrueOffsetParent(element, polyfill) {
|
|
1287
|
+
if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
|
|
1288
|
+
return null;
|
|
1289
|
+
}
|
|
1290
|
+
if (polyfill) {
|
|
1291
|
+
return polyfill(element);
|
|
1292
|
+
}
|
|
1293
|
+
let rawOffsetParent = element.offsetParent;
|
|
1294
|
+
|
|
1295
|
+
// Firefox returns the <html> element as the offsetParent if it's non-static,
|
|
1296
|
+
// while Chrome and Safari return the <body> element. The <body> element must
|
|
1297
|
+
// be used to perform the correct calculations even if the <html> element is
|
|
1298
|
+
// non-static.
|
|
1299
|
+
if (getDocumentElement(element) === rawOffsetParent) {
|
|
1300
|
+
rawOffsetParent = rawOffsetParent.ownerDocument.body;
|
|
1301
|
+
}
|
|
1302
|
+
return rawOffsetParent;
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
// Gets the closest ancestor positioned element. Handles some edge cases,
|
|
1306
|
+
// such as table ancestors and cross browser bugs.
|
|
1307
|
+
function getOffsetParent(element, polyfill) {
|
|
1308
|
+
const win = getWindow(element);
|
|
1309
|
+
if (isTopLayer(element)) {
|
|
1310
|
+
return win;
|
|
1311
|
+
}
|
|
1312
|
+
if (!isHTMLElement(element)) {
|
|
1313
|
+
let svgOffsetParent = getParentNode(element);
|
|
1314
|
+
while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
|
|
1315
|
+
if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
|
|
1316
|
+
return svgOffsetParent;
|
|
1317
|
+
}
|
|
1318
|
+
svgOffsetParent = getParentNode(svgOffsetParent);
|
|
1319
|
+
}
|
|
1320
|
+
return win;
|
|
1321
|
+
}
|
|
1322
|
+
let offsetParent = getTrueOffsetParent(element, polyfill);
|
|
1323
|
+
while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
|
|
1324
|
+
offsetParent = getTrueOffsetParent(offsetParent, polyfill);
|
|
1325
|
+
}
|
|
1326
|
+
if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
|
|
1327
|
+
return win;
|
|
1328
|
+
}
|
|
1329
|
+
return offsetParent || getContainingBlock(element) || win;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
const getElementRects = async function (data) {
|
|
1333
|
+
const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
|
|
1334
|
+
const getDimensionsFn = this.getDimensions;
|
|
1335
|
+
const floatingDimensions = await getDimensionsFn(data.floating);
|
|
1336
|
+
return {
|
|
1337
|
+
reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
|
|
1338
|
+
floating: {
|
|
1339
|
+
x: 0,
|
|
1340
|
+
y: 0,
|
|
1341
|
+
width: floatingDimensions.width,
|
|
1342
|
+
height: floatingDimensions.height
|
|
1343
|
+
}
|
|
1344
|
+
};
|
|
1345
|
+
};
|
|
1346
|
+
|
|
1347
|
+
function isRTL(element) {
|
|
1348
|
+
return getComputedStyle$1(element).direction === 'rtl';
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
const platform = {
|
|
1352
|
+
convertOffsetParentRelativeRectToViewportRelativeRect,
|
|
1353
|
+
getDocumentElement,
|
|
1354
|
+
getClippingRect,
|
|
1355
|
+
getOffsetParent,
|
|
1356
|
+
getElementRects,
|
|
1357
|
+
getClientRects,
|
|
1358
|
+
getDimensions,
|
|
1359
|
+
getScale,
|
|
1360
|
+
isElement,
|
|
1361
|
+
isRTL
|
|
1362
|
+
};
|
|
1363
|
+
|
|
1364
|
+
function rectsAreEqual(a, b) {
|
|
1365
|
+
return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
// https://samthor.au/2021/observing-dom/
|
|
1369
|
+
function observeMove(element, onMove) {
|
|
1370
|
+
let io = null;
|
|
1371
|
+
let timeoutId;
|
|
1372
|
+
const root = getDocumentElement(element);
|
|
1373
|
+
function cleanup() {
|
|
1374
|
+
var _io;
|
|
1375
|
+
clearTimeout(timeoutId);
|
|
1376
|
+
(_io = io) == null || _io.disconnect();
|
|
1377
|
+
io = null;
|
|
1378
|
+
}
|
|
1379
|
+
function refresh(skip, threshold) {
|
|
1380
|
+
if (skip === void 0) {
|
|
1381
|
+
skip = false;
|
|
1382
|
+
}
|
|
1383
|
+
if (threshold === void 0) {
|
|
1384
|
+
threshold = 1;
|
|
1385
|
+
}
|
|
1386
|
+
cleanup();
|
|
1387
|
+
const elementRectForRootMargin = element.getBoundingClientRect();
|
|
1388
|
+
const {
|
|
1389
|
+
left,
|
|
1390
|
+
top,
|
|
1391
|
+
width,
|
|
1392
|
+
height
|
|
1393
|
+
} = elementRectForRootMargin;
|
|
1394
|
+
if (!skip) {
|
|
1395
|
+
onMove();
|
|
1396
|
+
}
|
|
1397
|
+
if (!width || !height) {
|
|
1398
|
+
return;
|
|
1399
|
+
}
|
|
1400
|
+
const insetTop = floor(top);
|
|
1401
|
+
const insetRight = floor(root.clientWidth - (left + width));
|
|
1402
|
+
const insetBottom = floor(root.clientHeight - (top + height));
|
|
1403
|
+
const insetLeft = floor(left);
|
|
1404
|
+
const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
|
|
1405
|
+
const options = {
|
|
1406
|
+
rootMargin,
|
|
1407
|
+
threshold: max(0, min(1, threshold)) || 1
|
|
1408
|
+
};
|
|
1409
|
+
let isFirstUpdate = true;
|
|
1410
|
+
function handleObserve(entries) {
|
|
1411
|
+
const ratio = entries[0].intersectionRatio;
|
|
1412
|
+
if (ratio !== threshold) {
|
|
1413
|
+
if (!isFirstUpdate) {
|
|
1414
|
+
return refresh();
|
|
1415
|
+
}
|
|
1416
|
+
if (!ratio) {
|
|
1417
|
+
// If the reference is clipped, the ratio is 0. Throttle the refresh
|
|
1418
|
+
// to prevent an infinite loop of updates.
|
|
1419
|
+
timeoutId = setTimeout(() => {
|
|
1420
|
+
refresh(false, 1e-7);
|
|
1421
|
+
}, 1000);
|
|
1422
|
+
} else {
|
|
1423
|
+
refresh(false, ratio);
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
|
|
1427
|
+
// It's possible that even though the ratio is reported as 1, the
|
|
1428
|
+
// element is not actually fully within the IntersectionObserver's root
|
|
1429
|
+
// area anymore. This can happen under performance constraints. This may
|
|
1430
|
+
// be a bug in the browser's IntersectionObserver implementation. To
|
|
1431
|
+
// work around this, we compare the element's bounding rect now with
|
|
1432
|
+
// what it was at the time we created the IntersectionObserver. If they
|
|
1433
|
+
// are not equal then the element moved, so we refresh.
|
|
1434
|
+
refresh();
|
|
1435
|
+
}
|
|
1436
|
+
isFirstUpdate = false;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
// Older browsers don't support a `document` as the root and will throw an
|
|
1440
|
+
// error.
|
|
1441
|
+
try {
|
|
1442
|
+
io = new IntersectionObserver(handleObserve, {
|
|
1443
|
+
...options,
|
|
1444
|
+
// Handle <iframe>s
|
|
1445
|
+
root: root.ownerDocument
|
|
1446
|
+
});
|
|
1447
|
+
} catch (e) {
|
|
1448
|
+
io = new IntersectionObserver(handleObserve, options);
|
|
1449
|
+
}
|
|
1450
|
+
io.observe(element);
|
|
1451
|
+
}
|
|
1452
|
+
refresh(true);
|
|
1453
|
+
return cleanup;
|
|
1454
|
+
}
|
|
1455
|
+
|
|
1456
|
+
/**
|
|
1457
|
+
* Automatically updates the position of the floating element when necessary.
|
|
1458
|
+
* Should only be called when the floating element is mounted on the DOM or
|
|
1459
|
+
* visible on the screen.
|
|
1460
|
+
* @returns cleanup function that should be invoked when the floating element is
|
|
1461
|
+
* removed from the DOM or hidden from the screen.
|
|
1462
|
+
* @see https://floating-ui.com/docs/autoUpdate
|
|
1463
|
+
*/
|
|
1464
|
+
function autoUpdate(reference, floating, update, options) {
|
|
1465
|
+
if (options === void 0) {
|
|
1466
|
+
options = {};
|
|
1467
|
+
}
|
|
1468
|
+
const {
|
|
1469
|
+
ancestorScroll = true,
|
|
1470
|
+
ancestorResize = true,
|
|
1471
|
+
elementResize = typeof ResizeObserver === 'function',
|
|
1472
|
+
layoutShift = typeof IntersectionObserver === 'function',
|
|
1473
|
+
animationFrame = false
|
|
1474
|
+
} = options;
|
|
1475
|
+
const referenceEl = unwrapElement(reference);
|
|
1476
|
+
const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...getOverflowAncestors(floating)] : [];
|
|
1477
|
+
ancestors.forEach(ancestor => {
|
|
1478
|
+
ancestorScroll && ancestor.addEventListener('scroll', update, {
|
|
1479
|
+
passive: true
|
|
1480
|
+
});
|
|
1481
|
+
ancestorResize && ancestor.addEventListener('resize', update);
|
|
1482
|
+
});
|
|
1483
|
+
const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
|
|
1484
|
+
let reobserveFrame = -1;
|
|
1485
|
+
let resizeObserver = null;
|
|
1486
|
+
if (elementResize) {
|
|
1487
|
+
resizeObserver = new ResizeObserver(_ref => {
|
|
1488
|
+
let [firstEntry] = _ref;
|
|
1489
|
+
if (firstEntry && firstEntry.target === referenceEl && resizeObserver) {
|
|
1490
|
+
// Prevent update loops when using the `size` middleware.
|
|
1491
|
+
// https://github.com/floating-ui/floating-ui/issues/1740
|
|
1492
|
+
resizeObserver.unobserve(floating);
|
|
1493
|
+
cancelAnimationFrame(reobserveFrame);
|
|
1494
|
+
reobserveFrame = requestAnimationFrame(() => {
|
|
1495
|
+
var _resizeObserver;
|
|
1496
|
+
(_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
|
|
1497
|
+
});
|
|
1498
|
+
}
|
|
1499
|
+
update();
|
|
1500
|
+
});
|
|
1501
|
+
if (referenceEl && !animationFrame) {
|
|
1502
|
+
resizeObserver.observe(referenceEl);
|
|
1503
|
+
}
|
|
1504
|
+
resizeObserver.observe(floating);
|
|
1505
|
+
}
|
|
1506
|
+
let frameId;
|
|
1507
|
+
let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
|
|
1508
|
+
if (animationFrame) {
|
|
1509
|
+
frameLoop();
|
|
1510
|
+
}
|
|
1511
|
+
function frameLoop() {
|
|
1512
|
+
const nextRefRect = getBoundingClientRect(reference);
|
|
1513
|
+
if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
|
|
1514
|
+
update();
|
|
1515
|
+
}
|
|
1516
|
+
prevRefRect = nextRefRect;
|
|
1517
|
+
frameId = requestAnimationFrame(frameLoop);
|
|
1518
|
+
}
|
|
1519
|
+
update();
|
|
1520
|
+
return () => {
|
|
1521
|
+
var _resizeObserver2;
|
|
1522
|
+
ancestors.forEach(ancestor => {
|
|
1523
|
+
ancestorScroll && ancestor.removeEventListener('scroll', update);
|
|
1524
|
+
ancestorResize && ancestor.removeEventListener('resize', update);
|
|
1525
|
+
});
|
|
1526
|
+
cleanupIo == null || cleanupIo();
|
|
1527
|
+
(_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
|
|
1528
|
+
resizeObserver = null;
|
|
1529
|
+
if (animationFrame) {
|
|
1530
|
+
cancelAnimationFrame(frameId);
|
|
1531
|
+
}
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
|
|
1535
|
+
/**
|
|
1536
|
+
* Modifies the placement by translating the floating element along the
|
|
1537
|
+
* specified axes.
|
|
1538
|
+
* A number (shorthand for `mainAxis` or distance), or an axes configuration
|
|
1539
|
+
* object may be passed.
|
|
1540
|
+
* @see https://floating-ui.com/docs/offset
|
|
1541
|
+
*/
|
|
1542
|
+
const offset = offset$1;
|
|
1543
|
+
|
|
1544
|
+
/**
|
|
1545
|
+
* Optimizes the visibility of the floating element by choosing the placement
|
|
1546
|
+
* that has the most space available automatically, without needing to specify a
|
|
1547
|
+
* preferred placement. Alternative to `flip`.
|
|
1548
|
+
* @see https://floating-ui.com/docs/autoPlacement
|
|
1549
|
+
*/
|
|
1550
|
+
const autoPlacement = autoPlacement$1;
|
|
1551
|
+
|
|
1552
|
+
/**
|
|
1553
|
+
* Optimizes the visibility of the floating element by flipping the `placement`
|
|
1554
|
+
* in order to keep it in view when the preferred placement(s) will overflow the
|
|
1555
|
+
* clipping boundary. Alternative to `autoPlacement`.
|
|
1556
|
+
* @see https://floating-ui.com/docs/flip
|
|
1557
|
+
*/
|
|
1558
|
+
const flip = flip$1;
|
|
1559
|
+
|
|
1560
|
+
/**
|
|
1561
|
+
* Computes the `x` and `y` coordinates that will place the floating element
|
|
1562
|
+
* next to a given reference element.
|
|
1563
|
+
*/
|
|
1564
|
+
const computePosition = (reference, floating, options) => {
|
|
1565
|
+
// This caches the expensive `getClippingElementAncestors` function so that
|
|
1566
|
+
// multiple lifecycle resets re-use the same result. It only lives for a
|
|
1567
|
+
// single call. If other functions become expensive, we can add them as well.
|
|
1568
|
+
const cache = new Map();
|
|
1569
|
+
const mergedOptions = {
|
|
1570
|
+
platform,
|
|
1571
|
+
...options
|
|
1572
|
+
};
|
|
1573
|
+
const platformWithCache = {
|
|
1574
|
+
...mergedOptions.platform,
|
|
1575
|
+
_c: cache
|
|
1576
|
+
};
|
|
1577
|
+
return computePosition$1(reference, floating, {
|
|
1578
|
+
...mergedOptions,
|
|
1579
|
+
platform: platformWithCache
|
|
1580
|
+
});
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1583
|
+
/* eslint-disable line-comment-position, no-inline-comments */
|
|
1584
|
+
|
|
1585
|
+
|
|
1586
|
+
|
|
1587
|
+
const MAX_CONFIGURATION_COUNT = 10;
|
|
1588
|
+
|
|
1589
|
+
class AuroFloatingUI {
|
|
1590
|
+
|
|
1591
|
+
/**
|
|
1592
|
+
* @private
|
|
1593
|
+
*/
|
|
1594
|
+
static isMousePressed = false;
|
|
1595
|
+
|
|
1596
|
+
/**
|
|
1597
|
+
* @private
|
|
1598
|
+
*/
|
|
1599
|
+
static isMousePressHandlerInitialized = false;
|
|
1600
|
+
|
|
1601
|
+
/**
|
|
1602
|
+
* @private
|
|
1603
|
+
*/
|
|
1604
|
+
static setupMousePressChecker() {
|
|
1605
|
+
if (!AuroFloatingUI.isMousePressHandlerInitialized && window && window.addEventListener) {
|
|
1606
|
+
AuroFloatingUI.isMousePressHandlerInitialized = true;
|
|
1607
|
+
|
|
1608
|
+
const mouseEventGlobalHandler = (event) => {
|
|
1609
|
+
AuroFloatingUI.isMousePressed = event.type === 'mousedown';
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
window.addEventListener('mousedown', mouseEventGlobalHandler);
|
|
1613
|
+
window.addEventListener('mouseup', mouseEventGlobalHandler);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
constructor(element, behavior) {
|
|
1618
|
+
this.element = element;
|
|
1619
|
+
this.behavior = behavior;
|
|
1620
|
+
|
|
1621
|
+
// Store event listener references for cleanup
|
|
1622
|
+
this.focusHandler = null;
|
|
1623
|
+
this.clickHandler = null;
|
|
1624
|
+
this.keyDownHandler = null;
|
|
1625
|
+
|
|
1626
|
+
/**
|
|
1627
|
+
* @private
|
|
1628
|
+
*/
|
|
1629
|
+
this.configureTrial = 0;
|
|
1630
|
+
|
|
1631
|
+
/**
|
|
1632
|
+
* @private
|
|
1633
|
+
*/
|
|
1634
|
+
this.eventPrefix = undefined;
|
|
1635
|
+
|
|
1636
|
+
/**
|
|
1637
|
+
* @private
|
|
1638
|
+
*/
|
|
1639
|
+
this.id = undefined;
|
|
1640
|
+
|
|
1641
|
+
/**
|
|
1642
|
+
* @private
|
|
1643
|
+
*/
|
|
1644
|
+
this.showing = false;
|
|
1645
|
+
|
|
1646
|
+
/**
|
|
1647
|
+
* @private
|
|
1648
|
+
*/
|
|
1649
|
+
this.strategy = undefined;
|
|
1650
|
+
}
|
|
1651
|
+
|
|
1652
|
+
/**
|
|
1653
|
+
* Mirrors the size of the bibSizer element to the bib content.
|
|
1654
|
+
* Copies the width, height, max-width, and max-height styles from the bibSizer element to the bib content container.
|
|
1655
|
+
* This ensures that the bib content has the same dimensions as the sizer element.
|
|
1656
|
+
*/
|
|
1657
|
+
mirrorSize() {
|
|
1658
|
+
// mirror the boxsize from bibSizer
|
|
1659
|
+
if (this.element.bibSizer) {
|
|
1660
|
+
const sizerStyle = window.getComputedStyle(this.element.bibSizer);
|
|
1661
|
+
const bibContent = this.element.bib.shadowRoot.querySelector(".container");
|
|
1662
|
+
if (sizerStyle.width !== '0px') {
|
|
1663
|
+
bibContent.style.width = sizerStyle.width;
|
|
1664
|
+
}
|
|
1665
|
+
if (sizerStyle.height !== '0px') {
|
|
1666
|
+
bibContent.style.height = sizerStyle.height;
|
|
1667
|
+
}
|
|
1668
|
+
bibContent.style.maxWidth = sizerStyle.maxWidth;
|
|
1669
|
+
bibContent.style.maxHeight = sizerStyle.maxHeight;
|
|
1670
|
+
}
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
/**
|
|
1674
|
+
* @private
|
|
1675
|
+
* Determines the positioning strategy based on the current viewport size and mobile breakpoint.
|
|
1676
|
+
*
|
|
1677
|
+
* This method checks if the current viewport width is less than or equal to the specified mobile fullscreen breakpoint
|
|
1678
|
+
* defined in the bib element. If it is, the strategy is set to 'fullscreen'; otherwise, it defaults to 'floating'.
|
|
1679
|
+
*
|
|
1680
|
+
* @returns {String} The positioning strategy, one of 'fullscreen', 'floating', 'cover'.
|
|
1681
|
+
*/
|
|
1682
|
+
getPositioningStrategy() {
|
|
1683
|
+
const breakpoint = this.element.bib.mobileFullscreenBreakpoint || this.element.floaterConfig?.fullscreenBreakpoint;
|
|
1684
|
+
switch (this.behavior) {
|
|
1685
|
+
case "tooltip":
|
|
1686
|
+
return "floating";
|
|
1687
|
+
case "dialog":
|
|
1688
|
+
case "drawer":
|
|
1689
|
+
if (breakpoint) {
|
|
1690
|
+
const smallerThanBreakpoint = window.matchMedia(`(max-width: ${breakpoint})`).matches;
|
|
1691
|
+
|
|
1692
|
+
this.element.expanded = smallerThanBreakpoint;
|
|
1693
|
+
}
|
|
1694
|
+
if (this.element.nested) {
|
|
1695
|
+
return "cover";
|
|
1696
|
+
}
|
|
1697
|
+
return 'fullscreen';
|
|
1698
|
+
case "dropdown":
|
|
1699
|
+
case undefined:
|
|
1700
|
+
case null:
|
|
1701
|
+
if (breakpoint) {
|
|
1702
|
+
const smallerThanBreakpoint = window.matchMedia(`(max-width: ${breakpoint})`).matches;
|
|
1703
|
+
if (smallerThanBreakpoint) {
|
|
1704
|
+
return 'fullscreen';
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
return "floating";
|
|
1708
|
+
default:
|
|
1709
|
+
return this.behavior;
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
/**
|
|
1714
|
+
* @private
|
|
1715
|
+
* Positions the bib element based on the current configuration and positioning strategy.
|
|
1716
|
+
*
|
|
1717
|
+
* This method determines the appropriate positioning strategy (fullscreen or not) and configures the bib accordingly.
|
|
1718
|
+
* It also sets up middleware for the floater configuration, computes the position of the bib relative to the trigger element,
|
|
1719
|
+
* and applies the calculated position to the bib's style.
|
|
1720
|
+
*/
|
|
1721
|
+
position() {
|
|
1722
|
+
const strategy = this.getPositioningStrategy();
|
|
1723
|
+
this.configureBibStrategy(strategy);
|
|
1724
|
+
|
|
1725
|
+
if (strategy === 'floating') {
|
|
1726
|
+
this.mirrorSize();
|
|
1727
|
+
// Define the middlware for the floater configuration
|
|
1728
|
+
const middleware = [
|
|
1729
|
+
offset(this.element.floaterConfig?.offset || 0),
|
|
1730
|
+
...this.element.floaterConfig?.flip ? [flip()] : [], // Add flip middleware if flip is enabled.
|
|
1731
|
+
...this.element.floaterConfig?.autoPlacement ? [autoPlacement()] : [], // Add autoPlacement middleware if autoPlacement is enabled.
|
|
1732
|
+
];
|
|
1733
|
+
|
|
1734
|
+
// Compute the position of the bib
|
|
1735
|
+
computePosition(this.element.trigger, this.element.bib, {
|
|
1736
|
+
placement: this.element.floaterConfig?.placement,
|
|
1737
|
+
middleware: middleware || []
|
|
1738
|
+
}).then(({ x, y }) => { // eslint-disable-line id-length
|
|
1739
|
+
Object.assign(this.element.bib.style, {
|
|
1740
|
+
left: `${x}px`,
|
|
1741
|
+
top: `${y}px`,
|
|
1742
|
+
});
|
|
1743
|
+
});
|
|
1744
|
+
} else if (strategy === 'cover') {
|
|
1745
|
+
// Compute the position of the bib
|
|
1746
|
+
computePosition(this.element.parentNode, this.element.bib, {
|
|
1747
|
+
placement: 'bottom-start'
|
|
1748
|
+
}).then(({ x, y }) => { // eslint-disable-line id-length
|
|
1749
|
+
Object.assign(this.element.bib.style, {
|
|
1750
|
+
left: `${x}px`,
|
|
1751
|
+
top: `${y - this.element.parentNode.offsetHeight}px`,
|
|
1752
|
+
width: `${this.element.parentNode.offsetWidth}px`,
|
|
1753
|
+
height: `${this.element.parentNode.offsetHeight}px`
|
|
1754
|
+
});
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
}
|
|
1758
|
+
|
|
1759
|
+
/**
|
|
1760
|
+
* @private
|
|
1761
|
+
* Controls whether to lock the scrolling for the document's body.
|
|
1762
|
+
* @param {Boolean} lock - If true, locks the body's scrolling functionlity; otherwise, unlock.
|
|
1763
|
+
*/
|
|
1764
|
+
lockScroll(lock = true) {
|
|
1765
|
+
if (lock) {
|
|
1766
|
+
document.body.style.overflow = 'hidden'; // hide body's scrollbar
|
|
1767
|
+
|
|
1768
|
+
// Move `bib` by the amount the viewport is shifted to stay aligned in fullscreen.
|
|
1769
|
+
this.element.bib.style.transform = `translateY(${visualViewport.offsetTop}px)`;
|
|
1770
|
+
} else {
|
|
1771
|
+
document.body.style.overflow = '';
|
|
1772
|
+
}
|
|
1773
|
+
}
|
|
1774
|
+
|
|
1775
|
+
/**
|
|
1776
|
+
* @private
|
|
1777
|
+
* Configures the bib element's display strategy.
|
|
1778
|
+
*
|
|
1779
|
+
* Sets the bib to fullscreen or floating mode based on the provided strategy.
|
|
1780
|
+
* Dispatches a 'strategy-change' event if the strategy changes.
|
|
1781
|
+
*
|
|
1782
|
+
* @param {string} strategy - The positioning strategy ('fullscreen' or 'floating').
|
|
1783
|
+
*/
|
|
1784
|
+
configureBibStrategy(value) {
|
|
1785
|
+
if (value === 'fullscreen') {
|
|
1786
|
+
this.element.isBibFullscreen = true;
|
|
1787
|
+
// reset the prev position
|
|
1788
|
+
this.element.bib.setAttribute('isfullscreen', "");
|
|
1789
|
+
this.element.bib.style.position = 'fixed';
|
|
1790
|
+
this.element.bib.style.top = "0px";
|
|
1791
|
+
this.element.bib.style.left = "0px";
|
|
1792
|
+
this.element.bib.style.width = '';
|
|
1793
|
+
this.element.bib.style.height = '';
|
|
1794
|
+
|
|
1795
|
+
// reset the size that was mirroring `size` css-part
|
|
1796
|
+
const bibContent = this.element.bib.shadowRoot.querySelector(".container");
|
|
1797
|
+
if (bibContent) {
|
|
1798
|
+
bibContent.style.width = '';
|
|
1799
|
+
bibContent.style.height = '';
|
|
1800
|
+
bibContent.style.maxWidth = '';
|
|
1801
|
+
bibContent.style.maxHeight = `${window.visualViewport.height}px`;
|
|
1802
|
+
this.configureTrial = 0;
|
|
1803
|
+
} else if (this.configureTrial < MAX_CONFIGURATION_COUNT) {
|
|
1804
|
+
this.configureTrial += 1;
|
|
1805
|
+
|
|
1806
|
+
setTimeout(() => {
|
|
1807
|
+
this.configureBibStrategy(value);
|
|
1808
|
+
}, 0);
|
|
1809
|
+
}
|
|
1810
|
+
|
|
1811
|
+
if (this.element.isPopoverVisible) {
|
|
1812
|
+
this.lockScroll(true);
|
|
1813
|
+
}
|
|
1814
|
+
} else {
|
|
1815
|
+
this.element.bib.style.position = '';
|
|
1816
|
+
this.element.bib.removeAttribute('isfullscreen');
|
|
1817
|
+
this.element.isBibFullscreen = false;
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
const isChanged = this.strategy && this.strategy !== value;
|
|
1821
|
+
this.strategy = value;
|
|
1822
|
+
if (isChanged) {
|
|
1823
|
+
const event = new CustomEvent(this.eventPrefix ? `${this.eventPrefix}-strategy-change` : 'strategy-change', {
|
|
1824
|
+
detail: {
|
|
1825
|
+
value,
|
|
1826
|
+
},
|
|
1827
|
+
composed: true
|
|
1828
|
+
});
|
|
1829
|
+
|
|
1830
|
+
this.element.dispatchEvent(event);
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
updateState() {
|
|
1835
|
+
const isVisible = this.element.isPopoverVisible;
|
|
1836
|
+
if (!isVisible) {
|
|
1837
|
+
this.cleanupHideHandlers();
|
|
1838
|
+
try {
|
|
1839
|
+
this.element.cleanup?.();
|
|
1840
|
+
} catch (error) {
|
|
1841
|
+
// Do nothing
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
/**
|
|
1847
|
+
* @private
|
|
1848
|
+
* getting called on 'blur' in trigger or `focusin` in document
|
|
1849
|
+
*
|
|
1850
|
+
* Hides the bib if focus moves outside of the trigger or bib, unless a 'noHideOnThisFocusLoss' flag is set.
|
|
1851
|
+
* This method checks if the currently active element is still within the trigger or bib.
|
|
1852
|
+
* If not, and if the bib isn't in fullscreen mode with focus lost, it hides the bib.
|
|
1853
|
+
*/
|
|
1854
|
+
handleFocusLoss() {
|
|
1855
|
+
// if mouse is being pressed, skip and let click event to handle the action
|
|
1856
|
+
if (AuroFloatingUI.isMousePressed) {
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
if (this.element.noHideOnThisFocusLoss ||
|
|
1861
|
+
this.element.hasAttribute('noHideOnThisFocusLoss')) {
|
|
1862
|
+
return;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
const { activeElement } = document;
|
|
1866
|
+
// if focus is still inside of trigger or bib, do not close
|
|
1867
|
+
if (this.element.contains(activeElement) || this.element.bib?.contains(activeElement)) {
|
|
1868
|
+
return;
|
|
1869
|
+
}
|
|
1870
|
+
// if fullscreen bib is still open and the focus is missing, do not close
|
|
1871
|
+
if (this.element.bib.hasAttribute('isfullscreen') && activeElement === document.body) {
|
|
1872
|
+
return;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
this.hideBib();
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1878
|
+
setupHideHandlers() {
|
|
1879
|
+
this.preventFocusLoseOnBibClick = (event) => {
|
|
1880
|
+
event.preventDefault();
|
|
1881
|
+
event.stopPropagation();
|
|
1882
|
+
};
|
|
1883
|
+
this.element.bib.addEventListener('mousedown', this.preventFocusLoseOnBibClick);
|
|
1884
|
+
|
|
1885
|
+
// Define handlers & store references
|
|
1886
|
+
this.focusHandler = () => this.handleFocusLoss();
|
|
1887
|
+
|
|
1888
|
+
this.clickHandler = (evt) => {
|
|
1889
|
+
if ((!evt.composedPath().includes(this.element.trigger) &&
|
|
1890
|
+
!evt.composedPath().includes(this.element.bib)) ||
|
|
1891
|
+
(this.element.bib.backdrop && evt.composedPath().includes(this.element.bib.backdrop))) {
|
|
1892
|
+
const existedVisibleFloatingUI = document.expandedAuroFormkitDropdown || document.expandedAuroFloater;
|
|
1893
|
+
|
|
1894
|
+
if (existedVisibleFloatingUI && existedVisibleFloatingUI.element.isPopoverVisible) {
|
|
1895
|
+
// if something else is open, close that
|
|
1896
|
+
existedVisibleFloatingUI.hideBib();
|
|
1897
|
+
document.expandedAuroFormkitDropdown = null;
|
|
1898
|
+
document.expandedAuroFloater = this;
|
|
1899
|
+
} else {
|
|
1900
|
+
this.hideBib();
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
};
|
|
1904
|
+
|
|
1905
|
+
// ESC key handler
|
|
1906
|
+
this.keyDownHandler = (evt) => {
|
|
1907
|
+
if (evt.key === 'Escape' && this.element.isPopoverVisible) {
|
|
1908
|
+
const existedVisibleFloatingUI = document.expandedAuroFormkitDropdown || document.expandedAuroFloater;
|
|
1909
|
+
if (existedVisibleFloatingUI && existedVisibleFloatingUI !== this && existedVisibleFloatingUI.element.isPopoverVisible) {
|
|
1910
|
+
// if something else is open, let it handle itself
|
|
1911
|
+
return;
|
|
1912
|
+
}
|
|
1913
|
+
this.hideBib();
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
|
|
1917
|
+
if (this.behavior !== 'drawer' && this.behavior !== 'dialog') {
|
|
1918
|
+
// Add event listeners using the stored references
|
|
1919
|
+
document.addEventListener('focusin', this.focusHandler);
|
|
1920
|
+
}
|
|
1921
|
+
|
|
1922
|
+
document.addEventListener('keydown', this.keyDownHandler);
|
|
1923
|
+
|
|
1924
|
+
// send this task to the end of queue to prevent conflicting
|
|
1925
|
+
// it conflicts if showBib gets call from a button that's not this.element.trigger
|
|
1926
|
+
setTimeout(() => {
|
|
1927
|
+
window.addEventListener('click', this.clickHandler);
|
|
1928
|
+
}, 0);
|
|
1929
|
+
}
|
|
1930
|
+
|
|
1931
|
+
cleanupHideHandlers() {
|
|
1932
|
+
// Remove event listeners if they exist
|
|
1933
|
+
|
|
1934
|
+
if (this.preventFocusLoseOnBibClick) {
|
|
1935
|
+
this.element.bib.removeEventListener('mousedown', this.preventFocusLoseOnBibClick);
|
|
1936
|
+
delete this.preventFocusLoseOnBibClick;
|
|
1937
|
+
}
|
|
1938
|
+
|
|
1939
|
+
if (this.focusHandler) {
|
|
1940
|
+
document.removeEventListener('focusin', this.focusHandler);
|
|
1941
|
+
this.focusHandler = null;
|
|
1942
|
+
}
|
|
1943
|
+
|
|
1944
|
+
if (this.clickHandler) {
|
|
1945
|
+
window.removeEventListener('click', this.clickHandler);
|
|
1946
|
+
this.clickHandler = null;
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
if (this.keyDownHandler) {
|
|
1950
|
+
document.removeEventListener('keydown', this.keyDownHandler);
|
|
1951
|
+
this.keyDownHandler = null;
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
handleUpdate(changedProperties) {
|
|
1956
|
+
if (changedProperties.has('isPopoverVisible')) {
|
|
1957
|
+
this.updateState();
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
updateCurrentExpandedDropdown() {
|
|
1962
|
+
// Close any other dropdown that is already open
|
|
1963
|
+
const existedVisibleFloatingUI = document.expandedAuroFormkitDropdown || document.expandedAuroFloater;
|
|
1964
|
+
if (existedVisibleFloatingUI && existedVisibleFloatingUI !== this &&
|
|
1965
|
+
existedVisibleFloatingUI.element.isPopoverVisible &&
|
|
1966
|
+
document.expandedAuroFloater.eventPrefix === this.eventPrefix) {
|
|
1967
|
+
document.expandedAuroFloater.hideBib();
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
document.expandedAuroFloater = this;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
showBib() {
|
|
1974
|
+
if (!this.element.disabled && !this.showing) {
|
|
1975
|
+
this.updateCurrentExpandedDropdown();
|
|
1976
|
+
this.element.triggerChevron?.setAttribute('data-expanded', true);
|
|
1977
|
+
|
|
1978
|
+
// prevent double showing: isPopovervisible gets first and showBib gets called later
|
|
1979
|
+
if (!this.showing) {
|
|
1980
|
+
if (!this.element.modal) {
|
|
1981
|
+
this.setupHideHandlers();
|
|
1982
|
+
}
|
|
1983
|
+
this.showing = true;
|
|
1984
|
+
this.element.isPopoverVisible = true;
|
|
1985
|
+
this.position();
|
|
1986
|
+
this.dispatchEventDropdownToggle();
|
|
1987
|
+
}
|
|
1988
|
+
|
|
1989
|
+
// Setup auto update to handle resize and scroll
|
|
1990
|
+
this.element.cleanup = autoUpdate(this.element.trigger || this.element.parentNode, this.element.bib, () => {
|
|
1991
|
+
this.position();
|
|
1992
|
+
});
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
hideBib() {
|
|
1997
|
+
if (!this.element.disabled && !this.element.noToggle) {
|
|
1998
|
+
this.lockScroll(false);
|
|
1999
|
+
this.element.triggerChevron?.removeAttribute('data-expanded');
|
|
2000
|
+
|
|
2001
|
+
if (this.element.isPopoverVisible) {
|
|
2002
|
+
this.element.isPopoverVisible = false;
|
|
2003
|
+
}
|
|
2004
|
+
if (this.showing) {
|
|
2005
|
+
this.cleanupHideHandlers();
|
|
2006
|
+
this.showing = false;
|
|
2007
|
+
this.dispatchEventDropdownToggle();
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
document.expandedAuroFloater = null;
|
|
2011
|
+
}
|
|
2012
|
+
|
|
2013
|
+
/**
|
|
2014
|
+
* @private
|
|
2015
|
+
* @returns {void} Dispatches event with an object showing the state of the dropdown.
|
|
2016
|
+
*/
|
|
2017
|
+
dispatchEventDropdownToggle() {
|
|
2018
|
+
const event = new CustomEvent(this.eventPrefix ? `${this.eventPrefix}-toggled` : 'toggled', {
|
|
2019
|
+
detail: {
|
|
2020
|
+
expanded: this.showing,
|
|
2021
|
+
},
|
|
2022
|
+
composed: true
|
|
2023
|
+
});
|
|
2024
|
+
|
|
2025
|
+
this.element.dispatchEvent(event);
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
handleClick() {
|
|
2029
|
+
if (this.element.isPopoverVisible) {
|
|
2030
|
+
this.hideBib();
|
|
2031
|
+
} else {
|
|
2032
|
+
this.showBib();
|
|
2033
|
+
}
|
|
2034
|
+
|
|
2035
|
+
const event = new CustomEvent(this.eventPrefix ? `${this.eventPrefix}-triggerClick` : "triggerClick", {
|
|
2036
|
+
composed: true,
|
|
2037
|
+
detail: {
|
|
2038
|
+
expanded: this.element.isPopoverVisible
|
|
2039
|
+
}
|
|
2040
|
+
});
|
|
2041
|
+
|
|
2042
|
+
this.element.dispatchEvent(event);
|
|
2043
|
+
}
|
|
2044
|
+
|
|
2045
|
+
handleEvent(event) {
|
|
2046
|
+
if (!this.element.disableEventShow) {
|
|
2047
|
+
switch (event.type) {
|
|
2048
|
+
case 'keydown':
|
|
2049
|
+
// Support both Enter and Space keys for accessibility
|
|
2050
|
+
// Space is included as it's expected behavior for interactive elements
|
|
2051
|
+
|
|
2052
|
+
const origin = event.composedPath()[0];
|
|
2053
|
+
if (event.key === 'Enter' || ((!origin || origin.tagName !== "INPUT") && event.key === ' ')) {
|
|
2054
|
+
event.preventDefault(); // Prevent page scroll on space
|
|
2055
|
+
this.handleClick();
|
|
2056
|
+
}
|
|
2057
|
+
break;
|
|
2058
|
+
case 'mouseenter':
|
|
2059
|
+
if (this.element.hoverToggle) {
|
|
2060
|
+
this.showBib();
|
|
2061
|
+
}
|
|
2062
|
+
break;
|
|
2063
|
+
case 'mouseleave':
|
|
2064
|
+
if (this.element.hoverToggle) {
|
|
2065
|
+
this.hideBib();
|
|
2066
|
+
}
|
|
2067
|
+
break;
|
|
2068
|
+
case 'focus':
|
|
2069
|
+
if (this.element.focusShow) {
|
|
2070
|
+
|
|
2071
|
+
/*
|
|
2072
|
+
This needs to better handle clicking that gives focus -
|
|
2073
|
+
currently it shows and then immediately hides the bib
|
|
2074
|
+
*/
|
|
2075
|
+
this.showBib();
|
|
2076
|
+
}
|
|
2077
|
+
break;
|
|
2078
|
+
case 'blur':
|
|
2079
|
+
// send this task 100ms later queue to
|
|
2080
|
+
// wait a frame in case focus moves within the floating element/bib
|
|
2081
|
+
setTimeout(() => this.handleFocusLoss(), 0);
|
|
2082
|
+
break;
|
|
2083
|
+
case 'click':
|
|
2084
|
+
if (document.activeElement === document.body) {
|
|
2085
|
+
event.currentTarget.focus();
|
|
2086
|
+
}
|
|
2087
|
+
this.handleClick();
|
|
2088
|
+
break;
|
|
2089
|
+
// Do nothing
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
}
|
|
2093
|
+
|
|
2094
|
+
/**
|
|
2095
|
+
* Manages the tabIndex of the trigger element based on its focusability.
|
|
2096
|
+
*
|
|
2097
|
+
* If the trigger element or any of its children are inherently focusable, the tabIndex of the component is set to -1.
|
|
2098
|
+
* This prevents the component itself from being focusable when the trigger element already handles focus.
|
|
2099
|
+
*/
|
|
2100
|
+
handleTriggerTabIndex() {
|
|
2101
|
+
const focusableElementSelectors = [
|
|
2102
|
+
'a',
|
|
2103
|
+
'button',
|
|
2104
|
+
'input:not([type="hidden"])',
|
|
2105
|
+
'select',
|
|
2106
|
+
'textarea',
|
|
2107
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
2108
|
+
'auro-button',
|
|
2109
|
+
'auro-input',
|
|
2110
|
+
'auro-hyperlink'
|
|
2111
|
+
];
|
|
2112
|
+
|
|
2113
|
+
const triggerNode = this.element.querySelectorAll('[slot="trigger"]')[0];
|
|
2114
|
+
if (!triggerNode) {
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
const triggerNodeTagName = triggerNode.tagName.toLowerCase();
|
|
2118
|
+
|
|
2119
|
+
focusableElementSelectors.forEach((selector) => {
|
|
2120
|
+
// Check if the trigger node element is focusable
|
|
2121
|
+
if (triggerNodeTagName === selector) {
|
|
2122
|
+
this.element.tabIndex = -1;
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
// Check if any child is focusable
|
|
2127
|
+
if (triggerNode.querySelector(selector)) {
|
|
2128
|
+
this.element.tabIndex = -1;
|
|
2129
|
+
}
|
|
2130
|
+
});
|
|
2131
|
+
}
|
|
2132
|
+
|
|
2133
|
+
/**
|
|
2134
|
+
*
|
|
2135
|
+
* @param {*} eventPrefix
|
|
2136
|
+
*/
|
|
2137
|
+
regenerateBibId() {
|
|
2138
|
+
this.id = this.element.getAttribute('id');
|
|
2139
|
+
if (!this.id) {
|
|
2140
|
+
this.id = window.crypto.randomUUID();
|
|
2141
|
+
this.element.setAttribute('id', this.id);
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
this.element.bib.setAttribute("id", `${this.id}-floater-bib`);
|
|
2145
|
+
}
|
|
2146
|
+
|
|
2147
|
+
configure(elem, eventPrefix) {
|
|
2148
|
+
AuroFloatingUI.setupMousePressChecker();
|
|
2149
|
+
|
|
2150
|
+
this.eventPrefix = eventPrefix;
|
|
2151
|
+
if (this.element !== elem) {
|
|
2152
|
+
this.element = elem;
|
|
2153
|
+
}
|
|
2154
|
+
|
|
2155
|
+
if (this.behavior !== this.element.behavior) {
|
|
2156
|
+
this.behavior = this.element.behavior;
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
if (this.element.trigger) {
|
|
2160
|
+
this.disconnect();
|
|
2161
|
+
}
|
|
2162
|
+
this.element.trigger = this.element.triggerElement || this.element.shadowRoot.querySelector('#trigger') || this.element.trigger;
|
|
2163
|
+
this.element.bib = this.element.shadowRoot.querySelector('#bib') || this.element.bib;
|
|
2164
|
+
this.element.bibSizer = this.element.shadowRoot.querySelector('#bibSizer');
|
|
2165
|
+
this.element.triggerChevron = this.element.shadowRoot.querySelector('#showStateIcon');
|
|
2166
|
+
|
|
2167
|
+
|
|
2168
|
+
if (this.element.floaterConfig) {
|
|
2169
|
+
this.element.hoverToggle = this.element.floaterConfig.hoverToggle;
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
document.body.append(this.element.bib);
|
|
2173
|
+
|
|
2174
|
+
this.regenerateBibId();
|
|
2175
|
+
this.handleTriggerTabIndex();
|
|
2176
|
+
|
|
2177
|
+
this.handleEvent = this.handleEvent.bind(this);
|
|
2178
|
+
if (this.element.trigger) {
|
|
2179
|
+
this.element.trigger.addEventListener('keydown', this.handleEvent);
|
|
2180
|
+
this.element.trigger.addEventListener('click', this.handleEvent);
|
|
2181
|
+
this.element.trigger.addEventListener('mouseenter', this.handleEvent);
|
|
2182
|
+
this.element.trigger.addEventListener('mouseleave', this.handleEvent);
|
|
2183
|
+
this.element.trigger.addEventListener('focus', this.handleEvent);
|
|
2184
|
+
this.element.trigger.addEventListener('blur', this.handleEvent);
|
|
2185
|
+
}
|
|
2186
|
+
}
|
|
2187
|
+
|
|
2188
|
+
disconnect() {
|
|
2189
|
+
this.cleanupHideHandlers();
|
|
2190
|
+
if (this.element) {
|
|
2191
|
+
this.element.cleanup?.();
|
|
2192
|
+
|
|
2193
|
+
if (this.element.bib) {
|
|
2194
|
+
this.element.shadowRoot.append(this.element.bib);
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
// Remove event & keyboard listeners
|
|
2198
|
+
if (this.element?.trigger) {
|
|
2199
|
+
this.element.trigger.removeEventListener('keydown', this.handleEvent);
|
|
2200
|
+
this.element.trigger.removeEventListener('click', this.handleEvent);
|
|
2201
|
+
this.element.trigger.removeEventListener('mouseenter', this.handleEvent);
|
|
2202
|
+
this.element.trigger.removeEventListener('mouseleave', this.handleEvent);
|
|
2203
|
+
this.element.trigger.removeEventListener('focus', this.handleEvent);
|
|
2204
|
+
this.element.trigger.removeEventListener('blur', this.handleEvent);
|
|
2205
|
+
}
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
2211
|
+
// See LICENSE in the project root for license information.
|
|
2212
|
+
|
|
2213
|
+
|
|
2214
|
+
class AuroDependencyVersioning {
|
|
2215
|
+
|
|
2216
|
+
/**
|
|
2217
|
+
* Generates a unique string to be used for child auro element naming.
|
|
2218
|
+
* @private
|
|
2219
|
+
* @param {string} baseName - Defines the first part of the unique element name.
|
|
2220
|
+
* @param {string} version - Version of the component that will be appended to the baseName.
|
|
2221
|
+
* @returns {string} - Unique string to be used for naming.
|
|
2222
|
+
*/
|
|
2223
|
+
generateElementName(baseName, version) {
|
|
2224
|
+
let result = baseName;
|
|
2225
|
+
|
|
2226
|
+
result += '-';
|
|
2227
|
+
result += version.replace(/[.]/g, '_');
|
|
2228
|
+
|
|
2229
|
+
return result;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
/**
|
|
2233
|
+
* Generates a unique string to be used for child auro element naming.
|
|
2234
|
+
* @param {string} baseName - Defines the first part of the unique element name.
|
|
2235
|
+
* @param {string} version - Version of the component that will be appended to the baseName.
|
|
2236
|
+
* @returns {string} - Unique string to be used for naming.
|
|
2237
|
+
*/
|
|
2238
|
+
generateTag(baseName, version, tagClass) {
|
|
2239
|
+
const elementName = this.generateElementName(baseName, version);
|
|
2240
|
+
const tag = literal`${unsafeStatic(elementName)}`;
|
|
2241
|
+
|
|
2242
|
+
if (!customElements.get(elementName)) {
|
|
2243
|
+
customElements.define(elementName, class extends tagClass {});
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
return tag;
|
|
2247
|
+
}
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
// Copyright (c) 2020 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
|
|
2251
|
+
// See LICENSE in the project root for license information.
|
|
2252
|
+
|
|
2253
|
+
|
|
2254
|
+
/**
|
|
2255
|
+
* @attr {Boolean} hidden - If present, the component will be hidden both visually and from screen readers
|
|
2256
|
+
* @attr {Boolean} hiddenVisually - If present, the component will be hidden visually, but still read by screen readers
|
|
2257
|
+
* @attr {Boolean} hiddenAudible - If present, the component will be hidden from screen readers, but seen visually
|
|
2258
|
+
*/
|
|
2259
|
+
|
|
2260
|
+
class AuroElement extends LitElement {
|
|
2261
|
+
|
|
2262
|
+
// function to define props used within the scope of this component
|
|
2263
|
+
static get properties() {
|
|
2264
|
+
return {
|
|
2265
|
+
hidden: { type: Boolean,
|
|
2266
|
+
reflect: true },
|
|
2267
|
+
hiddenVisually: { type: Boolean,
|
|
2268
|
+
reflect: true },
|
|
2269
|
+
hiddenAudible: { type: Boolean,
|
|
2270
|
+
reflect: true },
|
|
2271
|
+
};
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
/**
|
|
2275
|
+
* @private Function that determines state of aria-hidden
|
|
2276
|
+
*/
|
|
2277
|
+
hideAudible(value) {
|
|
2278
|
+
if (value) {
|
|
2279
|
+
return 'true'
|
|
2280
|
+
}
|
|
2281
|
+
|
|
2282
|
+
return 'false'
|
|
2283
|
+
}
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
var error = {"svg":"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" aria-labelledby=\"error__desc\" class=\"ico_squareLarge\" data-deprecated=\"true\" role=\"img\" style=\"min-width:var(--auro-size-lg, var(--ds-size-300, 1.5rem));height:var(--auro-size-lg, var(--ds-size-300, 1.5rem));fill:currentColor\" viewBox=\"0 0 24 24\" part=\"svg\"><title/><desc id=\"error__desc\">Error alert indicator.</desc><path d=\"m13.047 5.599 6.786 11.586A1.207 1.207 0 0 1 18.786 19H5.214a1.207 1.207 0 0 1-1.047-1.815l6.786-11.586a1.214 1.214 0 0 1 2.094 0m-1.165.87a.23.23 0 0 0-.085.085L5.419 17.442a.232.232 0 0 0 .203.35h12.756a.234.234 0 0 0 .203-.35L12.203 6.554a.236.236 0 0 0-.321-.084M12 15.5a.75.75 0 1 1 0 1.5.75.75 0 0 1 0-1.5m-.024-6.22c.325 0 .589.261.589.583v4.434a.586.586 0 0 1-.589.583.586.586 0 0 1-.588-.583V9.863c0-.322.264-.583.588-.583\"/></svg>"};
|
|
2287
|
+
|
|
2288
|
+
/* eslint-disable no-underscore-dangle, jsdoc/no-undefined-types, jsdoc/require-param-description */
|
|
2289
|
+
|
|
2290
|
+
const _fetchMap = new Map();
|
|
2291
|
+
|
|
2292
|
+
/**
|
|
2293
|
+
* A callback to parse Response body.
|
|
2294
|
+
*
|
|
2295
|
+
* @callback ResponseParser
|
|
2296
|
+
* @param {Fetch.Response} response
|
|
2297
|
+
* @returns {Promise}
|
|
2298
|
+
*/
|
|
2299
|
+
|
|
2300
|
+
/**
|
|
2301
|
+
* A minimal in-memory map to de-duplicate Fetch API media requests.
|
|
2302
|
+
*
|
|
2303
|
+
* @param {String} uri
|
|
2304
|
+
* @param {Object} [options={}]
|
|
2305
|
+
* @param {ResponseParser} [options.responseParser=(response) => response.text()]
|
|
2306
|
+
* @returns {Promise}
|
|
2307
|
+
*/
|
|
2308
|
+
const cacheFetch = (uri, options = {}) => {
|
|
2309
|
+
const responseParser = options.responseParser || ((response) => response.text());
|
|
2310
|
+
if (!_fetchMap.has(uri)) {
|
|
2311
|
+
_fetchMap.set(uri, fetch(uri).then(responseParser));
|
|
2312
|
+
}
|
|
2313
|
+
return _fetchMap.get(uri);
|
|
2314
|
+
};
|
|
2315
|
+
|
|
2316
|
+
var styleCss$3 = css`:focus:not(:focus-visible){outline:3px solid transparent}.util_displayInline{display:inline}.util_displayInlineBlock{display:inline-block}.util_displayBlock,:host{display:block}.util_displayFlex{display:flex}.util_displayHidden,:host([hidden]:not(:focus):not(:active)){display:none}.util_displayHiddenVisually,:host([hiddenVisually]:not(:focus):not(:active)){position:absolute;overflow:hidden;clip:rect(1px, 1px, 1px, 1px);width:1px;height:1px;padding:0;border:0}.ico_squareLarge{fill:currentColor;height:var(--auro-size-lg, var(--ds-size-300, 1.5rem))}.ico_squareSmall{fill:currentColor;height:.6rem}.ico_squareMed{fill:currentColor;height:var(--auro-size-md, var(--ds-size-200, 1rem))}.ico_squareSml{fill:currentColor;height:var(--auro-size-sm, var(--ds-size-150, 0.75rem))}:host{color:currentColor;vertical-align:middle;line-height:1;display:inline-block}svg{min-width:var(--ds-auro-icon-size, 1.5rem) !important;width:var(--ds-auro-icon-size, 1.5rem) !important;height:var(--ds-auro-icon-size, 1.5rem) !important}.componentWrapper{display:flex}.svgWrapper{height:var(--ds-auro-icon-size);width:var(--ds-auro-icon-size)}.labelWrapper{margin-left:var(--ds-size-50, 0.25rem);line-height:1.8}`;
|
|
2317
|
+
|
|
2318
|
+
// Copyright (c) 2020 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
|
|
2319
|
+
// See LICENSE in the project root for license information.
|
|
2320
|
+
|
|
2321
|
+
|
|
2322
|
+
// See https://git.io/JJ6SJ for "How to document your components using JSDoc"
|
|
2323
|
+
/**
|
|
2324
|
+
* @slot - Hidden from visibility, used for a11y if icon description is needed
|
|
2325
|
+
*/
|
|
2326
|
+
|
|
2327
|
+
// build the component class
|
|
2328
|
+
class BaseIcon extends AuroElement {
|
|
2329
|
+
constructor() {
|
|
2330
|
+
super();
|
|
2331
|
+
this.onDark = false;
|
|
2332
|
+
}
|
|
2333
|
+
|
|
2334
|
+
// function to define props used within the scope of this component
|
|
2335
|
+
static get properties() {
|
|
2336
|
+
return {
|
|
2337
|
+
...super.properties,
|
|
2338
|
+
|
|
2339
|
+
/**
|
|
2340
|
+
* Set value for on-dark version of auro-icon.
|
|
2341
|
+
*/
|
|
2342
|
+
onDark: {
|
|
2343
|
+
type: Boolean,
|
|
2344
|
+
reflect: true
|
|
2345
|
+
},
|
|
2346
|
+
|
|
2347
|
+
/**
|
|
2348
|
+
* @private
|
|
2349
|
+
*/
|
|
2350
|
+
svg: {
|
|
2351
|
+
attribute: false,
|
|
2352
|
+
reflect: true
|
|
2353
|
+
}
|
|
2354
|
+
};
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
static get styles() {
|
|
2358
|
+
return css`
|
|
2359
|
+
${styleCss$3}
|
|
2360
|
+
`;
|
|
2361
|
+
}
|
|
2362
|
+
|
|
2363
|
+
/**
|
|
2364
|
+
* Async function to fetch requested icon from npm CDN.
|
|
2365
|
+
* @private
|
|
2366
|
+
* @param {string} category - Icon category.
|
|
2367
|
+
* @param {string} name - Icon name.
|
|
2368
|
+
* @returns {SVGElement} DOM - Ready HTML to be appended.
|
|
2369
|
+
*/
|
|
2370
|
+
async fetchIcon(category, name) {
|
|
2371
|
+
let iconHTML = '';
|
|
2372
|
+
|
|
2373
|
+
if (category === 'logos') {
|
|
2374
|
+
iconHTML = await cacheFetch(`${this.uri}/${category}/${name}.svg`);
|
|
2375
|
+
} else {
|
|
2376
|
+
iconHTML = await cacheFetch(`${this.uri}/icons/${category}/${name}.svg`);
|
|
2377
|
+
}
|
|
2378
|
+
|
|
2379
|
+
const dom = new DOMParser().parseFromString(iconHTML, 'text/html');
|
|
2380
|
+
|
|
2381
|
+
return dom.body.querySelector('svg');
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
// lifecycle function
|
|
2385
|
+
async firstUpdated() {
|
|
2386
|
+
if (!this.customSvg) {
|
|
2387
|
+
const svg = await this.fetchIcon(this.category, this.name);
|
|
2388
|
+
|
|
2389
|
+
if (svg) {
|
|
2390
|
+
this.svg = svg;
|
|
2391
|
+
} else if (!svg) {
|
|
2392
|
+
const penDOM = new DOMParser().parseFromString(error.svg, 'text/html');
|
|
2393
|
+
|
|
2394
|
+
this.svg = penDOM.body.firstChild;
|
|
2395
|
+
}
|
|
2396
|
+
}
|
|
2397
|
+
}
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
var tokensCss$2 = css`:host{--ds-auro-icon-color:var(--ds-basic-color-texticon-default, #2a2a2a);--ds-auro-alaska-color:#02426D;--ds-auro-icon-size:var(--ds-size-300, 1.5rem)}`;
|
|
2401
|
+
|
|
2402
|
+
var colorCss$3 = css`:host{color:var(--ds-auro-icon-color)}:host([customColor]){color:inherit}:host(:not([onDark])[variant=accent1]){--ds-auro-icon-color:var(--ds-basic-color-texticon-accent1, #265688)}:host(:not([onDark])[variant=disabled]){--ds-auro-icon-color:var(--ds-basic-color-texticon-disabled, #d0d0d0)}:host(:not([onDark])[variant=muted]){--ds-auro-icon-color:var(--ds-basic-color-texticon-muted, #676767)}:host(:not([onDark])[variant=statusDefault]){--ds-auro-icon-color:var(--ds-basic-color-status-default, #afb9c6)}:host(:not([onDark])[variant=statusInfo]){--ds-auro-icon-color:var(--ds-basic-color-status-info, #01426a)}:host(:not([onDark])[variant=statusSuccess]){--ds-auro-icon-color:var(--ds-basic-color-status-success, #447a1f)}:host(:not([onDark])[variant=statusWarning]){--ds-auro-icon-color:var(--ds-basic-color-status-warning, #fac200)}:host(:not([onDark])[variant=statusError]){--ds-auro-icon-color:var(--ds-basic-color-status-error, #e31f26)}:host(:not([onDark])[variant=statusInfoSubtle]){--ds-auro-icon-color:var(--ds-basic-color-status-info-subtle, #ebf3f9)}:host(:not([onDark])[variant=statusSuccessSubtle]){--ds-auro-icon-color:var(--ds-basic-color-status-success-subtle, #d6eac7)}:host(:not([onDark])[variant=statusWarningSubtle]){--ds-auro-icon-color:var(--ds-basic-color-status-warning-subtle, #fff0b2)}:host(:not([onDark])[variant=statusErrorSubtle]){--ds-auro-icon-color:var(--ds-basic-color-status-error-subtle, #fbc6c6)}:host(:not([onDark])[variant=fareBasicEconomy]){--ds-auro-icon-color:var(--ds-basic-color-fare-basiceconomy, #97eaf8)}:host(:not([onDark])[variant=fareBusiness]){--ds-auro-icon-color:var(--ds-basic-color-fare-business, #01426a)}:host(:not([onDark])[variant=fareEconomy]){--ds-auro-icon-color:var(--ds-basic-color-fare-economy, #0074ca)}:host(:not([onDark])[variant=fareFirst]){--ds-auro-icon-color:var(--ds-basic-color-fare-first, #00274a)}:host(:not([onDark])[variant=farePremiumEconomy]){--ds-auro-icon-color:var(--ds-basic-color-fare-premiumeconomy, #005154)}:host(:not([onDark])[variant=tierOneWorldEmerald]){--ds-auro-icon-color:var(--ds-basic-color-tier-program-oneworld-emerald, #139142)}:host(:not([onDark])[variant=tierOneWorldSapphire]){--ds-auro-icon-color:var(--ds-basic-color-tier-program-oneworld-sapphire, #015daa)}:host(:not([onDark])[variant=tierOneWorldRuby]){--ds-auro-icon-color:var(--ds-basic-color-tier-program-oneworld-ruby, #a41d4a)}:host([onDark]){--ds-auro-icon-color:var(--ds-basic-color-texticon-inverse, #ffffff)}:host([onDark][variant=disabled]){--ds-auro-icon-color:var(--ds-basic-color-texticon-inverse-disabled, #7e8894)}:host([onDark][variant=muted]){--ds-auro-icon-color:var(--ds-basic-color-texticon-inverse-muted, #ccd2db)}`;
|
|
2403
|
+
|
|
2404
|
+
// Copyright (c) 2025 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
|
|
2405
|
+
// See LICENSE in the project root for license information.
|
|
2406
|
+
|
|
2407
|
+
|
|
2408
|
+
class AuroIcon extends BaseIcon {
|
|
2409
|
+
constructor() {
|
|
2410
|
+
super();
|
|
2411
|
+
|
|
2412
|
+
this.variant = undefined;
|
|
2413
|
+
this.privateDefaults();
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
/**
|
|
2417
|
+
* Internal Defaults.
|
|
2418
|
+
* @private
|
|
2419
|
+
* @returns {void}
|
|
2420
|
+
*/
|
|
2421
|
+
privateDefaults() {
|
|
2422
|
+
this.uri = 'https://cdn.jsdelivr.net/npm/@alaskaairux/icons@latest/dist';
|
|
2423
|
+
this.runtimeUtils = new AuroLibraryRuntimeUtils$1();
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
// function to define props used within the scope of this component
|
|
2427
|
+
static get properties() {
|
|
2428
|
+
return {
|
|
2429
|
+
...super.properties,
|
|
2430
|
+
|
|
2431
|
+
/**
|
|
2432
|
+
* Set aria-hidden value. Default is `true`. Option is `false`.
|
|
2433
|
+
*/
|
|
2434
|
+
ariaHidden: {
|
|
2435
|
+
type: String,
|
|
2436
|
+
reflect: true
|
|
2437
|
+
},
|
|
2438
|
+
|
|
2439
|
+
/**
|
|
2440
|
+
* The category of the icon you are looking for. See https://auro.alaskaair.com/icons/usage.
|
|
2441
|
+
*/
|
|
2442
|
+
category: {
|
|
2443
|
+
type: String,
|
|
2444
|
+
reflect: true
|
|
2445
|
+
},
|
|
2446
|
+
|
|
2447
|
+
/**
|
|
2448
|
+
* Allows custom color to be set.
|
|
2449
|
+
*/
|
|
2450
|
+
customColor: {
|
|
2451
|
+
type: Boolean
|
|
2452
|
+
},
|
|
2453
|
+
|
|
2454
|
+
/**
|
|
2455
|
+
* When true, auro-icon will render a custom SVG inside the default slot.
|
|
2456
|
+
*/
|
|
2457
|
+
customSvg: {
|
|
2458
|
+
type: Boolean
|
|
2459
|
+
},
|
|
2460
|
+
|
|
2461
|
+
/**
|
|
2462
|
+
* Exposes content in slot as icon label.
|
|
2463
|
+
*/
|
|
2464
|
+
label: {
|
|
2465
|
+
type: Boolean,
|
|
2466
|
+
reflect: true
|
|
2467
|
+
},
|
|
2468
|
+
|
|
2469
|
+
/**
|
|
2470
|
+
* The name of the icon you are looking for without the file extension. See https://auro.alaskaair.com/icons/usage.
|
|
2471
|
+
*/
|
|
2472
|
+
name: {
|
|
2473
|
+
type: String,
|
|
2474
|
+
reflect: true
|
|
2475
|
+
},
|
|
2476
|
+
|
|
2477
|
+
/**
|
|
2478
|
+
* The style of the icon. The accepted variants are `accent1`, `disabled`, `muted`, `statusDefault`, `statusInfo`, `statusSuccess`, `statusWarning`, `statusError`, `statusInfoSubtle`, `statusSuccessSubtle`, `statusWarningSubtle`, `statusErrorSubtle`, `fareBasicEconomy`, `fareBusiness`, `fareEconomy`, `fareFirst`, `farePremiumEconomy`, `tierOneWorldEmerald`, `tierOneWorldSapphire`, `tierOneWorldRuby`.
|
|
2479
|
+
*/
|
|
2480
|
+
variant: {
|
|
2481
|
+
type: String,
|
|
2482
|
+
reflect: true
|
|
2483
|
+
}
|
|
2484
|
+
};
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
static get styles() {
|
|
2488
|
+
return [
|
|
2489
|
+
super.styles,
|
|
2490
|
+
css`${tokensCss$2}`,
|
|
2491
|
+
css`${styleCss$3}`,
|
|
2492
|
+
css`${colorCss$3}`
|
|
2493
|
+
];
|
|
2494
|
+
}
|
|
2495
|
+
|
|
2496
|
+
/**
|
|
2497
|
+
* This will register this element with the browser.
|
|
2498
|
+
* @param {string} [name="auro-icon"] - The name of element that you want to register to.
|
|
2499
|
+
*
|
|
2500
|
+
* @example
|
|
2501
|
+
* AuroIcon.register("custom-icon") // this will register this element to <custom-icon/>
|
|
2502
|
+
*
|
|
2503
|
+
*/
|
|
2504
|
+
static register(name = "auro-icon") {
|
|
2505
|
+
AuroLibraryRuntimeUtils$1.prototype.registerComponent(name, AuroIcon);
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
connectedCallback() {
|
|
2509
|
+
super.connectedCallback();
|
|
2510
|
+
|
|
2511
|
+
// Add the tag name as an attribute if it is different than the component name
|
|
2512
|
+
this.runtimeUtils.handleComponentTagRename(this, 'auro-icon');
|
|
2513
|
+
}
|
|
2514
|
+
|
|
2515
|
+
/**
|
|
2516
|
+
* @private
|
|
2517
|
+
* @returns {void} Exposes CSS parts for styling from parent components.
|
|
2518
|
+
*/
|
|
2519
|
+
exposeCssParts() {
|
|
2520
|
+
this.setAttribute('exportparts', 'svg:iconSvg');
|
|
2521
|
+
}
|
|
2522
|
+
|
|
2523
|
+
async firstUpdated() {
|
|
2524
|
+
await super.firstUpdated();
|
|
2525
|
+
|
|
2526
|
+
// Removes the SVG description for screenreader if ariaHidden is set to true
|
|
2527
|
+
if (!this.hasAttribute('ariaHidden') && this.svg) {
|
|
2528
|
+
const svgDesc = this.svg.querySelector('desc');
|
|
2529
|
+
|
|
2530
|
+
if (svgDesc) {
|
|
2531
|
+
svgDesc.remove();
|
|
2532
|
+
this.svg.removeAttribute('aria-labelledby');
|
|
2533
|
+
}
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
|
|
2537
|
+
// function that renders the HTML and CSS into the scope of the component
|
|
2538
|
+
render() {
|
|
2539
|
+
const labelClasses = {
|
|
2540
|
+
'labelWrapper': true,
|
|
2541
|
+
'util_displayHiddenVisually': !this.label
|
|
2542
|
+
};
|
|
2543
|
+
|
|
2544
|
+
const svgClasses = {
|
|
2545
|
+
'svgWrapper': true,
|
|
2546
|
+
};
|
|
2547
|
+
|
|
2548
|
+
return html`
|
|
2549
|
+
<div class="componentWrapper">
|
|
2550
|
+
<div
|
|
2551
|
+
class="${classMap(svgClasses)}"
|
|
2552
|
+
title="${ifDefined(this.title || undefined)}">
|
|
2553
|
+
<span aria-hidden="${ifDefined(this.ariaHidden || true)}" part="svg">
|
|
2554
|
+
${this.customSvg ? html`
|
|
2555
|
+
<slot name="svg"></slot>
|
|
2556
|
+
` : html`
|
|
2557
|
+
${this.svg}
|
|
2558
|
+
`
|
|
2559
|
+
}
|
|
2560
|
+
</span>
|
|
2561
|
+
</div>
|
|
2562
|
+
|
|
2563
|
+
<div class="${classMap(labelClasses)}">
|
|
2564
|
+
<slot></slot>
|
|
2565
|
+
</div>
|
|
2566
|
+
</div>
|
|
2567
|
+
`;
|
|
2568
|
+
}
|
|
2569
|
+
}
|
|
2570
|
+
|
|
2571
|
+
var iconVersion = '6.1.2';
|
|
2572
|
+
|
|
2573
|
+
var styleCss$2 = css`:host{position:absolute;z-index:var(--depth-tooltip, 400);display:none}.container{display:inline-block;overflow:auto;box-sizing:border-box;margin:var(--ds-size-50, 0.25rem) 0}:host([isfullscreen]){position:fixed;top:0;left:0}:host([isfullscreen]) .container{width:100dvw;max-width:none;height:100dvh;max-height:none;border-radius:unset;margin-top:0;box-shadow:unset;overscroll-behavior:contain}:host([data-show]){display:flex}:host([common]:not([isfullscreen])) .container,:host([rounded]:not([isfullscreen])) .container{border-radius:var(--ds-border-radius, 0.375rem)}:host([common][isfullscreen]) .container,:host([rounded][isfullscreen]) .container{border-radius:unset;box-shadow:unset}`;
|
|
2574
|
+
|
|
2575
|
+
var colorCss$2 = css`.container{background-color:var(--ds-auro-dropdownbib-container-color);box-shadow:var(--ds-auro-dropdownbib-boxshadow-color);color:var(--ds-auro-dropdownbib-text-color)}`;
|
|
2576
|
+
|
|
2577
|
+
var tokensCss$1 = css`:host{--ds-auro-dropdown-label-text-color: var(--ds-basic-color-texticon-muted, #676767);--ds-auro-dropdown-trigger-container-color: var(--ds-basic-color-surface-default, #ffffff);--ds-auro-dropdown-trigger-border-color: transparent;--ds-auro-dropdown-trigger-outline-color: transparent;--ds-auro-dropdown-trigger-text-color: var(--ds-basic-color-texticon-default, #2a2a2a);--ds-auro-dropdownbib-boxshadow-color: var(--ds-elevation-200, 0px 0px 10px rgba(0, 0, 0, 0.15));--ds-auro-dropdownbib-container-color: var(--ds-basic-color-surface-default, #ffffff);--ds-auro-dropdownbib-text-color: var(--ds-basic-color-texticon-default, #2a2a2a)}`;
|
|
2578
|
+
|
|
2579
|
+
// Copyright (c) 2020 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
|
|
2580
|
+
// See LICENSE in the project root for license information.
|
|
2581
|
+
|
|
2582
|
+
|
|
2583
|
+
|
|
2584
|
+
const DESIGN_TOKEN_BREAKPOINT_PREFIX = '--ds-grid-breakpoint-';
|
|
2585
|
+
const DESIGN_TOKEN_BREAKPOINT_OPTIONS = [
|
|
2586
|
+
'xl',
|
|
2587
|
+
'lg',
|
|
2588
|
+
'md',
|
|
2589
|
+
'sm',
|
|
2590
|
+
'xs',
|
|
2591
|
+
];
|
|
2592
|
+
|
|
2593
|
+
/**
|
|
2594
|
+
* @prop { String } fullscreenBreakpoint - Defines the screen size breakpoint (`lg`, `md`, `sm`, or `xs`) at which the dropdown switches to fullscreen mode on mobile. When expanded, the dropdown will automatically display in fullscreen mode if the screen size is equal to or smaller than the selected breakpoint.
|
|
2595
|
+
* @csspart bibContainer - Apply css to the bib container.
|
|
2596
|
+
*/
|
|
2597
|
+
|
|
2598
|
+
class AuroDropdownBib extends LitElement {
|
|
2599
|
+
|
|
2600
|
+
constructor() {
|
|
2601
|
+
super();
|
|
2602
|
+
|
|
2603
|
+
/**
|
|
2604
|
+
* @private
|
|
2605
|
+
*/
|
|
2606
|
+
this._mobileBreakpointValue = undefined;
|
|
2607
|
+
|
|
2608
|
+
AuroLibraryRuntimeUtils$1.prototype.handleComponentTagRename(this, 'auro-dropdownbib');
|
|
2609
|
+
}
|
|
2610
|
+
|
|
2611
|
+
static get styles() {
|
|
2612
|
+
return [
|
|
2613
|
+
styleCss$2,
|
|
2614
|
+
colorCss$2,
|
|
2615
|
+
tokensCss$1
|
|
2616
|
+
];
|
|
2617
|
+
}
|
|
2618
|
+
|
|
2619
|
+
static get properties() {
|
|
2620
|
+
return {
|
|
2621
|
+
|
|
2622
|
+
/**
|
|
2623
|
+
* If declared, will take the fullscreen when the bib is displayed.
|
|
2624
|
+
*/
|
|
2625
|
+
isFullscreen: {
|
|
2626
|
+
type: Boolean,
|
|
2627
|
+
reflect: true
|
|
2628
|
+
},
|
|
2629
|
+
|
|
2630
|
+
/**
|
|
2631
|
+
* If declared, will apply all styles for the common theme.
|
|
2632
|
+
*/
|
|
2633
|
+
common: {
|
|
2634
|
+
type: Boolean,
|
|
2635
|
+
reflect: true
|
|
2636
|
+
},
|
|
2637
|
+
|
|
2638
|
+
/**
|
|
2639
|
+
* If declared, will apply extra padding to bib content.
|
|
2640
|
+
*/
|
|
2641
|
+
inset: {
|
|
2642
|
+
type: Boolean,
|
|
2643
|
+
reflect: true
|
|
2644
|
+
},
|
|
2645
|
+
|
|
2646
|
+
/**
|
|
2647
|
+
* If declared, will apply border-radius to the bib.
|
|
2648
|
+
*/
|
|
2649
|
+
rounded: {
|
|
2650
|
+
type: Boolean,
|
|
2651
|
+
reflect: true
|
|
2652
|
+
},
|
|
2653
|
+
};
|
|
2654
|
+
}
|
|
2655
|
+
|
|
2656
|
+
set mobileFullscreenBreakpoint(value) {
|
|
2657
|
+
// verify the defined breakpoint is valid and exit out if not
|
|
2658
|
+
// 'disabled' is a design token breakpoint so it acts as our "undefined" value
|
|
2659
|
+
const validatedValue = DESIGN_TOKEN_BREAKPOINT_OPTIONS.includes(value) ? value : undefined;
|
|
2660
|
+
if (!validatedValue) {
|
|
2661
|
+
this._mobileBreakpointValue = undefined;
|
|
2662
|
+
} else {
|
|
2663
|
+
// get the pixel value for the defined breakpoint
|
|
2664
|
+
const docStyle = getComputedStyle(document.documentElement);
|
|
2665
|
+
this._mobileBreakpointValue = docStyle.getPropertyValue(DESIGN_TOKEN_BREAKPOINT_PREFIX + value);
|
|
2666
|
+
}
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
get mobileFullscreenBreakpoint() {
|
|
2670
|
+
return this._mobileBreakpointValue;
|
|
2671
|
+
}
|
|
2672
|
+
|
|
2673
|
+
updated(changedProperties) {
|
|
2674
|
+
if (changedProperties.has('isFullscreen')) {
|
|
2675
|
+
this.childNodes.forEach((child) => {
|
|
2676
|
+
// skip any text that is not in an HTMLElement on setting `isFullscreen` attr.
|
|
2677
|
+
if (child.nodeName !== '#text') {
|
|
2678
|
+
if (this.isFullscreen) {
|
|
2679
|
+
child.setAttribute('isFullscreen', 'true');
|
|
2680
|
+
} else {
|
|
2681
|
+
child.removeAttribute('isFullscreen');
|
|
2682
|
+
}
|
|
2683
|
+
}
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
// function that renders the HTML and CSS into the scope of the component
|
|
2689
|
+
render() {
|
|
2690
|
+
return html$1`
|
|
2691
|
+
<div class="container" part="bibContainer">
|
|
2692
|
+
<slot></slot>
|
|
2693
|
+
</div>
|
|
2694
|
+
`;
|
|
2695
|
+
}
|
|
2696
|
+
}
|
|
2697
|
+
|
|
2698
|
+
var dropdownVersion = '3.0.0';
|
|
2699
|
+
|
|
2700
|
+
var styleCss$1 = css`:host{position:relative;display:inline-block;max-width:100%}:host([fluid]){display:block}#bibSizer{position:absolute;z-index:-1;opacity:0;pointer-events:none}.label{font-size:var(--ds-basic-text-body-xs-font-size, 12px);font-weight:var(--ds-basic-text-body-xs-font-weight, 450);letter-spacing:var(--ds-basic-text-body-xs-letter-spacing, 0);line-height:var(--ds-basic-text-body-xs-line-height, 16px);transition:font-size .3s cubic-bezier(0.215, 0.61, 0.355, 1);white-space:normal}.label[hasTrigger=false]{font-size:var(--ds-basic-text-body-default-font-size, 16px);font-weight:var(--ds-basic-text-body-default-font-weight, 450);letter-spacing:var(--ds-basic-text-body-default-letter-spacing, 0);line-height:var(--ds-basic-text-body-default-line-height, 24px)}.trigger{position:relative;display:flex;align-items:center}.trigger[showBorder]{border-width:1px;border-style:solid;cursor:pointer;outline-style:solid;outline-width:1px}@media(hover: hover){.trigger:hover{cursor:pointer}}.triggerContentWrapper{overflow:hidden;flex:1;text-overflow:ellipsis;white-space:nowrap}#showStateIcon{display:flex;overflow:hidden;height:100%;align-items:center;margin-left:var(--ds-size-100, 0.5rem)}#showStateIcon [auro-icon]{height:var(--ds-size-300, 1.5rem);line-height:var(--ds-size-300, 1.5rem)}#showStateIcon[data-expanded=true] [auro-icon]{transform:rotate(-180deg)}:host([matchwidth]) #bibSizer{width:100%}:host([disabled]){pointer-events:none}:host([inset]) .trigger{padding:var(--ds-size-150, 0.75rem) var(--ds-size-200, 1rem)}:host([common]) .trigger,:host([inset][bordered]) .trigger{padding:var(--ds-size-200, 1rem) var(--ds-size-150, 0.75rem)}:host([inset][bordered][labeled]) .trigger{padding:var(--ds-size-100, 0.5rem) var(--ds-size-150, 0.75rem)}:host([common]) .trigger,:host([rounded]) .trigger{border-radius:var(--ds-border-radius, 0.375rem)}`;
|
|
2701
|
+
|
|
2702
|
+
var colorCss$1 = css`.label{color:var(--ds-auro-dropdown-label-text-color)}.trigger{border-color:var(--ds-auro-dropdown-trigger-border-color);background-color:var(--ds-auro-dropdown-trigger-container-color);color:var(--ds-auro-dropdown-trigger-text-color);outline-color:var(--ds-auro-dropdown-trigger-outline-color)}.trigger:focus-within,.trigger:active{--ds-auro-dropdown-trigger-border-color: var(--ds-advanced-color-state-focused, #01426a);--ds-auro-dropdown-trigger-outline-color: var(--ds-advanced-color-state-focused, #01426a)}:host([disabled]){--ds-auro-dropdown-trigger-text-color: var(--ds-basic-color-texticon-disabled, #d0d0d0);--ds-auro-dropdown-label-text-color: var(--ds-basic-color-texticon-disabled, #d0d0d0)}:host([common]),:host([bordered]){--ds-auro-dropdown-trigger-border-color: var(--ds-basic-color-border-bold, #585e67)}:host([common]) .trigger:active,:host([common]) .trigger:focus-within,:host([bordered]) .trigger:active,:host([bordered]) .trigger:focus-within{--ds-auro-dropdown-trigger-border-color: var(--ds-advanced-color-state-focused, #01426a)}:host([error]){--ds-auro-dropdown-trigger-border-color: var(--ds-basic-color-status-error, #e31f26)}:host([error]) .trigger{outline:solid 1px var(--ds-auro-dropdown-trigger-border-color)}:host([error]) .trigger:focus-within,:host([error]) .trigger:active{--ds-auro-dropdown-trigger-border-color: var(--ds-advanced-color-state-focused, #01426a);--ds-auro-dropdown-trigger-outline-color: var(--ds-advanced-color-state-focused, #01426a)}:host([disabled][common]),:host([disabled][bordered]){--ds-auro-dropdown-trigger-border-color: var(--ds-basic-color-border-subtle, #dddddd)}:host([onDark]){--ds-auro-dropdown-label-text-color: var(--ds-basic-color-texticon-inverse-muted, #ccd2db);--ds-auro-dropdown-trigger-container-color: var(--ds-advanced-color-shared-background-inverse, rgba(255, 255, 255, 0.15));--ds-auro-dropdown-trigger-text-color: var(--ds-basic-color-texticon-inverse, #ffffff)}:host([onDark]):focus-within,:host([onDark]):active{--ds-auro-dropdown-trigger-border-color: var(--ds-advanced-color-state-focused-inverse, #ffffff);--ds-auro-dropdown-trigger-outline-color: var(--ds-advanced-color-state-focused-inverse, #ffffff)}:host([onDark][disabled]){--ds-auro-dropdown-trigger-text-color: var(--ds-basic-color-texticon-inverse-disabled, #7e8894);--ds-auro-dropdown-label-text-color: var(--ds-basic-color-texticon-inverse-disabled, #7e8894)}:host([onDark][common]),:host([onDark][bordered]){--ds-auro-dropdown-trigger-border-color: var(--ds-basic-color-border-inverse, #ffffff)}:host([onDark][common]) .trigger:focus-within,:host([onDark][common]) .trigger:active,:host([onDark][bordered]) .trigger:focus-within,:host([onDark][bordered]) .trigger:active{--ds-auro-dropdown-trigger-border-color: var(--ds-advanced-color-state-focused-inverse, #ffffff);--ds-auro-dropdown-trigger-outline-color: var(--ds-advanced-color-state-focused-inverse, #ffffff)}:host([onDark][error]){--ds-auro-dropdown-trigger-border-color: var(--ds-advanced-color-state-error-inverse, #f9a4a8)}:host([onDark][error]) .trigger{outline:solid 1px var(--ds-auro-dropdown-trigger-border-color)}:host([onDark][error]) .trigger:focus-within,:host([onDark][error]) .trigger:active{--ds-auro-dropdown-trigger-border-color: var(--ds-advanced-color-state-focused-inverse, #ffffff);--ds-auro-dropdown-trigger-outline-color: var(--ds-advanced-color-state-focused-inverse, #ffffff)}:host([onDark][disabled][common]),:host([onDark][disabled][bordered]){--ds-auro-dropdown-trigger-container-color: var(--ds-advanced-color-shared-background-inverse-disabled, rgba(255, 255, 255, 0.1))}`;
|
|
2703
|
+
|
|
2704
|
+
var colorCss = css`:host([error]){--ds-auro-helptext-color: var(--ds-basic-color-status-error, #e31f26)}:host([onDark]){--ds-auro-helptext-color: var(--ds-basic-color-texticon-inverse-muted, #ccd2db)}:host([onDark][error]){--ds-auro-helptext-color: var(--ds-advanced-color-state-error-inverse, #f9a4a8)}.helptext-wrapper{color:var(--ds-auro-helptext-color)}`;
|
|
2705
|
+
|
|
2706
|
+
var styleCss = css`.helptext-wrapper{display:none;font-size:var(--ds-basic-text-body-xs-font-size, 12px);font-weight:var(--ds-basic-text-body-xs-font-weight, 450);letter-spacing:var(--ds-basic-text-body-xs-letter-spacing, 0);line-height:var(--ds-basic-text-body-xs-line-height, 16px)}:host([large]) .helptext-wrapper{font-size:var(--ds-basic-text-body-default-font-size, 16px);font-weight:var(--ds-basic-text-body-default-font-weight, 450);letter-spacing:var(--ds-basic-text-body-default-letter-spacing, 0);line-height:var(--ds-basic-text-body-default-line-height, 24px)}.helptext-wrapper[visible]{display:block}::slotted(*:not(:empty)){margin-top:var(--ds-size-50, 0.25rem);margin-bottom:0}::slotted(p){margin-block:0}`;
|
|
2707
|
+
|
|
2708
|
+
var tokensCss = css`:host{--ds-auro-helptext-color: var(--ds-basic-color-texticon-muted, #676767)}`;
|
|
2709
|
+
|
|
2710
|
+
// Copyright (c) Alaska Air. All right reserved. Licensed under the Apache-2.0 license
|
|
2711
|
+
// See LICENSE in the project root for license information.
|
|
2712
|
+
|
|
2713
|
+
// ---------------------------------------------------------------------
|
|
2714
|
+
|
|
2715
|
+
/* eslint-disable line-comment-position, no-inline-comments, no-confusing-arrow, no-nested-ternary, implicit-arrow-linebreak */
|
|
2716
|
+
|
|
2717
|
+
class AuroLibraryRuntimeUtils {
|
|
2718
|
+
|
|
2719
|
+
/* eslint-disable jsdoc/require-param */
|
|
2720
|
+
|
|
2721
|
+
/**
|
|
2722
|
+
* This will register a new custom element with the browser.
|
|
2723
|
+
* @param {String} name - The name of the custom element.
|
|
2724
|
+
* @param {Object} componentClass - The class to register as a custom element.
|
|
2725
|
+
* @returns {void}
|
|
2726
|
+
*/
|
|
2727
|
+
registerComponent(name, componentClass) {
|
|
2728
|
+
if (!customElements.get(name)) {
|
|
2729
|
+
customElements.define(name, class extends componentClass {});
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
|
|
2733
|
+
/**
|
|
2734
|
+
* Finds and returns the closest HTML Element based on a selector.
|
|
2735
|
+
* @returns {void}
|
|
2736
|
+
*/
|
|
2737
|
+
closestElement(
|
|
2738
|
+
selector, // selector like in .closest()
|
|
2739
|
+
base = this, // extra functionality to skip a parent
|
|
2740
|
+
__Closest = (el, found = el && el.closest(selector)) =>
|
|
2741
|
+
!el || el === document || el === window
|
|
2742
|
+
? null // standard .closest() returns null for non-found selectors also
|
|
2743
|
+
: found
|
|
2744
|
+
? found // found a selector INside this element
|
|
2745
|
+
: __Closest(el.getRootNode().host) // recursion!! break out to parent DOM
|
|
2746
|
+
) {
|
|
2747
|
+
return __Closest(base);
|
|
2748
|
+
}
|
|
2749
|
+
/* eslint-enable jsdoc/require-param */
|
|
2750
|
+
|
|
2751
|
+
/**
|
|
2752
|
+
* If the element passed is registered with a different tag name than what is passed in, the tag name is added as an attribute to the element.
|
|
2753
|
+
* @param {Object} elem - The element to check.
|
|
2754
|
+
* @param {String} tagName - The name of the Auro component to check for or add as an attribute.
|
|
2755
|
+
* @returns {void}
|
|
2756
|
+
*/
|
|
2757
|
+
handleComponentTagRename(elem, tagName) {
|
|
2758
|
+
const tag = tagName.toLowerCase();
|
|
2759
|
+
const elemTag = elem.tagName.toLowerCase();
|
|
2760
|
+
|
|
2761
|
+
if (elemTag !== tag) {
|
|
2762
|
+
elem.setAttribute(tag, true);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
/**
|
|
2767
|
+
* Validates if an element is a specific Auro component.
|
|
2768
|
+
* @param {Object} elem - The element to validate.
|
|
2769
|
+
* @param {String} tagName - The name of the Auro component to check against.
|
|
2770
|
+
* @returns {Boolean} - Returns true if the element is the specified Auro component.
|
|
2771
|
+
*/
|
|
2772
|
+
elementMatch(elem, tagName) {
|
|
2773
|
+
const tag = tagName.toLowerCase();
|
|
2774
|
+
const elemTag = elem.tagName.toLowerCase();
|
|
2775
|
+
|
|
2776
|
+
return elemTag === tag || elem.hasAttribute(tag);
|
|
2777
|
+
}
|
|
2778
|
+
}
|
|
2779
|
+
|
|
2780
|
+
// Copyright (c) 2025 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
|
|
2781
|
+
// See LICENSE in the project root for license information.
|
|
2782
|
+
|
|
2783
|
+
|
|
2784
|
+
/**
|
|
2785
|
+
* Displays help text or error messages within form elements - Internal Use Only.
|
|
2786
|
+
*
|
|
2787
|
+
* @attr { Boolean } large - If declared, make font-size to 1rem(16px).
|
|
2788
|
+
*/
|
|
2789
|
+
class AuroHelpText extends LitElement {
|
|
2790
|
+
|
|
2791
|
+
constructor() {
|
|
2792
|
+
super();
|
|
2793
|
+
|
|
2794
|
+
this.error = false;
|
|
2795
|
+
this.onDark = false;
|
|
2796
|
+
this.hasTextContent = false;
|
|
2797
|
+
|
|
2798
|
+
AuroLibraryRuntimeUtils.prototype.handleComponentTagRename(this, 'auro-helptext');
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
static get styles() {
|
|
2802
|
+
return [
|
|
2803
|
+
colorCss,
|
|
2804
|
+
styleCss,
|
|
2805
|
+
tokensCss
|
|
2806
|
+
];
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
// function to define props used within the scope of this component
|
|
2810
|
+
static get properties() {
|
|
2811
|
+
return {
|
|
2812
|
+
|
|
2813
|
+
/**
|
|
2814
|
+
* @private
|
|
2815
|
+
*/
|
|
2816
|
+
slotNodes: {
|
|
2817
|
+
type: Boolean,
|
|
2818
|
+
},
|
|
2819
|
+
|
|
2820
|
+
/**
|
|
2821
|
+
* @private
|
|
2822
|
+
*/
|
|
2823
|
+
hasTextContent: {
|
|
2824
|
+
type: Boolean,
|
|
2825
|
+
},
|
|
2826
|
+
|
|
2827
|
+
/**
|
|
2828
|
+
* If declared, make font color red.
|
|
2829
|
+
*/
|
|
2830
|
+
error: {
|
|
2831
|
+
type: Boolean,
|
|
2832
|
+
reflect: true,
|
|
2833
|
+
},
|
|
2834
|
+
|
|
2835
|
+
/**
|
|
2836
|
+
* If declared, will apply onDark styles.
|
|
2837
|
+
*/
|
|
2838
|
+
onDark: {
|
|
2839
|
+
type: Boolean,
|
|
2840
|
+
reflect: true
|
|
2841
|
+
}
|
|
2842
|
+
};
|
|
2843
|
+
}
|
|
2844
|
+
|
|
2845
|
+
/**
|
|
2846
|
+
* This will register this element with the browser.
|
|
2847
|
+
* @param {string} [name="auro-helptext"] - The name of element that you want to register to.
|
|
2848
|
+
*
|
|
2849
|
+
* @example
|
|
2850
|
+
* AuroCheckbox.register("custom-helptext") // this will register this element to <custom-helptext/>
|
|
2851
|
+
*
|
|
2852
|
+
*/
|
|
2853
|
+
static register(name = "auro-helptext") {
|
|
2854
|
+
AuroLibraryRuntimeUtils.prototype.registerComponent(name, AuroHelpText);
|
|
2855
|
+
}
|
|
2856
|
+
|
|
2857
|
+
updated() {
|
|
2858
|
+
this.handleSlotChange();
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
handleSlotChange(event) {
|
|
2862
|
+
if (event) {
|
|
2863
|
+
this.slotNodes = event.target.assignedNodes();
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
this.hasTextContent = this.checkSlotsForContent(this.slotNodes);
|
|
2867
|
+
}
|
|
2868
|
+
|
|
2869
|
+
/**
|
|
2870
|
+
* Checks if any of the provided nodes or their nested slot nodes contain non-empty text content.
|
|
2871
|
+
*
|
|
2872
|
+
* @param {NodeList|Array} nodes - The list of nodes to check for content.
|
|
2873
|
+
* @returns {boolean} - Returns true if any node or nested slot node contains non-empty text content, otherwise false.
|
|
2874
|
+
* @private
|
|
2875
|
+
*/
|
|
2876
|
+
checkSlotsForContent(nodes) {
|
|
2877
|
+
if (!nodes) {
|
|
2878
|
+
return false;
|
|
2879
|
+
}
|
|
2880
|
+
|
|
2881
|
+
return nodes.some((node) => {
|
|
2882
|
+
if (node.textContent.trim()) {
|
|
2883
|
+
return true;
|
|
2884
|
+
}
|
|
2885
|
+
|
|
2886
|
+
if (!node.querySelector) {
|
|
2887
|
+
return false;
|
|
2888
|
+
}
|
|
2889
|
+
|
|
2890
|
+
const nestedSlot = node.tagName === 'SLOT' ? node : node.querySelector('slot');
|
|
2891
|
+
if (!nestedSlot) {
|
|
2892
|
+
return false;
|
|
2893
|
+
}
|
|
2894
|
+
|
|
2895
|
+
const nestedSlotNodes = nestedSlot.assignedNodes();
|
|
2896
|
+
return this.checkSlotsForContent(nestedSlotNodes);
|
|
2897
|
+
});
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
// function that renders the HTML and CSS into the scope of the component
|
|
2901
|
+
render() {
|
|
2902
|
+
return html`
|
|
2903
|
+
<div class="helptext-wrapper" ?visible="${this.hasTextContent}">
|
|
2904
|
+
<slot @slotchange=${this.handleSlotChange}></slot>
|
|
2905
|
+
</div>
|
|
2906
|
+
`;
|
|
2907
|
+
}
|
|
2908
|
+
}
|
|
2909
|
+
|
|
2910
|
+
var helpTextVersion = '1.0.0';
|
|
2911
|
+
|
|
2912
|
+
// Copyright (c) 2020 Alaska Airlines. All right reserved. Licensed under the Apache-2.0 license
|
|
2913
|
+
// See LICENSE in the project root for license information.
|
|
2914
|
+
|
|
2915
|
+
|
|
2916
|
+
/**
|
|
2917
|
+
* @attr { Boolean } disableEventShow - If declared, the dropdown will only show by calling the API .show() public method.
|
|
2918
|
+
* @slot - Default slot for the popover content.
|
|
2919
|
+
* @slot label - Defines the content of the label.
|
|
2920
|
+
* @slot helpText - Defines the content of the helpText.
|
|
2921
|
+
* @slot trigger - Defines the content of the trigger.
|
|
2922
|
+
* @csspart trigger - The trigger content container.
|
|
2923
|
+
* @csspart chevron - The collapsed/expanded state icon container.
|
|
2924
|
+
* @csspart helpText - The helpText content container.
|
|
2925
|
+
* @event auroDropdown-triggerClick - Notifies that the trigger has been clicked.
|
|
2926
|
+
* @event auroDropdown-toggled - Notifies that the visibility of the dropdown bib has changed.
|
|
2927
|
+
* @event auroDropdown-idAdded - Notifies consumers that the unique ID for the dropdown bib has been generated.
|
|
2928
|
+
*/
|
|
2929
|
+
class AuroDropdown extends LitElement {
|
|
2930
|
+
constructor() {
|
|
2931
|
+
super();
|
|
2932
|
+
|
|
2933
|
+
this.isPopoverVisible = false;
|
|
2934
|
+
this.isBibFullscreen = false;
|
|
2935
|
+
this.matchWidth = false;
|
|
2936
|
+
this.noHideOnThisFocusLoss = false;
|
|
2937
|
+
|
|
2938
|
+
this.privateDefaults();
|
|
2939
|
+
|
|
2940
|
+
/**
|
|
2941
|
+
* @private
|
|
2942
|
+
* @property {boolean} delegatesFocus - Whether the shadow root delegates focus.
|
|
2943
|
+
*/
|
|
2944
|
+
this.constructor.shadowRootOptions = {
|
|
2945
|
+
...LitElement.shadowRootOptions,
|
|
2946
|
+
delegatesFocus: true,
|
|
2947
|
+
};
|
|
2948
|
+
|
|
2949
|
+
/**
|
|
2950
|
+
* @private
|
|
2951
|
+
*/
|
|
2952
|
+
this.triggerContentFocusable = false;
|
|
2953
|
+
|
|
2954
|
+
/**
|
|
2955
|
+
* @private
|
|
2956
|
+
*/
|
|
2957
|
+
this.showTriggerBorders = true;
|
|
2958
|
+
}
|
|
2959
|
+
|
|
2960
|
+
/**
|
|
2961
|
+
* @private
|
|
2962
|
+
* @returns {void} Internal defaults.
|
|
2963
|
+
*/
|
|
2964
|
+
privateDefaults() {
|
|
2965
|
+
this.bordered = false;
|
|
2966
|
+
this.chevron = false;
|
|
2967
|
+
this.disabled = false;
|
|
2968
|
+
this.error = false;
|
|
2969
|
+
this.inset = false;
|
|
2970
|
+
this.rounded = false;
|
|
2971
|
+
this.tabIndex = 0;
|
|
2972
|
+
this.noToggle = false;
|
|
2973
|
+
this.a11yAutocomplete = 'none';
|
|
2974
|
+
this.labeled = true;
|
|
2975
|
+
this.a11yRole = 'combobox';
|
|
2976
|
+
this.onDark = false;
|
|
2977
|
+
|
|
2978
|
+
// floaterConfig
|
|
2979
|
+
this.placement = 'bottom-start';
|
|
2980
|
+
this.offset = 0;
|
|
2981
|
+
this.noFlip = false;
|
|
2982
|
+
this.autoPlacement = false;
|
|
2983
|
+
|
|
2984
|
+
/**
|
|
2985
|
+
* @private
|
|
2986
|
+
*/
|
|
2987
|
+
this.hasTriggerContent = false;
|
|
2988
|
+
|
|
2989
|
+
/**
|
|
2990
|
+
* @private
|
|
2991
|
+
*/
|
|
2992
|
+
this.triggerContentSlot = undefined;
|
|
2993
|
+
|
|
2994
|
+
/**
|
|
2995
|
+
* @private
|
|
2996
|
+
*/
|
|
2997
|
+
this.runtimeUtils = new AuroLibraryRuntimeUtils$1();
|
|
2998
|
+
|
|
2999
|
+
/**
|
|
3000
|
+
* @private
|
|
3001
|
+
*/
|
|
3002
|
+
this.floater = new AuroFloatingUI();
|
|
3003
|
+
|
|
3004
|
+
/**
|
|
3005
|
+
* Generate unique names for dependency components.
|
|
3006
|
+
*/
|
|
3007
|
+
const versioning = new AuroDependencyVersioning();
|
|
3008
|
+
|
|
3009
|
+
/**
|
|
3010
|
+
* @private
|
|
3011
|
+
*/
|
|
3012
|
+
this.iconTag = versioning.generateTag('auro-formkit-dropdown-icon', iconVersion, AuroIcon);
|
|
3013
|
+
|
|
3014
|
+
/**
|
|
3015
|
+
* @private
|
|
3016
|
+
*/
|
|
3017
|
+
this.dropdownBibTag = versioning.generateTag('auro-formkit-dropdown-dropdownbib', dropdownVersion, AuroDropdownBib);
|
|
3018
|
+
|
|
3019
|
+
/**
|
|
3020
|
+
* @private
|
|
3021
|
+
*/
|
|
3022
|
+
this.helpTextTag = versioning.generateTag('auro-formkit-dropdown-helptext', helpTextVersion, AuroHelpText);
|
|
3023
|
+
|
|
3024
|
+
/**
|
|
3025
|
+
* @private
|
|
3026
|
+
*/
|
|
3027
|
+
this.bindFocusEventToTrigger = this.bindFocusEventToTrigger.bind(this);
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
/**
|
|
3031
|
+
* @ignore
|
|
3032
|
+
*/
|
|
3033
|
+
get floaterConfig() {
|
|
3034
|
+
return {
|
|
3035
|
+
placement: this.placement,
|
|
3036
|
+
flip: !this.noFlip,
|
|
3037
|
+
autoPlacement: this.autoPlacement,
|
|
3038
|
+
offset: this.offset,
|
|
3039
|
+
};
|
|
3040
|
+
}
|
|
3041
|
+
|
|
3042
|
+
/**
|
|
3043
|
+
* Public method to hide the dropdown.
|
|
3044
|
+
* @returns {void}
|
|
3045
|
+
*/
|
|
3046
|
+
hide() {
|
|
3047
|
+
this.floater.hideBib();
|
|
3048
|
+
}
|
|
3049
|
+
|
|
3050
|
+
/**
|
|
3051
|
+
* Public method to show the dropdown.
|
|
3052
|
+
* @returns {void}
|
|
3053
|
+
*/
|
|
3054
|
+
show() {
|
|
3055
|
+
this.floater.showBib();
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
// function to define props used within the scope of this component
|
|
3059
|
+
static get properties() {
|
|
3060
|
+
return {
|
|
3061
|
+
|
|
3062
|
+
/**
|
|
3063
|
+
* If declared, bib's position will be automatically calculated where to appear.
|
|
3064
|
+
* @default false
|
|
3065
|
+
*/
|
|
3066
|
+
autoPlacement: {
|
|
3067
|
+
type: Boolean,
|
|
3068
|
+
reflect: true
|
|
3069
|
+
},
|
|
3070
|
+
|
|
3071
|
+
/**
|
|
3072
|
+
* If declared, applies a border around the trigger slot.
|
|
3073
|
+
*/
|
|
3074
|
+
bordered: {
|
|
3075
|
+
type: Boolean,
|
|
3076
|
+
reflect: true
|
|
3077
|
+
},
|
|
3078
|
+
|
|
3079
|
+
/**
|
|
3080
|
+
* If declared, the dropdown displays a chevron on the right.
|
|
3081
|
+
* @attr {Boolean} chevron
|
|
3082
|
+
*/
|
|
3083
|
+
chevron: {
|
|
3084
|
+
type: Boolean,
|
|
3085
|
+
reflect: true
|
|
3086
|
+
},
|
|
3087
|
+
|
|
3088
|
+
/**
|
|
3089
|
+
* If declared, the dropdown will be styled with the common theme.
|
|
3090
|
+
*/
|
|
3091
|
+
common: {
|
|
3092
|
+
type: Boolean,
|
|
3093
|
+
reflect: true
|
|
3094
|
+
},
|
|
3095
|
+
|
|
3096
|
+
/**
|
|
3097
|
+
* If declared, the dropdown is not interactive.
|
|
3098
|
+
*/
|
|
3099
|
+
disabled: {
|
|
3100
|
+
type: Boolean,
|
|
3101
|
+
reflect: true
|
|
3102
|
+
},
|
|
3103
|
+
|
|
3104
|
+
/**
|
|
3105
|
+
* @private
|
|
3106
|
+
*/
|
|
3107
|
+
dropdownWidth: {
|
|
3108
|
+
type: Number
|
|
3109
|
+
},
|
|
3110
|
+
|
|
3111
|
+
/**
|
|
3112
|
+
* The unique ID for the dropdown bib element.
|
|
3113
|
+
* @private
|
|
3114
|
+
*/
|
|
3115
|
+
dropdownId: {
|
|
3116
|
+
type: String,
|
|
3117
|
+
reflect: false,
|
|
3118
|
+
attribute: false
|
|
3119
|
+
},
|
|
3120
|
+
|
|
3121
|
+
/**
|
|
3122
|
+
* If declared in combination with `bordered` property or `helpText` slot content, will apply red color to both.
|
|
3123
|
+
*/
|
|
3124
|
+
error: {
|
|
3125
|
+
type: Boolean,
|
|
3126
|
+
reflect: true
|
|
3127
|
+
},
|
|
3128
|
+
|
|
3129
|
+
/**
|
|
3130
|
+
* If declared, the bib will display when focus is applied to the trigger.
|
|
3131
|
+
*/
|
|
3132
|
+
focusShow: {
|
|
3133
|
+
type: Boolean,
|
|
3134
|
+
reflect: true
|
|
3135
|
+
},
|
|
3136
|
+
|
|
3137
|
+
/**
|
|
3138
|
+
* Makes the trigger to be full width of its parent container.
|
|
3139
|
+
*/
|
|
3140
|
+
fluid: {
|
|
3141
|
+
type: Boolean,
|
|
3142
|
+
reflect: true
|
|
3143
|
+
},
|
|
3144
|
+
|
|
3145
|
+
/**
|
|
3146
|
+
* If declared, will apply padding around trigger slot content.
|
|
3147
|
+
*/
|
|
3148
|
+
inset: {
|
|
3149
|
+
type: Boolean,
|
|
3150
|
+
reflect: true
|
|
3151
|
+
},
|
|
3152
|
+
|
|
3153
|
+
/**
|
|
3154
|
+
* If true, the dropdown bib is displayed.
|
|
3155
|
+
*/
|
|
3156
|
+
isPopoverVisible: {
|
|
3157
|
+
type: Boolean
|
|
3158
|
+
},
|
|
3159
|
+
|
|
3160
|
+
/**
|
|
3161
|
+
* If true, the dropdown bib is taking the fullscreen when it's open.
|
|
3162
|
+
*/
|
|
3163
|
+
isBibFullscreen: {
|
|
3164
|
+
type: Boolean,
|
|
3165
|
+
reflect: true
|
|
3166
|
+
},
|
|
3167
|
+
|
|
3168
|
+
/**
|
|
3169
|
+
* If declared, the trigger will toggle the dropdown on mouseover/mouseout.
|
|
3170
|
+
*/
|
|
3171
|
+
hoverToggle: {
|
|
3172
|
+
type: Boolean,
|
|
3173
|
+
reflect: true
|
|
3174
|
+
},
|
|
3175
|
+
|
|
3176
|
+
/**
|
|
3177
|
+
* @private
|
|
3178
|
+
*/
|
|
3179
|
+
hasTriggerContent: {
|
|
3180
|
+
type: Boolean
|
|
3181
|
+
},
|
|
3182
|
+
|
|
3183
|
+
/**
|
|
3184
|
+
* Defines the screen size breakpoint (`xs`, `sm`, `md`, `lg`, `xl`, `disabled`)
|
|
3185
|
+
* at which the dropdown switches to fullscreen mode on mobile. `disabled` indicates a dropdown should _never_ enter fullscreen.
|
|
3186
|
+
*
|
|
3187
|
+
* When expanded, the dropdown will automatically display in fullscreen mode
|
|
3188
|
+
* if the screen size is equal to or smaller than the selected breakpoint.
|
|
3189
|
+
* @default sm
|
|
3190
|
+
*/
|
|
3191
|
+
fullscreenBreakpoint: {
|
|
3192
|
+
type: String,
|
|
3193
|
+
reflect: true
|
|
3194
|
+
},
|
|
3195
|
+
|
|
3196
|
+
/**
|
|
3197
|
+
* Defines if there is a label preset.
|
|
3198
|
+
* @private
|
|
3199
|
+
*/
|
|
3200
|
+
labeled: {
|
|
3201
|
+
type: Boolean,
|
|
3202
|
+
reflect: true
|
|
3203
|
+
},
|
|
3204
|
+
|
|
3205
|
+
/**
|
|
3206
|
+
* If declared, the popover and trigger will be set to the same width.
|
|
3207
|
+
*/
|
|
3208
|
+
matchWidth: {
|
|
3209
|
+
type: Boolean,
|
|
3210
|
+
reflect: true
|
|
3211
|
+
},
|
|
3212
|
+
|
|
3213
|
+
/**
|
|
3214
|
+
* If declared, the bib will NOT flip to an alternate position
|
|
3215
|
+
* when there isn't enough space in the specified `placement`.
|
|
3216
|
+
* @default false
|
|
3217
|
+
*/
|
|
3218
|
+
noFlip: {
|
|
3219
|
+
type: Boolean,
|
|
3220
|
+
reflect: true
|
|
3221
|
+
},
|
|
3222
|
+
|
|
3223
|
+
/**
|
|
3224
|
+
* If declared, the dropdown will not hide when moving focus outside the element.
|
|
3225
|
+
*/
|
|
3226
|
+
noHideOnThisFocusLoss: {
|
|
3227
|
+
type: Boolean,
|
|
3228
|
+
reflect: true
|
|
3229
|
+
},
|
|
3230
|
+
|
|
3231
|
+
/**
|
|
3232
|
+
* If declared, the trigger will only show the dropdown bib.
|
|
3233
|
+
*/
|
|
3234
|
+
noToggle: {
|
|
3235
|
+
type: Boolean,
|
|
3236
|
+
reflect: true
|
|
3237
|
+
},
|
|
3238
|
+
|
|
3239
|
+
/**
|
|
3240
|
+
* Gap between the trigger element and bib.
|
|
3241
|
+
* @default 0
|
|
3242
|
+
*/
|
|
3243
|
+
offset: {
|
|
3244
|
+
type: Number,
|
|
3245
|
+
reflect: true
|
|
3246
|
+
},
|
|
3247
|
+
|
|
3248
|
+
/**
|
|
3249
|
+
* If declared, onDark styles will be applied.
|
|
3250
|
+
*/
|
|
3251
|
+
onDark: {
|
|
3252
|
+
type: Boolean,
|
|
3253
|
+
reflect: true
|
|
3254
|
+
},
|
|
3255
|
+
|
|
3256
|
+
onSlotChange: {
|
|
3257
|
+
type: Function,
|
|
3258
|
+
reflect: false
|
|
3259
|
+
},
|
|
3260
|
+
|
|
3261
|
+
/**
|
|
3262
|
+
* Position where the bib should appear relative to the trigger.
|
|
3263
|
+
* Accepted values:
|
|
3264
|
+
* "top" | "right" | "bottom" | "left" |
|
|
3265
|
+
* "bottom-start" | "top-start" | "top-end" |
|
|
3266
|
+
* "right-start" | "right-end" | "bottom-end" |
|
|
3267
|
+
* "left-start" | "left-end"
|
|
3268
|
+
* @default bottom-start
|
|
3269
|
+
*/
|
|
3270
|
+
placement: {
|
|
3271
|
+
type: String,
|
|
3272
|
+
reflect: true
|
|
3273
|
+
},
|
|
3274
|
+
|
|
3275
|
+
/**
|
|
3276
|
+
* If declared, will apply border-radius to trigger and default slots.
|
|
3277
|
+
*/
|
|
3278
|
+
rounded: {
|
|
3279
|
+
type: Boolean,
|
|
3280
|
+
reflect: true
|
|
3281
|
+
},
|
|
3282
|
+
|
|
3283
|
+
/**
|
|
3284
|
+
* @private
|
|
3285
|
+
*/
|
|
3286
|
+
tabIndex: {
|
|
3287
|
+
type: Number
|
|
3288
|
+
},
|
|
3289
|
+
|
|
3290
|
+
/**
|
|
3291
|
+
* The value for the role attribute of the trigger element.
|
|
3292
|
+
*/
|
|
3293
|
+
a11yRole: {
|
|
3294
|
+
type: String || undefined,
|
|
3295
|
+
attribute: false,
|
|
3296
|
+
reflect: false
|
|
3297
|
+
},
|
|
3298
|
+
|
|
3299
|
+
/**
|
|
3300
|
+
* The value for the aria-autocomplete attribute of the trigger element.
|
|
3301
|
+
*/
|
|
3302
|
+
a11yAutocomplete: {
|
|
3303
|
+
type: String,
|
|
3304
|
+
attribute: false,
|
|
3305
|
+
}
|
|
3306
|
+
};
|
|
3307
|
+
}
|
|
3308
|
+
|
|
3309
|
+
static get styles() {
|
|
3310
|
+
return [
|
|
3311
|
+
colorCss$1,
|
|
3312
|
+
styleCss$1,
|
|
3313
|
+
tokensCss$1
|
|
3314
|
+
];
|
|
3315
|
+
}
|
|
3316
|
+
|
|
3317
|
+
/**
|
|
3318
|
+
* This will register this element with the browser.
|
|
3319
|
+
* @param {string} [name="auro-dropdown"] - The name of element that you want to register to.
|
|
3320
|
+
*
|
|
3321
|
+
* @example
|
|
3322
|
+
* AuroDropdown.register("custom-dropdown") // this will register this element to <custom-dropdown/>
|
|
3323
|
+
*
|
|
3324
|
+
*/
|
|
3325
|
+
static register(name = "auro-dropdown") {
|
|
3326
|
+
AuroLibraryRuntimeUtils$1.prototype.registerComponent(name, AuroDropdown);
|
|
3327
|
+
}
|
|
3328
|
+
|
|
3329
|
+
/**
|
|
3330
|
+
* Accessor for reusing the focusable entity query string.
|
|
3331
|
+
* @private
|
|
3332
|
+
* @returns {string}
|
|
3333
|
+
*/
|
|
3334
|
+
get focusableEntityQuery () {
|
|
3335
|
+
return 'auro-input, [auro-input], auro-button, [auro-button], button, input';
|
|
3336
|
+
}
|
|
3337
|
+
|
|
3338
|
+
connectedCallback() {
|
|
3339
|
+
super.connectedCallback();
|
|
3340
|
+
}
|
|
3341
|
+
|
|
3342
|
+
disconnectedCallback() {
|
|
3343
|
+
super.disconnectedCallback();
|
|
3344
|
+
this.floater.disconnect();
|
|
3345
|
+
this.clearTriggerFocusEventBinding();
|
|
3346
|
+
}
|
|
3347
|
+
|
|
3348
|
+
updated(changedProperties) {
|
|
3349
|
+
this.floater.handleUpdate(changedProperties);
|
|
3350
|
+
|
|
3351
|
+
// Note: `disabled` is not a breakpoint (it is not a screen size),
|
|
3352
|
+
// so it looks like we never consume this - however, dropdownBib handles this in the setter as "undefined"
|
|
3353
|
+
if (changedProperties.has('fullscreenBreakpoint')) {
|
|
3354
|
+
this.bibContent.mobileFullscreenBreakpoint = this.fullscreenBreakpoint;
|
|
3355
|
+
}
|
|
3356
|
+
|
|
3357
|
+
// when trigger's content is changed without any attribute or node change,
|
|
3358
|
+
// `requestUpdate` needs to be called to update hasTriggerContnet
|
|
3359
|
+
if (changedProperties.size === 0 || changedProperties.has('isPopoverVisible')) {
|
|
3360
|
+
this.handleTriggerContentSlotChange();
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
firstUpdated() {
|
|
3366
|
+
|
|
3367
|
+
// Configure the floater to, this will generate the ID for the bib
|
|
3368
|
+
this.floater.configure(this, 'auroDropdown');
|
|
3369
|
+
|
|
3370
|
+
/**
|
|
3371
|
+
* @description Let subscribers know that the dropdown ID ha been generated and added.
|
|
3372
|
+
* @event auroDropdown-idAdded
|
|
3373
|
+
* @type {Object<key: 'id', value: string>} - The ID of the dropdown bib element.
|
|
3374
|
+
*/
|
|
3375
|
+
this.dispatchEvent(new CustomEvent('auroDropdown-idAdded', {detail: {id: this.floater.element.id}}));
|
|
3376
|
+
|
|
3377
|
+
// Set the bib ID locally if the user hasn't provided a focusable trigger
|
|
3378
|
+
if (!this.triggerContentFocusable) {
|
|
3379
|
+
this.dropdownId = this.floater.element.id;
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3382
|
+
this.bibContent = this.floater.element.bib;
|
|
3383
|
+
|
|
3384
|
+
// Add the tag name as an attribute if it is different than the component name
|
|
3385
|
+
this.runtimeUtils.handleComponentTagRename(this, 'auro-dropdown');
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3388
|
+
/**
|
|
3389
|
+
* Exposes CSS parts for styling from parent components.
|
|
3390
|
+
* @returns {void}
|
|
3391
|
+
*/
|
|
3392
|
+
exposeCssParts() {
|
|
3393
|
+
this.setAttribute('exportparts', 'trigger:dropdownTrigger, chevron:dropdownChevron, helpText:dropdownHelpText, size:dropdownSize');
|
|
3394
|
+
}
|
|
3395
|
+
|
|
3396
|
+
/**
|
|
3397
|
+
* Determines if content is within a custom slot.
|
|
3398
|
+
* @private
|
|
3399
|
+
* @param {HTMLElement} element - The element to check.
|
|
3400
|
+
* @returns {Boolean}
|
|
3401
|
+
*/
|
|
3402
|
+
isCustomSlotContent(element) {
|
|
3403
|
+
let currentElement = element;
|
|
3404
|
+
|
|
3405
|
+
let inCustomSlot = false;
|
|
3406
|
+
|
|
3407
|
+
while (currentElement) {
|
|
3408
|
+
currentElement = currentElement.parentElement;
|
|
3409
|
+
|
|
3410
|
+
if (currentElement && currentElement.hasAttribute('slot')) {
|
|
3411
|
+
inCustomSlot = true;
|
|
3412
|
+
break;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
|
|
3416
|
+
return inCustomSlot;
|
|
3417
|
+
}
|
|
3418
|
+
|
|
3419
|
+
/**
|
|
3420
|
+
* Determines if the element or any children are focusable.
|
|
3421
|
+
* @private
|
|
3422
|
+
* @param {HTMLElement} element - Element to check.
|
|
3423
|
+
* @returns {Boolean} - True if the element or any children are focusable.
|
|
3424
|
+
*/
|
|
3425
|
+
containsFocusableElement(element) {
|
|
3426
|
+
this.showTriggerBorders = true;
|
|
3427
|
+
|
|
3428
|
+
const nodes = [
|
|
3429
|
+
element,
|
|
3430
|
+
...element.children
|
|
3431
|
+
];
|
|
3432
|
+
|
|
3433
|
+
const focusableElements = [
|
|
3434
|
+
'a',
|
|
3435
|
+
'auro-hyperlink',
|
|
3436
|
+
'button',
|
|
3437
|
+
'auro-button',
|
|
3438
|
+
'input',
|
|
3439
|
+
'auro-input',
|
|
3440
|
+
];
|
|
3441
|
+
|
|
3442
|
+
const focusableElementsThatNeedBorders = ['auro-input'];
|
|
3443
|
+
|
|
3444
|
+
const result = nodes.some((node) => {
|
|
3445
|
+
const tagName = node.tagName.toLowerCase();
|
|
3446
|
+
|
|
3447
|
+
if (node.tabIndex > -1) {
|
|
3448
|
+
return true;
|
|
3449
|
+
}
|
|
3450
|
+
|
|
3451
|
+
if (focusableElements.includes(tagName)) {
|
|
3452
|
+
if ((tagName === 'a' || tagName === 'auro-hyperlink' || node.hasAttribute('auro-hyperlink')) && node.hasAttribute('href')) {
|
|
3453
|
+
return true;
|
|
3454
|
+
}
|
|
3455
|
+
if (!node.hasAttribute('disabled')) {
|
|
3456
|
+
return true;
|
|
3457
|
+
}
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
if (focusableElements.some((focusableElement) => focusableElement.startsWith('auro-') && (focusableElement === tagName || node.hasAttribute(focusableElement)))) {
|
|
3461
|
+
return true;
|
|
3462
|
+
}
|
|
3463
|
+
|
|
3464
|
+
return false;
|
|
3465
|
+
});
|
|
3466
|
+
|
|
3467
|
+
if (result) {
|
|
3468
|
+
this.showTriggerBorders = !nodes.some((node) => {
|
|
3469
|
+
const tagName = node.tagName.toLowerCase();
|
|
3470
|
+
return focusableElements.includes(tagName) && !focusableElementsThatNeedBorders.includes(tagName);
|
|
3471
|
+
});
|
|
3472
|
+
}
|
|
3473
|
+
|
|
3474
|
+
return result;
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3477
|
+
/**
|
|
3478
|
+
* @private
|
|
3479
|
+
* Creates and dispatches a duplicate focus event on the trigger element.
|
|
3480
|
+
* @param {Event} event - The original focus event.
|
|
3481
|
+
*/
|
|
3482
|
+
bindFocusEventToTrigger(event) {
|
|
3483
|
+
const dupEvent = new FocusEvent(event.type, {
|
|
3484
|
+
bubbles: false,
|
|
3485
|
+
cancelable: false,
|
|
3486
|
+
composed: true,
|
|
3487
|
+
});
|
|
3488
|
+
this.trigger.dispatchEvent(dupEvent);
|
|
3489
|
+
}
|
|
3490
|
+
|
|
3491
|
+
/**
|
|
3492
|
+
* @private
|
|
3493
|
+
* Sets up event listeners to deliver focus and blur events from nested Auro components within the trigger slot to trigger.
|
|
3494
|
+
* This ensures that focus/blur events originating from within these components are propagated to the trigger element itself.
|
|
3495
|
+
*/
|
|
3496
|
+
setupTriggerFocusEventBinding() {
|
|
3497
|
+
if (!this.triggerContentSlot || this.triggerContentSlot.length === 0) {
|
|
3498
|
+
return;
|
|
3499
|
+
}
|
|
3500
|
+
|
|
3501
|
+
this.triggerContentSlot.forEach((node) => {
|
|
3502
|
+
if (node.querySelectorAll) {
|
|
3503
|
+
const auroElements = node.querySelectorAll(this.focusableEntityQuery);
|
|
3504
|
+
auroElements.forEach((auroEl) => {
|
|
3505
|
+
auroEl.addEventListener('focus', this.bindFocusEventToTrigger);
|
|
3506
|
+
auroEl.addEventListener('blur', this.bindFocusEventToTrigger);
|
|
3507
|
+
});
|
|
3508
|
+
}
|
|
3509
|
+
});
|
|
3510
|
+
}
|
|
3511
|
+
|
|
3512
|
+
/**
|
|
3513
|
+
* Clears focus and blur event listeners from nested Auro components within the trigger slot.
|
|
3514
|
+
* @private
|
|
3515
|
+
* @returns {void}
|
|
3516
|
+
*/
|
|
3517
|
+
clearTriggerFocusEventBinding() {
|
|
3518
|
+
if (!this.triggerContentSlot || this.triggerContentSlot.length === 0) {
|
|
3519
|
+
return;
|
|
3520
|
+
}
|
|
3521
|
+
|
|
3522
|
+
this.triggerContentSlot.forEach((node) => {
|
|
3523
|
+
if (node.querySelectorAll) {
|
|
3524
|
+
const auroElements = node.querySelectorAll(this.focusableEntityQuery);
|
|
3525
|
+
auroElements.forEach((auroEl) => {
|
|
3526
|
+
auroEl.removeEventListener('focus', this.bindFocusEventToTrigger);
|
|
3527
|
+
auroEl.removeEventListener('blur', this.bindFocusEventToTrigger);
|
|
3528
|
+
});
|
|
3529
|
+
}
|
|
3530
|
+
});
|
|
3531
|
+
}
|
|
3532
|
+
|
|
3533
|
+
/*
|
|
3534
|
+
* Sets aria attributes for the trigger element if a custom one is passed in.
|
|
3535
|
+
* @private
|
|
3536
|
+
* @method setTriggerAriaAttributes
|
|
3537
|
+
* @param { HTMLElement } triggerElement - The custom trigger element.
|
|
3538
|
+
*/
|
|
3539
|
+
clearTriggerA11yAttributes(triggerElement) {
|
|
3540
|
+
|
|
3541
|
+
if (!triggerElement || !triggerElement.removeAttribute) {
|
|
3542
|
+
return;
|
|
3543
|
+
}
|
|
3544
|
+
|
|
3545
|
+
// Reset appropriate attributes for a11y
|
|
3546
|
+
triggerElement.removeAttribute('aria-labelledby');
|
|
3547
|
+
if (triggerElement.getAttribute('id') === `${this.id}-trigger-element`) {
|
|
3548
|
+
triggerElement.removeAttribute('id');
|
|
3549
|
+
}
|
|
3550
|
+
triggerElement.removeAttribute('role');
|
|
3551
|
+
triggerElement.removeAttribute('aria-expanded');
|
|
3552
|
+
|
|
3553
|
+
triggerElement.removeAttribute('aria-controls');
|
|
3554
|
+
triggerElement.removeAttribute('aria-autocomplete');
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
/**
|
|
3558
|
+
* Handles changes to the trigger content slot and updates related properties.
|
|
3559
|
+
*
|
|
3560
|
+
* It first updates the floater settings
|
|
3561
|
+
* Then, it retrieves the assigned nodes from the event target and checks if any of
|
|
3562
|
+
* the nodes contain non-empty text content, updating the `hasTriggerContent` property accordingly.
|
|
3563
|
+
*
|
|
3564
|
+
* @private
|
|
3565
|
+
* @method handleTriggerContentSlotChange
|
|
3566
|
+
* @param {Event} event - Native slotchange event.
|
|
3567
|
+
* @returns {void}
|
|
3568
|
+
*/
|
|
3569
|
+
handleTriggerContentSlotChange(event) {
|
|
3570
|
+
|
|
3571
|
+
this.floater.handleTriggerTabIndex();
|
|
3572
|
+
|
|
3573
|
+
// Get the trigger
|
|
3574
|
+
const trigger = this.shadowRoot.querySelector('#trigger');
|
|
3575
|
+
|
|
3576
|
+
// Get the trigger slot
|
|
3577
|
+
const triggerSlot = this.shadowRoot.querySelector('.triggerContent slot');
|
|
3578
|
+
|
|
3579
|
+
// If there's a trigger slot
|
|
3580
|
+
if (triggerSlot) {
|
|
3581
|
+
|
|
3582
|
+
// Get the content nodes to see if there are any children
|
|
3583
|
+
const triggerContentNodes = triggerSlot.assignedNodes();
|
|
3584
|
+
|
|
3585
|
+
// If there are children
|
|
3586
|
+
if (triggerContentNodes) {
|
|
3587
|
+
|
|
3588
|
+
// See if any of them are focusable elemeents
|
|
3589
|
+
this.triggerContentFocusable = triggerContentNodes.some((node) => this.containsFocusableElement(node));
|
|
3590
|
+
|
|
3591
|
+
// If any of them are focusable elements
|
|
3592
|
+
if (this.triggerContentFocusable) {
|
|
3593
|
+
|
|
3594
|
+
// Assume the consumer will be providing their own a11y in whatever they passed in
|
|
3595
|
+
this.clearTriggerA11yAttributes(trigger);
|
|
3596
|
+
|
|
3597
|
+
// Remove the tabindex from the trigger so it doesn't interrupt focus flow
|
|
3598
|
+
trigger.removeAttribute('tabindex');
|
|
3599
|
+
} else {
|
|
3600
|
+
|
|
3601
|
+
// Add the tabindex to the trigger so that it's in the focus flow
|
|
3602
|
+
trigger.setAttribute('tabindex', '0');
|
|
3603
|
+
}
|
|
3604
|
+
}
|
|
3605
|
+
}
|
|
3606
|
+
|
|
3607
|
+
if (event) {
|
|
3608
|
+
this.triggerNode = event.target;
|
|
3609
|
+
this.triggerContentSlot = event.target.assignedNodes();
|
|
3610
|
+
}
|
|
3611
|
+
|
|
3612
|
+
if (this.triggerContentSlot) {
|
|
3613
|
+
this.setupTriggerFocusEventBinding();
|
|
3614
|
+
|
|
3615
|
+
this.hasTriggerContent = this.triggerContentSlot.some((slot) => {
|
|
3616
|
+
if (slot.textContent.trim()) {
|
|
3617
|
+
return true;
|
|
3618
|
+
}
|
|
3619
|
+
const slotInSlot = slot.querySelector('slot');
|
|
3620
|
+
if (!slotInSlot) {
|
|
3621
|
+
return false;
|
|
3622
|
+
}
|
|
3623
|
+
const slotsInSlotNodes = slotInSlot.assignedNodes();
|
|
3624
|
+
return slotsInSlotNodes.some((ss) => Boolean(ss.textContent.trim()));
|
|
3625
|
+
});
|
|
3626
|
+
} else {
|
|
3627
|
+
this.hasTriggerContent = false;
|
|
3628
|
+
}
|
|
3629
|
+
}
|
|
3630
|
+
|
|
3631
|
+
/**
|
|
3632
|
+
* Handles the default slot change event and updates the content.
|
|
3633
|
+
*
|
|
3634
|
+
* This method retrieves all nodes assigned to the default slot of the event target and appends them
|
|
3635
|
+
* to the `bibContent` element. If a callback function `onSlotChange` is defined, it is invoked to
|
|
3636
|
+
* notify about the slot change.
|
|
3637
|
+
*
|
|
3638
|
+
* @private
|
|
3639
|
+
* @method handleDefaultSlot
|
|
3640
|
+
* @param {Event} event - The event object representing the slot change.
|
|
3641
|
+
* @fires Function#onSlotChange - Optional callback invoked when the slot content changes.
|
|
3642
|
+
*/
|
|
3643
|
+
handleDefaultSlot(event) {
|
|
3644
|
+
[...event.target.assignedNodes()].forEach((node) => this.bibContent.append(node));
|
|
3645
|
+
|
|
3646
|
+
if (this.onSlotChange) {
|
|
3647
|
+
this.onSlotChange();
|
|
3648
|
+
}
|
|
3649
|
+
}
|
|
3650
|
+
|
|
3651
|
+
/**
|
|
3652
|
+
* @private
|
|
3653
|
+
* @method handleLabelSlotChange
|
|
3654
|
+
* @param {event} event - The event object representing the slot change.
|
|
3655
|
+
* @description Handles the slot change event for the label slot.
|
|
3656
|
+
*/
|
|
3657
|
+
handleLabelSlotChange (event) {
|
|
3658
|
+
|
|
3659
|
+
// Get the nodes from the event
|
|
3660
|
+
const nodes = event.target.assignedNodes();
|
|
3661
|
+
|
|
3662
|
+
// Guard clause for no nodes
|
|
3663
|
+
if (!nodes) {
|
|
3664
|
+
return;
|
|
3665
|
+
}
|
|
3666
|
+
|
|
3667
|
+
// Convert the nodes to a measurable array so we can get the length
|
|
3668
|
+
const nodesArr = Array.from(nodes);
|
|
3669
|
+
|
|
3670
|
+
// If the nodes array has a length, the dropdown is labeled
|
|
3671
|
+
this.labeled = nodesArr.length > 0;
|
|
3672
|
+
}
|
|
3673
|
+
|
|
3674
|
+
// function that renders the HTML and CSS into the scope of the component
|
|
3675
|
+
render() {
|
|
3676
|
+
return html$1`
|
|
3677
|
+
<div>
|
|
3678
|
+
<div
|
|
3679
|
+
id="trigger"
|
|
3680
|
+
class="trigger"
|
|
3681
|
+
part="trigger"
|
|
3682
|
+
tabindex="${this.tabIndex}"
|
|
3683
|
+
?showBorder="${this.showTriggerBorders}"
|
|
3684
|
+
role="${ifDefined(this.triggerContentFocusable ? undefined : this.a11yRole)}"
|
|
3685
|
+
aria-expanded="${ifDefined(this.triggerContentFocusable ? undefined : this.isPopoverVisible)}"
|
|
3686
|
+
aria-controls="${ifDefined(this.triggerContentFocusable ? undefined : this.dropdownId)}"
|
|
3687
|
+
aria-labelledby="${ifDefined(this.triggerContentFocusable ? undefined : 'triggerLabel')}"
|
|
3688
|
+
>
|
|
3689
|
+
<div class="triggerContentWrapper">
|
|
3690
|
+
<label class="label" id="triggerLabel" hasTrigger=${this.hasTriggerContent}>
|
|
3691
|
+
<slot name="label" @slotchange="${this.handleLabelSlotChange}"></slot>
|
|
3692
|
+
</label>
|
|
3693
|
+
<div class="triggerContent">
|
|
3694
|
+
<slot
|
|
3695
|
+
name="trigger"
|
|
3696
|
+
@slotchange="${this.handleTriggerContentSlotChange}"></slot>
|
|
3697
|
+
</div>
|
|
3698
|
+
</div>
|
|
3699
|
+
${this.chevron || this.common ? html$1`
|
|
3700
|
+
<div
|
|
3701
|
+
id="showStateIcon"
|
|
3702
|
+
part="chevron">
|
|
3703
|
+
<${this.iconTag}
|
|
3704
|
+
category="interface"
|
|
3705
|
+
name="chevron-down"
|
|
3706
|
+
?onDark="${this.onDark}"
|
|
3707
|
+
variant="${this.disabled ? 'disabled' : 'muted'}">
|
|
3708
|
+
>
|
|
3709
|
+
</${this.iconTag}>
|
|
3710
|
+
</div>
|
|
3711
|
+
` : undefined }
|
|
3712
|
+
</div>
|
|
3713
|
+
<${this.helpTextTag} part="helpText" ?onDark=${this.onDark} ?error="${this.error}">
|
|
3714
|
+
<slot name="helpText"></slot>
|
|
3715
|
+
</${this.helpTextTag}>
|
|
3716
|
+
<div class="slotContent">
|
|
3717
|
+
<slot @slotchange="${this.handleDefaultSlot}"></slot>
|
|
3718
|
+
</div>
|
|
3719
|
+
<div id="bibSizer" part="size"></div>
|
|
3720
|
+
<${this.dropdownBibTag}
|
|
3721
|
+
id="bib"
|
|
3722
|
+
?data-show="${this.isPopoverVisible}"
|
|
3723
|
+
?isfullscreen="${this.isBibFullscreen}"
|
|
3724
|
+
?common="${this.common}"
|
|
3725
|
+
?rounded="${this.common || this.rounded}"
|
|
3726
|
+
?inset="${this.common || this.inset}"
|
|
3727
|
+
>
|
|
3728
|
+
</${this.dropdownBibTag}>
|
|
3729
|
+
</div>
|
|
3730
|
+
`;
|
|
3731
|
+
}
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3734
|
+
AuroDropdown.register();
|