@vonage/vivid 3.0.1 → 3.1.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 (72) hide show
  1. package/README.md +2 -2
  2. package/calendar/index.js +1 -0
  3. package/custom-elements.json +6206 -0
  4. package/data-grid/index.js +1104 -0
  5. package/index.js +2 -0
  6. package/lib/data-grid/data-grid-cell.d.ts +5 -0
  7. package/lib/data-grid/data-grid-cell.template.d.ts +4 -0
  8. package/lib/data-grid/data-grid-row.d.ts +3 -0
  9. package/lib/data-grid/data-grid-row.template.d.ts +3 -0
  10. package/lib/data-grid/data-grid.d.ts +3 -0
  11. package/lib/data-grid/data-grid.options.d.ts +31 -0
  12. package/lib/data-grid/data-grid.template.d.ts +3 -0
  13. package/lib/data-grid/definition.d.ts +6 -0
  14. package/lib/data-grid/index.d.ts +1 -0
  15. package/lib/popup/definition.d.ts +0 -1
  16. package/lib/popup/popup.d.ts +2 -2
  17. package/number-field/index.js +1 -1
  18. package/package.json +28 -29
  19. package/radio-group/index.js +1 -0
  20. package/shared/aria2.js +9 -0
  21. package/shared/definition.js +1 -1
  22. package/shared/definition11.js +1 -1
  23. package/shared/definition12.js +46 -797
  24. package/shared/definition13.js +1 -1
  25. package/shared/definition14.js +1 -1
  26. package/shared/definition16.js +1 -1
  27. package/shared/definition17.js +1 -1
  28. package/shared/definition18.js +594 -843
  29. package/shared/definition19.js +1 -1
  30. package/shared/definition2.js +1 -1
  31. package/shared/definition20.js +24 -28
  32. package/shared/definition21.js +1 -1
  33. package/shared/definition22.js +1 -1
  34. package/shared/definition23.js +1 -1
  35. package/shared/definition25.js +1 -1
  36. package/shared/definition27.js +2 -2
  37. package/shared/definition29.js +1 -1
  38. package/shared/definition30.js +1 -1
  39. package/shared/definition31.js +1 -1
  40. package/shared/definition32.js +1 -1
  41. package/shared/definition33.js +1 -1
  42. package/shared/definition34.js +1 -1
  43. package/shared/definition35.js +4 -3
  44. package/shared/definition36.js +1 -1
  45. package/shared/definition37.js +7 -3
  46. package/shared/definition38.js +3 -2
  47. package/shared/definition39.js +1 -1
  48. package/shared/definition4.js +1 -1
  49. package/shared/definition40.js +1 -1
  50. package/shared/definition42.js +2 -2
  51. package/shared/definition43.js +1 -1
  52. package/shared/definition45.js +1 -1
  53. package/shared/definition5.js +1 -1
  54. package/shared/definition6.js +1 -1
  55. package/shared/definition7.js +1 -1
  56. package/shared/definition8.js +1 -1
  57. package/shared/definition9.js +1 -1
  58. package/shared/form-elements.js +1 -1
  59. package/shared/icon.js +18 -6
  60. package/shared/index.js +10 -19
  61. package/shared/key-codes.js +4 -1
  62. package/shared/patterns/form-elements/form-elements.d.ts +2 -2
  63. package/shared/repeat.js +764 -0
  64. package/shared/slotted.js +1 -1
  65. package/shared/text-field.js +1 -1
  66. package/slider/index.js +1 -0
  67. package/styles/core/all.css +1 -1
  68. package/styles/core/theme.css +1 -1
  69. package/styles/core/typography.css +1 -1
  70. package/styles/tokens/theme-dark.css +4 -4
  71. package/styles/tokens/theme-light.css +4 -4
  72. package/vivid.api.json +3695 -0
@@ -0,0 +1,1104 @@
1
+ import { A as AttachedBehaviorHTMLDirective, F as FoundationElement, _ as __decorate, a as attr, o as observable, W as DOM, h as html, r as registerFactory } from '../shared/index.js';
2
+ import { k as keyEnd, a as keyHome, h as keyArrowRight, i as keyArrowLeft, j as keyPageDown, l as keyPageUp, b as keyArrowDown, c as keyArrowUp, f as keyEscape, m as keyFunction2, d as keyEnter } from '../shared/key-codes.js';
3
+ import { R as RepeatDirective } from '../shared/repeat.js';
4
+ import { N as NodeObservationBehavior, e as elements, s as slotted } from '../shared/slotted.js';
5
+ import { f as focusTemplateFactory } from '../shared/focus2.js';
6
+ import '../shared/focus.js';
7
+
8
+ /**
9
+ * The runtime behavior for child node observation.
10
+ * @public
11
+ */
12
+ class ChildrenBehavior extends NodeObservationBehavior {
13
+ /**
14
+ * Creates an instance of ChildrenBehavior.
15
+ * @param target - The element target to observe children on.
16
+ * @param options - The options to use when observing the element children.
17
+ */
18
+ constructor(target, options) {
19
+ super(target, options);
20
+ this.observer = null;
21
+ options.childList = true;
22
+ }
23
+ /**
24
+ * Begins observation of the nodes.
25
+ */
26
+ observe() {
27
+ if (this.observer === null) {
28
+ this.observer = new MutationObserver(this.handleEvent.bind(this));
29
+ }
30
+ this.observer.observe(this.target, this.options);
31
+ }
32
+ /**
33
+ * Disconnects observation of the nodes.
34
+ */
35
+ disconnect() {
36
+ this.observer.disconnect();
37
+ }
38
+ /**
39
+ * Retrieves the nodes that should be assigned to the target.
40
+ */
41
+ getNodes() {
42
+ if ("subtree" in this.options) {
43
+ return Array.from(this.target.querySelectorAll(this.options.selector));
44
+ }
45
+ return Array.from(this.target.childNodes);
46
+ }
47
+ }
48
+ /**
49
+ * A directive that observes the `childNodes` of an element and updates a property
50
+ * whenever they change.
51
+ * @param propertyOrOptions - The options used to configure child node observation.
52
+ * @public
53
+ */
54
+ function children(propertyOrOptions) {
55
+ if (typeof propertyOrOptions === "string") {
56
+ propertyOrOptions = {
57
+ property: propertyOrOptions,
58
+ };
59
+ }
60
+ return new AttachedBehaviorHTMLDirective("fast-children", ChildrenBehavior, propertyOrOptions);
61
+ }
62
+
63
+ /**
64
+ * This set of exported strings reference https://developer.mozilla.org/en-US/docs/Web/Events
65
+ * and should include all non-deprecated and non-experimental Standard events
66
+ */
67
+ const eventFocus = "focus";
68
+ const eventFocusIn = "focusin";
69
+ const eventFocusOut = "focusout";
70
+ const eventKeyDown = "keydown";
71
+
72
+ /**
73
+ * Enumerates the data grid auto generated header options
74
+ * default option generates a non-sticky header row
75
+ *
76
+ * @public
77
+ */
78
+ const GenerateHeaderOptions = {
79
+ none: "none",
80
+ default: "default",
81
+ sticky: "sticky",
82
+ };
83
+ /**
84
+ * Enumerates possible data grid cell types.
85
+ *
86
+ * @public
87
+ */
88
+ const DataGridCellTypes = {
89
+ default: "default",
90
+ columnHeader: "columnheader",
91
+ rowHeader: "rowheader",
92
+ };
93
+ /**
94
+ * Enumerates possible data grid row types
95
+ *
96
+ * @public
97
+ */
98
+ const DataGridRowTypes = {
99
+ default: "default",
100
+ header: "header",
101
+ stickyHeader: "sticky-header",
102
+ };
103
+
104
+ /**
105
+ * A Data Grid Row Custom HTML Element.
106
+ *
107
+ * @fires row-focused - Fires a custom 'row-focused' event when focus is on an element (usually a cell or its contents) in the row
108
+ * @slot - The default slot for custom cell elements
109
+ * @public
110
+ */
111
+ class DataGridRow$1 extends FoundationElement {
112
+ constructor() {
113
+ super(...arguments);
114
+ /**
115
+ * The type of row
116
+ *
117
+ * @public
118
+ * @remarks
119
+ * HTML Attribute: row-type
120
+ */
121
+ this.rowType = DataGridRowTypes.default;
122
+ /**
123
+ * The base data for this row
124
+ *
125
+ * @public
126
+ */
127
+ this.rowData = null;
128
+ /**
129
+ * The column definitions of the row
130
+ *
131
+ * @public
132
+ */
133
+ this.columnDefinitions = null;
134
+ /**
135
+ * Whether focus is on/in a cell within this row.
136
+ *
137
+ * @internal
138
+ */
139
+ this.isActiveRow = false;
140
+ this.cellsRepeatBehavior = null;
141
+ this.cellsPlaceholder = null;
142
+ /**
143
+ * @internal
144
+ */
145
+ this.focusColumnIndex = 0;
146
+ this.refocusOnLoad = false;
147
+ this.updateRowStyle = () => {
148
+ this.style.gridTemplateColumns = this.gridTemplateColumns;
149
+ };
150
+ }
151
+ gridTemplateColumnsChanged() {
152
+ if (this.$fastController.isConnected) {
153
+ this.updateRowStyle();
154
+ }
155
+ }
156
+ rowTypeChanged() {
157
+ if (this.$fastController.isConnected) {
158
+ this.updateItemTemplate();
159
+ }
160
+ }
161
+ rowDataChanged() {
162
+ if (this.rowData !== null && this.isActiveRow) {
163
+ this.refocusOnLoad = true;
164
+ return;
165
+ }
166
+ }
167
+ cellItemTemplateChanged() {
168
+ this.updateItemTemplate();
169
+ }
170
+ headerCellItemTemplateChanged() {
171
+ this.updateItemTemplate();
172
+ }
173
+ /**
174
+ * @internal
175
+ */
176
+ connectedCallback() {
177
+ super.connectedCallback();
178
+ // note that row elements can be reused with a different data object
179
+ // as the parent grid's repeat behavior reacts to changes in the data set.
180
+ if (this.cellsRepeatBehavior === null) {
181
+ this.cellsPlaceholder = document.createComment("");
182
+ this.appendChild(this.cellsPlaceholder);
183
+ this.updateItemTemplate();
184
+ this.cellsRepeatBehavior = new RepeatDirective(x => x.columnDefinitions, x => x.activeCellItemTemplate, { positioning: true }).createBehavior(this.cellsPlaceholder);
185
+ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
186
+ this.$fastController.addBehaviors([this.cellsRepeatBehavior]);
187
+ }
188
+ this.addEventListener("cell-focused", this.handleCellFocus);
189
+ this.addEventListener(eventFocusOut, this.handleFocusout);
190
+ this.addEventListener(eventKeyDown, this.handleKeydown);
191
+ this.updateRowStyle();
192
+ if (this.refocusOnLoad) {
193
+ // if focus was on the row when data changed try to refocus on same cell
194
+ this.refocusOnLoad = false;
195
+ if (this.cellElements.length > this.focusColumnIndex) {
196
+ this.cellElements[this.focusColumnIndex].focus();
197
+ }
198
+ }
199
+ }
200
+ /**
201
+ * @internal
202
+ */
203
+ disconnectedCallback() {
204
+ super.disconnectedCallback();
205
+ this.removeEventListener("cell-focused", this.handleCellFocus);
206
+ this.removeEventListener(eventFocusOut, this.handleFocusout);
207
+ this.removeEventListener(eventKeyDown, this.handleKeydown);
208
+ }
209
+ handleFocusout(e) {
210
+ if (!this.contains(e.target)) {
211
+ this.isActiveRow = false;
212
+ this.focusColumnIndex = 0;
213
+ }
214
+ }
215
+ handleCellFocus(e) {
216
+ this.isActiveRow = true;
217
+ this.focusColumnIndex = this.cellElements.indexOf(e.target);
218
+ this.$emit("row-focused", this);
219
+ }
220
+ handleKeydown(e) {
221
+ if (e.defaultPrevented) {
222
+ return;
223
+ }
224
+ let newFocusColumnIndex = 0;
225
+ switch (e.key) {
226
+ case keyArrowLeft:
227
+ // focus left one cell
228
+ newFocusColumnIndex = Math.max(0, this.focusColumnIndex - 1);
229
+ this.cellElements[newFocusColumnIndex].focus();
230
+ e.preventDefault();
231
+ break;
232
+ case keyArrowRight:
233
+ // focus right one cell
234
+ newFocusColumnIndex = Math.min(this.cellElements.length - 1, this.focusColumnIndex + 1);
235
+ this.cellElements[newFocusColumnIndex].focus();
236
+ e.preventDefault();
237
+ break;
238
+ case keyHome:
239
+ if (!e.ctrlKey) {
240
+ this.cellElements[0].focus();
241
+ e.preventDefault();
242
+ }
243
+ break;
244
+ case keyEnd:
245
+ if (!e.ctrlKey) {
246
+ // focus last cell of the row
247
+ this.cellElements[this.cellElements.length - 1].focus();
248
+ e.preventDefault();
249
+ }
250
+ break;
251
+ }
252
+ }
253
+ updateItemTemplate() {
254
+ this.activeCellItemTemplate =
255
+ this.rowType === DataGridRowTypes.default &&
256
+ this.cellItemTemplate !== undefined
257
+ ? this.cellItemTemplate
258
+ : this.rowType === DataGridRowTypes.default &&
259
+ this.cellItemTemplate === undefined
260
+ ? this.defaultCellItemTemplate
261
+ : this.headerCellItemTemplate !== undefined
262
+ ? this.headerCellItemTemplate
263
+ : this.defaultHeaderCellItemTemplate;
264
+ }
265
+ }
266
+ __decorate([
267
+ attr({ attribute: "grid-template-columns" })
268
+ ], DataGridRow$1.prototype, "gridTemplateColumns", void 0);
269
+ __decorate([
270
+ attr({ attribute: "row-type" })
271
+ ], DataGridRow$1.prototype, "rowType", void 0);
272
+ __decorate([
273
+ observable
274
+ ], DataGridRow$1.prototype, "rowData", void 0);
275
+ __decorate([
276
+ observable
277
+ ], DataGridRow$1.prototype, "columnDefinitions", void 0);
278
+ __decorate([
279
+ observable
280
+ ], DataGridRow$1.prototype, "cellItemTemplate", void 0);
281
+ __decorate([
282
+ observable
283
+ ], DataGridRow$1.prototype, "headerCellItemTemplate", void 0);
284
+ __decorate([
285
+ observable
286
+ ], DataGridRow$1.prototype, "rowIndex", void 0);
287
+ __decorate([
288
+ observable
289
+ ], DataGridRow$1.prototype, "isActiveRow", void 0);
290
+ __decorate([
291
+ observable
292
+ ], DataGridRow$1.prototype, "activeCellItemTemplate", void 0);
293
+ __decorate([
294
+ observable
295
+ ], DataGridRow$1.prototype, "defaultCellItemTemplate", void 0);
296
+ __decorate([
297
+ observable
298
+ ], DataGridRow$1.prototype, "defaultHeaderCellItemTemplate", void 0);
299
+ __decorate([
300
+ observable
301
+ ], DataGridRow$1.prototype, "cellElements", void 0);
302
+
303
+ /**
304
+ * A Data Grid Custom HTML Element.
305
+ *
306
+ * @slot - The default slot for custom row elements
307
+ * @public
308
+ */
309
+ class DataGrid$1 extends FoundationElement {
310
+ constructor() {
311
+ super();
312
+ /**
313
+ * When true the component will not add itself to the tab queue.
314
+ * Default is false.
315
+ *
316
+ * @public
317
+ * @remarks
318
+ * HTML Attribute: no-tabbing
319
+ */
320
+ this.noTabbing = false;
321
+ /**
322
+ * Whether the grid should automatically generate a header row and its type
323
+ *
324
+ * @public
325
+ * @remarks
326
+ * HTML Attribute: generate-header
327
+ */
328
+ this.generateHeader = GenerateHeaderOptions.default;
329
+ /**
330
+ * The data being displayed in the grid
331
+ *
332
+ * @public
333
+ */
334
+ this.rowsData = [];
335
+ /**
336
+ * The column definitions of the grid
337
+ *
338
+ * @public
339
+ */
340
+ this.columnDefinitions = null;
341
+ /**
342
+ * The index of the row that will receive focus the next time the
343
+ * grid is focused. This value changes as focus moves to different
344
+ * rows within the grid. Changing this value when focus is already
345
+ * within the grid moves focus to the specified row.
346
+ *
347
+ * @public
348
+ */
349
+ this.focusRowIndex = 0;
350
+ /**
351
+ * The index of the column that will receive focus the next time the
352
+ * grid is focused. This value changes as focus moves to different rows
353
+ * within the grid. Changing this value when focus is already within
354
+ * the grid moves focus to the specified column.
355
+ *
356
+ * @public
357
+ */
358
+ this.focusColumnIndex = 0;
359
+ this.rowsPlaceholder = null;
360
+ this.generatedHeader = null;
361
+ this.isUpdatingFocus = false;
362
+ this.pendingFocusUpdate = false;
363
+ this.rowindexUpdateQueued = false;
364
+ this.columnDefinitionsStale = true;
365
+ this.generatedGridTemplateColumns = "";
366
+ this.focusOnCell = (rowIndex, columnIndex, scrollIntoView) => {
367
+ if (this.rowElements.length === 0) {
368
+ this.focusRowIndex = 0;
369
+ this.focusColumnIndex = 0;
370
+ return;
371
+ }
372
+ const focusRowIndex = Math.max(0, Math.min(this.rowElements.length - 1, rowIndex));
373
+ const focusRow = this.rowElements[focusRowIndex];
374
+ const cells = focusRow.querySelectorAll('[role="cell"], [role="gridcell"], [role="columnheader"], [role="rowheader"]');
375
+ const focusColumnIndex = Math.max(0, Math.min(cells.length - 1, columnIndex));
376
+ const focusTarget = cells[focusColumnIndex];
377
+ if (scrollIntoView &&
378
+ this.scrollHeight !== this.clientHeight &&
379
+ ((focusRowIndex < this.focusRowIndex && this.scrollTop > 0) ||
380
+ (focusRowIndex > this.focusRowIndex &&
381
+ this.scrollTop < this.scrollHeight - this.clientHeight))) {
382
+ focusTarget.scrollIntoView({ block: "center", inline: "center" });
383
+ }
384
+ focusTarget.focus();
385
+ };
386
+ this.onChildListChange = (mutations,
387
+ /* eslint-disable-next-line @typescript-eslint/no-unused-vars */
388
+ observer) => {
389
+ if (mutations && mutations.length) {
390
+ mutations.forEach((mutation) => {
391
+ mutation.addedNodes.forEach((newNode) => {
392
+ if (newNode.nodeType === 1 &&
393
+ newNode.getAttribute("role") === "row") {
394
+ newNode.columnDefinitions = this.columnDefinitions;
395
+ }
396
+ });
397
+ });
398
+ this.queueRowIndexUpdate();
399
+ }
400
+ };
401
+ this.queueRowIndexUpdate = () => {
402
+ if (!this.rowindexUpdateQueued) {
403
+ this.rowindexUpdateQueued = true;
404
+ DOM.queueUpdate(this.updateRowIndexes);
405
+ }
406
+ };
407
+ this.updateRowIndexes = () => {
408
+ let newGridTemplateColumns = this.gridTemplateColumns;
409
+ if (newGridTemplateColumns === undefined) {
410
+ // try to generate columns based on manual rows
411
+ if (this.generatedGridTemplateColumns === "" && this.rowElements.length > 0) {
412
+ const firstRow = this.rowElements[0];
413
+ this.generatedGridTemplateColumns = new Array(firstRow.cellElements.length)
414
+ .fill("1fr")
415
+ .join(" ");
416
+ }
417
+ newGridTemplateColumns = this.generatedGridTemplateColumns;
418
+ }
419
+ this.rowElements.forEach((element, index) => {
420
+ const thisRow = element;
421
+ thisRow.rowIndex = index;
422
+ thisRow.gridTemplateColumns = newGridTemplateColumns;
423
+ if (this.columnDefinitionsStale) {
424
+ thisRow.columnDefinitions = this.columnDefinitions;
425
+ }
426
+ });
427
+ this.rowindexUpdateQueued = false;
428
+ this.columnDefinitionsStale = false;
429
+ };
430
+ }
431
+ /**
432
+ * generates a gridTemplateColumns based on columndata array
433
+ */
434
+ static generateTemplateColumns(columnDefinitions) {
435
+ let templateColumns = "";
436
+ columnDefinitions.forEach((column) => {
437
+ templateColumns = `${templateColumns}${templateColumns === "" ? "" : " "}${"1fr"}`;
438
+ });
439
+ return templateColumns;
440
+ }
441
+ noTabbingChanged() {
442
+ if (this.$fastController.isConnected) {
443
+ if (this.noTabbing) {
444
+ this.setAttribute("tabIndex", "-1");
445
+ }
446
+ else {
447
+ this.setAttribute("tabIndex", this.contains(document.activeElement) ||
448
+ this === document.activeElement
449
+ ? "-1"
450
+ : "0");
451
+ }
452
+ }
453
+ }
454
+ generateHeaderChanged() {
455
+ if (this.$fastController.isConnected) {
456
+ this.toggleGeneratedHeader();
457
+ }
458
+ }
459
+ gridTemplateColumnsChanged() {
460
+ if (this.$fastController.isConnected) {
461
+ this.updateRowIndexes();
462
+ }
463
+ }
464
+ rowsDataChanged() {
465
+ if (this.columnDefinitions === null && this.rowsData.length > 0) {
466
+ this.columnDefinitions = DataGrid$1.generateColumns(this.rowsData[0]);
467
+ }
468
+ if (this.$fastController.isConnected) {
469
+ this.toggleGeneratedHeader();
470
+ }
471
+ }
472
+ columnDefinitionsChanged() {
473
+ if (this.columnDefinitions === null) {
474
+ this.generatedGridTemplateColumns = "";
475
+ return;
476
+ }
477
+ this.generatedGridTemplateColumns = DataGrid$1.generateTemplateColumns(this.columnDefinitions);
478
+ if (this.$fastController.isConnected) {
479
+ this.columnDefinitionsStale = true;
480
+ this.queueRowIndexUpdate();
481
+ }
482
+ }
483
+ headerCellItemTemplateChanged() {
484
+ if (this.$fastController.isConnected) {
485
+ if (this.generatedHeader !== null) {
486
+ this.generatedHeader.headerCellItemTemplate = this.headerCellItemTemplate;
487
+ }
488
+ }
489
+ }
490
+ focusRowIndexChanged() {
491
+ if (this.$fastController.isConnected) {
492
+ this.queueFocusUpdate();
493
+ }
494
+ }
495
+ focusColumnIndexChanged() {
496
+ if (this.$fastController.isConnected) {
497
+ this.queueFocusUpdate();
498
+ }
499
+ }
500
+ /**
501
+ * @internal
502
+ */
503
+ connectedCallback() {
504
+ super.connectedCallback();
505
+ if (this.rowItemTemplate === undefined) {
506
+ this.rowItemTemplate = this.defaultRowItemTemplate;
507
+ }
508
+ this.rowsPlaceholder = document.createComment("");
509
+ this.appendChild(this.rowsPlaceholder);
510
+ this.toggleGeneratedHeader();
511
+ this.rowsRepeatBehavior = new RepeatDirective(x => x.rowsData, x => x.rowItemTemplate, { positioning: true }).createBehavior(this.rowsPlaceholder);
512
+ /* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
513
+ this.$fastController.addBehaviors([this.rowsRepeatBehavior]);
514
+ this.addEventListener("row-focused", this.handleRowFocus);
515
+ this.addEventListener(eventFocus, this.handleFocus);
516
+ this.addEventListener(eventKeyDown, this.handleKeydown);
517
+ this.addEventListener(eventFocusOut, this.handleFocusOut);
518
+ this.observer = new MutationObserver(this.onChildListChange);
519
+ // only observe if nodes are added or removed
520
+ this.observer.observe(this, { childList: true });
521
+ if (this.noTabbing) {
522
+ this.setAttribute("tabindex", "-1");
523
+ }
524
+ DOM.queueUpdate(this.queueRowIndexUpdate);
525
+ }
526
+ /**
527
+ * @internal
528
+ */
529
+ disconnectedCallback() {
530
+ super.disconnectedCallback();
531
+ this.removeEventListener("row-focused", this.handleRowFocus);
532
+ this.removeEventListener(eventFocus, this.handleFocus);
533
+ this.removeEventListener(eventKeyDown, this.handleKeydown);
534
+ this.removeEventListener(eventFocusOut, this.handleFocusOut);
535
+ // disconnect observer
536
+ this.observer.disconnect();
537
+ this.rowsPlaceholder = null;
538
+ this.generatedHeader = null;
539
+ }
540
+ /**
541
+ * @internal
542
+ */
543
+ handleRowFocus(e) {
544
+ this.isUpdatingFocus = true;
545
+ const focusRow = e.target;
546
+ this.focusRowIndex = this.rowElements.indexOf(focusRow);
547
+ this.focusColumnIndex = focusRow.focusColumnIndex;
548
+ this.setAttribute("tabIndex", "-1");
549
+ this.isUpdatingFocus = false;
550
+ }
551
+ /**
552
+ * @internal
553
+ */
554
+ handleFocus(e) {
555
+ this.focusOnCell(this.focusRowIndex, this.focusColumnIndex, true);
556
+ }
557
+ /**
558
+ * @internal
559
+ */
560
+ handleFocusOut(e) {
561
+ if (e.relatedTarget === null || !this.contains(e.relatedTarget)) {
562
+ this.setAttribute("tabIndex", this.noTabbing ? "-1" : "0");
563
+ }
564
+ }
565
+ /**
566
+ * @internal
567
+ */
568
+ handleKeydown(e) {
569
+ if (e.defaultPrevented) {
570
+ return;
571
+ }
572
+ let newFocusRowIndex;
573
+ const maxIndex = this.rowElements.length - 1;
574
+ const currentGridBottom = this.offsetHeight + this.scrollTop;
575
+ const lastRow = this.rowElements[maxIndex];
576
+ switch (e.key) {
577
+ case keyArrowUp:
578
+ e.preventDefault();
579
+ // focus up one row
580
+ this.focusOnCell(this.focusRowIndex - 1, this.focusColumnIndex, true);
581
+ break;
582
+ case keyArrowDown:
583
+ e.preventDefault();
584
+ // focus down one row
585
+ this.focusOnCell(this.focusRowIndex + 1, this.focusColumnIndex, true);
586
+ break;
587
+ case keyPageUp:
588
+ e.preventDefault();
589
+ if (this.rowElements.length === 0) {
590
+ this.focusOnCell(0, 0, false);
591
+ break;
592
+ }
593
+ if (this.focusRowIndex === 0) {
594
+ this.focusOnCell(0, this.focusColumnIndex, false);
595
+ return;
596
+ }
597
+ newFocusRowIndex = this.focusRowIndex - 1;
598
+ for (newFocusRowIndex; newFocusRowIndex >= 0; newFocusRowIndex--) {
599
+ const thisRow = this.rowElements[newFocusRowIndex];
600
+ if (thisRow.offsetTop < this.scrollTop) {
601
+ this.scrollTop =
602
+ thisRow.offsetTop + thisRow.clientHeight - this.clientHeight;
603
+ break;
604
+ }
605
+ }
606
+ this.focusOnCell(newFocusRowIndex, this.focusColumnIndex, false);
607
+ break;
608
+ case keyPageDown:
609
+ e.preventDefault();
610
+ if (this.rowElements.length === 0) {
611
+ this.focusOnCell(0, 0, false);
612
+ break;
613
+ }
614
+ // focus down one "page"
615
+ if (this.focusRowIndex >= maxIndex ||
616
+ lastRow.offsetTop + lastRow.offsetHeight <= currentGridBottom) {
617
+ this.focusOnCell(maxIndex, this.focusColumnIndex, false);
618
+ return;
619
+ }
620
+ newFocusRowIndex = this.focusRowIndex + 1;
621
+ for (newFocusRowIndex; newFocusRowIndex <= maxIndex; newFocusRowIndex++) {
622
+ const thisRow = this.rowElements[newFocusRowIndex];
623
+ if (thisRow.offsetTop + thisRow.offsetHeight > currentGridBottom) {
624
+ let stickyHeaderOffset = 0;
625
+ if (this.generateHeader === GenerateHeaderOptions.sticky &&
626
+ this.generatedHeader !== null) {
627
+ stickyHeaderOffset = this.generatedHeader.clientHeight;
628
+ }
629
+ this.scrollTop = thisRow.offsetTop - stickyHeaderOffset;
630
+ break;
631
+ }
632
+ }
633
+ this.focusOnCell(newFocusRowIndex, this.focusColumnIndex, false);
634
+ break;
635
+ case keyHome:
636
+ if (e.ctrlKey) {
637
+ e.preventDefault();
638
+ // focus first cell of first row
639
+ this.focusOnCell(0, 0, true);
640
+ }
641
+ break;
642
+ case keyEnd:
643
+ if (e.ctrlKey && this.columnDefinitions !== null) {
644
+ e.preventDefault();
645
+ // focus last cell of last row
646
+ this.focusOnCell(this.rowElements.length - 1, this.columnDefinitions.length - 1, true);
647
+ }
648
+ break;
649
+ }
650
+ }
651
+ queueFocusUpdate() {
652
+ if (this.isUpdatingFocus &&
653
+ (this.contains(document.activeElement) || this === document.activeElement)) {
654
+ return;
655
+ }
656
+ if (this.pendingFocusUpdate === false) {
657
+ this.pendingFocusUpdate = true;
658
+ DOM.queueUpdate(() => this.updateFocus());
659
+ }
660
+ }
661
+ updateFocus() {
662
+ this.pendingFocusUpdate = false;
663
+ this.focusOnCell(this.focusRowIndex, this.focusColumnIndex, true);
664
+ }
665
+ toggleGeneratedHeader() {
666
+ if (this.generatedHeader !== null) {
667
+ this.removeChild(this.generatedHeader);
668
+ this.generatedHeader = null;
669
+ }
670
+ if (this.generateHeader !== GenerateHeaderOptions.none &&
671
+ this.rowsData.length > 0) {
672
+ const generatedHeaderElement = document.createElement(this.rowElementTag);
673
+ this.generatedHeader = generatedHeaderElement;
674
+ this.generatedHeader.columnDefinitions = this.columnDefinitions;
675
+ this.generatedHeader.gridTemplateColumns = this.gridTemplateColumns;
676
+ this.generatedHeader.rowType =
677
+ this.generateHeader === GenerateHeaderOptions.sticky
678
+ ? DataGridRowTypes.stickyHeader
679
+ : DataGridRowTypes.header;
680
+ if (this.firstChild !== null || this.rowsPlaceholder !== null) {
681
+ this.insertBefore(generatedHeaderElement, this.firstChild !== null ? this.firstChild : this.rowsPlaceholder);
682
+ }
683
+ return;
684
+ }
685
+ }
686
+ }
687
+ /**
688
+ * generates a basic column definition by examining sample row data
689
+ */
690
+ DataGrid$1.generateColumns = (row) => {
691
+ return Object.getOwnPropertyNames(row).map((property, index) => {
692
+ return {
693
+ columnDataKey: property,
694
+ gridColumn: `${index}`,
695
+ };
696
+ });
697
+ };
698
+ __decorate([
699
+ attr({ attribute: "no-tabbing", mode: "boolean" })
700
+ ], DataGrid$1.prototype, "noTabbing", void 0);
701
+ __decorate([
702
+ attr({ attribute: "generate-header" })
703
+ ], DataGrid$1.prototype, "generateHeader", void 0);
704
+ __decorate([
705
+ attr({ attribute: "grid-template-columns" })
706
+ ], DataGrid$1.prototype, "gridTemplateColumns", void 0);
707
+ __decorate([
708
+ observable
709
+ ], DataGrid$1.prototype, "rowsData", void 0);
710
+ __decorate([
711
+ observable
712
+ ], DataGrid$1.prototype, "columnDefinitions", void 0);
713
+ __decorate([
714
+ observable
715
+ ], DataGrid$1.prototype, "rowItemTemplate", void 0);
716
+ __decorate([
717
+ observable
718
+ ], DataGrid$1.prototype, "cellItemTemplate", void 0);
719
+ __decorate([
720
+ observable
721
+ ], DataGrid$1.prototype, "headerCellItemTemplate", void 0);
722
+ __decorate([
723
+ observable
724
+ ], DataGrid$1.prototype, "focusRowIndex", void 0);
725
+ __decorate([
726
+ observable
727
+ ], DataGrid$1.prototype, "focusColumnIndex", void 0);
728
+ __decorate([
729
+ observable
730
+ ], DataGrid$1.prototype, "defaultRowItemTemplate", void 0);
731
+ __decorate([
732
+ observable
733
+ ], DataGrid$1.prototype, "rowElementTag", void 0);
734
+ __decorate([
735
+ observable
736
+ ], DataGrid$1.prototype, "rowElements", void 0);
737
+
738
+ const defaultCellContentsTemplate = html `
739
+ <template>
740
+ ${x => x.rowData === null ||
741
+ x.columnDefinition === null ||
742
+ x.columnDefinition.columnDataKey === null
743
+ ? null
744
+ : x.rowData[x.columnDefinition.columnDataKey]}
745
+ </template>
746
+ `;
747
+ const defaultHeaderCellContentsTemplate = html `
748
+ <template>
749
+ ${x => x.columnDefinition === null
750
+ ? null
751
+ : x.columnDefinition.title === undefined
752
+ ? x.columnDefinition.columnDataKey
753
+ : x.columnDefinition.title}
754
+ </template>
755
+ `;
756
+ /**
757
+ * A Data Grid Cell Custom HTML Element.
758
+ *
759
+ * @fires cell-focused - Fires a custom 'cell-focused' event when focus is on the cell or its contents
760
+ * @slot - The default slot for cell contents. The "cell contents template" renders here.
761
+ * @public
762
+ */
763
+ class DataGridCell$1 extends FoundationElement {
764
+ constructor() {
765
+ super(...arguments);
766
+ /**
767
+ * The type of cell
768
+ *
769
+ * @public
770
+ * @remarks
771
+ * HTML Attribute: cell-type
772
+ */
773
+ this.cellType = DataGridCellTypes.default;
774
+ /**
775
+ * The base data for the parent row
776
+ *
777
+ * @public
778
+ */
779
+ this.rowData = null;
780
+ /**
781
+ * The base data for the column
782
+ *
783
+ * @public
784
+ */
785
+ this.columnDefinition = null;
786
+ this.isActiveCell = false;
787
+ this.customCellView = null;
788
+ this.updateCellStyle = () => {
789
+ this.style.gridColumn = this.gridColumn;
790
+ };
791
+ }
792
+ cellTypeChanged() {
793
+ if (this.$fastController.isConnected) {
794
+ this.updateCellView();
795
+ }
796
+ }
797
+ gridColumnChanged() {
798
+ if (this.$fastController.isConnected) {
799
+ this.updateCellStyle();
800
+ }
801
+ }
802
+ columnDefinitionChanged(oldValue, newValue) {
803
+ if (this.$fastController.isConnected) {
804
+ this.updateCellView();
805
+ }
806
+ }
807
+ /**
808
+ * @internal
809
+ */
810
+ connectedCallback() {
811
+ var _a;
812
+ super.connectedCallback();
813
+ this.addEventListener(eventFocusIn, this.handleFocusin);
814
+ this.addEventListener(eventFocusOut, this.handleFocusout);
815
+ this.addEventListener(eventKeyDown, this.handleKeydown);
816
+ this.style.gridColumn = `${((_a = this.columnDefinition) === null || _a === void 0 ? void 0 : _a.gridColumn) === undefined
817
+ ? 0
818
+ : this.columnDefinition.gridColumn}`;
819
+ this.updateCellView();
820
+ this.updateCellStyle();
821
+ }
822
+ /**
823
+ * @internal
824
+ */
825
+ disconnectedCallback() {
826
+ super.disconnectedCallback();
827
+ this.removeEventListener(eventFocusIn, this.handleFocusin);
828
+ this.removeEventListener(eventFocusOut, this.handleFocusout);
829
+ this.removeEventListener(eventKeyDown, this.handleKeydown);
830
+ this.disconnectCellView();
831
+ }
832
+ handleFocusin(e) {
833
+ if (this.isActiveCell) {
834
+ return;
835
+ }
836
+ this.isActiveCell = true;
837
+ switch (this.cellType) {
838
+ case DataGridCellTypes.columnHeader:
839
+ if (this.columnDefinition !== null &&
840
+ this.columnDefinition.headerCellInternalFocusQueue !== true &&
841
+ typeof this.columnDefinition.headerCellFocusTargetCallback ===
842
+ "function") {
843
+ // move focus to the focus target
844
+ const focusTarget = this.columnDefinition.headerCellFocusTargetCallback(this);
845
+ if (focusTarget !== null) {
846
+ focusTarget.focus();
847
+ }
848
+ }
849
+ break;
850
+ default:
851
+ if (this.columnDefinition !== null &&
852
+ this.columnDefinition.cellInternalFocusQueue !== true &&
853
+ typeof this.columnDefinition.cellFocusTargetCallback === "function") {
854
+ // move focus to the focus target
855
+ const focusTarget = this.columnDefinition.cellFocusTargetCallback(this);
856
+ if (focusTarget !== null) {
857
+ focusTarget.focus();
858
+ }
859
+ }
860
+ break;
861
+ }
862
+ this.$emit("cell-focused", this);
863
+ }
864
+ handleFocusout(e) {
865
+ if (this !== document.activeElement && !this.contains(document.activeElement)) {
866
+ this.isActiveCell = false;
867
+ }
868
+ }
869
+ handleKeydown(e) {
870
+ if (e.defaultPrevented ||
871
+ this.columnDefinition === null ||
872
+ (this.cellType === DataGridCellTypes.default &&
873
+ this.columnDefinition.cellInternalFocusQueue !== true) ||
874
+ (this.cellType === DataGridCellTypes.columnHeader &&
875
+ this.columnDefinition.headerCellInternalFocusQueue !== true)) {
876
+ return;
877
+ }
878
+ switch (e.key) {
879
+ case keyEnter:
880
+ case keyFunction2:
881
+ if (this.contains(document.activeElement) &&
882
+ document.activeElement !== this) {
883
+ return;
884
+ }
885
+ switch (this.cellType) {
886
+ case DataGridCellTypes.columnHeader:
887
+ if (this.columnDefinition.headerCellFocusTargetCallback !==
888
+ undefined) {
889
+ const focusTarget = this.columnDefinition.headerCellFocusTargetCallback(this);
890
+ if (focusTarget !== null) {
891
+ focusTarget.focus();
892
+ }
893
+ e.preventDefault();
894
+ }
895
+ break;
896
+ default:
897
+ if (this.columnDefinition.cellFocusTargetCallback !== undefined) {
898
+ const focusTarget = this.columnDefinition.cellFocusTargetCallback(this);
899
+ if (focusTarget !== null) {
900
+ focusTarget.focus();
901
+ }
902
+ e.preventDefault();
903
+ }
904
+ break;
905
+ }
906
+ break;
907
+ case keyEscape:
908
+ if (this.contains(document.activeElement) &&
909
+ document.activeElement !== this) {
910
+ this.focus();
911
+ e.preventDefault();
912
+ }
913
+ break;
914
+ }
915
+ }
916
+ updateCellView() {
917
+ this.disconnectCellView();
918
+ if (this.columnDefinition === null) {
919
+ return;
920
+ }
921
+ switch (this.cellType) {
922
+ case DataGridCellTypes.columnHeader:
923
+ if (this.columnDefinition.headerCellTemplate !== undefined) {
924
+ this.customCellView = this.columnDefinition.headerCellTemplate.render(this, this);
925
+ }
926
+ else {
927
+ this.customCellView = defaultHeaderCellContentsTemplate.render(this, this);
928
+ }
929
+ break;
930
+ case undefined:
931
+ case DataGridCellTypes.rowHeader:
932
+ case DataGridCellTypes.default:
933
+ if (this.columnDefinition.cellTemplate !== undefined) {
934
+ this.customCellView = this.columnDefinition.cellTemplate.render(this, this);
935
+ }
936
+ else {
937
+ this.customCellView = defaultCellContentsTemplate.render(this, this);
938
+ }
939
+ break;
940
+ }
941
+ }
942
+ disconnectCellView() {
943
+ if (this.customCellView !== null) {
944
+ this.customCellView.dispose();
945
+ this.customCellView = null;
946
+ }
947
+ }
948
+ }
949
+ __decorate([
950
+ attr({ attribute: "cell-type" })
951
+ ], DataGridCell$1.prototype, "cellType", void 0);
952
+ __decorate([
953
+ attr({ attribute: "grid-column" })
954
+ ], DataGridCell$1.prototype, "gridColumn", void 0);
955
+ __decorate([
956
+ observable
957
+ ], DataGridCell$1.prototype, "rowData", void 0);
958
+ __decorate([
959
+ observable
960
+ ], DataGridCell$1.prototype, "columnDefinition", void 0);
961
+
962
+ var css_248z$2 = ":host {\n position: relative;\n display: block;\n}\n\n:host([generate-header=sticky]) {\n max-height: var(--data-grid-max-height, 200px);\n overflow-y: auto;\n}";
963
+
964
+ var css_248z$1 = "/**\n * Do not edit directly\n * Generated on Sun, 12 Feb 2023 10:53:43 GMT\n */\n:host {\n display: grid;\n width: 100%;\n box-sizing: border-box;\n color: var(--vvd-color-canvas-text);\n}\n\n:host([row-type=sticky-header]) {\n position: sticky;\n z-index: 999;\n top: 0;\n background: var(--vvd-color-canvas);\n}";
965
+
966
+ var css_248z = "/**\n * Do not edit directly\n * Generated on Sun, 12 Feb 2023 10:53:43 GMT\n */\n:host {\n position: relative;\n display: flex;\n overflow: hidden;\n box-sizing: border-box;\n align-items: center;\n padding: 8px 12px;\n border-bottom: 1px solid var(--vvd-color-neutral-100);\n block-size: calc(1px * (40 + 4 * clamp(-1, var(--vvd-size-density, 0), 2) + 8));\n color: var(--vvd-color-canvas-text);\n font: var(--vvd-typography-base);\n outline: none;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n:host([cell-type=columnheader]) {\n border-color: currentColor;\n font: var(--vvd-typography-base-bold);\n}\n\n.focus-indicator {\n --focus-stroke-gap-color: transparent;\n pointer-events: none;\n}\n#focus-wrapper:not(.active) > .focus-indicator {\n display: none;\n}";
967
+
968
+ class DataGrid extends DataGrid$1 {}
969
+
970
+ class DataGridRow extends DataGridRow$1 {}
971
+
972
+ let _2$1 = t => t,
973
+ _t$2,
974
+ _t2$1;
975
+ function createRowItemTemplate(context) {
976
+ const rowTag = context.tagFor(DataGridRow);
977
+ return html(_t$2 || (_t$2 = _2$1`
978
+ <${0}
979
+ :rowData="${0}"
980
+ :cellItemTemplate="${0}"
981
+ :headerCellItemTemplate="${0}"
982
+ ></${0}>
983
+ `), rowTag, x => x, (_, c) => c.parent.cellItemTemplate, (_, c) => c.parent.headerCellItemTemplate, rowTag);
984
+ }
985
+ const DataGridTemplate = context => {
986
+ const rowItemTemplate = createRowItemTemplate(context);
987
+ const rowTag = context.tagFor(DataGridRow);
988
+ return html(_t2$1 || (_t2$1 = _2$1`
989
+ <template
990
+ role="grid"
991
+ tabindex="0"
992
+ :rowElementTag="${0}"
993
+ :defaultRowItemTemplate="${0}"
994
+ ${0}
995
+ >
996
+ <slot></slot>
997
+ </template>
998
+ `), () => rowTag, rowItemTemplate, children({
999
+ property: 'rowElements',
1000
+ filter: elements('[role=row]')
1001
+ }));
1002
+ };
1003
+
1004
+ class DataGridCell extends DataGridCell$1 {
1005
+ handleFocusin(e) {
1006
+ super.handleFocusin(e);
1007
+ this.shadowRoot.getElementById('focus-wrapper').classList.add('active');
1008
+ }
1009
+ handleFocusout(e) {
1010
+ super.handleFocusout(e);
1011
+ this.shadowRoot.getElementById('focus-wrapper').classList.remove('active');
1012
+ }
1013
+ }
1014
+
1015
+ let _2 = t => t,
1016
+ _t$1,
1017
+ _t2,
1018
+ _t3;
1019
+ function createCellItemTemplate(context) {
1020
+ const cellTag = context.tagFor(DataGridCell);
1021
+ return html(_t$1 || (_t$1 = _2`
1022
+ <${0}
1023
+ cell-type="${0}"
1024
+ grid-column="${0}"
1025
+ :rowData="${0}"
1026
+ :columnDefinition="${0}"
1027
+ ></${0}>
1028
+ `), cellTag, x => x.isRowHeader ? 'rowheader' : undefined, (_, c) => c.index + 1, (_, c) => c.parent.rowData, x => x, cellTag);
1029
+ }
1030
+ function createHeaderCellItemTemplate(context) {
1031
+ const cellTag = context.tagFor(DataGridCell);
1032
+ return html(_t2 || (_t2 = _2`
1033
+ <${0}
1034
+ cell-type="columnheader"
1035
+ grid-column="${0}"
1036
+ :columnDefinition="${0}"
1037
+ ></${0}>
1038
+ `), cellTag, (_, c) => c.index + 1, x => x, cellTag);
1039
+ }
1040
+ const DataGridRowTemplate = context => {
1041
+ const cellItemTemplate = createCellItemTemplate(context);
1042
+ const headerCellItemTemplate = createHeaderCellItemTemplate(context);
1043
+ return html(_t3 || (_t3 = _2`
1044
+ <template
1045
+ role="row"
1046
+ class="${0}"
1047
+ :defaultCellItemTemplate="${0}"
1048
+ :defaultHeaderCellItemTemplate="${0}"
1049
+ ${0}
1050
+ >
1051
+ <slot ${0}></slot>
1052
+ </template>
1053
+ `), x => x.rowType !== 'default' ? x.rowType : '', cellItemTemplate, headerCellItemTemplate, children({
1054
+ property: 'cellElements',
1055
+ filter: elements('[role="cell"],[role="gridcell"],[role="columnheader"],[role="rowheader"]')
1056
+ }), slotted('slottedCellElements'));
1057
+ };
1058
+
1059
+ const DataGridCellRole = {
1060
+ columnheader: 'columnheader',
1061
+ rowheader: 'rowheader',
1062
+ default: 'gridcell'
1063
+ };
1064
+
1065
+ let _ = t => t,
1066
+ _t;
1067
+ function DataGridCellTemplate(context) {
1068
+ const focusTemplate = focusTemplateFactory(context);
1069
+ return html(_t || (_t = _`
1070
+ <template
1071
+ tabindex="-1"
1072
+ role="${0}"
1073
+ >
1074
+ <div id="focus-wrapper">
1075
+ <slot></slot>
1076
+ ${0}
1077
+ </div>
1078
+
1079
+ </template>
1080
+ `), x => {
1081
+ var _a;
1082
+ return (_a = DataGridCellRole[x.cellType]) !== null && _a !== void 0 ? _a : DataGridCellRole.default;
1083
+ }, () => focusTemplate);
1084
+ }
1085
+
1086
+ const dataGrid = DataGrid.compose({
1087
+ baseName: 'data-grid',
1088
+ template: DataGridTemplate,
1089
+ styles: css_248z$2
1090
+ })();
1091
+ const dataGridRow = DataGridRow.compose({
1092
+ baseName: 'data-grid-row',
1093
+ template: DataGridRowTemplate,
1094
+ styles: css_248z$1
1095
+ })();
1096
+ const dataGridCell = DataGridCell.compose({
1097
+ baseName: 'data-grid-cell',
1098
+ template: DataGridCellTemplate,
1099
+ styles: css_248z
1100
+ })();
1101
+ const dataGridElements = [dataGridCell, dataGridRow, dataGrid];
1102
+ const registerDataGrid = registerFactory(dataGridElements);
1103
+
1104
+ registerDataGrid();