@viasat/beam-react 2.41.0 → 2.42.0
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/lib/wip/DateField/DateField.cjs.js +1 -1
- package/lib/wip/DateField/DateField.es.js +75 -71
- package/lib/wip/DateField/useDateFieldKeyboard.cjs.js +1 -1
- package/lib/wip/DateField/useDateFieldKeyboard.d.ts +15 -1
- package/lib/wip/DateField/useDateFieldKeyboard.es.js +33 -29
- package/lib/wip/DateField/useDateFieldValue.cjs.js +1 -1
- package/lib/wip/DateField/useDateFieldValue.d.ts +19 -0
- package/lib/wip/DateField/useDateFieldValue.es.js +84 -66
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),fe=require("clsx"),me=require("react"),e=require("../../../chunks/DateField.Segment.CY0jg03_.js"),ge=require("../../../chunks/constants.CgMu0_1M.js"),pe=require("../../../chunks/form.context.D5XrYvpI.js"),xe=require("../../Form/contexts/label.context.cjs.js"),ve=require("../../Form/contexts/helperText.context.cjs.js"),ye=require("../../Form/hooks/useUniversalRef.hook.cjs.js"),r=require("./DateField.Segments.cjs.js"),Se=require("./DateField.utils.cjs.js"),qe=require("./useDateFieldFocus.cjs.js"),he=require("./useDateFieldForm.cjs.js"),we=require("./useDateFieldKeyboard.cjs.js"),Ie=require("./useDateFieldSegments.cjs.js"),Re=require("./useDateFieldValidity.cjs.js"),Pe=require("./useDateFieldValue.cjs.js"),Te=require("./useInvalidState.cjs.js"),Ve=me.forwardRef(function({value:S,defaultValue:q,onChange:h,label:d=null,helperText:n=null,error:o,hideRequiredMarker:w=!1,validationRules:I,width:R,theme:u,fluid:P=!1,disabled:T=!1,readOnly:V=!1,required:j=!1,name:c,id:M,className:N,style:O,"aria-label":B,"aria-describedby":C,"aria-labelledby":E,...H},L){const{disabled:i,readOnly:t,required:F,invalid:K,errorMessageProvided:_,defaultValue:$,errorId:b,helperTextId:k,validationErrorsId:A,labelId:D,ariaDescribedBy:U,ariaLabelledBy:W,showErrors:z}=he.useDateFieldForm({name:c,disabled:T,readOnly:V,required:j,defaultValue:q,error:o,hasHelperText:!!n,hasLabel:!!d,validationRules:I,ariaDescribedBy:C,ariaLabelledBy:E}),{refFn:G,ref:f}=ye.useUniversalRef(L),{segmentRefs:J,registerSegmentRef:Q}=Ie.useDateFieldSegments(),{segmentText:X,segmentValues:m,currentValue:g,wasTouched:Y,appendDigit:Z,adjustSegment:ee,deleteLastDigit:ie,clearSegment:ae,beginSegmentEdit:le,commitOnBlur:se}=Pe.useDateFieldValue({value:S,defaultValue:$,onChange:h}),{focusedSegment:p,fieldTabIndex:te,handleSegmentFocus:x,handleFieldFocus:re,handleFieldBlur:de,handleFieldMouseDown:ne,focusNext:v,focusPrevious:oe}=qe.useDateFieldFocus({disabled:i,fieldRef:f,segmentRefs:J,partsOrder:r.PARTS_ORDER,onSegmentFocusChange:le,onFieldBlur:se}),ue=we.useDateFieldKeyboard({disabled:i,readOnly:t,fieldRef:f,focusNext:v,focusPrevious:oe,adjustSegment:ee,deleteLastDigit:ie,clearSegment:ae}),{isInvalid:ce}=Re.useDateFieldValidity({segments:m,currentValue:g,wasTouched:Y,isFocused:p!==null}),Fe=(l,s)=>{const{advanced:De}=Z(l,s);De&&v(l)},y=Te.useInvalidState({formInvalid:K,valueInvalid:ce}),_e=l=>{if(i)return;const s=l.target.closest("label");!s||s.id!==D||(l.preventDefault(),x(r.PARTS_ORDER[0]))},be=fe(e.styles[e.baseClassNamePrefix],u&&ge.themeClassName(u),P&&e.styles[`${e.classModifierPrefix}fluid`],y&&e.styles[`${e.classModifierPrefix}error`],i&&e.styles[`${e.classModifierPrefix}disabled`],t&&e.styles[`${e.classModifierPrefix}read-only`],N);return a.jsxs("div",{className:be,style:{...O,maxWidth:R},onMouseDownCapture:_e,children:[a.jsx(xe.LabelProvider,{ctxId:D,ctxDisabled:i,ctxRequired:F&&!w,children:d}),a.jsx("div",{...H,ref:G,id:M,role:"group","aria-label":B,"aria-labelledby":W,"aria-disabled":i||void 0,"aria-required":F||void 0,"aria-invalid":y||void 0,"aria-describedby":U,"aria-errormessage":_?b:void 0,tabIndex:te,className:e.styles[e.staticDateFieldClassNames.field],onMouseDown:ne,onFocus:re,children:a.jsx(r.DateFieldSegments,{segmentText:X,segmentValues:m,focusedSegment:p,disabled:i,readOnly:t,onSegmentFocus:x,onSegmentBlur:de,onSegmentInput:Fe,onSegmentKeyDown:ue,registerSegmentRef:Q})}),a.jsx("input",{type:"hidden",name:c,value:Se.toISODateString(g),disabled:i}),a.jsxs(ve.HelperTextProvider,{ctxId:k,ctxDisabled:i,children:[n,_&&a.jsx(pe.HelperText,{id:b,appearance:"negative",children:o})]}),z(A)]})});exports.DateField=Ve;
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
import { jsxs as S, jsx as l } from "react/jsx-runtime";
|
|
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
|
|
2
|
+
import De from "clsx";
|
|
3
|
+
import { forwardRef as Fe } from "react";
|
|
4
|
+
import { s as a, b as he, c as s, a as xe } from "../../../chunks/DateField.Segment.C2qoaY0Z.js";
|
|
5
|
+
import { t as ye } from "../../../chunks/constants.Cruz2A1w.js";
|
|
6
|
+
import { H as Se } from "../../../chunks/form.context.cEuTL68U.js";
|
|
7
|
+
import { LabelProvider as Ie } from "../../Form/contexts/label.context.es.js";
|
|
8
|
+
import { HelperTextProvider as we } from "../../Form/contexts/helperText.context.es.js";
|
|
9
|
+
import { useUniversalRef as Re } from "../../Form/hooks/useUniversalRef.hook.es.js";
|
|
10
|
+
import { DateFieldSegments as Ne, PARTS_ORDER as I } from "./DateField.Segments.es.js";
|
|
11
|
+
import { toISODateString as Ve } from "./DateField.utils.es.js";
|
|
12
|
+
import { useDateFieldFocus as Be } from "./useDateFieldFocus.es.js";
|
|
13
|
+
import { useDateFieldForm as Ce } from "./useDateFieldForm.es.js";
|
|
14
|
+
import { useDateFieldKeyboard as Oe } from "./useDateFieldKeyboard.es.js";
|
|
15
|
+
import { useDateFieldSegments as Pe } from "./useDateFieldSegments.es.js";
|
|
16
|
+
import { useDateFieldValidity as Te } from "./useDateFieldValidity.es.js";
|
|
17
|
+
import { useDateFieldValue as Me } from "./useDateFieldValue.es.js";
|
|
18
|
+
import { useInvalidState as qe } from "./useInvalidState.es.js";
|
|
19
|
+
const aa = Fe(
|
|
20
20
|
function({
|
|
21
21
|
value: w,
|
|
22
22
|
defaultValue: R,
|
|
23
23
|
onChange: N,
|
|
24
|
-
label:
|
|
25
|
-
helperText:
|
|
24
|
+
label: t = null,
|
|
25
|
+
helperText: o = null,
|
|
26
26
|
error: n,
|
|
27
27
|
hideRequiredMarker: V = !1,
|
|
28
28
|
validationRules: B,
|
|
@@ -34,9 +34,9 @@ const Ze = ve(
|
|
|
34
34
|
required: M = !1,
|
|
35
35
|
name: u,
|
|
36
36
|
id: q,
|
|
37
|
-
className:
|
|
38
|
-
style:
|
|
39
|
-
"aria-label":
|
|
37
|
+
className: L,
|
|
38
|
+
style: E,
|
|
39
|
+
"aria-label": H,
|
|
40
40
|
"aria-describedby": $,
|
|
41
41
|
"aria-labelledby": j,
|
|
42
42
|
...K
|
|
@@ -55,92 +55,96 @@ const Ze = ve(
|
|
|
55
55
|
ariaDescribedBy: z,
|
|
56
56
|
ariaLabelledBy: G,
|
|
57
57
|
showErrors: J
|
|
58
|
-
} =
|
|
58
|
+
} = Ce({
|
|
59
59
|
name: u,
|
|
60
60
|
disabled: P,
|
|
61
61
|
readOnly: T,
|
|
62
62
|
required: M,
|
|
63
63
|
defaultValue: R,
|
|
64
64
|
error: n,
|
|
65
|
-
hasHelperText: !!
|
|
66
|
-
hasLabel: !!
|
|
65
|
+
hasHelperText: !!o,
|
|
66
|
+
hasLabel: !!t,
|
|
67
67
|
validationRules: B,
|
|
68
68
|
ariaDescribedBy: $,
|
|
69
69
|
ariaLabelledBy: j
|
|
70
|
-
}), { refFn: Q, ref: g } =
|
|
70
|
+
}), { refFn: Q, ref: g } = Re(W), { segmentRefs: X, registerSegmentRef: Y } = Pe(), {
|
|
71
71
|
segmentText: Z,
|
|
72
72
|
segmentValues: v,
|
|
73
73
|
currentValue: D,
|
|
74
74
|
wasTouched: ee,
|
|
75
75
|
appendDigit: ae,
|
|
76
76
|
adjustSegment: re,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
77
|
+
deleteLastDigit: le,
|
|
78
|
+
clearSegment: ie,
|
|
79
|
+
beginSegmentEdit: se,
|
|
80
|
+
commitOnBlur: de
|
|
81
|
+
} = Me({
|
|
80
82
|
value: w,
|
|
81
83
|
defaultValue: U,
|
|
82
84
|
onChange: N
|
|
83
85
|
}), {
|
|
84
86
|
focusedSegment: F,
|
|
85
|
-
fieldTabIndex:
|
|
87
|
+
fieldTabIndex: te,
|
|
86
88
|
handleSegmentFocus: h,
|
|
87
|
-
handleFieldFocus:
|
|
88
|
-
handleFieldBlur:
|
|
89
|
-
handleFieldMouseDown:
|
|
89
|
+
handleFieldFocus: oe,
|
|
90
|
+
handleFieldBlur: ne,
|
|
91
|
+
handleFieldMouseDown: me,
|
|
90
92
|
focusNext: x,
|
|
91
|
-
focusPrevious:
|
|
92
|
-
} =
|
|
93
|
+
focusPrevious: ue
|
|
94
|
+
} = Be({
|
|
93
95
|
disabled: e,
|
|
94
96
|
fieldRef: g,
|
|
95
97
|
segmentRefs: X,
|
|
96
98
|
partsOrder: I,
|
|
97
|
-
onSegmentFocusChange:
|
|
98
|
-
onFieldBlur:
|
|
99
|
-
}),
|
|
99
|
+
onSegmentFocusChange: se,
|
|
100
|
+
onFieldBlur: de
|
|
101
|
+
}), fe = Oe({
|
|
100
102
|
disabled: e,
|
|
101
103
|
readOnly: d,
|
|
102
104
|
fieldRef: g,
|
|
103
105
|
focusNext: x,
|
|
104
|
-
focusPrevious:
|
|
105
|
-
adjustSegment: re
|
|
106
|
-
|
|
106
|
+
focusPrevious: ue,
|
|
107
|
+
adjustSegment: re,
|
|
108
|
+
deleteLastDigit: le,
|
|
109
|
+
clearSegment: ie
|
|
110
|
+
}), { isInvalid: ce } = Te({
|
|
107
111
|
segments: v,
|
|
108
112
|
currentValue: D,
|
|
109
113
|
wasTouched: ee,
|
|
110
114
|
isFocused: F !== null
|
|
111
|
-
}),
|
|
112
|
-
const { advanced:
|
|
113
|
-
|
|
114
|
-
}, y =
|
|
115
|
+
}), pe = (r, i) => {
|
|
116
|
+
const { advanced: ve } = ae(r, i);
|
|
117
|
+
ve && x(r);
|
|
118
|
+
}, y = qe({
|
|
115
119
|
formInvalid: A,
|
|
116
|
-
valueInvalid:
|
|
117
|
-
}),
|
|
120
|
+
valueInvalid: ce
|
|
121
|
+
}), be = (r) => {
|
|
118
122
|
if (e) return;
|
|
119
123
|
const i = r.target.closest("label");
|
|
120
124
|
!i || i.id !== b || (r.preventDefault(), h(I[0]));
|
|
121
|
-
},
|
|
122
|
-
a[
|
|
123
|
-
m &&
|
|
125
|
+
}, ge = De(
|
|
126
|
+
a[he],
|
|
127
|
+
m && ye(m),
|
|
124
128
|
O && a[`${s}fluid`],
|
|
125
129
|
y && a[`${s}error`],
|
|
126
130
|
e && a[`${s}disabled`],
|
|
127
131
|
d && a[`${s}read-only`],
|
|
128
|
-
|
|
132
|
+
L
|
|
129
133
|
);
|
|
130
134
|
return /* @__PURE__ */ S(
|
|
131
135
|
"div",
|
|
132
136
|
{
|
|
133
|
-
className:
|
|
134
|
-
style: { ...
|
|
135
|
-
onMouseDownCapture:
|
|
137
|
+
className: ge,
|
|
138
|
+
style: { ...E, maxWidth: C },
|
|
139
|
+
onMouseDownCapture: be,
|
|
136
140
|
children: [
|
|
137
141
|
/* @__PURE__ */ l(
|
|
138
|
-
|
|
142
|
+
Ie,
|
|
139
143
|
{
|
|
140
144
|
ctxId: b,
|
|
141
145
|
ctxDisabled: e,
|
|
142
146
|
ctxRequired: f && !V,
|
|
143
|
-
children:
|
|
147
|
+
children: t
|
|
144
148
|
}
|
|
145
149
|
),
|
|
146
150
|
/* @__PURE__ */ l(
|
|
@@ -150,19 +154,19 @@ const Ze = ve(
|
|
|
150
154
|
ref: Q,
|
|
151
155
|
id: q,
|
|
152
156
|
role: "group",
|
|
153
|
-
"aria-label":
|
|
157
|
+
"aria-label": H,
|
|
154
158
|
"aria-labelledby": G,
|
|
155
159
|
"aria-disabled": e || void 0,
|
|
156
160
|
"aria-required": f || void 0,
|
|
157
161
|
"aria-invalid": y || void 0,
|
|
158
162
|
"aria-describedby": z,
|
|
159
163
|
"aria-errormessage": c ? p : void 0,
|
|
160
|
-
tabIndex:
|
|
161
|
-
className: a[
|
|
162
|
-
onMouseDown:
|
|
163
|
-
onFocus:
|
|
164
|
+
tabIndex: te,
|
|
165
|
+
className: a[xe.field],
|
|
166
|
+
onMouseDown: me,
|
|
167
|
+
onFocus: oe,
|
|
164
168
|
children: /* @__PURE__ */ l(
|
|
165
|
-
|
|
169
|
+
Ne,
|
|
166
170
|
{
|
|
167
171
|
segmentText: Z,
|
|
168
172
|
segmentValues: v,
|
|
@@ -170,9 +174,9 @@ const Ze = ve(
|
|
|
170
174
|
disabled: e,
|
|
171
175
|
readOnly: d,
|
|
172
176
|
onSegmentFocus: h,
|
|
173
|
-
onSegmentBlur:
|
|
174
|
-
onSegmentInput:
|
|
175
|
-
onSegmentKeyDown:
|
|
177
|
+
onSegmentBlur: ne,
|
|
178
|
+
onSegmentInput: pe,
|
|
179
|
+
onSegmentKeyDown: fe,
|
|
176
180
|
registerSegmentRef: Y
|
|
177
181
|
}
|
|
178
182
|
)
|
|
@@ -183,13 +187,13 @@ const Ze = ve(
|
|
|
183
187
|
{
|
|
184
188
|
type: "hidden",
|
|
185
189
|
name: u,
|
|
186
|
-
value:
|
|
190
|
+
value: Ve(D),
|
|
187
191
|
disabled: e
|
|
188
192
|
}
|
|
189
193
|
),
|
|
190
|
-
/* @__PURE__ */ S(
|
|
191
|
-
|
|
192
|
-
c && /* @__PURE__ */ l(
|
|
194
|
+
/* @__PURE__ */ S(we, { ctxId: _, ctxDisabled: e, children: [
|
|
195
|
+
o,
|
|
196
|
+
c && /* @__PURE__ */ l(Se, { id: p, appearance: "negative", children: n })
|
|
193
197
|
] }),
|
|
194
198
|
J(k)
|
|
195
199
|
]
|
|
@@ -198,5 +202,5 @@ const Ze = ve(
|
|
|
198
202
|
}
|
|
199
203
|
);
|
|
200
204
|
export {
|
|
201
|
-
|
|
205
|
+
aa as DateField
|
|
202
206
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react");function d({disabled:c,readOnly:u,fieldRef:a,focusNext:o,focusPrevious:n,adjustSegment:t,deleteLastDigit:y,clearSegment:p}){const w=b.useMemo(()=>{const i={ArrowRight:({segment:r,isRTL:e})=>((e?n:o)(r),!0),ArrowLeft:({segment:r,isRTL:e})=>((e?o:n)(r),!0)};return u?i:{...i,ArrowUp:({segment:r})=>t(r,1),ArrowDown:({segment:r})=>t(r,-1),PageUp:({segment:r})=>t(r,5),PageDown:({segment:r})=>t(r,-5),Home:({segment:r})=>t(r,"min"),End:({segment:r})=>t(r,"max"),Backspace:({segment:r})=>(y(r).wasEmpty&&n(r),!0),Delete:({segment:r})=>(p(r),!0)}},[t,p,y,o,n,u]);return b.useCallback((i,r)=>{if(c||r.altKey||r.ctrlKey||r.metaKey||r.shiftKey)return;const e=w[r.key];if(!e)return;const l=a.current,K=!!l&&(getComputedStyle(l).direction==="rtl"||!!l.closest('[dir="rtl"]'));e({segment:i,event:r,isRTL:K})&&r.preventDefault()},[c,w,a])}exports.useDateFieldKeyboard=d;
|
|
@@ -40,5 +40,19 @@ export interface UseDateFieldKeyboardArgs {
|
|
|
40
40
|
* dispatcher leaves the key to native page scroll.
|
|
41
41
|
*/
|
|
42
42
|
adjustSegment: (type: SegmentType, amount: SegmentAdjustment) => boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Removes the last raw digit from the segment buffer (Backspace).
|
|
45
|
+
* Returns `{ wasEmpty: true }` when the buffer was already empty, signalling
|
|
46
|
+
* the keyboard handler to move focus to the previous segment.
|
|
47
|
+
* Provided by `useDateFieldValue`.
|
|
48
|
+
*/
|
|
49
|
+
deleteLastDigit: (type: SegmentType) => {
|
|
50
|
+
wasEmpty: boolean;
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Clears the entire segment buffer to `''` (Delete). Focus stays on the
|
|
54
|
+
* current segment. Provided by `useDateFieldValue`.
|
|
55
|
+
*/
|
|
56
|
+
clearSegment: (type: SegmentType) => void;
|
|
43
57
|
}
|
|
44
|
-
export declare function useDateFieldKeyboard({ disabled, readOnly, fieldRef, focusNext, focusPrevious, adjustSegment, }: UseDateFieldKeyboardArgs): (segment: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
|
|
58
|
+
export declare function useDateFieldKeyboard({ disabled, readOnly, fieldRef, focusNext, focusPrevious, adjustSegment, deleteLastDigit, clearSegment, }: UseDateFieldKeyboardArgs): (segment: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
|
|
@@ -1,45 +1,49 @@
|
|
|
1
|
-
import { useMemo as
|
|
2
|
-
function
|
|
3
|
-
disabled:
|
|
4
|
-
readOnly:
|
|
5
|
-
fieldRef:
|
|
6
|
-
focusNext:
|
|
7
|
-
focusPrevious:
|
|
8
|
-
adjustSegment:
|
|
1
|
+
import { useMemo as f, useCallback as h } from "react";
|
|
2
|
+
function b({
|
|
3
|
+
disabled: p,
|
|
4
|
+
readOnly: e,
|
|
5
|
+
fieldRef: u,
|
|
6
|
+
focusNext: l,
|
|
7
|
+
focusPrevious: i,
|
|
8
|
+
adjustSegment: n,
|
|
9
|
+
deleteLastDigit: w,
|
|
10
|
+
clearSegment: y
|
|
9
11
|
}) {
|
|
10
|
-
const
|
|
12
|
+
const a = f(
|
|
11
13
|
() => {
|
|
12
14
|
const o = {
|
|
13
15
|
// Nav keys always own the event (arrows are contentEditable caret keys we
|
|
14
16
|
// suppress even at the first/last segment), so they always report handled.
|
|
15
|
-
ArrowRight: ({ segment: r, isRTL:
|
|
16
|
-
ArrowLeft: ({ segment: r, isRTL:
|
|
17
|
+
ArrowRight: ({ segment: r, isRTL: t }) => ((t ? i : l)(r), !0),
|
|
18
|
+
ArrowLeft: ({ segment: r, isRTL: t }) => ((t ? l : i)(r), !0)
|
|
17
19
|
};
|
|
18
|
-
return
|
|
20
|
+
return e ? o : {
|
|
19
21
|
...o,
|
|
20
|
-
ArrowUp: ({ segment: r }) =>
|
|
21
|
-
ArrowDown: ({ segment: r }) =>
|
|
22
|
-
PageUp: ({ segment: r }) =>
|
|
23
|
-
PageDown: ({ segment: r }) =>
|
|
24
|
-
Home: ({ segment: r }) =>
|
|
25
|
-
End: ({ segment: r }) =>
|
|
26
|
-
//
|
|
27
|
-
//
|
|
22
|
+
ArrowUp: ({ segment: r }) => n(r, 1),
|
|
23
|
+
ArrowDown: ({ segment: r }) => n(r, -1),
|
|
24
|
+
PageUp: ({ segment: r }) => n(r, 5),
|
|
25
|
+
PageDown: ({ segment: r }) => n(r, -5),
|
|
26
|
+
Home: ({ segment: r }) => n(r, "min"),
|
|
27
|
+
End: ({ segment: r }) => n(r, "max"),
|
|
28
|
+
// DF-5: Backspace removes the last digit (empty → focus previous); Delete clears the segment.
|
|
29
|
+
// Both always own the key (delete or focus-hop), so they report handled.
|
|
30
|
+
Backspace: ({ segment: r }) => (w(r).wasEmpty && i(r), !0),
|
|
31
|
+
Delete: ({ segment: r }) => (y(r), !0)
|
|
28
32
|
};
|
|
29
33
|
},
|
|
30
|
-
[
|
|
34
|
+
[n, y, w, l, i, e]
|
|
31
35
|
);
|
|
32
|
-
return
|
|
36
|
+
return h(
|
|
33
37
|
(o, r) => {
|
|
34
|
-
if (
|
|
35
|
-
const
|
|
36
|
-
if (!
|
|
37
|
-
const c =
|
|
38
|
-
|
|
38
|
+
if (p || r.altKey || r.ctrlKey || r.metaKey || r.shiftKey) return;
|
|
39
|
+
const t = a[r.key];
|
|
40
|
+
if (!t) return;
|
|
41
|
+
const c = u.current, K = !!c && (getComputedStyle(c).direction === "rtl" || !!c.closest('[dir="rtl"]'));
|
|
42
|
+
t({ segment: o, event: r, isRTL: K }) && r.preventDefault();
|
|
39
43
|
},
|
|
40
|
-
[
|
|
44
|
+
[p, a, u]
|
|
41
45
|
);
|
|
42
46
|
}
|
|
43
47
|
export {
|
|
44
|
-
|
|
48
|
+
b as useDateFieldKeyboard
|
|
45
49
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react"),r=require("./DateField.utils.cjs.js"),E=require("./DateField.validation.cjs.js");function M({value:l,defaultValue:F,onChange:g}){const T=t.useRef(l!==void 0),b=T.current,[i,S]=t.useState(()=>r.segmentTextFromValue(b?l??null:F??null)),[_,h]=t.useState(!1),c=t.useRef(i),d=t.useRef(new Set),o=t.useRef(!1),y={day:r.segmentNumber("day",i.day),month:r.segmentNumber("month",i.month),year:r.segmentNumber("year",i.year)},D=r.deriveValue(y),x=t.useRef(D),R=t.useRef(b?l??null:null),m=t.useRef(g);t.useEffect(()=>{m.current=g},[g]),t.useEffect(()=>{if(!T.current||o.current||r.isSameDateValue(l??null,R.current))return;R.current=l??null;const e=r.segmentTextFromValue(l??null);c.current=e,S(e),x.current=r.deriveValueFromText(e)},[l]);const f=t.useCallback(e=>{var u;const n=r.deriveValueFromText(e);r.isSameDateValue(n,x.current)||(x.current=n,(u=m.current)==null||u.call(m,n))},[]),a=t.useCallback((e,n,{replace:u})=>{const s={...c.current,[e]:n};c.current=s,S(s),h(!0),f(s),u?d.current.add(e):d.current.delete(e)},[f]),N=t.useCallback((e,n)=>{const u=d.current.has(e)?"":c.current[e],s=E.tryAppendDigit(e,u,n);return s.rejected?{advanced:!1,rejected:!0}:(a(e,s.newBuffer,{replace:s.shouldAdvance}),{advanced:s.shouldAdvance,rejected:!1})},[a]),k=t.useCallback((e,n)=>{const u=c.current,s=r.segmentNumber(e,u[e]),p=r.getDaysInMonth(r.segmentNumber("year",u.year),r.segmentNumber("month",u.month)),V=r.adjustSegmentValue(e,s,n,{daysInMonth:p,today:r.todayParts()});return V==null?!1:(o.current=!0,a(e,String(V).padStart(E.SEGMENT_MAX_LENGTH[e],"0"),{replace:!0}),!0)},[a]),C=t.useCallback(e=>{const n=c.current[e];return n===""?{wasEmpty:!0}:(o.current=!0,a(e,n.slice(0,-1),{replace:!1}),{wasEmpty:!1})},[a]),v=t.useCallback(e=>{c.current[e]!==""&&(o.current=!0,a(e,"",{replace:!1}))},[a]),w=t.useCallback(e=>{o.current=!0,d.current.add(e)},[]),j=t.useCallback(()=>{o.current=!1;const e=c.current,n={day:r.normalizeSegmentText("day",e.day),month:r.normalizeSegmentText("month",e.month),year:r.normalizeSegmentText("year",e.year)};c.current=n,S(n),h(!0),f(n)},[f]);return{segmentText:i,segmentValues:y,currentValue:D,isControlled:b,wasTouched:_,appendDigit:N,adjustSegment:k,deleteLastDigit:C,clearSegment:v,beginSegmentEdit:w,commitOnBlur:j}}exports.useDateFieldValue=M;
|
|
@@ -32,6 +32,25 @@ export interface UseDateFieldValueReturn {
|
|
|
32
32
|
* the key to native (e.g. page scroll).
|
|
33
33
|
*/
|
|
34
34
|
adjustSegment: (type: SegmentType, amount: SegmentAdjustment) => boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Removes the last raw digit from the segment buffer (Backspace behaviour).
|
|
37
|
+
*
|
|
38
|
+
* Returns `{ wasEmpty: true }` when the buffer was already empty so the
|
|
39
|
+
* caller (keyboard handler) knows to move focus to the previous segment.
|
|
40
|
+
* Clears `replaceNextRef` for the segment so a digit typed immediately after
|
|
41
|
+
* appends rather than replaces.
|
|
42
|
+
*/
|
|
43
|
+
deleteLastDigit: (type: SegmentType) => {
|
|
44
|
+
wasEmpty: boolean;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Clears the entire segment buffer to `''` (Delete behaviour).
|
|
48
|
+
*
|
|
49
|
+
* Focus stays on the current segment. Fires `onChange(null)` via
|
|
50
|
+
* `emitIfChanged` when the cleared segment was part of a complete date.
|
|
51
|
+
* Clears `replaceNextRef` for the segment so the next digit appends.
|
|
52
|
+
*/
|
|
53
|
+
clearSegment: (type: SegmentType) => void;
|
|
35
54
|
beginSegmentEdit: (type: SegmentType) => void;
|
|
36
55
|
commitOnBlur: () => void;
|
|
37
56
|
}
|
|
@@ -1,78 +1,96 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { segmentTextFromValue as v, segmentNumber as
|
|
3
|
-
import { tryAppendDigit as
|
|
4
|
-
function
|
|
5
|
-
value:
|
|
6
|
-
defaultValue:
|
|
7
|
-
onChange:
|
|
1
|
+
import { useRef as o, useState as w, useEffect as b, useCallback as s } from "react";
|
|
2
|
+
import { segmentTextFromValue as v, segmentNumber as d, deriveValue as C, isSameDateValue as A, deriveValueFromText as M, getDaysInMonth as H, adjustSegmentValue as O, todayParts as P, normalizeSegmentText as T } from "./DateField.utils.es.js";
|
|
3
|
+
import { tryAppendDigit as W, SEGMENT_MAX_LENGTH as X } from "./DateField.validation.es.js";
|
|
4
|
+
function Q({
|
|
5
|
+
value: a,
|
|
6
|
+
defaultValue: N,
|
|
7
|
+
onChange: x
|
|
8
8
|
}) {
|
|
9
|
-
const
|
|
10
|
-
() => v(
|
|
11
|
-
), [
|
|
12
|
-
day:
|
|
13
|
-
month:
|
|
14
|
-
year:
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
),
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}, [
|
|
21
|
-
if (!
|
|
22
|
-
|
|
23
|
-
const e = v(
|
|
24
|
-
|
|
25
|
-
}, [
|
|
26
|
-
const
|
|
27
|
-
var
|
|
28
|
-
const t =
|
|
29
|
-
|
|
30
|
-
}, []),
|
|
9
|
+
const E = o(a !== void 0), h = E.current, [i, S] = w(
|
|
10
|
+
() => v(h ? a ?? null : N ?? null)
|
|
11
|
+
), [F, V] = w(!1), c = o(i), m = o(/* @__PURE__ */ new Set()), l = o(!1), p = {
|
|
12
|
+
day: d("day", i.day),
|
|
13
|
+
month: d("month", i.month),
|
|
14
|
+
year: d("year", i.year)
|
|
15
|
+
}, D = C(p), y = o(D), R = o(
|
|
16
|
+
h ? a ?? null : null
|
|
17
|
+
), f = o(x);
|
|
18
|
+
b(() => {
|
|
19
|
+
f.current = x;
|
|
20
|
+
}, [x]), b(() => {
|
|
21
|
+
if (!E.current || l.current || A(a ?? null, R.current)) return;
|
|
22
|
+
R.current = a ?? null;
|
|
23
|
+
const e = v(a ?? null);
|
|
24
|
+
c.current = e, S(e), y.current = M(e);
|
|
25
|
+
}, [a]);
|
|
26
|
+
const g = s((e) => {
|
|
27
|
+
var r;
|
|
28
|
+
const t = M(e);
|
|
29
|
+
A(t, y.current) || (y.current = t, (r = f.current) == null || r.call(f, t));
|
|
30
|
+
}, []), u = s(
|
|
31
|
+
(e, t, { replace: r }) => {
|
|
32
|
+
const n = { ...c.current, [e]: t };
|
|
33
|
+
c.current = n, S(n), V(!0), g(n), r ? m.current.add(e) : m.current.delete(e);
|
|
34
|
+
},
|
|
35
|
+
[g]
|
|
36
|
+
), I = s(
|
|
31
37
|
(e, t) => {
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
const m = { ...r.current, [e]: o.newBuffer };
|
|
35
|
-
return r.current = m, f(m), T(!0), s(m), o.shouldAdvance ? l.current.add(e) : l.current.delete(e), { advanced: o.shouldAdvance, rejected: !1 };
|
|
38
|
+
const r = m.current.has(e) ? "" : c.current[e], n = W(e, r, t);
|
|
39
|
+
return n.rejected ? { advanced: !1, rejected: !0 } : (u(e, n.newBuffer, { replace: n.shouldAdvance }), { advanced: n.shouldAdvance, rejected: !1 });
|
|
36
40
|
},
|
|
37
|
-
[
|
|
38
|
-
),
|
|
41
|
+
[u]
|
|
42
|
+
), B = s(
|
|
39
43
|
(e, t) => {
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
),
|
|
44
|
-
daysInMonth:
|
|
45
|
-
today:
|
|
44
|
+
const r = c.current, n = d(e, r[e]), z = H(
|
|
45
|
+
d("year", r.year),
|
|
46
|
+
d("month", r.month)
|
|
47
|
+
), j = O(e, n, t, {
|
|
48
|
+
daysInMonth: z,
|
|
49
|
+
today: P()
|
|
46
50
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
return j == null ? !1 : (l.current = !0, u(
|
|
52
|
+
e,
|
|
53
|
+
String(j).padStart(X[e], "0"),
|
|
54
|
+
{ replace: !0 }
|
|
55
|
+
), !0);
|
|
56
|
+
},
|
|
57
|
+
[u]
|
|
58
|
+
), G = s(
|
|
59
|
+
(e) => {
|
|
60
|
+
const t = c.current[e];
|
|
61
|
+
return t === "" ? { wasEmpty: !0 } : (l.current = !0, u(e, t.slice(0, -1), { replace: !1 }), { wasEmpty: !1 });
|
|
62
|
+
},
|
|
63
|
+
[u]
|
|
64
|
+
), L = s(
|
|
65
|
+
(e) => {
|
|
66
|
+
c.current[e] !== "" && (l.current = !0, u(e, "", { replace: !1 }));
|
|
51
67
|
},
|
|
52
|
-
[
|
|
53
|
-
),
|
|
54
|
-
|
|
55
|
-
}, []),
|
|
56
|
-
|
|
57
|
-
const e =
|
|
58
|
-
day:
|
|
59
|
-
month:
|
|
60
|
-
year:
|
|
68
|
+
[u]
|
|
69
|
+
), _ = s((e) => {
|
|
70
|
+
l.current = !0, m.current.add(e);
|
|
71
|
+
}, []), k = s(() => {
|
|
72
|
+
l.current = !1;
|
|
73
|
+
const e = c.current, t = {
|
|
74
|
+
day: T("day", e.day),
|
|
75
|
+
month: T("month", e.month),
|
|
76
|
+
year: T("year", e.year)
|
|
61
77
|
};
|
|
62
|
-
|
|
63
|
-
}, [
|
|
78
|
+
c.current = t, S(t), V(!0), g(t);
|
|
79
|
+
}, [g]);
|
|
64
80
|
return {
|
|
65
|
-
segmentText:
|
|
66
|
-
segmentValues:
|
|
67
|
-
currentValue:
|
|
68
|
-
isControlled:
|
|
69
|
-
wasTouched:
|
|
70
|
-
appendDigit:
|
|
71
|
-
adjustSegment:
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
segmentText: i,
|
|
82
|
+
segmentValues: p,
|
|
83
|
+
currentValue: D,
|
|
84
|
+
isControlled: h,
|
|
85
|
+
wasTouched: F,
|
|
86
|
+
appendDigit: I,
|
|
87
|
+
adjustSegment: B,
|
|
88
|
+
deleteLastDigit: G,
|
|
89
|
+
clearSegment: L,
|
|
90
|
+
beginSegmentEdit: _,
|
|
91
|
+
commitOnBlur: k
|
|
74
92
|
};
|
|
75
93
|
}
|
|
76
94
|
export {
|
|
77
|
-
|
|
95
|
+
Q as useDateFieldValue
|
|
78
96
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viasat/beam-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.42.0",
|
|
4
4
|
"description": "React component library for the Beam design system",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Viasat",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
"access": "public"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@viasat/beam-fonts": "2.
|
|
63
|
-
"@viasat/beam-shared": "2.
|
|
64
|
-
"@viasat/beam-styles": "2.
|
|
65
|
-
"@viasat/beam-tokens": "2.
|
|
66
|
-
"@viasat/beam-icons": "2.
|
|
62
|
+
"@viasat/beam-fonts": "2.42.0",
|
|
63
|
+
"@viasat/beam-shared": "2.42.0",
|
|
64
|
+
"@viasat/beam-styles": "2.42.0",
|
|
65
|
+
"@viasat/beam-tokens": "2.42.0",
|
|
66
|
+
"@viasat/beam-icons": "2.42.0",
|
|
67
67
|
"clsx": "^1.2.1",
|
|
68
68
|
"@floating-ui/react": "^0.26.18",
|
|
69
69
|
"@stepperize/react": "^5.1.5",
|