@vonage/vivid 3.48.0 → 3.49.0-preview.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/accordion/index.cjs +21 -0
  2. package/accordion-item/index.cjs +18 -0
  3. package/action-group/index.cjs +7 -0
  4. package/alert/index.cjs +30 -0
  5. package/appearance-ui/index.cjs +96 -0
  6. package/audio-player/index.cjs +34 -0
  7. package/avatar/index.cjs +11 -0
  8. package/badge/index.cjs +14 -0
  9. package/banner/index.cjs +29 -0
  10. package/breadcrumb/index.cjs +13 -0
  11. package/breadcrumb-item/index.cjs +22 -0
  12. package/button/index.cjs +25 -0
  13. package/calendar/index.cjs +9 -0
  14. package/calendar-event/index.cjs +9 -0
  15. package/card/index.cjs +14 -0
  16. package/checkbox/index.cjs +21 -0
  17. package/combobox/index.cjs +39 -0
  18. package/data-grid/index.cjs +18 -0
  19. package/date-picker/index.cjs +40 -0
  20. package/date-range-picker/index.cjs +40 -0
  21. package/dialog/index.cjs +31 -0
  22. package/divider/index.cjs +8 -0
  23. package/elevation/index.cjs +7 -0
  24. package/empty-state/index.cjs +12 -0
  25. package/fab/index.cjs +22 -0
  26. package/file-picker/index.cjs +30 -0
  27. package/focus/index.cjs +7 -0
  28. package/header/index.cjs +8 -0
  29. package/icon/index.cjs +10 -0
  30. package/index.cjs +296 -0
  31. package/layout/index.cjs +7 -0
  32. package/listbox/index.cjs +77 -0
  33. package/locales/en-GB.cjs +106 -0
  34. package/locales/en-US.cjs +106 -0
  35. package/locales/ja-JP.cjs +106 -0
  36. package/locales/zh-CN.cjs +106 -0
  37. package/menu/index.cjs +32 -0
  38. package/menu-item/index.cjs +22 -0
  39. package/nav/index.cjs +6 -0
  40. package/nav-disclosure/index.cjs +17 -0
  41. package/nav-item/index.cjs +22 -0
  42. package/note/index.cjs +16 -0
  43. package/number-field/index.cjs +33 -0
  44. package/option/index.cjs +23 -0
  45. package/package.json +20 -2
  46. package/pagination/index.cjs +28 -0
  47. package/popup/index.cjs +27 -0
  48. package/progress/index.cjs +9 -0
  49. package/progress-ring/index.cjs +9 -0
  50. package/radio/index.cjs +14 -0
  51. package/radio-group/index.cjs +14 -0
  52. package/select/index.cjs +38 -0
  53. package/selectable-box/index.cjs +25 -0
  54. package/shared/Reflector.cjs +67 -0
  55. package/shared/_has.cjs +62 -0
  56. package/shared/affix.cjs +64 -0
  57. package/shared/affix.js +8 -4
  58. package/shared/anchor.cjs +90 -0
  59. package/shared/anchored.cjs +78 -0
  60. package/shared/apply-mixins.cjs +25 -0
  61. package/shared/aria-global.cjs +74 -0
  62. package/shared/aria.cjs +11 -0
  63. package/shared/aria2.cjs +11 -0
  64. package/shared/base-progress.cjs +72 -0
  65. package/shared/breadcrumb-item.cjs +27 -0
  66. package/shared/button.cjs +202 -0
  67. package/shared/calendar-event.cjs +41 -0
  68. package/shared/children.cjs +61 -0
  69. package/shared/class-names.cjs +17 -0
  70. package/shared/definition.cjs +165 -0
  71. package/shared/definition10.cjs +102 -0
  72. package/shared/definition11.cjs +164 -0
  73. package/shared/definition11.js +38 -36
  74. package/shared/definition12.cjs +50 -0
  75. package/shared/definition13.cjs +779 -0
  76. package/shared/definition14.cjs +157 -0
  77. package/shared/definition15.cjs +249 -0
  78. package/shared/definition16.cjs +746 -0
  79. package/shared/definition17.cjs +1372 -0
  80. package/shared/definition18.cjs +175 -0
  81. package/shared/definition19.cjs +416 -0
  82. package/shared/definition2.cjs +232 -0
  83. package/shared/definition20.cjs +278 -0
  84. package/shared/definition21.cjs +83 -0
  85. package/shared/definition22.cjs +74 -0
  86. package/shared/definition23.cjs +106 -0
  87. package/shared/definition24.cjs +2392 -0
  88. package/shared/definition25.cjs +75 -0
  89. package/shared/definition26.cjs +39 -0
  90. package/shared/definition27.cjs +66 -0
  91. package/shared/definition28.cjs +849 -0
  92. package/shared/definition29.cjs +72 -0
  93. package/shared/definition3.cjs +72 -0
  94. package/shared/definition30.cjs +98 -0
  95. package/shared/definition31.cjs +37 -0
  96. package/shared/definition32.cjs +24 -0
  97. package/shared/definition33.cjs +64 -0
  98. package/shared/definition34.cjs +533 -0
  99. package/shared/definition35.cjs +295 -0
  100. package/shared/definition36.cjs +219 -0
  101. package/shared/definition37.cjs +109 -0
  102. package/shared/definition38.cjs +92 -0
  103. package/shared/definition39.cjs +448 -0
  104. package/shared/definition4.cjs +198 -0
  105. package/shared/definition40.cjs +49 -0
  106. package/shared/definition41.cjs +694 -0
  107. package/shared/definition42.cjs +152 -0
  108. package/shared/definition43.cjs +113 -0
  109. package/shared/definition44.cjs +607 -0
  110. package/shared/definition45.cjs +152 -0
  111. package/shared/definition46.cjs +166 -0
  112. package/shared/definition47.cjs +35 -0
  113. package/shared/definition48.cjs +98 -0
  114. package/shared/definition49.cjs +543 -0
  115. package/shared/definition5.cjs +199 -0
  116. package/shared/definition50.cjs +52 -0
  117. package/shared/definition51.cjs +150 -0
  118. package/shared/definition52.cjs +304 -0
  119. package/shared/definition53.cjs +309 -0
  120. package/shared/definition54.cjs +146 -0
  121. package/shared/definition55.cjs +128 -0
  122. package/shared/definition56.cjs +99 -0
  123. package/shared/definition57.cjs +310 -0
  124. package/shared/definition58.cjs +20 -0
  125. package/shared/definition59.cjs +51 -0
  126. package/shared/definition6.cjs +83 -0
  127. package/shared/definition60.cjs +1810 -0
  128. package/shared/definition7.cjs +72 -0
  129. package/shared/definition8.cjs +152 -0
  130. package/shared/definition9.cjs +69 -0
  131. package/shared/dialog-polyfill.esm.cjs +862 -0
  132. package/shared/direction.cjs +22 -0
  133. package/shared/dom.cjs +23 -0
  134. package/shared/enums.cjs +87 -0
  135. package/shared/focus.cjs +8 -0
  136. package/shared/focus2.cjs +11 -0
  137. package/shared/form-associated.cjs +470 -0
  138. package/shared/icon.cjs +237 -0
  139. package/shared/index.cjs +5061 -0
  140. package/shared/index2.cjs +231 -0
  141. package/shared/key-codes.cjs +115 -0
  142. package/shared/key-codes2.cjs +14 -0
  143. package/shared/listbox.cjs +1072 -0
  144. package/shared/localized.cjs +11 -0
  145. package/shared/numbers.cjs +38 -0
  146. package/shared/patterns/affix.d.ts +5 -1
  147. package/shared/presentationDate.cjs +6192 -0
  148. package/shared/radio.cjs +153 -0
  149. package/shared/ref.cjs +43 -0
  150. package/shared/repeat.cjs +767 -0
  151. package/shared/select.options.cjs +12 -0
  152. package/shared/slotted.cjs +123 -0
  153. package/shared/start-end.cjs +52 -0
  154. package/shared/strings.cjs +11 -0
  155. package/shared/text-anchor.cjs +33 -0
  156. package/shared/text-anchor.template.cjs +48 -0
  157. package/shared/text-field.cjs +5 -0
  158. package/shared/text-field2.cjs +228 -0
  159. package/shared/tree-item.cjs +154 -0
  160. package/shared/when.cjs +31 -0
  161. package/side-drawer/index.cjs +8 -0
  162. package/slider/index.cjs +16 -0
  163. package/split-button/index.cjs +20 -0
  164. package/styles/core/all.css +1 -1
  165. package/styles/core/theme.css +1 -1
  166. package/styles/core/typography.css +1 -1
  167. package/styles/tokens/theme-dark.css +4 -4
  168. package/styles/tokens/theme-light.css +4 -4
  169. package/styles/tokens/vivid-2-compat.css +1 -1
  170. package/switch/index.cjs +15 -0
  171. package/tab/index.cjs +17 -0
  172. package/tab-panel/index.cjs +6 -0
  173. package/tabs/index.cjs +24 -0
  174. package/tag/index.cjs +17 -0
  175. package/tag-group/index.cjs +7 -0
  176. package/text-anchor/index.cjs +24 -0
  177. package/text-area/index.cjs +25 -0
  178. package/text-field/index.cjs +27 -0
  179. package/toggletip/index.cjs +29 -0
  180. package/tooltip/index.cjs +29 -0
  181. package/tree-item/index.cjs +22 -0
  182. package/tree-view/index.cjs +14 -0
@@ -0,0 +1,1072 @@
1
+ 'use strict';
2
+
3
+ const keyCodes$1 = require('./key-codes2.cjs');
4
+ const index = require('./index.cjs');
5
+ const definition = require('./definition35.cjs');
6
+ const ariaGlobal = require('./aria-global.cjs');
7
+ const applyMixins = require('./apply-mixins.cjs');
8
+ const keyCodes = require('./key-codes.cjs');
9
+ const strings = require('./strings.cjs');
10
+ const numbers = require('./numbers.cjs');
11
+
12
+ /**
13
+ * Returns the index of the last element in the array where predicate is true, and -1 otherwise.
14
+ *
15
+ * @param array - the array to test
16
+ * @param predicate - find calls predicate once for each element of the array, in descending order, until it finds one where predicate returns true. If such an element is found, findLastIndex immediately returns that element index. Otherwise, findIndex returns -1.
17
+ */
18
+ function findLastIndex(array, predicate) {
19
+ let k = array.length;
20
+ while (k--) {
21
+ if (predicate(array[k], k, array)) {
22
+ return k;
23
+ }
24
+ }
25
+ return -1;
26
+ }
27
+
28
+ /**
29
+ * A Listbox Custom HTML Element.
30
+ * Implements the {@link https://www.w3.org/TR/wai-aria-1.1/#listbox | ARIA listbox }.
31
+ *
32
+ * @slot - The default slot for the listbox options
33
+ *
34
+ * @public
35
+ */
36
+ let Listbox$1 = class Listbox extends index.FoundationElement {
37
+ constructor() {
38
+ super(...arguments);
39
+ /**
40
+ * The internal unfiltered list of selectable options.
41
+ *
42
+ * @internal
43
+ */
44
+ this._options = [];
45
+ /**
46
+ * The index of the selected option.
47
+ *
48
+ * @public
49
+ */
50
+ this.selectedIndex = -1;
51
+ /**
52
+ * A collection of the selected options.
53
+ *
54
+ * @public
55
+ */
56
+ this.selectedOptions = [];
57
+ /**
58
+ * A standard `click` event creates a `focus` event before firing, so a
59
+ * `mousedown` event is used to skip that initial focus.
60
+ *
61
+ * @internal
62
+ */
63
+ this.shouldSkipFocus = false;
64
+ /**
65
+ * The current typeahead buffer string.
66
+ *
67
+ * @internal
68
+ */
69
+ this.typeaheadBuffer = "";
70
+ /**
71
+ * Flag for the typeahead timeout expiration.
72
+ *
73
+ * @internal
74
+ */
75
+ this.typeaheadExpired = true;
76
+ /**
77
+ * The timeout ID for the typeahead handler.
78
+ *
79
+ * @internal
80
+ */
81
+ this.typeaheadTimeout = -1;
82
+ }
83
+ /**
84
+ * The first selected option.
85
+ *
86
+ * @internal
87
+ */
88
+ get firstSelectedOption() {
89
+ var _a;
90
+ return (_a = this.selectedOptions[0]) !== null && _a !== void 0 ? _a : null;
91
+ }
92
+ /**
93
+ * Returns true if there is one or more selectable option.
94
+ *
95
+ * @internal
96
+ */
97
+ get hasSelectableOptions() {
98
+ return this.options.length > 0 && !this.options.every(o => o.disabled);
99
+ }
100
+ /**
101
+ * The number of options.
102
+ *
103
+ * @public
104
+ */
105
+ get length() {
106
+ var _a, _b;
107
+ return (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0;
108
+ }
109
+ /**
110
+ * The list of options.
111
+ *
112
+ * @public
113
+ */
114
+ get options() {
115
+ index.Observable.track(this, "options");
116
+ return this._options;
117
+ }
118
+ set options(value) {
119
+ this._options = value;
120
+ index.Observable.notify(this, "options");
121
+ }
122
+ /**
123
+ * Flag for the typeahead timeout expiration.
124
+ *
125
+ * @deprecated use `Listbox.typeaheadExpired`
126
+ * @internal
127
+ */
128
+ get typeAheadExpired() {
129
+ return this.typeaheadExpired;
130
+ }
131
+ set typeAheadExpired(value) {
132
+ this.typeaheadExpired = value;
133
+ }
134
+ /**
135
+ * Handle click events for listbox options.
136
+ *
137
+ * @internal
138
+ */
139
+ clickHandler(e) {
140
+ const captured = e.target.closest(`option,[role=option]`);
141
+ if (captured && !captured.disabled) {
142
+ this.selectedIndex = this.options.indexOf(captured);
143
+ return true;
144
+ }
145
+ }
146
+ /**
147
+ * Ensures that the provided option is focused and scrolled into view.
148
+ *
149
+ * @param optionToFocus - The option to focus
150
+ * @internal
151
+ */
152
+ focusAndScrollOptionIntoView(optionToFocus = this.firstSelectedOption) {
153
+ // To ensure that the browser handles both `focus()` and `scrollIntoView()`, the
154
+ // timing here needs to guarantee that they happen on different frames. Since this
155
+ // function is typically called from the `openChanged` observer, `DOM.queueUpdate`
156
+ // causes the calls to be grouped into the same frame. To prevent this,
157
+ // `requestAnimationFrame` is used instead of `DOM.queueUpdate`.
158
+ if (this.contains(document.activeElement) && optionToFocus !== null) {
159
+ optionToFocus.focus();
160
+ requestAnimationFrame(() => {
161
+ optionToFocus.scrollIntoView({ block: "nearest" });
162
+ });
163
+ }
164
+ }
165
+ /**
166
+ * Handles `focusin` actions for the component. When the component receives focus,
167
+ * the list of selected options is refreshed and the first selected option is scrolled
168
+ * into view.
169
+ *
170
+ * @internal
171
+ */
172
+ focusinHandler(e) {
173
+ if (!this.shouldSkipFocus && e.target === e.currentTarget) {
174
+ this.setSelectedOptions();
175
+ this.focusAndScrollOptionIntoView();
176
+ }
177
+ this.shouldSkipFocus = false;
178
+ }
179
+ /**
180
+ * Returns the options which match the current typeahead buffer.
181
+ *
182
+ * @internal
183
+ */
184
+ getTypeaheadMatches() {
185
+ const pattern = this.typeaheadBuffer.replace(/[.*+\-?^${}()|[\]\\]/g, "\\$&");
186
+ const re = new RegExp(`^${pattern}`, "gi");
187
+ return this.options.filter((o) => o.text.trim().match(re));
188
+ }
189
+ /**
190
+ * Determines the index of the next option which is selectable, if any.
191
+ *
192
+ * @param prev - the previous selected index
193
+ * @param next - the next index to select
194
+ *
195
+ * @internal
196
+ */
197
+ getSelectableIndex(prev = this.selectedIndex, next) {
198
+ const direction = prev > next ? -1 : prev < next ? 1 : 0;
199
+ const potentialDirection = prev + direction;
200
+ let nextSelectableOption = null;
201
+ switch (direction) {
202
+ case -1: {
203
+ nextSelectableOption = this.options.reduceRight((nextSelectableOption, thisOption, index) => !nextSelectableOption &&
204
+ !thisOption.disabled &&
205
+ index < potentialDirection
206
+ ? thisOption
207
+ : nextSelectableOption, nextSelectableOption);
208
+ break;
209
+ }
210
+ case 1: {
211
+ nextSelectableOption = this.options.reduce((nextSelectableOption, thisOption, index) => !nextSelectableOption &&
212
+ !thisOption.disabled &&
213
+ index > potentialDirection
214
+ ? thisOption
215
+ : nextSelectableOption, nextSelectableOption);
216
+ break;
217
+ }
218
+ }
219
+ return this.options.indexOf(nextSelectableOption);
220
+ }
221
+ /**
222
+ * Handles external changes to child options.
223
+ *
224
+ * @param source - the source object
225
+ * @param propertyName - the property
226
+ *
227
+ * @internal
228
+ */
229
+ handleChange(source, propertyName) {
230
+ switch (propertyName) {
231
+ case "selected": {
232
+ if (Listbox.slottedOptionFilter(source)) {
233
+ this.selectedIndex = this.options.indexOf(source);
234
+ }
235
+ this.setSelectedOptions();
236
+ break;
237
+ }
238
+ }
239
+ }
240
+ /**
241
+ * Moves focus to an option whose label matches characters typed by the user.
242
+ * Consecutive keystrokes are batched into a buffer of search text used
243
+ * to match against the set of options. If `TYPE_AHEAD_TIMEOUT_MS` passes
244
+ * between consecutive keystrokes, the search restarts.
245
+ *
246
+ * @param key - the key to be evaluated
247
+ *
248
+ * @internal
249
+ */
250
+ handleTypeAhead(key) {
251
+ if (this.typeaheadTimeout) {
252
+ window.clearTimeout(this.typeaheadTimeout);
253
+ }
254
+ this.typeaheadTimeout = window.setTimeout(() => (this.typeaheadExpired = true), Listbox.TYPE_AHEAD_TIMEOUT_MS);
255
+ if (key.length > 1) {
256
+ return;
257
+ }
258
+ this.typeaheadBuffer = `${this.typeaheadExpired ? "" : this.typeaheadBuffer}${key}`;
259
+ }
260
+ /**
261
+ * Handles `keydown` actions for listbox navigation and typeahead.
262
+ *
263
+ * @internal
264
+ */
265
+ keydownHandler(e) {
266
+ if (this.disabled) {
267
+ return true;
268
+ }
269
+ this.shouldSkipFocus = false;
270
+ const key = e.key;
271
+ switch (key) {
272
+ // Select the first available option
273
+ case keyCodes.keyHome: {
274
+ if (!e.shiftKey) {
275
+ e.preventDefault();
276
+ this.selectFirstOption();
277
+ }
278
+ break;
279
+ }
280
+ // Select the next selectable option
281
+ case keyCodes.keyArrowDown: {
282
+ if (!e.shiftKey) {
283
+ e.preventDefault();
284
+ this.selectNextOption();
285
+ }
286
+ break;
287
+ }
288
+ // Select the previous selectable option
289
+ case keyCodes.keyArrowUp: {
290
+ if (!e.shiftKey) {
291
+ e.preventDefault();
292
+ this.selectPreviousOption();
293
+ }
294
+ break;
295
+ }
296
+ // Select the last available option
297
+ case keyCodes.keyEnd: {
298
+ e.preventDefault();
299
+ this.selectLastOption();
300
+ break;
301
+ }
302
+ case keyCodes.keyTab: {
303
+ this.focusAndScrollOptionIntoView();
304
+ return true;
305
+ }
306
+ case keyCodes.keyEnter:
307
+ case keyCodes.keyEscape: {
308
+ return true;
309
+ }
310
+ case keyCodes.keySpace: {
311
+ if (this.typeaheadExpired) {
312
+ return true;
313
+ }
314
+ }
315
+ // Send key to Typeahead handler
316
+ default: {
317
+ if (key.length === 1) {
318
+ this.handleTypeAhead(`${key}`);
319
+ }
320
+ return true;
321
+ }
322
+ }
323
+ }
324
+ /**
325
+ * Prevents `focusin` events from firing before `click` events when the
326
+ * element is unfocused.
327
+ *
328
+ * @internal
329
+ */
330
+ mousedownHandler(e) {
331
+ this.shouldSkipFocus = !this.contains(document.activeElement);
332
+ return true;
333
+ }
334
+ /**
335
+ * Switches between single-selection and multi-selection mode.
336
+ *
337
+ * @param prev - the previous value of the `multiple` attribute
338
+ * @param next - the next value of the `multiple` attribute
339
+ *
340
+ * @internal
341
+ */
342
+ multipleChanged(prev, next) {
343
+ this.ariaMultiSelectable = next ? "true" : null;
344
+ }
345
+ /**
346
+ * Updates the list of selected options when the `selectedIndex` changes.
347
+ *
348
+ * @param prev - the previous selected index value
349
+ * @param next - the current selected index value
350
+ *
351
+ * @internal
352
+ */
353
+ selectedIndexChanged(prev, next) {
354
+ var _a;
355
+ if (!this.hasSelectableOptions) {
356
+ this.selectedIndex = -1;
357
+ return;
358
+ }
359
+ if (((_a = this.options[this.selectedIndex]) === null || _a === void 0 ? void 0 : _a.disabled) && typeof prev === "number") {
360
+ const selectableIndex = this.getSelectableIndex(prev, next);
361
+ const newNext = selectableIndex > -1 ? selectableIndex : prev;
362
+ this.selectedIndex = newNext;
363
+ if (next === newNext) {
364
+ this.selectedIndexChanged(next, newNext);
365
+ }
366
+ return;
367
+ }
368
+ this.setSelectedOptions();
369
+ }
370
+ /**
371
+ * Updates the selectedness of each option when the list of selected options changes.
372
+ *
373
+ * @param prev - the previous list of selected options
374
+ * @param next - the current list of selected options
375
+ *
376
+ * @internal
377
+ */
378
+ selectedOptionsChanged(prev, next) {
379
+ var _a;
380
+ const filteredNext = next.filter(Listbox.slottedOptionFilter);
381
+ (_a = this.options) === null || _a === void 0 ? void 0 : _a.forEach(o => {
382
+ const notifier = index.Observable.getNotifier(o);
383
+ notifier.unsubscribe(this, "selected");
384
+ o.selected = filteredNext.includes(o);
385
+ notifier.subscribe(this, "selected");
386
+ });
387
+ }
388
+ /**
389
+ * Moves focus to the first selectable option.
390
+ *
391
+ * @public
392
+ */
393
+ selectFirstOption() {
394
+ var _a, _b;
395
+ if (!this.disabled) {
396
+ this.selectedIndex = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.findIndex(o => !o.disabled)) !== null && _b !== void 0 ? _b : -1;
397
+ }
398
+ }
399
+ /**
400
+ * Moves focus to the last selectable option.
401
+ *
402
+ * @internal
403
+ */
404
+ selectLastOption() {
405
+ if (!this.disabled) {
406
+ this.selectedIndex = findLastIndex(this.options, o => !o.disabled);
407
+ }
408
+ }
409
+ /**
410
+ * Moves focus to the next selectable option.
411
+ *
412
+ * @internal
413
+ */
414
+ selectNextOption() {
415
+ if (!this.disabled && this.selectedIndex < this.options.length - 1) {
416
+ this.selectedIndex += 1;
417
+ }
418
+ }
419
+ /**
420
+ * Moves focus to the previous selectable option.
421
+ *
422
+ * @internal
423
+ */
424
+ selectPreviousOption() {
425
+ if (!this.disabled && this.selectedIndex > 0) {
426
+ this.selectedIndex = this.selectedIndex - 1;
427
+ }
428
+ }
429
+ /**
430
+ * Updates the selected index to match the first selected option.
431
+ *
432
+ * @internal
433
+ */
434
+ setDefaultSelectedOption() {
435
+ var _a, _b;
436
+ this.selectedIndex = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.findIndex(el => el.defaultSelected)) !== null && _b !== void 0 ? _b : -1;
437
+ }
438
+ /**
439
+ * Sets an option as selected and gives it focus.
440
+ *
441
+ * @public
442
+ */
443
+ setSelectedOptions() {
444
+ var _a, _b, _c;
445
+ if ((_a = this.options) === null || _a === void 0 ? void 0 : _a.length) {
446
+ this.selectedOptions = [this.options[this.selectedIndex]];
447
+ this.ariaActiveDescendant = (_c = (_b = this.firstSelectedOption) === null || _b === void 0 ? void 0 : _b.id) !== null && _c !== void 0 ? _c : "";
448
+ this.focusAndScrollOptionIntoView();
449
+ }
450
+ }
451
+ /**
452
+ * Updates the list of options and resets the selected option when the slotted option content changes.
453
+ *
454
+ * @param prev - the previous list of slotted options
455
+ * @param next - the current list of slotted options
456
+ *
457
+ * @internal
458
+ */
459
+ slottedOptionsChanged(prev, next) {
460
+ this.options = next.reduce((options, item) => {
461
+ if (definition.isListboxOption(item)) {
462
+ options.push(item);
463
+ }
464
+ return options;
465
+ }, []);
466
+ const setSize = `${this.options.length}`;
467
+ this.options.forEach((option, index) => {
468
+ if (!option.id) {
469
+ option.id = strings.uniqueId("option-");
470
+ }
471
+ option.ariaPosInSet = `${index + 1}`;
472
+ option.ariaSetSize = setSize;
473
+ });
474
+ if (this.$fastController.isConnected) {
475
+ this.setSelectedOptions();
476
+ this.setDefaultSelectedOption();
477
+ }
478
+ }
479
+ /**
480
+ * Updates the filtered list of options when the typeahead buffer changes.
481
+ *
482
+ * @param prev - the previous typeahead buffer value
483
+ * @param next - the current typeahead buffer value
484
+ *
485
+ * @internal
486
+ */
487
+ typeaheadBufferChanged(prev, next) {
488
+ if (this.$fastController.isConnected) {
489
+ const typeaheadMatches = this.getTypeaheadMatches();
490
+ if (typeaheadMatches.length) {
491
+ const selectedIndex = this.options.indexOf(typeaheadMatches[0]);
492
+ if (selectedIndex > -1) {
493
+ this.selectedIndex = selectedIndex;
494
+ }
495
+ }
496
+ this.typeaheadExpired = false;
497
+ }
498
+ }
499
+ };
500
+ /**
501
+ * A static filter to include only selectable options.
502
+ *
503
+ * @param n - element to filter
504
+ * @public
505
+ */
506
+ Listbox$1.slottedOptionFilter = (n) => definition.isListboxOption(n) && !n.hidden;
507
+ /**
508
+ * Typeahead timeout in milliseconds.
509
+ *
510
+ * @internal
511
+ */
512
+ Listbox$1.TYPE_AHEAD_TIMEOUT_MS = 1000;
513
+ index.__decorate([
514
+ index.attr({ mode: "boolean" })
515
+ ], Listbox$1.prototype, "disabled", void 0);
516
+ index.__decorate([
517
+ index.observable
518
+ ], Listbox$1.prototype, "selectedIndex", void 0);
519
+ index.__decorate([
520
+ index.observable
521
+ ], Listbox$1.prototype, "selectedOptions", void 0);
522
+ index.__decorate([
523
+ index.observable
524
+ ], Listbox$1.prototype, "slottedOptions", void 0);
525
+ index.__decorate([
526
+ index.observable
527
+ ], Listbox$1.prototype, "typeaheadBuffer", void 0);
528
+ /**
529
+ * Includes ARIA states and properties relating to the ARIA listbox role
530
+ *
531
+ * @public
532
+ */
533
+ class DelegatesARIAListbox {
534
+ }
535
+ index.__decorate([
536
+ index.observable
537
+ ], DelegatesARIAListbox.prototype, "ariaActiveDescendant", void 0);
538
+ index.__decorate([
539
+ index.observable
540
+ ], DelegatesARIAListbox.prototype, "ariaDisabled", void 0);
541
+ index.__decorate([
542
+ index.observable
543
+ ], DelegatesARIAListbox.prototype, "ariaExpanded", void 0);
544
+ index.__decorate([
545
+ index.observable
546
+ ], DelegatesARIAListbox.prototype, "ariaMultiSelectable", void 0);
547
+ applyMixins.applyMixins(DelegatesARIAListbox, ariaGlobal.ARIAGlobalStatesAndProperties);
548
+ applyMixins.applyMixins(Listbox$1, DelegatesARIAListbox);
549
+
550
+ /**
551
+ * A Listbox Custom HTML Element.
552
+ * Implements the {@link https://w3c.github.io/aria/#listbox | ARIA listbox }.
553
+ *
554
+ * @public
555
+ */
556
+ class ListboxElement extends Listbox$1 {
557
+ constructor() {
558
+ super(...arguments);
559
+ /**
560
+ * The index of the most recently checked option.
561
+ *
562
+ * @internal
563
+ * @remarks
564
+ * Multiple-selection mode only.
565
+ */
566
+ this.activeIndex = -1;
567
+ /**
568
+ * The start index when checking a range of options.
569
+ *
570
+ * @internal
571
+ */
572
+ this.rangeStartIndex = -1;
573
+ }
574
+ /**
575
+ * Returns the last checked option.
576
+ *
577
+ * @internal
578
+ */
579
+ get activeOption() {
580
+ return this.options[this.activeIndex];
581
+ }
582
+ /**
583
+ * Returns the list of checked options.
584
+ *
585
+ * @internal
586
+ */
587
+ get checkedOptions() {
588
+ var _a;
589
+ return (_a = this.options) === null || _a === void 0 ? void 0 : _a.filter(o => o.checked);
590
+ }
591
+ /**
592
+ * Returns the index of the first selected option.
593
+ *
594
+ * @internal
595
+ */
596
+ get firstSelectedOptionIndex() {
597
+ return this.options.indexOf(this.firstSelectedOption);
598
+ }
599
+ /**
600
+ * Updates the `ariaActiveDescendant` property when the active index changes.
601
+ *
602
+ * @param prev - the previous active index
603
+ * @param next - the next active index
604
+ *
605
+ * @internal
606
+ */
607
+ activeIndexChanged(prev, next) {
608
+ var _a, _b;
609
+ this.ariaActiveDescendant = (_b = (_a = this.options[next]) === null || _a === void 0 ? void 0 : _a.id) !== null && _b !== void 0 ? _b : "";
610
+ this.focusAndScrollOptionIntoView();
611
+ }
612
+ /**
613
+ * Toggles the checked state for the currently active option.
614
+ *
615
+ * @remarks
616
+ * Multiple-selection mode only.
617
+ *
618
+ * @internal
619
+ */
620
+ checkActiveIndex() {
621
+ if (!this.multiple) {
622
+ return;
623
+ }
624
+ const activeItem = this.activeOption;
625
+ if (activeItem) {
626
+ activeItem.checked = true;
627
+ }
628
+ }
629
+ /**
630
+ * Sets the active index to the first option and marks it as checked.
631
+ *
632
+ * @remarks
633
+ * Multi-selection mode only.
634
+ *
635
+ * @param preserveChecked - mark all options unchecked before changing the active index
636
+ *
637
+ * @internal
638
+ */
639
+ checkFirstOption(preserveChecked = false) {
640
+ if (preserveChecked) {
641
+ if (this.rangeStartIndex === -1) {
642
+ this.rangeStartIndex = this.activeIndex + 1;
643
+ }
644
+ this.options.forEach((o, i) => {
645
+ o.checked = numbers.inRange(i, this.rangeStartIndex);
646
+ });
647
+ }
648
+ else {
649
+ this.uncheckAllOptions();
650
+ }
651
+ this.activeIndex = 0;
652
+ this.checkActiveIndex();
653
+ }
654
+ /**
655
+ * Decrements the active index and sets the matching option as checked.
656
+ *
657
+ * @remarks
658
+ * Multi-selection mode only.
659
+ *
660
+ * @param preserveChecked - mark all options unchecked before changing the active index
661
+ *
662
+ * @internal
663
+ */
664
+ checkLastOption(preserveChecked = false) {
665
+ if (preserveChecked) {
666
+ if (this.rangeStartIndex === -1) {
667
+ this.rangeStartIndex = this.activeIndex;
668
+ }
669
+ this.options.forEach((o, i) => {
670
+ o.checked = numbers.inRange(i, this.rangeStartIndex, this.options.length);
671
+ });
672
+ }
673
+ else {
674
+ this.uncheckAllOptions();
675
+ }
676
+ this.activeIndex = this.options.length - 1;
677
+ this.checkActiveIndex();
678
+ }
679
+ /**
680
+ * @override
681
+ * @internal
682
+ */
683
+ connectedCallback() {
684
+ super.connectedCallback();
685
+ this.addEventListener("focusout", this.focusoutHandler);
686
+ }
687
+ /**
688
+ * @override
689
+ * @internal
690
+ */
691
+ disconnectedCallback() {
692
+ this.removeEventListener("focusout", this.focusoutHandler);
693
+ super.disconnectedCallback();
694
+ }
695
+ /**
696
+ * Increments the active index and marks the matching option as checked.
697
+ *
698
+ * @remarks
699
+ * Multiple-selection mode only.
700
+ *
701
+ * @param preserveChecked - mark all options unchecked before changing the active index
702
+ *
703
+ * @internal
704
+ */
705
+ checkNextOption(preserveChecked = false) {
706
+ if (preserveChecked) {
707
+ if (this.rangeStartIndex === -1) {
708
+ this.rangeStartIndex = this.activeIndex;
709
+ }
710
+ this.options.forEach((o, i) => {
711
+ o.checked = numbers.inRange(i, this.rangeStartIndex, this.activeIndex + 1);
712
+ });
713
+ }
714
+ else {
715
+ this.uncheckAllOptions();
716
+ }
717
+ this.activeIndex += this.activeIndex < this.options.length - 1 ? 1 : 0;
718
+ this.checkActiveIndex();
719
+ }
720
+ /**
721
+ * Decrements the active index and marks the matching option as checked.
722
+ *
723
+ * @remarks
724
+ * Multiple-selection mode only.
725
+ *
726
+ * @param preserveChecked - mark all options unchecked before changing the active index
727
+ *
728
+ * @internal
729
+ */
730
+ checkPreviousOption(preserveChecked = false) {
731
+ if (preserveChecked) {
732
+ if (this.rangeStartIndex === -1) {
733
+ this.rangeStartIndex = this.activeIndex;
734
+ }
735
+ if (this.checkedOptions.length === 1) {
736
+ this.rangeStartIndex += 1;
737
+ }
738
+ this.options.forEach((o, i) => {
739
+ o.checked = numbers.inRange(i, this.activeIndex, this.rangeStartIndex);
740
+ });
741
+ }
742
+ else {
743
+ this.uncheckAllOptions();
744
+ }
745
+ this.activeIndex -= this.activeIndex > 0 ? 1 : 0;
746
+ this.checkActiveIndex();
747
+ }
748
+ /**
749
+ * Handles click events for listbox options.
750
+ *
751
+ * @param e - the event object
752
+ *
753
+ * @override
754
+ * @internal
755
+ */
756
+ clickHandler(e) {
757
+ var _a;
758
+ if (!this.multiple) {
759
+ return super.clickHandler(e);
760
+ }
761
+ const captured = (_a = e.target) === null || _a === void 0 ? void 0 : _a.closest(`[role=option]`);
762
+ if (!captured || captured.disabled) {
763
+ return;
764
+ }
765
+ this.uncheckAllOptions();
766
+ this.activeIndex = this.options.indexOf(captured);
767
+ this.checkActiveIndex();
768
+ this.toggleSelectedForAllCheckedOptions();
769
+ return true;
770
+ }
771
+ /**
772
+ * @override
773
+ * @internal
774
+ */
775
+ focusAndScrollOptionIntoView() {
776
+ super.focusAndScrollOptionIntoView(this.activeOption);
777
+ }
778
+ /**
779
+ * In multiple-selection mode:
780
+ * If any options are selected, the first selected option is checked when
781
+ * the listbox receives focus. If no options are selected, the first
782
+ * selectable option is checked.
783
+ *
784
+ * @override
785
+ * @internal
786
+ */
787
+ focusinHandler(e) {
788
+ if (!this.multiple) {
789
+ return super.focusinHandler(e);
790
+ }
791
+ if (!this.shouldSkipFocus && e.target === e.currentTarget) {
792
+ this.uncheckAllOptions();
793
+ if (this.activeIndex === -1) {
794
+ this.activeIndex =
795
+ this.firstSelectedOptionIndex !== -1
796
+ ? this.firstSelectedOptionIndex
797
+ : 0;
798
+ }
799
+ this.checkActiveIndex();
800
+ this.setSelectedOptions();
801
+ this.focusAndScrollOptionIntoView();
802
+ }
803
+ this.shouldSkipFocus = false;
804
+ }
805
+ /**
806
+ * Unchecks all options when the listbox loses focus.
807
+ *
808
+ * @internal
809
+ */
810
+ focusoutHandler(e) {
811
+ if (this.multiple) {
812
+ this.uncheckAllOptions();
813
+ }
814
+ }
815
+ /**
816
+ * Handles keydown actions for listbox navigation and typeahead
817
+ *
818
+ * @override
819
+ * @internal
820
+ */
821
+ keydownHandler(e) {
822
+ if (!this.multiple) {
823
+ return super.keydownHandler(e);
824
+ }
825
+ if (this.disabled) {
826
+ return true;
827
+ }
828
+ const { key, shiftKey } = e;
829
+ this.shouldSkipFocus = false;
830
+ switch (key) {
831
+ // Select the first available option
832
+ case keyCodes.keyHome: {
833
+ this.checkFirstOption(shiftKey);
834
+ return;
835
+ }
836
+ // Select the next selectable option
837
+ case keyCodes.keyArrowDown: {
838
+ this.checkNextOption(shiftKey);
839
+ return;
840
+ }
841
+ // Select the previous selectable option
842
+ case keyCodes.keyArrowUp: {
843
+ this.checkPreviousOption(shiftKey);
844
+ return;
845
+ }
846
+ // Select the last available option
847
+ case keyCodes.keyEnd: {
848
+ this.checkLastOption(shiftKey);
849
+ return;
850
+ }
851
+ case keyCodes.keyTab: {
852
+ this.focusAndScrollOptionIntoView();
853
+ return true;
854
+ }
855
+ case keyCodes.keyEscape: {
856
+ this.uncheckAllOptions();
857
+ this.checkActiveIndex();
858
+ return true;
859
+ }
860
+ case keyCodes.keySpace: {
861
+ e.preventDefault();
862
+ if (this.typeAheadExpired) {
863
+ this.toggleSelectedForAllCheckedOptions();
864
+ return;
865
+ }
866
+ }
867
+ // Send key to Typeahead handler
868
+ default: {
869
+ if (key.length === 1) {
870
+ this.handleTypeAhead(`${key}`);
871
+ }
872
+ return true;
873
+ }
874
+ }
875
+ }
876
+ /**
877
+ * Prevents `focusin` events from firing before `click` events when the
878
+ * element is unfocused.
879
+ *
880
+ * @override
881
+ * @internal
882
+ */
883
+ mousedownHandler(e) {
884
+ if (e.offsetX >= 0 && e.offsetX <= this.scrollWidth) {
885
+ return super.mousedownHandler(e);
886
+ }
887
+ }
888
+ /**
889
+ * Switches between single-selection and multi-selection mode.
890
+ *
891
+ * @internal
892
+ */
893
+ multipleChanged(prev, next) {
894
+ var _a;
895
+ this.ariaMultiSelectable = next ? "true" : null;
896
+ (_a = this.options) === null || _a === void 0 ? void 0 : _a.forEach(o => {
897
+ o.checked = next ? false : undefined;
898
+ });
899
+ this.setSelectedOptions();
900
+ }
901
+ /**
902
+ * Sets an option as selected and gives it focus.
903
+ *
904
+ * @override
905
+ * @public
906
+ */
907
+ setSelectedOptions() {
908
+ if (!this.multiple) {
909
+ super.setSelectedOptions();
910
+ return;
911
+ }
912
+ if (this.$fastController.isConnected && this.options) {
913
+ this.selectedOptions = this.options.filter(o => o.selected);
914
+ this.focusAndScrollOptionIntoView();
915
+ }
916
+ }
917
+ /**
918
+ * Ensures the size is a positive integer when the property is updated.
919
+ *
920
+ * @param prev - the previous size value
921
+ * @param next - the current size value
922
+ *
923
+ * @internal
924
+ */
925
+ sizeChanged(prev, next) {
926
+ var _a;
927
+ const size = Math.max(0, parseInt((_a = next === null || next === void 0 ? void 0 : next.toFixed()) !== null && _a !== void 0 ? _a : "", 10));
928
+ if (size !== next) {
929
+ index.DOM.queueUpdate(() => {
930
+ this.size = size;
931
+ });
932
+ }
933
+ }
934
+ /**
935
+ * Toggles the selected state of the provided options. If any provided items
936
+ * are in an unselected state, all items are set to selected. If every
937
+ * provided item is selected, they are all unselected.
938
+ *
939
+ * @internal
940
+ */
941
+ toggleSelectedForAllCheckedOptions() {
942
+ const enabledCheckedOptions = this.checkedOptions.filter(o => !o.disabled);
943
+ const force = !enabledCheckedOptions.every(o => o.selected);
944
+ enabledCheckedOptions.forEach(o => (o.selected = force));
945
+ this.selectedIndex = this.options.indexOf(enabledCheckedOptions[enabledCheckedOptions.length - 1]);
946
+ this.setSelectedOptions();
947
+ }
948
+ /**
949
+ * @override
950
+ * @internal
951
+ */
952
+ typeaheadBufferChanged(prev, next) {
953
+ if (!this.multiple) {
954
+ super.typeaheadBufferChanged(prev, next);
955
+ return;
956
+ }
957
+ if (this.$fastController.isConnected) {
958
+ const typeaheadMatches = this.getTypeaheadMatches();
959
+ const activeIndex = this.options.indexOf(typeaheadMatches[0]);
960
+ if (activeIndex > -1) {
961
+ this.activeIndex = activeIndex;
962
+ this.uncheckAllOptions();
963
+ this.checkActiveIndex();
964
+ }
965
+ this.typeAheadExpired = false;
966
+ }
967
+ }
968
+ /**
969
+ * Unchecks all options.
970
+ *
971
+ * @remarks
972
+ * Multiple-selection mode only.
973
+ *
974
+ * @param preserveChecked - reset the rangeStartIndex
975
+ *
976
+ * @internal
977
+ */
978
+ uncheckAllOptions(preserveChecked = false) {
979
+ this.options.forEach(o => (o.checked = this.multiple ? false : undefined));
980
+ if (!preserveChecked) {
981
+ this.rangeStartIndex = -1;
982
+ }
983
+ }
984
+ }
985
+ index.__decorate([
986
+ index.observable
987
+ ], ListboxElement.prototype, "activeIndex", void 0);
988
+ index.__decorate([
989
+ index.attr({ mode: "boolean" })
990
+ ], ListboxElement.prototype, "multiple", void 0);
991
+ index.__decorate([
992
+ index.attr({ converter: index.nullableNumberConverter })
993
+ ], ListboxElement.prototype, "size", void 0);
994
+
995
+ var __defProp = Object.defineProperty;
996
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
997
+ var __decorateClass = (decorators, target, key, kind) => {
998
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
999
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
1000
+ if (decorator = decorators[i])
1001
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
1002
+ if (kind && result)
1003
+ __defProp(target, key, result);
1004
+ return result;
1005
+ };
1006
+ class Listbox extends ListboxElement {
1007
+ orientationChanged() {
1008
+ if (this.orientation === "horizontal") {
1009
+ this.addEventListener("keydown", this.#horizontalKeydownHandler);
1010
+ } else {
1011
+ this.removeEventListener("keydown", this.#horizontalKeydownHandler);
1012
+ }
1013
+ }
1014
+ /**
1015
+ * Handles `keydown` actions for horizontal listbox navigation and typeahead.
1016
+ *
1017
+ * @internal
1018
+ */
1019
+ #horizontalKeydownHandler(e) {
1020
+ if (this.disabled) {
1021
+ return true;
1022
+ }
1023
+ const key = e.key;
1024
+ switch (key) {
1025
+ case keyCodes$1.keyArrowRight: {
1026
+ if (!e.shiftKey) {
1027
+ e.preventDefault();
1028
+ this.selectNextOption();
1029
+ }
1030
+ break;
1031
+ }
1032
+ case keyCodes$1.keyArrowLeft: {
1033
+ if (!e.shiftKey) {
1034
+ e.preventDefault();
1035
+ this.selectPreviousOption();
1036
+ }
1037
+ break;
1038
+ }
1039
+ }
1040
+ }
1041
+ slottedOptionsChanged(prev, next) {
1042
+ super.slottedOptionsChanged(prev, next);
1043
+ this.#disableSlottedChildren();
1044
+ }
1045
+ attributeChangedCallback(name, oldValue, newValue) {
1046
+ super.attributeChangedCallback(name, oldValue, newValue);
1047
+ if (name === "disabled") {
1048
+ this.#disableSlottedChildren();
1049
+ }
1050
+ }
1051
+ #disableSlottedChildren() {
1052
+ this.options.forEach((optionElement) => {
1053
+ if (!optionElement.disabled) {
1054
+ optionElement.disabled = this.disabled;
1055
+ }
1056
+ });
1057
+ }
1058
+ }
1059
+ __decorateClass([
1060
+ index.attr
1061
+ ], Listbox.prototype, "appearance", 2);
1062
+ __decorateClass([
1063
+ index.attr
1064
+ ], Listbox.prototype, "orientation", 2);
1065
+ __decorateClass([
1066
+ index.attr
1067
+ ], Listbox.prototype, "shape", 2);
1068
+
1069
+ exports.DelegatesARIAListbox = DelegatesARIAListbox;
1070
+ exports.Listbox = Listbox;
1071
+ exports.Listbox$1 = Listbox$1;
1072
+ exports.ListboxElement = ListboxElement;