@reliability-design/web 1.4.4 → 1.4.6

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 (58) hide show
  1. package/dist/components/rel-accordion/rel-accordion.ts +13 -1
  2. package/dist/components/rel-alert/rel-alert.ts +1 -1
  3. package/dist/components/rel-autocomplete/rel-autocomplete.ts +33 -2
  4. package/dist/components/rel-badge/rel-badge.ts +6 -1
  5. package/dist/components/rel-button/rel-button.ts +18 -2
  6. package/dist/components/rel-calendar/rel-calendar.ts +86 -18
  7. package/dist/components/rel-carousel/rel-carousel.ts +45 -2
  8. package/dist/components/rel-checkbox/rel-checkbox.ts +4 -1
  9. package/dist/components/rel-chip/rel-chip.ts +59 -19
  10. package/dist/components/rel-date-picker/date-parse.test.ts +116 -0
  11. package/dist/components/rel-date-picker/date-parse.ts +178 -0
  12. package/dist/components/rel-date-picker/rel-date-picker.ts +675 -93
  13. package/dist/components/rel-drawer/rel-drawer.ts +28 -61
  14. package/dist/components/rel-menu/rel-menu.ts +130 -15
  15. package/dist/components/rel-menubar/rel-menubar.ts +221 -63
  16. package/dist/components/rel-nav-menu/rel-nav-menu.ts +39 -3
  17. package/dist/components/rel-otp/rel-otp.ts +14 -4
  18. package/dist/components/rel-pagination/rel-pagination.ts +13 -0
  19. package/dist/components/rel-popover/rel-popover.ts +64 -5
  20. package/dist/components/rel-progress/rel-progress.ts +13 -4
  21. package/dist/components/rel-radio/README.md +6 -3
  22. package/dist/components/rel-radio/rel-radio.ts +236 -60
  23. package/dist/components/rel-range-picker/rel-range-picker.ts +581 -91
  24. package/dist/components/rel-resizable/rel-resizable-group.ts +20 -0
  25. package/dist/components/rel-segmented-button/rel-segmented-button.ts +55 -13
  26. package/dist/components/rel-select/rel-select.ts +203 -24
  27. package/dist/components/rel-sheet/rel-sheet.ts +184 -18
  28. package/dist/components/rel-sidebar/rel-sidebar.ts +50 -40
  29. package/dist/components/rel-skeleton/rel-skeleton.ts +9 -0
  30. package/dist/components/rel-slider/rel-slider.ts +6 -3
  31. package/dist/components/rel-snackbar/rel-snackbar.ts +20 -16
  32. package/dist/components/rel-stepper/rel-stepper.ts +47 -2
  33. package/dist/components/rel-switch/rel-switch.ts +3 -1
  34. package/dist/components/rel-tab/rel-tab.ts +32 -7
  35. package/dist/components/rel-textfield/rel-textfield.ts +263 -75
  36. package/dist/components/rel-time-picker/rel-time-picker.ts +749 -261
  37. package/dist/components/rel-time-picker/time-parse.test.ts +67 -0
  38. package/dist/components/rel-time-picker/time-parse.ts +85 -0
  39. package/dist/components/rel-toast/rel-toast.ts +4 -2
  40. package/dist/components/rel-tooltip/README.md +13 -5
  41. package/dist/components/rel-tooltip/rel-tooltip.ts +33 -0
  42. package/dist/components/rel-topbar/rel-topbar-actions.ts +1 -1
  43. package/dist/components/rel-topbar/rel-topbar-brand.ts +1 -1
  44. package/dist/components/rel-topbar/rel-topbar-dropdown-item.ts +1 -1
  45. package/dist/components/rel-topbar/rel-topbar-dropdown.ts +1 -1
  46. package/dist/components/rel-topbar/rel-topbar-item.ts +318 -319
  47. package/dist/components/rel-topbar/rel-topbar-mobile-panel.ts +1 -1
  48. package/dist/components/rel-topbar/rel-topbar-profile.ts +224 -224
  49. package/dist/components/rel-topbar/rel-topbar-utilities.ts +1 -1
  50. package/dist/components/rel-topbar/rel-topbar.ts +440 -440
  51. package/dist/components/rel-upload/rel-upload.ts +25 -0
  52. package/dist/index.d.mts +461 -23
  53. package/dist/index.d.ts +461 -23
  54. package/dist/index.js +3906 -807
  55. package/dist/index.js.map +1 -1
  56. package/dist/index.mjs +4143 -1055
  57. package/dist/index.mjs.map +1 -1
  58. package/package.json +2 -2
@@ -0,0 +1,116 @@
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
+ });
@@ -0,0 +1,178 @@
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
+ }