@vonage/vivid 3.0.0-next.121 → 3.0.0-next.122

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