@viasat/beam-react 2.47.0 → 2.47.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 CHANGED
@@ -1,3 +1,13 @@
1
+ ## 2.47.1 (2026-07-27)
2
+
3
+ ### 🩹 Fixes
4
+
5
+ - **DateField:** predictable empty-seed + simpler Backspace/Delete (EPTOOLS-2766) ([#1377](https://git.viasat.com/vega/Beam/pull/1377))
6
+
7
+ ### ❤️ Thank You
8
+
9
+ - Roman-Ionita, Alin
10
+
1
11
  ## 2.47.0 (2026-07-23)
2
12
 
3
13
  ### 🚀 Features
@@ -1 +1 @@
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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),De=require("clsx"),fe=require("react"),e=require("../../../chunks/DateField.Segment.CY0jg03_.js"),me=require("../../../chunks/constants.CgMu0_1M.js"),ge=require("../../../chunks/form.context.D5XrYvpI.js"),pe=require("../../Form/contexts/label.context.cjs.js"),xe=require("../../Form/contexts/helperText.context.cjs.js"),ve=require("../../Form/hooks/useUniversalRef.hook.cjs.js"),r=require("./DateField.Segments.cjs.js"),ye=require("./DateField.utils.cjs.js"),Se=require("./useDateFieldFocus.cjs.js"),qe=require("./useDateFieldForm.cjs.js"),he=require("./useDateFieldKeyboard.cjs.js"),we=require("./useDateFieldSegments.cjs.js"),Ie=require("./useDateFieldValidity.cjs.js"),Re=require("./useDateFieldValue.cjs.js"),Pe=require("./useInvalidState.cjs.js"),Te=fe.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}=qe.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}=ve.useUniversalRef(K),{segmentRefs:J,registerSegmentRef:Q}=we.useDateFieldSegments(),{segmentText:X,segmentValues:m,currentValue:g,wasTouched:Y,appendDigit:Z,adjustSegment:ee,clearSegment:ie,beginSegmentEdit:ae,commitOnBlur:le}=Re.useDateFieldValue({value:S,defaultValue:$,onChange:h}),{focusedSegment:p,fieldTabIndex:se,handleSegmentFocus:x,handleFieldFocus:te,handleFieldBlur:re,handleFieldMouseDown:de,focusNext:v,focusPrevious:ne}=Se.useDateFieldFocus({disabled:i,fieldRef:f,segmentRefs:J,partsOrder:r.PARTS_ORDER,onSegmentFocusChange:ae,onFieldBlur:le}),oe=he.useDateFieldKeyboard({disabled:i,readOnly:t,fieldRef:f,focusNext:v,focusPrevious:ne,adjustSegment:ee,clearSegment:ie}),{isInvalid:ue}=Ie.useDateFieldValidity({segments:m,currentValue:g,wasTouched:Y,isFocused:p!==null}),ce=(l,s)=>{const{advanced:be}=Z(l,s);be&&v(l)},y=Pe.useInvalidState({formInvalid:L,valueInvalid:ue}),Fe=l=>{if(i)return;const s=l.target.closest("label");!s||s.id!==D||(l.preventDefault(),x(r.PARTS_ORDER[0]))},_e=De(e.styles[e.baseClassNamePrefix],u&&me.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:_e,style:{...O,maxWidth:R},onMouseDownCapture:Fe,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:se,className:e.styles[e.staticDateFieldClassNames.field],onMouseDown:de,onFocus:te,children:a.jsx(r.DateFieldSegments,{segmentText:X,segmentValues:m,focusedSegment:p,disabled:i,readOnly:t,onSegmentFocus:x,onSegmentBlur:re,onSegmentInput:ce,onSegmentKeyDown:oe,registerSegmentRef:Q})}),a.jsx("input",{type:"hidden",name:c,value:ye.toISODateString(g),disabled:i}),a.jsxs(xe.HelperTextProvider,{ctxId:k,ctxDisabled:i,children:[n,_&&a.jsx(ge.HelperText,{id:b,appearance:"negative",children:o})]}),z(A)]})});exports.DateField=Te;
@@ -1,22 +1,22 @@
1
1
  import { jsxs as S, jsx as l } from "react/jsx-runtime";
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(
2
+ import ve from "clsx";
3
+ import { forwardRef as De } from "react";
4
+ import { s as a, b as Fe, c as s, a as he } from "../../../chunks/DateField.Segment.C2qoaY0Z.js";
5
+ import { t as xe } from "../../../chunks/constants.Cruz2A1w.js";
6
+ import { H as ye } from "../../../chunks/form.context.cEuTL68U.js";
7
+ import { LabelProvider as Se } from "../../Form/contexts/label.context.es.js";
8
+ import { HelperTextProvider as Ie } from "../../Form/contexts/helperText.context.es.js";
9
+ import { useUniversalRef as we } from "../../Form/hooks/useUniversalRef.hook.es.js";
10
+ import { DateFieldSegments as Re, PARTS_ORDER as I } from "./DateField.Segments.es.js";
11
+ import { toISODateString as Ne } from "./DateField.utils.es.js";
12
+ import { useDateFieldFocus as Ve } from "./useDateFieldFocus.es.js";
13
+ import { useDateFieldForm as Be } from "./useDateFieldForm.es.js";
14
+ import { useDateFieldKeyboard as Ce } from "./useDateFieldKeyboard.es.js";
15
+ import { useDateFieldSegments as Oe } from "./useDateFieldSegments.es.js";
16
+ import { useDateFieldValidity as Pe } from "./useDateFieldValidity.es.js";
17
+ import { useDateFieldValue as Te } from "./useDateFieldValue.es.js";
18
+ import { useInvalidState as Me } from "./useInvalidState.es.js";
19
+ const ea = De(
20
20
  function({
21
21
  value: w,
22
22
  defaultValue: R,
@@ -34,9 +34,9 @@ const aa = Fe(
34
34
  required: M = !1,
35
35
  name: u,
36
36
  id: q,
37
- className: L,
38
- style: E,
39
- "aria-label": H,
37
+ className: E,
38
+ style: H,
39
+ "aria-label": L,
40
40
  "aria-describedby": $,
41
41
  "aria-labelledby": j,
42
42
  ...K
@@ -55,7 +55,7 @@ const aa = Fe(
55
55
  ariaDescribedBy: z,
56
56
  ariaLabelledBy: G,
57
57
  showErrors: J
58
- } = Ce({
58
+ } = Be({
59
59
  name: u,
60
60
  disabled: P,
61
61
  readOnly: T,
@@ -67,79 +67,77 @@ const aa = Fe(
67
67
  validationRules: B,
68
68
  ariaDescribedBy: $,
69
69
  ariaLabelledBy: j
70
- }), { refFn: Q, ref: g } = Re(W), { segmentRefs: X, registerSegmentRef: Y } = Pe(), {
70
+ }), { refFn: Q, ref: g } = we(W), { segmentRefs: X, registerSegmentRef: Y } = Oe(), {
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
- deleteLastDigit: le,
78
- clearSegment: ie,
79
- beginSegmentEdit: se,
80
- commitOnBlur: de
81
- } = Me({
77
+ clearSegment: le,
78
+ beginSegmentEdit: ie,
79
+ commitOnBlur: se
80
+ } = Te({
82
81
  value: w,
83
82
  defaultValue: U,
84
83
  onChange: N
85
84
  }), {
86
85
  focusedSegment: F,
87
- fieldTabIndex: te,
86
+ fieldTabIndex: de,
88
87
  handleSegmentFocus: h,
89
- handleFieldFocus: oe,
90
- handleFieldBlur: ne,
91
- handleFieldMouseDown: me,
88
+ handleFieldFocus: te,
89
+ handleFieldBlur: oe,
90
+ handleFieldMouseDown: ne,
92
91
  focusNext: x,
93
- focusPrevious: ue
94
- } = Be({
92
+ focusPrevious: me
93
+ } = Ve({
95
94
  disabled: e,
96
95
  fieldRef: g,
97
96
  segmentRefs: X,
98
97
  partsOrder: I,
99
- onSegmentFocusChange: se,
100
- onFieldBlur: de
101
- }), fe = Oe({
98
+ onSegmentFocusChange: ie,
99
+ onFieldBlur: se
100
+ }), ue = Ce({
102
101
  disabled: e,
103
102
  readOnly: d,
104
103
  fieldRef: g,
105
104
  focusNext: x,
106
- focusPrevious: ue,
105
+ focusPrevious: me,
107
106
  adjustSegment: re,
108
- deleteLastDigit: le,
109
- clearSegment: ie
110
- }), { isInvalid: ce } = Te({
107
+ clearSegment: le
108
+ }), { isInvalid: fe } = Pe({
111
109
  segments: v,
112
110
  currentValue: D,
113
111
  wasTouched: ee,
114
112
  isFocused: F !== null
115
- }), pe = (r, i) => {
116
- const { advanced: ve } = ae(r, i);
117
- ve && x(r);
118
- }, y = qe({
113
+ }), ce = (r, i) => {
114
+ const { advanced: ge } = ae(r, i);
115
+ ge && x(r);
116
+ }, y = Me({
119
117
  formInvalid: A,
120
- valueInvalid: ce
121
- }), be = (r) => {
118
+ valueInvalid: fe
119
+ }), pe = (r) => {
122
120
  if (e) return;
123
121
  const i = r.target.closest("label");
124
122
  !i || i.id !== b || (r.preventDefault(), h(I[0]));
125
- }, ge = De(
126
- a[he],
127
- m && ye(m),
123
+ }, be = ve(
124
+ a[Fe],
125
+ m && xe(m),
128
126
  O && a[`${s}fluid`],
129
127
  y && a[`${s}error`],
130
128
  e && a[`${s}disabled`],
131
129
  d && a[`${s}read-only`],
132
- L
130
+ E
133
131
  );
134
132
  return /* @__PURE__ */ S(
135
133
  "div",
136
134
  {
137
- className: ge,
138
- style: { ...E, maxWidth: C },
139
- onMouseDownCapture: be,
135
+ className: be,
136
+ style: { ...H, maxWidth: C },
137
+ onMouseDownCapture: pe,
140
138
  children: [
141
139
  /* @__PURE__ */ l(
142
- Ie,
140
+ Se,
143
141
  {
144
142
  ctxId: b,
145
143
  ctxDisabled: e,
@@ -154,19 +152,19 @@ const aa = Fe(
154
152
  ref: Q,
155
153
  id: q,
156
154
  role: "group",
157
- "aria-label": H,
155
+ "aria-label": L,
158
156
  "aria-labelledby": G,
159
157
  "aria-disabled": e || void 0,
160
158
  "aria-required": f || void 0,
161
159
  "aria-invalid": y || void 0,
162
160
  "aria-describedby": z,
163
161
  "aria-errormessage": c ? p : void 0,
164
- tabIndex: te,
165
- className: a[xe.field],
166
- onMouseDown: me,
167
- onFocus: oe,
162
+ tabIndex: de,
163
+ className: a[he.field],
164
+ onMouseDown: ne,
165
+ onFocus: te,
168
166
  children: /* @__PURE__ */ l(
169
- Ne,
167
+ Re,
170
168
  {
171
169
  segmentText: Z,
172
170
  segmentValues: v,
@@ -174,9 +172,9 @@ const aa = Fe(
174
172
  disabled: e,
175
173
  readOnly: d,
176
174
  onSegmentFocus: h,
177
- onSegmentBlur: ne,
178
- onSegmentInput: pe,
179
- onSegmentKeyDown: fe,
175
+ onSegmentBlur: oe,
176
+ onSegmentInput: ce,
177
+ onSegmentKeyDown: ue,
180
178
  registerSegmentRef: Y
181
179
  }
182
180
  )
@@ -187,13 +185,13 @@ const aa = Fe(
187
185
  {
188
186
  type: "hidden",
189
187
  name: u,
190
- value: Ve(D),
188
+ value: Ne(D),
191
189
  disabled: e
192
190
  }
193
191
  ),
194
- /* @__PURE__ */ S(we, { ctxId: _, ctxDisabled: e, children: [
192
+ /* @__PURE__ */ S(Ie, { ctxId: _, ctxDisabled: e, children: [
195
193
  o,
196
- c && /* @__PURE__ */ l(Se, { id: p, appearance: "negative", children: n })
194
+ c && /* @__PURE__ */ l(ye, { id: p, appearance: "negative", children: n })
197
195
  ] }),
198
196
  J(k)
199
197
  ]
@@ -202,5 +200,5 @@ const aa = Fe(
202
200
  }
203
201
  );
204
202
  export {
205
- aa as DateField
203
+ ea as DateField
206
204
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./DateField.validation.cjs.js"),s=31,o=12,m={day:s,month:o,year:9999},u=(e,t,n)=>Math.min(n,Math.max(t,e)),g=(e,t)=>((e-1)%t+t)%t+1,S=2024,y=(e,t)=>t==null?31:new Date(e??S,t,0).getDate(),M=()=>{const e=new Date;return{day:e.getDate(),month:e.getMonth()+1,year:e.getFullYear()}},N=(e,t,n,r)=>{if(n==="min")return e==="year"?null:1;if(n==="max")return e==="year"?null:e==="day"?r.daysInMonth:o;if(t==null)return r.today[e];if(e==="year")return u(t+n,1,9999);const a=e==="day"?s:o;return g(t+n,a)},T={day:"",month:"",year:""},c=e=>e instanceof Date&&!Number.isNaN(e.getTime()),d=e=>{const{day:t,month:n,year:r}=e;if(t==null||n==null||r==null)return null;const a=new Date(r,n-1,t);return a.setFullYear(r),Number.isNaN(a.getTime())||a.getFullYear()!==r||a.getMonth()!==n-1||a.getDate()!==t?null:a},f=(e,t)=>e==null&&t==null?!0:e==null||t==null?!1:e.getTime()===t.getTime(),_=e=>{if(!c(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}`},h=e=>e.filter(t=>t.type!=="literal").map(t=>t.type),D=e=>c(e)?{day:String(e.getDate()).padStart(2,"0"),month:String(e.getMonth()+1).padStart(2,"0"),year:String(e.getFullYear()).padStart(4,"0")}:T,l=(e,t)=>{if(t===""||e==="year"&&t.length<i.SEGMENT_MAX_LENGTH.year)return null;const n=parseInt(t,10);return Number.isNaN(n)||n===0?null:n},A=e=>d({day:l("day",e.day),month:l("month",e.month),year:l("year",e.year)}),E=(e,t)=>t===""?"":t.padStart(i.SEGMENT_MAX_LENGTH[e],"0"),p=(e,t,n)=>t===""?{displayValue:n,isPlaceholder:!0}:{displayValue:t.padStart(i.SEGMENT_MAX_LENGTH[e],"0"),isPlaceholder:!1},V=e=>{const t=window.getSelection();if(!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)},F=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=s;exports.MONTH_MAX=o;exports.SEGMENT_ARIA_MAX=m;exports.adjustSegmentValue=N;exports.clamp=u;exports.clearSelectionWithin=F;exports.deriveValue=d;exports.deriveValueFromText=A;exports.getDaysInMonth=y;exports.getSegmentDisplay=p;exports.getSegmentOrder=h;exports.isSameDateValue=f;exports.normalizeSegmentText=E;exports.segmentNumber=l;exports.segmentTextFromValue=D;exports.selectElementContents=V;exports.toISODateString=_;exports.todayParts=M;exports.wrapInRange=g;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("./DateField.validation.cjs.js"),i=31,l=12,S={day:i,month:l,year:9999},u=(e,t,n)=>Math.min(n,Math.max(t,e)),g=(e,t)=>((e-1)%t+t)%t+1,y=2024,M=(e,t)=>t==null?31:new Date(e??y,t,0).getDate(),N=()=>{const e=new Date;return{day:e.getDate(),month:e.getMonth()+1,year:e.getFullYear()}},f=(e,t,n,r)=>{if(n==="min")return e==="year"?null:1;if(n==="max")return e==="year"?null:e==="day"?r.daysInMonth:l;if(t==null){if(e==="year")return r.today.year;const m=e==="day"?i:l;return n>0?1:m}if(e==="year")return u(t+n,1,9999);const a=e==="day"?i:l;return g(t+n,a)},T={day:"",month:"",year:""},c=e=>e instanceof Date&&!Number.isNaN(e.getTime()),d=e=>{const{day:t,month:n,year:r}=e;if(t==null||n==null||r==null)return null;const a=new Date(r,n-1,t);return a.setFullYear(r),Number.isNaN(a.getTime())||a.getFullYear()!==r||a.getMonth()!==n-1||a.getDate()!==t?null:a},_=(e,t)=>e==null&&t==null?!0:e==null||t==null?!1:e.getTime()===t.getTime(),h=e=>{if(!c(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}`},D=e=>e.filter(t=>t.type!=="literal").map(t=>t.type),A=e=>c(e)?{day:String(e.getDate()).padStart(2,"0"),month:String(e.getMonth()+1).padStart(2,"0"),year:String(e.getFullYear()).padStart(4,"0")}:T,o=(e,t)=>{if(t===""||e==="year"&&t.length<s.SEGMENT_MAX_LENGTH.year)return null;const n=parseInt(t,10);return Number.isNaN(n)||n===0?null:n},E=e=>d({day:o("day",e.day),month:o("month",e.month),year:o("year",e.year)}),p=(e,t)=>t===""?"":t.padStart(s.SEGMENT_MAX_LENGTH[e],"0"),V=(e,t,n)=>t===""?{displayValue:n,isPlaceholder:!0}:{displayValue:t.padStart(s.SEGMENT_MAX_LENGTH[e],"0"),isPlaceholder:!1},F=e=>{const t=window.getSelection();if(!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)},I=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=i;exports.MONTH_MAX=l;exports.SEGMENT_ARIA_MAX=S;exports.adjustSegmentValue=f;exports.clamp=u;exports.clearSelectionWithin=I;exports.deriveValue=d;exports.deriveValueFromText=E;exports.getDaysInMonth=M;exports.getSegmentDisplay=V;exports.getSegmentOrder=D;exports.isSameDateValue=_;exports.normalizeSegmentText=p;exports.segmentNumber=o;exports.segmentTextFromValue=A;exports.selectElementContents=F;exports.toISODateString=h;exports.todayParts=N;exports.wrapInRange=g;
@@ -49,7 +49,11 @@ export declare const todayParts: () => {
49
49
  export interface AdjustSegmentContext {
50
50
  /** Days in the current month (use {@link getDaysInMonth} to compute). */
51
51
  daysInMonth: number;
52
- /** Today's local-date values used to seed an empty segment on the first press. */
52
+ /**
53
+ * Today's local-date values. Only `year` is read now — it seeds an empty
54
+ * year segment on the first press. Day/month seed to a fixed first/last
55
+ * valid value instead, so `day`/`month` here go unused.
56
+ */
53
57
  today: {
54
58
  day: number;
55
59
  month: number;
@@ -71,8 +75,10 @@ export interface AdjustSegmentContext {
71
75
  * currently selected month (month-aware).
72
76
  * - **month**: modular wrap within `[1, MONTH_MAX]`.
73
77
  * - **year**: clamp to `[1, 9999]`; no wrap.
74
- * - **Empty segment + numeric delta**: seeds to `ctx.today[type]` (first press
75
- * sets today's value; subsequent presses step from there).
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.
76
82
  * - **`'min'`**: returns 1 for day/month, null for year.
77
83
  * - **`'max'`**: returns `ctx.daysInMonth` for day (End → month-aware last
78
84
  * valid day), MONTH_MAX for month, null for year.
@@ -1,74 +1,78 @@
1
- import { SEGMENT_MAX_LENGTH as s } from "./DateField.validation.es.js";
2
- const i = 31, o = 12, f = {
3
- day: i,
4
- month: o,
1
+ import { SEGMENT_MAX_LENGTH as i } from "./DateField.validation.es.js";
2
+ const s = 31, l = 12, h = {
3
+ day: s,
4
+ month: l,
5
5
  year: 9999
6
- }, c = (t, e, n) => Math.min(n, Math.max(e, t)), g = (t, e) => ((t - 1) % e + e) % e + 1, d = 2024, h = (t, e) => e == null ? 31 : new Date(t ?? d, e, 0).getDate(), N = () => {
7
- const t = /* @__PURE__ */ new Date();
8
- return { day: t.getDate(), month: t.getMonth() + 1, year: t.getFullYear() };
9
- }, M = (t, e, n, r) => {
10
- if (n === "min") return t === "year" ? null : 1;
6
+ }, g = (e, t, n) => Math.min(n, Math.max(t, e)), d = (e, t) => ((e - 1) % t + t) % t + 1, m = 2024, N = (e, t) => t == null ? 31 : new Date(e ?? m, t, 0).getDate(), M = () => {
7
+ const e = /* @__PURE__ */ new Date();
8
+ return { day: e.getDate(), month: e.getMonth() + 1, year: e.getFullYear() };
9
+ }, D = (e, t, n, r) => {
10
+ if (n === "min") return e === "year" ? null : 1;
11
11
  if (n === "max")
12
- return t === "year" ? null : t === "day" ? r.daysInMonth : o;
13
- if (e == null) return r.today[t];
14
- if (t === "year") return c(e + n, 1, 9999);
15
- const a = t === "day" ? i : o;
16
- return g(e + n, a);
17
- }, m = { day: "", month: "", year: "" }, u = (t) => t instanceof Date && !Number.isNaN(t.getTime()), y = (t) => {
18
- const { day: e, month: n, year: r } = t;
19
- if (e == null || n == null || r == null) return null;
20
- const a = new Date(r, n - 1, e);
21
- return a.setFullYear(r), Number.isNaN(a.getTime()) || a.getFullYear() !== r || a.getMonth() !== n - 1 || a.getDate() !== e ? null : a;
22
- }, D = (t, e) => t == null && e == null ? !0 : t == null || e == null ? !1 : t.getTime() === e.getTime(), p = (t) => {
23
- if (!u(t)) return "";
24
- const e = String(t.getFullYear()).padStart(4, "0"), n = String(t.getMonth() + 1).padStart(2, "0"), r = String(t.getDate()).padStart(2, "0");
25
- return `${e}-${n}-${r}`;
26
- }, T = (t) => t.filter(
27
- (e) => e.type !== "literal"
28
- ).map((e) => e.type), A = (t) => u(t) ? {
29
- day: String(t.getDate()).padStart(2, "0"),
30
- month: String(t.getMonth() + 1).padStart(2, "0"),
31
- year: String(t.getFullYear()).padStart(4, "0")
32
- } : m, l = (t, e) => {
33
- if (e === "" || t === "year" && e.length < s.year) return null;
34
- const n = parseInt(e, 10);
12
+ return e === "year" ? null : e === "day" ? r.daysInMonth : l;
13
+ if (t == null) {
14
+ if (e === "year") return r.today.year;
15
+ const c = e === "day" ? s : l;
16
+ return n > 0 ? 1 : c;
17
+ }
18
+ if (e === "year") return g(t + n, 1, 9999);
19
+ const a = e === "day" ? s : l;
20
+ return d(t + n, a);
21
+ }, y = { day: "", month: "", year: "" }, u = (e) => e instanceof Date && !Number.isNaN(e.getTime()), S = (e) => {
22
+ const { day: t, month: n, year: r } = e;
23
+ if (t == null || n == null || r == null) return null;
24
+ const a = new Date(r, n - 1, t);
25
+ return a.setFullYear(r), Number.isNaN(a.getTime()) || a.getFullYear() !== r || a.getMonth() !== n - 1 || a.getDate() !== t ? null : a;
26
+ }, T = (e, t) => e == null && t == null ? !0 : e == null || t == null ? !1 : e.getTime() === t.getTime(), p = (e) => {
27
+ if (!u(e)) return "";
28
+ const t = String(e.getFullYear()).padStart(4, "0"), n = String(e.getMonth() + 1).padStart(2, "0"), r = String(e.getDate()).padStart(2, "0");
29
+ return `${t}-${n}-${r}`;
30
+ }, A = (e) => e.filter(
31
+ (t) => t.type !== "literal"
32
+ ).map((t) => t.type), E = (e) => u(e) ? {
33
+ day: String(e.getDate()).padStart(2, "0"),
34
+ month: String(e.getMonth() + 1).padStart(2, "0"),
35
+ year: String(e.getFullYear()).padStart(4, "0")
36
+ } : y, o = (e, t) => {
37
+ if (t === "" || e === "year" && t.length < i.year) return null;
38
+ const n = parseInt(t, 10);
35
39
  return Number.isNaN(n) || n === 0 ? null : n;
36
- }, E = (t) => y({
37
- day: l("day", t.day),
38
- month: l("month", t.month),
39
- year: l("year", t.year)
40
- }), _ = (t, e) => e === "" ? "" : e.padStart(s[t], "0"), w = (t, e, n) => e === "" ? { displayValue: n, isPlaceholder: !0 } : {
41
- displayValue: e.padStart(s[t], "0"),
40
+ }, _ = (e) => S({
41
+ day: o("day", e.day),
42
+ month: o("month", e.month),
43
+ year: o("year", e.year)
44
+ }), w = (e, t) => t === "" ? "" : t.padStart(i[e], "0"), F = (e, t, n) => t === "" ? { displayValue: n, isPlaceholder: !0 } : {
45
+ displayValue: t.padStart(i[e], "0"),
42
46
  isPlaceholder: !1
43
- }, F = (t) => {
44
- const e = window.getSelection();
45
- if (!e) return;
47
+ }, V = (e) => {
48
+ const t = window.getSelection();
49
+ if (!t) return;
46
50
  const n = document.createRange();
47
- n.selectNodeContents(t), e.removeAllRanges(), e.addRange(n);
48
- }, V = (t) => {
51
+ n.selectNodeContents(e), t.removeAllRanges(), t.addRange(n);
52
+ }, Y = (e) => {
49
53
  var n;
50
- if (!t) return;
51
- const e = (n = window.getSelection) == null ? void 0 : n.call(window);
52
- e && e.rangeCount > 0 && t.contains(e.anchorNode) && e.removeAllRanges();
54
+ if (!e) return;
55
+ const t = (n = window.getSelection) == null ? void 0 : n.call(window);
56
+ t && t.rangeCount > 0 && e.contains(t.anchorNode) && t.removeAllRanges();
53
57
  };
54
58
  export {
55
- i as DAY_SPIN_MAX,
56
- o as MONTH_MAX,
57
- f as SEGMENT_ARIA_MAX,
58
- M as adjustSegmentValue,
59
- c as clamp,
60
- V as clearSelectionWithin,
61
- y as deriveValue,
62
- E as deriveValueFromText,
63
- h as getDaysInMonth,
64
- w as getSegmentDisplay,
65
- T as getSegmentOrder,
66
- D as isSameDateValue,
67
- _ as normalizeSegmentText,
68
- l as segmentNumber,
69
- A as segmentTextFromValue,
70
- F as selectElementContents,
59
+ s as DAY_SPIN_MAX,
60
+ l as MONTH_MAX,
61
+ h as SEGMENT_ARIA_MAX,
62
+ D as adjustSegmentValue,
63
+ g as clamp,
64
+ Y as clearSelectionWithin,
65
+ S as deriveValue,
66
+ _ as deriveValueFromText,
67
+ N as getDaysInMonth,
68
+ F as getSegmentDisplay,
69
+ A as getSegmentOrder,
70
+ T as isSameDateValue,
71
+ w as normalizeSegmentText,
72
+ o as segmentNumber,
73
+ E as segmentTextFromValue,
74
+ V as selectElementContents,
71
75
  p as toISODateString,
72
- N as todayParts,
73
- g as wrapInRange
76
+ M as todayParts,
77
+ d as wrapInRange
74
78
  };
@@ -1 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("react");function d({disabled:a,readOnly:c,fieldRef:y,focusNext:o,focusPrevious:e,adjustSegment:t,clearSegment:l}){const p=w.useMemo(()=>{const n={ArrowRight:({segment:r,isRTL:i})=>((i?e:o)(r),!0),ArrowLeft:({segment:r,isRTL:i})=>((i?o:e)(r),!0)};return c?n:{...n,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})=>(l(r).wasEmpty&&e(r),!0),Delete:({segment:r})=>(l(r),!0)}},[t,l,o,e,c]);return w.useCallback((n,r)=>{if(a||r.altKey||r.ctrlKey||r.metaKey||r.shiftKey)return;const i=p[r.key];if(!i)return;const u=y.current,b=!!u&&(getComputedStyle(u).direction==="rtl"||!!u.closest('[dir="rtl"]'));i({segment:n,event:r,isRTL:b})&&r.preventDefault()},[a,p,y])}exports.useDateFieldKeyboard=d;
@@ -41,18 +41,14 @@ export interface UseDateFieldKeyboardArgs {
41
41
  */
42
42
  adjustSegment: (type: SegmentType, amount: SegmentAdjustment) => boolean;
43
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.
44
+ * Clears the entire segment buffer to `''` — shared by Backspace and Delete.
45
+ * Returns `{ wasEmpty: true }` when the buffer was already
46
+ * empty, signalling Backspace to move focus to the previous segment instead;
47
+ * Delete ignores the result and leaves focus on the current segment.
47
48
  * Provided by `useDateFieldValue`.
48
49
  */
49
- deleteLastDigit: (type: SegmentType) => {
50
+ clearSegment: (type: SegmentType) => {
50
51
  wasEmpty: boolean;
51
52
  };
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;
57
53
  }
58
- export declare function useDateFieldKeyboard({ disabled, readOnly, fieldRef, focusNext, focusPrevious, adjustSegment, deleteLastDigit, clearSegment, }: UseDateFieldKeyboardArgs): (segment: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
54
+ export declare function useDateFieldKeyboard({ disabled, readOnly, fieldRef, focusNext, focusPrevious, adjustSegment, clearSegment, }: UseDateFieldKeyboardArgs): (segment: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
@@ -1,49 +1,47 @@
1
- import { useMemo as f, useCallback as h } from "react";
2
- function b({
3
- disabled: p,
4
- readOnly: e,
5
- fieldRef: u,
1
+ import { useMemo as D, useCallback as K } from "react";
2
+ function A({
3
+ disabled: e,
4
+ readOnly: u,
5
+ fieldRef: w,
6
6
  focusNext: l,
7
- focusPrevious: i,
8
- adjustSegment: n,
9
- deleteLastDigit: w,
10
- clearSegment: y
7
+ focusPrevious: n,
8
+ adjustSegment: t,
9
+ clearSegment: p
11
10
  }) {
12
- const a = f(
13
- () => {
14
- const o = {
15
- // Nav keys always own the event (arrows are contentEditable caret keys we
16
- // suppress even at the first/last segment), so they always report handled.
17
- ArrowRight: ({ segment: r, isRTL: t }) => ((t ? i : l)(r), !0),
18
- ArrowLeft: ({ segment: r, isRTL: t }) => ((t ? l : i)(r), !0)
19
- };
20
- return e ? o : {
21
- ...o,
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)
32
- };
33
- },
34
- [n, y, w, l, i, e]
35
- );
36
- return h(
11
+ const y = D(() => {
12
+ const o = {
13
+ // Nav keys always own the event (arrows are contentEditable caret keys we
14
+ // suppress even at the first/last segment), so they always report handled.
15
+ ArrowRight: ({ segment: r, isRTL: i }) => ((i ? n : l)(r), !0),
16
+ ArrowLeft: ({ segment: r, isRTL: i }) => ((i ? l : n)(r), !0)
17
+ };
18
+ return u ? o : {
19
+ ...o,
20
+ ArrowUp: ({ segment: r }) => t(r, 1),
21
+ ArrowDown: ({ segment: r }) => t(r, -1),
22
+ PageUp: ({ segment: r }) => t(r, 5),
23
+ PageDown: ({ segment: r }) => t(r, -5),
24
+ Home: ({ segment: r }) => t(r, "min"),
25
+ End: ({ segment: r }) => t(r, "max"),
26
+ // Backspace and Delete both clear the whole segment to
27
+ // placeholder. Backspace on an already-empty segment moves focus to the
28
+ // previous segment instead (MUI parity); Delete just clears.
29
+ // Both always own the key (clear or focus-hop), so they report handled.
30
+ Backspace: ({ segment: r }) => (p(r).wasEmpty && n(r), !0),
31
+ Delete: ({ segment: r }) => (p(r), !0)
32
+ };
33
+ }, [t, p, l, n, u]);
34
+ return K(
37
35
  (o, r) => {
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();
36
+ if (e || r.altKey || r.ctrlKey || r.metaKey || r.shiftKey) return;
37
+ const i = y[r.key];
38
+ if (!i) return;
39
+ const c = w.current, a = !!c && (getComputedStyle(c).direction === "rtl" || !!c.closest('[dir="rtl"]'));
40
+ i({ segment: o, event: r, isRTL: a }) && r.preventDefault();
43
41
  },
44
- [p, a, u]
42
+ [e, y, w]
45
43
  );
46
44
  }
47
45
  export {
48
- b as useDateFieldKeyboard
46
+ A as useDateFieldKeyboard
49
47
  };
@@ -1 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),t=require("./DateField.utils.cjs.js"),E=require("./DateField.validation.cjs.js");function p({value:c,defaultValue:F,onChange:g}){const T=r.useRef(c!==void 0),b=T.current,[o,S]=r.useState(()=>t.segmentTextFromValue(b?c??null:F??null)),[_,y]=r.useState(!1),a=r.useRef(o),d=r.useRef(new Set),i=r.useRef(!1),h={day:t.segmentNumber("day",o.day),month:t.segmentNumber("month",o.month),year:t.segmentNumber("year",o.year)},R=t.deriveValue(h),x=r.useRef(R),V=r.useRef(b?c??null:null),m=r.useRef(g);r.useEffect(()=>{m.current=g},[g]),r.useEffect(()=>{if(!T.current||i.current||t.isSameDateValue(c??null,V.current))return;V.current=c??null;const e=t.segmentTextFromValue(c??null);a.current=e,S(e),x.current=t.deriveValueFromText(e)},[c]);const f=r.useCallback(e=>{var u;const n=t.deriveValueFromText(e);t.isSameDateValue(n,x.current)||(x.current=n,(u=m.current)==null||u.call(m,n))},[]),l=r.useCallback((e,n,{replace:u})=>{const s={...a.current,[e]:n};a.current=s,S(s),y(!0),f(s),u?d.current.add(e):d.current.delete(e)},[f]),N=r.useCallback((e,n)=>{const u=d.current.has(e)?"":a.current[e],s=E.tryAppendDigit(e,u,n);return s.rejected?{advanced:!1,rejected:!0}:(l(e,s.newBuffer,{replace:s.shouldAdvance}),{advanced:s.shouldAdvance,rejected:!1})},[l]),k=r.useCallback((e,n)=>{const u=a.current,s=t.segmentNumber(e,u[e]),v=t.getDaysInMonth(t.segmentNumber("year",u.year),t.segmentNumber("month",u.month)),D=t.adjustSegmentValue(e,s,n,{daysInMonth:v,today:t.todayParts()});return D==null?!1:(i.current=!0,l(e,String(D).padStart(E.SEGMENT_MAX_LENGTH[e],"0"),{replace:!0}),!0)},[l]),w=r.useCallback(e=>a.current[e]===""?{wasEmpty:!0}:(i.current=!0,l(e,"",{replace:!1}),{wasEmpty:!1}),[l]),C=r.useCallback(e=>{i.current=!0,d.current.add(e)},[]),j=r.useCallback(()=>{i.current=!1;const e=a.current,n={day:t.normalizeSegmentText("day",e.day),month:t.normalizeSegmentText("month",e.month),year:t.normalizeSegmentText("year",e.year)};a.current=n,S(n),y(!0),f(n)},[f]);return{segmentText:o,segmentValues:h,currentValue:R,isControlled:b,wasTouched:_,appendDigit:N,adjustSegment:k,clearSegment:w,beginSegmentEdit:C,commitOnBlur:j}}exports.useDateFieldValue=p;
@@ -17,7 +17,9 @@ export interface UseDateFieldValueReturn {
17
17
  * Increments, decrements, or jumps a segment to its min/max boundary.
18
18
  *
19
19
  * - Numeric `amount` (e.g. ±1, ±5): day/month wrap modularly; year clamps
20
- * to [1, 9999]. An empty segment seeds to today's value on the first press.
20
+ * to [1, 9999]. An empty day/month segment seeds to a fixed first/last
21
+ * valid value based on direction; an empty year seeds to the current
22
+ * year.
21
23
  * - `'min'` / `'max'`: jump to the lower/upper bound. No-op on year (no
22
24
  * meaningful bound until DF-10 adds minDate/maxDate).
23
25
  *
@@ -33,24 +35,19 @@ export interface UseDateFieldValueReturn {
33
35
  */
34
36
  adjustSegment: (type: SegmentType, amount: SegmentAdjustment) => boolean;
35
37
  /**
36
- * Removes the last raw digit from the segment buffer (Backspace behaviour).
38
+ * Clears the entire segment buffer to `''` — the shared Backspace and
39
+ * Delete behaviour.
37
40
  *
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.
41
+ * Returns `{ wasEmpty: true }` when the buffer was already empty, without
42
+ * mutating, so the caller (keyboard handler) knows Backspace should move
43
+ * focus to the previous segment instead of clearing. Otherwise focus stays
44
+ * on the current segment. Fires `onChange(null)` via `emitIfChanged` when
45
+ * the cleared segment was part of a complete date. Clears `replaceNextRef`
46
+ * for the segment so the next digit appends.
42
47
  */
43
- deleteLastDigit: (type: SegmentType) => {
48
+ clearSegment: (type: SegmentType) => {
44
49
  wasEmpty: boolean;
45
50
  };
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;
54
51
  beginSegmentEdit: (type: SegmentType) => void;
55
52
  commitOnBlur: () => void;
56
53
  }
@@ -1,75 +1,63 @@
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,
1
+ import { useRef as s, useState as w, useEffect as b, useCallback as o } from "react";
2
+ import { segmentTextFromValue as A, segmentNumber as l, deriveValue as C, isSameDateValue as M, deriveValueFromText as N, getDaysInMonth as H, adjustSegmentValue as L, todayParts as O, normalizeSegmentText as T } 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: u,
6
+ defaultValue: v,
7
7
  onChange: x
8
8
  }) {
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);
9
+ const E = s(u !== void 0), h = E.current, [d, S] = w(
10
+ () => A(h ? u ?? null : v ?? null)
11
+ ), [F, V] = w(!1), c = s(d), i = s(/* @__PURE__ */ new Set()), m = s(!1), p = {
12
+ day: l("day", d.day),
13
+ month: l("month", d.month),
14
+ year: l("year", d.year)
15
+ }, D = C(p), y = s(D), R = s(h ? u ?? null : null), f = s(x);
18
16
  b(() => {
19
17
  f.current = x;
20
18
  }, [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) => {
19
+ if (!E.current || m.current || M(u ?? null, R.current)) return;
20
+ R.current = u ?? null;
21
+ const e = A(u ?? null);
22
+ c.current = e, S(e), y.current = N(e);
23
+ }, [u]);
24
+ const g = o((e) => {
27
25
  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(
26
+ const t = N(e);
27
+ M(t, y.current) || (y.current = t, (r = f.current) == null || r.call(f, t));
28
+ }, []), a = o(
31
29
  (e, t, { replace: r }) => {
32
30
  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);
31
+ c.current = n, S(n), V(!0), g(n), r ? i.current.add(e) : i.current.delete(e);
34
32
  },
35
33
  [g]
36
- ), I = s(
34
+ ), I = o(
37
35
  (e, t) => {
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
+ const r = i.current.has(e) ? "" : c.current[e], n = P(e, r, t);
37
+ return n.rejected ? { advanced: !1, rejected: !0 } : (a(e, n.newBuffer, { replace: n.shouldAdvance }), { advanced: n.shouldAdvance, rejected: !1 });
40
38
  },
41
- [u]
42
- ), B = s(
39
+ [a]
40
+ ), B = o(
43
41
  (e, t) => {
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, {
42
+ const r = c.current, n = l(e, r[e]), z = H(
43
+ l("year", r.year),
44
+ l("month", r.month)
45
+ ), j = L(e, n, t, {
48
46
  daysInMonth: z,
49
- today: P()
47
+ today: O()
50
48
  });
51
- return j == null ? !1 : (l.current = !0, u(
52
- e,
53
- String(j).padStart(X[e], "0"),
54
- { replace: !0 }
55
- ), !0);
49
+ return j == null ? !1 : (m.current = !0, a(e, String(j).padStart(W[e], "0"), {
50
+ replace: !0
51
+ }), !0);
56
52
  },
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 }));
67
- },
68
- [u]
69
- ), _ = s((e) => {
70
- l.current = !0, m.current.add(e);
71
- }, []), k = s(() => {
72
- l.current = !1;
53
+ [a]
54
+ ), G = o(
55
+ (e) => c.current[e] === "" ? { wasEmpty: !0 } : (m.current = !0, a(e, "", { replace: !1 }), { wasEmpty: !1 }),
56
+ [a]
57
+ ), _ = o((e) => {
58
+ m.current = !0, i.current.add(e);
59
+ }, []), k = o(() => {
60
+ m.current = !1;
73
61
  const e = c.current, t = {
74
62
  day: T("day", e.day),
75
63
  month: T("month", e.month),
@@ -78,19 +66,18 @@ function Q({
78
66
  c.current = t, S(t), V(!0), g(t);
79
67
  }, [g]);
80
68
  return {
81
- segmentText: i,
69
+ segmentText: d,
82
70
  segmentValues: p,
83
71
  currentValue: D,
84
72
  isControlled: h,
85
73
  wasTouched: F,
86
74
  appendDigit: I,
87
75
  adjustSegment: B,
88
- deleteLastDigit: G,
89
- clearSegment: L,
76
+ clearSegment: G,
90
77
  beginSegmentEdit: _,
91
78
  commitOnBlur: k
92
79
  };
93
80
  }
94
81
  export {
95
- Q as useDateFieldValue
82
+ K as useDateFieldValue
96
83
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viasat/beam-react",
3
- "version": "2.47.0",
3
+ "version": "2.47.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.47.0",
64
- "@viasat/beam-shared": "2.47.0",
65
- "@viasat/beam-styles": "2.47.0",
66
- "@viasat/beam-tokens": "2.47.0",
67
- "@viasat/beam-icons": "2.47.0",
68
- "@viasat/beam-react-claude-plugin": "2.47.0",
63
+ "@viasat/beam-fonts": "2.47.1",
64
+ "@viasat/beam-shared": "2.47.1",
65
+ "@viasat/beam-styles": "2.47.1",
66
+ "@viasat/beam-tokens": "2.47.1",
67
+ "@viasat/beam-icons": "2.47.1",
68
+ "@viasat/beam-react-claude-plugin": "2.47.1",
69
69
  "clsx": "^1.2.1",
70
70
  "@floating-ui/react": "^0.26.18",
71
71
  "@stepperize/react": "^5.1.5",