@redvars/peacock 3.14.0 → 3.16.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/dist/table.js CHANGED
@@ -1,9 +1,11 @@
1
1
  import { i, _ as __decorate, I as IndividualComponent, a as i$1, b, A } from './IndividualComponent-Bdwyrvd6.js';
2
2
  import { n } from './property-B49QQ8pS.js';
3
3
  import { r } from './state-DkTK9EGF.js';
4
- import { e } from './class-map-DG7CA1et.js';
4
+ import { e } from './query-CHb9Ft_d.js';
5
+ import { e as e$1 } from './class-map-DG7CA1et.js';
6
+ import { o as o$1 } from './style-map-BQD5Et1D.js';
5
7
  import { o } from './unsafe-html-Ct0N2_UU.js';
6
- import { t as throttle } from './throttle-C7ZAPqtu.js';
8
+ import './base-Cl6v8-BZ.js';
7
9
  import './directive-ZPhl09Yt.js';
8
10
 
9
11
  var css_248z = i`* {
@@ -22,168 +24,400 @@ var css_248z = i`* {
22
24
  :host {
23
25
  display: block;
24
26
  height: 100%;
25
- min-height: 20em;
27
+ min-width: 0;
28
+ --table-row-height: 3rem;
26
29
  --table-border-color: var(--color-outline-variant);
27
- --table-border: 1px solid var(--table-border-color);
28
- --table-col-content-padding: var(--spacing-150, 0.75rem)
29
- var(--spacing-200, 1rem);
30
+ --table-cell-padding-inline: var(--spacing-200, 1rem);
31
+ --table-header-background: var(--color-surface, #fff);
32
+ --table-background: var(--color-surface, #fff);
33
+ --_table-checkbox-width: 3rem;
34
+ --_table-edge-shadow: color-mix(in srgb, var(--color-shadow) 14%, transparent);
35
+ }
36
+
37
+ :host([density=compact]) {
38
+ --table-row-height: 2.25rem;
39
+ --table-cell-padding-inline: var(--spacing-150, 0.75rem);
40
+ }
41
+
42
+ :host([density=comfortable]) {
43
+ --table-row-height: 3.5rem;
30
44
  }
31
45
 
32
46
  .table {
47
+ position: relative;
33
48
  height: 100%;
34
49
  display: flex;
35
50
  flex-direction: column;
36
- background: var(--color-surface, #fff);
51
+ background: var(--table-background);
52
+ color: var(--color-on-surface);
37
53
  font-family: var(--typography-body-medium-font-family);
38
54
  font-size: var(--typography-body-medium-font-size);
39
55
  font-weight: var(--typography-body-medium-font-weight);
40
56
  line-height: var(--typography-body-medium-line-height);
41
57
  letter-spacing: var(--typography-body-medium-letter-spacing);
42
58
  }
43
- .table .table-scroll-container {
59
+
60
+ .table-scroll-container {
61
+ contain: inline-size;
44
62
  position: relative;
63
+ flex: 1 1 auto;
64
+ min-height: 0;
45
65
  overflow: auto;
46
- height: 100%;
47
- }
48
- .table .empty-table {
49
- height: 80%;
50
- display: flex;
51
- align-items: center;
52
- justify-content: center;
53
- }
54
- .table .empty-table .empty-state {
55
- width: 10rem;
56
- }
57
- .table wc-pagination {
58
- border-top: 1px solid var(--table-border-color);
59
- }
60
- .table.horizontal-scrolled .fixed-columns::after {
61
- box-shadow: 10px 0 20px -20px var(--color-outline) inset;
62
- content: " ";
63
- height: 100%;
64
- position: absolute;
65
- top: 0;
66
- right: -20px;
67
- width: 20px;
66
+ outline: none;
68
67
  }
69
68
 
70
69
  .row {
70
+ --_cell-background: var(--table-background);
71
71
  display: flex;
72
- box-sizing: border-box;
73
72
  width: max-content;
74
73
  min-width: 100%;
75
74
  }
76
- .row .columns-container {
75
+
76
+ .columns {
77
77
  display: flex;
78
78
  }
79
- .row .col {
80
- margin: 0;
81
- color: var(--color-on-surface);
79
+
80
+ .scroll-group {
81
+ flex: 1 0 auto;
82
+ isolation: isolate;
83
+ }
84
+ .scroll-group > .cell:last-child {
85
+ flex-grow: 1;
86
+ }
87
+
88
+ .pinned-group {
89
+ position: sticky;
90
+ z-index: 1;
91
+ flex: none;
92
+ }
93
+
94
+ .pinned-group-start {
95
+ inset-inline-start: 0;
96
+ }
97
+
98
+ .pinned-group-end {
99
+ inset-inline-end: 0;
100
+ }
101
+
102
+ .cell {
103
+ position: relative;
104
+ display: flex;
105
+ align-items: center;
82
106
  flex-shrink: 0;
107
+ min-width: 0;
108
+ min-height: var(--table-row-height);
109
+ padding-inline: var(--table-cell-padding-inline);
110
+ background: var(--_cell-background);
111
+ border-bottom: 1px solid var(--table-border-color);
112
+ }
113
+ .cell:focus-visible {
114
+ outline: 2px solid var(--color-primary);
115
+ outline-offset: -2px;
116
+ }
117
+ .cell.align-start {
118
+ justify-content: flex-start;
119
+ text-align: start;
120
+ }
121
+ .cell.align-center {
122
+ justify-content: center;
123
+ text-align: center;
124
+ }
125
+ .cell.align-end {
126
+ justify-content: flex-end;
127
+ text-align: end;
128
+ }
129
+ .cell.numeric {
130
+ font-variant-numeric: tabular-nums;
131
+ }
132
+ .cell.cell-checkbox {
133
+ width: var(--_table-checkbox-width);
134
+ padding-inline: 0;
135
+ }
136
+
137
+ .cell-text {
138
+ min-width: 0;
139
+ overflow: hidden;
140
+ white-space: nowrap;
141
+ text-overflow: ellipsis;
142
+ }
143
+ .wrap .cell-text {
144
+ padding-block: var(--spacing-100, 0.5rem);
145
+ white-space: normal;
146
+ overflow-wrap: anywhere;
83
147
  }
84
- .row .col .col-content {
148
+
149
+ .cell-template {
85
150
  display: flex;
86
151
  align-items: center;
87
- height: 100%;
152
+ min-width: 0;
153
+ max-width: 100%;
88
154
  }
89
- .row .col .col-content .col-text {
90
- padding: var(--table-col-content-padding);
91
- flex: 1;
155
+
156
+ .header {
157
+ position: sticky;
158
+ top: 0;
159
+ z-index: 3;
160
+ }
161
+ .header .row {
162
+ --_cell-background: var(--table-header-background);
163
+ }
164
+ .header .cell {
165
+ color: var(--color-on-surface-variant);
166
+ font-family: var(--typography-label-large-font-family);
167
+ font-size: var(--typography-label-large-font-size);
168
+ font-weight: var(--typography-label-large-font-weight);
169
+ line-height: var(--typography-label-large-line-height);
170
+ letter-spacing: var(--typography-label-large-letter-spacing);
171
+ }
172
+ .header .cell.sortable {
173
+ padding-inline: 0;
174
+ }
175
+ .header .cell.sorted {
176
+ color: var(--color-on-surface);
177
+ }
178
+ .header .header-label {
179
+ min-width: 0;
92
180
  overflow: hidden;
93
181
  white-space: nowrap;
94
182
  text-overflow: ellipsis;
95
183
  }
96
- .row .col .col-content .col-template {
184
+
185
+ .sort-button {
186
+ background: transparent;
187
+ border: none;
188
+ appearance: none;
189
+ margin: 0;
190
+ outline: none;
191
+ padding: 0;
192
+ display: flex;
193
+ align-items: center;
194
+ justify-content: inherit;
195
+ gap: var(--spacing-050, 0.25rem);
196
+ align-self: stretch;
97
197
  width: 100%;
198
+ min-width: 0;
199
+ padding-inline: var(--table-cell-padding-inline);
200
+ color: inherit;
201
+ font: inherit;
202
+ letter-spacing: inherit;
203
+ text-align: inherit;
204
+ cursor: pointer;
98
205
  }
99
- .row .col .col-content .col-action {
100
- --button-container-shape: 0;
206
+ .align-end .sort-button {
207
+ flex-direction: row-reverse;
101
208
  }
102
- .row .col .col-content .checkbox {
103
- padding: 0 var(--spacing-100, 0.5rem);
209
+ .sort-button:hover {
210
+ background: color-mix(in srgb, var(--color-on-surface) 6%, transparent);
104
211
  }
105
- .row .col.center .col-content {
106
- justify-content: center;
212
+ .sort-button:focus-visible {
213
+ outline: 2px solid var(--color-primary);
214
+ outline-offset: -2px;
107
215
  }
108
- .row .col:last-child {
109
- flex: 1;
216
+
217
+ .sort-icon {
218
+ flex: none;
219
+ --icon-size: 1.125rem;
220
+ font-size: 1.125rem;
221
+ opacity: 0;
222
+ transition: opacity var(--duration-short2, 100ms) ease;
110
223
  }
111
- .row .fixed-columns {
112
- position: sticky;
113
- left: 0;
224
+ .sort-button:hover .sort-icon, .sort-button:focus-visible .sort-icon {
225
+ opacity: 0.6;
114
226
  }
115
- .row .scrollable-columns {
116
- flex: 0 0 auto;
227
+ .sorted .sort-icon {
228
+ opacity: 1;
117
229
  }
118
230
 
119
- .header {
120
- position: sticky;
231
+ .loading-bar {
232
+ position: absolute;
233
+ inset-inline: 0;
234
+ bottom: 0;
235
+ --progress-height: 2px;
236
+ }
237
+
238
+ .body .cell {
239
+ cursor: pointer;
240
+ }
241
+ .body .cell.cell-checkbox {
242
+ cursor: default;
243
+ }
244
+ .body .row:hover {
245
+ --_cell-background: var(--color-surface-container-low);
246
+ }
247
+ .body .row.selected {
248
+ --_cell-background: color-mix(
249
+ in srgb,
250
+ var(--color-secondary-container) 55%,
251
+ var(--table-background)
252
+ );
253
+ }
254
+ .body .row.selected > .columns:first-child > .cell:first-child {
255
+ box-shadow: inset 2px 0 0 var(--color-primary);
256
+ }
257
+ .body .row.selected:hover {
258
+ --_cell-background: var(--color-secondary-container);
259
+ }
260
+ .body .skeleton-row .cell {
261
+ cursor: default;
262
+ }
263
+
264
+ :host([striped]) .body .row:nth-child(even):not(.selected) {
265
+ --_cell-background: color-mix(
266
+ in srgb,
267
+ var(--color-surface-container) 45%,
268
+ var(--table-background)
269
+ );
270
+ }
271
+ :host([striped]) .body .row:nth-child(even):not(.selected):hover {
272
+ --_cell-background: var(--color-surface-container-low);
273
+ }
274
+
275
+ .skeleton-bar {
276
+ block-size: 0.75rem;
277
+ max-inline-size: 100%;
278
+ --skeleton-container-shape: var(--shape-corner-extra-small);
279
+ }
280
+ .cell-checkbox .skeleton-bar {
281
+ inline-size: 1.125rem;
282
+ block-size: 1.125rem;
283
+ }
284
+
285
+ .checkbox {
286
+ display: flex;
287
+ }
288
+
289
+ .pinned-group-start::after,
290
+ .pinned-group-end::before {
291
+ content: "";
292
+ position: absolute;
121
293
  top: 0;
122
- font-family: var(--typography-label-medium-font-family);
123
- font-size: var(--typography-label-medium-font-size);
124
- font-weight: var(--typography-label-medium-font-weight);
125
- line-height: var(--typography-label-medium-line-height);
126
- letter-spacing: var(--typography-label-medium-letter-spacing);
294
+ bottom: 0;
295
+ width: 0.75rem;
296
+ pointer-events: none;
297
+ opacity: 0;
298
+ transition: opacity var(--duration-short4, 200ms) ease;
127
299
  }
128
- .header .col {
129
- background: var(--color-surface-variant, #f4f4f4);
300
+
301
+ .pinned-group-start::after {
302
+ inset-inline-end: -0.75rem;
303
+ background: linear-gradient(to right, var(--_table-edge-shadow), transparent);
130
304
  }
131
- .header .col.sort {
132
- background: var(--color-secondary-container, #e8eaf6);
305
+
306
+ .pinned-group-end::before {
307
+ inset-inline-start: -0.75rem;
308
+ background: linear-gradient(to left, var(--_table-edge-shadow), transparent);
133
309
  }
134
310
 
135
- .body .row .col {
136
- cursor: pointer;
137
- background: var(--color-surface, #fff);
138
- border-bottom: 1px solid var(--color-surface-variant, #f4f4f4);
311
+ .scrolled-from-start .pinned-group-start::after,
312
+ .scrolled-from-end .pinned-group-end::before {
313
+ opacity: 1;
139
314
  }
140
- .body .row .col.col-checkbox .col-content {
141
- border: 0;
315
+
316
+ .bulk-bar {
317
+ position: absolute;
318
+ top: 0;
319
+ inset-inline: var(--_table-checkbox-width) 0;
320
+ z-index: 4;
321
+ display: flex;
322
+ align-items: center;
323
+ gap: var(--spacing-100, 0.5rem);
324
+ height: var(--table-row-height);
325
+ padding-inline: var(--spacing-100, 0.5rem) var(--spacing-100, 0.5rem);
326
+ background: var(--color-secondary-container);
327
+ color: var(--color-on-secondary-container);
328
+ border-bottom: 1px solid var(--table-border-color);
329
+ overflow-x: auto;
330
+ scrollbar-width: none;
331
+ white-space: nowrap;
332
+ font-family: var(--typography-label-large-font-family);
333
+ font-size: var(--typography-label-large-font-size);
334
+ font-weight: var(--typography-label-large-font-weight);
335
+ line-height: var(--typography-label-large-line-height);
336
+ letter-spacing: var(--typography-label-large-letter-spacing);
142
337
  }
143
- .body .row .col .col-content {
144
- border: 2px solid transparent;
145
- border-bottom: 1px solid transparent;
338
+ .bulk-bar > *,
339
+ .bulk-bar ::slotted(*) {
340
+ flex: none;
146
341
  }
147
- .body .row .col .col-content .col-text {
148
- text-wrap: wrap;
342
+
343
+ .bulk-count {
344
+ padding-inline-start: var(--spacing-050, 0.25rem);
345
+ white-space: nowrap;
346
+ font-variant-numeric: tabular-nums;
149
347
  }
150
- .body .row .col:focus {
151
- outline: none;
152
- border-bottom-color: var(--color-primary);
348
+
349
+ .bulk-spacer {
350
+ flex: 1;
351
+ }
352
+
353
+ ::slotted([slot=bulk-actions]) {
354
+ display: inline-flex;
355
+ align-items: center;
356
+ gap: var(--spacing-050, 0.25rem);
357
+ }
358
+
359
+ .empty-table {
360
+ position: sticky;
361
+ inset-inline-start: 0;
362
+ display: flex;
363
+ align-items: center;
364
+ justify-content: center;
365
+ min-height: 16rem;
366
+ padding: var(--spacing-400, 2rem) var(--spacing-200, 1rem);
153
367
  }
154
- .body .row .col:focus .col-content {
155
- border-color: var(--color-primary);
368
+ .empty-table .empty-state {
369
+ max-width: 24rem;
156
370
  }
157
- .body .row:hover .col {
158
- background-color: var(--color-surface-container-low, #f8f8f8);
371
+
372
+ .table-footer {
373
+ flex: none;
374
+ border-top: 1px solid var(--table-border-color);
159
375
  }`;
160
376
 
377
+ var Table_1;
161
378
  const DEFAULT_CELL_WIDTH = 16; // in rem
379
+ const CHECKBOX_CELL_WIDTH = 3; // in rem
380
+ const SKELETON_ROWS = 5;
381
+ const collator = new Intl.Collator(undefined, {
382
+ numeric: true,
383
+ sensitivity: 'base',
384
+ });
162
385
  /**
163
386
  * @label Table
164
387
  * @tag wc-table
165
388
  * @rawTag table
166
389
  * @summary A configurable component for displaying tabular data.
167
390
  * @overview
168
- * <p>The table component displays rows of data with support for sorting, pagination, row selection, and fixed columns.</p>
391
+ * <p>The table displays rows of data with sorting, pagination, row selection, sticky header and sticky start or end columns.</p>
392
+ * <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>
393
+ * <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>
394
+ *
395
+ * @fires {CustomEvent} cell-click - Dispatched when a cell is clicked or activated with Enter. Detail: `{ record, column, altKey, ctrlKey, metaKey, shiftKey }`.
396
+ * @fires {CustomEvent} row-click - Dispatched when a row is clicked or activated with Enter. Detail: `{ record }`.
397
+ * @fires {CustomEvent} selection-change - Dispatched when the row selection changes. Detail: `{ value, isSelectAll, allPages }`.
398
+ * @fires {CustomEvent} sort - Dispatched when the table is sorted. Detail: `{ sortBy, sortOrder }`.
399
+ * @fires {CustomEvent} page - Dispatched when the page or page size changes. Detail: `{ page, pageSize }`.
169
400
  *
170
- * @fires {CustomEvent} cell-click - Dispatched when a table cell is clicked.
171
- * @fires {CustomEvent} selection-change - Dispatched when the row selection changes.
172
- * @fires {CustomEvent} sort - Dispatched when the table is sorted.
173
- * @fires {CustomEvent} page - Dispatched when the page or page size changes.
401
+ * @slot bulk-actions - Actions shown in the selection bar while rows are selected.
402
+ *
403
+ * @cssprop --table-row-height - Minimum height of a row. Set by `density`.
404
+ * @cssprop --table-border-color - Color of the row dividers.
405
+ * @cssprop --table-cell-padding-inline - Horizontal padding of a cell.
174
406
  *
175
407
  * @example
176
408
  * ```html
177
- * <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>
409
+ * <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>
178
410
  * ```
179
411
  * @tags display, data
180
412
  */
181
- let Table = class Table extends i$1 {
413
+ let Table = Table_1 = class Table extends i$1 {
182
414
  constructor() {
415
+ // ── Static ───────────────────────────────────────────────────────────────
183
416
  super(...arguments);
417
+ // ── Properties ───────────────────────────────────────────────────────────
184
418
  /**
185
419
  * Grid columns configuration.
186
- * Each column can have: name, label, width (px), fixed (boolean), template (function).
420
+ * Each column can have: name, label, width (rem), fixed, align, type, sortable, wrap, template.
187
421
  */
188
422
  this.columns = [];
189
423
  /**
@@ -215,7 +449,7 @@ let Table = class Table extends i$1 {
215
449
  */
216
450
  this.sortOrder = 'asc';
217
451
  /**
218
- * If true, pagination is enabled. Defaults to `true`.
452
+ * If true, pagination is enabled. Defaults to `false`.
219
453
  */
220
454
  this.paginate = false;
221
455
  /**
@@ -226,6 +460,31 @@ let Table = class Table extends i$1 {
226
460
  * The number of rows per page. Defaults to `10`.
227
461
  */
228
462
  this.pageSize = 10;
463
+ /**
464
+ * Whether another page exists after this one, in managed mode with an unknown total.
465
+ */
466
+ this.hasNext = false;
467
+ /**
468
+ * Pagination variant: `full` (page numbers), `compact` or `simple`. Defaults to `full`.
469
+ */
470
+ this.paginationVariant = 'full';
471
+ /**
472
+ * Row height: `compact`, `default` or `comfortable`. Defaults to `default`.
473
+ */
474
+ this.density = 'default';
475
+ /**
476
+ * Shades every other row.
477
+ */
478
+ this.striped = false;
479
+ /**
480
+ * Shows a loading state: skeleton rows while there is no data, otherwise a progress bar
481
+ * under the header so the current rows stay readable.
482
+ */
483
+ this.loading = false;
484
+ /**
485
+ * Accessible name of the table.
486
+ */
487
+ this.label = '';
229
488
  /**
230
489
  * Headline text shown when the table has no data.
231
490
  */
@@ -234,92 +493,220 @@ let Table = class Table extends i$1 {
234
493
  * Description text shown when the table has no data.
235
494
  */
236
495
  this.emptyStateDescription = 'There are no items to display';
237
- /** Tracks the currently hovered row and column for hover-highlight CSS. */
238
- this.hoveredCell = {};
239
- /** True when all rows on the current page are selected. */
240
- this.isSelectAll = false;
241
- /** True when some (but not all) rows on the current page are selected. */
242
- this.isSelectAllIntermediate = false;
243
- /** True when the scroll container has been scrolled horizontally. */
244
- this.isHorizontallyScrolled = false;
245
- // ── Private fields ────────────────────────────────────────────────────────
246
- /** Throttled version of the cell-mouseover handler to avoid excessive state updates. */
247
- this.onCellMouseOverThrottled = throttle((row, column) => {
248
- this.hoveredCell = { row, column };
249
- }, 30);
250
- this.onSelectAllClick = () => {
251
- this.isSelectAll = !this.isSelectAll;
252
- let selectedRowKeys = [];
253
- if (this.isSelectAll) {
254
- selectedRowKeys = this.data
255
- .slice((this.page - 1) * this.pageSize, this.page * this.pageSize)
256
- .map(row => row[this.keyField]);
257
- }
258
- this.onSelectChange(selectedRowKeys);
496
+ // ── States ───────────────────────────────────────────────────────────────
497
+ /** True when every item across all pages is selected, not only the current page. */
498
+ this.allPagesSelected = false;
499
+ /** True when content is scrolled under the start-pinned columns. */
500
+ this.scrolledFromStart = false;
501
+ /** True when more content waits past the end-pinned columns. */
502
+ this.scrolledFromEnd = false;
503
+ /** The cell that holds the grid's single tab stop. Row 0 is the header. */
504
+ this.activeCell = { row: 0, col: 0 };
505
+ // ── Private fields ───────────────────────────────────────────────────────
506
+ /** Set when a keyboard move must focus the active cell after the next render. */
507
+ this.pendingFocus = false;
508
+ this.onScrollContainer = () => {
509
+ this.updateScrollEdges();
259
510
  };
260
- this.onRowSelectClick = (row) => {
261
- let selectedRowKeys = [...this.selectedRowKeys];
262
- if (selectedRowKeys.includes(row[this.keyField])) {
263
- this.isSelectAll = false;
264
- selectedRowKeys = selectedRowKeys.filter(rowId => rowId !== row[this.keyField]);
265
- }
266
- else {
267
- selectedRowKeys.push(row[this.keyField]);
511
+ this.onGridFocusIn = (event) => {
512
+ const cell = event.target.closest('[data-cell]');
513
+ if (!cell)
514
+ return;
515
+ const row = Number(cell.dataset.row);
516
+ const col = Number(cell.dataset.col);
517
+ if (row !== this.activeCell.row || col !== this.activeCell.col) {
518
+ this.activeCell = { row, col };
268
519
  }
269
- this.onSelectChange(selectedRowKeys);
270
520
  };
271
- this.onScrollContainer = (event) => {
521
+ this.onGridKeydown = (event) => {
272
522
  const target = event.target;
273
- this.isHorizontallyScrolled = !!target.scrollLeft;
523
+ const cell = target.closest('[data-cell]');
524
+ // Leave keys alone while focus is on interactive content inside a cell.
525
+ if (!cell || (target !== cell && !target.hasAttribute('data-focus-target')))
526
+ return;
527
+ const row = Number(cell.dataset.row);
528
+ const col = Number(cell.dataset.col);
529
+ const lastRow = this.getPageRows().length;
530
+ const lastCol = this.getGridColumns().length - 1;
531
+ let next;
532
+ switch (event.key) {
533
+ case 'ArrowRight':
534
+ next = { row, col: Math.min(col + 1, lastCol) };
535
+ break;
536
+ case 'ArrowLeft':
537
+ next = { row, col: Math.max(col - 1, 0) };
538
+ break;
539
+ case 'ArrowDown':
540
+ next = { row: Math.min(row + 1, lastRow), col };
541
+ break;
542
+ case 'ArrowUp':
543
+ next = { row: Math.max(row - 1, 0), col };
544
+ break;
545
+ case 'Home':
546
+ next = { row: event.ctrlKey ? 0 : row, col: 0 };
547
+ break;
548
+ case 'End':
549
+ next = { row: event.ctrlKey ? lastRow : row, col: lastCol };
550
+ break;
551
+ case ' ':
552
+ if (row > 0 && this.selectionType === 'checkbox') {
553
+ event.preventDefault();
554
+ const pageRows = this.getPageRows();
555
+ this.onRowSelectClick(pageRows[row - 1], pageRows);
556
+ }
557
+ return;
558
+ case 'Enter':
559
+ if (row > 0) {
560
+ const pageRows = this.getPageRows();
561
+ const column = this.getGridColumns()[col]?.column;
562
+ if (column)
563
+ this.dispatchCellEvents(pageRows[row - 1], column, event);
564
+ }
565
+ return;
566
+ case 'c':
567
+ case 'C':
568
+ if ((event.ctrlKey || event.metaKey) && row > 0) {
569
+ window.navigator.clipboard?.writeText(cell.innerText).catch(() => { });
570
+ }
571
+ return;
572
+ default:
573
+ return;
574
+ }
575
+ event.preventDefault();
576
+ this.activeCell = next;
577
+ this.pendingFocus = true;
578
+ // The cell may already be active (an edge was reached): focus it anyway.
579
+ if (next.row === row && next.col === col) {
580
+ this.pendingFocus = false;
581
+ }
274
582
  };
275
583
  }
276
- onSelectChange(selectedRowKeys) {
277
- this.selectedRowKeys = selectedRowKeys;
278
- this.dispatchEvent(new CustomEvent('selection-change', {
279
- detail: {
280
- value: this.selectedRowKeys,
281
- isSelectAll: this.isSelectAll,
282
- },
283
- bubbles: true,
284
- composed: true,
285
- }));
584
+ // ── Lifecycle ────────────────────────────────────────────────────────────
585
+ disconnectedCallback() {
586
+ super.disconnectedCallback();
587
+ this.resizeObserver?.disconnect();
286
588
  }
287
- onCellClick(row, col, evt) {
288
- this.dispatchEvent(new CustomEvent('cell-click', {
289
- detail: {
290
- record: row,
291
- column: col,
292
- altKey: evt.altKey,
293
- ctrlKey: evt.ctrlKey,
294
- metaKey: evt.metaKey,
295
- shiftKey: evt.shiftKey,
296
- },
297
- bubbles: true,
298
- composed: true,
299
- }));
589
+ firstUpdated() {
590
+ if (typeof ResizeObserver !== 'undefined' && this.scrollContainer) {
591
+ this.resizeObserver = new ResizeObserver(() => this.updateScrollEdges());
592
+ this.resizeObserver.observe(this.scrollContainer);
593
+ }
594
+ this.updateScrollEdges();
300
595
  }
301
- get totalColumnsWidth() {
302
- let total = 0;
596
+ willUpdate(changed) {
597
+ if (!Number.isFinite(this.page) || this.page < 1) {
598
+ this.page = 1;
599
+ }
600
+ // Filtering the data can leave the current page past the end.
601
+ // An empty data set (for example before the first load) keeps the requested page.
602
+ if (this.paginate &&
603
+ !this.managed &&
604
+ changed.has('data') &&
605
+ this.data?.length) {
606
+ const lastPage = Math.max(1, Math.ceil((this.data?.length ?? 0) / this.pageSize));
607
+ if (this.page > lastPage)
608
+ this.page = lastPage;
609
+ }
610
+ if (changed.has('data') && !this.managed) {
611
+ this.allPagesSelected = false;
612
+ }
613
+ const rowCount = this.getPageRows().length;
614
+ const colCount = this.getGridColumns().length;
615
+ const row = Math.min(this.activeCell.row, rowCount);
616
+ const col = Math.min(this.activeCell.col, Math.max(0, colCount - 1));
617
+ if (row !== this.activeCell.row || col !== this.activeCell.col) {
618
+ this.activeCell = { row, col };
619
+ }
620
+ }
621
+ updated(changed) {
622
+ if (changed.has('columns') || changed.has('data')) {
623
+ this.updateScrollEdges();
624
+ }
625
+ if (this.pendingFocus) {
626
+ this.pendingFocus = false;
627
+ this.getFocusTarget(this.activeCell.row, this.activeCell.col)?.focus();
628
+ }
629
+ }
630
+ // ── Private methods ──────────────────────────────────────────────────────
631
+ /** Columns in visual order: checkbox, start-pinned, scrolling, end-pinned. */
632
+ getGridColumns() {
633
+ const start = [];
634
+ const scroll = [];
635
+ const end = [];
303
636
  if (this.selectionType === 'checkbox') {
304
- total += 3; // approximate checkbox column width in rem
637
+ start.push({ placement: 'start' });
305
638
  }
306
- this.columns.forEach(col => {
307
- total += col.width ?? DEFAULT_CELL_WIDTH;
639
+ (this.columns ?? []).forEach(column => {
640
+ const placement = Table_1.getPlacement(column);
641
+ const entry = { column, placement };
642
+ if (placement === 'start')
643
+ start.push(entry);
644
+ else if (placement === 'end')
645
+ end.push(entry);
646
+ else
647
+ scroll.push(entry);
648
+ });
649
+ return [...start, ...scroll, ...end];
650
+ }
651
+ static getPlacement(column) {
652
+ if (column.fixed === true || column.fixed === 'start')
653
+ return 'start';
654
+ if (column.fixed === 'end')
655
+ return 'end';
656
+ return 'scroll';
657
+ }
658
+ static getAlign(column) {
659
+ return column.align ?? (column.type === 'number' ? 'end' : 'start');
660
+ }
661
+ static getWidth(column) {
662
+ const width = Number.parseFloat(String(column.width ?? ''));
663
+ return Number.isFinite(width) && width > 0 ? width : DEFAULT_CELL_WIDTH;
664
+ }
665
+ get totalColumnsWidth() {
666
+ let total = this.selectionType === 'checkbox' ? CHECKBOX_CELL_WIDTH : 0;
667
+ (this.columns ?? []).forEach(col => {
668
+ total += Table_1.getWidth(col);
308
669
  });
309
670
  return total;
310
671
  }
672
+ isColumnSortable(column) {
673
+ return this.sortable && column.sortable !== false;
674
+ }
675
+ /** Total item count across pages, or `undefined` when it is unknown. */
311
676
  getTotalItems() {
312
- if (this.paginate && !this.managed && this.data)
313
- return this.data.length;
314
- return this.totalItems ?? 0;
677
+ if (!this.managed)
678
+ return this.data?.length ?? 0;
679
+ return this.totalItems ?? undefined;
315
680
  }
316
- getSortIcon(col) {
317
- if (this.sortBy === col.name) {
318
- return this.sortOrder === 'asc'
319
- ? 'keyboard_arrow_up'
320
- : 'keyboard_arrow_down';
681
+ /** Rows shown on the current page, sorted and sliced unless the table is managed. */
682
+ getPageRows() {
683
+ let rows = [...(this.data ?? [])];
684
+ if (this.managed)
685
+ return rows;
686
+ if (this.sortable && this.sortBy) {
687
+ const direction = this.sortOrder === 'desc' ? -1 : 1;
688
+ const key = this.sortBy;
689
+ rows = rows.sort((a, b) => Table_1.compare(a?.[key], b?.[key]) * direction);
690
+ }
691
+ if (this.paginate) {
692
+ rows = rows.slice((this.page - 1) * this.pageSize, this.page * this.pageSize);
321
693
  }
322
- return 'unfold_more';
694
+ return rows;
695
+ }
696
+ /** Compares numbers by value and everything else as text with natural number order. */
697
+ static compare(a, b) {
698
+ if (a === b)
699
+ return 0;
700
+ if (a === undefined || a === null || a === '')
701
+ return 1;
702
+ if (b === undefined || b === null || b === '')
703
+ return -1;
704
+ if (typeof a === 'number' && typeof b === 'number')
705
+ return a - b;
706
+ return collator.compare(String(a), String(b));
707
+ }
708
+ getRowKey(row) {
709
+ return row?.[this.keyField];
323
710
  }
324
711
  onSortClick(col) {
325
712
  if (this.sortBy === col.name) {
@@ -328,6 +715,7 @@ let Table = class Table extends i$1 {
328
715
  }
329
716
  else {
330
717
  this.sortBy = '';
718
+ this.sortOrder = 'asc';
331
719
  }
332
720
  }
333
721
  else {
@@ -340,212 +728,464 @@ let Table = class Table extends i$1 {
340
728
  composed: true,
341
729
  }));
342
730
  }
343
- renderHeader() {
344
- const fixedCols = [];
345
- const scrollCols = [];
346
- if (this.selectionType === 'checkbox') {
347
- fixedCols.push(b `
348
- <div class="col col-checkbox center">
349
- <div class="col-content">
350
- <wc-checkbox
351
- class="checkbox"
352
- .value=${this.isSelectAll}
353
- .indeterminate=${this.isSelectAllIntermediate}
354
- @change=${this.onSelectAllClick}
355
- ></wc-checkbox>
356
- </div>
357
- </div>
358
- `);
731
+ onSelectAllClick(pageRows) {
732
+ const pageKeys = pageRows.map(row => this.getRowKey(row));
733
+ const allSelected = pageKeys.length > 0 &&
734
+ pageKeys.every(key => this.selectedRowKeys.includes(key));
735
+ const next = allSelected
736
+ ? this.selectedRowKeys.filter(key => !pageKeys.includes(key))
737
+ : [...new Set([...this.selectedRowKeys, ...pageKeys])];
738
+ this.allPagesSelected = false;
739
+ this.onSelectChange(next, pageRows);
740
+ }
741
+ onRowSelectClick(row, pageRows) {
742
+ const key = this.getRowKey(row);
743
+ const next = this.selectedRowKeys.includes(key)
744
+ ? this.selectedRowKeys.filter(rowKey => rowKey !== key)
745
+ : [...this.selectedRowKeys, key];
746
+ this.allPagesSelected = false;
747
+ this.onSelectChange(next, pageRows);
748
+ }
749
+ selectAllPages(pageRows) {
750
+ // Without the full data set (managed mode), the flag tells the owner to act on every item.
751
+ const keys = this.managed
752
+ ? [
753
+ ...new Set([
754
+ ...this.selectedRowKeys,
755
+ ...pageRows.map(row => this.getRowKey(row)),
756
+ ]),
757
+ ]
758
+ : (this.data ?? []).map(row => this.getRowKey(row));
759
+ this.allPagesSelected = true;
760
+ this.onSelectChange(keys, pageRows);
761
+ }
762
+ clearSelection() {
763
+ this.allPagesSelected = false;
764
+ this.onSelectChange([], this.getPageRows());
765
+ }
766
+ onSelectChange(selectedRowKeys, pageRows) {
767
+ this.selectedRowKeys = selectedRowKeys;
768
+ const isSelectAll = pageRows.length > 0 &&
769
+ pageRows.every(row => selectedRowKeys.includes(this.getRowKey(row)));
770
+ this.dispatchEvent(new CustomEvent('selection-change', {
771
+ detail: {
772
+ value: this.selectedRowKeys,
773
+ isSelectAll,
774
+ allPages: this.allPagesSelected,
775
+ },
776
+ bubbles: true,
777
+ composed: true,
778
+ }));
779
+ }
780
+ onCellClick(row, col, evt) {
781
+ const selection = window.getSelection();
782
+ if (selection?.type === 'Range')
783
+ return;
784
+ this.dispatchCellEvents(row, col, evt);
785
+ }
786
+ dispatchCellEvents(row, col, evt) {
787
+ this.dispatchEvent(new CustomEvent('cell-click', {
788
+ detail: {
789
+ record: row,
790
+ column: col,
791
+ altKey: evt.altKey,
792
+ ctrlKey: evt.ctrlKey,
793
+ metaKey: evt.metaKey,
794
+ shiftKey: evt.shiftKey,
795
+ },
796
+ bubbles: true,
797
+ composed: true,
798
+ }));
799
+ this.dispatchEvent(new CustomEvent('row-click', {
800
+ detail: { record: row },
801
+ bubbles: true,
802
+ composed: true,
803
+ }));
804
+ }
805
+ onPage(event) {
806
+ event.stopPropagation();
807
+ this.page = event.detail.page;
808
+ this.pageSize = event.detail.pageSize;
809
+ this.dispatchEvent(new CustomEvent('page', {
810
+ detail: { page: this.page, pageSize: this.pageSize },
811
+ bubbles: true,
812
+ composed: true,
813
+ }));
814
+ }
815
+ updateScrollEdges() {
816
+ const el = this.scrollContainer;
817
+ if (!el)
818
+ return;
819
+ // scrollLeft is negative in right-to-left layouts; the magnitude is what matters.
820
+ const scrolled = Math.abs(el.scrollLeft);
821
+ this.scrolledFromStart = scrolled > 0;
822
+ this.scrolledFromEnd = scrolled + el.clientWidth < el.scrollWidth - 1;
823
+ }
824
+ getCell(row, col) {
825
+ return (this.renderRoot.querySelector(`[data-cell][data-row="${row}"][data-col="${col}"]`) ?? null);
826
+ }
827
+ /** The element that takes focus for a cell: its sort button, or the cell itself. */
828
+ getFocusTarget(row, col) {
829
+ const cell = this.getCell(row, col);
830
+ return cell?.querySelector('[data-focus-target]') ?? cell;
831
+ }
832
+ tabIndexFor(row, col) {
833
+ return this.activeCell.row === row && this.activeCell.col === col
834
+ ? '0'
835
+ : '-1';
836
+ }
837
+ // ── Render helpers ───────────────────────────────────────────────────────
838
+ renderCellContent(row, column) {
839
+ if (column.template) {
840
+ const content = column.template(row, column);
841
+ return b `<div class="cell-template">
842
+ ${typeof content === 'string' ? o(content) : content}
843
+ </div>`;
359
844
  }
360
- this.columns.forEach(col => {
361
- const colWidth = col.width
362
- ? parseInt(String(col.width), 10)
363
- : DEFAULT_CELL_WIDTH;
364
- const colEl = b `
845
+ const value = row?.[column.name];
846
+ return b `<div class="cell-text" title=${value ?? ''}>${value}</div>`;
847
+ }
848
+ cellClasses(entry, extra = {}) {
849
+ const { column } = entry;
850
+ return e$1({
851
+ cell: true,
852
+ 'cell-checkbox': !column,
853
+ [`align-${column ? Table_1.getAlign(column) : 'center'}`]: true,
854
+ numeric: column?.type === 'number',
855
+ wrap: !!column?.wrap,
856
+ ...extra,
857
+ });
858
+ }
859
+ cellStyle(entry) {
860
+ const width = entry.column
861
+ ? Table_1.getWidth(entry.column)
862
+ : CHECKBOX_CELL_WIDTH;
863
+ return o$1({ width: `${width}rem` });
864
+ }
865
+ /** Splits a row's cells into the start-pinned, scrolling and end-pinned groups. */
866
+ renderRowGroups(columns, renderCell) {
867
+ const groups = {
868
+ start: [],
869
+ scroll: [],
870
+ end: [],
871
+ };
872
+ columns.forEach((entry, index) => {
873
+ groups[entry.placement].push(renderCell(entry, index));
874
+ });
875
+ return b `
876
+ ${groups.start.length
877
+ ? b `<div class="columns pinned-group pinned-group-start" role="none">
878
+ ${groups.start}
879
+ </div>`
880
+ : A}
881
+ <div class="columns scroll-group" role="none">${groups.scroll}</div>
882
+ ${groups.end.length
883
+ ? b `<div class="columns pinned-group pinned-group-end" role="none">
884
+ ${groups.end}
885
+ </div>`
886
+ : A}
887
+ `;
888
+ }
889
+ renderHeader(columns, pageRows) {
890
+ const pageKeys = pageRows.map(row => this.getRowKey(row));
891
+ const selectedOnPage = pageKeys.filter(key => this.selectedRowKeys.includes(key)).length;
892
+ const allOnPage = pageKeys.length > 0 && selectedOnPage === pageKeys.length;
893
+ return b `
894
+ <div class="header" role="rowgroup">
365
895
  <div
366
- class=${e({ col: true, sort: this.sortBy === col.name })}
367
- style="width: ${colWidth}rem"
896
+ class="row"
897
+ role="row"
898
+ aria-rowindex="1"
899
+ style="min-width: ${this.totalColumnsWidth}rem"
368
900
  >
369
- <div class="col-content">
370
- <div class="col-text">${col.label}</div>
371
- <div class="col-actions">
372
- ${this.sortable
373
- ? b `
374
- <wc-button
375
- class="col-action"
376
- color="secondary"
377
- variant="text"
378
- @click=${() => this.onSortClick(col)}
379
- >
380
- <wc-icon
381
- slot="icon"
382
- name=${this.getSortIcon(col)}
383
- ></wc-icon>
384
- </wc-button>
385
- `
386
- : A}
387
- </div>
388
- </div>
389
- </div>
390
- `;
391
- if (col.fixed) {
392
- fixedCols.push(colEl);
901
+ ${this.renderRowGroups(columns, (entry, index) => {
902
+ const { column } = entry;
903
+ if (!column) {
904
+ return b `
905
+ <div
906
+ class=${this.cellClasses(entry)}
907
+ style=${this.cellStyle(entry)}
908
+ role="columnheader"
909
+ data-cell
910
+ data-row="0"
911
+ data-col=${index}
912
+ tabindex=${this.tabIndexFor(0, index)}
913
+ aria-label="Select all rows on this page"
914
+ @keydown=${(event) => {
915
+ if (event.key === ' ' || event.key === 'Enter') {
916
+ event.preventDefault();
917
+ this.onSelectAllClick(pageRows);
918
+ }
919
+ }}
920
+ >
921
+ <wc-checkbox
922
+ class="checkbox"
923
+ tabindex="-1"
924
+ aria-label="Select all rows on this page"
925
+ .checked=${allOnPage}
926
+ .indeterminate=${selectedOnPage > 0 && !allOnPage}
927
+ ?disabled=${pageKeys.length === 0}
928
+ @change=${() => this.onSelectAllClick(pageRows)}
929
+ ></wc-checkbox>
930
+ </div>
931
+ `;
393
932
  }
394
- else {
395
- scrollCols.push(colEl);
933
+ const sortable = this.isColumnSortable(column);
934
+ const sorted = this.sortBy === column.name;
935
+ let ariaSort;
936
+ if (sortable) {
937
+ if (!sorted)
938
+ ariaSort = 'none';
939
+ else
940
+ ariaSort =
941
+ this.sortOrder === 'asc' ? 'ascending' : 'descending';
396
942
  }
397
- });
398
- return b `
399
- <div class="header">
400
- <div class="row" style="min-width: ${this.totalColumnsWidth}rem">
401
- <div class="fixed-columns columns-container">${fixedCols}</div>
402
- <div class="scrollable-columns columns-container">${scrollCols}</div>
943
+ return b `
944
+ <div
945
+ class=${this.cellClasses(entry, { sorted, sortable })}
946
+ style=${this.cellStyle(entry)}
947
+ role="columnheader"
948
+ aria-sort=${ariaSort ?? A}
949
+ data-cell
950
+ data-row="0"
951
+ data-col=${index}
952
+ tabindex=${sortable ? A : this.tabIndexFor(0, index)}
953
+ >
954
+ ${sortable
955
+ ? b `
956
+ <button
957
+ type="button"
958
+ class="sort-button"
959
+ data-focus-target
960
+ tabindex=${this.tabIndexFor(0, index)}
961
+ @click=${() => this.onSortClick(column)}
962
+ >
963
+ <span class="header-label">${column.label}</span>
964
+ <wc-icon
965
+ class="sort-icon"
966
+ aria-hidden="true"
967
+ name=${sorted && this.sortOrder === 'desc'
968
+ ? 'arrow_downward'
969
+ : 'arrow_upward'}
970
+ ></wc-icon>
971
+ </button>
972
+ `
973
+ : b `<span class="header-label">${column.label}</span>`}
974
+ </div>
975
+ `;
976
+ })}
403
977
  </div>
978
+ ${this.loading && pageRows.length
979
+ ? b `<wc-linear-progress
980
+ class="loading-bar"
981
+ indeterminate
982
+ aria-label="Loading"
983
+ ></wc-linear-progress>`
984
+ : A}
404
985
  </div>
405
986
  `;
406
987
  }
407
- renderBody() {
408
- let data = [...this.data];
409
- if (!this.managed) {
410
- if (this.sortable && this.sortBy) {
411
- data = data.sort((a, b) => {
412
- if (a[this.sortBy] < b[this.sortBy])
413
- return this.sortOrder === 'asc' ? -1 : 1;
414
- if (a[this.sortBy] > b[this.sortBy])
415
- return this.sortOrder === 'asc' ? 1 : -1;
416
- return 0;
417
- });
418
- }
419
- if (this.paginate) {
420
- data = data.slice((this.page - 1) * this.pageSize, this.page * this.pageSize);
421
- }
422
- }
423
- const rows = data.map(row => {
424
- const fixedCols = [];
425
- const scrollCols = [];
426
- if (this.selectionType === 'checkbox') {
427
- fixedCols.push(b `
428
- <div class="col center col-checkbox">
429
- <div class="col-content">
430
- <wc-checkbox
431
- class="checkbox"
432
- .value=${this.selectedRowKeys.includes(row[this.keyField])}
433
- @change=${() => this.onRowSelectClick(row)}
434
- ></wc-checkbox>
435
- </div>
436
- </div>
437
- `);
438
- }
439
- this.columns.forEach(column => {
440
- const colWidth = column.width
441
- ? parseInt(String(column.width), 10)
442
- : DEFAULT_CELL_WIDTH;
443
- const colEl = b `
444
- <div
445
- tabindex="0"
446
- class=${e({
447
- col: true,
448
- 'col-hover': this.hoveredCell.row === row &&
449
- this.hoveredCell.column === column,
450
- })}
451
- style="width: ${colWidth}rem"
452
- @mouseover=${() => this.onCellMouseOverThrottled(row, column)}
453
- @focus=${() => this.onCellMouseOverThrottled(row, column)}
454
- @keydown=${(event) => {
455
- if ((event.ctrlKey || event.metaKey) && event.key === 'c') {
456
- const elem = event.target;
457
- window.navigator.clipboard
458
- .writeText(elem.innerText)
459
- .catch(() => { });
460
- }
461
- }}
462
- @click=${(evt) => {
463
- const selection = window.getSelection();
464
- if (selection?.type !== 'Range') {
465
- this.onCellClick(row, column, evt);
466
- }
467
- }}
468
- >
469
- <div class="col-content">
470
- ${column.template
471
- ? b `<div class="col-template">
472
- ${o(column.template(row, column))}
473
- </div>`
474
- : b `<div class="col-text" title=${row?.[column.name] ?? ''}>
475
- ${row?.[column.name]}
476
- </div>`}
477
- </div>
478
- </div>
479
- `;
480
- if (column.fixed) {
481
- fixedCols.push(colEl);
482
- }
483
- else {
484
- scrollCols.push(colEl);
485
- }
486
- });
988
+ renderBody(columns, pageRows) {
989
+ const rowOffset = this.paginate ? (this.page - 1) * this.pageSize : 0;
990
+ const selectable = this.selectionType === 'checkbox';
991
+ const rows = pageRows.map((row, rowIndex) => {
992
+ const gridRow = rowIndex + 1;
993
+ const selected = selectable && this.selectedRowKeys.includes(this.getRowKey(row));
487
994
  return b `
488
995
  <div
489
- class=${e({
490
- row: true,
491
- 'row-hover': this.hoveredCell.row === row,
492
- })}
996
+ class=${e$1({ row: true, selected })}
997
+ role="row"
998
+ aria-rowindex=${rowOffset + rowIndex + 2}
999
+ aria-selected=${selectable ? String(selected) : A}
493
1000
  style="min-width: ${this.totalColumnsWidth}rem"
494
1001
  >
495
- <div class="fixed-columns columns-container">${fixedCols}</div>
496
- <div class="scrollable-columns columns-container">${scrollCols}</div>
1002
+ ${this.renderRowGroups(columns, (entry, index) => {
1003
+ const { column } = entry;
1004
+ if (!column) {
1005
+ return b `
1006
+ <div
1007
+ class=${this.cellClasses(entry)}
1008
+ style=${this.cellStyle(entry)}
1009
+ role="gridcell"
1010
+ data-cell
1011
+ data-row=${gridRow}
1012
+ data-col=${index}
1013
+ tabindex=${this.tabIndexFor(gridRow, index)}
1014
+ >
1015
+ <wc-checkbox
1016
+ class="checkbox"
1017
+ tabindex="-1"
1018
+ aria-label="Select row"
1019
+ .checked=${selected}
1020
+ @change=${() => this.onRowSelectClick(row, pageRows)}
1021
+ ></wc-checkbox>
1022
+ </div>
1023
+ `;
1024
+ }
1025
+ // Enter on a cell is handled by the grid's keydown listener.
1026
+ /* eslint-disable lit-a11y/click-events-have-key-events */
1027
+ return b `
1028
+ <div
1029
+ class=${this.cellClasses(entry)}
1030
+ style=${this.cellStyle(entry)}
1031
+ role="gridcell"
1032
+ data-cell
1033
+ data-row=${gridRow}
1034
+ data-col=${index}
1035
+ tabindex=${this.tabIndexFor(gridRow, index)}
1036
+ @click=${(evt) => this.onCellClick(row, column, evt)}
1037
+ >
1038
+ ${this.renderCellContent(row, column)}
1039
+ </div>
1040
+ `;
1041
+ /* eslint-enable lit-a11y/click-events-have-key-events */
1042
+ })}
497
1043
  </div>
498
1044
  `;
499
1045
  });
500
- return b `<div class="body">${rows}</div>`;
1046
+ return b `<div class="body" role="rowgroup">${rows}</div>`;
1047
+ }
1048
+ renderSkeletonBody(columns) {
1049
+ const count = this.paginate ? Math.min(this.pageSize, 10) : SKELETON_ROWS;
1050
+ return b `
1051
+ <div class="body" role="rowgroup">
1052
+ ${Array.from({ length: count }, (_, rowIndex) => b `
1053
+ <div
1054
+ class="row skeleton-row"
1055
+ role="row"
1056
+ style="min-width: ${this.totalColumnsWidth}rem"
1057
+ >
1058
+ ${this.renderRowGroups(columns, (entry, index) => b `
1059
+ <div
1060
+ class=${this.cellClasses(entry)}
1061
+ style=${this.cellStyle(entry)}
1062
+ role="gridcell"
1063
+ >
1064
+ <wc-skeleton
1065
+ class="skeleton-bar"
1066
+ visible
1067
+ style=${entry.column
1068
+ ? `inline-size: ${40 + ((rowIndex * 7 + index * 13) % 45)}%`
1069
+ : A}
1070
+ ></wc-skeleton>
1071
+ </div>
1072
+ `)}
1073
+ </div>
1074
+ `)}
1075
+ </div>
1076
+ `;
501
1077
  }
502
1078
  renderEmptyState() {
503
1079
  return b `
504
1080
  <div class="empty-table">
505
1081
  <wc-empty-state
506
- class="empty-state content-center"
1082
+ class="empty-state"
507
1083
  headline=${this.emptyStateHeadline}
508
1084
  description=${this.emptyStateDescription}
509
1085
  ></wc-empty-state>
510
1086
  </div>
511
1087
  `;
512
1088
  }
1089
+ renderBulkBar(pageRows) {
1090
+ if (this.selectionType !== 'checkbox')
1091
+ return A;
1092
+ const count = this.selectedRowKeys.length;
1093
+ if (count === 0)
1094
+ return A;
1095
+ const total = this.getTotalItems();
1096
+ const shownCount = this.allPagesSelected && total !== undefined ? total : count;
1097
+ const pageFullySelected = pageRows.length > 0 &&
1098
+ pageRows.every(row => this.selectedRowKeys.includes(this.getRowKey(row)));
1099
+ const canSelectAllPages = this.paginate &&
1100
+ !this.allPagesSelected &&
1101
+ pageFullySelected &&
1102
+ total !== undefined &&
1103
+ total > count;
1104
+ return b `
1105
+ <div class="bulk-bar" role="region" aria-label="Selection">
1106
+ <span class="bulk-count" aria-live="polite"
1107
+ >${shownCount} selected</span
1108
+ >
1109
+ ${canSelectAllPages
1110
+ ? b `<wc-button
1111
+ class="bulk-select-all"
1112
+ variant="text"
1113
+ size="sm"
1114
+ @click=${() => this.selectAllPages(pageRows)}
1115
+ >Select all ${total}</wc-button
1116
+ >`
1117
+ : A}
1118
+ <span class="bulk-spacer"></span>
1119
+ <slot name="bulk-actions"></slot>
1120
+ <wc-button
1121
+ class="bulk-clear"
1122
+ variant="text"
1123
+ size="sm"
1124
+ @click=${this.clearSelection}
1125
+ >Clear</wc-button
1126
+ >
1127
+ </div>
1128
+ `;
1129
+ }
513
1130
  renderPagination() {
514
1131
  if (!this.paginate)
515
1132
  return A;
516
1133
  return b `
517
- <wc-pagination
518
- .page=${this.page}
519
- .pageSize=${this.pageSize}
520
- .totalItems=${this.getTotalItems()}
521
- @page=${(e) => {
522
- this.page = e.detail.page;
523
- this.pageSize = e.detail.pageSize;
524
- this.dispatchEvent(new CustomEvent('page', {
525
- detail: { page: this.page, pageSize: this.pageSize },
526
- bubbles: true,
527
- composed: true,
528
- }));
529
- }}
530
- ></wc-pagination>
1134
+ <div class="table-footer">
1135
+ <wc-pagination
1136
+ .page=${this.page}
1137
+ .pageSize=${this.pageSize}
1138
+ .totalItems=${this.getTotalItems()}
1139
+ .hasNext=${this.hasNext}
1140
+ .variant=${this.paginationVariant}
1141
+ .pageSizes=${this.pageSizes ?? [10, 25, 50, 100]}
1142
+ @page=${this.onPage}
1143
+ ></wc-pagination>
1144
+ </div>
531
1145
  `;
532
1146
  }
1147
+ // ── Render ───────────────────────────────────────────────────────────────
533
1148
  render() {
534
- const tableClasses = {
535
- table: true,
536
- sortable: this.sortable,
537
- paginate: this.paginate,
538
- 'horizontal-scrolled': this.isHorizontallyScrolled,
539
- };
1149
+ const columns = this.getGridColumns();
1150
+ const pageRows = this.getPageRows();
1151
+ const total = this.getTotalItems();
1152
+ const hasRows = pageRows.length > 0;
1153
+ let body;
1154
+ if (hasRows)
1155
+ body = this.renderBody(columns, pageRows);
1156
+ else if (this.loading)
1157
+ body = this.renderSkeletonBody(columns);
1158
+ else
1159
+ body = this.renderEmptyState();
540
1160
  return b `
541
- <div class=${e(tableClasses)}>
542
- <div class="table-scroll-container" @scroll=${this.onScrollContainer}>
543
- ${this.renderHeader()}
544
- ${this.data && this.data.length
545
- ? this.renderBody()
546
- : this.renderEmptyState()}
1161
+ <div
1162
+ class=${e$1({
1163
+ table: true,
1164
+ 'scrolled-from-start': this.scrolledFromStart,
1165
+ 'scrolled-from-end': this.scrolledFromEnd,
1166
+ 'has-selection': this.selectedRowKeys.length > 0,
1167
+ })}
1168
+ >
1169
+ ${this.renderBulkBar(pageRows)}
1170
+ <div
1171
+ class="table-scroll-container"
1172
+ role="grid"
1173
+ aria-label=${this.label || A}
1174
+ aria-busy=${this.loading ? 'true' : A}
1175
+ aria-multiselectable=${this.selectionType === 'checkbox'
1176
+ ? 'true'
1177
+ : A}
1178
+ aria-rowcount=${this.paginate && total !== undefined
1179
+ ? total + 1
1180
+ : A}
1181
+ aria-colcount=${columns.length}
1182
+ @scroll=${this.onScrollContainer}
1183
+ @focusin=${this.onGridFocusIn}
1184
+ @keydown=${this.onGridKeydown}
1185
+ >
1186
+ ${this.renderHeader(columns, pageRows)} ${body}
547
1187
  </div>
548
- <div class="table-footer">${this.renderPagination()}</div>
1188
+ ${this.renderPagination()}
549
1189
  </div>
550
1190
  `;
551
1191
  }
@@ -587,9 +1227,30 @@ __decorate([
587
1227
  __decorate([
588
1228
  n({ type: Number, attribute: 'page-size' })
589
1229
  ], Table.prototype, "pageSize", void 0);
1230
+ __decorate([
1231
+ n({ type: Array, attribute: 'page-sizes' })
1232
+ ], Table.prototype, "pageSizes", void 0);
590
1233
  __decorate([
591
1234
  n({ type: Number, attribute: 'total-items' })
592
1235
  ], Table.prototype, "totalItems", void 0);
1236
+ __decorate([
1237
+ n({ type: Boolean, attribute: 'has-next' })
1238
+ ], Table.prototype, "hasNext", void 0);
1239
+ __decorate([
1240
+ n({ type: String, attribute: 'pagination-variant' })
1241
+ ], Table.prototype, "paginationVariant", void 0);
1242
+ __decorate([
1243
+ n({ type: String, reflect: true })
1244
+ ], Table.prototype, "density", void 0);
1245
+ __decorate([
1246
+ n({ type: Boolean, reflect: true })
1247
+ ], Table.prototype, "striped", void 0);
1248
+ __decorate([
1249
+ n({ type: Boolean, reflect: true })
1250
+ ], Table.prototype, "loading", void 0);
1251
+ __decorate([
1252
+ n({ type: String })
1253
+ ], Table.prototype, "label", void 0);
593
1254
  __decorate([
594
1255
  n({ type: String, attribute: 'empty-state-headline' })
595
1256
  ], Table.prototype, "emptyStateHeadline", void 0);
@@ -598,17 +1259,20 @@ __decorate([
598
1259
  ], Table.prototype, "emptyStateDescription", void 0);
599
1260
  __decorate([
600
1261
  r()
601
- ], Table.prototype, "hoveredCell", void 0);
1262
+ ], Table.prototype, "allPagesSelected", void 0);
602
1263
  __decorate([
603
1264
  r()
604
- ], Table.prototype, "isSelectAll", void 0);
1265
+ ], Table.prototype, "scrolledFromStart", void 0);
605
1266
  __decorate([
606
1267
  r()
607
- ], Table.prototype, "isSelectAllIntermediate", void 0);
1268
+ ], Table.prototype, "scrolledFromEnd", void 0);
608
1269
  __decorate([
609
1270
  r()
610
- ], Table.prototype, "isHorizontallyScrolled", void 0);
611
- Table = __decorate([
1271
+ ], Table.prototype, "activeCell", void 0);
1272
+ __decorate([
1273
+ e('.table-scroll-container')
1274
+ ], Table.prototype, "scrollContainer", void 0);
1275
+ Table = Table_1 = __decorate([
612
1276
  IndividualComponent
613
1277
  ], Table);
614
1278