@commmerce/ui 1.2.0 → 1.3.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.
@@ -9,12 +9,12 @@ 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 _CmCombobox_instances, _CmCombobox_internals, _CmCombobox_id, _CmCombobox_default, _CmCombobox_labels, _CmCombobox_observer, _CmCombobox_stopOutside, _CmCombobox_readChildren, _CmCombobox_labelOf, _CmCombobox_createText_get, _CmCombobox_rows, _CmCombobox_emit, _CmCombobox_show, _CmCombobox_hide, _CmCombobox_enabled, _CmCombobox_move, _CmCombobox_choose, _CmCombobox_create, _CmCombobox_focusInput, _CmCombobox_onInput, _CmCombobox_onKeyDown, _CmCombobox_onBlur, _CmCombobox_highlight;
12
+ var _CmCombobox_instances, _CmCombobox_internals, _CmCombobox_id, _CmCombobox_default, _CmCombobox_labels, _CmCombobox_groups, _CmCombobox_observer, _CmCombobox_stopOutside, _CmCombobox_readChildren, _CmCombobox_labelOf, _CmCombobox_displayOf, _CmCombobox_createText_get, _CmCombobox_rows, _CmCombobox_emit, _CmCombobox_show, _CmCombobox_hide, _CmCombobox_enabled, _CmCombobox_move, _CmCombobox_choose, _CmCombobox_create, _CmCombobox_focusInput, _CmCombobox_onInput, _CmCombobox_onKeyDown, _CmCombobox_onBlur, _CmCombobox_highlight;
13
13
  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, closeOnOutsidePointer } from '../popover.js';
17
+ import { popoverStyles, groupStyles, sortByGroup, groupRuns, closeOnOutsidePointer } from '../popover.js';
18
18
  import './icon.js';
19
19
  import './tag.js';
20
20
  import './spinner.js';
@@ -31,6 +31,8 @@ const strings = defineStrings('combobox', {
31
31
  required: 'Please select an item in the list.',
32
32
  /** Validation: `required`, `multiple` and nothing chosen. */
33
33
  requiredMultiple: 'Choose at least one item.',
34
+ /** The chosen option in the box or its tag with `show-group`: "Lead: Company". */
35
+ grouped: '{group}: {label}',
34
36
  });
35
37
  /**
36
38
  * Editable combobox: a text box that suggests matching options as the merchant types (the WAI-ARIA APG
@@ -38,9 +40,11 @@ const strings = defineStrings('combobox', {
38
40
  * tags). With `filter="none"` it doesn't filter by itself: listen for `cm-search`, fetch matches, set `options`
39
41
  * and toggle `loading`. With `allow-custom` the merchant can add a value that isn't in the list (a new product tag).
40
42
  *
41
- * Options come from `<option>` children or the `options` property, as for `cm-select`.
43
+ * Options come from `<option>` children or the `options` property, as for `cm-select`, and can be grouped under
44
+ * headings with `<optgroup label="…">` or a `group` on each option (since 1.3). Filtering keeps the heading of
45
+ * every group that still has a match.
42
46
  * @element cm-combobox
43
- * @slot - `<option value="…">Label</option>` elements. `disabled` and `selected` are honoured.
47
+ * @slot - `<option value="…">Label</option>` elements, optionally inside `<optgroup label="…">`. `disabled` (also on an optgroup) and `selected` are honoured.
44
48
  * @fires change - When the value changes (an option picked or removed, or a custom value added).
45
49
  * @fires input - Same moment as `change`.
46
50
  * @fires cm-search - As the merchant types, with `detail: { query }`. Use it to load matches from the server.
@@ -67,7 +71,7 @@ export class CmCombobox extends CmLocalizedElement {
67
71
  this.values = [];
68
72
  /** Shown in the empty text box, e.g. "Search tags". */
69
73
  this.placeholder = '';
70
- /** Options as strings or `{ value, label, disabled }`. Used instead of `<option>` children when set. */
74
+ /** Options as strings or `{ value, label, disabled, group }`. Used instead of `<option>` children when set. */
71
75
  this.options = [];
72
76
  /** Lets the merchant choose several options, shown as removable tags. Backspace in the empty box removes the last one. */
73
77
  this.multiple = false;
@@ -83,6 +87,11 @@ export class CmCombobox extends CmLocalizedElement {
83
87
  this.disabled = false;
84
88
  /** Whether the list is showing. */
85
89
  this.open = false;
90
+ /**
91
+ * Shows the chosen option's group before its label in the box, or in its tag with `multiple` ("Lead: Company"),
92
+ * for grouped lists where labels repeat across groups. The list itself shows the bare label under its heading. Since 1.3.
93
+ */
94
+ this.showGroup = false;
86
95
  this._query = '';
87
96
  this._active = -1;
88
97
  this._slotted = [];
@@ -93,6 +102,8 @@ export class CmCombobox extends CmLocalizedElement {
93
102
  _CmCombobox_default.set(this, null);
94
103
  /** Labels for chosen values, so tags keep their text when async options change. */
95
104
  _CmCombobox_labels.set(this, new Map());
105
+ /** Groups of chosen values, for the same reason (`show-group`). */
106
+ _CmCombobox_groups.set(this, new Map());
96
107
  _CmCombobox_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_readChildren).call(this)));
97
108
  _CmCombobox_stopOutside.set(this, void 0);
98
109
  _CmCombobox_onInput.set(this, (e) => {
@@ -174,7 +185,7 @@ export class CmCombobox extends CmLocalizedElement {
174
185
  if (!this._typing)
175
186
  return;
176
187
  this._typing = false;
177
- this._query = this.multiple ? '' : this.value ? __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_labelOf).call(this, this.value) : '';
188
+ this._query = this.multiple ? '' : this.value ? __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_displayOf).call(this, this.value) : '';
178
189
  });
179
190
  });
180
191
  }
@@ -212,11 +223,11 @@ export class CmCombobox extends CmLocalizedElement {
212
223
  this.value = state;
213
224
  }
214
225
  }
215
- /** All options in use, normalised (before filtering). */
226
+ /** All options in use, normalised (before filtering), in the order shown (options of a group together). */
216
227
  get items() {
217
228
  if (!this.options?.length)
218
- return this._slotted;
219
- return this.options.map((o) => (typeof o === 'string' ? { value: o, label: o } : o));
229
+ return sortByGroup(this._slotted);
230
+ return sortByGroup(this.options.map((o) => (typeof o === 'string' ? { value: o, label: o } : o)));
220
231
  }
221
232
  /** The options shown for the current query. */
222
233
  get filteredItems() {
@@ -232,10 +243,13 @@ export class CmCombobox extends CmLocalizedElement {
232
243
  __classPrivateFieldSet(this, _CmCombobox_default, { value: this.value, values: [...this.values] }, "f");
233
244
  }
234
245
  willUpdate(changed) {
235
- for (const o of this.items)
246
+ for (const o of this.items) {
236
247
  __classPrivateFieldGet(this, _CmCombobox_labels, "f").set(o.value, o.label);
237
- if ((changed.has('value') || changed.has('options') || changed.has('_slotted')) && !this.multiple && !this._typing) {
238
- this._query = this.value ? __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_labelOf).call(this, this.value) : '';
248
+ if (o.group)
249
+ __classPrivateFieldGet(this, _CmCombobox_groups, "f").set(o.value, o.group);
250
+ }
251
+ if ((changed.has('value') || changed.has('options') || changed.has('_slotted') || changed.has('showGroup')) && !this.multiple && !this._typing) {
252
+ this._query = this.value ? __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_displayOf).call(this, this.value) : '';
239
253
  }
240
254
  if (changed.has('_query') || changed.has('options') || changed.has('_slotted') || changed.has('loading')) {
241
255
  const rows = __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_rows).call(this);
@@ -280,6 +294,12 @@ export class CmCombobox extends CmLocalizedElement {
280
294
  const described = [this.error && `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-help`].filter(Boolean).join(' ');
281
295
  const hostLabel = this.getAttribute('aria-label');
282
296
  const selected = (v) => (this.multiple ? this.values.includes(v) : v === this.value);
297
+ const option = (o, i) => html `<li role="option" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-o${i}" class=${i === this._active ? 'active' : ''}
298
+ aria-selected=${o.create ? 'false' : selected(o.value) ? 'true' : 'false'} aria-disabled=${o.disabled ? 'true' : nothing}
299
+ @pointerenter=${() => !o.disabled && (this._active = i)} @click=${() => __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_choose).call(this, i)}>
300
+ ${o.create
301
+ ? html `<cm-icon name="plus" size="16"></cm-icon><span class="create">${this.t('add', { value: o.label })}</span>`
302
+ : html `${this.multiple ? html `<cm-icon class="check" name="check" size="16"></cm-icon>` : nothing}<span>${__classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_highlight).call(this, o.label)}</span>`}</li>`;
283
303
  const status = this.loading ? this.loadingText || this.t('loading')
284
304
  : !this.open ? ''
285
305
  : rows.length ? this.t('results', { count: rows.length })
@@ -291,8 +311,8 @@ export class CmCombobox extends CmLocalizedElement {
291
311
  <div class="wrap">
292
312
  <div class="box" part="box" @click=${(e) => { if (!e.target.closest('cm-tag'))
293
313
  __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_focusInput).call(this); }}>
294
- ${this.multiple ? this.values.map((v) => html `<cm-tag removable ?disabled=${this.disabled} remove-label=${this.t('remove', { label: __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_labelOf).call(this, v) })}
295
- @cm-remove=${() => { this.removeValue(v); __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_focusInput).call(this); }}>${__classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_labelOf).call(this, v)}</cm-tag>`) : nothing}
314
+ ${this.multiple ? this.values.map((v) => html `<cm-tag removable ?disabled=${this.disabled} remove-label=${this.t('remove', { label: __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_displayOf).call(this, v) })}
315
+ @cm-remove=${() => { this.removeValue(v); __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_focusInput).call(this); }}>${__classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_displayOf).call(this, v)}</cm-tag>`) : nothing}
296
316
  <input id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-in" part="input" type="text" role="combobox" autocomplete="off" spellcheck="false"
297
317
  .value=${live(this._query)} placeholder=${this.multiple && this.values.length ? nothing : this.placeholder || nothing}
298
318
  aria-label=${!this.label && hostLabel ? hostLabel : nothing}
@@ -314,12 +334,10 @@ export class CmCombobox extends CmLocalizedElement {
314
334
  <ul role="listbox" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-list" part="listbox" ?hidden=${!rows.length}
315
335
  aria-labelledby=${this.label ? `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-l` : nothing} aria-label=${!this.label && hostLabel ? hostLabel : nothing}
316
336
  aria-multiselectable=${this.multiple ? 'true' : nothing}>
317
- ${rows.map((o, i) => html `<li role="option" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-o${i}" class=${i === this._active ? 'active' : ''}
318
- aria-selected=${o.create ? 'false' : selected(o.value) ? 'true' : 'false'} aria-disabled=${o.disabled ? 'true' : nothing}
319
- @pointerenter=${() => !o.disabled && (this._active = i)} @click=${() => __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_choose).call(this, i)}>
320
- ${o.create
321
- ? html `<cm-icon name="plus" size="16"></cm-icon><span class="create">${this.t('add', { value: o.label })}</span>`
322
- : html `${this.multiple ? html `<cm-icon class="check" name="check" size="16"></cm-icon>` : nothing}<span>${__classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_highlight).call(this, o.label)}</span>`}</li>`)}
337
+ ${groupRuns(rows).map((run, gi) => run.group
338
+ ? html `<li role="group" aria-labelledby="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-g${gi}"><div role="presentation" class="gh" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-g${gi}">${run.group}</div>
339
+ <ul role="none" class="gopts">${run.rows.map(({ row, index }) => option(row, index))}</ul></li>`
340
+ : run.rows.map(({ row, index }) => option(row, index)))}
323
341
  </ul>
324
342
  ${this.loading
325
343
  ? html `<p class="message"><cm-spinner size="small" aria-hidden="true"></cm-spinner><span aria-hidden="true">${this.loadingText || this.t('loading')}</span></p>`
@@ -333,9 +351,15 @@ export class CmCombobox extends CmLocalizedElement {
333
351
  </div>`;
334
352
  }
335
353
  }
336
- _CmCombobox_internals = new WeakMap(), _CmCombobox_id = new WeakMap(), _CmCombobox_default = new WeakMap(), _CmCombobox_labels = new WeakMap(), _CmCombobox_observer = new WeakMap(), _CmCombobox_stopOutside = new WeakMap(), _CmCombobox_onInput = new WeakMap(), _CmCombobox_onKeyDown = new WeakMap(), _CmCombobox_onBlur = new WeakMap(), _CmCombobox_instances = new WeakSet(), _CmCombobox_readChildren = function _CmCombobox_readChildren() {
354
+ _CmCombobox_internals = new WeakMap(), _CmCombobox_id = new WeakMap(), _CmCombobox_default = new WeakMap(), _CmCombobox_labels = new WeakMap(), _CmCombobox_groups = new WeakMap(), _CmCombobox_observer = new WeakMap(), _CmCombobox_stopOutside = new WeakMap(), _CmCombobox_onInput = new WeakMap(), _CmCombobox_onKeyDown = new WeakMap(), _CmCombobox_onBlur = new WeakMap(), _CmCombobox_instances = new WeakSet(), _CmCombobox_readChildren = function _CmCombobox_readChildren() {
337
355
  const opts = [...this.querySelectorAll('option')];
338
- this._slotted = opts.map((o) => ({ value: o.value, label: o.label || o.textContent.trim(), disabled: o.disabled }));
356
+ this._slotted = opts.map((o) => {
357
+ const g = o.parentElement?.localName === 'optgroup' ? o.parentElement : null;
358
+ const opt = { value: o.value, label: o.label || o.textContent.trim(), disabled: o.disabled || !!g?.disabled };
359
+ if (g?.label)
360
+ opt.group = g.label;
361
+ return opt;
362
+ });
339
363
  if (!this.hasUpdated) {
340
364
  const sel = opts.filter((o) => o.hasAttribute('selected')).map((o) => o.value);
341
365
  if (this.multiple && !this.values.length && sel.length)
@@ -345,6 +369,12 @@ _CmCombobox_internals = new WeakMap(), _CmCombobox_id = new WeakMap(), _CmCombob
345
369
  }
346
370
  }, _CmCombobox_labelOf = function _CmCombobox_labelOf(v) {
347
371
  return this.items.find((o) => o.value === v)?.label ?? __classPrivateFieldGet(this, _CmCombobox_labels, "f").get(v) ?? v;
372
+ }, _CmCombobox_displayOf = function _CmCombobox_displayOf(v) {
373
+ const label = __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_labelOf).call(this, v);
374
+ if (!this.showGroup)
375
+ return label;
376
+ const group = this.items.find((o) => o.value === v)?.group ?? __classPrivateFieldGet(this, _CmCombobox_groups, "f").get(v);
377
+ return group ? this.t('grouped', { group, label }) : label;
348
378
  }, _CmCombobox_createText_get = function _CmCombobox_createText_get() {
349
379
  if (!this.allowCustom || !this._typing)
350
380
  return '';
@@ -402,7 +432,7 @@ _CmCombobox_internals = new WeakMap(), _CmCombobox_id = new WeakMap(), _CmCombob
402
432
  }
403
433
  __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_hide).call(this);
404
434
  this._typing = false;
405
- this._query = row.label;
435
+ this._query = this.showGroup && row.group ? this.t('grouped', { group: row.group, label: row.label }) : row.label;
406
436
  if (row.value !== this.value) {
407
437
  this.value = row.value;
408
438
  __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_emit).call(this);
@@ -454,6 +484,7 @@ CmCombobox.properties = {
454
484
  required: { type: Boolean, reflect: true },
455
485
  disabled: { type: Boolean, reflect: true },
456
486
  open: { type: Boolean, reflect: true },
487
+ showGroup: { type: Boolean, attribute: 'show-group' },
457
488
  _query: { state: true },
458
489
  _active: { state: true },
459
490
  _slotted: { state: true },
@@ -462,6 +493,7 @@ CmCombobox.properties = {
462
493
  CmCombobox.styles = [
463
494
  base,
464
495
  popoverStyles,
496
+ groupStyles,
465
497
  css `
466
498
  :host { display: block; position: relative; }
467
499
  .field { display: flex; flex-direction: column; gap: var(--cm-space-10); }
@@ -17,6 +17,16 @@ declare const strings: {
17
17
  wrongType: string;
18
18
  tooLarge: string;
19
19
  tooMany: string;
20
+ /** `variant="photo"`: text of the empty tile when there is no `label`. */
21
+ takePhoto: string;
22
+ /** `variant="photo"`: visible text of the buttons under a taken photo. */
23
+ retake: string;
24
+ removePhoto: string;
25
+ /** `variant="photo"`: accessible names of those buttons. `{name}` is the `label`, or the `photo` string without one. */
26
+ retakeName: string;
27
+ removeName: string;
28
+ /** `variant="photo"`: what the photo is called in button names when there is no `label`. */
29
+ photo: string;
20
30
  };
21
31
  declare module '../localize.js' {
22
32
  interface CmStrings {
@@ -27,6 +37,10 @@ declare module '../localize.js' {
27
37
  * Drop zone for choosing files, with thumbnails of chosen images and a remove button on each.
28
38
  * Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
29
39
  * Participates in native forms (submit with `enctype="multipart/form-data"`).
40
+ *
41
+ * `variant="photo"` (since 1.3) is the phone capture pattern: one tile with a camera icon and the label; once a photo
42
+ * is taken or chosen, the tile shows it with Retake and Remove buttons. Add `capture="environment"` to open the
43
+ * back camera directly on phones.
30
44
  * @element cm-file-upload
31
45
  * @fires change - When files are added or removed. Read `files`.
32
46
  * @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
@@ -75,6 +89,12 @@ export declare class CmFileUpload extends CmLocalizedElement {
75
89
  files: {
76
90
  attribute: boolean;
77
91
  };
92
+ variant: {
93
+ reflect: boolean;
94
+ };
95
+ capture: {
96
+ reflect: boolean;
97
+ };
78
98
  _rejected: {
79
99
  state: boolean;
80
100
  };
@@ -103,6 +123,19 @@ export declare class CmFileUpload extends CmLocalizedElement {
103
123
  error: string;
104
124
  /** The chosen files. Set it to `[]` to clear. */
105
125
  files: File[];
126
+ /**
127
+ * `photo` (since 1.3): a single-photo tile for phones. It shows a camera icon and the `label` (or the prompt
128
+ * "Take a photo" without one); after a photo is taken it fills the tile, with Retake and Remove buttons under it.
129
+ * One file only (`multiple` is ignored); `accept` defaults to `image/*`. Size the tile with CSS on the element;
130
+ * it is 4:3 (change it with `::part(photo)`, e.g. `aspect-ratio: 16 / 10` for a visiting card).
131
+ */
132
+ variant?: 'photo';
133
+ /**
134
+ * Asks phones to open the camera instead of the file chooser, as `capture` on a native input (since 1.3):
135
+ * `environment` for the back camera (a shop front, a document), `user` for the front camera (a selfie).
136
+ * Desktop browsers ignore it and show the file chooser.
137
+ */
138
+ capture?: 'environment' | 'user';
106
139
  _rejected: string;
107
140
  static styles: import("lit").CSSResult[];
108
141
  get form(): HTMLFormElement | null;
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
3
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
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
- var _CmFileUpload_instances, _CmFileUpload_internals, _CmFileUpload_id, _CmFileUpload_urls, _CmFileUpload_size, _CmFileUpload_url, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_zone;
6
+ var _CmFileUpload_instances, _CmFileUpload_internals, _CmFileUpload_id, _CmFileUpload_urls, _CmFileUpload_photo_get, _CmFileUpload_accept_get, _CmFileUpload_multiple_get, _CmFileUpload_size, _CmFileUpload_url, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_zone, _CmFileUpload_retake, _CmFileUpload_renderPhoto;
7
7
  import { LitElement, html, css, nothing } from 'lit';
8
8
  import { base, define, nextId } from '../base.js';
9
9
  import { CmLocalizedElement, defineStrings } from '../localize.js';
@@ -25,6 +25,16 @@ const strings = defineStrings('fileUpload', {
25
25
  wrongType: '{name} is not an allowed file type',
26
26
  tooLarge: '{name} is larger than {size}',
27
27
  tooMany: 'You can add up to {max} files',
28
+ /** `variant="photo"`: text of the empty tile when there is no `label`. */
29
+ takePhoto: 'Take a photo',
30
+ /** `variant="photo"`: visible text of the buttons under a taken photo. */
31
+ retake: 'Retake',
32
+ removePhoto: 'Remove',
33
+ /** `variant="photo"`: accessible names of those buttons. `{name}` is the `label`, or the `photo` string without one. */
34
+ retakeName: 'Retake {name}',
35
+ removeName: 'Remove {name}',
36
+ /** `variant="photo"`: what the photo is called in button names when there is no `label`. */
37
+ photo: 'photo',
28
38
  });
29
39
  /** Does `file` match an `accept` list such as `image/*,.pdf`? */
30
40
  function accepts(file, accept) {
@@ -37,6 +47,10 @@ function accepts(file, accept) {
37
47
  * Drop zone for choosing files, with thumbnails of chosen images and a remove button on each.
38
48
  * Wraps a native file input, so it works with the keyboard, screen readers and drag and drop.
39
49
  * Participates in native forms (submit with `enctype="multipart/form-data"`).
50
+ *
51
+ * `variant="photo"` (since 1.3) is the phone capture pattern: one tile with a camera icon and the label; once a photo
52
+ * is taken or chosen, the tile shows it with Retake and Remove buttons. Add `capture="environment"` to open the
53
+ * back camera directly on phones.
40
54
  * @element cm-file-upload
41
55
  * @fires change - When files are added or removed. Read `files`.
42
56
  * @fires cm-reject - When chosen files are refused for type or size. `detail.files` lists them.
@@ -97,7 +111,8 @@ export class CmFileUpload extends CmLocalizedElement {
97
111
  for (const f of this.files)
98
112
  data.append(this.name || 'file', f);
99
113
  __classPrivateFieldGet(this, _CmFileUpload_internals, "f").setFormValue(this.files.length ? data : null);
100
- const input = this.renderRoot.querySelector('input') ?? undefined;
114
+ // The photo tile keeps a hidden input for Retake; with a photo shown, point validation at the Retake button.
115
+ const input = (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get) && this.files.length ? this.renderRoot.querySelector('.retake') : this.renderRoot.querySelector('input')) ?? undefined;
101
116
  const msg = this.error || this._rejected;
102
117
  if (msg)
103
118
  __classPrivateFieldGet(this, _CmFileUpload_internals, "f").setValidity({ customError: true }, msg, input);
@@ -111,7 +126,7 @@ export class CmFileUpload extends CmLocalizedElement {
111
126
  const incoming = [...list];
112
127
  const ok = [], refused = [], reasons = [];
113
128
  for (const f of incoming) {
114
- if (!accepts(f, this.accept)) {
129
+ if (!accepts(f, __classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_accept_get))) {
115
130
  refused.push(f);
116
131
  reasons.push(this.t('wrongType', { name: f.name }));
117
132
  }
@@ -122,10 +137,10 @@ export class CmFileUpload extends CmLocalizedElement {
122
137
  else
123
138
  ok.push(f);
124
139
  }
125
- let next = this.multiple ? [...this.files, ...ok] : ok.slice(-1);
126
- if (!this.multiple && !ok.length)
140
+ let next = __classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_multiple_get) ? [...this.files, ...ok] : ok.slice(-1);
141
+ if (!__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_multiple_get) && !ok.length)
127
142
  next = this.files;
128
- if (this.multiple && this.maxFiles && next.length > this.maxFiles) {
143
+ if (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_multiple_get) && this.maxFiles && next.length > this.maxFiles) {
129
144
  refused.push(...next.slice(this.maxFiles));
130
145
  reasons.push(this.t('tooMany', { max: this.maxFiles }));
131
146
  next = next.slice(0, this.maxFiles);
@@ -148,6 +163,8 @@ export class CmFileUpload extends CmLocalizedElement {
148
163
  this.updateComplete.then(() => this.renderRoot.querySelector('input')?.focus());
149
164
  }
150
165
  render() {
166
+ if (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get))
167
+ return __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_renderPhoto).call(this);
151
168
  const msg = this.error || this._rejected;
152
169
  const showZone = !this.files.length || this.multiple;
153
170
  const tile = this.files.length > 0;
@@ -173,7 +190,7 @@ export class CmFileUpload extends CmLocalizedElement {
173
190
  `;
174
191
  }
175
192
  }
176
- _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFileUpload_urls = new WeakMap(), _CmFileUpload_instances = new WeakSet(), _CmFileUpload_size = function _CmFileUpload_size(n) {
193
+ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFileUpload_urls = new WeakMap(), _CmFileUpload_instances = new WeakSet(), _CmFileUpload_photo_get = function _CmFileUpload_photo_get() { return this.variant === 'photo'; }, _CmFileUpload_accept_get = function _CmFileUpload_accept_get() { return this.accept || (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get) ? 'image/*' : ''); }, _CmFileUpload_multiple_get = function _CmFileUpload_multiple_get() { return this.multiple && !__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get); }, _CmFileUpload_size = function _CmFileUpload_size(n) {
177
194
  return n >= 1024 * 1024
178
195
  ? this.t('megabytes', { size: this.formatNumber(+(n / 1024 / 1024).toFixed(1), { useGrouping: false }) })
179
196
  : this.t('kilobytes', { size: this.formatNumber(Math.max(1, Math.round(n / 1024)), { useGrouping: false }) });
@@ -193,7 +210,7 @@ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFi
193
210
  const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, (this.error || this._rejected) && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
194
211
  return html `<label class="zone ${tile ? 'tile' : ''}" part="zone"
195
212
  @dragenter=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, true)} @dragleave=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)} @drop=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)}>
196
- <input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${this.accept || nothing} ?multiple=${this.multiple} ?disabled=${this.disabled}
213
+ <input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${this.accept || nothing} capture=${this.capture || nothing} ?multiple=${this.multiple} ?disabled=${this.disabled}
197
214
  ?required=${this.required && !this.files.length}
198
215
  aria-labelledby=${[this.label && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-l`, `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p`].filter(Boolean).join(' ')}
199
216
  aria-describedby=${described || nothing} aria-invalid=${this.error || this._rejected ? 'true' : nothing}
@@ -201,6 +218,38 @@ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFi
201
218
  <cm-icon name=${tile ? 'plus' : 'upload'} size=${tile ? 24 : 38}></cm-icon>
202
219
  <span id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p">${tile ? this.t('addMore') : this.prompt}</span>
203
220
  </label>`;
221
+ }, _CmFileUpload_retake = function _CmFileUpload_retake() { this.renderRoot.querySelector('input[type=file]')?.click(); }, _CmFileUpload_renderPhoto = function _CmFileUpload_renderPhoto() {
222
+ const msg = this.error || this._rejected;
223
+ const f = this.files[0];
224
+ const name = this.label || this.t('photo');
225
+ const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, msg && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
226
+ const input = (hidden) => html `<input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_accept_get)} capture=${this.capture || nothing}
227
+ ?disabled=${this.disabled} ?required=${this.required && !f} tabindex=${hidden ? '-1' : nothing} aria-hidden=${hidden ? 'true' : nothing}
228
+ ?hidden=${hidden} aria-labelledby=${hidden ? nothing : `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p`} aria-describedby=${(!hidden && described) || nothing} aria-invalid=${msg ? 'true' : nothing}
229
+ @change=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_onInputChange)} @cancel=${(e) => e.stopPropagation()} />`;
230
+ const hint = this.hint ? html `<span class="hint" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint">${this.hint}</span>` : nothing;
231
+ return html `
232
+ ${f
233
+ ? html `<div class="shot" part="photo">
234
+ ${f.type.startsWith('image/')
235
+ ? html `<img src=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_url).call(this, f)} alt=${name} />`
236
+ : html `<div class="doc"><cm-icon name="book" size="24"></cm-icon><span class="name">${f.name}</span><span class="size">${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_size).call(this, f.size)}</span></div>`}
237
+ </div>
238
+ <p class="caption" aria-hidden="true">${this.label}</p>
239
+ ${input(true)}
240
+ ${this.disabled ? nothing : html `<div class="actions" part="actions">
241
+ <button type="button" class="action retake" aria-label=${this.t('retakeName', { name })} aria-describedby=${msg ? `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg` : nothing} @click=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_retake)}><cm-icon name="camera" size="16"></cm-icon>${this.t('retake')}</button>
242
+ <button type="button" class="action" aria-label=${this.t('removeName', { name })} @click=${() => this.removeFile(f)}><cm-icon name="trash" size="16"></cm-icon>${this.t('removePhoto')}</button>
243
+ </div>`}`
244
+ : html `<label class="zone photo ${msg ? 'invalid' : ''}" part="zone photo"
245
+ @dragenter=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, true)} @dragleave=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)} @drop=${() => __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_setOver).call(this, false)}>
246
+ ${input(false)}
247
+ <cm-icon name="camera" size="32"></cm-icon>
248
+ <span class="photo-label" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p" part="label">${this.label || this.t('takePhoto')}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</span>
249
+ ${hint}
250
+ </label>`}
251
+ ${msg ? html `<p class="msg" id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg" role="alert">${msg}</p>` : nothing}
252
+ `;
204
253
  };
205
254
  CmFileUpload.formAssociated = true;
206
255
  CmFileUpload.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
@@ -217,6 +266,8 @@ CmFileUpload.properties = {
217
266
  disabled: { type: Boolean, reflect: true },
218
267
  error: { reflect: true },
219
268
  files: { attribute: false },
269
+ variant: { reflect: true },
270
+ capture: { reflect: true },
220
271
  _rejected: { state: true },
221
272
  };
222
273
  CmFileUpload.styles = [
@@ -254,8 +305,28 @@ CmFileUpload.styles = [
254
305
  .msg { margin: var(--cm-space-10) 0 0; font-size: 12px; color: var(--cm-text-critical); }
255
306
  :host([disabled]) .zone { cursor: not-allowed; background: var(--cm-bg-input-filled); color: var(--cm-text-secondary); border-color: var(--cm-border-default); }
256
307
  :host([disabled]) .remove { display: none; }
308
+ /* variant="photo" (1.3) */
309
+ .zone.photo { min-height: 0; aspect-ratio: 4 / 3; border-radius: var(--cm-radius-md); font-size: 14px; }
310
+ .zone.photo.invalid { border-color: var(--cm-border-critical); }
311
+ .photo-label { font-weight: 500; overflow-wrap: anywhere; }
312
+ .shot {
313
+ aspect-ratio: 4 / 3; border-radius: var(--cm-radius-md); overflow: hidden;
314
+ background: var(--cm-bg-inset); border: var(--cm-border-1) solid var(--cm-border-card);
315
+ }
316
+ .shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
317
+ .caption { margin: var(--cm-space-10) 0 0; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
318
+ .caption:empty { display: none; }
319
+ .actions { display: flex; flex-wrap: wrap; gap: var(--cm-space-10); margin-top: var(--cm-space-10); }
320
+ .action {
321
+ display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: 1 1 0; min-width: max-content;
322
+ min-height: 40px; padding: 0 var(--cm-space-15); font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
323
+ background: var(--cm-bg-hover); color: var(--cm-text-default);
324
+ border: var(--cm-border-1) solid var(--cm-border-strong); border-radius: var(--cm-radius-sm);
325
+ }
326
+ .action:hover { background: var(--cm-bg-surface); }
327
+ .action:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
257
328
  @media (max-width: 640px) {
258
- .zone:not(.tile) { min-height: 100px; font-size: 14px; }
329
+ .zone:not(.tile):not(.photo) { min-height: 100px; font-size: 14px; }
259
330
  .label { font-size: var(--cm-type-heading-sm-resp-size); }
260
331
  }
261
332
  `,
@@ -14,7 +14,7 @@ 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, closeOnOutsidePointer } from '../popover.js';
17
+ import { popoverStyles, groupStyles, closeOnOutsidePointer } from '../popover.js';
18
18
  import './icon.js';
19
19
  import './spinner.js';
20
20
  const strings = defineStrings('globalSearch', {
@@ -246,6 +246,7 @@ CmGlobalSearch.properties = {
246
246
  CmGlobalSearch.styles = [
247
247
  base,
248
248
  popoverStyles,
249
+ groupStyles,
249
250
  css `
250
251
  :host { display: block; position: relative; }
251
252
  .wrap { position: relative; }
@@ -281,12 +282,6 @@ CmGlobalSearch.styles = [
281
282
  }
282
283
  [role='listbox'] { padding-block: 6px; }
283
284
  [role='listbox'][hidden] { display: none; }
284
- [role='group'] + [role='group'] { margin-block-start: 6px; padding-block-start: 6px; border-top: var(--cm-border-1) solid var(--cm-border-default); }
285
- .gh {
286
- display: flex; align-items: baseline; gap: var(--cm-space-10); padding: 6px var(--cm-space-20) 2px;
287
- font-size: 12px; line-height: 16px; font-weight: 600; color: var(--cm-text-default);
288
- }
289
- .gh .count { font-weight: 400; color: var(--cm-text-tertiary); }
290
285
  [role='option'] {
291
286
  display: flex; align-items: center; gap: var(--cm-space-10); min-height: 40px; padding: 6px var(--cm-space-20);
292
287
  font-size: 14px; line-height: 20px; color: var(--cm-text-default); text-decoration: none; cursor: pointer;
@@ -4,8 +4,12 @@ declare const itemStrings: {
4
4
  /** Accessible name of the drag handle, and the keyboard hint read with it. */
5
5
  reorder: string;
6
6
  hint: string;
7
+ /** The keyboard hint in a list with a `group`: the arrows also cross into the list before or after. */
8
+ hintGroup: string;
7
9
  /** Announced after a move. */
8
10
  moved: string;
11
+ /** Announced after a move into another list (`group`). */
12
+ movedTo: string;
9
13
  };
10
14
  declare const listStrings: {
11
15
  /** Accessible name of the show/hide button. */
@@ -25,6 +29,7 @@ declare module '../localize.js' {
25
29
  * @slot - Child `cm-nested-item`s.
26
30
  * @slot actions - Controls at the end of the row: a badge, a toggle, edit and delete buttons.
27
31
  * @fires cm-reorder - Bubbles from the moved item: `detail: { item, from, to }` (positions among its siblings). Cancelable.
32
+ * @fires cm-move - Bubbles from the item before it moves into another list with the same `group` (since 1.3): `detail: { item, from, to, fromList, toList }`, where `from` is its position in `fromList` and `to` its position in `toList` after the move. Cancelable: the component moves the element unless you call `preventDefault()`.
28
33
  */
29
34
  export declare class CmNestedItem extends CmLocalizedElement {
30
35
  #private;
@@ -51,6 +56,14 @@ export declare class CmNestedItem extends CmLocalizedElement {
51
56
  constructor();
52
57
  connectedCallback(): void;
53
58
  static styles: import("lit").CSSResult[];
59
+ /** The `cm-nested-list` this item is a top-level row of, or null when it is nested in another item. */
60
+ get list(): CmNestedList | null;
61
+ /**
62
+ * Moves this top-level row into another `cm-nested-list` with the same `group`, at position `to` (default: the
63
+ * end), firing a cancelable `cm-move` first. With its own list it is the same as `moveTo(to)`. Use it for a
64
+ * "Move to…" menu. Returns false if nothing moved. Since 1.3.
65
+ */
66
+ moveToList(list: CmNestedList, to?: number): boolean;
54
67
  /** Sibling `cm-nested-item`s, including this one. */
55
68
  get siblings(): CmNestedItem[];
56
69
  /**
@@ -67,11 +80,13 @@ export declare class CmNestedItem extends CmLocalizedElement {
67
80
  * sub-links, or categories and sub-categories. The heading sits in a 90px grey bar with its own
68
81
  * actions; rows below are indented one step per level. With `sortable`, each row gets a drag
69
82
  * handle that also works from the keyboard (↑/↓, Home/End). With `collapsible`, the bar gets a
70
- * round button that shows and hides the rows.
83
+ * round button that shows and hides the rows. Give sortable lists the same `group` to let top-level rows move
84
+ * between them, by drag and drop or from the keyboard (since 1.3).
71
85
  * @element cm-nested-list
72
86
  * @slot - `cm-nested-item` rows.
73
87
  * @slot actions - Controls in the heading bar, e.g. an "Add links" button or a toggle.
74
88
  * @fires cm-reorder - When a row is moved. See `cm-nested-item`.
89
+ * @fires cm-move - When a row moves into another list with the same `group`. Fired on the row before it moves, so it bubbles through the list it leaves. See `cm-nested-item`.
75
90
  * @fires cm-toggle - `detail: { open }` when a collapsible list is shown or hidden.
76
91
  */
77
92
  export declare class CmNestedList extends CmLocalizedElement {
@@ -94,9 +109,15 @@ export declare class CmNestedList extends CmLocalizedElement {
94
109
  type: BooleanConstructor;
95
110
  reflect: boolean;
96
111
  };
112
+ group: {
113
+ reflect: boolean;
114
+ };
97
115
  _msg: {
98
116
  state: boolean;
99
117
  };
118
+ _empty: {
119
+ state: boolean;
120
+ };
100
121
  };
101
122
  /** Title in the grey bar, e.g. "Header" or "Clothing & accessories". */
102
123
  heading: string;
@@ -108,10 +129,21 @@ export declare class CmNestedList extends CmLocalizedElement {
108
129
  collapsible: boolean;
109
130
  /** Whether the rows are shown when `collapsible`. */
110
131
  open: boolean;
132
+ /**
133
+ * Name shared by sortable lists that accept each other's top-level rows (since 1.3), e.g. every section of a
134
+ * form layout. Rows then move between them by drag and drop (mouse or touch) and from the keyboard: ↑ on the
135
+ * first row or ↓ on the last moves it into the list before or after. The component moves the element and fires
136
+ * a cancelable `cm-move`. An empty list in a group shows a drop area.
137
+ */
138
+ group: string;
111
139
  _msg: string;
140
+ _empty: boolean;
112
141
  static styles: import("lit").CSSResult[];
142
+ /** The top-level `cm-nested-item` rows, in order. */
143
+ get items(): CmNestedItem[];
113
144
  /** Reads a message to screen readers, e.g. after a move. */
114
145
  announce(msg: string): void;
146
+ willUpdate(): void;
115
147
  updated(changed: Map<string, unknown>): void;
116
148
  render(): import("lit-html").TemplateResult<1>;
117
149
  }