primer_view_components 0.27.0 → 0.29.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/app/assets/javascripts/app/components/primer/alpha/action_menu/action_menu_element.d.ts +0 -9
- data/app/assets/javascripts/app/components/primer/alpha/select_panel_element.d.ts +64 -0
- data/app/assets/javascripts/app/components/primer/aria_live.d.ts +8 -0
- data/app/assets/javascripts/app/components/primer/primer.d.ts +4 -0
- data/app/assets/javascripts/app/components/primer/shared_events.d.ts +9 -0
- data/app/assets/javascripts/primer_view_components.js +1 -1
- data/app/assets/javascripts/primer_view_components.js.map +1 -1
- data/app/assets/styles/primer_view_components.css +1 -1
- data/app/assets/styles/primer_view_components.css.map +1 -1
- data/app/components/primer/alpha/action_list.css +1 -1
- data/app/components/primer/alpha/action_list.css.map +1 -1
- data/app/components/primer/alpha/action_list.pcss +1 -0
- data/app/components/primer/alpha/action_menu/action_menu_element.d.ts +0 -9
- data/app/components/primer/alpha/action_menu/action_menu_element.ts +0 -11
- data/app/components/primer/alpha/action_menu.rb +13 -6
- data/app/components/primer/alpha/select_panel.html.erb +100 -0
- data/app/components/primer/alpha/select_panel.rb +486 -0
- data/app/components/primer/alpha/select_panel_element.d.ts +64 -0
- data/app/components/primer/alpha/select_panel_element.js +927 -0
- data/app/components/primer/alpha/select_panel_element.ts +1049 -0
- data/app/components/primer/aria_live.d.ts +8 -0
- data/app/components/primer/aria_live.js +38 -0
- data/app/components/primer/aria_live.ts +41 -0
- data/app/components/primer/base_component.rb +1 -1
- data/app/components/primer/primer.d.ts +4 -0
- data/app/components/primer/primer.js +4 -0
- data/app/components/primer/primer.ts +4 -0
- data/app/components/primer/shared_events.d.ts +9 -0
- data/app/components/primer/shared_events.js +1 -0
- data/app/components/primer/shared_events.ts +10 -0
- data/app/forms/example_toggle_switch_form/example_field_caption.html.erb +1 -1
- data/lib/primer/forms/toggle_switch.html.erb +1 -2
- data/lib/primer/static/generate_info_arch.rb +3 -2
- data/lib/primer/view_components/version.rb +1 -1
- data/lib/primer/yard/component_manifest.rb +2 -0
- data/previews/primer/alpha/action_menu_preview.rb +1 -1
- data/previews/primer/alpha/select_panel_preview/_interaction_subject_js.html.erb +25 -0
- data/previews/primer/alpha/select_panel_preview/eventually_local_fetch.html.erb +16 -0
- data/previews/primer/alpha/select_panel_preview/eventually_local_fetch_initial_failure.html.erb +12 -0
- data/previews/primer/alpha/select_panel_preview/eventually_local_fetch_no_results.html.erb +16 -0
- data/previews/primer/alpha/select_panel_preview/footer_buttons.html.erb +23 -0
- data/previews/primer/alpha/select_panel_preview/local_fetch.html.erb +19 -0
- data/previews/primer/alpha/select_panel_preview/local_fetch_no_results.html.erb +15 -0
- data/previews/primer/alpha/select_panel_preview/multiselect.html.erb +17 -0
- data/previews/primer/alpha/select_panel_preview/multiselect_form.html.erb +31 -0
- data/previews/primer/alpha/select_panel_preview/playground.html.erb +23 -0
- data/previews/primer/alpha/select_panel_preview/remote_fetch.html.erb +16 -0
- data/previews/primer/alpha/select_panel_preview/remote_fetch_filter_failure.html.erb +13 -0
- data/previews/primer/alpha/select_panel_preview/remote_fetch_initial_failure.html.erb +12 -0
- data/previews/primer/alpha/select_panel_preview/remote_fetch_no_results.html.erb +16 -0
- data/previews/primer/alpha/select_panel_preview/single_select.html.erb +20 -0
- data/previews/primer/alpha/select_panel_preview/single_select_form.html.erb +33 -0
- data/previews/primer/alpha/select_panel_preview/with_avatar_items.html.erb +19 -0
- data/previews/primer/alpha/select_panel_preview/with_dynamic_label.html.erb +23 -0
- data/previews/primer/alpha/select_panel_preview/with_dynamic_label_and_aria_prefix.html.erb +24 -0
- data/previews/primer/alpha/select_panel_preview/with_leading_icons.html.erb +31 -0
- data/previews/primer/alpha/select_panel_preview/with_subtitle.html.erb +25 -0
- data/previews/primer/alpha/select_panel_preview/with_trailing_icons.html.erb +19 -0
- data/previews/primer/alpha/select_panel_preview.rb +239 -0
- data/static/arguments.json +140 -0
- data/static/audited_at.json +2 -0
- data/static/constants.json +18 -0
- data/static/info_arch.json +950 -106
- data/static/previews.json +294 -0
- data/static/statuses.json +2 -0
- metadata +39 -2
@@ -0,0 +1,927 @@
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
6
|
+
};
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
11
|
+
};
|
12
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
13
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
14
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
15
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
16
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
17
|
+
};
|
18
|
+
var _SelectPanelElement_instances, _SelectPanelElement_dialogIntersectionObserver, _SelectPanelElement_abortController, _SelectPanelElement_originalLabel, _SelectPanelElement_inputName, _SelectPanelElement_selectedItems, _SelectPanelElement_loadingDelayTimeoutId, _SelectPanelElement_loadingAnnouncementTimeoutId, _SelectPanelElement_waitForCondition, _SelectPanelElement_softDisableItems, _SelectPanelElement_updateTabIndices, _SelectPanelElement_potentiallyDisallowActivation, _SelectPanelElement_isAnchorActivationViaSpace, _SelectPanelElement_isActivation, _SelectPanelElement_checkSelectedItems, _SelectPanelElement_addSelectedItem, _SelectPanelElement_removeSelectedItem, _SelectPanelElement_setTextFieldLoadingSpinnerTimer, _SelectPanelElement_handleIncludeFragmentEvent, _SelectPanelElement_toggleIncludeFragmentElements, _SelectPanelElement_handleRemoteInputEvent, _SelectPanelElement_defaultFilterFn, _SelectPanelElement_handleSearchFieldEvent, _SelectPanelElement_updateItemVisibility, _SelectPanelElement_inErrorState, _SelectPanelElement_setErrorState, _SelectPanelElement_clearErrorState, _SelectPanelElement_maybeAnnounce, _SelectPanelElement_fetchStrategy_get, _SelectPanelElement_filterInputTextFieldElement_get, _SelectPanelElement_performFilteringLocally, _SelectPanelElement_handleInvokerActivated, _SelectPanelElement_handleDialogItemActivated, _SelectPanelElement_handleItemActivated, _SelectPanelElement_setDynamicLabel, _SelectPanelElement_updateInput, _SelectPanelElement_firstItem_get, _SelectPanelElement_hideItem, _SelectPanelElement_showItem, _SelectPanelElement_getItemContent;
|
19
|
+
import { getAnchoredPosition } from '@primer/behaviors';
|
20
|
+
import { controller, target } from '@github/catalyst';
|
21
|
+
import { announceFromElement, announce } from '../aria_live';
|
22
|
+
import { IncludeFragmentElement } from '@github/include-fragment-element';
|
23
|
+
import '@oddbird/popover-polyfill';
|
24
|
+
const validSelectors = ['[role="option"]'];
|
25
|
+
const menuItemSelectors = validSelectors.join(',');
|
26
|
+
const visibleMenuItemSelectors = validSelectors.map(selector => `:not([hidden]) > ${selector}`).join(',');
|
27
|
+
var FetchStrategy;
|
28
|
+
(function (FetchStrategy) {
|
29
|
+
FetchStrategy[FetchStrategy["REMOTE"] = 0] = "REMOTE";
|
30
|
+
FetchStrategy[FetchStrategy["EVENTUALLY_LOCAL"] = 1] = "EVENTUALLY_LOCAL";
|
31
|
+
FetchStrategy[FetchStrategy["LOCAL"] = 2] = "LOCAL";
|
32
|
+
})(FetchStrategy || (FetchStrategy = {}));
|
33
|
+
var ErrorStateType;
|
34
|
+
(function (ErrorStateType) {
|
35
|
+
ErrorStateType[ErrorStateType["BODY"] = 0] = "BODY";
|
36
|
+
ErrorStateType[ErrorStateType["BANNER"] = 1] = "BANNER";
|
37
|
+
})(ErrorStateType || (ErrorStateType = {}));
|
38
|
+
const updateWhenVisible = (() => {
|
39
|
+
const anchors = new Set();
|
40
|
+
let resizeObserver = null;
|
41
|
+
function updateVisibleAnchors() {
|
42
|
+
for (const anchor of anchors) {
|
43
|
+
anchor.updateAnchorPosition();
|
44
|
+
}
|
45
|
+
}
|
46
|
+
return (el) => {
|
47
|
+
// eslint-disable-next-line github/prefer-observers
|
48
|
+
window.addEventListener('resize', updateVisibleAnchors);
|
49
|
+
// eslint-disable-next-line github/prefer-observers
|
50
|
+
window.addEventListener('scroll', updateVisibleAnchors);
|
51
|
+
resizeObserver || (resizeObserver = new ResizeObserver(() => {
|
52
|
+
for (const anchor of anchors) {
|
53
|
+
anchor.updateAnchorPosition();
|
54
|
+
}
|
55
|
+
}));
|
56
|
+
resizeObserver.observe(el.ownerDocument.documentElement);
|
57
|
+
el.addEventListener('dialog:close', () => {
|
58
|
+
anchors.delete(el);
|
59
|
+
});
|
60
|
+
el.addEventListener('dialog:open', () => {
|
61
|
+
anchors.add(el);
|
62
|
+
});
|
63
|
+
};
|
64
|
+
})();
|
65
|
+
let SelectPanelElement = class SelectPanelElement extends HTMLElement {
|
66
|
+
constructor() {
|
67
|
+
super(...arguments);
|
68
|
+
_SelectPanelElement_instances.add(this);
|
69
|
+
_SelectPanelElement_dialogIntersectionObserver.set(this, void 0);
|
70
|
+
_SelectPanelElement_abortController.set(this, void 0);
|
71
|
+
_SelectPanelElement_originalLabel.set(this, '');
|
72
|
+
_SelectPanelElement_inputName.set(this, '');
|
73
|
+
_SelectPanelElement_selectedItems.set(this, new Map());
|
74
|
+
_SelectPanelElement_loadingDelayTimeoutId.set(this, null);
|
75
|
+
_SelectPanelElement_loadingAnnouncementTimeoutId.set(this, null);
|
76
|
+
}
|
77
|
+
get open() {
|
78
|
+
return this.dialog.open;
|
79
|
+
}
|
80
|
+
get selectVariant() {
|
81
|
+
return this.getAttribute('data-select-variant');
|
82
|
+
}
|
83
|
+
get ariaSelectionType() {
|
84
|
+
return this.selectVariant === 'multiple' ? 'aria-checked' : 'aria-selected';
|
85
|
+
}
|
86
|
+
set selectVariant(variant) {
|
87
|
+
if (variant) {
|
88
|
+
this.setAttribute('data-select-variant', variant);
|
89
|
+
}
|
90
|
+
else {
|
91
|
+
this.removeAttribute('variant');
|
92
|
+
}
|
93
|
+
}
|
94
|
+
get dynamicLabelPrefix() {
|
95
|
+
const prefix = this.getAttribute('data-dynamic-label-prefix');
|
96
|
+
if (!prefix)
|
97
|
+
return '';
|
98
|
+
return `${prefix}:`;
|
99
|
+
}
|
100
|
+
get dynamicAriaLabelPrefix() {
|
101
|
+
const prefix = this.getAttribute('data-dynamic-aria-label-prefix');
|
102
|
+
if (!prefix)
|
103
|
+
return '';
|
104
|
+
return `${prefix}:`;
|
105
|
+
}
|
106
|
+
set dynamicLabelPrefix(value) {
|
107
|
+
this.setAttribute('data-dynamic-label', value);
|
108
|
+
}
|
109
|
+
get dynamicLabel() {
|
110
|
+
return this.hasAttribute('data-dynamic-label');
|
111
|
+
}
|
112
|
+
set dynamicLabel(value) {
|
113
|
+
this.toggleAttribute('data-dynamic-label', value);
|
114
|
+
}
|
115
|
+
get invokerElement() {
|
116
|
+
const id = this.querySelector('dialog')?.id;
|
117
|
+
if (!id)
|
118
|
+
return null;
|
119
|
+
for (const el of this.querySelectorAll(`[aria-controls]`)) {
|
120
|
+
if (el.getAttribute('aria-controls') === id) {
|
121
|
+
return el;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
return null;
|
125
|
+
}
|
126
|
+
get closeButton() {
|
127
|
+
return this.querySelector('button[data-close-dialog-id]');
|
128
|
+
}
|
129
|
+
get invokerLabel() {
|
130
|
+
if (!this.invokerElement)
|
131
|
+
return null;
|
132
|
+
return this.invokerElement.querySelector('.Button-label');
|
133
|
+
}
|
134
|
+
get selectedItems() {
|
135
|
+
return Array.from(__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").values());
|
136
|
+
}
|
137
|
+
get align() {
|
138
|
+
return (this.getAttribute('anchor-align') || 'start');
|
139
|
+
}
|
140
|
+
get side() {
|
141
|
+
return (this.getAttribute('anchor-side') || 'outside-bottom');
|
142
|
+
}
|
143
|
+
updateAnchorPosition() {
|
144
|
+
// If the selectPanel is removed from the screen on resize close the dialog
|
145
|
+
if (this && this.offsetParent === null) {
|
146
|
+
this.dialog.close();
|
147
|
+
}
|
148
|
+
if (this.invokerElement) {
|
149
|
+
const { top, left } = getAnchoredPosition(this.dialog, this.invokerElement, {
|
150
|
+
align: this.align,
|
151
|
+
side: this.side,
|
152
|
+
anchorOffset: 4,
|
153
|
+
});
|
154
|
+
this.dialog.style.top = `${top}px`;
|
155
|
+
this.dialog.style.left = `${left}px`;
|
156
|
+
this.dialog.style.bottom = 'auto';
|
157
|
+
this.dialog.style.right = 'auto';
|
158
|
+
}
|
159
|
+
}
|
160
|
+
connectedCallback() {
|
161
|
+
const { signal } = (__classPrivateFieldSet(this, _SelectPanelElement_abortController, new AbortController(), "f"));
|
162
|
+
this.addEventListener('keydown', this, { signal });
|
163
|
+
this.addEventListener('click', this, { signal });
|
164
|
+
this.addEventListener('mousedown', this, { signal });
|
165
|
+
this.addEventListener('input', this, { signal });
|
166
|
+
this.addEventListener('remote-input-success', this, { signal });
|
167
|
+
this.addEventListener('remote-input-error', this, { signal });
|
168
|
+
this.addEventListener('loadstart', this, { signal });
|
169
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setDynamicLabel).call(this);
|
170
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
171
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_softDisableItems).call(this);
|
172
|
+
updateWhenVisible(this);
|
173
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.remoteInput), () => {
|
174
|
+
this.remoteInput.addEventListener('loadstart', this, { signal });
|
175
|
+
this.remoteInput.addEventListener('loadend', this, { signal });
|
176
|
+
});
|
177
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.includeFragment), () => {
|
178
|
+
this.includeFragment.addEventListener('include-fragment-replaced', this, { signal });
|
179
|
+
this.includeFragment.addEventListener('error', this, { signal });
|
180
|
+
this.includeFragment.addEventListener('loadend', this, { signal });
|
181
|
+
});
|
182
|
+
__classPrivateFieldSet(this, _SelectPanelElement_dialogIntersectionObserver, new IntersectionObserver(entries => {
|
183
|
+
for (const entry of entries) {
|
184
|
+
const elem = entry.target;
|
185
|
+
if (entry.isIntersecting && elem === this.dialog) {
|
186
|
+
this.updateAnchorPosition();
|
187
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL) {
|
188
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
}
|
192
|
+
}), "f");
|
193
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.dialog), () => {
|
194
|
+
if (this.getAttribute('data-open-on-load') === 'true') {
|
195
|
+
this.show();
|
196
|
+
}
|
197
|
+
__classPrivateFieldGet(this, _SelectPanelElement_dialogIntersectionObserver, "f").observe(this.dialog);
|
198
|
+
this.dialog.addEventListener('close', this, { signal });
|
199
|
+
});
|
200
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL) {
|
201
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => this.items.length > 0, () => {
|
202
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
203
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
204
|
+
});
|
205
|
+
}
|
206
|
+
}
|
207
|
+
disconnectedCallback() {
|
208
|
+
__classPrivateFieldGet(this, _SelectPanelElement_abortController, "f").abort();
|
209
|
+
}
|
210
|
+
handleEvent(event) {
|
211
|
+
if (event.target === this.filterInputTextField) {
|
212
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleSearchFieldEvent).call(this, event);
|
213
|
+
return;
|
214
|
+
}
|
215
|
+
if (event.target === this.remoteInput) {
|
216
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleRemoteInputEvent).call(this, event);
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
const targetIsInvoker = this.invokerElement?.contains(event.target);
|
220
|
+
const targetIsCloseButton = this.closeButton?.contains(event.target);
|
221
|
+
const eventIsActivation = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_isActivation).call(this, event);
|
222
|
+
if (targetIsInvoker && event.type === 'mousedown') {
|
223
|
+
return;
|
224
|
+
}
|
225
|
+
if (event.type === 'mousedown' && event.target instanceof HTMLInputElement) {
|
226
|
+
return;
|
227
|
+
}
|
228
|
+
// Prevent safari bug that dismisses menu on mousedown instead of allowing
|
229
|
+
// the click event to propagate to the button
|
230
|
+
if (event.type === 'mousedown') {
|
231
|
+
event.preventDefault();
|
232
|
+
return;
|
233
|
+
}
|
234
|
+
if (targetIsInvoker && eventIsActivation) {
|
235
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleInvokerActivated).call(this, event);
|
236
|
+
return;
|
237
|
+
}
|
238
|
+
if (targetIsCloseButton && eventIsActivation) {
|
239
|
+
// hide() will automatically be called by dialog event triggered from `data-close-dialog-id`
|
240
|
+
return;
|
241
|
+
}
|
242
|
+
if (event.target === this.dialog && event.type === 'close') {
|
243
|
+
this.dispatchEvent(new CustomEvent('panelClosed', {
|
244
|
+
detail: { panel: this },
|
245
|
+
bubbles: true,
|
246
|
+
}));
|
247
|
+
return;
|
248
|
+
}
|
249
|
+
const item = event.target.closest(visibleMenuItemSelectors)?.parentElement;
|
250
|
+
const targetIsItem = item !== null && item !== undefined;
|
251
|
+
if (targetIsItem && eventIsActivation) {
|
252
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_potentiallyDisallowActivation).call(this, event))
|
253
|
+
return;
|
254
|
+
const dialogInvoker = item.closest('[data-show-dialog-id]');
|
255
|
+
if (dialogInvoker) {
|
256
|
+
const dialog = this.ownerDocument.getElementById(dialogInvoker.getAttribute('data-show-dialog-id') || '');
|
257
|
+
if (dialog && this.contains(dialogInvoker) && this.contains(dialog)) {
|
258
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleDialogItemActivated).call(this, event, dialog);
|
259
|
+
return;
|
260
|
+
}
|
261
|
+
}
|
262
|
+
// Pressing the space key on a link will cause the page to scroll unless preventDefault() is called.
|
263
|
+
// We then click it manually to navigate.
|
264
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_isAnchorActivationViaSpace).call(this, event)) {
|
265
|
+
event.preventDefault();
|
266
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item)?.click();
|
267
|
+
}
|
268
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleItemActivated).call(this, item);
|
269
|
+
return;
|
270
|
+
}
|
271
|
+
if (event.type === 'click') {
|
272
|
+
const rect = this.dialog.getBoundingClientRect();
|
273
|
+
const clickWasInsideDialog = rect.top <= event.clientY &&
|
274
|
+
event.clientY <= rect.top + rect.height &&
|
275
|
+
rect.left <= event.clientX &&
|
276
|
+
event.clientX <= rect.left + rect.width;
|
277
|
+
if (!clickWasInsideDialog) {
|
278
|
+
this.hide();
|
279
|
+
}
|
280
|
+
}
|
281
|
+
// The include fragment will have been removed from the DOM by the time
|
282
|
+
// the include-fragment-replaced event has been dispatched, so we have to
|
283
|
+
// check for the type of the event target manually, since this.includeFragment
|
284
|
+
// will be null.
|
285
|
+
if (event.target instanceof IncludeFragmentElement) {
|
286
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleIncludeFragmentEvent).call(this, event);
|
287
|
+
}
|
288
|
+
}
|
289
|
+
show() {
|
290
|
+
this.updateAnchorPosition();
|
291
|
+
this.dialog.showModal();
|
292
|
+
const event = new CustomEvent('dialog:open', {
|
293
|
+
detail: { dialog: this.dialog },
|
294
|
+
});
|
295
|
+
this.dispatchEvent(event);
|
296
|
+
}
|
297
|
+
hide() {
|
298
|
+
this.dialog.close();
|
299
|
+
}
|
300
|
+
get visibleItems() {
|
301
|
+
return Array.from(this.querySelectorAll(visibleMenuItemSelectors)).map(element => element.parentElement);
|
302
|
+
}
|
303
|
+
get items() {
|
304
|
+
return Array.from(this.querySelectorAll(menuItemSelectors)).map(element => element.parentElement);
|
305
|
+
}
|
306
|
+
get focusableItem() {
|
307
|
+
for (const item of this.items) {
|
308
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
309
|
+
if (!itemContent)
|
310
|
+
continue;
|
311
|
+
if (itemContent.getAttribute('tabindex') === '0') {
|
312
|
+
return itemContent;
|
313
|
+
}
|
314
|
+
}
|
315
|
+
}
|
316
|
+
getItemById(itemId) {
|
317
|
+
return this.querySelector(`li[data-item-id="${itemId}"`);
|
318
|
+
}
|
319
|
+
isItemDisabled(item) {
|
320
|
+
if (item) {
|
321
|
+
return item.classList.contains('ActionListItem--disabled');
|
322
|
+
}
|
323
|
+
else {
|
324
|
+
return false;
|
325
|
+
}
|
326
|
+
}
|
327
|
+
disableItem(item) {
|
328
|
+
if (item) {
|
329
|
+
item.classList.add('ActionListItem--disabled');
|
330
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item).setAttribute('aria-disabled', 'true');
|
331
|
+
}
|
332
|
+
}
|
333
|
+
enableItem(item) {
|
334
|
+
if (item) {
|
335
|
+
item.classList.remove('ActionListItem--disabled');
|
336
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item).removeAttribute('aria-disabled');
|
337
|
+
}
|
338
|
+
}
|
339
|
+
isItemHidden(item) {
|
340
|
+
if (item) {
|
341
|
+
return item.hasAttribute('hidden');
|
342
|
+
}
|
343
|
+
else {
|
344
|
+
return false;
|
345
|
+
}
|
346
|
+
}
|
347
|
+
isItemChecked(item) {
|
348
|
+
if (item) {
|
349
|
+
return __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item).getAttribute(this.ariaSelectionType) === 'true';
|
350
|
+
}
|
351
|
+
else {
|
352
|
+
return false;
|
353
|
+
}
|
354
|
+
}
|
355
|
+
checkItem(item) {
|
356
|
+
if (item && (this.selectVariant === 'single' || this.selectVariant === 'multiple')) {
|
357
|
+
if (!this.isItemChecked(item)) {
|
358
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleItemActivated).call(this, item);
|
359
|
+
}
|
360
|
+
}
|
361
|
+
}
|
362
|
+
uncheckItem(item) {
|
363
|
+
if (item && (this.selectVariant === 'single' || this.selectVariant === 'multiple')) {
|
364
|
+
if (this.isItemChecked(item)) {
|
365
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleItemActivated).call(this, item);
|
366
|
+
}
|
367
|
+
}
|
368
|
+
}
|
369
|
+
};
|
370
|
+
_SelectPanelElement_dialogIntersectionObserver = new WeakMap();
|
371
|
+
_SelectPanelElement_abortController = new WeakMap();
|
372
|
+
_SelectPanelElement_originalLabel = new WeakMap();
|
373
|
+
_SelectPanelElement_inputName = new WeakMap();
|
374
|
+
_SelectPanelElement_selectedItems = new WeakMap();
|
375
|
+
_SelectPanelElement_loadingDelayTimeoutId = new WeakMap();
|
376
|
+
_SelectPanelElement_loadingAnnouncementTimeoutId = new WeakMap();
|
377
|
+
_SelectPanelElement_instances = new WeakSet();
|
378
|
+
_SelectPanelElement_waitForCondition = function _SelectPanelElement_waitForCondition(condition, body) {
|
379
|
+
if (condition()) {
|
380
|
+
body();
|
381
|
+
}
|
382
|
+
else {
|
383
|
+
const mutationObserver = new MutationObserver(() => {
|
384
|
+
if (condition()) {
|
385
|
+
body();
|
386
|
+
mutationObserver.disconnect();
|
387
|
+
}
|
388
|
+
});
|
389
|
+
mutationObserver.observe(this, { childList: true, subtree: true });
|
390
|
+
}
|
391
|
+
};
|
392
|
+
_SelectPanelElement_softDisableItems = function _SelectPanelElement_softDisableItems() {
|
393
|
+
const { signal } = __classPrivateFieldGet(this, _SelectPanelElement_abortController, "f");
|
394
|
+
for (const item of this.querySelectorAll(validSelectors.join(','))) {
|
395
|
+
item.addEventListener('click', __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_potentiallyDisallowActivation).bind(this), { signal });
|
396
|
+
item.addEventListener('keydown', __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_potentiallyDisallowActivation).bind(this), { signal });
|
397
|
+
}
|
398
|
+
};
|
399
|
+
_SelectPanelElement_updateTabIndices = function _SelectPanelElement_updateTabIndices() {
|
400
|
+
let setZeroTabIndex = false;
|
401
|
+
if (this.selectVariant === 'single') {
|
402
|
+
for (const item of this.items) {
|
403
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
404
|
+
if (!itemContent)
|
405
|
+
continue;
|
406
|
+
if (!this.isItemHidden(item) && this.isItemChecked(item) && !setZeroTabIndex) {
|
407
|
+
itemContent.setAttribute('tabindex', '0');
|
408
|
+
setZeroTabIndex = true;
|
409
|
+
}
|
410
|
+
else {
|
411
|
+
itemContent.setAttribute('tabindex', '-1');
|
412
|
+
}
|
413
|
+
// <li> elements should not themselves be tabbable
|
414
|
+
item.setAttribute('tabindex', '-1');
|
415
|
+
}
|
416
|
+
}
|
417
|
+
else {
|
418
|
+
for (const item of this.items) {
|
419
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
420
|
+
if (!itemContent)
|
421
|
+
continue;
|
422
|
+
if (!this.isItemHidden(item) && !setZeroTabIndex) {
|
423
|
+
setZeroTabIndex = true;
|
424
|
+
}
|
425
|
+
else {
|
426
|
+
itemContent.setAttribute('tabindex', '-1');
|
427
|
+
}
|
428
|
+
// <li> elements should not themselves be tabbable
|
429
|
+
item.setAttribute('tabindex', '-1');
|
430
|
+
}
|
431
|
+
}
|
432
|
+
if (!setZeroTabIndex && __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_firstItem_get)) {
|
433
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_firstItem_get))?.setAttribute('tabindex', '0');
|
434
|
+
}
|
435
|
+
};
|
436
|
+
_SelectPanelElement_potentiallyDisallowActivation = function _SelectPanelElement_potentiallyDisallowActivation(event) {
|
437
|
+
if (!__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_isActivation).call(this, event))
|
438
|
+
return false;
|
439
|
+
const item = event.target.closest(visibleMenuItemSelectors);
|
440
|
+
if (!item)
|
441
|
+
return false;
|
442
|
+
if (item.getAttribute('aria-disabled')) {
|
443
|
+
event.preventDefault();
|
444
|
+
// eslint-disable-next-line no-restricted-syntax
|
445
|
+
event.stopPropagation();
|
446
|
+
// eslint-disable-next-line no-restricted-syntax
|
447
|
+
event.stopImmediatePropagation();
|
448
|
+
return true;
|
449
|
+
}
|
450
|
+
return false;
|
451
|
+
};
|
452
|
+
_SelectPanelElement_isAnchorActivationViaSpace = function _SelectPanelElement_isAnchorActivationViaSpace(event) {
|
453
|
+
return (event.target instanceof HTMLAnchorElement &&
|
454
|
+
event instanceof KeyboardEvent &&
|
455
|
+
event.type === 'keydown' &&
|
456
|
+
!(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
|
457
|
+
event.key === ' ');
|
458
|
+
};
|
459
|
+
_SelectPanelElement_isActivation = function _SelectPanelElement_isActivation(event) {
|
460
|
+
// Some browsers fire MouseEvents (Firefox) and others fire PointerEvents (Chrome). Activating an item via
|
461
|
+
// enter or space counterintuitively fires one of these rather than a KeyboardEvent. Since PointerEvent
|
462
|
+
// inherits from MouseEvent, it is enough to check for MouseEvent here.
|
463
|
+
return (event instanceof MouseEvent && event.type === 'click') || __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_isAnchorActivationViaSpace).call(this, event);
|
464
|
+
};
|
465
|
+
_SelectPanelElement_checkSelectedItems = function _SelectPanelElement_checkSelectedItems() {
|
466
|
+
for (const item of this.items) {
|
467
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
468
|
+
if (!itemContent)
|
469
|
+
continue;
|
470
|
+
const value = itemContent.getAttribute('data-value');
|
471
|
+
if (value) {
|
472
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").has(value)) {
|
473
|
+
itemContent.setAttribute(this.ariaSelectionType, 'true');
|
474
|
+
}
|
475
|
+
}
|
476
|
+
}
|
477
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
478
|
+
};
|
479
|
+
_SelectPanelElement_addSelectedItem = function _SelectPanelElement_addSelectedItem(item) {
|
480
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
481
|
+
if (!itemContent)
|
482
|
+
return;
|
483
|
+
const value = itemContent.getAttribute('data-value');
|
484
|
+
if (value) {
|
485
|
+
__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").set(value, {
|
486
|
+
value,
|
487
|
+
label: itemContent.querySelector('.ActionListItem-label')?.textContent?.trim(),
|
488
|
+
inputName: itemContent.getAttribute('data-input-name'),
|
489
|
+
element: item,
|
490
|
+
});
|
491
|
+
}
|
492
|
+
};
|
493
|
+
_SelectPanelElement_removeSelectedItem = function _SelectPanelElement_removeSelectedItem(item) {
|
494
|
+
const value = item.getAttribute('data-value');
|
495
|
+
if (value) {
|
496
|
+
__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").delete(value);
|
497
|
+
}
|
498
|
+
};
|
499
|
+
_SelectPanelElement_setTextFieldLoadingSpinnerTimer = function _SelectPanelElement_setTextFieldLoadingSpinnerTimer() {
|
500
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_loadingDelayTimeoutId, "f"))
|
501
|
+
clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingDelayTimeoutId, "f"));
|
502
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"))
|
503
|
+
clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"));
|
504
|
+
__classPrivateFieldSet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, setTimeout(() => {
|
505
|
+
announce('Loading', { element: this.ariaLiveContainer });
|
506
|
+
}, 2000), "f");
|
507
|
+
__classPrivateFieldSet(this, _SelectPanelElement_loadingDelayTimeoutId, setTimeout(() => {
|
508
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_filterInputTextFieldElement_get).showLeadingSpinner();
|
509
|
+
}, 1000), "f");
|
510
|
+
};
|
511
|
+
_SelectPanelElement_handleIncludeFragmentEvent = function _SelectPanelElement_handleIncludeFragmentEvent(event) {
|
512
|
+
switch (event.type) {
|
513
|
+
case 'include-fragment-replaced': {
|
514
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
515
|
+
break;
|
516
|
+
}
|
517
|
+
case 'loadstart': {
|
518
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_toggleIncludeFragmentElements).call(this, false);
|
519
|
+
break;
|
520
|
+
}
|
521
|
+
case 'loadend': {
|
522
|
+
this.dispatchEvent(new CustomEvent('loadend'));
|
523
|
+
break;
|
524
|
+
}
|
525
|
+
case 'error': {
|
526
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_toggleIncludeFragmentElements).call(this, true);
|
527
|
+
const errorElement = this.fragmentErrorElement;
|
528
|
+
// check if the errorElement is visible in the dom
|
529
|
+
if (errorElement && !errorElement.hasAttribute('hidden')) {
|
530
|
+
announceFromElement(errorElement, { element: this.ariaLiveContainer, assertive: true });
|
531
|
+
return;
|
532
|
+
}
|
533
|
+
break;
|
534
|
+
}
|
535
|
+
}
|
536
|
+
};
|
537
|
+
_SelectPanelElement_toggleIncludeFragmentElements = function _SelectPanelElement_toggleIncludeFragmentElements(showError) {
|
538
|
+
for (const el of this.includeFragment.querySelectorAll('[data-show-on-error]')) {
|
539
|
+
if (el instanceof HTMLElement)
|
540
|
+
el.hidden = !showError;
|
541
|
+
}
|
542
|
+
for (const el of this.includeFragment.querySelectorAll('[data-hide-on-error]')) {
|
543
|
+
if (el instanceof HTMLElement)
|
544
|
+
el.hidden = showError;
|
545
|
+
}
|
546
|
+
};
|
547
|
+
_SelectPanelElement_handleRemoteInputEvent = function _SelectPanelElement_handleRemoteInputEvent(event) {
|
548
|
+
switch (event.type) {
|
549
|
+
case 'remote-input-success': {
|
550
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_clearErrorState).call(this);
|
551
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
552
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_checkSelectedItems).call(this);
|
553
|
+
break;
|
554
|
+
}
|
555
|
+
case 'remote-input-error': {
|
556
|
+
this.bodySpinner?.setAttribute('hidden', '');
|
557
|
+
if (this.includeFragment || this.visibleItems.length === 0) {
|
558
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setErrorState).call(this, ErrorStateType.BODY);
|
559
|
+
}
|
560
|
+
else {
|
561
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setErrorState).call(this, ErrorStateType.BANNER);
|
562
|
+
}
|
563
|
+
break;
|
564
|
+
}
|
565
|
+
case 'loadstart': {
|
566
|
+
if (!__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_performFilteringLocally).call(this)) {
|
567
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_clearErrorState).call(this);
|
568
|
+
this.bodySpinner?.removeAttribute('hidden');
|
569
|
+
if (this.bodySpinner)
|
570
|
+
break;
|
571
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setTextFieldLoadingSpinnerTimer).call(this);
|
572
|
+
}
|
573
|
+
break;
|
574
|
+
}
|
575
|
+
case 'loadend': {
|
576
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_filterInputTextFieldElement_get).hideLeadingSpinner();
|
577
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"))
|
578
|
+
clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"));
|
579
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_loadingDelayTimeoutId, "f"))
|
580
|
+
clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingDelayTimeoutId, "f"));
|
581
|
+
this.dispatchEvent(new CustomEvent('loadend'));
|
582
|
+
break;
|
583
|
+
}
|
584
|
+
}
|
585
|
+
};
|
586
|
+
_SelectPanelElement_defaultFilterFn = function _SelectPanelElement_defaultFilterFn(item, query) {
|
587
|
+
const text = (item.getAttribute('data-filter-string') || item.textContent || '').toLowerCase();
|
588
|
+
return text.indexOf(query.toLowerCase()) > -1;
|
589
|
+
};
|
590
|
+
_SelectPanelElement_handleSearchFieldEvent = function _SelectPanelElement_handleSearchFieldEvent(event) {
|
591
|
+
if (event.type === 'keydown' && event.key === 'ArrowDown') {
|
592
|
+
if (this.focusableItem) {
|
593
|
+
this.focusableItem.focus();
|
594
|
+
event.preventDefault();
|
595
|
+
}
|
596
|
+
}
|
597
|
+
if (event.type !== 'input')
|
598
|
+
return;
|
599
|
+
// remote-input-element does not trigger another loadstart event if a request is
|
600
|
+
// already in-flight, so we use the input event on the text field to reset the
|
601
|
+
// loading spinner timer instead
|
602
|
+
if (!this.bodySpinner && !__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_performFilteringLocally).call(this)) {
|
603
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setTextFieldLoadingSpinnerTimer).call(this);
|
604
|
+
}
|
605
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL || __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.EVENTUALLY_LOCAL) {
|
606
|
+
if (this.includeFragment) {
|
607
|
+
this.includeFragment.refetch();
|
608
|
+
return;
|
609
|
+
}
|
610
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
611
|
+
}
|
612
|
+
};
|
613
|
+
_SelectPanelElement_updateItemVisibility = function _SelectPanelElement_updateItemVisibility() {
|
614
|
+
if (!this.list)
|
615
|
+
return;
|
616
|
+
let atLeastOneResult = false;
|
617
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_performFilteringLocally).call(this)) {
|
618
|
+
const query = this.filterInputTextField?.value ?? '';
|
619
|
+
const filter = this.filterFn || __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_defaultFilterFn);
|
620
|
+
for (const item of this.items) {
|
621
|
+
if (filter(item, query)) {
|
622
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_showItem).call(this, item);
|
623
|
+
atLeastOneResult = true;
|
624
|
+
}
|
625
|
+
else {
|
626
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_hideItem).call(this, item);
|
627
|
+
}
|
628
|
+
}
|
629
|
+
}
|
630
|
+
else {
|
631
|
+
atLeastOneResult = this.items.length > 0;
|
632
|
+
}
|
633
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateTabIndices).call(this);
|
634
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_maybeAnnounce).call(this);
|
635
|
+
for (const item of this.items) {
|
636
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
637
|
+
if (!itemContent)
|
638
|
+
continue;
|
639
|
+
const value = itemContent.getAttribute('data-value');
|
640
|
+
if (value && !__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").has(value) && this.isItemChecked(item)) {
|
641
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_addSelectedItem).call(this, item);
|
642
|
+
}
|
643
|
+
}
|
644
|
+
if (!this.noResults)
|
645
|
+
return;
|
646
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_inErrorState).call(this)) {
|
647
|
+
this.noResults.setAttribute('hidden', '');
|
648
|
+
return;
|
649
|
+
}
|
650
|
+
if (atLeastOneResult) {
|
651
|
+
this.noResults.setAttribute('hidden', '');
|
652
|
+
// TODO can we change this to search for `@panelId-list`
|
653
|
+
this.list?.querySelector('.ActionListWrap')?.removeAttribute('hidden');
|
654
|
+
}
|
655
|
+
else {
|
656
|
+
this.list?.querySelector('.ActionListWrap')?.setAttribute('hidden', '');
|
657
|
+
this.noResults.removeAttribute('hidden');
|
658
|
+
}
|
659
|
+
};
|
660
|
+
_SelectPanelElement_inErrorState = function _SelectPanelElement_inErrorState() {
|
661
|
+
if (this.fragmentErrorElement && !this.fragmentErrorElement.hasAttribute('hidden')) {
|
662
|
+
return true;
|
663
|
+
}
|
664
|
+
return !this.bannerErrorElement.hasAttribute('hidden');
|
665
|
+
};
|
666
|
+
_SelectPanelElement_setErrorState = function _SelectPanelElement_setErrorState(type) {
|
667
|
+
let errorElement = this.fragmentErrorElement;
|
668
|
+
if (type === ErrorStateType.BODY) {
|
669
|
+
this.fragmentErrorElement?.removeAttribute('hidden');
|
670
|
+
this.bannerErrorElement.setAttribute('hidden', '');
|
671
|
+
}
|
672
|
+
else {
|
673
|
+
errorElement = this.bannerErrorElement;
|
674
|
+
this.bannerErrorElement?.removeAttribute('hidden');
|
675
|
+
this.fragmentErrorElement?.setAttribute('hidden', '');
|
676
|
+
}
|
677
|
+
// check if the errorElement is visible in the dom
|
678
|
+
if (errorElement && !errorElement.hasAttribute('hidden')) {
|
679
|
+
announceFromElement(errorElement, { element: this.ariaLiveContainer, assertive: true });
|
680
|
+
return;
|
681
|
+
}
|
682
|
+
};
|
683
|
+
_SelectPanelElement_clearErrorState = function _SelectPanelElement_clearErrorState() {
|
684
|
+
this.fragmentErrorElement?.setAttribute('hidden', '');
|
685
|
+
this.bannerErrorElement.setAttribute('hidden', '');
|
686
|
+
};
|
687
|
+
_SelectPanelElement_maybeAnnounce = function _SelectPanelElement_maybeAnnounce() {
|
688
|
+
if (this.open && this.list) {
|
689
|
+
const items = this.items;
|
690
|
+
if (items.length > 0) {
|
691
|
+
const instructions = 'tab for results';
|
692
|
+
announce(`${items.length} result${items.length === 1 ? '' : 's'} ${instructions}`, {
|
693
|
+
element: this.ariaLiveContainer,
|
694
|
+
});
|
695
|
+
}
|
696
|
+
else {
|
697
|
+
const noResultsEl = this.noResults;
|
698
|
+
if (noResultsEl) {
|
699
|
+
announceFromElement(noResultsEl, { element: this.ariaLiveContainer });
|
700
|
+
}
|
701
|
+
}
|
702
|
+
}
|
703
|
+
};
|
704
|
+
_SelectPanelElement_fetchStrategy_get = function _SelectPanelElement_fetchStrategy_get() {
|
705
|
+
if (!this.list)
|
706
|
+
return FetchStrategy.REMOTE;
|
707
|
+
switch (this.list.getAttribute('data-fetch-strategy')) {
|
708
|
+
case 'local':
|
709
|
+
return FetchStrategy.LOCAL;
|
710
|
+
case 'eventually_local':
|
711
|
+
return FetchStrategy.EVENTUALLY_LOCAL;
|
712
|
+
default:
|
713
|
+
return FetchStrategy.REMOTE;
|
714
|
+
}
|
715
|
+
};
|
716
|
+
_SelectPanelElement_filterInputTextFieldElement_get = function _SelectPanelElement_filterInputTextFieldElement_get() {
|
717
|
+
return this.filterInputTextField.closest('primer-text-field');
|
718
|
+
};
|
719
|
+
_SelectPanelElement_performFilteringLocally = function _SelectPanelElement_performFilteringLocally() {
|
720
|
+
return __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL || __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.EVENTUALLY_LOCAL;
|
721
|
+
};
|
722
|
+
_SelectPanelElement_handleInvokerActivated = function _SelectPanelElement_handleInvokerActivated(event) {
|
723
|
+
event.preventDefault();
|
724
|
+
// eslint-disable-next-line no-restricted-syntax
|
725
|
+
event.stopPropagation();
|
726
|
+
if (this.open) {
|
727
|
+
this.hide();
|
728
|
+
}
|
729
|
+
else {
|
730
|
+
this.show();
|
731
|
+
}
|
732
|
+
};
|
733
|
+
_SelectPanelElement_handleDialogItemActivated = function _SelectPanelElement_handleDialogItemActivated(event, dialog) {
|
734
|
+
this.querySelector('.ActionListWrap').style.display = 'none';
|
735
|
+
const dialog_controller = new AbortController();
|
736
|
+
const { signal } = dialog_controller;
|
737
|
+
const handleDialogClose = () => {
|
738
|
+
dialog_controller.abort();
|
739
|
+
this.querySelector('.ActionListWrap').style.display = '';
|
740
|
+
if (this.open) {
|
741
|
+
this.hide();
|
742
|
+
}
|
743
|
+
const activeElement = this.ownerDocument.activeElement;
|
744
|
+
const lostFocus = this.ownerDocument.activeElement === this.ownerDocument.body;
|
745
|
+
const focusInClosedMenu = this.contains(activeElement);
|
746
|
+
if (lostFocus || focusInClosedMenu) {
|
747
|
+
setTimeout(() => this.invokerElement?.focus(), 0);
|
748
|
+
}
|
749
|
+
};
|
750
|
+
// a modal <dialog> element will close all popovers
|
751
|
+
dialog.addEventListener('close', handleDialogClose, { signal });
|
752
|
+
dialog.addEventListener('cancel', handleDialogClose, { signal });
|
753
|
+
};
|
754
|
+
_SelectPanelElement_handleItemActivated = function _SelectPanelElement_handleItemActivated(item) {
|
755
|
+
// Hide popover after current event loop to prevent changes in focus from
|
756
|
+
// altering the target of the event. Not doing this specifically affects
|
757
|
+
// <a> tags. It causes the event to be sent to the currently focused element
|
758
|
+
// instead of the anchor, which effectively prevents navigation, i.e. it
|
759
|
+
// appears as if hitting enter does nothing. Curiously, clicking instead
|
760
|
+
// works fine.
|
761
|
+
if (this.selectVariant !== 'multiple') {
|
762
|
+
setTimeout(() => {
|
763
|
+
if (this.open) {
|
764
|
+
this.hide();
|
765
|
+
}
|
766
|
+
});
|
767
|
+
}
|
768
|
+
// The rest of the code below deals with single/multiple selection behavior, and should not
|
769
|
+
// interfere with events fired by menu items whose behavior is specified outside the library.
|
770
|
+
if (this.selectVariant !== 'multiple' && this.selectVariant !== 'single')
|
771
|
+
return;
|
772
|
+
const checked = !this.isItemChecked(item);
|
773
|
+
const activationSuccess = this.dispatchEvent(new CustomEvent('beforeItemActivated', {
|
774
|
+
bubbles: true,
|
775
|
+
detail: { item, checked },
|
776
|
+
cancelable: true,
|
777
|
+
}));
|
778
|
+
if (!activationSuccess)
|
779
|
+
return;
|
780
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
781
|
+
if (this.selectVariant === 'single') {
|
782
|
+
// Only check, never uncheck here. Single-select mode does not allow unchecking a checked item.
|
783
|
+
if (checked) {
|
784
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_addSelectedItem).call(this, item);
|
785
|
+
itemContent?.setAttribute(this.ariaSelectionType, 'true');
|
786
|
+
}
|
787
|
+
for (const checkedItem of this.querySelectorAll(`[${this.ariaSelectionType}]`)) {
|
788
|
+
if (checkedItem !== itemContent) {
|
789
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_removeSelectedItem).call(this, checkedItem);
|
790
|
+
checkedItem.setAttribute(this.ariaSelectionType, 'false');
|
791
|
+
}
|
792
|
+
}
|
793
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setDynamicLabel).call(this);
|
794
|
+
}
|
795
|
+
else {
|
796
|
+
// multi-select mode allows unchecking a checked item
|
797
|
+
itemContent?.setAttribute(this.ariaSelectionType, `${checked}`);
|
798
|
+
if (checked) {
|
799
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_addSelectedItem).call(this, item);
|
800
|
+
}
|
801
|
+
else {
|
802
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_removeSelectedItem).call(this, item);
|
803
|
+
}
|
804
|
+
}
|
805
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
806
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateTabIndices).call(this);
|
807
|
+
this.dispatchEvent(new CustomEvent('itemActivated', {
|
808
|
+
bubbles: true,
|
809
|
+
detail: { item, checked },
|
810
|
+
}));
|
811
|
+
};
|
812
|
+
_SelectPanelElement_setDynamicLabel = function _SelectPanelElement_setDynamicLabel() {
|
813
|
+
if (!this.dynamicLabel)
|
814
|
+
return;
|
815
|
+
const invokerLabel = this.invokerLabel;
|
816
|
+
if (!invokerLabel)
|
817
|
+
return;
|
818
|
+
__classPrivateFieldSet(this, _SelectPanelElement_originalLabel, __classPrivateFieldGet(this, _SelectPanelElement_originalLabel, "f") || (invokerLabel.textContent || ''), "f");
|
819
|
+
const itemLabel = this.querySelector(`[${this.ariaSelectionType}=true] .ActionListItem-label`)?.textContent || __classPrivateFieldGet(this, _SelectPanelElement_originalLabel, "f");
|
820
|
+
if (itemLabel) {
|
821
|
+
const prefixSpan = document.createElement('span');
|
822
|
+
prefixSpan.classList.add('color-fg-muted');
|
823
|
+
const contentSpan = document.createElement('span');
|
824
|
+
prefixSpan.textContent = `${this.dynamicLabelPrefix} `;
|
825
|
+
contentSpan.textContent = itemLabel;
|
826
|
+
invokerLabel.replaceChildren(prefixSpan, contentSpan);
|
827
|
+
if (this.dynamicAriaLabelPrefix) {
|
828
|
+
this.invokerElement?.setAttribute('aria-label', `${this.dynamicAriaLabelPrefix} ${itemLabel.trim()}`);
|
829
|
+
}
|
830
|
+
}
|
831
|
+
else {
|
832
|
+
invokerLabel.textContent = __classPrivateFieldGet(this, _SelectPanelElement_originalLabel, "f");
|
833
|
+
}
|
834
|
+
};
|
835
|
+
_SelectPanelElement_updateInput = function _SelectPanelElement_updateInput() {
|
836
|
+
if (this.selectVariant === 'single') {
|
837
|
+
const input = this.querySelector(`[data-list-inputs=true] input`);
|
838
|
+
if (!input)
|
839
|
+
return;
|
840
|
+
const selectedItem = this.selectedItems[0];
|
841
|
+
if (selectedItem) {
|
842
|
+
input.value = (selectedItem.value || selectedItem.label || '').trim();
|
843
|
+
if (selectedItem.inputName)
|
844
|
+
input.name = selectedItem.inputName;
|
845
|
+
input.removeAttribute('disabled');
|
846
|
+
}
|
847
|
+
else {
|
848
|
+
input.setAttribute('disabled', 'disabled');
|
849
|
+
}
|
850
|
+
}
|
851
|
+
else if (this.selectVariant !== 'none') {
|
852
|
+
// multiple select variant
|
853
|
+
const inputList = this.querySelector('[data-list-inputs=true]');
|
854
|
+
if (!inputList)
|
855
|
+
return;
|
856
|
+
const inputs = inputList.querySelectorAll('input');
|
857
|
+
if (inputs.length > 0) {
|
858
|
+
__classPrivateFieldSet(this, _SelectPanelElement_inputName, __classPrivateFieldGet(this, _SelectPanelElement_inputName, "f") || inputs[0].name, "f");
|
859
|
+
}
|
860
|
+
for (const selectedItem of this.selectedItems) {
|
861
|
+
const newInput = document.createElement('input');
|
862
|
+
newInput.setAttribute('data-list-input', 'true');
|
863
|
+
newInput.type = 'hidden';
|
864
|
+
newInput.autocomplete = 'off';
|
865
|
+
newInput.name = selectedItem.inputName || __classPrivateFieldGet(this, _SelectPanelElement_inputName, "f");
|
866
|
+
newInput.value = (selectedItem.value || selectedItem.label || '').trim();
|
867
|
+
inputList.append(newInput);
|
868
|
+
}
|
869
|
+
for (const input of inputs) {
|
870
|
+
input.remove();
|
871
|
+
}
|
872
|
+
}
|
873
|
+
};
|
874
|
+
_SelectPanelElement_firstItem_get = function _SelectPanelElement_firstItem_get() {
|
875
|
+
return (this.querySelector(visibleMenuItemSelectors)?.parentElement || null);
|
876
|
+
};
|
877
|
+
_SelectPanelElement_hideItem = function _SelectPanelElement_hideItem(item) {
|
878
|
+
if (item) {
|
879
|
+
item.setAttribute('hidden', 'hidden');
|
880
|
+
}
|
881
|
+
};
|
882
|
+
_SelectPanelElement_showItem = function _SelectPanelElement_showItem(item) {
|
883
|
+
if (item) {
|
884
|
+
item.removeAttribute('hidden');
|
885
|
+
}
|
886
|
+
};
|
887
|
+
_SelectPanelElement_getItemContent = function _SelectPanelElement_getItemContent(item) {
|
888
|
+
return item.querySelector('.ActionListContent');
|
889
|
+
};
|
890
|
+
__decorate([
|
891
|
+
target
|
892
|
+
], SelectPanelElement.prototype, "includeFragment", void 0);
|
893
|
+
__decorate([
|
894
|
+
target
|
895
|
+
], SelectPanelElement.prototype, "dialog", void 0);
|
896
|
+
__decorate([
|
897
|
+
target
|
898
|
+
], SelectPanelElement.prototype, "filterInputTextField", void 0);
|
899
|
+
__decorate([
|
900
|
+
target
|
901
|
+
], SelectPanelElement.prototype, "remoteInput", void 0);
|
902
|
+
__decorate([
|
903
|
+
target
|
904
|
+
], SelectPanelElement.prototype, "list", void 0);
|
905
|
+
__decorate([
|
906
|
+
target
|
907
|
+
], SelectPanelElement.prototype, "ariaLiveContainer", void 0);
|
908
|
+
__decorate([
|
909
|
+
target
|
910
|
+
], SelectPanelElement.prototype, "noResults", void 0);
|
911
|
+
__decorate([
|
912
|
+
target
|
913
|
+
], SelectPanelElement.prototype, "fragmentErrorElement", void 0);
|
914
|
+
__decorate([
|
915
|
+
target
|
916
|
+
], SelectPanelElement.prototype, "bannerErrorElement", void 0);
|
917
|
+
__decorate([
|
918
|
+
target
|
919
|
+
], SelectPanelElement.prototype, "bodySpinner", void 0);
|
920
|
+
SelectPanelElement = __decorate([
|
921
|
+
controller
|
922
|
+
], SelectPanelElement);
|
923
|
+
export { SelectPanelElement };
|
924
|
+
if (!window.customElements.get('select-panel')) {
|
925
|
+
window.SelectPanelElement = SelectPanelElement;
|
926
|
+
window.customElements.define('select-panel', SelectPanelElement);
|
927
|
+
}
|