@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.
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),be=require("clsx"),De=require("react"),e=require("../../../chunks/DateField.Segment.CY0jg03_.js"),fe=require("../../../chunks/constants.CgMu0_1M.js"),me=require("../../../chunks/form.context.D5XrYvpI.js"),pe=require("../../Form/contexts/label.context.cjs.js"),xe=require("../../Form/contexts/helperText.context.cjs.js"),ge=require("../../Form/hooks/useUniversalRef.hook.cjs.js"),r=require("./DateField.Segments.cjs.js"),ve=require("./DateField.utils.cjs.js"),ye=require("./useDateFieldFocus.cjs.js"),Se=require("./useDateFieldForm.cjs.js"),qe=require("./useDateFieldKeyboard.cjs.js"),he=require("./useDateFieldSegments.cjs.js"),we=require("./useDateFieldValidity.cjs.js"),Ie=require("./useDateFieldValue.cjs.js"),Re=require("./useInvalidState.cjs.js"),Pe=De.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},K){const{disabled:i,readOnly:t,required:F,invalid:L,errorMessageProvided:_,defaultValue:$,errorId:b,helperTextId:k,validationErrorsId:A,labelId:D,ariaDescribedBy:U,ariaLabelledBy:W,showErrors:z}=Se.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}=ge.useUniversalRef(K),{segmentRefs:J,registerSegmentRef:Q}=he.useDateFieldSegments(),{segmentText:X,segmentValues:m,currentValue:p,wasTouched:Y,appendDigit:Z,adjustSegment:ee,beginSegmentEdit:ie,commitOnBlur:ae}=Ie.useDateFieldValue({value:S,defaultValue:$,onChange:h}),{focusedSegment:x,fieldTabIndex:le,handleSegmentFocus:g,handleFieldFocus:se,handleFieldBlur:te,handleFieldMouseDown:re,focusNext:v,focusPrevious:de}=ye.useDateFieldFocus({disabled:i,fieldRef:f,segmentRefs:J,partsOrder:r.PARTS_ORDER,onSegmentFocusChange:ie,onFieldBlur:ae}),ne=qe.useDateFieldKeyboard({disabled:i,readOnly:t,fieldRef:f,focusNext:v,focusPrevious:de,adjustSegment:ee}),{isInvalid:oe}=we.useDateFieldValidity({segments:m,currentValue:p,wasTouched:Y,isFocused:x!==null}),ue=(l,s)=>{const{advanced:_e}=Z(l,s);_e&&v(l)},y=Re.useInvalidState({formInvalid:L,valueInvalid:oe}),ce=l=>{if(i)return;const s=l.target.closest("label");!s||s.id!==D||(l.preventDefault(),g(r.PARTS_ORDER[0]))},Fe=be(e.styles[e.baseClassNamePrefix],u&&fe.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:Fe,style:{...O,maxWidth:R},onMouseDownCapture:ce,children:[a.jsx(pe.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:le,className:e.styles[e.staticDateFieldClassNames.field],onMouseDown:re,onFocus:se,children:a.jsx(r.DateFieldSegments,{segmentText:X,segmentValues:m,focusedSegment:x,disabled:i,readOnly:t,onSegmentFocus:g,onSegmentBlur:te,onSegmentInput:ue,onSegmentKeyDown:ne,registerSegmentRef:Q})}),a.jsx("input",{type:"hidden",name:c,value:ve.toISODateString(p),disabled:i}),a.jsxs(xe.HelperTextProvider,{ctxId:k,ctxDisabled:i,children:[n,_&&a.jsx(me.HelperText,{id:b,appearance:"negative",children:o})]}),z(A)]})});exports.DateField=Pe;
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 ge from "clsx";
3
- import { forwardRef as ve } from "react";
4
- import { s as a, b as De, c as s, a as Fe } from "../../../chunks/DateField.Segment.C2qoaY0Z.js";
5
- import { t as he } from "../../../chunks/constants.Cruz2A1w.js";
6
- import { H as xe } from "../../../chunks/form.context.cEuTL68U.js";
7
- import { LabelProvider as ye } from "../../Form/contexts/label.context.es.js";
8
- import { HelperTextProvider as Se } from "../../Form/contexts/helperText.context.es.js";
9
- import { useUniversalRef as Ie } from "../../Form/hooks/useUniversalRef.hook.es.js";
10
- import { DateFieldSegments as we, PARTS_ORDER as I } from "./DateField.Segments.es.js";
11
- import { toISODateString as Re } from "./DateField.utils.es.js";
12
- import { useDateFieldFocus as Ne } from "./useDateFieldFocus.es.js";
13
- import { useDateFieldForm as Ve } from "./useDateFieldForm.es.js";
14
- import { useDateFieldKeyboard as Be } from "./useDateFieldKeyboard.es.js";
15
- import { useDateFieldSegments as Ce } from "./useDateFieldSegments.es.js";
16
- import { useDateFieldValidity as Oe } from "./useDateFieldValidity.es.js";
17
- import { useDateFieldValue as Pe } from "./useDateFieldValue.es.js";
18
- import { useInvalidState as Te } from "./useInvalidState.es.js";
19
- const Ze = ve(
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: o = null,
25
- helperText: t = null,
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: E,
38
- style: H,
39
- "aria-label": L,
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
- } = Ve({
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: !!t,
66
- hasLabel: !!o,
65
+ hasHelperText: !!o,
66
+ hasLabel: !!t,
67
67
  validationRules: B,
68
68
  ariaDescribedBy: $,
69
69
  ariaLabelledBy: j
70
- }), { refFn: Q, ref: g } = Ie(W), { segmentRefs: X, registerSegmentRef: Y } = Ce(), {
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
- beginSegmentEdit: le,
78
- commitOnBlur: ie
79
- } = Pe({
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: se,
87
+ fieldTabIndex: te,
86
88
  handleSegmentFocus: h,
87
- handleFieldFocus: de,
88
- handleFieldBlur: oe,
89
- handleFieldMouseDown: te,
89
+ handleFieldFocus: oe,
90
+ handleFieldBlur: ne,
91
+ handleFieldMouseDown: me,
90
92
  focusNext: x,
91
- focusPrevious: ne
92
- } = Ne({
93
+ focusPrevious: ue
94
+ } = Be({
93
95
  disabled: e,
94
96
  fieldRef: g,
95
97
  segmentRefs: X,
96
98
  partsOrder: I,
97
- onSegmentFocusChange: le,
98
- onFieldBlur: ie
99
- }), me = Be({
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: ne,
105
- adjustSegment: re
106
- }), { isInvalid: ue } = Oe({
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
- }), fe = (r, i) => {
112
- const { advanced: be } = ae(r, i);
113
- be && x(r);
114
- }, y = Te({
115
+ }), pe = (r, i) => {
116
+ const { advanced: ve } = ae(r, i);
117
+ ve && x(r);
118
+ }, y = qe({
115
119
  formInvalid: A,
116
- valueInvalid: ue
117
- }), ce = (r) => {
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
- }, pe = ge(
122
- a[De],
123
- m && he(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
- E
132
+ L
129
133
  );
130
134
  return /* @__PURE__ */ S(
131
135
  "div",
132
136
  {
133
- className: pe,
134
- style: { ...H, maxWidth: C },
135
- onMouseDownCapture: ce,
137
+ className: ge,
138
+ style: { ...E, maxWidth: C },
139
+ onMouseDownCapture: be,
136
140
  children: [
137
141
  /* @__PURE__ */ l(
138
- ye,
142
+ Ie,
139
143
  {
140
144
  ctxId: b,
141
145
  ctxDisabled: e,
142
146
  ctxRequired: f && !V,
143
- children: o
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": L,
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: se,
161
- className: a[Fe.field],
162
- onMouseDown: te,
163
- onFocus: de,
164
+ tabIndex: te,
165
+ className: a[xe.field],
166
+ onMouseDown: me,
167
+ onFocus: oe,
164
168
  children: /* @__PURE__ */ l(
165
- we,
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: oe,
174
- onSegmentInput: fe,
175
- onSegmentKeyDown: me,
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: Re(D),
190
+ value: Ve(D),
187
191
  disabled: e
188
192
  }
189
193
  ),
190
- /* @__PURE__ */ S(Se, { ctxId: _, ctxDisabled: e, children: [
191
- t,
192
- c && /* @__PURE__ */ l(xe, { id: p, appearance: "negative", children: n })
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
- Ze as DateField
205
+ aa as DateField
202
206
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react");function d({disabled:c,readOnly:a,fieldRef:u,focusNext:n,focusPrevious:o,adjustSegment:t}){const y=s.useMemo(()=>{const i={ArrowRight:({segment:r,isRTL:e})=>((e?o:n)(r),!0),ArrowLeft:({segment:r,isRTL:e})=>((e?n:o)(r),!0)};return a?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")}},[t,n,o,a]);return s.useCallback((i,r)=>{if(c||r.altKey||r.ctrlKey||r.metaKey||r.shiftKey)return;const e=y[r.key];if(!e)return;const l=u.current,b=!!l&&(getComputedStyle(l).direction==="rtl"||!!l.closest('[dir="rtl"]'));e({segment:i,event:r,isRTL:b})&&r.preventDefault()},[c,y,u])}exports.useDateFieldKeyboard=d;
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 u, useCallback as K } from "react";
2
- function A({
3
- disabled: e,
4
- readOnly: p,
5
- fieldRef: w,
6
- focusNext: t,
7
- focusPrevious: l,
8
- adjustSegment: i
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 y = u(
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: n }) => ((n ? l : t)(r), !0),
16
- ArrowLeft: ({ segment: r, isRTL: n }) => ((n ? t : l)(r), !0)
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 p ? o : {
20
+ return e ? o : {
19
21
  ...o,
20
- ArrowUp: ({ segment: r }) => i(r, 1),
21
- ArrowDown: ({ segment: r }) => i(r, -1),
22
- PageUp: ({ segment: r }) => i(r, 5),
23
- PageDown: ({ segment: r }) => i(r, -5),
24
- Home: ({ segment: r }) => i(r, "min"),
25
- End: ({ segment: r }) => i(r, "max")
26
- // ── Extension points ─────────────────────────────────────────────
27
- // DF-5: Backspace / Delete (clear segment) → value action
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
- [i, t, l, p]
34
+ [n, y, w, l, i, e]
31
35
  );
32
- return K(
36
+ return h(
33
37
  (o, r) => {
34
- if (e || r.altKey || r.ctrlKey || r.metaKey || r.shiftKey) return;
35
- const n = y[r.key];
36
- if (!n) return;
37
- const c = w.current, a = !!c && (getComputedStyle(c).direction === "rtl" || !!c.closest('[dir="rtl"]'));
38
- n({ segment: o, event: r, isRTL: a }) && r.preventDefault();
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
- [e, y, w]
44
+ [p, a, u]
41
45
  );
42
46
  }
43
47
  export {
44
- A as useDateFieldKeyboard
48
+ b as useDateFieldKeyboard
45
49
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react"),t=require("./DateField.utils.cjs.js"),_=require("./DateField.validation.cjs.js");function M({value:c,defaultValue:N,onChange:x}){const R=n.useRef(c!==void 0),S=R.current,[o,m]=n.useState(()=>t.segmentTextFromValue(S?c??null:N??null)),[E,b]=n.useState(!1),s=n.useRef(o),d=n.useRef(new Set),f=n.useRef(!1),V={day:t.segmentNumber("day",o.day),month:t.segmentNumber("month",o.month),year:t.segmentNumber("year",o.year)},y=t.deriveValue(V),T=n.useRef(y),D=n.useRef(S?c??null:null),g=n.useRef(x);n.useEffect(()=>{g.current=x},[x]),n.useEffect(()=>{if(!R.current||f.current||t.isSameDateValue(c??null,D.current))return;D.current=c??null;const e=t.segmentTextFromValue(c??null);s.current=e,m(e),T.current=t.deriveValueFromText(e)},[c]);const a=n.useCallback(e=>{var u;const r=t.deriveValueFromText(e);t.isSameDateValue(r,T.current)||(T.current=r,(u=g.current)==null||u.call(g,r))},[]),j=n.useCallback((e,r)=>{const u=d.current.has(e)?"":s.current[e],l=_.tryAppendDigit(e,u,r);if(l.rejected)return{advanced:!1,rejected:!0};const i={...s.current,[e]:l.newBuffer};return s.current=i,m(i),b(!0),a(i),l.shouldAdvance?d.current.add(e):d.current.delete(e),{advanced:l.shouldAdvance,rejected:!1}},[a]),v=n.useCallback((e,r)=>{const u=s.current,l=t.segmentNumber(e,u[e]),i=t.getDaysInMonth(t.segmentNumber("year",u.year),t.segmentNumber("month",u.month)),F=t.adjustSegmentValue(e,l,r,{daysInMonth:i,today:t.todayParts()});if(F==null)return!1;f.current=!0;const C=String(F).padStart(_.SEGMENT_MAX_LENGTH[e],"0"),h={...u,[e]:C};return s.current=h,m(h),b(!0),a(h),d.current.add(e),!0},[a]),k=n.useCallback(e=>{f.current=!0,d.current.add(e)},[]),w=n.useCallback(()=>{f.current=!1;const e=s.current,r={day:t.normalizeSegmentText("day",e.day),month:t.normalizeSegmentText("month",e.month),year:t.normalizeSegmentText("year",e.year)};s.current=r,m(r),b(!0),a(r)},[a]);return{segmentText:o,segmentValues:V,currentValue:y,isControlled:S,wasTouched:E,appendDigit:j,adjustSegment:v,beginSegmentEdit:k,commitOnBlur:w}}exports.useDateFieldValue=M;
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 u, useState as M, useEffect as N, useCallback as i } from "react";
2
- import { segmentTextFromValue as v, segmentNumber as a, deriveValue as C, isSameDateValue as w, deriveValueFromText as F, getDaysInMonth as H, adjustSegmentValue as L, todayParts as O, normalizeSegmentText as E } from "./DateField.utils.es.js";
3
- import { tryAppendDigit as P, SEGMENT_MAX_LENGTH as W } from "./DateField.validation.es.js";
4
- function K({
5
- value: c,
6
- defaultValue: I,
7
- onChange: h
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 D = u(c !== void 0), S = D.current, [d, f] = M(
10
- () => v(S ? c ?? null : I ?? null)
11
- ), [B, T] = M(!1), r = u(d), l = u(/* @__PURE__ */ new Set()), x = u(!1), R = {
12
- day: a("day", d.day),
13
- month: a("month", d.month),
14
- year: a("year", d.year)
15
- }, j = C(R), y = u(j), b = u(
16
- S ? c ?? null : null
17
- ), g = u(h);
18
- N(() => {
19
- g.current = h;
20
- }, [h]), N(() => {
21
- if (!D.current || x.current || w(c ?? null, b.current)) return;
22
- b.current = c ?? null;
23
- const e = v(c ?? null);
24
- r.current = e, f(e), y.current = F(e);
25
- }, [c]);
26
- const s = i((e) => {
27
- var n;
28
- const t = F(e);
29
- w(t, y.current) || (y.current = t, (n = g.current) == null || n.call(g, t));
30
- }, []), G = i(
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 n = l.current.has(e) ? "" : r.current[e], o = P(e, n, t);
33
- if (o.rejected) return { advanced: !1, rejected: !0 };
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
- [s]
38
- ), _ = i(
41
+ [u]
42
+ ), B = s(
39
43
  (e, t) => {
40
- const n = r.current, o = a(e, n[e]), m = H(
41
- a("year", n.year),
42
- a("month", n.month)
43
- ), A = L(e, o, t, {
44
- daysInMonth: m,
45
- today: O()
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
- if (A == null) return !1;
48
- x.current = !0;
49
- const z = String(A).padStart(W[e], "0"), V = { ...n, [e]: z };
50
- return r.current = V, f(V), T(!0), s(V), l.current.add(e), !0;
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
- [s]
53
- ), k = i((e) => {
54
- x.current = !0, l.current.add(e);
55
- }, []), p = i(() => {
56
- x.current = !1;
57
- const e = r.current, t = {
58
- day: E("day", e.day),
59
- month: E("month", e.month),
60
- year: E("year", e.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
- r.current = t, f(t), T(!0), s(t);
63
- }, [s]);
78
+ c.current = t, S(t), V(!0), g(t);
79
+ }, [g]);
64
80
  return {
65
- segmentText: d,
66
- segmentValues: R,
67
- currentValue: j,
68
- isControlled: S,
69
- wasTouched: B,
70
- appendDigit: G,
71
- adjustSegment: _,
72
- beginSegmentEdit: k,
73
- commitOnBlur: p
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
- K as useDateFieldValue
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.41.0",
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.41.0",
63
- "@viasat/beam-shared": "2.41.0",
64
- "@viasat/beam-styles": "2.41.0",
65
- "@viasat/beam-tokens": "2.41.0",
66
- "@viasat/beam-icons": "2.41.0",
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",