@commmerce/ui 1.5.1 → 1.6.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 (65) hide show
  1. package/dist/calendar.js +2 -0
  2. package/dist/cdn.js +1018 -659
  3. package/dist/components/action-menu.d.ts +28 -1
  4. package/dist/components/action-menu.js +86 -17
  5. package/dist/components/badge.d.ts +3 -2
  6. package/dist/components/badge.js +4 -3
  7. package/dist/components/bottom-sheet.js +1 -1
  8. package/dist/components/button.d.ts +5 -1
  9. package/dist/components/button.js +18 -6
  10. package/dist/components/calendar.d.ts +6 -1
  11. package/dist/components/calendar.js +15 -1
  12. package/dist/components/card.d.ts +38 -0
  13. package/dist/components/card.js +77 -12
  14. package/dist/components/checkbox.js +7 -2
  15. package/dist/components/color-field.js +2 -0
  16. package/dist/components/combobox.d.ts +27 -2
  17. package/dist/components/combobox.js +109 -15
  18. package/dist/components/data-table.d.ts +127 -9
  19. package/dist/components/data-table.js +577 -67
  20. package/dist/components/date-picker.d.ts +1 -1
  21. package/dist/components/date-picker.js +1 -1
  22. package/dist/components/date-range-picker.d.ts +1 -1
  23. package/dist/components/date-range-picker.js +2 -2
  24. package/dist/components/empty-state.d.ts +8 -6
  25. package/dist/components/empty-state.js +26 -17
  26. package/dist/components/file-upload.d.ts +49 -4
  27. package/dist/components/file-upload.js +136 -29
  28. package/dist/components/layout.d.ts +2 -2
  29. package/dist/components/layout.js +5 -5
  30. package/dist/components/menu-item.d.ts +18 -0
  31. package/dist/components/menu-item.js +8 -0
  32. package/dist/components/page-header.d.ts +6 -0
  33. package/dist/components/page-header.js +22 -5
  34. package/dist/components/pagination.d.ts +3 -2
  35. package/dist/components/pagination.js +13 -10
  36. package/dist/components/radio.js +4 -2
  37. package/dist/components/resource-list.d.ts +28 -3
  38. package/dist/components/resource-list.js +47 -15
  39. package/dist/components/search.d.ts +2 -2
  40. package/dist/components/search.js +4 -2
  41. package/dist/components/segmented-control.js +1 -1
  42. package/dist/components/select.d.ts +11 -1
  43. package/dist/components/select.js +17 -4
  44. package/dist/components/side-navigation.d.ts +1 -1
  45. package/dist/components/side-navigation.js +5 -3
  46. package/dist/components/signature-field.js +2 -2
  47. package/dist/components/status-tabs.d.ts +24 -4
  48. package/dist/components/status-tabs.js +82 -9
  49. package/dist/components/table-header.d.ts +1 -1
  50. package/dist/components/table-header.js +3 -3
  51. package/dist/components/tag.d.ts +7 -0
  52. package/dist/components/tag.js +6 -3
  53. package/dist/components/text-field.d.ts +1 -1
  54. package/dist/components/text-field.js +3 -1
  55. package/dist/components/toggle.js +3 -1
  56. package/dist/components/tooltip.d.ts +5 -2
  57. package/dist/components/tooltip.js +14 -9
  58. package/dist/custom-elements.json +1599 -129
  59. package/dist/density.d.ts +21 -0
  60. package/dist/density.js +46 -0
  61. package/dist/field.d.ts +9 -5
  62. package/dist/field.js +16 -10
  63. package/dist/index.d.ts +1 -1
  64. package/dist/popover.js +1 -1
  65. package/package.json +3 -3
@@ -9,31 +9,58 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _CmDataTable_instances, _CmDataTable_userSorted, _CmDataTable_observer, _CmDataTable_readLight, _CmDataTable_say, _CmDataTable_enhanceLight, _CmDataTable_lightIcon, _CmDataTable_onLightSort, _CmDataTable_onSort, _CmDataTable_text, _CmDataTable_cls;
12
+ var _CmDataTable_instances, _CmDataTable_userSorted, _CmDataTable_id, _CmDataTable_observer, _CmDataTable_resize, _CmDataTable_observed, _CmDataTable_raf, _CmDataTable_shift, _CmDataTable_readLight, _CmDataTable_say, _CmDataTable_saySort, _CmDataTable_enhanceLight, _CmDataTable_lightIcon, _CmDataTable_onLightSort, _CmDataTable_onSort, _CmDataTable_observe, _CmDataTable_onAnyScroll, _CmDataTable_measure, _CmDataTable_text, _CmDataTable_width, _CmDataTable_cls, _CmDataTable_style, _CmDataTable_onOver, _CmDataTable_onFocus, _CmDataTable_primary, _CmDataTable_rowName, _CmDataTable_actionsOf, _CmDataTable_onAction, _CmDataTable_actions, _CmDataTable_content, _CmDataTable_setWidth, _CmDataTable_currentWidth, _CmDataTable_onResizeKey, _CmDataTable_onResizeDown, _CmDataTable_togglePicker, _CmDataTable_onOutside, _CmDataTable_onPickerKey, _CmDataTable_setVisible, _CmDataTable_renderPicker, _CmDataTable_renderHead, _CmDataTable_renderRow, _CmDataTable_toggleRow, _CmDataTable_renderCards;
13
13
  import { html, css, nothing } from 'lit';
14
- import { base, define } from '../base.js';
14
+ import { base, define, nextId, logicalKey } from '../base.js';
15
15
  import { CmLocalizedElement, defineStrings, formatDate } from '../localize.js';
16
+ import { adoptDensity } from '../density.js';
16
17
  import './icon.js';
17
18
  import './skeleton.js';
19
+ import './button.js';
18
20
  const strings = defineStrings('dataTable', {
19
21
  /** Shown when there are no rows and no `empty` slot. */
20
22
  empty: 'No data',
21
23
  /** Announced after a sort. `{direction}` is the common `ascending` or `descending`. */
22
24
  sorted: 'Sorted by {column}, {direction}',
25
+ /** Under a table wider than its box, while there is more to scroll to. */
26
+ scrollHint: 'Scroll for more',
27
+ /** The column picker's button, and the name of its list of choices. */
28
+ columns: 'Columns',
29
+ showColumns: 'Show columns',
30
+ /** Accessible name of a column's resize handle. */
31
+ resize: 'Resize {column} column',
32
+ /** Announced after a column is resized. */
33
+ resized: '{column} column, {width} pixels wide',
34
+ /** With `mobile="priority"` on a narrow table: shows and hides a row's low-priority fields. */
35
+ viewAll: 'View all fields',
36
+ viewLess: 'Hide fields',
37
+ /** Accessible name of a row action: `{action}` is its label, `{name}` the row's first (or `primary`) value. */
38
+ rowAction: '{action}, {name}',
23
39
  });
40
+ /** Narrowest a merchant can make a column. */
41
+ const MIN_WIDTH = 48;
42
+ /** Arrow keys on a resize handle change the width by this much. */
43
+ const STEP = 16;
24
44
  let sheetAdded = false;
25
45
  /**
26
46
  * Styles for a server-rendered `<table>` written inside `cm-data-table` (light DOM, so it can't be styled
27
47
  * from the shadow root). Added to the document once, scoped to `cm-data-table > table`.
48
+ * The 1.6 table standard: a 40px heading row in 12px semibold, 48px body rows (40px compact, 44px at least on touch
49
+ * screens), cells padded 12px across and 10px down in 13px text. Mirrors the shadow styles below: change both together.
28
50
  */
29
51
  const LIGHT_CSS = `
30
- cm-data-table > table { width: 100%; border-collapse: separate; border-spacing: 0; font: inherit; font-size: var(--cm-font-size-14); line-height: var(--cm-line-height-14); font-variant-numeric: tabular-nums; color: var(--cm-text-default); }
52
+ cm-data-table > table { width: 100%; border-collapse: separate; border-spacing: 0; font: inherit; font-size: var(--cm-font-size-13); line-height: var(--cm-line-height-13); font-variant-numeric: tabular-nums; color: var(--cm-text-default); }
31
53
  cm-data-table > table caption { text-align: start; font-weight: 600; font-size: var(--cm-font-size-16); line-height: var(--cm-line-height-16); padding-block-end: var(--cm-space-8); }
32
- cm-data-table > table th { font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-12); font-weight: 500; color: var(--cm-text-tertiary); text-align: start; padding: var(--cm-space-8) var(--cm-space-16); background: var(--cm-bg-hover); border-block: var(--cm-border-1) solid var(--cm-border-subtle); white-space: nowrap; }
33
- cm-data-table > table th:first-child { border-inline-start: var(--cm-border-1) solid var(--cm-border-subtle); border-start-start-radius: var(--cm-radius-md); }
34
- cm-data-table > table th:last-child { border-inline-end: var(--cm-border-1) solid var(--cm-border-subtle); border-start-end-radius: var(--cm-radius-md); }
35
- cm-data-table > table td { padding: var(--cm-space-8) var(--cm-space-16); border-block-end: var(--cm-border-1) solid var(--cm-border-subtle); vertical-align: middle; }
36
- cm-data-table > table tfoot td, cm-data-table > table tfoot th { font-weight: 500; background: var(--cm-bg-surface); border-block: var(--cm-border-1) solid var(--cm-border-subtle); font-size: var(--cm-font-size-14); color: var(--cm-text-default); }
54
+ cm-data-table > table th, cm-data-table > table td { box-sizing: border-box; }
55
+ cm-data-table > table thead th { height: var(--cm-table-header-height, 40px); font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-12); font-weight: 600; color: var(--cm-text-tertiary); text-align: start; padding: 0 var(--cm-space-12); background: var(--cm-bg-hover); border-block: var(--cm-border-1) solid var(--cm-border-subtle); white-space: nowrap; }
56
+ cm-data-table > table thead th:first-child { border-inline-start: var(--cm-border-1) solid var(--cm-border-subtle); border-start-start-radius: var(--cm-radius-md); }
57
+ cm-data-table > table thead th:last-child { border-inline-end: var(--cm-border-1) solid var(--cm-border-subtle); border-start-end-radius: var(--cm-radius-md); }
58
+ cm-data-table > table tbody td, cm-data-table > table tbody th, cm-data-table > table tfoot td, cm-data-table > table tfoot th { height: var(--cm-table-row-height, 48px); padding: 10px var(--cm-space-12); border-block-end: var(--cm-border-1) solid var(--cm-border-subtle); vertical-align: middle; text-align: start; }
59
+ cm-data-table > table tbody th { font-weight: 400; }
60
+ cm-data-table[density="compact"] { --cm-table-row-height: 40px; }
61
+ cm-data-table[density="comfortable"] { --cm-table-row-height: 48px; }
62
+ @media (pointer: coarse) { cm-data-table > table tbody td, cm-data-table > table tbody th, cm-data-table > table tfoot td { height: max(var(--cm-table-row-height, 48px), var(--cm-control-height-touch, 44px)); } }
63
+ cm-data-table > table tfoot td, cm-data-table > table tfoot th { font-weight: 500; background: var(--cm-bg-surface); border-block: var(--cm-border-1) solid var(--cm-border-subtle); color: var(--cm-text-default); }
37
64
  cm-data-table > table tbody tr:hover td, cm-data-table > table tbody tr:hover th { background: var(--cm-bg-hover); }
38
65
  cm-data-table > table th > button.cm-sort { display: inline-flex; align-items: center; gap: 4px; padding: 2px 0; font: inherit; color: inherit; background: none; border: 0; cursor: pointer; text-align: inherit; }
39
66
  cm-data-table > table th[data-type='numeric'] > button.cm-sort, cm-data-table > table th[data-type='money'] > button.cm-sort { flex-direction: row-reverse; }
@@ -41,7 +68,29 @@ cm-data-table > table th > button.cm-sort cm-icon { color: var(--cm-icon-selecte
41
68
  cm-data-table > table th > button.cm-sort:hover cm-icon, cm-data-table > table th[aria-sort='ascending'] cm-icon, cm-data-table > table th[aria-sort='descending'] cm-icon { opacity: 1; }
42
69
  cm-data-table > table th > button.cm-sort:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
43
70
  @media (forced-colors: active) { cm-data-table > table th > button.cm-sort cm-icon { opacity: 1; } }
44
- cm-data-table > table .numeric, cm-data-table > table [data-type='numeric'], cm-data-table > table [data-type='money'] { text-align: end; font-variant-numeric: tabular-nums; }
71
+ cm-data-table > table .numeric, cm-data-table > table [data-type='numeric'], cm-data-table > table [data-type='money'], cm-data-table > table [data-type='actions'] { text-align: end; font-variant-numeric: tabular-nums; }
72
+ cm-data-table > table .numeric, cm-data-table > table [data-type='numeric'], cm-data-table > table [data-type='money'], cm-data-table > table [data-type='date'] { white-space: nowrap; }
73
+ cm-data-table > table [data-type='actions'] { width: 1%; white-space: nowrap; }
74
+ cm-data-table > table tbody td[data-type='actions'] { padding-block: 0; }
75
+ cm-data-table > table td[data-type='actions'] > * + * { margin-inline-start: var(--cm-space-8); }
76
+ cm-data-table:not([row-actions='always']) > table tbody tr:not(:hover):not(:focus-within) td[data-type='actions'] > * { opacity: 0; }
77
+ @media (hover: none), (pointer: coarse) { cm-data-table:not([row-actions='always']) > table tbody tr:not(:hover):not(:focus-within) td[data-type='actions'] > * { opacity: 1; } }
78
+ cm-data-table[sticky-header] > table thead th { position: sticky; top: var(--cm-data-table-sticky-top, 0px); z-index: 2; transform: translateY(var(--_shift, 0px)); }
79
+ /* The host is the size container for its own light table too: WebKit looks a light-DOM element's container up in the
80
+ DOM tree, not through the shadow root's .frame. */
81
+ cm-data-table:has(> table) { container-type: inline-size; }
82
+ @container (max-width: 640px) {
83
+ cm-data-table[mobile='priority'] > table [data-priority='low'] { display: none; }
84
+ cm-data-table[mobile='cards'] > table, cm-data-table[mobile='cards'] > table tbody, cm-data-table[mobile='cards'] > table tfoot { display: block; }
85
+ cm-data-table[mobile='cards'] > table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
86
+ cm-data-table[mobile='cards'] > table tr { display: block; margin-block-end: var(--cm-space-8); padding: var(--cm-space-12) var(--cm-space-16); border: var(--cm-border-1) solid var(--cm-border-subtle); border-radius: var(--cm-radius-md); background: var(--cm-bg-surface); }
87
+ cm-data-table[mobile='cards'] > table tr > * { display: flex; justify-content: space-between; gap: var(--cm-space-12); height: auto; padding: var(--cm-space-4) 0; border: 0; background: none; text-align: end; white-space: normal; }
88
+ cm-data-table[mobile='cards'] > table tbody tr:hover > * { background: none; }
89
+ cm-data-table[mobile='cards'] > table tr > :first-child { font-size: var(--cm-font-size-14); line-height: var(--cm-line-height-14); font-weight: 600; text-align: start; }
90
+ cm-data-table[mobile='cards'] > table tr > :not(:first-child)[data-label]::before { content: attr(data-label); font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-12); color: var(--cm-text-tertiary); text-align: start; font-weight: 400; }
91
+ cm-data-table[mobile='cards'] > table td[data-type='actions'] { justify-content: flex-start; flex-wrap: wrap; padding-block-start: var(--cm-space-8); }
92
+ cm-data-table[mobile='cards'] > table td[data-type='actions'] > * { opacity: 1; }
93
+ }
45
94
  `;
46
95
  function addLightStyles() {
47
96
  if (sheetAdded || typeof document === 'undefined')
@@ -51,7 +100,9 @@ function addLightStyles() {
51
100
  sheet.replaceSync(LIGHT_CSS);
52
101
  document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
53
102
  }
54
- const isEnd = (c) => (c.align ?? (c.type === 'numeric' || c.type === 'money' ? 'end' : 'start')) === 'end';
103
+ const isNum = (c) => c.type === 'numeric' || c.type === 'money';
104
+ const isEnd = (c) => (c.align ?? (isNum(c) || c.type === 'actions' ? 'end' : 'start')) === 'end';
105
+ const isText = (c) => !c.type || c.type === 'text';
55
106
  /**
56
107
  * Reads a number from a cell: 1200, "1,200", "Rs. 1,200", "₹1,200.50", "-500", "(500)" (negative), "12%".
57
108
  * Leading text such as a currency is skipped, so its dot is never read as a decimal point.
@@ -94,10 +145,21 @@ function compare(a, b, type, locale) {
94
145
  return (toTime(a) || 0) - (toTime(b) || 0);
95
146
  return collator(locale).compare(String(a), String(b));
96
147
  }
148
+ /** The composed (shadow-including) parent of a node. */
149
+ const up = (n) => n.parentElement ?? (n.getRootNode().host ?? null);
97
150
  /**
98
- * A data table for reports and read-only lists: sales by day, stock by location, order lines.
151
+ * A data table for reports and lists of records: sales by day, stock by location, accounts, tasks.
99
152
  * A real `<table>` with column headings, sortable columns, a totals row, a sticky header and first column,
100
- * loading rows and an empty state. For lists merchants select and act on, use Resource list.
153
+ * loading rows and an empty state. For lists merchants select and act on in bulk, use Resource list.
154
+ *
155
+ * The table standard (since 1.6): a 40px heading row in 12px semibold; 48px body rows (`density="compact"`: 40px;
156
+ * at least 44px on touch screens) with cells padded 12px across and 10px down in 13px text; numbers, money and
157
+ * actions right-aligned; numbers and dates never wrap; text ends in "…" with the full value on hover.
158
+ * Set `data-cm-density="compact"` on any ancestor to make every table and list in it compact.
159
+ *
160
+ * On phones each table picks a strategy with `mobile` (judged by the table's own width, 640px or less):
161
+ * `scroll` (default) keeps the columns and shows that it scrolls sideways; `cards` turns each row into a card;
162
+ * `priority` hides `priority: 'low'` columns and adds "View all fields" to each row.
101
163
  *
102
164
  * Give it `columns` and `rows`, or write a native `<table>` inside it (for server-rendered pages): that
103
165
  * table is styled to match. Mark a heading `<th data-sort="text|numeric|money|date">` to make its column sortable
@@ -108,7 +170,18 @@ function compare(a, b, type, locale) {
108
170
  * @slot empty - Shown instead of the rows when `rows` is empty, e.g. a `cm-empty-state`.
109
171
  * @fires cm-sort - `detail: { key, direction }` when a sortable heading is clicked. Cancelable: call
110
172
  * `preventDefault()` to stop the table sorting itself. With `sort-mode="manual"` it never sorts itself.
111
- * @cssprop --cm-data-table-max-height - With `sticky-header`, the table scrolls inside this height. Default `none`.
173
+ * @fires cm-row-action - `detail: { action, row, index }` when a button in an `actions` column is pressed: the action's
174
+ * `value`, the row object and its index in `rows`.
175
+ * @fires cm-column-resize - `detail: { key, width }` when the merchant resizes a column (`resizable`), in pixels. Store
176
+ * it and pass it back as the column's `width`.
177
+ * @fires cm-columns-change - `detail: { key, visible, columns }` when the merchant shows or hides a column with the column
178
+ * picker. `columns` is the new array (the table has already switched to it); store it to keep the choice.
179
+ * @cssprop --cm-data-table-max-height - With `sticky-header`, the table scrolls inside this height. Default `none`: the
180
+ * heading row sticks to the page or to the nearest scrolling box instead.
181
+ * @cssprop --cm-data-table-sticky-top - With `sticky-header`, how far from the top the heading row sticks, e.g. under a
182
+ * sticky app header. Default `0px`.
183
+ * @cssprop --cm-data-table-cell-max-width - Widest a text column grows before its text ends in "…". Default `320px` (and never more than 45% of the table's width).
184
+ * @cssprop --cm-table-row-height - Height of body rows. Set by `density`/`data-cm-density`: 48px, compact 40px.
112
185
  */
113
186
  export class CmDataTable extends CmLocalizedElement {
114
187
  constructor() {
@@ -130,7 +203,10 @@ export class CmDataTable extends CmLocalizedElement {
130
203
  this.direction = 'ascending';
131
204
  /** `auto`: the table sorts its own rows. `manual`: it only fires `cm-sort` (sort on your server, then set `rows`). */
132
205
  this.sortMode = 'auto';
133
- /** Keeps the heading row visible while the table scrolls inside `--cm-data-table-max-height`. */
206
+ /**
207
+ * Keeps the heading row in view while the rows scroll: inside `--cm-data-table-max-height` when you set one,
208
+ * otherwise under the top of the page or of the nearest scrolling box (plus `--cm-data-table-sticky-top`).
209
+ */
134
210
  this.stickyHeader = false;
135
211
  /** Keeps the first column visible while the table scrolls sideways (on narrow screens). */
136
212
  this.stickyFirstColumn = false;
@@ -138,20 +214,61 @@ export class CmDataTable extends CmLocalizedElement {
138
214
  this.loading = false;
139
215
  /** How many placeholder rows `loading` shows. */
140
216
  this.loadingRows = 5;
217
+ /**
218
+ * What the table does when it is 640px wide or less (since 1.6): `scroll` keeps every column, scrolls sideways and
219
+ * says so ("Scroll for more", faded edges); `cards` shows each row as a card of label and value pairs with the primary
220
+ * column as its title and the actions at the bottom; `priority` hides `priority: 'low'` columns and gives each row a
221
+ * "View all fields" button that shows them. Pick one per table: see the "Tables on phones" pattern.
222
+ */
223
+ this.mobile = 'scroll';
224
+ /** `hover` (default): an `actions` column's buttons appear when the row is hovered or has focus (always on touch screens). `always`: always shown. */
225
+ this.rowActions = 'hover';
226
+ /** Adds a resize handle to each heading: drag it, or focus it and press the left and right arrow keys (16px a press). */
227
+ this.resizable = false;
228
+ /** Adds a "Columns" button above the table that shows and hides columns. */
229
+ this.columnPicker = false;
141
230
  this._light = false;
142
231
  this._announce = '';
232
+ this._widths = {};
233
+ this._expanded = new Set();
234
+ this._picker = false;
235
+ this._overflows = false;
143
236
  _CmDataTable_userSorted.set(this, false);
237
+ _CmDataTable_id.set(this, nextId('cm-dt'));
144
238
  _CmDataTable_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_readLight).call(this)));
239
+ _CmDataTable_resize.set(this, typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_measure).call(this)));
240
+ _CmDataTable_observed.set(this, []);
241
+ _CmDataTable_raf.set(this, 0);
242
+ _CmDataTable_shift.set(this, -1);
243
+ /** Scrolling elsewhere on the page only matters to a sticky heading; the table's own scroll and size are watched directly. */
244
+ _CmDataTable_onAnyScroll.set(this, () => {
245
+ if (__classPrivateFieldGet(this, _CmDataTable_raf, "f") || !this.stickyHeader)
246
+ return;
247
+ __classPrivateFieldSet(this, _CmDataTable_raf, requestAnimationFrame(() => { __classPrivateFieldSet(this, _CmDataTable_raf, 0, "f"); __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_measure).call(this); }), "f");
248
+ });
249
+ _CmDataTable_onOutside.set(this, (e) => {
250
+ const tools = this.renderRoot.querySelector('.tools');
251
+ if (tools && !e.composedPath().includes(tools))
252
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_togglePicker).call(this, false);
253
+ });
145
254
  }
146
255
  connectedCallback() {
147
256
  super.connectedCallback();
257
+ adoptDensity(this);
148
258
  __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_readLight).call(this);
149
259
  // subtree: while the page is still being parsed, the table's head and rows arrive after the table itself.
150
260
  __classPrivateFieldGet(this, _CmDataTable_observer, "f").observe(this, { childList: true, subtree: true });
261
+ document.addEventListener('scroll', __classPrivateFieldGet(this, _CmDataTable_onAnyScroll, "f"), { capture: true, passive: true });
262
+ window.addEventListener('resize', __classPrivateFieldGet(this, _CmDataTable_onAnyScroll, "f"), { passive: true });
151
263
  }
152
264
  disconnectedCallback() {
153
265
  super.disconnectedCallback();
154
266
  __classPrivateFieldGet(this, _CmDataTable_observer, "f").disconnect();
267
+ __classPrivateFieldGet(this, _CmDataTable_resize, "f")?.disconnect();
268
+ __classPrivateFieldSet(this, _CmDataTable_observed, [], "f");
269
+ document.removeEventListener('scroll', __classPrivateFieldGet(this, _CmDataTable_onAnyScroll, "f"), { capture: true });
270
+ window.removeEventListener('resize', __classPrivateFieldGet(this, _CmDataTable_onAnyScroll, "f"));
271
+ document.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmDataTable_onOutside, "f"), { capture: true });
155
272
  }
156
273
  /** The rows in display order: sorted when `sort` is set and `sort-mode` is `auto`. */
157
274
  get sortedRows() {
@@ -169,67 +286,100 @@ export class CmDataTable extends CmLocalizedElement {
169
286
  return sign * compare(av, bv, col.type, this.locale) || i - j;
170
287
  }).map(([r]) => r);
171
288
  }
289
+ /** The columns shown: every column whose `visible` isn't `false`. */
290
+ get visibleColumns() {
291
+ return (this.columns ?? []).filter((c) => c.visible !== false);
292
+ }
172
293
  updated(changed) {
173
294
  if (__classPrivateFieldGet(this, _CmDataTable_userSorted, "f") && (changed.has('sort') || changed.has('direction')) && this.sort) {
174
295
  __classPrivateFieldSet(this, _CmDataTable_userSorted, false, "f");
175
296
  const col = this.columns.find((c) => c.key === this.sort);
176
297
  if (col)
177
- __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_say).call(this, col.label, this.direction);
298
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_saySort).call(this, col.label, this.direction);
299
+ }
300
+ if (changed.has('columns')) {
301
+ // A column given a new width by the app takes it over from an earlier resize.
302
+ const before = changed.get('columns') ?? [];
303
+ const next = { ...this._widths };
304
+ let touched = false;
305
+ for (const c of this.columns ?? []) {
306
+ const old = before.find((b) => b.key === c.key);
307
+ if (c.width !== undefined && old?.width !== c.width && next[c.key] !== undefined) {
308
+ delete next[c.key];
309
+ touched = true;
310
+ }
311
+ }
312
+ if (touched)
313
+ this._widths = next;
178
314
  }
315
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_observe).call(this);
316
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_measure).call(this);
179
317
  }
180
318
  render() {
181
319
  const status = html `<span class="sr" role="status">${this._announce}</span>`;
182
- if (this._light)
183
- return html `<div class="scroll" part="scroll"><slot></slot></div>${status}`;
184
- const cols = this.columns ?? [];
320
+ const hint = html `<p class="hint" part="scroll-hint" aria-hidden="true">${this.t('scrollHint')}<cm-icon name="chevron-right" size="16"></cm-icon></p>`;
321
+ const fades = html `<span class="fade s" aria-hidden="true"></span><span class="fade e" aria-hidden="true"></span>`;
322
+ const region = this.stickyHeader || this.stickyFirstColumn || this._overflows;
323
+ if (this._light) {
324
+ return html `<div class="frame" part="frame"><div class="wrap"><div class="scroll" part="scroll" tabindex=${this._overflows ? '0' : nothing}
325
+ role=${this._overflows ? 'region' : nothing} aria-label=${this._overflows ? this.querySelector('caption')?.textContent?.trim() || nothing : nothing}
326
+ @scroll=${() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_measure).call(this)}><slot></slot></div>${fades}</div>${hint}</div>${status}`;
327
+ }
328
+ const cols = this.visibleColumns;
329
+ const primary = __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_primary).call(this, cols);
330
+ const low = this.mobile === 'priority' ? cols.filter((c) => c.priority === 'low' && c !== primary) : [];
185
331
  const rows = this.sortedRows;
186
332
  const n = Math.max(1, cols.length);
187
333
  const showEmpty = !this.loading && rows.length === 0;
334
+ const cards = this.mobile === 'cards' && !this.loading && rows.length > 0;
188
335
  return html `
189
- <div class="scroll" part="scroll" tabindex=${this.stickyHeader || this.stickyFirstColumn ? '0' : nothing}
190
- role=${this.stickyHeader || this.stickyFirstColumn ? 'region' : nothing}
191
- aria-label=${(this.stickyHeader || this.stickyFirstColumn) && this.caption ? this.caption : nothing}>
192
- <table part="table" aria-busy=${this.loading ? 'true' : 'false'}>
193
- ${this.caption ? html `<caption part="caption">${this.caption}</caption>` : nothing}
194
- <thead><tr>${cols.map((c) => {
195
- const on = this.sort === c.key;
196
- const state = on ? this.direction : 'none';
197
- const label = c.hidden ? html `<span class="sr">${c.label}</span>` : c.label;
198
- return html `<th scope="col" class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c)} aria-sort=${c.sortable ? state : nothing}>${c.sortable
199
- ? html `<button type="button" class=${on ? 'on' : ''} @click=${() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onSort).call(this, c)}>${label}<cm-icon
200
- name=${on && this.direction === 'descending' ? 'chevron-down' : 'chevron-up'} size="12"></cm-icon></button>`
201
- : label}</th>`;
202
- })}</tr></thead>
203
- <tbody>
204
- ${this.loading
205
- ? Array.from({ length: Math.max(1, this.loadingRows) }, () => html `<tr>${cols.map((c) => html `<td class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c)}><cm-skeleton></cm-skeleton></td>`)}</tr>`)
206
- : rows.map((r) => html `<tr part="row">${cols.map((c, i) => i === 0
207
- ? html `<th scope="row" class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c)} part="cell">${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_text).call(this, r[c.key])}</th>`
208
- : html `<td class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c)} part="cell">${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_text).call(this, r[c.key])}</td>`)}</tr>`)}
209
- ${showEmpty ? html `<tr class="empty"><td colspan=${n}><slot name="empty">${this.t('empty')}</slot></td></tr>` : nothing}
210
- </tbody>
211
- ${this.totals && !this.loading && !showEmpty
212
- ? html `<tfoot><tr part="totals">${cols.map((c) => html `<td class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c)}>${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_text).call(this, this.totals[c.key])}</td>`)}</tr></tfoot>`
336
+ <div class="frame" part="frame" ?data-cards=${cards}>
337
+ ${this.columnPicker ? __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_renderPicker).call(this) : nothing}
338
+ <div class="wrap">
339
+ <div class="scroll" part="scroll" tabindex=${region ? '0' : nothing}
340
+ role=${region ? 'region' : nothing}
341
+ aria-label=${region && this.caption ? this.caption : nothing} @scroll=${() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_measure).call(this)}>
342
+ <table part="table" aria-busy=${this.loading ? 'true' : 'false'} @pointerover=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onOver)} @focusin=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onFocus)}
343
+ @focusout=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onFocus)}>
344
+ ${this.caption ? html `<caption part="caption">${this.caption}</caption>` : nothing}
345
+ <thead><tr>${cols.map((c) => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_renderHead).call(this, c, primary))}</tr></thead>
346
+ <tbody>
347
+ ${this.loading
348
+ ? Array.from({ length: Math.max(1, this.loadingRows) }, () => html `<tr>${cols.map((c) => html `<td class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c, primary)} style=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_style).call(this, c)}><cm-skeleton></cm-skeleton></td>`)}</tr>`)
349
+ : rows.map((r, i) => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_renderRow).call(this, r, cols, primary, low, i))}
350
+ ${showEmpty ? html `<tr class="empty"><td colspan=${n}><slot name="empty">${this.t('empty')}</slot></td></tr>` : nothing}
351
+ </tbody>
352
+ ${this.totals && !this.loading && !showEmpty
353
+ ? html `<tfoot><tr part="totals">${cols.map((c) => html `<td class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c, primary)} style=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_style).call(this, c)}>${c.type === 'actions' ? nothing : __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_text).call(this, this.totals[c.key])}</td>`)}</tr></tfoot>`
213
354
  : nothing}
214
- </table>
355
+ </table>
356
+ </div>
357
+ ${fades}
358
+ </div>
359
+ ${hint}
360
+ ${cards ? __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_renderCards).call(this, rows, cols, primary) : nothing}
215
361
  </div>${status}
216
362
  `;
217
363
  }
218
364
  }
219
- _CmDataTable_userSorted = new WeakMap(), _CmDataTable_observer = new WeakMap(), _CmDataTable_instances = new WeakSet(), _CmDataTable_readLight = function _CmDataTable_readLight() {
365
+ _CmDataTable_userSorted = new WeakMap(), _CmDataTable_id = new WeakMap(), _CmDataTable_observer = new WeakMap(), _CmDataTable_resize = new WeakMap(), _CmDataTable_observed = new WeakMap(), _CmDataTable_raf = new WeakMap(), _CmDataTable_shift = new WeakMap(), _CmDataTable_onAnyScroll = new WeakMap(), _CmDataTable_onOutside = new WeakMap(), _CmDataTable_instances = new WeakSet(), _CmDataTable_readLight = function _CmDataTable_readLight() {
220
366
  this._light = !!this.querySelector(':scope > table');
221
367
  if (this._light) {
222
368
  addLightStyles();
223
369
  __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_enhanceLight).call(this);
224
370
  }
225
- }, _CmDataTable_say = function _CmDataTable_say(label, direction) {
226
- this._announce = this.t('sorted', { column: label, direction: this.t(direction) });
371
+ }, _CmDataTable_say = function _CmDataTable_say(text) {
372
+ // A changed string is announced again even when it reads the same as before.
373
+ this._announce = this._announce === text ? `${text} ` : text;
374
+ }, _CmDataTable_saySort = function _CmDataTable_saySort(label, direction) {
375
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_say).call(this, this.t('sorted', { column: label, direction: this.t(direction) }));
227
376
  }, _CmDataTable_enhanceLight = function _CmDataTable_enhanceLight() {
228
377
  const table = this.querySelector(':scope > table');
229
378
  const cells = table?.tHead?.rows[0]?.cells;
230
379
  if (!cells)
231
380
  return;
232
- [...cells].forEach((th, index) => {
381
+ const heads = [...cells];
382
+ heads.forEach((th, index) => {
233
383
  if (!th.dataset.sort || th.querySelector(':scope > button.cm-sort'))
234
384
  return;
235
385
  th.dataset.type = th.dataset.sort;
@@ -246,6 +396,22 @@ _CmDataTable_userSorted = new WeakMap(), _CmDataTable_observer = new WeakMap(),
246
396
  __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_lightIcon).call(this, th);
247
397
  button.addEventListener('click', () => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onLightSort).call(this, table, th, index));
248
398
  });
399
+ // Cards and priority layouts: each cell learns its heading's label and priority.
400
+ for (const body of [...table.tBodies, ...(table.tFoot ? [table.tFoot] : [])]) {
401
+ for (const row of body.rows) {
402
+ [...row.cells].forEach((cell, i) => {
403
+ const th = heads[i];
404
+ if (!th)
405
+ return;
406
+ if (!cell.dataset.label)
407
+ cell.dataset.label = (th.textContent ?? '').trim();
408
+ if (th.dataset.priority && !cell.dataset.priority)
409
+ cell.dataset.priority = th.dataset.priority;
410
+ if (th.dataset.type === 'actions' && !cell.dataset.type)
411
+ cell.dataset.type = 'actions';
412
+ });
413
+ }
414
+ }
249
415
  }, _CmDataTable_lightIcon = function _CmDataTable_lightIcon(th) {
250
416
  th.querySelector(':scope > button.cm-sort > cm-icon')?.setAttribute('name', th.getAttribute('aria-sort') === 'descending' ? 'chevron-down' : 'chevron-up');
251
417
  }, _CmDataTable_onLightSort = function _CmDataTable_onLightSort(table, th, index) {
@@ -272,7 +438,7 @@ _CmDataTable_userSorted = new WeakMap(), _CmDataTable_observer = new WeakMap(),
272
438
  other.setAttribute('aria-sort', other === th ? direction : 'none');
273
439
  __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_lightIcon).call(this, other);
274
440
  }
275
- __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_say).call(this, label, direction);
441
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_saySort).call(this, label, direction);
276
442
  }, _CmDataTable_onSort = function _CmDataTable_onSort(c) {
277
443
  const direction = this.sort === c.key && this.direction === 'ascending' ? 'descending' : 'ascending';
278
444
  const ev = new CustomEvent('cm-sort', { detail: { key: c.key, direction }, bubbles: true, composed: true, cancelable: true });
@@ -283,14 +449,229 @@ _CmDataTable_userSorted = new WeakMap(), _CmDataTable_observer = new WeakMap(),
283
449
  this.sort = c.key;
284
450
  this.direction = direction;
285
451
  }
452
+ }, _CmDataTable_observe = function _CmDataTable_observe() {
453
+ const els = [this.renderRoot.querySelector('.scroll'), this.renderRoot.querySelector('table') ?? this.querySelector(':scope > table')]
454
+ .filter(Boolean);
455
+ if (els.length === __classPrivateFieldGet(this, _CmDataTable_observed, "f").length && els.every((e, i) => e === __classPrivateFieldGet(this, _CmDataTable_observed, "f")[i]))
456
+ return;
457
+ __classPrivateFieldGet(this, _CmDataTable_resize, "f")?.disconnect();
458
+ els.forEach((e) => __classPrivateFieldGet(this, _CmDataTable_resize, "f")?.observe(e));
459
+ __classPrivateFieldSet(this, _CmDataTable_observed, els, "f");
460
+ }, _CmDataTable_measure = function _CmDataTable_measure() {
461
+ const scroll = this.renderRoot?.querySelector('.scroll');
462
+ const frame = this.renderRoot?.querySelector('.frame');
463
+ if (!scroll || !frame)
464
+ return;
465
+ const ownHeight = getComputedStyle(scroll).maxBlockSize !== 'none';
466
+ const overflows = scroll.scrollWidth > scroll.clientWidth + 1;
467
+ if (overflows !== this._overflows)
468
+ this._overflows = overflows;
469
+ // A sticky heading sticks to the page (or an outer box) only if this box isn't a scroll container.
470
+ scroll.toggleAttribute('data-open', this.stickyHeader && !ownHeight && !overflows);
471
+ const pos = Math.abs(scroll.scrollLeft);
472
+ frame.toggleAttribute('data-more-start', overflows && pos > 1);
473
+ frame.toggleAttribute('data-more-end', overflows && pos + scroll.clientWidth < scroll.scrollWidth - 1);
474
+ // The faded edges cover the rows, not the caption above them.
475
+ const caption = (this.renderRoot.querySelector('caption') ?? this.querySelector(':scope > table > caption'));
476
+ const cap = caption && getComputedStyle(caption).position !== 'absolute' ? `${caption.offsetHeight}px` : '';
477
+ if (scroll.parentElement.style.getPropertyValue('--_cap') !== cap)
478
+ scroll.parentElement.style.setProperty('--_cap', cap);
479
+ // Sticky heading in a table that also scrolls sideways: the box is a scroll container, so position: sticky can't
480
+ // reach the page. Move the heading down by hand instead, as far as the top of whatever is scrolling.
481
+ let shift = 0;
482
+ const table = (this.renderRoot.querySelector('table') ?? this.querySelector(':scope > table'));
483
+ const head = table?.tHead;
484
+ if (this.stickyHeader && !ownHeight && overflows && table && head) {
485
+ const current = __classPrivateFieldGet(this, _CmDataTable_shift, "f") > 0 ? __classPrivateFieldGet(this, _CmDataTable_shift, "f") : 0;
486
+ const headTop = head.getBoundingClientRect().top - current;
487
+ const tableBottom = table.getBoundingClientRect().bottom - current;
488
+ let top = 0;
489
+ for (let a = up(this); a && a !== document.documentElement && a !== document.body; a = up(a)) {
490
+ // Like position: sticky, under the scrolling box's top border and padding.
491
+ const cs = getComputedStyle(a);
492
+ if (/(auto|scroll|overlay|hidden|clip)/.test(cs.overflowY))
493
+ top = Math.max(top, a.getBoundingClientRect().top + a.clientTop + (parseFloat(cs.paddingTop) || 0));
494
+ }
495
+ top += parseFloat(getComputedStyle(this).getPropertyValue('--cm-data-table-sticky-top')) || 0;
496
+ shift = Math.max(0, Math.min(top - headTop, tableBottom - headTop - head.getBoundingClientRect().height));
497
+ }
498
+ // Resize handles say their column's width (set or measured), as a separator's value.
499
+ for (const handle of this.renderRoot.querySelectorAll('.rz')) {
500
+ const now = String(Math.round(handle.closest('th').getBoundingClientRect().width));
501
+ if (handle.getAttribute('aria-valuenow') !== now)
502
+ handle.setAttribute('aria-valuenow', now);
503
+ }
504
+ if (shift !== __classPrivateFieldGet(this, _CmDataTable_shift, "f")) {
505
+ __classPrivateFieldSet(this, _CmDataTable_shift, shift, "f");
506
+ if (shift)
507
+ scroll.style.setProperty('--_shift', `${shift}px`);
508
+ else
509
+ scroll.style.removeProperty('--_shift');
510
+ }
286
511
  }, _CmDataTable_text = function _CmDataTable_text(v) {
287
512
  if (v === null || v === undefined)
288
513
  return '';
289
514
  if (v instanceof Date)
290
515
  return formatDate(v, {}, this.locale);
291
516
  return String(v);
292
- }, _CmDataTable_cls = function _CmDataTable_cls(c) {
293
- return `${isEnd(c) ? 'end' : ''} ${c.type === 'numeric' || c.type === 'money' ? 'num' : ''}`;
517
+ }, _CmDataTable_width = function _CmDataTable_width(c) {
518
+ return this._widths[c.key] ?? c.width;
519
+ }, _CmDataTable_cls = function _CmDataTable_cls(c, primary) {
520
+ return [
521
+ isEnd(c) && 'end', isNum(c) && 'num', (isNum(c) || c.type === 'date') && 'nw', c.type === 'actions' && 'act',
522
+ c.priority === 'low' && c !== primary && 'low', __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_width).call(this, c) !== undefined && 'w',
523
+ ].filter(Boolean).join(' ');
524
+ }, _CmDataTable_style = function _CmDataTable_style(c) {
525
+ const w = __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_width).call(this, c);
526
+ return w === undefined ? nothing : `--_w: ${w}px`;
527
+ }, _CmDataTable_onOver = function _CmDataTable_onOver(e) {
528
+ const cell = e.composedPath()[0]?.closest?.('.t');
529
+ if (!cell)
530
+ return;
531
+ if (cell.scrollWidth > cell.clientWidth + 1)
532
+ cell.title = cell.textContent ?? '';
533
+ else
534
+ cell.removeAttribute('title');
535
+ }, _CmDataTable_onFocus = function _CmDataTable_onFocus(e) {
536
+ if (e.type === 'focusin')
537
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onOver).call(this, e);
538
+ const row = e.composedPath().find((n) => n instanceof HTMLTableRowElement);
539
+ if (!row)
540
+ return;
541
+ const into = e.type === 'focusin' || (e.relatedTarget instanceof Node && row.contains(e.relatedTarget));
542
+ row.toggleAttribute('data-focus', into);
543
+ }, _CmDataTable_primary = function _CmDataTable_primary(cols) {
544
+ return cols.find((c) => c.primary) ?? cols.find((c) => c.type !== 'actions') ?? cols[0];
545
+ }, _CmDataTable_rowName = function _CmDataTable_rowName(r, primary) {
546
+ return primary ? __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_text).call(this, r[primary.key]) : '';
547
+ }, _CmDataTable_actionsOf = function _CmDataTable_actionsOf(c, r) {
548
+ const own = r[c.key];
549
+ return Array.isArray(own) ? own : c.actions ?? [];
550
+ }, _CmDataTable_onAction = function _CmDataTable_onAction(a, r) {
551
+ const index = (this.rows ?? []).indexOf(r);
552
+ this.dispatchEvent(new CustomEvent('cm-row-action', { detail: { action: a.value ?? a.label, row: r, index }, bubbles: true, composed: true }));
553
+ }, _CmDataTable_actions = function _CmDataTable_actions(c, r, name) {
554
+ return html `<span class="acts">${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_actionsOf).call(this, c, r).map((a) => html `<cm-button size="slim" icon=${a.icon ?? nothing}
555
+ ?icon-only=${!!a.iconOnly} label=${a.iconOnly ? this.t('rowAction', { action: a.label, name }) : nothing} tone=${a.tone ?? nothing}
556
+ @click=${() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onAction).call(this, a, r)}>${a.label}${a.iconOnly || !name ? nothing : html `<span class="sr">, ${name}</span>`}</cm-button>`)}</span>`;
557
+ }, _CmDataTable_content = function _CmDataTable_content(c, r, name) {
558
+ if (c.type === 'actions')
559
+ return __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_actions).call(this, c, r, name);
560
+ const text = __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_text).call(this, r[c.key]);
561
+ return isText(c) ? html `<span class="t">${text}</span>` : text;
562
+ }, _CmDataTable_setWidth = function _CmDataTable_setWidth(c, width, done) {
563
+ const w = Math.max(MIN_WIDTH, Math.round(width));
564
+ this._widths = { ...this._widths, [c.key]: w };
565
+ if (!done)
566
+ return;
567
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_say).call(this, this.t('resized', { column: c.label, width: w }));
568
+ this.dispatchEvent(new CustomEvent('cm-column-resize', { detail: { key: c.key, width: w }, bubbles: true, composed: true }));
569
+ }, _CmDataTable_currentWidth = function _CmDataTable_currentWidth(c, handle) {
570
+ return __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_width).call(this, c) ?? Math.round(handle.closest('th').getBoundingClientRect().width);
571
+ }, _CmDataTable_onResizeKey = function _CmDataTable_onResizeKey(e, c) {
572
+ const key = logicalKey(e, this);
573
+ if (key !== 'ArrowLeft' && key !== 'ArrowRight')
574
+ return;
575
+ e.preventDefault();
576
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_setWidth).call(this, c, __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_currentWidth).call(this, c, e.currentTarget) + (key === 'ArrowRight' ? STEP : -STEP), true);
577
+ }, _CmDataTable_onResizeDown = function _CmDataTable_onResizeDown(e, c) {
578
+ if (e.button !== 0)
579
+ return;
580
+ e.preventDefault();
581
+ const handle = e.currentTarget;
582
+ const start = handle.closest('th').getBoundingClientRect().width;
583
+ const x0 = e.clientX;
584
+ const rtl = getComputedStyle(this).direction === 'rtl';
585
+ try {
586
+ handle.setPointerCapture(e.pointerId);
587
+ }
588
+ catch { /* synthetic events have no active pointer */ }
589
+ handle.setAttribute('data-dragging', '');
590
+ let last = start;
591
+ const move = (ev) => { last = start + (ev.clientX - x0) * (rtl ? -1 : 1); __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_setWidth).call(this, c, last, false); };
592
+ const end = () => {
593
+ handle.removeEventListener('pointermove', move);
594
+ handle.removeEventListener('pointerup', end);
595
+ handle.removeEventListener('pointercancel', end);
596
+ handle.removeAttribute('data-dragging');
597
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_setWidth).call(this, c, last, true);
598
+ };
599
+ handle.addEventListener('pointermove', move);
600
+ handle.addEventListener('pointerup', end);
601
+ handle.addEventListener('pointercancel', end);
602
+ }, _CmDataTable_togglePicker = function _CmDataTable_togglePicker(open = !this._picker) {
603
+ this._picker = open;
604
+ if (open)
605
+ document.addEventListener('pointerdown', __classPrivateFieldGet(this, _CmDataTable_onOutside, "f"), { capture: true });
606
+ else
607
+ document.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmDataTable_onOutside, "f"), { capture: true });
608
+ }, _CmDataTable_onPickerKey = function _CmDataTable_onPickerKey(e) {
609
+ if (e.key !== 'Escape' || !this._picker)
610
+ return;
611
+ e.stopPropagation();
612
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_togglePicker).call(this, false);
613
+ this.renderRoot.querySelector('.pick')?.focus();
614
+ }, _CmDataTable_setVisible = function _CmDataTable_setVisible(key, visible) {
615
+ const columns = this.columns.map((c) => (c.key === key ? { ...c, visible } : c));
616
+ this.columns = columns;
617
+ this.dispatchEvent(new CustomEvent('cm-columns-change', { detail: { key, visible, columns }, bubbles: true, composed: true }));
618
+ }, _CmDataTable_renderPicker = function _CmDataTable_renderPicker() {
619
+ const all = this.columns ?? [];
620
+ const primary = __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_primary).call(this, this.visibleColumns);
621
+ return html `<div class="tools" part="tools" @keydown=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onPickerKey)}>
622
+ <button type="button" class="pick" part="column-picker" aria-expanded=${this._picker ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmDataTable_id, "f")}-cols"
623
+ @click=${() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_togglePicker).call(this)}>${this.t('columns')}<cm-icon name="chevron-down" size="16" aria-hidden="true"></cm-icon></button>
624
+ <fieldset class="panel" id="${__classPrivateFieldGet(this, _CmDataTable_id, "f")}-cols" part="column-panel" ?hidden=${!this._picker}>
625
+ <legend class="sr">${this.t('showColumns')}</legend>
626
+ ${all.map((c) => html `<label class="opt"><input type="checkbox" .checked=${c.visible !== false} ?disabled=${c === primary}
627
+ @change=${(e) => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_setVisible).call(this, c.key, e.target.checked)} />${c.label}</label>`)}
628
+ </fieldset>
629
+ </div>`;
630
+ }, _CmDataTable_renderHead = function _CmDataTable_renderHead(c, primary) {
631
+ const on = this.sort === c.key;
632
+ const state = on ? this.direction : 'none';
633
+ const hideLabel = c.hidden || c.type === 'actions';
634
+ const label = hideLabel ? html `<span class="sr">${c.label}</span>` : html `<span class="t">${c.label}</span>`;
635
+ return html `<th scope="col" class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c, primary)} style=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_style).call(this, c)} aria-sort=${c.sortable ? state : nothing}><div class="h">${c.sortable
636
+ ? html `<button type="button" class="sort ${on ? 'on' : ''}" @click=${() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onSort).call(this, c)}>${label}<cm-icon
637
+ name=${on && this.direction === 'descending' ? 'chevron-down' : 'chevron-up'} size="12"></cm-icon></button>`
638
+ : label}${this.resizable && c.type !== 'actions'
639
+ ? html `<span class="rz" part="resize-handle" role="separator" aria-orientation="vertical" tabindex="0" aria-label=${this.t('resize', { column: c.label })}
640
+ aria-valuemin=${MIN_WIDTH} aria-valuemax="1600"
641
+ @keydown=${(e) => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onResizeKey).call(this, e, c)} @pointerdown=${(e) => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onResizeDown).call(this, e, c)}></span>`
642
+ : nothing}</div></th>`;
643
+ }, _CmDataTable_renderRow = function _CmDataTable_renderRow(r, cols, primary, low, index) {
644
+ const name = __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_rowName).call(this, r, primary);
645
+ const open = this._expanded.has(r);
646
+ const moreId = `${__classPrivateFieldGet(this, _CmDataTable_id, "f")}-more-${index}`;
647
+ const row = html `<tr part="row">${cols.map((c) => c === primary
648
+ ? html `<th scope="row" class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c, primary)} style=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_style).call(this, c)} part="cell">${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_content).call(this, c, r, name)}${low.length
649
+ ? html `<button type="button" class="more-btn" aria-expanded=${open ? 'true' : 'false'} aria-controls=${moreId}
650
+ @click=${() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_toggleRow).call(this, r)}>${this.t(open ? 'viewLess' : 'viewAll')}</button>` : nothing}</th>`
651
+ : html `<td class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c, primary)} style=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_style).call(this, c)} part="cell">${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_content).call(this, c, r, name)}</td>`)}</tr>`;
652
+ // One template whether or not the details are open, so the toggle button (and its focus) survives.
653
+ return html `${row}${low.length && open ? html `<tr class="more" id=${moreId} part="row-details"><td colspan=${cols.length - low.length}>
654
+ <dl class="pairs">${low.map((c) => html `<dt>${c.label}</dt><dd class=${isNum(c) ? 'num' : ''}>${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_text).call(this, r[c.key])}</dd>`)}</dl></td></tr>` : nothing}`;
655
+ }, _CmDataTable_toggleRow = function _CmDataTable_toggleRow(r) {
656
+ const next = new Set(this._expanded);
657
+ if (next.has(r))
658
+ next.delete(r);
659
+ else
660
+ next.add(r);
661
+ this._expanded = next;
662
+ }, _CmDataTable_renderCards = function _CmDataTable_renderCards(rows, cols, primary) {
663
+ const fields = cols.filter((c) => c !== primary && c.type !== 'actions');
664
+ const actionCols = cols.filter((c) => c.type === 'actions');
665
+ const card = (r, total = false) => {
666
+ const name = __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_rowName).call(this, r, primary);
667
+ return html `<li class="card ${total ? 'total' : ''}" part="card">
668
+ <p class="card-title">${name}</p>
669
+ ${fields.length ? html `<dl class="pairs">${fields.map((c) => html `<dt>${c.label}</dt><dd class=${isNum(c) ? 'num' : ''}>${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_text).call(this, r[c.key])}</dd>`)}</dl>` : nothing}
670
+ ${!total && actionCols.length ? html `<div class="card-actions">${actionCols.map((c) => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_actions).call(this, c, r, name))}</div>` : nothing}
671
+ </li>`;
672
+ };
673
+ return html `${this.caption ? html `<p class="cards-caption" aria-hidden="true">${this.caption}</p>` : nothing}
674
+ <ul class="cards" part="cards" aria-label=${this.caption || nothing}>${rows.map((r) => card(r))}${this.totals ? card(this.totals, true) : nothing}</ul>`;
294
675
  };
295
676
  CmDataTable.properties = {
296
677
  columns: { type: Array },
@@ -305,49 +686,178 @@ CmDataTable.properties = {
305
686
  stickyFirstColumn: { type: Boolean, attribute: 'sticky-first-column', reflect: true },
306
687
  loading: { type: Boolean, reflect: true },
307
688
  loadingRows: { type: Number, attribute: 'loading-rows' },
689
+ density: { reflect: true },
690
+ mobile: { reflect: true },
691
+ rowActions: { attribute: 'row-actions', reflect: true },
692
+ resizable: { type: Boolean, reflect: true },
693
+ columnPicker: { type: Boolean, attribute: 'column-picker', reflect: true },
308
694
  _light: { state: true },
309
695
  _announce: { state: true },
696
+ _widths: { state: true },
697
+ _expanded: { state: true },
698
+ _picker: { state: true },
699
+ _overflows: { state: true },
310
700
  };
311
701
  CmDataTable.styles = [
312
702
  base,
313
703
  css `
314
704
  :host { display: block; font-size: var(--cm-font-size-14); line-height: var(--cm-line-height-14); font-variant-numeric: tabular-nums; }
705
+ :host([density='compact']) { --cm-table-row-height: 40px; }
706
+ :host([density='comfortable']) { --cm-table-row-height: 48px; }
707
+ /* The table's own width decides the phone layout (mobile), not the window's. */
708
+ .frame { container-type: inline-size; }
709
+ .wrap { position: relative; }
315
710
  .scroll { overflow: auto; max-block-size: var(--cm-data-table-max-height, none); }
711
+ /* Sticky heading row without a max height: when the table fits, the box stops being a scroll container so the
712
+ heading can stick to the page or an outer scrolling box. (When it scrolls sideways, measure() moves it.) */
713
+ .scroll[data-open] { overflow: visible; }
316
714
  .scroll:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
317
- table { inline-size: 100%; border-collapse: separate; border-spacing: 0; }
715
+ table {
716
+ inline-size: 100%; border-collapse: separate; border-spacing: 0;
717
+ font-size: var(--cm-font-size-13); line-height: var(--cm-line-height-13);
718
+ }
318
719
  caption { text-align: start; font-weight: 600; font-size: var(--cm-font-size-16); line-height: var(--cm-line-height-16); padding-block-end: var(--cm-space-8); }
319
- :host([caption-hidden]) caption {
720
+ :host([caption-hidden]) caption, .sr {
320
721
  position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
321
722
  }
322
- th, td { padding: var(--cm-space-8) var(--cm-space-16); text-align: start; vertical-align: middle; }
723
+ th, td { padding: 0 var(--cm-space-12); text-align: start; vertical-align: middle; }
724
+ /* Heading row: 40px, 12px semibold. */
323
725
  thead th {
324
- font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-12); font-weight: 500; padding-block: var(--cm-space-8); white-space: nowrap; color: var(--cm-text-tertiary);
325
-
726
+ position: relative; block-size: var(--cm-table-header-height, 40px);
727
+ font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-12); font-weight: 600; white-space: nowrap; color: var(--cm-text-tertiary);
326
728
  background: var(--cm-bg-hover); border-block: var(--cm-border-1) solid var(--cm-border-subtle);
327
729
  }
328
730
  thead th:first-child { border-inline-start: var(--cm-border-1) solid var(--cm-border-subtle); border-start-start-radius: var(--cm-radius-md); }
329
731
  thead th:last-child { border-inline-end: var(--cm-border-1) solid var(--cm-border-subtle); border-start-end-radius: var(--cm-radius-md); }
330
- tbody td, tbody th { font-weight: 400; border-block-end: var(--cm-border-1) solid var(--cm-border-subtle); background: var(--cm-bg-surface); }
732
+ /* Body rows: 48px (compact 40px), cells padded 12px across and 10px down, 13px text. */
733
+ tbody td, tbody th, tfoot td {
734
+ block-size: var(--cm-table-row-height, 48px);
735
+ padding-block: 10px; /* scale-exempt: the table standard (#33) pads cells 10px down */
736
+ border-block-end: var(--cm-border-1) solid var(--cm-border-subtle); background: var(--cm-bg-surface);
737
+ }
738
+ tbody td, tbody th { font-weight: 400; }
739
+ @media (pointer: coarse) {
740
+ tbody td, tbody th, tfoot td { block-size: max(var(--cm-table-row-height, 48px), var(--cm-control-height-touch, 44px)); }
741
+ }
331
742
  tbody tr:hover td, tbody tr:hover th { background: var(--cm-bg-hover); }
332
- tfoot td { font-weight: 500; background: var(--cm-bg-surface); border-block-end: var(--cm-border-1) solid var(--cm-border-subtle); }
743
+ tfoot td { font-weight: 500; }
333
744
  .end { text-align: end; }
334
745
  .num { font-variant-numeric: tabular-nums; }
335
- :host([sticky-header]) thead th { position: sticky; inset-block-start: 0; z-index: 2; }
746
+ .nw { white-space: nowrap; }
747
+ /* Text cells: one line, "…" when longer than the column (title shows the full value on hover). 45cqi: at most
748
+ 45% of the table's width, so a long name can't push the other columns out of a narrow table. */
749
+ .t { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-inline-size: min(var(--cm-data-table-cell-max-width, 320px), 45cqi); }
750
+ /* A column with a width (set, or resized): exactly that wide, whatever its content. */
751
+ .w { inline-size: var(--_w); min-inline-size: var(--_w); max-inline-size: var(--_w); }
752
+ .w > .t, .w > .h { inline-size: 0; min-inline-size: 100%; max-inline-size: none; }
753
+ .w > .h .t { max-inline-size: none; }
754
+ .h { display: flex; align-items: center; min-inline-size: 0; }
755
+ .end > .h { justify-content: flex-end; }
756
+ .act { inline-size: 1%; white-space: nowrap; }
757
+ tbody .act { padding-block: 0; } /* a 32px button fits a 40px compact row */
758
+ .acts { display: inline-flex; gap: var(--cm-space-8); justify-content: flex-end; vertical-align: middle; transition: opacity var(--cm-duration-fast) var(--cm-easing-standard); }
759
+ /* Row actions appear on hover and while the row has focus. They stay in the accessibility tree and in the tab order
760
+ (opacity only), and are always shown on touch screens, which have no hover. */
761
+ /* data-focus: set from focusin/focusout as well, since WebKit doesn't match :focus-within across the buttons' shadow roots. */
762
+ :host(:not([row-actions='always'])) tbody tr:not(:hover):not(:focus-within):not([data-focus]) .acts { opacity: 0; }
763
+ @media (hover: none), (pointer: coarse) { :host(:not([row-actions='always'])) tbody tr:not(:hover):not(:focus-within):not([data-focus]) .acts { opacity: 1; } }
764
+ :host(:not([row-actions='always'])) tbody tr[data-focus] .acts { opacity: 1; }
765
+ @media (prefers-reduced-motion: reduce) { .acts { transition: none; } }
766
+ :host([sticky-header]) thead th {
767
+ position: sticky; inset-block-start: var(--cm-data-table-sticky-top, 0px); z-index: 2; transform: translateY(var(--_shift, 0px));
768
+ }
336
769
  :host([sticky-first-column]) tr > :first-child { position: sticky; inset-inline-start: 0; z-index: 1; }
337
770
  :host([sticky-first-column]) thead th:first-child { z-index: 3; }
338
771
  :host([sticky-first-column]) tfoot td:first-child { background: var(--cm-bg-surface); }
339
- .sr { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
340
- button {
341
- display: inline-flex; align-items: center; gap: 4px; padding: 2px 0; font: inherit; color: inherit;
772
+ button.sort {
773
+ display: inline-flex; align-items: center; gap: 4px; max-inline-size: 100%; min-inline-size: 0; padding: 2px 0; font: inherit; color: inherit;
342
774
  background: none; border: 0; cursor: pointer; text-align: inherit;
343
775
  }
344
- .end button { flex-direction: row-reverse; }
345
- button cm-icon { color: var(--cm-icon-selected); opacity: 0; }
346
- button:hover cm-icon, button.on cm-icon { opacity: 1; }
347
- button:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
348
- .empty td { padding: var(--cm-space-20); border-block-end: 0; }
776
+ .end button.sort { flex-direction: row-reverse; }
777
+ button.sort cm-icon { flex: none; color: var(--cm-icon-selected); opacity: 0; }
778
+ button.sort:hover cm-icon, button.sort.on cm-icon { opacity: 1; }
779
+ button:focus-visible, .rz:focus-visible, input:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
780
+ /* Resize handle: a 24px strip centred on the heading's end edge (inside the last heading). */
781
+ .rz {
782
+ position: absolute; inset-block: 0; inset-inline-end: calc(-1 * var(--cm-space-12, 12px)); z-index: 4; inline-size: var(--cm-space-24, 24px);
783
+ cursor: col-resize; touch-action: none; display: flex; justify-content: center;
784
+ }
785
+ th:last-child > .h > .rz { inset-inline-end: 0; }
786
+ .rz::after { content: ''; inline-size: 2px; block-size: 100%; background: transparent; }
787
+ .rz:hover::after, .rz:focus-visible::after, .rz[data-dragging]::after { background: var(--cm-border-strong); }
788
+ .empty td { padding: var(--cm-space-20); border-block-end: 0; block-size: auto; }
349
789
  .light { display: contents; }
350
- @media (forced-colors: active) { button cm-icon { opacity: 1; } }
790
+ /* Scroll affordance: faded edges where there is more, and a hint under the table. */
791
+ .fade {
792
+ position: absolute; inset-block: var(--_cap, 0px) 0; inline-size: var(--cm-space-24); pointer-events: none; z-index: 5; opacity: 0;
793
+ transition: opacity var(--cm-duration-fast) var(--cm-easing-standard);
794
+ }
795
+ .fade.s { inset-inline-start: 0; background: linear-gradient(to right, var(--cm-bg-surface), transparent); }
796
+ .fade.e { inset-inline-end: 0; background: linear-gradient(to left, var(--cm-bg-surface), transparent); }
797
+ :host(:dir(rtl)) .fade.s { background: linear-gradient(to left, var(--cm-bg-surface), transparent); }
798
+ :host(:dir(rtl)) .fade.e { background: linear-gradient(to right, var(--cm-bg-surface), transparent); }
799
+ .frame[data-more-start] .fade.s, .frame[data-more-end] .fade.e { opacity: 1; }
800
+ :host([sticky-first-column]) .fade.s { display: none; }
801
+ @media (prefers-reduced-motion: reduce) { .fade { transition: none; } }
802
+ .hint {
803
+ display: none; align-items: center; justify-content: flex-end; gap: var(--cm-space-4); margin: 0; padding-block-start: var(--cm-space-8);
804
+ font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-12); color: var(--cm-text-tertiary);
805
+ }
806
+ .frame[data-more-end] .hint { display: flex; }
807
+ /* Column picker. */
808
+ .tools { position: relative; display: flex; justify-content: flex-end; padding-block-end: var(--cm-space-8); }
809
+ .pick {
810
+ display: inline-flex; align-items: center; gap: var(--cm-space-4); block-size: var(--cm-control-height-sm, 32px); padding: 0 var(--cm-space-12);
811
+ font: inherit; font-size: var(--cm-font-size-13); font-weight: 500; color: var(--cm-text-default); cursor: pointer;
812
+ background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm);
813
+ }
814
+ .pick:hover { background: var(--cm-bg-hover); }
815
+ .panel {
816
+ position: absolute; inset-block-start: 100%; inset-inline-end: 0; z-index: 10; min-inline-size: 200px; margin: 0; padding: var(--cm-space-8);
817
+ background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-subtle); border-radius: var(--cm-radius-md); box-shadow: var(--cm-shadow-md);
818
+ }
819
+ .panel legend { padding: 0; }
820
+ .opt {
821
+ display: flex; align-items: center; gap: var(--cm-space-8); min-block-size: var(--cm-control-height-sm, 32px); padding: 0 var(--cm-space-8);
822
+ font-size: var(--cm-font-size-13); border-radius: var(--cm-radius-sm); cursor: pointer;
823
+ }
824
+ .opt:hover { background: var(--cm-bg-hover); }
825
+ .opt input { inline-size: 16px; block-size: 16px; margin: 0; accent-color: var(--cm-icon-selected); }
826
+ @media (pointer: coarse) {
827
+ .pick { block-size: var(--cm-control-height-touch, 44px); }
828
+ .opt { min-block-size: var(--cm-control-height-touch, 44px); }
829
+ }
830
+ /* Priority strategy: the row's "View all fields" button and the row of low-priority fields it opens. */
831
+ .more-btn {
832
+ display: none; align-items: center; min-block-size: var(--cm-space-24); margin-block-start: var(--cm-space-4); padding: 0;
833
+ font: inherit; font-size: var(--cm-font-size-12); font-weight: 500; color: var(--cm-text-default); text-decoration: underline;
834
+ background: none; border: 0; cursor: pointer;
835
+ }
836
+ tr.more { display: none; }
837
+ tr.more td { block-size: auto; background: var(--cm-bg-hover); }
838
+ .pairs { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); gap: var(--cm-space-4) var(--cm-space-12); margin: 0; }
839
+ .pairs dt { color: var(--cm-text-tertiary); font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-13); }
840
+ .pairs dd { margin: 0; min-inline-size: 0; overflow-wrap: anywhere; }
841
+ .pairs dd.num { text-align: end; white-space: nowrap; }
842
+ /* Cards strategy. */
843
+ .cards { display: none; list-style: none; margin: 0; padding: 0; gap: var(--cm-space-8); font-size: var(--cm-font-size-13); line-height: var(--cm-line-height-13); }
844
+ .cards-caption { display: none; margin: 0; padding-block-end: var(--cm-space-8); font-weight: 600; font-size: var(--cm-font-size-16); line-height: var(--cm-line-height-16); }
845
+ .card {
846
+ display: grid; gap: var(--cm-space-8); padding: var(--cm-space-12) var(--cm-space-16);
847
+ background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-subtle); border-radius: var(--cm-radius-md);
848
+ }
849
+ .card-title { margin: 0; font-size: var(--cm-font-size-14); line-height: var(--cm-line-height-14); font-weight: 600; overflow-wrap: anywhere; }
850
+ .card.total .card-title { font-weight: 500; }
851
+ .card-actions { display: flex; flex-wrap: wrap; gap: var(--cm-space-8); padding-block-start: var(--cm-space-4); }
852
+ @container (max-width: 640px) {
853
+ :host([mobile='cards']) .frame[data-cards] .wrap, :host([mobile='cards']) .frame[data-cards] .hint { display: none; }
854
+ :host([mobile='cards']) .frame[data-cards] .cards { display: grid; }
855
+ :host([mobile='cards']:not([caption-hidden])) .frame[data-cards] .cards-caption { display: block; }
856
+ :host([mobile='priority']) .low { display: none; }
857
+ :host([mobile='priority']) .more-btn { display: inline-flex; }
858
+ :host([mobile='priority']) tr.more { display: table-row; }
859
+ }
860
+ @media (forced-colors: active) { button.sort cm-icon { opacity: 1; } .acts { opacity: 1 !important; } }
351
861
  `,
352
862
  ];
353
863
  define('cm-data-table', CmDataTable);