@design-system-rte/core 1.6.5-rc2 → 1.7.0-rc1

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.
Files changed (27) hide show
  1. package/components/datepicker/datepicker-menu-focus-order.d.ts +4 -0
  2. package/components/datepicker/datepicker-menu-focus-order.d.ts.map +1 -0
  3. package/components/datepicker/datepicker-menu-focus-order.js +34 -0
  4. package/components/datepicker/datepicker.constants.d.ts +23 -0
  5. package/components/datepicker/datepicker.constants.d.ts.map +1 -0
  6. package/components/datepicker/datepicker.constants.js +36 -0
  7. package/components/datepicker/datepicker.interface.d.ts +59 -0
  8. package/components/datepicker/datepicker.utils.d.ts +132 -0
  9. package/components/datepicker/datepicker.utils.d.ts.map +1 -0
  10. package/components/datepicker/datepicker.utils.js +539 -0
  11. package/components/datepicker/index.d.ts +6 -0
  12. package/components/datepicker/index.d.ts.map +1 -0
  13. package/components/datepicker/index.js +4 -0
  14. package/components/datepicker/segmented-date-field.d.ts +27 -0
  15. package/components/datepicker/segmented-date-field.d.ts.map +1 -0
  16. package/components/datepicker/segmented-date-field.js +318 -0
  17. package/components/file-upload/file-upload.interface.d.ts +26 -0
  18. package/components/file-upload/file-upload.util.d.ts +7 -0
  19. package/components/file-upload/file-upload.util.d.ts.map +1 -0
  20. package/components/file-upload/file-upload.util.js +16 -0
  21. package/components/file-upload/index.d.ts +2 -0
  22. package/components/file-upload/index.d.ts.map +1 -0
  23. package/components/file-upload/index.js +1 -0
  24. package/components/toast/toast.utils.d.ts +1 -1
  25. package/index.d.ts +2 -0
  26. package/index.js +2 -0
  27. package/package.json +9 -1
@@ -0,0 +1,539 @@
1
+ import { ARROW_DOWN_KEY, ARROW_LEFT_KEY, ARROW_RIGHT_KEY, ARROW_UP_KEY, } from "../../constants/keyboard/keyboard.constants";
2
+ import { DATEPICKER_ARIA_CHANGE_DATE_PREFIX, DATEPICKER_ARIA_OPEN_CALENDAR, DATEPICKER_DEFAULT_LOCALE, DATEPICKER_MENU_REST_TAB_KEYS_COMPACT, DATEPICKER_MENU_REST_TAB_KEYS_DAY, DATEPICKER_YEAR_GRID_PAGE_SIZE, } from "./datepicker.constants";
3
+ const DD_MM_YYYY_EMPTY_SLOT_MARKER = "\u200b";
4
+ function stripDdMmYyyySegmentPart(part) {
5
+ return part.split(DD_MM_YYYY_EMPTY_SLOT_MARKER).join("").replace(/\D/g, "");
6
+ }
7
+ function parseDdMmYyyyTwoSlashParts(dayPart, secondPart) {
8
+ const dayDigits = stripDdMmYyyySegmentPart(dayPart).slice(0, 2);
9
+ const rest = stripDdMmYyyySegmentPart(secondPart).slice(0, 4);
10
+ if (rest.length > 2) {
11
+ return { dayDigits, monthDigits: "", yearDigits: rest };
12
+ }
13
+ if (rest.length === 1 || rest.length === 2) {
14
+ const monthNum = Number.parseInt(rest, 10);
15
+ if (!Number.isNaN(monthNum) && monthNum > 12) {
16
+ return { dayDigits, monthDigits: "", yearDigits: rest };
17
+ }
18
+ }
19
+ return { dayDigits, monthDigits: rest.slice(0, 2), yearDigits: "" };
20
+ }
21
+ function encodeDdMmYyyyDoubleSlashBoundaries(masked) {
22
+ let result = masked;
23
+ while (result.includes("//")) {
24
+ result = result.replace("//", `/${DD_MM_YYYY_EMPTY_SLOT_MARKER}/`);
25
+ }
26
+ return result;
27
+ }
28
+ export function parseDdMmYyyyMaskedString(value) {
29
+ const trimmed = value.trim();
30
+ if (trimmed.includes("/")) {
31
+ const rawParts = trimmed.split("/");
32
+ if (rawParts.length === 2) {
33
+ return parseDdMmYyyyTwoSlashParts(rawParts[0] ?? "", rawParts[1] ?? "");
34
+ }
35
+ return {
36
+ dayDigits: stripDdMmYyyySegmentPart(rawParts[0] ?? "").slice(0, 2),
37
+ monthDigits: stripDdMmYyyySegmentPart(rawParts[1] ?? "").slice(0, 2),
38
+ yearDigits: stripDdMmYyyySegmentPart(rawParts[2] ?? "").slice(0, 4),
39
+ };
40
+ }
41
+ const digitsOnly = trimmed.replace(/\D/g, "").slice(0, 8);
42
+ return {
43
+ dayDigits: digitsOnly.slice(0, 2),
44
+ monthDigits: digitsOnly.slice(2, 4),
45
+ yearDigits: digitsOnly.slice(4, 8),
46
+ };
47
+ }
48
+ export function buildMaskedDdMmYyyyFromDigitParts(parts) {
49
+ const { dayDigits, monthDigits, yearDigits } = parts;
50
+ const hasDay = dayDigits.length > 0;
51
+ const hasMonth = monthDigits.length > 0;
52
+ const hasYear = yearDigits.length > 0;
53
+ if (!hasDay && !hasMonth && !hasYear) {
54
+ return "";
55
+ }
56
+ if (hasDay && !hasMonth && !hasYear) {
57
+ return dayDigits;
58
+ }
59
+ if (!hasDay && hasMonth && !hasYear) {
60
+ return `/${monthDigits}`;
61
+ }
62
+ if (!hasDay && !hasMonth && hasYear) {
63
+ return encodeDdMmYyyyDoubleSlashBoundaries(`//${yearDigits}`);
64
+ }
65
+ if (hasDay && hasMonth && !hasYear) {
66
+ return `${dayDigits}/${monthDigits}`;
67
+ }
68
+ if (hasDay && !hasMonth && hasYear) {
69
+ return encodeDdMmYyyyDoubleSlashBoundaries(`${dayDigits}//${yearDigits}`);
70
+ }
71
+ if (!hasDay && hasMonth && hasYear) {
72
+ return `/${monthDigits}/${yearDigits}`;
73
+ }
74
+ return encodeDdMmYyyyDoubleSlashBoundaries(`${dayDigits}/${monthDigits}/${yearDigits}`);
75
+ }
76
+ export function getDatepickerMenuRestTabKeysInOrder(calendarType) {
77
+ if (calendarType === "day") {
78
+ return DATEPICKER_MENU_REST_TAB_KEYS_DAY;
79
+ }
80
+ return DATEPICKER_MENU_REST_TAB_KEYS_COMPACT;
81
+ }
82
+ export function resolveDatepickerMenuFocusableElement(element) {
83
+ if (element.tagName === "BUTTON") {
84
+ return element;
85
+ }
86
+ const innerButton = element.querySelector("button");
87
+ if (innerButton instanceof HTMLElement) {
88
+ return innerButton;
89
+ }
90
+ return element;
91
+ }
92
+ export function startOfMonth(date) {
93
+ return new Date(date.getFullYear(), date.getMonth(), 1);
94
+ }
95
+ function endOfMonth(date) {
96
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0);
97
+ }
98
+ function monthHasSelectableDay(params) {
99
+ const { year, monthIndex, minDate, maxDate, disabledDates } = params;
100
+ const lastDay = endOfMonth(new Date(year, monthIndex, 1)).getDate();
101
+ for (let day = 1; day <= lastDay; day++) {
102
+ const date = startOfDay(new Date(year, monthIndex, day));
103
+ if (!isDateDisabled({ date, minDate, maxDate, disabledDates })) {
104
+ return true;
105
+ }
106
+ }
107
+ return false;
108
+ }
109
+ function yearHasSelectableDay(params) {
110
+ const { year, minDate, maxDate, disabledDates } = params;
111
+ for (let monthIndex = 0; monthIndex < 12; monthIndex++) {
112
+ if (monthHasSelectableDay({ year, monthIndex, minDate, maxDate, disabledDates })) {
113
+ return true;
114
+ }
115
+ }
116
+ return false;
117
+ }
118
+ function getMondayBasedWeekdayIndex(date) {
119
+ return (date.getDay() + 6) % 7;
120
+ }
121
+ function isSameMonth(first, second) {
122
+ return first.getFullYear() === second.getFullYear() && first.getMonth() === second.getMonth();
123
+ }
124
+ export function maskDateInput(value) {
125
+ const parts = parseDdMmYyyyMaskedString(value);
126
+ return buildMaskedDdMmYyyyFromDigitParts(parts);
127
+ }
128
+ export function formatDate(date) {
129
+ const day = `${date.getDate()}`.padStart(2, "0");
130
+ const month = `${date.getMonth() + 1}`.padStart(2, "0");
131
+ const year = `${date.getFullYear()}`.padStart(4, "0");
132
+ return `${day}/${month}/${year}`;
133
+ }
134
+ export function getDatepickerCalendarButtonAriaLabel(selectedDate) {
135
+ if (selectedDate === null) {
136
+ return DATEPICKER_ARIA_OPEN_CALENDAR;
137
+ }
138
+ return `${DATEPICKER_ARIA_CHANGE_DATE_PREFIX}${formatDate(selectedDate)}`;
139
+ }
140
+ export function parseDate(value) {
141
+ const trimmedValue = value.trim();
142
+ if (trimmedValue.length === 0) {
143
+ return null;
144
+ }
145
+ const datePartsMatch = /^(\d{2})\/(\d{2})\/(\d{4})$/.exec(trimmedValue);
146
+ if (!datePartsMatch) {
147
+ return null;
148
+ }
149
+ const day = Number(datePartsMatch[1]);
150
+ const month = Number(datePartsMatch[2]);
151
+ const year = Number(datePartsMatch[3]);
152
+ if (month < 1 || month > 12) {
153
+ return null;
154
+ }
155
+ const date = new Date(year, month - 1, day);
156
+ const isValidParsedDate = date.getFullYear() === year &&
157
+ date.getMonth() === month - 1 &&
158
+ date.getDate() === day &&
159
+ !Number.isNaN(date.valueOf());
160
+ return isValidParsedDate ? date : null;
161
+ }
162
+ export function isSameDay(first, second) {
163
+ return (first.getFullYear() === second.getFullYear() &&
164
+ first.getMonth() === second.getMonth() &&
165
+ first.getDate() === second.getDate());
166
+ }
167
+ export function isBeforeDay(first, second) {
168
+ return startOfDay(first).valueOf() < startOfDay(second).valueOf();
169
+ }
170
+ export function isAfterDay(first, second) {
171
+ return startOfDay(first).valueOf() > startOfDay(second).valueOf();
172
+ }
173
+ export function startOfDay(date) {
174
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
175
+ }
176
+ export function getLastDayOfMonth(year, monthIndex) {
177
+ return new Date(year, monthIndex + 1, 0).getDate();
178
+ }
179
+ export function projectDayToMonthAnchor(desiredDayOfMonth, year, monthIndex) {
180
+ const lastDayInMonth = getLastDayOfMonth(year, monthIndex);
181
+ const dayClampedToMonth = Math.min(Math.max(desiredDayOfMonth, 1), lastDayInMonth);
182
+ return startOfDay(new Date(year, monthIndex, dayClampedToMonth));
183
+ }
184
+ export function addDays(date, amount) {
185
+ const nextDate = new Date(date);
186
+ nextDate.setDate(nextDate.getDate() + amount);
187
+ return nextDate;
188
+ }
189
+ export function addMonths(date, amount) {
190
+ return new Date(date.getFullYear(), date.getMonth() + amount, 1);
191
+ }
192
+ export function addYears(date, amount) {
193
+ return new Date(date.getFullYear() + amount, date.getMonth(), 1);
194
+ }
195
+ export function getDecadeStartYear(year) {
196
+ return Math.floor(year / 10) * 10;
197
+ }
198
+ export function navigateViewDate(params) {
199
+ const { viewDate, calendarType } = params;
200
+ if (calendarType === "day") {
201
+ const action = params.dayAction;
202
+ if (!action) {
203
+ return viewDate;
204
+ }
205
+ if (["prevYear", "nextYear"].includes(action)) {
206
+ return addMonths(viewDate, action === "prevYear" ? -12 : 12);
207
+ }
208
+ return addMonths(viewDate, action === "prevMonth" ? -1 : 1);
209
+ }
210
+ if (calendarType === "month") {
211
+ const step = params.compactStep;
212
+ if (!step) {
213
+ return viewDate;
214
+ }
215
+ return addYears(viewDate, step === "previous" ? -1 : 1);
216
+ }
217
+ if (calendarType === "year") {
218
+ const step = params.compactStep;
219
+ if (!step) {
220
+ return viewDate;
221
+ }
222
+ const yearStep = DATEPICKER_YEAR_GRID_PAGE_SIZE;
223
+ return addYears(viewDate, step === "previous" ? -yearStep : yearStep);
224
+ }
225
+ return viewDate;
226
+ }
227
+ function isCalendarDayInDisabledDates(currentDay, disabledDates) {
228
+ if (!disabledDates || disabledDates.length === 0) {
229
+ return false;
230
+ }
231
+ return disabledDates.some((forbidden) => isSameDay(currentDay, startOfDay(forbidden)));
232
+ }
233
+ export function isDateDisabled(params) {
234
+ const { date, minDate, maxDate, disabledDates } = params;
235
+ const currentDay = startOfDay(date);
236
+ if (minDate && isBeforeDay(currentDay, minDate)) {
237
+ return true;
238
+ }
239
+ if (maxDate && isAfterDay(currentDay, maxDate)) {
240
+ return true;
241
+ }
242
+ return isCalendarDayInDisabledDates(currentDay, disabledDates);
243
+ }
244
+ export function getMonthLabel(date, locale = DATEPICKER_DEFAULT_LOCALE) {
245
+ return new Intl.DateTimeFormat(locale, { month: "long", year: "numeric" }).format(date);
246
+ }
247
+ export function getYearLabel(date, locale = DATEPICKER_DEFAULT_LOCALE) {
248
+ return new Intl.DateTimeFormat(locale, { year: "numeric" }).format(date);
249
+ }
250
+ export function getDecadeRangeLabel(date) {
251
+ const decadeStart = getDecadeStartYear(date.getFullYear());
252
+ const decadeEnd = decadeStart + DATEPICKER_YEAR_GRID_PAGE_SIZE - 1;
253
+ return `${decadeStart} – ${decadeEnd}`;
254
+ }
255
+ export function getWeekdayShortLabels(locale = DATEPICKER_DEFAULT_LOCALE) {
256
+ const monday = new Date(2021, 0, 4);
257
+ return Array.from({ length: 7 }).map((_, index) => {
258
+ const day = addDays(monday, index);
259
+ const label = new Intl.DateTimeFormat(locale, { weekday: "short" }).format(day);
260
+ const firstLetter = label.trim().charAt(0);
261
+ return firstLetter.toLocaleUpperCase(locale);
262
+ });
263
+ }
264
+ export function resolveInitialCalendarDay(params) {
265
+ const { pendingDate, selectedDate, dayCells } = params;
266
+ const candidate = startOfDay(pendingDate ?? selectedDate ?? new Date());
267
+ const fromCandidate = resolveEnabledDateForPreferredDay(dayCells, candidate);
268
+ if (fromCandidate !== null) {
269
+ return fromCandidate;
270
+ }
271
+ const today = startOfDay(new Date());
272
+ const fromToday = resolveEnabledDateForPreferredDay(dayCells, today);
273
+ if (fromToday !== null) {
274
+ return fromToday;
275
+ }
276
+ const firstEnabled = dayCells.find((cell) => !cell.isDisabled);
277
+ return firstEnabled ? firstEnabled.date : candidate;
278
+ }
279
+ function resolveEnabledDateForPreferredDay(dayCells, day) {
280
+ const match = dayCells.find((cell) => isSameDay(cell.date, day));
281
+ if (!match) {
282
+ return null;
283
+ }
284
+ if (!match.isDisabled) {
285
+ return match.date;
286
+ }
287
+ const resolved = findNextEnabledFromIndex(dayCells, dayCells.indexOf(match));
288
+ return resolved ? resolved.date : null;
289
+ }
290
+ function findNextEnabledFromIndex(dayCells, startIndex) {
291
+ for (let index = startIndex; index < dayCells.length; index++) {
292
+ const cell = dayCells[index];
293
+ if (!cell.isDisabled) {
294
+ return cell;
295
+ }
296
+ }
297
+ for (let index = 0; index < startIndex; index++) {
298
+ const cell = dayCells[index];
299
+ if (!cell.isDisabled) {
300
+ return cell;
301
+ }
302
+ }
303
+ return undefined;
304
+ }
305
+ export function getDayCellIndexForDate(dayCells, date) {
306
+ return dayCells.findIndex((cell) => isSameDay(cell.date, date));
307
+ }
308
+ export function getDayGridCellCountForViewMonth(viewDate) {
309
+ const firstMonthDay = startOfMonth(viewDate);
310
+ const leadingDaysFromPreviousMonth = getMondayBasedWeekdayIndex(firstMonthDay);
311
+ const daysInMonth = getLastDayOfMonth(viewDate.getFullYear(), viewDate.getMonth());
312
+ return Math.ceil((leadingDaysFromPreviousMonth + daysInMonth) / 7) * 7;
313
+ }
314
+ export function buildDayGrid(params) {
315
+ const { viewDate, selectedDate, minDate, maxDate, disabledDates } = params;
316
+ const firstMonthDay = startOfMonth(viewDate);
317
+ const leadingDaysFromPreviousMonth = getMondayBasedWeekdayIndex(firstMonthDay);
318
+ const gridStart = addDays(firstMonthDay, -leadingDaysFromPreviousMonth);
319
+ const cellCount = getDayGridCellCountForViewMonth(viewDate);
320
+ const today = startOfDay(new Date());
321
+ return Array.from({ length: cellCount }).map((_, index) => {
322
+ const cellDate = addDays(gridStart, index);
323
+ const isCurrentMonth = isSameMonth(cellDate, viewDate);
324
+ const isSelected = !!selectedDate && isSameDay(cellDate, selectedDate);
325
+ const isToday = isSameDay(cellDate, today);
326
+ let cellType = "default";
327
+ if (!isCurrentMonth) {
328
+ cellType = "prev/next";
329
+ }
330
+ else if (isSelected) {
331
+ cellType = "selected";
332
+ }
333
+ else if (isToday) {
334
+ cellType = "today";
335
+ }
336
+ return {
337
+ date: cellDate,
338
+ label: `${cellDate.getDate()}`,
339
+ cellType,
340
+ isDisabled: isDateDisabled({ date: cellDate, minDate, maxDate, disabledDates }),
341
+ };
342
+ });
343
+ }
344
+ export function buildMonthGrid(params) {
345
+ const { viewDate, selectedDate, minDate, maxDate, disabledDates, locale = DATEPICKER_DEFAULT_LOCALE } = params;
346
+ const selectedMonthDate = selectedDate ? startOfMonth(selectedDate) : null;
347
+ const currentMonthDate = startOfMonth(new Date());
348
+ const year = viewDate.getFullYear();
349
+ return Array.from({ length: 12 }).map((_, monthIndex) => {
350
+ const cellDate = new Date(year, monthIndex, 1);
351
+ return {
352
+ monthIndex,
353
+ label: new Intl.DateTimeFormat(locale, { month: "long" }).format(cellDate),
354
+ isDisabled: !monthHasSelectableDay({ year, monthIndex, minDate, maxDate, disabledDates }),
355
+ isCurrent: cellDate.getTime() === currentMonthDate.getTime(),
356
+ isSelected: !!selectedMonthDate && cellDate.getTime() === selectedMonthDate.getTime(),
357
+ };
358
+ });
359
+ }
360
+ export function buildYearGrid(params) {
361
+ const { viewDate, selectedDate, minDate, maxDate, disabledDates } = params;
362
+ const currentYear = new Date().getFullYear();
363
+ const selectedYear = selectedDate?.getFullYear() ?? null;
364
+ const startYear = getDecadeStartYear(viewDate.getFullYear());
365
+ return Array.from({ length: DATEPICKER_YEAR_GRID_PAGE_SIZE }).map((_, index) => {
366
+ const year = startYear + index;
367
+ return {
368
+ year,
369
+ label: `${year}`,
370
+ isDisabled: !yearHasSelectableDay({ year, minDate, maxDate, disabledDates }),
371
+ isCurrent: year === currentYear,
372
+ isSelected: selectedYear === year,
373
+ };
374
+ });
375
+ }
376
+ export function getNextGridCellIndex(params) {
377
+ const { currentIndex, key, columnCount, cellCount } = params;
378
+ if (key === ARROW_LEFT_KEY) {
379
+ return currentIndex > 0 ? currentIndex - 1 : null;
380
+ }
381
+ if (key === ARROW_RIGHT_KEY) {
382
+ return currentIndex < cellCount - 1 ? currentIndex + 1 : null;
383
+ }
384
+ if (key === ARROW_UP_KEY) {
385
+ const nextIndex = currentIndex - columnCount;
386
+ return nextIndex >= 0 ? nextIndex : null;
387
+ }
388
+ if (key === ARROW_DOWN_KEY) {
389
+ const nextIndex = currentIndex + columnCount;
390
+ return nextIndex < cellCount ? nextIndex : null;
391
+ }
392
+ return null;
393
+ }
394
+ const ARROW_KEY_TO_COLUMN_DELTA = {
395
+ [ARROW_LEFT_KEY]: -1,
396
+ [ARROW_RIGHT_KEY]: 1,
397
+ };
398
+ const DATEPICKER_GRID_VERTICAL_STEP = {
399
+ day: 7,
400
+ monthYear: 3,
401
+ };
402
+ export function getDatepickerGridArrowDelta(key, layout) {
403
+ if (key === ARROW_UP_KEY) {
404
+ return -DATEPICKER_GRID_VERTICAL_STEP[layout];
405
+ }
406
+ if (key === ARROW_DOWN_KEY) {
407
+ return DATEPICKER_GRID_VERTICAL_STEP[layout];
408
+ }
409
+ return ARROW_KEY_TO_COLUMN_DELTA[key] ?? 0;
410
+ }
411
+ export function getDayOfMonthOrNull(date) {
412
+ return date?.getDate() ?? null;
413
+ }
414
+ export function resolveDatepickerMenuOpenState(params) {
415
+ const { textValue, constraints, pendingDate, selectedDate } = params;
416
+ const fallbackViewDate = params.fallbackViewDate ?? new Date();
417
+ const trimmedText = textValue.trim();
418
+ const parsedFromField = trimmedText.length > 0 ? parseDate(trimmedText) : null;
419
+ const parsedNormalized = parsedFromField ? startOfDay(parsedFromField) : null;
420
+ const isParsedUsable = parsedNormalized !== null && !isDateDisabled({ date: parsedNormalized, ...constraints });
421
+ let viewDateForGrid;
422
+ let pendingForMenu;
423
+ if (isParsedUsable && parsedNormalized) {
424
+ pendingForMenu = parsedNormalized;
425
+ viewDateForGrid = startOfMonth(parsedNormalized);
426
+ }
427
+ else {
428
+ pendingForMenu = null;
429
+ viewDateForGrid = fallbackViewDate;
430
+ }
431
+ const dayCells = buildDayGrid({
432
+ viewDate: viewDateForGrid,
433
+ selectedDate: pendingForMenu,
434
+ ...constraints,
435
+ });
436
+ const menuInitialActiveDate = resolveInitialCalendarDay({
437
+ pendingDate: pendingForMenu,
438
+ selectedDate: pendingForMenu,
439
+ dayCells,
440
+ });
441
+ const monthNavigationAnchorDay = getDayOfMonthOrNull(pendingForMenu ?? pendingDate ?? selectedDate);
442
+ return {
443
+ viewDate: viewDateForGrid,
444
+ pendingForMenu,
445
+ menuInitialActiveDate,
446
+ monthNavigationAnchorDay,
447
+ };
448
+ }
449
+ export function applyDatepickerTextInputChange(params) {
450
+ const masked = maskDateInput(params.rawValue);
451
+ const trimmed = masked.trim();
452
+ const parsed = trimmed.length > 0 ? parseDate(trimmed) : null;
453
+ if (parsed) {
454
+ const normalized = startOfDay(parsed);
455
+ if (isDateDisabled({ date: normalized, ...params.constraints })) {
456
+ return { outcome: "partial", maskedValue: masked };
457
+ }
458
+ return {
459
+ outcome: "committed",
460
+ date: normalized,
461
+ monthAnchorDay: normalized.getDate(),
462
+ maskedValue: masked,
463
+ };
464
+ }
465
+ if (masked.length === 0) {
466
+ return { outcome: "cleared", maskedValue: masked };
467
+ }
468
+ return { outcome: "partial", maskedValue: masked };
469
+ }
470
+ export function tryProjectPendingDateToViewMonth(params) {
471
+ const { anchorDay, viewDate, constraints } = params;
472
+ if (anchorDay === null) {
473
+ return null;
474
+ }
475
+ const projectedDate = projectDayToMonthAnchor(anchorDay, viewDate.getFullYear(), viewDate.getMonth());
476
+ if (isDateDisabled({ date: projectedDate, ...constraints })) {
477
+ return null;
478
+ }
479
+ return projectedDate;
480
+ }
481
+ export function normalizeDatepickerMenuSelectionDate(params) {
482
+ const normalized = startOfDay(params.date);
483
+ if (isDateDisabled({ date: normalized, ...params.constraints })) {
484
+ return null;
485
+ }
486
+ return normalized;
487
+ }
488
+ export function resolveDatepickerMenuKeyboardDayNavigation(params) {
489
+ const normalized = startOfDay(params.focusTargetDay);
490
+ if (isDateDisabled({ date: normalized, ...params.constraints })) {
491
+ return null;
492
+ }
493
+ return {
494
+ viewDate: startOfMonth(normalized),
495
+ menuInitialActiveDate: normalized,
496
+ };
497
+ }
498
+ export function resolveDatepickerMenuKeyboardMonthNavigation(params) {
499
+ const monthStart = startOfMonth(params.focusTargetMonthStart);
500
+ if (!monthHasSelectableDay({
501
+ year: monthStart.getFullYear(),
502
+ monthIndex: monthStart.getMonth(),
503
+ ...params.constraints,
504
+ })) {
505
+ return null;
506
+ }
507
+ return {
508
+ viewDate: monthStart,
509
+ menuInitialActiveDate: monthStart,
510
+ };
511
+ }
512
+ export function resolveDatepickerMenuKeyboardYearNavigation(params) {
513
+ if (!yearHasSelectableDay({
514
+ year: params.focusTargetYear,
515
+ ...params.constraints,
516
+ })) {
517
+ return null;
518
+ }
519
+ const monthStart = new Date(params.focusTargetYear, 0, 1);
520
+ return {
521
+ viewDate: monthStart,
522
+ menuInitialActiveDate: monthStart,
523
+ };
524
+ }
525
+ export function buildRestoreCommittedDatepickerFieldState(params) {
526
+ const { selectedDate } = params;
527
+ return {
528
+ pendingDate: selectedDate,
529
+ textValue: selectedDate ? formatDate(selectedDate) : "",
530
+ };
531
+ }
532
+ export function alignViewDateToSelectedMonthIfNeeded(params) {
533
+ const viewMonthStart = startOfMonth(params.viewDate);
534
+ const selectedMonthStart = startOfMonth(params.selectedDate);
535
+ if (viewMonthStart.getTime() === selectedMonthStart.getTime()) {
536
+ return params.viewDate;
537
+ }
538
+ return selectedMonthStart;
539
+ }
@@ -0,0 +1,6 @@
1
+ export type * from "./datepicker.interface";
2
+ export * from "./datepicker.constants";
3
+ export * from "./datepicker.utils";
4
+ export * from "./datepicker-menu-focus-order";
5
+ export * from "./segmented-date-field";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../components/datepicker/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,wBAAwB,CAAC;AAC5C,cAAc,wBAAwB,CAAC;AACvC,cAAc,oBAAoB,CAAC;AACnC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,wBAAwB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export * from "./datepicker.constants";
2
+ export * from "./datepicker.utils";
3
+ export * from "./datepicker-menu-focus-order";
4
+ export * from "./segmented-date-field";
@@ -0,0 +1,27 @@
1
+ export type SegmentedDateActiveSegment = "day" | "month" | "year";
2
+ export declare const SEGMENT_ORDER: readonly SegmentedDateActiveSegment[];
3
+ export interface SegmentedDateFieldState {
4
+ dayDigits: string;
5
+ monthDigits: string;
6
+ yearDigits: string;
7
+ activeSegment: SegmentedDateActiveSegment;
8
+ }
9
+ export declare function getSegmentDisplayText(digits: string, segment: SegmentedDateActiveSegment, emptyPlaceholder: string): string;
10
+ export declare function createEmptySegmentedDateFieldState(): SegmentedDateFieldState;
11
+ export declare function segmentedStateFromDdMmYyyyString(value: string): SegmentedDateFieldState;
12
+ export declare function segmentedStateFromIsoDate(date: Date): SegmentedDateFieldState;
13
+ export declare function buildDigitsOnlyFromState(state: SegmentedDateFieldState): string;
14
+ export declare function buildMaskedDdMmYyyyFromState(state: SegmentedDateFieldState): string;
15
+ export declare function getParsedDateFromState(state: SegmentedDateFieldState): Date | null;
16
+ export declare function isSegmentCompleteValid(segment: SegmentedDateActiveSegment, state: SegmentedDateFieldState): boolean;
17
+ export declare function applySegmentLeaveWhenChangingActiveSegment(state: SegmentedDateFieldState, nextActiveSegment: SegmentedDateActiveSegment): SegmentedDateFieldState;
18
+ export declare function resetIncompleteSegmentsOnBlur(state: SegmentedDateFieldState): SegmentedDateFieldState;
19
+ export declare function firstIncompleteSegmentForState(state: SegmentedDateFieldState): SegmentedDateActiveSegment;
20
+ export interface ReduceSegmentedDateFieldKeyParams {
21
+ state: SegmentedDateFieldState;
22
+ key: string;
23
+ isComposing: boolean;
24
+ }
25
+ export declare function reduceSegmentedDateFieldKey(params: ReduceSegmentedDateFieldKeyParams): SegmentedDateFieldState | null;
26
+ export declare function shouldPreventDefaultSegmentedKey(key: string): boolean;
27
+ //# sourceMappingURL=segmented-date-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segmented-date-field.d.ts","sourceRoot":"","sources":["../../../components/datepicker/segmented-date-field.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,0BAA0B,GAAG,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;AAElE,eAAO,MAAM,aAAa,EAAE,SAAS,0BAA0B,EAA6B,CAAC;AAE7F,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,0BAA0B,CAAC;CAC3C;AA8BD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,0BAA0B,EACnC,gBAAgB,EAAE,MAAM,GACvB,MAAM,CASR;AAED,wBAAgB,kCAAkC,IAAI,uBAAuB,CAO5E;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,GAAG,uBAAuB,CAQvF;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,IAAI,GAAG,uBAAuB,CAO7E;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,uBAAuB,GAAG,MAAM,CAE/E;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,uBAAuB,GAAG,MAAM,CAMnF;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,uBAAuB,GAAG,IAAI,GAAG,IAAI,CAElF;AAkED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,0BAA0B,EAAE,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAQnH;AAiBD,wBAAgB,0CAA0C,CACxD,KAAK,EAAE,uBAAuB,EAC9B,iBAAiB,EAAE,0BAA0B,GAC5C,uBAAuB,CAezB;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,uBAAuB,GAAG,uBAAuB,CAiBrG;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,uBAAuB,GAAG,0BAA0B,CAWzG;AA2GD,MAAM,WAAW,iCAAiC;IAChD,KAAK,EAAE,uBAAuB,CAAC;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,iCAAiC,GAAG,uBAAuB,GAAG,IAAI,CA2BrH;AAED,wBAAgB,gCAAgC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAQrE"}