@viasat/beam-react 2.53.0 → 2.54.1
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 +20 -0
- package/assets/Alert.css +1 -1
- package/assets/Badge.css +1 -1
- package/assets/DateField.css +1 -1
- package/assets/index.css +1 -1
- package/lib/wip/DateField/DateField.Segments.cjs.js +1 -1
- package/lib/wip/DateField/DateField.Segments.d.ts +4 -3
- package/lib/wip/DateField/DateField.Segments.es.js +39 -45
- package/lib/wip/DateField/DateField.cjs.js +1 -1
- package/lib/wip/DateField/DateField.es.js +175 -170
- package/lib/wip/DateField/DateField.types.d.ts +8 -1
- package/lib/wip/DateField/DateField.utils.cjs.js +1 -1
- package/lib/wip/DateField/DateField.utils.d.ts +15 -0
- package/lib/wip/DateField/DateField.utils.es.js +120 -77
- package/lib/wip/DateField/useDateFieldFocus.d.ts +1 -1
- package/lib/wip/DateField/useDateFieldKeyboard.d.ts +2 -2
- package/package.json +7 -7
|
@@ -116,8 +116,23 @@ export declare const isMinMaxMisconfigured: (minDate?: Nullable<Date>, maxDate?:
|
|
|
116
116
|
*/
|
|
117
117
|
export declare const clampDateToRange: (value: Date, minDate?: Nullable<Date>, maxDate?: Nullable<Date>) => Date;
|
|
118
118
|
export declare const toISODateString: (value: Nullable<Date>) => string;
|
|
119
|
+
/** Type guard: a literal separator (`/`, `.`, `年`, …) rather than a segment. */
|
|
120
|
+
export declare const isLiteralPart: (part: DateFieldPart) => part is DateFieldPart & {
|
|
121
|
+
type: "literal";
|
|
122
|
+
};
|
|
119
123
|
/** Ordered segment types from a parts array (literals stripped). */
|
|
120
124
|
export declare const getSegmentOrder: (parts: ReadonlyArray<DateFieldPart>) => ReadonlyArray<SegmentType>;
|
|
125
|
+
/**
|
|
126
|
+
* Locale-derived segment order + separators (DF-8), memoized per locale. Falls
|
|
127
|
+
* back to en-US for any locale Intl can't resolve to the three date segments —
|
|
128
|
+
* en-US being the ECMAScript-guaranteed baseline (Intl's own ultimate fallback).
|
|
129
|
+
* Resolved lazily on first use, so a broken Intl (which can't render the field
|
|
130
|
+
* anyway — `getMonthName` needs it too) surfaces at render, catchable by an
|
|
131
|
+
* error boundary, instead of crashing the bundle at import.
|
|
132
|
+
*/
|
|
133
|
+
export declare const getDateParts: (locale: string) => ReadonlyArray<DateFieldPart>;
|
|
134
|
+
/** @internal — test-only. Clears the per-locale parts cache for Intl isolation. */
|
|
135
|
+
export declare const __clearDatePartsCache: () => void;
|
|
121
136
|
/** Per-segment zero-padded strings from a Date. All-empty for null/invalid. */
|
|
122
137
|
export declare const segmentTextFromValue: (value: Nullable<Date>) => SegmentText;
|
|
123
138
|
/** The number a segment string contributes to the date / `aria-valuenow`, or
|
|
@@ -1,89 +1,132 @@
|
|
|
1
1
|
import "../../../chunks/constants.Cruz2A1w.js";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as S } from "../../../chunks/helpers.CiQfGwdc.js";
|
|
3
3
|
import { SEGMENT_MAX_LENGTH as u } from "./DateField.validation.es.js";
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
return { day:
|
|
7
|
-
}, o = (
|
|
8
|
-
if (n === "min") return
|
|
4
|
+
const m = new Intl.DateTimeFormat("en-US", { month: "long" }), L = (t) => m.format(new Date(2e3, t - 1, 1)), g = 31, l = 12, h = 1, T = 9999, M = (t, e, n) => Math.min(n, Math.max(e, t)), p = (t, e) => ((t - 1) % e + e) % e + 1, w = 2024, O = (t, e) => e == null ? 31 : new Date(t ?? w, e, 0).getDate(), K = () => {
|
|
5
|
+
const t = /* @__PURE__ */ new Date();
|
|
6
|
+
return { day: t.getDate(), month: t.getMonth() + 1, year: t.getFullYear() };
|
|
7
|
+
}, o = (t) => t instanceof Date && !Number.isNaN(t.getTime()), X = (t, e, n, r) => {
|
|
8
|
+
if (n === "min") return t === "year" ? null : 1;
|
|
9
9
|
if (n === "max")
|
|
10
|
-
return
|
|
11
|
-
if (
|
|
12
|
-
if (
|
|
13
|
-
const
|
|
14
|
-
return n > 0 ? 1 :
|
|
10
|
+
return t === "year" ? null : t === "day" ? r.daysInMonth : l;
|
|
11
|
+
if (e == null) {
|
|
12
|
+
if (t === "year") return r.today.year;
|
|
13
|
+
const f = t === "day" ? g : l;
|
|
14
|
+
return n > 0 ? 1 : f;
|
|
15
15
|
}
|
|
16
|
-
if (
|
|
17
|
-
const
|
|
18
|
-
return
|
|
19
|
-
},
|
|
20
|
-
const { day:
|
|
21
|
-
if (
|
|
22
|
-
const
|
|
23
|
-
return
|
|
24
|
-
},
|
|
25
|
-
const r = a(
|
|
26
|
-
return !(o(
|
|
27
|
-
},
|
|
28
|
-
if (
|
|
29
|
-
const r = a(
|
|
30
|
-
return o(
|
|
31
|
-
},
|
|
32
|
-
if (!o(
|
|
33
|
-
const
|
|
34
|
-
return `${
|
|
35
|
-
},
|
|
36
|
-
(
|
|
37
|
-
).map((
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
16
|
+
if (t === "year") return M(e + n, h, T);
|
|
17
|
+
const s = t === "day" ? g : l;
|
|
18
|
+
return p(e + n, s);
|
|
19
|
+
}, A = { day: "", month: "", year: "" }, N = (t) => {
|
|
20
|
+
const { day: e, month: n, year: r } = t;
|
|
21
|
+
if (e == null || n == null || r == null) return null;
|
|
22
|
+
const s = new Date(r, n - 1, e);
|
|
23
|
+
return s.setFullYear(r), Number.isNaN(s.getTime()) || s.getFullYear() !== r || s.getMonth() !== n - 1 || s.getDate() !== e ? null : s;
|
|
24
|
+
}, k = (t, e) => t == null && e == null ? !0 : t == null || e == null ? !1 : t.getTime() === e.getTime(), a = S, H = (t) => o(t) ? a(t) : null, U = (t, e, n) => {
|
|
25
|
+
const r = a(t);
|
|
26
|
+
return !(o(e) && r < a(e) || o(n) && r > a(n));
|
|
27
|
+
}, _ = (t, e) => o(t) && o(e) && a(t) > a(e), b = (t, e, n) => {
|
|
28
|
+
if (_(e, n)) return t;
|
|
29
|
+
const r = a(t);
|
|
30
|
+
return o(e) && r < a(e) ? new Date(e.getFullYear(), e.getMonth(), e.getDate()) : o(n) && r > a(n) ? new Date(n.getFullYear(), n.getMonth(), n.getDate()) : t;
|
|
31
|
+
}, B = (t) => {
|
|
32
|
+
if (!o(t)) return "";
|
|
33
|
+
const e = String(t.getFullYear()).padStart(4, "0"), n = String(t.getMonth() + 1).padStart(2, "0"), r = String(t.getDate()).padStart(2, "0");
|
|
34
|
+
return `${e}-${n}-${r}`;
|
|
35
|
+
}, E = (t) => t.type === "literal", D = (t) => t.filter(
|
|
36
|
+
(e) => !E(e)
|
|
37
|
+
).map((e) => e.type), P = new Date(2020, 0, 2), R = /* @__PURE__ */ new Set([
|
|
38
|
+
8206,
|
|
39
|
+
8207,
|
|
40
|
+
8234,
|
|
41
|
+
8235,
|
|
42
|
+
8236,
|
|
43
|
+
8237,
|
|
44
|
+
8238,
|
|
45
|
+
8294,
|
|
46
|
+
8295,
|
|
47
|
+
8296,
|
|
48
|
+
8297
|
|
49
|
+
]), F = (t) => [...t].filter((e) => !R.has(e.codePointAt(0) ?? -1)).join(""), I = /* @__PURE__ */ new Set(["day", "month", "year", "literal"]), d = 3, y = (t) => {
|
|
50
|
+
try {
|
|
51
|
+
const e = new Intl.DateTimeFormat(t, {
|
|
52
|
+
year: "numeric",
|
|
53
|
+
month: "2-digit",
|
|
54
|
+
day: "2-digit",
|
|
55
|
+
calendar: "gregory"
|
|
56
|
+
}).formatToParts(P).filter((r) => I.has(r.type)).map((r) => ({
|
|
57
|
+
type: r.type,
|
|
58
|
+
value: r.type === "literal" ? F(r.value) : ""
|
|
59
|
+
})), n = D(e);
|
|
60
|
+
return n.length === d && new Set(n).size === d ? e : null;
|
|
61
|
+
} catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}, c = /* @__PURE__ */ new Map(), G = (t) => {
|
|
65
|
+
let e = t;
|
|
66
|
+
try {
|
|
67
|
+
e = new Intl.Locale(t).toString();
|
|
68
|
+
} catch {
|
|
69
|
+
e = t.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
const n = c.get(e);
|
|
72
|
+
if (n) return n;
|
|
73
|
+
const r = y(t) ?? y("en-US");
|
|
74
|
+
if (!r)
|
|
75
|
+
throw new Error("DateField: Intl cannot resolve en-US date parts");
|
|
76
|
+
return c.set(e, r), r;
|
|
77
|
+
}, $ = () => c.clear(), j = (t) => o(t) ? {
|
|
78
|
+
day: String(t.getDate()).padStart(2, "0"),
|
|
79
|
+
month: String(t.getMonth() + 1).padStart(2, "0"),
|
|
80
|
+
year: String(t.getFullYear()).padStart(4, "0")
|
|
81
|
+
} : A, i = (t, e) => {
|
|
82
|
+
if (e === "" || t === "year" && e.length < u.year) return null;
|
|
83
|
+
const n = parseInt(e, 10);
|
|
44
84
|
return Number.isNaN(n) || n === 0 ? null : n;
|
|
45
|
-
},
|
|
46
|
-
day: i("day",
|
|
47
|
-
month: i("month",
|
|
48
|
-
year: i("year",
|
|
49
|
-
}),
|
|
50
|
-
displayValue:
|
|
85
|
+
}, z = (t) => N({
|
|
86
|
+
day: i("day", t.day),
|
|
87
|
+
month: i("month", t.month),
|
|
88
|
+
year: i("year", t.year)
|
|
89
|
+
}), W = (t, e) => e === "" ? "" : e.padStart(u[t], "0"), q = (t, e, n) => e === "" ? { displayValue: n, isPlaceholder: !0 } : {
|
|
90
|
+
displayValue: e.padStart(u[t], "0"),
|
|
51
91
|
isPlaceholder: !1
|
|
52
|
-
},
|
|
53
|
-
const
|
|
54
|
-
if (!
|
|
92
|
+
}, J = (t) => {
|
|
93
|
+
const e = window.getSelection();
|
|
94
|
+
if (!e) return;
|
|
55
95
|
const n = document.createRange();
|
|
56
|
-
n.selectNodeContents(
|
|
57
|
-
},
|
|
96
|
+
n.selectNodeContents(t), e.removeAllRanges(), e.addRange(n);
|
|
97
|
+
}, Q = (t) => {
|
|
58
98
|
var n;
|
|
59
|
-
if (!
|
|
60
|
-
const
|
|
61
|
-
|
|
99
|
+
if (!t) return;
|
|
100
|
+
const e = (n = window.getSelection) == null ? void 0 : n.call(window);
|
|
101
|
+
e && e.rangeCount > 0 && t.contains(e.anchorNode) && e.removeAllRanges();
|
|
62
102
|
};
|
|
63
103
|
export {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
b as
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
104
|
+
g as DAY_SPIN_MAX,
|
|
105
|
+
l as MONTH_MAX,
|
|
106
|
+
T as YEAR_MAX,
|
|
107
|
+
h as YEAR_MIN,
|
|
108
|
+
$ as __clearDatePartsCache,
|
|
109
|
+
X as adjustSegmentValue,
|
|
110
|
+
M as clamp,
|
|
111
|
+
b as clampDateToRange,
|
|
112
|
+
Q as clearSelectionWithin,
|
|
113
|
+
H as dateKeyOrNull,
|
|
114
|
+
N as deriveValue,
|
|
115
|
+
z as deriveValueFromText,
|
|
116
|
+
G as getDateParts,
|
|
117
|
+
O as getDaysInMonth,
|
|
118
|
+
L as getMonthName,
|
|
119
|
+
q as getSegmentDisplay,
|
|
120
|
+
D as getSegmentOrder,
|
|
121
|
+
U as isDateInRange,
|
|
122
|
+
E as isLiteralPart,
|
|
123
|
+
_ as isMinMaxMisconfigured,
|
|
124
|
+
k as isSameDateValue,
|
|
125
|
+
W as normalizeSegmentText,
|
|
83
126
|
i as segmentNumber,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
127
|
+
j as segmentTextFromValue,
|
|
128
|
+
J as selectElementContents,
|
|
129
|
+
B as toISODateString,
|
|
130
|
+
K as todayParts,
|
|
131
|
+
p as wrapInRange
|
|
89
132
|
};
|
|
@@ -4,7 +4,7 @@ export interface UseDateFieldFocusArgs {
|
|
|
4
4
|
disabled: boolean;
|
|
5
5
|
fieldRef: RefObject<HTMLDivElement>;
|
|
6
6
|
segmentRefs: MutableRefObject<Map<SegmentType, HTMLSpanElement>>;
|
|
7
|
-
/** Ordered segment types (literals stripped)
|
|
7
|
+
/** Ordered segment types (literals stripped), derived from the active locale. */
|
|
8
8
|
partsOrder: ReadonlyArray<SegmentType>;
|
|
9
9
|
/** Called when focus enters a segment (any path). */
|
|
10
10
|
onSegmentFocusChange?: (segment: SegmentType) => void;
|
|
@@ -28,9 +28,9 @@ export interface UseDateFieldKeyboardArgs {
|
|
|
28
28
|
readOnly: boolean;
|
|
29
29
|
/** Field root ref, used to detect RTL direction. */
|
|
30
30
|
fieldRef: RefObject<HTMLDivElement>;
|
|
31
|
-
/** Move focus to the next segment in `
|
|
31
|
+
/** Move focus to the next segment in the locale-derived `partsOrder`. */
|
|
32
32
|
focusNext: (segment: SegmentType) => void;
|
|
33
|
-
/** Move focus to the previous segment in `
|
|
33
|
+
/** Move focus to the previous segment in the locale-derived `partsOrder`. */
|
|
34
34
|
focusPrevious: (segment: SegmentType) => void;
|
|
35
35
|
/**
|
|
36
36
|
* Increment, decrement, or jump a segment to its min/max boundary.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viasat/beam-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.54.1",
|
|
4
4
|
"description": "React component library for the Beam design system",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Viasat",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"access": "public"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
|
-
"@viasat/beam-fonts": "2.
|
|
64
|
-
"@viasat/beam-shared": "2.
|
|
65
|
-
"@viasat/beam-styles": "2.
|
|
66
|
-
"@viasat/beam-tokens": "2.
|
|
67
|
-
"@viasat/beam-icons": "2.
|
|
68
|
-
"@viasat/beam-react-claude-plugin": "2.
|
|
63
|
+
"@viasat/beam-fonts": "2.54.1",
|
|
64
|
+
"@viasat/beam-shared": "2.54.1",
|
|
65
|
+
"@viasat/beam-styles": "2.54.1",
|
|
66
|
+
"@viasat/beam-tokens": "2.54.1",
|
|
67
|
+
"@viasat/beam-icons": "2.54.1",
|
|
68
|
+
"@viasat/beam-react-claude-plugin": "2.54.1",
|
|
69
69
|
"clsx": "^1.2.1",
|
|
70
70
|
"@floating-ui/react": "^0.26.18",
|
|
71
71
|
"@stepperize/react": "^5.1.5",
|