@iyulab/components 1.56.0 → 1.57.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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.57.0] - 2026-10-03
4
+
5
+ ### Added
6
+
7
+ - **`u-date-range-picker` takes a typed range.** The field is a text box like `u-date-picker`'s: type
8
+ `2026-10-01 ~ 2026-10-31` (also `–`, ` - `, the ISO interval with `/`, a short second day such as
9
+ `10-31`, or one day for a one-day range) and press Enter or leave the field. A second day without a
10
+ year that would fall before the first runs into the next year (`2025-12-20 ~ 01-05`). It shows
11
+ `YYYY-MM-DD – YYYY-MM-DD` in every browser language; `format="locale"` uses the locale's numeric
12
+ order. Clicking the field opens the calendar and keeps the caret in the text box; ArrowDown or
13
+ Alt+ArrowDown moves into the calendar. Text that is not a range clears the value and reports
14
+ `badInput`. New CSS part `input`.
15
+ - **`parseDateRange`, `formatDateRangeText`** next to `parseDate`.
16
+
17
+ ### Changed
18
+
19
+ - **`u-date-range-picker`: the trigger text is `YYYY-MM-DD – YYYY-MM-DD`** (was the locale's joined
20
+ range, e.g. `Mar 6 – Apr 3, 2026`) so that what is shown can be typed back, and a click keeps focus
21
+ in the text box — the same as `u-date-picker`.
22
+
3
23
  ## [1.56.0] - 2026-10-03
4
24
 
5
25
  ### Added
@@ -1,5 +1,6 @@
1
1
  import { PropertyValues } from 'lit';
2
2
  import { UFormControlElement } from '../UFormControlElement.js';
3
+ import { DateTextFormat } from '../../utilities/format.js';
3
4
  import { UCalendar } from '../calendar/UCalendar.js';
4
5
  import { UPopover } from '../popover/UPopover.js';
5
6
  import { DateRangePresetOption } from './presets.js';
@@ -12,6 +13,13 @@ export type { DateRangePreset, DateRangePresetName, DateRangePresetOption } from
12
13
  * `start` and `end` read the two halves. The picker never holds a reversed range — choosing the
13
14
  * earlier day second makes it the start, and a reversed value set from code is put in order.
14
15
  *
16
+ * The field is a text box: type `2026-10-01 ~ 2026-10-31` (also `–`, ` - `, the ISO interval with
17
+ * `/`, a short second day such as `10-31`, or one day for a one-day range) and press Enter or leave
18
+ * the field. It shows `YYYY-MM-DD – YYYY-MM-DD` whatever the browser language, or the locale's
19
+ * numeric order with `format="locale"`. Clicking the field opens the calendar and keeps the caret
20
+ * in the text box; ArrowDown (or Alt+ArrowDown) moves into the calendar. Text that is not a range
21
+ * clears the value and reports `badInput`.
22
+ *
15
23
  * The calendar shows two months. The first day chosen is an anchor and the range previews up to
16
24
  * the day under the pointer or keyboard focus; the second day completes the range, fires
17
25
  * `change` and closes the calendar. Escape while an anchor is set drops it; Escape again closes.
@@ -29,6 +37,7 @@ export type { DateRangePreset, DateRangePresetName, DateRangePresetOption } from
29
37
  * Exposes a `:state(open)` custom state while the calendar is showing.
30
38
  *
31
39
  * @csspart field - the u-field element
40
+ * @csspart input - the text box
32
41
  * @csspart container - the element wrapping the trigger area
33
42
  * @csspart popover - the popover element showing the calendar
34
43
  * @csspart calendar - the calendar container
@@ -59,8 +68,11 @@ export declare class UDateRangePicker extends UFormControlElement<string> {
59
68
  max?: string;
60
69
  /** Whether to show the clear button */
61
70
  clearable: boolean;
62
- /** Placeholder text (shown on the trigger when there is no value) */
71
+ /** Placeholder text (shown when there is no value). Defaults to the pattern to type. */
63
72
  placeholder?: string;
73
+ /** How the text box writes and reads each day: `iso` (default, `YYYY-MM-DD` in every language) or
74
+ * `locale` (the active locale's numeric order). ISO is read in both. The value is ISO either way. */
75
+ format: DateTextFormat;
64
76
  /**
65
77
  * Quick ranges listed beside the calendar, in display order — built-in names and app-defined
66
78
  * `{ label, range }` presets. As an attribute: space-separated built-in names
@@ -76,6 +88,12 @@ export declare class UDateRangePicker extends UFormControlElement<string> {
76
88
  calendarEl?: UCalendar;
77
89
  private readonly calendarId;
78
90
  private open;
91
+ /** What the person is typing, until it is committed; `null` shows the value. */
92
+ private draft;
93
+ /** The committed text was not a range — the value is empty and validity reports `badInput`. */
94
+ private badText;
95
+ /** Set when the calendar opens by keyboard (or its button): focus then moves into the grid. */
96
+ private focusCalendarOnOpen;
79
97
  protected willUpdate(changed: PropertyValues): void;
80
98
  protected shouldValidate(changed: PropertyValues): boolean;
81
99
  protected updated(changed: PropertyValues): void;
@@ -88,6 +106,18 @@ export declare class UDateRangePicker extends UFormControlElement<string> {
88
106
  private handleRangeSelect;
89
107
  /** A user-chosen range (calendar or preset): set it, announce it, close the calendar. */
90
108
  private commitRange;
109
+ private get textInputEl();
110
+ private openCalendar;
111
+ /** A click on the field (not on its clear or calendar button) opens the calendar and keeps the caret in the text box. */
112
+ private handleContainerClick;
113
+ private handleCalendarButtonClick;
114
+ private handleTextInput;
115
+ /** ArrowDown / Alt+ArrowDown opens the calendar and moves into it; Enter commits what was typed. */
116
+ private handleTextKeydown;
117
+ /** Turns the typed text into the value — empty clears it; text that is not a range clears it and
118
+ * reports `badInput` (the text stays to be fixed); a range reaching outside `min`/`max` is kept
119
+ * and reported as out of range. */
120
+ private commitText;
91
121
  /** Escape that reaches the picker closes the calendar — the calendar keeps the first Escape
92
122
  * for itself while a range is half picked. */
93
123
  private handleCalendarKeydown;
@@ -102,7 +132,6 @@ export declare class UDateRangePicker extends UFormControlElement<string> {
102
132
  private emitChange;
103
133
  protected setValidity(): void;
104
134
  reset(): void;
105
- /** `.container` is a div — no native `disabled`, so a disabled picker ignores `focus()` here. */
106
135
  focus(options?: FocusOptions): void;
107
136
  blur(): void;
108
137
  }
@@ -5,7 +5,7 @@ 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 { formatDateRange } from "../../utilities/format.js";
8
+ import { dateTextPattern, formatDateRangeText, parseDateRange } 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";
@@ -32,17 +32,58 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
32
32
  constructor(..._args) {
33
33
  super(..._args);
34
34
  this.clearable = false;
35
+ this.format = "iso";
35
36
  this.presets = [];
36
37
  this.calendarId = `u-date-range-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
37
38
  this.open = false;
39
+ this.draft = null;
40
+ this.badText = false;
41
+ this.focusCalendarOnOpen = false;
38
42
  this.handleRangeSelect = (e) => {
39
43
  this.commitRange(e.detail.start, e.detail.end);
40
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();
81
+ };
41
82
  this.handleCalendarKeydown = (e) => {
42
83
  if (e.key !== "Escape") return;
43
84
  e.preventDefault();
44
85
  this.popoverEl?.hide();
45
- this.containerEl?.focus();
86
+ this.textInputEl?.focus();
46
87
  };
47
88
  this.handlePopoverShow = () => {
48
89
  this.open = true;
@@ -54,12 +95,12 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
54
95
  e.preventDefault();
55
96
  e.stopPropagation();
56
97
  this.resetValue();
57
- this.containerEl?.focus();
98
+ this.textInputEl?.focus();
58
99
  };
59
100
  this.handleFooterResetClick = () => {
60
101
  this.resetValue();
61
102
  this.popoverEl?.hide();
62
- this.containerEl?.focus();
103
+ this.textInputEl?.focus();
63
104
  };
64
105
  this.handleClearKeydown = (e) => {
65
106
  if (e.key !== "Enter" && e.key !== " ") return;
@@ -98,13 +139,17 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
98
139
  if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
99
140
  if (changed.has("open") && this.open) {
100
141
  const calendar = this.calendarEl;
101
- calendar?.showDate(this.start ?? /* @__PURE__ */ new Date());
102
- this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
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());
103
147
  }
104
148
  }
105
149
  render() {
106
150
  const range = parseInterval(this.value);
107
- const displayText = range ? formatDateRange(range.start, range.end) : this.value ?? "";
151
+ const shown = range ? formatDateRangeText(range.start, range.end, this.format) : this.value ?? "";
152
+ const pattern = dateTextPattern(this.format);
108
153
  return html`
109
154
  <u-field part="field"
110
155
  ?required=${this.required}
@@ -114,17 +159,25 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
114
159
  .description=${this.description}
115
160
  .validationMessage=${this.validationMessage}
116
161
  >
117
- <div class="container" part="container"
118
- tabindex=${this.effectivelyDisabled ? "-1" : "0"}
119
- role="combobox"
120
- aria-disabled=${ifDefined(this.effectivelyDisabled ? "true" : void 0)}
121
- aria-haspopup="dialog"
122
- aria-expanded=${this.open}
123
- aria-label=${ifDefined(this.resolvedAriaLabel)}
124
- aria-description=${ifDefined(this.resolvedAriaDescription)}
125
- aria-controls=${this.calendarId}
126
- >
127
- <span class="text-content ${!displayText ? "placeholder" : ""}">${displayText || this.placeholder || ""}</span>
162
+ <div class="container" part="container" @click=${this.handleContainerClick}>
163
+ <input class="text-input" part="input"
164
+ type="text"
165
+ autocomplete="off"
166
+ role="combobox"
167
+ aria-haspopup="dialog"
168
+ aria-expanded=${this.open}
169
+ aria-controls=${this.calendarId}
170
+ aria-label=${ifDefined(this.resolvedAriaLabel)}
171
+ aria-description=${ifDefined(this.resolvedAriaDescription)}
172
+ aria-invalid=${this.badText ? "true" : "false"}
173
+ placeholder=${this.placeholder ?? `${pattern} – ${pattern}`}
174
+ .value=${this.draft ?? shown}
175
+ ?disabled=${this.effectivelyDisabled}
176
+ ?readonly=${this.readonly}
177
+ @input=${this.handleTextInput}
178
+ @keydown=${this.handleTextKeydown}
179
+ @blur=${this.commitText}
180
+ />
128
181
  <u-icon class="suffix-item"
129
182
  ?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
130
183
  role="button"
@@ -135,9 +188,14 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
135
188
  @click=${this.handleClearClick}
136
189
  @keydown=${this.handleClearKeydown}
137
190
  ></u-icon>
138
- <u-icon class="suffix-item"
191
+ <u-icon class="suffix-item calendar-button"
192
+ role="button"
193
+ tabindex="-1"
194
+ aria-label=${Locale.getValue("chooseDateRange")}
195
+ ?hidden=${this.effectivelyDisabled || this.readonly}
139
196
  lib="internal"
140
197
  name="calendar"
198
+ @click=${this.handleCalendarButtonClick}
141
199
  ></u-icon>
142
200
  </div>
143
201
  </u-field>
@@ -147,7 +205,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
147
205
  role="dialog"
148
206
  aria-label=${Locale.getValue("chooseDateRange")}
149
207
  for=".container"
150
- trigger="click"
208
+ trigger="manual"
151
209
  strategy="fixed"
152
210
  placement="bottom-start"
153
211
  offset="4"
@@ -207,13 +265,29 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
207
265
  commitRange(start, end) {
208
266
  const next = `${start}/${end}`;
209
267
  const changed = next !== this.value;
268
+ this.draft = null;
269
+ this.badText = false;
210
270
  this.value = next;
211
271
  if (changed) this.emitChange();
212
272
  this.popoverEl?.hide();
213
- this.containerEl?.focus();
273
+ this.textInputEl?.focus();
274
+ }
275
+ get textInputEl() {
276
+ return this.renderRoot.querySelector(".text-input");
277
+ }
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);
214
286
  }
215
287
  resetValue() {
216
288
  const hadValue = !!this.value;
289
+ this.draft = null;
290
+ this.badText = false;
217
291
  this.value = void 0;
218
292
  if (hadValue) this.emitChange();
219
293
  }
@@ -228,7 +302,10 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
228
302
  let flags = {};
229
303
  let message = "";
230
304
  const range = parseInterval(this.value);
231
- if (this.required && !this.value) {
305
+ if (this.badText) {
306
+ flags = { badInput: true };
307
+ message = Locale.getValue("badInput");
308
+ } else if (this.required && !this.value) {
232
309
  flags = { valueMissing: true };
233
310
  message = Locale.getValue("valueMissing");
234
311
  } else if (this.value && !range) {
@@ -241,19 +318,20 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
241
318
  flags = { rangeOverflow: true };
242
319
  message = Locale.getValue("rangeOverflow", { max: this.max });
243
320
  }
244
- this.commit(flags, message, this.containerEl ?? void 0);
321
+ this.commit(flags, message, this.textInputEl ?? this.containerEl ?? void 0);
245
322
  }
246
323
  reset() {
247
324
  this.value = void 0;
325
+ this.draft = null;
326
+ this.badText = false;
248
327
  this.invalid = false;
249
328
  }
250
- /** `.container` is a div — no native `disabled`, so a disabled picker ignores `focus()` here. */
251
329
  focus(options) {
252
330
  if (this.effectivelyDisabled) return;
253
- this.containerEl?.focus(options);
331
+ this.textInputEl?.focus(options);
254
332
  }
255
333
  blur() {
256
- this.containerEl?.blur();
334
+ this.textInputEl?.blur();
257
335
  }
258
336
  };
259
337
  __decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "min", void 0);
@@ -263,6 +341,10 @@ __decorate([property({
263
341
  reflect: true
264
342
  }), __decorateMetadata("design:type", Boolean)], UDateRangePicker.prototype, "clearable", void 0);
265
343
  __decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDateRangePicker.prototype, "placeholder", void 0);
344
+ __decorate([property({
345
+ type: String,
346
+ reflect: true
347
+ }), __decorateMetadata("design:type", Object)], UDateRangePicker.prototype, "format", void 0);
266
348
  __decorate([property({
267
349
  attribute: "presets",
268
350
  converter: { fromAttribute: (v) => (v ?? "").split(/\s+/).filter(Boolean) }
@@ -271,6 +353,8 @@ __decorate([query(".container", true), __decorateMetadata("design:type", typeof
271
353
  __decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDateRangePicker.prototype, "popoverEl", void 0);
272
354
  __decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDateRangePicker.prototype, "calendarEl", void 0);
273
355
  __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);
274
358
  UDateRangePicker = __decorate([customElement("u-date-range-picker")], UDateRangePicker);
275
359
  //#endregion
276
360
  export { UDateRangePicker };
@@ -78,6 +78,25 @@ var styles = css`
78
78
  border-block-end: 1px solid var(--u-border-color-weak, #EEEEEE);
79
79
  }
80
80
  }
81
+
82
+ /* The trigger is a text box — it takes the container's room and reads like its text. */
83
+ .text-input {
84
+ flex: 1 1 auto;
85
+ min-width: 0;
86
+ border: none;
87
+ outline: none;
88
+ padding: 0;
89
+ margin: 0;
90
+ background: transparent;
91
+ color: inherit;
92
+ font: inherit;
93
+ }
94
+ .text-input::placeholder {
95
+ color: var(--u-txt-color-weak, #616161);
96
+ }
97
+ .calendar-button {
98
+ cursor: pointer;
99
+ }
81
100
  `;
82
101
  //#endregion
83
102
  export { styles };
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, formatDateText, formatDateTimeText, formatNumber, parseDate, parseDateTime, parseNumber } from "./utilities/format.js";
29
+ import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeText, formatNumber, parseDate, parseDateRange, parseDateTime, 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, formatDateText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, 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, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, parseDateRange, parseDateTime, parseNumber, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
@@ -95,3 +95,20 @@ export declare function parseDateTime(text: string, options?: {
95
95
  }): string | null;
96
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
97
  export declare function formatDateTimeText(isoLocal: string, format?: DateTextFormat, locale?: LocaleTag): string;
98
+ /**
99
+ * Reads a period of days as people type it — `2026-10-01 ~ 2026-10-31`, `2026-10-01 – 10-31`,
100
+ * the ISO interval `2026-10-01/2026-10-31`, or a single day (a one-day range) — and returns
101
+ * `{ start, end }` as ISO dates, earlier first, or `null`. Each day is read by {@link parseDate}; a
102
+ * short second day (`10-31`) takes the first day's year, or the next year when it would otherwise
103
+ * fall before the first day (`2025-12-20 ~ 01-05`).
104
+ */
105
+ export declare function parseDateRange(text: string, options?: {
106
+ format?: DateTextFormat;
107
+ locale?: LocaleTag;
108
+ referenceDate?: Date;
109
+ }): {
110
+ start: string;
111
+ end: string;
112
+ } | null;
113
+ /** Writes a period as `{start} – {end}`, each day as {@link formatDateText} writes it. */
114
+ export declare function formatDateRangeText(start: string, end: string, format?: DateTextFormat, locale?: LocaleTag): string;
@@ -246,5 +246,54 @@ function formatDateTimeText(isoLocal, format = "iso", locale) {
246
246
  const m = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(isoLocal);
247
247
  return m ? `${formatDateText(m[1], format, locale)} ${m[2]}` : isoLocal;
248
248
  }
249
+ /** Separators read between the two days of a typed range: `~`, en/em dash, or ` - ` with spaces. */
250
+ var RANGE_SEPARATOR = /\s*[~–—]\s*|\s+-\s+/;
251
+ /**
252
+ * Reads a period of days as people type it — `2026-10-01 ~ 2026-10-31`, `2026-10-01 – 10-31`,
253
+ * the ISO interval `2026-10-01/2026-10-31`, or a single day (a one-day range) — and returns
254
+ * `{ start, end }` as ISO dates, earlier first, or `null`. Each day is read by {@link parseDate}; a
255
+ * short second day (`10-31`) takes the first day's year, or the next year when it would otherwise
256
+ * fall before the first day (`2025-12-20 ~ 01-05`).
257
+ */
258
+ function parseDateRange(text, options = {}) {
259
+ const t = text.trim();
260
+ if (!t) return null;
261
+ let parts = t.split(RANGE_SEPARATOR);
262
+ if (parts.length === 1) {
263
+ const iso = /^(\d{4}-\d{2}-\d{2})\/(\d{4}-\d{2}-\d{2})$/.exec(t);
264
+ if (iso) parts = [iso[1], iso[2]];
265
+ }
266
+ if (parts.length > 2) return null;
267
+ const start = parseDate(parts[0], options);
268
+ if (!start) return null;
269
+ if (parts.length === 1) return {
270
+ start,
271
+ end: start
272
+ };
273
+ const [y, m, d] = start.split("-").map(Number);
274
+ let end = parseDate(parts[1], {
275
+ ...options,
276
+ referenceDate: new Date(y, m - 1, d)
277
+ });
278
+ if (!end) return null;
279
+ if (end < start && !/\d{4}/.test(parts[1])) {
280
+ end = parseDate(parts[1], {
281
+ ...options,
282
+ referenceDate: new Date(y + 1, 0, 1)
283
+ });
284
+ if (!end) return null;
285
+ }
286
+ return start <= end ? {
287
+ start,
288
+ end
289
+ } : {
290
+ start: end,
291
+ end: start
292
+ };
293
+ }
294
+ /** Writes a period as `{start} – {end}`, each day as {@link formatDateText} writes it. */
295
+ function formatDateRangeText(start, end, format = "iso", locale) {
296
+ return `${formatDateText(start, format, locale)} – ${formatDateText(end, format, locale)}`;
297
+ }
249
298
  //#endregion
250
- export { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatDateTimeText, formatNumber, parseDate, parseDateTime, parseNumber };
299
+ export { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateRangeText, formatDateText, formatDateTimeText, formatNumber, parseDate, parseDateRange, parseDateTime, parseNumber };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@iyulab/components",
3
3
  "description": "web-components library based on lit-element made by iyulab",
4
- "version": "1.56.0",
4
+ "version": "1.57.0",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",
@@ -24,6 +24,15 @@ code is put in order (no `change`).
24
24
 
25
25
  > The calendar week always starts on Sunday, regardless of locale.
26
26
 
27
+ **Typing a range.** The field is a text box: type `2026-10-01 ~ 2026-10-31` (also `–`, ` - `, the ISO
28
+ interval `2026-10-01/2026-10-31`, a short second day such as `10-31` — the first day's year, or the
29
+ next year when it would fall before the first day — or one day for a one-day range) and press Enter
30
+ or leave the field. It shows `YYYY-MM-DD – YYYY-MM-DD` in every browser language; `format="locale"`
31
+ uses the locale's numeric order for each day. Clicking the field opens the calendar and keeps the
32
+ caret in the text box; ArrowDown (or Alt+ArrowDown) moves into the calendar. Text that is not a range
33
+ clears the value and reports `badInput` (the text stays to be fixed). The reader and writer are
34
+ exported as `parseDateRange` and `formatDateRangeText`.
35
+
27
36
  ```html
28
37
  <u-date-range-picker name="ordered" label="Ordered"></u-date-range-picker>
29
38
 
@@ -88,7 +97,8 @@ picker.addEventListener('change', () => {
88
97
  | `min` | `string` | — | — | Earliest selectable day (ISO `YYYY-MM-DD`), inclusive |
89
98
  | `max` | `string` | — | — | Latest selectable day (ISO `YYYY-MM-DD`), inclusive |
90
99
  | `clearable` | `boolean` | `false` | ✓ | Show clear button |
91
- | `placeholder` | `string` | — | — | Placeholder text |
100
+ | `placeholder` | `string` | — | — | Placeholder text (defaults to the pattern to type) |
101
+ | `format` | `'iso' \| 'locale'` | `'iso'` | ✓ | How the text box writes and reads each day |
92
102
  | `presets` | `Array<DateRangePresetName \| DateRangePreset>` | `[]` | — | Quick ranges beside the calendar; attribute form is space-separated built-in names |
93
103
  | `disabled` | `boolean` | `false` | ✓ | Disable |
94
104
  | `readonly` | `boolean` | `false` | ✓ | Read-only |
@@ -123,6 +133,7 @@ Validation: `required` with no value → `valueMissing`; a value that is not two
123
133
  |------|-------------|
124
134
  | `field` | The `u-field` element |
125
135
  | `container` | The element wrapping the trigger area |
136
+ | `input` | The text box |
126
137
  | `popover` | The popover element showing the calendar |
127
138
  | `calendar` | The calendar container |
128
139
  | `calendar-month` | One month block |