@viasat/beam-react 2.47.0 → 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,96 +1,103 @@
1
- import { useRef as o, useState as w, useEffect as b, useCallback as s } from "react";
2
- import { segmentTextFromValue as v, segmentNumber as d, deriveValue as C, isSameDateValue as A, deriveValueFromText as M, getDaysInMonth as H, adjustSegmentValue as O, todayParts as P, normalizeSegmentText as T } from "./DateField.utils.es.js";
3
- import { tryAppendDigit as W, SEGMENT_MAX_LENGTH as X } from "./DateField.validation.es.js";
4
- function Q({
5
- value: a,
6
- defaultValue: N,
7
- onChange: x
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 = o(a !== void 0), h = E.current, [i, S] = w(
10
- () => v(h ? a ?? null : N ?? null)
11
- ), [F, V] = w(!1), c = o(i), m = o(/* @__PURE__ */ new Set()), l = o(!1), p = {
12
- day: d("day", i.day),
13
- month: d("month", i.month),
14
- year: d("year", i.year)
15
- }, D = C(p), y = o(D), R = o(
16
- h ? a ?? null : null
17
- ), f = o(x);
18
- b(() => {
19
- f.current = x;
20
- }, [x]), b(() => {
21
- if (!E.current || l.current || A(a ?? null, R.current)) return;
22
- R.current = a ?? null;
23
- const e = v(a ?? null);
24
- c.current = e, S(e), y.current = M(e);
25
- }, [a]);
26
- const g = s((e) => {
27
- var r;
28
- const t = M(e);
29
- A(t, y.current) || (y.current = t, (r = f.current) == null || r.call(f, t));
30
- }, []), u = s(
31
- (e, t, { replace: r }) => {
32
- const n = { ...c.current, [e]: t };
33
- c.current = n, S(n), V(!0), g(n), r ? m.current.add(e) : m.current.delete(e);
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);
34
24
  },
35
- [g]
36
- ), I = s(
37
- (e, t) => {
38
- const r = m.current.has(e) ? "" : c.current[e], n = W(e, r, t);
39
- return n.rejected ? { advanced: !1, rejected: !0 } : (u(e, n.newBuffer, { replace: n.shouldAdvance }), { advanced: n.shouldAdvance, rejected: !1 });
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);
40
40
  },
41
- [u]
42
- ), B = s(
43
- (e, t) => {
44
- const r = c.current, n = d(e, r[e]), z = H(
45
- d("year", r.year),
46
- d("month", r.month)
47
- ), j = O(e, n, t, {
48
- daysInMonth: z,
49
- today: P()
50
- });
51
- return j == null ? !1 : (l.current = !0, u(
52
- e,
53
- String(j).padStart(X[e], "0"),
54
- { replace: !0 }
55
- ), !0);
56
- },
57
- [u]
58
- ), G = s(
59
- (e) => {
60
- const t = c.current[e];
61
- return t === "" ? { wasEmpty: !0 } : (l.current = !0, u(e, t.slice(0, -1), { replace: !1 }), { wasEmpty: !1 });
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 });
62
46
  },
63
- [u]
64
- ), L = s(
65
- (e) => {
66
- c.current[e] !== "" && (l.current = !0, u(e, "", { replace: !1 }));
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()
56
+ });
57
+ return d == null ? !1 : (f.current = !0, l(e, String(d).padStart(te[e], "0"), {
58
+ replace: !0
59
+ }), !0);
67
60
  },
68
- [u]
69
- ), _ = s((e) => {
70
- l.current = !0, m.current.add(e);
71
- }, []), k = s(() => {
72
- l.current = !1;
73
- const e = c.current, t = {
74
- day: T("day", e.day),
75
- month: T("month", e.month),
76
- year: T("year", e.year)
77
- };
78
- c.current = t, S(t), V(!0), g(t);
79
- }, [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)]);
80
87
  return {
81
- segmentText: i,
82
- segmentValues: p,
83
- currentValue: D,
84
- isControlled: h,
88
+ segmentText: m,
89
+ segmentValues: B,
90
+ currentValue: G,
91
+ isControlled: p,
85
92
  wasTouched: F,
86
- appendDigit: I,
87
- adjustSegment: B,
88
- deleteLastDigit: G,
89
- clearSegment: L,
90
- beginSegmentEdit: _,
91
- commitOnBlur: k
93
+ appendDigit: L,
94
+ adjustSegment: P,
95
+ clearSegment: W,
96
+ beginSegmentEdit: X,
97
+ commitOnBlur: J,
98
+ clampAnnouncement: H
92
99
  };
93
100
  }
94
101
  export {
95
- Q as useDateFieldValue
102
+ ue as useDateFieldValue
96
103
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viasat/beam-react",
3
- "version": "2.47.0",
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.0",
64
- "@viasat/beam-shared": "2.47.0",
65
- "@viasat/beam-styles": "2.47.0",
66
- "@viasat/beam-tokens": "2.47.0",
67
- "@viasat/beam-icons": "2.47.0",
68
- "@viasat/beam-react-claude-plugin": "2.47.0",
63
+ "@viasat/beam-fonts": "2.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;