@viasat/beam-react 2.47.1 → 2.48.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,78 +1,86 @@
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
- year: 9999
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 = () => {
1
+ import { SEGMENT_MAX_LENGTH as u } from "./DateField.validation.es.js";
2
+ const c = 31, s = 12, d = 1, y = 9999, f = (e, t, n) => Math.min(n, Math.max(t, e)), S = (e, t) => ((e - 1) % t + t) % t + 1, h = 2024, T = (e, t) => t == null ? 31 : new Date(e ?? h, t, 0).getDate(), A = () => {
7
3
  const e = /* @__PURE__ */ new Date();
8
4
  return { day: e.getDate(), month: e.getMonth() + 1, year: e.getFullYear() };
9
- }, D = (e, t, n, r) => {
5
+ }, o = (e) => e instanceof Date && !Number.isNaN(e.getTime()), Y = (e, t, n, r) => {
10
6
  if (n === "min") return e === "year" ? null : 1;
11
7
  if (n === "max")
12
- return e === "year" ? null : e === "day" ? r.daysInMonth : l;
8
+ return e === "year" ? null : e === "day" ? r.daysInMonth : s;
13
9
  if (t == null) {
14
10
  if (e === "year") return r.today.year;
15
- const c = e === "day" ? s : l;
16
- return n > 0 ? 1 : c;
11
+ const g = e === "day" ? c : s;
12
+ return n > 0 ? 1 : g;
17
13
  }
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) => {
14
+ if (e === "year") return f(t + n, d, y);
15
+ const l = e === "day" ? c : s;
16
+ return S(t + n, l);
17
+ }, M = { day: "", month: "", year: "" }, m = (e) => {
22
18
  const { day: t, month: n, year: r } = e;
23
19
  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 "";
20
+ const l = new Date(r, n - 1, t);
21
+ return l.setFullYear(r), Number.isNaN(l.getTime()) || l.getFullYear() !== r || l.getMonth() !== n - 1 || l.getDate() !== t ? null : l;
22
+ }, F = (e, t) => e == null && t == null ? !0 : e == null || t == null ? !1 : e.getTime() === t.getTime(), a = (e) => e.getFullYear() * 1e4 + (e.getMonth() + 1) * 100 + e.getDate(), w = (e) => o(e) ? a(e) : null, E = (e, t, n) => {
23
+ const r = a(e);
24
+ return !(o(t) && r < a(t) || o(n) && r > a(n));
25
+ }, N = (e, t) => o(e) && o(t) && a(e) > a(t), R = (e, t, n) => {
26
+ if (N(t, n)) return e;
27
+ const r = a(e);
28
+ return o(t) && r < a(t) ? new Date(t.getFullYear(), t.getMonth(), t.getDate()) : o(n) && r > a(n) ? new Date(n.getFullYear(), n.getMonth(), n.getDate()) : e;
29
+ }, _ = (e) => {
30
+ if (!o(e)) return "";
28
31
  const t = String(e.getFullYear()).padStart(4, "0"), n = String(e.getMonth() + 1).padStart(2, "0"), r = String(e.getDate()).padStart(2, "0");
29
32
  return `${t}-${n}-${r}`;
30
- }, A = (e) => e.filter(
33
+ }, D = (e) => e.filter(
31
34
  (t) => t.type !== "literal"
32
- ).map((t) => t.type), E = (e) => u(e) ? {
35
+ ).map((t) => t.type), I = (e) => o(e) ? {
33
36
  day: String(e.getDate()).padStart(2, "0"),
34
37
  month: String(e.getMonth() + 1).padStart(2, "0"),
35
38
  year: String(e.getFullYear()).padStart(4, "0")
36
- } : y, o = (e, t) => {
37
- if (t === "" || e === "year" && t.length < i.year) return null;
39
+ } : M, i = (e, t) => {
40
+ if (t === "" || e === "year" && t.length < u.year) return null;
38
41
  const n = parseInt(t, 10);
39
42
  return Number.isNaN(n) || n === 0 ? null : n;
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"),
43
+ }, V = (e) => m({
44
+ day: i("day", e.day),
45
+ month: i("month", e.month),
46
+ year: i("year", e.year)
47
+ }), P = (e, t) => t === "" ? "" : t.padStart(u[e], "0"), X = (e, t, n) => t === "" ? { displayValue: n, isPlaceholder: !0 } : {
48
+ displayValue: t.padStart(u[e], "0"),
46
49
  isPlaceholder: !1
47
- }, V = (e) => {
50
+ }, C = (e) => {
48
51
  const t = window.getSelection();
49
52
  if (!t) return;
50
53
  const n = document.createRange();
51
54
  n.selectNodeContents(e), t.removeAllRanges(), t.addRange(n);
52
- }, Y = (e) => {
55
+ }, L = (e) => {
53
56
  var n;
54
57
  if (!e) return;
55
58
  const t = (n = window.getSelection) == null ? void 0 : n.call(window);
56
59
  t && t.rangeCount > 0 && e.contains(t.anchorNode) && t.removeAllRanges();
57
60
  };
58
61
  export {
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,
75
- p as toISODateString,
76
- M as todayParts,
77
- d as wrapInRange
62
+ c as DAY_SPIN_MAX,
63
+ s as MONTH_MAX,
64
+ y as YEAR_MAX,
65
+ d as YEAR_MIN,
66
+ Y as adjustSegmentValue,
67
+ f as clamp,
68
+ R as clampDateToRange,
69
+ L as clearSelectionWithin,
70
+ w as dateKeyOrNull,
71
+ m as deriveValue,
72
+ V as deriveValueFromText,
73
+ T as getDaysInMonth,
74
+ X as getSegmentDisplay,
75
+ D as getSegmentOrder,
76
+ E as isDateInRange,
77
+ N as isMinMaxMisconfigured,
78
+ F as isSameDateValue,
79
+ P as normalizeSegmentText,
80
+ i as segmentNumber,
81
+ I as segmentTextFromValue,
82
+ C as selectElementContents,
83
+ _ as toISODateString,
84
+ A as todayParts,
85
+ S as wrapInRange
78
86
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),I=require("./DateField.utils.cjs.js");function M({disabled:n,fieldRef:a,segmentRefs:T,partsOrder:o,onSegmentFocusChange:b,onFieldBlur:D}){const[l,i]=e.useState(null),s=o[0],r=e.useRef(b),f=e.useRef(D);e.useEffect(()=>{r.current=b,f.current=D},[b,D]),e.useEffect(()=>{if(l===null||l==="all")return;const t=T.current.get(l);t&&document.activeElement!==t&&t.focus()},[l,T]);const _=e.useCallback(t=>{var u;n||(i(t),(u=r.current)==null||u.call(r,t))},[n]),v=e.useCallback(t=>{var u;n||t.target===a.current&&(i(s),(u=r.current)==null||u.call(r,s))},[n,a,s]),E=e.useCallback(t=>{var u,c;(u=a.current)!=null&&u.contains(t.relatedTarget)||(i(null),(c=f.current)==null||c.call(f),I.clearSelectionWithin(a.current))},[a]),d=e.useCallback(t=>{var c;if(n)return;t.target.closest("[data-segment]")||(t.preventDefault(),i(s),(c=r.current)==null||c.call(r,s))},[n,s]),k=e.useCallback((t,u)=>{var y;const c=o.indexOf(t);if(c===-1)return;const x=o[c+u];x!=null&&(i(x),(y=r.current)==null||y.call(r,x))},[o]),q=e.useCallback(t=>{k(t,1)},[k]),w=e.useCallback(t=>{k(t,-1)},[k]);return{focusedSegment:l,fieldTabIndex:n?-1:l===null?0:-1,handleSegmentFocus:_,handleFieldFocus:v,handleFieldBlur:E,handleFieldMouseDown:d,focusNext:q,focusPrevious:w}}exports.useDateFieldFocus=M;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),P=require("./DateField.utils.cjs.js");function j({disabled:l,fieldRef:i,segmentRefs:T,partsOrder:b,onSegmentFocusChange:d,onFieldBlur:x}){const[c,o]=r.useState(null),a=b[0],y=r.useRef(c);y.current=c;const e=r.useRef(d),k=r.useRef(x);r.useEffect(()=>{e.current=d,k.current=x},[d,x]),r.useEffect(()=>{if(c===null||c==="all")return;const t=T.current.get(c);t&&document.activeElement!==t&&t.focus()},[c,T]);const E=r.useCallback(t=>{var u;l||(o(t),(u=e.current)==null||u.call(e,t))},[l]),q=r.useCallback(t=>{var u;l||t.target===i.current&&(o(a),(u=e.current)==null||u.call(e,a))},[l,i,a]),v=r.useCallback(t=>{var n,s,f,_;if((n=i.current)!=null&&n.contains(t.relatedTarget))return;const u=(f=(s=t.target)==null?void 0:s.getAttribute)==null?void 0:f.call(s,"data-segment");u&&u!==y.current||(o(null),(_=k.current)==null||_.call(k),P.clearSelectionWithin(i.current))},[i]),w=r.useCallback(t=>{var n;if(l)return;t.target.closest("[data-segment]")||(t.preventDefault(),o(a),(n=e.current)==null||n.call(e,a))},[l,a]),D=r.useCallback((t,u)=>{var f;const n=b.indexOf(t);if(n===-1)return;const s=b[n+u];s!=null&&(o(s),(f=e.current)==null||f.call(e,s))},[b]),I=r.useCallback(t=>{D(t,1)},[D]),M=r.useCallback(t=>{D(t,-1)},[D]);return{focusedSegment:c,fieldTabIndex:l?-1:c===null?0:-1,handleSegmentFocus:E,handleFieldFocus:q,handleFieldBlur:v,handleFieldMouseDown:w,focusNext:I,focusPrevious:M}}exports.useDateFieldFocus=j;
@@ -1,71 +1,78 @@
1
- import { useState as j, useRef as E, useEffect as I, useCallback as e } from "react";
2
- import { clearSelectionWithin as m } from "./DateField.utils.es.js";
3
- function G({
4
- disabled: n,
5
- fieldRef: i,
6
- segmentRefs: v,
7
- partsOrder: f,
8
- onSegmentFocusChange: T,
9
- onFieldBlur: D
1
+ import { useState as d, useRef as y, useEffect as v, useCallback as o } from "react";
2
+ import { clearSelectionWithin as j } from "./DateField.utils.es.js";
3
+ function H({
4
+ disabled: s,
5
+ fieldRef: l,
6
+ segmentRefs: E,
7
+ partsOrder: x,
8
+ onSegmentFocusChange: m,
9
+ onFieldBlur: p
10
10
  }) {
11
- const [s, l] = j(null), o = f[0], r = E(T), a = E(D);
12
- I(() => {
13
- r.current = T, a.current = D;
14
- }, [T, D]), I(() => {
15
- if (s === null || s === "all") return;
16
- const t = v.current.get(s);
11
+ const [u, f] = d(null), i = x[0], I = y(u);
12
+ I.current = u;
13
+ const r = y(m), T = y(p);
14
+ v(() => {
15
+ r.current = m, T.current = p;
16
+ }, [m, p]), v(() => {
17
+ if (u === null || u === "all") return;
18
+ const t = E.current.get(u);
17
19
  t && document.activeElement !== t && t.focus();
18
- }, [s, v]);
19
- const k = e(
20
+ }, [u, E]);
21
+ const w = o(
20
22
  (t) => {
21
23
  var c;
22
- n || (l(t), (c = r.current) == null || c.call(r, t));
24
+ s || (f(t), (c = r.current) == null || c.call(r, t));
23
25
  },
24
- [n]
25
- ), w = e(
26
+ [s]
27
+ ), A = o(
26
28
  (t) => {
27
29
  var c;
28
- n || t.target === i.current && (l(o), (c = r.current) == null || c.call(r, o));
30
+ s || t.target === l.current && (f(i), (c = r.current) == null || c.call(r, i));
29
31
  },
30
- [n, i, o]
31
- ), M = e(
32
+ [s, l, i]
33
+ ), M = o(
32
34
  (t) => {
33
- var c, u;
34
- (c = i.current) != null && c.contains(t.relatedTarget) || (l(null), (u = a.current) == null || u.call(a), m(i.current));
35
+ var n, e, a, k;
36
+ if ((n = l.current) != null && n.contains(t.relatedTarget)) return;
37
+ const c = (a = (e = t.target) == null ? void 0 : e.getAttribute) == null ? void 0 : a.call(
38
+ e,
39
+ "data-segment"
40
+ );
41
+ c && c !== I.current || (f(null), (k = T.current) == null || k.call(T), j(l.current));
35
42
  },
36
- [i]
37
- ), N = e(
43
+ [l]
44
+ ), N = o(
38
45
  (t) => {
39
- var u;
40
- if (n) return;
41
- t.target.closest("[data-segment]") || (t.preventDefault(), l(o), (u = r.current) == null || u.call(r, o));
46
+ var n;
47
+ if (s) return;
48
+ t.target.closest("[data-segment]") || (t.preventDefault(), f(i), (n = r.current) == null || n.call(r, i));
42
49
  },
43
- [n, o]
44
- ), x = e(
50
+ [s, i]
51
+ ), D = o(
45
52
  (t, c) => {
46
- var y;
47
- const u = f.indexOf(t);
48
- if (u === -1) return;
49
- const p = f[u + c];
50
- p != null && (l(p), (y = r.current) == null || y.call(r, p));
53
+ var a;
54
+ const n = x.indexOf(t);
55
+ if (n === -1) return;
56
+ const e = x[n + c];
57
+ e != null && (f(e), (a = r.current) == null || a.call(r, e));
51
58
  },
52
- [f]
53
- ), P = e(
59
+ [x]
60
+ ), P = o(
54
61
  (t) => {
55
- x(t, 1);
62
+ D(t, 1);
56
63
  },
57
- [x]
58
- ), W = e(
64
+ [D]
65
+ ), W = o(
59
66
  (t) => {
60
- x(t, -1);
67
+ D(t, -1);
61
68
  },
62
- [x]
69
+ [D]
63
70
  );
64
71
  return {
65
- focusedSegment: s,
66
- fieldTabIndex: n ? -1 : s === null ? 0 : -1,
67
- handleSegmentFocus: k,
68
- handleFieldFocus: w,
72
+ focusedSegment: u,
73
+ fieldTabIndex: s ? -1 : u === null ? 0 : -1,
74
+ handleSegmentFocus: w,
75
+ handleFieldFocus: A,
69
76
  handleFieldBlur: M,
70
77
  handleFieldMouseDown: N,
71
78
  focusNext: P,
@@ -73,5 +80,5 @@ function G({
73
80
  };
74
81
  }
75
82
  export {
76
- G as useDateFieldFocus
83
+ H as useDateFieldFocus
77
84
  };
@@ -15,9 +15,11 @@ export interface UseDateFieldValidityReturn {
15
15
  allFilled: boolean;
16
16
  hasPartialValue: boolean;
17
17
  /** "Show error?" for value-driven invalidity. True when the user has
18
- * touched the field AND either:
19
- * - all segments are filled but combine to an invalid date (Feb 30), or
20
- * - some segments are filled, others empty, and focus has left the field. */
18
+ * touched the field AND (all segments filled but combine to an invalid
19
+ * date (Feb 30), OR some filled/some empty and focus has left).
20
+ * `minDate`/`maxDate` out-of-range values aren't flagged here — the
21
+ * built-in bound is a blur clamp (see `commitOnBlur`), not a validity
22
+ * constraint; use a `validationRule` for range errors/submit-blocking. */
21
23
  isInvalid: boolean;
22
24
  }
23
25
  export declare function useDateFieldValidity({ segments, currentValue, wasTouched, isFocused, }: UseDateFieldValidityArgs): UseDateFieldValidityReturn;
@@ -1 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("react"),t=require("./DateField.utils.cjs.js"),j=require("./DateField.validation.cjs.js");function G({value:a,defaultValue:A,onChange:x,minDate:R,maxDate:y,getClampAnnouncement:V}){const N=r.useRef(a!==void 0),F=N.current,[m,h]=r.useState(()=>t.segmentTextFromValue(F?a??null:A??null)),[D,_]=r.useState(!1),[C,M]=r.useState(""),c=r.useRef(m),f=r.useRef(new Set),d=r.useRef(!1),l=r.useRef(null),v={day:t.segmentNumber("day",m.day),month:t.segmentNumber("month",m.month),year:t.segmentNumber("year",m.year)},k=t.deriveValue(v),E=r.useRef(k),p=r.useRef(F?a??null:null),g=r.useRef(x),S=r.useRef(V);r.useEffect(()=>{g.current=x,S.current=V},[x,V]),r.useEffect(()=>()=>{l.current!=null&&cancelAnimationFrame(l.current)},[]),r.useEffect(()=>{if(!N.current||d.current||t.isSameDateValue(a??null,p.current))return;p.current=a??null;const e=t.segmentTextFromValue(a??null);c.current=e,h(e),E.current=t.deriveValueFromText(e)},[a]);const b=r.useCallback(e=>{var n;const s=t.deriveValueFromText(e);t.isSameDateValue(s,E.current)||(E.current=s,(n=g.current)==null||n.call(g,s))},[]),o=r.useCallback((e,s,{replace:n})=>{const u={...c.current,[e]:s};c.current=u,h(u),_(!0),b(u),n?f.current.add(e):f.current.delete(e)},[b]),q=r.useCallback((e,s)=>{const n=f.current.has(e)?"":c.current[e],u=j.tryAppendDigit(e,n,s);return u.rejected?{advanced:!1,rejected:!0}:(o(e,u.newBuffer,{replace:u.shouldAdvance}),{advanced:u.shouldAdvance,rejected:!1})},[o]),z=r.useCallback((e,s)=>{const n=c.current,u=t.segmentNumber(e,n[e]),T=t.getDaysInMonth(t.segmentNumber("year",n.year),t.segmentNumber("month",n.month)),i=t.adjustSegmentValue(e,u,s,{daysInMonth:T,today:t.todayParts()});return i==null?!1:(d.current=!0,o(e,String(i).padStart(j.SEGMENT_MAX_LENGTH[e],"0"),{replace:!0}),!0)},[o]),I=r.useCallback(e=>c.current[e]===""?{wasEmpty:!0}:(d.current=!0,o(e,"",{replace:!1}),{wasEmpty:!1}),[o]),O=r.useCallback(e=>{d.current=!0,f.current.add(e)},[]),B=r.useCallback(()=>{var T;d.current=!1;const e=c.current,s={day:t.normalizeSegmentText("day",e.day),month:t.normalizeSegmentText("month",e.month),year:t.normalizeSegmentText("year",e.year)},n=t.deriveValueFromText(s);let u=s;if(n!=null&&D&&!t.isDateInRange(n,R,y)){const i=t.clampDateToRange(n,R,y);if(u=t.segmentTextFromValue(i),!t.isSameDateValue(i,n)){const w=((T=S.current)==null?void 0:T.call(S,i))??"";w&&(l.current!=null&&cancelAnimationFrame(l.current),l.current=requestAnimationFrame(()=>{l.current=null,M(w)}))}}c.current=u,h(u),_(!0),b(u)},[b,D,t.dateKeyOrNull(R),t.dateKeyOrNull(y)]);return{segmentText:m,segmentValues:v,currentValue:k,isControlled:F,wasTouched:D,appendDigit:q,adjustSegment:z,clearSegment:I,beginSegmentEdit:O,commitOnBlur:B,clampAnnouncement:C}}exports.useDateFieldValue=G;
@@ -5,6 +5,23 @@ export interface UseDateFieldValueArgs {
5
5
  defaultValue?: Nullable<Date>;
6
6
  /** Fires on user-driven value transitions only, never on controlled `value` changes. */
7
7
  onChange?: (value: Nullable<Date>) => void;
8
+ /**
9
+ * Earliest allowed date (inclusive, compared by calendar day). Springs a
10
+ * touched value to this bound on blur (see `commitOnBlur`) — does not bound
11
+ * the year segment's spin/Home/End, which is free (see `adjustSegment`).
12
+ */
13
+ minDate?: Nullable<Date>;
14
+ /**
15
+ * Latest allowed date (inclusive, compared by calendar day). Springs a
16
+ * touched value to this bound on blur (see `commitOnBlur`) — does not bound
17
+ * the year segment's spin/Home/End, which is free (see `adjustSegment`).
18
+ */
19
+ maxDate?: Nullable<Date>;
20
+ /**
21
+ * Called when a touched value springs to a bound on blur; returns a localized
22
+ * message set on the polite live region. Omit → no announcement.
23
+ */
24
+ getClampAnnouncement?: (clampedDate: Date) => string;
8
25
  }
9
26
  export interface UseDateFieldValueReturn {
10
27
  segmentText: SegmentText;
@@ -17,21 +34,21 @@ export interface UseDateFieldValueReturn {
17
34
  * Increments, decrements, or jumps a segment to its min/max boundary.
18
35
  *
19
36
  * - Numeric `amount` (e.g. ±1, ±5): day/month wrap modularly; year clamps
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.
23
- * - `'min'` / `'max'`: jump to the lower/upper bound. No-op on year (no
24
- * meaningful bound until DF-10 adds minDate/maxDate).
37
+ * to `[YEAR_MIN, YEAR_MAX]` (free-spinning, independent of `minDate`/
38
+ * `maxDate` — see `DateField.utils.adjustSegmentValue`). An empty day/month
39
+ * segment seeds to a direction-based first/last valid value; an empty year
40
+ * seeds to the current year.
41
+ * - `'min'` / `'max'`: jump to the lower/upper bound. No-op on year (Home/End
42
+ * don't bound the year to `minDate`/`maxDate`).
25
43
  *
26
44
  * Follows the `appendDigit` mutation pattern: writes zero-padded `segmentText`,
27
45
  * sets `wasTouched`, calls `emitIfChanged`, and marks the segment in
28
46
  * `replaceNextRef` so a digit typed immediately after replaces rather than
29
47
  * appends.
30
48
  *
31
- * @returns `true` if the segment was adjusted, `false` on a no-op (currently
32
- * only year `'min'`/`'max'`, until DF-10 adds year bounds). The keyboard
33
- * dispatcher uses this to decide whether to `preventDefault` — a no-op leaves
34
- * the key to native (e.g. page scroll).
49
+ * @returns `true` if the segment was adjusted, `false` on a no-op (year
50
+ * `'min'`/`'max'`). The keyboard dispatcher uses this to decide whether to
51
+ * `preventDefault` — a no-op leaves the key to native (e.g. page scroll).
35
52
  */
36
53
  adjustSegment: (type: SegmentType, amount: SegmentAdjustment) => boolean;
37
54
  /**
@@ -50,5 +67,7 @@ export interface UseDateFieldValueReturn {
50
67
  };
51
68
  beginSegmentEdit: (type: SegmentType) => void;
52
69
  commitOnBlur: () => void;
70
+ /** Polite live-region message set when the blur clamp springs a value to a bound. */
71
+ clampAnnouncement: string;
53
72
  }
54
- export declare function useDateFieldValue({ value, defaultValue, onChange, }: UseDateFieldValueArgs): UseDateFieldValueReturn;
73
+ export declare function useDateFieldValue({ value, defaultValue, onChange, minDate, maxDate, getClampAnnouncement, }: UseDateFieldValueArgs): UseDateFieldValueReturn;
@@ -1,83 +1,103 @@
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
- onChange: x
1
+ import { useRef as c, useState as w, useEffect as N, useCallback as a } from "react";
2
+ import { segmentTextFromValue as b, segmentNumber as i, deriveValue as Q, isSameDateValue as v, deriveValueFromText as D, getDaysInMonth as U, adjustSegmentValue as Y, todayParts as Z, normalizeSegmentText as I, isDateInRange as $, clampDateToRange as C, dateKeyOrNull as k } from "./DateField.utils.es.js";
3
+ import { tryAppendDigit as ee, SEGMENT_MAX_LENGTH as te } from "./DateField.validation.es.js";
4
+ function ue({
5
+ value: s,
6
+ defaultValue: q,
7
+ onChange: T,
8
+ minDate: E,
9
+ maxDate: R,
10
+ getClampAnnouncement: V
8
11
  }) {
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);
16
- b(() => {
17
- f.current = x;
18
- }, [x]), b(() => {
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) => {
25
- var r;
26
- const t = N(e);
27
- M(t, y.current) || (y.current = t, (r = f.current) == null || r.call(f, t));
28
- }, []), a = o(
29
- (e, t, { replace: r }) => {
30
- const n = { ...c.current, [e]: t };
31
- c.current = n, S(n), V(!0), g(n), r ? i.current.add(e) : i.current.delete(e);
12
+ const M = c(s !== void 0), p = M.current, [m, A] = w(
13
+ () => b(p ? s ?? null : q ?? null)
14
+ ), [F, z] = w(!1), [H, K] = w(""), u = c(m), g = c(/* @__PURE__ */ new Set()), f = c(!1), o = c(null), B = {
15
+ day: i("day", m.day),
16
+ month: i("month", m.month),
17
+ year: i("year", m.year)
18
+ }, G = Q(B), j = c(G), O = c(p ? s ?? null : null), h = c(T), x = c(V);
19
+ N(() => {
20
+ h.current = T, x.current = V;
21
+ }, [T, V]), N(
22
+ () => () => {
23
+ o.current != null && cancelAnimationFrame(o.current);
32
24
  },
33
- [g]
34
- ), I = o(
35
- (e, t) => {
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 });
25
+ []
26
+ ), N(() => {
27
+ if (!M.current || f.current || v(s ?? null, O.current)) return;
28
+ O.current = s ?? null;
29
+ const e = b(s ?? null);
30
+ u.current = e, A(e), j.current = D(e);
31
+ }, [s]);
32
+ const y = a((e) => {
33
+ var t;
34
+ const n = D(e);
35
+ v(n, j.current) || (j.current = n, (t = h.current) == null || t.call(h, n));
36
+ }, []), l = a(
37
+ (e, n, { replace: t }) => {
38
+ const r = { ...u.current, [e]: n };
39
+ u.current = r, A(r), z(!0), y(r), t ? g.current.add(e) : g.current.delete(e);
38
40
  },
39
- [a]
40
- ), B = o(
41
- (e, 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, {
46
- daysInMonth: z,
47
- today: O()
41
+ [y]
42
+ ), L = a(
43
+ (e, n) => {
44
+ const t = g.current.has(e) ? "" : u.current[e], r = ee(e, t, n);
45
+ return r.rejected ? { advanced: !1, rejected: !0 } : (l(e, r.newBuffer, { replace: r.shouldAdvance }), { advanced: r.shouldAdvance, rejected: !1 });
46
+ },
47
+ [l]
48
+ ), P = a(
49
+ (e, n) => {
50
+ const t = u.current, r = i(e, t[e]), S = U(
51
+ i("year", t.year),
52
+ i("month", t.month)
53
+ ), d = Y(e, r, n, {
54
+ daysInMonth: S,
55
+ today: Z()
48
56
  });
49
- return j == null ? !1 : (m.current = !0, a(e, String(j).padStart(W[e], "0"), {
57
+ return d == null ? !1 : (f.current = !0, l(e, String(d).padStart(te[e], "0"), {
50
58
  replace: !0
51
59
  }), !0);
52
60
  },
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;
61
- const e = c.current, t = {
62
- day: T("day", e.day),
63
- month: T("month", e.month),
64
- year: T("year", e.year)
65
- };
66
- c.current = t, S(t), V(!0), g(t);
67
- }, [g]);
61
+ [l]
62
+ ), W = a(
63
+ (e) => u.current[e] === "" ? { wasEmpty: !0 } : (f.current = !0, l(e, "", { replace: !1 }), { wasEmpty: !1 }),
64
+ [l]
65
+ ), X = a((e) => {
66
+ f.current = !0, g.current.add(e);
67
+ }, []), J = a(() => {
68
+ var S;
69
+ f.current = !1;
70
+ const e = u.current, n = {
71
+ day: I("day", e.day),
72
+ month: I("month", e.month),
73
+ year: I("year", e.year)
74
+ }, t = D(n);
75
+ let r = n;
76
+ if (t != null && F && !$(t, E, R)) {
77
+ const d = C(t, E, R);
78
+ if (r = b(d), !v(d, t)) {
79
+ const _ = ((S = x.current) == null ? void 0 : S.call(x, d)) ?? "";
80
+ _ && (o.current != null && cancelAnimationFrame(o.current), o.current = requestAnimationFrame(() => {
81
+ o.current = null, K(_);
82
+ }));
83
+ }
84
+ }
85
+ u.current = r, A(r), z(!0), y(r);
86
+ }, [y, F, k(E), k(R)]);
68
87
  return {
69
- segmentText: d,
70
- segmentValues: p,
71
- currentValue: D,
72
- isControlled: h,
88
+ segmentText: m,
89
+ segmentValues: B,
90
+ currentValue: G,
91
+ isControlled: p,
73
92
  wasTouched: F,
74
- appendDigit: I,
75
- adjustSegment: B,
76
- clearSegment: G,
77
- beginSegmentEdit: _,
78
- commitOnBlur: k
93
+ appendDigit: L,
94
+ adjustSegment: P,
95
+ clearSegment: W,
96
+ beginSegmentEdit: X,
97
+ commitOnBlur: J,
98
+ clampAnnouncement: H
79
99
  };
80
100
  }
81
101
  export {
82
- K as useDateFieldValue
102
+ ue as useDateFieldValue
83
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viasat/beam-react",
3
- "version": "2.47.1",
3
+ "version": "2.48.0",
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.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",
63
+ "@viasat/beam-fonts": "2.48.0",
64
+ "@viasat/beam-shared": "2.48.0",
65
+ "@viasat/beam-styles": "2.48.0",
66
+ "@viasat/beam-tokens": "2.48.0",
67
+ "@viasat/beam-icons": "2.48.0",
68
+ "@viasat/beam-react-claude-plugin": "2.48.0",
69
69
  "clsx": "^1.2.1",
70
70
  "@floating-ui/react": "^0.26.18",
71
71
  "@stepperize/react": "^5.1.5",
@@ -1 +0,0 @@
1
- var w=require("../assets/DateField.css");const N=require("react/jsx-runtime"),F=require("clsx"),d=require("react"),M=require("./classNames.DC8Ra4sw.js"),q=require("../lib/wip/DateField/DateField.utils.cjs.js"),P="date-field",{baseClassNamePrefix:R,classModifierPrefix:k,subElementClassPrefix:r}=M.getBEMClassNames(P),c={field:`${r}field`,segments:`${r}segments`,segment:`${r}segment`,separator:`${r}separator`},u={"bm-light":"bm-light","bm-dark":"bm-dark","bm-inverse":"bm-inverse","bm-enterprise":"bm-enterprise","bm-consumer":"bm-consumer","bm-date-field":"bm-date-field","bm-date-field--disabled":"bm-date-field--disabled","bm-date-field--error":"bm-date-field--error","bm-date-field__field":"bm-date-field__field","bm-date-field__segment":"bm-date-field__segment","bm-date-field--read-only":"bm-date-field--read-only","bm-date-field--fluid":"bm-date-field--fluid","bm-date-field__segments":"bm-date-field__segments","bm-date-field__separator":"bm-date-field__separator"},I={day:"day",month:"month",year:"year"},$=({type:n,value:_,valueMax:g,displayValue:t,isPlaceholder:C,isActive:a,disabled:l,readOnly:o,onFocus:p,onBlur:x,onInput:E,onKeyDown:h,segmentRef:m})=>{const s=!l&&!o,f=d.useRef(null),v=d.useCallback(e=>{f.current=e,m(e)},[m]),D=e=>{if(!s)return;const b=e.currentTarget,i=e.nativeEvent.data;i!=null&&i.length===1&&E(n,i),b.textContent!==t&&(b.textContent=t)};return d.useLayoutEffect(()=>{if(!a||!s)return;const e=f.current;e&&q.selectElementContents(e)},[t,a,s]),N.jsx("span",{ref:v,role:"spinbutton","aria-label":I[n],"aria-valuenow":_??void 0,"aria-valuemin":1,"aria-valuemax":g,"aria-valuetext":t,"aria-disabled":l||void 0,"aria-readonly":o||void 0,contentEditable:s&&a,suppressContentEditableWarning:!0,tabIndex:a?0:-1,inputMode:s?"numeric":void 0,spellCheck:!1,autoCorrect:"off",autoCapitalize:"off","data-segment":n,"data-active":a,"data-placeholder":C,onFocus:p,onBlur:x,onInput:D,onKeyDown:e=>h(n,e),onMouseUp:e=>e.preventDefault(),className:F(u[c.segment]),children:t})};exports.DateFieldSegment=$;exports.baseClassNamePrefix=R;exports.classModifierPrefix=k;exports.staticDateFieldClassNames=c;exports.styles=u;