@commmerce/ui 0.0.0-stage → 1.0.0-rc.4

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 (125) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +41 -2
  3. package/dist/base.d.ts +7 -0
  4. package/dist/base.js +22 -0
  5. package/dist/cdn.js +1958 -0
  6. package/dist/components/accordion.d.ts +43 -0
  7. package/dist/components/accordion.js +83 -0
  8. package/dist/components/action-bar.d.ts +42 -0
  9. package/dist/components/action-bar.js +84 -0
  10. package/dist/components/action-menu.d.ts +89 -0
  11. package/dist/components/action-menu.js +283 -0
  12. package/dist/components/app-card.d.ts +57 -0
  13. package/dist/components/app-card.js +100 -0
  14. package/dist/components/avatar.d.ts +48 -0
  15. package/dist/components/avatar.js +82 -0
  16. package/dist/components/badge.d.ts +23 -0
  17. package/dist/components/badge.js +35 -0
  18. package/dist/components/banner.d.ts +36 -0
  19. package/dist/components/banner.js +88 -0
  20. package/dist/components/bottom-navigation.d.ts +48 -0
  21. package/dist/components/bottom-navigation.js +98 -0
  22. package/dist/components/bottom-sheet.d.ts +54 -0
  23. package/dist/components/bottom-sheet.js +133 -0
  24. package/dist/components/button.d.ts +53 -0
  25. package/dist/components/button.js +101 -0
  26. package/dist/components/card.d.ts +37 -0
  27. package/dist/components/card.js +58 -0
  28. package/dist/components/checkbox.d.ts +68 -0
  29. package/dist/components/checkbox.js +114 -0
  30. package/dist/components/comment.d.ts +76 -0
  31. package/dist/components/comment.js +170 -0
  32. package/dist/components/data-table.d.ts +132 -0
  33. package/dist/components/data-table.js +331 -0
  34. package/dist/components/empty-state.d.ts +49 -0
  35. package/dist/components/empty-state.js +94 -0
  36. package/dist/components/file-upload.d.ts +102 -0
  37. package/dist/components/file-upload.js +243 -0
  38. package/dist/components/filter-panel.d.ts +86 -0
  39. package/dist/components/filter-panel.js +128 -0
  40. package/dist/components/flash-offer-bar.d.ts +34 -0
  41. package/dist/components/flash-offer-bar.js +73 -0
  42. package/dist/components/grid.d.ts +39 -0
  43. package/dist/components/grid.js +42 -0
  44. package/dist/components/header-bar.d.ts +48 -0
  45. package/dist/components/header-bar.js +121 -0
  46. package/dist/components/icon.d.ts +30 -0
  47. package/dist/components/icon.js +36 -0
  48. package/dist/components/info-panel.d.ts +63 -0
  49. package/dist/components/info-panel.js +108 -0
  50. package/dist/components/layout.d.ts +45 -0
  51. package/dist/components/layout.js +67 -0
  52. package/dist/components/link-tabs.d.ts +40 -0
  53. package/dist/components/link-tabs.js +85 -0
  54. package/dist/components/menu-item.d.ts +68 -0
  55. package/dist/components/menu-item.js +64 -0
  56. package/dist/components/mobile-menu.d.ts +69 -0
  57. package/dist/components/mobile-menu.js +184 -0
  58. package/dist/components/modal.d.ts +46 -0
  59. package/dist/components/modal.js +59 -0
  60. package/dist/components/nav-item.d.ts +98 -0
  61. package/dist/components/nav-item.js +84 -0
  62. package/dist/components/nested-list.d.ts +105 -0
  63. package/dist/components/nested-list.js +279 -0
  64. package/dist/components/notification-panel.d.ts +121 -0
  65. package/dist/components/notification-panel.js +174 -0
  66. package/dist/components/option-group.d.ts +74 -0
  67. package/dist/components/option-group.js +172 -0
  68. package/dist/components/page-header.d.ts +58 -0
  69. package/dist/components/page-header.js +121 -0
  70. package/dist/components/page.d.ts +34 -0
  71. package/dist/components/page.js +41 -0
  72. package/dist/components/pagination.d.ts +64 -0
  73. package/dist/components/pagination.js +160 -0
  74. package/dist/components/progress-bar.d.ts +45 -0
  75. package/dist/components/progress-bar.js +81 -0
  76. package/dist/components/radio.d.ts +131 -0
  77. package/dist/components/radio.js +252 -0
  78. package/dist/components/report-tile.d.ts +65 -0
  79. package/dist/components/report-tile.js +112 -0
  80. package/dist/components/resource-list.d.ts +143 -0
  81. package/dist/components/resource-list.js +335 -0
  82. package/dist/components/save-bar.d.ts +58 -0
  83. package/dist/components/save-bar.js +128 -0
  84. package/dist/components/search.d.ts +78 -0
  85. package/dist/components/search.js +144 -0
  86. package/dist/components/select.d.ts +106 -0
  87. package/dist/components/select.js +338 -0
  88. package/dist/components/side-navigation.d.ts +51 -0
  89. package/dist/components/side-navigation.js +194 -0
  90. package/dist/components/side-panel.d.ts +50 -0
  91. package/dist/components/side-panel.js +73 -0
  92. package/dist/components/skeleton-display.d.ts +32 -0
  93. package/dist/components/skeleton-display.js +70 -0
  94. package/dist/components/skeleton.d.ts +41 -0
  95. package/dist/components/skeleton.js +59 -0
  96. package/dist/components/smart-tip.d.ts +62 -0
  97. package/dist/components/smart-tip.js +128 -0
  98. package/dist/components/spinner.d.ts +27 -0
  99. package/dist/components/spinner.js +48 -0
  100. package/dist/components/stack.d.ts +45 -0
  101. package/dist/components/stack.js +49 -0
  102. package/dist/components/status-tabs.d.ts +65 -0
  103. package/dist/components/status-tabs.js +158 -0
  104. package/dist/components/table-header.d.ts +84 -0
  105. package/dist/components/table-header.js +151 -0
  106. package/dist/components/tag.d.ts +39 -0
  107. package/dist/components/tag.js +68 -0
  108. package/dist/components/text-field.d.ts +101 -0
  109. package/dist/components/text-field.js +162 -0
  110. package/dist/components/thumbnail.d.ts +40 -0
  111. package/dist/components/thumbnail.js +61 -0
  112. package/dist/components/toast.d.ts +108 -0
  113. package/dist/components/toast.js +268 -0
  114. package/dist/components/toggle.d.ts +60 -0
  115. package/dist/components/toggle.js +108 -0
  116. package/dist/components/tooltip.d.ts +56 -0
  117. package/dist/components/tooltip.js +267 -0
  118. package/dist/custom-elements.json +13222 -0
  119. package/dist/index.d.ts +70 -0
  120. package/dist/index.js +56 -0
  121. package/dist/overlay.d.ts +57 -0
  122. package/dist/overlay.js +205 -0
  123. package/dist/spacing.d.ts +6 -0
  124. package/dist/spacing.js +7 -0
  125. package/package.json +59 -4
@@ -0,0 +1,331 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
+ if (kind === "m") throw new TypeError("Private method is not writable");
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
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
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
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;
13
+ import { LitElement, html, css, nothing } from 'lit';
14
+ import { base, define } from '../base.js';
15
+ import './icon.js';
16
+ import './skeleton.js';
17
+ let sheetAdded = false;
18
+ /**
19
+ * Styles for a server-rendered `<table>` written inside `cm-data-table` (light DOM, so it can't be styled
20
+ * from the shadow root). Added to the document once, scoped to `cm-data-table > table`.
21
+ */
22
+ const LIGHT_CSS = `
23
+ cm-data-table > table { width: 100%; border-collapse: separate; border-spacing: 0; font: inherit; font-size: 14px; line-height: 1.5; color: var(--cm-text-default); }
24
+ cm-data-table > table caption { text-align: start; font-weight: 500; font-size: 16px; padding-block-end: var(--cm-space-10); }
25
+ cm-data-table > table th { font-size: 12px; font-weight: 400; text-align: start; padding: 7px var(--cm-space-20); background: var(--cm-bg-hover); border-block: var(--cm-border-1) solid var(--cm-border-subtle); white-space: nowrap; }
26
+ 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); }
27
+ 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); }
28
+ cm-data-table > table td { padding: var(--cm-space-10) var(--cm-space-20); border-block-end: var(--cm-border-1) solid var(--cm-border-default); vertical-align: middle; }
29
+ 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-default); font-size: 14px; }
30
+ cm-data-table > table tbody tr:hover td, cm-data-table > table tbody tr:hover th { background: var(--cm-bg-hover); }
31
+ 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; }
32
+ 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; }
33
+ cm-data-table > table th > button.cm-sort cm-icon { color: var(--cm-icon-selected); opacity: 0; }
34
+ 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; }
35
+ cm-data-table > table th > button.cm-sort:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
36
+ @media (forced-colors: active) { cm-data-table > table th > button.cm-sort cm-icon { opacity: 1; } }
37
+ 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; }
38
+ `;
39
+ function addLightStyles() {
40
+ if (sheetAdded || typeof document === 'undefined')
41
+ return;
42
+ sheetAdded = true;
43
+ const sheet = new CSSStyleSheet();
44
+ sheet.replaceSync(LIGHT_CSS);
45
+ document.adoptedStyleSheets = [...document.adoptedStyleSheets, sheet];
46
+ }
47
+ const isEnd = (c) => (c.align ?? (c.type === 'numeric' || c.type === 'money' ? 'end' : 'start')) === 'end';
48
+ /**
49
+ * Reads a number from a cell: 1200, "1,200", "Rs. 1,200", "₹1,200.50", "-500", "(500)" (negative), "12%".
50
+ * Leading text such as a currency is skipped, so its dot is never read as a decimal point.
51
+ */
52
+ function toNumber(v) {
53
+ if (typeof v === 'number')
54
+ return v;
55
+ const text = String(v ?? '').trim();
56
+ const negative = /^\(.*\)$/.test(text) || /^-|^[^\d]*-\s*\d/.test(text);
57
+ const m = text.match(/\d[\d,]*(?:\.\d+)?/);
58
+ if (!m)
59
+ return NaN;
60
+ const n = Number(m[0].replace(/,/g, ''));
61
+ return negative ? -n : n;
62
+ }
63
+ const toTime = (v) => (v instanceof Date ? v.getTime() : typeof v === 'number' ? v : Date.parse(String(v ?? '')));
64
+ const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' });
65
+ /** Compares two cell values the way a column of `type` should sort. Empty values sort last. */
66
+ function compare(a, b, type) {
67
+ const empty = (v) => v === null || v === undefined || v === '';
68
+ if (empty(a) || empty(b))
69
+ return empty(a) === empty(b) ? 0 : empty(a) ? 1 : -1;
70
+ if (type === 'numeric' || type === 'money')
71
+ return (toNumber(a) || 0) - (toNumber(b) || 0);
72
+ if (type === 'date')
73
+ return (toTime(a) || 0) - (toTime(b) || 0);
74
+ return collator.compare(String(a), String(b));
75
+ }
76
+ /**
77
+ * A data table for reports and read-only lists: sales by day, stock by location, order lines.
78
+ * A real `<table>` with column headings, sortable columns, a totals row, a sticky header and first column,
79
+ * loading rows and an empty state. For lists merchants select and act on, use Resource list.
80
+ *
81
+ * Give it `columns` and `rows`, or write a native `<table>` inside it (for server-rendered pages): that
82
+ * table is styled to match. Mark a heading `<th data-sort="text|numeric|money|date">` to make its column sortable
83
+ * in the browser too (a cell's `data-value` is compared instead of its text when present; `data-key` names the
84
+ * column in `cm-sort`). Every sort is announced to screen readers ("Sorted by Net sales, descending").
85
+ * @element cm-data-table
86
+ * @slot - Optional: a native `<table>` to style instead of `columns`/`rows`.
87
+ * @slot empty - Shown instead of the rows when `rows` is empty, e.g. a `cm-empty-state`.
88
+ * @fires cm-sort - `detail: { key, direction }` when a sortable heading is clicked. Cancelable: call
89
+ * `preventDefault()` to stop the table sorting itself. With `sort-mode="manual"` it never sorts itself.
90
+ * @cssprop --cm-data-table-max-height - With `sticky-header`, the table scrolls inside this height. Default `none`.
91
+ */
92
+ export class CmDataTable extends LitElement {
93
+ constructor() {
94
+ super(...arguments);
95
+ _CmDataTable_instances.add(this);
96
+ /** The columns, in order. */
97
+ this.columns = [];
98
+ /** The rows: objects keyed by column `key`. Values are shown as text. */
99
+ this.rows = [];
100
+ /** A totals row shown at the bottom (`<tfoot>`), keyed like a row. Leave a key out for an empty cell. */
101
+ this.totals = null;
102
+ /** What the table shows, e.g. "Sales by day". Every table needs one; it names the table for screen readers. */
103
+ this.caption = '';
104
+ /** Keeps the caption for screen readers but hides it, when a card or page heading already says it. */
105
+ this.captionHidden = false;
106
+ /** Key of the sorted column. Empty: rows stay in the order given. */
107
+ this.sort = '';
108
+ /** Direction of the sorted column. */
109
+ this.direction = 'ascending';
110
+ /** `auto`: the table sorts its own rows. `manual`: it only fires `cm-sort` (sort on your server, then set `rows`). */
111
+ this.sortMode = 'auto';
112
+ /** Keeps the heading row visible while the table scrolls inside `--cm-data-table-max-height`. */
113
+ this.stickyHeader = false;
114
+ /** Keeps the first column visible while the table scrolls sideways (on narrow screens). */
115
+ this.stickyFirstColumn = false;
116
+ /** Shows placeholder rows and marks the table busy. */
117
+ this.loading = false;
118
+ /** How many placeholder rows `loading` shows. */
119
+ this.loadingRows = 5;
120
+ this._light = false;
121
+ this._announce = '';
122
+ _CmDataTable_userSorted.set(this, false);
123
+ _CmDataTable_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_readLight).call(this)));
124
+ }
125
+ connectedCallback() {
126
+ super.connectedCallback();
127
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_readLight).call(this);
128
+ // subtree: while the page is still being parsed, the table's head and rows arrive after the table itself.
129
+ __classPrivateFieldGet(this, _CmDataTable_observer, "f").observe(this, { childList: true, subtree: true });
130
+ }
131
+ disconnectedCallback() {
132
+ super.disconnectedCallback();
133
+ __classPrivateFieldGet(this, _CmDataTable_observer, "f").disconnect();
134
+ }
135
+ /** The rows in display order: sorted when `sort` is set and `sort-mode` is `auto`. */
136
+ get sortedRows() {
137
+ const rows = [...(this.rows ?? [])];
138
+ const col = this.columns.find((c) => c.key === this.sort);
139
+ if (!col || this.sortMode === 'manual')
140
+ return rows;
141
+ const sign = this.direction === 'descending' ? -1 : 1;
142
+ // Stable sort; empty values stay last in both directions.
143
+ return rows.map((r, i) => [r, i]).sort(([a, i], [b, j]) => {
144
+ const av = a[col.key], bv = b[col.key];
145
+ const emptyA = av === null || av === undefined || av === '', emptyB = bv === null || bv === undefined || bv === '';
146
+ if (emptyA || emptyB)
147
+ return emptyA === emptyB ? i - j : emptyA ? 1 : -1;
148
+ return sign * compare(av, bv, col.type) || i - j;
149
+ }).map(([r]) => r);
150
+ }
151
+ updated(changed) {
152
+ if (__classPrivateFieldGet(this, _CmDataTable_userSorted, "f") && (changed.has('sort') || changed.has('direction')) && this.sort) {
153
+ __classPrivateFieldSet(this, _CmDataTable_userSorted, false, "f");
154
+ const col = this.columns.find((c) => c.key === this.sort);
155
+ if (col)
156
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_say).call(this, col.label, this.direction);
157
+ }
158
+ }
159
+ render() {
160
+ const status = html `<span class="sr" role="status">${this._announce}</span>`;
161
+ if (this._light)
162
+ return html `<div class="scroll" part="scroll"><slot></slot></div>${status}`;
163
+ const cols = this.columns ?? [];
164
+ const rows = this.sortedRows;
165
+ const n = Math.max(1, cols.length);
166
+ const showEmpty = !this.loading && rows.length === 0;
167
+ return html `
168
+ <div class="scroll" part="scroll" tabindex=${this.stickyHeader || this.stickyFirstColumn ? '0' : nothing}
169
+ role=${this.stickyHeader || this.stickyFirstColumn ? 'region' : nothing}
170
+ aria-label=${(this.stickyHeader || this.stickyFirstColumn) && this.caption ? this.caption : nothing}>
171
+ <table part="table" aria-busy=${this.loading ? 'true' : 'false'}>
172
+ ${this.caption ? html `<caption part="caption">${this.caption}</caption>` : nothing}
173
+ <thead><tr>${cols.map((c) => {
174
+ const on = this.sort === c.key;
175
+ const state = on ? this.direction : 'none';
176
+ const label = c.hidden ? html `<span class="sr">${c.label}</span>` : c.label;
177
+ return html `<th scope="col" class=${__classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_cls).call(this, c)} aria-sort=${c.sortable ? state : nothing}>${c.sortable
178
+ ? html `<button type="button" class=${on ? 'on' : ''} @click=${() => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onSort).call(this, c)}>${label}<cm-icon
179
+ name=${on && this.direction === 'descending' ? 'chevron-down' : 'chevron-up'} size="12"></cm-icon></button>`
180
+ : label}</th>`;
181
+ })}</tr></thead>
182
+ <tbody>
183
+ ${this.loading
184
+ ? 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>`)
185
+ : rows.map((r) => html `<tr part="row">${cols.map((c, i) => i === 0
186
+ ? 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>`
187
+ : 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>`)}
188
+ ${showEmpty ? html `<tr class="empty"><td colspan=${n}><slot name="empty">No data</slot></td></tr>` : nothing}
189
+ </tbody>
190
+ ${this.totals && !this.loading && !showEmpty
191
+ ? 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>`
192
+ : nothing}
193
+ </table>
194
+ </div>${status}
195
+ `;
196
+ }
197
+ }
198
+ _CmDataTable_userSorted = new WeakMap(), _CmDataTable_observer = new WeakMap(), _CmDataTable_instances = new WeakSet(), _CmDataTable_readLight = function _CmDataTable_readLight() {
199
+ this._light = !!this.querySelector(':scope > table');
200
+ if (this._light) {
201
+ addLightStyles();
202
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_enhanceLight).call(this);
203
+ }
204
+ }, _CmDataTable_say = function _CmDataTable_say(label, direction) {
205
+ this._announce = `Sorted by ${label}, ${direction}`;
206
+ }, _CmDataTable_enhanceLight = function _CmDataTable_enhanceLight() {
207
+ const table = this.querySelector(':scope > table');
208
+ const cells = table?.tHead?.rows[0]?.cells;
209
+ if (!cells)
210
+ return;
211
+ [...cells].forEach((th, index) => {
212
+ if (!th.dataset.sort || th.querySelector(':scope > button.cm-sort'))
213
+ return;
214
+ th.dataset.type = th.dataset.sort;
215
+ const button = document.createElement('button');
216
+ button.type = 'button';
217
+ button.className = 'cm-sort';
218
+ button.append(...th.childNodes);
219
+ const icon = document.createElement('cm-icon');
220
+ icon.setAttribute('size', '12');
221
+ button.append(icon);
222
+ th.append(button);
223
+ if (!th.hasAttribute('aria-sort'))
224
+ th.setAttribute('aria-sort', 'none');
225
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_lightIcon).call(this, th);
226
+ button.addEventListener('click', () => __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onLightSort).call(this, table, th, index));
227
+ });
228
+ }, _CmDataTable_lightIcon = function _CmDataTable_lightIcon(th) {
229
+ th.querySelector(':scope > button.cm-sort > cm-icon')?.setAttribute('name', th.getAttribute('aria-sort') === 'descending' ? 'chevron-down' : 'chevron-up');
230
+ }, _CmDataTable_onLightSort = function _CmDataTable_onLightSort(table, th, index) {
231
+ const label = (th.querySelector(':scope > button.cm-sort')?.textContent ?? '').trim();
232
+ const key = th.dataset.key || label;
233
+ const direction = th.getAttribute('aria-sort') === 'ascending' ? 'descending' : 'ascending';
234
+ const ev = new CustomEvent('cm-sort', { detail: { key, direction }, bubbles: true, composed: true, cancelable: true });
235
+ if (!this.dispatchEvent(ev) || this.sortMode === 'manual')
236
+ return;
237
+ const type = th.dataset.sort;
238
+ const sign = direction === 'descending' ? -1 : 1;
239
+ for (const body of table.tBodies) {
240
+ const value = (r) => { const c = r.cells[index]; return c ? (c.dataset.value ?? c.textContent ?? '').trim() : ''; };
241
+ const sorted = [...body.rows].map((r, i) => [r, value(r), i]).sort(([, a, i], [, b, j]) => {
242
+ if (a === '' || b === '')
243
+ return a === b ? i - j : a === '' ? 1 : -1;
244
+ return sign * compare(a, b, type) || i - j;
245
+ });
246
+ body.append(...sorted.map(([r]) => r));
247
+ }
248
+ for (const other of table.tHead.rows[0].cells) {
249
+ if (!other.dataset.sort)
250
+ continue;
251
+ other.setAttribute('aria-sort', other === th ? direction : 'none');
252
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_lightIcon).call(this, other);
253
+ }
254
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_say).call(this, label, direction);
255
+ }, _CmDataTable_onSort = function _CmDataTable_onSort(c) {
256
+ const direction = this.sort === c.key && this.direction === 'ascending' ? 'descending' : 'ascending';
257
+ const ev = new CustomEvent('cm-sort', { detail: { key: c.key, direction }, bubbles: true, composed: true, cancelable: true });
258
+ // In manual mode the page sorts and then sets `sort`/`direction`; the announcement waits for that.
259
+ const ok = this.dispatchEvent(ev);
260
+ __classPrivateFieldSet(this, _CmDataTable_userSorted, ok, "f");
261
+ if (ok && this.sortMode !== 'manual') {
262
+ this.sort = c.key;
263
+ this.direction = direction;
264
+ }
265
+ }, _CmDataTable_text = function _CmDataTable_text(v) {
266
+ if (v === null || v === undefined)
267
+ return '';
268
+ if (v instanceof Date)
269
+ return v.toLocaleDateString();
270
+ return String(v);
271
+ }, _CmDataTable_cls = function _CmDataTable_cls(c) {
272
+ return `${isEnd(c) ? 'end' : ''} ${c.type === 'numeric' || c.type === 'money' ? 'num' : ''}`;
273
+ };
274
+ CmDataTable.properties = {
275
+ columns: { type: Array },
276
+ rows: { type: Array },
277
+ totals: { type: Object },
278
+ caption: {},
279
+ captionHidden: { type: Boolean, attribute: 'caption-hidden', reflect: true },
280
+ sort: { reflect: true },
281
+ direction: { reflect: true },
282
+ sortMode: { attribute: 'sort-mode', reflect: true },
283
+ stickyHeader: { type: Boolean, attribute: 'sticky-header', reflect: true },
284
+ stickyFirstColumn: { type: Boolean, attribute: 'sticky-first-column', reflect: true },
285
+ loading: { type: Boolean, reflect: true },
286
+ loadingRows: { type: Number, attribute: 'loading-rows' },
287
+ _light: { state: true },
288
+ _announce: { state: true },
289
+ };
290
+ CmDataTable.styles = [
291
+ base,
292
+ css `
293
+ :host { display: block; font-size: 14px; line-height: 1.5; }
294
+ .scroll { overflow: auto; max-block-size: var(--cm-data-table-max-height, none); }
295
+ .scroll:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
296
+ table { inline-size: 100%; border-collapse: separate; border-spacing: 0; }
297
+ caption { text-align: start; font-weight: 500; font-size: 16px; padding-block-end: var(--cm-space-10); }
298
+ :host([caption-hidden]) caption {
299
+ position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
300
+ }
301
+ th, td { padding: var(--cm-space-10) var(--cm-space-20); text-align: start; vertical-align: middle; }
302
+ thead th {
303
+ font-size: 12px; font-weight: 400; padding-block: 7px; white-space: nowrap; color: var(--cm-text-default);
304
+ background: var(--cm-bg-hover); border-block: var(--cm-border-1) solid var(--cm-border-subtle);
305
+ }
306
+ thead th:first-child { border-inline-start: var(--cm-border-1) solid var(--cm-border-subtle); border-start-start-radius: var(--cm-radius-md); }
307
+ thead th:last-child { border-inline-end: var(--cm-border-1) solid var(--cm-border-subtle); border-start-end-radius: var(--cm-radius-md); }
308
+ tbody td, tbody th { font-weight: 400; border-block-end: var(--cm-border-1) solid var(--cm-border-default); background: var(--cm-bg-surface); }
309
+ tbody tr:hover td, tbody tr:hover th { background: var(--cm-bg-hover); }
310
+ tfoot td { font-weight: 500; background: var(--cm-bg-surface); border-block-end: var(--cm-border-1) solid var(--cm-border-default); }
311
+ .end { text-align: end; }
312
+ .num { font-variant-numeric: tabular-nums; }
313
+ :host([sticky-header]) thead th { position: sticky; inset-block-start: 0; z-index: 2; }
314
+ :host([sticky-first-column]) tr > :first-child { position: sticky; inset-inline-start: 0; z-index: 1; }
315
+ :host([sticky-first-column]) thead th:first-child { z-index: 3; }
316
+ :host([sticky-first-column]) tfoot td:first-child { background: var(--cm-bg-surface); }
317
+ .sr { position: absolute; inline-size: 1px; block-size: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
318
+ button {
319
+ display: inline-flex; align-items: center; gap: 4px; padding: 2px 0; font: inherit; color: inherit;
320
+ background: none; border: 0; cursor: pointer; text-align: inherit;
321
+ }
322
+ .end button { flex-direction: row-reverse; }
323
+ button cm-icon { color: var(--cm-icon-selected); opacity: 0; }
324
+ button:hover cm-icon, button.on cm-icon { opacity: 1; }
325
+ button:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
326
+ .empty td { padding: var(--cm-space-20); border-block-end: 0; }
327
+ .light { display: contents; }
328
+ @media (forced-colors: active) { button cm-icon { opacity: 1; } }
329
+ `,
330
+ ];
331
+ define('cm-data-table', CmDataTable);
@@ -0,0 +1,49 @@
1
+ import { LitElement } from 'lit';
2
+ import type { IconName } from '@commmerce/icons';
3
+ import './icon.js';
4
+ /**
5
+ * Shown in place of a list or page when there is nothing to show yet, with the next step to take.
6
+ * A soft circle holds an illustration (an image, your own markup or one of the system icons).
7
+ * @element cm-empty-state
8
+ * @slot - Optional supporting text under the heading.
9
+ * @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`.
10
+ * @slot actions - The primary action (usually one primary `cm-button`), plus an optional link.
11
+ */
12
+ export declare class CmEmptyState extends LitElement {
13
+ #private;
14
+ static properties: {
15
+ heading: {};
16
+ image: {};
17
+ icon: {};
18
+ headingLevel: {
19
+ type: NumberConstructor;
20
+ attribute: string;
21
+ };
22
+ size: {
23
+ reflect: boolean;
24
+ };
25
+ };
26
+ /** What is missing, said plainly: "No products found". */
27
+ heading: string;
28
+ /** URL of an illustration shown in the circle. Decorative, so it has no alt text. */
29
+ image: string;
30
+ /** System icon shown in the circle when there is no `image` or `image` slot. */
31
+ icon: IconName | '';
32
+ /** Heading level, so the page outline stays correct. Default 2. */
33
+ headingLevel: 2 | 3 | 4 | 5 | 6;
34
+ /** `large` (250px circle, page-level) or `small` (200px circle, inside a card or on mobile). */
35
+ size: 'large' | 'small';
36
+ static styles: import("lit").CSSResult[];
37
+ /** @internal */
38
+ hasText: boolean;
39
+ /** @internal */
40
+ hasActions: boolean;
41
+ /** @internal */
42
+ hasImage: boolean;
43
+ render(): import("lit-html").TemplateResult<1>;
44
+ }
45
+ declare global {
46
+ interface HTMLElementTagNameMap {
47
+ 'cm-empty-state': CmEmptyState;
48
+ }
49
+ }
@@ -0,0 +1,94 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _CmEmptyState_instances, _CmEmptyState_slot;
7
+ import { LitElement, html, css, nothing } from 'lit';
8
+ import { base, define } from '../base.js';
9
+ import './icon.js';
10
+ /**
11
+ * Shown in place of a list or page when there is nothing to show yet, with the next step to take.
12
+ * A soft circle holds an illustration (an image, your own markup or one of the system icons).
13
+ * @element cm-empty-state
14
+ * @slot - Optional supporting text under the heading.
15
+ * @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`.
16
+ * @slot actions - The primary action (usually one primary `cm-button`), plus an optional link.
17
+ */
18
+ export class CmEmptyState extends LitElement {
19
+ constructor() {
20
+ super(...arguments);
21
+ _CmEmptyState_instances.add(this);
22
+ /** What is missing, said plainly: "No products found". */
23
+ this.heading = '';
24
+ /** URL of an illustration shown in the circle. Decorative, so it has no alt text. */
25
+ this.image = '';
26
+ /** System icon shown in the circle when there is no `image` or `image` slot. */
27
+ this.icon = 'box';
28
+ /** Heading level, so the page outline stays correct. Default 2. */
29
+ this.headingLevel = 2;
30
+ /** `large` (250px circle, page-level) or `small` (200px circle, inside a card or on mobile). */
31
+ this.size = 'large';
32
+ /** @internal */
33
+ this.hasText = false;
34
+ /** @internal */
35
+ this.hasActions = false;
36
+ /** @internal */
37
+ this.hasImage = false;
38
+ }
39
+ render() {
40
+ const level = Math.min(6, Math.max(2, this.headingLevel || 2));
41
+ const fallback = this.image
42
+ ? html `<img src=${this.image} alt="" part="image">`
43
+ : this.icon ? html `<cm-icon name=${this.icon} size="96"></cm-icon>` : nothing;
44
+ return html `<div class="wrap" part="empty-state">
45
+ <div class="circle" part="circle" aria-hidden=${this.hasImage ? nothing : 'true'}>
46
+ <slot name="image" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasImage')}>${fallback}</slot>
47
+ </div>
48
+ <div class="title" role="heading" aria-level=${level} part="heading">${this.heading}</div>
49
+ <div class="text" ?hidden=${!this.hasText}><slot @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasText')}></slot></div>
50
+ <div class="actions" ?hidden=${!this.hasActions}><slot name="actions" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasActions')}></slot></div>
51
+ </div>`;
52
+ }
53
+ }
54
+ _CmEmptyState_instances = new WeakSet(), _CmEmptyState_slot = function _CmEmptyState_slot(e, key) {
55
+ const s = e.target;
56
+ this[key] = s.assignedNodes({ flatten: true }).some((n) => n.nodeType === 1 || n.textContent.trim());
57
+ this.requestUpdate();
58
+ };
59
+ CmEmptyState.properties = {
60
+ heading: {},
61
+ image: {},
62
+ icon: {},
63
+ headingLevel: { type: Number, attribute: 'heading-level' },
64
+ size: { reflect: true },
65
+ };
66
+ CmEmptyState.styles = [
67
+ base,
68
+ css `
69
+ :host { display: block; }
70
+ .wrap {
71
+ display: flex; flex-direction: column; align-items: center; text-align: center;
72
+ padding: var(--cm-space-30) var(--cm-space-20);
73
+ }
74
+ .circle {
75
+ display: flex; align-items: center; justify-content: center; overflow: hidden;
76
+ width: 250px; height: 250px; border-radius: var(--cm-radius-full);
77
+ background: var(--cm-bg-input-filled); color: var(--cm-icon-selected);
78
+ }
79
+ .circle img, ::slotted([slot='image']) { max-width: 66%; max-height: 66%; object-fit: contain; }
80
+ .title { margin: 40px 0 0; font-size: 16px; font-weight: 400; }
81
+ .text { margin-top: var(--cm-space-10); max-width: 46ch; font-size: 14px; color: var(--cm-text-tertiary); }
82
+ .text[hidden], .actions[hidden] { display: none; }
83
+ .actions { display: flex; flex-wrap: wrap; justify-content: center; gap: var(--cm-space-20); margin-top: var(--cm-space-20); }
84
+ :host([size='small']) .circle { width: 200px; height: 200px; }
85
+ :host([size='small']) .title { margin-top: 30px; font-size: 14px; }
86
+ :host([size='small']) .actions { gap: var(--cm-space-10); }
87
+ @media (max-width: 640px) {
88
+ .circle { width: 200px; height: 200px; }
89
+ .title { margin-top: 30px; font-size: 14px; }
90
+ .actions { gap: var(--cm-space-10); }
91
+ }
92
+ `,
93
+ ];
94
+ define('cm-empty-state', CmEmptyState);
@@ -0,0 +1,102 @@
1
+ import { LitElement } from 'lit';
2
+ import './icon.js';
3
+ /**
4
+ * Drop zone for choosing files, with thumbnails of chosen images and a remove button on each.
5
+ * Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
6
+ * Participates in native forms (submit with `enctype="multipart/form-data"`).
7
+ * @element cm-file-upload
8
+ * @fires change - When files are added or removed. Read `files`.
9
+ * @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
10
+ */
11
+ export declare class CmFileUpload extends LitElement {
12
+ #private;
13
+ static formAssociated: boolean;
14
+ static shadowRootOptions: {
15
+ delegatesFocus: boolean;
16
+ mode: ShadowRootMode;
17
+ serializable?: boolean;
18
+ slotAssignment?: SlotAssignmentMode;
19
+ };
20
+ static properties: {
21
+ label: {};
22
+ hint: {};
23
+ prompt: {};
24
+ name: {
25
+ reflect: boolean;
26
+ };
27
+ accept: {};
28
+ multiple: {
29
+ type: BooleanConstructor;
30
+ };
31
+ maxSize: {
32
+ type: NumberConstructor;
33
+ attribute: string;
34
+ };
35
+ maxFiles: {
36
+ type: NumberConstructor;
37
+ attribute: string;
38
+ };
39
+ required: {
40
+ type: BooleanConstructor;
41
+ reflect: boolean;
42
+ };
43
+ disabled: {
44
+ type: BooleanConstructor;
45
+ reflect: boolean;
46
+ };
47
+ error: {
48
+ reflect: boolean;
49
+ };
50
+ files: {
51
+ attribute: boolean;
52
+ };
53
+ _rejected: {
54
+ state: boolean;
55
+ };
56
+ };
57
+ /** Heading above the zone, e.g. "Add product images". */
58
+ label: string;
59
+ /** Rule shown next to the label in text-tertiary, e.g. "max. file size 300 KB". */
60
+ hint: string;
61
+ /** Text inside the zone. */
62
+ prompt: string;
63
+ /** Form field name. */
64
+ name: string;
65
+ /** Allowed types, as for a native input: `image/*`, `.pdf,.csv`. Other files are refused. */
66
+ accept: string;
67
+ /** Allows more than one file. Chosen files are added to the list rather than replacing it. */
68
+ multiple: boolean;
69
+ /** Largest allowed file in bytes. Larger files are refused. */
70
+ maxSize: number;
71
+ /** Most files allowed when `multiple`; 0 for no limit. */
72
+ maxFiles: number;
73
+ /** The form will not submit without a file. */
74
+ required: boolean;
75
+ /** Blocks interaction. Also set by a disabled `<fieldset>`. */
76
+ disabled: boolean;
77
+ /** Error message from your own validation; announced and linked to the input. */
78
+ error: string;
79
+ /** The chosen files. Set it to `[]` to clear. */
80
+ files: File[];
81
+ _rejected: string;
82
+ static styles: import("lit").CSSResult[];
83
+ get form(): HTMLFormElement | null;
84
+ get validity(): ValidityState;
85
+ get validationMessage(): string;
86
+ checkValidity(): boolean;
87
+ reportValidity(): boolean;
88
+ formResetCallback(): void;
89
+ formDisabledCallback(d: boolean): void;
90
+ disconnectedCallback(): void;
91
+ updated(changed: Map<string, unknown>): void;
92
+ /** Adds files as if the merchant had chosen them: filters by type, size and count, then fires events. */
93
+ addFiles(list: Iterable<File>): void;
94
+ /** Removes one chosen file and fires `change`. */
95
+ removeFile(file: File): void;
96
+ render(): import("lit-html").TemplateResult<1>;
97
+ }
98
+ declare global {
99
+ interface HTMLElementTagNameMap {
100
+ 'cm-file-upload': CmFileUpload;
101
+ }
102
+ }