@iyulab/components 1.57.0 → 1.58.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/dist/assets/locales/ar.json.js +12 -2
  3. package/dist/assets/locales/de.json.js +12 -2
  4. package/dist/assets/locales/en.json.js +12 -2
  5. package/dist/assets/locales/es.json.js +14 -2
  6. package/dist/assets/locales/fr.json.js +12 -2
  7. package/dist/assets/locales/id.json.js +12 -2
  8. package/dist/assets/locales/ja.json.js +14 -2
  9. package/dist/assets/locales/ko.json.js +14 -2
  10. package/dist/assets/locales/pt-BR.json.js +12 -2
  11. package/dist/assets/locales/ru.json.js +12 -2
  12. package/dist/assets/locales/th.json.js +14 -2
  13. package/dist/assets/locales/vi.json.js +12 -2
  14. package/dist/assets/locales/zh-CN.json.js +14 -2
  15. package/dist/assets/locales/zh-TW.json.js +14 -2
  16. package/dist/components/calendar/UCalendar.d.ts +4 -0
  17. package/dist/components/calendar/UCalendar.js +5 -4
  18. package/dist/components/calendar/date-text-controller.d.ts +62 -0
  19. package/dist/components/calendar/date-text-controller.js +90 -0
  20. package/dist/components/calendar/dates.d.ts +4 -0
  21. package/dist/components/calendar/dates.js +5 -1
  22. package/dist/components/calendar/datetime.d.ts +14 -0
  23. package/dist/components/calendar/datetime.js +35 -0
  24. package/dist/components/calendar/picker.styles.js +35 -0
  25. package/dist/components/carousel/UCarousel.d.ts +7 -1
  26. package/dist/components/carousel/UCarousel.js +8 -1
  27. package/dist/components/date-picker/UDatePicker.d.ts +33 -21
  28. package/dist/components/date-picker/UDatePicker.js +128 -103
  29. package/dist/components/date-picker/UDatePicker.styles.js +0 -19
  30. package/dist/components/date-range-picker/UDateRangePicker.d.ts +71 -24
  31. package/dist/components/date-range-picker/UDateRangePicker.js +233 -103
  32. package/dist/index.js +2 -2
  33. package/dist/utilities/Locale.d.ts +2 -2
  34. package/dist/utilities/Locale.js +2 -2
  35. package/dist/utilities/format.d.ts +32 -4
  36. package/dist/utilities/format.js +131 -15
  37. package/package.json +1 -1
  38. package/skills/iyulab-components/references/components/carousel.md +3 -1
  39. package/skills/iyulab-components/references/components/date-picker.md +34 -2
  40. package/skills/iyulab-components/references/components/date-range-picker.md +52 -5
  41. package/skills/iyulab-components/references/utilities/locale.md +1 -1
@@ -5,11 +5,13 @@ import "../button/UButton.js";
5
5
  import { devWarnOnce } from "../../utilities/devWarning.js";
6
6
  import "../icon/UIcon.js";
7
7
  import { Locale } from "../../utilities/Locale.js";
8
- import { dateTextPattern, formatDateRangeText, parseDateRange } from "../../utilities/format.js";
8
+ import { dateTextPattern, formatDateRangeText, formatDateTimeRangeText, parseDateRange, parseDateTimeRange } from "../../utilities/format.js";
9
9
  import { parseISODate } from "../calendar/dates.js";
10
10
  import { UCalendar } from "../calendar/UCalendar.js";
11
11
  import "../field/UField.js";
12
12
  import { UPopover } from "../popover/UPopover.js";
13
+ import { DateTextController } from "../calendar/date-text-controller.js";
14
+ import { normalizeTime, splitDateTime, toDateTimeOffset } from "../calendar/datetime.js";
13
15
  import { styles } from "../calendar/picker.styles.js";
14
16
  import { resolvePresets } from "./presets.js";
15
17
  import { styles as styles$1 } from "./UDateRangePicker.styles.js";
@@ -18,66 +20,67 @@ import { customElement, property, query, state } from "lit/decorators.js";
18
20
  import { ifDefined } from "lit/directives/if-defined.js";
19
21
  //#region src/components/date-range-picker/UDateRangePicker.ts
20
22
  var ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
21
- /** Splits `"start/end"` into its two ISO dates — `undefined` unless both halves are ISO dates. */
22
- function parseInterval(value) {
23
+ var ISO_DATE_TIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/;
24
+ /** Splits `"start/end"` into its two halves — ISO dates, or in `mode="datetime"` ISO date-times;
25
+ * `undefined` unless both halves have that shape. */
26
+ function parseInterval(value, mode) {
23
27
  if (!value) return void 0;
24
28
  const [start, end, ...rest] = value.split("/");
25
- if (rest.length || !ISO_DATE.test(start ?? "") || !ISO_DATE.test(end ?? "")) return void 0;
29
+ const shape = mode === "datetime" ? ISO_DATE_TIME : ISO_DATE;
30
+ if (rest.length || !shape.test(start ?? "") || !shape.test(end ?? "")) return void 0;
26
31
  return {
27
32
  start,
28
33
  end
29
34
  };
30
35
  }
36
+ /** Whether `start` comes after `end` — by day in `date` mode, by instant in `datetime` mode. */
37
+ function reversed(start, end, mode) {
38
+ return mode === "datetime" ? new Date(start).getTime() > new Date(end).getTime() : start > end;
39
+ }
40
+ /** The ISO day of a half (`YYYY-MM-DD` either way). */
41
+ var dayPart = (half) => half.slice(0, 10);
31
42
  var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
32
43
  constructor(..._args) {
33
44
  super(..._args);
34
45
  this.clearable = false;
35
46
  this.format = "iso";
36
47
  this.presets = [];
48
+ this.confirm = false;
49
+ this.mode = "date";
50
+ this.seconds = false;
37
51
  this.calendarId = `u-date-range-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
38
52
  this.open = false;
39
- this.draft = null;
40
- this.badText = false;
41
- this.focusCalendarOnOpen = false;
53
+ this.textEntry = new DateTextController(this, {
54
+ toValue: (text) => {
55
+ if (!text.trim()) return void 0;
56
+ const range = this.parseTyped(text);
57
+ if (!range) return null;
58
+ return this.build(dayPart(range.start), dayPart(range.end), {
59
+ start: range.start.slice(11) || this.wholeDay.start,
60
+ end: range.end.slice(11) || this.wholeDay.end
61
+ });
62
+ },
63
+ dayOf: (text) => {
64
+ const start = this.parseTyped(text)?.start;
65
+ return start ? dayPart(start) : null;
66
+ },
67
+ shown: () => {
68
+ const range = parseInterval(this.value, this.mode);
69
+ if (!range) return this.value ?? "";
70
+ return this.mode === "datetime" ? formatDateTimeRangeText(range.start, range.end, this.format, void 0, this.seconds) : formatDateRangeText(range.start, range.end, this.format);
71
+ },
72
+ onChange: () => this.emitChange(),
73
+ onBadText: () => {
74
+ if (!this.novalidate) this.validate();
75
+ },
76
+ popover: () => this.popoverEl,
77
+ calendar: () => this.calendarEl,
78
+ container: () => this.containerEl,
79
+ input: () => this.textInputEl,
80
+ interactive: () => !this.effectivelyDisabled && !this.readonly
81
+ });
42
82
  this.handleRangeSelect = (e) => {
43
- this.commitRange(e.detail.start, e.detail.end);
44
- };
45
- this.handleContainerClick = (e) => {
46
- if (e.target.closest?.("u-icon")) return;
47
- const input = this.textInputEl;
48
- if (input && this.renderRoot instanceof ShadowRoot && this.renderRoot.activeElement !== input) input.focus();
49
- this.openCalendar(false);
50
- };
51
- this.handleCalendarButtonClick = (e) => {
52
- e.stopPropagation();
53
- if (this.open) {
54
- this.popoverEl?.hide();
55
- this.textInputEl?.focus();
56
- } else this.openCalendar(true);
57
- };
58
- this.handleTextInput = (e) => {
59
- this.draft = e.target.value;
60
- const typed = parseDateRange(this.draft, { format: this.format });
61
- if (typed && this.open) this.calendarEl?.showDate(typed.start);
62
- };
63
- this.handleTextKeydown = (e) => {
64
- if (e.key === "ArrowDown") {
65
- e.preventDefault();
66
- this.commitText();
67
- this.openCalendar(true);
68
- } else if (e.key === "Enter" && !e.isComposing) this.commitText();
69
- };
70
- this.commitText = () => {
71
- if (this.draft === null) return;
72
- const text = this.draft;
73
- const range = parseDateRange(text, { format: this.format });
74
- this.badText = !!text.trim() && range === null;
75
- const next = range ? `${range.start}/${range.end}` : void 0;
76
- const changed = next !== this.value;
77
- this.value = next;
78
- this.draft = this.badText ? text : null;
79
- if (changed) this.emitChange();
80
- else if (this.badText && !this.novalidate) this.validate();
83
+ this.commitRange(e.detail.start, e.detail.end, this.workingTimes());
81
84
  };
82
85
  this.handleCalendarKeydown = (e) => {
83
86
  if (e.key !== "Escape") return;
@@ -98,10 +101,21 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
98
101
  this.textInputEl?.focus();
99
102
  };
100
103
  this.handleFooterResetClick = () => {
104
+ if (this.confirm) {
105
+ this.staged = void 0;
106
+ return;
107
+ }
101
108
  this.resetValue();
102
109
  this.popoverEl?.hide();
103
110
  this.textInputEl?.focus();
104
111
  };
112
+ this.handleApplyClick = () => {
113
+ this.commitValue(this.staged);
114
+ };
115
+ this.handleCancelClick = () => {
116
+ this.popoverEl?.hide();
117
+ this.textInputEl?.focus();
118
+ };
105
119
  this.handleClearKeydown = (e) => {
106
120
  if (e.key !== "Enter" && e.key !== " ") return;
107
121
  e.preventDefault();
@@ -115,41 +129,78 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
115
129
  styles$1
116
130
  ];
117
131
  }
118
- /** First day of the range (ISO), or `undefined` when there is no complete range. */
132
+ /** Start of the range — the ISO day, or in `mode="datetime"` the ISO date-time; `undefined` when
133
+ * there is no complete range. */
119
134
  get start() {
120
- return parseInterval(this.value)?.start;
135
+ return parseInterval(this.value, this.mode)?.start;
121
136
  }
122
- /** Last day of the range (ISO), or `undefined` when there is no complete range. */
137
+ /** End of the range — the ISO day, or in `mode="datetime"` the ISO date-time; `undefined` when
138
+ * there is no complete range. */
123
139
  get end() {
124
- return parseInterval(this.value)?.end;
140
+ return parseInterval(this.value, this.mode)?.end;
141
+ }
142
+ /** Times a whole-day range takes in `mode="datetime"` — a preset or a first calendar pick: from
143
+ * the first minute (or second, with `seconds`) to the last. */
144
+ get wholeDay() {
145
+ return this.seconds ? {
146
+ start: "00:00:00",
147
+ end: "23:59:59"
148
+ } : {
149
+ start: "00:00",
150
+ end: "23:59"
151
+ };
125
152
  }
126
153
  willUpdate(changed) {
127
154
  super.willUpdate(changed);
128
155
  if (changed.has("value")) {
129
- const range = parseInterval(this.value);
130
- if (range && range.start > range.end) this.value = `${range.end}/${range.start}`;
156
+ const range = parseInterval(this.value, this.mode);
157
+ if (range && reversed(range.start, range.end, this.mode)) this.value = `${range.end}/${range.start}`;
131
158
  }
159
+ if (this.open && (changed.has("open") || changed.has("value"))) this.staged = this.value;
160
+ }
161
+ /** What the open calendar shows and edits: the staged range with `confirm`, otherwise the value. */
162
+ get working() {
163
+ return this.confirm && this.open ? this.staged : this.value;
164
+ }
165
+ /** The times the working range has — or, without one, the ones the next range takes. */
166
+ workingTimes() {
167
+ const range = parseInterval(this.working, this.mode);
168
+ if (this.mode !== "datetime" || !range) return this.pendingTimes ?? this.wholeDay;
169
+ return {
170
+ start: splitDateTime(range.start, true).time,
171
+ end: splitDateTime(range.end, true).time
172
+ };
173
+ }
174
+ /** The value for two days (and, in `mode="datetime"`, two times), earlier first. */
175
+ build(startDay, endDay, times) {
176
+ if (this.mode !== "datetime") return `${startDay}/${endDay}`;
177
+ const start = toDateTimeOffset(startDay, times.start);
178
+ const end = toDateTimeOffset(endDay, times.end);
179
+ return reversed(start, end, this.mode) ? `${end}/${start}` : `${start}/${end}`;
180
+ }
181
+ /** Typed text as a range — days, or in `mode="datetime"` local date-times. A day typed without a
182
+ * time keeps the working range's time at that end. */
183
+ parseTyped(text) {
184
+ if (this.mode !== "datetime") return parseDateRange(text, { format: this.format });
185
+ const times = this.workingTimes();
186
+ return parseDateTimeRange(text, {
187
+ format: this.format,
188
+ startTime: times.start,
189
+ endTime: times.end,
190
+ seconds: this.seconds
191
+ });
132
192
  }
133
193
  shouldValidate(changed) {
134
- return super.shouldValidate(changed) || changed.has("min") || changed.has("max");
194
+ return super.shouldValidate(changed) || changed.has("min") || changed.has("max") || changed.has("isDateDisabled");
135
195
  }
136
196
  updated(changed) {
137
197
  super.updated(changed);
138
198
  if (changed.has("value")) this.internals?.setFormValue(this.value ?? "");
139
199
  if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
140
- if (changed.has("open") && this.open) {
141
- const calendar = this.calendarEl;
142
- const typed = this.draft !== null ? parseDateRange(this.draft, { format: this.format }) : null;
143
- calendar?.showDate(typed?.start ?? this.start ?? /* @__PURE__ */ new Date());
144
- const moveFocus = this.focusCalendarOnOpen;
145
- this.focusCalendarOnOpen = false;
146
- if (moveFocus) this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
147
- }
200
+ if (changed.has("open") && this.open) this.textEntry.calendarOpened(this.start ? dayPart(this.start) : /* @__PURE__ */ new Date());
148
201
  }
149
202
  render() {
150
- const range = parseInterval(this.value);
151
- const shown = range ? formatDateRangeText(range.start, range.end, this.format) : this.value ?? "";
152
- const pattern = dateTextPattern(this.format);
203
+ const pattern = this.mode === "datetime" ? `${dateTextPattern(this.format)} ${this.seconds ? "HH:mm:ss" : "HH:mm"}` : dateTextPattern(this.format);
153
204
  return html`
154
205
  <u-field part="field"
155
206
  ?required=${this.required}
@@ -159,7 +210,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
159
210
  .description=${this.description}
160
211
  .validationMessage=${this.validationMessage}
161
212
  >
162
- <div class="container" part="container" @click=${this.handleContainerClick}>
213
+ <div class="container" part="container" @click=${this.textEntry.handleContainerClick}>
163
214
  <input class="text-input" part="input"
164
215
  type="text"
165
216
  autocomplete="off"
@@ -169,14 +220,14 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
169
220
  aria-controls=${this.calendarId}
170
221
  aria-label=${ifDefined(this.resolvedAriaLabel)}
171
222
  aria-description=${ifDefined(this.resolvedAriaDescription)}
172
- aria-invalid=${this.badText ? "true" : "false"}
223
+ aria-invalid=${this.textEntry.badText ? "true" : "false"}
173
224
  placeholder=${this.placeholder ?? `${pattern} – ${pattern}`}
174
- .value=${this.draft ?? shown}
225
+ .value=${this.textEntry.text}
175
226
  ?disabled=${this.effectivelyDisabled}
176
227
  ?readonly=${this.readonly}
177
- @input=${this.handleTextInput}
178
- @keydown=${this.handleTextKeydown}
179
- @blur=${this.commitText}
228
+ @input=${this.textEntry.handleInput}
229
+ @keydown=${this.textEntry.handleKeydown}
230
+ @blur=${this.textEntry.commit}
180
231
  />
181
232
  <u-icon class="suffix-item"
182
233
  ?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
@@ -195,7 +246,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
195
246
  ?hidden=${this.effectivelyDisabled || this.readonly}
196
247
  lib="internal"
197
248
  name="calendar"
198
- @click=${this.handleCalendarButtonClick}
249
+ @click=${this.textEntry.handleCalendarButtonClick}
199
250
  ></u-icon>
200
251
  </div>
201
252
  </u-field>
@@ -219,6 +270,8 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
219
270
  }
220
271
  renderCalendar() {
221
272
  const presets = resolvePresets(this.presets, /* @__PURE__ */ new Date(), (name) => devWarnOnce(`date-range-preset:${name}`, `u-date-range-picker: unknown preset "${name}" — it is not listed.`));
273
+ const working = parseInterval(this.working, this.mode);
274
+ const showClear = this.clearable && !!this.working;
222
275
  return html`
223
276
  <div class="body">
224
277
  ${presets.length ? this.renderPresets(presets) : ""}
@@ -227,46 +280,114 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
227
280
  exportparts="calendar-month, calendar-header, calendar-title, calendar-weekdays, calendar-grid, calendar-week, day"
228
281
  selection="range"
229
282
  visible-months="2"
230
- .start=${this.start}
231
- .end=${this.end}
283
+ .start=${working && dayPart(working.start)}
284
+ .end=${working && dayPart(working.end)}
232
285
  .min=${this.min}
233
286
  .max=${this.max}
287
+ .isDateDisabled=${this.isDateDisabled}
234
288
  @range-select=${this.handleRangeSelect}
235
289
  @keydown=${this.handleCalendarKeydown}
236
290
  ></u-calendar>
237
- ${this.clearable && this.value ? html`
291
+ ${this.renderTimeRow()}
292
+ ${showClear || this.confirm ? html`
238
293
  <div class="calendar-footer" part="calendar-footer">
239
- <u-button variant="ghost" size="sm" @click=${this.handleFooterResetClick}>${Locale.getValue("clear")}</u-button>
294
+ ${showClear ? html`
295
+ <u-button variant="ghost" size="sm" @click=${this.handleFooterResetClick}>${Locale.getValue("clear")}</u-button>
296
+ ` : ""}
297
+ ${this.confirm ? html`
298
+ <span class="confirm-actions">
299
+ <u-button variant="ghost" size="sm" @click=${this.handleCancelClick}>${Locale.getValue("cancel")}</u-button>
300
+ <u-button size="sm" @click=${this.handleApplyClick}>${Locale.getValue("apply")}</u-button>
301
+ </span>
302
+ ` : ""}
240
303
  </div>
241
304
  ` : ""}
242
305
  </div>
243
306
  </div>
244
307
  `;
245
308
  }
309
+ renderTimeRow() {
310
+ if (this.mode !== "datetime") return "";
311
+ const times = this.workingTimes();
312
+ return html`
313
+ <div class="calendar-time" part="calendar-time">
314
+ <label class="time-field">${Locale.getValue("startTime")}
315
+ <input type="time" class="time-input" part="time-input"
316
+ step=${ifDefined(this.seconds ? "1" : void 0)}
317
+ .value=${normalizeTime(times.start, this.seconds)}
318
+ @change=${(e) => this.handleTimeChange("start", e)}
319
+ />
320
+ </label>
321
+ <label class="time-field">${Locale.getValue("endTime")}
322
+ <input type="time" class="time-input" part="time-input"
323
+ step=${ifDefined(this.seconds ? "1" : void 0)}
324
+ .value=${normalizeTime(times.end, this.seconds)}
325
+ @change=${(e) => this.handleTimeChange("end", e)}
326
+ />
327
+ </label>
328
+ </div>
329
+ `;
330
+ }
331
+ /** A time input changed — with a range, that end moves (committed at once, or staged with
332
+ * `confirm`; the calendar stays open); without one, the next range takes it. A start time set
333
+ * after the end on the same day swaps the two, as a reversed range always is. */
334
+ handleTimeChange(which, e) {
335
+ const time = normalizeTime(e.target.value || this.wholeDay[which], this.seconds);
336
+ const times = {
337
+ ...this.workingTimes(),
338
+ [which]: time
339
+ };
340
+ this.pendingTimes = times;
341
+ const range = parseInterval(this.working, this.mode);
342
+ if (!range) return;
343
+ const next = this.build(dayPart(range.start), dayPart(range.end), times);
344
+ if (this.confirm) {
345
+ this.staged = next;
346
+ return;
347
+ }
348
+ const changed = next !== this.value;
349
+ this.textEntry.clear();
350
+ this.value = next;
351
+ if (changed) this.emitChange();
352
+ }
246
353
  renderPresets(presets) {
247
354
  return html`
248
355
  <div class="presets" part="presets" role="group" aria-label=${Locale.getValue("quickRanges")}>
249
356
  ${presets.map((p) => html`
250
357
  <button type="button" class="preset" part="preset"
251
- aria-pressed=${`${p.start}/${p.end}` === this.value}
252
- ?disabled=${this.outOfBounds(p)}
253
- @click=${() => this.commitRange(p.start, p.end)}
358
+ aria-pressed=${this.build(p.start, p.end, this.wholeDay) === this.working}
359
+ ?disabled=${this.unavailable(p)}
360
+ @click=${() => this.commitRange(p.start, p.end, this.wholeDay)}
254
361
  >${p.label}</button>
255
362
  `)}
256
363
  </div>
257
364
  `;
258
365
  }
259
- /** A preset that reaches outside `min`/`max` is not offered — its label would promise more
260
- * than the picker may hold. */
261
- outOfBounds(p) {
262
- return !!this.min && p.start < this.min || !!this.max && p.end > this.max;
366
+ /** A preset that reaches outside `min`/`max`, or starts or ends on a disabled day, is not
367
+ * offered — its label would promise a range the calendar itself refuses. */
368
+ unavailable(p) {
369
+ return !!this.min && p.start < this.min || !!this.max && p.end > this.max || this.endpointDisabled(p);
370
+ }
371
+ /** Whether `isDateDisabled` refuses either end of the range (the days between may be disabled). */
372
+ endpointDisabled(p) {
373
+ return !!this.isDateDisabled && (this.isDateDisabled(dayPart(p.start)) || this.isDateDisabled(dayPart(p.end)));
374
+ }
375
+ /** A user-chosen range of days (calendar or preset) at `times` (`mode="datetime"`): set it,
376
+ * announce it, close the calendar — or, with `confirm`, stage it for Apply. A calendar pick keeps
377
+ * the times already set; a preset covers its days whole. */
378
+ commitRange(start, end, times) {
379
+ const next = this.build(start, end, times);
380
+ if (this.confirm) {
381
+ this.staged = next;
382
+ return;
383
+ }
384
+ this.commitValue(next);
263
385
  }
264
- /** A user-chosen range (calendar or preset): set it, announce it, close the calendar. */
265
- commitRange(start, end) {
266
- const next = `${start}/${end}`;
386
+ /** Commits `next` as the value (firing `change` when it differs), closes the calendar and
387
+ * returns focus to the text box. */
388
+ commitValue(next) {
267
389
  const changed = next !== this.value;
268
- this.draft = null;
269
- this.badText = false;
390
+ this.textEntry.clear();
270
391
  this.value = next;
271
392
  if (changed) this.emitChange();
272
393
  this.popoverEl?.hide();
@@ -275,19 +396,9 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
275
396
  get textInputEl() {
276
397
  return this.renderRoot.querySelector(".text-input");
277
398
  }
278
- openCalendar(focusGrid) {
279
- if (this.effectivelyDisabled || this.readonly) return;
280
- if (this.open) {
281
- if (focusGrid) this.calendarEl?.focusDay();
282
- return;
283
- }
284
- this.focusCalendarOnOpen = focusGrid;
285
- if (this.containerEl) this.popoverEl?.show(this.containerEl);
286
- }
287
399
  resetValue() {
288
400
  const hadValue = !!this.value;
289
- this.draft = null;
290
- this.badText = false;
401
+ this.textEntry.clear();
291
402
  this.value = void 0;
292
403
  if (hadValue) this.emitChange();
293
404
  }
@@ -301,8 +412,12 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
301
412
  setValidity() {
302
413
  let flags = {};
303
414
  let message = "";
304
- const range = parseInterval(this.value);
305
- if (this.badText) {
415
+ const parsed = parseInterval(this.value, this.mode);
416
+ const range = parsed && {
417
+ start: dayPart(parsed.start),
418
+ end: dayPart(parsed.end)
419
+ };
420
+ if (this.textEntry.badText) {
306
421
  flags = { badInput: true };
307
422
  message = Locale.getValue("badInput");
308
423
  } else if (this.required && !this.value) {
@@ -317,13 +432,15 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
317
432
  } else if (range && this.max && parseISODate(range.end) > parseISODate(this.max)) {
318
433
  flags = { rangeOverflow: true };
319
434
  message = Locale.getValue("rangeOverflow", { max: this.max });
435
+ } else if (range && this.endpointDisabled(range)) {
436
+ flags = { stepMismatch: true };
437
+ message = Locale.getValue("dateUnavailable");
320
438
  }
321
439
  this.commit(flags, message, this.textInputEl ?? this.containerEl ?? void 0);
322
440
  }
323
441
  reset() {
324
442
  this.value = void 0;
325
- this.draft = null;
326
- this.badText = false;
443
+ this.textEntry.clear();
327
444
  this.invalid = false;
328
445
  }
329
446
  focus(options) {
@@ -340,6 +457,7 @@ __decorate([property({
340
457
  type: Boolean,
341
458
  reflect: true
342
459
  }), __decorateMetadata("design:type", Boolean)], UDateRangePicker.prototype, "clearable", void 0);
460
+ __decorate([property({ attribute: false }), __decorateMetadata("design:type", Object)], UDateRangePicker.prototype, "isDateDisabled", void 0);
343
461
  __decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "placeholder", void 0);
344
462
  __decorate([property({
345
463
  type: String,
@@ -349,12 +467,24 @@ __decorate([property({
349
467
  attribute: "presets",
350
468
  converter: { fromAttribute: (v) => (v ?? "").split(/\s+/).filter(Boolean) }
351
469
  }), __decorateMetadata("design:type", Array)], UDateRangePicker.prototype, "presets", void 0);
470
+ __decorate([property({
471
+ type: Boolean,
472
+ reflect: true
473
+ }), __decorateMetadata("design:type", Boolean)], UDateRangePicker.prototype, "confirm", void 0);
474
+ __decorate([property({
475
+ type: String,
476
+ reflect: true
477
+ }), __decorateMetadata("design:type", Object)], UDateRangePicker.prototype, "mode", void 0);
478
+ __decorate([property({
479
+ type: Boolean,
480
+ reflect: true
481
+ }), __decorateMetadata("design:type", Boolean)], UDateRangePicker.prototype, "seconds", void 0);
352
482
  __decorate([query(".container", true), __decorateMetadata("design:type", typeof HTMLElement === "undefined" ? Object : HTMLElement)], UDateRangePicker.prototype, "containerEl", void 0);
353
483
  __decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDateRangePicker.prototype, "popoverEl", void 0);
354
484
  __decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDateRangePicker.prototype, "calendarEl", void 0);
355
485
  __decorate([state(), __decorateMetadata("design:type", Boolean)], UDateRangePicker.prototype, "open", void 0);
356
- __decorate([state(), __decorateMetadata("design:type", Object)], UDateRangePicker.prototype, "draft", void 0);
357
- __decorate([state(), __decorateMetadata("design:type", Object)], UDateRangePicker.prototype, "badText", void 0);
486
+ __decorate([state(), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "staged", void 0);
487
+ __decorate([state(), __decorateMetadata("design:type", Object)], UDateRangePicker.prototype, "pendingTimes", void 0);
358
488
  UDateRangePicker = __decorate([customElement("u-date-range-picker")], UDateRangePicker);
359
489
  //#endregion
360
490
  export { UDateRangePicker };
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ import { UCheckbox } from "./components/checkbox/UCheckbox.js";
26
26
  import { UTag } from "./components/tag/UTag.js";
27
27
  import { UChip } from "./components/chip/UChip.js";
28
28
  import { UCopyButton } from "./components/copy-button/UCopyButton.js";
29
- import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeText, formatNumber, parseDate, parseDateRange, parseDateTime, parseNumber } from "./utilities/format.js";
29
+ import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber } from "./utilities/format.js";
30
30
  import { UField } from "./components/field/UField.js";
31
31
  import { UPopover } from "./components/popover/UPopover.js";
32
32
  import { UDatePicker } from "./components/date-picker/UDatePicker.js";
@@ -62,4 +62,4 @@ import { Dialog } from "./utilities/Dialog.js";
62
62
  import { Theme } from "./utilities/Theme.js";
63
63
  import { Toast } from "./utilities/Toast.js";
64
64
  import { decodeTsv, encodeTsv } from "./utilities/tsv.js";
65
- export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDateRangePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOverlayElement, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, createDevWarner, dateAttrConverter, dateTextPattern, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, parseDateRange, parseDateTime, parseNumber, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
65
+ export { ALERT_STATUSES, BrowserStorage, Dialog, IconCache, IconRegistry, Locale, OverlayManager, Theme, Toast, UAlert, UAvatar, UBadge, UBreadcrumb, UBreadcrumbItem, UButton, UButtonGroup, UCard, UCarousel, UCheckbox, UChip, UCopyButton, UDatePicker, UDateRangePicker, UDialog, UDivider, UDrawer, UElement, UExpander, UField, UFileInput, UFloatingElement, UForm, UFormControlElement, UIcon, UIconButton, UInput, UMenu, UMenuItem, UOption, UOverlayElement, UPanel, UPopover, UProgressBar, UProgressRing, URadio, URating, USelect, USkeleton, USlider, USpinner, USplitPanel, USwitch, UTab, UTabPanel, UTag, UText, UTextarea, UTooltip, UTree, UTreeItem, arrayAttrConverter, booleanAttrConverter, createDevWarner, dateAttrConverter, dateTextPattern, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeRangeText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, parseDateRange, parseDateTime, parseDateTimeRange, parseNumber, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
@@ -12,7 +12,7 @@ export type SupportedLocale = 'en' | 'ko' | 'ja' | 'zh-CN' | 'zh-TW' | 'es' | 'f
12
12
  /** 내장 로케일은 자동완성되지만, 임의의 BCP47 태그도 그대로 받는다. */
13
13
  export type LocaleTag = SupportedLocale | (string & {});
14
14
  /** 라이브러리가 제공하는 chrome 문자열 키. 지금은 검증 메시지뿐이지만 이후 다른 UI 문구도 추가될 수 있다. */
15
- export type LocaleMessageKey = 'valueMissing' | 'badInput' | 'typeMismatch' | 'patternMismatch' | 'rangeUnderflow' | 'rangeOverflow' | 'stepMismatch' | 'tooShort' | 'tooLong' | 'increment' | 'decrement' | 'clear' | 'today' | 'time' | 'showPassword' | 'hidePassword' | 'previousSlide' | 'nextSlide' | 'goToSlide' | 'stopSlideRotation' | 'startSlideRotation' | 'chooseDate' | 'chooseDateRange' | 'yesterday' | 'last7Days' | 'last30Days' | 'thisWeek' | 'lastWeek' | 'thisMonth' | 'lastMonth' | 'thisYear' | 'quickRanges' | 'rangeStartChosen' | 'previousMonth' | 'nextMonth' | 'close' | 'copy' | 'copied' | 'chooseFile' | 'noFileChosen' | 'filesSelected' | 'resizePanels' | 'breadcrumb' | 'search' | 'alertError' | 'alertWarning' | 'alertSuccess' | 'alertInfo' | 'alertNotice' | 'alertMessage' | 'remove' | 'closeTab' | 'confirm' | 'cancel';
15
+ export type LocaleMessageKey = 'valueMissing' | 'badInput' | 'typeMismatch' | 'patternMismatch' | 'rangeUnderflow' | 'rangeOverflow' | 'stepMismatch' | 'tooShort' | 'tooLong' | 'increment' | 'decrement' | 'clear' | 'today' | 'time' | 'showPassword' | 'hidePassword' | 'previousSlide' | 'nextSlide' | 'goToSlide' | 'stopSlideRotation' | 'startSlideRotation' | 'chooseDate' | 'chooseDateRange' | 'yesterday' | 'last7Days' | 'last30Days' | 'thisWeek' | 'lastWeek' | 'thisMonth' | 'lastMonth' | 'thisYear' | 'quickRanges' | 'rangeStartChosen' | 'previousMonth' | 'nextMonth' | 'close' | 'copy' | 'copied' | 'chooseFile' | 'noFileChosen' | 'filesSelected' | 'resizePanels' | 'breadcrumb' | 'search' | 'alertError' | 'alertWarning' | 'alertSuccess' | 'alertInfo' | 'alertNotice' | 'alertMessage' | 'remove' | 'closeTab' | 'confirm' | 'cancel' | 'apply' | 'dateUnavailable' | 'startTime' | 'endTime' | 'timeAm' | 'timePm';
16
16
  type LocaleTable = Record<LocaleMessageKey, string>;
17
17
  /**
18
18
  * 한 패키지(또는 앱 영역)의 문자열 묶음.
@@ -64,7 +64,7 @@ export declare class Locale {
64
64
  * 현재 활성 로케일 기준으로 메시지를 조회합니다.
65
65
  * `params`가 있으면 템플릿의 `{name}` 자리를 치환합니다.
66
66
  */
67
- static getValue(key: LocaleMessageKey, params?: Record<string, string | number>): string;
67
+ static getValue(key: LocaleMessageKey, params?: Record<string, string | number>, locale?: LocaleTag): string;
68
68
  /**
69
69
  * 네임스페이스 핸들을 얻습니다 — 같은 이름이면 **같은 저장소**를 가리킵니다.
70
70
  *
@@ -125,8 +125,8 @@ var Locale = class {
125
125
  * 현재 활성 로케일 기준으로 메시지를 조회합니다.
126
126
  * `params`가 있으면 템플릿의 `{name}` 자리를 치환합니다.
127
127
  */
128
- static getValue(key, params) {
129
- return interpolate(lookup(active, key), params);
128
+ static getValue(key, params, locale) {
129
+ return interpolate(lookup(locale ?? active, key), params);
130
130
  }
131
131
  /**
132
132
  * 네임스페이스 핸들을 얻습니다 — 같은 이름이면 **같은 저장소**를 가리킵니다.
@@ -84,17 +84,22 @@ export declare function parseDate(text: string, options?: {
84
84
  /**
85
85
  * Reads a date and a time of day as people type them and returns local `YYYY-MM-DDTHH:mm`, or `null`.
86
86
  * The date part is anything {@link parseDate} reads; the time follows a space or `T` as `HH:mm`
87
- * (`9:05`, `09:05`, `09:05:30` — seconds are dropped). Text with only a date takes `defaultTime`
88
- * (`00:00` unless given). An hour above 23 or a minute above 59 is `null`.
87
+ * (`9:05`, `09:05`, `09:05:30` — seconds are dropped). With `seconds`, the result is
88
+ * `YYYY-MM-DDTHH:mm:ss` and typed seconds are kept (`:00` when none are typed). Text with only a date
89
+ * takes `defaultTime` (`00:00` unless given). An hour above 23, or a minute or second above 59, is `null`.
89
90
  */
90
91
  export declare function parseDateTime(text: string, options?: {
91
92
  format?: DateTextFormat;
92
93
  locale?: LocaleTag;
93
94
  referenceDate?: Date;
94
95
  defaultTime?: string;
96
+ seconds?: boolean;
95
97
  }): string | null;
96
- /** Writes local `YYYY-MM-DDTHH:mm` (or a longer ISO date-time) as `{date} HH:mm`, the date part as {@link formatDateText} writes it. */
97
- export declare function formatDateTimeText(isoLocal: string, format?: DateTextFormat, locale?: LocaleTag): string;
98
+ /**
99
+ * Writes local `YYYY-MM-DDTHH:mm` (or a longer ISO date-time) as `{date} HH:mm`, the date part as
100
+ * {@link formatDateText} writes it — `{date} HH:mm:ss` with `seconds`.
101
+ */
102
+ export declare function formatDateTimeText(isoLocal: string, format?: DateTextFormat, locale?: LocaleTag, seconds?: boolean): string;
98
103
  /**
99
104
  * Reads a period of days as people type it — `2026-10-01 ~ 2026-10-31`, `2026-10-01 – 10-31`,
100
105
  * the ISO interval `2026-10-01/2026-10-31`, or a single day (a one-day range) — and returns
@@ -112,3 +117,26 @@ export declare function parseDateRange(text: string, options?: {
112
117
  } | null;
113
118
  /** Writes a period as `{start} – {end}`, each day as {@link formatDateText} writes it. */
114
119
  export declare function formatDateRangeText(start: string, end: string, format?: DateTextFormat, locale?: LocaleTag): string;
120
+ /**
121
+ * Reads a period with times of day — `2026-10-01 09:00 ~ 2026-10-31 18:00`, `2026-10-01 09:00 ~ 18:00`
122
+ * (a time alone ends on the first day), the ISO interval `2026-10-01T09:00/2026-10-31T18:00`, or the
123
+ * day forms {@link parseDateRange} reads — and returns `{ start, end }` as local `YYYY-MM-DDTHH:mm`,
124
+ * earlier first, or `null`. A day typed without a time takes `startTime` (default `00:00`) at the
125
+ * start and `endTime` (default `23:59`) at the end, so a period of days covers them whole; one day
126
+ * alone runs from `startTime` to `endTime` that day. A short second day takes the first day's year,
127
+ * or the next year when it would otherwise fall before the first day. With `seconds`, both ends are
128
+ * `YYYY-MM-DDTHH:mm:ss` (see {@link parseDateTime}).
129
+ */
130
+ export declare function parseDateTimeRange(text: string, options?: {
131
+ format?: DateTextFormat;
132
+ locale?: LocaleTag;
133
+ referenceDate?: Date;
134
+ startTime?: string;
135
+ endTime?: string;
136
+ seconds?: boolean;
137
+ }): {
138
+ start: string;
139
+ end: string;
140
+ } | null;
141
+ /** Writes a period with times as `{start} – {end}`, each as {@link formatDateTimeText} writes it. */
142
+ export declare function formatDateTimeRangeText(start: string, end: string, format?: DateTextFormat, locale?: LocaleTag, seconds?: boolean): string;