@primer/view-components 0.27.1-rc.54e32349 → 0.28.0-rc.22557eac
Sign up to get free protection for your applications and to get access to all the features.
- package/app/assets/javascripts/app/components/primer/alpha/action_menu/action_menu_element.d.ts +0 -9
- package/app/assets/javascripts/app/components/primer/alpha/select_panel_element.d.ts +64 -0
- package/app/assets/javascripts/app/components/primer/aria_live.d.ts +8 -0
- package/app/assets/javascripts/app/components/primer/primer.d.ts +4 -0
- package/app/assets/javascripts/app/components/primer/shared_events.d.ts +9 -0
- package/app/assets/javascripts/primer_view_components.js +1 -1
- package/app/assets/javascripts/primer_view_components.js.map +1 -1
- package/app/components/primer/alpha/action_menu/action_menu_element.d.ts +0 -9
- package/app/components/primer/alpha/select_panel_element.d.ts +64 -0
- package/app/components/primer/alpha/select_panel_element.js +922 -0
- package/app/components/primer/aria_live.d.ts +8 -0
- package/app/components/primer/aria_live.js +38 -0
- package/app/components/primer/primer.d.ts +4 -0
- package/app/components/primer/primer.js +4 -0
- package/app/components/primer/shared_events.d.ts +9 -0
- package/app/components/primer/shared_events.js +1 -0
- package/package.json +2 -1
- package/static/arguments.json +118 -0
- package/static/audited_at.json +1 -0
- package/static/constants.json +16 -0
- package/static/info_arch.json +897 -116
- package/static/previews.json +294 -0
- package/static/statuses.json +1 -0
@@ -0,0 +1,922 @@
|
|
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
|
+
}
|
188
|
+
}
|
189
|
+
}), "f");
|
190
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => Boolean(this.dialog), () => {
|
191
|
+
if (this.getAttribute('data-open-on-load') === 'true') {
|
192
|
+
this.show();
|
193
|
+
}
|
194
|
+
__classPrivateFieldGet(this, _SelectPanelElement_dialogIntersectionObserver, "f").observe(this.dialog);
|
195
|
+
this.dialog.addEventListener('close', this, { signal });
|
196
|
+
});
|
197
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL) {
|
198
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_waitForCondition).call(this, () => this.items.length > 0, () => {
|
199
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
200
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
201
|
+
});
|
202
|
+
}
|
203
|
+
}
|
204
|
+
disconnectedCallback() {
|
205
|
+
__classPrivateFieldGet(this, _SelectPanelElement_abortController, "f").abort();
|
206
|
+
}
|
207
|
+
handleEvent(event) {
|
208
|
+
if (event.target === this.filterInputTextField) {
|
209
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleSearchFieldEvent).call(this, event);
|
210
|
+
return;
|
211
|
+
}
|
212
|
+
if (event.target === this.remoteInput) {
|
213
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleRemoteInputEvent).call(this, event);
|
214
|
+
return;
|
215
|
+
}
|
216
|
+
const targetIsInvoker = this.invokerElement?.contains(event.target);
|
217
|
+
const targetIsCloseButton = this.closeButton?.contains(event.target);
|
218
|
+
const eventIsActivation = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_isActivation).call(this, event);
|
219
|
+
if (targetIsInvoker && event.type === 'mousedown') {
|
220
|
+
return;
|
221
|
+
}
|
222
|
+
if (event.type === 'mousedown' && event.target instanceof HTMLInputElement) {
|
223
|
+
return;
|
224
|
+
}
|
225
|
+
// Prevent safari bug that dismisses menu on mousedown instead of allowing
|
226
|
+
// the click event to propagate to the button
|
227
|
+
if (event.type === 'mousedown') {
|
228
|
+
event.preventDefault();
|
229
|
+
return;
|
230
|
+
}
|
231
|
+
if (targetIsInvoker && eventIsActivation) {
|
232
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleInvokerActivated).call(this, event);
|
233
|
+
return;
|
234
|
+
}
|
235
|
+
if (targetIsCloseButton && eventIsActivation) {
|
236
|
+
// hide() will automatically be called by dialog event triggered from `data-close-dialog-id`
|
237
|
+
return;
|
238
|
+
}
|
239
|
+
if (event.target === this.dialog && event.type === 'close') {
|
240
|
+
this.dispatchEvent(new CustomEvent('panelClosed', {
|
241
|
+
detail: { panel: this },
|
242
|
+
bubbles: true,
|
243
|
+
}));
|
244
|
+
return;
|
245
|
+
}
|
246
|
+
const item = event.target.closest(visibleMenuItemSelectors)?.parentElement;
|
247
|
+
const targetIsItem = item !== null && item !== undefined;
|
248
|
+
if (targetIsItem && eventIsActivation) {
|
249
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_potentiallyDisallowActivation).call(this, event))
|
250
|
+
return;
|
251
|
+
const dialogInvoker = item.closest('[data-show-dialog-id]');
|
252
|
+
if (dialogInvoker) {
|
253
|
+
const dialog = this.ownerDocument.getElementById(dialogInvoker.getAttribute('data-show-dialog-id') || '');
|
254
|
+
if (dialog && this.contains(dialogInvoker) && this.contains(dialog)) {
|
255
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleDialogItemActivated).call(this, event, dialog);
|
256
|
+
return;
|
257
|
+
}
|
258
|
+
}
|
259
|
+
// Pressing the space key on a link will cause the page to scroll unless preventDefault() is called.
|
260
|
+
// We then click it manually to navigate.
|
261
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_isAnchorActivationViaSpace).call(this, event)) {
|
262
|
+
event.preventDefault();
|
263
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item)?.click();
|
264
|
+
}
|
265
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleItemActivated).call(this, item);
|
266
|
+
return;
|
267
|
+
}
|
268
|
+
if (event.type === 'click') {
|
269
|
+
const rect = this.dialog.getBoundingClientRect();
|
270
|
+
const clickWasInsideDialog = rect.top <= event.clientY &&
|
271
|
+
event.clientY <= rect.top + rect.height &&
|
272
|
+
rect.left <= event.clientX &&
|
273
|
+
event.clientX <= rect.left + rect.width;
|
274
|
+
if (!clickWasInsideDialog) {
|
275
|
+
this.hide();
|
276
|
+
}
|
277
|
+
}
|
278
|
+
// The include fragment will have been removed from the DOM by the time
|
279
|
+
// the include-fragment-replaced event has been dispatched, so we have to
|
280
|
+
// check for the type of the event target manually, since this.includeFragment
|
281
|
+
// will be null.
|
282
|
+
if (event.target instanceof IncludeFragmentElement) {
|
283
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleIncludeFragmentEvent).call(this, event);
|
284
|
+
}
|
285
|
+
}
|
286
|
+
show() {
|
287
|
+
this.updateAnchorPosition();
|
288
|
+
this.dialog.showModal();
|
289
|
+
const event = new CustomEvent('dialog:open', {
|
290
|
+
detail: { dialog: this.dialog },
|
291
|
+
});
|
292
|
+
this.dispatchEvent(event);
|
293
|
+
}
|
294
|
+
hide() {
|
295
|
+
this.dialog.close();
|
296
|
+
}
|
297
|
+
get visibleItems() {
|
298
|
+
return Array.from(this.querySelectorAll(visibleMenuItemSelectors)).map(element => element.parentElement);
|
299
|
+
}
|
300
|
+
get items() {
|
301
|
+
return Array.from(this.querySelectorAll(menuItemSelectors)).map(element => element.parentElement);
|
302
|
+
}
|
303
|
+
get focusableItem() {
|
304
|
+
for (const item of this.items) {
|
305
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
306
|
+
if (!itemContent)
|
307
|
+
continue;
|
308
|
+
if (itemContent.getAttribute('tabindex') === '0') {
|
309
|
+
return itemContent;
|
310
|
+
}
|
311
|
+
}
|
312
|
+
}
|
313
|
+
getItemById(itemId) {
|
314
|
+
return this.querySelector(`li[data-item-id="${itemId}"`);
|
315
|
+
}
|
316
|
+
isItemDisabled(item) {
|
317
|
+
if (item) {
|
318
|
+
return item.classList.contains('ActionListItem--disabled');
|
319
|
+
}
|
320
|
+
else {
|
321
|
+
return false;
|
322
|
+
}
|
323
|
+
}
|
324
|
+
disableItem(item) {
|
325
|
+
if (item) {
|
326
|
+
item.classList.add('ActionListItem--disabled');
|
327
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item).setAttribute('aria-disabled', 'true');
|
328
|
+
}
|
329
|
+
}
|
330
|
+
enableItem(item) {
|
331
|
+
if (item) {
|
332
|
+
item.classList.remove('ActionListItem--disabled');
|
333
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item).removeAttribute('aria-disabled');
|
334
|
+
}
|
335
|
+
}
|
336
|
+
isItemHidden(item) {
|
337
|
+
if (item) {
|
338
|
+
return item.hasAttribute('hidden');
|
339
|
+
}
|
340
|
+
else {
|
341
|
+
return false;
|
342
|
+
}
|
343
|
+
}
|
344
|
+
isItemChecked(item) {
|
345
|
+
if (item) {
|
346
|
+
return __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item).getAttribute(this.ariaSelectionType) === 'true';
|
347
|
+
}
|
348
|
+
else {
|
349
|
+
return false;
|
350
|
+
}
|
351
|
+
}
|
352
|
+
checkItem(item) {
|
353
|
+
if (item && (this.selectVariant === 'single' || this.selectVariant === 'multiple')) {
|
354
|
+
if (!this.isItemChecked(item)) {
|
355
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleItemActivated).call(this, item);
|
356
|
+
}
|
357
|
+
}
|
358
|
+
}
|
359
|
+
uncheckItem(item) {
|
360
|
+
if (item && (this.selectVariant === 'single' || this.selectVariant === 'multiple')) {
|
361
|
+
if (this.isItemChecked(item)) {
|
362
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_handleItemActivated).call(this, item);
|
363
|
+
}
|
364
|
+
}
|
365
|
+
}
|
366
|
+
};
|
367
|
+
_SelectPanelElement_dialogIntersectionObserver = new WeakMap();
|
368
|
+
_SelectPanelElement_abortController = new WeakMap();
|
369
|
+
_SelectPanelElement_originalLabel = new WeakMap();
|
370
|
+
_SelectPanelElement_inputName = new WeakMap();
|
371
|
+
_SelectPanelElement_selectedItems = new WeakMap();
|
372
|
+
_SelectPanelElement_loadingDelayTimeoutId = new WeakMap();
|
373
|
+
_SelectPanelElement_loadingAnnouncementTimeoutId = new WeakMap();
|
374
|
+
_SelectPanelElement_instances = new WeakSet();
|
375
|
+
_SelectPanelElement_waitForCondition = function _SelectPanelElement_waitForCondition(condition, body) {
|
376
|
+
if (condition()) {
|
377
|
+
body();
|
378
|
+
}
|
379
|
+
else {
|
380
|
+
const mutationObserver = new MutationObserver(() => {
|
381
|
+
body();
|
382
|
+
mutationObserver.disconnect();
|
383
|
+
});
|
384
|
+
mutationObserver.observe(this, { childList: true, subtree: true });
|
385
|
+
}
|
386
|
+
};
|
387
|
+
_SelectPanelElement_softDisableItems = function _SelectPanelElement_softDisableItems() {
|
388
|
+
const { signal } = __classPrivateFieldGet(this, _SelectPanelElement_abortController, "f");
|
389
|
+
for (const item of this.querySelectorAll(validSelectors.join(','))) {
|
390
|
+
item.addEventListener('click', __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_potentiallyDisallowActivation).bind(this), { signal });
|
391
|
+
item.addEventListener('keydown', __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_potentiallyDisallowActivation).bind(this), { signal });
|
392
|
+
}
|
393
|
+
};
|
394
|
+
_SelectPanelElement_updateTabIndices = function _SelectPanelElement_updateTabIndices() {
|
395
|
+
let setZeroTabIndex = false;
|
396
|
+
if (this.selectVariant === 'single') {
|
397
|
+
for (const item of this.items) {
|
398
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
399
|
+
if (!itemContent)
|
400
|
+
continue;
|
401
|
+
if (!this.isItemHidden(item) && this.isItemChecked(item) && !setZeroTabIndex) {
|
402
|
+
itemContent.setAttribute('tabindex', '0');
|
403
|
+
setZeroTabIndex = true;
|
404
|
+
}
|
405
|
+
else {
|
406
|
+
itemContent.setAttribute('tabindex', '-1');
|
407
|
+
}
|
408
|
+
// <li> elements should not themselves be tabbable
|
409
|
+
item.setAttribute('tabindex', '-1');
|
410
|
+
}
|
411
|
+
}
|
412
|
+
else {
|
413
|
+
for (const item of this.items) {
|
414
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
415
|
+
if (!itemContent)
|
416
|
+
continue;
|
417
|
+
if (!this.isItemHidden(item) && !setZeroTabIndex) {
|
418
|
+
setZeroTabIndex = true;
|
419
|
+
}
|
420
|
+
else {
|
421
|
+
itemContent.setAttribute('tabindex', '-1');
|
422
|
+
}
|
423
|
+
// <li> elements should not themselves be tabbable
|
424
|
+
item.setAttribute('tabindex', '-1');
|
425
|
+
}
|
426
|
+
}
|
427
|
+
if (!setZeroTabIndex && __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_firstItem_get)) {
|
428
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_firstItem_get))?.setAttribute('tabindex', '0');
|
429
|
+
}
|
430
|
+
};
|
431
|
+
_SelectPanelElement_potentiallyDisallowActivation = function _SelectPanelElement_potentiallyDisallowActivation(event) {
|
432
|
+
if (!__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_isActivation).call(this, event))
|
433
|
+
return false;
|
434
|
+
const item = event.target.closest(visibleMenuItemSelectors);
|
435
|
+
if (!item)
|
436
|
+
return false;
|
437
|
+
if (item.getAttribute('aria-disabled')) {
|
438
|
+
event.preventDefault();
|
439
|
+
// eslint-disable-next-line no-restricted-syntax
|
440
|
+
event.stopPropagation();
|
441
|
+
// eslint-disable-next-line no-restricted-syntax
|
442
|
+
event.stopImmediatePropagation();
|
443
|
+
return true;
|
444
|
+
}
|
445
|
+
return false;
|
446
|
+
};
|
447
|
+
_SelectPanelElement_isAnchorActivationViaSpace = function _SelectPanelElement_isAnchorActivationViaSpace(event) {
|
448
|
+
return (event.target instanceof HTMLAnchorElement &&
|
449
|
+
event instanceof KeyboardEvent &&
|
450
|
+
event.type === 'keydown' &&
|
451
|
+
!(event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) &&
|
452
|
+
event.key === ' ');
|
453
|
+
};
|
454
|
+
_SelectPanelElement_isActivation = function _SelectPanelElement_isActivation(event) {
|
455
|
+
// Some browsers fire MouseEvents (Firefox) and others fire PointerEvents (Chrome). Activating an item via
|
456
|
+
// enter or space counterintuitively fires one of these rather than a KeyboardEvent. Since PointerEvent
|
457
|
+
// inherits from MouseEvent, it is enough to check for MouseEvent here.
|
458
|
+
return (event instanceof MouseEvent && event.type === 'click') || __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_isAnchorActivationViaSpace).call(this, event);
|
459
|
+
};
|
460
|
+
_SelectPanelElement_checkSelectedItems = function _SelectPanelElement_checkSelectedItems() {
|
461
|
+
for (const item of this.items) {
|
462
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
463
|
+
if (!itemContent)
|
464
|
+
continue;
|
465
|
+
const value = itemContent.getAttribute('data-value');
|
466
|
+
if (value) {
|
467
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").has(value)) {
|
468
|
+
itemContent.setAttribute(this.ariaSelectionType, 'true');
|
469
|
+
}
|
470
|
+
}
|
471
|
+
}
|
472
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
473
|
+
};
|
474
|
+
_SelectPanelElement_addSelectedItem = function _SelectPanelElement_addSelectedItem(item) {
|
475
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
476
|
+
if (!itemContent)
|
477
|
+
return;
|
478
|
+
const value = itemContent.getAttribute('data-value');
|
479
|
+
if (value) {
|
480
|
+
__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").set(value, {
|
481
|
+
value,
|
482
|
+
label: itemContent.querySelector('.ActionListItem-label')?.textContent?.trim(),
|
483
|
+
inputName: itemContent.getAttribute('data-input-name'),
|
484
|
+
element: item,
|
485
|
+
});
|
486
|
+
}
|
487
|
+
};
|
488
|
+
_SelectPanelElement_removeSelectedItem = function _SelectPanelElement_removeSelectedItem(item) {
|
489
|
+
const value = item.getAttribute('data-value');
|
490
|
+
if (value) {
|
491
|
+
__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").delete(value);
|
492
|
+
}
|
493
|
+
};
|
494
|
+
_SelectPanelElement_setTextFieldLoadingSpinnerTimer = function _SelectPanelElement_setTextFieldLoadingSpinnerTimer() {
|
495
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_loadingDelayTimeoutId, "f"))
|
496
|
+
clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingDelayTimeoutId, "f"));
|
497
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"))
|
498
|
+
clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"));
|
499
|
+
__classPrivateFieldSet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, setTimeout(() => {
|
500
|
+
announce('Loading', { element: this.ariaLiveContainer });
|
501
|
+
}, 2000), "f");
|
502
|
+
__classPrivateFieldSet(this, _SelectPanelElement_loadingDelayTimeoutId, setTimeout(() => {
|
503
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_filterInputTextFieldElement_get).showLeadingSpinner();
|
504
|
+
}, 1000), "f");
|
505
|
+
};
|
506
|
+
_SelectPanelElement_handleIncludeFragmentEvent = function _SelectPanelElement_handleIncludeFragmentEvent(event) {
|
507
|
+
switch (event.type) {
|
508
|
+
case 'include-fragment-replaced': {
|
509
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
510
|
+
break;
|
511
|
+
}
|
512
|
+
case 'loadstart': {
|
513
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_toggleIncludeFragmentElements).call(this, false);
|
514
|
+
break;
|
515
|
+
}
|
516
|
+
case 'loadend': {
|
517
|
+
this.dispatchEvent(new CustomEvent('loadend'));
|
518
|
+
break;
|
519
|
+
}
|
520
|
+
case 'error': {
|
521
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_toggleIncludeFragmentElements).call(this, true);
|
522
|
+
const errorElement = this.fragmentErrorElement;
|
523
|
+
// check if the errorElement is visible in the dom
|
524
|
+
if (errorElement && !errorElement.hasAttribute('hidden')) {
|
525
|
+
announceFromElement(errorElement, { element: this.ariaLiveContainer, assertive: true });
|
526
|
+
return;
|
527
|
+
}
|
528
|
+
break;
|
529
|
+
}
|
530
|
+
}
|
531
|
+
};
|
532
|
+
_SelectPanelElement_toggleIncludeFragmentElements = function _SelectPanelElement_toggleIncludeFragmentElements(showError) {
|
533
|
+
for (const el of this.includeFragment.querySelectorAll('[data-show-on-error]')) {
|
534
|
+
if (el instanceof HTMLElement)
|
535
|
+
el.hidden = !showError;
|
536
|
+
}
|
537
|
+
for (const el of this.includeFragment.querySelectorAll('[data-hide-on-error]')) {
|
538
|
+
if (el instanceof HTMLElement)
|
539
|
+
el.hidden = showError;
|
540
|
+
}
|
541
|
+
};
|
542
|
+
_SelectPanelElement_handleRemoteInputEvent = function _SelectPanelElement_handleRemoteInputEvent(event) {
|
543
|
+
switch (event.type) {
|
544
|
+
case 'remote-input-success': {
|
545
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_clearErrorState).call(this);
|
546
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
547
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_checkSelectedItems).call(this);
|
548
|
+
break;
|
549
|
+
}
|
550
|
+
case 'remote-input-error': {
|
551
|
+
this.bodySpinner?.setAttribute('hidden', '');
|
552
|
+
if (this.includeFragment || this.visibleItems.length === 0) {
|
553
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setErrorState).call(this, ErrorStateType.BODY);
|
554
|
+
}
|
555
|
+
else {
|
556
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setErrorState).call(this, ErrorStateType.BANNER);
|
557
|
+
}
|
558
|
+
break;
|
559
|
+
}
|
560
|
+
case 'loadstart': {
|
561
|
+
if (!__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_performFilteringLocally).call(this)) {
|
562
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_clearErrorState).call(this);
|
563
|
+
this.bodySpinner?.removeAttribute('hidden');
|
564
|
+
if (this.bodySpinner)
|
565
|
+
break;
|
566
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setTextFieldLoadingSpinnerTimer).call(this);
|
567
|
+
}
|
568
|
+
break;
|
569
|
+
}
|
570
|
+
case 'loadend': {
|
571
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_filterInputTextFieldElement_get).hideLeadingSpinner();
|
572
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"))
|
573
|
+
clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingAnnouncementTimeoutId, "f"));
|
574
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_loadingDelayTimeoutId, "f"))
|
575
|
+
clearTimeout(__classPrivateFieldGet(this, _SelectPanelElement_loadingDelayTimeoutId, "f"));
|
576
|
+
this.dispatchEvent(new CustomEvent('loadend'));
|
577
|
+
break;
|
578
|
+
}
|
579
|
+
}
|
580
|
+
};
|
581
|
+
_SelectPanelElement_defaultFilterFn = function _SelectPanelElement_defaultFilterFn(item, query) {
|
582
|
+
const text = (item.getAttribute('data-filter-string') || item.textContent || '').toLowerCase();
|
583
|
+
return text.indexOf(query.toLowerCase()) > -1;
|
584
|
+
};
|
585
|
+
_SelectPanelElement_handleSearchFieldEvent = function _SelectPanelElement_handleSearchFieldEvent(event) {
|
586
|
+
if (event.type === 'keydown' && event.key === 'ArrowDown') {
|
587
|
+
if (this.focusableItem) {
|
588
|
+
this.focusableItem.focus();
|
589
|
+
event.preventDefault();
|
590
|
+
}
|
591
|
+
}
|
592
|
+
if (event.type !== 'input')
|
593
|
+
return;
|
594
|
+
// remote-input-element does not trigger another loadstart event if a request is
|
595
|
+
// already in-flight, so we use the input event on the text field to reset the
|
596
|
+
// loading spinner timer instead
|
597
|
+
if (!this.bodySpinner && !__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_performFilteringLocally).call(this)) {
|
598
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setTextFieldLoadingSpinnerTimer).call(this);
|
599
|
+
}
|
600
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL || __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.EVENTUALLY_LOCAL) {
|
601
|
+
if (this.includeFragment) {
|
602
|
+
this.includeFragment.refetch();
|
603
|
+
return;
|
604
|
+
}
|
605
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateItemVisibility).call(this);
|
606
|
+
}
|
607
|
+
};
|
608
|
+
_SelectPanelElement_updateItemVisibility = function _SelectPanelElement_updateItemVisibility() {
|
609
|
+
if (!this.list)
|
610
|
+
return;
|
611
|
+
let atLeastOneResult = false;
|
612
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_performFilteringLocally).call(this)) {
|
613
|
+
const query = this.filterInputTextField?.value ?? '';
|
614
|
+
const filter = this.filterFn || __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_defaultFilterFn);
|
615
|
+
for (const item of this.items) {
|
616
|
+
if (filter(item, query)) {
|
617
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_showItem).call(this, item);
|
618
|
+
atLeastOneResult = true;
|
619
|
+
}
|
620
|
+
else {
|
621
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_hideItem).call(this, item);
|
622
|
+
}
|
623
|
+
}
|
624
|
+
}
|
625
|
+
else {
|
626
|
+
atLeastOneResult = this.items.length > 0;
|
627
|
+
}
|
628
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateTabIndices).call(this);
|
629
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_maybeAnnounce).call(this);
|
630
|
+
for (const item of this.items) {
|
631
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
632
|
+
if (!itemContent)
|
633
|
+
continue;
|
634
|
+
const value = itemContent.getAttribute('data-value');
|
635
|
+
if (value && !__classPrivateFieldGet(this, _SelectPanelElement_selectedItems, "f").has(value) && this.isItemChecked(item)) {
|
636
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_addSelectedItem).call(this, item);
|
637
|
+
}
|
638
|
+
}
|
639
|
+
if (!this.noResults)
|
640
|
+
return;
|
641
|
+
if (__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_inErrorState).call(this)) {
|
642
|
+
this.noResults.setAttribute('hidden', '');
|
643
|
+
return;
|
644
|
+
}
|
645
|
+
if (atLeastOneResult) {
|
646
|
+
this.noResults.setAttribute('hidden', '');
|
647
|
+
// TODO can we change this to search for `@panelId-list`
|
648
|
+
this.list?.querySelector('.ActionListWrap')?.removeAttribute('hidden');
|
649
|
+
}
|
650
|
+
else {
|
651
|
+
this.list?.querySelector('.ActionListWrap')?.setAttribute('hidden', '');
|
652
|
+
this.noResults.removeAttribute('hidden');
|
653
|
+
}
|
654
|
+
};
|
655
|
+
_SelectPanelElement_inErrorState = function _SelectPanelElement_inErrorState() {
|
656
|
+
if (this.fragmentErrorElement && !this.fragmentErrorElement.hasAttribute('hidden')) {
|
657
|
+
return true;
|
658
|
+
}
|
659
|
+
return !this.bannerErrorElement.hasAttribute('hidden');
|
660
|
+
};
|
661
|
+
_SelectPanelElement_setErrorState = function _SelectPanelElement_setErrorState(type) {
|
662
|
+
let errorElement = this.fragmentErrorElement;
|
663
|
+
if (type === ErrorStateType.BODY) {
|
664
|
+
this.fragmentErrorElement?.removeAttribute('hidden');
|
665
|
+
this.bannerErrorElement.setAttribute('hidden', '');
|
666
|
+
}
|
667
|
+
else {
|
668
|
+
errorElement = this.bannerErrorElement;
|
669
|
+
this.bannerErrorElement?.removeAttribute('hidden');
|
670
|
+
this.fragmentErrorElement?.setAttribute('hidden', '');
|
671
|
+
}
|
672
|
+
// check if the errorElement is visible in the dom
|
673
|
+
if (errorElement && !errorElement.hasAttribute('hidden')) {
|
674
|
+
announceFromElement(errorElement, { element: this.ariaLiveContainer, assertive: true });
|
675
|
+
return;
|
676
|
+
}
|
677
|
+
};
|
678
|
+
_SelectPanelElement_clearErrorState = function _SelectPanelElement_clearErrorState() {
|
679
|
+
this.fragmentErrorElement?.setAttribute('hidden', '');
|
680
|
+
this.bannerErrorElement.setAttribute('hidden', '');
|
681
|
+
};
|
682
|
+
_SelectPanelElement_maybeAnnounce = function _SelectPanelElement_maybeAnnounce() {
|
683
|
+
if (this.open && this.list) {
|
684
|
+
const items = this.items;
|
685
|
+
if (items.length > 0) {
|
686
|
+
const instructions = 'tab for results';
|
687
|
+
announce(`${items.length} result${items.length === 1 ? '' : 's'} ${instructions}`, {
|
688
|
+
element: this.ariaLiveContainer,
|
689
|
+
});
|
690
|
+
}
|
691
|
+
else {
|
692
|
+
const noResultsEl = this.noResults;
|
693
|
+
if (noResultsEl) {
|
694
|
+
announceFromElement(noResultsEl, { element: this.ariaLiveContainer });
|
695
|
+
}
|
696
|
+
}
|
697
|
+
}
|
698
|
+
};
|
699
|
+
_SelectPanelElement_fetchStrategy_get = function _SelectPanelElement_fetchStrategy_get() {
|
700
|
+
if (!this.list)
|
701
|
+
return FetchStrategy.REMOTE;
|
702
|
+
switch (this.list.getAttribute('data-fetch-strategy')) {
|
703
|
+
case 'local':
|
704
|
+
return FetchStrategy.LOCAL;
|
705
|
+
case 'eventually_local':
|
706
|
+
return FetchStrategy.EVENTUALLY_LOCAL;
|
707
|
+
default:
|
708
|
+
return FetchStrategy.REMOTE;
|
709
|
+
}
|
710
|
+
};
|
711
|
+
_SelectPanelElement_filterInputTextFieldElement_get = function _SelectPanelElement_filterInputTextFieldElement_get() {
|
712
|
+
return this.filterInputTextField.closest('primer-text-field');
|
713
|
+
};
|
714
|
+
_SelectPanelElement_performFilteringLocally = function _SelectPanelElement_performFilteringLocally() {
|
715
|
+
return __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.LOCAL || __classPrivateFieldGet(this, _SelectPanelElement_instances, "a", _SelectPanelElement_fetchStrategy_get) === FetchStrategy.EVENTUALLY_LOCAL;
|
716
|
+
};
|
717
|
+
_SelectPanelElement_handleInvokerActivated = function _SelectPanelElement_handleInvokerActivated(event) {
|
718
|
+
event.preventDefault();
|
719
|
+
// eslint-disable-next-line no-restricted-syntax
|
720
|
+
event.stopPropagation();
|
721
|
+
if (this.open) {
|
722
|
+
this.hide();
|
723
|
+
}
|
724
|
+
else {
|
725
|
+
this.show();
|
726
|
+
}
|
727
|
+
};
|
728
|
+
_SelectPanelElement_handleDialogItemActivated = function _SelectPanelElement_handleDialogItemActivated(event, dialog) {
|
729
|
+
this.querySelector('.ActionListWrap').style.display = 'none';
|
730
|
+
const dialog_controller = new AbortController();
|
731
|
+
const { signal } = dialog_controller;
|
732
|
+
const handleDialogClose = () => {
|
733
|
+
dialog_controller.abort();
|
734
|
+
this.querySelector('.ActionListWrap').style.display = '';
|
735
|
+
if (this.open) {
|
736
|
+
this.hide();
|
737
|
+
}
|
738
|
+
const activeElement = this.ownerDocument.activeElement;
|
739
|
+
const lostFocus = this.ownerDocument.activeElement === this.ownerDocument.body;
|
740
|
+
const focusInClosedMenu = this.contains(activeElement);
|
741
|
+
if (lostFocus || focusInClosedMenu) {
|
742
|
+
setTimeout(() => this.invokerElement?.focus(), 0);
|
743
|
+
}
|
744
|
+
};
|
745
|
+
// a modal <dialog> element will close all popovers
|
746
|
+
dialog.addEventListener('close', handleDialogClose, { signal });
|
747
|
+
dialog.addEventListener('cancel', handleDialogClose, { signal });
|
748
|
+
};
|
749
|
+
_SelectPanelElement_handleItemActivated = function _SelectPanelElement_handleItemActivated(item) {
|
750
|
+
// Hide popover after current event loop to prevent changes in focus from
|
751
|
+
// altering the target of the event. Not doing this specifically affects
|
752
|
+
// <a> tags. It causes the event to be sent to the currently focused element
|
753
|
+
// instead of the anchor, which effectively prevents navigation, i.e. it
|
754
|
+
// appears as if hitting enter does nothing. Curiously, clicking instead
|
755
|
+
// works fine.
|
756
|
+
if (this.selectVariant !== 'multiple') {
|
757
|
+
setTimeout(() => {
|
758
|
+
if (this.open) {
|
759
|
+
this.hide();
|
760
|
+
}
|
761
|
+
});
|
762
|
+
}
|
763
|
+
// The rest of the code below deals with single/multiple selection behavior, and should not
|
764
|
+
// interfere with events fired by menu items whose behavior is specified outside the library.
|
765
|
+
if (this.selectVariant !== 'multiple' && this.selectVariant !== 'single')
|
766
|
+
return;
|
767
|
+
const checked = !this.isItemChecked(item);
|
768
|
+
const activationSuccess = this.dispatchEvent(new CustomEvent('beforeItemActivated', {
|
769
|
+
bubbles: true,
|
770
|
+
detail: { item, checked },
|
771
|
+
cancelable: true,
|
772
|
+
}));
|
773
|
+
if (!activationSuccess)
|
774
|
+
return;
|
775
|
+
const itemContent = __classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_getItemContent).call(this, item);
|
776
|
+
if (this.selectVariant === 'single') {
|
777
|
+
// Only check, never uncheck here. Single-select mode does not allow unchecking a checked item.
|
778
|
+
if (checked) {
|
779
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_addSelectedItem).call(this, item);
|
780
|
+
itemContent?.setAttribute(this.ariaSelectionType, 'true');
|
781
|
+
}
|
782
|
+
for (const checkedItem of this.querySelectorAll(`[${this.ariaSelectionType}]`)) {
|
783
|
+
if (checkedItem !== itemContent) {
|
784
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_removeSelectedItem).call(this, checkedItem);
|
785
|
+
checkedItem.setAttribute(this.ariaSelectionType, 'false');
|
786
|
+
}
|
787
|
+
}
|
788
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_setDynamicLabel).call(this);
|
789
|
+
}
|
790
|
+
else {
|
791
|
+
// multi-select mode allows unchecking a checked item
|
792
|
+
itemContent?.setAttribute(this.ariaSelectionType, `${checked}`);
|
793
|
+
if (checked) {
|
794
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_addSelectedItem).call(this, item);
|
795
|
+
}
|
796
|
+
else {
|
797
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_removeSelectedItem).call(this, item);
|
798
|
+
}
|
799
|
+
}
|
800
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateInput).call(this);
|
801
|
+
__classPrivateFieldGet(this, _SelectPanelElement_instances, "m", _SelectPanelElement_updateTabIndices).call(this);
|
802
|
+
this.dispatchEvent(new CustomEvent('itemActivated', {
|
803
|
+
bubbles: true,
|
804
|
+
detail: { item, checked },
|
805
|
+
}));
|
806
|
+
};
|
807
|
+
_SelectPanelElement_setDynamicLabel = function _SelectPanelElement_setDynamicLabel() {
|
808
|
+
if (!this.dynamicLabel)
|
809
|
+
return;
|
810
|
+
const invokerLabel = this.invokerLabel;
|
811
|
+
if (!invokerLabel)
|
812
|
+
return;
|
813
|
+
__classPrivateFieldSet(this, _SelectPanelElement_originalLabel, __classPrivateFieldGet(this, _SelectPanelElement_originalLabel, "f") || (invokerLabel.textContent || ''), "f");
|
814
|
+
const itemLabel = this.querySelector(`[${this.ariaSelectionType}=true] .ActionListItem-label`)?.textContent || __classPrivateFieldGet(this, _SelectPanelElement_originalLabel, "f");
|
815
|
+
if (itemLabel) {
|
816
|
+
const prefixSpan = document.createElement('span');
|
817
|
+
prefixSpan.classList.add('color-fg-muted');
|
818
|
+
const contentSpan = document.createElement('span');
|
819
|
+
prefixSpan.textContent = `${this.dynamicLabelPrefix} `;
|
820
|
+
contentSpan.textContent = itemLabel;
|
821
|
+
invokerLabel.replaceChildren(prefixSpan, contentSpan);
|
822
|
+
if (this.dynamicAriaLabelPrefix) {
|
823
|
+
this.invokerElement?.setAttribute('aria-label', `${this.dynamicAriaLabelPrefix} ${itemLabel.trim()}`);
|
824
|
+
}
|
825
|
+
}
|
826
|
+
else {
|
827
|
+
invokerLabel.textContent = __classPrivateFieldGet(this, _SelectPanelElement_originalLabel, "f");
|
828
|
+
}
|
829
|
+
};
|
830
|
+
_SelectPanelElement_updateInput = function _SelectPanelElement_updateInput() {
|
831
|
+
if (this.selectVariant === 'single') {
|
832
|
+
const input = this.querySelector(`[data-list-inputs=true] input`);
|
833
|
+
if (!input)
|
834
|
+
return;
|
835
|
+
const selectedItem = this.selectedItems[0];
|
836
|
+
if (selectedItem) {
|
837
|
+
input.value = (selectedItem.value || selectedItem.label || '').trim();
|
838
|
+
if (selectedItem.inputName)
|
839
|
+
input.name = selectedItem.inputName;
|
840
|
+
input.removeAttribute('disabled');
|
841
|
+
}
|
842
|
+
else {
|
843
|
+
input.setAttribute('disabled', 'disabled');
|
844
|
+
}
|
845
|
+
}
|
846
|
+
else if (this.selectVariant !== 'none') {
|
847
|
+
// multiple select variant
|
848
|
+
const inputList = this.querySelector('[data-list-inputs=true]');
|
849
|
+
if (!inputList)
|
850
|
+
return;
|
851
|
+
const inputs = inputList.querySelectorAll('input');
|
852
|
+
if (inputs.length > 0) {
|
853
|
+
__classPrivateFieldSet(this, _SelectPanelElement_inputName, __classPrivateFieldGet(this, _SelectPanelElement_inputName, "f") || inputs[0].name, "f");
|
854
|
+
}
|
855
|
+
for (const selectedItem of this.selectedItems) {
|
856
|
+
const newInput = document.createElement('input');
|
857
|
+
newInput.setAttribute('data-list-input', 'true');
|
858
|
+
newInput.type = 'hidden';
|
859
|
+
newInput.autocomplete = 'off';
|
860
|
+
newInput.name = selectedItem.inputName || __classPrivateFieldGet(this, _SelectPanelElement_inputName, "f");
|
861
|
+
newInput.value = (selectedItem.value || selectedItem.label || '').trim();
|
862
|
+
inputList.append(newInput);
|
863
|
+
}
|
864
|
+
for (const input of inputs) {
|
865
|
+
input.remove();
|
866
|
+
}
|
867
|
+
}
|
868
|
+
};
|
869
|
+
_SelectPanelElement_firstItem_get = function _SelectPanelElement_firstItem_get() {
|
870
|
+
return (this.querySelector(visibleMenuItemSelectors)?.parentElement || null);
|
871
|
+
};
|
872
|
+
_SelectPanelElement_hideItem = function _SelectPanelElement_hideItem(item) {
|
873
|
+
if (item) {
|
874
|
+
item.setAttribute('hidden', 'hidden');
|
875
|
+
}
|
876
|
+
};
|
877
|
+
_SelectPanelElement_showItem = function _SelectPanelElement_showItem(item) {
|
878
|
+
if (item) {
|
879
|
+
item.removeAttribute('hidden');
|
880
|
+
}
|
881
|
+
};
|
882
|
+
_SelectPanelElement_getItemContent = function _SelectPanelElement_getItemContent(item) {
|
883
|
+
return item.querySelector('.ActionListContent');
|
884
|
+
};
|
885
|
+
__decorate([
|
886
|
+
target
|
887
|
+
], SelectPanelElement.prototype, "includeFragment", void 0);
|
888
|
+
__decorate([
|
889
|
+
target
|
890
|
+
], SelectPanelElement.prototype, "dialog", void 0);
|
891
|
+
__decorate([
|
892
|
+
target
|
893
|
+
], SelectPanelElement.prototype, "filterInputTextField", void 0);
|
894
|
+
__decorate([
|
895
|
+
target
|
896
|
+
], SelectPanelElement.prototype, "remoteInput", void 0);
|
897
|
+
__decorate([
|
898
|
+
target
|
899
|
+
], SelectPanelElement.prototype, "list", void 0);
|
900
|
+
__decorate([
|
901
|
+
target
|
902
|
+
], SelectPanelElement.prototype, "ariaLiveContainer", void 0);
|
903
|
+
__decorate([
|
904
|
+
target
|
905
|
+
], SelectPanelElement.prototype, "noResults", void 0);
|
906
|
+
__decorate([
|
907
|
+
target
|
908
|
+
], SelectPanelElement.prototype, "fragmentErrorElement", void 0);
|
909
|
+
__decorate([
|
910
|
+
target
|
911
|
+
], SelectPanelElement.prototype, "bannerErrorElement", void 0);
|
912
|
+
__decorate([
|
913
|
+
target
|
914
|
+
], SelectPanelElement.prototype, "bodySpinner", void 0);
|
915
|
+
SelectPanelElement = __decorate([
|
916
|
+
controller
|
917
|
+
], SelectPanelElement);
|
918
|
+
export { SelectPanelElement };
|
919
|
+
if (!window.customElements.get('select-panel')) {
|
920
|
+
window.SelectPanelElement = SelectPanelElement;
|
921
|
+
window.customElements.define('select-panel', SelectPanelElement);
|
922
|
+
}
|