@viasat/beam-react 2.64.0 → 2.66.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.
Files changed (37) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/assets/dataTable.css +1 -1
  3. package/chunks/{dataTable.B_4qCCp1.js → dataTable.B2F2FRDV.js} +5 -3
  4. package/chunks/dataTable.I3f-w2wt.js +1 -0
  5. package/lib/wip/DataTable/DataTable.Body.cjs.js +1 -1
  6. package/lib/wip/DataTable/DataTable.Body.es.js +1 -1
  7. package/lib/wip/DataTable/DataTable.Cell.cjs.js +1 -1
  8. package/lib/wip/DataTable/DataTable.Cell.es.js +1 -1
  9. package/lib/wip/DataTable/DataTable.ColumnHeader.cjs.js +1 -1
  10. package/lib/wip/DataTable/DataTable.ColumnHeader.es.js +1 -1
  11. package/lib/wip/DataTable/DataTable.Footer.cjs.js +1 -1
  12. package/lib/wip/DataTable/DataTable.Footer.es.js +1 -1
  13. package/lib/wip/DataTable/DataTable.Head.cjs.js +1 -1
  14. package/lib/wip/DataTable/DataTable.Head.es.js +27 -10
  15. package/lib/wip/DataTable/DataTable.Header.cjs.js +1 -1
  16. package/lib/wip/DataTable/DataTable.Header.es.js +1 -1
  17. package/lib/wip/DataTable/DataTable.Row.cjs.js +1 -1
  18. package/lib/wip/DataTable/DataTable.Row.es.js +1 -1
  19. package/lib/wip/DataTable/DataTable.Toolbar.cjs.js +1 -1
  20. package/lib/wip/DataTable/DataTable.Toolbar.es.js +1 -1
  21. package/lib/wip/DataTable/DataTable.cjs.js +1 -1
  22. package/lib/wip/DataTable/DataTable.columns.d.ts +3 -3
  23. package/lib/wip/DataTable/DataTable.es.js +1 -1
  24. package/lib/wip/DataTable/DataTable.types.d.ts +11 -3
  25. package/lib/wip/DateField/DateField.cjs.js +1 -1
  26. package/lib/wip/DateField/DateField.d.ts +2 -2
  27. package/lib/wip/DateField/DateField.es.js +220 -194
  28. package/lib/wip/DateField/DateField.types.d.ts +17 -0
  29. package/lib/wip/DateField/index.d.ts +1 -1
  30. package/lib/wip/DateField/useDateFieldFocus.cjs.js +1 -1
  31. package/lib/wip/DateField/useDateFieldFocus.d.ts +1 -1
  32. package/lib/wip/DateField/useDateFieldFocus.es.js +52 -53
  33. package/lib/wip/DateField/useDateFieldValue.cjs.js +1 -1
  34. package/lib/wip/DateField/useDateFieldValue.d.ts +7 -0
  35. package/lib/wip/DateField/useDateFieldValue.es.js +79 -75
  36. package/package.json +7 -7
  37. package/chunks/dataTable.B2EH91vH.js +0 -1
@@ -1,245 +1,271 @@
1
- import { jsxs as B, jsx as a } from "react/jsx-runtime";
2
- import Re from "clsx";
3
- import { forwardRef as Ce, useMemo as Ee, useCallback as Oe } from "react";
4
- import { s as r, b as Be, c as i, a as m } from "../../../chunks/DateField.Segment.BMXzpxgl.js";
5
- import { t as Le } from "../../../chunks/constants.Cruz2A1w.js";
6
- import { i as Ve } from "../../../chunks/helpers.CiQfGwdc.js";
7
- import { H as Te } from "../../../chunks/form.context.BDYA2JQs.js";
8
- import { LabelProvider as Ae } from "../../Form/contexts/label.context.es.js";
9
- import { HelperTextProvider as Pe } from "../../Form/contexts/helperText.context.es.js";
10
- import { useUniversalRef as qe } from "../../Form/hooks/useUniversalRef.hook.es.js";
11
- import { useIsMounted as Ke } from "../../../utils/hooks/useIsMounted.es.js";
12
- import { ErrorBoundary as He } from "../ErrorBoundary/ErrorBoundary.es.js";
13
- import { DateFieldSegments as We } from "./DateField.Segments.es.js";
14
- import { useDevMinMaxWarning as Ye, useDevInvalidValueWarning as _e } from "./DateField.devWarnings.es.js";
15
- import { getDateParts as $e, getSegmentOrder as je, toISODateString as ke, DEFAULT_LOCALE as L } from "./DateField.utils.es.js";
16
- import { useDateFieldFocus as Ue } from "./useDateFieldFocus.es.js";
17
- import { useDateFieldForm as ze } from "./useDateFieldForm.es.js";
18
- import { useDateFieldKeyboard as Ge } from "./useDateFieldKeyboard.es.js";
19
- import { useDateFieldSegments as Je } from "./useDateFieldSegments.es.js";
20
- import { useDateFieldValidity as Qe } from "./useDateFieldValidity.es.js";
21
- import { useDateFieldValue as Xe } from "./useDateFieldValue.es.js";
22
- import { useInvalidState as Ze } from "./useInvalidState.es.js";
23
- const ea = "MM/DD/YYYY", aa = () => {
24
- process.env.NODE_ENV !== "production" && console.warn(
25
- "DateField: segments failed to render; showing a static fallback."
26
- );
27
- }, Ma = Ce(
1
+ import { jsxs as Y, jsx as t } from "react/jsx-runtime";
2
+ import Pe from "clsx";
3
+ import { forwardRef as qe, useRef as c, useMemo as He, useCallback as o } from "react";
4
+ import { s, b as Ke, c as u, a as g } from "../../../chunks/DateField.Segment.BMXzpxgl.js";
5
+ import { t as je } from "../../../chunks/constants.Cruz2A1w.js";
6
+ import { i as We } from "../../../chunks/helpers.CiQfGwdc.js";
7
+ import { H as Ye } from "../../../chunks/form.context.BDYA2JQs.js";
8
+ import { LabelProvider as _e } from "../../Form/contexts/label.context.es.js";
9
+ import { HelperTextProvider as $e } from "../../Form/contexts/helperText.context.es.js";
10
+ import { useIsMounted as ke } from "../../../utils/hooks/useIsMounted.es.js";
11
+ import { mergeRefs as Ue } from "../../../utils/functions.es.js";
12
+ import { ErrorBoundary as ze } from "../ErrorBoundary/ErrorBoundary.es.js";
13
+ import { DateFieldSegments as Ge } from "./DateField.Segments.es.js";
14
+ import { useDevMinMaxWarning as Je, useDevInvalidValueWarning as Qe } from "./DateField.devWarnings.es.js";
15
+ import { getDateParts as Xe, getSegmentOrder as Ze, toISODateString as er, DEFAULT_LOCALE as _ } from "./DateField.utils.es.js";
16
+ import { useDateFieldFocus as rr } from "./useDateFieldFocus.es.js";
17
+ import { useDateFieldForm as ar } from "./useDateFieldForm.es.js";
18
+ import { useDateFieldKeyboard as tr } from "./useDateFieldKeyboard.es.js";
19
+ import { useDateFieldSegments as sr } from "./useDateFieldSegments.es.js";
20
+ import { useDateFieldValidity as nr } from "./useDateFieldValidity.es.js";
21
+ import { useDateFieldValue as lr } from "./useDateFieldValue.es.js";
22
+ import { useInvalidState as or } from "./useInvalidState.es.js";
23
+ const ir = "MM/DD/YYYY", dr = () => {
24
+ process.env.NODE_ENV !== "production" && console.warn("DateField: segments failed to render; showing a static fallback.");
25
+ }, Br = qe(
28
26
  function({
29
- value: u,
30
- defaultValue: c,
31
- onChange: V,
32
- minDate: f,
33
- maxDate: p,
34
- getClampAnnouncement: T,
35
- locale: A,
36
- label: g = null,
37
- helperText: b = null,
38
- error: v,
39
- hideRequiredMarker: P = !1,
40
- validationRules: q,
41
- width: K,
42
- theme: D,
43
- fluid: H = !1,
44
- disabled: W = !1,
45
- readOnly: Y = !1,
46
- required: _ = !1,
47
- name: F,
48
- id: $,
49
- className: j,
50
- style: k,
51
- "aria-label": U,
52
- "aria-describedby": z,
53
- "aria-labelledby": G,
54
- ...J
55
- }, Q) {
27
+ value: v,
28
+ defaultValue: D,
29
+ onChange: $,
30
+ minDate: F,
31
+ maxDate: h,
32
+ getClampAnnouncement: k,
33
+ locale: U,
34
+ label: S = null,
35
+ helperText: x = null,
36
+ error: y,
37
+ hideRequiredMarker: z = !1,
38
+ validationRules: G,
39
+ width: J,
40
+ theme: I,
41
+ fluid: Q = !1,
42
+ disabled: X = !1,
43
+ readOnly: Z = !1,
44
+ required: ee = !1,
45
+ name: M,
46
+ id: re,
47
+ className: ae,
48
+ style: te,
49
+ "aria-label": se,
50
+ "aria-describedby": ne,
51
+ "aria-labelledby": le,
52
+ ...oe
53
+ }, R) {
56
54
  const {
57
55
  disabled: e,
58
- readOnly: t,
59
- required: h,
60
- invalid: X,
61
- errorMessageProvided: S,
62
- defaultValue: Z,
63
- errorId: x,
64
- helperTextId: ee,
65
- validationErrorsId: ae,
66
- labelId: y,
67
- ariaDescribedBy: re,
68
- ariaLabelledBy: se,
69
- showErrors: oe
70
- } = ze({
71
- name: F,
72
- disabled: W,
73
- readOnly: Y,
74
- required: _,
75
- defaultValue: c,
76
- error: v,
77
- hasHelperText: !!b,
78
- hasLabel: !!g,
79
- validationRules: q,
80
- ariaDescribedBy: z,
81
- ariaLabelledBy: G
56
+ readOnly: n,
57
+ required: E,
58
+ invalid: ie,
59
+ errorMessageProvided: N,
60
+ defaultValue: de,
61
+ errorId: O,
62
+ helperTextId: ce,
63
+ validationErrorsId: ue,
64
+ labelId: w,
65
+ ariaDescribedBy: me,
66
+ ariaLabelledBy: fe,
67
+ showErrors: pe
68
+ } = ar({
69
+ name: M,
70
+ disabled: X,
71
+ readOnly: Z,
72
+ required: ee,
73
+ defaultValue: D,
74
+ error: y,
75
+ hasHelperText: !!x,
76
+ hasLabel: !!S,
77
+ validationRules: G,
78
+ ariaDescribedBy: ne,
79
+ ariaLabelledBy: le
82
80
  });
83
- Ye(f, p), _e(u, c);
84
- const { refFn: ie, ref: I } = qe(Q), { segmentRefs: te, registerSegmentRef: le } = Je(), ne = A ?? L, M = Ke(), l = $e(M ? ne : L), N = Ee(() => je(l), [l]), {
85
- segmentText: de,
86
- segmentValues: w,
87
- currentValue: R,
88
- wasTouched: me,
89
- appendDigit: C,
90
- adjustSegment: ue,
91
- clearSegment: ce,
92
- beginSegmentEdit: fe,
93
- commitOnBlur: pe,
94
- clampAnnouncement: ge
95
- } = Xe({
96
- value: u,
97
- defaultValue: Z,
98
- onChange: V,
99
- minDate: f,
100
- maxDate: p,
101
- getClampAnnouncement: T
81
+ Je(F, h), Qe(v, D);
82
+ const l = c(null), { segmentRefs: be, registerSegmentRef: ge } = sr(), ve = U ?? _, C = ke(), m = Xe(C ? ve : _), i = He(() => Ze(m), [m]), {
83
+ segmentText: De,
84
+ segmentValues: L,
85
+ currentValue: B,
86
+ wasTouched: Fe,
87
+ appendDigit: V,
88
+ adjustSegment: he,
89
+ clearSegment: Se,
90
+ clearAll: T,
91
+ beginSegmentEdit: xe,
92
+ commitOnBlur: ye,
93
+ clampAnnouncement: Ie
94
+ } = lr({
95
+ value: v,
96
+ defaultValue: de,
97
+ onChange: $,
98
+ minDate: F,
99
+ maxDate: h,
100
+ getClampAnnouncement: k
102
101
  }), {
103
- focusedSegment: E,
104
- fieldTabIndex: be,
105
- handleSegmentFocus: O,
106
- handleFieldFocus: ve,
107
- handleFieldBlur: De,
108
- handleFieldMouseDown: Fe,
109
- focusNext: n,
110
- focusPrevious: he
111
- } = Ue({
102
+ focusedSegment: A,
103
+ fieldTabIndex: Me,
104
+ handleSegmentFocus: d,
105
+ handleFieldFocus: Re,
106
+ handleFieldBlur: Ee,
107
+ handleFieldMouseDown: Ne,
108
+ focusNext: f,
109
+ focusPrevious: Oe
110
+ } = rr({
112
111
  disabled: e,
113
- fieldRef: I,
114
- segmentRefs: te,
115
- partsOrder: N,
116
- onSegmentFocusChange: fe,
117
- onFieldBlur: pe
118
- }), Se = Ge({
112
+ fieldRef: l,
113
+ segmentRefs: be,
114
+ partsOrder: i,
115
+ onSegmentFocusChange: xe,
116
+ onFieldBlur: ye
117
+ }), we = tr({
119
118
  disabled: e,
120
- readOnly: t,
121
- fieldRef: I,
122
- focusNext: n,
123
- focusPrevious: he,
124
- adjustSegment: ue,
125
- clearSegment: ce
126
- }), { isInvalid: xe } = Qe({
127
- segments: w,
128
- currentValue: R,
129
- wasTouched: me,
130
- isFocused: E !== null
131
- }), ye = Oe(
132
- (s, o) => {
133
- const { advanced: we } = C(s, o);
134
- we && n(s);
119
+ readOnly: n,
120
+ fieldRef: l,
121
+ focusNext: f,
122
+ focusPrevious: Oe,
123
+ adjustSegment: he,
124
+ clearSegment: Se
125
+ }), { isInvalid: Ce } = nr({
126
+ segments: L,
127
+ currentValue: B,
128
+ wasTouched: Fe,
129
+ isFocused: A !== null
130
+ }), Le = o(
131
+ (r, a) => {
132
+ const { advanced: b } = V(r, a);
133
+ b && f(r);
135
134
  },
136
- [C, n]
137
- ), d = Ze({
138
- formInvalid: X,
139
- valueInvalid: xe
140
- }), Ie = M && Ve() ? "textbox" : "spinbutton", Me = (s) => {
135
+ [V, f]
136
+ ), p = or({
137
+ formInvalid: ie,
138
+ valueInvalid: Ce
139
+ }), Be = C && We() ? "textbox" : "spinbutton", P = o(
140
+ (r) => {
141
+ e || d(i[0], r);
142
+ },
143
+ [e, d, i]
144
+ ), q = o(() => {
145
+ var a;
146
+ if (e) return;
147
+ const r = document.activeElement;
148
+ r instanceof HTMLElement && r !== l.current && ((a = l.current) != null && a.contains(r)) && r.blur();
149
+ }, [e]), H = o(() => {
150
+ e || n || T();
151
+ }, [e, n, T]), K = c(P), j = c(q), W = c(H);
152
+ K.current = P, j.current = q, W.current = H;
153
+ const Ve = o(
154
+ (r) => {
155
+ const a = r ? Object.assign(r, {
156
+ focus: (b) => K.current(b),
157
+ blur: () => j.current(),
158
+ clear: () => W.current()
159
+ }) : null;
160
+ Ue(
161
+ l,
162
+ R
163
+ )(a);
164
+ },
165
+ [R]
166
+ ), Te = (r) => {
141
167
  if (e) return;
142
- const o = s.target.closest("label");
143
- !o || o.id !== y || (s.preventDefault(), O(N[0]));
144
- }, Ne = Re(
145
- r[Be],
146
- D && Le(D),
147
- H && r[`${i}fluid`],
148
- d && r[`${i}error`],
149
- e && r[`${i}disabled`],
150
- t && r[`${i}read-only`],
151
- j
168
+ const a = r.target.closest("label");
169
+ !a || a.id !== w || (r.preventDefault(), d(i[0]));
170
+ }, Ae = Pe(
171
+ s[Ke],
172
+ I && je(I),
173
+ Q && s[`${u}fluid`],
174
+ p && s[`${u}error`],
175
+ e && s[`${u}disabled`],
176
+ n && s[`${u}read-only`],
177
+ ae
152
178
  );
153
- return /* @__PURE__ */ B(
179
+ return /* @__PURE__ */ Y(
154
180
  "div",
155
181
  {
156
- className: Ne,
157
- style: { ...k, maxWidth: K },
158
- onMouseDownCapture: Me,
182
+ className: Ae,
183
+ style: { ...te, maxWidth: J },
184
+ onMouseDownCapture: Te,
159
185
  children: [
160
- /* @__PURE__ */ a(
161
- Ae,
186
+ /* @__PURE__ */ t(
187
+ _e,
162
188
  {
163
- ctxId: y,
189
+ ctxId: w,
164
190
  ctxDisabled: e,
165
- ctxRequired: h && !P,
166
- children: g
191
+ ctxRequired: E && !z,
192
+ children: S
167
193
  }
168
194
  ),
169
- /* @__PURE__ */ a(
195
+ /* @__PURE__ */ t(
170
196
  "div",
171
197
  {
172
- ...J,
173
- ref: ie,
174
- id: $,
198
+ ...oe,
199
+ ref: Ve,
200
+ id: re,
175
201
  role: "group",
176
- "aria-label": U,
177
- "aria-labelledby": se,
202
+ "aria-label": se,
203
+ "aria-labelledby": fe,
178
204
  "aria-disabled": e || void 0,
179
- "aria-required": h || void 0,
180
- "aria-invalid": d || void 0,
181
- "aria-describedby": re,
182
- "aria-errormessage": S ? x : void 0,
183
- tabIndex: be,
184
- className: r[m.field],
185
- onMouseDown: Fe,
186
- onFocus: ve,
187
- children: /* @__PURE__ */ a(
188
- He,
205
+ "aria-required": E || void 0,
206
+ "aria-invalid": p || void 0,
207
+ "aria-describedby": me,
208
+ "aria-errormessage": N ? O : void 0,
209
+ tabIndex: Me,
210
+ className: s[g.field],
211
+ onMouseDown: Ne,
212
+ onFocus: Re,
213
+ children: /* @__PURE__ */ t(
214
+ ze,
189
215
  {
190
- fallback: /* @__PURE__ */ a("span", { className: r[m.segments], children: ea }),
191
- onError: aa,
192
- children: /* @__PURE__ */ a(
193
- We,
216
+ fallback: /* @__PURE__ */ t("span", { className: s[g.segments], children: ir }),
217
+ onError: dr,
218
+ children: /* @__PURE__ */ t(
219
+ Ge,
194
220
  {
195
- parts: l,
196
- segmentText: de,
197
- segmentValues: w,
198
- focusedSegment: E,
221
+ parts: m,
222
+ segmentText: De,
223
+ segmentValues: L,
224
+ focusedSegment: A,
199
225
  disabled: e,
200
- readOnly: t,
201
- invalid: d,
202
- role: Ie,
203
- onSegmentFocus: O,
204
- onSegmentBlur: De,
205
- onSegmentInput: ye,
206
- onSegmentKeyDown: Se,
207
- registerSegmentRef: le
226
+ readOnly: n,
227
+ invalid: p,
228
+ role: Be,
229
+ onSegmentFocus: d,
230
+ onSegmentBlur: Ee,
231
+ onSegmentInput: Le,
232
+ onSegmentKeyDown: we,
233
+ registerSegmentRef: ge
208
234
  }
209
235
  )
210
236
  }
211
237
  )
212
238
  }
213
239
  ),
214
- /* @__PURE__ */ a(
240
+ /* @__PURE__ */ t(
215
241
  "span",
216
242
  {
217
243
  role: "status",
218
244
  "aria-live": "polite",
219
245
  "aria-atomic": "true",
220
- className: r[m.srStatus],
221
- children: ge
246
+ className: s[g.srStatus],
247
+ children: Ie
222
248
  }
223
249
  ),
224
- /* @__PURE__ */ a(
250
+ /* @__PURE__ */ t(
225
251
  "input",
226
252
  {
227
253
  type: "hidden",
228
- name: F,
229
- value: ke(R),
254
+ name: M,
255
+ value: er(B),
230
256
  disabled: e
231
257
  }
232
258
  ),
233
- /* @__PURE__ */ B(Pe, { ctxId: ee, ctxDisabled: e, children: [
234
- b,
235
- S && /* @__PURE__ */ a(Te, { id: x, appearance: "negative", children: v })
259
+ /* @__PURE__ */ Y($e, { ctxId: ce, ctxDisabled: e, children: [
260
+ x,
261
+ N && /* @__PURE__ */ t(Ye, { id: O, appearance: "negative", children: y })
236
262
  ] }),
237
- oe(ae)
263
+ pe(ue)
238
264
  ]
239
265
  }
240
266
  );
241
267
  }
242
268
  );
243
269
  export {
244
- Ma as DateField
270
+ Br as DateField
245
271
  };
@@ -31,6 +31,23 @@ export type DateFieldPart = {
31
31
  type: SegmentType | 'literal';
32
32
  value: string;
33
33
  };
34
+ /**
35
+ * The DateField `ref` value (DF-16): the field's **root DOM element**
36
+ * (`role="group"`) augmented with a `clear()` method. Keeping the ref a real
37
+ * element (not a separate handle object) means it works anywhere a DOM node is
38
+ * expected — a `Popover` / `FloatingUI` trigger, measuring, `scrollIntoView` —
39
+ * while also carrying the field's imperative API.
40
+ *
41
+ * `focus()` and `blur()` are field-aware overrides of the native element methods:
42
+ * `focus()` moves to the first segment; `blur()` exits the field (running the
43
+ * same commit / normalize / clamp as a user blur). Both no-op when the field is
44
+ * disabled. `clear()` empties every segment and fires `onChange(null)` (only
45
+ * when a value was present), and no-ops when disabled or read-only.
46
+ * (`selectAll()` is reserved for DF-13.)
47
+ */
48
+ export type DateFieldHandle = HTMLDivElement & {
49
+ clear(): void;
50
+ };
34
51
  export interface DateFieldProps extends DateFieldInputAttributes {
35
52
  /**
36
53
  * Specify HelperText for DateField
@@ -1,2 +1,2 @@
1
1
  export { DateField } from './DateField';
2
- export type { DateFieldProps } from './DateField.types';
2
+ export type { DateFieldHandle, DateFieldProps } from './DateField.types';
@@ -1 +1 @@
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
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react"),P=require("./DateField.utils.cjs.js");function j({disabled:l,fieldRef:a,segmentRefs:v,partsOrder:b,onSegmentFocusChange:D,onFieldBlur:x}){const[n,o]=e.useState(null),i=b[0],y=e.useRef(n);y.current=n;const r=e.useRef(D),d=e.useRef(x);e.useEffect(()=>{r.current=D,d.current=x},[D,x]);const T=e.useRef(void 0);e.useEffect(()=>{if(n===null||n==="all")return;const t=v.current.get(n);t&&(document.activeElement!==t&&t.focus(T.current),T.current=void 0)},[n,v]);const p=e.useCallback((t,c)=>{var u;l||(T.current=c,o(t),(u=r.current)==null||u.call(r,t))},[l]),E=e.useCallback(t=>{var c;l||t.target===a.current&&(o(i),(c=r.current)==null||c.call(r,i))},[l,a,i]),q=e.useCallback(t=>{var u,s,f,_;if((u=a.current)!=null&&u.contains(t.relatedTarget))return;const c=(f=(s=t.target)==null?void 0:s.getAttribute)==null?void 0:f.call(s,"data-segment");c&&c!==y.current||(o(null),(_=d.current)==null||_.call(d),P.clearSelectionWithin(a.current))},[a]),w=e.useCallback(t=>{var u;if(l)return;t.target.closest("[data-segment]")||(t.preventDefault(),o(i),(u=r.current)==null||u.call(r,i))},[l,i]),k=e.useCallback((t,c)=>{var f;const u=b.indexOf(t);if(u===-1)return;const s=b[u+c];s!=null&&(o(s),(f=r.current)==null||f.call(r,s))},[b]),I=e.useCallback(t=>{k(t,1)},[k]),M=e.useCallback(t=>{k(t,-1)},[k]);return{focusedSegment:n,fieldTabIndex:l?-1:n===null?0:-1,handleSegmentFocus:p,handleFieldFocus:E,handleFieldBlur:q,handleFieldMouseDown:w,focusNext:I,focusPrevious:M}}exports.useDateFieldFocus=j;
@@ -14,7 +14,7 @@ export interface UseDateFieldFocusArgs {
14
14
  export interface UseDateFieldFocusReturn {
15
15
  focusedSegment: FocusTarget;
16
16
  fieldTabIndex: number;
17
- handleSegmentFocus: (segment: SegmentType) => void;
17
+ handleSegmentFocus: (segment: SegmentType, options?: FocusOptions) => void;
18
18
  handleFieldFocus: (event: FocusEvent<HTMLDivElement>) => void;
19
19
  handleFieldBlur: (event: FocusEvent<HTMLElement>) => void;
20
20
  handleFieldMouseDown: (event: MouseEvent<HTMLDivElement>) => void;
@@ -1,76 +1,75 @@
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,
1
+ import { useState as j, useRef as d, useEffect as k, useCallback as s } from "react";
2
+ import { clearSelectionWithin as q } from "./DateField.utils.es.js";
3
+ function J({
4
+ disabled: o,
5
+ fieldRef: f,
6
+ segmentRefs: y,
7
7
  partsOrder: x,
8
- onSegmentFocusChange: m,
9
- onFieldBlur: p
8
+ onSegmentFocusChange: v,
9
+ onFieldBlur: D
10
10
  }) {
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(() => {
11
+ const [u, l] = j(null), i = x[0], E = d(u);
12
+ E.current = u;
13
+ const r = d(v), p = d(D);
14
+ k(() => {
15
+ r.current = v, p.current = D;
16
+ }, [v, D]);
17
+ const m = d(void 0);
18
+ k(() => {
17
19
  if (u === null || u === "all") return;
18
- const t = E.current.get(u);
19
- t && document.activeElement !== t && t.focus();
20
- }, [u, E]);
21
- const w = o(
22
- (t) => {
20
+ const t = y.current.get(u);
21
+ t && (document.activeElement !== t && t.focus(m.current), m.current = void 0);
22
+ }, [u, y]);
23
+ const w = s(
24
+ (t, n) => {
23
25
  var c;
24
- s || (f(t), (c = r.current) == null || c.call(r, t));
26
+ o || (m.current = n, l(t), (c = r.current) == null || c.call(r, t));
25
27
  },
26
- [s]
27
- ), A = o(
28
+ [o]
29
+ ), A = s(
28
30
  (t) => {
29
- var c;
30
- s || t.target === l.current && (f(i), (c = r.current) == null || c.call(r, i));
31
+ var n;
32
+ o || t.target === f.current && (l(i), (n = r.current) == null || n.call(r, i));
31
33
  },
32
- [s, l, i]
33
- ), M = o(
34
+ [o, f, i]
35
+ ), M = s(
34
36
  (t) => {
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));
37
+ var c, e, a, I;
38
+ if ((c = f.current) != null && c.contains(t.relatedTarget)) return;
39
+ const n = (a = (e = t.target) == null ? void 0 : e.getAttribute) == null ? void 0 : a.call(e, "data-segment");
40
+ n && n !== E.current || (l(null), (I = p.current) == null || I.call(p), q(f.current));
42
41
  },
43
- [l]
44
- ), N = o(
42
+ [f]
43
+ ), N = s(
45
44
  (t) => {
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));
45
+ var c;
46
+ if (o) return;
47
+ t.target.closest("[data-segment]") || (t.preventDefault(), l(i), (c = r.current) == null || c.call(r, i));
49
48
  },
50
- [s, i]
51
- ), D = o(
52
- (t, c) => {
49
+ [o, i]
50
+ ), T = s(
51
+ (t, n) => {
53
52
  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));
53
+ const c = x.indexOf(t);
54
+ if (c === -1) return;
55
+ const e = x[c + n];
56
+ e != null && (l(e), (a = r.current) == null || a.call(r, e));
58
57
  },
59
58
  [x]
60
- ), P = o(
59
+ ), P = s(
61
60
  (t) => {
62
- D(t, 1);
61
+ T(t, 1);
63
62
  },
64
- [D]
65
- ), W = o(
63
+ [T]
64
+ ), W = s(
66
65
  (t) => {
67
- D(t, -1);
66
+ T(t, -1);
68
67
  },
69
- [D]
68
+ [T]
70
69
  );
71
70
  return {
72
71
  focusedSegment: u,
73
- fieldTabIndex: s ? -1 : u === null ? 0 : -1,
72
+ fieldTabIndex: o ? -1 : u === null ? 0 : -1,
74
73
  handleSegmentFocus: w,
75
74
  handleFieldFocus: A,
76
75
  handleFieldBlur: M,
@@ -80,5 +79,5 @@ function H({
80
79
  };
81
80
  }
82
81
  export {
83
- H as useDateFieldFocus
82
+ J as useDateFieldFocus
84
83
  };