@commmerce/ui 1.13.0 → 1.14.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.
- package/dist/cdn.js +583 -573
- package/dist/components/checkbox.d.ts +3 -0
- package/dist/components/checkbox.js +18 -7
- package/dist/components/color-field.js +8 -4
- package/dist/components/combobox.js +12 -7
- package/dist/components/date-picker.js +17 -6
- package/dist/components/date-range-picker.js +12 -6
- package/dist/components/file-upload.js +12 -9
- package/dist/components/option-group.js +13 -5
- package/dist/components/radio.js +11 -7
- package/dist/components/select.js +12 -8
- package/dist/components/signature-field.js +9 -5
- package/dist/components/text-field.d.ts +35 -0
- package/dist/components/text-field.js +58 -8
- package/dist/custom-elements.json +183 -0
- package/dist/validation.d.ts +39 -0
- package/dist/validation.js +121 -0
- package/package.json +3 -3
|
@@ -64,7 +64,10 @@ export declare class CmCheckbox extends CmLocalizedElement {
|
|
|
64
64
|
static styles: import("lit").CSSResult[];
|
|
65
65
|
connectedCallback(): void;
|
|
66
66
|
get form(): HTMLFormElement | null;
|
|
67
|
+
get validity(): ValidityState;
|
|
68
|
+
get validationMessage(): string;
|
|
67
69
|
checkValidity(): boolean;
|
|
70
|
+
reportValidity(): boolean;
|
|
68
71
|
formResetCallback(): void;
|
|
69
72
|
formDisabledCallback(d: boolean): void;
|
|
70
73
|
updated(): void;
|
|
@@ -9,10 +9,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _CmCheckbox_instances, _CmCheckbox_internals, _CmCheckbox_id, _CmCheckbox_defaultChecked, _CmCheckbox_onChange;
|
|
12
|
+
var _CmCheckbox_instances, _CmCheckbox_internals, _CmCheckbox_v, _CmCheckbox_id, _CmCheckbox_defaultChecked, _CmCheckbox_onChange;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { base, define, nextId } from '../base.js';
|
|
15
15
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
16
|
+
import { FieldValidity } from '../validation.js';
|
|
16
17
|
const strings = defineStrings('checkbox', {
|
|
17
18
|
/** Validation message when `required` and not ticked. */
|
|
18
19
|
required: 'Please tick this box.',
|
|
@@ -44,6 +45,7 @@ export class CmCheckbox extends CmLocalizedElement {
|
|
|
44
45
|
/** Form will not submit until ticked. */
|
|
45
46
|
this.required = false;
|
|
46
47
|
_CmCheckbox_internals.set(this, this.attachInternals());
|
|
48
|
+
_CmCheckbox_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmCheckbox_internals, "f")));
|
|
47
49
|
_CmCheckbox_id.set(this, nextId('cm-cb'));
|
|
48
50
|
_CmCheckbox_defaultChecked.set(this, false);
|
|
49
51
|
}
|
|
@@ -52,8 +54,11 @@ export class CmCheckbox extends CmLocalizedElement {
|
|
|
52
54
|
__classPrivateFieldSet(this, _CmCheckbox_defaultChecked, this.checked, "f");
|
|
53
55
|
}
|
|
54
56
|
get form() { return __classPrivateFieldGet(this, _CmCheckbox_internals, "f").form; }
|
|
57
|
+
get validity() { return __classPrivateFieldGet(this, _CmCheckbox_internals, "f").validity; }
|
|
58
|
+
get validationMessage() { return __classPrivateFieldGet(this, _CmCheckbox_internals, "f").validationMessage; }
|
|
55
59
|
checkValidity() { return __classPrivateFieldGet(this, _CmCheckbox_internals, "f").checkValidity(); }
|
|
56
|
-
|
|
60
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmCheckbox_v, "f").report(() => __classPrivateFieldGet(this, _CmCheckbox_internals, "f").reportValidity()); }
|
|
61
|
+
formResetCallback() { this.checked = __classPrivateFieldGet(this, _CmCheckbox_defaultChecked, "f"); __classPrivateFieldGet(this, _CmCheckbox_v, "f").reset(); }
|
|
57
62
|
formDisabledCallback(d) { this.disabled = d; }
|
|
58
63
|
updated() {
|
|
59
64
|
__classPrivateFieldGet(this, _CmCheckbox_internals, "f").setFormValue(this.checked ? this.value : null);
|
|
@@ -61,23 +66,26 @@ export class CmCheckbox extends CmLocalizedElement {
|
|
|
61
66
|
__classPrivateFieldGet(this, _CmCheckbox_internals, "f").setValidity({ valueMissing: true }, this.t('required'));
|
|
62
67
|
else
|
|
63
68
|
__classPrivateFieldGet(this, _CmCheckbox_internals, "f").setValidity({});
|
|
69
|
+
__classPrivateFieldGet(this, _CmCheckbox_v, "f").sync();
|
|
64
70
|
}
|
|
65
71
|
render() {
|
|
66
72
|
const mark = this.indeterminate
|
|
67
73
|
? html `<svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true"><path d="M2 6h8" stroke="currentColor" stroke-width="2" stroke-linecap="round"/></svg>`
|
|
68
74
|
: html `<svg width="12" height="12" viewBox="0 0 12 12" aria-hidden="true"><path d="M2 6.2 4.8 9 10 3" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>`;
|
|
75
|
+
const message = __classPrivateFieldGet(this, _CmCheckbox_v, "f").message;
|
|
76
|
+
const described = [this.description && `${__classPrivateFieldGet(this, _CmCheckbox_id, "f")}-d`, message && `${__classPrivateFieldGet(this, _CmCheckbox_id, "f")}-err`].filter(Boolean).join(' ');
|
|
69
77
|
return html `<label for=${__classPrivateFieldGet(this, _CmCheckbox_id, "f")}>
|
|
70
78
|
<input type="checkbox" id=${__classPrivateFieldGet(this, _CmCheckbox_id, "f")} .checked=${this.checked} .indeterminate=${this.indeterminate}
|
|
71
|
-
?disabled=${this.disabled} ?required=${this.required}
|
|
72
|
-
aria-describedby=${
|
|
79
|
+
?disabled=${this.disabled} ?required=${this.required} aria-invalid=${message ? 'true' : nothing}
|
|
80
|
+
aria-describedby=${described || nothing} @change=${__classPrivateFieldGet(this, _CmCheckbox_instances, "m", _CmCheckbox_onChange)} />
|
|
73
81
|
<span class="box" part="box">${mark}</span>
|
|
74
82
|
${this.label || this.description
|
|
75
83
|
? html `<span class="text"><span class="label">${this.label}<slot></slot></span>${this.description ? html `<span class="desc" id="${__classPrivateFieldGet(this, _CmCheckbox_id, "f")}-d">${this.description}</span>` : nothing}</span>`
|
|
76
84
|
: html `<slot></slot>`}
|
|
77
|
-
</label
|
|
85
|
+
</label>${message ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmCheckbox_id, "f")}-err" role="alert">${message}</p>` : nothing}`;
|
|
78
86
|
}
|
|
79
87
|
}
|
|
80
|
-
_CmCheckbox_internals = new WeakMap(), _CmCheckbox_id = new WeakMap(), _CmCheckbox_defaultChecked = new WeakMap(), _CmCheckbox_instances = new WeakSet(), _CmCheckbox_onChange = function _CmCheckbox_onChange(e) {
|
|
88
|
+
_CmCheckbox_internals = new WeakMap(), _CmCheckbox_v = new WeakMap(), _CmCheckbox_id = new WeakMap(), _CmCheckbox_defaultChecked = new WeakMap(), _CmCheckbox_instances = new WeakSet(), _CmCheckbox_onChange = function _CmCheckbox_onChange(e) {
|
|
81
89
|
const input = e.target;
|
|
82
90
|
this.checked = input.checked;
|
|
83
91
|
this.indeterminate = false;
|
|
@@ -98,7 +106,7 @@ CmCheckbox.properties = {
|
|
|
98
106
|
CmCheckbox.styles = [
|
|
99
107
|
base,
|
|
100
108
|
css `
|
|
101
|
-
:host { display: inline-flex; }
|
|
109
|
+
:host { display: inline-flex; flex-direction: column; }
|
|
102
110
|
label { position: relative; display: inline-flex; align-items: flex-start; gap: var(--cm-space-8); padding-block: 2px; cursor: pointer; }
|
|
103
111
|
/* The 16px box (18px on touch screens, owner standard 1.6) sits centred on the label's first line (20px); the
|
|
104
112
|
invisible input around it is a 24px target. Without a label the element is 24px tall with the box in the middle,
|
|
@@ -120,6 +128,9 @@ CmCheckbox.styles = [
|
|
|
120
128
|
:host([disabled]) label { cursor: not-allowed; }
|
|
121
129
|
:host([disabled]) .box { background: var(--cm-bg-input-filled); border-color: var(--cm-border-subtle); }
|
|
122
130
|
:host([disabled]) .label { color: var(--cm-text-secondary); }
|
|
131
|
+
/* 1.14: the field's own message, under the label text (past the box and its gap). */
|
|
132
|
+
.error { margin: 0; padding-inline-start: var(--cm-space-24); font-size: var(--cm-type-body-xs-size); line-height: var(--cm-type-body-xs-line-height); color: var(--cm-text-critical); }
|
|
133
|
+
:host([data-cm-invalid]) .box, :host([data-cm-invalid]) label:hover input:not(:disabled) + .box { border-color: var(--cm-border-critical); }
|
|
123
134
|
`,
|
|
124
135
|
];
|
|
125
136
|
define('cm-checkbox', CmCheckbox);
|
|
@@ -9,12 +9,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _CmColorField_instances, _CmColorField_internals, _CmColorField_id, _CmColorField_defaultValue, _CmColorField_typed, _CmColorField_emit, _CmColorField_pick, _CmColorField_onSwatchKey, _CmColorField_onHexInput, _CmColorField_commitHex, _CmColorField_onHexChange, _CmColorField_onHexKey, _CmColorField_onPickerInput, _CmColorField_onPickerChange;
|
|
12
|
+
var _CmColorField_instances, _CmColorField_internals, _CmColorField_v, _CmColorField_id, _CmColorField_defaultValue, _CmColorField_typed, _CmColorField_emit, _CmColorField_pick, _CmColorField_onSwatchKey, _CmColorField_onHexInput, _CmColorField_commitHex, _CmColorField_onHexChange, _CmColorField_onHexKey, _CmColorField_onPickerInput, _CmColorField_onPickerChange;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { live } from 'lit/directives/live.js';
|
|
15
15
|
import { fieldStyles } from '../field.js';
|
|
16
16
|
import { base, define, nextId, logicalKey } from '../base.js';
|
|
17
17
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
18
|
+
import { FieldValidity } from '../validation.js';
|
|
18
19
|
import './icon.js';
|
|
19
20
|
const strings = defineStrings('colorField', {
|
|
20
21
|
/** Accessible name of each swatch with a name: "Blue, #2e6faf". */
|
|
@@ -123,6 +124,7 @@ export class CmColorField extends CmLocalizedElement {
|
|
|
123
124
|
/** The hex box holds text that isn't a colour (after it was committed). */
|
|
124
125
|
this._invalid = false;
|
|
125
126
|
_CmColorField_internals.set(this, this.attachInternals());
|
|
127
|
+
_CmColorField_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmColorField_internals, "f")));
|
|
126
128
|
_CmColorField_id.set(this, nextId('cm-cf'));
|
|
127
129
|
_CmColorField_defaultValue.set(this, '');
|
|
128
130
|
/** The value this element set itself from the hex box; any other new value replaces the box's text. */
|
|
@@ -136,8 +138,9 @@ export class CmColorField extends CmLocalizedElement {
|
|
|
136
138
|
get validity() { return __classPrivateFieldGet(this, _CmColorField_internals, "f").validity; }
|
|
137
139
|
get validationMessage() { return __classPrivateFieldGet(this, _CmColorField_internals, "f").validationMessage; }
|
|
138
140
|
checkValidity() { return __classPrivateFieldGet(this, _CmColorField_internals, "f").checkValidity(); }
|
|
139
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmColorField_internals, "f").reportValidity(); }
|
|
141
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmColorField_v, "f").report(() => __classPrivateFieldGet(this, _CmColorField_internals, "f").reportValidity()); }
|
|
140
142
|
formResetCallback() {
|
|
143
|
+
__classPrivateFieldGet(this, _CmColorField_v, "f").reset();
|
|
141
144
|
this.value = __classPrivateFieldGet(this, _CmColorField_defaultValue, "f");
|
|
142
145
|
this._draft = undefined;
|
|
143
146
|
this._invalid = false;
|
|
@@ -178,12 +181,13 @@ export class CmColorField extends CmLocalizedElement {
|
|
|
178
181
|
__classPrivateFieldGet(this, _CmColorField_internals, "f").setValidity({ valueMissing: true }, this.t('required'), anchor);
|
|
179
182
|
else
|
|
180
183
|
__classPrivateFieldGet(this, _CmColorField_internals, "f").setValidity({});
|
|
184
|
+
__classPrivateFieldGet(this, _CmColorField_v, "f").sync();
|
|
181
185
|
}
|
|
182
186
|
render() {
|
|
183
187
|
const items = this.items;
|
|
184
188
|
const current = normalizeHex(this.value ?? '');
|
|
185
189
|
const sel = items.findIndex((s) => s.value === current);
|
|
186
|
-
const message = this.error || (this._invalid || (this.value && !current) ? this.t('invalid') : '');
|
|
190
|
+
const message = this.error || (this._invalid || (this.value && !current) ? this.t('invalid') : '') || __classPrivateFieldGet(this, _CmColorField_v, "f").message;
|
|
187
191
|
const describedBy = [message && `${__classPrivateFieldGet(this, _CmColorField_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmColorField_id, "f")}-help`].filter(Boolean).join(' ') || nothing;
|
|
188
192
|
const hostLabel = this.getAttribute('aria-label');
|
|
189
193
|
const named = this.label || hostLabel || '';
|
|
@@ -225,7 +229,7 @@ export class CmColorField extends CmLocalizedElement {
|
|
|
225
229
|
</div>`;
|
|
226
230
|
}
|
|
227
231
|
}
|
|
228
|
-
_CmColorField_internals = new WeakMap(), _CmColorField_id = new WeakMap(), _CmColorField_defaultValue = new WeakMap(), _CmColorField_typed = new WeakMap(), _CmColorField_instances = new WeakSet(), _CmColorField_emit = function _CmColorField_emit(...types) {
|
|
232
|
+
_CmColorField_internals = new WeakMap(), _CmColorField_v = new WeakMap(), _CmColorField_id = new WeakMap(), _CmColorField_defaultValue = new WeakMap(), _CmColorField_typed = new WeakMap(), _CmColorField_instances = new WeakSet(), _CmColorField_emit = function _CmColorField_emit(...types) {
|
|
229
233
|
for (const type of types)
|
|
230
234
|
this.dispatchEvent(new Event(type, { bubbles: true, composed: true }));
|
|
231
235
|
}, _CmColorField_pick = function _CmColorField_pick(i) {
|
|
@@ -9,12 +9,13 @@ 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_groups, _CmCombobox_observer, _CmCombobox_stopOutside, _CmCombobox_readChildren, _CmCombobox_labelOf, _CmCombobox_displayOf, _CmCombobox_createText_get, _CmCombobox_rows, _CmCombobox_layer, _CmCombobox_emit, _CmCombobox_show, _CmCombobox_hide, _CmCombobox_enabled, _CmCombobox_move, _CmCombobox_choose, _CmCombobox_create, _CmCombobox_focusInput, _CmCombobox_onFocusIn, _CmCombobox_onFocusOut, _CmCombobox_focusTag, _CmCombobox_onTagKey, _CmCombobox_onInput, _CmCombobox_onKeyDown, _CmCombobox_onBlur, _CmCombobox_highlight, _CmCombobox_tags;
|
|
12
|
+
var _CmCombobox_instances, _CmCombobox_internals, _CmCombobox_v, _CmCombobox_id, _CmCombobox_default, _CmCombobox_labels, _CmCombobox_groups, _CmCombobox_observer, _CmCombobox_stopOutside, _CmCombobox_readChildren, _CmCombobox_labelOf, _CmCombobox_displayOf, _CmCombobox_createText_get, _CmCombobox_rows, _CmCombobox_layer, _CmCombobox_emit, _CmCombobox_show, _CmCombobox_hide, _CmCombobox_enabled, _CmCombobox_move, _CmCombobox_choose, _CmCombobox_create, _CmCombobox_focusInput, _CmCombobox_onFocusIn, _CmCombobox_onFocusOut, _CmCombobox_focusTag, _CmCombobox_onTagKey, _CmCombobox_onInput, _CmCombobox_onKeyDown, _CmCombobox_onBlur, _CmCombobox_highlight, _CmCombobox_tags;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { live } from 'lit/directives/live.js';
|
|
15
15
|
import { fieldStyles, optionStyles } from '../field.js';
|
|
16
16
|
import { base, define, nextId, logicalKey } from '../base.js';
|
|
17
17
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
18
|
+
import { FieldValidity } from '../validation.js';
|
|
18
19
|
import { popoverStyles, groupStyles, sortByGroup, groupRuns, closeOnOutsidePointer } from '../popover.js';
|
|
19
20
|
import { TopLayer, topLayerStyles } from '../top-layer.js';
|
|
20
21
|
import './icon.js';
|
|
@@ -121,6 +122,7 @@ export class CmCombobox extends CmLocalizedElement {
|
|
|
121
122
|
/** True while the text box holds the merchant's own query rather than the chosen option's label. */
|
|
122
123
|
this._typing = false;
|
|
123
124
|
_CmCombobox_internals.set(this, this.attachInternals());
|
|
125
|
+
_CmCombobox_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmCombobox_internals, "f")));
|
|
124
126
|
_CmCombobox_id.set(this, nextId('cm-cb'));
|
|
125
127
|
_CmCombobox_default.set(this, null);
|
|
126
128
|
/** Labels for chosen values, so tags keep their text when async options change. */
|
|
@@ -246,7 +248,7 @@ export class CmCombobox extends CmLocalizedElement {
|
|
|
246
248
|
get validity() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").validity; }
|
|
247
249
|
get validationMessage() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").validationMessage; }
|
|
248
250
|
checkValidity() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").checkValidity(); }
|
|
249
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmCombobox_internals, "f").reportValidity(); }
|
|
251
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmCombobox_v, "f").report(() => __classPrivateFieldGet(this, _CmCombobox_internals, "f").reportValidity()); }
|
|
250
252
|
formResetCallback() {
|
|
251
253
|
const d = __classPrivateFieldGet(this, _CmCombobox_default, "f") ?? { value: '', values: [] };
|
|
252
254
|
this.value = d.value;
|
|
@@ -254,6 +256,7 @@ export class CmCombobox extends CmLocalizedElement {
|
|
|
254
256
|
this._query = '';
|
|
255
257
|
this._typing = false;
|
|
256
258
|
this.open = false;
|
|
259
|
+
__classPrivateFieldGet(this, _CmCombobox_v, "f").reset();
|
|
257
260
|
}
|
|
258
261
|
formDisabledCallback(d) { this.disabled = d; if (d)
|
|
259
262
|
this.open = false; }
|
|
@@ -328,6 +331,7 @@ export class CmCombobox extends CmLocalizedElement {
|
|
|
328
331
|
__classPrivateFieldGet(this, _CmCombobox_internals, "f").setValidity({ valueMissing: true }, this.t(this.multiple ? 'requiredMultiple' : 'required'), input);
|
|
329
332
|
else
|
|
330
333
|
__classPrivateFieldGet(this, _CmCombobox_internals, "f").setValidity({});
|
|
334
|
+
__classPrivateFieldGet(this, _CmCombobox_v, "f").sync();
|
|
331
335
|
if ((changed.has('_active') || changed.has('open')) && this.open && this._active >= 0) {
|
|
332
336
|
this.renderRoot.querySelector(`#${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-o${this._active}`)?.scrollIntoView({ block: 'nearest' });
|
|
333
337
|
}
|
|
@@ -343,7 +347,8 @@ export class CmCombobox extends CmLocalizedElement {
|
|
|
343
347
|
focus(options) { this.renderRoot.querySelector('input')?.focus(options); }
|
|
344
348
|
render() {
|
|
345
349
|
const rows = __classPrivateFieldGet(this, _CmCombobox_instances, "m", _CmCombobox_rows).call(this);
|
|
346
|
-
const
|
|
350
|
+
const message = __classPrivateFieldGet(this, _CmCombobox_v, "f").message;
|
|
351
|
+
const described = [message && `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-help`].filter(Boolean).join(' ');
|
|
347
352
|
const hostLabel = this.getAttribute('aria-label');
|
|
348
353
|
const selected = (v) => (this.multiple ? this.values.includes(v) : v === this.value);
|
|
349
354
|
const option = (o, i) => html `<li role="option" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-o${i}" class=${i === this._active ? 'active' : ''}
|
|
@@ -370,7 +375,7 @@ export class CmCombobox extends CmLocalizedElement {
|
|
|
370
375
|
aria-label=${!this.label && hostLabel ? hostLabel : nothing}
|
|
371
376
|
aria-autocomplete="list" aria-expanded=${this.open ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-list"
|
|
372
377
|
aria-activedescendant=${this.open && this._active >= 0 ? `${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-o${this._active}` : nothing}
|
|
373
|
-
aria-invalid=${
|
|
378
|
+
aria-invalid=${message ? 'true' : nothing} aria-describedby=${described || nothing}
|
|
374
379
|
aria-required=${this.required ? 'true' : nothing} ?disabled=${this.disabled}
|
|
375
380
|
@input=${__classPrivateFieldGet(this, _CmCombobox_onInput, "f")} @keydown=${__classPrivateFieldGet(this, _CmCombobox_onKeyDown, "f")} @blur=${__classPrivateFieldGet(this, _CmCombobox_onBlur, "f")}
|
|
376
381
|
@click=${() => { if (!this.open)
|
|
@@ -398,13 +403,13 @@ export class CmCombobox extends CmLocalizedElement {
|
|
|
398
403
|
</div>
|
|
399
404
|
</div>
|
|
400
405
|
<span class="vh" role="status" aria-live="polite">${status}</span>
|
|
401
|
-
${
|
|
406
|
+
${message ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-err" role="alert">${message}</p>` : nothing}
|
|
402
407
|
${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmCombobox_id, "f")}-help">${this.helpText}</p>` : nothing}
|
|
403
408
|
<slot></slot>
|
|
404
409
|
</div>`;
|
|
405
410
|
}
|
|
406
411
|
}
|
|
407
|
-
_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_layer = new WeakMap(), _CmCombobox_onFocusIn = new WeakMap(), _CmCombobox_onFocusOut = new WeakMap(), _CmCombobox_onInput = new WeakMap(), _CmCombobox_onKeyDown = new WeakMap(), _CmCombobox_onBlur = new WeakMap(), _CmCombobox_instances = new WeakSet(), _CmCombobox_readChildren = function _CmCombobox_readChildren() {
|
|
412
|
+
_CmCombobox_internals = new WeakMap(), _CmCombobox_v = 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_layer = new WeakMap(), _CmCombobox_onFocusIn = new WeakMap(), _CmCombobox_onFocusOut = new WeakMap(), _CmCombobox_onInput = new WeakMap(), _CmCombobox_onKeyDown = new WeakMap(), _CmCombobox_onBlur = new WeakMap(), _CmCombobox_instances = new WeakSet(), _CmCombobox_readChildren = function _CmCombobox_readChildren() {
|
|
408
413
|
const opts = [...this.querySelectorAll('option')];
|
|
409
414
|
this._slotted = opts.map((o) => {
|
|
410
415
|
const g = o.parentElement?.localName === 'optgroup' ? o.parentElement : null;
|
|
@@ -627,7 +632,7 @@ CmCombobox.styles = [
|
|
|
627
632
|
input::placeholder { color: var(--cm-text-tertiary); }
|
|
628
633
|
.chev { flex: none; color: var(--cm-icon-selected); transition: transform var(--cm-duration-fast) var(--cm-easing-standard); }
|
|
629
634
|
:host([open]) .chev { transform: rotate(180deg); }
|
|
630
|
-
:host([error]:not([error=''])) .box { border-color: var(--cm-border-critical); }
|
|
635
|
+
:host([error]:not([error=''])) .box, :host([data-cm-invalid]) .box { border-color: var(--cm-border-critical); }
|
|
631
636
|
:host([disabled]) .box { background: var(--cm-bg-input-filled); border-color: var(--cm-border-subtle); cursor: not-allowed; }
|
|
632
637
|
:host([disabled]) input { color: var(--cm-text-secondary); cursor: not-allowed; }
|
|
633
638
|
[role='listbox'][hidden] { display: none; }
|
|
@@ -9,11 +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 _CmDatePicker_instances, _CmDatePicker_localeProp, _CmDatePicker_internals, _CmDatePicker_id, _CmDatePicker_defaultValue, _CmDatePicker_keepText, _CmDatePicker_focusGrid, _CmDatePicker_date, _CmDatePicker_time, _CmDatePicker_keepTime, _CmDatePicker_timeTextValue, _CmDatePicker_timeText_get, _CmDatePicker_timeText_set, _CmDatePicker_ownValue, _CmDatePicker_locale_get, _CmDatePicker_fmt_get, _CmDatePicker_tf_get, _CmDatePicker_dateValue_get, _CmDatePicker_limit, _CmDatePicker_minDate_get, _CmDatePicker_maxDate_get, _CmDatePicker_step_get, _CmDatePicker_firstDay_get, _CmDatePicker_pattern_get, _CmDatePicker_format, _CmDatePicker_formatTime, _CmDatePicker_timePattern_get, _CmDatePicker_split, _CmDatePicker_prepareFocus, _CmDatePicker_validate, _CmDatePicker_validateTime, _CmDatePicker_layer, _CmDatePicker_selfSet, _CmDatePicker_setValue, _CmDatePicker_setParts, _CmDatePicker_setDate, _CmDatePicker_commitText, _CmDatePicker_commitTime, _CmDatePicker_stepTime, _CmDatePicker_onTimeKey, _CmDatePicker_pick, _CmDatePicker_focusTrigger, _CmDatePicker_toggle, _CmDatePicker_onInputKey, _CmDatePicker_onGridKey, _CmDatePicker_onPopKey, _CmDatePicker_onMonth, _CmDatePicker_onOutside;
|
|
12
|
+
var _CmDatePicker_instances, _CmDatePicker_localeProp, _CmDatePicker_internals, _CmDatePicker_v, _CmDatePicker_id, _CmDatePicker_defaultValue, _CmDatePicker_keepText, _CmDatePicker_focusGrid, _CmDatePicker_date, _CmDatePicker_time, _CmDatePicker_keepTime, _CmDatePicker_timeTextValue, _CmDatePicker_timeText_get, _CmDatePicker_timeText_set, _CmDatePicker_ownValue, _CmDatePicker_locale_get, _CmDatePicker_fmt_get, _CmDatePicker_tf_get, _CmDatePicker_dateValue_get, _CmDatePicker_limit, _CmDatePicker_minDate_get, _CmDatePicker_maxDate_get, _CmDatePicker_step_get, _CmDatePicker_firstDay_get, _CmDatePicker_pattern_get, _CmDatePicker_format, _CmDatePicker_formatTime, _CmDatePicker_timePattern_get, _CmDatePicker_split, _CmDatePicker_prepareFocus, _CmDatePicker_validate, _CmDatePicker_setValidity, _CmDatePicker_validateTime, _CmDatePicker_layer, _CmDatePicker_selfSet, _CmDatePicker_setValue, _CmDatePicker_setParts, _CmDatePicker_setDate, _CmDatePicker_commitText, _CmDatePicker_commitTime, _CmDatePicker_stepTime, _CmDatePicker_onTimeKey, _CmDatePicker_pick, _CmDatePicker_focusTrigger, _CmDatePicker_toggle, _CmDatePicker_onInputKey, _CmDatePicker_onGridKey, _CmDatePicker_onPopKey, _CmDatePicker_onMonth, _CmDatePicker_onOutside;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { live } from 'lit/directives/live.js';
|
|
15
15
|
import { base, define, nextId, logicalKey } from '../base.js';
|
|
16
16
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
17
|
+
import { FieldValidity } from '../validation.js';
|
|
17
18
|
import { TopLayer, topLayerStyles } from '../top-layer.js';
|
|
18
19
|
import { fromISO, toISO, addMonths, startOfMonth, clamp, trapTab, dateFieldStyles, gridKey, renderGrid, calendarStyles, dateFormat, parseDate, resolveLocale, localeFirstDay, listConverter, asList, datePattern, splitDateTime, fromISODateTime, timeToMinutes, minutesToTime, nowISO, timeFormat, timePattern, parseTime, } from '../calendar.js';
|
|
19
20
|
import './icon.js';
|
|
@@ -125,6 +126,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
125
126
|
this._timeError = '';
|
|
126
127
|
this._focus = new Date();
|
|
127
128
|
_CmDatePicker_internals.set(this, this.attachInternals());
|
|
129
|
+
_CmDatePicker_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmDatePicker_internals, "f")));
|
|
128
130
|
_CmDatePicker_id.set(this, nextId('cm-dp'));
|
|
129
131
|
_CmDatePicker_defaultValue.set(this, null);
|
|
130
132
|
_CmDatePicker_keepText.set(this, false);
|
|
@@ -224,8 +226,10 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
224
226
|
/** The value as a local Date (with `time`, at that time), or null. */
|
|
225
227
|
get valueAsDate() { return this.time ? (this.value ? fromISODateTime(this.value) : null) : fromISO(this.value); }
|
|
226
228
|
checkValidity() { __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_validate).call(this); return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").checkValidity(); }
|
|
227
|
-
reportValidity() { __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_validate).call(this); return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").reportValidity(); }
|
|
229
|
+
reportValidity() { __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_validate).call(this); return __classPrivateFieldGet(this, _CmDatePicker_v, "f").report(() => __classPrivateFieldGet(this, _CmDatePicker_internals, "f").reportValidity()); }
|
|
228
230
|
formResetCallback() {
|
|
231
|
+
__classPrivateFieldGet(this, _CmDatePicker_v, "f").reset();
|
|
232
|
+
this._dateError = this._timeError = '';
|
|
229
233
|
this.value = __classPrivateFieldGet(this, _CmDatePicker_defaultValue, "f") ?? '';
|
|
230
234
|
if (this.time) {
|
|
231
235
|
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_split).call(this, this.value);
|
|
@@ -293,7 +297,11 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
293
297
|
render() {
|
|
294
298
|
const fmt = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get);
|
|
295
299
|
const value = fromISO(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get));
|
|
296
|
-
|
|
300
|
+
// The typed-text messages (1.13) name the box; otherwise the field's own message once shown (1.14) marks both.
|
|
301
|
+
const typed = [this._dateError, this._timeError].filter(Boolean).join(' ');
|
|
302
|
+
const shown = __classPrivateFieldGet(this, _CmDatePicker_v, "f").message;
|
|
303
|
+
const err = this.error || typed || shown;
|
|
304
|
+
const all = !this.error && !typed && !!shown;
|
|
297
305
|
const described = [err && `${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-help`].filter(Boolean).join(' ');
|
|
298
306
|
const hostLabel = this.getAttribute('aria-label');
|
|
299
307
|
const name = this.label || hostLabel || '';
|
|
@@ -303,7 +311,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
303
311
|
? html `<label class="label" for="${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-in" part="label">${this.label}${this.required ? html `<span class="req" aria-hidden="true">*</span>` : nothing}</label>`
|
|
304
312
|
: nothing}
|
|
305
313
|
<div class="wrap ${this.time ? 'timed' : ''}">
|
|
306
|
-
<div class="box ${this._dateError && !this.error ? 'invalid' : ''}" part="box">
|
|
314
|
+
<div class="box ${(this._dateError && !this.error) || all ? 'invalid' : ''}" part="box">
|
|
307
315
|
<input id="${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-in" part="input" type="text" autocomplete="off" spellcheck="false"
|
|
308
316
|
.value=${live(this._text)} placeholder=${this.placeholder || __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_pattern_get)}
|
|
309
317
|
aria-label=${!this.label && hostLabel ? hostLabel : nothing}
|
|
@@ -316,7 +324,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
316
324
|
aria-haspopup="dialog" aria-expanded=${this.open ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-pop"
|
|
317
325
|
@click=${__classPrivateFieldGet(this, _CmDatePicker_toggle, "f")}><cm-icon name="calendar" size="16"></cm-icon></button>
|
|
318
326
|
</div>
|
|
319
|
-
${this.time ? html `<div class="box time ${this._timeError && !this.error ? 'invalid' : ''}" part="time-box">
|
|
327
|
+
${this.time ? html `<div class="box time ${(this._timeError && !this.error) || all ? 'invalid' : ''}" part="time-box">
|
|
320
328
|
<input class="time-in" part="time-input" type="text" autocomplete="off" spellcheck="false"
|
|
321
329
|
.value=${live(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_timeText_get))} placeholder=${__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_timePattern_get)}
|
|
322
330
|
aria-label=${this.t(name ? 'timeFor' : 'time', { label: name })}
|
|
@@ -342,7 +350,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
342
350
|
</div>`;
|
|
343
351
|
}
|
|
344
352
|
}
|
|
345
|
-
_CmDatePicker_localeProp = new WeakMap(), _CmDatePicker_internals = new WeakMap(), _CmDatePicker_id = new WeakMap(), _CmDatePicker_defaultValue = new WeakMap(), _CmDatePicker_keepText = new WeakMap(), _CmDatePicker_focusGrid = new WeakMap(), _CmDatePicker_date = new WeakMap(), _CmDatePicker_time = new WeakMap(), _CmDatePicker_keepTime = new WeakMap(), _CmDatePicker_timeTextValue = new WeakMap(), _CmDatePicker_ownValue = new WeakMap(), _CmDatePicker_layer = new WeakMap(), _CmDatePicker_selfSet = new WeakMap(), _CmDatePicker_onTimeKey = new WeakMap(), _CmDatePicker_toggle = new WeakMap(), _CmDatePicker_onInputKey = new WeakMap(), _CmDatePicker_onGridKey = new WeakMap(), _CmDatePicker_onPopKey = new WeakMap(), _CmDatePicker_onMonth = new WeakMap(), _CmDatePicker_onOutside = new WeakMap(), _CmDatePicker_instances = new WeakSet(), _CmDatePicker_timeText_get = function _CmDatePicker_timeText_get() { return __classPrivateFieldGet(this, _CmDatePicker_timeTextValue, "f"); }, _CmDatePicker_timeText_set = function _CmDatePicker_timeText_set(v) { if (v !== __classPrivateFieldGet(this, _CmDatePicker_timeTextValue, "f")) {
|
|
353
|
+
_CmDatePicker_localeProp = new WeakMap(), _CmDatePicker_internals = new WeakMap(), _CmDatePicker_v = new WeakMap(), _CmDatePicker_id = new WeakMap(), _CmDatePicker_defaultValue = new WeakMap(), _CmDatePicker_keepText = new WeakMap(), _CmDatePicker_focusGrid = new WeakMap(), _CmDatePicker_date = new WeakMap(), _CmDatePicker_time = new WeakMap(), _CmDatePicker_keepTime = new WeakMap(), _CmDatePicker_timeTextValue = new WeakMap(), _CmDatePicker_ownValue = new WeakMap(), _CmDatePicker_layer = new WeakMap(), _CmDatePicker_selfSet = new WeakMap(), _CmDatePicker_onTimeKey = new WeakMap(), _CmDatePicker_toggle = new WeakMap(), _CmDatePicker_onInputKey = new WeakMap(), _CmDatePicker_onGridKey = new WeakMap(), _CmDatePicker_onPopKey = new WeakMap(), _CmDatePicker_onMonth = new WeakMap(), _CmDatePicker_onOutside = new WeakMap(), _CmDatePicker_instances = new WeakSet(), _CmDatePicker_timeText_get = function _CmDatePicker_timeText_get() { return __classPrivateFieldGet(this, _CmDatePicker_timeTextValue, "f"); }, _CmDatePicker_timeText_set = function _CmDatePicker_timeText_set(v) { if (v !== __classPrivateFieldGet(this, _CmDatePicker_timeTextValue, "f")) {
|
|
346
354
|
__classPrivateFieldSet(this, _CmDatePicker_timeTextValue, v, "f");
|
|
347
355
|
this.requestUpdate();
|
|
348
356
|
} }, _CmDatePicker_locale_get = function _CmDatePicker_locale_get() { return resolveLocale(this, this.locale); }, _CmDatePicker_fmt_get = function _CmDatePicker_fmt_get() { return dateFormat(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_locale_get)); }, _CmDatePicker_tf_get = function _CmDatePicker_tf_get() { return timeFormat(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_locale_get), this.hourCycle); }, _CmDatePicker_dateValue_get = function _CmDatePicker_dateValue_get() { return this.time ? __classPrivateFieldGet(this, _CmDatePicker_date, "f") : this.value; }, _CmDatePicker_limit = function _CmDatePicker_limit(v) { return this.time && v.trim().toLowerCase() === 'now' ? nowISO() : v; }, _CmDatePicker_minDate_get = function _CmDatePicker_minDate_get() { return fromISO(splitDateTime(__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_limit).call(this, this.min)).date || this.min); }, _CmDatePicker_maxDate_get = function _CmDatePicker_maxDate_get() { return fromISO(splitDateTime(__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_limit).call(this, this.max)).date || this.max); }, _CmDatePicker_step_get = function _CmDatePicker_step_get() { const n = Math.trunc(Number(this.step)); return n >= 1 && n <= 1440 ? n : 1; }, _CmDatePicker_firstDay_get = function _CmDatePicker_firstDay_get() {
|
|
@@ -364,6 +372,9 @@ _CmDatePicker_localeProp = new WeakMap(), _CmDatePicker_internals = new WeakMap(
|
|
|
364
372
|
this._focus = clamp(start, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get), __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get));
|
|
365
373
|
__classPrivateFieldSet(this, _CmDatePicker_focusGrid, true, "f");
|
|
366
374
|
}, _CmDatePicker_validate = function _CmDatePicker_validate() {
|
|
375
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setValidity).call(this);
|
|
376
|
+
__classPrivateFieldGet(this, _CmDatePicker_v, "f").sync();
|
|
377
|
+
}, _CmDatePicker_setValidity = function _CmDatePicker_setValidity() {
|
|
367
378
|
const input = this.renderRoot.querySelector('input') ?? undefined;
|
|
368
379
|
const d = fromISO(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get));
|
|
369
380
|
const fmt = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get);
|
|
@@ -9,11 +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 _CmDateRangePicker_instances, _CmDateRangePicker_localeProp, _CmDateRangePicker_internals, _CmDateRangePicker_id, _CmDateRangePicker_default, _CmDateRangePicker_keepText, _CmDateRangePicker_focusGrid, _CmDateRangePicker_locale_get, _CmDateRangePicker_fmt_get, _CmDateRangePicker_firstDay_get, _CmDateRangePicker_picking, _CmDateRangePicker_pattern_get, _CmDateRangePicker_format, _CmDateRangePicker_layer, _CmDateRangePicker_emit, _CmDateRangePicker_setRange, _CmDateRangePicker_commitText, _CmDateRangePicker_pick, _CmDateRangePicker_applyPreset, _CmDateRangePicker_focusTrigger, _CmDateRangePicker_toggle, _CmDateRangePicker_onInputKey, _CmDateRangePicker_onGridKey, _CmDateRangePicker_onPopKey, _CmDateRangePicker_onOutside, _CmDateRangePicker_mark;
|
|
12
|
+
var _CmDateRangePicker_instances, _CmDateRangePicker_localeProp, _CmDateRangePicker_internals, _CmDateRangePicker_v, _CmDateRangePicker_id, _CmDateRangePicker_default, _CmDateRangePicker_keepText, _CmDateRangePicker_focusGrid, _CmDateRangePicker_locale_get, _CmDateRangePicker_fmt_get, _CmDateRangePicker_firstDay_get, _CmDateRangePicker_picking, _CmDateRangePicker_pattern_get, _CmDateRangePicker_format, _CmDateRangePicker_layer, _CmDateRangePicker_emit, _CmDateRangePicker_setRange, _CmDateRangePicker_commitText, _CmDateRangePicker_pick, _CmDateRangePicker_applyPreset, _CmDateRangePicker_focusTrigger, _CmDateRangePicker_toggle, _CmDateRangePicker_onInputKey, _CmDateRangePicker_onGridKey, _CmDateRangePicker_onPopKey, _CmDateRangePicker_onOutside, _CmDateRangePicker_mark;
|
|
13
13
|
import { LitElement, html, css, nothing } from 'lit';
|
|
14
14
|
import { live } from 'lit/directives/live.js';
|
|
15
15
|
import { base, define, nextId, logicalKey } from '../base.js';
|
|
16
16
|
import { CmLocalizedElement, defineStrings } from '../localize.js';
|
|
17
|
+
import { FieldValidity } from '../validation.js';
|
|
17
18
|
import { TopLayer, topLayerStyles } from '../top-layer.js';
|
|
18
19
|
import { fromISO, toISO, addDays, addMonths, startOfMonth, endOfMonth, clamp, gridKey, renderGrid, calendarStyles, dateFormat, parseDate, resolveLocale, localeFirstDay, listConverter, asList, trapTab, dateFieldStyles, datePattern, } from '../calendar.js';
|
|
19
20
|
import './icon.js';
|
|
@@ -141,6 +142,7 @@ export class CmDateRangePicker extends CmLocalizedElement {
|
|
|
141
142
|
this._draftEnd = '';
|
|
142
143
|
this._hover = null;
|
|
143
144
|
_CmDateRangePicker_internals.set(this, this.attachInternals());
|
|
145
|
+
_CmDateRangePicker_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f")));
|
|
144
146
|
_CmDateRangePicker_id.set(this, nextId('cm-drp'));
|
|
145
147
|
_CmDateRangePicker_default.set(this, null);
|
|
146
148
|
_CmDateRangePicker_keepText.set(this, false);
|
|
@@ -220,12 +222,13 @@ export class CmDateRangePicker extends CmLocalizedElement {
|
|
|
220
222
|
get validity() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").validity; }
|
|
221
223
|
get validationMessage() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").validationMessage; }
|
|
222
224
|
checkValidity() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").checkValidity(); }
|
|
223
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").reportValidity(); }
|
|
225
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmDateRangePicker_v, "f").report(() => __classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").reportValidity()); }
|
|
224
226
|
formResetCallback() {
|
|
225
227
|
[this.start, this.end] = __classPrivateFieldGet(this, _CmDateRangePicker_default, "f") ?? ['', ''];
|
|
226
228
|
this._startText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, this.start);
|
|
227
229
|
this._endText = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "m", _CmDateRangePicker_format).call(this, this.end);
|
|
228
230
|
this.open = false;
|
|
231
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_v, "f").reset();
|
|
229
232
|
}
|
|
230
233
|
formDisabledCallback(d) { this.disabled = d; if (d)
|
|
231
234
|
this.open = false; }
|
|
@@ -311,6 +314,7 @@ export class CmDateRangePicker extends CmLocalizedElement {
|
|
|
311
314
|
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({ customError: true }, this.t('unavailable'), inS);
|
|
312
315
|
else
|
|
313
316
|
__classPrivateFieldGet(this, _CmDateRangePicker_internals, "f").setValidity({});
|
|
317
|
+
__classPrivateFieldGet(this, _CmDateRangePicker_v, "f").sync();
|
|
314
318
|
if (this.open && __classPrivateFieldGet(this, _CmDateRangePicker_focusGrid, "f")) {
|
|
315
319
|
__classPrivateFieldSet(this, _CmDateRangePicker_focusGrid, false, "f");
|
|
316
320
|
this.renderRoot.querySelector('td[tabindex="0"]')?.focus();
|
|
@@ -319,7 +323,8 @@ export class CmDateRangePicker extends CmLocalizedElement {
|
|
|
319
323
|
render() {
|
|
320
324
|
const fmt = __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_fmt_get);
|
|
321
325
|
const s = fromISO(this.start), e = fromISO(this.end);
|
|
322
|
-
const
|
|
326
|
+
const message = __classPrivateFieldGet(this, _CmDateRangePicker_v, "f").message;
|
|
327
|
+
const described = [message && `${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-help`].filter(Boolean).join(' ');
|
|
323
328
|
const hostLabel = this.getAttribute('aria-label');
|
|
324
329
|
const name = this.label || hostLabel || '';
|
|
325
330
|
const presets = asList(this.presets).map((p) => resolvePreset(p, new Date(), (k) => this.t(k))).filter((p) => !!p);
|
|
@@ -332,7 +337,7 @@ export class CmDateRangePicker extends CmLocalizedElement {
|
|
|
332
337
|
.value=${live(text)} placeholder=${__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_pattern_get)}
|
|
333
338
|
aria-label=${which === 'start' ? this.startLabel || this.t('start') : this.endLabel || this.t('end')}
|
|
334
339
|
?required=${this.required} ?disabled=${this.disabled}
|
|
335
|
-
aria-invalid=${
|
|
340
|
+
aria-invalid=${message ? 'true' : nothing} aria-describedby=${described || nothing}
|
|
336
341
|
@input=${(ev) => { ev.stopPropagation(); const v = ev.target.value; if (which === 'start')
|
|
337
342
|
this._startText = v;
|
|
338
343
|
else
|
|
@@ -374,12 +379,12 @@ export class CmDateRangePicker extends CmLocalizedElement {
|
|
|
374
379
|
</div>` : nothing}
|
|
375
380
|
</div>
|
|
376
381
|
</div>
|
|
377
|
-
${
|
|
382
|
+
${message ? html `<p class="error" id="${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-err" role="alert">${message}</p>` : nothing}
|
|
378
383
|
${this.helpText ? html `<p class="help" id="${__classPrivateFieldGet(this, _CmDateRangePicker_id, "f")}-help">${this.helpText}</p>` : nothing}
|
|
379
384
|
</div>`;
|
|
380
385
|
}
|
|
381
386
|
}
|
|
382
|
-
_CmDateRangePicker_localeProp = new WeakMap(), _CmDateRangePicker_internals = new WeakMap(), _CmDateRangePicker_id = new WeakMap(), _CmDateRangePicker_default = new WeakMap(), _CmDateRangePicker_keepText = new WeakMap(), _CmDateRangePicker_focusGrid = new WeakMap(), _CmDateRangePicker_picking = new WeakMap(), _CmDateRangePicker_layer = new WeakMap(), _CmDateRangePicker_toggle = new WeakMap(), _CmDateRangePicker_onInputKey = new WeakMap(), _CmDateRangePicker_onGridKey = new WeakMap(), _CmDateRangePicker_onPopKey = new WeakMap(), _CmDateRangePicker_onOutside = new WeakMap(), _CmDateRangePicker_instances = new WeakSet(), _CmDateRangePicker_locale_get = function _CmDateRangePicker_locale_get() { return resolveLocale(this, this.locale); }, _CmDateRangePicker_fmt_get = function _CmDateRangePicker_fmt_get() { return dateFormat(__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_locale_get)); }, _CmDateRangePicker_firstDay_get = function _CmDateRangePicker_firstDay_get() {
|
|
387
|
+
_CmDateRangePicker_localeProp = new WeakMap(), _CmDateRangePicker_internals = new WeakMap(), _CmDateRangePicker_v = new WeakMap(), _CmDateRangePicker_id = new WeakMap(), _CmDateRangePicker_default = new WeakMap(), _CmDateRangePicker_keepText = new WeakMap(), _CmDateRangePicker_focusGrid = new WeakMap(), _CmDateRangePicker_picking = new WeakMap(), _CmDateRangePicker_layer = new WeakMap(), _CmDateRangePicker_toggle = new WeakMap(), _CmDateRangePicker_onInputKey = new WeakMap(), _CmDateRangePicker_onGridKey = new WeakMap(), _CmDateRangePicker_onPopKey = new WeakMap(), _CmDateRangePicker_onOutside = new WeakMap(), _CmDateRangePicker_instances = new WeakSet(), _CmDateRangePicker_locale_get = function _CmDateRangePicker_locale_get() { return resolveLocale(this, this.locale); }, _CmDateRangePicker_fmt_get = function _CmDateRangePicker_fmt_get() { return dateFormat(__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_locale_get)); }, _CmDateRangePicker_firstDay_get = function _CmDateRangePicker_firstDay_get() {
|
|
383
388
|
const n = Number(this.firstDayOfWeek);
|
|
384
389
|
return this.firstDayOfWeek == null || Number.isNaN(n) ? localeFirstDay(__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_locale_get)) : ((Math.trunc(n) % 7) + 7) % 7;
|
|
385
390
|
}, _CmDateRangePicker_pattern_get = function _CmDateRangePicker_pattern_get() { return datePattern(__classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_fmt_get), { d: this.t('patternDay'), m: this.t('patternMonth'), y: this.t('patternYear') }); }, _CmDateRangePicker_format = function _CmDateRangePicker_format(v) { const d = fromISO(v); return d ? __classPrivateFieldGet(this, _CmDateRangePicker_instances, "a", _CmDateRangePicker_fmt_get).short(d) : v; }, _CmDateRangePicker_emit = function _CmDateRangePicker_emit() {
|
|
@@ -470,6 +475,7 @@ CmDateRangePicker.properties = {
|
|
|
470
475
|
CmDateRangePicker.styles = [
|
|
471
476
|
base, topLayerStyles, dateFieldStyles, calendarStyles,
|
|
472
477
|
css `
|
|
478
|
+
:host([data-cm-invalid]) .box { border-color: var(--cm-border-critical); }
|
|
473
479
|
.sep { flex: none; color: var(--cm-text-tertiary); }
|
|
474
480
|
input { flex: 0 1 6.6em; }
|
|
475
481
|
:host([size='small']) input { flex-basis: 6.6em; }
|
|
@@ -3,10 +3,11 @@ 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_photo_get, _CmFileUpload_accept_get, _CmFileUpload_multiple_get, _CmFileUpload_size, _CmFileUpload_url, _CmFileUpload_busy, _CmFileUpload_cancel, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_prompt, _CmFileUpload_file, _CmFileUpload_zone, _CmFileUpload_retake, _CmFileUpload_renderPhoto;
|
|
6
|
+
var _CmFileUpload_instances, _CmFileUpload_internals, _CmFileUpload_v, _CmFileUpload_id, _CmFileUpload_urls, _CmFileUpload_photo_get, _CmFileUpload_accept_get, _CmFileUpload_multiple_get, _CmFileUpload_size, _CmFileUpload_url, _CmFileUpload_busy, _CmFileUpload_cancel, _CmFileUpload_onInputChange, _CmFileUpload_setOver, _CmFileUpload_prompt, _CmFileUpload_file, _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';
|
|
10
|
+
import { FieldValidity } from '../validation.js';
|
|
10
11
|
import './icon.js';
|
|
11
12
|
const strings = defineStrings('fileUpload', {
|
|
12
13
|
/** Text inside the empty zone. `{browse}` is where the `browse` word goes, drawn like a link. */
|
|
@@ -108,6 +109,7 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
108
109
|
this._fileErrors = new Map();
|
|
109
110
|
this._over = false;
|
|
110
111
|
_CmFileUpload_internals.set(this, this.attachInternals());
|
|
112
|
+
_CmFileUpload_v.set(this, new FieldValidity(this, __classPrivateFieldGet(this, _CmFileUpload_internals, "f")));
|
|
111
113
|
_CmFileUpload_id.set(this, nextId('cm-fu'));
|
|
112
114
|
_CmFileUpload_urls.set(this, new Map());
|
|
113
115
|
}
|
|
@@ -115,8 +117,8 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
115
117
|
get validity() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").validity; }
|
|
116
118
|
get validationMessage() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").validationMessage; }
|
|
117
119
|
checkValidity() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").checkValidity(); }
|
|
118
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmFileUpload_internals, "f").reportValidity(); }
|
|
119
|
-
formResetCallback() { this.files = []; this._rejected = ''; this._progress = new Map(); this._fileErrors = new Map(); }
|
|
120
|
+
reportValidity() { return __classPrivateFieldGet(this, _CmFileUpload_v, "f").report(() => __classPrivateFieldGet(this, _CmFileUpload_internals, "f").reportValidity()); }
|
|
121
|
+
formResetCallback() { __classPrivateFieldGet(this, _CmFileUpload_v, "f").reset(); this.files = []; this._rejected = ''; this._progress = new Map(); this._fileErrors = new Map(); }
|
|
120
122
|
formDisabledCallback(d) { this.disabled = d; }
|
|
121
123
|
disconnectedCallback() {
|
|
122
124
|
super.disconnectedCallback();
|
|
@@ -145,6 +147,7 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
145
147
|
__classPrivateFieldGet(this, _CmFileUpload_internals, "f").setValidity({ valueMissing: true }, this.t('required'), input);
|
|
146
148
|
else
|
|
147
149
|
__classPrivateFieldGet(this, _CmFileUpload_internals, "f").setValidity({});
|
|
150
|
+
__classPrivateFieldGet(this, _CmFileUpload_v, "f").sync();
|
|
148
151
|
}
|
|
149
152
|
/** Adds files as if the merchant had chosen them: filters by type, size and count, then fires events. */
|
|
150
153
|
addFiles(list) {
|
|
@@ -215,7 +218,7 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
215
218
|
render() {
|
|
216
219
|
if (__classPrivateFieldGet(this, _CmFileUpload_instances, "a", _CmFileUpload_photo_get))
|
|
217
220
|
return __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_renderPhoto).call(this);
|
|
218
|
-
const msg = this.error || this._rejected;
|
|
221
|
+
const msg = this.error || this._rejected || __classPrivateFieldGet(this, _CmFileUpload_v, "f").message;
|
|
219
222
|
const showZone = !this.files.length || this.multiple;
|
|
220
223
|
const tile = this.files.length > 0;
|
|
221
224
|
return html `
|
|
@@ -235,7 +238,7 @@ export class CmFileUpload extends CmLocalizedElement {
|
|
|
235
238
|
`;
|
|
236
239
|
}
|
|
237
240
|
}
|
|
238
|
-
_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) {
|
|
241
|
+
_CmFileUpload_internals = new WeakMap(), _CmFileUpload_v = 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) {
|
|
239
242
|
return n >= 1024 * 1024
|
|
240
243
|
? this.t('megabytes', { size: this.formatNumber(+(n / 1024 / 1024).toFixed(1), { useGrouping: false }) })
|
|
241
244
|
: this.t('kilobytes', { size: this.formatNumber(Math.max(1, Math.round(n / 1024)), { useGrouping: false }) });
|
|
@@ -277,14 +280,14 @@ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFi
|
|
|
277
280
|
@click=${() => this.removeFile(f)}><cm-icon name="close" size="12"></cm-icon></button>`}
|
|
278
281
|
</div>${err ? html `<p class="ferr" id=${errId} role="alert">${err}</p>` : nothing}</li>`;
|
|
279
282
|
}, _CmFileUpload_zone = function _CmFileUpload_zone(tile) {
|
|
280
|
-
const
|
|
281
|
-
const
|
|
283
|
+
const msg = this.error || this._rejected || __classPrivateFieldGet(this, _CmFileUpload_v, "f").message;
|
|
284
|
+
const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, msg && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
|
|
282
285
|
return html `<label class="zone ${tile ? 'tile' : 'row'} ${msg && !tile ? 'invalid' : ''}" part="zone"
|
|
283
286
|
@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)}>
|
|
284
287
|
<input type="file" id=${__classPrivateFieldGet(this, _CmFileUpload_id, "f")} accept=${this.accept || nothing} capture=${this.capture || nothing} ?multiple=${this.multiple} ?disabled=${this.disabled}
|
|
285
288
|
?required=${this.required && !this.files.length}
|
|
286
289
|
aria-labelledby=${[this.label && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-l`, `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p`].filter(Boolean).join(' ')}
|
|
287
|
-
aria-describedby=${described || nothing} aria-invalid=${
|
|
290
|
+
aria-describedby=${described || nothing} aria-invalid=${msg ? 'true' : nothing}
|
|
288
291
|
@change=${__classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_onInputChange)} @cancel=${(e) => e.stopPropagation()} />
|
|
289
292
|
${tile
|
|
290
293
|
? html `<cm-icon name="plus" size="24"></cm-icon><span id="${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-p">${this.t('addMore')}</span>`
|
|
@@ -294,7 +297,7 @@ _CmFileUpload_internals = new WeakMap(), _CmFileUpload_id = new WeakMap(), _CmFi
|
|
|
294
297
|
</label>`;
|
|
295
298
|
}, _CmFileUpload_retake = function _CmFileUpload_retake() { this.renderRoot.querySelector('input[type=file]')?.click(); }, _CmFileUpload_renderPhoto = function _CmFileUpload_renderPhoto() {
|
|
296
299
|
const f = this.files[0];
|
|
297
|
-
const msg = this.error || this._rejected || (f && this._fileErrors.get(f)) ||
|
|
300
|
+
const msg = this.error || this._rejected || (f && this._fileErrors.get(f)) || __classPrivateFieldGet(this, _CmFileUpload_v, "f").message;
|
|
298
301
|
const busy = !!f && __classPrivateFieldGet(this, _CmFileUpload_instances, "m", _CmFileUpload_busy).call(this, f);
|
|
299
302
|
const name = this.label || this.t('photo');
|
|
300
303
|
const described = [this.hint && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-hint`, msg && `${__classPrivateFieldGet(this, _CmFileUpload_id, "f")}-msg`].filter(Boolean).join(' ');
|