@iyulab/components 1.54.0 → 1.56.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,46 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.56.0] - 2026-10-03
4
+
5
+ ### Added
6
+
7
+ - **`u-date-picker mode="datetime"` takes a typed date and time.** The field is the same text box as in
8
+ `mode="date"`: type `2026-10-02 14:30` (or `9:05`; seconds are dropped) and press Enter or leave the
9
+ field. It shows `YYYY-MM-DD HH:mm` whatever the browser language (`format="locale"` writes the date
10
+ part in the locale's numeric order). Typing only a date keeps the time already set. An impossible time
11
+ (`25:00`) clears the value and reports `badInput`. The value is still a full ISO-8601 `DateTimeOffset`.
12
+ - **`parseDateTime`, `formatDateTimeText`** next to `parseDate`.
13
+
14
+ ### Changed
15
+
16
+ - **`u-date-picker mode="datetime"`: the trigger text is `YYYY-MM-DD HH:mm`** (was the locale's medium
17
+ date and short time, e.g. `Oct 2, 2026, 2:30 PM`), and a click keeps focus in the text box — the same
18
+ as `mode="date"` since 1.55.0.
19
+
20
+ ## [1.55.0] - 2026-10-03
21
+
22
+ ### Added
23
+
24
+ - **`u-date-picker` takes a typed date.** In `mode="date"` the field is now a text box: type
25
+ `2026-10-02`, `2026/10/2`, `20261002` or `10-02` (this year) and press Enter or leave the field.
26
+ It shows the date as `YYYY-MM-DD` whatever the browser language — the native date input follows
27
+ the browser's UI language instead (`10/02/2026` in an English browser), which is why a picker that
28
+ could not be typed into was the only way to get a stable format. `format="locale"` shows and reads
29
+ the locale's numeric order (`10/02/2026` in `en-US`, `02.10.2026` in `de`); ISO is read either way.
30
+ Clicking the field opens the calendar and leaves the caret in the text box; ArrowDown or
31
+ Alt+ArrowDown moves into the calendar. Text that is not a date clears the value and reports
32
+ `badInput`, as the native date input does; a date outside `min`/`max` is kept and reported as out
33
+ of range. New CSS part `input`. `mode="datetime"` is unchanged.
34
+ - **`parseDate`, `formatDateText`, `dateTextPattern`** — the text box's reader and writer, exported
35
+ next to `parseNumber`: `parseDate('20261002')` is `'2026-10-02'`, `parseDate('2026-02-30')` is `null`.
36
+
37
+ ### Changed
38
+
39
+ - **`u-date-picker` in `mode="date"`: the trigger text is `YYYY-MM-DD`** (was the locale's medium
40
+ date, e.g. `Oct 2, 2026`) so that what is shown can be typed back. Use `format="locale"` for the
41
+ locale's numeric order. A click no longer moves focus into the calendar — it stays in the text box
42
+ so the person can type; the keyboard path into the calendar is ArrowDown.
43
+
3
44
  ## [1.54.0] - 2026-10-02
4
45
 
5
46
  ### Added
@@ -1,11 +1,18 @@
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
  export type DatePickerMode = 'date' | 'datetime';
6
7
  /**
7
8
  * A single-date(-time)-selection form control. In `mode="date"` (default) the value follows
8
- * the same convention as the native `input[type=date]`: an ISO `YYYY-MM-DD` string. In
9
+ * the same convention as the native `input[type=date]`: an ISO `YYYY-MM-DD` string. The field is a
10
+ * text box in both modes — type `2026-10-02`, `20261002` or `10-02` (this year), plus a time
11
+ * (`2026-10-02 14:30`) in `mode="datetime"`, and press Enter or leave the field; the calendar is a
12
+ * helper. The text shows as `YYYY-MM-DD` (`YYYY-MM-DD HH:mm`) whatever the browser language, or in
13
+ * the locale's numeric order with `format="locale"`. Clicking the field opens the calendar and keeps
14
+ * typing in the field; ArrowDown (or Alt+ArrowDown) moves into the calendar. Text that is not a date
15
+ * clears the value and reports `badInput`, like the native input. In
9
16
  * `mode="datetime"` the value is a complete ISO-8601 `DateTimeOffset` string
10
17
  * (`YYYY-MM-DDTHH:mm:ss±HH:mm`) — the component always fills in seconds and the browser's
11
18
  * local UTC offset, so the value is unconditionally valid regardless of how coarse the time
@@ -23,6 +30,7 @@ export type DatePickerMode = 'date' | 'datetime';
23
30
  * as a CSS hook for consumers who want to react to the open/closed state from outside.
24
31
  *
25
32
  * @csspart field - the u-field element
33
+ * @csspart input - the text box
26
34
  * @csspart container - the element wrapping the trigger area
27
35
  * @csspart popover - the popover element showing the calendar
28
36
  * @csspart calendar - the calendar container
@@ -59,8 +67,14 @@ export declare class UDatePicker extends UFormControlElement<string> {
59
67
  max?: string;
60
68
  /** Whether to show the clear button */
61
69
  clearable: boolean;
62
- /** Placeholder text (shown on the trigger when there is no value) */
70
+ /** Placeholder text (shown when there is no value). Defaults to the pattern to type
71
+ * (`YYYY-MM-DD`, or `YYYY-MM-DD HH:mm` in `mode="datetime"`). */
63
72
  placeholder?: string;
73
+ /** How the text box writes and reads the date: `iso` (default, `YYYY-MM-DD` in every language)
74
+ * or `locale` (the active locale's numeric order, e.g. `10/02/2026` in `en-US`). ISO and
75
+ * `20261002` are read in both. The time, in `mode="datetime"`, is always `HH:mm`. The value is
76
+ * ISO either way. */
77
+ format: DateTextFormat;
64
78
  containerEl?: HTMLElement;
65
79
  popoverEl?: UPopover;
66
80
  calendarEl?: UCalendar;
@@ -70,6 +84,13 @@ export declare class UDatePicker extends UFormControlElement<string> {
70
84
  /** Time-of-day for the next selection while no `value` exists yet (`mode="datetime"` only) —
71
85
  * once `value` is set, the time input reads/writes its time portion directly instead. */
72
86
  private pendingTime;
87
+ /** What the person is typing in the text box, until it is committed; `null` shows the value. */
88
+ private draft;
89
+ /** The committed text was not a date — the value is empty and validity reports `badInput`. */
90
+ private badText;
91
+ /** Set when the calendar opens by keyboard (or its button): focus then moves into the grid. A click
92
+ * in the text box opens it too, but leaves the caret where the person is typing. */
93
+ private focusCalendarOnOpen;
73
94
  protected updated(changed: PropertyValues): void;
74
95
  render(): import('lit-html').TemplateResult<1>;
75
96
  private renderCalendar;
@@ -86,6 +107,23 @@ export declare class UDatePicker extends UFormControlElement<string> {
86
107
  * trigger — unlike selecting a day, adjusting the time doesn't conclude the interaction. */
87
108
  private handleTimeChange;
88
109
  private handleDaySelect;
110
+ private get textInputEl();
111
+ private openCalendar;
112
+ /** The typed text as a date (ISO) and, in `mode="datetime"`, a time — or `null` when it is not one.
113
+ * Typing only a date in `mode="datetime"` keeps the time already set (or the pending one). */
114
+ private parseTyped;
115
+ private handleTextInput;
116
+ /** A click anywhere on the field (not on its clear or calendar button) opens the calendar and
117
+ * puts the caret in the text box — the person can pick a day or keep typing. */
118
+ private handleContainerClick;
119
+ private handleCalendarButtonClick;
120
+ /** ArrowDown / Alt+ArrowDown opens the calendar and moves into it (the combobox convention);
121
+ * Enter commits what was typed. Escape is the popover layer's — it closes the calendar. */
122
+ private handleTextKeydown;
123
+ /** Turns the typed text into the value. Empty text clears it; text that is not a date also clears
124
+ * it and reports `badInput` (the native date input does the same); a date outside `min`/`max` is
125
+ * kept and reported as out of range — the person typed it, so it is not silently dropped. */
126
+ private commitText;
89
127
  /** Escape inside the grid closes the calendar and returns focus to the trigger — the grid
90
128
  * itself does not know it lives in a popover, so the picker owns this. */
91
129
  private handleCalendarKeydown;
@@ -4,7 +4,7 @@ import { UFormControlElement } from "../UFormControlElement.js";
4
4
  import "../button/UButton.js";
5
5
  import "../icon/UIcon.js";
6
6
  import { Locale } from "../../utilities/Locale.js";
7
- import { formatDate } from "../../utilities/format.js";
7
+ import { dateTextPattern, formatDateText, formatDateTimeText, parseDate, parseDateTime } from "../../utilities/format.js";
8
8
  import { isOutOfRange, parseISODate, toISODate } from "../calendar/dates.js";
9
9
  import { UCalendar } from "../calendar/UCalendar.js";
10
10
  import "../field/UField.js";
@@ -45,9 +45,13 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
45
45
  super(..._args);
46
46
  this.mode = "date";
47
47
  this.clearable = false;
48
+ this.format = "iso";
48
49
  this.calendarId = `u-date-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
49
50
  this.open = false;
50
51
  this.pendingTime = "00:00";
52
+ this.draft = null;
53
+ this.badText = false;
54
+ this.focusCalendarOnOpen = false;
51
55
  this.handleTimeChange = (e) => {
52
56
  const time = e.target.value || "00:00";
53
57
  this.pendingTime = time;
@@ -60,11 +64,49 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
60
64
  this.handleDaySelect = (e) => {
61
65
  this.selectDay(parseISODate(e.detail.date));
62
66
  };
67
+ this.handleTextInput = (e) => {
68
+ this.draft = e.target.value;
69
+ const typed = this.parseTyped(this.draft);
70
+ if (typed && this.open) this.calendarEl?.showDate(typed.date);
71
+ };
72
+ this.handleContainerClick = (e) => {
73
+ if (e.target.closest?.("u-icon")) return;
74
+ const input = this.textInputEl;
75
+ if (input && this.renderRoot instanceof ShadowRoot && this.renderRoot.activeElement !== input) input.focus();
76
+ this.openCalendar(false);
77
+ };
78
+ this.handleCalendarButtonClick = (e) => {
79
+ e.stopPropagation();
80
+ if (this.open) {
81
+ this.popoverEl?.hide();
82
+ this.textInputEl?.focus();
83
+ } else this.openCalendar(true);
84
+ };
85
+ this.handleTextKeydown = (e) => {
86
+ if (e.key === "ArrowDown") {
87
+ e.preventDefault();
88
+ this.commitText();
89
+ this.openCalendar(true);
90
+ } else if (e.key === "Enter" && !e.isComposing) this.commitText();
91
+ };
92
+ this.commitText = () => {
93
+ if (this.draft === null) return;
94
+ const text = this.draft;
95
+ const typed = this.parseTyped(text);
96
+ this.badText = !!text.trim() && typed === null;
97
+ const next = typed ? buildValue(parseISODate(typed.date), this.mode, typed.time) : void 0;
98
+ if (typed && this.mode === "datetime") this.pendingTime = typed.time;
99
+ const changed = next !== this.value;
100
+ this.value = next;
101
+ this.draft = this.badText ? text : null;
102
+ if (changed) this.emitChange();
103
+ else if (this.badText && !this.novalidate) this.validate();
104
+ };
63
105
  this.handleCalendarKeydown = (e) => {
64
106
  if (e.key !== "Escape") return;
65
107
  e.preventDefault();
66
108
  this.popoverEl?.hide();
67
- this.containerEl?.focus();
109
+ (this.textInputEl ?? this.containerEl)?.focus();
68
110
  };
69
111
  this.handlePopoverShow = () => {
70
112
  this.open = true;
@@ -76,7 +118,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
76
118
  e.preventDefault();
77
119
  e.stopPropagation();
78
120
  this.resetValue();
79
- this.containerEl?.focus();
121
+ (this.textInputEl ?? this.containerEl)?.focus();
80
122
  };
81
123
  this.handleTodayClick = () => {
82
124
  const now = /* @__PURE__ */ new Date();
@@ -86,7 +128,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
86
128
  this.handleFooterResetClick = () => {
87
129
  this.resetValue();
88
130
  this.popoverEl?.hide();
89
- this.containerEl?.focus();
131
+ (this.textInputEl ?? this.containerEl)?.focus();
90
132
  };
91
133
  this.handleClearKeydown = (e) => {
92
134
  if (e.key !== "Enter" && e.key !== " ") return;
@@ -107,16 +149,16 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
107
149
  if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
108
150
  if (changed.has("open") && this.open) {
109
151
  const calendar = this.calendarEl;
110
- const base = this.value ? toISODate(splitValue(this.value).date) : toISODate(/* @__PURE__ */ new Date());
152
+ const base = (this.draft !== null ? this.parseTyped(this.draft)?.date : void 0) ?? (this.value ? toISODate(splitValue(this.value).date) : toISODate(/* @__PURE__ */ new Date()));
111
153
  calendar?.showDate(base);
112
- this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
154
+ const moveFocus = this.focusCalendarOnOpen;
155
+ this.focusCalendarOnOpen = false;
156
+ if (moveFocus) this.popoverEl?.updateComplete.then(() => calendar?.focusDay());
113
157
  }
114
158
  }
115
159
  render() {
116
- const displayText = this.value ? formatDate(this.value, this.mode === "datetime" ? {
117
- dateStyle: "medium",
118
- timeStyle: "short"
119
- } : void 0) : "";
160
+ const datetime = this.mode === "datetime";
161
+ const shown = this.value ? datetime ? formatDateTimeText(`${toISODate(splitValue(this.value).date)}T${splitValue(this.value).time}`, this.format) : formatDateText(toISODate(splitValue(this.value).date), this.format) : "";
120
162
  return html`
121
163
  <u-field part="field"
122
164
  ?required=${this.required}
@@ -126,17 +168,26 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
126
168
  .description=${this.description}
127
169
  .validationMessage=${this.validationMessage}
128
170
  >
129
- <div class="container" part="container"
130
- tabindex=${this.effectivelyDisabled ? "-1" : "0"}
131
- role="combobox"
132
- aria-disabled=${ifDefined(this.effectivelyDisabled ? "true" : void 0)}
133
- aria-haspopup="dialog"
134
- aria-expanded=${this.open}
135
- aria-label=${ifDefined(this.resolvedAriaLabel)}
136
- aria-description=${ifDefined(this.resolvedAriaDescription)}
137
- aria-controls=${this.calendarId}
138
- >
139
- <span class="text-content ${!displayText ? "placeholder" : ""}">${displayText || this.placeholder || ""}</span>
171
+ <div class="container" part="container" @click=${this.handleContainerClick}>
172
+ <input class="text-input" part="input"
173
+ type="text"
174
+ inputmode=${datetime ? "text" : "numeric"}
175
+ autocomplete="off"
176
+ role="combobox"
177
+ aria-haspopup="dialog"
178
+ aria-expanded=${this.open}
179
+ aria-controls=${this.calendarId}
180
+ aria-label=${ifDefined(this.resolvedAriaLabel)}
181
+ aria-description=${ifDefined(this.resolvedAriaDescription)}
182
+ aria-invalid=${this.badText ? "true" : "false"}
183
+ placeholder=${this.placeholder ?? (datetime ? `${dateTextPattern(this.format)} HH:mm` : dateTextPattern(this.format))}
184
+ .value=${this.draft ?? shown}
185
+ ?disabled=${this.effectivelyDisabled}
186
+ ?readonly=${this.readonly}
187
+ @input=${this.handleTextInput}
188
+ @keydown=${this.handleTextKeydown}
189
+ @blur=${this.commitText}
190
+ />
140
191
  <u-icon class="suffix-item"
141
192
  ?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
142
193
  role="button"
@@ -147,9 +198,14 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
147
198
  @click=${this.handleClearClick}
148
199
  @keydown=${this.handleClearKeydown}
149
200
  ></u-icon>
150
- <u-icon class="suffix-item"
201
+ <u-icon class="suffix-item calendar-button"
202
+ role="button"
203
+ tabindex="-1"
204
+ aria-label=${Locale.getValue("chooseDate")}
205
+ ?hidden=${this.effectivelyDisabled || this.readonly}
151
206
  lib="internal"
152
207
  name="calendar"
208
+ @click=${this.handleCalendarButtonClick}
153
209
  ></u-icon>
154
210
  </div>
155
211
  </u-field>
@@ -159,7 +215,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
159
215
  role="dialog"
160
216
  aria-label=${Locale.getValue("chooseDate")}
161
217
  for=".container"
162
- trigger="click"
218
+ trigger="manual"
163
219
  strategy="fixed"
164
220
  placement="bottom-start"
165
221
  offset="4"
@@ -223,10 +279,44 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
223
279
  if (this.mode === "datetime") this.pendingTime = time;
224
280
  if (changed) this.emitChange();
225
281
  this.popoverEl?.hide();
226
- this.containerEl?.focus();
282
+ (this.textInputEl ?? this.containerEl)?.focus();
283
+ }
284
+ get textInputEl() {
285
+ return this.renderRoot.querySelector(".text-input");
286
+ }
287
+ openCalendar(focusGrid) {
288
+ if (this.effectivelyDisabled || this.readonly) return;
289
+ if (this.open) {
290
+ if (focusGrid) this.calendarEl?.focusDay();
291
+ return;
292
+ }
293
+ this.focusCalendarOnOpen = focusGrid;
294
+ if (this.containerEl) this.popoverEl?.show(this.containerEl);
295
+ }
296
+ /** The typed text as a date (ISO) and, in `mode="datetime"`, a time — or `null` when it is not one.
297
+ * Typing only a date in `mode="datetime"` keeps the time already set (or the pending one). */
298
+ parseTyped(text) {
299
+ if (this.mode !== "datetime") {
300
+ const date = parseDate(text, { format: this.format });
301
+ return date ? {
302
+ date,
303
+ time: this.pendingTime
304
+ } : null;
305
+ }
306
+ const keep = this.value ? splitValue(this.value).time : this.pendingTime;
307
+ const dt = parseDateTime(text, {
308
+ format: this.format,
309
+ defaultTime: keep
310
+ });
311
+ return dt ? {
312
+ date: dt.slice(0, 10),
313
+ time: dt.slice(11, 16)
314
+ } : null;
227
315
  }
228
316
  resetValue() {
229
317
  const hadValue = !!this.value;
318
+ this.draft = null;
319
+ this.badText = false;
230
320
  this.value = void 0;
231
321
  if (hadValue) this.emitChange();
232
322
  }
@@ -240,7 +330,10 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
240
330
  setValidity() {
241
331
  let flags = {};
242
332
  let message = "";
243
- if (this.required && !this.value) {
333
+ if (this.badText) {
334
+ flags = { badInput: true };
335
+ message = Locale.getValue("badInput");
336
+ } else if (this.required && !this.value) {
244
337
  flags = { valueMissing: true };
245
338
  message = Locale.getValue("valueMissing");
246
339
  } else if (this.value && this.min && splitValue(this.value).date.getTime() < parseISODate(this.min).getTime()) {
@@ -250,10 +343,12 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
250
343
  flags = { rangeOverflow: true };
251
344
  message = Locale.getValue("rangeOverflow", { max: this.max });
252
345
  }
253
- this.commit(flags, message, this.containerEl ?? void 0);
346
+ this.commit(flags, message, this.textInputEl ?? this.containerEl ?? void 0);
254
347
  }
255
348
  reset() {
256
349
  this.value = void 0;
350
+ this.draft = null;
351
+ this.badText = false;
257
352
  this.invalid = false;
258
353
  }
259
354
  /** `.container`는 div라 네이티브 `disabled`가 없다 — disabled일 때 `tabindex="-1"`로만
@@ -261,10 +356,10 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
261
356
  * 네이티브 `disabled` `<input>`에서 얻는 것과 같은 no-op을 여기서 직접 재현한다. */
262
357
  focus(options) {
263
358
  if (this.effectivelyDisabled) return;
264
- this.containerEl?.focus(options);
359
+ (this.textInputEl ?? this.containerEl)?.focus(options);
265
360
  }
266
361
  blur() {
267
- this.containerEl?.blur();
362
+ (this.textInputEl ?? this.containerEl)?.blur();
268
363
  }
269
364
  };
270
365
  __decorate([property({
@@ -278,11 +373,17 @@ __decorate([property({
278
373
  reflect: true
279
374
  }), __decorateMetadata("design:type", Boolean)], UDatePicker.prototype, "clearable", void 0);
280
375
  __decorate([property({ type: String }), __decorateMetadata("design:type", String)], UDatePicker.prototype, "placeholder", void 0);
376
+ __decorate([property({
377
+ type: String,
378
+ reflect: true
379
+ }), __decorateMetadata("design:type", Object)], UDatePicker.prototype, "format", void 0);
281
380
  __decorate([query(".container", true), __decorateMetadata("design:type", typeof HTMLElement === "undefined" ? Object : HTMLElement)], UDatePicker.prototype, "containerEl", void 0);
282
381
  __decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDatePicker.prototype, "popoverEl", void 0);
283
382
  __decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDatePicker.prototype, "calendarEl", void 0);
284
383
  __decorate([state(), __decorateMetadata("design:type", Boolean)], UDatePicker.prototype, "open", void 0);
285
384
  __decorate([state(), __decorateMetadata("design:type", String)], UDatePicker.prototype, "pendingTime", void 0);
385
+ __decorate([state(), __decorateMetadata("design:type", Object)], UDatePicker.prototype, "draft", void 0);
386
+ __decorate([state(), __decorateMetadata("design:type", Object)], UDatePicker.prototype, "badText", void 0);
286
387
  UDatePicker = __decorate([customElement("u-date-picker")], UDatePicker);
287
388
  //#endregion
288
389
  export { UDatePicker };
@@ -18,6 +18,25 @@ var styles = css`
18
18
  width: var(--date-picker-popover-width);
19
19
  }
20
20
 
21
+ /* mode="date": the trigger is a text box — it takes the container's room and reads like its text. */
22
+ .text-input {
23
+ flex: 1 1 auto;
24
+ min-width: 0;
25
+ border: none;
26
+ outline: none;
27
+ padding: 0;
28
+ margin: 0;
29
+ background: transparent;
30
+ color: inherit;
31
+ font: inherit;
32
+ }
33
+ .text-input::placeholder {
34
+ color: var(--u-txt-color-weak, #616161);
35
+ }
36
+ .calendar-button {
37
+ cursor: pointer;
38
+ }
39
+
21
40
  .calendar-time {
22
41
  display: flex;
23
42
  justify-content: flex-end;
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 { formatCurrency, formatDate, formatDateRange, formatNumber, parseNumber } from "./utilities/format.js";
29
+ import { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatDateTimeText, formatNumber, parseDate, 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, decodeTsv, devWarnOnce, encodeTsv, formatCurrency, formatDate, formatDateRange, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, 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, formatDateText, formatDateTimeText, formatNumber, getDefaultBaseUrl, getParentElement, isCoarsePointer, isFocusCandidate, isImeComposing, jsonAttrConverter, parseDate, parseDateTime, parseNumber, querySelectorAllWithin, querySelectorDeep, querySelectorWithin, resetDevWarnings, setDefaultBaseUrl, urlAttrConverter };
@@ -55,3 +55,43 @@ export declare function formatDateRange(start: Date | string, end: Date | string
55
55
  * not read. `locale` defaults to the active `Locale`.
56
56
  */
57
57
  export declare function parseNumber(text: string, locale?: LocaleTag): number | null;
58
+ /** How a date is written in a text field: ISO `YYYY-MM-DD`, or the locale's numeric order (`10/02/2026`, `02.10.2026`). */
59
+ export type DateTextFormat = 'iso' | 'locale';
60
+ /**
61
+ * Writes an ISO `YYYY-MM-DD` date the way {@link parseDate} reads it back: `iso` keeps it as is;
62
+ * `locale` uses the locale's numeric order with two-digit month and day (`10/02/2026` in `en-US`,
63
+ * `02.10.2026` in `de`). A string that is not an ISO date is returned unchanged.
64
+ */
65
+ export declare function formatDateText(iso: string, format?: DateTextFormat, locale?: LocaleTag): string;
66
+ /** The pattern a person should type for `format` — `YYYY-MM-DD`, or e.g. `MM/DD/YYYY` for `locale` in `en-US`. */
67
+ export declare function dateTextPattern(format?: DateTextFormat, locale?: LocaleTag): string;
68
+ /**
69
+ * Reads a date the way people type it into a field and returns it as ISO `YYYY-MM-DD`, or `null`
70
+ * when the text is not a real date (`2026-02-30` is `null`). Accepted, whatever `format` is:
71
+ * - `2026-10-02`, `2026/10/02`, `2026.10.02`, `2026. 10. 2.` — a four-digit first part is year-month-day;
72
+ * - `20261002` — eight digits are year, month, day.
73
+ *
74
+ * `format` decides the rest: with `iso`, three parts are year-month-day and two parts (`10-02`)
75
+ * are month-day; with `locale`, both follow the locale's numeric order (`10/02/2026` and `10/02`
76
+ * in `en-US`, `02.10.2026` and `2.10` in `de`). Two parts take the year of `referenceDate`
77
+ * (today by default). Two-digit years are not read.
78
+ */
79
+ export declare function parseDate(text: string, options?: {
80
+ format?: DateTextFormat;
81
+ locale?: LocaleTag;
82
+ referenceDate?: Date;
83
+ }): string | null;
84
+ /**
85
+ * Reads a date and a time of day as people type them and returns local `YYYY-MM-DDTHH:mm`, or `null`.
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`.
89
+ */
90
+ export declare function parseDateTime(text: string, options?: {
91
+ format?: DateTextFormat;
92
+ locale?: LocaleTag;
93
+ referenceDate?: Date;
94
+ defaultTime?: string;
95
+ }): 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;
@@ -132,5 +132,119 @@ function parseNumber(text, locale) {
132
132
  const value = Number(`${negative ? "-" : ""}${digits || "0"}.${fracPart || "0"}`);
133
133
  return Number.isFinite(value) ? value : null;
134
134
  }
135
+ /** The year/month/day order and separator the locale's numeric date uses (`en-US` → month/day/year · `/`). */
136
+ function numericDateLayout(locale) {
137
+ const parts = new Intl.DateTimeFormat(locale, {
138
+ year: "numeric",
139
+ month: "2-digit",
140
+ day: "2-digit"
141
+ }).formatToParts(new Date(2026, 9, 2));
142
+ return {
143
+ order: parts.filter((p) => p.type === "year" || p.type === "month" || p.type === "day").map((p) => p.type),
144
+ separator: parts.find((p) => p.type === "literal")?.value ?? "-"
145
+ };
146
+ }
147
+ /**
148
+ * Writes an ISO `YYYY-MM-DD` date the way {@link parseDate} reads it back: `iso` keeps it as is;
149
+ * `locale` uses the locale's numeric order with two-digit month and day (`10/02/2026` in `en-US`,
150
+ * `02.10.2026` in `de`). A string that is not an ISO date is returned unchanged.
151
+ */
152
+ function formatDateText(iso, format = "iso", locale) {
153
+ const m = /^(\d{4})-(\d{2})-(\d{2})$/.exec(iso);
154
+ if (!m || format === "iso") return iso;
155
+ return new Intl.DateTimeFormat(locale ?? Locale.get(), {
156
+ year: "numeric",
157
+ month: "2-digit",
158
+ day: "2-digit"
159
+ }).format(new Date(Number(m[1]), Number(m[2]) - 1, Number(m[3])));
160
+ }
161
+ /** The pattern a person should type for `format` — `YYYY-MM-DD`, or e.g. `MM/DD/YYYY` for `locale` in `en-US`. */
162
+ function dateTextPattern(format = "iso", locale) {
163
+ if (format === "iso") return "YYYY-MM-DD";
164
+ const { order, separator } = numericDateLayout(locale ?? Locale.get());
165
+ const token = {
166
+ year: "YYYY",
167
+ month: "MM",
168
+ day: "DD"
169
+ };
170
+ return order.map((p) => token[p]).join(separator);
171
+ }
172
+ /**
173
+ * Reads a date the way people type it into a field and returns it as ISO `YYYY-MM-DD`, or `null`
174
+ * when the text is not a real date (`2026-02-30` is `null`). Accepted, whatever `format` is:
175
+ * - `2026-10-02`, `2026/10/02`, `2026.10.02`, `2026. 10. 2.` — a four-digit first part is year-month-day;
176
+ * - `20261002` — eight digits are year, month, day.
177
+ *
178
+ * `format` decides the rest: with `iso`, three parts are year-month-day and two parts (`10-02`)
179
+ * are month-day; with `locale`, both follow the locale's numeric order (`10/02/2026` and `10/02`
180
+ * in `en-US`, `02.10.2026` and `2.10` in `de`). Two parts take the year of `referenceDate`
181
+ * (today by default). Two-digit years are not read.
182
+ */
183
+ function parseDate(text, options = {}) {
184
+ const t = text.trim().replace(/\.$/, "");
185
+ if (!t) return null;
186
+ let y, mo, d;
187
+ const compact = /^(\d{4})(\d{2})(\d{2})$/.exec(t);
188
+ const parts = compact ? null : t.split(/\s*[-/.]\s*|\s+/);
189
+ if (compact) [y, mo, d] = [
190
+ Number(compact[1]),
191
+ Number(compact[2]),
192
+ Number(compact[3])
193
+ ];
194
+ else {
195
+ if (!parts || parts.some((p) => !/^\d{1,4}$/.test(p))) return null;
196
+ const order = options.format === "locale" ? numericDateLayout(options.locale ?? Locale.get()).order : [
197
+ "year",
198
+ "month",
199
+ "day"
200
+ ];
201
+ let layout;
202
+ if (parts.length === 3) layout = parts[0].length === 4 ? [
203
+ "year",
204
+ "month",
205
+ "day"
206
+ ] : order;
207
+ else if (parts.length === 2) layout = order.filter((p) => p !== "year");
208
+ else return null;
209
+ const read = {};
210
+ layout.forEach((p, i) => {
211
+ read[p] = parts[i];
212
+ });
213
+ if (read.year !== void 0 && read.year.length !== 4) return null;
214
+ if (read.month.length > 2 || read.day.length > 2) return null;
215
+ y = read.year !== void 0 ? Number(read.year) : (options.referenceDate ?? /* @__PURE__ */ new Date()).getFullYear();
216
+ mo = Number(read.month);
217
+ d = Number(read.day);
218
+ }
219
+ const date = new Date(y, mo - 1, d);
220
+ if (date.getFullYear() !== y || date.getMonth() !== mo - 1 || date.getDate() !== d) return null;
221
+ return `${String(y).padStart(4, "0")}-${String(mo).padStart(2, "0")}-${String(d).padStart(2, "0")}`;
222
+ }
223
+ /**
224
+ * Reads a date and a time of day as people type them and returns local `YYYY-MM-DDTHH:mm`, or `null`.
225
+ * The date part is anything {@link parseDate} reads; the time follows a space or `T` as `HH:mm`
226
+ * (`9:05`, `09:05`, `09:05:30` — seconds are dropped). Text with only a date takes `defaultTime`
227
+ * (`00:00` unless given). An hour above 23 or a minute above 59 is `null`.
228
+ */
229
+ function parseDateTime(text, options = {}) {
230
+ const t = text.trim();
231
+ const m = /^(.*?)(?:[T\s]+(\d{1,2}):(\d{2})(?::\d{2})?)?$/.exec(t);
232
+ if (!m) return null;
233
+ const date = parseDate(m[1], options);
234
+ if (!date) return null;
235
+ if (m[2] === void 0) {
236
+ const fallback = options.defaultTime ?? "00:00";
237
+ return /^\d{2}:\d{2}$/.test(fallback) ? `${date}T${fallback}` : null;
238
+ }
239
+ const h = Number(m[2]);
240
+ const min = Number(m[3]);
241
+ if (h > 23 || min > 59) return null;
242
+ return `${date}T${String(h).padStart(2, "0")}:${String(min).padStart(2, "0")}`;
243
+ }
244
+ /** Writes local `YYYY-MM-DDTHH:mm` (or a longer ISO date-time) as `{date} HH:mm`, the date part as {@link formatDateText} writes it. */
245
+ function formatDateTimeText(isoLocal, format = "iso", locale) {
246
+ const m = /^(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2})/.exec(isoLocal);
247
+ return m ? `${formatDateText(m[1], format, locale)} ${m[2]}` : isoLocal;
248
+ }
135
249
  //#endregion
136
- export { formatCurrency, formatDate, formatDateRange, formatNumber, parseNumber };
250
+ export { dateTextPattern, formatCurrency, formatDate, formatDateRange, formatDateText, formatDateTimeText, formatNumber, parseDate, 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.54.0",
4
+ "version": "1.56.0",
5
5
  "keywords": [
6
6
  "iyulab",
7
7
  "components",
@@ -14,6 +14,18 @@ value is unconditionally valid regardless of how coarse the time input was). For
14
14
 
15
15
  > The calendar week always starts on Sunday, regardless of locale.
16
16
 
17
+ **Typing a date (`mode="date"`).** The field is a text box. Type `2026-10-02`, `2026/10/2`,
18
+ `20261002`, or just `10-02` (this year), then press Enter or leave the field. The text shows as
19
+ `YYYY-MM-DD` in every browser language; `format="locale"` shows and reads the locale's numeric
20
+ order instead (`10/02/2026` in `en-US`, `02.10.2026` in `de` — ISO is still read). Clicking the
21
+ field opens the calendar and keeps the caret in the text box; ArrowDown (or Alt+ArrowDown) moves
22
+ into the calendar. Text that is not a date clears the value and reports `badInput` (the text stays
23
+ so it can be fixed); a date outside `min`/`max` is kept and reported as out of range.
24
+ In `mode="datetime"` the text box takes a time after the date (`2026-10-02 14:30`, `9:05`, seconds
25
+ dropped) and shows `YYYY-MM-DD HH:mm`; typing only a date keeps the time already set.
26
+ The parser and formatter are exported as `parseDate`, `parseDateTime`, `formatDateText`,
27
+ `formatDateTimeText` and `dateTextPattern`.
28
+
17
29
  The calendar popover has a footer with a "Today" quick-action button (selects today's date —
18
30
  in `mode="datetime"` this also sets the time to right now — disabled when today falls outside
19
31
  `min`/`max`) and, when `clearable` and a value is set, a "Clear" button next to it. Picking a
@@ -41,7 +53,8 @@ day preserves whatever time-of-day was already set; only the "Today" button over
41
53
  | `min` | `string` | — | — | Minimum selectable date (ISO `YYYY-MM-DD`, date-only in both modes) |
42
54
  | `max` | `string` | — | — | Maximum selectable date (ISO `YYYY-MM-DD`, date-only in both modes) |
43
55
  | `clearable` | `boolean` | `false` | ✓ | Show clear button |
44
- | `placeholder` | `string` | — | — | Placeholder text |
56
+ | `placeholder` | `string` | — | — | Placeholder text (defaults to the pattern to type, e.g. `YYYY-MM-DD` or `YYYY-MM-DD HH:mm`) |
57
+ | `format` | `'iso' \| 'locale'` | `'iso'` | ✓ | How the text box writes and reads the date part |
45
58
  | `disabled` | `boolean` | `false` | ✓ | Disable |
46
59
  | `readonly` | `boolean` | `false` | ✓ | Read-only |
47
60
  | `required` | `boolean` | `false` | ✓ | Required |
@@ -55,7 +68,7 @@ day preserves whatever time-of-day was already set; only the "Today" button over
55
68
 
56
69
  | Event | Description |
57
70
  |-------|-------------|
58
- | `change` | Fires when the user clicks a date cell, confirms via keyboard, changes the time input (`mode="datetime"`, once a date is set), or clicks the clear button. Programmatic value assignment does not fire it. |
71
+ | `change` | Fires when the user clicks a date cell, confirms via keyboard, commits typed text (Enter or leaving the field, when the value changes), changes the time input (`mode="datetime"`, once a date is set), or clicks the clear button. Programmatic value assignment does not fire it. |
59
72
 
60
73
  ## Methods
61
74
 
@@ -72,6 +85,7 @@ day preserves whatever time-of-day was already set; only the "Today" button over
72
85
  |------|-------------|
73
86
  | `field` | The `u-field` element |
74
87
  | `container` | The element wrapping the trigger area |
88
+ | `input` | The text box |
75
89
  | `popover` | The popover element showing the calendar |
76
90
  | `calendar` | The calendar container |
77
91
  | `calendar-header` | The month navigation header |