@vonage/vivid 3.0.0-next.119 → 3.0.0-next.120

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