@commmerce/ui 1.6.0 → 1.7.1

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.
@@ -0,0 +1,325 @@
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 _CmCommandPalette_instances, _CmCommandPalette_onShortcut, _CmCommandPalette_query_get, _CmCommandPalette_view, _CmCommandPalette_rows, _CmCommandPalette_onInput, _CmCommandPalette_onKeyDown, _CmCommandPalette_choose, _CmCommandPalette_keys;
7
+ import { html, css, nothing } from 'lit';
8
+ import { live } from 'lit/directives/live.js';
9
+ import { define } from '../base.js';
10
+ import { defineStrings } from '../localize.js';
11
+ import { CmOverlay } from '../overlay.js';
12
+ import { popoverStyles, groupStyles, resultStyles, resultOption, resultContent, resultGroupHeading, moveActive } from '../popover.js';
13
+ import { matchesShortcut, shortcutHasModifier, isTypingTarget, shortcutKeys, ariaKeyShortcut } from '../shortcut.js';
14
+ import './icon.js';
15
+ import './spinner.js';
16
+ const strings = defineStrings('commandPalette', {
17
+ /** Accessible name of the dialog and its text box. */
18
+ label: 'Command palette',
19
+ placeholder: 'Search or run a command',
20
+ /** Heading of the recent items, shown while the box is empty. */
21
+ recent: 'Recent',
22
+ /** Shown and announced when nothing matches. */
23
+ noResults: 'No results',
24
+ /** Announced as the list changes. */
25
+ results: { one: '{count} result', other: '{count} results' },
26
+ /** The row under a group of search results that links to every match. */
27
+ seeAll: 'See all',
28
+ });
29
+ const fold = (s) => s.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
30
+ /** Whether an action matches a query: every word of the query appears in the title or a keyword (any case, any accents). */
31
+ export function commandMatches(item, query) {
32
+ const words = fold(query).split(/\s+/).filter(Boolean);
33
+ if (!words.length)
34
+ return true;
35
+ const hay = fold([item.title, ...(item.keywords ?? [])].join(' '));
36
+ return words.every((w) => hay.includes(w));
37
+ }
38
+ /**
39
+ * A search box in a dialog for people who work from the keyboard: jump to any record or run an action without
40
+ * leaving the keys. Opens with `show()`, the `open` attribute or an opt-in page-wide shortcut (`shortcut="mod+k"`:
41
+ * Cmd+K on a Mac, Ctrl+K elsewhere).
42
+ *
43
+ * Two kinds of content, in groups:
44
+ * - `actions`: things your app can do or places it can go ("New lead", "Go to Tasks"), set once. The palette
45
+ * filters them itself as the merchant types (every typed word must appear in the title or a keyword).
46
+ * - `results`: records your app finds, as in `cm-global-search`: listen for `cm-search`, fetch, then set
47
+ * `results` (and `loading` while it runs).
48
+ *
49
+ * While the box is empty it shows `recent` items, then every action.
50
+ * Choosing an item fires a cancelable `cm-select` and closes the palette; links are followed, and an item's
51
+ * `run` function is called, unless the event is cancelled.
52
+ *
53
+ * A native modal `<dialog>` like `cm-modal`: the page behind is inert, Escape and the backdrop close it, and focus
54
+ * goes back to where it was. Inside, the text box is a combobox over a grouped listbox, as in `cm-global-search`.
55
+ * @element cm-command-palette
56
+ * @fires cm-search - As the merchant types (and when the box is cleared), with `detail: { query }`. Fetch records and set `results`.
57
+ * @fires cm-select - When an item or a "See all" row is chosen, with `detail: { item, group, href }` (`item` is undefined for "See all"). The palette has already closed. Cancelable: `preventDefault()` stops the link and the item's `run`, to route in your app.
58
+ * @fires cm-open - After the palette opens.
59
+ * @fires cm-close - Before it closes from Escape, the backdrop, the close button or the shortcut. `detail: { reason }`. Cancelable.
60
+ * @fires cm-closed - After it has closed and focus has gone back.
61
+ * @csspart dialog - The native dialog.
62
+ * @csspart panel - The white box.
63
+ * @csspart box - The row with the search icon and the text input.
64
+ * @csspart input - The text input.
65
+ * @csspart close - The close button (narrow screens).
66
+ * @csspart results - The scrolling area under the box.
67
+ * @csspart listbox - The grouped list.
68
+ */
69
+ export class CmCommandPalette extends CmOverlay {
70
+ constructor() {
71
+ super();
72
+ _CmCommandPalette_instances.add(this);
73
+ /** The query. Updated as the merchant types; emptied when the palette closes. */
74
+ this.value = '';
75
+ /** Records found for the current query, grouped by kind, as in `cm-global-search`. Shown only while there is a query. Groups with no items are skipped. */
76
+ this.results = [];
77
+ /** Actions and places, grouped ("Actions", "Navigate"). Always available: filtered by the palette as the merchant types. */
78
+ this.actions = [];
79
+ /** Items the merchant chose recently, shown under "Recent" while the box is empty. Your app keeps the list (e.g. add the chosen item in `cm-select`). */
80
+ this.recent = [];
81
+ /** Shows "Loading" with a spinner in place of `results` while you fetch them. Matching actions still show. */
82
+ this.loading = false;
83
+ /**
84
+ * A shortcut that opens (and closes) the palette from anywhere on the page: `mod+k` is Cmd+K on a Mac and
85
+ * Ctrl+K elsewhere. Off by default: turn it on for one palette per page. A shortcut without Ctrl, Cmd or Alt
86
+ * (like `/`) is ignored while the merchant is typing in a field. The page only gets the key while it has focus
87
+ * (not from the address bar; in an embedded app, only while focus is in the app's frame), and shortcuts the
88
+ * browser reserves (Ctrl+T, Ctrl+W, Ctrl+N) can't be used: keep a visible button that calls `show()` too.
89
+ */
90
+ this.shortcut = '';
91
+ this._active = -1;
92
+ _CmCommandPalette_onShortcut.set(this, (e) => {
93
+ if (!this.shortcut || e.defaultPrevented || e.repeat || !matchesShortcut(e, this.shortcut))
94
+ return;
95
+ if (!this.open && !shortcutHasModifier(this.shortcut) && isTypingTarget(e))
96
+ return;
97
+ if (this.open && !shortcutHasModifier(this.shortcut))
98
+ return; // the key types into the box
99
+ e.preventDefault();
100
+ this.toggle();
101
+ });
102
+ _CmCommandPalette_onInput.set(this, (e) => {
103
+ this.value = e.target.value;
104
+ this._active = __classPrivateFieldGet(this, _CmCommandPalette_instances, "m", _CmCommandPalette_rows).call(this).length ? 0 : -1;
105
+ this.dispatchEvent(new CustomEvent('cm-search', { detail: { query: this.value }, bubbles: true, composed: true }));
106
+ });
107
+ _CmCommandPalette_onKeyDown.set(this, (e) => {
108
+ const n = __classPrivateFieldGet(this, _CmCommandPalette_instances, "m", _CmCommandPalette_rows).call(this).length;
109
+ switch (e.key) {
110
+ case 'ArrowDown':
111
+ case 'ArrowUp':
112
+ e.preventDefault();
113
+ this._active = moveActive(this._active, e.key === 'ArrowDown' ? 1 : -1, n);
114
+ break;
115
+ case 'Home':
116
+ case 'End':
117
+ if (e.shiftKey || !n)
118
+ break; // Shift+Home/End still select text
119
+ e.preventDefault();
120
+ this._active = e.key === 'Home' ? 0 : n - 1;
121
+ break;
122
+ case 'Enter':
123
+ if (e.isComposing || this._active < 0)
124
+ break;
125
+ e.preventDefault();
126
+ this.renderRoot.querySelector(`#${this.uid}-o${this._active}`)?.click();
127
+ break;
128
+ default:
129
+ }
130
+ });
131
+ // CmOverlay starts `label` as ''; undefined reads the built-in string instead.
132
+ this.label = undefined;
133
+ }
134
+ /** Opens the palette if it is closed and closes it if it is open. */
135
+ toggle() { if (this.open)
136
+ this.requestClose('method');
137
+ else
138
+ this.show(); }
139
+ connectedCallback() {
140
+ super.connectedCallback();
141
+ document.addEventListener('keydown', __classPrivateFieldGet(this, _CmCommandPalette_onShortcut, "f"));
142
+ }
143
+ disconnectedCallback() {
144
+ super.disconnectedCallback();
145
+ document.removeEventListener('keydown', __classPrivateFieldGet(this, _CmCommandPalette_onShortcut, "f"));
146
+ }
147
+ willUpdate(changed) {
148
+ super.willUpdate?.(changed);
149
+ if (changed.has('open') && !this.open && changed.get('open')) {
150
+ this.value = '';
151
+ this._active = -1;
152
+ }
153
+ if (['results', 'actions', 'recent', 'loading', 'value', 'open'].some((k) => changed.has(k))) {
154
+ const n = __classPrivateFieldGet(this, _CmCommandPalette_instances, "m", _CmCommandPalette_rows).call(this).length;
155
+ // The first row is highlighted whenever there is one, so Enter runs it.
156
+ if (this._active >= n || this._active < 0)
157
+ this._active = n ? 0 : -1;
158
+ }
159
+ }
160
+ updated(changed) {
161
+ super.updated(changed);
162
+ if ((changed.has('_active') || changed.has('open')) && this.open && this._active >= 0) {
163
+ this.renderRoot.querySelector(`#${this.uid}-o${this._active}`)?.scrollIntoView({ block: 'nearest' });
164
+ }
165
+ }
166
+ /** Focus goes to the text box, with any text in it selected. */
167
+ focusFirst() {
168
+ const input = this.renderRoot.querySelector('input');
169
+ input?.focus();
170
+ input?.select();
171
+ }
172
+ render() {
173
+ const view = this.open ? __classPrivateFieldGet(this, _CmCommandPalette_instances, "m", _CmCommandPalette_view).call(this) : [];
174
+ const rows = __classPrivateFieldGet(this, _CmCommandPalette_instances, "m", _CmCommandPalette_rows).call(this, view);
175
+ const q = __classPrivateFieldGet(this, _CmCommandPalette_instances, "a", _CmCommandPalette_query_get);
176
+ const items = rows.filter((r) => r.item).length;
177
+ const status = !this.open || !q ? ''
178
+ : this.loading ? this.loadingText
179
+ : rows.length ? this.t('results', { count: items })
180
+ : this.emptyText;
181
+ const id = this.uid;
182
+ let i = -1;
183
+ return this.renderDialog(html `<div class="panel" part="panel">
184
+ <div class="top">
185
+ <div class="box" part="box">
186
+ <cm-icon name="search" size="16"></cm-icon>
187
+ <input id="${id}-in" part="input" type="text" role="combobox" enterkeyhint="go" autocomplete="off" spellcheck="false"
188
+ aria-label=${this.label} placeholder=${this.placeholder || nothing} .value=${live(this.value)}
189
+ aria-autocomplete="list" aria-expanded=${rows.length ? 'true' : 'false'} aria-controls="${id}-list"
190
+ aria-activedescendant=${this._active >= 0 && rows.length ? `${id}-o${this._active}` : nothing}
191
+ @input=${__classPrivateFieldGet(this, _CmCommandPalette_onInput, "f")} @keydown=${__classPrivateFieldGet(this, _CmCommandPalette_onKeyDown, "f")} />
192
+ <kbd class="esc" aria-hidden="true">${shortcutKeys('escape')[0]}</kbd>
193
+ </div>
194
+ <button type="button" class="x" part="close" aria-label=${this.closeLabel} @click=${() => this.requestClose('close-button')}>
195
+ <cm-icon name="close" size="18"></cm-icon></button>
196
+ </div>
197
+ <div class="list" part="results" @pointerdown=${(e) => { if (e.target.closest?.('[role=option]'))
198
+ e.preventDefault(); }}>
199
+ ${this.loading && q
200
+ ? html `<p class="message"><cm-spinner size="small" aria-hidden="true"></cm-spinner><span aria-hidden="true">${this.loadingText}</span></p>` : nothing}
201
+ <div role="listbox" id="${id}-list" part="listbox" aria-label=${this.label} ?hidden=${!rows.length}>
202
+ ${view.map((v, gi) => html `<div role="group" aria-labelledby="${id}-g${gi}">
203
+ ${resultGroupHeading(`${id}-g${gi}`, v.group.label, v.group.total !== undefined ? this.formatNumber(v.group.total) : undefined, this.t('results', { count: v.group.total ?? 0 }))}
204
+ ${v.rows.map((row) => {
205
+ const n = ++i;
206
+ const it = row.item;
207
+ return resultOption({
208
+ id: `${id}-o${n}`, active: n === this._active, href: row.href, cls: it ? '' : 'all',
209
+ keyshortcuts: it?.shortcut ? ariaKeyShortcut(it.shortcut) : undefined,
210
+ onHover: () => (this._active = n), onChoose: (e) => __classPrivateFieldGet(this, _CmCommandPalette_instances, "m", _CmCommandPalette_choose).call(this, e, row),
211
+ }, it ? resultContent(it, __classPrivateFieldGet(this, _CmCommandPalette_instances, "m", _CmCommandPalette_keys).call(this, it.shortcut)) : html `<span class="text">${row.group.seeAllLabel || this.seeAllLabel}</span>`);
212
+ })}
213
+ </div>`)}
214
+ </div>
215
+ ${q && !this.loading && !rows.length ? html `<p class="message" aria-hidden="true">${this.emptyText}</p>` : nothing}
216
+ </div>
217
+ <span class="vh" role="status" aria-live="polite">${status}</span>
218
+ </div>`);
219
+ }
220
+ }
221
+ _CmCommandPalette_onShortcut = new WeakMap(), _CmCommandPalette_onInput = new WeakMap(), _CmCommandPalette_onKeyDown = new WeakMap(), _CmCommandPalette_instances = new WeakSet(), _CmCommandPalette_query_get = function _CmCommandPalette_query_get() { return this.value.trim(); }, _CmCommandPalette_view = function _CmCommandPalette_view() {
222
+ const q = __classPrivateFieldGet(this, _CmCommandPalette_instances, "a", _CmCommandPalette_query_get);
223
+ const groups = [];
224
+ const add = (group, items, withSeeAll = false) => {
225
+ const rows = items.map((item) => ({ group, item, href: item.href }));
226
+ if (withSeeAll && group.href)
227
+ rows.push({ group, href: group.href });
228
+ if (items.length)
229
+ groups.push({ group, rows });
230
+ };
231
+ if (!q) {
232
+ if (this.recent?.length)
233
+ add({ label: this.recentLabel, items: this.recent }, this.recent);
234
+ }
235
+ else if (!this.loading) {
236
+ for (const g of this.results ?? [])
237
+ if (g?.items?.length)
238
+ add(g, g.items, true);
239
+ }
240
+ for (const g of this.actions ?? []) {
241
+ if (g?.items?.length)
242
+ add(g, q ? g.items.filter((it) => commandMatches(it, q)) : g.items);
243
+ }
244
+ return groups;
245
+ }, _CmCommandPalette_rows = function _CmCommandPalette_rows(view = __classPrivateFieldGet(this, _CmCommandPalette_instances, "m", _CmCommandPalette_view).call(this)) { return view.flatMap((v) => v.rows); }, _CmCommandPalette_choose = function _CmCommandPalette_choose(e, row) {
246
+ // Close first, so focus is back on the opener before the app reacts (e.g. opens a modal).
247
+ this.closeNow();
248
+ const ok = this.dispatchEvent(new CustomEvent('cm-select', {
249
+ detail: { item: row.item, group: row.group, href: row.href }, bubbles: true, composed: true, cancelable: true,
250
+ }));
251
+ if (!ok) {
252
+ e.preventDefault();
253
+ return;
254
+ }
255
+ row.item?.run?.(row.item);
256
+ }, _CmCommandPalette_keys = function _CmCommandPalette_keys(spec) {
257
+ if (!spec)
258
+ return nothing;
259
+ return html `<span class="keys" aria-hidden="true">${shortcutKeys(spec).map((k) => html `<kbd>${k}</kbd>`)}</span>`;
260
+ };
261
+ CmCommandPalette.properties = {
262
+ ...CmOverlay.properties,
263
+ label: { string: 'label' },
264
+ placeholder: { string: 'placeholder' },
265
+ value: {},
266
+ results: { type: Array },
267
+ actions: { type: Array },
268
+ recent: { type: Array },
269
+ loading: { type: Boolean, reflect: true },
270
+ shortcut: {},
271
+ emptyText: { attribute: 'empty-text', string: 'noResults' },
272
+ loadingText: { attribute: 'loading-text', string: 'loading' },
273
+ recentLabel: { attribute: 'recent-label', string: 'recent' },
274
+ seeAllLabel: { attribute: 'see-all-label', string: 'seeAll' },
275
+ _active: { state: true },
276
+ };
277
+ CmCommandPalette.styles = [
278
+ ...CmOverlay.overlayStyles,
279
+ popoverStyles,
280
+ groupStyles,
281
+ resultStyles,
282
+ css `
283
+ dialog {
284
+ position: fixed; inset: 0; margin: max(var(--cm-space-16), 12dvh) auto auto; height: fit-content;
285
+ width: min(var(--cm-command-palette-width, 640px), calc(100vw - 32px));
286
+ }
287
+ .panel { max-height: calc(88dvh - 32px); border-radius: var(--cm-radius-lg); box-shadow: var(--cm-shadow-lg); }
288
+ .box {
289
+ display: flex; align-items: center; gap: var(--cm-space-8); flex: 1; min-width: 0; height: var(--cm-control-height-lg);
290
+ padding-block: 0; padding-inline: var(--cm-space-12) var(--cm-space-8); background: var(--cm-bg-page);
291
+ border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm);
292
+ }
293
+ .box:focus-within { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
294
+ .top {
295
+ display: flex; align-items: center; gap: var(--cm-space-8); flex: none; padding: var(--cm-space-12);
296
+ border-bottom: var(--cm-border-1) solid var(--cm-border-subtle);
297
+ }
298
+ .box > cm-icon { flex: none; color: var(--cm-icon-selected); }
299
+ input {
300
+ flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; background: none; outline: none;
301
+ font: inherit; font-size: var(--cm-font-size-14); color: var(--cm-text-default);
302
+ }
303
+ input::placeholder { color: var(--cm-text-tertiary); }
304
+ .x { display: none; width: var(--cm-control-height-md); height: var(--cm-control-height-md); color: var(--cm-icon-selected); }
305
+ .x:hover { background: var(--cm-bg-hover); }
306
+ .x:focus-visible { outline: 2px solid var(--cm-border-strong); }
307
+ .list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding-inline: var(--cm-space-8); padding-block-end: var(--cm-space-4); }
308
+ [role='option'] { border-radius: var(--cm-radius-sm); }
309
+ .keys { display: flex; flex: none; gap: var(--cm-space-4); }
310
+ .message { padding-inline: var(--cm-space-12); }
311
+ @media (max-width: 640px) {
312
+ dialog { width: 100vw; height: 100dvh; margin: 0; }
313
+ .panel { height: 100%; max-height: none; border-radius: 0; box-shadow: none; }
314
+ .esc { display: none; }
315
+ .x { display: grid; }
316
+ }
317
+ @media (pointer: coarse) {
318
+ .box { height: var(--cm-control-height-touch); }
319
+ input { font-size: var(--cm-font-size-16); }
320
+ .x { width: var(--cm-control-height-touch); height: var(--cm-control-height-touch); }
321
+ [role='option'] { min-height: var(--cm-control-height-touch); }
322
+ }
323
+ `,
324
+ ];
325
+ define('cm-command-palette', CmCommandPalette);
@@ -69,6 +69,12 @@ export interface DataTableColumn {
69
69
  width?: number;
70
70
  /** With `type: 'actions'`: the buttons in every row (since 1.6). A row can list its own as an array under the column's key. */
71
71
  actions?: DataTableAction[];
72
+ /**
73
+ * Text cells wrap onto up to this many lines, then end in "…" (since 1.7), instead of staying on one line. Use it for
74
+ * long notes or lists of signals that would otherwise make rows very tall. The full value shows on hover and is
75
+ * always read by screen readers. In a server-rendered `<table>`, put `data-lines="1"` to `"4"` on any element inside a cell (not on the cell itself), e.g. `<td><div data-lines="3">…</div></td>`, or one per list item to keep each item to one line.
76
+ */
77
+ lines?: number;
72
78
  }
73
79
  /** A row: column keys to cell values. Values are shown as text, never as HTML. */
74
80
  export type DataTableRow = Record<string, unknown>;
@@ -9,7 +9,7 @@ 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_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;
12
+ var _CmDataTable_instances, _CmDataTable_userSorted, _CmDataTable_id, _CmDataTable_observer, _CmDataTable_resize, _CmDataTable_observed, _CmDataTable_raf, _CmDataTable_shift, _CmDataTable_lightOver, _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
14
  import { base, define, nextId, logicalKey } from '../base.js';
15
15
  import { CmLocalizedElement, defineStrings, formatDate } from '../localize.js';
@@ -71,6 +71,10 @@ cm-data-table > table th > button.cm-sort:focus-visible { outline: 2px solid var
71
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
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
73
  cm-data-table > table [data-type='actions'] { width: 1%; white-space: nowrap; }
74
+ cm-data-table > table td [data-lines] { overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow-wrap: anywhere; }
75
+ cm-data-table > table td [data-lines='1'] { display: block; white-space: nowrap; text-overflow: ellipsis; overflow-wrap: normal; max-inline-size: var(--cm-data-table-cell-max-width, 320px); }
76
+ cm-data-table > table td [data-lines='3'] { -webkit-line-clamp: 3; line-clamp: 3; }
77
+ cm-data-table > table td [data-lines='4'] { -webkit-line-clamp: 4; line-clamp: 4; }
74
78
  cm-data-table > table tbody td[data-type='actions'] { padding-block: 0; }
75
79
  cm-data-table > table td[data-type='actions'] > * + * { margin-inline-start: var(--cm-space-8); }
76
80
  cm-data-table:not([row-actions='always']) > table tbody tr:not(:hover):not(:focus-within) td[data-type='actions'] > * { opacity: 0; }
@@ -240,6 +244,8 @@ export class CmDataTable extends CmLocalizedElement {
240
244
  _CmDataTable_observed.set(this, []);
241
245
  _CmDataTable_raf.set(this, 0);
242
246
  _CmDataTable_shift.set(this, -1);
247
+ _CmDataTable_lightOver.set(this, (e) => { if (e.target?.closest?.('[data-lines]'))
248
+ __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_onOver).call(this, e); });
243
249
  /** Scrolling elsewhere on the page only matters to a sticky heading; the table's own scroll and size are watched directly. */
244
250
  _CmDataTable_onAnyScroll.set(this, () => {
245
251
  if (__classPrivateFieldGet(this, _CmDataTable_raf, "f") || !this.stickyHeader)
@@ -254,6 +260,7 @@ export class CmDataTable extends CmLocalizedElement {
254
260
  }
255
261
  connectedCallback() {
256
262
  super.connectedCallback();
263
+ this.addEventListener('pointerover', __classPrivateFieldGet(this, _CmDataTable_lightOver, "f")); // server-rendered tables: hover title on [data-lines]
257
264
  adoptDensity(this);
258
265
  __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_readLight).call(this);
259
266
  // subtree: while the page is still being parsed, the table's head and rows arrive after the table itself.
@@ -362,7 +369,7 @@ export class CmDataTable extends CmLocalizedElement {
362
369
  `;
363
370
  }
364
371
  }
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() {
372
+ _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_lightOver = new WeakMap(), _CmDataTable_onAnyScroll = new WeakMap(), _CmDataTable_onOutside = new WeakMap(), _CmDataTable_instances = new WeakSet(), _CmDataTable_readLight = function _CmDataTable_readLight() {
366
373
  this._light = !!this.querySelector(':scope > table');
367
374
  if (this._light) {
368
375
  addLightStyles();
@@ -525,10 +532,18 @@ _CmDataTable_userSorted = new WeakMap(), _CmDataTable_id = new WeakMap(), _CmDat
525
532
  const w = __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_width).call(this, c);
526
533
  return w === undefined ? nothing : `--_w: ${w}px`;
527
534
  }, _CmDataTable_onOver = function _CmDataTable_onOver(e) {
535
+ const clamped = e.composedPath()[0]?.closest?.('[data-lines]');
536
+ if (clamped && this.contains(clamped)) {
537
+ if (clamped.scrollWidth > clamped.clientWidth + 1 || clamped.scrollHeight > clamped.clientHeight + 1)
538
+ clamped.title = clamped.textContent?.trim() ?? '';
539
+ else
540
+ clamped.removeAttribute('title');
541
+ return;
542
+ }
528
543
  const cell = e.composedPath()[0]?.closest?.('.t');
529
544
  if (!cell)
530
545
  return;
531
- if (cell.scrollWidth > cell.clientWidth + 1)
546
+ if (cell.scrollWidth > cell.clientWidth + 1 || cell.scrollHeight > cell.clientHeight + 1)
532
547
  cell.title = cell.textContent ?? '';
533
548
  else
534
549
  cell.removeAttribute('title');
@@ -558,7 +573,10 @@ _CmDataTable_userSorted = new WeakMap(), _CmDataTable_id = new WeakMap(), _CmDat
558
573
  if (c.type === 'actions')
559
574
  return __classPrivateFieldGet(this, _CmDataTable_instances, "m", _CmDataTable_actions).call(this, c, r, name);
560
575
  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;
576
+ if (!isText(c))
577
+ return text;
578
+ const lines = Math.trunc(Number(c.lines)) || 0;
579
+ return lines > 1 ? html `<span class="t lines" style="--_lines: ${lines}">${text}</span>` : html `<span class="t">${text}</span>`;
562
580
  }, _CmDataTable_setWidth = function _CmDataTable_setWidth(c, width, done) {
563
581
  const w = Math.max(MIN_WIDTH, Math.round(width));
564
582
  this._widths = { ...this._widths, [c.key]: w };
@@ -751,6 +769,8 @@ CmDataTable.styles = [
751
769
  .w { inline-size: var(--_w); min-inline-size: var(--_w); max-inline-size: var(--_w); }
752
770
  .w > .t, .w > .h { inline-size: 0; min-inline-size: 100%; max-inline-size: none; }
753
771
  .w > .h .t { max-inline-size: none; }
772
+ /* lines (1.7): wrap onto up to N lines, then "…". */
773
+ .t.lines { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: var(--_lines); line-clamp: var(--_lines); white-space: normal; overflow-wrap: anywhere; }
754
774
  .h { display: flex; align-items: center; min-inline-size: 0; }
755
775
  .end > .h { justify-content: flex-end; }
756
776
  .act { inline-size: 1%; white-space: nowrap; }
@@ -14,7 +14,8 @@ import { LitElement, html, css, nothing } from 'lit';
14
14
  import { live } from 'lit/directives/live.js';
15
15
  import { base, define, nextId } from '../base.js';
16
16
  import { CmLocalizedElement, defineStrings } from '../localize.js';
17
- import { popoverStyles, groupStyles, closeOnOutsidePointer } from '../popover.js';
17
+ import { popoverStyles, groupStyles, resultStyles, resultOption, resultContent, resultGroupHeading, moveActive, closeOnOutsidePointer } from '../popover.js';
18
+ import { isTypingTarget } from '../shortcut.js';
18
19
  import './icon.js';
19
20
  import './spinner.js';
20
21
  const strings = defineStrings('globalSearch', {
@@ -113,8 +114,7 @@ export class CmGlobalSearch extends CmLocalizedElement {
113
114
  _CmGlobalSearch_onShortcut.set(this, (e) => {
114
115
  if (!this.shortcut || e.key !== this.shortcut || e.ctrlKey || e.metaKey || e.altKey || e.defaultPrevented)
115
116
  return;
116
- const t = e.composedPath()[0];
117
- if (t && (t.isContentEditable || /^(input|textarea|select)$/i.test(t.localName ?? '')))
117
+ if (isTypingTarget(e))
118
118
  return;
119
119
  if (!this.getClientRects().length)
120
120
  return; // hidden, e.g. inside a closed layer
@@ -154,11 +154,9 @@ export class CmGlobalSearch extends CmLocalizedElement {
154
154
  let i = -1;
155
155
  const groups = (this.results ?? []).filter((g) => g?.items?.length);
156
156
  const option = (row, content, cls = '') => {
157
- i++;
158
- const n = i;
159
- return html `<a role="option" id="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-o${n}" class="${cls}${n === this._active ? ' active' : ''}" href=${row.href} tabindex="-1"
160
- aria-selected=${n === this._active ? 'true' : 'false'} @pointerenter=${() => (this._active = n)}
161
- @click=${(e) => __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_choose).call(this, e, row)}>${content}</a>`;
157
+ const n = ++i;
158
+ return resultOption({ id: `${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-o${n}`, active: n === this._active, href: row.href, cls,
159
+ onHover: () => (this._active = n), onChoose: (e) => __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_choose).call(this, e, row) }, content);
162
160
  };
163
161
  return html `<div class="wrap">
164
162
  <div class="box" part="box" @click=${(e) => { if (e.target === e.currentTarget)
@@ -183,8 +181,8 @@ export class CmGlobalSearch extends CmLocalizedElement {
183
181
  ${groups.map((g, gi) => {
184
182
  const total = g.total ?? g.items.length;
185
183
  return html `<div role="group" aria-labelledby="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-g${gi}">
186
- <div role="presentation" class="gh" id="${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-g${gi}"><span>${g.label}</span><span class="count" aria-hidden="true">${this.formatNumber(total)}</span><span class="vh">, ${this.t('results', { count: total })}</span></div>
187
- ${g.items.map((it) => option({ group: g, item: it, href: it.href }, html `${it.icon ? html `<cm-icon name=${it.icon} size="16"></cm-icon>` : nothing}<span class="text"><span class="title">${it.title}</span>${it.description ? html `<span class="vh">, </span><span class="desc">${it.description}</span>` : nothing}</span>`))}
184
+ ${resultGroupHeading(`${__classPrivateFieldGet(this, _CmGlobalSearch_id, "f")}-g${gi}`, g.label, this.formatNumber(total), this.t('results', { count: total }))}
185
+ ${g.items.map((it) => option({ group: g, item: it, href: it.href }, resultContent(it)))}
188
186
  ${g.href ? option({ group: g, href: g.href }, html `<span class="text">${g.seeAllLabel || this.seeAllLabel}</span>`, 'all') : nothing}
189
187
  </div>`;
190
188
  })}
@@ -207,15 +205,7 @@ _CmGlobalSearch_id = new WeakMap(), _CmGlobalSearch_stopOutside = new WeakMap(),
207
205
  }, _CmGlobalSearch_showing_get = function _CmGlobalSearch_showing_get() { return this.open && !!this.value.trim(); }, _CmGlobalSearch_hide = function _CmGlobalSearch_hide() { this.open = false; this._active = -1; }, _CmGlobalSearch_search = function _CmGlobalSearch_search() {
208
206
  this.dispatchEvent(new CustomEvent('cm-search', { detail: { query: this.value }, bubbles: true, composed: true }));
209
207
  }, _CmGlobalSearch_move = function _CmGlobalSearch_move(step) {
210
- const n = __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_rows).call(this).length;
211
- if (!n) {
212
- this._active = -1;
213
- return;
214
- }
215
- if (this._active < 0)
216
- this._active = step > 0 ? 0 : n - 1;
217
- else
218
- this._active = (this._active + step + n) % n;
208
+ this._active = moveActive(this._active, step, __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_rows).call(this).length);
219
209
  }, _CmGlobalSearch_clear = function _CmGlobalSearch_clear(focus = true) {
220
210
  this.value = '';
221
211
  __classPrivateFieldGet(this, _CmGlobalSearch_instances, "m", _CmGlobalSearch_hide).call(this);
@@ -248,6 +238,7 @@ CmGlobalSearch.styles = [
248
238
  base,
249
239
  popoverStyles,
250
240
  groupStyles,
241
+ resultStyles,
251
242
  css `
252
243
  :host { display: block; position: relative; }
253
244
  .wrap { position: relative; }
@@ -271,30 +262,12 @@ CmGlobalSearch.styles = [
271
262
  }
272
263
  .clear:hover { background: var(--cm-bg-hover); }
273
264
  .clear:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 0; }
274
- kbd {
275
- flex: none; min-width: 20px; padding: 0 var(--cm-space-4); font: inherit; font-size: var(--cm-font-size-12); line-height: var(--cm-line-height-12); text-align: center;
276
- color: var(--cm-text-tertiary); border: var(--cm-border-1) solid var(--cm-border-subtle); border-radius: var(--cm-radius-xs);
277
- }
278
265
  .box:focus-within kbd { display: none; }
279
266
  .pop {
280
267
  position: var(--cm-global-search-results-position, absolute);
281
268
  box-shadow: var(--cm-global-search-results-shadow, var(--cm-shadow-md));
282
269
  overflow-y: auto; max-height: var(--cm-global-search-results-max-height, min(480px, calc(100dvh - 140px)));
283
270
  }
284
- [role='listbox'] { padding-block: var(--cm-space-4); }
285
- [role='listbox'][hidden] { display: none; }
286
- [role='option'] {
287
- display: flex; align-items: center; gap: var(--cm-space-8); min-height: var(--cm-control-height-md); padding: var(--cm-space-8) var(--cm-space-12);
288
- font-size: 14px; line-height: 20px; color: var(--cm-text-default); text-decoration: none; cursor: pointer;
289
- }
290
- [role='option'].active { background: var(--cm-bg-hover); box-shadow: inset 2px 0 0 var(--cm-border-strong); }
291
- [role='option'].active:dir(rtl) { box-shadow: inset -2px 0 0 var(--cm-border-strong); }
292
- [role='option'] cm-icon { flex: none; color: var(--cm-icon-selected); }
293
- .text { flex: 1; min-width: 0; }
294
- .title, .desc { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
295
- .desc { font-size: 12px; line-height: 16px; color: var(--cm-text-tertiary); }
296
- .all { font-size: var(--cm-font-size-13); text-decoration: underline; }
297
- .gh { padding-inline: var(--cm-space-12); }
298
271
  @media (pointer: coarse) { .box { min-height: var(--cm-control-height-touch); } input { font-size: var(--cm-font-size-16); } }
299
272
  `,
300
273
  ];
@@ -2,6 +2,11 @@ import { LitElement } from 'lit';
2
2
  /**
3
3
  * Side card on detail pages that lists facts as label/value pairs (order details, SKU, tags).
4
4
  * Put `cm-info-item` elements inside. The Figma file calls this the "Additional Info Card".
5
+ * Labels are 13/18 in text-tertiary, values 14/20 medium (owner standard).
6
+ *
7
+ * On record pages (since 1.7) use `variant="compact"` (the padding of a compact `cm-card`: 16px, 12px under the title)
8
+ * and `layout="rows"`: each fact on one row, the label on the start side and the value beside it, the way a CRM's
9
+ * Details card reads. Rows fit the 320px aside of a record layout.
5
10
  * @element cm-info-panel
6
11
  * @slot - `cm-info-item` elements.
7
12
  * @fires cm-action - When the header text action (for example REMOVE) is pressed.
@@ -17,6 +22,12 @@ export declare class CmInfoPanel extends LitElement {
17
22
  type: NumberConstructor;
18
23
  attribute: string;
19
24
  };
25
+ variant: {
26
+ reflect: boolean;
27
+ };
28
+ layout: {
29
+ reflect: boolean;
30
+ };
20
31
  _list: {
21
32
  state: boolean;
22
33
  };
@@ -29,13 +40,20 @@ export declare class CmInfoPanel extends LitElement {
29
40
  actionLabel: string;
30
41
  /** Heading level for the title. Default 2. */
31
42
  headingLevel: 2 | 3 | 4 | 5 | 6;
43
+ /** `default` (24px padding, like a standard `cm-card`; 16px on phones; 20px before 1.7.1) or `compact` (16px padding and 12px under the title, like a compact `cm-card`). Since 1.7. */
44
+ variant: 'default' | 'compact';
45
+ /**
46
+ * `stacked` (default: each label over its value; `half` items share a line) or `rows` (each label beside its value,
47
+ * two fifths of the width for the label; `half` is ignored). Since 1.7.
48
+ */
49
+ layout: 'stacked' | 'rows';
32
50
  /** The items area is a list only while it holds just `cm-info-item`s (not, say, a loading skeleton). */
33
51
  _list: boolean;
34
52
  static styles: import("lit").CSSResult[];
35
53
  render(): import("lit-html").TemplateResult<1>;
36
54
  }
37
55
  /**
38
- * One fact in an info panel: a label and its value (text, a badge or tags).
56
+ * One fact in an info panel: a label (13px) and its value (14px): text, a link, a badge or tags.
39
57
  * @element cm-info-item
40
58
  * @slot - The value.
41
59
  */