@redvars/peacock 3.15.0 → 3.17.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.
Files changed (157) hide show
  1. package/dist/assets/styles.css +1 -1
  2. package/dist/assets/styles.css.map +1 -1
  3. package/dist/assets/theme.js +19 -19
  4. package/dist/assets/tokens.css +1 -1
  5. package/dist/assets/tokens.css.map +1 -1
  6. package/dist/card-content.js +8 -7
  7. package/dist/card-content.js.map +1 -1
  8. package/dist/card.js +142 -98
  9. package/dist/card.js.map +1 -1
  10. package/dist/{chart-bar-D5dGFJfK.js → cartesian-chart-DgE4USyC.js} +529 -312
  11. package/dist/cartesian-chart-DgE4USyC.js.map +1 -0
  12. package/dist/chart-area.js +78 -0
  13. package/dist/chart-area.js.map +1 -0
  14. package/dist/chart-bar.js +283 -213
  15. package/dist/chart-bar.js.map +1 -1
  16. package/dist/{transform-DSwFSqzD.js → chart-base-C2qRMF48.js} +771 -102
  17. package/dist/chart-base-C2qRMF48.js.map +1 -0
  18. package/dist/chart-doughnut.js +55 -287
  19. package/dist/chart-doughnut.js.map +1 -1
  20. package/dist/chart-line.js +626 -0
  21. package/dist/chart-line.js.map +1 -0
  22. package/dist/chart-pie.js +637 -195
  23. package/dist/chart-pie.js.map +1 -1
  24. package/dist/code-editor.js +704 -131
  25. package/dist/code-editor.js.map +1 -1
  26. package/dist/code-group.js +188 -0
  27. package/dist/code-group.js.map +1 -0
  28. package/dist/code-highlighter.js +895 -257
  29. package/dist/code-highlighter.js.map +1 -1
  30. package/dist/custom-elements-jsdocs.json +2278 -677
  31. package/dist/custom-elements.json +13962 -3690
  32. package/dist/image.js +5 -1
  33. package/dist/image.js.map +1 -1
  34. package/dist/index.js +8 -7
  35. package/dist/index.js.map +1 -1
  36. package/dist/loader-full.js +1 -1
  37. package/dist/loader.js +9 -3
  38. package/dist/loader.js.map +1 -1
  39. package/dist/{is-dark-mode-DOcaw4Yq.js → observe-theme-change-DCifz1uv.js} +2 -6
  40. package/dist/observe-theme-change-DCifz1uv.js.map +1 -0
  41. package/dist/pagination.js +408 -110
  42. package/dist/pagination.js.map +1 -1
  43. package/dist/path-CJ0Arqcy.js +166 -0
  44. package/dist/path-CJ0Arqcy.js.map +1 -0
  45. package/dist/snackbar.js +89 -34
  46. package/dist/snackbar.js.map +1 -1
  47. package/dist/src/__internal/chart/cartesian-chart.d.ts +80 -0
  48. package/dist/src/__internal/chart/chart-base.d.ts +113 -0
  49. package/dist/src/__internal/chart/paths.d.ts +5 -0
  50. package/dist/src/__internal/chart/types.d.ts +42 -0
  51. package/dist/src/card/card-content.d.ts +2 -3
  52. package/dist/src/card/card.d.ts +31 -17
  53. package/dist/src/chart-area/chart-area.d.ts +54 -0
  54. package/dist/src/chart-area/index.d.ts +1 -0
  55. package/dist/src/chart-bar/chart-bar.d.ts +44 -33
  56. package/dist/src/chart-bar/index.d.ts +0 -1
  57. package/dist/src/chart-doughnut/chart-doughnut.d.ts +33 -39
  58. package/dist/src/chart-line/chart-line.d.ts +69 -0
  59. package/dist/src/chart-line/index.d.ts +1 -0
  60. package/dist/src/chart-pie/chart-pie.d.ts +63 -28
  61. package/dist/src/code-editor/code-editor.d.ts +52 -13
  62. package/dist/src/code-editor/editor-theme.d.ts +60 -0
  63. package/dist/src/code-highlighter/code-group.d.ts +52 -0
  64. package/dist/src/code-highlighter/code-highlighter.d.ts +122 -15
  65. package/dist/src/code-highlighter/index.d.ts +1 -0
  66. package/dist/src/code-highlighter/line-ranges.d.ts +24 -0
  67. package/dist/src/code-highlighter/local.d.ts +4 -1
  68. package/dist/src/code-highlighter/token-colors.d.ts +8 -0
  69. package/dist/src/index.d.ts +4 -2
  70. package/dist/src/pagination/page-items.d.ts +14 -0
  71. package/dist/src/pagination/pagination.d.ts +46 -7
  72. package/dist/src/snackbar/snackbar.d.ts +13 -1
  73. package/dist/src/table/table.d.ts +125 -27
  74. package/dist/src/toolbar/toolbar.d.ts +56 -51
  75. package/dist/table.js +1007 -338
  76. package/dist/table.js.map +1 -1
  77. package/dist/test/chart.test.d.ts +1 -0
  78. package/dist/test/code-highlighter.test.d.ts +1 -0
  79. package/dist/test/pagination.test.d.ts +1 -0
  80. package/dist/test/table.test.d.ts +1 -0
  81. package/dist/token-colors-0TFHWbcq.js +81 -0
  82. package/dist/token-colors-0TFHWbcq.js.map +1 -0
  83. package/dist/toolbar.js +195 -184
  84. package/dist/toolbar.js.map +1 -1
  85. package/dist/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +1 -2
  87. package/readme.md +7 -6
  88. package/scss/_code-block.scss +139 -0
  89. package/scss/tokens.css +24 -0
  90. package/src/__internal/chart/cartesian-chart.ts +404 -0
  91. package/src/__internal/chart/chart-base.scss +252 -0
  92. package/src/__internal/chart/chart-base.ts +474 -0
  93. package/src/__internal/chart/paths.ts +28 -0
  94. package/src/__internal/chart/types.ts +49 -0
  95. package/src/card/card-content.ts +12 -9
  96. package/src/card/card.scss +66 -54
  97. package/src/card/card.ts +109 -73
  98. package/src/chart-area/chart-area.ts +82 -0
  99. package/src/chart-area/index.ts +1 -0
  100. package/src/chart-bar/chart-bar.ts +336 -250
  101. package/src/chart-bar/index.ts +0 -1
  102. package/src/chart-doughnut/chart-doughnut.ts +62 -262
  103. package/src/chart-doughnut/demo/index.html +14 -22
  104. package/src/chart-line/chart-line.scss +25 -0
  105. package/src/chart-line/chart-line.ts +346 -0
  106. package/src/chart-line/index.ts +1 -0
  107. package/src/chart-pie/chart-pie.scss +35 -16
  108. package/src/chart-pie/chart-pie.ts +282 -188
  109. package/src/chart-pie/demo/index.html +13 -21
  110. package/src/code-editor/code-editor.scss +132 -36
  111. package/src/code-editor/code-editor.ts +308 -88
  112. package/src/code-editor/demo/index.html +39 -12
  113. package/src/code-editor/editor-theme.ts +213 -0
  114. package/src/code-highlighter/code-group.scss +34 -0
  115. package/src/code-highlighter/code-group.ts +173 -0
  116. package/src/code-highlighter/code-highlighter.scss +226 -111
  117. package/src/code-highlighter/code-highlighter.ts +554 -199
  118. package/src/code-highlighter/demo/index.html +68 -4
  119. package/src/code-highlighter/index.ts +1 -0
  120. package/src/code-highlighter/line-ranges.ts +81 -0
  121. package/src/code-highlighter/local.ts +9 -3
  122. package/src/code-highlighter/token-colors.ts +42 -0
  123. package/src/index.ts +4 -2
  124. package/src/loader.ts +8 -2
  125. package/src/pagination/page-items.ts +50 -0
  126. package/src/pagination/pagination.scss +159 -44
  127. package/src/pagination/pagination.ts +275 -74
  128. package/src/snackbar/demo/index.html +39 -4
  129. package/src/snackbar/snackbar.scss +27 -10
  130. package/src/snackbar/snackbar.ts +80 -37
  131. package/src/table/table.scss +337 -109
  132. package/src/table/table.ts +812 -272
  133. package/src/toolbar/toolbar-colors.scss +6 -7
  134. package/src/toolbar/toolbar.scss +35 -106
  135. package/src/toolbar/toolbar.ts +180 -80
  136. package/dist/array-D5vjT2Xm.js +0 -14
  137. package/dist/array-D5vjT2Xm.js.map +0 -1
  138. package/dist/chart-bar-D5dGFJfK.js.map +0 -1
  139. package/dist/chart-stacked-bar.js +0 -403
  140. package/dist/chart-stacked-bar.js.map +0 -1
  141. package/dist/copy-to-clipboard-upGx-Ueo.js +0 -39
  142. package/dist/copy-to-clipboard-upGx-Ueo.js.map +0 -1
  143. package/dist/is-dark-mode-DOcaw4Yq.js.map +0 -1
  144. package/dist/pie-Dz0IDiPt.js +0 -537
  145. package/dist/pie-Dz0IDiPt.js.map +0 -1
  146. package/dist/pierre-dark-DFWl0m-C.js +0 -4
  147. package/dist/pierre-dark-DFWl0m-C.js.map +0 -1
  148. package/dist/pierre-light-BEkAPImt.js +0 -4
  149. package/dist/pierre-light-BEkAPImt.js.map +0 -1
  150. package/dist/src/chart-bar/chart-stacked-bar.d.ts +0 -78
  151. package/dist/src/code-highlighter/constants.d.ts +0 -1
  152. package/dist/transform-DSwFSqzD.js.map +0 -1
  153. package/src/chart-bar/chart-bar.scss +0 -58
  154. package/src/chart-bar/chart-stacked-bar.ts +0 -398
  155. package/src/chart-doughnut/chart-donut.scss +0 -37
  156. package/src/code-highlighter/constants.ts +0 -117
  157. /package/dist/test/{chart-bar.test.d.ts → card.test.d.ts} +0 -0
@@ -1,49 +1,100 @@
1
1
  import { html, LitElement, nothing } from 'lit';
2
- import { property, state } from 'lit/decorators.js';
2
+ import type { PropertyValues, TemplateResult } from 'lit';
3
+ import { property, query, state } from 'lit/decorators.js';
3
4
  import { classMap } from 'lit/directives/class-map.js';
5
+ import { styleMap } from 'lit/directives/style-map.js';
4
6
  import { unsafeHTML } from 'lit/directives/unsafe-html.js';
5
7
 
6
- import { throttle } from '@/__internal/utils/throttle.js';
7
-
8
8
  import styles from './table.scss';
9
9
  import IndividualComponent from '@/IndividualComponent.js';
10
+ import type { PaginationVariant } from '../pagination/pagination.js';
10
11
 
11
12
  const DEFAULT_CELL_WIDTH = 16; // in rem
13
+ const CHECKBOX_CELL_WIDTH = 3; // in rem
14
+ const SKELETON_ROWS = 5;
15
+
16
+ /** A record shown in one row. */
17
+ export type TableRow = Record<string, any>;
12
18
 
13
19
  export interface TableColumn {
20
+ /** Field of the row shown in this column. */
14
21
  name: string;
22
+ /** Header text. */
15
23
  label: string;
24
+ /** Width in rem. Defaults to 16. */
16
25
  width?: number;
17
- fixed?: boolean;
18
- template?: (row: any, column: TableColumn) => string;
26
+ /**
27
+ * Keeps the column in view while the table scrolls sideways. `true` or `"start"` pins it to
28
+ * the start edge, `"end"` to the end edge (for example a row-actions column).
29
+ */
30
+ fixed?: boolean | 'start' | 'end';
31
+ /** Horizontal alignment. Number columns default to `"end"`, others to `"start"`. */
32
+ align?: 'start' | 'center' | 'end';
33
+ /** Data type. `"number"` aligns to the end and uses tabular figures. */
34
+ type?: 'text' | 'number';
35
+ /** Set to `false` to turn sorting off for this column only. */
36
+ sortable?: boolean;
37
+ /** Lets long text wrap instead of truncating with an ellipsis. */
38
+ wrap?: boolean;
39
+ /**
40
+ * Custom cell content. Return a Lit `TemplateResult` (preferred), or a string of trusted
41
+ * HTML. A string is inserted as HTML without escaping, so never build it from user input.
42
+ */
43
+ template?: (row: TableRow, column: TableColumn) => string | TemplateResult;
19
44
  }
20
45
 
46
+ type ColumnPlacement = 'start' | 'scroll' | 'end';
47
+
48
+ /** A rendered column: a data column, or the selection checkbox column. */
49
+ interface GridColumn {
50
+ column?: TableColumn;
51
+ placement: ColumnPlacement;
52
+ }
53
+
54
+ const collator = new Intl.Collator(undefined, {
55
+ numeric: true,
56
+ sensitivity: 'base',
57
+ });
58
+
21
59
  /**
22
60
  * @label Table
23
61
  * @tag wc-table
24
62
  * @rawTag table
25
63
  * @summary A configurable component for displaying tabular data.
26
64
  * @overview
27
- * <p>The table component displays rows of data with support for sorting, pagination, row selection, and fixed columns.</p>
65
+ * <p>The table displays rows of data with sorting, pagination, row selection, sticky header and sticky start or end columns.</p>
66
+ * <p>It follows the grid keyboard pattern: the table is one tab stop and the arrow keys move between cells. <kbd>Space</kbd> selects the focused row, <kbd>Enter</kbd> activates the focused cell, and <kbd>Ctrl</kbd>+<kbd>C</kbd> copies its text.</p>
67
+ * <p>When rows are selected, a bar over the header shows the count and the actions placed in the <code>bulk-actions</code> slot.</p>
68
+ *
69
+ * @fires {CustomEvent} cell-click - Dispatched when a cell is clicked or activated with Enter. Detail: `{ record, column, altKey, ctrlKey, metaKey, shiftKey }`.
70
+ * @fires {CustomEvent} row-click - Dispatched when a row is clicked or activated with Enter. Detail: `{ record }`.
71
+ * @fires {CustomEvent} selection-change - Dispatched when the row selection changes. Detail: `{ value, isSelectAll, allPages }`.
72
+ * @fires {CustomEvent} sort - Dispatched when the table is sorted. Detail: `{ sortBy, sortOrder }`.
73
+ * @fires {CustomEvent} page - Dispatched when the page or page size changes. Detail: `{ page, pageSize }`.
74
+ *
75
+ * @slot bulk-actions - Actions shown in the selection bar while rows are selected.
28
76
  *
29
- * @fires {CustomEvent} cell-click - Dispatched when a table cell is clicked.
30
- * @fires {CustomEvent} selection-change - Dispatched when the row selection changes.
31
- * @fires {CustomEvent} sort - Dispatched when the table is sorted.
32
- * @fires {CustomEvent} page - Dispatched when the page or page size changes.
77
+ * @cssprop --table-row-height - Minimum height of a row. Set by `density`.
78
+ * @cssprop --table-border-color - Color of the row dividers.
79
+ * @cssprop --table-cell-padding-inline - Horizontal padding of a cell.
33
80
  *
34
81
  * @example
35
82
  * ```html
36
- * <wc-table columns="[{'name': 'name','label': 'Name','width': 16},{'name': 'age','label': 'Age','width': 7}]" data="[{'name': 'John','age': 30},{'name': 'Jane','age': 25}]"></wc-table>
83
+ * <wc-table columns="[{'name': 'name','label': 'Name','width': 16},{'name': 'age','label': 'Age','width': 7,'type': 'number'}]" data="[{'name': 'John','age': 30},{'name': 'Jane','age': 25}]"></wc-table>
37
84
  * ```
38
85
  * @tags display, data
39
86
  */
40
87
  @IndividualComponent
41
88
  export class Table extends LitElement {
89
+ // ── Static ───────────────────────────────────────────────────────────────
90
+
42
91
  static styles = [styles];
43
92
 
93
+ // ── Properties ───────────────────────────────────────────────────────────
94
+
44
95
  /**
45
96
  * Grid columns configuration.
46
- * Each column can have: name, label, width (px), fixed (boolean), template (function).
97
+ * Each column can have: name, label, width (rem), fixed, align, type, sortable, wrap, template.
47
98
  */
48
99
  @property({ type: Array })
49
100
  columns: TableColumn[] = [];
@@ -52,7 +103,7 @@ export class Table extends LitElement {
52
103
  * Grid data to display on table.
53
104
  */
54
105
  @property({ type: Array })
55
- data: any[] = [];
106
+ data: TableRow[] = [];
56
107
 
57
108
  /**
58
109
  * Row selection type. Set to `"checkbox"` to enable checkbox selection.
@@ -97,7 +148,7 @@ export class Table extends LitElement {
97
148
  sortOrder: 'asc' | 'desc' = 'asc';
98
149
 
99
150
  /**
100
- * If true, pagination is enabled. Defaults to `true`.
151
+ * If true, pagination is enabled. Defaults to `false`.
101
152
  */
102
153
  @property({ type: Boolean })
103
154
  paginate: boolean = false;
@@ -115,11 +166,55 @@ export class Table extends LitElement {
115
166
  pageSize: number = 10;
116
167
 
117
168
  /**
118
- * Total number of items (used in managed/controlled mode).
169
+ * Supported page size options, passed to the pagination.
170
+ */
171
+ @property({ type: Array, attribute: 'page-sizes' })
172
+ pageSizes: number[] | undefined;
173
+
174
+ /**
175
+ * Total number of items (used in managed/controlled mode). Leave it unset when the total is
176
+ * unknown; the pagination then shows previous and next, driven by `has-next`.
119
177
  */
120
178
  @property({ type: Number, attribute: 'total-items' })
121
179
  totalItems: number | undefined;
122
180
 
181
+ /**
182
+ * Whether another page exists after this one, in managed mode with an unknown total.
183
+ */
184
+ @property({ type: Boolean, attribute: 'has-next' })
185
+ hasNext: boolean = false;
186
+
187
+ /**
188
+ * Pagination variant: `full` (page numbers), `compact` or `simple`. Defaults to `full`.
189
+ */
190
+ @property({ type: String, attribute: 'pagination-variant' })
191
+ paginationVariant: PaginationVariant = 'full';
192
+
193
+ /**
194
+ * Row height: `compact`, `default` or `comfortable`. Defaults to `default`.
195
+ */
196
+ @property({ type: String, reflect: true })
197
+ density: 'compact' | 'default' | 'comfortable' = 'default';
198
+
199
+ /**
200
+ * Shades every other row.
201
+ */
202
+ @property({ type: Boolean, reflect: true })
203
+ striped: boolean = false;
204
+
205
+ /**
206
+ * Shows a loading state: skeleton rows while there is no data, otherwise a progress bar
207
+ * under the header so the current rows stay readable.
208
+ */
209
+ @property({ type: Boolean, reflect: true })
210
+ loading: boolean = false;
211
+
212
+ /**
213
+ * Accessible name of the table.
214
+ */
215
+ @property({ type: String })
216
+ label: string = '';
217
+
123
218
  /**
124
219
  * Headline text shown when the table has no data.
125
220
  */
@@ -132,60 +227,254 @@ export class Table extends LitElement {
132
227
  @property({ type: String, attribute: 'empty-state-description' })
133
228
  emptyStateDescription: string = 'There are no items to display';
134
229
 
135
- /** Tracks the currently hovered row and column for hover-highlight CSS. */
230
+ // ── States ───────────────────────────────────────────────────────────────
231
+
232
+ /** True when every item across all pages is selected, not only the current page. */
136
233
  @state()
137
- private hoveredCell: { row?: any; column?: any } = {};
234
+ private allPagesSelected: boolean = false;
138
235
 
139
- /** True when all rows on the current page are selected. */
236
+ /** True when content is scrolled under the start-pinned columns. */
140
237
  @state()
141
- private isSelectAll: boolean = false;
238
+ private scrolledFromStart: boolean = false;
142
239
 
143
- /** True when some (but not all) rows on the current page are selected. */
240
+ /** True when more content waits past the end-pinned columns. */
144
241
  @state()
145
- private isSelectAllIntermediate: boolean = false;
242
+ private scrolledFromEnd: boolean = false;
146
243
 
147
- /** True when the scroll container has been scrolled horizontally. */
244
+ /** The cell that holds the grid's single tab stop. Row 0 is the header. */
148
245
  @state()
149
- private isHorizontallyScrolled: boolean = false;
150
-
151
- // ── Private fields ────────────────────────────────────────────────────────
152
-
153
- /** Throttled version of the cell-mouseover handler to avoid excessive state updates. */
154
- private onCellMouseOverThrottled = throttle((row: any, column: any) => {
155
- this.hoveredCell = { row, column };
156
- }, 30);
157
-
158
- private onSelectAllClick = () => {
159
- this.isSelectAll = !this.isSelectAll;
160
- let selectedRowKeys: string[] = [];
161
- if (this.isSelectAll) {
162
- selectedRowKeys = this.data
163
- .slice((this.page - 1) * this.pageSize, this.page * this.pageSize)
164
- .map(row => row[this.keyField]);
246
+ private activeCell: { row: number; col: number } = { row: 0, col: 0 };
247
+
248
+ // ── Queries ──────────────────────────────────────────────────────────────
249
+
250
+ @query('.table-scroll-container')
251
+ private scrollContainer?: HTMLElement;
252
+
253
+ // ── Private fields ───────────────────────────────────────────────────────
254
+
255
+ /** Set when a keyboard move must focus the active cell after the next render. */
256
+ private pendingFocus: boolean = false;
257
+
258
+ /** Watches the scroll container so the edge shadows follow resizes. */
259
+ private resizeObserver?: ResizeObserver;
260
+
261
+ // ── Lifecycle ────────────────────────────────────────────────────────────
262
+
263
+ disconnectedCallback() {
264
+ super.disconnectedCallback();
265
+ this.resizeObserver?.disconnect();
266
+ }
267
+
268
+ firstUpdated() {
269
+ if (typeof ResizeObserver !== 'undefined' && this.scrollContainer) {
270
+ this.resizeObserver = new ResizeObserver(() => this.updateScrollEdges());
271
+ this.resizeObserver.observe(this.scrollContainer);
165
272
  }
166
- this.onSelectChange(selectedRowKeys);
167
- };
273
+ this.updateScrollEdges();
274
+ }
275
+
276
+ protected override willUpdate(changed: PropertyValues<Table>): void {
277
+ if (!Number.isFinite(this.page) || this.page < 1) {
278
+ this.page = 1;
279
+ }
280
+
281
+ // Filtering the data can leave the current page past the end.
282
+ // An empty data set (for example before the first load) keeps the requested page.
283
+ if (
284
+ this.paginate &&
285
+ !this.managed &&
286
+ changed.has('data') &&
287
+ this.data?.length
288
+ ) {
289
+ const lastPage = Math.max(
290
+ 1,
291
+ Math.ceil((this.data?.length ?? 0) / this.pageSize),
292
+ );
293
+ if (this.page > lastPage) this.page = lastPage;
294
+ }
295
+
296
+ if (changed.has('data') && !this.managed) {
297
+ this.allPagesSelected = false;
298
+ }
299
+
300
+ const rowCount = this.getPageRows().length;
301
+ const colCount = this.getGridColumns().length;
302
+ const row = Math.min(this.activeCell.row, rowCount);
303
+ const col = Math.min(this.activeCell.col, Math.max(0, colCount - 1));
304
+ if (row !== this.activeCell.row || col !== this.activeCell.col) {
305
+ this.activeCell = { row, col };
306
+ }
307
+ }
308
+
309
+ protected override updated(changed: PropertyValues<Table>): void {
310
+ if (changed.has('columns') || changed.has('data')) {
311
+ this.updateScrollEdges();
312
+ }
313
+ if (this.pendingFocus) {
314
+ this.pendingFocus = false;
315
+ this.getFocusTarget(this.activeCell.row, this.activeCell.col)?.focus();
316
+ }
317
+ }
318
+
319
+ // ── Private methods ──────────────────────────────────────────────────────
168
320
 
169
- private onRowSelectClick = (row: any) => {
170
- let selectedRowKeys = [...this.selectedRowKeys];
171
- if (selectedRowKeys.includes(row[this.keyField])) {
172
- this.isSelectAll = false;
173
- selectedRowKeys = selectedRowKeys.filter(
174
- rowId => rowId !== row[this.keyField],
321
+ /** Columns in visual order: checkbox, start-pinned, scrolling, end-pinned. */
322
+ private getGridColumns(): GridColumn[] {
323
+ const start: GridColumn[] = [];
324
+ const scroll: GridColumn[] = [];
325
+ const end: GridColumn[] = [];
326
+
327
+ if (this.selectionType === 'checkbox') {
328
+ start.push({ placement: 'start' });
329
+ }
330
+ (this.columns ?? []).forEach(column => {
331
+ const placement = Table.getPlacement(column);
332
+ const entry = { column, placement };
333
+ if (placement === 'start') start.push(entry);
334
+ else if (placement === 'end') end.push(entry);
335
+ else scroll.push(entry);
336
+ });
337
+ return [...start, ...scroll, ...end];
338
+ }
339
+
340
+ private static getPlacement(column: TableColumn): ColumnPlacement {
341
+ if (column.fixed === true || column.fixed === 'start') return 'start';
342
+ if (column.fixed === 'end') return 'end';
343
+ return 'scroll';
344
+ }
345
+
346
+ private static getAlign(column: TableColumn): 'start' | 'center' | 'end' {
347
+ return column.align ?? (column.type === 'number' ? 'end' : 'start');
348
+ }
349
+
350
+ private static getWidth(column: TableColumn): number {
351
+ const width = Number.parseFloat(String(column.width ?? ''));
352
+ return Number.isFinite(width) && width > 0 ? width : DEFAULT_CELL_WIDTH;
353
+ }
354
+
355
+ private get totalColumnsWidth(): number {
356
+ let total = this.selectionType === 'checkbox' ? CHECKBOX_CELL_WIDTH : 0;
357
+ (this.columns ?? []).forEach(col => {
358
+ total += Table.getWidth(col);
359
+ });
360
+ return total;
361
+ }
362
+
363
+ private isColumnSortable(column: TableColumn): boolean {
364
+ return this.sortable && column.sortable !== false;
365
+ }
366
+
367
+ /** Total item count across pages, or `undefined` when it is unknown. */
368
+ private getTotalItems(): number | undefined {
369
+ if (!this.managed) return this.data?.length ?? 0;
370
+ return this.totalItems ?? undefined;
371
+ }
372
+
373
+ /** Rows shown on the current page, sorted and sliced unless the table is managed. */
374
+ private getPageRows(): TableRow[] {
375
+ let rows = [...(this.data ?? [])];
376
+ if (this.managed) return rows;
377
+
378
+ if (this.sortable && this.sortBy) {
379
+ const direction = this.sortOrder === 'desc' ? -1 : 1;
380
+ const key = this.sortBy;
381
+ rows = rows.sort((a, b) => Table.compare(a?.[key], b?.[key]) * direction);
382
+ }
383
+ if (this.paginate) {
384
+ rows = rows.slice(
385
+ (this.page - 1) * this.pageSize,
386
+ this.page * this.pageSize,
175
387
  );
388
+ }
389
+ return rows;
390
+ }
391
+
392
+ /** Compares numbers by value and everything else as text with natural number order. */
393
+ private static compare(a: unknown, b: unknown): number {
394
+ if (a === b) return 0;
395
+ if (a === undefined || a === null || a === '') return 1;
396
+ if (b === undefined || b === null || b === '') return -1;
397
+ if (typeof a === 'number' && typeof b === 'number') return a - b;
398
+ return collator.compare(String(a), String(b));
399
+ }
400
+
401
+ private getRowKey(row: TableRow): string {
402
+ return row?.[this.keyField];
403
+ }
404
+
405
+ private onSortClick(col: TableColumn) {
406
+ if (this.sortBy === col.name) {
407
+ if (this.sortOrder === 'asc') {
408
+ this.sortOrder = 'desc';
409
+ } else {
410
+ this.sortBy = '';
411
+ this.sortOrder = 'asc';
412
+ }
176
413
  } else {
177
- selectedRowKeys.push(row[this.keyField]);
414
+ this.sortBy = col.name;
415
+ this.sortOrder = 'asc';
178
416
  }
179
- this.onSelectChange(selectedRowKeys);
180
- };
417
+ this.dispatchEvent(
418
+ new CustomEvent('sort', {
419
+ detail: { sortBy: this.sortBy, sortOrder: this.sortOrder },
420
+ bubbles: true,
421
+ composed: true,
422
+ }),
423
+ );
424
+ }
425
+
426
+ private onSelectAllClick(pageRows: TableRow[]) {
427
+ const pageKeys = pageRows.map(row => this.getRowKey(row));
428
+ const allSelected =
429
+ pageKeys.length > 0 &&
430
+ pageKeys.every(key => this.selectedRowKeys.includes(key));
431
+
432
+ const next = allSelected
433
+ ? this.selectedRowKeys.filter(key => !pageKeys.includes(key))
434
+ : [...new Set([...this.selectedRowKeys, ...pageKeys])];
435
+ this.allPagesSelected = false;
436
+ this.onSelectChange(next, pageRows);
437
+ }
438
+
439
+ private onRowSelectClick(row: TableRow, pageRows: TableRow[]) {
440
+ const key = this.getRowKey(row);
441
+ const next = this.selectedRowKeys.includes(key)
442
+ ? this.selectedRowKeys.filter(rowKey => rowKey !== key)
443
+ : [...this.selectedRowKeys, key];
444
+ this.allPagesSelected = false;
445
+ this.onSelectChange(next, pageRows);
446
+ }
447
+
448
+ private selectAllPages(pageRows: TableRow[]) {
449
+ // Without the full data set (managed mode), the flag tells the owner to act on every item.
450
+ const keys = this.managed
451
+ ? [
452
+ ...new Set([
453
+ ...this.selectedRowKeys,
454
+ ...pageRows.map(row => this.getRowKey(row)),
455
+ ]),
456
+ ]
457
+ : (this.data ?? []).map(row => this.getRowKey(row));
458
+ this.allPagesSelected = true;
459
+ this.onSelectChange(keys, pageRows);
460
+ }
461
+
462
+ private clearSelection() {
463
+ this.allPagesSelected = false;
464
+ this.onSelectChange([], this.getPageRows());
465
+ }
181
466
 
182
- private onSelectChange(selectedRowKeys: string[]) {
467
+ private onSelectChange(selectedRowKeys: string[], pageRows: TableRow[]) {
183
468
  this.selectedRowKeys = selectedRowKeys;
469
+ const isSelectAll =
470
+ pageRows.length > 0 &&
471
+ pageRows.every(row => selectedRowKeys.includes(this.getRowKey(row)));
184
472
  this.dispatchEvent(
185
473
  new CustomEvent('selection-change', {
186
474
  detail: {
187
475
  value: this.selectedRowKeys,
188
- isSelectAll: this.isSelectAll,
476
+ isSelectAll,
477
+ allPages: this.allPagesSelected,
189
478
  },
190
479
  bubbles: true,
191
480
  composed: true,
@@ -193,7 +482,17 @@ export class Table extends LitElement {
193
482
  );
194
483
  }
195
484
 
196
- private onCellClick(row: any, col: TableColumn, evt: MouseEvent) {
485
+ private onCellClick(row: TableRow, col: TableColumn, evt: MouseEvent) {
486
+ const selection = window.getSelection();
487
+ if (selection?.type === 'Range') return;
488
+ this.dispatchCellEvents(row, col, evt);
489
+ }
490
+
491
+ private dispatchCellEvents(
492
+ row: TableRow,
493
+ col: TableColumn,
494
+ evt: MouseEvent | KeyboardEvent,
495
+ ) {
197
496
  this.dispatchEvent(
198
497
  new CustomEvent('cell-click', {
199
498
  detail: {
@@ -208,235 +507,410 @@ export class Table extends LitElement {
208
507
  composed: true,
209
508
  }),
210
509
  );
510
+ this.dispatchEvent(
511
+ new CustomEvent('row-click', {
512
+ detail: { record: row },
513
+ bubbles: true,
514
+ composed: true,
515
+ }),
516
+ );
211
517
  }
212
518
 
213
- private onScrollContainer = (event: Event) => {
214
- const target = event.target as HTMLElement;
215
- this.isHorizontallyScrolled = !!target.scrollLeft;
519
+ private onPage(event: CustomEvent<{ page: number; pageSize: number }>) {
520
+ event.stopPropagation();
521
+ this.page = event.detail.page;
522
+ this.pageSize = event.detail.pageSize;
523
+ this.dispatchEvent(
524
+ new CustomEvent('page', {
525
+ detail: { page: this.page, pageSize: this.pageSize },
526
+ bubbles: true,
527
+ composed: true,
528
+ }),
529
+ );
530
+ }
531
+
532
+ private onScrollContainer = () => {
533
+ this.updateScrollEdges();
216
534
  };
217
535
 
218
- private get totalColumnsWidth(): number {
219
- let total = 0;
220
- if (this.selectionType === 'checkbox') {
221
- total += 3; // approximate checkbox column width in rem
222
- }
223
- this.columns.forEach(col => {
224
- total += col.width ?? DEFAULT_CELL_WIDTH;
225
- });
226
- return total;
536
+ private updateScrollEdges() {
537
+ const el = this.scrollContainer;
538
+ if (!el) return;
539
+ // scrollLeft is negative in right-to-left layouts; the magnitude is what matters.
540
+ const scrolled = Math.abs(el.scrollLeft);
541
+ this.scrolledFromStart = scrolled > 0;
542
+ this.scrolledFromEnd = scrolled + el.clientWidth < el.scrollWidth - 1;
227
543
  }
228
544
 
229
- private getTotalItems(): number {
230
- if (this.paginate && !this.managed && this.data) return this.data.length;
231
- return this.totalItems ?? 0;
545
+ private getCell(row: number, col: number): HTMLElement | null {
546
+ return (
547
+ this.renderRoot.querySelector<HTMLElement>(
548
+ `[data-cell][data-row="${row}"][data-col="${col}"]`,
549
+ ) ?? null
550
+ );
232
551
  }
233
552
 
234
- private getSortIcon(col: TableColumn): string {
235
- if (this.sortBy === col.name) {
236
- return this.sortOrder === 'asc'
237
- ? 'keyboard_arrow_up'
238
- : 'keyboard_arrow_down';
239
- }
240
- return 'unfold_more';
553
+ /** The element that takes focus for a cell: its sort button, or the cell itself. */
554
+ private getFocusTarget(row: number, col: number): HTMLElement | null {
555
+ const cell = this.getCell(row, col);
556
+ return cell?.querySelector<HTMLElement>('[data-focus-target]') ?? cell;
241
557
  }
242
558
 
243
- private onSortClick(col: TableColumn) {
244
- if (this.sortBy === col.name) {
245
- if (this.sortOrder === 'asc') {
246
- this.sortOrder = 'desc';
247
- } else {
248
- this.sortBy = '';
249
- }
250
- } else {
251
- this.sortBy = col.name;
252
- this.sortOrder = 'asc';
253
- }
254
- this.dispatchEvent(
255
- new CustomEvent('sort', {
256
- detail: { sortBy: this.sortBy, sortOrder: this.sortOrder },
257
- bubbles: true,
258
- composed: true,
259
- }),
260
- );
559
+ private tabIndexFor(row: number, col: number): string {
560
+ return this.activeCell.row === row && this.activeCell.col === col
561
+ ? '0'
562
+ : '-1';
261
563
  }
262
564
 
263
- private renderHeader() {
264
- const fixedCols: any[] = [];
265
- const scrollCols: any[] = [];
565
+ private onGridFocusIn = (event: FocusEvent) => {
566
+ const cell = (event.target as HTMLElement).closest<HTMLElement>(
567
+ '[data-cell]',
568
+ );
569
+ if (!cell) return;
570
+ const row = Number(cell.dataset.row);
571
+ const col = Number(cell.dataset.col);
572
+ if (row !== this.activeCell.row || col !== this.activeCell.col) {
573
+ this.activeCell = { row, col };
574
+ }
575
+ };
266
576
 
267
- if (this.selectionType === 'checkbox') {
268
- fixedCols.push(html`
269
- <div class="col col-checkbox center">
270
- <div class="col-content">
271
- <wc-checkbox
272
- class="checkbox"
273
- .value=${this.isSelectAll}
274
- .indeterminate=${this.isSelectAllIntermediate}
275
- @change=${this.onSelectAllClick}
276
- ></wc-checkbox>
277
- </div>
278
- </div>
279
- `);
577
+ private onGridKeydown = (event: KeyboardEvent) => {
578
+ const target = event.target as HTMLElement;
579
+ const cell = target.closest<HTMLElement>('[data-cell]');
580
+ // Leave keys alone while focus is on interactive content inside a cell.
581
+ if (!cell || (target !== cell && !target.hasAttribute('data-focus-target')))
582
+ return;
583
+
584
+ const row = Number(cell.dataset.row);
585
+ const col = Number(cell.dataset.col);
586
+ const lastRow = this.getPageRows().length;
587
+ const lastCol = this.getGridColumns().length - 1;
588
+ let next: { row: number; col: number } | undefined;
589
+
590
+ switch (event.key) {
591
+ case 'ArrowRight':
592
+ next = { row, col: Math.min(col + 1, lastCol) };
593
+ break;
594
+ case 'ArrowLeft':
595
+ next = { row, col: Math.max(col - 1, 0) };
596
+ break;
597
+ case 'ArrowDown':
598
+ next = { row: Math.min(row + 1, lastRow), col };
599
+ break;
600
+ case 'ArrowUp':
601
+ next = { row: Math.max(row - 1, 0), col };
602
+ break;
603
+ case 'Home':
604
+ next = { row: event.ctrlKey ? 0 : row, col: 0 };
605
+ break;
606
+ case 'End':
607
+ next = { row: event.ctrlKey ? lastRow : row, col: lastCol };
608
+ break;
609
+ case ' ':
610
+ if (row > 0 && this.selectionType === 'checkbox') {
611
+ event.preventDefault();
612
+ const pageRows = this.getPageRows();
613
+ this.onRowSelectClick(pageRows[row - 1], pageRows);
614
+ }
615
+ return;
616
+ case 'Enter':
617
+ if (row > 0) {
618
+ const pageRows = this.getPageRows();
619
+ const column = this.getGridColumns()[col]?.column;
620
+ if (column) this.dispatchCellEvents(pageRows[row - 1], column, event);
621
+ }
622
+ return;
623
+ case 'c':
624
+ case 'C':
625
+ if ((event.ctrlKey || event.metaKey) && row > 0) {
626
+ window.navigator.clipboard?.writeText(cell.innerText).catch(() => {});
627
+ }
628
+ return;
629
+ default:
630
+ return;
280
631
  }
281
632
 
282
- this.columns.forEach(col => {
283
- const colWidth = col.width
284
- ? parseInt(String(col.width), 10)
285
- : DEFAULT_CELL_WIDTH;
286
- const colEl = html`
287
- <div
288
- class=${classMap({ col: true, sort: this.sortBy === col.name })}
289
- style="width: ${colWidth}rem"
290
- >
291
- <div class="col-content">
292
- <div class="col-text">${col.label}</div>
293
- <div class="col-actions">
294
- ${this.sortable
295
- ? html`
296
- <wc-button
297
- class="col-action"
298
- color="secondary"
299
- variant="text"
300
- @click=${() => this.onSortClick(col)}
301
- >
302
- <wc-icon
303
- slot="icon"
304
- name=${this.getSortIcon(col)}
305
- ></wc-icon>
306
- </wc-button>
307
- `
308
- : nothing}
309
- </div>
310
- </div>
311
- </div>
312
- `;
313
- if (col.fixed) {
314
- fixedCols.push(colEl);
315
- } else {
316
- scrollCols.push(colEl);
317
- }
633
+ event.preventDefault();
634
+ this.activeCell = next;
635
+ this.pendingFocus = true;
636
+ // The cell may already be active (an edge was reached): focus it anyway.
637
+ if (next.row === row && next.col === col) {
638
+ this.pendingFocus = false;
639
+ }
640
+ };
641
+
642
+ // ── Render helpers ───────────────────────────────────────────────────────
643
+
644
+ private renderCellContent(row: TableRow, column: TableColumn) {
645
+ if (column.template) {
646
+ const content = column.template(row, column);
647
+ return html`<div class="cell-template">
648
+ ${typeof content === 'string' ? unsafeHTML(content) : content}
649
+ </div>`;
650
+ }
651
+ const value = row?.[column.name];
652
+ return html`<div class="cell-text" title=${value ?? ''}>${value}</div>`;
653
+ }
654
+
655
+ private cellClasses(entry: GridColumn, extra: Record<string, boolean> = {}) {
656
+ const { column } = entry;
657
+ return classMap({
658
+ cell: true,
659
+ 'cell-checkbox': !column,
660
+ [`align-${column ? Table.getAlign(column) : 'center'}`]: true,
661
+ numeric: column?.type === 'number',
662
+ wrap: !!column?.wrap,
663
+ ...extra,
318
664
  });
665
+ }
319
666
 
667
+ private cellStyle(entry: GridColumn) {
668
+ const width = entry.column
669
+ ? Table.getWidth(entry.column)
670
+ : CHECKBOX_CELL_WIDTH;
671
+ return styleMap({ width: `${width}rem` });
672
+ }
673
+
674
+ /** Splits a row's cells into the start-pinned, scrolling and end-pinned groups. */
675
+ private renderRowGroups(
676
+ columns: GridColumn[],
677
+ renderCell: (entry: GridColumn, index: number) => TemplateResult,
678
+ ) {
679
+ const groups: Record<ColumnPlacement, TemplateResult[]> = {
680
+ start: [],
681
+ scroll: [],
682
+ end: [],
683
+ };
684
+ columns.forEach((entry, index) => {
685
+ groups[entry.placement].push(renderCell(entry, index));
686
+ });
320
687
  return html`
321
- <div class="header">
322
- <div class="row" style="min-width: ${this.totalColumnsWidth}rem">
323
- <div class="fixed-columns columns-container">${fixedCols}</div>
324
- <div class="scrollable-columns columns-container">${scrollCols}</div>
325
- </div>
326
- </div>
688
+ ${groups.start.length
689
+ ? html`<div class="columns pinned-group pinned-group-start" role="none">
690
+ ${groups.start}
691
+ </div>`
692
+ : nothing}
693
+ <div class="columns scroll-group" role="none">${groups.scroll}</div>
694
+ ${groups.end.length
695
+ ? html`<div class="columns pinned-group pinned-group-end" role="none">
696
+ ${groups.end}
697
+ </div>`
698
+ : nothing}
327
699
  `;
328
700
  }
329
701
 
330
- private renderBody() {
331
- let data = [...this.data];
702
+ private renderHeader(columns: GridColumn[], pageRows: TableRow[]) {
703
+ const pageKeys = pageRows.map(row => this.getRowKey(row));
704
+ const selectedOnPage = pageKeys.filter(key =>
705
+ this.selectedRowKeys.includes(key),
706
+ ).length;
707
+ const allOnPage = pageKeys.length > 0 && selectedOnPage === pageKeys.length;
332
708
 
333
- if (!this.managed) {
334
- if (this.sortable && this.sortBy) {
335
- data = data.sort((a, b) => {
336
- if (a[this.sortBy] < b[this.sortBy])
337
- return this.sortOrder === 'asc' ? -1 : 1;
338
- if (a[this.sortBy] > b[this.sortBy])
339
- return this.sortOrder === 'asc' ? 1 : -1;
340
- return 0;
341
- });
342
- }
343
- if (this.paginate) {
344
- data = data.slice(
345
- (this.page - 1) * this.pageSize,
346
- this.page * this.pageSize,
347
- );
348
- }
349
- }
709
+ return html`
710
+ <div class="header" role="rowgroup">
711
+ <div
712
+ class="row"
713
+ role="row"
714
+ aria-rowindex="1"
715
+ style="--_row-min-width: ${this.totalColumnsWidth}rem"
716
+ >
717
+ ${this.renderRowGroups(columns, (entry, index) => {
718
+ const { column } = entry;
719
+ if (!column) {
720
+ return html`
721
+ <div
722
+ class=${this.cellClasses(entry)}
723
+ style=${this.cellStyle(entry)}
724
+ role="columnheader"
725
+ data-cell
726
+ data-row="0"
727
+ data-col=${index}
728
+ tabindex=${this.tabIndexFor(0, index)}
729
+ aria-label="Select all rows on this page"
730
+ @keydown=${(event: KeyboardEvent) => {
731
+ if (event.key === ' ' || event.key === 'Enter') {
732
+ event.preventDefault();
733
+ this.onSelectAllClick(pageRows);
734
+ }
735
+ }}
736
+ >
737
+ <wc-checkbox
738
+ class="checkbox"
739
+ tabindex="-1"
740
+ aria-label="Select all rows on this page"
741
+ .checked=${allOnPage}
742
+ .indeterminate=${selectedOnPage > 0 && !allOnPage}
743
+ ?disabled=${pageKeys.length === 0}
744
+ @change=${() => this.onSelectAllClick(pageRows)}
745
+ ></wc-checkbox>
746
+ </div>
747
+ `;
748
+ }
350
749
 
351
- const rows = data.map(row => {
352
- const fixedCols: any[] = [];
353
- const scrollCols: any[] = [];
354
-
355
- if (this.selectionType === 'checkbox') {
356
- fixedCols.push(html`
357
- <div class="col center col-checkbox">
358
- <div class="col-content">
359
- <wc-checkbox
360
- class="checkbox"
361
- .value=${this.selectedRowKeys.includes(row[this.keyField])}
362
- @change=${() => this.onRowSelectClick(row)}
363
- ></wc-checkbox>
364
- </div>
365
- </div>
366
- `);
367
- }
750
+ const sortable = this.isColumnSortable(column);
751
+ const sorted = this.sortBy === column.name;
752
+ let ariaSort: 'ascending' | 'descending' | 'none' | undefined;
753
+ if (sortable) {
754
+ if (!sorted) ariaSort = 'none';
755
+ else
756
+ ariaSort =
757
+ this.sortOrder === 'asc' ? 'ascending' : 'descending';
758
+ }
368
759
 
369
- this.columns.forEach(column => {
370
- const colWidth = column.width
371
- ? parseInt(String(column.width), 10)
372
- : DEFAULT_CELL_WIDTH;
373
- const colEl = html`
374
- <div
375
- tabindex="0"
376
- class=${classMap({
377
- col: true,
378
- 'col-hover':
379
- this.hoveredCell.row === row &&
380
- this.hoveredCell.column === column,
381
- })}
382
- style="width: ${colWidth}rem"
383
- @mouseover=${() => this.onCellMouseOverThrottled(row, column)}
384
- @focus=${() => this.onCellMouseOverThrottled(row, column)}
385
- @keydown=${(event: KeyboardEvent) => {
386
- if ((event.ctrlKey || event.metaKey) && event.key === 'c') {
387
- const elem = event.target as HTMLElement;
388
- window.navigator.clipboard
389
- .writeText(elem.innerText)
390
- .catch(() => {});
391
- }
392
- }}
393
- @click=${(evt: MouseEvent) => {
394
- const selection = window.getSelection();
395
- if (selection?.type !== 'Range') {
396
- this.onCellClick(row, column, evt);
397
- }
398
- }}
399
- >
400
- <div class="col-content">
401
- ${column.template
402
- ? html`<div class="col-template">
403
- ${unsafeHTML(column.template(row, column))}
404
- </div>`
405
- : html`<div class="col-text" title=${row?.[column.name] ?? ''}>
406
- ${row?.[column.name]}
407
- </div>`}
408
- </div>
409
- </div>
410
- `;
411
- if (column.fixed) {
412
- fixedCols.push(colEl);
413
- } else {
414
- scrollCols.push(colEl);
415
- }
416
- });
760
+ return html`
761
+ <div
762
+ class=${this.cellClasses(entry, { sorted, sortable })}
763
+ style=${this.cellStyle(entry)}
764
+ role="columnheader"
765
+ aria-sort=${ariaSort ?? nothing}
766
+ data-cell
767
+ data-row="0"
768
+ data-col=${index}
769
+ tabindex=${sortable ? nothing : this.tabIndexFor(0, index)}
770
+ >
771
+ ${sortable
772
+ ? html`
773
+ <button
774
+ type="button"
775
+ class="sort-button"
776
+ data-focus-target
777
+ tabindex=${this.tabIndexFor(0, index)}
778
+ @click=${() => this.onSortClick(column)}
779
+ >
780
+ <span class="header-label">${column.label}</span>
781
+ <wc-icon
782
+ class="sort-icon"
783
+ aria-hidden="true"
784
+ name=${sorted && this.sortOrder === 'desc'
785
+ ? 'arrow_downward'
786
+ : 'arrow_upward'}
787
+ ></wc-icon>
788
+ </button>
789
+ `
790
+ : html`<span class="header-label">${column.label}</span>`}
791
+ </div>
792
+ `;
793
+ })}
794
+ </div>
795
+ ${this.loading && pageRows.length
796
+ ? html`<wc-linear-progress
797
+ class="loading-bar"
798
+ indeterminate
799
+ aria-label="Loading"
800
+ ></wc-linear-progress>`
801
+ : nothing}
802
+ </div>
803
+ `;
804
+ }
805
+
806
+ private renderBody(columns: GridColumn[], pageRows: TableRow[]) {
807
+ const rowOffset = this.paginate ? (this.page - 1) * this.pageSize : 0;
808
+ const selectable = this.selectionType === 'checkbox';
809
+
810
+ const rows = pageRows.map((row, rowIndex) => {
811
+ const gridRow = rowIndex + 1;
812
+ const selected =
813
+ selectable && this.selectedRowKeys.includes(this.getRowKey(row));
417
814
 
418
815
  return html`
419
816
  <div
420
- class=${classMap({
421
- row: true,
422
- 'row-hover': this.hoveredCell.row === row,
423
- })}
424
- style="min-width: ${this.totalColumnsWidth}rem"
817
+ class=${classMap({ row: true, selected })}
818
+ role="row"
819
+ aria-rowindex=${rowOffset + rowIndex + 2}
820
+ aria-selected=${selectable ? String(selected) : nothing}
821
+ style="--_row-min-width: ${this.totalColumnsWidth}rem"
425
822
  >
426
- <div class="fixed-columns columns-container">${fixedCols}</div>
427
- <div class="scrollable-columns columns-container">${scrollCols}</div>
823
+ ${this.renderRowGroups(columns, (entry, index) => {
824
+ const { column } = entry;
825
+ if (!column) {
826
+ return html`
827
+ <div
828
+ class=${this.cellClasses(entry)}
829
+ style=${this.cellStyle(entry)}
830
+ role="gridcell"
831
+ data-cell
832
+ data-row=${gridRow}
833
+ data-col=${index}
834
+ tabindex=${this.tabIndexFor(gridRow, index)}
835
+ >
836
+ <wc-checkbox
837
+ class="checkbox"
838
+ tabindex="-1"
839
+ aria-label="Select row"
840
+ .checked=${selected}
841
+ @change=${() => this.onRowSelectClick(row, pageRows)}
842
+ ></wc-checkbox>
843
+ </div>
844
+ `;
845
+ }
846
+ // Enter on a cell is handled by the grid's keydown listener.
847
+ /* eslint-disable lit-a11y/click-events-have-key-events */
848
+ return html`
849
+ <div
850
+ class=${this.cellClasses(entry)}
851
+ style=${this.cellStyle(entry)}
852
+ role="gridcell"
853
+ data-cell
854
+ data-row=${gridRow}
855
+ data-col=${index}
856
+ tabindex=${this.tabIndexFor(gridRow, index)}
857
+ @click=${(evt: MouseEvent) =>
858
+ this.onCellClick(row, column, evt)}
859
+ >
860
+ ${this.renderCellContent(row, column)}
861
+ </div>
862
+ `;
863
+ /* eslint-enable lit-a11y/click-events-have-key-events */
864
+ })}
428
865
  </div>
429
866
  `;
430
867
  });
431
868
 
432
- return html`<div class="body">${rows}</div>`;
869
+ return html`<div class="body" role="rowgroup">${rows}</div>`;
870
+ }
871
+
872
+ private renderSkeletonBody(columns: GridColumn[]) {
873
+ const count = this.paginate ? Math.min(this.pageSize, 10) : SKELETON_ROWS;
874
+ return html`
875
+ <div class="body" role="rowgroup">
876
+ ${Array.from(
877
+ { length: count },
878
+ (_, rowIndex) => html`
879
+ <div
880
+ class="row skeleton-row"
881
+ role="row"
882
+ style="--_row-min-width: ${this.totalColumnsWidth}rem"
883
+ >
884
+ ${this.renderRowGroups(
885
+ columns,
886
+ (entry, index) => html`
887
+ <div
888
+ class=${this.cellClasses(entry)}
889
+ style=${this.cellStyle(entry)}
890
+ role="gridcell"
891
+ >
892
+ <wc-skeleton
893
+ class="skeleton-bar"
894
+ visible
895
+ style=${entry.column
896
+ ? `inline-size: ${40 + ((rowIndex * 7 + index * 13) % 45)}%`
897
+ : nothing}
898
+ ></wc-skeleton>
899
+ </div>
900
+ `,
901
+ )}
902
+ </div>
903
+ `,
904
+ )}
905
+ </div>
906
+ `;
433
907
  }
434
908
 
435
909
  private renderEmptyState() {
436
910
  return html`
437
911
  <div class="empty-table">
438
912
  <wc-empty-state
439
- class="empty-state content-center"
913
+ class="empty-state"
440
914
  headline=${this.emptyStateHeadline}
441
915
  description=${this.emptyStateDescription}
442
916
  ></wc-empty-state>
@@ -444,46 +918,112 @@ export class Table extends LitElement {
444
918
  `;
445
919
  }
446
920
 
921
+ private renderBulkBar(pageRows: TableRow[]) {
922
+ if (this.selectionType !== 'checkbox') return nothing;
923
+ const count = this.selectedRowKeys.length;
924
+ if (count === 0) return nothing;
925
+
926
+ const total = this.getTotalItems();
927
+ const shownCount =
928
+ this.allPagesSelected && total !== undefined ? total : count;
929
+ const pageFullySelected =
930
+ pageRows.length > 0 &&
931
+ pageRows.every(row => this.selectedRowKeys.includes(this.getRowKey(row)));
932
+ const canSelectAllPages =
933
+ this.paginate &&
934
+ !this.allPagesSelected &&
935
+ pageFullySelected &&
936
+ total !== undefined &&
937
+ total > count;
938
+
939
+ return html`
940
+ <div class="bulk-bar" role="region" aria-label="Selection">
941
+ <span class="bulk-count" aria-live="polite"
942
+ >${shownCount} selected</span
943
+ >
944
+ ${canSelectAllPages
945
+ ? html`<wc-button
946
+ class="bulk-select-all"
947
+ variant="text"
948
+ size="sm"
949
+ @click=${() => this.selectAllPages(pageRows)}
950
+ >Select all ${total}</wc-button
951
+ >`
952
+ : nothing}
953
+ <span class="bulk-spacer"></span>
954
+ <slot name="bulk-actions"></slot>
955
+ <wc-button
956
+ class="bulk-clear"
957
+ variant="text"
958
+ size="sm"
959
+ @click=${this.clearSelection}
960
+ >Clear</wc-button
961
+ >
962
+ </div>
963
+ `;
964
+ }
965
+
447
966
  private renderPagination() {
448
967
  if (!this.paginate) return nothing;
449
968
 
450
969
  return html`
451
- <wc-pagination
452
- .page=${this.page}
453
- .pageSize=${this.pageSize}
454
- .totalItems=${this.getTotalItems()}
455
- @page=${(e: CustomEvent) => {
456
- this.page = e.detail.page;
457
- this.pageSize = e.detail.pageSize;
458
- this.dispatchEvent(
459
- new CustomEvent('page', {
460
- detail: { page: this.page, pageSize: this.pageSize },
461
- bubbles: true,
462
- composed: true,
463
- }),
464
- );
465
- }}
466
- ></wc-pagination>
970
+ <div class="table-footer">
971
+ <wc-pagination
972
+ .page=${this.page}
973
+ .pageSize=${this.pageSize}
974
+ .totalItems=${this.getTotalItems()}
975
+ .hasNext=${this.hasNext}
976
+ .variant=${this.paginationVariant}
977
+ .pageSizes=${this.pageSizes ?? [10, 25, 50, 100]}
978
+ @page=${this.onPage}
979
+ ></wc-pagination>
980
+ </div>
467
981
  `;
468
982
  }
469
983
 
984
+ // ── Render ───────────────────────────────────────────────────────────────
985
+
470
986
  render() {
471
- const tableClasses = {
472
- table: true,
473
- sortable: this.sortable,
474
- paginate: this.paginate,
475
- 'horizontal-scrolled': this.isHorizontallyScrolled,
476
- };
987
+ const columns = this.getGridColumns();
988
+ const pageRows = this.getPageRows();
989
+ const total = this.getTotalItems();
990
+ const hasRows = pageRows.length > 0;
991
+
992
+ let body;
993
+ if (hasRows) body = this.renderBody(columns, pageRows);
994
+ else if (this.loading) body = this.renderSkeletonBody(columns);
995
+ else body = this.renderEmptyState();
477
996
 
478
997
  return html`
479
- <div class=${classMap(tableClasses)}>
480
- <div class="table-scroll-container" @scroll=${this.onScrollContainer}>
481
- ${this.renderHeader()}
482
- ${this.data && this.data.length
483
- ? this.renderBody()
484
- : this.renderEmptyState()}
998
+ <div
999
+ class=${classMap({
1000
+ table: true,
1001
+ 'scrolled-from-start': this.scrolledFromStart,
1002
+ 'scrolled-from-end': this.scrolledFromEnd,
1003
+ 'has-selection': this.selectedRowKeys.length > 0,
1004
+ 'has-footer': this.paginate,
1005
+ })}
1006
+ >
1007
+ ${this.renderBulkBar(pageRows)}
1008
+ <div
1009
+ class="table-scroll-container"
1010
+ role="grid"
1011
+ aria-label=${this.label || nothing}
1012
+ aria-busy=${this.loading ? 'true' : nothing}
1013
+ aria-multiselectable=${this.selectionType === 'checkbox'
1014
+ ? 'true'
1015
+ : nothing}
1016
+ aria-rowcount=${this.paginate && total !== undefined
1017
+ ? total + 1
1018
+ : nothing}
1019
+ aria-colcount=${columns.length}
1020
+ @scroll=${this.onScrollContainer}
1021
+ @focusin=${this.onGridFocusIn}
1022
+ @keydown=${this.onGridKeydown}
1023
+ >
1024
+ ${this.renderHeader(columns, pageRows)} ${body}
485
1025
  </div>
486
- <div class="table-footer">${this.renderPagination()}</div>
1026
+ ${this.renderPagination()}
487
1027
  </div>
488
1028
  `;
489
1029
  }