@commmerce/ui 1.0.0-rc.4 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/LICENSE.md +152 -17
  2. package/README.md +2 -3
  3. package/THIRD_PARTY_NOTICES.txt +175 -0
  4. package/dist/base.d.ts +5 -0
  5. package/dist/base.js +10 -0
  6. package/dist/calendar.d.ts +95 -0
  7. package/dist/calendar.js +280 -0
  8. package/dist/cdn.js +721 -477
  9. package/dist/components/accordion.js +2 -2
  10. package/dist/components/action-bar.d.ts +12 -2
  11. package/dist/components/action-bar.js +10 -5
  12. package/dist/components/action-menu.d.ts +17 -4
  13. package/dist/components/action-menu.js +8 -5
  14. package/dist/components/app-card.d.ts +24 -2
  15. package/dist/components/app-card.js +25 -10
  16. package/dist/components/banner.d.ts +2 -2
  17. package/dist/components/banner.js +4 -3
  18. package/dist/components/bottom-navigation.d.ts +16 -4
  19. package/dist/components/bottom-navigation.js +10 -7
  20. package/dist/components/bottom-sheet.d.ts +4 -1
  21. package/dist/components/bottom-sheet.js +2 -2
  22. package/dist/components/checkbox.d.ts +12 -2
  23. package/dist/components/checkbox.js +7 -2
  24. package/dist/components/combobox.d.ts +186 -0
  25. package/dist/components/combobox.js +521 -0
  26. package/dist/components/comment.d.ts +27 -9
  27. package/dist/components/comment.js +14 -13
  28. package/dist/components/data-table.d.ts +14 -2
  29. package/dist/components/data-table.js +31 -10
  30. package/dist/components/date-picker.d.ts +179 -0
  31. package/dist/components/date-picker.js +336 -0
  32. package/dist/components/date-range-picker.d.ts +251 -0
  33. package/dist/components/date-range-picker.js +484 -0
  34. package/dist/components/file-upload.d.ts +30 -4
  35. package/dist/components/file-upload.js +37 -17
  36. package/dist/components/filter-panel.d.ts +29 -6
  37. package/dist/components/filter-panel.js +16 -14
  38. package/dist/components/flash-offer-bar.d.ts +18 -4
  39. package/dist/components/flash-offer-bar.js +13 -8
  40. package/dist/components/header-bar.d.ts +20 -4
  41. package/dist/components/header-bar.js +20 -13
  42. package/dist/components/icon.d.ts +7 -0
  43. package/dist/components/icon.js +9 -1
  44. package/dist/components/link-tabs.d.ts +16 -4
  45. package/dist/components/link-tabs.js +10 -7
  46. package/dist/components/mobile-menu.d.ts +19 -4
  47. package/dist/components/mobile-menu.js +16 -10
  48. package/dist/components/modal.d.ts +4 -1
  49. package/dist/components/nested-list.d.ts +22 -3
  50. package/dist/components/nested-list.js +25 -12
  51. package/dist/components/notification-panel.d.ts +26 -5
  52. package/dist/components/notification-panel.js +17 -11
  53. package/dist/components/option-group.d.ts +12 -2
  54. package/dist/components/option-group.js +13 -7
  55. package/dist/components/page-header.d.ts +18 -2
  56. package/dist/components/page-header.js +23 -10
  57. package/dist/components/pagination.d.ts +27 -4
  58. package/dist/components/pagination.js +28 -16
  59. package/dist/components/progress-bar.d.ts +12 -2
  60. package/dist/components/progress-bar.js +9 -4
  61. package/dist/components/radio.d.ts +12 -1
  62. package/dist/components/radio.js +12 -6
  63. package/dist/components/report-tile.d.ts +12 -1
  64. package/dist/components/report-tile.js +9 -4
  65. package/dist/components/resource-list.d.ts +36 -5
  66. package/dist/components/resource-list.js +50 -23
  67. package/dist/components/save-bar.d.ts +23 -6
  68. package/dist/components/save-bar.js +14 -12
  69. package/dist/components/search.d.ts +28 -7
  70. package/dist/components/search.js +18 -13
  71. package/dist/components/select.d.ts +12 -2
  72. package/dist/components/select.js +9 -4
  73. package/dist/components/side-navigation.d.ts +16 -4
  74. package/dist/components/side-navigation.js +16 -12
  75. package/dist/components/side-panel.d.ts +5 -2
  76. package/dist/components/side-panel.js +5 -3
  77. package/dist/components/skeleton-display.d.ts +6 -4
  78. package/dist/components/skeleton-display.js +4 -5
  79. package/dist/components/smart-tip.d.ts +25 -6
  80. package/dist/components/smart-tip.js +18 -12
  81. package/dist/components/spinner.d.ts +4 -3
  82. package/dist/components/spinner.js +5 -6
  83. package/dist/components/status-tabs.d.ts +12 -2
  84. package/dist/components/status-tabs.js +14 -8
  85. package/dist/components/table-header.d.ts +15 -2
  86. package/dist/components/table-header.js +13 -5
  87. package/dist/components/tag.d.ts +12 -2
  88. package/dist/components/tag.js +9 -4
  89. package/dist/components/text-field.d.ts +12 -2
  90. package/dist/components/text-field.js +9 -4
  91. package/dist/components/thumbnail.d.ts +12 -2
  92. package/dist/components/thumbnail.js +8 -3
  93. package/dist/components/toast.d.ts +14 -3
  94. package/dist/components/toast.js +20 -9
  95. package/dist/components/toggle.js +2 -0
  96. package/dist/custom-elements.json +16477 -6434
  97. package/dist/index.d.ts +7 -1
  98. package/dist/index.js +5 -1
  99. package/dist/localize.d.ts +130 -0
  100. package/dist/localize.js +232 -0
  101. package/dist/overlay.d.ts +8 -4
  102. package/dist/overlay.js +9 -12
  103. package/package.json +5 -4
@@ -0,0 +1,521 @@
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 _CmCombobox_instances, _CmCombobox_internals, _CmCombobox_id, _CmCombobox_default, _CmCombobox_labels, _CmCombobox_observer, _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_onOutside, _CmCombobox_highlight;
13
+ import { LitElement, html, css, nothing } from 'lit';
14
+ import { live } from 'lit/directives/live.js';
15
+ import { base, define, nextId } from '../base.js';
16
+ import { CmLocalizedElement, defineStrings } from '../localize.js';
17
+ import './icon.js';
18
+ import './tag.js';
19
+ import './spinner.js';
20
+ const strings = defineStrings('combobox', {
21
+ /** Shown in the open list when nothing matches. */
22
+ noResults: 'No results',
23
+ /** Announced as the list changes. */
24
+ results: { one: '{count} result', other: '{count} results' },
25
+ /** The row that adds what was typed (`allow-custom`). */
26
+ add: 'Add “{value}”',
27
+ /** Accessible name of a tag's remove button (`multiple`). */
28
+ remove: 'Remove {label}',
29
+ /** Validation: `required` and nothing chosen. */
30
+ required: 'Please select an item in the list.',
31
+ /** Validation: `required`, `multiple` and nothing chosen. */
32
+ requiredMultiple: 'Choose at least one item.',
33
+ });
34
+ /**
35
+ * Editable combobox: a text box that suggests matching options as the merchant types (the WAI-ARIA APG
36
+ * "combobox with list autocomplete" pattern). Picks one option, or several with `multiple` (shown as removable
37
+ * tags). With `filter="none"` it doesn't filter by itself: listen for `cm-search`, fetch matches, set `options`
38
+ * and toggle `loading`. With `allow-custom` the merchant can add a value that isn't in the list (a new product tag).
39
+ *
40
+ * Options come from `<option>` children or the `options` property, as for `cm-select`.
41
+ * @element cm-combobox
42
+ * @slot - `<option value="…">Label</option>` elements. `disabled` and `selected` are honoured.
43
+ * @fires change - When the value changes (an option picked or removed, or a custom value added).
44
+ * @fires input - Same moment as `change`.
45
+ * @fires cm-search - As the merchant types, with `detail: { query }`. Use it to load matches from the server.
46
+ * @fires cm-create - Before a custom value is added (`allow-custom`), with `detail: { value }`. Cancelable: call `preventDefault()` to refuse it.
47
+ * @csspart box - The bordered box around the tags and the text input.
48
+ * @csspart input - The text input.
49
+ * @csspart listbox - The list of suggestions.
50
+ */
51
+ export class CmCombobox extends CmLocalizedElement {
52
+ constructor() {
53
+ super(...arguments);
54
+ _CmCombobox_instances.add(this);
55
+ /** Visible label above the box. Required for accessibility unless the element has an aria-label. */
56
+ this.label = '';
57
+ /** One sentence under the box in text-tertiary. */
58
+ this.helpText = '';
59
+ /** Error message; turns the border critical and sets aria-invalid. */
60
+ this.error = '';
61
+ /** Form field name. With `multiple`, each value is submitted as its own entry under this name. */
62
+ this.name = '';
63
+ /** Value of the chosen option (single mode). Empty when nothing is chosen. */
64
+ this.value = '';
65
+ /** Values of the chosen options (`multiple` mode), in the order they were added. */
66
+ this.values = [];
67
+ /** Shown in the empty text box, e.g. "Search tags". */
68
+ this.placeholder = '';
69
+ /** Options as strings or `{ value, label, disabled }`. Used instead of `<option>` children when set. */
70
+ this.options = [];
71
+ /** Lets the merchant choose several options, shown as removable tags. Backspace in the empty box removes the last one. */
72
+ this.multiple = false;
73
+ /** Lets the merchant add what they typed when it isn't an option ("Add “summer”"). Fires a cancelable `cm-create`. */
74
+ this.allowCustom = false;
75
+ /** How typing narrows the list: `contains` (default), `starts-with`, or `none` when you filter on the server from `cm-search`. */
76
+ this.filter = 'contains';
77
+ /** Shows a spinner in the list while you load options. */
78
+ this.loading = false;
79
+ /** The form will not submit until something is chosen. */
80
+ this.required = false;
81
+ /** Blocks interaction. Also set by a disabled `<fieldset>`. */
82
+ this.disabled = false;
83
+ /** Whether the list is showing. */
84
+ this.open = false;
85
+ this._query = '';
86
+ this._active = -1;
87
+ this._slotted = [];
88
+ /** True while the text box holds the merchant's own query rather than the chosen option's label. */
89
+ this._typing = false;
90
+ _CmCombobox_internals.set(this, this.attachInternals());
91
+ _CmCombobox_id.set(this, nextId('cm-cb'));
92
+ _CmCombobox_default.set(this, null);
93
+ /** Labels for chosen values, so tags keep their text when async options change. */
94
+ _CmCombobox_labels.set(this, new Map());
95
+ _CmCombobox_observer.set(this, new MutationObserver(() => __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_readChildren).call(this)));
96
+ _CmCombobox_onInput.set(this, (e) => {
97
+ e.stopPropagation(); // the native per-keystroke input event; `input` is fired when the value changes
98
+ this._query = e.target.value;
99
+ this._typing = true;
100
+ this._active = -1;
101
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_show).call(this);
102
+ this.dispatchEvent(new CustomEvent('cm-search', { detail: { query: this._query }, bubbles: true, composed: true }));
103
+ });
104
+ _CmCombobox_onKeyDown.set(this, (e) => {
105
+ if (this.disabled)
106
+ return;
107
+ const k = e.key;
108
+ switch (k) {
109
+ case 'ArrowDown':
110
+ e.preventDefault();
111
+ if (!this.open) {
112
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_show).call(this);
113
+ if (!e.altKey)
114
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_move).call(this, 'first');
115
+ }
116
+ else
117
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_move).call(this, 1);
118
+ break;
119
+ case 'ArrowUp':
120
+ e.preventDefault();
121
+ if (!this.open) {
122
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_show).call(this);
123
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_move).call(this, 'last');
124
+ }
125
+ else
126
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_move).call(this, -1);
127
+ break;
128
+ case 'Enter':
129
+ if (this.open && this._active >= 0) {
130
+ e.preventDefault();
131
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_choose).call(this, this._active);
132
+ }
133
+ else if (__classPrivateFieldGet(this, _CmCombobox_instances, "a", _CmCombobox_createText_get)) {
134
+ e.preventDefault();
135
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_create).call(this, __classPrivateFieldGet(this, _CmCombobox_instances, "a", _CmCombobox_createText_get));
136
+ }
137
+ break;
138
+ case 'Escape':
139
+ if (this.open) {
140
+ e.preventDefault();
141
+ e.stopPropagation();
142
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_hide).call(this);
143
+ }
144
+ else if (this._query) {
145
+ e.preventDefault();
146
+ this._query = '';
147
+ this._typing = true;
148
+ if (!this.multiple && this.value) {
149
+ this.value = '';
150
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_emit).call(this);
151
+ }
152
+ }
153
+ break;
154
+ case 'Backspace':
155
+ if (this.multiple && !this._query && this.values.length) {
156
+ e.preventDefault();
157
+ this.removeValue(this.values[this.values.length - 1]);
158
+ }
159
+ break;
160
+ case 'Tab':
161
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_hide).call(this);
162
+ break;
163
+ default:
164
+ }
165
+ });
166
+ _CmCombobox_onBlur.set(this, () => {
167
+ // Leaving the box: put back the chosen option's label (single), or clear an unfinished query (multiple).
168
+ queueMicrotask(() => {
169
+ if (this.shadowRoot?.activeElement === this.renderRoot.querySelector('input'))
170
+ return;
171
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_hide).call(this);
172
+ if (!this._typing)
173
+ return;
174
+ this._typing = false;
175
+ this._query = this.multiple ? '' : this.value ? __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_labelOf).call(this, this.value) : '';
176
+ });
177
+ });
178
+ _CmCombobox_onOutside.set(this, (e) => {
179
+ if (this.open && !e.composedPath().includes(this))
180
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_hide).call(this);
181
+ });
182
+ }
183
+ connectedCallback() {
184
+ super.connectedCallback();
185
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_readChildren).call(this);
186
+ __classPrivateFieldGet(this, _CmCombobox_observer, "f").observe(this, { childList: true, subtree: true, characterData: true, attributes: true, attributeFilter: ['value', 'label', 'disabled', 'selected'] });
187
+ document.addEventListener('pointerdown', __classPrivateFieldGet(this, _CmCombobox_onOutside, "f"), true);
188
+ }
189
+ disconnectedCallback() {
190
+ super.disconnectedCallback();
191
+ __classPrivateFieldGet(this, _CmCombobox_observer, "f").disconnect();
192
+ document.removeEventListener('pointerdown', __classPrivateFieldGet(this, _CmCombobox_onOutside, "f"), true);
193
+ }
194
+ get form() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").form; }
195
+ get validity() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").validity; }
196
+ get validationMessage() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").validationMessage; }
197
+ checkValidity() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").checkValidity(); }
198
+ reportValidity() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").reportValidity(); }
199
+ formResetCallback() {
200
+ const d = __classPrivateFieldGet(this, _CmCombobox_default, "f") ?? { value: '', values: [] };
201
+ this.value = d.value;
202
+ this.values = [...d.values];
203
+ this._query = '';
204
+ this._typing = false;
205
+ this.open = false;
206
+ }
207
+ formDisabledCallback(d) { this.disabled = d; if (d)
208
+ this.open = false; }
209
+ formStateRestoreCallback(state) {
210
+ if (typeof state === 'string') {
211
+ if (this.multiple)
212
+ this.values = state ? state.split('\n') : [];
213
+ else
214
+ this.value = state;
215
+ }
216
+ }
217
+ /** All options in use, normalised (before filtering). */
218
+ get items() {
219
+ if (!this.options?.length)
220
+ return this._slotted;
221
+ return this.options.map((o) => (typeof o === 'string' ? { value: o, label: o } : o));
222
+ }
223
+ /** The options shown for the current query. */
224
+ get filteredItems() {
225
+ const q = this._typing ? this._query.trim().toLowerCase() : '';
226
+ if (!q || this.filter === 'none')
227
+ return this.items;
228
+ return this.items.filter((o) => {
229
+ const l = o.label.toLowerCase();
230
+ return this.filter === 'starts-with' ? l.startsWith(q) : l.includes(q);
231
+ });
232
+ }
233
+ firstUpdated() {
234
+ __classPrivateFieldSet(this, _CmCombobox_default, { value: this.value, values: [...this.values] }, "f");
235
+ }
236
+ willUpdate(changed) {
237
+ for (const o of this.items)
238
+ __classPrivateFieldGet(this, _CmCombobox_labels, "f").set(o.value, o.label);
239
+ if ((changed.has('value') || changed.has('options') || changed.has('_slotted')) && !this.multiple && !this._typing) {
240
+ this._query = this.value ? __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_labelOf).call(this, this.value) : '';
241
+ }
242
+ if (changed.has('_query') || changed.has('options') || changed.has('_slotted') || changed.has('loading')) {
243
+ const rows = __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_rows).call(this);
244
+ if (this._active >= rows.length)
245
+ this._active = -1;
246
+ }
247
+ }
248
+ updated(changed) {
249
+ const input = this.renderRoot.querySelector('input') ?? undefined;
250
+ if (this.multiple) {
251
+ if (this.name && this.values.length) {
252
+ const fd = new FormData();
253
+ for (const v of this.values)
254
+ fd.append(this.name, v);
255
+ __classPrivateFieldGet(this, _CmCombobox_internals, "f").setFormValue(fd, this.values.join('\n'));
256
+ }
257
+ else
258
+ __classPrivateFieldGet(this, _CmCombobox_internals, "f").setFormValue(null);
259
+ }
260
+ else
261
+ __classPrivateFieldGet(this, _CmCombobox_internals, "f").setFormValue(this.value || null, this.value);
262
+ const empty = this.multiple ? !this.values.length : !this.value;
263
+ if (this.error)
264
+ __classPrivateFieldGet(this, _CmCombobox_internals, "f").setValidity({ customError: true }, this.error, input);
265
+ else if (this.required && empty)
266
+ __classPrivateFieldGet(this, _CmCombobox_internals, "f").setValidity({ valueMissing: true }, this.t(this.multiple ? 'requiredMultiple' : 'required'), input);
267
+ else
268
+ __classPrivateFieldGet(this, _CmCombobox_internals, "f").setValidity({});
269
+ if ((changed.has('_active') || changed.has('open')) && this.open && this._active >= 0) {
270
+ this.renderRoot.querySelector(`#${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-o${this._active}`)?.scrollIntoView({ block: 'nearest' });
271
+ }
272
+ }
273
+ /** Removes a chosen value (`multiple`). */
274
+ removeValue(value) {
275
+ if (!this.values.includes(value))
276
+ return;
277
+ this.values = this.values.filter((v) => v !== value);
278
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_emit).call(this);
279
+ }
280
+ render() {
281
+ const rows = __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_rows).call(this);
282
+ const described = [this.error && `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-help`].filter(Boolean).join(' ');
283
+ const hostLabel = this.getAttribute('aria-label');
284
+ const selected = (v) => (this.multiple ? this.values.includes(v) : v === this.value);
285
+ const status = this.loading ? this.loadingText || this.t('loading')
286
+ : !this.open ? ''
287
+ : rows.length ? this.t('results', { count: rows.length })
288
+ : this.emptyText || this.t('noResults');
289
+ return html `<div class="field">
290
+ ${this.label
291
+ ? html `<label class="label" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-l" for="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-in" part="label">${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</label>`
292
+ : nothing}
293
+ <div class="wrap">
294
+ <div class="box" part="box" @click=${(e) => { if (!e.target.closest('cm-tag'))
295
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_focusInput).call(this); }}>
296
+ ${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) })}
297
+ @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}
298
+ <input id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-in" part="input" type="text" role="combobox" autocomplete="off" spellcheck="false"
299
+ .value=${live(this._query)} placeholder=${this.multiple && this.values.length ? nothing : this.placeholder || nothing}
300
+ aria-label=${!this.label && hostLabel ? hostLabel : nothing}
301
+ aria-autocomplete="list" aria-expanded=${this.open ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-list"
302
+ aria-activedescendant=${this.open && this._active >= 0 ? `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-o${this._active}` : nothing}
303
+ aria-invalid=${this.error ? 'true' : nothing} aria-describedby=${described || nothing}
304
+ aria-required=${this.required ? 'true' : nothing} ?disabled=${this.disabled}
305
+ @input=${__classPrivateFieldGet(this, _CmCombobox_onInput, "f")} @keydown=${__classPrivateFieldGet(this, _CmCombobox_onKeyDown, "f")} @blur=${__classPrivateFieldGet(this, _CmCombobox_onBlur, "f")}
306
+ @click=${() => { if (!this.open)
307
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_show).call(this); }} @change=${(e) => e.stopPropagation()} />
308
+ <cm-icon class="chev" name="chevron-down" size="16" @click=${() => { if (this.open)
309
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_hide).call(this);
310
+ else {
311
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_show).call(this);
312
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_focusInput).call(this);
313
+ } }}></cm-icon>
314
+ </div>
315
+ <div class="pop" part="popover" ?hidden=${!this.open} @pointerdown=${(e) => e.preventDefault()}>
316
+ <ul role="listbox" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-list" part="listbox" ?hidden=${!rows.length}
317
+ aria-labelledby=${this.label ? `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-l` : nothing} aria-label=${!this.label && hostLabel ? hostLabel : nothing}
318
+ aria-multiselectable=${this.multiple ? 'true' : nothing}>
319
+ ${rows.map((o, i) => html `<li role="option" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-o${i}" class=${i === this._active ? 'active' : ''}
320
+ aria-selected=${o.create ? 'false' : selected(o.value) ? 'true' : 'false'} aria-disabled=${o.disabled ? 'true' : nothing}
321
+ @pointerenter=${() => !o.disabled && (this._active = i)} @click=${() => __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_choose).call(this, i)}>
322
+ ${o.create
323
+ ? html `<cm-icon name="plus" size="16"></cm-icon><span class="create">${this.t('add', { value: o.label })}</span>`
324
+ : 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>`)}
325
+ </ul>
326
+ ${this.loading
327
+ ? html `<p class="message"><cm-spinner size="small" aria-hidden="true"></cm-spinner><span aria-hidden="true">${this.loadingText || this.t('loading')}</span></p>`
328
+ : !rows.length ? html `<p class="message">${this.emptyText || this.t('noResults')}</p>` : nothing}
329
+ </div>
330
+ </div>
331
+ <span class="vh" role="status" aria-live="polite">${status}</span>
332
+ ${this.error ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-err" role="alert">${this.error}</p>` : nothing}
333
+ ${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-help">${this.helpText}</p>` : nothing}
334
+ <slot></slot>
335
+ </div>`;
336
+ }
337
+ }
338
+ _CmCombobox_internals = new WeakMap(), _CmCombobox_id = new WeakMap(), _CmCombobox_default = new WeakMap(), _CmCombobox_labels = new WeakMap(), _CmCombobox_observer = new WeakMap(), _CmCombobox_onInput = new WeakMap(), _CmCombobox_onKeyDown = new WeakMap(), _CmCombobox_onBlur = new WeakMap(), _CmCombobox_onOutside = new WeakMap(), _CmCombobox_instances = new WeakSet(), _CmCombobox_readChildren = function _CmCombobox_readChildren() {
339
+ const opts = [...this.querySelectorAll('option')];
340
+ this._slotted = opts.map((o) => ({ value: o.value, label: o.label || o.textContent.trim(), disabled: o.disabled }));
341
+ if (!this.hasUpdated) {
342
+ const sel = opts.filter((o) => o.hasAttribute('selected')).map((o) => o.value);
343
+ if (this.multiple && !this.values.length && sel.length)
344
+ this.values = sel;
345
+ if (!this.multiple && !this.value && sel.length)
346
+ this.value = sel[0];
347
+ }
348
+ }, _CmCombobox_labelOf = function _CmCombobox_labelOf(v) {
349
+ return this.items.find((o) => o.value === v)?.label ?? __classPrivateFieldGet(this, _CmCombobox_labels, "f").get(v) ?? v;
350
+ }, _CmCombobox_createText_get = function _CmCombobox_createText_get() {
351
+ if (!this.allowCustom || !this._typing)
352
+ return '';
353
+ const q = this._query.trim();
354
+ if (!q)
355
+ return '';
356
+ const lq = q.toLowerCase();
357
+ if (this.items.some((o) => o.label.toLowerCase() === lq || o.value.toLowerCase() === lq))
358
+ return '';
359
+ if (this.multiple ? this.values.some((v) => v.toLowerCase() === lq) : this.value.toLowerCase() === lq)
360
+ return '';
361
+ return q;
362
+ }, _CmCombobox_rows = function _CmCombobox_rows() {
363
+ const rows = this.loading ? [] : [...this.filteredItems];
364
+ const c = __classPrivateFieldGet(this, _CmCombobox_instances, "a", _CmCombobox_createText_get);
365
+ if (c && !this.loading)
366
+ rows.push({ value: c, label: c, create: true });
367
+ return rows;
368
+ }, _CmCombobox_emit = function _CmCombobox_emit() {
369
+ this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
370
+ this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
371
+ }, _CmCombobox_show = function _CmCombobox_show() { if (!this.disabled)
372
+ this.open = true; }, _CmCombobox_hide = function _CmCombobox_hide() { this.open = false; this._active = -1; }, _CmCombobox_enabled = function _CmCombobox_enabled(rows = __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_rows).call(this)) { return rows.flatMap((o, i) => (o.disabled ? [] : [i])); }, _CmCombobox_move = function _CmCombobox_move(step) {
373
+ const en = __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_enabled).call(this);
374
+ if (!en.length) {
375
+ this._active = -1;
376
+ return;
377
+ }
378
+ if (step === 'first')
379
+ return void (this._active = en[0]);
380
+ if (step === 'last')
381
+ return void (this._active = en[en.length - 1]);
382
+ const pos = en.indexOf(this._active);
383
+ if (pos < 0) {
384
+ this._active = step > 0 ? en[0] : en[en.length - 1];
385
+ return;
386
+ }
387
+ this._active = en[(pos + step + en.length) % en.length];
388
+ }, _CmCombobox_choose = function _CmCombobox_choose(i) {
389
+ const row = __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_rows).call(this)[i];
390
+ if (!row || row.disabled)
391
+ return;
392
+ if (row.create) {
393
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_create).call(this, row.value);
394
+ return;
395
+ }
396
+ if (this.multiple) {
397
+ this.values = this.values.includes(row.value) ? this.values.filter((v) => v !== row.value) : [...this.values, row.value];
398
+ this._query = '';
399
+ this._typing = false;
400
+ this._active = -1;
401
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_emit).call(this);
402
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_focusInput).call(this);
403
+ return;
404
+ }
405
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_hide).call(this);
406
+ this._typing = false;
407
+ this._query = row.label;
408
+ if (row.value !== this.value) {
409
+ this.value = row.value;
410
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_emit).call(this);
411
+ }
412
+ }, _CmCombobox_create = function _CmCombobox_create(text) {
413
+ const ok = this.dispatchEvent(new CustomEvent('cm-create', { detail: { value: text }, bubbles: true, composed: true, cancelable: true }));
414
+ if (!ok)
415
+ return;
416
+ __classPrivateFieldGet(this, _CmCombobox_labels, "f").set(text, text);
417
+ if (this.multiple) {
418
+ this.values = [...this.values, text];
419
+ this._query = '';
420
+ this._typing = false;
421
+ this._active = -1;
422
+ }
423
+ else {
424
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_hide).call(this);
425
+ this.value = text;
426
+ this._typing = false;
427
+ this._query = text;
428
+ }
429
+ __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_emit).call(this);
430
+ }, _CmCombobox_focusInput = function _CmCombobox_focusInput() { this.renderRoot.querySelector('input')?.focus(); }, _CmCombobox_highlight = function _CmCombobox_highlight(label) {
431
+ const q = this._typing ? this._query.trim() : '';
432
+ if (!q || this.filter === 'none')
433
+ return label;
434
+ const i = label.toLowerCase().indexOf(q.toLowerCase());
435
+ if (i < 0 || (this.filter === 'starts-with' && i !== 0))
436
+ return label;
437
+ return html `${label.slice(0, i)}<mark>${label.slice(i, i + q.length)}</mark>${label.slice(i + q.length)}`;
438
+ };
439
+ CmCombobox.formAssociated = true;
440
+ CmCombobox.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
441
+ CmCombobox.properties = {
442
+ label: {},
443
+ helpText: { attribute: 'help-text' },
444
+ error: { reflect: true },
445
+ name: { reflect: true },
446
+ value: {},
447
+ values: { type: Array },
448
+ placeholder: {},
449
+ options: { type: Array },
450
+ multiple: { type: Boolean, reflect: true },
451
+ allowCustom: { type: Boolean, attribute: 'allow-custom' },
452
+ filter: {},
453
+ loading: { type: Boolean, reflect: true },
454
+ emptyText: { attribute: 'empty-text', string: 'noResults' },
455
+ loadingText: { attribute: 'loading-text', string: 'loading' },
456
+ required: { type: Boolean, reflect: true },
457
+ disabled: { type: Boolean, reflect: true },
458
+ open: { type: Boolean, reflect: true },
459
+ _query: { state: true },
460
+ _active: { state: true },
461
+ _slotted: { state: true },
462
+ _typing: { state: true },
463
+ };
464
+ CmCombobox.styles = [
465
+ base,
466
+ css `
467
+ :host { display: block; position: relative; }
468
+ .field { display: flex; flex-direction: column; gap: var(--cm-space-10); }
469
+ .label { font-size: var(--cm-type-label-size); color: var(--cm-text-default); }
470
+ .req { color: var(--cm-text-critical); margin-inline-start: 2px; }
471
+ .wrap { position: relative; }
472
+ .box {
473
+ display: flex; flex-wrap: wrap; align-items: center; gap: 6px; width: 100%; min-height: 42px; padding: 7px var(--cm-space-10);
474
+ background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-input); border-radius: var(--cm-radius-sm); cursor: text;
475
+ }
476
+ .box:focus-within { border-color: var(--cm-border-strong); box-shadow: 0 0 0 1px var(--cm-border-strong); }
477
+ .tags { display: contents; }
478
+ input {
479
+ flex: 1 1 80px; min-width: 80px; height: 26px; padding: 0; border: 0; outline: none; background: none;
480
+ font: inherit; font-size: 16px; color: var(--cm-text-default);
481
+ }
482
+ input::placeholder { color: var(--cm-text-tertiary); }
483
+ .chev { flex: none; margin-inline-start: auto; color: var(--cm-icon-selected); transition: transform .15s; }
484
+ :host([open]) .chev { transform: rotate(180deg); }
485
+ :host([error]:not([error=''])) .box { border-color: var(--cm-border-critical); }
486
+ :host([disabled]) .box { background: var(--cm-bg-input-filled); border-color: var(--cm-border-default); cursor: not-allowed; }
487
+ :host([disabled]) input { color: var(--cm-text-secondary); cursor: not-allowed; }
488
+ .pop {
489
+ position: absolute; z-index: 20; inset-block-start: calc(100% + var(--cm-space-10)); inset-inline: 0;
490
+ background: var(--cm-bg-surface); border: var(--cm-border-1) solid var(--cm-border-default);
491
+ border-radius: var(--cm-radius-md); box-shadow: var(--cm-shadow-100); overflow: hidden;
492
+ }
493
+ .pop[hidden] { display: none; }
494
+ [role='listbox'] { max-height: 242px; overflow-y: auto; margin: 0; padding: var(--cm-space-10) 0; list-style: none; }
495
+ [role='listbox'][hidden] { display: none; }
496
+ [role='option'] {
497
+ display: flex; align-items: center; gap: var(--cm-space-10); min-height: 40px; padding: 6px var(--cm-space-20);
498
+ font-size: 16px; color: var(--cm-text-default); cursor: pointer;
499
+ }
500
+ [role='option'] .check { flex: none; visibility: hidden; }
501
+ [role='option'][aria-selected='true'] .check { visibility: visible; }
502
+ [role='option'].active { background: var(--cm-bg-hover); box-shadow: inset 2px 0 0 var(--cm-border-strong); }
503
+ [role='option'].active:dir(rtl) { box-shadow: inset -2px 0 0 var(--cm-border-strong); }
504
+ :host(:not([multiple])) [role='option'][aria-selected='true'] { background: var(--cm-action-primary); color: var(--cm-action-primary-text); }
505
+ :host(:not([multiple])) [role='option'][aria-selected='true'].active { background: var(--cm-action-primary-hover); }
506
+ [role='option'][aria-disabled='true'] { color: var(--cm-text-secondary); cursor: not-allowed; }
507
+ [role='option'] mark { background: none; color: inherit; font-weight: 600; }
508
+ .create { font-style: normal; }
509
+ .message { display: flex; align-items: center; gap: var(--cm-space-10); margin: 0; padding: var(--cm-space-15) var(--cm-space-20); font-size: 14px; color: var(--cm-text-tertiary); }
510
+ .vh {
511
+ position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
512
+ clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
513
+ }
514
+ .help, .error { margin: 0; font-size: 12px; color: var(--cm-text-tertiary); }
515
+ .error { color: var(--cm-text-critical); }
516
+ slot { display: none; }
517
+ @media (max-width: 640px) { [role='option'] { font-size: 14px; min-height: 30px; padding-inline: var(--cm-space-15); } }
518
+ @media (prefers-reduced-motion: reduce) { .chev { transition: none; } }
519
+ `,
520
+ ];
521
+ define('cm-combobox', CmCombobox);
@@ -1,12 +1,23 @@
1
- import { LitElement } from 'lit';
1
+ import { CmLocalizedElement } from '../localize.js';
2
2
  import './button.js';
3
+ declare const boxStrings: {
4
+ /** Section title, the text box's accessible name, and the post button. */
5
+ heading: string;
6
+ label: string;
7
+ action: string;
8
+ };
9
+ declare module '../localize.js' {
10
+ interface CmStrings {
11
+ commentBox: typeof boxStrings;
12
+ }
13
+ }
3
14
  /**
4
15
  * One entry in an order or customer timeline: when it was written, what it says and who wrote it.
5
16
  * Stack several inside any container, `space-10` apart; put a `cm-comment-box` above or below to add new ones.
6
17
  * @element cm-comment
7
18
  * @slot - The comment text.
8
19
  */
9
- export declare class CmComment extends LitElement {
20
+ export declare class CmComment extends CmLocalizedElement {
10
21
  #private;
11
22
  static properties: {
12
23
  author: {};
@@ -30,13 +41,19 @@ export declare class CmComment extends LitElement {
30
41
  * @slot - Existing `cm-comment` elements, shown as a list under the box.
31
42
  * @fires cm-submit - When Post is pressed with text; `detail.value` is the trimmed text. Cancelable: the default clears the box.
32
43
  */
33
- export declare class CmCommentBox extends LitElement {
44
+ export declare class CmCommentBox extends CmLocalizedElement {
34
45
  #private;
35
46
  static properties: {
36
- heading: {};
37
- label: {};
47
+ heading: {
48
+ string: string;
49
+ };
50
+ label: {
51
+ string: string;
52
+ };
38
53
  placeholder: {};
39
- action: {};
54
+ action: {
55
+ string: string;
56
+ };
40
57
  value: {};
41
58
  disabled: {
42
59
  type: BooleanConstructor;
@@ -47,13 +64,13 @@ export declare class CmCommentBox extends LitElement {
47
64
  attribute: string;
48
65
  };
49
66
  };
50
- /** Section title above the box. */
67
+ /** Section title above the box. Default: the built-in string `heading` ("Comments"). */
51
68
  heading: string;
52
- /** Accessible name of the text box. */
69
+ /** Accessible name of the text box. Default: the built-in string `label` ("Add a comment"). */
53
70
  label: string;
54
71
  /** Placeholder in the empty box. */
55
72
  placeholder: string;
56
- /** Text of the post button. */
73
+ /** Text of the post button. Default: the built-in string `action` ("Post comment"). */
57
74
  action: string;
58
75
  /** Current text in the box. */
59
76
  value: string;
@@ -74,3 +91,4 @@ declare global {
74
91
  'cm-comment-box': CmCommentBox;
75
92
  }
76
93
  }
94
+ export {};
@@ -4,16 +4,23 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _CmComment_instances, _CmComment_shown, _CmCommentBox_instances, _CmCommentBox_id, _CmCommentBox_key;
7
- import { LitElement, html, css, nothing } from 'lit';
7
+ import { html, css, nothing } from 'lit';
8
8
  import { base, define, nextId } from '../base.js';
9
+ import { CmLocalizedElement, defineStrings, formatDate } from '../localize.js';
9
10
  import './button.js';
11
+ const boxStrings = defineStrings('commentBox', {
12
+ /** Section title, the text box's accessible name, and the post button. */
13
+ heading: 'Comments',
14
+ label: 'Add a comment',
15
+ action: 'Post comment',
16
+ });
10
17
  /**
11
18
  * One entry in an order or customer timeline: when it was written, what it says and who wrote it.
12
19
  * Stack several inside any container, `space-10` apart; put a `cm-comment-box` above or below to add new ones.
13
20
  * @element cm-comment
14
21
  * @slot - The comment text.
15
22
  */
16
- export class CmComment extends LitElement {
23
+ export class CmComment extends CmLocalizedElement {
17
24
  constructor() {
18
25
  super(...arguments);
19
26
  _CmComment_instances.add(this);
@@ -47,7 +54,7 @@ _CmComment_instances = new WeakSet(), _CmComment_shown = function _CmComment_sho
47
54
  const d = new Date(this.datetime);
48
55
  if (Number.isNaN(d.getTime()))
49
56
  return this.datetime;
50
- return new Intl.DateTimeFormat(undefined, { dateStyle: 'medium', timeStyle: 'short' }).format(d);
57
+ return formatDate(d, { dateStyle: 'medium', timeStyle: 'short' }, this.locale);
51
58
  };
52
59
  CmComment.properties = {
53
60
  author: {},
@@ -74,18 +81,12 @@ define('cm-comment', CmComment);
74
81
  * @slot - Existing `cm-comment` elements, shown as a list under the box.
75
82
  * @fires cm-submit - When Post is pressed with text; `detail.value` is the trimmed text. Cancelable: the default clears the box.
76
83
  */
77
- export class CmCommentBox extends LitElement {
84
+ export class CmCommentBox extends CmLocalizedElement {
78
85
  constructor() {
79
86
  super(...arguments);
80
87
  _CmCommentBox_instances.add(this);
81
- /** Section title above the box. */
82
- this.heading = 'Comments';
83
- /** Accessible name of the text box. */
84
- this.label = 'Add a comment';
85
88
  /** Placeholder in the empty box. */
86
89
  this.placeholder = '';
87
- /** Text of the post button. */
88
- this.action = 'Post comment';
89
90
  /** Current text in the box. */
90
91
  this.value = '';
91
92
  /** Blocks typing and posting (for example while the comment saves). */
@@ -134,10 +135,10 @@ _CmCommentBox_id = new WeakMap(), _CmCommentBox_instances = new WeakSet(), _CmCo
134
135
  }
135
136
  };
136
137
  CmCommentBox.properties = {
137
- heading: {},
138
- label: {},
138
+ heading: { string: 'heading' },
139
+ label: { string: 'label' },
139
140
  placeholder: {},
140
- action: {},
141
+ action: { string: 'action' },
141
142
  value: {},
142
143
  disabled: { type: Boolean, reflect: true },
143
144
  headingLevel: { type: Number, attribute: 'heading-level' },