@poadio/ui-elements 0.1.0 → 0.3.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 +42 -0
- package/README.md +47 -1
- package/dist/accordion.d.ts +31 -0
- package/dist/accordion.d.ts.map +1 -0
- package/dist/accordion.js +67 -0
- package/dist/accordion.js.map +1 -0
- package/dist/checkbox.d.ts +15 -1
- package/dist/checkbox.d.ts.map +1 -1
- package/dist/checkbox.js +18 -0
- package/dist/checkbox.js.map +1 -1
- package/dist/combo.d.ts +88 -0
- package/dist/combo.d.ts.map +1 -0
- package/dist/combo.js +238 -0
- package/dist/combo.js.map +1 -0
- package/dist/confirm.d.ts +35 -0
- package/dist/confirm.d.ts.map +1 -0
- package/dist/confirm.js +94 -0
- package/dist/confirm.js.map +1 -0
- package/dist/datepicker.d.ts +146 -0
- package/dist/datepicker.d.ts.map +1 -0
- package/dist/datepicker.js +468 -0
- package/dist/datepicker.js.map +1 -0
- package/dist/declaration.d.ts +25 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +35 -0
- package/dist/declaration.js.map +1 -0
- package/dist/dialog.d.ts +137 -0
- package/dist/dialog.d.ts.map +1 -0
- package/dist/dialog.js +174 -0
- package/dist/dialog.js.map +1 -0
- package/dist/element.d.ts +4 -0
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +5 -2
- package/dist/element.js.map +1 -1
- package/dist/index.d.ts +40 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23 -1
- package/dist/index.js.map +1 -1
- package/dist/menu.d.ts +121 -0
- package/dist/menu.d.ts.map +1 -0
- package/dist/menu.js +245 -0
- package/dist/menu.js.map +1 -0
- package/dist/meter.d.ts +1 -0
- package/dist/meter.d.ts.map +1 -1
- package/dist/meter.js +1 -2
- package/dist/meter.js.map +1 -1
- package/dist/multiselect.d.ts +133 -0
- package/dist/multiselect.d.ts.map +1 -0
- package/dist/multiselect.js +230 -0
- package/dist/multiselect.js.map +1 -0
- package/dist/option-list.d.ts +28 -0
- package/dist/option-list.d.ts.map +1 -0
- package/dist/option-list.js +31 -0
- package/dist/option-list.js.map +1 -0
- package/dist/paginator.d.ts +65 -0
- package/dist/paginator.d.ts.map +1 -0
- package/dist/paginator.js +110 -0
- package/dist/paginator.js.map +1 -0
- package/dist/segmented.d.ts +1 -0
- package/dist/segmented.d.ts.map +1 -1
- package/dist/segmented.js +1 -2
- package/dist/segmented.js.map +1 -1
- package/dist/select.d.ts +3 -6
- package/dist/select.d.ts.map +1 -1
- package/dist/select.js +8 -24
- package/dist/select.js.map +1 -1
- package/dist/services.d.ts +3 -0
- package/dist/services.d.ts.map +1 -0
- package/dist/services.js +10 -0
- package/dist/services.js.map +1 -0
- package/dist/slider.d.ts +1 -0
- package/dist/slider.d.ts.map +1 -1
- package/dist/slider.js +1 -2
- package/dist/slider.js.map +1 -1
- package/dist/split-button.d.ts +47 -0
- package/dist/split-button.d.ts.map +1 -0
- package/dist/split-button.js +64 -0
- package/dist/split-button.js.map +1 -0
- package/dist/stepper.d.ts +56 -0
- package/dist/stepper.d.ts.map +1 -0
- package/dist/stepper.js +69 -0
- package/dist/stepper.js.map +1 -0
- package/dist/table.d.ts +176 -0
- package/dist/table.d.ts.map +1 -0
- package/dist/table.js +293 -0
- package/dist/table.js.map +1 -0
- package/dist/tabs.d.ts +62 -0
- package/dist/tabs.d.ts.map +1 -0
- package/dist/tabs.js +118 -0
- package/dist/tabs.js.map +1 -0
- package/dist/toast.d.ts +79 -0
- package/dist/toast.d.ts.map +1 -0
- package/dist/toast.js +176 -0
- package/dist/toast.js.map +1 -0
- package/package.json +3 -3
- package/src/accordion.ts +80 -0
- package/src/checkbox.ts +21 -1
- package/src/combo.ts +220 -0
- package/src/confirm.ts +106 -0
- package/src/datepicker.ts +413 -0
- package/src/declaration.ts +37 -0
- package/src/dialog.ts +217 -0
- package/src/element.ts +7 -2
- package/src/index.ts +33 -2
- package/src/menu.ts +281 -0
- package/src/meter.ts +2 -1
- package/src/multiselect.ts +273 -0
- package/src/option-list.ts +51 -0
- package/src/paginator.ts +151 -0
- package/src/segmented.ts +2 -1
- package/src/select.ts +14 -30
- package/src/services.ts +10 -0
- package/src/slider.ts +2 -1
- package/src/split-button.ts +76 -0
- package/src/stepper.ts +86 -0
- package/src/table.ts +364 -0
- package/src/tabs.ts +129 -0
- package/src/toast.ts +203 -0
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <poad-datepicker name="day" value="2026-11-24" placeholder="Pick a day"></poad-datepicker> "yyyy-MM-dd" (ISO local)
|
|
3
|
+
* <poad-datepicker mode="datetime" selection-mode="range" show-button-bar></poad-datepicker> tableau de deux dates
|
|
4
|
+
* <poad-datepicker inline show-week aria-label="Day"></poad-datepicker>
|
|
5
|
+
*
|
|
6
|
+
* Sélecteur de date : machine `datepicker` de @poadio/ui-core (grille de 6 semaines dans la langue de l'élément — noms
|
|
7
|
+
* de mois et de jours, premier jour de la semaine, format, 12 / 24 h par `Intl` —, clavier WAI-ARIA de la grille, choix
|
|
8
|
+
* unique / intervalle / plusieurs, bornes et jours désactivés, saisie au clavier lue selon le format, heure, valeur ISO
|
|
9
|
+
* locale ou `Date` avec `data-type="date"`). Propriété `value` ; évènements `input` / `change` (detail : la valeur)
|
|
10
|
+
* quand l'utilisateur choisit, tape ou efface, `openchange`, `clear`, `monthchange`, `yearchange`. Formulaire : `name`
|
|
11
|
+
* (ISO ; une entrée par date en intervalle ou en plusieurs), `required`. Panneau flottant (couche interne), en ligne
|
|
12
|
+
* (`inline`), ou feuille basse sur petit écran. Même DOM, mêmes classes, même ARIA que `poad-datepicker` d'ui-angular.
|
|
13
|
+
* Styles : `datepicker.css`, `icon.css`, `floating.css`, `sheet.css`.
|
|
14
|
+
*/
|
|
15
|
+
import {
|
|
16
|
+
DATEPICKER_OFFSET, DATEPICKER_PLACEMENTS, SHEET_MOBILE_QUERY, datepickerBumpTime, datepickerDayDisabled, datepickerDayProps, datepickerDecadeStart,
|
|
17
|
+
datepickerDisabledKeys, datepickerDisplay, datepickerEffectiveMode, datepickerFollow, datepickerFormat, datepickerGridKey, datepickerHasTime, datepickerHourDisplay,
|
|
18
|
+
datepickerHoverInRange, datepickerInitialView, datepickerInputProps, datepickerMonthDisabled, datepickerMonthLabel, datepickerMonths, datepickerNavLabels,
|
|
19
|
+
datepickerNavigate, datepickerPanelProps, datepickerParse, datepickerPickDay, datepickerRootClasses, datepickerRows, datepickerSelected, datepickerShouldClose,
|
|
20
|
+
datepickerTimeFromInput, datepickerValue, datepickerWeekdays, datepickerWithTime, datepickerYearDisabled, datepickerYears, elementIsRtl, isSameDay, isoOf, pad2,
|
|
21
|
+
sheetUse, startOfDay, startOfMonth, toDate, uiFirstDayOfWeek, uiUses12Hours,
|
|
22
|
+
type DateLimits, type DateMode, type DateSelection, type DateValue, type DateView,
|
|
23
|
+
} from '@poadio/ui-core';
|
|
24
|
+
import { classOf, h, type Child } from './dom.js';
|
|
25
|
+
import { PoadFormElement } from './element.js';
|
|
26
|
+
import { FloatingTracker, Listening, Sheet, listenOutside, mediaMatches } from './floating.js';
|
|
27
|
+
import { icon } from './icon.js';
|
|
28
|
+
|
|
29
|
+
type Time = { readonly h: number; readonly m: number; readonly s: number };
|
|
30
|
+
type Part = 'h' | 'm' | 's';
|
|
31
|
+
|
|
32
|
+
export class PoadDatepickerElement extends PoadFormElement {
|
|
33
|
+
static override props = {
|
|
34
|
+
value: 'json', mode: 'string', selectionMode: 'string', dataType: 'string', format: 'string', placeholder: 'string', min: 'string', max: 'string',
|
|
35
|
+
disabledDates: 'json', disabledDays: 'json', showIcon: 'boolean', inline: 'boolean', showTime: 'boolean', hourFormat: 'number', stepMinute: 'number',
|
|
36
|
+
showSeconds: 'boolean', showButtonBar: 'boolean', showWeek: 'boolean', firstDayOfWeek: 'number', locale: 'string', readonlyInput: 'boolean',
|
|
37
|
+
manualInput: 'boolean', clearable: 'boolean', size: 'string', invalid: 'boolean', disabled: 'boolean', closeOnSelect: 'boolean', mobile: 'string',
|
|
38
|
+
ariaLabel: 'string', name: 'string', required: 'boolean',
|
|
39
|
+
} as const;
|
|
40
|
+
declare value?: DateValue;
|
|
41
|
+
declare mode?: DateMode;
|
|
42
|
+
declare selectionMode?: DateSelection;
|
|
43
|
+
/** `string` (défaut : ISO local) ou `date`. */
|
|
44
|
+
declare dataType?: 'date' | 'string';
|
|
45
|
+
/** Format d'affichage (`dd MM yyyy HH mm ss a`) ; défaut : selon le mode et la langue. */
|
|
46
|
+
declare format?: string | null;
|
|
47
|
+
declare placeholder?: string;
|
|
48
|
+
declare min?: Date | string | null;
|
|
49
|
+
declare max?: Date | string | null;
|
|
50
|
+
declare disabledDates?: readonly (Date | string)[];
|
|
51
|
+
/** Jours de semaine désactivés (0 = dimanche … 6 = samedi). */
|
|
52
|
+
declare disabledDays?: readonly number[];
|
|
53
|
+
declare showIcon?: boolean;
|
|
54
|
+
declare inline?: boolean;
|
|
55
|
+
declare showTime?: boolean;
|
|
56
|
+
declare hourFormat?: 12 | 24;
|
|
57
|
+
declare stepMinute?: number;
|
|
58
|
+
declare showSeconds?: boolean;
|
|
59
|
+
declare showButtonBar?: boolean;
|
|
60
|
+
declare showWeek?: boolean;
|
|
61
|
+
declare firstDayOfWeek?: number;
|
|
62
|
+
/** Langue des noms, du format et de la semaine ; défaut : celle de l'élément (`lang`). */
|
|
63
|
+
declare locale?: string;
|
|
64
|
+
declare readonlyInput?: boolean;
|
|
65
|
+
/** Saisie au clavier (lue au blur ou à Entrée). Défaut oui. */
|
|
66
|
+
declare manualInput?: boolean;
|
|
67
|
+
declare clearable?: boolean;
|
|
68
|
+
declare size?: 'sm' | 'md' | 'lg';
|
|
69
|
+
declare invalid?: boolean;
|
|
70
|
+
declare disabled?: boolean;
|
|
71
|
+
/** Fermer après un choix ; défaut : oui, sauf plusieurs dates ou avec l'heure. */
|
|
72
|
+
declare closeOnSelect?: boolean | null;
|
|
73
|
+
declare mobile?: 'auto' | 'sheet' | 'popover';
|
|
74
|
+
declare ariaLabel: string | null;
|
|
75
|
+
declare name?: string;
|
|
76
|
+
declare required?: boolean;
|
|
77
|
+
protected readonly resetProps = ['value'];
|
|
78
|
+
|
|
79
|
+
private readonly today = startOfDay(new Date());
|
|
80
|
+
private open = false;
|
|
81
|
+
private inSheet = false;
|
|
82
|
+
private view: DateView | null = null;
|
|
83
|
+
private viewDate: Date | null = null;
|
|
84
|
+
private focusDate: Date | null = null;
|
|
85
|
+
private hoverDate: Date | null = null;
|
|
86
|
+
private draft: string | null = null;
|
|
87
|
+
private time: Time = { h: 0, m: 0, s: 0 };
|
|
88
|
+
private timeEdit: { readonly part: Part; readonly text: string } | null = null;
|
|
89
|
+
private lastKey: string | null = null;
|
|
90
|
+
private readonly tracker = new FloatingTracker(() => this.update());
|
|
91
|
+
private readonly outside = new Listening(() => listenOutside(() => [this], () => this.close()));
|
|
92
|
+
private readonly sheet = new Sheet(() => this.update());
|
|
93
|
+
|
|
94
|
+
private get loc() { return this.locale ?? this.i18n().locale; }
|
|
95
|
+
private get selection(): DateSelection { return this.selectionMode ?? 'single'; }
|
|
96
|
+
private get selected() { return datepickerSelected(this.value); }
|
|
97
|
+
private get hasTime() { return datepickerHasTime(this.mode ?? 'date', this.showTime); }
|
|
98
|
+
private get hours(): 12 | 24 { return this.hourFormat ?? (uiUses12Hours(this.loc) ? 12 : 24); }
|
|
99
|
+
private get fmt() {
|
|
100
|
+
return datepickerFormat({ format: this.format ?? null, mode: this.mode ?? 'date', showTime: this.showTime, hours: this.hours, showSeconds: this.showSeconds, locale: this.loc });
|
|
101
|
+
}
|
|
102
|
+
private get limits(): DateLimits {
|
|
103
|
+
return { min: toDate(this.min ?? null), max: toDate(this.max ?? null), disabledDays: this.disabledDays ?? [], disabledKeys: datepickerDisabledKeys(this.disabledDates ?? []) };
|
|
104
|
+
}
|
|
105
|
+
private input(): HTMLInputElement | null { return this.querySelector<HTMLInputElement>(':scope > .poad-datepicker input.poad-dp__input'); }
|
|
106
|
+
private panel(): HTMLElement | null { return this.querySelector<HTMLElement>(':scope > .poad-datepicker .poad-dp__panel'); }
|
|
107
|
+
|
|
108
|
+
protected formValue() {
|
|
109
|
+
const dates = this.selected;
|
|
110
|
+
if (!dates.length) return { value: null, missing: true };
|
|
111
|
+
const mode = datepickerEffectiveMode(this.mode ?? 'date', this.showTime);
|
|
112
|
+
if (dates.length === 1 || !this.name) return { value: isoOf(dates[0]!, mode, this.showSeconds), missing: false };
|
|
113
|
+
const data = new FormData();
|
|
114
|
+
for (const d of dates) data.append(this.name, isoOf(d, mode, this.showSeconds));
|
|
115
|
+
return { value: data, missing: false };
|
|
116
|
+
}
|
|
117
|
+
override disconnectedCallback(): void {
|
|
118
|
+
super.disconnectedCallback();
|
|
119
|
+
this.open = false;
|
|
120
|
+
this.tracker.sync(null, null);
|
|
121
|
+
this.outside.toggle(false);
|
|
122
|
+
this.sheet.dispose();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private setOpen(next: boolean) {
|
|
126
|
+
this.open = next;
|
|
127
|
+
this.update();
|
|
128
|
+
this.emit('openchange', next);
|
|
129
|
+
}
|
|
130
|
+
private openPanel() {
|
|
131
|
+
if (this.inactive || this.open || this.inline) return;
|
|
132
|
+
const sel = this.selected;
|
|
133
|
+
const base = sel[sel.length - 1] ?? this.today;
|
|
134
|
+
this.viewDate = startOfMonth(base);
|
|
135
|
+
this.focusDate = base;
|
|
136
|
+
this.view = datepickerInitialView(this.mode ?? 'date');
|
|
137
|
+
this.inSheet = sheetUse(this.mobile ?? 'auto', mediaMatches(SHEET_MOBILE_QUERY));
|
|
138
|
+
this.setOpen(true);
|
|
139
|
+
}
|
|
140
|
+
private close() {
|
|
141
|
+
if (!this.open) return;
|
|
142
|
+
this.hoverDate = null;
|
|
143
|
+
this.inSheet = false;
|
|
144
|
+
this.setOpen(false);
|
|
145
|
+
}
|
|
146
|
+
private toggle() { if (this.open) this.close(); else this.openPanel(); }
|
|
147
|
+
|
|
148
|
+
private commit(dates: readonly Date[]) {
|
|
149
|
+
const out = datepickerValue(dates, { selection: this.selection, dataType: this.dataType ?? 'string', mode: datepickerEffectiveMode(this.mode ?? 'date', this.showTime), showSeconds: this.showSeconds });
|
|
150
|
+
this.value = out;
|
|
151
|
+
this.changed(out);
|
|
152
|
+
}
|
|
153
|
+
private withTime = (d: Date) => datepickerWithTime(d, this.hasTime ? this.time : null, this.showSeconds);
|
|
154
|
+
private shouldClose() { return datepickerShouldClose(this.closeOnSelect ?? null, this.selection, this.hasTime); }
|
|
155
|
+
private pickDay(d: Date) {
|
|
156
|
+
if (datepickerDayDisabled(d, this.limits)) return;
|
|
157
|
+
this.focusDate = d;
|
|
158
|
+
if (!isSameDay(startOfMonth(d), this.viewDate!)) this.viewDate = startOfMonth(d);
|
|
159
|
+
const r = datepickerPickDay(this.selected, d, this.selection, this.withTime);
|
|
160
|
+
this.commit(r.dates);
|
|
161
|
+
if (r.complete && this.shouldClose()) this.close();
|
|
162
|
+
}
|
|
163
|
+
private applyTyped(raw: string) {
|
|
164
|
+
const ds = datepickerParse(raw, this.fmt, this.selection, this.selected, this.limits);
|
|
165
|
+
if (ds === null) return;
|
|
166
|
+
if (!ds.length) { if (this.selected.length) this.commit([]); return; }
|
|
167
|
+
this.commit(ds);
|
|
168
|
+
}
|
|
169
|
+
private clear(e?: Event) {
|
|
170
|
+
e?.stopPropagation();
|
|
171
|
+
if (this.inactive) return;
|
|
172
|
+
this.commit([]);
|
|
173
|
+
this.emit('clear');
|
|
174
|
+
}
|
|
175
|
+
private applyTime(next: Time) {
|
|
176
|
+
this.time = next;
|
|
177
|
+
const sel = this.selected;
|
|
178
|
+
if (this.mode === 'time') { this.commit([datepickerWithTime(sel[0] ?? this.today, next, this.showSeconds)]); return; }
|
|
179
|
+
if (!sel.length) { this.update(); return; }
|
|
180
|
+
if (this.selection === 'single') this.commit([datepickerWithTime(sel[0]!, next, this.showSeconds)]);
|
|
181
|
+
else this.commit(sel.map((d, i) => (i === sel.length - 1 ? datepickerWithTime(d, next, this.showSeconds) : d)));
|
|
182
|
+
}
|
|
183
|
+
private pickToday() {
|
|
184
|
+
const now = new Date();
|
|
185
|
+
this.emit('todayclick', now);
|
|
186
|
+
const mode = this.mode ?? 'date';
|
|
187
|
+
if (mode === 'time') { this.applyTime({ h: now.getHours(), m: now.getMinutes(), s: now.getSeconds() }); return; }
|
|
188
|
+
this.viewDate = startOfMonth(now);
|
|
189
|
+
this.view = datepickerInitialView(mode);
|
|
190
|
+
if (mode === 'month' || mode === 'year') { this.commit([now]); return; }
|
|
191
|
+
if (this.hasTime) this.time = { h: now.getHours(), m: now.getMinutes(), s: now.getSeconds() };
|
|
192
|
+
this.pickDay(now);
|
|
193
|
+
}
|
|
194
|
+
private navigate(dir: 1 | -1) {
|
|
195
|
+
const r = datepickerNavigate(this.view!, this.viewDate!, dir);
|
|
196
|
+
this.viewDate = r.viewDate;
|
|
197
|
+
this.update();
|
|
198
|
+
if (r.month) this.emit('monthchange', r.month);
|
|
199
|
+
if (r.year !== undefined) this.emit('yearchange', r.year);
|
|
200
|
+
}
|
|
201
|
+
private pickMonth(m: number) {
|
|
202
|
+
const y = this.viewDate!.getFullYear();
|
|
203
|
+
if (this.mode === 'month') { this.commit([new Date(y, m, 1)]); if (this.shouldClose()) this.close(); return; }
|
|
204
|
+
this.viewDate = new Date(y, m, 1);
|
|
205
|
+
this.view = 'days';
|
|
206
|
+
this.update();
|
|
207
|
+
this.emit('monthchange', { month: m, year: y });
|
|
208
|
+
}
|
|
209
|
+
private pickYear(y: number) {
|
|
210
|
+
if (this.mode === 'year') { this.commit([new Date(y, 0, 1)]); if (this.shouldClose()) this.close(); return; }
|
|
211
|
+
this.viewDate = new Date(y, this.viewDate!.getMonth(), 1);
|
|
212
|
+
this.view = 'months';
|
|
213
|
+
this.update();
|
|
214
|
+
this.emit('yearchange', y);
|
|
215
|
+
}
|
|
216
|
+
private focusGridDay(d: Date) {
|
|
217
|
+
this.focusDate = d;
|
|
218
|
+
this.update();
|
|
219
|
+
this.panel()?.querySelector<HTMLElement>(`[data-key="${isoOf(d)}"]`)?.focus();
|
|
220
|
+
}
|
|
221
|
+
private onGridKey(e: KeyboardEvent, firstDay: number) {
|
|
222
|
+
const r = datepickerGridKey(this.focusDate!, e.key, { shiftKey: e.shiftKey, firstDay, rtl: elementIsRtl(e.currentTarget as HTMLElement) });
|
|
223
|
+
if (!r) return;
|
|
224
|
+
e.preventDefault();
|
|
225
|
+
if ('pick' in r) { this.pickDay(this.focusDate!); return; }
|
|
226
|
+
const follow = datepickerFollow(this.viewDate!, r.move);
|
|
227
|
+
if (follow) this.viewDate = follow;
|
|
228
|
+
this.focusGridDay(r.move);
|
|
229
|
+
}
|
|
230
|
+
private readonly onInputKey = (e: KeyboardEvent) => {
|
|
231
|
+
const manual = this.manualInput !== false;
|
|
232
|
+
if (e.key === 'Escape' && this.open) { e.preventDefault(); this.close(); return; }
|
|
233
|
+
if (e.key === 'Enter') {
|
|
234
|
+
if (this.draft !== null) { const d = this.draft; this.draft = null; this.applyTyped(d); this.update(); } else this.toggle();
|
|
235
|
+
e.preventDefault();
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
if (e.key === 'ArrowDown' && (e.altKey || !manual)) { e.preventDefault(); this.openPanel(); return; }
|
|
239
|
+
if (e.key === 'ArrowDown' && this.open) { e.preventDefault(); this.focusGridDay(this.focusDate!); return; }
|
|
240
|
+
if (e.key === 'Tab') this.close();
|
|
241
|
+
if (e.key === ' ' && (!manual || this.readonlyInput)) { e.preventDefault(); this.toggle(); }
|
|
242
|
+
};
|
|
243
|
+
private readonly onPanelKey = (e: KeyboardEvent) => {
|
|
244
|
+
if (e.key === 'Escape') { e.preventDefault(); this.close(); this.input()?.focus(); }
|
|
245
|
+
if (e.key === 'Tab' && !this.inSheet) this.close();
|
|
246
|
+
};
|
|
247
|
+
private timeFrom(part: Part, raw: string) {
|
|
248
|
+
this.timeEdit = null;
|
|
249
|
+
const tt = datepickerTimeFromInput(this.time, part, raw, this.hours);
|
|
250
|
+
if (tt) this.applyTime(tt); else this.update();
|
|
251
|
+
}
|
|
252
|
+
protected override updated(): void {
|
|
253
|
+
super.updated();
|
|
254
|
+
const floating = this.open && !this.inSheet && !this.inline;
|
|
255
|
+
const pane = floating ? this.querySelector<HTMLElement>(':scope > .poad-datepicker > .poad-dp-pane') : null;
|
|
256
|
+
this.tracker.sync(pane ? this.querySelector<HTMLElement>(':scope > .poad-datepicker > .poad-dp__box') : null, pane, {
|
|
257
|
+
candidates: DATEPICKER_PLACEMENTS, offset: DATEPICKER_OFFSET, shift: true,
|
|
258
|
+
});
|
|
259
|
+
this.outside.toggle(floating);
|
|
260
|
+
this.sheet.sync(this);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
protected render() {
|
|
264
|
+
const { t } = this.i18n();
|
|
265
|
+
const registry = this.icons();
|
|
266
|
+
const loc = this.loc;
|
|
267
|
+
const mode = this.mode ?? 'date';
|
|
268
|
+
const selection = this.selection;
|
|
269
|
+
const firstDay = this.firstDayOfWeek ?? uiFirstDayOfWeek(loc);
|
|
270
|
+
const selected = this.selected;
|
|
271
|
+
const hasValue = selected.length > 0;
|
|
272
|
+
const hasTime = this.hasTime;
|
|
273
|
+
const hours = this.hours;
|
|
274
|
+
const disabled = this.inactive;
|
|
275
|
+
const manual = this.manualInput !== false;
|
|
276
|
+
// la valeur change (choix, page) : heure suivie, et la vue si le panneau est fermé
|
|
277
|
+
const last = selected[selected.length - 1];
|
|
278
|
+
const key = selected.map((d) => d.getTime()).join(',');
|
|
279
|
+
if (key !== this.lastKey) {
|
|
280
|
+
this.lastKey = key;
|
|
281
|
+
if (last) {
|
|
282
|
+
this.time = { h: last.getHours(), m: last.getMinutes(), s: last.getSeconds() };
|
|
283
|
+
if (!this.open) { this.viewDate = startOfMonth(last); this.focusDate = last; }
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
this.view ??= datepickerInitialView(mode);
|
|
287
|
+
this.viewDate ??= startOfMonth(last ?? new Date());
|
|
288
|
+
this.focusDate ??= last ?? new Date();
|
|
289
|
+
const view = this.view, viewDate = this.viewDate, focusDate = this.focusDate, limits = this.limits, today = this.today, time = this.time;
|
|
290
|
+
const nav = datepickerNavLabels(view);
|
|
291
|
+
const rows = datepickerRows({ viewDate, firstDay, selected, selection, today, limits, locale: loc });
|
|
292
|
+
const decade = datepickerDecadeStart(viewDate);
|
|
293
|
+
const spin = (part: Part, shown: number): Child => {
|
|
294
|
+
const up = part === 'h' ? 'date.increaseHours' : part === 'm' ? 'date.increaseMinutes' : 'date.increaseSeconds';
|
|
295
|
+
const down = part === 'h' ? 'date.decreaseHours' : part === 'm' ? 'date.decreaseMinutes' : 'date.decreaseSeconds';
|
|
296
|
+
const label = part === 'h' ? 'date.hours' : part === 'm' ? 'date.minutes' : 'date.seconds';
|
|
297
|
+
const step = this.stepMinute ?? 1;
|
|
298
|
+
return h('div', { class: 'poad-dp__spin' }, [
|
|
299
|
+
h('button', { type: 'button', tabindex: -1, 'aria-label': t(up), onclick: () => this.applyTime(datepickerBumpTime(this.time, part, 1, step)) }, icon(registry, 'chevron-up', { size: 12 })),
|
|
300
|
+
h('input', {
|
|
301
|
+
type: 'text', inputmode: 'numeric', 'aria-label': t(label), value: this.timeEdit?.part === part ? this.timeEdit.text : pad2(shown),
|
|
302
|
+
oninput: (e: Event) => { this.timeEdit = { part, text: (e.target as HTMLInputElement).value }; },
|
|
303
|
+
onblur: (e: Event) => { if (this.timeEdit?.part === part) this.timeFrom(part, (e.target as HTMLInputElement).value); },
|
|
304
|
+
onkeydown: (e: KeyboardEvent) => {
|
|
305
|
+
if (e.key === 'ArrowUp') { e.preventDefault(); this.timeEdit = null; this.applyTime(datepickerBumpTime(this.time, part, 1, step)); }
|
|
306
|
+
else if (e.key === 'ArrowDown') { e.preventDefault(); this.timeEdit = null; this.applyTime(datepickerBumpTime(this.time, part, -1, step)); }
|
|
307
|
+
else if (e.key === 'Enter') { e.preventDefault(); this.timeFrom(part, (e.target as HTMLInputElement).value); this.close(); this.input()?.focus(); }
|
|
308
|
+
},
|
|
309
|
+
}),
|
|
310
|
+
h('button', { type: 'button', tabindex: -1, 'aria-label': t(down), onclick: () => this.applyTime(datepickerBumpTime(this.time, part, -1, step)) }, icon(registry, 'chevron-down', { size: 12 })),
|
|
311
|
+
]);
|
|
312
|
+
};
|
|
313
|
+
const cells = (list: readonly { label: string | number; sel: boolean; now: boolean; off: boolean; pick: () => void }[]) =>
|
|
314
|
+
h('div', { class: 'poad-dp__cells', role: 'grid' }, list.map((c) => h('button', {
|
|
315
|
+
type: 'button', role: 'gridcell', class: classOf({ 'is-sel': c.sel, 'is-now': c.now }) || undefined, disabled: c.off, onclick: c.pick,
|
|
316
|
+
}, String(c.label))));
|
|
317
|
+
const calendar: Child = [
|
|
318
|
+
mode !== 'time' && [
|
|
319
|
+
h('div', { class: 'poad-dp__head' }, [
|
|
320
|
+
h('button', { type: 'button', class: 'poad-dp__nav', 'aria-label': t(nav.prev), onclick: () => this.navigate(-1) }, icon(registry, 'chevron-left', { size: 14 })),
|
|
321
|
+
h('span', { class: 'poad-dp__title' }, [
|
|
322
|
+
view === 'days' && mode !== 'month' && mode !== 'year' && h('button', { type: 'button', onclick: () => { this.view = 'months'; this.update(); } }, datepickerMonthLabel(loc, viewDate)),
|
|
323
|
+
view !== 'years' && mode !== 'year'
|
|
324
|
+
? h('button', { type: 'button', onclick: () => { this.view = 'years'; this.update(); } }, String(viewDate.getFullYear()))
|
|
325
|
+
: h('span', {}, `${decade} – ${decade + 11}`),
|
|
326
|
+
]),
|
|
327
|
+
h('button', { type: 'button', class: 'poad-dp__nav', 'aria-label': t(nav.next), onclick: () => this.navigate(1) }, icon(registry, 'chevron-right', { size: 14 })),
|
|
328
|
+
]),
|
|
329
|
+
view === 'days' && h('div', {
|
|
330
|
+
class: ['poad-dp__grid', { 'has-week': !!this.showWeek }], role: 'grid', onkeydown: (e: KeyboardEvent) => this.onGridKey(e, firstDay),
|
|
331
|
+
}, [
|
|
332
|
+
h('div', { class: 'poad-dp__row poad-dp__weekdays', role: 'row' }, [
|
|
333
|
+
this.showWeek && h('span', { class: 'poad-dp__wk', 'aria-hidden': 'true' }, t('date.weekShort')),
|
|
334
|
+
datepickerWeekdays(loc, firstDay).map((w) => h('span', { role: 'columnheader' }, w)),
|
|
335
|
+
]),
|
|
336
|
+
rows.map((row) => h('div', { class: 'poad-dp__row', role: 'row' }, [
|
|
337
|
+
this.showWeek && h('span', { class: 'poad-dp__wk' }, String(row[0]!.week)),
|
|
338
|
+
row.map((c) => {
|
|
339
|
+
const a = datepickerDayProps(c, isSameDay(c.date, focusDate), datepickerHoverInRange(c.date, selected, this.hoverDate, selection));
|
|
340
|
+
return h('button', {
|
|
341
|
+
type: 'button', role: a.role, class: ['poad-dp__day', a.classes], 'data-key': a['data-key'], disabled: a.disabled, 'aria-selected': a['aria-selected'],
|
|
342
|
+
'aria-label': a['aria-label'], 'aria-disabled': a['aria-disabled'], tabindex: a.tabindex, onclick: () => this.pickDay(c.date),
|
|
343
|
+
onmouseenter: () => { this.hoverDate = c.date; this.update(); }, onmouseleave: () => { this.hoverDate = null; this.update(); },
|
|
344
|
+
onfocus: () => { if (!isSameDay(c.date, this.focusDate!)) { this.focusDate = c.date; this.update(); } },
|
|
345
|
+
}, String(c.day));
|
|
346
|
+
}),
|
|
347
|
+
])),
|
|
348
|
+
]),
|
|
349
|
+
view === 'months' && cells(datepickerMonths(loc).map((m, i) => ({
|
|
350
|
+
label: m, sel: selected.some((d) => d.getFullYear() === viewDate.getFullYear() && d.getMonth() === i),
|
|
351
|
+
now: today.getFullYear() === viewDate.getFullYear() && today.getMonth() === i, off: datepickerMonthDisabled(viewDate.getFullYear(), i, limits), pick: () => this.pickMonth(i),
|
|
352
|
+
}))),
|
|
353
|
+
view === 'years' && cells(datepickerYears(viewDate).map((y) => ({
|
|
354
|
+
label: y, sel: selected.some((d) => d.getFullYear() === y), now: y === today.getFullYear(), off: datepickerYearDisabled(y, limits), pick: () => this.pickYear(y),
|
|
355
|
+
}))),
|
|
356
|
+
],
|
|
357
|
+
hasTime && h('div', { class: ['poad-dp__time', { 'has-border': mode !== 'time' }], role: 'group', 'aria-label': t('date.time') }, [
|
|
358
|
+
spin('h', datepickerHourDisplay(time.h, hours)),
|
|
359
|
+
h('span', { class: 'poad-dp__colon' }, ':'),
|
|
360
|
+
spin('m', time.m),
|
|
361
|
+
this.showSeconds && [h('span', { class: 'poad-dp__colon' }, ':'), spin('s', time.s)],
|
|
362
|
+
hours === 12 && h('button', {
|
|
363
|
+
type: 'button', class: 'poad-dp__ampm', 'aria-label': t('date.toggleAmPm'), onclick: () => this.applyTime({ ...this.time, h: (this.time.h + 12) % 24 }),
|
|
364
|
+
}, time.h < 12 ? 'AM' : 'PM'),
|
|
365
|
+
]),
|
|
366
|
+
(this.showButtonBar || this.inSheet) && h('div', { class: 'poad-dp__bar' }, [
|
|
367
|
+
h('button', { type: 'button', onclick: () => this.pickToday() }, t('common.today')),
|
|
368
|
+
(selection === 'range' || selection === 'multiple') && h('span', { class: 'poad-dp__count' }, t('date.selectedCount', { n: selected.length })),
|
|
369
|
+
h('button', { type: 'button', class: 'is-muted', onclick: () => this.clear() }, t('common.clear')),
|
|
370
|
+
this.inSheet && h('button', { type: 'button', class: 'is-ok', onclick: () => this.close() }, t('common.ok')),
|
|
371
|
+
]),
|
|
372
|
+
];
|
|
373
|
+
const id = this.uid;
|
|
374
|
+
const pp = datepickerPanelProps(id, mode);
|
|
375
|
+
const panel = (sheet: boolean) => h('div', {
|
|
376
|
+
class: ['poad-dp__panel', { 'is-sheet': sheet }], id: pp.id, role: pp.role, 'aria-modal': pp['aria-modal'], 'aria-label': t(pp.labelKey),
|
|
377
|
+
onmousedown: sheet ? undefined : (e: MouseEvent) => e.preventDefault(), onkeydown: this.onPanelKey,
|
|
378
|
+
}, calendar);
|
|
379
|
+
const ia = datepickerInputProps({ id, open: this.open, invalid: this.invalid });
|
|
380
|
+
const root = ['poad-datepicker', datepickerRootClasses({ open: this.open, disabled, invalid: this.invalid, inline: this.inline, size: this.size ?? 'md' })];
|
|
381
|
+
if (this.inline) {
|
|
382
|
+
return h('div', { class: root }, h('div', { class: 'poad-dp__panel is-inline', id: pp.id, role: 'group', 'aria-label': this.ariaLabel || undefined }, calendar));
|
|
383
|
+
}
|
|
384
|
+
const typing = !manual || this.readonlyInput;
|
|
385
|
+
return h('div', { class: root }, [
|
|
386
|
+
h('div', {
|
|
387
|
+
class: 'poad-dp__box',
|
|
388
|
+
onclick: (e: MouseEvent) => { if (disabled || (e.target as HTMLElement).closest('button')) return; if (typing) this.toggle(); else if (!this.open) this.openPanel(); },
|
|
389
|
+
}, [
|
|
390
|
+
h('input', {
|
|
391
|
+
type: 'text', class: 'poad-dp__input', id: ia.id, role: ia.role, 'aria-haspopup': ia['aria-haspopup'], 'aria-expanded': ia['aria-expanded'],
|
|
392
|
+
'aria-controls': ia['aria-controls'], 'aria-invalid': ia['aria-invalid'], 'aria-label': this.ariaLabel || undefined,
|
|
393
|
+
value: this.draft ?? datepickerDisplay(selected, this.fmt, selection), placeholder: this.placeholder ?? '', readonly: typing, disabled, spellcheck: 'false',
|
|
394
|
+
oninput: (e: Event) => { this.draft = (e.target as HTMLInputElement).value; }, onkeydown: this.onInputKey,
|
|
395
|
+
onfocus: () => { if (typing) this.openPanel(); },
|
|
396
|
+
onblur: () => { if (this.draft !== null) { const d = this.draft; this.draft = null; this.applyTyped(d); this.update(); } },
|
|
397
|
+
}),
|
|
398
|
+
this.clearable && hasValue && !disabled && h('button', {
|
|
399
|
+
type: 'button', class: 'poad-dp__btn', tabindex: -1, 'aria-label': t('common.clear'), onclick: (e: MouseEvent) => this.clear(e),
|
|
400
|
+
}, icon(registry, 'x', { size: 13 })),
|
|
401
|
+
this.showIcon !== false && h('button', {
|
|
402
|
+
type: 'button', class: 'poad-dp__btn poad-dp__cal', tabindex: -1, disabled, 'aria-label': t('date.openCalendar'),
|
|
403
|
+
onclick: (e: MouseEvent) => { e.stopPropagation(); this.toggle(); },
|
|
404
|
+
}, icon(registry, mode === 'time' ? 'clock' : 'calendar', { size: 15 })),
|
|
405
|
+
]),
|
|
406
|
+
this.open && !this.inSheet && h('div', { class: 'poad-floating poad-dp-pane', style: this.tracker.style }, panel(false)),
|
|
407
|
+
this.sheet.render({
|
|
408
|
+
open: this.open && this.inSheet, title: t(pp.labelKey), titleId: `${id}-sheet-title`, restoreFocus: false, label: t('common.close'), icons: registry,
|
|
409
|
+
onClose: () => this.close(),
|
|
410
|
+
}, this.inSheet ? panel(true) : null),
|
|
411
|
+
]);
|
|
412
|
+
}
|
|
413
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Éléments de DÉCLARATION à contenu (`<poad-tab>`, `<poad-accordion-panel>`, `<poad-step>`) — interne au paquet.
|
|
3
|
+
*
|
|
4
|
+
* Ils ne dessinent rien : leur groupe lit leurs propriétés (`declared()`) et pose leur contenu (leurs enfants, capturés
|
|
5
|
+
* une fois) dans son propre DOM. Ils ne capturent ni ne redessinent rien à leur connexion — le groupe les retire de la
|
|
6
|
+
* page en se dessinant. Changer une de leurs propriétés (ou un attribut) redessine le groupe qui les a lus.
|
|
7
|
+
*/
|
|
8
|
+
import { PoadElement, declared, type PropType } from './element.js';
|
|
9
|
+
|
|
10
|
+
const contents = new WeakMap<Element, Node[]>();
|
|
11
|
+
const owners = new WeakMap<Element, { update(): void }>();
|
|
12
|
+
|
|
13
|
+
/** Contenu d'une déclaration (ses enfants), capturé la première fois qu'il est lu. */
|
|
14
|
+
export function contentOf(el: Element): Node[] {
|
|
15
|
+
let nodes = contents.get(el);
|
|
16
|
+
if (!nodes) contents.set(el, (nodes = [...el.childNodes]));
|
|
17
|
+
return nodes;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** Déclarations `tag` parmi le contenu d'un groupe : leurs données, leur contenu ; le groupe devient leur « propriétaire ». */
|
|
21
|
+
export function declarations<T>(owner: { update(): void }, content: readonly Node[] | null, tag: string, props: Readonly<Record<string, PropType>>): { readonly data: T; readonly el: Element; readonly content: Node[] }[] {
|
|
22
|
+
return (content ?? []).filter((n): n is Element => n instanceof Element && n.localName === tag).map((el) => {
|
|
23
|
+
owners.set(el, owner);
|
|
24
|
+
return { data: declared<T>(el, props), el, content: contentOf(el) };
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export abstract class PoadDeclarationElement extends PoadElement {
|
|
29
|
+
override connectedCallback(): void {}
|
|
30
|
+
override disconnectedCallback(): void {}
|
|
31
|
+
override update(): void {
|
|
32
|
+
owners.get(this)?.update();
|
|
33
|
+
}
|
|
34
|
+
protected render() {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|