@viasat/beam-react 2.39.3 → 2.41.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,9 +1,14 @@
1
- import { ComponentPropsWithRef, ReactElement, FocusEvent } from 'react';
1
+ import { ComponentPropsWithRef, ReactElement, FocusEvent, KeyboardEvent } from 'react';
2
2
  import { Nullable } from '@viasat/beam-shared/utils/types';
3
3
  import { ThemeTypes } from '@viasat/beam-shared/utils/constants';
4
4
  import { FormValidator } from '@viasat/beam-shared/components/form';
5
5
  type DateFieldInputAttributes = Omit<ComponentPropsWithRef<'input'>, 'value' | 'defaultValue' | 'onChange' | 'min' | 'max' | 'type' | 'size' | 'ref' | 'form' | 'autoComplete' | 'inputMode'>;
6
6
  export type SegmentType = 'day' | 'month' | 'year';
7
+ /**
8
+ * Argument to `adjustSegment` / `adjustSegmentValue`.
9
+ * A numeric delta (e.g. ±1, ±5) or a boundary keyword for Home/End.
10
+ */
11
+ export type SegmentAdjustment = number | 'min' | 'max';
7
12
  export type FocusTarget = SegmentType | 'all' | null;
8
13
  /** Per-segment values. Month is 1-12 (NOT 0-11). */
9
14
  export interface SegmentValues {
@@ -97,6 +102,12 @@ export interface DateFieldSegmentProps {
97
102
  type: SegmentType;
98
103
  /** Numeric segment value — used for `aria-valuenow`. `null` when the segment has no committed value. */
99
104
  value: Nullable<number>;
105
+ /**
106
+ * The upper bound announced as `aria-valuemax`.
107
+ * For day: month-aware (e.g. 28 for Feb non-leap); for month: 12; for year: 9999.
108
+ * Computed by `DateField.Segments` so the segment itself stays a pure renderer.
109
+ */
110
+ valueMax: number;
100
111
  /** Pre-computed text to render inside the segment (buffer, formatted value, or placeholder). */
101
112
  displayValue: string;
102
113
  /** True when `displayValue` IS the placeholder (drives `data-placeholder` CSS hook). */
@@ -104,7 +115,9 @@ export interface DateFieldSegmentProps {
104
115
  isActive: boolean;
105
116
  disabled: boolean;
106
117
  readOnly: boolean;
118
+ /** Fires when the segment gains focus (Tab, click, or programmatic). */
107
119
  onFocus: () => void;
120
+ /** Fires when focus leaves the segment; `relatedTarget` drives field-exit detection. */
108
121
  onBlur: (event: FocusEvent<HTMLSpanElement>) => void;
109
122
  /**
110
123
  * Single-character input callback. DF-2 single-digit typing path. The
@@ -113,6 +126,12 @@ export interface DateFieldSegmentProps {
113
126
  * DF-13 will add a paste-aware branch for whole-value parsing.
114
127
  */
115
128
  onInput: (type: SegmentType, char: string) => void;
129
+ /**
130
+ * Fires on segment keydown. The orchestrator routes it into
131
+ * `useDateFieldKeyboard` (DF-3: ArrowLeft/Right segment nav, RTL-aware;
132
+ * DF-4/DF-5 extend with increment/clear).
133
+ */
134
+ onKeyDown: (type: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
116
135
  segmentRef: (element: HTMLSpanElement | null) => void;
117
136
  }
118
137
  export {};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./DateField.validation.cjs.js"),u={day:"",month:"",year:""},o=e=>e instanceof Date&&!Number.isNaN(e.getTime()),s=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},g=(e,t)=>e==null&&t==null?!0:e==null||t==null?!1:e.getTime()===t.getTime(),m=e=>{if(!o(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),c=e=>o(e)?{day:String(e.getDate()).padStart(2,"0"),month:String(e.getMonth()+1).padStart(2,"0"),year:String(e.getFullYear()).padStart(4,"0")}:u,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},S=e=>s({day:l("day",e.day),month:l("month",e.month),year:l("year",e.year)}),y=(e,t)=>t===""?"":t.padStart(i.SEGMENT_MAX_LENGTH[e],"0"),T=(e,t,n)=>t===""?{displayValue:n,isPlaceholder:!0}:{displayValue:t.padStart(i.SEGMENT_MAX_LENGTH[e],"0"),isPlaceholder:!1},p=e=>{const t=window.getSelection();if(!t)return;const n=document.createRange();n.selectNodeContents(e),t.removeAllRanges(),t.addRange(n)};exports.deriveValue=s;exports.deriveValueFromText=S;exports.getSegmentDisplay=T;exports.getSegmentOrder=d;exports.isSameDateValue=g;exports.normalizeSegmentText=y;exports.segmentNumber=l;exports.segmentTextFromValue=c;exports.selectElementContents=p;exports.toISODateString=m;
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,5 +1,88 @@
1
1
  import { Nullable } from '@viasat/beam-shared/utils/types';
2
- import { DateFieldPart, SegmentText, SegmentType, SegmentValues } from './DateField.types';
2
+ import { DateFieldPart, SegmentAdjustment, SegmentText, SegmentType, SegmentValues } from './DateField.types';
3
+ /**
4
+ * Absolute spin ceiling for day — independent of the current month.
5
+ *
6
+ * Intentional divergence (MUI-X model, not React Aria clamp): the day segment
7
+ * spins to this absolute max (31) even though `aria-valuemax` is month-aware
8
+ * (28–30, computed in `DateField.Segments`). So a user can spin ONE step past the
9
+ * announced ceiling into an out-of-range day (e.g. April 30 → 31); the validity
10
+ * layer surfaces that via `aria-invalid` rather than clamping to `daysInMonth`.
11
+ * The announced-vs-reachable gap is deliberate — see docs/adr/calendar.md (spin
12
+ * model). Out-of-range days (e.g. Feb 31) are caught by the validity layer, not here.
13
+ */
14
+ export declare const DAY_SPIN_MAX = 31;
15
+ /** Absolute maximum for month (1-based). */
16
+ export declare const MONTH_MAX = 12;
17
+ /**
18
+ * Announced aria-valuemax per segment type.
19
+ * Day uses the absolute calendar max (31); month-aware override for day is
20
+ * computed in `DateField.Segments` and passed as `valueMax` to `DateFieldSegment`.
21
+ */
22
+ export declare const SEGMENT_ARIA_MAX: Record<SegmentType, number>;
23
+ /** Clamps `n` to `[lo, hi]` (inclusive). */
24
+ export declare const clamp: (n: number, lo: number, hi: number) => number;
25
+ /**
26
+ * Modular wrap within a 1-based inclusive range `[1, max]`.
27
+ * Handles negative deltas correctly (e.g. 1 − 1 in a max-12 range → 12).
28
+ */
29
+ export declare const wrapInRange: (n: number, max: number) => number;
30
+ /**
31
+ * Returns the number of days in the given month/year combination.
32
+ *
33
+ * - `month` is 1-based (1 = January, 12 = December).
34
+ * - When `month` is null (unknown), returns 31 (conservative maximum).
35
+ * - When `month` is provided but `year` is null, uses {@link LEAP_YEAR_FALLBACK}
36
+ * so February correctly reports 29 days (leap-safe fallback).
37
+ */
38
+ export declare const getDaysInMonth: (year: Nullable<number>, month: Nullable<number>) => number;
39
+ /**
40
+ * Returns today's date parts as a plain object.
41
+ * Extracted so callers in the value hook and DF-8 can share the same helper.
42
+ */
43
+ export declare const todayParts: () => {
44
+ day: number;
45
+ month: number;
46
+ year: number;
47
+ };
48
+ /** Context passed into {@link adjustSegmentValue} — kept pure by the caller. */
49
+ export interface AdjustSegmentContext {
50
+ /** Days in the current month (use {@link getDaysInMonth} to compute). */
51
+ daysInMonth: number;
52
+ /** Today's local-date values used to seed an empty segment on the first press. */
53
+ today: {
54
+ day: number;
55
+ month: number;
56
+ year: number;
57
+ };
58
+ }
59
+ /**
60
+ * Computes the next numeric value for a date segment after an increment,
61
+ * decrement, or boundary jump.
62
+ *
63
+ * Returns `null` to signal "no change" (Home/End on the year segment, which
64
+ * has no meaningful bound until DF-10 adds minDate/maxDate).
65
+ *
66
+ * Rules:
67
+ * - **day spin (numeric delta)**: modular wrap within `[1, DAY_SPIN_MAX]` — the
68
+ * absolute calendar maximum. Out-of-range dates (e.g. Feb 31) are flagged
69
+ * invalid by the existing validity layer (`useDateFieldValidity`), not clamped here.
70
+ * - **day End (`'max'`)**: uses `ctx.daysInMonth` — the last valid day of the
71
+ * currently selected month (month-aware).
72
+ * - **month**: modular wrap within `[1, MONTH_MAX]`.
73
+ * - **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).
76
+ * - **`'min'`**: returns 1 for day/month, null for year.
77
+ * - **`'max'`**: returns `ctx.daysInMonth` for day (End → month-aware last
78
+ * valid day), MONTH_MAX for month, null for year.
79
+ *
80
+ * @param type - Segment kind (`'day'`, `'month'`, or `'year'`).
81
+ * @param current - Current numeric value of the segment, or `null` when empty.
82
+ * @param amount - Numeric delta (e.g. ±1, ±5) or `'min'`/`'max'` for Home/End.
83
+ * @param ctx - Pure context: days-in-month and today's date parts.
84
+ */
85
+ export declare const adjustSegmentValue: (type: SegmentType, current: Nullable<number>, amount: SegmentAdjustment, ctx: AdjustSegmentContext) => Nullable<number>;
3
86
  export declare const deriveValue: (segments: SegmentValues) => Nullable<Date>;
4
87
  export declare const isSameDateValue: (a: Nullable<Date>, b: Nullable<Date>) => boolean;
5
88
  export declare const toISODateString: (value: Nullable<Date>) => string;
@@ -24,3 +107,8 @@ export interface SegmentDisplay {
24
107
  export declare const getSegmentDisplay: (type: SegmentType, text: string, placeholder: string) => SegmentDisplay;
25
108
  /** Selects an element's entire textContent (whole-segment highlight). */
26
109
  export declare const selectElementContents: (element: HTMLElement) => void;
110
+ /** Clears the DOM selection when it currently lives inside `container`. Chrome
111
+ * leaves the whole-segment Range highlighted after the field blurs; Safari
112
+ * clears it automatically. Scoped to `container` so a selection elsewhere on
113
+ * the page is untouched. */
114
+ export declare const clearSelectionWithin: (container: HTMLElement | null) => void;
@@ -1,45 +1,74 @@
1
- import { SEGMENT_MAX_LENGTH as o } from "./DateField.validation.es.js";
2
- const s = { day: "", month: "", year: "" }, i = (e) => e instanceof Date && !Number.isNaN(e.getTime()), u = (e) => {
3
- const { day: t, month: n, year: r } = e;
4
- if (t == null || n == null || r == null) return null;
5
- const a = new Date(r, n - 1, t);
6
- return a.setFullYear(r), Number.isNaN(a.getTime()) || a.getFullYear() !== r || a.getMonth() !== n - 1 || a.getDate() !== t ? null : a;
7
- }, m = (e, t) => e == null && t == null ? !0 : e == null || t == null ? !1 : e.getTime() === t.getTime(), d = (e) => {
8
- if (!i(e)) return "";
9
- const t = String(e.getFullYear()).padStart(4, "0"), n = String(e.getMonth() + 1).padStart(2, "0"), r = String(e.getDate()).padStart(2, "0");
10
- return `${t}-${n}-${r}`;
11
- }, c = (e) => e.filter(
12
- (t) => t.type !== "literal"
13
- ).map((t) => t.type), y = (e) => i(e) ? {
14
- day: String(e.getDate()).padStart(2, "0"),
15
- month: String(e.getMonth() + 1).padStart(2, "0"),
16
- year: String(e.getFullYear()).padStart(4, "0")
17
- } : s, l = (e, t) => {
18
- if (t === "" || e === "year" && t.length < o.year) return null;
19
- const n = parseInt(t, 10);
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,
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;
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);
20
35
  return Number.isNaN(n) || n === 0 ? null : n;
21
- }, S = (e) => u({
22
- day: l("day", e.day),
23
- month: l("month", e.month),
24
- year: l("year", e.year)
25
- }), p = (e, t) => t === "" ? "" : t.padStart(o[e], "0"), f = (e, t, n) => t === "" ? { displayValue: n, isPlaceholder: !0 } : {
26
- displayValue: t.padStart(o[e], "0"),
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"),
27
42
  isPlaceholder: !1
28
- }, N = (e) => {
29
- const t = window.getSelection();
30
- if (!t) return;
43
+ }, F = (t) => {
44
+ const e = window.getSelection();
45
+ if (!e) return;
31
46
  const n = document.createRange();
32
- n.selectNodeContents(e), t.removeAllRanges(), t.addRange(n);
47
+ n.selectNodeContents(t), e.removeAllRanges(), e.addRange(n);
48
+ }, V = (t) => {
49
+ 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();
33
53
  };
34
54
  export {
35
- u as deriveValue,
36
- S as deriveValueFromText,
37
- f as getSegmentDisplay,
38
- c as getSegmentOrder,
39
- m as isSameDateValue,
40
- p as normalizeSegmentText,
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,
41
68
  l as segmentNumber,
42
- y as segmentTextFromValue,
43
- N as selectElementContents,
44
- d as toISODateString
69
+ A as segmentTextFromValue,
70
+ F as selectElementContents,
71
+ p as toISODateString,
72
+ N as todayParts,
73
+ g as wrapInRange
45
74
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("react");function M({disabled:n,fieldRef:i,segmentRefs:T,partsOrder:f,onSegmentFocusChange:x,onFieldBlur:k}){const[l,a]=c.useState(null),s=f[0],r=c.useRef(x),o=c.useRef(k);c.useEffect(()=>{r.current=x,o.current=k},[x,k]),c.useEffect(()=>{if(l===null||l==="all")return;const t=T.current.get(l);t&&document.activeElement!==t&&t.focus()},[l,T]);const b=c.useCallback(t=>{var u;n||(a(t),(u=r.current)==null||u.call(r,t))},[n]),y=c.useCallback(t=>{var u;n||t.target===i.current&&(a(s),(u=r.current)==null||u.call(r,s))},[n,i,s]),E=c.useCallback(t=>{var u,e;(u=i.current)!=null&&u.contains(t.relatedTarget)||(a(null),(e=o.current)==null||e.call(o))},[i]),v=c.useCallback(t=>{var e;if(n)return;t.target.closest("[data-segment]")||(t.preventDefault(),a(s),(e=r.current)==null||e.call(r,s))},[n,s]),I=c.useCallback(t=>{var D;const u=f.indexOf(t);if(u===-1)return;const e=f[u+1];e!=null&&(a(e),(D=r.current)==null||D.call(r,e))},[f]);return{focusedSegment:l,fieldTabIndex:n?-1:l===null?0:-1,handleSegmentFocus:b,handleFieldFocus:y,handleFieldBlur:E,handleFieldMouseDown:v,focusNext:I}}exports.useDateFieldFocus=M;
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,8 +1,8 @@
1
- import { FocusEvent, MouseEvent, MutableRefObject } from 'react';
1
+ import { FocusEvent, MouseEvent, MutableRefObject, RefObject } from 'react';
2
2
  import { FocusTarget, SegmentType } from './DateField.types';
3
3
  export interface UseDateFieldFocusArgs {
4
4
  disabled: boolean;
5
- fieldRef: MutableRefObject<HTMLDivElement | null>;
5
+ fieldRef: RefObject<HTMLDivElement>;
6
6
  segmentRefs: MutableRefObject<Map<SegmentType, HTMLSpanElement>>;
7
7
  /** Ordered segment types (literals stripped). En-US hardcoded; DF-8 derives from locale. */
8
8
  partsOrder: ReadonlyArray<SegmentType>;
@@ -19,5 +19,6 @@ export interface UseDateFieldFocusReturn {
19
19
  handleFieldBlur: (event: FocusEvent<HTMLElement>) => void;
20
20
  handleFieldMouseDown: (event: MouseEvent<HTMLDivElement>) => void;
21
21
  focusNext: (currentType: SegmentType) => void;
22
+ focusPrevious: (currentType: SegmentType) => void;
22
23
  }
23
24
  export declare function useDateFieldFocus({ disabled, fieldRef, segmentRefs, partsOrder, onSegmentFocusChange, onFieldBlur, }: UseDateFieldFocusArgs): UseDateFieldFocusReturn;
@@ -1,65 +1,77 @@
1
- import { useState as N, useRef as I, useEffect as k, useCallback as s } from "react";
2
- function z({
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({
3
4
  disabled: n,
4
- fieldRef: f,
5
- segmentRefs: D,
6
- partsOrder: o,
7
- onSegmentFocusChange: a,
8
- onFieldBlur: T
5
+ fieldRef: i,
6
+ segmentRefs: v,
7
+ partsOrder: f,
8
+ onSegmentFocusChange: T,
9
+ onFieldBlur: D
9
10
  }) {
10
- const [e, i] = N(null), l = o[0], r = I(a), x = I(T);
11
- k(() => {
12
- r.current = a, x.current = T;
13
- }, [a, T]), k(() => {
14
- if (e === null || e === "all") return;
15
- const t = D.current.get(e);
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);
16
17
  t && document.activeElement !== t && t.focus();
17
- }, [e, D]);
18
- const p = s(
18
+ }, [s, v]);
19
+ const k = e(
19
20
  (t) => {
20
- var u;
21
- n || (i(t), (u = r.current) == null || u.call(r, t));
21
+ var c;
22
+ n || (l(t), (c = r.current) == null || c.call(r, t));
22
23
  },
23
24
  [n]
24
- ), v = s(
25
+ ), w = e(
25
26
  (t) => {
26
- var u;
27
- n || t.target === f.current && (i(l), (u = r.current) == null || u.call(r, l));
27
+ var c;
28
+ n || t.target === i.current && (l(o), (c = r.current) == null || c.call(r, o));
28
29
  },
29
- [n, f, l]
30
- ), w = s(
30
+ [n, i, o]
31
+ ), M = e(
31
32
  (t) => {
32
- var u, c;
33
- (u = f.current) != null && u.contains(t.relatedTarget) || (i(null), (c = x.current) == null || c.call(x));
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));
34
35
  },
35
- [f]
36
- ), y = s(
36
+ [i]
37
+ ), N = e(
37
38
  (t) => {
38
- var c;
39
+ var u;
39
40
  if (n) return;
40
- t.target.closest("[data-segment]") || (t.preventDefault(), i(l), (c = r.current) == null || c.call(r, l));
41
+ t.target.closest("[data-segment]") || (t.preventDefault(), l(o), (u = r.current) == null || u.call(r, o));
41
42
  },
42
- [n, l]
43
- ), M = s(
44
- (t) => {
45
- var E;
46
- const u = o.indexOf(t);
43
+ [n, o]
44
+ ), x = e(
45
+ (t, c) => {
46
+ var y;
47
+ const u = f.indexOf(t);
47
48
  if (u === -1) return;
48
- const c = o[u + 1];
49
- c != null && (i(c), (E = r.current) == null || E.call(r, c));
49
+ const p = f[u + c];
50
+ p != null && (l(p), (y = r.current) == null || y.call(r, p));
51
+ },
52
+ [f]
53
+ ), P = e(
54
+ (t) => {
55
+ x(t, 1);
56
+ },
57
+ [x]
58
+ ), W = e(
59
+ (t) => {
60
+ x(t, -1);
50
61
  },
51
- [o]
62
+ [x]
52
63
  );
53
64
  return {
54
- focusedSegment: e,
55
- fieldTabIndex: n ? -1 : e === null ? 0 : -1,
56
- handleSegmentFocus: p,
57
- handleFieldFocus: v,
58
- handleFieldBlur: w,
59
- handleFieldMouseDown: y,
60
- focusNext: M
65
+ focusedSegment: s,
66
+ fieldTabIndex: n ? -1 : s === null ? 0 : -1,
67
+ handleSegmentFocus: k,
68
+ handleFieldFocus: w,
69
+ handleFieldBlur: M,
70
+ handleFieldMouseDown: N,
71
+ focusNext: P,
72
+ focusPrevious: W
61
73
  };
62
74
  }
63
75
  export {
64
- z as useDateFieldFocus
76
+ G as useDateFieldFocus
65
77
  };
@@ -0,0 +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;
@@ -0,0 +1,44 @@
1
+ import { KeyboardEvent, RefObject } from 'react';
2
+ import { SegmentAdjustment, SegmentType } from './DateField.types';
3
+ /** Per-call context passed to each key binding. */
4
+ export interface SegmentKeyContext {
5
+ /** Segment the key event fired on. */
6
+ segment: SegmentType;
7
+ /** The originating keydown event. */
8
+ event: KeyboardEvent<HTMLSpanElement>;
9
+ /** Whether the field is rendered right-to-left. */
10
+ isRTL: boolean;
11
+ }
12
+ /**
13
+ * A key binding: runs the action for one key, given the call context, and
14
+ * returns whether it handled the key. The dispatcher `preventDefault`s only when
15
+ * a binding returns `true`, so a binding can decline (return `false`) to leave
16
+ * the key to the browser's native default (e.g. page scroll).
17
+ */
18
+ export type SegmentKeyBinding = (ctx: SegmentKeyContext) => boolean;
19
+ export interface UseDateFieldKeyboardArgs {
20
+ /** When true, the dispatcher ignores all keys. */
21
+ disabled: boolean;
22
+ /**
23
+ * When true, value-mutation keys (ArrowUp/Down, PageUp/Down, Home, End) are
24
+ * left unbound so they fall through to the browser (native page scroll);
25
+ * only the navigation keys (ArrowLeft/Right) are bound. Blocks value mutation
26
+ * without suppressing scroll.
27
+ */
28
+ readOnly: boolean;
29
+ /** Field root ref, used to detect RTL direction. */
30
+ fieldRef: RefObject<HTMLDivElement>;
31
+ /** Move focus to the next segment in `PARTS_ORDER`. */
32
+ focusNext: (segment: SegmentType) => void;
33
+ /** Move focus to the previous segment in `PARTS_ORDER`. */
34
+ focusPrevious: (segment: SegmentType) => void;
35
+ /**
36
+ * Increment, decrement, or jump a segment to its min/max boundary.
37
+ * Provided by `useDateFieldValue`. Numeric `amount` wraps day/month and
38
+ * clamps year; `'min'`/`'max'` map to Home/End respectively. Returns `false`
39
+ * on a no-op (year `'min'`/`'max'` until DF-10 adds year bounds) so the
40
+ * dispatcher leaves the key to native page scroll.
41
+ */
42
+ adjustSegment: (type: SegmentType, amount: SegmentAdjustment) => boolean;
43
+ }
44
+ export declare function useDateFieldKeyboard({ disabled, readOnly, fieldRef, focusNext, focusPrevious, adjustSegment, }: UseDateFieldKeyboardArgs): (segment: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
@@ -0,0 +1,45 @@
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
9
+ }) {
10
+ const y = u(
11
+ () => {
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: n }) => ((n ? l : t)(r), !0),
16
+ ArrowLeft: ({ segment: r, isRTL: n }) => ((n ? t : l)(r), !0)
17
+ };
18
+ return p ? o : {
19
+ ...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
28
+ };
29
+ },
30
+ [i, t, l, p]
31
+ );
32
+ return K(
33
+ (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();
39
+ },
40
+ [e, y, w]
41
+ );
42
+ }
43
+ export {
44
+ A as useDateFieldKeyboard
45
+ };
@@ -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 j({value:u,defaultValue:F,onChange:m}){const T=t.useRef(u!==void 0),f=T.current,[c,g]=t.useState(()=>r.segmentTextFromValue(f?u??null:F??null)),[h,S]=t.useState(!1),s=t.useRef(c),a=t.useRef(new Set),x=t.useRef(!1),V={day:r.segmentNumber("day",c.day),month:r.segmentNumber("month",c.month),year:r.segmentNumber("year",c.year)},y=r.deriveValue(V),b=t.useRef(y),D=t.useRef(f?u??null:null),l=t.useRef(m);t.useEffect(()=>{l.current=m},[m]),t.useEffect(()=>{if(!T.current||x.current||r.isSameDateValue(u??null,D.current))return;D.current=u??null;const e=r.segmentTextFromValue(u??null);s.current=e,g(e),b.current=r.deriveValueFromText(e)},[u]);const o=t.useCallback(e=>{var i;const n=r.deriveValueFromText(e);r.isSameDateValue(n,b.current)||(b.current=n,(i=l.current)==null||i.call(l,n))},[]),_=t.useCallback((e,n)=>{const i=a.current.has(e)?"":s.current[e],d=E.tryAppendDigit(e,i,n);if(d.rejected)return{advanced:!1,rejected:!0};const R={...s.current,[e]:d.newBuffer};return s.current=R,g(R),S(!0),o(R),d.shouldAdvance?a.current.add(e):a.current.delete(e),{advanced:d.shouldAdvance,rejected:!1}},[o]),v=t.useCallback(e=>{x.current=!0,a.current.add(e)},[]),w=t.useCallback(()=>{x.current=!1;const e=s.current,n={day:r.normalizeSegmentText("day",e.day),month:r.normalizeSegmentText("month",e.month),year:r.normalizeSegmentText("year",e.year)};s.current=n,g(n),S(!0),o(n)},[o]);return{segmentText:c,segmentValues:V,currentValue:y,isControlled:f,wasTouched:h,appendDigit:_,beginSegmentEdit:v,commitOnBlur:w}}exports.useDateFieldValue=j;
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,5 +1,5 @@
1
1
  import { Nullable } from '@viasat/beam-shared/utils/types';
2
- import { AppendDigitResult, SegmentText, SegmentType, SegmentValues } from './DateField.types';
2
+ import { AppendDigitResult, SegmentAdjustment, SegmentText, SegmentType, SegmentValues } from './DateField.types';
3
3
  export interface UseDateFieldValueArgs {
4
4
  value?: Nullable<Date>;
5
5
  defaultValue?: Nullable<Date>;
@@ -13,6 +13,25 @@ export interface UseDateFieldValueReturn {
13
13
  isControlled: boolean;
14
14
  wasTouched: boolean;
15
15
  appendDigit: (type: SegmentType, digit: string) => AppendDigitResult;
16
+ /**
17
+ * Increments, decrements, or jumps a segment to its min/max boundary.
18
+ *
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.
21
+ * - `'min'` / `'max'`: jump to the lower/upper bound. No-op on year (no
22
+ * meaningful bound until DF-10 adds minDate/maxDate).
23
+ *
24
+ * Follows the `appendDigit` mutation pattern: writes zero-padded `segmentText`,
25
+ * sets `wasTouched`, calls `emitIfChanged`, and marks the segment in
26
+ * `replaceNextRef` so a digit typed immediately after replaces rather than
27
+ * appends.
28
+ *
29
+ * @returns `true` if the segment was adjusted, `false` on a no-op (currently
30
+ * only year `'min'`/`'max'`, until DF-10 adds year bounds). The keyboard
31
+ * dispatcher uses this to decide whether to `preventDefault` — a no-op leaves
32
+ * the key to native (e.g. page scroll).
33
+ */
34
+ adjustSegment: (type: SegmentType, amount: SegmentAdjustment) => boolean;
16
35
  beginSegmentEdit: (type: SegmentType) => void;
17
36
  commitOnBlur: () => void;
18
37
  }