@iyulab/components 1.57.0 → 1.57.1
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 +9 -0
- package/dist/components/calendar/date-text-controller.d.ts +62 -0
- package/dist/components/calendar/date-text-controller.js +90 -0
- package/dist/components/date-picker/UDatePicker.d.ts +4 -20
- package/dist/components/date-picker/UDatePicker.js +40 -73
- package/dist/components/date-range-picker/UDateRangePicker.d.ts +2 -17
- package/dist/components/date-range-picker/UDateRangePicker.js +34 -75
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.57.1] - 2026-10-03
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **`u-date-picker`: picking a day after typing shows the picked day.** Text typed into the field but
|
|
8
|
+
not yet committed stayed in the box after a day was picked in the calendar (or the time changed), so
|
|
9
|
+
the field showed the half-typed text while the value was the picked day. `u-date-range-picker` already
|
|
10
|
+
cleared it; both pickers now share one implementation of the text box.
|
|
11
|
+
|
|
3
12
|
## [1.57.0] - 2026-10-03
|
|
4
13
|
|
|
5
14
|
### Added
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { ReactiveController, ReactiveControllerHost } from 'lit';
|
|
2
|
+
import { UCalendar } from './UCalendar.js';
|
|
3
|
+
import { UPopover } from '../popover/UPopover.js';
|
|
4
|
+
/** What a picker with a typed-date text box gives the controller. */
|
|
5
|
+
export interface DateTextControllerOptions {
|
|
6
|
+
/** The value to commit for the typed text — `undefined` for empty text, `null` when it is not readable. */
|
|
7
|
+
toValue(text: string): string | undefined | null;
|
|
8
|
+
/** The ISO day the typed text points at, so an open calendar can follow the typing; `null` when none. */
|
|
9
|
+
dayOf(text: string): string | null;
|
|
10
|
+
/** The value as the text box shows it when nothing is being typed. */
|
|
11
|
+
shown(): string;
|
|
12
|
+
/** Called after a commit that changed the value — the picker validates and fires `change`. */
|
|
13
|
+
onChange(): void;
|
|
14
|
+
/** Called when unreadable text is committed without a value change — the picker re-validates. */
|
|
15
|
+
onBadText(): void;
|
|
16
|
+
popover(): UPopover | undefined;
|
|
17
|
+
calendar(): UCalendar | undefined;
|
|
18
|
+
container(): HTMLElement | undefined;
|
|
19
|
+
input(): HTMLInputElement | null;
|
|
20
|
+
/** Whether the picker takes input now (not disabled, not read-only). */
|
|
21
|
+
interactive(): boolean;
|
|
22
|
+
}
|
|
23
|
+
type Host = ReactiveControllerHost & HTMLElement & {
|
|
24
|
+
value?: string;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The typed-date text box shared by `u-date-picker` and `u-date-range-picker`: what is being typed
|
|
28
|
+
* (`draft`), whether the last commit was unreadable (`badText`), committing on Enter and blur,
|
|
29
|
+
* opening the calendar on a click (caret stays in the box) or ArrowDown (focus moves into the grid),
|
|
30
|
+
* and following the typing in an open calendar.
|
|
31
|
+
*/
|
|
32
|
+
export declare class DateTextController implements ReactiveController {
|
|
33
|
+
private readonly host;
|
|
34
|
+
private readonly options;
|
|
35
|
+
/** What the person is typing, until it is committed; `null` shows the value. */
|
|
36
|
+
draft: string | null;
|
|
37
|
+
/** The committed text was not readable — the value is empty and validity reports `badInput`. */
|
|
38
|
+
badText: boolean;
|
|
39
|
+
private focusGridOnOpen;
|
|
40
|
+
constructor(host: Host, options: DateTextControllerOptions);
|
|
41
|
+
hostConnected(): void;
|
|
42
|
+
/** The text box's current text. */
|
|
43
|
+
get text(): string;
|
|
44
|
+
/** Forget what was typed — after a calendar pick, a clear or a reset. */
|
|
45
|
+
clear(): void;
|
|
46
|
+
/** Called when the calendar has opened: show the typed (or current) month and, if the opening
|
|
47
|
+
* came from the keyboard, move focus into the grid. */
|
|
48
|
+
calendarOpened(fallbackDay: string | Date): void;
|
|
49
|
+
open(focusGrid: boolean): void;
|
|
50
|
+
handleInput: (e: Event) => void;
|
|
51
|
+
/** ArrowDown / Alt+ArrowDown opens the calendar and moves into it (the combobox convention);
|
|
52
|
+
* Enter commits what was typed. Escape belongs to the popover layer — it closes the calendar. */
|
|
53
|
+
handleKeydown: (e: KeyboardEvent) => void;
|
|
54
|
+
/** A click on the field (not on its clear or calendar button) opens the calendar and keeps the
|
|
55
|
+
* caret in the text box — the person can pick a day or keep typing. */
|
|
56
|
+
handleContainerClick: (e: MouseEvent) => void;
|
|
57
|
+
handleCalendarButtonClick: (e: MouseEvent) => void;
|
|
58
|
+
/** Turns the typed text into the value. Empty text clears it; unreadable text also clears it and
|
|
59
|
+
* reports `badInput` while the text stays to be fixed (the native date input does the same). */
|
|
60
|
+
commit: () => void;
|
|
61
|
+
}
|
|
62
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//#region src/components/calendar/date-text-controller.ts
|
|
2
|
+
/**
|
|
3
|
+
* The typed-date text box shared by `u-date-picker` and `u-date-range-picker`: what is being typed
|
|
4
|
+
* (`draft`), whether the last commit was unreadable (`badText`), committing on Enter and blur,
|
|
5
|
+
* opening the calendar on a click (caret stays in the box) or ArrowDown (focus moves into the grid),
|
|
6
|
+
* and following the typing in an open calendar.
|
|
7
|
+
*/
|
|
8
|
+
var DateTextController = class {
|
|
9
|
+
constructor(host, options) {
|
|
10
|
+
this.host = host;
|
|
11
|
+
this.options = options;
|
|
12
|
+
this.draft = null;
|
|
13
|
+
this.badText = false;
|
|
14
|
+
this.focusGridOnOpen = false;
|
|
15
|
+
this.handleInput = (e) => {
|
|
16
|
+
this.draft = e.target.value;
|
|
17
|
+
this.host.requestUpdate();
|
|
18
|
+
const day = this.options.dayOf(this.draft);
|
|
19
|
+
if (day && this.options.popover()?.open) this.options.calendar()?.showDate(day);
|
|
20
|
+
};
|
|
21
|
+
this.handleKeydown = (e) => {
|
|
22
|
+
if (e.key === "ArrowDown") {
|
|
23
|
+
e.preventDefault();
|
|
24
|
+
this.commit();
|
|
25
|
+
this.open(true);
|
|
26
|
+
} else if (e.key === "Enter" && !e.isComposing) this.commit();
|
|
27
|
+
};
|
|
28
|
+
this.handleContainerClick = (e) => {
|
|
29
|
+
if (e.target.closest?.("u-icon")) return;
|
|
30
|
+
const input = this.options.input();
|
|
31
|
+
const root = this.host.shadowRoot;
|
|
32
|
+
if (input && root && root.activeElement !== input) input.focus();
|
|
33
|
+
this.open(false);
|
|
34
|
+
};
|
|
35
|
+
this.handleCalendarButtonClick = (e) => {
|
|
36
|
+
e.stopPropagation();
|
|
37
|
+
if (this.options.popover()?.open) {
|
|
38
|
+
this.options.popover()?.hide();
|
|
39
|
+
this.options.input()?.focus();
|
|
40
|
+
} else this.open(true);
|
|
41
|
+
};
|
|
42
|
+
this.commit = () => {
|
|
43
|
+
if (this.draft === null) return;
|
|
44
|
+
const text = this.draft;
|
|
45
|
+
const next = this.options.toValue(text);
|
|
46
|
+
this.badText = next === null;
|
|
47
|
+
const value = next ?? void 0;
|
|
48
|
+
const changed = value !== this.host.value;
|
|
49
|
+
this.host.value = value;
|
|
50
|
+
this.draft = this.badText ? text : null;
|
|
51
|
+
this.host.requestUpdate();
|
|
52
|
+
if (changed) this.options.onChange();
|
|
53
|
+
else if (this.badText) this.options.onBadText();
|
|
54
|
+
};
|
|
55
|
+
host.addController(this);
|
|
56
|
+
}
|
|
57
|
+
hostConnected() {}
|
|
58
|
+
/** The text box's current text. */
|
|
59
|
+
get text() {
|
|
60
|
+
return this.draft ?? this.options.shown();
|
|
61
|
+
}
|
|
62
|
+
/** Forget what was typed — after a calendar pick, a clear or a reset. */
|
|
63
|
+
clear() {
|
|
64
|
+
this.draft = null;
|
|
65
|
+
this.badText = false;
|
|
66
|
+
this.host.requestUpdate();
|
|
67
|
+
}
|
|
68
|
+
/** Called when the calendar has opened: show the typed (or current) month and, if the opening
|
|
69
|
+
* came from the keyboard, move focus into the grid. */
|
|
70
|
+
calendarOpened(fallbackDay) {
|
|
71
|
+
const calendar = this.options.calendar();
|
|
72
|
+
const typed = this.draft !== null ? this.options.dayOf(this.draft) : null;
|
|
73
|
+
calendar?.showDate(typed ?? fallbackDay);
|
|
74
|
+
const moveFocus = this.focusGridOnOpen;
|
|
75
|
+
this.focusGridOnOpen = false;
|
|
76
|
+
if (moveFocus) this.options.popover()?.updateComplete.then(() => calendar?.focusDay());
|
|
77
|
+
}
|
|
78
|
+
open(focusGrid) {
|
|
79
|
+
if (!this.options.interactive()) return;
|
|
80
|
+
if (this.options.popover()?.open) {
|
|
81
|
+
if (focusGrid) this.options.calendar()?.focusDay();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this.focusGridOnOpen = focusGrid;
|
|
85
|
+
const container = this.options.container();
|
|
86
|
+
if (container) this.options.popover()?.show(container);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
//#endregion
|
|
90
|
+
export { DateTextController };
|
|
@@ -84,14 +84,11 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
84
84
|
/** Time-of-day for the next selection while no `value` exists yet (`mode="datetime"` only) —
|
|
85
85
|
* once `value` is set, the time input reads/writes its time portion directly instead. */
|
|
86
86
|
private pendingTime;
|
|
87
|
-
/**
|
|
88
|
-
private
|
|
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;
|
|
87
|
+
/** The typed-date text box — what is being typed, committing it, opening the calendar. */
|
|
88
|
+
private readonly textEntry;
|
|
94
89
|
protected updated(changed: PropertyValues): void;
|
|
90
|
+
/** The value as the text box shows it: `YYYY-MM-DD`, or `YYYY-MM-DD HH:mm` in `mode="datetime"`. */
|
|
91
|
+
private shownText;
|
|
95
92
|
render(): import('lit-html').TemplateResult<1>;
|
|
96
93
|
private renderCalendar;
|
|
97
94
|
private renderTimeRow;
|
|
@@ -108,22 +105,9 @@ export declare class UDatePicker extends UFormControlElement<string> {
|
|
|
108
105
|
private handleTimeChange;
|
|
109
106
|
private handleDaySelect;
|
|
110
107
|
private get textInputEl();
|
|
111
|
-
private openCalendar;
|
|
112
108
|
/** The typed text as a date (ISO) and, in `mode="datetime"`, a time — or `null` when it is not one.
|
|
113
109
|
* Typing only a date in `mode="datetime"` keeps the time already set (or the pending one). */
|
|
114
110
|
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;
|
|
127
111
|
/** Escape inside the grid closes the calendar and returns focus to the trigger — the grid
|
|
128
112
|
* itself does not know it lives in a popover, so the picker owns this. */
|
|
129
113
|
private handleCalendarKeydown;
|
|
@@ -9,6 +9,7 @@ import { isOutOfRange, parseISODate, toISODate } from "../calendar/dates.js";
|
|
|
9
9
|
import { UCalendar } from "../calendar/UCalendar.js";
|
|
10
10
|
import "../field/UField.js";
|
|
11
11
|
import { UPopover } from "../popover/UPopover.js";
|
|
12
|
+
import { DateTextController } from "../calendar/date-text-controller.js";
|
|
12
13
|
import { styles } from "../calendar/picker.styles.js";
|
|
13
14
|
import { styles as styles$1 } from "./UDatePicker.styles.js";
|
|
14
15
|
import { html } from "lit";
|
|
@@ -49,59 +50,39 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
49
50
|
this.calendarId = `u-date-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
|
|
50
51
|
this.open = false;
|
|
51
52
|
this.pendingTime = "00:00";
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
this.textEntry = new DateTextController(this, {
|
|
54
|
+
toValue: (text) => {
|
|
55
|
+
if (!text.trim()) return void 0;
|
|
56
|
+
const typed = this.parseTyped(text);
|
|
57
|
+
if (!typed) return null;
|
|
58
|
+
if (this.mode === "datetime") this.pendingTime = typed.time;
|
|
59
|
+
return buildValue(parseISODate(typed.date), this.mode, typed.time);
|
|
60
|
+
},
|
|
61
|
+
dayOf: (text) => this.parseTyped(text)?.date ?? null,
|
|
62
|
+
shown: () => this.shownText(),
|
|
63
|
+
onChange: () => this.emitChange(),
|
|
64
|
+
onBadText: () => {
|
|
65
|
+
if (!this.novalidate) this.validate();
|
|
66
|
+
},
|
|
67
|
+
popover: () => this.popoverEl,
|
|
68
|
+
calendar: () => this.calendarEl,
|
|
69
|
+
container: () => this.containerEl,
|
|
70
|
+
input: () => this.textInputEl,
|
|
71
|
+
interactive: () => !this.effectivelyDisabled && !this.readonly
|
|
72
|
+
});
|
|
55
73
|
this.handleTimeChange = (e) => {
|
|
56
74
|
const time = e.target.value || "00:00";
|
|
57
75
|
this.pendingTime = time;
|
|
58
76
|
if (!this.value) return;
|
|
59
77
|
const iso = buildValue(splitValue(this.value).date, this.mode, time);
|
|
60
78
|
const changed = iso !== this.value;
|
|
79
|
+
this.textEntry.clear();
|
|
61
80
|
this.value = iso;
|
|
62
81
|
if (changed) this.emitChange();
|
|
63
82
|
};
|
|
64
83
|
this.handleDaySelect = (e) => {
|
|
65
84
|
this.selectDay(parseISODate(e.detail.date));
|
|
66
85
|
};
|
|
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
|
-
};
|
|
105
86
|
this.handleCalendarKeydown = (e) => {
|
|
106
87
|
if (e.key !== "Escape") return;
|
|
107
88
|
e.preventDefault();
|
|
@@ -147,18 +128,16 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
147
128
|
super.updated(changed);
|
|
148
129
|
if (changed.has("value")) this.internals?.setFormValue(this.value ?? "");
|
|
149
130
|
if (changed.has("open")) this.internals?.states[this.open ? "add" : "delete"]("open");
|
|
150
|
-
if (changed.has("open") && this.open)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
131
|
+
if (changed.has("open") && this.open) this.textEntry.calendarOpened(this.value ? toISODate(splitValue(this.value).date) : /* @__PURE__ */ new Date());
|
|
132
|
+
}
|
|
133
|
+
/** The value as the text box shows it: `YYYY-MM-DD`, or `YYYY-MM-DD HH:mm` in `mode="datetime"`. */
|
|
134
|
+
shownText() {
|
|
135
|
+
if (!this.value) return "";
|
|
136
|
+
const { date, time } = splitValue(this.value);
|
|
137
|
+
return this.mode === "datetime" ? formatDateTimeText(`${toISODate(date)}T${time}`, this.format) : formatDateText(toISODate(date), this.format);
|
|
158
138
|
}
|
|
159
139
|
render() {
|
|
160
140
|
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) : "";
|
|
162
141
|
return html`
|
|
163
142
|
<u-field part="field"
|
|
164
143
|
?required=${this.required}
|
|
@@ -168,7 +147,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
168
147
|
.description=${this.description}
|
|
169
148
|
.validationMessage=${this.validationMessage}
|
|
170
149
|
>
|
|
171
|
-
<div class="container" part="container" @click=${this.handleContainerClick}>
|
|
150
|
+
<div class="container" part="container" @click=${this.textEntry.handleContainerClick}>
|
|
172
151
|
<input class="text-input" part="input"
|
|
173
152
|
type="text"
|
|
174
153
|
inputmode=${datetime ? "text" : "numeric"}
|
|
@@ -179,14 +158,14 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
179
158
|
aria-controls=${this.calendarId}
|
|
180
159
|
aria-label=${ifDefined(this.resolvedAriaLabel)}
|
|
181
160
|
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
182
|
-
aria-invalid=${this.badText ? "true" : "false"}
|
|
161
|
+
aria-invalid=${this.textEntry.badText ? "true" : "false"}
|
|
183
162
|
placeholder=${this.placeholder ?? (datetime ? `${dateTextPattern(this.format)} HH:mm` : dateTextPattern(this.format))}
|
|
184
|
-
.value=${this.
|
|
163
|
+
.value=${this.textEntry.text}
|
|
185
164
|
?disabled=${this.effectivelyDisabled}
|
|
186
165
|
?readonly=${this.readonly}
|
|
187
|
-
@input=${this.
|
|
188
|
-
@keydown=${this.
|
|
189
|
-
@blur=${this.
|
|
166
|
+
@input=${this.textEntry.handleInput}
|
|
167
|
+
@keydown=${this.textEntry.handleKeydown}
|
|
168
|
+
@blur=${this.textEntry.commit}
|
|
190
169
|
/>
|
|
191
170
|
<u-icon class="suffix-item"
|
|
192
171
|
?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
|
|
@@ -205,7 +184,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
205
184
|
?hidden=${this.effectivelyDisabled || this.readonly}
|
|
206
185
|
lib="internal"
|
|
207
186
|
name="calendar"
|
|
208
|
-
@click=${this.handleCalendarButtonClick}
|
|
187
|
+
@click=${this.textEntry.handleCalendarButtonClick}
|
|
209
188
|
></u-icon>
|
|
210
189
|
</div>
|
|
211
190
|
</u-field>
|
|
@@ -275,6 +254,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
275
254
|
const time = timeOverride ?? (this.value ? splitValue(this.value).time : this.pendingTime);
|
|
276
255
|
const iso = buildValue(date, this.mode, time);
|
|
277
256
|
const changed = iso !== this.value;
|
|
257
|
+
this.textEntry.clear();
|
|
278
258
|
this.value = iso;
|
|
279
259
|
if (this.mode === "datetime") this.pendingTime = time;
|
|
280
260
|
if (changed) this.emitChange();
|
|
@@ -284,15 +264,6 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
284
264
|
get textInputEl() {
|
|
285
265
|
return this.renderRoot.querySelector(".text-input");
|
|
286
266
|
}
|
|
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
267
|
/** The typed text as a date (ISO) and, in `mode="datetime"`, a time — or `null` when it is not one.
|
|
297
268
|
* Typing only a date in `mode="datetime"` keeps the time already set (or the pending one). */
|
|
298
269
|
parseTyped(text) {
|
|
@@ -315,8 +286,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
315
286
|
}
|
|
316
287
|
resetValue() {
|
|
317
288
|
const hadValue = !!this.value;
|
|
318
|
-
this.
|
|
319
|
-
this.badText = false;
|
|
289
|
+
this.textEntry.clear();
|
|
320
290
|
this.value = void 0;
|
|
321
291
|
if (hadValue) this.emitChange();
|
|
322
292
|
}
|
|
@@ -330,7 +300,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
330
300
|
setValidity() {
|
|
331
301
|
let flags = {};
|
|
332
302
|
let message = "";
|
|
333
|
-
if (this.badText) {
|
|
303
|
+
if (this.textEntry.badText) {
|
|
334
304
|
flags = { badInput: true };
|
|
335
305
|
message = Locale.getValue("badInput");
|
|
336
306
|
} else if (this.required && !this.value) {
|
|
@@ -347,8 +317,7 @@ var UDatePicker = class UDatePicker extends UFormControlElement {
|
|
|
347
317
|
}
|
|
348
318
|
reset() {
|
|
349
319
|
this.value = void 0;
|
|
350
|
-
this.
|
|
351
|
-
this.badText = false;
|
|
320
|
+
this.textEntry.clear();
|
|
352
321
|
this.invalid = false;
|
|
353
322
|
}
|
|
354
323
|
/** `.container`는 div라 네이티브 `disabled`가 없다 — disabled일 때 `tabindex="-1"`로만
|
|
@@ -382,8 +351,6 @@ __decorate([query("u-popover", true), __decorateMetadata("design:type", typeof U
|
|
|
382
351
|
__decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDatePicker.prototype, "calendarEl", void 0);
|
|
383
352
|
__decorate([state(), __decorateMetadata("design:type", Boolean)], UDatePicker.prototype, "open", void 0);
|
|
384
353
|
__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);
|
|
387
354
|
UDatePicker = __decorate([customElement("u-date-picker")], UDatePicker);
|
|
388
355
|
//#endregion
|
|
389
356
|
export { UDatePicker };
|
|
@@ -88,12 +88,8 @@ export declare class UDateRangePicker extends UFormControlElement<string> {
|
|
|
88
88
|
calendarEl?: UCalendar;
|
|
89
89
|
private readonly calendarId;
|
|
90
90
|
private open;
|
|
91
|
-
/**
|
|
92
|
-
private
|
|
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;
|
|
91
|
+
/** The typed-range text box — what is being typed, committing it, opening the calendar. */
|
|
92
|
+
private readonly textEntry;
|
|
97
93
|
protected willUpdate(changed: PropertyValues): void;
|
|
98
94
|
protected shouldValidate(changed: PropertyValues): boolean;
|
|
99
95
|
protected updated(changed: PropertyValues): void;
|
|
@@ -107,17 +103,6 @@ export declare class UDateRangePicker extends UFormControlElement<string> {
|
|
|
107
103
|
/** A user-chosen range (calendar or preset): set it, announce it, close the calendar. */
|
|
108
104
|
private commitRange;
|
|
109
105
|
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;
|
|
121
106
|
/** Escape that reaches the picker closes the calendar — the calendar keeps the first Escape
|
|
122
107
|
* for itself while a range is half picked. */
|
|
123
108
|
private handleCalendarKeydown;
|
|
@@ -10,6 +10,7 @@ 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";
|
|
13
14
|
import { styles } from "../calendar/picker.styles.js";
|
|
14
15
|
import { resolvePresets } from "./presets.js";
|
|
15
16
|
import { styles as styles$1 } from "./UDateRangePicker.styles.js";
|
|
@@ -36,49 +37,30 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
36
37
|
this.presets = [];
|
|
37
38
|
this.calendarId = `u-date-range-picker-calendar-${Math.random().toString(36).slice(2, 8)}`;
|
|
38
39
|
this.open = false;
|
|
39
|
-
this.
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
this.textEntry = new DateTextController(this, {
|
|
41
|
+
toValue: (text) => {
|
|
42
|
+
if (!text.trim()) return void 0;
|
|
43
|
+
const range = parseDateRange(text, { format: this.format });
|
|
44
|
+
return range ? `${range.start}/${range.end}` : null;
|
|
45
|
+
},
|
|
46
|
+
dayOf: (text) => parseDateRange(text, { format: this.format })?.start ?? null,
|
|
47
|
+
shown: () => {
|
|
48
|
+
const range = parseInterval(this.value);
|
|
49
|
+
return range ? formatDateRangeText(range.start, range.end, this.format) : this.value ?? "";
|
|
50
|
+
},
|
|
51
|
+
onChange: () => this.emitChange(),
|
|
52
|
+
onBadText: () => {
|
|
53
|
+
if (!this.novalidate) this.validate();
|
|
54
|
+
},
|
|
55
|
+
popover: () => this.popoverEl,
|
|
56
|
+
calendar: () => this.calendarEl,
|
|
57
|
+
container: () => this.containerEl,
|
|
58
|
+
input: () => this.textInputEl,
|
|
59
|
+
interactive: () => !this.effectivelyDisabled && !this.readonly
|
|
60
|
+
});
|
|
42
61
|
this.handleRangeSelect = (e) => {
|
|
43
62
|
this.commitRange(e.detail.start, e.detail.end);
|
|
44
63
|
};
|
|
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
|
-
};
|
|
82
64
|
this.handleCalendarKeydown = (e) => {
|
|
83
65
|
if (e.key !== "Escape") return;
|
|
84
66
|
e.preventDefault();
|
|
@@ -137,18 +119,9 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
137
119
|
super.updated(changed);
|
|
138
120
|
if (changed.has("value")) this.internals?.setFormValue(this.value ?? "");
|
|
139
121
|
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
|
-
}
|
|
122
|
+
if (changed.has("open") && this.open) this.textEntry.calendarOpened(this.start ?? /* @__PURE__ */ new Date());
|
|
148
123
|
}
|
|
149
124
|
render() {
|
|
150
|
-
const range = parseInterval(this.value);
|
|
151
|
-
const shown = range ? formatDateRangeText(range.start, range.end, this.format) : this.value ?? "";
|
|
152
125
|
const pattern = dateTextPattern(this.format);
|
|
153
126
|
return html`
|
|
154
127
|
<u-field part="field"
|
|
@@ -159,7 +132,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
159
132
|
.description=${this.description}
|
|
160
133
|
.validationMessage=${this.validationMessage}
|
|
161
134
|
>
|
|
162
|
-
<div class="container" part="container" @click=${this.handleContainerClick}>
|
|
135
|
+
<div class="container" part="container" @click=${this.textEntry.handleContainerClick}>
|
|
163
136
|
<input class="text-input" part="input"
|
|
164
137
|
type="text"
|
|
165
138
|
autocomplete="off"
|
|
@@ -169,14 +142,14 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
169
142
|
aria-controls=${this.calendarId}
|
|
170
143
|
aria-label=${ifDefined(this.resolvedAriaLabel)}
|
|
171
144
|
aria-description=${ifDefined(this.resolvedAriaDescription)}
|
|
172
|
-
aria-invalid=${this.badText ? "true" : "false"}
|
|
145
|
+
aria-invalid=${this.textEntry.badText ? "true" : "false"}
|
|
173
146
|
placeholder=${this.placeholder ?? `${pattern} – ${pattern}`}
|
|
174
|
-
.value=${this.
|
|
147
|
+
.value=${this.textEntry.text}
|
|
175
148
|
?disabled=${this.effectivelyDisabled}
|
|
176
149
|
?readonly=${this.readonly}
|
|
177
|
-
@input=${this.
|
|
178
|
-
@keydown=${this.
|
|
179
|
-
@blur=${this.
|
|
150
|
+
@input=${this.textEntry.handleInput}
|
|
151
|
+
@keydown=${this.textEntry.handleKeydown}
|
|
152
|
+
@blur=${this.textEntry.commit}
|
|
180
153
|
/>
|
|
181
154
|
<u-icon class="suffix-item"
|
|
182
155
|
?hidden=${!this.clearable || !this.value || this.effectivelyDisabled || this.readonly}
|
|
@@ -195,7 +168,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
195
168
|
?hidden=${this.effectivelyDisabled || this.readonly}
|
|
196
169
|
lib="internal"
|
|
197
170
|
name="calendar"
|
|
198
|
-
@click=${this.handleCalendarButtonClick}
|
|
171
|
+
@click=${this.textEntry.handleCalendarButtonClick}
|
|
199
172
|
></u-icon>
|
|
200
173
|
</div>
|
|
201
174
|
</u-field>
|
|
@@ -265,8 +238,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
265
238
|
commitRange(start, end) {
|
|
266
239
|
const next = `${start}/${end}`;
|
|
267
240
|
const changed = next !== this.value;
|
|
268
|
-
this.
|
|
269
|
-
this.badText = false;
|
|
241
|
+
this.textEntry.clear();
|
|
270
242
|
this.value = next;
|
|
271
243
|
if (changed) this.emitChange();
|
|
272
244
|
this.popoverEl?.hide();
|
|
@@ -275,19 +247,9 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
275
247
|
get textInputEl() {
|
|
276
248
|
return this.renderRoot.querySelector(".text-input");
|
|
277
249
|
}
|
|
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
250
|
resetValue() {
|
|
288
251
|
const hadValue = !!this.value;
|
|
289
|
-
this.
|
|
290
|
-
this.badText = false;
|
|
252
|
+
this.textEntry.clear();
|
|
291
253
|
this.value = void 0;
|
|
292
254
|
if (hadValue) this.emitChange();
|
|
293
255
|
}
|
|
@@ -302,7 +264,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
302
264
|
let flags = {};
|
|
303
265
|
let message = "";
|
|
304
266
|
const range = parseInterval(this.value);
|
|
305
|
-
if (this.badText) {
|
|
267
|
+
if (this.textEntry.badText) {
|
|
306
268
|
flags = { badInput: true };
|
|
307
269
|
message = Locale.getValue("badInput");
|
|
308
270
|
} else if (this.required && !this.value) {
|
|
@@ -322,8 +284,7 @@ var UDateRangePicker = class UDateRangePicker extends UFormControlElement {
|
|
|
322
284
|
}
|
|
323
285
|
reset() {
|
|
324
286
|
this.value = void 0;
|
|
325
|
-
this.
|
|
326
|
-
this.badText = false;
|
|
287
|
+
this.textEntry.clear();
|
|
327
288
|
this.invalid = false;
|
|
328
289
|
}
|
|
329
290
|
focus(options) {
|
|
@@ -353,8 +314,6 @@ __decorate([query(".container", true), __decorateMetadata("design:type", typeof
|
|
|
353
314
|
__decorate([query("u-popover", true), __decorateMetadata("design:type", typeof UPopover === "undefined" ? Object : UPopover)], UDateRangePicker.prototype, "popoverEl", void 0);
|
|
354
315
|
__decorate([query("u-calendar"), __decorateMetadata("design:type", typeof UCalendar === "undefined" ? Object : UCalendar)], UDateRangePicker.prototype, "calendarEl", void 0);
|
|
355
316
|
__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);
|
|
358
317
|
UDateRangePicker = __decorate([customElement("u-date-range-picker")], UDateRangePicker);
|
|
359
318
|
//#endregion
|
|
360
319
|
export { UDateRangePicker };
|