@viasat/beam-react 2.47.1 → 2.48.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/DateField.css +1 -1
- package/assets/card.css +1 -1
- package/chunks/{DateField.Segment.C2qoaY0Z.js → DateField.Segment.BVe6TzWY.js} +48 -45
- package/chunks/DateField.Segment.CnDrSK1L.js +1 -0
- package/lib/wip/DateField/DateField.Segment.cjs.js +1 -1
- package/lib/wip/DateField/DateField.Segment.d.ts +1 -1
- package/lib/wip/DateField/DateField.Segment.es.js +1 -1
- package/lib/wip/DateField/DateField.Segments.cjs.js +1 -1
- package/lib/wip/DateField/DateField.Segments.es.js +36 -31
- package/lib/wip/DateField/DateField.cjs.js +1 -1
- package/lib/wip/DateField/DateField.es.js +185 -162
- package/lib/wip/DateField/DateField.types.d.ts +22 -3
- package/lib/wip/DateField/DateField.utils.cjs.js +1 -1
- package/lib/wip/DateField/DateField.utils.d.ts +44 -22
- package/lib/wip/DateField/DateField.utils.es.js +57 -49
- package/lib/wip/DateField/useDateFieldFocus.cjs.js +1 -1
- package/lib/wip/DateField/useDateFieldFocus.es.js +56 -49
- package/lib/wip/DateField/useDateFieldValidity.d.ts +5 -3
- package/lib/wip/DateField/useDateFieldValue.cjs.js +1 -1
- package/lib/wip/DateField/useDateFieldValue.d.ts +29 -10
- package/lib/wip/DateField/useDateFieldValue.es.js +90 -70
- package/package.json +7 -7
- package/chunks/DateField.Segment.CY0jg03_.js +0 -1
|
@@ -1,204 +1,227 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { s as a, b as
|
|
5
|
-
import { t as
|
|
6
|
-
import { H as
|
|
7
|
-
import { LabelProvider as
|
|
8
|
-
import { HelperTextProvider as
|
|
9
|
-
import { useUniversalRef as
|
|
10
|
-
import { DateFieldSegments as
|
|
11
|
-
import { toISODateString as
|
|
12
|
-
import { useDateFieldFocus as
|
|
13
|
-
import { useDateFieldForm as
|
|
14
|
-
import { useDateFieldKeyboard as
|
|
15
|
-
import { useDateFieldSegments as
|
|
16
|
-
import { useDateFieldValidity as
|
|
17
|
-
import { useDateFieldValue as
|
|
18
|
-
import { useInvalidState as
|
|
19
|
-
const
|
|
1
|
+
import { jsxs as N, jsx as r } from "react/jsx-runtime";
|
|
2
|
+
import xe from "clsx";
|
|
3
|
+
import { forwardRef as Ie, useEffect as Ne } from "react";
|
|
4
|
+
import { s as a, b as we, c as s, a as w } from "../../../chunks/DateField.Segment.BVe6TzWY.js";
|
|
5
|
+
import { t as Re } from "../../../chunks/constants.Cruz2A1w.js";
|
|
6
|
+
import { H as Ve } from "../../../chunks/form.context.cEuTL68U.js";
|
|
7
|
+
import { LabelProvider as Me } from "../../Form/contexts/label.context.es.js";
|
|
8
|
+
import { HelperTextProvider as Oe } from "../../Form/contexts/helperText.context.es.js";
|
|
9
|
+
import { useUniversalRef as Be } from "../../Form/hooks/useUniversalRef.hook.es.js";
|
|
10
|
+
import { DateFieldSegments as Ce, PARTS_ORDER as R } from "./DateField.Segments.es.js";
|
|
11
|
+
import { isMinMaxMisconfigured as Ee, dateKeyOrNull as V, toISODateString as Pe } from "./DateField.utils.es.js";
|
|
12
|
+
import { useDateFieldFocus as Te } from "./useDateFieldFocus.es.js";
|
|
13
|
+
import { useDateFieldForm as qe } from "./useDateFieldForm.es.js";
|
|
14
|
+
import { useDateFieldKeyboard as He } from "./useDateFieldKeyboard.es.js";
|
|
15
|
+
import { useDateFieldSegments as Ke } from "./useDateFieldSegments.es.js";
|
|
16
|
+
import { useDateFieldValidity as Le } from "./useDateFieldValidity.es.js";
|
|
17
|
+
import { useDateFieldValue as $e } from "./useDateFieldValue.es.js";
|
|
18
|
+
import { useInvalidState as je } from "./useInvalidState.es.js";
|
|
19
|
+
const da = Ie(
|
|
20
20
|
function({
|
|
21
|
-
value:
|
|
22
|
-
defaultValue:
|
|
23
|
-
onChange:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
21
|
+
value: M,
|
|
22
|
+
defaultValue: O,
|
|
23
|
+
onChange: B,
|
|
24
|
+
minDate: t,
|
|
25
|
+
maxDate: d,
|
|
26
|
+
getClampAnnouncement: C,
|
|
27
|
+
label: n = null,
|
|
28
|
+
helperText: u = null,
|
|
29
|
+
error: m,
|
|
30
|
+
hideRequiredMarker: E = !1,
|
|
31
|
+
validationRules: P,
|
|
32
|
+
width: T,
|
|
33
|
+
theme: c,
|
|
34
|
+
fluid: q = !1,
|
|
35
|
+
disabled: H = !1,
|
|
36
|
+
readOnly: K = !1,
|
|
37
|
+
required: L = !1,
|
|
38
|
+
name: f,
|
|
39
|
+
id: $,
|
|
40
|
+
className: j,
|
|
41
|
+
style: A,
|
|
42
|
+
"aria-label": W,
|
|
43
|
+
"aria-describedby": _,
|
|
44
|
+
"aria-labelledby": U,
|
|
45
|
+
...k
|
|
46
|
+
}, z) {
|
|
44
47
|
const {
|
|
45
48
|
disabled: e,
|
|
46
|
-
readOnly:
|
|
47
|
-
required:
|
|
48
|
-
invalid:
|
|
49
|
-
errorMessageProvided:
|
|
50
|
-
defaultValue:
|
|
51
|
-
errorId:
|
|
52
|
-
helperTextId:
|
|
53
|
-
validationErrorsId:
|
|
54
|
-
labelId:
|
|
55
|
-
ariaDescribedBy:
|
|
56
|
-
ariaLabelledBy:
|
|
57
|
-
showErrors:
|
|
58
|
-
} =
|
|
59
|
-
name:
|
|
60
|
-
disabled:
|
|
61
|
-
readOnly:
|
|
62
|
-
required:
|
|
63
|
-
defaultValue:
|
|
64
|
-
error:
|
|
65
|
-
hasHelperText: !!
|
|
66
|
-
hasLabel: !!
|
|
67
|
-
validationRules:
|
|
68
|
-
ariaDescribedBy:
|
|
69
|
-
ariaLabelledBy:
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
49
|
+
readOnly: o,
|
|
50
|
+
required: p,
|
|
51
|
+
invalid: G,
|
|
52
|
+
errorMessageProvided: b,
|
|
53
|
+
defaultValue: J,
|
|
54
|
+
errorId: g,
|
|
55
|
+
helperTextId: Q,
|
|
56
|
+
validationErrorsId: X,
|
|
57
|
+
labelId: v,
|
|
58
|
+
ariaDescribedBy: Y,
|
|
59
|
+
ariaLabelledBy: Z,
|
|
60
|
+
showErrors: ee
|
|
61
|
+
} = qe({
|
|
62
|
+
name: f,
|
|
63
|
+
disabled: H,
|
|
64
|
+
readOnly: K,
|
|
65
|
+
required: L,
|
|
66
|
+
defaultValue: O,
|
|
67
|
+
error: m,
|
|
68
|
+
hasHelperText: !!u,
|
|
69
|
+
hasLabel: !!n,
|
|
70
|
+
validationRules: P,
|
|
71
|
+
ariaDescribedBy: _,
|
|
72
|
+
ariaLabelledBy: U
|
|
73
|
+
});
|
|
74
|
+
Ne(() => {
|
|
75
|
+
process.env.NODE_ENV !== "production" && Ee(t, d) && console.warn(
|
|
76
|
+
"DateField: `minDate` is after `maxDate` — no date satisfies both, so the blur clamp is disabled and values are left as typed."
|
|
77
|
+
);
|
|
78
|
+
}, [V(t), V(d)]);
|
|
79
|
+
const { refFn: ae, ref: F } = Be(z), { segmentRefs: re, registerSegmentRef: ie } = Ke(), {
|
|
80
|
+
segmentText: le,
|
|
81
|
+
segmentValues: D,
|
|
82
|
+
currentValue: h,
|
|
83
|
+
wasTouched: se,
|
|
84
|
+
appendDigit: te,
|
|
85
|
+
adjustSegment: de,
|
|
86
|
+
clearSegment: oe,
|
|
87
|
+
beginSegmentEdit: ne,
|
|
88
|
+
commitOnBlur: ue,
|
|
89
|
+
clampAnnouncement: me
|
|
90
|
+
} = $e({
|
|
91
|
+
value: M,
|
|
92
|
+
defaultValue: J,
|
|
93
|
+
onChange: B,
|
|
94
|
+
minDate: t,
|
|
95
|
+
maxDate: d,
|
|
96
|
+
getClampAnnouncement: C
|
|
84
97
|
}), {
|
|
85
|
-
focusedSegment:
|
|
86
|
-
fieldTabIndex:
|
|
87
|
-
handleSegmentFocus:
|
|
88
|
-
handleFieldFocus:
|
|
89
|
-
handleFieldBlur:
|
|
90
|
-
handleFieldMouseDown:
|
|
98
|
+
focusedSegment: y,
|
|
99
|
+
fieldTabIndex: ce,
|
|
100
|
+
handleSegmentFocus: S,
|
|
101
|
+
handleFieldFocus: fe,
|
|
102
|
+
handleFieldBlur: pe,
|
|
103
|
+
handleFieldMouseDown: be,
|
|
91
104
|
focusNext: x,
|
|
92
|
-
focusPrevious:
|
|
93
|
-
} =
|
|
105
|
+
focusPrevious: ge
|
|
106
|
+
} = Te({
|
|
94
107
|
disabled: e,
|
|
95
|
-
fieldRef:
|
|
96
|
-
segmentRefs:
|
|
97
|
-
partsOrder:
|
|
98
|
-
onSegmentFocusChange:
|
|
99
|
-
onFieldBlur:
|
|
100
|
-
}),
|
|
108
|
+
fieldRef: F,
|
|
109
|
+
segmentRefs: re,
|
|
110
|
+
partsOrder: R,
|
|
111
|
+
onSegmentFocusChange: ne,
|
|
112
|
+
onFieldBlur: ue
|
|
113
|
+
}), ve = He({
|
|
101
114
|
disabled: e,
|
|
102
|
-
readOnly:
|
|
103
|
-
fieldRef:
|
|
115
|
+
readOnly: o,
|
|
116
|
+
fieldRef: F,
|
|
104
117
|
focusNext: x,
|
|
105
|
-
focusPrevious:
|
|
106
|
-
adjustSegment:
|
|
107
|
-
clearSegment:
|
|
108
|
-
}), { isInvalid:
|
|
109
|
-
segments:
|
|
110
|
-
currentValue:
|
|
111
|
-
wasTouched:
|
|
112
|
-
isFocused:
|
|
113
|
-
}),
|
|
114
|
-
const { advanced:
|
|
115
|
-
|
|
116
|
-
},
|
|
117
|
-
formInvalid:
|
|
118
|
-
valueInvalid:
|
|
119
|
-
}),
|
|
118
|
+
focusPrevious: ge,
|
|
119
|
+
adjustSegment: de,
|
|
120
|
+
clearSegment: oe
|
|
121
|
+
}), { isInvalid: Fe } = Le({
|
|
122
|
+
segments: D,
|
|
123
|
+
currentValue: h,
|
|
124
|
+
wasTouched: se,
|
|
125
|
+
isFocused: y !== null
|
|
126
|
+
}), De = (i, l) => {
|
|
127
|
+
const { advanced: Se } = te(i, l);
|
|
128
|
+
Se && x(i);
|
|
129
|
+
}, I = je({
|
|
130
|
+
formInvalid: G,
|
|
131
|
+
valueInvalid: Fe
|
|
132
|
+
}), he = (i) => {
|
|
120
133
|
if (e) return;
|
|
121
|
-
const
|
|
122
|
-
!
|
|
123
|
-
},
|
|
124
|
-
a[
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
134
|
+
const l = i.target.closest("label");
|
|
135
|
+
!l || l.id !== v || (i.preventDefault(), S(R[0]));
|
|
136
|
+
}, ye = xe(
|
|
137
|
+
a[we],
|
|
138
|
+
c && Re(c),
|
|
139
|
+
q && a[`${s}fluid`],
|
|
140
|
+
I && a[`${s}error`],
|
|
128
141
|
e && a[`${s}disabled`],
|
|
129
|
-
|
|
130
|
-
|
|
142
|
+
o && a[`${s}read-only`],
|
|
143
|
+
j
|
|
131
144
|
);
|
|
132
|
-
return /* @__PURE__ */
|
|
145
|
+
return /* @__PURE__ */ N(
|
|
133
146
|
"div",
|
|
134
147
|
{
|
|
135
|
-
className:
|
|
136
|
-
style: { ...
|
|
137
|
-
onMouseDownCapture:
|
|
148
|
+
className: ye,
|
|
149
|
+
style: { ...A, maxWidth: T },
|
|
150
|
+
onMouseDownCapture: he,
|
|
138
151
|
children: [
|
|
139
|
-
/* @__PURE__ */
|
|
140
|
-
|
|
152
|
+
/* @__PURE__ */ r(
|
|
153
|
+
Me,
|
|
141
154
|
{
|
|
142
|
-
ctxId:
|
|
155
|
+
ctxId: v,
|
|
143
156
|
ctxDisabled: e,
|
|
144
|
-
ctxRequired:
|
|
145
|
-
children:
|
|
157
|
+
ctxRequired: p && !E,
|
|
158
|
+
children: n
|
|
146
159
|
}
|
|
147
160
|
),
|
|
148
|
-
/* @__PURE__ */
|
|
161
|
+
/* @__PURE__ */ r(
|
|
149
162
|
"div",
|
|
150
163
|
{
|
|
151
|
-
...
|
|
152
|
-
ref:
|
|
153
|
-
id:
|
|
164
|
+
...k,
|
|
165
|
+
ref: ae,
|
|
166
|
+
id: $,
|
|
154
167
|
role: "group",
|
|
155
|
-
"aria-label":
|
|
156
|
-
"aria-labelledby":
|
|
168
|
+
"aria-label": W,
|
|
169
|
+
"aria-labelledby": Z,
|
|
157
170
|
"aria-disabled": e || void 0,
|
|
158
|
-
"aria-required":
|
|
159
|
-
"aria-invalid":
|
|
160
|
-
"aria-describedby":
|
|
161
|
-
"aria-errormessage":
|
|
162
|
-
tabIndex:
|
|
163
|
-
className: a[
|
|
164
|
-
onMouseDown:
|
|
165
|
-
onFocus:
|
|
166
|
-
children: /* @__PURE__ */
|
|
167
|
-
|
|
171
|
+
"aria-required": p || void 0,
|
|
172
|
+
"aria-invalid": I || void 0,
|
|
173
|
+
"aria-describedby": Y,
|
|
174
|
+
"aria-errormessage": b ? g : void 0,
|
|
175
|
+
tabIndex: ce,
|
|
176
|
+
className: a[w.field],
|
|
177
|
+
onMouseDown: be,
|
|
178
|
+
onFocus: fe,
|
|
179
|
+
children: /* @__PURE__ */ r(
|
|
180
|
+
Ce,
|
|
168
181
|
{
|
|
169
|
-
segmentText:
|
|
170
|
-
segmentValues:
|
|
171
|
-
focusedSegment:
|
|
182
|
+
segmentText: le,
|
|
183
|
+
segmentValues: D,
|
|
184
|
+
focusedSegment: y,
|
|
172
185
|
disabled: e,
|
|
173
|
-
readOnly:
|
|
174
|
-
onSegmentFocus:
|
|
175
|
-
onSegmentBlur:
|
|
176
|
-
onSegmentInput:
|
|
177
|
-
onSegmentKeyDown:
|
|
178
|
-
registerSegmentRef:
|
|
186
|
+
readOnly: o,
|
|
187
|
+
onSegmentFocus: S,
|
|
188
|
+
onSegmentBlur: pe,
|
|
189
|
+
onSegmentInput: De,
|
|
190
|
+
onSegmentKeyDown: ve,
|
|
191
|
+
registerSegmentRef: ie
|
|
179
192
|
}
|
|
180
193
|
)
|
|
181
194
|
}
|
|
182
195
|
),
|
|
183
|
-
/* @__PURE__ */
|
|
196
|
+
/* @__PURE__ */ r(
|
|
197
|
+
"span",
|
|
198
|
+
{
|
|
199
|
+
role: "status",
|
|
200
|
+
"aria-live": "polite",
|
|
201
|
+
"aria-atomic": "true",
|
|
202
|
+
className: a[w.srStatus],
|
|
203
|
+
children: me
|
|
204
|
+
}
|
|
205
|
+
),
|
|
206
|
+
/* @__PURE__ */ r(
|
|
184
207
|
"input",
|
|
185
208
|
{
|
|
186
209
|
type: "hidden",
|
|
187
|
-
name:
|
|
188
|
-
value:
|
|
210
|
+
name: f,
|
|
211
|
+
value: Pe(h),
|
|
189
212
|
disabled: e
|
|
190
213
|
}
|
|
191
214
|
),
|
|
192
|
-
/* @__PURE__ */
|
|
193
|
-
|
|
194
|
-
|
|
215
|
+
/* @__PURE__ */ N(Oe, { ctxId: Q, ctxDisabled: e, children: [
|
|
216
|
+
u,
|
|
217
|
+
b && /* @__PURE__ */ r(Ve, { id: g, appearance: "negative", children: m })
|
|
195
218
|
] }),
|
|
196
|
-
|
|
219
|
+
ee(X)
|
|
197
220
|
]
|
|
198
221
|
}
|
|
199
222
|
);
|
|
200
223
|
}
|
|
201
224
|
);
|
|
202
225
|
export {
|
|
203
|
-
|
|
226
|
+
da as DateField
|
|
204
227
|
};
|
|
@@ -89,9 +89,21 @@ export interface DateFieldProps extends DateFieldInputAttributes {
|
|
|
89
89
|
defaultValue?: Nullable<Date>;
|
|
90
90
|
/**
|
|
91
91
|
* Fires when the derived `Date | null` value transitions.
|
|
92
|
-
* In DF-1, user-input handlers don't exist yet — wired up in DF-2.
|
|
93
92
|
*/
|
|
94
93
|
onChange?: (value: Nullable<Date>) => void;
|
|
94
|
+
/**
|
|
95
|
+
* Lower bound; on blur, a touched value springs up to it. Use `validationRules` for validation.
|
|
96
|
+
*/
|
|
97
|
+
minDate?: Date;
|
|
98
|
+
/**
|
|
99
|
+
* Upper bound; on blur, a touched value springs down to it. Use `validationRules` for validation.
|
|
100
|
+
*/
|
|
101
|
+
maxDate?: Date;
|
|
102
|
+
/**
|
|
103
|
+
* Called when a touched value springs to a bound on blur; return a localized
|
|
104
|
+
* message announced politely to screen readers. Omit → no announcement.
|
|
105
|
+
*/
|
|
106
|
+
getClampAnnouncement?: (clampedDate: Date) => string;
|
|
95
107
|
}
|
|
96
108
|
/**
|
|
97
109
|
* Internal props for the segment subcomponent. Not part of the public API.
|
|
@@ -103,8 +115,15 @@ export interface DateFieldSegmentProps {
|
|
|
103
115
|
/** Numeric segment value — used for `aria-valuenow`. `null` when the segment has no committed value. */
|
|
104
116
|
value: Nullable<number>;
|
|
105
117
|
/**
|
|
106
|
-
* The
|
|
107
|
-
*
|
|
118
|
+
* The lower bound announced as `aria-valuemin` — an intrinsic calendar
|
|
119
|
+
* range, NOT the `minDate` prop (day/month: always 1; year: always 1).
|
|
120
|
+
* Computed by `DateField.Segments` so the segment itself stays a pure renderer.
|
|
121
|
+
*/
|
|
122
|
+
valueMin: number;
|
|
123
|
+
/**
|
|
124
|
+
* The upper bound announced as `aria-valuemax` — an intrinsic calendar
|
|
125
|
+
* range, NOT the `maxDate` prop (day: month-aware, e.g. 28 for Feb
|
|
126
|
+
* non-leap; month: 12; year: always 9999).
|
|
108
127
|
* Computed by `DateField.Segments` so the segment itself stays a pure renderer.
|
|
109
128
|
*/
|
|
110
129
|
valueMax: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("./DateField.validation.cjs.js"),u=31,s=12,c=1,d=9999,y=(e,t,n)=>Math.min(n,Math.max(t,e)),S=(e,t)=>((e-1)%t+t)%t+1,N=2024,h=(e,t)=>t==null?31:new Date(e??N,t,0).getDate(),T=()=>{const e=new Date;return{day:e.getDate(),month:e.getMonth()+1,year:e.getFullYear()}},l=e=>e instanceof Date&&!Number.isNaN(e.getTime()),_=(e,t,n,r)=>{if(n==="min")return e==="year"?null:1;if(n==="max")return e==="year"?null:e==="day"?r.daysInMonth:s;if(t==null){if(e==="year")return r.today.year;const f=e==="day"?u:s;return n>0?1:f}if(e==="year")return y(t+n,c,d);const o=e==="day"?u:s;return S(t+n,o)},A={day:"",month:"",year:""},M=e=>{const{day:t,month:n,year:r}=e;if(t==null||n==null||r==null)return null;const o=new Date(r,n-1,t);return o.setFullYear(r),Number.isNaN(o.getTime())||o.getFullYear()!==r||o.getMonth()!==n-1||o.getDate()!==t?null:o},E=(e,t)=>e==null&&t==null?!0:e==null||t==null?!1:e.getTime()===t.getTime(),a=e=>e.getFullYear()*1e4+(e.getMonth()+1)*100+e.getDate(),p=e=>l(e)?a(e):null,D=(e,t,n)=>{const r=a(e);return!(l(t)&&r<a(t)||l(n)&&r>a(n))},m=(e,t)=>l(e)&&l(t)&&a(e)>a(t),Y=(e,t,n)=>{if(m(t,n))return e;const r=a(e);return l(t)&&r<a(t)?new Date(t.getFullYear(),t.getMonth(),t.getDate()):l(n)&&r>a(n)?new Date(n.getFullYear(),n.getMonth(),n.getDate()):e},F=e=>{if(!l(e))return"";const t=String(e.getFullYear()).padStart(4,"0"),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return`${t}-${n}-${r}`},R=e=>e.filter(t=>t.type!=="literal").map(t=>t.type),I=e=>l(e)?{day:String(e.getDate()).padStart(2,"0"),month:String(e.getMonth()+1).padStart(2,"0"),year:String(e.getFullYear()).padStart(4,"0")}:A,i=(e,t)=>{if(t===""||e==="year"&&t.length<g.SEGMENT_MAX_LENGTH.year)return null;const n=parseInt(t,10);return Number.isNaN(n)||n===0?null:n},V=e=>M({day:i("day",e.day),month:i("month",e.month),year:i("year",e.year)}),w=(e,t)=>t===""?"":t.padStart(g.SEGMENT_MAX_LENGTH[e],"0"),X=(e,t,n)=>t===""?{displayValue:n,isPlaceholder:!0}:{displayValue:t.padStart(g.SEGMENT_MAX_LENGTH[e],"0"),isPlaceholder:!1},O=e=>{const t=window.getSelection();if(!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)},P=e=>{var n;if(!e)return;const t=(n=window.getSelection)==null?void 0:n.call(window);t&&t.rangeCount>0&&e.contains(t.anchorNode)&&t.removeAllRanges()};exports.DAY_SPIN_MAX=u;exports.MONTH_MAX=s;exports.YEAR_MAX=d;exports.YEAR_MIN=c;exports.adjustSegmentValue=_;exports.clamp=y;exports.clampDateToRange=Y;exports.clearSelectionWithin=P;exports.dateKeyOrNull=p;exports.deriveValue=M;exports.deriveValueFromText=V;exports.getDaysInMonth=h;exports.getSegmentDisplay=X;exports.getSegmentOrder=R;exports.isDateInRange=D;exports.isMinMaxMisconfigured=m;exports.isSameDateValue=E;exports.normalizeSegmentText=w;exports.segmentNumber=i;exports.segmentTextFromValue=I;exports.selectElementContents=O;exports.toISODateString=F;exports.todayParts=T;exports.wrapInRange=S;
|
|
@@ -15,11 +15,12 @@ export declare const DAY_SPIN_MAX = 31;
|
|
|
15
15
|
/** Absolute maximum for month (1-based). */
|
|
16
16
|
export declare const MONTH_MAX = 12;
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
18
|
+
* Absolute floor/ceiling for the free-spinning year segment. `minDate`/
|
|
19
|
+
* `maxDate` no longer bound the year directly (DF-10: the whole date clamps
|
|
20
|
+
* to those bounds on blur instead — see `commitOnBlur`).
|
|
21
21
|
*/
|
|
22
|
-
export declare const
|
|
22
|
+
export declare const YEAR_MIN = 1;
|
|
23
|
+
export declare const YEAR_MAX = 9999;
|
|
23
24
|
/** Clamps `n` to `[lo, hi]` (inclusive). */
|
|
24
25
|
export declare const clamp: (n: number, lo: number, hi: number) => number;
|
|
25
26
|
/**
|
|
@@ -64,24 +65,15 @@ export interface AdjustSegmentContext {
|
|
|
64
65
|
* Computes the next numeric value for a date segment after an increment,
|
|
65
66
|
* decrement, or boundary jump.
|
|
66
67
|
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
* -
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
* - **month**: modular wrap within `[1, MONTH_MAX]`.
|
|
77
|
-
* - **year**: clamp to `[1, 9999]`; no wrap.
|
|
78
|
-
* - **Empty segment + numeric delta**: direction-based first/last valid value
|
|
79
|
-
* for day/month — positive amount → `1`, negative amount → `DAY_SPIN_MAX`/
|
|
80
|
-
* `MONTH_MAX`. Year has no natural bound, so it seeds to `ctx.today.year`
|
|
81
|
-
* regardless of direction.
|
|
82
|
-
* - **`'min'`**: returns 1 for day/month, null for year.
|
|
83
|
-
* - **`'max'`**: returns `ctx.daysInMonth` for day (End → month-aware last
|
|
84
|
-
* valid day), MONTH_MAX for month, null for year.
|
|
68
|
+
* Day and month wrap modularly within their absolute ranges (day:
|
|
69
|
+
* `[1, DAY_SPIN_MAX]`; month: `[1, MONTH_MAX]`); out-of-range dates (e.g. Feb
|
|
70
|
+
* 31) are flagged by the validity layer, not clamped here. Year clamps (no
|
|
71
|
+
* wrap) within `[YEAR_MIN, YEAR_MAX]` and spins free of `minDate`/`maxDate`
|
|
72
|
+
* (DF-10: those clamp the whole date on blur instead — see `commitOnBlur`);
|
|
73
|
+
* year `'min'`/`'max'` (Home/End) are a no-op (`null`). An empty segment seeds
|
|
74
|
+
* on the first numeric press: day/month to a direction-based first/last valid
|
|
75
|
+
* value (positive amount → `1`, negative → `DAY_SPIN_MAX`/`MONTH_MAX`;
|
|
76
|
+
* EPTOOLS-2766), year to `ctx.today.year`.
|
|
85
77
|
*
|
|
86
78
|
* @param type - Segment kind (`'day'`, `'month'`, or `'year'`).
|
|
87
79
|
* @param current - Current numeric value of the segment, or `null` when empty.
|
|
@@ -91,6 +83,36 @@ export interface AdjustSegmentContext {
|
|
|
91
83
|
export declare const adjustSegmentValue: (type: SegmentType, current: Nullable<number>, amount: SegmentAdjustment, ctx: AdjustSegmentContext) => Nullable<number>;
|
|
92
84
|
export declare const deriveValue: (segments: SegmentValues) => Nullable<Date>;
|
|
93
85
|
export declare const isSameDateValue: (a: Nullable<Date>, b: Nullable<Date>) => boolean;
|
|
86
|
+
/**
|
|
87
|
+
* `dateKey` for a possibly-absent/invalid `Date`, collapsing both to `null`
|
|
88
|
+
* (never `NaN` — a `NaN` dependency would itself churn every render). Used to
|
|
89
|
+
* key memo/callback deps on a bound's primitive calendar day instead of the
|
|
90
|
+
* `Date` object's identity.
|
|
91
|
+
*/
|
|
92
|
+
export declare const dateKeyOrNull: (d?: Nullable<Date>) => Nullable<number>;
|
|
93
|
+
/**
|
|
94
|
+
* True when `value`'s calendar day falls within `[minDate, maxDate]`
|
|
95
|
+
* (inclusive). Compared by calendar day only, so a `maxDate` with a non-zero
|
|
96
|
+
* time-of-day still accepts the same day. A missing bound is unbounded on
|
|
97
|
+
* that side.
|
|
98
|
+
*/
|
|
99
|
+
export declare const isDateInRange: (value: Date, minDate?: Nullable<Date>, maxDate?: Nullable<Date>) => boolean;
|
|
100
|
+
/**
|
|
101
|
+
* True when both bounds are valid Dates but `minDate`'s calendar day is after
|
|
102
|
+
* `maxDate`'s — a misconfiguration where no date can satisfy both. `DateField`
|
|
103
|
+
* dev-warns on this, and `clampDateToRange` skips clamping so a touched value
|
|
104
|
+
* isn't flip-flopped between the two bounds on repeated blurs.
|
|
105
|
+
*/
|
|
106
|
+
export declare const isMinMaxMisconfigured: (minDate?: Nullable<Date>, maxDate?: Nullable<Date>) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Clamps `value` to the nearest in-range bound by calendar day: `minDate` when
|
|
109
|
+
* the value is before it, `maxDate` when after, else the value unchanged. An
|
|
110
|
+
* invalid/absent bound is ignored (unbounded on that side). Returns a
|
|
111
|
+
* local-midnight `Date` on the bound's calendar day. Used by `commitOnBlur` to
|
|
112
|
+
* normalize a well-formed out-of-range date; structural invalids (Feb 30) never
|
|
113
|
+
* reach here since they derive to `null`.
|
|
114
|
+
*/
|
|
115
|
+
export declare const clampDateToRange: (value: Date, minDate?: Nullable<Date>, maxDate?: Nullable<Date>) => Date;
|
|
94
116
|
export declare const toISODateString: (value: Nullable<Date>) => string;
|
|
95
117
|
/** Ordered segment types from a parts array (literals stripped). */
|
|
96
118
|
export declare const getSegmentOrder: (parts: ReadonlyArray<DateFieldPart>) => ReadonlyArray<SegmentType>;
|