@vonage/vivid 3.32.0 → 3.35.0
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.
- package/accordion/index.js +5 -5
- package/accordion-item/index.js +4 -4
- package/action-group/index.js +1 -1
- package/alert/index.js +6 -6
- package/avatar/index.js +2 -2
- package/badge/index.js +2 -2
- package/banner/index.js +5 -5
- package/breadcrumb/index.js +1 -1
- package/breadcrumb-item/index.js +3 -3
- package/button/index.js +4 -4
- package/calendar/index.js +1 -1
- package/calendar-event/index.js +1 -1
- package/card/index.js +3 -3
- package/checkbox/index.js +5 -3
- package/combobox/index.js +8 -8
- package/custom-elements.json +256 -18
- package/data-grid/index.js +2 -2
- package/date-picker/index.js +9 -9
- package/dialog/index.js +6 -6
- package/divider/index.js +1 -1
- package/elevation/index.js +1 -1
- package/empty-state/index.js +2 -2
- package/fab/index.js +4 -4
- package/file-picker/index.js +5 -5
- package/focus/index.js +1 -1
- package/header/index.js +2 -2
- package/icon/index.js +1 -1
- package/index.js +59 -59
- package/layout/index.js +1 -1
- package/lib/avatar/avatar.d.ts +1 -1
- package/lib/calendar/calendar.d.ts +1 -1
- package/lib/date-picker/calendar/dateStr.d.ts +1 -0
- package/lib/date-picker/calendar/month.d.ts +1 -0
- package/lib/date-picker/calendar/year.d.ts +2 -0
- package/lib/date-picker/date-picker.d.ts +2 -0
- package/lib/icon/icon.d.ts +0 -1
- package/lib/listbox/listbox.d.ts +9 -1
- package/lib/progress-ring/progress-ring.d.ts +1 -1
- package/lib/text-field/text-field.d.ts +1 -0
- package/listbox/index.js +20 -16
- package/locales/en-GB.js +48 -14
- package/locales/en-US.js +48 -14
- package/locales/ja-JP.js +48 -14
- package/locales/zh-CN.js +48 -14
- package/menu/index.js +8 -8
- package/menu-item/index.js +4 -4
- package/nav/index.js +1 -1
- package/nav-disclosure/index.js +3 -3
- package/nav-item/index.js +3 -3
- package/note/index.js +2 -3
- package/number-field/index.js +6 -6
- package/option/index.js +3 -3
- package/package.json +2 -16
- package/pagination/index.js +5 -5
- package/popup/index.js +6 -6
- package/progress/index.js +1 -1
- package/progress-ring/index.js +1 -1
- package/radio/index.js +2 -2
- package/radio-group/index.js +1 -1
- package/select/index.js +8 -8
- package/shared/affix.js +25 -9
- package/shared/apply-mixins.js +1 -1
- package/shared/breadcrumb-item.js +5 -5
- package/shared/button.js +13 -13
- package/shared/calendar-event.js +36 -16
- package/shared/definition.js +133 -194
- package/shared/definition10.js +225 -40
- package/shared/definition11.js +36 -32
- package/shared/definition12.js +763 -98
- package/shared/definition13.js +125 -89
- package/shared/definition14.js +207 -27
- package/shared/definition15.js +710 -731
- package/shared/definition16.js +1289 -47
- package/shared/definition17.js +6113 -93
- package/shared/definition18.js +242 -164
- package/shared/definition19.js +47 -692
- package/shared/definition2.js +199 -117
- package/shared/definition20.js +59 -1671
- package/shared/definition21.js +95 -255
- package/shared/definition22.js +2218 -1167
- package/shared/definition23.js +61 -5784
- package/shared/definition24.js +28 -117
- package/shared/definition25.js +52 -66
- package/shared/definition26.js +391 -214
- package/shared/definition27.js +441 -34
- package/shared/definition28.js +85 -73
- package/shared/definition29.js +21 -2283
- package/shared/definition3.js +61 -24
- package/shared/definition30.js +13 -49
- package/shared/definition31.js +54 -39
- package/shared/definition32.js +413 -375
- package/shared/definition33.js +223 -304
- package/shared/definition34.js +197 -13
- package/shared/definition35.js +88 -73
- package/shared/definition36.js +75 -25
- package/shared/definition37.js +434 -34
- package/shared/definition38.js +32 -432
- package/shared/definition39.js +677 -187
- package/shared/definition4.js +157 -12
- package/shared/definition40.js +95 -48
- package/shared/definition41.js +577 -31
- package/shared/definition42.js +126 -424
- package/shared/definition43.js +114 -618
- package/shared/definition44.js +24 -80
- package/shared/definition45.js +71 -543
- package/shared/definition46.js +499 -92
- package/shared/definition47.js +19 -133
- package/shared/definition48.js +129 -52
- package/shared/definition49.js +281 -17
- package/shared/definition5.js +71 -36
- package/shared/definition50.js +153 -484
- package/shared/definition51.js +131 -98
- package/shared/definition52.js +131 -16
- package/shared/definition53.js +80 -264
- package/shared/definition54.js +293 -118
- package/shared/definition55.js +12 -117
- package/shared/definition56.js +39 -68
- package/shared/definition57.js +166 -288
- package/shared/definition6.js +56 -111
- package/shared/definition7.js +120 -195
- package/shared/definition8.js +58 -23
- package/shared/definition9.js +92 -66
- package/shared/focus.js +2 -1
- package/shared/focus2.js +1 -1
- package/shared/form-associated.js +2 -2
- package/shared/icon.js +48 -27
- package/shared/index.js +7 -27
- package/shared/index2.js +108 -80
- package/shared/key-codes.js +1 -1
- package/shared/listbox.js +88 -11
- package/shared/patterns/form-elements/form-elements.d.ts +4 -4
- package/shared/radio.js +23 -7
- package/shared/repeat.js +1 -1
- package/shared/text-anchor.js +21 -4
- package/shared/text-anchor.template.js +37 -40
- package/shared/text-field.js +2 -2
- package/shared/text-field2.js +15 -15
- package/shared/tree-item.js +12 -12
- package/side-drawer/index.js +1 -1
- package/slider/index.js +2 -2
- package/split-button/index.js +3 -3
- package/style.css +6106 -0
- package/styles/core/all.css +1 -1
- package/styles/core/theme.css +1 -1
- package/styles/core/typography.css +1 -1
- package/styles/tokens/theme-dark.css +4 -4
- package/styles/tokens/theme-light.css +4 -4
- package/styles/tokens/vivid-2-compat.css +1 -1
- package/switch/index.js +3 -3
- package/tab/index.js +3 -3
- package/tab-panel/index.js +1 -1
- package/tabs/index.js +5 -5
- package/tag/index.js +3 -3
- package/tag-group/index.js +1 -1
- package/text-anchor/index.js +1 -1
- package/text-area/index.js +3 -3
- package/text-field/index.js +3 -3
- package/toggletip/index.js +7 -7
- package/tooltip/index.js +7 -7
- package/tree-item/index.js +3 -3
- package/tree-view/index.js +1 -1
- package/vivid.api.json +10 -1
- package/lib/accordion/index.d.ts +0 -1
- package/lib/accordion-item/index.d.ts +0 -1
- package/lib/action-group/index.d.ts +0 -1
- package/lib/alert/index.d.ts +0 -1
- package/lib/avatar/index.d.ts +0 -1
- package/lib/badge/index.d.ts +0 -1
- package/lib/banner/index.d.ts +0 -1
- package/lib/breadcrumb/index.d.ts +0 -1
- package/lib/breadcrumb-item/index.d.ts +0 -1
- package/lib/button/index.d.ts +0 -1
- package/lib/calendar/index.d.ts +0 -1
- package/lib/calendar-event/index.d.ts +0 -1
- package/lib/card/index.d.ts +0 -1
- package/lib/checkbox/index.d.ts +0 -1
- package/lib/combobox/index.d.ts +0 -1
- package/lib/data-grid/index.d.ts +0 -1
- package/lib/date-picker/index.d.ts +0 -1
- package/lib/dialog/index.d.ts +0 -1
- package/lib/divider/index.d.ts +0 -1
- package/lib/elevation/index.d.ts +0 -1
- package/lib/empty-state/index.d.ts +0 -1
- package/lib/fab/index.d.ts +0 -1
- package/lib/file-picker/index.d.ts +0 -1
- package/lib/focus/index.d.ts +0 -1
- package/lib/header/index.d.ts +0 -1
- package/lib/icon/index.d.ts +0 -1
- package/lib/layout/index.d.ts +0 -1
- package/lib/listbox/index.d.ts +0 -1
- package/lib/menu/index.d.ts +0 -1
- package/lib/menu-item/index.d.ts +0 -1
- package/lib/nav/index.d.ts +0 -1
- package/lib/nav-disclosure/index.d.ts +0 -1
- package/lib/nav-item/index.d.ts +0 -1
- package/lib/note/index.d.ts +0 -1
- package/lib/number-field/index.d.ts +0 -1
- package/lib/option/index.d.ts +0 -1
- package/lib/pagination/index.d.ts +0 -1
- package/lib/popup/index.d.ts +0 -1
- package/lib/progress/index.d.ts +0 -1
- package/lib/progress-ring/index.d.ts +0 -1
- package/lib/radio/index.d.ts +0 -1
- package/lib/radio-group/index.d.ts +0 -1
- package/lib/select/index.d.ts +0 -1
- package/lib/side-drawer/index.d.ts +0 -1
- package/lib/slider/index.d.ts +0 -1
- package/lib/split-button/index.d.ts +0 -1
- package/lib/switch/index.d.ts +0 -1
- package/lib/tab/index.d.ts +0 -1
- package/lib/tab-panel/index.d.ts +0 -1
- package/lib/tabs/index.d.ts +0 -1
- package/lib/tag/index.d.ts +0 -1
- package/lib/tag-group/index.d.ts +0 -1
- package/lib/text-anchor/index.d.ts +0 -1
- package/lib/text-area/index.d.ts +0 -1
- package/lib/text-field/index.d.ts +0 -1
- package/lib/toggletip/index.d.ts +0 -1
- package/lib/tooltip/index.d.ts +0 -1
- package/lib/tree-item/index.d.ts +0 -1
- package/lib/tree-view/index.d.ts +0 -1
package/shared/definition16.js
CHANGED
|
@@ -1,48 +1,1290 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as iconRegistries } from './definition24.js';
|
|
2
|
+
import { F as FoundationElement, _ as __decorate, a as attr, o as observable, D as DOM, h as html, r as registerFactory } from './index.js';
|
|
3
|
+
import { b as keyEnd, c as keyHome, h as keyArrowRight, i as keyArrowLeft, j as keyPageDown, l as keyPageUp, d as keyArrowDown, e as keyArrowUp, f as keyEscape, m as keyFunction2, k as keyEnter } from './key-codes.js';
|
|
4
|
+
import { R as RepeatDirective } from './repeat.js';
|
|
5
|
+
import { e as elements } from './node-observation.js';
|
|
6
|
+
import { c as children } from './children.js';
|
|
7
|
+
import { s as slotted } from './slotted.js';
|
|
8
|
+
import { I as Icon } from './icon.js';
|
|
9
|
+
import { f as focusTemplateFactory } from './focus2.js';
|
|
3
10
|
import { w as when } from './when.js';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This set of exported strings reference https://developer.mozilla.org/en-US/docs/Web/Events
|
|
14
|
+
* and should include all non-deprecated and non-experimental Standard events
|
|
15
|
+
*/
|
|
16
|
+
const eventFocus = "focus";
|
|
17
|
+
const eventFocusIn = "focusin";
|
|
18
|
+
const eventFocusOut = "focusout";
|
|
19
|
+
const eventKeyDown = "keydown";
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Enumerates the data grid auto generated header options
|
|
23
|
+
* default option generates a non-sticky header row
|
|
24
|
+
*
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
const GenerateHeaderOptions$1 = {
|
|
28
|
+
none: "none",
|
|
29
|
+
default: "default",
|
|
30
|
+
sticky: "sticky",
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Enumerates possible data grid cell types.
|
|
34
|
+
*
|
|
35
|
+
* @public
|
|
36
|
+
*/
|
|
37
|
+
const DataGridCellTypes = {
|
|
38
|
+
default: "default",
|
|
39
|
+
columnHeader: "columnheader",
|
|
40
|
+
rowHeader: "rowheader",
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Enumerates possible data grid row types
|
|
44
|
+
*
|
|
45
|
+
* @public
|
|
46
|
+
*/
|
|
47
|
+
const DataGridRowTypes$1 = {
|
|
48
|
+
default: "default",
|
|
49
|
+
header: "header",
|
|
50
|
+
stickyHeader: "sticky-header",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* A Data Grid Row Custom HTML Element.
|
|
55
|
+
*
|
|
56
|
+
* @fires row-focused - Fires a custom 'row-focused' event when focus is on an element (usually a cell or its contents) in the row
|
|
57
|
+
* @slot - The default slot for custom cell elements
|
|
58
|
+
* @public
|
|
59
|
+
*/
|
|
60
|
+
let DataGridRow$1 = class DataGridRow extends FoundationElement {
|
|
61
|
+
constructor() {
|
|
62
|
+
super(...arguments);
|
|
63
|
+
/**
|
|
64
|
+
* The type of row
|
|
65
|
+
*
|
|
66
|
+
* @public
|
|
67
|
+
* @remarks
|
|
68
|
+
* HTML Attribute: row-type
|
|
69
|
+
*/
|
|
70
|
+
this.rowType = DataGridRowTypes$1.default;
|
|
71
|
+
/**
|
|
72
|
+
* The base data for this row
|
|
73
|
+
*
|
|
74
|
+
* @public
|
|
75
|
+
*/
|
|
76
|
+
this.rowData = null;
|
|
77
|
+
/**
|
|
78
|
+
* The column definitions of the row
|
|
79
|
+
*
|
|
80
|
+
* @public
|
|
81
|
+
*/
|
|
82
|
+
this.columnDefinitions = null;
|
|
83
|
+
/**
|
|
84
|
+
* Whether focus is on/in a cell within this row.
|
|
85
|
+
*
|
|
86
|
+
* @internal
|
|
87
|
+
*/
|
|
88
|
+
this.isActiveRow = false;
|
|
89
|
+
this.cellsRepeatBehavior = null;
|
|
90
|
+
this.cellsPlaceholder = null;
|
|
91
|
+
/**
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
this.focusColumnIndex = 0;
|
|
95
|
+
this.refocusOnLoad = false;
|
|
96
|
+
this.updateRowStyle = () => {
|
|
97
|
+
this.style.gridTemplateColumns = this.gridTemplateColumns;
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
gridTemplateColumnsChanged() {
|
|
101
|
+
if (this.$fastController.isConnected) {
|
|
102
|
+
this.updateRowStyle();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
rowTypeChanged() {
|
|
106
|
+
if (this.$fastController.isConnected) {
|
|
107
|
+
this.updateItemTemplate();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
rowDataChanged() {
|
|
111
|
+
if (this.rowData !== null && this.isActiveRow) {
|
|
112
|
+
this.refocusOnLoad = true;
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
cellItemTemplateChanged() {
|
|
117
|
+
this.updateItemTemplate();
|
|
118
|
+
}
|
|
119
|
+
headerCellItemTemplateChanged() {
|
|
120
|
+
this.updateItemTemplate();
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @internal
|
|
124
|
+
*/
|
|
125
|
+
connectedCallback() {
|
|
126
|
+
super.connectedCallback();
|
|
127
|
+
// note that row elements can be reused with a different data object
|
|
128
|
+
// as the parent grid's repeat behavior reacts to changes in the data set.
|
|
129
|
+
if (this.cellsRepeatBehavior === null) {
|
|
130
|
+
this.cellsPlaceholder = document.createComment("");
|
|
131
|
+
this.appendChild(this.cellsPlaceholder);
|
|
132
|
+
this.updateItemTemplate();
|
|
133
|
+
this.cellsRepeatBehavior = new RepeatDirective(x => x.columnDefinitions, x => x.activeCellItemTemplate, { positioning: true }).createBehavior(this.cellsPlaceholder);
|
|
134
|
+
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
135
|
+
this.$fastController.addBehaviors([this.cellsRepeatBehavior]);
|
|
136
|
+
}
|
|
137
|
+
this.addEventListener("cell-focused", this.handleCellFocus);
|
|
138
|
+
this.addEventListener(eventFocusOut, this.handleFocusout);
|
|
139
|
+
this.addEventListener(eventKeyDown, this.handleKeydown);
|
|
140
|
+
this.updateRowStyle();
|
|
141
|
+
if (this.refocusOnLoad) {
|
|
142
|
+
// if focus was on the row when data changed try to refocus on same cell
|
|
143
|
+
this.refocusOnLoad = false;
|
|
144
|
+
if (this.cellElements.length > this.focusColumnIndex) {
|
|
145
|
+
this.cellElements[this.focusColumnIndex].focus();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* @internal
|
|
151
|
+
*/
|
|
152
|
+
disconnectedCallback() {
|
|
153
|
+
super.disconnectedCallback();
|
|
154
|
+
this.removeEventListener("cell-focused", this.handleCellFocus);
|
|
155
|
+
this.removeEventListener(eventFocusOut, this.handleFocusout);
|
|
156
|
+
this.removeEventListener(eventKeyDown, this.handleKeydown);
|
|
157
|
+
}
|
|
158
|
+
handleFocusout(e) {
|
|
159
|
+
if (!this.contains(e.target)) {
|
|
160
|
+
this.isActiveRow = false;
|
|
161
|
+
this.focusColumnIndex = 0;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
handleCellFocus(e) {
|
|
165
|
+
this.isActiveRow = true;
|
|
166
|
+
this.focusColumnIndex = this.cellElements.indexOf(e.target);
|
|
167
|
+
this.$emit("row-focused", this);
|
|
168
|
+
}
|
|
169
|
+
handleKeydown(e) {
|
|
170
|
+
if (e.defaultPrevented) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
let newFocusColumnIndex = 0;
|
|
174
|
+
switch (e.key) {
|
|
175
|
+
case keyArrowLeft:
|
|
176
|
+
// focus left one cell
|
|
177
|
+
newFocusColumnIndex = Math.max(0, this.focusColumnIndex - 1);
|
|
178
|
+
this.cellElements[newFocusColumnIndex].focus();
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
break;
|
|
181
|
+
case keyArrowRight:
|
|
182
|
+
// focus right one cell
|
|
183
|
+
newFocusColumnIndex = Math.min(this.cellElements.length - 1, this.focusColumnIndex + 1);
|
|
184
|
+
this.cellElements[newFocusColumnIndex].focus();
|
|
185
|
+
e.preventDefault();
|
|
186
|
+
break;
|
|
187
|
+
case keyHome:
|
|
188
|
+
if (!e.ctrlKey) {
|
|
189
|
+
this.cellElements[0].focus();
|
|
190
|
+
e.preventDefault();
|
|
191
|
+
}
|
|
192
|
+
break;
|
|
193
|
+
case keyEnd:
|
|
194
|
+
if (!e.ctrlKey) {
|
|
195
|
+
// focus last cell of the row
|
|
196
|
+
this.cellElements[this.cellElements.length - 1].focus();
|
|
197
|
+
e.preventDefault();
|
|
198
|
+
}
|
|
199
|
+
break;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
updateItemTemplate() {
|
|
203
|
+
this.activeCellItemTemplate =
|
|
204
|
+
this.rowType === DataGridRowTypes$1.default &&
|
|
205
|
+
this.cellItemTemplate !== undefined
|
|
206
|
+
? this.cellItemTemplate
|
|
207
|
+
: this.rowType === DataGridRowTypes$1.default &&
|
|
208
|
+
this.cellItemTemplate === undefined
|
|
209
|
+
? this.defaultCellItemTemplate
|
|
210
|
+
: this.headerCellItemTemplate !== undefined
|
|
211
|
+
? this.headerCellItemTemplate
|
|
212
|
+
: this.defaultHeaderCellItemTemplate;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
__decorate([
|
|
216
|
+
attr({ attribute: "grid-template-columns" })
|
|
217
|
+
], DataGridRow$1.prototype, "gridTemplateColumns", void 0);
|
|
218
|
+
__decorate([
|
|
219
|
+
attr({ attribute: "row-type" })
|
|
220
|
+
], DataGridRow$1.prototype, "rowType", void 0);
|
|
221
|
+
__decorate([
|
|
222
|
+
observable
|
|
223
|
+
], DataGridRow$1.prototype, "rowData", void 0);
|
|
224
|
+
__decorate([
|
|
225
|
+
observable
|
|
226
|
+
], DataGridRow$1.prototype, "columnDefinitions", void 0);
|
|
227
|
+
__decorate([
|
|
228
|
+
observable
|
|
229
|
+
], DataGridRow$1.prototype, "cellItemTemplate", void 0);
|
|
230
|
+
__decorate([
|
|
231
|
+
observable
|
|
232
|
+
], DataGridRow$1.prototype, "headerCellItemTemplate", void 0);
|
|
233
|
+
__decorate([
|
|
234
|
+
observable
|
|
235
|
+
], DataGridRow$1.prototype, "rowIndex", void 0);
|
|
236
|
+
__decorate([
|
|
237
|
+
observable
|
|
238
|
+
], DataGridRow$1.prototype, "isActiveRow", void 0);
|
|
239
|
+
__decorate([
|
|
240
|
+
observable
|
|
241
|
+
], DataGridRow$1.prototype, "activeCellItemTemplate", void 0);
|
|
242
|
+
__decorate([
|
|
243
|
+
observable
|
|
244
|
+
], DataGridRow$1.prototype, "defaultCellItemTemplate", void 0);
|
|
245
|
+
__decorate([
|
|
246
|
+
observable
|
|
247
|
+
], DataGridRow$1.prototype, "defaultHeaderCellItemTemplate", void 0);
|
|
248
|
+
__decorate([
|
|
249
|
+
observable
|
|
250
|
+
], DataGridRow$1.prototype, "cellElements", void 0);
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* A Data Grid Custom HTML Element.
|
|
254
|
+
*
|
|
255
|
+
* @slot - The default slot for custom row elements
|
|
256
|
+
* @public
|
|
257
|
+
*/
|
|
258
|
+
let DataGrid$1 = class DataGrid extends FoundationElement {
|
|
259
|
+
constructor() {
|
|
260
|
+
super();
|
|
261
|
+
/**
|
|
262
|
+
* When true the component will not add itself to the tab queue.
|
|
263
|
+
* Default is false.
|
|
264
|
+
*
|
|
265
|
+
* @public
|
|
266
|
+
* @remarks
|
|
267
|
+
* HTML Attribute: no-tabbing
|
|
268
|
+
*/
|
|
269
|
+
this.noTabbing = false;
|
|
270
|
+
/**
|
|
271
|
+
* Whether the grid should automatically generate a header row and its type
|
|
272
|
+
*
|
|
273
|
+
* @public
|
|
274
|
+
* @remarks
|
|
275
|
+
* HTML Attribute: generate-header
|
|
276
|
+
*/
|
|
277
|
+
this.generateHeader = GenerateHeaderOptions$1.default;
|
|
278
|
+
/**
|
|
279
|
+
* The data being displayed in the grid
|
|
280
|
+
*
|
|
281
|
+
* @public
|
|
282
|
+
*/
|
|
283
|
+
this.rowsData = [];
|
|
284
|
+
/**
|
|
285
|
+
* The column definitions of the grid
|
|
286
|
+
*
|
|
287
|
+
* @public
|
|
288
|
+
*/
|
|
289
|
+
this.columnDefinitions = null;
|
|
290
|
+
/**
|
|
291
|
+
* The index of the row that will receive focus the next time the
|
|
292
|
+
* grid is focused. This value changes as focus moves to different
|
|
293
|
+
* rows within the grid. Changing this value when focus is already
|
|
294
|
+
* within the grid moves focus to the specified row.
|
|
295
|
+
*
|
|
296
|
+
* @public
|
|
297
|
+
*/
|
|
298
|
+
this.focusRowIndex = 0;
|
|
299
|
+
/**
|
|
300
|
+
* The index of the column that will receive focus the next time the
|
|
301
|
+
* grid is focused. This value changes as focus moves to different rows
|
|
302
|
+
* within the grid. Changing this value when focus is already within
|
|
303
|
+
* the grid moves focus to the specified column.
|
|
304
|
+
*
|
|
305
|
+
* @public
|
|
306
|
+
*/
|
|
307
|
+
this.focusColumnIndex = 0;
|
|
308
|
+
this.rowsPlaceholder = null;
|
|
309
|
+
this.generatedHeader = null;
|
|
310
|
+
this.isUpdatingFocus = false;
|
|
311
|
+
this.pendingFocusUpdate = false;
|
|
312
|
+
this.rowindexUpdateQueued = false;
|
|
313
|
+
this.columnDefinitionsStale = true;
|
|
314
|
+
this.generatedGridTemplateColumns = "";
|
|
315
|
+
this.focusOnCell = (rowIndex, columnIndex, scrollIntoView) => {
|
|
316
|
+
if (this.rowElements.length === 0) {
|
|
317
|
+
this.focusRowIndex = 0;
|
|
318
|
+
this.focusColumnIndex = 0;
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const focusRowIndex = Math.max(0, Math.min(this.rowElements.length - 1, rowIndex));
|
|
322
|
+
const focusRow = this.rowElements[focusRowIndex];
|
|
323
|
+
const cells = focusRow.querySelectorAll('[role="cell"], [role="gridcell"], [role="columnheader"], [role="rowheader"]');
|
|
324
|
+
const focusColumnIndex = Math.max(0, Math.min(cells.length - 1, columnIndex));
|
|
325
|
+
const focusTarget = cells[focusColumnIndex];
|
|
326
|
+
if (scrollIntoView &&
|
|
327
|
+
this.scrollHeight !== this.clientHeight &&
|
|
328
|
+
((focusRowIndex < this.focusRowIndex && this.scrollTop > 0) ||
|
|
329
|
+
(focusRowIndex > this.focusRowIndex &&
|
|
330
|
+
this.scrollTop < this.scrollHeight - this.clientHeight))) {
|
|
331
|
+
focusTarget.scrollIntoView({ block: "center", inline: "center" });
|
|
332
|
+
}
|
|
333
|
+
focusTarget.focus();
|
|
334
|
+
};
|
|
335
|
+
this.onChildListChange = (mutations,
|
|
336
|
+
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
337
|
+
observer) => {
|
|
338
|
+
if (mutations && mutations.length) {
|
|
339
|
+
mutations.forEach((mutation) => {
|
|
340
|
+
mutation.addedNodes.forEach((newNode) => {
|
|
341
|
+
if (newNode.nodeType === 1 &&
|
|
342
|
+
newNode.getAttribute("role") === "row") {
|
|
343
|
+
newNode.columnDefinitions = this.columnDefinitions;
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
this.queueRowIndexUpdate();
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
this.queueRowIndexUpdate = () => {
|
|
351
|
+
if (!this.rowindexUpdateQueued) {
|
|
352
|
+
this.rowindexUpdateQueued = true;
|
|
353
|
+
DOM.queueUpdate(this.updateRowIndexes);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
356
|
+
this.updateRowIndexes = () => {
|
|
357
|
+
let newGridTemplateColumns = this.gridTemplateColumns;
|
|
358
|
+
if (newGridTemplateColumns === undefined) {
|
|
359
|
+
// try to generate columns based on manual rows
|
|
360
|
+
if (this.generatedGridTemplateColumns === "" && this.rowElements.length > 0) {
|
|
361
|
+
const firstRow = this.rowElements[0];
|
|
362
|
+
this.generatedGridTemplateColumns = new Array(firstRow.cellElements.length)
|
|
363
|
+
.fill("1fr")
|
|
364
|
+
.join(" ");
|
|
365
|
+
}
|
|
366
|
+
newGridTemplateColumns = this.generatedGridTemplateColumns;
|
|
367
|
+
}
|
|
368
|
+
this.rowElements.forEach((element, index) => {
|
|
369
|
+
const thisRow = element;
|
|
370
|
+
thisRow.rowIndex = index;
|
|
371
|
+
thisRow.gridTemplateColumns = newGridTemplateColumns;
|
|
372
|
+
if (this.columnDefinitionsStale) {
|
|
373
|
+
thisRow.columnDefinitions = this.columnDefinitions;
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
this.rowindexUpdateQueued = false;
|
|
377
|
+
this.columnDefinitionsStale = false;
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* generates a gridTemplateColumns based on columndata array
|
|
382
|
+
*/
|
|
383
|
+
static generateTemplateColumns(columnDefinitions) {
|
|
384
|
+
let templateColumns = "";
|
|
385
|
+
columnDefinitions.forEach((column) => {
|
|
386
|
+
templateColumns = `${templateColumns}${templateColumns === "" ? "" : " "}${"1fr"}`;
|
|
387
|
+
});
|
|
388
|
+
return templateColumns;
|
|
389
|
+
}
|
|
390
|
+
noTabbingChanged() {
|
|
391
|
+
if (this.$fastController.isConnected) {
|
|
392
|
+
if (this.noTabbing) {
|
|
393
|
+
this.setAttribute("tabIndex", "-1");
|
|
394
|
+
}
|
|
395
|
+
else {
|
|
396
|
+
this.setAttribute("tabIndex", this.contains(document.activeElement) ||
|
|
397
|
+
this === document.activeElement
|
|
398
|
+
? "-1"
|
|
399
|
+
: "0");
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
generateHeaderChanged() {
|
|
404
|
+
if (this.$fastController.isConnected) {
|
|
405
|
+
this.toggleGeneratedHeader();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
gridTemplateColumnsChanged() {
|
|
409
|
+
if (this.$fastController.isConnected) {
|
|
410
|
+
this.updateRowIndexes();
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
rowsDataChanged() {
|
|
414
|
+
if (this.columnDefinitions === null && this.rowsData.length > 0) {
|
|
415
|
+
this.columnDefinitions = DataGrid.generateColumns(this.rowsData[0]);
|
|
416
|
+
}
|
|
417
|
+
if (this.$fastController.isConnected) {
|
|
418
|
+
this.toggleGeneratedHeader();
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
columnDefinitionsChanged() {
|
|
422
|
+
if (this.columnDefinitions === null) {
|
|
423
|
+
this.generatedGridTemplateColumns = "";
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
this.generatedGridTemplateColumns = DataGrid.generateTemplateColumns(this.columnDefinitions);
|
|
427
|
+
if (this.$fastController.isConnected) {
|
|
428
|
+
this.columnDefinitionsStale = true;
|
|
429
|
+
this.queueRowIndexUpdate();
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
headerCellItemTemplateChanged() {
|
|
433
|
+
if (this.$fastController.isConnected) {
|
|
434
|
+
if (this.generatedHeader !== null) {
|
|
435
|
+
this.generatedHeader.headerCellItemTemplate = this.headerCellItemTemplate;
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
focusRowIndexChanged() {
|
|
440
|
+
if (this.$fastController.isConnected) {
|
|
441
|
+
this.queueFocusUpdate();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
focusColumnIndexChanged() {
|
|
445
|
+
if (this.$fastController.isConnected) {
|
|
446
|
+
this.queueFocusUpdate();
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* @internal
|
|
451
|
+
*/
|
|
452
|
+
connectedCallback() {
|
|
453
|
+
super.connectedCallback();
|
|
454
|
+
if (this.rowItemTemplate === undefined) {
|
|
455
|
+
this.rowItemTemplate = this.defaultRowItemTemplate;
|
|
456
|
+
}
|
|
457
|
+
this.rowsPlaceholder = document.createComment("");
|
|
458
|
+
this.appendChild(this.rowsPlaceholder);
|
|
459
|
+
this.toggleGeneratedHeader();
|
|
460
|
+
this.rowsRepeatBehavior = new RepeatDirective(x => x.rowsData, x => x.rowItemTemplate, { positioning: true }).createBehavior(this.rowsPlaceholder);
|
|
461
|
+
/* eslint-disable-next-line @typescript-eslint/no-non-null-assertion */
|
|
462
|
+
this.$fastController.addBehaviors([this.rowsRepeatBehavior]);
|
|
463
|
+
this.addEventListener("row-focused", this.handleRowFocus);
|
|
464
|
+
this.addEventListener(eventFocus, this.handleFocus);
|
|
465
|
+
this.addEventListener(eventKeyDown, this.handleKeydown);
|
|
466
|
+
this.addEventListener(eventFocusOut, this.handleFocusOut);
|
|
467
|
+
this.observer = new MutationObserver(this.onChildListChange);
|
|
468
|
+
// only observe if nodes are added or removed
|
|
469
|
+
this.observer.observe(this, { childList: true });
|
|
470
|
+
if (this.noTabbing) {
|
|
471
|
+
this.setAttribute("tabindex", "-1");
|
|
472
|
+
}
|
|
473
|
+
DOM.queueUpdate(this.queueRowIndexUpdate);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* @internal
|
|
477
|
+
*/
|
|
478
|
+
disconnectedCallback() {
|
|
479
|
+
super.disconnectedCallback();
|
|
480
|
+
this.removeEventListener("row-focused", this.handleRowFocus);
|
|
481
|
+
this.removeEventListener(eventFocus, this.handleFocus);
|
|
482
|
+
this.removeEventListener(eventKeyDown, this.handleKeydown);
|
|
483
|
+
this.removeEventListener(eventFocusOut, this.handleFocusOut);
|
|
484
|
+
// disconnect observer
|
|
485
|
+
this.observer.disconnect();
|
|
486
|
+
this.rowsPlaceholder = null;
|
|
487
|
+
this.generatedHeader = null;
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* @internal
|
|
491
|
+
*/
|
|
492
|
+
handleRowFocus(e) {
|
|
493
|
+
this.isUpdatingFocus = true;
|
|
494
|
+
const focusRow = e.target;
|
|
495
|
+
this.focusRowIndex = this.rowElements.indexOf(focusRow);
|
|
496
|
+
this.focusColumnIndex = focusRow.focusColumnIndex;
|
|
497
|
+
this.setAttribute("tabIndex", "-1");
|
|
498
|
+
this.isUpdatingFocus = false;
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* @internal
|
|
502
|
+
*/
|
|
503
|
+
handleFocus(e) {
|
|
504
|
+
this.focusOnCell(this.focusRowIndex, this.focusColumnIndex, true);
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* @internal
|
|
508
|
+
*/
|
|
509
|
+
handleFocusOut(e) {
|
|
510
|
+
if (e.relatedTarget === null || !this.contains(e.relatedTarget)) {
|
|
511
|
+
this.setAttribute("tabIndex", this.noTabbing ? "-1" : "0");
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
/**
|
|
515
|
+
* @internal
|
|
516
|
+
*/
|
|
517
|
+
handleKeydown(e) {
|
|
518
|
+
if (e.defaultPrevented) {
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
let newFocusRowIndex;
|
|
522
|
+
const maxIndex = this.rowElements.length - 1;
|
|
523
|
+
const currentGridBottom = this.offsetHeight + this.scrollTop;
|
|
524
|
+
const lastRow = this.rowElements[maxIndex];
|
|
525
|
+
switch (e.key) {
|
|
526
|
+
case keyArrowUp:
|
|
527
|
+
e.preventDefault();
|
|
528
|
+
// focus up one row
|
|
529
|
+
this.focusOnCell(this.focusRowIndex - 1, this.focusColumnIndex, true);
|
|
530
|
+
break;
|
|
531
|
+
case keyArrowDown:
|
|
532
|
+
e.preventDefault();
|
|
533
|
+
// focus down one row
|
|
534
|
+
this.focusOnCell(this.focusRowIndex + 1, this.focusColumnIndex, true);
|
|
535
|
+
break;
|
|
536
|
+
case keyPageUp:
|
|
537
|
+
e.preventDefault();
|
|
538
|
+
if (this.rowElements.length === 0) {
|
|
539
|
+
this.focusOnCell(0, 0, false);
|
|
540
|
+
break;
|
|
541
|
+
}
|
|
542
|
+
if (this.focusRowIndex === 0) {
|
|
543
|
+
this.focusOnCell(0, this.focusColumnIndex, false);
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
newFocusRowIndex = this.focusRowIndex - 1;
|
|
547
|
+
for (newFocusRowIndex; newFocusRowIndex >= 0; newFocusRowIndex--) {
|
|
548
|
+
const thisRow = this.rowElements[newFocusRowIndex];
|
|
549
|
+
if (thisRow.offsetTop < this.scrollTop) {
|
|
550
|
+
this.scrollTop =
|
|
551
|
+
thisRow.offsetTop + thisRow.clientHeight - this.clientHeight;
|
|
552
|
+
break;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
this.focusOnCell(newFocusRowIndex, this.focusColumnIndex, false);
|
|
556
|
+
break;
|
|
557
|
+
case keyPageDown:
|
|
558
|
+
e.preventDefault();
|
|
559
|
+
if (this.rowElements.length === 0) {
|
|
560
|
+
this.focusOnCell(0, 0, false);
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
// focus down one "page"
|
|
564
|
+
if (this.focusRowIndex >= maxIndex ||
|
|
565
|
+
lastRow.offsetTop + lastRow.offsetHeight <= currentGridBottom) {
|
|
566
|
+
this.focusOnCell(maxIndex, this.focusColumnIndex, false);
|
|
567
|
+
return;
|
|
568
|
+
}
|
|
569
|
+
newFocusRowIndex = this.focusRowIndex + 1;
|
|
570
|
+
for (newFocusRowIndex; newFocusRowIndex <= maxIndex; newFocusRowIndex++) {
|
|
571
|
+
const thisRow = this.rowElements[newFocusRowIndex];
|
|
572
|
+
if (thisRow.offsetTop + thisRow.offsetHeight > currentGridBottom) {
|
|
573
|
+
let stickyHeaderOffset = 0;
|
|
574
|
+
if (this.generateHeader === GenerateHeaderOptions$1.sticky &&
|
|
575
|
+
this.generatedHeader !== null) {
|
|
576
|
+
stickyHeaderOffset = this.generatedHeader.clientHeight;
|
|
577
|
+
}
|
|
578
|
+
this.scrollTop = thisRow.offsetTop - stickyHeaderOffset;
|
|
579
|
+
break;
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
this.focusOnCell(newFocusRowIndex, this.focusColumnIndex, false);
|
|
583
|
+
break;
|
|
584
|
+
case keyHome:
|
|
585
|
+
if (e.ctrlKey) {
|
|
586
|
+
e.preventDefault();
|
|
587
|
+
// focus first cell of first row
|
|
588
|
+
this.focusOnCell(0, 0, true);
|
|
589
|
+
}
|
|
590
|
+
break;
|
|
591
|
+
case keyEnd:
|
|
592
|
+
if (e.ctrlKey && this.columnDefinitions !== null) {
|
|
593
|
+
e.preventDefault();
|
|
594
|
+
// focus last cell of last row
|
|
595
|
+
this.focusOnCell(this.rowElements.length - 1, this.columnDefinitions.length - 1, true);
|
|
596
|
+
}
|
|
597
|
+
break;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
queueFocusUpdate() {
|
|
601
|
+
if (this.isUpdatingFocus &&
|
|
602
|
+
(this.contains(document.activeElement) || this === document.activeElement)) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
if (this.pendingFocusUpdate === false) {
|
|
606
|
+
this.pendingFocusUpdate = true;
|
|
607
|
+
DOM.queueUpdate(() => this.updateFocus());
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
updateFocus() {
|
|
611
|
+
this.pendingFocusUpdate = false;
|
|
612
|
+
this.focusOnCell(this.focusRowIndex, this.focusColumnIndex, true);
|
|
613
|
+
}
|
|
614
|
+
toggleGeneratedHeader() {
|
|
615
|
+
if (this.generatedHeader !== null) {
|
|
616
|
+
this.removeChild(this.generatedHeader);
|
|
617
|
+
this.generatedHeader = null;
|
|
618
|
+
}
|
|
619
|
+
if (this.generateHeader !== GenerateHeaderOptions$1.none &&
|
|
620
|
+
this.rowsData.length > 0) {
|
|
621
|
+
const generatedHeaderElement = document.createElement(this.rowElementTag);
|
|
622
|
+
this.generatedHeader = generatedHeaderElement;
|
|
623
|
+
this.generatedHeader.columnDefinitions = this.columnDefinitions;
|
|
624
|
+
this.generatedHeader.gridTemplateColumns = this.gridTemplateColumns;
|
|
625
|
+
this.generatedHeader.rowType =
|
|
626
|
+
this.generateHeader === GenerateHeaderOptions$1.sticky
|
|
627
|
+
? DataGridRowTypes$1.stickyHeader
|
|
628
|
+
: DataGridRowTypes$1.header;
|
|
629
|
+
if (this.firstChild !== null || this.rowsPlaceholder !== null) {
|
|
630
|
+
this.insertBefore(generatedHeaderElement, this.firstChild !== null ? this.firstChild : this.rowsPlaceholder);
|
|
631
|
+
}
|
|
632
|
+
return;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
/**
|
|
637
|
+
* generates a basic column definition by examining sample row data
|
|
638
|
+
*/
|
|
639
|
+
DataGrid$1.generateColumns = (row) => {
|
|
640
|
+
return Object.getOwnPropertyNames(row).map((property, index) => {
|
|
641
|
+
return {
|
|
642
|
+
columnDataKey: property,
|
|
643
|
+
gridColumn: `${index}`,
|
|
644
|
+
};
|
|
645
|
+
});
|
|
646
|
+
};
|
|
647
|
+
__decorate([
|
|
648
|
+
attr({ attribute: "no-tabbing", mode: "boolean" })
|
|
649
|
+
], DataGrid$1.prototype, "noTabbing", void 0);
|
|
650
|
+
__decorate([
|
|
651
|
+
attr({ attribute: "generate-header" })
|
|
652
|
+
], DataGrid$1.prototype, "generateHeader", void 0);
|
|
653
|
+
__decorate([
|
|
654
|
+
attr({ attribute: "grid-template-columns" })
|
|
655
|
+
], DataGrid$1.prototype, "gridTemplateColumns", void 0);
|
|
656
|
+
__decorate([
|
|
657
|
+
observable
|
|
658
|
+
], DataGrid$1.prototype, "rowsData", void 0);
|
|
659
|
+
__decorate([
|
|
660
|
+
observable
|
|
661
|
+
], DataGrid$1.prototype, "columnDefinitions", void 0);
|
|
662
|
+
__decorate([
|
|
663
|
+
observable
|
|
664
|
+
], DataGrid$1.prototype, "rowItemTemplate", void 0);
|
|
665
|
+
__decorate([
|
|
666
|
+
observable
|
|
667
|
+
], DataGrid$1.prototype, "cellItemTemplate", void 0);
|
|
668
|
+
__decorate([
|
|
669
|
+
observable
|
|
670
|
+
], DataGrid$1.prototype, "headerCellItemTemplate", void 0);
|
|
671
|
+
__decorate([
|
|
672
|
+
observable
|
|
673
|
+
], DataGrid$1.prototype, "focusRowIndex", void 0);
|
|
674
|
+
__decorate([
|
|
675
|
+
observable
|
|
676
|
+
], DataGrid$1.prototype, "focusColumnIndex", void 0);
|
|
677
|
+
__decorate([
|
|
678
|
+
observable
|
|
679
|
+
], DataGrid$1.prototype, "defaultRowItemTemplate", void 0);
|
|
680
|
+
__decorate([
|
|
681
|
+
observable
|
|
682
|
+
], DataGrid$1.prototype, "rowElementTag", void 0);
|
|
683
|
+
__decorate([
|
|
684
|
+
observable
|
|
685
|
+
], DataGrid$1.prototype, "rowElements", void 0);
|
|
686
|
+
|
|
687
|
+
const defaultCellContentsTemplate = html `
|
|
688
|
+
<template>
|
|
689
|
+
${x => x.rowData === null ||
|
|
690
|
+
x.columnDefinition === null ||
|
|
691
|
+
x.columnDefinition.columnDataKey === null
|
|
692
|
+
? null
|
|
693
|
+
: x.rowData[x.columnDefinition.columnDataKey]}
|
|
694
|
+
</template>
|
|
695
|
+
`;
|
|
696
|
+
const defaultHeaderCellContentsTemplate = html `
|
|
697
|
+
<template>
|
|
698
|
+
${x => x.columnDefinition === null
|
|
699
|
+
? null
|
|
700
|
+
: x.columnDefinition.title === undefined
|
|
701
|
+
? x.columnDefinition.columnDataKey
|
|
702
|
+
: x.columnDefinition.title}
|
|
703
|
+
</template>
|
|
704
|
+
`;
|
|
705
|
+
/**
|
|
706
|
+
* A Data Grid Cell Custom HTML Element.
|
|
707
|
+
*
|
|
708
|
+
* @fires cell-focused - Fires a custom 'cell-focused' event when focus is on the cell or its contents
|
|
709
|
+
* @slot - The default slot for cell contents. The "cell contents template" renders here.
|
|
710
|
+
* @public
|
|
711
|
+
*/
|
|
712
|
+
let DataGridCell$1 = class DataGridCell extends FoundationElement {
|
|
713
|
+
constructor() {
|
|
714
|
+
super(...arguments);
|
|
715
|
+
/**
|
|
716
|
+
* The type of cell
|
|
717
|
+
*
|
|
718
|
+
* @public
|
|
719
|
+
* @remarks
|
|
720
|
+
* HTML Attribute: cell-type
|
|
721
|
+
*/
|
|
722
|
+
this.cellType = DataGridCellTypes.default;
|
|
723
|
+
/**
|
|
724
|
+
* The base data for the parent row
|
|
725
|
+
*
|
|
726
|
+
* @public
|
|
727
|
+
*/
|
|
728
|
+
this.rowData = null;
|
|
729
|
+
/**
|
|
730
|
+
* The base data for the column
|
|
731
|
+
*
|
|
732
|
+
* @public
|
|
733
|
+
*/
|
|
734
|
+
this.columnDefinition = null;
|
|
735
|
+
this.isActiveCell = false;
|
|
736
|
+
this.customCellView = null;
|
|
737
|
+
this.updateCellStyle = () => {
|
|
738
|
+
this.style.gridColumn = this.gridColumn;
|
|
739
|
+
};
|
|
740
|
+
}
|
|
741
|
+
cellTypeChanged() {
|
|
742
|
+
if (this.$fastController.isConnected) {
|
|
743
|
+
this.updateCellView();
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
gridColumnChanged() {
|
|
747
|
+
if (this.$fastController.isConnected) {
|
|
748
|
+
this.updateCellStyle();
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
columnDefinitionChanged(oldValue, newValue) {
|
|
752
|
+
if (this.$fastController.isConnected) {
|
|
753
|
+
this.updateCellView();
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* @internal
|
|
758
|
+
*/
|
|
759
|
+
connectedCallback() {
|
|
760
|
+
var _a;
|
|
761
|
+
super.connectedCallback();
|
|
762
|
+
this.addEventListener(eventFocusIn, this.handleFocusin);
|
|
763
|
+
this.addEventListener(eventFocusOut, this.handleFocusout);
|
|
764
|
+
this.addEventListener(eventKeyDown, this.handleKeydown);
|
|
765
|
+
this.style.gridColumn = `${((_a = this.columnDefinition) === null || _a === void 0 ? void 0 : _a.gridColumn) === undefined
|
|
766
|
+
? 0
|
|
767
|
+
: this.columnDefinition.gridColumn}`;
|
|
768
|
+
this.updateCellView();
|
|
769
|
+
this.updateCellStyle();
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* @internal
|
|
773
|
+
*/
|
|
774
|
+
disconnectedCallback() {
|
|
775
|
+
super.disconnectedCallback();
|
|
776
|
+
this.removeEventListener(eventFocusIn, this.handleFocusin);
|
|
777
|
+
this.removeEventListener(eventFocusOut, this.handleFocusout);
|
|
778
|
+
this.removeEventListener(eventKeyDown, this.handleKeydown);
|
|
779
|
+
this.disconnectCellView();
|
|
780
|
+
}
|
|
781
|
+
handleFocusin(e) {
|
|
782
|
+
if (this.isActiveCell) {
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
this.isActiveCell = true;
|
|
786
|
+
switch (this.cellType) {
|
|
787
|
+
case DataGridCellTypes.columnHeader:
|
|
788
|
+
if (this.columnDefinition !== null &&
|
|
789
|
+
this.columnDefinition.headerCellInternalFocusQueue !== true &&
|
|
790
|
+
typeof this.columnDefinition.headerCellFocusTargetCallback ===
|
|
791
|
+
"function") {
|
|
792
|
+
// move focus to the focus target
|
|
793
|
+
const focusTarget = this.columnDefinition.headerCellFocusTargetCallback(this);
|
|
794
|
+
if (focusTarget !== null) {
|
|
795
|
+
focusTarget.focus();
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
break;
|
|
799
|
+
default:
|
|
800
|
+
if (this.columnDefinition !== null &&
|
|
801
|
+
this.columnDefinition.cellInternalFocusQueue !== true &&
|
|
802
|
+
typeof this.columnDefinition.cellFocusTargetCallback === "function") {
|
|
803
|
+
// move focus to the focus target
|
|
804
|
+
const focusTarget = this.columnDefinition.cellFocusTargetCallback(this);
|
|
805
|
+
if (focusTarget !== null) {
|
|
806
|
+
focusTarget.focus();
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
break;
|
|
810
|
+
}
|
|
811
|
+
this.$emit("cell-focused", this);
|
|
812
|
+
}
|
|
813
|
+
handleFocusout(e) {
|
|
814
|
+
if (this !== document.activeElement && !this.contains(document.activeElement)) {
|
|
815
|
+
this.isActiveCell = false;
|
|
816
|
+
}
|
|
817
|
+
}
|
|
818
|
+
handleKeydown(e) {
|
|
819
|
+
if (e.defaultPrevented ||
|
|
820
|
+
this.columnDefinition === null ||
|
|
821
|
+
(this.cellType === DataGridCellTypes.default &&
|
|
822
|
+
this.columnDefinition.cellInternalFocusQueue !== true) ||
|
|
823
|
+
(this.cellType === DataGridCellTypes.columnHeader &&
|
|
824
|
+
this.columnDefinition.headerCellInternalFocusQueue !== true)) {
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
switch (e.key) {
|
|
828
|
+
case keyEnter:
|
|
829
|
+
case keyFunction2:
|
|
830
|
+
if (this.contains(document.activeElement) &&
|
|
831
|
+
document.activeElement !== this) {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
switch (this.cellType) {
|
|
835
|
+
case DataGridCellTypes.columnHeader:
|
|
836
|
+
if (this.columnDefinition.headerCellFocusTargetCallback !==
|
|
837
|
+
undefined) {
|
|
838
|
+
const focusTarget = this.columnDefinition.headerCellFocusTargetCallback(this);
|
|
839
|
+
if (focusTarget !== null) {
|
|
840
|
+
focusTarget.focus();
|
|
841
|
+
}
|
|
842
|
+
e.preventDefault();
|
|
843
|
+
}
|
|
844
|
+
break;
|
|
845
|
+
default:
|
|
846
|
+
if (this.columnDefinition.cellFocusTargetCallback !== undefined) {
|
|
847
|
+
const focusTarget = this.columnDefinition.cellFocusTargetCallback(this);
|
|
848
|
+
if (focusTarget !== null) {
|
|
849
|
+
focusTarget.focus();
|
|
850
|
+
}
|
|
851
|
+
e.preventDefault();
|
|
852
|
+
}
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
break;
|
|
856
|
+
case keyEscape:
|
|
857
|
+
if (this.contains(document.activeElement) &&
|
|
858
|
+
document.activeElement !== this) {
|
|
859
|
+
this.focus();
|
|
860
|
+
e.preventDefault();
|
|
861
|
+
}
|
|
862
|
+
break;
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
updateCellView() {
|
|
866
|
+
this.disconnectCellView();
|
|
867
|
+
if (this.columnDefinition === null) {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
switch (this.cellType) {
|
|
871
|
+
case DataGridCellTypes.columnHeader:
|
|
872
|
+
if (this.columnDefinition.headerCellTemplate !== undefined) {
|
|
873
|
+
this.customCellView = this.columnDefinition.headerCellTemplate.render(this, this);
|
|
874
|
+
}
|
|
875
|
+
else {
|
|
876
|
+
this.customCellView = defaultHeaderCellContentsTemplate.render(this, this);
|
|
877
|
+
}
|
|
878
|
+
break;
|
|
879
|
+
case undefined:
|
|
880
|
+
case DataGridCellTypes.rowHeader:
|
|
881
|
+
case DataGridCellTypes.default:
|
|
882
|
+
if (this.columnDefinition.cellTemplate !== undefined) {
|
|
883
|
+
this.customCellView = this.columnDefinition.cellTemplate.render(this, this);
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
this.customCellView = defaultCellContentsTemplate.render(this, this);
|
|
887
|
+
}
|
|
888
|
+
break;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
disconnectCellView() {
|
|
892
|
+
if (this.customCellView !== null) {
|
|
893
|
+
this.customCellView.dispose();
|
|
894
|
+
this.customCellView = null;
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
};
|
|
898
|
+
__decorate([
|
|
899
|
+
attr({ attribute: "cell-type" })
|
|
900
|
+
], DataGridCell$1.prototype, "cellType", void 0);
|
|
901
|
+
__decorate([
|
|
902
|
+
attr({ attribute: "grid-column" })
|
|
903
|
+
], DataGridCell$1.prototype, "gridColumn", void 0);
|
|
904
|
+
__decorate([
|
|
905
|
+
observable
|
|
906
|
+
], DataGridCell$1.prototype, "rowData", void 0);
|
|
907
|
+
__decorate([
|
|
908
|
+
observable
|
|
909
|
+
], DataGridCell$1.prototype, "columnDefinition", void 0);
|
|
910
|
+
|
|
911
|
+
const dataGridStyles = ":host {\n display: block;\n}\n\n:host([generate-header=sticky]) {\n max-block-size: 400px;\n}\n\n.base {\n position: relative;\n overflow: auto;\n block-size: inherit;\n inline-size: 100%;\n max-block-size: inherit;\n}\n.base::-webkit-scrollbar {\n display: none;\n}";
|
|
912
|
+
|
|
913
|
+
const dataGridRowStyles = "/**\n * Do not edit directly\n * Generated on Wed, 06 Sep 2023 09:40:36 GMT\n */\n.base {\n display: grid;\n width: 100%;\n box-sizing: border-box;\n color: var(--vvd-color-canvas-text);\n}\n.base.connotation-cta {\n /* @cssprop [--vvd-data-grid-row-cta-primary=var(--vvd-color-cta-500)] */\n --_connotation-color-primary: var(--vvd-data-grid-row-cta-primary, var(--vvd-color-cta-500));\n /* @cssprop [--vvd-data-grid-row-cta-primary-text=var(--vvd-color-canvas)] */\n --_connotation-color-primary-text: var(--vvd-data-grid-row-cta-primary-text, var(--vvd-color-canvas));\n /* @cssprop [--vvd-data-grid-row-cta-primary-increment=var(--vvd-color-cta-600)] */\n --_connotation-color-primary-increment: var(--vvd-data-grid-row-cta-primary-increment, var(--vvd-color-cta-600));\n /* @cssprop [--vvd-data-grid-row-cta-faint=var(--vvd-color-cta-50)] */\n --_connotation-color-faint: var(--vvd-data-grid-row-cta-faint, var(--vvd-color-cta-50));\n /* @cssprop [--vvd-data-grid-row-cta-pale=var(--vvd-color-cta-300)] */\n --_connotation-color-pale: var(--vvd-data-grid-row-cta-pale, var(--vvd-color-cta-300));\n /* @cssprop [--vvd-data-grid-row-cta-dim=var(--vvd-color-cta-200)] */\n --_connotation-color-dim: var(--vvd-data-grid-row-cta-dim, var(--vvd-color-cta-200));\n}\n.base:not(.connotation-cta) {\n /* @cssprop [--vvd-data-grid-row-accent-primary=var(--vvd-color-canvas-text)] */\n --_connotation-color-primary: var(--vvd-data-grid-row-accent-primary, var(--vvd-color-canvas-text));\n /* @cssprop [--vvd-data-grid-row-accent-primary-text=var(--vvd-color-canvas)] */\n --_connotation-color-primary-text: var(--vvd-data-grid-row-accent-primary-text, var(--vvd-color-canvas));\n /* @cssprop [--vvd-data-grid-row-accent-primary-increment=var(--vvd-color-neutral-800)] */\n --_connotation-color-primary-increment: var(--vvd-data-grid-row-accent-primary-increment, var(--vvd-color-neutral-800));\n /* @cssprop [--vvd-data-grid-row-accent-faint=var(--vvd-color-neutral-50)] */\n --_connotation-color-faint: var(--vvd-data-grid-row-accent-faint, var(--vvd-color-neutral-50));\n /* @cssprop [--vvd-data-grid-row-accent-pale=var(--vvd-color-neutral-300)] */\n --_connotation-color-pale: var(--vvd-data-grid-row-accent-pale, var(--vvd-color-neutral-300));\n /* @cssprop [--vvd-data-grid-row-accent-dim=var(--vvd-color-neutral-200)] */\n --_connotation-color-dim: var(--vvd-data-grid-row-accent-dim, var(--vvd-color-neutral-200));\n}\n.base {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: transparent;\n --_appearance-color-outline: transparent;\n}\n.base:where(:hover, .hover):where(:not(:disabled, .disabled, .readonly)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-faint);\n --_appearance-color-outline: transparent;\n}\n.base:where(.selected, [aria-current]):where(:not(:disabled, .disabled, :hover, .hover)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-dim);\n --_appearance-color-outline: transparent;\n}\n.base:where(.selected, [aria-current]):where(:hover, .hover) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-pale);\n --_appearance-color-outline: transparent;\n}\n:host([row-type=sticky-header]) .base {\n position: sticky;\n z-index: 9;\n top: 0;\n background: var(--data-grid-row-background, var(--vvd-color-canvas));\n}\n:host([row-type=hidden-header]) .base {\n display: none;\n}\n:host(:is([aria-selected]):not([row-type=header])) .base {\n background-color: var(--_appearance-color-fill);\n}";
|
|
914
|
+
|
|
915
|
+
const dataGridCellStyles = "/**\n * Do not edit directly\n * Generated on Wed, 06 Sep 2023 09:40:36 GMT\n */\n:host {\n min-inline-size: 80px;\n}\n\n.base {\n position: relative;\n display: flex;\n box-sizing: border-box;\n align-items: center;\n padding: 8px 12px;\n border-bottom: 1px solid var(--vvd-color-neutral-400);\n block-size: calc(1px * (40 + 4 * clamp(-1, var(--vvd-size-density, 0), 2) + 8));\n color: var(--_appearance-color-text);\n font: var(--vvd-typography-base);\n}\n.base.connotation-cta {\n /* @cssprop [--vvd-data-grid-cell-cta-primary=var(--vvd-color-cta-500)] */\n --_connotation-color-primary: var(--vvd-data-grid-cell-cta-primary, var(--vvd-color-cta-500));\n /* @cssprop [--vvd-data-grid-cell-cta-primary-text=var(--vvd-color-canvas)] */\n --_connotation-color-primary-text: var(--vvd-data-grid-cell-cta-primary-text, var(--vvd-color-canvas));\n /* @cssprop [--vvd-data-grid-cell-cta-primary-increment=var(--vvd-color-cta-600)] */\n --_connotation-color-primary-increment: var(--vvd-data-grid-cell-cta-primary-increment, var(--vvd-color-cta-600));\n /* @cssprop [--vvd-data-grid-cell-cta-faint=var(--vvd-color-cta-50)] */\n --_connotation-color-faint: var(--vvd-data-grid-cell-cta-faint, var(--vvd-color-cta-50));\n /* @cssprop [--vvd-data-grid-cell-cta-pale=var(--vvd-color-cta-300)] */\n --_connotation-color-pale: var(--vvd-data-grid-cell-cta-pale, var(--vvd-color-cta-300));\n /* @cssprop [--vvd-data-grid-cell-cta-dim=var(--vvd-color-cta-200)] */\n --_connotation-color-dim: var(--vvd-data-grid-cell-cta-dim, var(--vvd-color-cta-200));\n}\n.base:not(.connotation-cta) {\n /* @cssprop [--vvd-data-grid-cell-accent-primary=var(--vvd-color-canvas-text)] */\n --_connotation-color-primary: var(--vvd-data-grid-cell-accent-primary, var(--vvd-color-canvas-text));\n /* @cssprop [--vvd-data-grid-cell-accent-primary-text=var(--vvd-color-canvas)] */\n --_connotation-color-primary-text: var(--vvd-data-grid-cell-accent-primary-text, var(--vvd-color-canvas));\n /* @cssprop [--vvd-data-grid-cell-accent-primary-increment=var(--vvd-color-neutral-800)] */\n --_connotation-color-primary-increment: var(--vvd-data-grid-cell-accent-primary-increment, var(--vvd-color-neutral-800));\n /* @cssprop [--vvd-data-grid-cell-accent-faint=var(--vvd-color-neutral-50)] */\n --_connotation-color-faint: var(--vvd-data-grid-cell-accent-faint, var(--vvd-color-neutral-50));\n /* @cssprop [--vvd-data-grid-cell-accent-pale=var(--vvd-color-neutral-300)] */\n --_connotation-color-pale: var(--vvd-data-grid-cell-accent-pale, var(--vvd-color-neutral-300));\n /* @cssprop [--vvd-data-grid-cell-accent-dim=var(--vvd-color-neutral-200)] */\n --_connotation-color-dim: var(--vvd-data-grid-cell-accent-dim, var(--vvd-color-neutral-200));\n}\n.base {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: transparent;\n --_appearance-color-outline: transparent;\n}\n.base:where(:hover, .hover):where(:not(:disabled, .disabled, .readonly)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-faint);\n --_appearance-color-outline: transparent;\n}\n.base:where(.selected, [aria-current]):where(:not(:disabled, .disabled, :hover, .hover)) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-dim);\n --_appearance-color-outline: transparent;\n}\n.base:where(.selected, [aria-current]):where(:hover, .hover) {\n --_appearance-color-text: var(--_connotation-color-primary);\n --_appearance-color-fill: var(--_connotation-color-pale);\n --_appearance-color-outline: transparent;\n}\n:host([cell-type=columnheader]) .base {\n border-color: var(--vvd-color-canvas-text);\n font: var(--vvd-typography-base-bold);\n}\n:host(:is([aria-selected]):not([cell-type=columnheader])) .base {\n background-color: var(--_appearance-color-fill);\n}\n\n.focus-indicator {\n --focus-stroke-gap-color: transparent;\n pointer-events: none;\n}\n.base:not(.active) > .focus-indicator {\n display: none;\n}\n\nslot {\n display: block;\n overflow: hidden;\n inline-size: 100%;\n text-overflow: ellipsis;\n white-space: nowrap;\n}\n\n.header-icon {\n margin-inline-start: auto;\n}";
|
|
916
|
+
|
|
917
|
+
var __defProp$2 = Object.defineProperty;
|
|
918
|
+
var __getOwnPropDesc$2 = Object.getOwnPropertyDescriptor;
|
|
919
|
+
var __decorateClass$2 = (decorators, target, key, kind) => {
|
|
920
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$2(target, key) : target;
|
|
921
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
922
|
+
if (decorator = decorators[i])
|
|
923
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
924
|
+
if (kind && result)
|
|
925
|
+
__defProp$2(target, key, result);
|
|
926
|
+
return result;
|
|
927
|
+
};
|
|
928
|
+
const DataGridSelectionMode = {
|
|
929
|
+
none: "none",
|
|
930
|
+
singleRow: "single-row",
|
|
931
|
+
multiRow: "multi-row",
|
|
932
|
+
singleCell: "single-cell",
|
|
933
|
+
multiCell: "multi-cell"
|
|
934
|
+
};
|
|
935
|
+
class DataGrid extends DataGrid$1 {
|
|
936
|
+
constructor() {
|
|
937
|
+
super();
|
|
938
|
+
this.#handleKeypress = (e) => {
|
|
939
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
940
|
+
this.#handleClick(e);
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
this.#handleClick = ({ target, ctrlKey, shiftKey, metaKey }) => {
|
|
944
|
+
if (target.getAttribute("role") !== "gridcell")
|
|
945
|
+
return;
|
|
946
|
+
if (this.selectionMode === DataGridSelectionMode.singleCell || this.selectionMode === DataGridSelectionMode.multiCell) {
|
|
947
|
+
this.#handleCellSelection({ target, ctrlKey, shiftKey, metaKey });
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
if (this.selectionMode === DataGridSelectionMode.singleRow || this.selectionMode === DataGridSelectionMode.multiRow) {
|
|
951
|
+
this.#handleRowSelection({ target, ctrlKey, shiftKey, metaKey });
|
|
952
|
+
}
|
|
953
|
+
};
|
|
954
|
+
this.#handleCellSelection = ({ target, ctrlKey, shiftKey, metaKey }) => {
|
|
955
|
+
const cell = target;
|
|
956
|
+
if (this.selectionMode === DataGridSelectionMode.multiCell && (ctrlKey || shiftKey || metaKey)) {
|
|
957
|
+
this.#setSelectedState(cell, !this.#selectedCells.includes(cell));
|
|
958
|
+
} else {
|
|
959
|
+
const cacheTargetSelection = cell.getAttribute("aria-selected") === "true";
|
|
960
|
+
this.#resetSelection();
|
|
961
|
+
this.#setSelectedState(cell, !cacheTargetSelection);
|
|
962
|
+
}
|
|
963
|
+
};
|
|
964
|
+
this.#handleRowSelection = ({ target, ctrlKey, shiftKey, metaKey }) => {
|
|
965
|
+
const row = target.parentNode;
|
|
966
|
+
if (this.selectionMode === DataGridSelectionMode.multiRow && (ctrlKey || shiftKey || metaKey)) {
|
|
967
|
+
this.#setSelectedState(row, !this.#selectedRows.includes(row));
|
|
968
|
+
} else {
|
|
969
|
+
const cacheTargetSelection = row.getAttribute("aria-selected") === "true";
|
|
970
|
+
this.#resetSelection();
|
|
971
|
+
this.#setSelectedState(row, !cacheTargetSelection);
|
|
972
|
+
}
|
|
973
|
+
};
|
|
974
|
+
this.#setSelectedState = (cell, selectedState) => {
|
|
975
|
+
cell.setAttribute("aria-selected", selectedState.toString());
|
|
976
|
+
};
|
|
977
|
+
this.#resetSelection = () => {
|
|
978
|
+
if (this.selectionMode === DataGridSelectionMode.singleCell || this.selectionMode === DataGridSelectionMode.multiCell) {
|
|
979
|
+
Array.from(this.querySelectorAll('[role="gridcell"]')).forEach((cell) => this.#setSelectedState(cell, false));
|
|
980
|
+
Array.from(this.querySelectorAll('[role="row"]')).forEach((row) => row.removeAttribute("aria-selected"));
|
|
981
|
+
}
|
|
982
|
+
if (this.selectionMode === DataGridSelectionMode.none) {
|
|
983
|
+
Array.from(this.querySelectorAll('[role="gridcell"]')).forEach((cell) => cell.removeAttribute("aria-selected"));
|
|
984
|
+
Array.from(this.querySelectorAll('[role="row"]')).forEach((row) => row.removeAttribute("aria-selected"));
|
|
985
|
+
}
|
|
986
|
+
if (this.selectionMode === DataGridSelectionMode.singleRow || this.selectionMode === DataGridSelectionMode.multiRow) {
|
|
987
|
+
Array.from(this.querySelectorAll('[role="gridcell"]')).forEach((cell) => cell.removeAttribute("aria-selected"));
|
|
988
|
+
Array.from(this.querySelectorAll('[role="row"]')).forEach((row) => row.setAttribute("aria-selected", "false"));
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
this.#initSelections = () => {
|
|
992
|
+
if (this.selectionMode === DataGridSelectionMode.singleCell || this.selectionMode === DataGridSelectionMode.multiCell) {
|
|
993
|
+
Array.from(this.querySelectorAll('[role="gridcell"]')).forEach((cell) => !cell.hasAttribute("aria-selected") && this.#setSelectedState(cell, false));
|
|
994
|
+
Array.from(this.querySelectorAll('[role="row"]')).forEach((row) => row.removeAttribute("aria-selected"));
|
|
995
|
+
}
|
|
996
|
+
if (this.selectionMode === DataGridSelectionMode.none) {
|
|
997
|
+
Array.from(this.querySelectorAll('[role="gridcell"]')).forEach((cell) => cell.removeAttribute("aria-selected"));
|
|
998
|
+
Array.from(this.querySelectorAll('[role="row"]')).forEach((row) => row.removeAttribute("aria-selected"));
|
|
999
|
+
}
|
|
1000
|
+
if (this.selectionMode === DataGridSelectionMode.singleRow || this.selectionMode === DataGridSelectionMode.multiRow) {
|
|
1001
|
+
Array.from(this.querySelectorAll('[role="gridcell"]')).forEach((cell) => cell.removeAttribute("aria-selected"));
|
|
1002
|
+
Array.from(this.querySelectorAll('[role="row"]')).forEach((row) => !row.hasAttribute("aria-selected") && row.setAttribute("aria-selected", "false"));
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
this.addEventListener("click", this.#handleClick);
|
|
1006
|
+
this.addEventListener("keydown", this.#handleKeypress);
|
|
1007
|
+
}
|
|
1008
|
+
get #selectedRows() {
|
|
1009
|
+
return this.rowElements.filter((row) => row.getAttribute("aria-selected") === "true");
|
|
1010
|
+
}
|
|
1011
|
+
get #selectedCells() {
|
|
1012
|
+
return this.rowElements.reduce((acc, row) => {
|
|
1013
|
+
const rowChildren = Array.from(row.children);
|
|
1014
|
+
const selectedCells = rowChildren.filter((cell) => cell.getAttribute("aria-selected") === "true");
|
|
1015
|
+
return acc.concat(selectedCells);
|
|
1016
|
+
}, []);
|
|
1017
|
+
}
|
|
1018
|
+
selectionModeChanged(oldValue) {
|
|
1019
|
+
if (oldValue === void 0) {
|
|
1020
|
+
DOM.queueUpdate(this.#initSelections);
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
this.#resetSelection();
|
|
1024
|
+
}
|
|
1025
|
+
#handleKeypress;
|
|
1026
|
+
#handleClick;
|
|
1027
|
+
#handleCellSelection;
|
|
1028
|
+
#handleRowSelection;
|
|
1029
|
+
#setSelectedState;
|
|
1030
|
+
#resetSelection;
|
|
1031
|
+
#initSelections;
|
|
1032
|
+
static generateColumns(rowData) {
|
|
1033
|
+
return Object.keys(rowData).map((property, index) => {
|
|
1034
|
+
return {
|
|
1035
|
+
columnDataKey: property,
|
|
1036
|
+
gridColumn: `${index}`
|
|
1037
|
+
};
|
|
1038
|
+
});
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
__decorateClass$2([
|
|
1042
|
+
attr({ attribute: "selection-mode" })
|
|
1043
|
+
], DataGrid.prototype, "selectionMode", 2);
|
|
1044
|
+
|
|
1045
|
+
var __defProp$1 = Object.defineProperty;
|
|
1046
|
+
var __getOwnPropDesc$1 = Object.getOwnPropertyDescriptor;
|
|
1047
|
+
var __decorateClass$1 = (decorators, target, key, kind) => {
|
|
1048
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc$1(target, key) : target;
|
|
1049
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1050
|
+
if (decorator = decorators[i])
|
|
1051
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1052
|
+
if (kind && result)
|
|
1053
|
+
__defProp$1(target, key, result);
|
|
1054
|
+
return result;
|
|
1055
|
+
};
|
|
1056
|
+
class DataGridRow extends DataGridRow$1 {
|
|
1057
|
+
constructor() {
|
|
1058
|
+
super(...arguments);
|
|
1059
|
+
this.ariaSelected = null;
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
__decorateClass$1([
|
|
1063
|
+
attr({ attribute: "aria-selected" })
|
|
1064
|
+
], DataGridRow.prototype, "ariaSelected", 2);
|
|
1065
|
+
|
|
1066
|
+
const DataGridCellSortStates = {
|
|
1067
|
+
none: "none",
|
|
1068
|
+
ascending: "ascending",
|
|
1069
|
+
descending: "descending",
|
|
1070
|
+
other: "other"
|
|
1071
|
+
};
|
|
1072
|
+
const GenerateHeaderOptions = {
|
|
1073
|
+
none: "none",
|
|
1074
|
+
default: "default",
|
|
1075
|
+
sticky: "sticky"
|
|
1076
|
+
};
|
|
1077
|
+
const DataGridRowTypes = {
|
|
1078
|
+
default: "default",
|
|
1079
|
+
header: "header",
|
|
1080
|
+
stickyHeader: "sticky-header"
|
|
1081
|
+
};
|
|
1082
|
+
const DataGridCellRole = {
|
|
1083
|
+
columnheader: "columnheader",
|
|
1084
|
+
rowheader: "rowheader",
|
|
1085
|
+
default: "gridcell"
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
function createRowItemTemplate(context) {
|
|
1089
|
+
const rowTag = context.tagFor(DataGridRow);
|
|
1090
|
+
return html`
|
|
1091
|
+
<${rowTag}
|
|
1092
|
+
:rowData="${(x) => x}"
|
|
1093
|
+
:cellItemTemplate="${(_, c) => c.parent.cellItemTemplate}"
|
|
1094
|
+
:headerCellItemTemplate="${(_, c) => c.parent.headerCellItemTemplate}"
|
|
1095
|
+
></${rowTag}>
|
|
1096
|
+
`;
|
|
1097
|
+
}
|
|
1098
|
+
function getMultiSelectAriaState(x) {
|
|
1099
|
+
return x.selectionMode === void 0 || x.selectionMode === DataGridSelectionMode.none ? null : x.selectionMode.includes("multi") ? "true" : "false";
|
|
1100
|
+
}
|
|
1101
|
+
function setHeaderRow(x) {
|
|
1102
|
+
if (x.columnDefinitions === null) {
|
|
1103
|
+
const headerRow = x.querySelector('[cell-type="columnheader"]')?.parentElement;
|
|
1104
|
+
if (headerRow) {
|
|
1105
|
+
const rowType = x.generateHeader === GenerateHeaderOptions.sticky ? DataGridRowTypes.stickyHeader : x.generateHeader === GenerateHeaderOptions.default ? DataGridRowTypes.header : "hidden-header";
|
|
1106
|
+
headerRow.setAttribute("row-type", rowType);
|
|
1107
|
+
}
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
function handleColumnSort(_, { event }) {
|
|
1111
|
+
event.stopPropagation();
|
|
1112
|
+
}
|
|
1113
|
+
const DataGridTemplate = (context) => {
|
|
1114
|
+
const rowItemTemplate = createRowItemTemplate(context);
|
|
1115
|
+
const rowTag = context.tagFor(DataGridRow);
|
|
1116
|
+
return html`
|
|
1117
|
+
<template
|
|
1118
|
+
aria-multiselectable="${getMultiSelectAriaState}"
|
|
1119
|
+
role="grid"
|
|
1120
|
+
tabindex="0"
|
|
1121
|
+
@sort="${handleColumnSort}"
|
|
1122
|
+
:rowElementTag="${() => rowTag}"
|
|
1123
|
+
:defaultRowItemTemplate="${rowItemTemplate}"
|
|
1124
|
+
${children({
|
|
1125
|
+
property: "rowElements",
|
|
1126
|
+
filter: elements("[role=row]")
|
|
1127
|
+
})}
|
|
1128
|
+
>
|
|
1129
|
+
<div class="base">
|
|
1130
|
+
${setHeaderRow}
|
|
1131
|
+
<slot></slot>
|
|
1132
|
+
</div>
|
|
1133
|
+
</template>
|
|
1134
|
+
`;
|
|
1135
|
+
};
|
|
1136
|
+
|
|
1137
|
+
var __defProp = Object.defineProperty;
|
|
1138
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
1139
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
1140
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
1141
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
1142
|
+
if (decorator = decorators[i])
|
|
1143
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
1144
|
+
if (kind && result)
|
|
1145
|
+
__defProp(target, key, result);
|
|
1146
|
+
return result;
|
|
1147
|
+
};
|
|
1148
|
+
class DataGridCell extends DataGridCell$1 {
|
|
1149
|
+
constructor() {
|
|
1150
|
+
super();
|
|
1151
|
+
this.ariaSelected = null;
|
|
1152
|
+
this.ariaSort = null;
|
|
1153
|
+
this.updateCellStyle = () => {
|
|
1154
|
+
if (this.gridColumn && !this.gridColumn.includes("undefined")) {
|
|
1155
|
+
this.style.gridColumn = this.gridColumn;
|
|
1156
|
+
} else {
|
|
1157
|
+
this.style.removeProperty("grid-column");
|
|
1158
|
+
}
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1161
|
+
ariaSelectedChanged(_, selectedState) {
|
|
1162
|
+
this.shadowRoot.querySelector(".base")?.classList.toggle("selected", selectedState === "true");
|
|
1163
|
+
}
|
|
1164
|
+
connectedCallback() {
|
|
1165
|
+
super.connectedCallback();
|
|
1166
|
+
this.ariaSelectedChanged(null, this.ariaSelected);
|
|
1167
|
+
}
|
|
1168
|
+
handleFocusin(e) {
|
|
1169
|
+
super.handleFocusin(e);
|
|
1170
|
+
this.shadowRoot.querySelector(".base").classList.add("active");
|
|
1171
|
+
}
|
|
1172
|
+
handleFocusout(e) {
|
|
1173
|
+
super.handleFocusout(e);
|
|
1174
|
+
this.shadowRoot.querySelector(".base").classList.remove("active");
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
__decorateClass([
|
|
1178
|
+
attr({ attribute: "aria-selected", mode: "fromView" })
|
|
1179
|
+
], DataGridCell.prototype, "ariaSelected", 2);
|
|
1180
|
+
__decorateClass([
|
|
1181
|
+
attr({ attribute: "aria-sort" })
|
|
1182
|
+
], DataGridCell.prototype, "ariaSort", 2);
|
|
1183
|
+
|
|
1184
|
+
function createCellItemTemplate(context) {
|
|
1185
|
+
const cellTag = context.tagFor(DataGridCell);
|
|
1186
|
+
return html`
|
|
1187
|
+
<${cellTag}
|
|
1188
|
+
cell-type="${(x) => x.isRowHeader ? "rowheader" : void 0}"
|
|
1189
|
+
grid-column="${(_, c) => c.index + 1}"
|
|
1190
|
+
:rowData="${(_, c) => c.parent.rowData}"
|
|
1191
|
+
:columnDefinition="${(x) => x}"
|
|
1192
|
+
selected="${(_, c) => c.parent.ariaSelected === "true" ? true : null}"
|
|
1193
|
+
></${cellTag}>
|
|
1194
|
+
`;
|
|
1195
|
+
}
|
|
1196
|
+
function createHeaderCellItemTemplate(context) {
|
|
1197
|
+
const cellTag = context.tagFor(DataGridCell);
|
|
1198
|
+
return html`
|
|
1199
|
+
<${cellTag}
|
|
1200
|
+
cell-type="columnheader"
|
|
1201
|
+
grid-column="${(_, c) => c.index + 1}"
|
|
1202
|
+
:columnDefinition="${(x) => x}"
|
|
1203
|
+
></${cellTag}>
|
|
1204
|
+
`;
|
|
1205
|
+
}
|
|
1206
|
+
const DataGridRowTemplate = (context) => {
|
|
1207
|
+
const cellItemTemplate = createCellItemTemplate(context);
|
|
1208
|
+
const headerCellItemTemplate = createHeaderCellItemTemplate(context);
|
|
1209
|
+
return html`
|
|
1210
|
+
<template
|
|
1211
|
+
role="row"
|
|
1212
|
+
class="${(x) => x.rowType !== "default" ? x.rowType : ""}"
|
|
1213
|
+
:defaultCellItemTemplate="${cellItemTemplate}"
|
|
1214
|
+
:defaultHeaderCellItemTemplate="${headerCellItemTemplate}"
|
|
1215
|
+
${children({
|
|
1216
|
+
property: "cellElements",
|
|
1217
|
+
filter: elements('[role="cell"],[role="gridcell"],[role="columnheader"],[role="rowheader"]')
|
|
1218
|
+
})}
|
|
1219
|
+
>
|
|
1220
|
+
<div class="base ${(x) => x.ariaSelected === "true" ? "selected" : ""}"
|
|
1221
|
+
style="grid-template-columns: ${(x) => x.gridTemplateColumns};"
|
|
1222
|
+
>
|
|
1223
|
+
<slot ${slotted("slottedCellElements")}></slot>
|
|
1224
|
+
</div>
|
|
1225
|
+
</template>
|
|
1226
|
+
`;
|
|
1227
|
+
};
|
|
1228
|
+
|
|
1229
|
+
function shouldShowSortIcons(x) {
|
|
1230
|
+
if (x.columnDefinition) {
|
|
1231
|
+
x.ariaSort = !x.columnDefinition.sortable ? null : x.columnDefinition.sortDirection ? x.columnDefinition.sortDirection : DataGridCellSortStates.none;
|
|
1232
|
+
}
|
|
1233
|
+
return x.cellType === "columnheader" && x.ariaSort !== null && x.ariaSort !== DataGridCellSortStates.other;
|
|
1234
|
+
}
|
|
1235
|
+
function getSortIcon(x) {
|
|
1236
|
+
return x.ariaSort === DataGridCellSortStates.ascending ? "sort-asc-solid" : x.ariaSort === DataGridCellSortStates.descending ? "sort-desc-solid" : "sort-solid";
|
|
1237
|
+
}
|
|
1238
|
+
function renderSortIcons(c) {
|
|
1239
|
+
const iconTag = c.tagFor(Icon);
|
|
1240
|
+
return html`
|
|
1241
|
+
${when(shouldShowSortIcons, html`
|
|
1242
|
+
<${iconTag} class="header-icon" name="${getSortIcon}"></${iconTag}>
|
|
1243
|
+
`)}
|
|
1244
|
+
`;
|
|
1245
|
+
}
|
|
1246
|
+
function handleClick(x) {
|
|
1247
|
+
if (x.cellType === "columnheader" && x.ariaSort !== null) {
|
|
1248
|
+
x.$emit(
|
|
1249
|
+
"sort",
|
|
1250
|
+
{ columnDataKey: x.columnDefinition && x.columnDefinition.columnDataKey ? x.columnDefinition.columnDataKey : x.textContent.trim(), sortDirection: x.ariaSort }
|
|
1251
|
+
);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
function DataGridCellTemplate(context) {
|
|
1255
|
+
const focusTemplate = focusTemplateFactory(context);
|
|
1256
|
+
return html`
|
|
1257
|
+
<template
|
|
1258
|
+
tabindex="-1"
|
|
1259
|
+
role="${(x) => DataGridCellRole[x.cellType] ?? DataGridCellRole.default}"
|
|
1260
|
+
@click="${handleClick}"
|
|
1261
|
+
>
|
|
1262
|
+
<div class="base">
|
|
1263
|
+
<slot></slot>
|
|
1264
|
+
${() => focusTemplate}
|
|
1265
|
+
${(_) => renderSortIcons(context)}
|
|
1266
|
+
</div>
|
|
1267
|
+
|
|
1268
|
+
</template>
|
|
1269
|
+
`;
|
|
1270
|
+
}
|
|
1271
|
+
|
|
1272
|
+
const dataGrid = DataGrid.compose({
|
|
1273
|
+
baseName: "data-grid",
|
|
1274
|
+
template: DataGridTemplate,
|
|
1275
|
+
styles: dataGridStyles
|
|
1276
|
+
})();
|
|
1277
|
+
const dataGridRow = DataGridRow.compose({
|
|
1278
|
+
baseName: "data-grid-row",
|
|
1279
|
+
template: DataGridRowTemplate,
|
|
1280
|
+
styles: dataGridRowStyles
|
|
1281
|
+
})();
|
|
1282
|
+
const dataGridCell = DataGridCell.compose({
|
|
1283
|
+
baseName: "data-grid-cell",
|
|
1284
|
+
template: DataGridCellTemplate,
|
|
1285
|
+
styles: dataGridCellStyles
|
|
1286
|
+
})();
|
|
1287
|
+
const dataGridElements = [dataGridCell, dataGridRow, dataGrid, ...iconRegistries];
|
|
1288
|
+
const registerDataGrid = registerFactory(dataGridElements);
|
|
1289
|
+
|
|
1290
|
+
export { dataGridRow as a, dataGridCell as b, dataGridElements as c, dataGrid as d, registerDataGrid as r };
|