@commmerce/ui 1.1.1 → 1.2.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/calendar.d.ts +38 -0
- package/dist/calendar.js +109 -0
- package/dist/cdn.js +677 -450
- package/dist/components/button.d.ts +10 -0
- package/dist/components/button.js +25 -0
- package/dist/components/card.d.ts +5 -0
- package/dist/components/card.js +44 -5
- package/dist/components/date-picker.d.ts +49 -5
- package/dist/components/date-picker.js +211 -48
- package/dist/components/empty-state.d.ts +19 -4
- package/dist/components/empty-state.js +59 -5
- package/dist/components/metric.d.ts +97 -0
- package/dist/components/metric.js +168 -0
- package/dist/components/page-header.js +3 -2
- package/dist/components/resource-list.d.ts +14 -2
- package/dist/components/resource-list.js +48 -6
- package/dist/components/table-header.d.ts +14 -0
- package/dist/components/table-header.js +21 -0
- package/dist/components/text-field.d.ts +36 -2
- package/dist/components/text-field.js +86 -14
- package/dist/components/timeline.d.ts +210 -0
- package/dist/components/timeline.js +380 -0
- package/dist/custom-elements.json +5102 -3386
- package/dist/index.d.ts +3 -0
- package/dist/index.js +2 -0
- package/package.json +3 -3
|
@@ -9,12 +9,12 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _CmDatePicker_instances, _CmDatePicker_localeProp, _CmDatePicker_internals, _CmDatePicker_id, _CmDatePicker_defaultValue, _CmDatePicker_keepText, _CmDatePicker_focusGrid, _CmDatePicker_locale_get, _CmDatePicker_fmt_get, _CmDatePicker_firstDay_get, _CmDatePicker_pattern_get, _CmDatePicker_format, _CmDatePicker_prepareFocus, _CmDatePicker_setValue, _CmDatePicker_commitText, _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_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_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 { fromISO, toISO, addMonths, startOfMonth, clamp, trapTab, dateFieldStyles, gridKey, renderGrid, calendarStyles, dateFormat, parseDate, resolveLocale, localeFirstDay, listConverter, asList, datePattern, } from '../calendar.js';
|
|
17
|
+
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';
|
|
18
18
|
import './icon.js';
|
|
19
19
|
const strings = defineStrings('datePicker', {
|
|
20
20
|
/** Calendar button while no date is set. */
|
|
@@ -43,9 +43,23 @@ const strings = defineStrings('datePicker', {
|
|
|
43
43
|
rangeOverflow: 'Choose {date} or earlier.',
|
|
44
44
|
/** Validation: a date in `disabled-dates` or refused by `isDateDisabled`. */
|
|
45
45
|
unavailable: 'This date isn\'t available. Choose another date.',
|
|
46
|
+
/** With `time`: accessible name of the time box. */
|
|
47
|
+
time: 'Time',
|
|
48
|
+
/** With `time`: accessible name of the time box when the field has a label. */
|
|
49
|
+
timeFor: 'Time for {label}',
|
|
50
|
+
/** With `time`: letters for hours and minutes in the time placeholder, e.g. hh:mm am. */
|
|
51
|
+
patternHour: 'hh',
|
|
52
|
+
patternMinute: 'mm',
|
|
53
|
+
/** With `time`, validation: the text in the time box is not a time. `{pattern}` is e.g. hh:mm am. */
|
|
54
|
+
badTime: 'Enter a time like {pattern}.',
|
|
55
|
+
/** With `time`, validation: a date is set but no time. */
|
|
56
|
+
timeMissing: 'Enter a time.',
|
|
57
|
+
/** With `time`, validation: a time off the `step`. `{count}` is the step in minutes. */
|
|
58
|
+
stepMismatch: { one: 'Choose a time on the minute.', other: 'Choose a time in steps of {count} minutes.' },
|
|
46
59
|
});
|
|
47
60
|
/**
|
|
48
|
-
* Date field: type a date or pick one from a calendar.
|
|
61
|
+
* Date field: type a date or pick one from a calendar. With `time`, a time box sits next to it and the value is a
|
|
62
|
+
* local date and time, `yyyy-mm-ddThh:mm`. Follows the WAI-ARIA APG "date picker dialog" pattern:
|
|
49
63
|
* the calendar button opens a month grid where arrows move by day and week, Page Up/Down by month, Shift+Page Up/Down
|
|
50
64
|
* by year, Home/End to the start and end of the week, Enter picks and Escape closes. Month and weekday names come
|
|
51
65
|
* from `Intl` in the page's language. Participates in native forms with an ISO `yyyy-mm-dd` value.
|
|
@@ -55,6 +69,8 @@ const strings = defineStrings('datePicker', {
|
|
|
55
69
|
* @csspart box - The bordered box around the text input and calendar button.
|
|
56
70
|
* @csspart input - The text input.
|
|
57
71
|
* @csspart calendar - The month grid.
|
|
72
|
+
* @csspart time-box - With `time`: the bordered box around the time input.
|
|
73
|
+
* @csspart time-input - With `time`: the time input.
|
|
58
74
|
*/
|
|
59
75
|
export class CmDatePicker extends CmLocalizedElement {
|
|
60
76
|
constructor() {
|
|
@@ -68,11 +84,17 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
68
84
|
this.error = '';
|
|
69
85
|
/** Form field name. */
|
|
70
86
|
this.name = '';
|
|
71
|
-
/**
|
|
87
|
+
/**
|
|
88
|
+
* The date as ISO `yyyy-mm-dd`; empty when no date is set. With `time`: the local date and time
|
|
89
|
+
* `yyyy-mm-ddThh:mm` (no time zone or offset), empty until both a date and a time are set.
|
|
90
|
+
*/
|
|
72
91
|
this.value = '';
|
|
73
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* Earliest date that can be chosen, ISO `yyyy-mm-dd`. With `time` it may include a time, `yyyy-mm-ddThh:mm`,
|
|
94
|
+
* or be `now` (the current minute, checked again whenever the field is validated).
|
|
95
|
+
*/
|
|
74
96
|
this.min = '';
|
|
75
|
-
/** Latest date that can be chosen, ISO `yyyy-mm-dd`. */
|
|
97
|
+
/** Latest date that can be chosen, ISO `yyyy-mm-dd`. With `time`, also `yyyy-mm-ddThh:mm` or `now`. */
|
|
76
98
|
this.max = '';
|
|
77
99
|
/** Shown in the empty box. Defaults to the locale's pattern, e.g. "dd/mm/yyyy". */
|
|
78
100
|
this.placeholder = '';
|
|
@@ -87,6 +109,15 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
87
109
|
this.open = false;
|
|
88
110
|
/** `small`: 12px label, 14px value (filter panels). */
|
|
89
111
|
this.size = 'default';
|
|
112
|
+
/**
|
|
113
|
+
* Adds a time box next to the date box, so the field holds a date and a time. Times are typed (`3:30 pm`, `15:30`)
|
|
114
|
+
* and shown in the locale's clock (12-hour with am/pm for `en-IN`); Up and Down change the time by `step`.
|
|
115
|
+
*/
|
|
116
|
+
this.time = false;
|
|
117
|
+
/** With `time`: minutes between allowed times, counted from midnight (15 allows :00, :15, :30, :45). Up and Down in the time box move by it. Default 1. */
|
|
118
|
+
this.step = 1;
|
|
119
|
+
/** With `time`: `h12` or `h23` to force a 12- or 24-hour clock. Empty: the locale's clock. */
|
|
120
|
+
this.hourCycle = '';
|
|
90
121
|
this._text = '';
|
|
91
122
|
this._focus = new Date();
|
|
92
123
|
_CmDatePicker_internals.set(this, this.attachInternals());
|
|
@@ -94,6 +125,20 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
94
125
|
_CmDatePicker_defaultValue.set(this, null);
|
|
95
126
|
_CmDatePicker_keepText.set(this, false);
|
|
96
127
|
_CmDatePicker_focusGrid.set(this, false);
|
|
128
|
+
/** With `time`: the date and time parts, kept while the other part is still missing (the value is then empty). */
|
|
129
|
+
_CmDatePicker_date.set(this, '');
|
|
130
|
+
_CmDatePicker_time.set(this, '');
|
|
131
|
+
_CmDatePicker_keepTime.set(this, false);
|
|
132
|
+
_CmDatePicker_timeTextValue.set(this, '');
|
|
133
|
+
_CmDatePicker_ownValue.set(this, false);
|
|
134
|
+
_CmDatePicker_onTimeKey.set(this, (e) => {
|
|
135
|
+
if (e.key === 'Enter')
|
|
136
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_commitTime).call(this);
|
|
137
|
+
else if ((e.key === 'ArrowUp' || e.key === 'ArrowDown') && !e.altKey) {
|
|
138
|
+
e.preventDefault();
|
|
139
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_stepTime).call(this, e.key === 'ArrowUp' ? 1 : -1);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
97
142
|
_CmDatePicker_toggle.set(this, () => {
|
|
98
143
|
if (this.disabled)
|
|
99
144
|
return;
|
|
@@ -122,7 +167,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
122
167
|
const next = gridKey(logicalKey(e, this), e, this._focus, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_firstDay_get));
|
|
123
168
|
if (next) {
|
|
124
169
|
e.preventDefault();
|
|
125
|
-
this._focus = clamp(next,
|
|
170
|
+
this._focus = clamp(next, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get), __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get));
|
|
126
171
|
__classPrivateFieldSet(this, _CmDatePicker_focusGrid, true, "f");
|
|
127
172
|
return;
|
|
128
173
|
}
|
|
@@ -142,7 +187,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
142
187
|
trapTab(e, e.currentTarget);
|
|
143
188
|
});
|
|
144
189
|
_CmDatePicker_onMonth.set(this, (step) => {
|
|
145
|
-
this._focus = clamp(addMonths(this._focus, step),
|
|
190
|
+
this._focus = clamp(addMonths(this._focus, step), __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get), __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get));
|
|
146
191
|
});
|
|
147
192
|
_CmDatePicker_onOutside.set(this, (e) => {
|
|
148
193
|
if (this.open && !e.composedPath().includes(this))
|
|
@@ -169,11 +214,19 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
169
214
|
get form() { return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").form; }
|
|
170
215
|
get validity() { return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").validity; }
|
|
171
216
|
get validationMessage() { return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").validationMessage; }
|
|
172
|
-
/** The value as a local Date, or null. */
|
|
173
|
-
get valueAsDate() { return fromISO(this.value); }
|
|
174
|
-
checkValidity() { return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").checkValidity(); }
|
|
175
|
-
reportValidity() { return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").reportValidity(); }
|
|
176
|
-
formResetCallback() {
|
|
217
|
+
/** The value as a local Date (with `time`, at that time), or null. */
|
|
218
|
+
get valueAsDate() { return this.time ? (this.value ? fromISODateTime(this.value) : null) : fromISO(this.value); }
|
|
219
|
+
checkValidity() { __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_validate).call(this); return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").checkValidity(); }
|
|
220
|
+
reportValidity() { __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_validate).call(this); return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").reportValidity(); }
|
|
221
|
+
formResetCallback() {
|
|
222
|
+
this.value = __classPrivateFieldGet(this, _CmDatePicker_defaultValue, "f") ?? '';
|
|
223
|
+
if (this.time) {
|
|
224
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_split).call(this, this.value);
|
|
225
|
+
__classPrivateFieldSet(this, _CmDatePicker_instances, __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_formatTime).call(this, __classPrivateFieldGet(this, _CmDatePicker_time, "f")), "a", _CmDatePicker_timeText_set);
|
|
226
|
+
}
|
|
227
|
+
this._text = __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_format).call(this, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get));
|
|
228
|
+
this.open = false;
|
|
229
|
+
}
|
|
177
230
|
formDisabledCallback(d) { this.disabled = d; if (d)
|
|
178
231
|
this.open = false; }
|
|
179
232
|
formStateRestoreCallback(state) { this.value = state ?? ''; }
|
|
@@ -189,37 +242,30 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
189
242
|
const d = fromISO(iso);
|
|
190
243
|
if (!d)
|
|
191
244
|
return true;
|
|
192
|
-
const min =
|
|
245
|
+
const min = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get), max = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get);
|
|
193
246
|
if ((min && d < min) || (max && d > max))
|
|
194
247
|
return true;
|
|
195
248
|
return asList(this.disabledDates).includes(iso) || !!this.isDateDisabled?.(iso);
|
|
196
249
|
}
|
|
197
250
|
willUpdate(changed) {
|
|
198
|
-
if (changed.has('value') && !__classPrivateFieldGet(this,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
251
|
+
if (this.time && (changed.has('value') || changed.has('time')) && !__classPrivateFieldGet(this, _CmDatePicker_ownValue, "f")) {
|
|
252
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_split).call(this, this.value);
|
|
253
|
+
if (!__classPrivateFieldGet(this, _CmDatePicker_keepTime, "f"))
|
|
254
|
+
__classPrivateFieldSet(this, _CmDatePicker_instances, __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_formatTime).call(this, __classPrivateFieldGet(this, _CmDatePicker_time, "f")), "a", _CmDatePicker_timeText_set);
|
|
255
|
+
}
|
|
256
|
+
else if (this.time && (changed.has('locale') || changed.has('hourCycle')) && __classPrivateFieldGet(this, _CmDatePicker_time, "f"))
|
|
257
|
+
__classPrivateFieldSet(this, _CmDatePicker_instances, __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_formatTime).call(this, __classPrivateFieldGet(this, _CmDatePicker_time, "f")), "a", _CmDatePicker_timeText_set);
|
|
258
|
+
if ((changed.has('value') || changed.has('time')) && !__classPrivateFieldGet(this, _CmDatePicker_keepText, "f"))
|
|
259
|
+
this._text = __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_format).call(this, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get));
|
|
260
|
+
else if (changed.has('locale') && fromISO(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get)))
|
|
261
|
+
this._text = __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_format).call(this, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get));
|
|
202
262
|
__classPrivateFieldSet(this, _CmDatePicker_keepText, false, "f");
|
|
263
|
+
__classPrivateFieldSet(this, _CmDatePicker_keepTime, false, "f");
|
|
264
|
+
__classPrivateFieldSet(this, _CmDatePicker_ownValue, false, "f");
|
|
203
265
|
}
|
|
204
266
|
updated(changed) {
|
|
205
|
-
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setFormValue(this.value || null, this._text);
|
|
206
|
-
|
|
207
|
-
const d = fromISO(this.value);
|
|
208
|
-
const fmt = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get);
|
|
209
|
-
if (this.error)
|
|
210
|
-
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ customError: true }, this.error, input);
|
|
211
|
-
else if (this._text.trim() && !d)
|
|
212
|
-
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ badInput: true }, this.t('badInput', { pattern: __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_pattern_get) }), input);
|
|
213
|
-
else if (this.required && !d)
|
|
214
|
-
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ valueMissing: true }, this.t('required'), input);
|
|
215
|
-
else if (d && fromISO(this.min) && d < fromISO(this.min))
|
|
216
|
-
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ rangeUnderflow: true }, this.t('rangeUnderflow', { date: fmt.medium(fromISO(this.min)) }), input);
|
|
217
|
-
else if (d && fromISO(this.max) && d > fromISO(this.max))
|
|
218
|
-
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ rangeOverflow: true }, this.t('rangeOverflow', { date: fmt.medium(fromISO(this.max)) }), input);
|
|
219
|
-
else if (d && this.isUnavailable(this.value))
|
|
220
|
-
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ customError: true }, this.t('unavailable'), input);
|
|
221
|
-
else
|
|
222
|
-
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({});
|
|
267
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setFormValue(this.value || null, this.time ? this.value : this._text);
|
|
268
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_validate).call(this);
|
|
223
269
|
if (this.open && __classPrivateFieldGet(this, _CmDatePicker_focusGrid, "f")) {
|
|
224
270
|
__classPrivateFieldSet(this, _CmDatePicker_focusGrid, false, "f");
|
|
225
271
|
this.renderRoot.querySelector('td[tabindex="0"]')?.focus();
|
|
@@ -229,7 +275,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
229
275
|
}
|
|
230
276
|
render() {
|
|
231
277
|
const fmt = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get);
|
|
232
|
-
const value = fromISO(this
|
|
278
|
+
const value = fromISO(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get));
|
|
233
279
|
const described = [this.error && `${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-err`, this.helpText && `${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-help`].filter(Boolean).join(' ');
|
|
234
280
|
const hostLabel = this.getAttribute('aria-label');
|
|
235
281
|
const name = this.label || hostLabel || '';
|
|
@@ -238,7 +284,7 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
238
284
|
${this.label
|
|
239
285
|
? 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>`
|
|
240
286
|
: nothing}
|
|
241
|
-
<div class="wrap">
|
|
287
|
+
<div class="wrap ${this.time ? 'timed' : ''}">
|
|
242
288
|
<div class="box" part="box">
|
|
243
289
|
<input id="${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-in" part="input" type="text" autocomplete="off" spellcheck="false"
|
|
244
290
|
.value=${live(this._text)} placeholder=${this.placeholder || __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_pattern_get)}
|
|
@@ -252,13 +298,22 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
252
298
|
aria-haspopup="dialog" aria-expanded=${this.open ? 'true' : 'false'} aria-controls="${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-pop"
|
|
253
299
|
@click=${__classPrivateFieldGet(this, _CmDatePicker_toggle, "f")}><cm-icon name="calendar" size="18"></cm-icon></button>
|
|
254
300
|
</div>
|
|
301
|
+
${this.time ? html `<div class="box time" part="time-box">
|
|
302
|
+
<input class="time-in" part="time-input" type="text" autocomplete="off" spellcheck="false"
|
|
303
|
+
.value=${live(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_timeText_get))} placeholder=${__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_timePattern_get)}
|
|
304
|
+
aria-label=${this.t(name ? 'timeFor' : 'time', { label: name })}
|
|
305
|
+
?required=${this.required} ?disabled=${this.disabled}
|
|
306
|
+
aria-invalid=${this.error ? 'true' : nothing} aria-describedby=${described || nothing}
|
|
307
|
+
@input=${(e) => { e.stopPropagation(); __classPrivateFieldSet(this, _CmDatePicker_instances, e.target.value, "a", _CmDatePicker_timeText_set); }}
|
|
308
|
+
@change=${() => __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_commitTime).call(this)} @keydown=${__classPrivateFieldGet(this, _CmDatePicker_onTimeKey, "f")} />
|
|
309
|
+
</div>` : nothing}
|
|
255
310
|
<div class="pop" id="${__classPrivateFieldGet(this, _CmDatePicker_id, "f")}-pop" part="popover" role="dialog" aria-modal="true" aria-label=${this.t('dialog')}
|
|
256
311
|
?hidden=${!this.open} @keydown=${__classPrivateFieldGet(this, _CmDatePicker_onPopKey, "f")}>
|
|
257
312
|
${this.open ? html `<div class="cal">${renderGrid({
|
|
258
313
|
id: __classPrivateFieldGet(this, _CmDatePicker_id, "f"), fmt, firstDay: __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_firstDay_get), month, focus: this._focus,
|
|
259
|
-
min:
|
|
314
|
+
min: __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get), max: __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get),
|
|
260
315
|
isDisabled: (d) => this.isUnavailable(toISO(d)),
|
|
261
|
-
mark: (d) => (value && toISO(d) === this
|
|
316
|
+
mark: (d) => (value && toISO(d) === __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get) ? 'selected' : ''),
|
|
262
317
|
onPick: (d) => __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_pick).call(this, d), onKey: __classPrivateFieldGet(this, _CmDatePicker_onGridKey, "f"), onMonth: __classPrivateFieldGet(this, _CmDatePicker_onMonth, "f"),
|
|
263
318
|
previousLabel: this.t('previousMonth'), nextLabel: this.t('nextMonth'),
|
|
264
319
|
})}</div>` : nothing}
|
|
@@ -269,46 +324,151 @@ export class CmDatePicker extends CmLocalizedElement {
|
|
|
269
324
|
</div>`;
|
|
270
325
|
}
|
|
271
326
|
}
|
|
272
|
-
_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_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(),
|
|
327
|
+
_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_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")) {
|
|
328
|
+
__classPrivateFieldSet(this, _CmDatePicker_timeTextValue, v, "f");
|
|
329
|
+
this.requestUpdate();
|
|
330
|
+
} }, _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() {
|
|
273
331
|
const n = Number(this.firstDayOfWeek);
|
|
274
332
|
return this.firstDayOfWeek == null || Number.isNaN(n) ? localeFirstDay(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_locale_get)) : ((Math.trunc(n) % 7) + 7) % 7;
|
|
275
333
|
}, _CmDatePicker_pattern_get = function _CmDatePicker_pattern_get() { return datePattern(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get), { d: this.t('patternDay'), m: this.t('patternMonth'), y: this.t('patternYear') }); }, _CmDatePicker_format = function _CmDatePicker_format(v) {
|
|
276
334
|
const d = fromISO(v);
|
|
277
335
|
return d ? __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get).short(d) : v;
|
|
336
|
+
}, _CmDatePicker_formatTime = function _CmDatePicker_formatTime(t) {
|
|
337
|
+
const minutes = timeToMinutes(t);
|
|
338
|
+
return minutes === null ? '' : __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_tf_get).format(minutes);
|
|
339
|
+
}, _CmDatePicker_timePattern_get = function _CmDatePicker_timePattern_get() { return timePattern(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_tf_get), { h: this.t('patternHour'), m: this.t('patternMinute') }); }, _CmDatePicker_split = function _CmDatePicker_split(v) {
|
|
340
|
+
const { date, time } = splitDateTime(v);
|
|
341
|
+
__classPrivateFieldSet(this, _CmDatePicker_date, date, "f");
|
|
342
|
+
__classPrivateFieldSet(this, _CmDatePicker_time, date ? time : '', "f");
|
|
278
343
|
}, _CmDatePicker_prepareFocus = function _CmDatePicker_prepareFocus() {
|
|
279
344
|
const today = new Date();
|
|
280
|
-
const start = fromISO(this
|
|
281
|
-
this._focus = clamp(start,
|
|
345
|
+
const start = fromISO(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get)) ?? new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
|
346
|
+
this._focus = clamp(start, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get), __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get));
|
|
282
347
|
__classPrivateFieldSet(this, _CmDatePicker_focusGrid, true, "f");
|
|
348
|
+
}, _CmDatePicker_validate = function _CmDatePicker_validate() {
|
|
349
|
+
const input = this.renderRoot.querySelector('input') ?? undefined;
|
|
350
|
+
const d = fromISO(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_dateValue_get));
|
|
351
|
+
const fmt = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get);
|
|
352
|
+
if (this.error)
|
|
353
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ customError: true }, this.error, input);
|
|
354
|
+
else if (this._text.trim() && !d)
|
|
355
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ badInput: true }, this.t('badInput', { pattern: __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_pattern_get) }), input);
|
|
356
|
+
else if (this.time)
|
|
357
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_validateTime).call(this, d, input);
|
|
358
|
+
else if (this.required && !d)
|
|
359
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ valueMissing: true }, this.t('required'), input);
|
|
360
|
+
else if (d && __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get) && d < __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get))
|
|
361
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ rangeUnderflow: true }, this.t('rangeUnderflow', { date: fmt.medium(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_minDate_get)) }), input);
|
|
362
|
+
else if (d && __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get) && d > __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get))
|
|
363
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ rangeOverflow: true }, this.t('rangeOverflow', { date: fmt.medium(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_maxDate_get)) }), input);
|
|
364
|
+
else if (d && this.isUnavailable(this.value))
|
|
365
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({ customError: true }, this.t('unavailable'), input);
|
|
366
|
+
else
|
|
367
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({});
|
|
368
|
+
}, _CmDatePicker_validateTime = function _CmDatePicker_validateTime(d, dateInput) {
|
|
369
|
+
const timeInput = this.renderRoot.querySelector('input.time-in') ?? dateInput;
|
|
370
|
+
const set = (flags, key, vars, anchor = dateInput) => __classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity(flags, this.t(key, vars), anchor);
|
|
371
|
+
const minutes = timeToMinutes(__classPrivateFieldGet(this, _CmDatePicker_time, "f"));
|
|
372
|
+
if (__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_timeText_get).trim() && minutes === null)
|
|
373
|
+
return set({ badInput: true }, 'badTime', { pattern: __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_timePattern_get) }, timeInput);
|
|
374
|
+
if (!d && minutes === null) {
|
|
375
|
+
if (this.required)
|
|
376
|
+
return set({ valueMissing: true }, 'required');
|
|
377
|
+
return __classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({});
|
|
378
|
+
}
|
|
379
|
+
if (!d)
|
|
380
|
+
return set({ badInput: true }, 'required');
|
|
381
|
+
if (minutes === null)
|
|
382
|
+
return set({ badInput: true }, 'timeMissing', undefined, timeInput);
|
|
383
|
+
const at = fromISODateTime(`${__classPrivateFieldGet(this, _CmDatePicker_date, "f")}T${__classPrivateFieldGet(this, _CmDatePicker_time, "f")}`);
|
|
384
|
+
const min = fromISODateTime(__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_limit).call(this, this.min)), max = fromISODateTime(__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_limit).call(this, this.max), true);
|
|
385
|
+
const show = (limit, v) => (splitDateTime(limit).time ? __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_tf_get).dateTime(v) : __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get).medium(v));
|
|
386
|
+
if (min && at < min)
|
|
387
|
+
return set({ rangeUnderflow: true }, 'rangeUnderflow', { date: show(__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_limit).call(this, this.min), min) }, timeInput);
|
|
388
|
+
if (max && at > max)
|
|
389
|
+
return set({ rangeOverflow: true }, 'rangeOverflow', { date: show(__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_limit).call(this, this.max), max) }, timeInput);
|
|
390
|
+
if (minutes % __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_step_get))
|
|
391
|
+
return set({ stepMismatch: true }, 'stepMismatch', { count: __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_step_get) }, timeInput);
|
|
392
|
+
if (this.isUnavailable(__classPrivateFieldGet(this, _CmDatePicker_date, "f")))
|
|
393
|
+
return set({ customError: true }, 'unavailable');
|
|
394
|
+
__classPrivateFieldGet(this, _CmDatePicker_internals, "f").setValidity({});
|
|
283
395
|
}, _CmDatePicker_setValue = function _CmDatePicker_setValue(v) {
|
|
284
396
|
if (v === this.value)
|
|
285
397
|
return;
|
|
286
398
|
this.value = v;
|
|
287
399
|
this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
|
|
288
400
|
this.dispatchEvent(new Event('change', { bubbles: true, composed: true }));
|
|
401
|
+
}, _CmDatePicker_setParts = function _CmDatePicker_setParts(date, time) {
|
|
402
|
+
__classPrivateFieldSet(this, _CmDatePicker_date, date, "f");
|
|
403
|
+
__classPrivateFieldSet(this, _CmDatePicker_time, time, "f");
|
|
404
|
+
const v = date && time ? `${date}T${time}` : '';
|
|
405
|
+
__classPrivateFieldSet(this, _CmDatePicker_ownValue, true, "f");
|
|
406
|
+
this.requestUpdate();
|
|
407
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setValue).call(this, v);
|
|
408
|
+
}, _CmDatePicker_setDate = function _CmDatePicker_setDate(iso) {
|
|
409
|
+
if (this.time)
|
|
410
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setParts).call(this, iso, __classPrivateFieldGet(this, _CmDatePicker_time, "f"));
|
|
411
|
+
else
|
|
412
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setValue).call(this, iso);
|
|
289
413
|
}, _CmDatePicker_commitText = function _CmDatePicker_commitText() {
|
|
290
414
|
const text = this._text.trim();
|
|
291
415
|
if (!text) {
|
|
292
|
-
__classPrivateFieldGet(this, _CmDatePicker_instances, "m",
|
|
416
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setDate).call(this, '');
|
|
293
417
|
return;
|
|
294
418
|
}
|
|
295
419
|
const iso = parseDate(text, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_fmt_get));
|
|
296
420
|
if (iso) {
|
|
297
|
-
__classPrivateFieldGet(this, _CmDatePicker_instances, "m",
|
|
421
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setDate).call(this, iso);
|
|
298
422
|
this._text = __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_format).call(this, iso);
|
|
299
423
|
}
|
|
300
424
|
else {
|
|
301
425
|
__classPrivateFieldSet(this, _CmDatePicker_keepText, true, "f");
|
|
302
|
-
__classPrivateFieldGet(this, _CmDatePicker_instances, "m",
|
|
426
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setDate).call(this, '');
|
|
427
|
+
}
|
|
428
|
+
}, _CmDatePicker_commitTime = function _CmDatePicker_commitTime() {
|
|
429
|
+
const text = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_timeText_get).trim();
|
|
430
|
+
const t = text ? parseTime(text, __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_tf_get)) : '';
|
|
431
|
+
__classPrivateFieldSet(this, _CmDatePicker_keepText, true, "f");
|
|
432
|
+
if (t === null) {
|
|
433
|
+
__classPrivateFieldSet(this, _CmDatePicker_keepTime, true, "f");
|
|
434
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setParts).call(this, __classPrivateFieldGet(this, _CmDatePicker_date, "f"), '');
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setParts).call(this, __classPrivateFieldGet(this, _CmDatePicker_date, "f"), t);
|
|
438
|
+
__classPrivateFieldSet(this, _CmDatePicker_instances, __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_formatTime).call(this, t), "a", _CmDatePicker_timeText_set);
|
|
439
|
+
}, _CmDatePicker_stepTime = function _CmDatePicker_stepTime(dir) {
|
|
440
|
+
const step = __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_step_get);
|
|
441
|
+
let current = parseTime(__classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_timeText_get), __classPrivateFieldGet(this, _CmDatePicker_instances, "a", _CmDatePicker_tf_get));
|
|
442
|
+
if (!current) {
|
|
443
|
+
const min = splitDateTime(__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_limit).call(this, this.min));
|
|
444
|
+
const now = new Date();
|
|
445
|
+
current = min.time && (!__classPrivateFieldGet(this, _CmDatePicker_date, "f") || __classPrivateFieldGet(this, _CmDatePicker_date, "f") === min.date) ? min.time : minutesToTime(now.getHours() * 60 + now.getMinutes());
|
|
446
|
+
const m = timeToMinutes(current);
|
|
447
|
+
if (m % step === 0) {
|
|
448
|
+
__classPrivateFieldSet(this, _CmDatePicker_keepText, true, "f");
|
|
449
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setParts).call(this, __classPrivateFieldGet(this, _CmDatePicker_date, "f"), current);
|
|
450
|
+
__classPrivateFieldSet(this, _CmDatePicker_instances, __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_formatTime).call(this, current), "a", _CmDatePicker_timeText_set);
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
dir = 1;
|
|
303
454
|
}
|
|
455
|
+
const m = timeToMinutes(current);
|
|
456
|
+
const next = dir > 0 ? (Math.floor(m / step) + 1) * step : (Math.ceil(m / step) - 1) * step;
|
|
457
|
+
const t = minutesToTime(next >= 1440 ? 0 : next < 0 ? Math.floor(1439 / step) * step : next);
|
|
458
|
+
__classPrivateFieldSet(this, _CmDatePicker_keepText, true, "f");
|
|
459
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setParts).call(this, __classPrivateFieldGet(this, _CmDatePicker_date, "f"), t);
|
|
460
|
+
__classPrivateFieldSet(this, _CmDatePicker_instances, __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_formatTime).call(this, t), "a", _CmDatePicker_timeText_set);
|
|
304
461
|
}, _CmDatePicker_pick = function _CmDatePicker_pick(d) {
|
|
305
462
|
const iso = toISO(d);
|
|
306
463
|
if (this.isUnavailable(iso))
|
|
307
464
|
return;
|
|
308
465
|
this.open = false;
|
|
309
|
-
__classPrivateFieldGet(this, _CmDatePicker_instances, "m",
|
|
466
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_setDate).call(this, iso);
|
|
310
467
|
this._text = __classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_format).call(this, iso);
|
|
311
|
-
__classPrivateFieldGet(this,
|
|
468
|
+
if (this.time && !__classPrivateFieldGet(this, _CmDatePicker_time, "f"))
|
|
469
|
+
this.updateComplete.then(() => this.renderRoot.querySelector('input.time-in')?.focus());
|
|
470
|
+
else
|
|
471
|
+
__classPrivateFieldGet(this, _CmDatePicker_instances, "m", _CmDatePicker_focusTrigger).call(this);
|
|
312
472
|
}, _CmDatePicker_focusTrigger = function _CmDatePicker_focusTrigger() { this.renderRoot.querySelector('.trigger')?.focus(); };
|
|
313
473
|
CmDatePicker.formAssociated = true;
|
|
314
474
|
CmDatePicker.shadowRootOptions = { ...LitElement.shadowRootOptions, delegatesFocus: true };
|
|
@@ -329,6 +489,9 @@ CmDatePicker.properties = {
|
|
|
329
489
|
disabled: { type: Boolean, reflect: true },
|
|
330
490
|
open: { type: Boolean, reflect: true },
|
|
331
491
|
size: { reflect: true },
|
|
492
|
+
time: { type: Boolean, reflect: true },
|
|
493
|
+
step: { type: Number },
|
|
494
|
+
hourCycle: { attribute: 'hour-cycle' },
|
|
332
495
|
_text: { state: true },
|
|
333
496
|
_focus: { state: true },
|
|
334
497
|
};
|
|
@@ -4,10 +4,13 @@ import './icon.js';
|
|
|
4
4
|
/**
|
|
5
5
|
* Shown in place of a list or page when there is nothing to show yet, with the next step to take.
|
|
6
6
|
* A soft circle holds an illustration (an image, your own markup or one of the system icons).
|
|
7
|
+
* `size="inline"` is the compact form for an empty list inside a card or table: one or two left-aligned lines,
|
|
8
|
+
* an optional small icon and an optional text action, with no circle.
|
|
7
9
|
* @element cm-empty-state
|
|
8
|
-
* @slot - Optional supporting text under the heading.
|
|
9
|
-
* @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`.
|
|
10
|
+
* @slot - Optional supporting text under the heading (inline: after it, on the same line).
|
|
11
|
+
* @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`. Inline: 20px.
|
|
10
12
|
* @slot actions - The primary action (usually one primary `cm-button`), plus an optional link.
|
|
13
|
+
* @fires cm-action - The text action (`action`) was pressed. Not fired when it has `action-href` (it is then a link).
|
|
11
14
|
*/
|
|
12
15
|
export declare class CmEmptyState extends LitElement {
|
|
13
16
|
#private;
|
|
@@ -22,6 +25,10 @@ export declare class CmEmptyState extends LitElement {
|
|
|
22
25
|
size: {
|
|
23
26
|
reflect: boolean;
|
|
24
27
|
};
|
|
28
|
+
action: {};
|
|
29
|
+
actionHref: {
|
|
30
|
+
attribute: string;
|
|
31
|
+
};
|
|
25
32
|
};
|
|
26
33
|
/** What is missing, said plainly: "No products found". */
|
|
27
34
|
heading: string;
|
|
@@ -31,8 +38,16 @@ export declare class CmEmptyState extends LitElement {
|
|
|
31
38
|
icon: IconName | '';
|
|
32
39
|
/** Heading level, so the page outline stays correct. Default 2. */
|
|
33
40
|
headingLevel: 2 | 3 | 4 | 5 | 6;
|
|
34
|
-
/**
|
|
35
|
-
|
|
41
|
+
/**
|
|
42
|
+
* `large` (250px circle, page-level), `small` (200px circle, inside a card or on mobile) or `inline`
|
|
43
|
+
* (since 1.2: no circle, a 20px icon, heading and text on one or two left-aligned lines; for an empty list
|
|
44
|
+
* inside a card, panel or table). Inline shows the `icon` (default `box`); set `icon=""` for text only.
|
|
45
|
+
*/
|
|
46
|
+
size: 'large' | 'small' | 'inline';
|
|
47
|
+
/** Text of one action drawn as a text button ("Add task", "View all"), after the text. Meant for `size="inline"`; larger sizes put a `cm-button` in the `actions` slot. Fires `cm-action`. Since 1.2. */
|
|
48
|
+
action: string;
|
|
49
|
+
/** Makes the text action a link to this URL instead of a button. Since 1.2. */
|
|
50
|
+
actionHref: string;
|
|
36
51
|
static styles: import("lit").CSSResult[];
|
|
37
52
|
/** @internal */
|
|
38
53
|
hasText: boolean;
|
|
@@ -3,17 +3,20 @@ 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 _CmEmptyState_instances, _CmEmptyState_slot;
|
|
6
|
+
var _CmEmptyState_instances, _CmEmptyState_slot, _CmEmptyState_textAction, _CmEmptyState_renderInline;
|
|
7
7
|
import { LitElement, html, css, nothing } from 'lit';
|
|
8
8
|
import { base, define } from '../base.js';
|
|
9
9
|
import './icon.js';
|
|
10
10
|
/**
|
|
11
11
|
* Shown in place of a list or page when there is nothing to show yet, with the next step to take.
|
|
12
12
|
* A soft circle holds an illustration (an image, your own markup or one of the system icons).
|
|
13
|
+
* `size="inline"` is the compact form for an empty list inside a card or table: one or two left-aligned lines,
|
|
14
|
+
* an optional small icon and an optional text action, with no circle.
|
|
13
15
|
* @element cm-empty-state
|
|
14
|
-
* @slot - Optional supporting text under the heading.
|
|
15
|
-
* @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`.
|
|
16
|
+
* @slot - Optional supporting text under the heading (inline: after it, on the same line).
|
|
17
|
+
* @slot image - Your own illustration, drawn inside the circle. Decorative: give it `alt=""`. Inline: 20px.
|
|
16
18
|
* @slot actions - The primary action (usually one primary `cm-button`), plus an optional link.
|
|
19
|
+
* @fires cm-action - The text action (`action`) was pressed. Not fired when it has `action-href` (it is then a link).
|
|
17
20
|
*/
|
|
18
21
|
export class CmEmptyState extends LitElement {
|
|
19
22
|
constructor() {
|
|
@@ -27,8 +30,16 @@ export class CmEmptyState extends LitElement {
|
|
|
27
30
|
this.icon = 'box';
|
|
28
31
|
/** Heading level, so the page outline stays correct. Default 2. */
|
|
29
32
|
this.headingLevel = 2;
|
|
30
|
-
/**
|
|
33
|
+
/**
|
|
34
|
+
* `large` (250px circle, page-level), `small` (200px circle, inside a card or on mobile) or `inline`
|
|
35
|
+
* (since 1.2: no circle, a 20px icon, heading and text on one or two left-aligned lines; for an empty list
|
|
36
|
+
* inside a card, panel or table). Inline shows the `icon` (default `box`); set `icon=""` for text only.
|
|
37
|
+
*/
|
|
31
38
|
this.size = 'large';
|
|
39
|
+
/** Text of one action drawn as a text button ("Add task", "View all"), after the text. Meant for `size="inline"`; larger sizes put a `cm-button` in the `actions` slot. Fires `cm-action`. Since 1.2. */
|
|
40
|
+
this.action = '';
|
|
41
|
+
/** Makes the text action a link to this URL instead of a button. Since 1.2. */
|
|
42
|
+
this.actionHref = '';
|
|
32
43
|
/** @internal */
|
|
33
44
|
this.hasText = false;
|
|
34
45
|
/** @internal */
|
|
@@ -38,6 +49,8 @@ export class CmEmptyState extends LitElement {
|
|
|
38
49
|
}
|
|
39
50
|
render() {
|
|
40
51
|
const level = Math.min(6, Math.max(2, this.headingLevel || 2));
|
|
52
|
+
if (this.size === 'inline')
|
|
53
|
+
return __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_renderInline).call(this, level);
|
|
41
54
|
const fallback = this.image
|
|
42
55
|
? html `<img src=${this.image} alt="" part="image">`
|
|
43
56
|
: this.icon ? html `<cm-icon name=${this.icon} size="96"></cm-icon>` : nothing;
|
|
@@ -47,7 +60,7 @@ export class CmEmptyState extends LitElement {
|
|
|
47
60
|
</div>
|
|
48
61
|
<div class="title" role="heading" aria-level=${level} part="heading">${this.heading}</div>
|
|
49
62
|
<div class="text" ?hidden=${!this.hasText}><slot @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasText')}></slot></div>
|
|
50
|
-
<div class="actions" ?hidden=${!this.hasActions}><slot name="actions" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasActions')}></slot></div
|
|
63
|
+
<div class="actions" ?hidden=${!this.hasActions}><slot name="actions" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasActions')}></slot></div>${this.action ? html `<div class="actions">${__classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_textAction).call(this)}</div>` : nothing}
|
|
51
64
|
</div>`;
|
|
52
65
|
}
|
|
53
66
|
}
|
|
@@ -55,6 +68,27 @@ _CmEmptyState_instances = new WeakSet(), _CmEmptyState_slot = function _CmEmptyS
|
|
|
55
68
|
const s = e.target;
|
|
56
69
|
this[key] = s.assignedNodes({ flatten: true }).some((n) => n.nodeType === 1 || n.textContent.trim());
|
|
57
70
|
this.requestUpdate();
|
|
71
|
+
}, _CmEmptyState_textAction = function _CmEmptyState_textAction() {
|
|
72
|
+
if (!this.action)
|
|
73
|
+
return nothing;
|
|
74
|
+
return this.actionHref
|
|
75
|
+
? html `<a class="text-action" part="action" href=${this.actionHref}>${this.action}</a>`
|
|
76
|
+
: html `<button class="text-action" type="button" part="action"
|
|
77
|
+
@click=${() => this.dispatchEvent(new CustomEvent('cm-action', { bubbles: true, composed: true }))}>${this.action}</button>`;
|
|
78
|
+
}, _CmEmptyState_renderInline = function _CmEmptyState_renderInline(level) {
|
|
79
|
+
const fallback = this.image
|
|
80
|
+
? html `<img src=${this.image} alt="" part="image">`
|
|
81
|
+
: this.icon ? html `<cm-icon name=${this.icon} size="20"></cm-icon>` : nothing;
|
|
82
|
+
return html `<div class="wrap inline" part="empty-state">
|
|
83
|
+
<span class="icon" part="circle" aria-hidden=${this.hasImage ? nothing : 'true'} ?hidden=${!this.hasImage && !this.image && !this.icon}>
|
|
84
|
+
<slot name="image" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasImage')}>${fallback}</slot>
|
|
85
|
+
</span>
|
|
86
|
+
<div class="line">
|
|
87
|
+
<div class="title" role="heading" aria-level=${level} part="heading">${this.heading}</div>
|
|
88
|
+
<span class="text" ?hidden=${!this.hasText}> <slot @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasText')}></slot></span>${__classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_textAction).call(this)}
|
|
89
|
+
<span class="actions" ?hidden=${!this.hasActions}><slot name="actions" @slotchange=${(e) => __classPrivateFieldGet(this, _CmEmptyState_instances, "m", _CmEmptyState_slot).call(this, e, 'hasActions')}></slot></span>
|
|
90
|
+
</div>
|
|
91
|
+
</div>`;
|
|
58
92
|
};
|
|
59
93
|
CmEmptyState.properties = {
|
|
60
94
|
heading: {},
|
|
@@ -62,6 +96,8 @@ CmEmptyState.properties = {
|
|
|
62
96
|
icon: {},
|
|
63
97
|
headingLevel: { type: Number, attribute: 'heading-level' },
|
|
64
98
|
size: { reflect: true },
|
|
99
|
+
action: {},
|
|
100
|
+
actionHref: { attribute: 'action-href' },
|
|
65
101
|
};
|
|
66
102
|
CmEmptyState.styles = [
|
|
67
103
|
base,
|
|
@@ -84,6 +120,24 @@ CmEmptyState.styles = [
|
|
|
84
120
|
:host([size='small']) .circle { width: 200px; height: 200px; }
|
|
85
121
|
:host([size='small']) .title { margin-top: 30px; font-size: 14px; }
|
|
86
122
|
:host([size='small']) .actions { gap: var(--cm-space-10); }
|
|
123
|
+
/* Inline (1.2): a line of text with an optional 20px icon, no circle, no extra height. */
|
|
124
|
+
.inline { flex-direction: row; align-items: flex-start; gap: var(--cm-space-10); padding: 0; text-align: start; font-size: 14px; line-height: 20px; }
|
|
125
|
+
.inline .icon { display: inline-flex; flex: none; width: 20px; height: 20px; overflow: hidden; color: var(--cm-icon-default); }
|
|
126
|
+
.inline .icon img, .inline ::slotted([slot='image']) { width: 20px; height: 20px; max-width: none; max-height: none; object-fit: contain; }
|
|
127
|
+
.inline .line { min-width: 0; text-align: start; }
|
|
128
|
+
.inline .title { display: inline; margin: 0; font-size: inherit; font-weight: 500; color: var(--cm-text-default); }
|
|
129
|
+
.inline .text { display: inline; margin: 0; font-size: inherit; color: var(--cm-text-tertiary); }
|
|
130
|
+
.inline .actions { display: inline-flex; vertical-align: middle; margin: 0; margin-inline-start: var(--cm-space-10); }
|
|
131
|
+
.inline .text[hidden], .inline .actions[hidden], .inline .icon[hidden] { display: none; }
|
|
132
|
+
.text-action {
|
|
133
|
+
display: inline-flex; align-items: center; min-height: 24px; vertical-align: middle;
|
|
134
|
+
margin: -2px 0; padding: 0 2px; border: 0; background: none; cursor: pointer;
|
|
135
|
+
font: inherit; font-weight: 500; color: var(--cm-text-default);
|
|
136
|
+
text-decoration: underline; text-underline-offset: 3px; border-radius: var(--cm-radius-xs);
|
|
137
|
+
}
|
|
138
|
+
.text-action:hover { text-decoration-thickness: 2px; }
|
|
139
|
+
.text-action:focus-visible { outline: 2px solid var(--cm-border-strong); outline-offset: 2px; }
|
|
140
|
+
.inline .text-action { display: inline; min-height: 0; vertical-align: baseline; margin: 0; margin-inline-start: var(--cm-space-10); padding-block: 2px; }
|
|
87
141
|
@media (max-width: 640px) {
|
|
88
142
|
.circle { width: 200px; height: 200px; }
|
|
89
143
|
.title { margin-top: 30px; font-size: 14px; }
|