@design.estate/dees-catalog 24.6.0 → 24.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist_bundle/bundle.js +141 -66
- package/dist_bundle/bundle.js.map +1 -1
- package/dist_ts_web/00_commitinfo_data.js +1 -1
- package/dist_ts_web/elements/00group-appui/dees-appui/dees-appui.js +16 -7
- package/dist_ts_web/elements/00group-input/dees-input-datepicker/component.d.ts +58 -7
- package/dist_ts_web/elements/00group-input/dees-input-datepicker/component.js +127 -60
- package/dist_ts_web/elements/00group-input/dees-input-datepicker/demo.js +16 -2
- package/dist_ts_web/elements/00group-input/dees-input-datepicker/template.js +15 -2
- package/package.json +1 -1
- package/readme.md +42 -15
- package/ts_web/00_commitinfo_data.ts +1 -1
- package/ts_web/elements/00group-appui/dees-appui/dees-appui.ts +12 -6
- package/ts_web/elements/00group-appui/dees-appui/readme.md +6 -0
- package/ts_web/elements/00group-input/dees-input-datepicker/component.ts +121 -53
- package/ts_web/elements/00group-input/dees-input-datepicker/demo.ts +21 -1
- package/ts_web/elements/00group-input/dees-input-datepicker/template.ts +13 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@design.estate/dees-catalog",
|
|
3
|
-
"version": "24.6.
|
|
3
|
+
"version": "24.6.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.",
|
|
6
6
|
"main": "dist_ts_web/index.js",
|
package/readme.md
CHANGED
|
@@ -1818,13 +1818,14 @@ both bubbling and composed, so a Lit template or a composite input listens with
|
|
|
1818
1818
|
`@input` and `@change` as on a native control:
|
|
1819
1819
|
|
|
1820
1820
|
- `input` as the value changes: each keystroke of a text field, each edit of an
|
|
1821
|
-
editor (code, richtext, wysiwyg), each
|
|
1821
|
+
editor (code, richtext, wysiwyg), each edit of a datepicker's text that changes its
|
|
1822
|
+
value, each pick of a choice.
|
|
1822
1823
|
- `change` when the reader commits it: a text field (text, textarea, phone, IBAN)
|
|
1823
1824
|
when the reader leaves it with a changed value or presses Enter in a single-line
|
|
1824
|
-
one, as the native field does
|
|
1825
|
-
every other input — checkbox, toggle,
|
|
1826
|
-
|
|
1827
|
-
once, right after its `input`.
|
|
1825
|
+
one, as the native field does, and so a date typed into a datepicker; an editor
|
|
1826
|
+
when the reader leaves it after editing; every other input — checkbox, toggle,
|
|
1827
|
+
dropdown, radiogroup, multitoggle, quantityselector, a date picked in a datepicker,
|
|
1828
|
+
tags, typelist, list, fileupload, profilepicture — at once, right after its `input`.
|
|
1828
1829
|
|
|
1829
1830
|
The event's target is the input: read `event.target.value` (or `getValue()`). The
|
|
1830
1831
|
events an input dispatches itself also carry the value as `detail.value`; the `input`
|
|
@@ -2346,13 +2347,39 @@ Profile picture input with cropping, zoom, and image processing.
|
|
|
2346
2347
|
|
|
2347
2348
|
#### `DeesInputDatepicker`
|
|
2348
2349
|
Date and time picker component with calendar interface and manual typing support.
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2350
|
+
Listen to `change` (or `changeSubject`) for a committed date, to `input` for the value
|
|
2351
|
+
as the reader types, or collect `.value` through `dees-form`. `input` and `change`
|
|
2352
|
+
carry the field's `value` as `detail.value`; `validation-change` carries `valid` and
|
|
2353
|
+
`message`.
|
|
2354
|
+
|
|
2355
|
+
| What the reader does | What the field reports |
|
|
2356
|
+
| --- | --- |
|
|
2357
|
+
| An edit of the text that changes the value | `value` is set at once, then `input`; `validation-change` first when the text's validity changes. No `change`, no `changeSubject`. |
|
|
2358
|
+
| An edit that leaves the value as it is | only `validation-change`, when the text's validity changes |
|
|
2359
|
+
| Enter, or leaving the field | `changeSubject`, then `change`, once, when the value differs from the one before the typing began; nothing when it is the same |
|
|
2360
|
+
| A day, a time box, Today or Clear in the calendar, or the field's Clear | at once: `changeSubject`, `input`, then `change`, when the value differs from the one before the typing (the value, when nothing is typed); only `input` when it takes a typed value back to that one |
|
|
2361
|
+
| Code sets `value` to another value, or calls `setValue()` or `reset()` | nothing; typed text is replaced, and the value set is the one the next typing starts from |
|
|
2362
|
+
|
|
2363
|
+
While the reader types, `value` is always what Enter would leave: the moment the text
|
|
2364
|
+
names, nothing for emptied text, and for text the field does not take (no date yet, an
|
|
2365
|
+
invalid calendar day, a day outside the bounds or in `disabledDates`) the value from
|
|
2366
|
+
before the typing, so a date taken on the way (`2026-02-3`, 3 February, on the way to
|
|
2367
|
+
`2026-02-31`) is taken back with another `input`. A host that saves on `change` or
|
|
2368
|
+
`changeSubject` saves once, the date typed; one that wants a live Save state binds
|
|
2369
|
+
`.value`, `@input` (`detail.value`) and `@validation-change` (`detail.valid`). Bounds
|
|
2370
|
+
set while text is typed read it again at once: that reports `input` when the value moves, and `change`
|
|
2371
|
+
still waits for Enter or leaving the field. The text stays as typed until Enter or
|
|
2372
|
+
leaving the field writes it in `dateFormat`; text the field does not take stays
|
|
2373
|
+
visible with an accessible message. An IME composition's text is read when the
|
|
2374
|
+
composition ends; Enter while composing commits nothing. Invalid calendar fields
|
|
2375
|
+
(including non-leap February 29 and February 31) never roll into another month. While
|
|
2376
|
+
the calendar is open, it selects a typed moment and shows its month and time; partial
|
|
2377
|
+
text leaves its month. `checkValidity()` and `reportValidity()` include draft
|
|
2378
|
+
validity, so `dees-form` cannot submit a stale date while its displayed draft is
|
|
2379
|
+
invalid. The empty field shows a form it reads: `YYYY-MM-DD`, with ` HH:mm` (or
|
|
2380
|
+
` h:mm AM/PM` with `timeFormat="12h"`) when it takes a time, whatever `dateFormat`,
|
|
2381
|
+
unless `placeholder` is set. The field reads `YYYY-MM-DD`, `DD.MM.YYYY` and
|
|
2382
|
+
`MM/DD/YYYY`, with a time after a space; `dateFormat` is how it writes a date.
|
|
2356
2383
|
|
|
2357
2384
|
`minDate` and `maxDate` are inclusive calendar-day bounds on the field's clock. `disabledDates`
|
|
2358
2385
|
uses the same calendar-day comparison for typing, day buttons and Today. With
|
|
@@ -2379,8 +2406,9 @@ the field keeps its zone and says why. The calendar offers the field's zone firs
|
|
|
2379
2406
|
its list does not name it; a zone name the runtime does not know is passed over for the
|
|
2380
2407
|
next, with a warning. A time the clock skips when it goes forward is refused ("This
|
|
2381
2408
|
time doesn't exist that day."), typed or picked. A time it reads twice when it goes
|
|
2382
|
-
back is the pass the bounds take, of those the pass of a value in that same hour
|
|
2383
|
-
|
|
2409
|
+
back is the pass the bounds take, of those the pass of a value in that same hour (while
|
|
2410
|
+
the reader types, the value from before the typing), so an edited time stays in its
|
|
2411
|
+
pass, else the earlier; bounds with their time compare as instants,
|
|
2384
2412
|
so a from/to pair keeps its end at or after its start in that hour too.
|
|
2385
2413
|
|
|
2386
2414
|
A date-only value (`2026-10-27`) is that calendar day in every zone, without a
|
|
@@ -2394,7 +2422,6 @@ dialogs.
|
|
|
2394
2422
|
<dees-input-datepicker
|
|
2395
2423
|
key="eventDate"
|
|
2396
2424
|
label="Event Date"
|
|
2397
|
-
placeholder="YYYY-MM-DD"
|
|
2398
2425
|
value="2025-01-15T14:30:00Z" // ISO string format
|
|
2399
2426
|
dateFormat="YYYY-MM-DD" // Display format (default: YYYY-MM-DD)
|
|
2400
2427
|
.enableTime=${true} // Enable time selection
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const commitinfo = {
|
|
5
5
|
name: '@design.estate/dees-catalog',
|
|
6
|
-
version: '24.6.
|
|
6
|
+
version: '24.6.2',
|
|
7
7
|
description: 'A comprehensive library that provides dynamic web components for building sophisticated and modern web applications using JavaScript and TypeScript.'
|
|
8
8
|
}
|
|
@@ -1595,11 +1595,19 @@ export class DeesAppui extends DeesElement {
|
|
|
1595
1595
|
if (config.logoText !== undefined) {
|
|
1596
1596
|
this.mainmenuLogoText = config.logoText;
|
|
1597
1597
|
}
|
|
1598
|
-
if (config.
|
|
1598
|
+
if (config.sections !== undefined) {
|
|
1599
|
+
this.mainmenuGroups = this.buildMainMenuFromSections(config.sections);
|
|
1600
|
+
} else if (config.groups !== undefined) {
|
|
1599
1601
|
this.mainmenuGroups = [...config.groups];
|
|
1600
1602
|
}
|
|
1601
1603
|
if (config.bottomTabs !== undefined) {
|
|
1602
1604
|
this.mainmenuBottomTabs = [...config.bottomTabs];
|
|
1605
|
+
} else if (config.bottomItems !== undefined) {
|
|
1606
|
+
this.mainmenuBottomTabs = this.buildBottomTabsFromItems(config.bottomItems);
|
|
1607
|
+
}
|
|
1608
|
+
if (config.sections !== undefined || config.groups !== undefined || config.bottomTabs !== undefined || config.bottomItems !== undefined) {
|
|
1609
|
+
const viewId = this.viewRegistry.getCurrentViewId();
|
|
1610
|
+
if (viewId) this.markViewInMainMenu(viewId);
|
|
1603
1611
|
}
|
|
1604
1612
|
}
|
|
1605
1613
|
|
|
@@ -2936,7 +2944,7 @@ export class DeesAppui extends DeesElement {
|
|
|
2936
2944
|
// Build main menu from view references or direct config
|
|
2937
2945
|
if (config.mainMenu) {
|
|
2938
2946
|
if (config.mainMenu.sections) {
|
|
2939
|
-
this.mainmenuGroups = this.buildMainMenuFromSections(config);
|
|
2947
|
+
this.mainmenuGroups = this.buildMainMenuFromSections(config.mainMenu.sections);
|
|
2940
2948
|
} else if (config.mainMenu.groups) {
|
|
2941
2949
|
this.mainmenuGroups = config.mainMenu.groups;
|
|
2942
2950
|
}
|
|
@@ -3303,10 +3311,8 @@ export class DeesAppui extends DeesElement {
|
|
|
3303
3311
|
}
|
|
3304
3312
|
}
|
|
3305
3313
|
|
|
3306
|
-
private buildMainMenuFromSections(
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
return config.mainMenu.sections.map((section) => ({
|
|
3314
|
+
private buildMainMenuFromSections(sections: interfaces.IMainMenuSection[]): interfaces.IMenuGroup[] {
|
|
3315
|
+
return sections.map((section) => ({
|
|
3310
3316
|
name: section.name || '',
|
|
3311
3317
|
items: section.views
|
|
3312
3318
|
.map((viewId) => {
|
|
@@ -258,6 +258,12 @@ appui.setMainMenuBadge('inbox', 12);
|
|
|
258
258
|
appui.clearMainMenuBadge('inbox');
|
|
259
259
|
```
|
|
260
260
|
|
|
261
|
+
`setMainMenu()` also accepts `sections` and `bottomItems` containing registered view IDs, just as
|
|
262
|
+
`configure()` does. A later call can add or replace these after asynchronous data arrives; it changes
|
|
263
|
+
the sidebar without navigating or recreating the current view. `sections` takes precedence over
|
|
264
|
+
`groups`, and `bottomTabs` over `bottomItems`. An empty array clears that part of the menu; an omitted
|
|
265
|
+
field leaves it unchanged.
|
|
266
|
+
|
|
261
267
|
A selection made in the sidebar reaches the host as `mainmenu-item-select` with
|
|
262
268
|
`detail: { item }`. Every row shows `label` when the item carries one and `key`
|
|
263
269
|
otherwise, so `key` stays the stable identity a badge or a selection is
|
|
@@ -70,8 +70,13 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
70
70
|
@property({ type: Number, reflect: true })
|
|
71
71
|
accessor weekStartsOn: 0 | 1 | undefined;
|
|
72
72
|
|
|
73
|
+
/**
|
|
74
|
+
* What the empty field shows. Empty (the default), a form its typing reads: `YYYY-MM-DD`, with
|
|
75
|
+
* ` HH:mm` when it takes a time, or ` h:mm AM/PM` with `timeFormat="12h"`. The hint never follows
|
|
76
|
+
* `dateFormat`, which is how the field writes a date, not one it reads.
|
|
77
|
+
*/
|
|
73
78
|
@property({ type: String, reflect: true })
|
|
74
|
-
accessor placeholder: string = '
|
|
79
|
+
accessor placeholder: string = '';
|
|
75
80
|
|
|
76
81
|
@property({ type: Boolean, reflect: true })
|
|
77
82
|
accessor enableTimezone: boolean = false;
|
|
@@ -101,7 +106,10 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
101
106
|
@state()
|
|
102
107
|
accessor selectedMinute: number = 0;
|
|
103
108
|
|
|
104
|
-
/**
|
|
109
|
+
/**
|
|
110
|
+
* The text the reader is typing, until Enter, leaving the field or a pick writes it as the field
|
|
111
|
+
* does; text the field cannot take stays as typed.
|
|
112
|
+
*/
|
|
105
113
|
@state()
|
|
106
114
|
accessor draftText: string | null = null;
|
|
107
115
|
|
|
@@ -112,6 +120,18 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
112
120
|
|
|
113
121
|
private lastCommittedValue: string | undefined;
|
|
114
122
|
|
|
123
|
+
/**
|
|
124
|
+
* The value the field held when the reader began typing: Enter or leaving the field reports a
|
|
125
|
+
* typed value with `change` only when it differs from it, and text the field does not take
|
|
126
|
+
* returns the value to it.
|
|
127
|
+
*/
|
|
128
|
+
private draftBase = '';
|
|
129
|
+
|
|
130
|
+
/** The value the reader last committed: while they type, the one from before the typing. */
|
|
131
|
+
private get committedValue(): string {
|
|
132
|
+
return this.draftText === null ? this.value : this.draftBase;
|
|
133
|
+
}
|
|
134
|
+
|
|
115
135
|
/** The zone the field's readings were taken in, to read them again when it changes. */
|
|
116
136
|
private readingTimeZone: string | undefined;
|
|
117
137
|
|
|
@@ -134,7 +154,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
134
154
|
public willUpdate(changed: Map<PropertyKey, unknown>): void {
|
|
135
155
|
super.willUpdate(changed);
|
|
136
156
|
if (changed.has('value') && this.value !== this.lastCommittedValue || this.clockTimeZone !== this.readingTimeZone) {
|
|
137
|
-
this.
|
|
157
|
+
this.takeValue(this.value);
|
|
138
158
|
}
|
|
139
159
|
}
|
|
140
160
|
|
|
@@ -142,7 +162,9 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
142
162
|
super.updated(changed);
|
|
143
163
|
if (changed.has('disabled') && this.disabled) this.closePopup();
|
|
144
164
|
if (['value', 'minDate', 'maxDate', 'disabledDates', 'required', 'disabled', 'timezone'].some(key => changed.has(key))) {
|
|
145
|
-
|
|
165
|
+
// Typed text is read again under the new bounds at once, so the value stays what Enter would leave.
|
|
166
|
+
if (this.draftText !== null && !this.disabled) this.takeEdit();
|
|
167
|
+
else this.updateValidation(this.currentValidationMessage());
|
|
146
168
|
}
|
|
147
169
|
if (this.popupInstance) {
|
|
148
170
|
this.popupInstance.minDate = this.minDate;
|
|
@@ -165,15 +187,21 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
165
187
|
}
|
|
166
188
|
}
|
|
167
189
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Takes `value` as the field's value, and its day and time as the calendar's selection. The text
|
|
192
|
+
* then shows the value as the field writes it and the calendar turns to its month; while the reader
|
|
193
|
+
* types (`keepText`), their text stays as typed and the calendar keeps the month it shows.
|
|
194
|
+
*/
|
|
195
|
+
private takeValue(value: string, keepText = false): void {
|
|
196
|
+
this.value = value;
|
|
197
|
+
this.lastCommittedValue = value;
|
|
172
198
|
this.readingTimeZone = this.clockTimeZone;
|
|
173
|
-
this.selectedDate = parseDateValue(
|
|
174
|
-
this.viewDate = new Date(this.selectedDate ?? readClock(new Date(), this.readingTimeZone));
|
|
199
|
+
this.selectedDate = parseDateValue(value, this.readingTimeZone);
|
|
175
200
|
this.selectedHour = this.selectedDate?.getUTCHours() ?? 0;
|
|
176
201
|
this.selectedMinute = this.selectedDate?.getUTCMinutes() ?? 0;
|
|
202
|
+
if (keepText) return;
|
|
203
|
+
this.draftText = null;
|
|
204
|
+
this.viewDate = new Date(this.selectedDate ?? readClock(new Date(), this.readingTimeZone));
|
|
177
205
|
}
|
|
178
206
|
|
|
179
207
|
/** A value as the field writes it, on its clock or, with `timeZone`, on the clock of that zone. */
|
|
@@ -289,7 +317,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
289
317
|
|
|
290
318
|
private handleDateSelected = (event: Event): void => {
|
|
291
319
|
if (this.disabled) return;
|
|
292
|
-
this.commitDate((event as CustomEvent<Date>).detail
|
|
320
|
+
this.commitDate((event as CustomEvent<Date>).detail);
|
|
293
321
|
};
|
|
294
322
|
|
|
295
323
|
private handleDateCleared = (): void => {
|
|
@@ -313,7 +341,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
313
341
|
return;
|
|
314
342
|
}
|
|
315
343
|
this.timezone = timeZone;
|
|
316
|
-
if (reading) this.commitDate(reading
|
|
344
|
+
if (reading) this.commitDate(reading);
|
|
317
345
|
};
|
|
318
346
|
|
|
319
347
|
/**
|
|
@@ -334,8 +362,8 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
334
362
|
|
|
335
363
|
/**
|
|
336
364
|
* Which of the two moments a reading in an hour the clock reads twice names, as the clock's offset
|
|
337
|
-
* then: one the bounds take, and of those the one the field's value is in when
|
|
338
|
-
*
|
|
365
|
+
* then: one the bounds take, and of those the one the field's committed value is in when that value
|
|
366
|
+
* sits in the same hour, so a time edited there stays in its pass; else the earlier. Undefined for a
|
|
339
367
|
* reading the clock shows once.
|
|
340
368
|
*/
|
|
341
369
|
private passOf(reading: Date | null, timeZone = this.clockTimeZone): number | undefined {
|
|
@@ -349,53 +377,87 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
349
377
|
}
|
|
350
378
|
|
|
351
379
|
/**
|
|
352
|
-
* The pass of an hour the clock reads twice the field's value is in
|
|
380
|
+
* The pass of an hour the clock reads twice the field's committed value is in (while the reader
|
|
381
|
+
* types, the value from before the typing, as Enter has always read it): its day and the clock's
|
|
353
382
|
* offset. Undefined for a value the clock shows once, whose offset says nothing of another reading.
|
|
354
383
|
*/
|
|
355
384
|
private valuePass(timeZone: string): { day: number; offset: number } | undefined {
|
|
356
385
|
const offset = this.valueOffset(timeZone);
|
|
357
386
|
if (offset === undefined) return undefined;
|
|
358
|
-
const reading = readClock(new Date(this.
|
|
387
|
+
const reading = readClock(new Date(this.committedValue), timeZone);
|
|
359
388
|
return clockInstants(reading, timeZone).length === 2 ? { day: calendarDayKey(reading), offset } : undefined;
|
|
360
389
|
}
|
|
361
390
|
|
|
362
|
-
/** The clock's offset at the field's value, when the value says its instant. */
|
|
391
|
+
/** The clock's offset at the field's committed value, when the value says its instant. */
|
|
363
392
|
private valueOffset(timeZone = this.clockTimeZone): number | undefined {
|
|
364
|
-
|
|
365
|
-
|
|
393
|
+
const value = this.committedValue;
|
|
394
|
+
if (!namesInstant(value)) return undefined;
|
|
395
|
+
const instant = new Date(value);
|
|
366
396
|
return Number.isNaN(instant.getTime()) ? undefined : clockOffset(instant, timeZone);
|
|
367
397
|
}
|
|
368
398
|
|
|
369
|
-
|
|
399
|
+
/** Commits a moment picked in the calendar, set in its time boxes or by Today, or kept in a zone chosen. */
|
|
400
|
+
private commitDate(date: Date): void {
|
|
370
401
|
const offset = this.passOf(date);
|
|
371
402
|
const message = dateValidationMessage(date, this.constraintsIn(this.clockTimeZone, offset), this.t);
|
|
372
|
-
if (message) { this.updateValidation(message); return
|
|
373
|
-
|
|
374
|
-
const changed = value !== this.value;
|
|
375
|
-
this.lastCommittedValue = value;
|
|
376
|
-
this.value = value;
|
|
377
|
-
this.readingTimeZone = this.clockTimeZone;
|
|
378
|
-
this.selectedDate = new Date(date);
|
|
379
|
-
this.selectedHour = date.getUTCHours();
|
|
380
|
-
this.selectedMinute = date.getUTCMinutes();
|
|
381
|
-
this.viewDate = new Date(date);
|
|
382
|
-
if (normalizeDraft) this.draftText = null;
|
|
383
|
-
this.updateValidation('');
|
|
384
|
-
if (changed) {
|
|
385
|
-
this.changeSubject.next(this);
|
|
386
|
-
this.reportValueCommit();
|
|
387
|
-
}
|
|
388
|
-
return true;
|
|
403
|
+
if (message) { this.updateValidation(message); return; }
|
|
404
|
+
this.commitValue(this.formatValueWithTimezone(date, offset), { pick: true });
|
|
389
405
|
}
|
|
390
406
|
|
|
407
|
+
/** Clears the value, from the field's button or the calendar's. */
|
|
391
408
|
private commitClear(): void {
|
|
392
|
-
|
|
393
|
-
|
|
409
|
+
this.commitValue('', { pick: true });
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* Commits a value: a pick, Clear, Enter or leaving the field. `changeSubject` and `change` report it
|
|
414
|
+
* once, when it differs from the value before the typing. `input` comes first for a pick that
|
|
415
|
+
* changes it, as every pick reports `input` then `change`, and for a commit that changes the value
|
|
416
|
+
* `input` last reported. Text the field does not take stays as typed (`keepText`).
|
|
417
|
+
*/
|
|
418
|
+
private commitValue(value: string, { pick = false, keepText = false } = {}): void {
|
|
419
|
+
const before = this.committedValue;
|
|
420
|
+
const reported = this.value;
|
|
421
|
+
this.takeValue(value, keepText);
|
|
394
422
|
this.updateValidation(this.currentValidationMessage());
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
423
|
+
const changed = value !== before;
|
|
424
|
+
if (changed) this.changeSubject.next(this);
|
|
425
|
+
if (value !== reported || (pick && changed)) this.dispatchValueEvent('input');
|
|
426
|
+
if (changed) this.dispatchValueEvent('change');
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/**
|
|
430
|
+
* What the typed text leaves the field holding, as Enter takes it: the moment it names, nothing for
|
|
431
|
+
* no text, and for text the field does not take (`refused`) the value from before the typing.
|
|
432
|
+
*/
|
|
433
|
+
private readDraft(): { value: string; reading: Date | null; refused: boolean } {
|
|
434
|
+
const text = this.draftText?.trim() ?? '';
|
|
435
|
+
if (!text) return { value: '', reading: null, refused: false };
|
|
436
|
+
const reading = this.manualMessage(text) ? null : this.parseManualDate(text);
|
|
437
|
+
if (!reading) return { value: this.draftBase, reading: null, refused: true };
|
|
438
|
+
return { value: this.formatValueWithTimezone(reading, this.passOf(reading)), reading, refused: false };
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Takes an edit of the text: the value becomes the one Enter would leave and `input` reports it,
|
|
443
|
+
* the text stays as typed, and the calendar turns to a moment it names. `change` waits for Enter or
|
|
444
|
+
* leaving the field.
|
|
445
|
+
*/
|
|
446
|
+
private takeEdit(): void {
|
|
447
|
+
const { value, reading } = this.readDraft();
|
|
448
|
+
const edited = value !== this.value;
|
|
449
|
+
if (edited) {
|
|
450
|
+
this.takeValue(value, true);
|
|
451
|
+
if (reading) this.viewDate = new Date(reading);
|
|
398
452
|
}
|
|
453
|
+
this.updateValidation(this.currentValidationMessage());
|
|
454
|
+
if (edited) this.dispatchValueEvent('input');
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
/** Enter or leaving the field: commits the typed text and writes it as the field does; text it does not take stays. */
|
|
458
|
+
private commitDraft(): void {
|
|
459
|
+
const { value, refused } = this.readDraft();
|
|
460
|
+
this.commitValue(value, { keepText: refused });
|
|
399
461
|
}
|
|
400
462
|
|
|
401
463
|
private handleCloseRequest = (): void => {
|
|
@@ -423,7 +485,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
423
485
|
if (this.disabled || e.isComposing) return;
|
|
424
486
|
if (e.key === 'Enter') {
|
|
425
487
|
e.preventDefault();
|
|
426
|
-
if (this.draftText !== null) this.
|
|
488
|
+
if (this.draftText !== null) this.commitDraft();
|
|
427
489
|
else void this.toggleCalendar();
|
|
428
490
|
} else if (e.key === 'ArrowDown' && e.altKey) {
|
|
429
491
|
e.preventDefault();
|
|
@@ -451,22 +513,28 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
451
513
|
if (!this.disabled) this.commitClear();
|
|
452
514
|
}
|
|
453
515
|
|
|
516
|
+
/**
|
|
517
|
+
* Each edit sets the value Enter would leave and reports it with `input`, without rewriting the
|
|
518
|
+
* text under the caret: a moment the field takes, nothing for emptied text, and the value from
|
|
519
|
+
* before the typing for text it does not take, which says why. An edit inside an IME composition
|
|
520
|
+
* waits for the composition to end.
|
|
521
|
+
*/
|
|
454
522
|
public handleManualInput(e: InputEvent): void {
|
|
455
523
|
if (this.disabled) return;
|
|
524
|
+
if (this.draftText === null) this.draftBase = this.value;
|
|
456
525
|
this.draftText = (e.target as HTMLInputElement).value;
|
|
457
|
-
if (!e.isComposing) this.
|
|
526
|
+
if (!e.isComposing) this.takeEdit();
|
|
458
527
|
}
|
|
459
528
|
|
|
460
|
-
|
|
461
|
-
|
|
529
|
+
/** The text an IME composition leaves is an edit; an engine may send no `input` after the composition ends. */
|
|
530
|
+
public handleCompositionEnd(e: CompositionEvent): void {
|
|
531
|
+
if (this.disabled || this.draftText === null) return;
|
|
532
|
+
this.draftText = (e.target as HTMLInputElement).value;
|
|
533
|
+
this.takeEdit();
|
|
462
534
|
}
|
|
463
535
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
if (!text) { this.commitClear(); return; }
|
|
467
|
-
const message = this.manualMessage(text);
|
|
468
|
-
if (message) { this.updateValidation(message); return; }
|
|
469
|
-
this.commitDate(this.parseManualDate(text)!, normalizeDraft);
|
|
536
|
+
public handleInputBlur(_event: FocusEvent): void {
|
|
537
|
+
if (!this.disabled && this.draftText !== null) this.commitDraft();
|
|
470
538
|
}
|
|
471
539
|
|
|
472
540
|
/** The fields of typed text: the day, and the hour and minute when it names a time. */
|
|
@@ -550,7 +618,7 @@ export class DeesInputDatepicker extends DeesInputBase<DeesInputDatepicker> {
|
|
|
550
618
|
}
|
|
551
619
|
|
|
552
620
|
public setValue(value: string | null): void {
|
|
553
|
-
this.
|
|
621
|
+
this.takeValue(value ?? '');
|
|
554
622
|
this.updateValidation(this.currentValidationMessage());
|
|
555
623
|
}
|
|
556
624
|
|
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
import { html } from '@design.estate/dees-element';
|
|
1
2
|
import { focusedInputDemo } from '../../../demos/inputs.js';
|
|
3
|
+
import { demoCode, demoOutput, demoSection, showDemoResult } from '../../../demos/templates.js';
|
|
4
|
+
import type { DeesInputDatepicker } from './component.js';
|
|
2
5
|
|
|
3
|
-
|
|
6
|
+
/** What a host holds after each report of the field: the report, its value, and why typed text is not taken. */
|
|
7
|
+
const showReport = (event: Event) => {
|
|
8
|
+
const field = event.currentTarget as DeesInputDatepicker;
|
|
9
|
+
const value = field.value || '(empty)';
|
|
10
|
+
const reason = field.checkValidity() ? '' : `${field.validationText} `;
|
|
11
|
+
showDemoResult(field, `${event.type}: ${reason}value: ${value}`);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const demoFunc = () => focusedInputDemo('datepicker', demoSection(
|
|
15
|
+
'Typed dates',
|
|
16
|
+
'A typed date the field takes is its value as it is typed, reported by input, so a Save button can follow it; change follows once, on Enter or leaving the field. Text it does not take says why and leaves the value from before the typing.',
|
|
17
|
+
html`
|
|
18
|
+
<div class="dees-demo-grid">
|
|
19
|
+
<dees-input-datepicker label="Renewal date" value="2026-12-31" minDate="2026-11-01" @input=${showReport} @change=${showReport} @validation-change=${showReport}></dees-input-datepicker>
|
|
20
|
+
<dees-input-datepicker label="Maintenance window" .enableTime=${true} timeFormat="12h" @input=${showReport} @change=${showReport} @validation-change=${showReport}></dees-input-datepicker>
|
|
21
|
+
</div>${demoOutput('Type a date to see what the field reports.')}
|
|
22
|
+
${demoCode('<dees-input-datepicker label="Renewal date" .value=${renewal} @input=${(event) => (draft = event.detail.value)} @validation-change=${(event) => (valid = event.detail.valid)} @change=${(event) => save(event.detail.value)}></dees-input-datepicker>')}`,
|
|
23
|
+
));
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { html, type TemplateResult } from '@design.estate/dees-element';
|
|
2
2
|
import type { DeesInputDatepicker } from './component.js';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* What the empty field shows: its `placeholder`, else a form its typing reads, with the time when it
|
|
6
|
+
* takes one. Not `dateFormat`: the field writes in that format but reads only the forms of
|
|
7
|
+
* `parseDateFields` (`YYYY-MM-DD`, `DD.MM.YYYY`, `MM/DD/YYYY`).
|
|
8
|
+
*/
|
|
9
|
+
const placeholderOf = (component: DeesInputDatepicker): string => {
|
|
10
|
+
if (component.placeholder) return component.placeholder;
|
|
11
|
+
if (!component.enableTime) return 'YYYY-MM-DD';
|
|
12
|
+
return `YYYY-MM-DD ${component.timeFormat === '12h' ? 'h:mm AM/PM' : 'HH:mm'}`;
|
|
13
|
+
};
|
|
14
|
+
|
|
4
15
|
export const renderDatepicker = (component: DeesInputDatepicker): TemplateResult => {
|
|
5
16
|
return html`
|
|
6
17
|
<div class="input-wrapper">
|
|
@@ -15,12 +26,13 @@ export const renderDatepicker = (component: DeesInputDatepicker): TemplateResult
|
|
|
15
26
|
aria-describedby="date-description date-validation"
|
|
16
27
|
class="date-input field-control ${component.isOpened ? 'open' : ''}"
|
|
17
28
|
.value=${component.draftText ?? component.formatDate(component.value)}
|
|
18
|
-
.placeholder=${component
|
|
29
|
+
.placeholder=${placeholderOf(component)}
|
|
19
30
|
?disabled=${component.disabled}
|
|
20
31
|
?required=${component.required}
|
|
21
32
|
@click=${component.toggleCalendar}
|
|
22
33
|
@keydown=${component.handleKeydown}
|
|
23
34
|
@input=${component.handleManualInput}
|
|
35
|
+
@compositionend=${component.handleCompositionEnd}
|
|
24
36
|
@blur=${component.handleInputBlur}
|
|
25
37
|
style="padding-right: ${component.value || component.draftText ? 'calc(var(--dees-input-action-size) + 40px)' : '40px'}"
|
|
26
38
|
/>
|