@reliability-design/web 1.4.6 → 1.4.7
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 +211 -49
- package/dist/components/rel-accordion/README.md +132 -132
- package/dist/components/rel-alert/README.md +145 -141
- package/dist/components/rel-autocomplete/README.md +156 -61
- package/dist/components/rel-avatar/README.md +116 -130
- package/dist/components/rel-badge/README.md +98 -93
- package/dist/components/rel-breadcrumb/README.md +96 -102
- package/dist/components/rel-button/README.md +160 -130
- package/dist/components/rel-calendar/README.md +109 -109
- package/dist/components/rel-card/README.md +75 -94
- package/dist/components/rel-cardmedia/README.md +100 -127
- package/dist/components/rel-carousel/README.md +184 -166
- package/dist/components/rel-checkbox/README.md +93 -75
- package/dist/components/rel-chip/README.md +132 -121
- package/dist/components/rel-container/README.md +107 -99
- package/dist/components/rel-date-picker/README.md +200 -289
- package/dist/components/rel-divider/README.md +78 -100
- package/dist/components/rel-drawer/README.md +187 -200
- package/dist/components/rel-kbd/README.md +141 -151
- package/dist/components/rel-menu/README.md +178 -151
- package/dist/components/rel-menubar/README.md +218 -329
- package/dist/components/rel-otp/README.md +170 -440
- package/dist/components/rel-pagination/README.md +100 -424
- package/dist/components/rel-popover/README.md +203 -568
- package/dist/components/rel-progress/README.md +88 -110
- package/dist/components/rel-radio/README.md +131 -138
- package/dist/components/rel-range-picker/README.md +162 -0
- package/dist/components/rel-resizable/README.md +199 -140
- package/dist/components/rel-segmented-button/README.md +155 -141
- package/dist/components/rel-select/README.md +154 -93
- package/dist/components/rel-sheet/README.md +168 -224
- package/dist/components/rel-skeleton/README.md +103 -0
- package/dist/components/rel-slider/README.md +130 -135
- package/dist/components/rel-snackbar/README.md +162 -134
- package/dist/components/rel-stepper/README.md +158 -160
- package/dist/components/rel-switch/README.md +108 -102
- package/dist/components/rel-tab/README.md +171 -163
- package/dist/components/rel-textfield/README.md +159 -69
- package/dist/components/rel-time-picker/README.md +122 -157
- package/dist/components/rel-toast/README.md +157 -148
- package/dist/components/rel-tooltip/README.md +108 -111
- package/dist/components/rel-upload/README.md +220 -0
- package/dist/index.d.mts +1147 -340
- package/dist/index.d.ts +1147 -340
- package/dist/index.js +3451 -3163
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3416 -3118
- package/dist/index.mjs.map +1 -1
- package/dist/styles/vars.css +877 -866
- package/dist/{vars-XNMTSRVN.css → vars-JHTUGNRG.css} +877 -866
- package/package.json +3 -2
- package/dist/components/rel-accordion/rel-accordion.ts +0 -336
- package/dist/components/rel-alert/rel-alert.ts +0 -305
- package/dist/components/rel-autocomplete/rel-autocomplete.ts +0 -720
- package/dist/components/rel-avatar/rel-avatar.ts +0 -142
- package/dist/components/rel-badge/rel-badge.ts +0 -175
- package/dist/components/rel-breadcrumb/rel-breadcrumb.ts +0 -106
- package/dist/components/rel-button/rel-button.ts +0 -560
- package/dist/components/rel-calendar/index.ts +0 -1
- package/dist/components/rel-calendar/rel-calendar.ts +0 -565
- package/dist/components/rel-card/rel-card.ts +0 -88
- package/dist/components/rel-cardmedia/rel-cardmedia.ts +0 -88
- package/dist/components/rel-carousel/index.ts +0 -1
- package/dist/components/rel-carousel/rel-carousel.ts +0 -723
- package/dist/components/rel-chart/README.md +0 -286
- package/dist/components/rel-chart/index.ts +0 -1
- package/dist/components/rel-chart/rel-chart.ts +0 -754
- package/dist/components/rel-checkbox/rel-checkbox.ts +0 -382
- package/dist/components/rel-chip/rel-chip.ts +0 -483
- package/dist/components/rel-container/rel-container.ts +0 -95
- package/dist/components/rel-date-picker/date-format.test.ts +0 -43
- package/dist/components/rel-date-picker/date-format.ts +0 -47
- package/dist/components/rel-date-picker/date-parse.test.ts +0 -116
- package/dist/components/rel-date-picker/date-parse.ts +0 -178
- package/dist/components/rel-date-picker/index.ts +0 -1
- package/dist/components/rel-date-picker/rel-date-picker.ts +0 -1676
- package/dist/components/rel-divider/rel-divider.ts +0 -54
- package/dist/components/rel-drawer/index.ts +0 -1
- package/dist/components/rel-drawer/rel-drawer-footer.ts +0 -27
- package/dist/components/rel-drawer/rel-drawer.ts +0 -607
- package/dist/components/rel-kbd/rel-kbd.ts +0 -188
- package/dist/components/rel-layout/rel-layout.ts +0 -49
- package/dist/components/rel-menu/rel-menu.ts +0 -541
- package/dist/components/rel-menubar/index.ts +0 -2
- package/dist/components/rel-menubar/rel-menubar-menu.css +0 -3
- package/dist/components/rel-menubar/rel-menubar-menu.ts +0 -17
- package/dist/components/rel-menubar/rel-menubar.ts +0 -777
- package/dist/components/rel-nav-menu/README.md +0 -289
- package/dist/components/rel-nav-menu/index.ts +0 -3
- package/dist/components/rel-nav-menu/rel-nav-menu-item.ts +0 -243
- package/dist/components/rel-nav-menu/rel-nav-menu-panel.ts +0 -72
- package/dist/components/rel-nav-menu/rel-nav-menu.ts +0 -270
- package/dist/components/rel-navbar/README.md +0 -126
- package/dist/components/rel-navbar/rel-navbar.ts +0 -105
- package/dist/components/rel-otp/index.ts +0 -1
- package/dist/components/rel-otp/rel-otp.ts +0 -527
- package/dist/components/rel-pagination/index.ts +0 -1
- package/dist/components/rel-pagination/rel-pagination.ts +0 -522
- package/dist/components/rel-popover/index.ts +0 -2
- package/dist/components/rel-popover/rel-popover-content.ts +0 -81
- package/dist/components/rel-popover/rel-popover.ts +0 -475
- package/dist/components/rel-progress/rel-progress.ts +0 -234
- package/dist/components/rel-radio/rel-radio.ts +0 -481
- package/dist/components/rel-range-picker/rel-range-picker.ts +0 -1688
- package/dist/components/rel-resizable/index.ts +0 -3
- package/dist/components/rel-resizable/rel-resizable-group.ts +0 -405
- package/dist/components/rel-resizable/rel-resizable-handle.ts +0 -150
- package/dist/components/rel-resizable/rel-resizable-panel.ts +0 -58
- package/dist/components/rel-segmented-button/rel-segmented-button.ts +0 -217
- package/dist/components/rel-select/rel-select.ts +0 -1416
- package/dist/components/rel-sheet/rel-sheet.ts +0 -610
- package/dist/components/rel-sidebar/README.md +0 -209
- package/dist/components/rel-sidebar/rel-sidebar.ts +0 -1191
- package/dist/components/rel-skeleton/rel-skeleton.ts +0 -143
- package/dist/components/rel-slider/rel-slider.ts +0 -673
- package/dist/components/rel-snackbar/rel-snackbar.ts +0 -329
- package/dist/components/rel-stepper/rel-stepper.ts +0 -567
- package/dist/components/rel-switch/rel-switch.ts +0 -199
- package/dist/components/rel-tab/rel-tab.ts +0 -264
- package/dist/components/rel-table/README.md +0 -178
- package/dist/components/rel-table/rel-table-body.ts +0 -22
- package/dist/components/rel-table/rel-table-caption.ts +0 -30
- package/dist/components/rel-table/rel-table-cell.ts +0 -43
- package/dist/components/rel-table/rel-table-footer.ts +0 -24
- package/dist/components/rel-table/rel-table-head.ts +0 -47
- package/dist/components/rel-table/rel-table-header.ts +0 -22
- package/dist/components/rel-table/rel-table-row.ts +0 -37
- package/dist/components/rel-table/rel-table.ts +0 -62
- package/dist/components/rel-textfield/rel-textfield.ts +0 -1054
- package/dist/components/rel-time-picker/rel-time-picker.ts +0 -1482
- package/dist/components/rel-time-picker/time-parse.test.ts +0 -67
- package/dist/components/rel-time-picker/time-parse.ts +0 -85
- package/dist/components/rel-toast/rel-toast.ts +0 -206
- package/dist/components/rel-tooltip/rel-tooltip.ts +0 -193
- package/dist/components/rel-topbar/rel-topbar-actions.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar-brand.ts +0 -54
- package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +0 -69
- package/dist/components/rel-topbar/rel-topbar-dropdown.ts +0 -31
- package/dist/components/rel-topbar/rel-topbar-item.ts +0 -324
- package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar-profile.ts +0 -243
- package/dist/components/rel-topbar/rel-topbar-utilities.ts +0 -27
- package/dist/components/rel-topbar/rel-topbar.ts +0 -446
- package/dist/components/rel-upload/UPLOAD-DESIGN-CHANGES.md +0 -134
- package/dist/components/rel-upload/rel-upload-actions.ts +0 -163
- package/dist/components/rel-upload/rel-upload.ts +0 -968
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { test } from "node:test";
|
|
2
|
-
import assert from "node:assert/strict";
|
|
3
|
-
import {
|
|
4
|
-
parseDateInput,
|
|
5
|
-
isDayFirstPattern,
|
|
6
|
-
isDayFirstLocale,
|
|
7
|
-
} from "./date-parse";
|
|
8
|
-
|
|
9
|
-
// Reference "today": 2026-07-21 (a Tuesday), noon to dodge TZ edges.
|
|
10
|
-
const ref = new Date(2026, 6, 21, 12, 0, 0);
|
|
11
|
-
const opts = { referenceDate: ref };
|
|
12
|
-
|
|
13
|
-
const ymd = (d: Date | null) =>
|
|
14
|
-
d === null
|
|
15
|
-
? null
|
|
16
|
-
: `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(
|
|
17
|
-
d.getDate()
|
|
18
|
-
).padStart(2, "0")}`;
|
|
19
|
-
|
|
20
|
-
test("shortcuts: t / today / t±N / tN", () => {
|
|
21
|
-
assert.equal(ymd(parseDateInput("t", opts)), "2026-07-21");
|
|
22
|
-
assert.equal(ymd(parseDateInput("T", opts)), "2026-07-21");
|
|
23
|
-
assert.equal(ymd(parseDateInput("today", opts)), "2026-07-21");
|
|
24
|
-
assert.equal(ymd(parseDateInput("t+1", opts)), "2026-07-22");
|
|
25
|
-
assert.equal(ymd(parseDateInput("t1", opts)), "2026-07-22");
|
|
26
|
-
assert.equal(ymd(parseDateInput("T + 7", opts)), "2026-07-28");
|
|
27
|
-
assert.equal(ymd(parseDateInput("t-1", opts)), "2026-07-20");
|
|
28
|
-
assert.equal(ymd(parseDateInput("t-30", opts)), "2026-06-21");
|
|
29
|
-
// month/year rollover
|
|
30
|
-
assert.equal(ymd(parseDateInput("t+11", opts)), "2026-08-01");
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
test("incomplete shortcut is not 'today'", () => {
|
|
34
|
-
assert.equal(parseDateInput("t+", opts), null);
|
|
35
|
-
assert.equal(parseDateInput("t-", opts), null);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
test("ISO and year-first forms", () => {
|
|
39
|
-
assert.equal(ymd(parseDateInput("2026-07-21", opts)), "2026-07-21");
|
|
40
|
-
assert.equal(ymd(parseDateInput("2026/7/21", opts)), "2026-07-21");
|
|
41
|
-
assert.equal(ymd(parseDateInput("2026.07.21", opts)), "2026-07-21");
|
|
42
|
-
assert.equal(ymd(parseDateInput("20260721", opts)), "2026-07-21");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
test("numeric M/D/Y vs D/M/Y via dayFirst", () => {
|
|
46
|
-
assert.equal(ymd(parseDateInput("7/21/2026", opts)), "2026-07-21");
|
|
47
|
-
assert.equal(
|
|
48
|
-
ymd(parseDateInput("21/7/2026", { ...opts, dayFirst: true })),
|
|
49
|
-
"2026-07-21"
|
|
50
|
-
);
|
|
51
|
-
// ambiguous "3/4": order decided by dayFirst
|
|
52
|
-
assert.equal(ymd(parseDateInput("3/4/2026", opts)), "2026-03-04");
|
|
53
|
-
assert.equal(
|
|
54
|
-
ymd(parseDateInput("3/4/2026", { ...opts, dayFirst: true })),
|
|
55
|
-
"2026-04-03"
|
|
56
|
-
);
|
|
57
|
-
// a part > 12 forces the order regardless of dayFirst
|
|
58
|
-
assert.equal(ymd(parseDateInput("21/7/2026", opts)), "2026-07-21");
|
|
59
|
-
assert.equal(ymd(parseDateInput("7/21/2026", { ...opts, dayFirst: true })), "2026-07-21");
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
test("two-digit years map to 20YY", () => {
|
|
63
|
-
assert.equal(ymd(parseDateInput("7/21/26", opts)), "2026-07-21");
|
|
64
|
-
assert.equal(ymd(parseDateInput("21/7/26", { ...opts, dayFirst: true })), "2026-07-21");
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
test("month names, long and short, any case", () => {
|
|
68
|
-
assert.equal(ymd(parseDateInput("21 Jul 2026", opts)), "2026-07-21");
|
|
69
|
-
assert.equal(ymd(parseDateInput("Jul 21 2026", opts)), "2026-07-21");
|
|
70
|
-
assert.equal(ymd(parseDateInput("July 21, 2026", opts)), "2026-07-21");
|
|
71
|
-
assert.equal(ymd(parseDateInput("21 december 2026", opts)), "2026-12-21");
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test("partial input fills from the reference date", () => {
|
|
75
|
-
assert.equal(ymd(parseDateInput("5", opts)), "2026-07-05"); // day in ref month
|
|
76
|
-
assert.equal(ymd(parseDateInput("21/7", { ...opts, dayFirst: true })), "2026-07-21");
|
|
77
|
-
assert.equal(ymd(parseDateInput("12/25", opts)), "2026-12-25");
|
|
78
|
-
assert.equal(ymd(parseDateInput("25 Dec", opts)), "2026-12-25");
|
|
79
|
-
assert.equal(ymd(parseDateInput("Dec 25", opts)), "2026-12-25");
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
test("impossible dates rejected", () => {
|
|
83
|
-
assert.equal(parseDateInput("2026-02-30", opts), null);
|
|
84
|
-
assert.equal(parseDateInput("31/4/2026", { ...opts, dayFirst: true }), null);
|
|
85
|
-
assert.equal(parseDateInput("0", opts), null);
|
|
86
|
-
assert.equal(parseDateInput("32", opts), null);
|
|
87
|
-
assert.equal(parseDateInput("13/13/2026", opts), null);
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
test("garbage rejected", () => {
|
|
91
|
-
assert.equal(parseDateInput("", opts), null);
|
|
92
|
-
assert.equal(parseDateInput("asdf", opts), null);
|
|
93
|
-
assert.equal(parseDateInput("1/2/3/4", opts), null);
|
|
94
|
-
assert.equal(parseDateInput("Jul", opts), null);
|
|
95
|
-
assert.equal(parseDateInput("tomorrow+1", opts), null);
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("leap day handling", () => {
|
|
99
|
-
assert.equal(ymd(parseDateInput("2028-02-29", opts)), "2028-02-29");
|
|
100
|
-
assert.equal(parseDateInput("2026-02-29", opts), null);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
test("isDayFirstPattern", () => {
|
|
104
|
-
assert.equal(isDayFirstPattern("DD/MM/YYYY"), true);
|
|
105
|
-
assert.equal(isDayFirstPattern("MM/DD/YYYY"), false);
|
|
106
|
-
assert.equal(isDayFirstPattern("YYYY-MM-DD"), false);
|
|
107
|
-
assert.equal(isDayFirstPattern("D MMM YYYY"), true);
|
|
108
|
-
assert.equal(isDayFirstPattern("[Due] MM/DD"), false);
|
|
109
|
-
assert.equal(isDayFirstPattern("YYYY"), null);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test("isDayFirstLocale", () => {
|
|
113
|
-
assert.equal(isDayFirstLocale("en-US"), false);
|
|
114
|
-
assert.equal(isDayFirstLocale("en-GB"), true);
|
|
115
|
-
assert.equal(isDayFirstLocale("de-DE"), true);
|
|
116
|
-
});
|
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Free-form date parsing for rel-date-picker's typed keyboard entry.
|
|
3
|
-
*
|
|
4
|
-
* Pure (Date + Intl only, no DOM, no Date.now — "today" comes in via
|
|
5
|
-
* `referenceDate`) so it is unit-testable in Node. The component owns range
|
|
6
|
-
* checks (minDate/maxDate); this module only turns text into a calendar day.
|
|
7
|
-
*
|
|
8
|
-
* Shortcuts (case/whitespace-insensitive):
|
|
9
|
-
* "t", "today" → referenceDate
|
|
10
|
-
* "t+7", "t7", "t +7" → referenceDate + 7 days
|
|
11
|
-
* "t-3" → referenceDate − 3 days
|
|
12
|
-
*
|
|
13
|
-
* Date entry — parts split on `/ - . ,` or spaces, then classified:
|
|
14
|
-
* "2026-07-21", "21/7/2026", "7/21/26", "21 Jul 2026", "July 21, 2026",
|
|
15
|
-
* "21/7" (reference year), "21" (reference month), "20260721" (ISO digits).
|
|
16
|
-
* Two-digit years map to 20YY. When day/month order is ambiguous (both ≤ 12),
|
|
17
|
-
* `dayFirst` decides — derive it from the display format or locale via
|
|
18
|
-
* `isDayFirstPattern` / `isDayFirstLocale`.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
export interface ParseDateOptions {
|
|
22
|
-
/** "Today" and the fallback year/month for partial input. */
|
|
23
|
-
referenceDate: Date;
|
|
24
|
-
/** Ambiguous "a/b" order: true → day/month (EU), false → month/day (US). */
|
|
25
|
-
dayFirst?: boolean;
|
|
26
|
-
/** Locale for month-name matching (default "en-US"). */
|
|
27
|
-
locale?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/** Day-before-month order of a display pattern, e.g. "DD/MM/YYYY" → true. */
|
|
31
|
-
export function isDayFirstPattern(pattern: string): boolean | null {
|
|
32
|
-
// Strip bracketed literals so "[Due] DD/MM" doesn't match the literal's letters.
|
|
33
|
-
const bare = pattern.replace(/\[[^\]]*\]/g, "");
|
|
34
|
-
const d = bare.search(/D/);
|
|
35
|
-
const m = bare.search(/M/);
|
|
36
|
-
if (d === -1 || m === -1) return null;
|
|
37
|
-
return d < m;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** Day-before-month order of a locale's default numeric date format. */
|
|
41
|
-
export function isDayFirstLocale(locale: string): boolean {
|
|
42
|
-
try {
|
|
43
|
-
const parts = new Intl.DateTimeFormat(locale).formatToParts(
|
|
44
|
-
new Date(2020, 0, 15)
|
|
45
|
-
);
|
|
46
|
-
const d = parts.findIndex((p) => p.type === "day");
|
|
47
|
-
const m = parts.findIndex((p) => p.type === "month");
|
|
48
|
-
return d !== -1 && m !== -1 && d < m;
|
|
49
|
-
} catch {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/** 0-based month index for a month name in the locale (long/short), or null. */
|
|
55
|
-
function matchMonthName(token: string, locale: string): number | null {
|
|
56
|
-
const cleaned = token.replace(/\.$/, "").toLowerCase();
|
|
57
|
-
if (!cleaned || /\d/.test(cleaned)) return null;
|
|
58
|
-
for (const style of ["long", "short"] as const) {
|
|
59
|
-
const fmt = new Intl.DateTimeFormat(locale, { month: style });
|
|
60
|
-
for (let m = 0; m < 12; m++) {
|
|
61
|
-
if (fmt.format(new Date(2020, m, 15)).toLowerCase() === cleaned) return m;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/** Reject impossible days (Feb 30 …) by round-tripping through Date. */
|
|
68
|
-
function buildDate(year: number, monthIndex: number, day: number): Date | null {
|
|
69
|
-
if (monthIndex < 0 || monthIndex > 11 || day < 1 || day > 31) return null;
|
|
70
|
-
const date = new Date(year, monthIndex, day, 12, 0, 0);
|
|
71
|
-
if (date.getFullYear() !== year || date.getMonth() !== monthIndex || date.getDate() !== day) {
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
return date;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function normalizeYear(raw: string): number {
|
|
78
|
-
const n = parseInt(raw, 10);
|
|
79
|
-
return raw.length <= 2 ? 2000 + n : n;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export function parseDateInput(
|
|
83
|
-
text: string,
|
|
84
|
-
opts: ParseDateOptions
|
|
85
|
-
): Date | null {
|
|
86
|
-
const input = text.trim();
|
|
87
|
-
if (!input) return null;
|
|
88
|
-
const locale = opts.locale ?? "en-US";
|
|
89
|
-
const ref = opts.referenceDate;
|
|
90
|
-
|
|
91
|
-
// ── Shortcuts: t / today / t±N ──
|
|
92
|
-
const shortcut = input.match(/^t(?:oday)?\s*(?:([+-])\s*)?(\d+)?$/i);
|
|
93
|
-
if (shortcut) {
|
|
94
|
-
const sign = shortcut[1] === "-" ? -1 : 1;
|
|
95
|
-
const offset = shortcut[2] ? sign * parseInt(shortcut[2], 10) : 0;
|
|
96
|
-
// "t-" / "t+" with no number is incomplete, not "today".
|
|
97
|
-
if (shortcut[1] && !shortcut[2]) return null;
|
|
98
|
-
return new Date(ref.getFullYear(), ref.getMonth(), ref.getDate() + offset, 12, 0, 0);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// ── Single run of digits: "21" (day), "0721"?, "20260721" (ISO) ──
|
|
102
|
-
if (/^\d+$/.test(input)) {
|
|
103
|
-
if (input.length <= 2) {
|
|
104
|
-
return buildDate(ref.getFullYear(), ref.getMonth(), parseInt(input, 10));
|
|
105
|
-
}
|
|
106
|
-
if (input.length === 8) {
|
|
107
|
-
return buildDate(
|
|
108
|
-
parseInt(input.slice(0, 4), 10),
|
|
109
|
-
parseInt(input.slice(4, 6), 10) - 1,
|
|
110
|
-
parseInt(input.slice(6), 10)
|
|
111
|
-
);
|
|
112
|
-
}
|
|
113
|
-
return null;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// ── Tokenized parts ──
|
|
117
|
-
const parts = input.split(/[\s/\-.,]+/).filter(Boolean);
|
|
118
|
-
if (parts.length < 2 || parts.length > 3) return null;
|
|
119
|
-
|
|
120
|
-
const dayFirst = opts.dayFirst ?? false;
|
|
121
|
-
|
|
122
|
-
// Classify each part: 4-digit year, month name, or plain number.
|
|
123
|
-
const yearIdx = parts.findIndex((p) => /^\d{4}$/.test(p));
|
|
124
|
-
const monthNameIdx = parts.findIndex((p) => matchMonthName(p, locale) !== null);
|
|
125
|
-
|
|
126
|
-
if (parts.length === 3) {
|
|
127
|
-
if (!parts.every((p, i) => i === monthNameIdx || /^\d{1,4}$/.test(p))) return null;
|
|
128
|
-
// ISO-style: 4-digit year leads → Y-M-D regardless of dayFirst.
|
|
129
|
-
if (yearIdx === 0 && monthNameIdx === -1) {
|
|
130
|
-
return buildDate(
|
|
131
|
-
parseInt(parts[0], 10),
|
|
132
|
-
parseInt(parts[1], 10) - 1,
|
|
133
|
-
parseInt(parts[2], 10)
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
// Year (2- or 4-digit) is last otherwise.
|
|
137
|
-
const yearRaw = parts[2];
|
|
138
|
-
if (!/^\d{1,4}$/.test(yearRaw) || monthNameIdx === 2) return null;
|
|
139
|
-
const year = normalizeYear(yearRaw);
|
|
140
|
-
let monthIndex: number;
|
|
141
|
-
let day: number;
|
|
142
|
-
if (monthNameIdx !== -1) {
|
|
143
|
-
monthIndex = matchMonthName(parts[monthNameIdx], locale)!;
|
|
144
|
-
const dayRaw = parts[monthNameIdx === 0 ? 1 : 0];
|
|
145
|
-
if (!/^\d{1,2}$/.test(dayRaw)) return null;
|
|
146
|
-
day = parseInt(dayRaw, 10);
|
|
147
|
-
} else {
|
|
148
|
-
if (!/^\d{1,2}$/.test(parts[0]) || !/^\d{1,2}$/.test(parts[1])) return null;
|
|
149
|
-
const a = parseInt(parts[0], 10);
|
|
150
|
-
const b = parseInt(parts[1], 10);
|
|
151
|
-
// A part that can't be a month forces the order; otherwise dayFirst decides.
|
|
152
|
-
if (a > 12 && b > 12) return null;
|
|
153
|
-
const useDayFirst = a > 12 ? true : b > 12 ? false : dayFirst;
|
|
154
|
-
day = useDayFirst ? a : b;
|
|
155
|
-
monthIndex = (useDayFirst ? b : a) - 1;
|
|
156
|
-
}
|
|
157
|
-
return buildDate(year, monthIndex, day);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
// Two parts: day + month in the reference year ("21/7", "21 Jul", "Jul 21").
|
|
161
|
-
let monthIndex: number;
|
|
162
|
-
let day: number;
|
|
163
|
-
if (monthNameIdx !== -1) {
|
|
164
|
-
monthIndex = matchMonthName(parts[monthNameIdx], locale)!;
|
|
165
|
-
const dayRaw = parts[monthNameIdx === 0 ? 1 : 0];
|
|
166
|
-
if (!/^\d{1,2}$/.test(dayRaw)) return null;
|
|
167
|
-
day = parseInt(dayRaw, 10);
|
|
168
|
-
} else {
|
|
169
|
-
if (!/^\d{1,2}$/.test(parts[0]) || !/^\d{1,2}$/.test(parts[1])) return null;
|
|
170
|
-
const a = parseInt(parts[0], 10);
|
|
171
|
-
const b = parseInt(parts[1], 10);
|
|
172
|
-
if (a > 12 && b > 12) return null;
|
|
173
|
-
const useDayFirst = a > 12 ? true : b > 12 ? false : dayFirst;
|
|
174
|
-
day = useDayFirst ? a : b;
|
|
175
|
-
monthIndex = (useDayFirst ? b : a) - 1;
|
|
176
|
-
}
|
|
177
|
-
return buildDate(ref.getFullYear(), monthIndex, day);
|
|
178
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./rel-date-picker";
|