@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,62 +1,78 @@
1
- import { useRef as n, useState as E, useEffect as j, useCallback as i } from "react";
2
- import { segmentTextFromValue as v, segmentNumber as T, deriveValue as C, isSameDateValue as w, deriveValueFromText as A, normalizeSegmentText as V } from "./DateField.utils.es.js";
3
- import { tryAppendDigit as I } from "./DateField.validation.es.js";
4
- function G({
5
- value: r,
6
- defaultValue: F,
7
- onChange: m
1
+ import { useRef as u, useState as M, useEffect as N, useCallback as i } from "react";
2
+ import { segmentTextFromValue as v, segmentNumber as a, deriveValue as C, isSameDateValue as w, deriveValueFromText as F, getDaysInMonth as H, adjustSegmentValue as L, todayParts as O, normalizeSegmentText as E } 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: c,
6
+ defaultValue: I,
7
+ onChange: h
8
8
  }) {
9
- const R = n(r !== void 0), f = R.current, [u, x] = E(
10
- () => v(f ? r ?? null : F ?? null)
11
- ), [B, S] = E(!1), c = n(u), s = n(/* @__PURE__ */ new Set()), g = n(!1), p = {
12
- day: T("day", u.day),
13
- month: T("month", u.month),
14
- year: T("year", u.year)
15
- }, D = C(p), h = n(D), b = n(
16
- f ? r ?? null : null
17
- ), o = n(m);
18
- j(() => {
19
- o.current = m;
20
- }, [m]), j(() => {
21
- if (!R.current || g.current || w(r ?? null, b.current)) return;
22
- b.current = r ?? null;
23
- const e = v(r ?? null);
24
- c.current = e, x(e), h.current = A(e);
25
- }, [r]);
26
- const a = i((e) => {
27
- var d;
28
- const t = A(e);
29
- w(t, h.current) || (h.current = t, (d = o.current) == null || d.call(o, t));
30
- }, []), N = i(
9
+ const D = u(c !== void 0), S = D.current, [d, f] = M(
10
+ () => v(S ? c ?? null : I ?? null)
11
+ ), [B, T] = M(!1), r = u(d), l = u(/* @__PURE__ */ new Set()), x = u(!1), R = {
12
+ day: a("day", d.day),
13
+ month: a("month", d.month),
14
+ year: a("year", d.year)
15
+ }, j = C(R), y = u(j), b = u(
16
+ S ? c ?? null : null
17
+ ), g = u(h);
18
+ N(() => {
19
+ g.current = h;
20
+ }, [h]), N(() => {
21
+ if (!D.current || x.current || w(c ?? null, b.current)) return;
22
+ b.current = c ?? null;
23
+ const e = v(c ?? null);
24
+ r.current = e, f(e), y.current = F(e);
25
+ }, [c]);
26
+ const s = i((e) => {
27
+ var n;
28
+ const t = F(e);
29
+ w(t, y.current) || (y.current = t, (n = g.current) == null || n.call(g, t));
30
+ }, []), G = i(
31
31
  (e, t) => {
32
- const d = s.current.has(e) ? "" : c.current[e], l = I(e, d, t);
33
- if (l.rejected) return { advanced: !1, rejected: !0 };
34
- const y = { ...c.current, [e]: l.newBuffer };
35
- return c.current = y, x(y), S(!0), a(y), l.shouldAdvance ? s.current.add(e) : s.current.delete(e), { advanced: l.shouldAdvance, rejected: !1 };
32
+ const n = l.current.has(e) ? "" : r.current[e], o = P(e, n, t);
33
+ if (o.rejected) return { advanced: !1, rejected: !0 };
34
+ const m = { ...r.current, [e]: o.newBuffer };
35
+ return r.current = m, f(m), T(!0), s(m), o.shouldAdvance ? l.current.add(e) : l.current.delete(e), { advanced: o.shouldAdvance, rejected: !1 };
36
36
  },
37
- [a]
37
+ [s]
38
+ ), _ = i(
39
+ (e, t) => {
40
+ const n = r.current, o = a(e, n[e]), m = H(
41
+ a("year", n.year),
42
+ a("month", n.month)
43
+ ), A = L(e, o, t, {
44
+ daysInMonth: m,
45
+ today: O()
46
+ });
47
+ if (A == null) return !1;
48
+ x.current = !0;
49
+ const z = String(A).padStart(W[e], "0"), V = { ...n, [e]: z };
50
+ return r.current = V, f(V), T(!0), s(V), l.current.add(e), !0;
51
+ },
52
+ [s]
38
53
  ), k = i((e) => {
39
- g.current = !0, s.current.add(e);
40
- }, []), z = i(() => {
41
- g.current = !1;
42
- const e = c.current, t = {
43
- day: V("day", e.day),
44
- month: V("month", e.month),
45
- year: V("year", e.year)
54
+ x.current = !0, l.current.add(e);
55
+ }, []), p = i(() => {
56
+ x.current = !1;
57
+ const e = r.current, t = {
58
+ day: E("day", e.day),
59
+ month: E("month", e.month),
60
+ year: E("year", e.year)
46
61
  };
47
- c.current = t, x(t), S(!0), a(t);
48
- }, [a]);
62
+ r.current = t, f(t), T(!0), s(t);
63
+ }, [s]);
49
64
  return {
50
- segmentText: u,
51
- segmentValues: p,
52
- currentValue: D,
53
- isControlled: f,
65
+ segmentText: d,
66
+ segmentValues: R,
67
+ currentValue: j,
68
+ isControlled: S,
54
69
  wasTouched: B,
55
- appendDigit: N,
70
+ appendDigit: G,
71
+ adjustSegment: _,
56
72
  beginSegmentEdit: k,
57
- commitOnBlur: z
73
+ commitOnBlur: p
58
74
  };
59
75
  }
60
76
  export {
61
- G as useDateFieldValue
77
+ K as useDateFieldValue
62
78
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viasat/beam-react",
3
- "version": "2.39.3",
3
+ "version": "2.41.0",
4
4
  "description": "React component library for the Beam design system",
5
5
  "license": "MIT",
6
6
  "author": "Viasat",
@@ -59,11 +59,11 @@
59
59
  "access": "public"
60
60
  },
61
61
  "dependencies": {
62
- "@viasat/beam-fonts": "2.39.3",
63
- "@viasat/beam-shared": "2.39.3",
64
- "@viasat/beam-styles": "2.39.3",
65
- "@viasat/beam-tokens": "2.39.3",
66
- "@viasat/beam-icons": "2.39.3",
62
+ "@viasat/beam-fonts": "2.41.0",
63
+ "@viasat/beam-shared": "2.41.0",
64
+ "@viasat/beam-styles": "2.41.0",
65
+ "@viasat/beam-tokens": "2.41.0",
66
+ "@viasat/beam-icons": "2.41.0",
67
67
  "clsx": "^1.2.1",
68
68
  "@floating-ui/react": "^0.26.18",
69
69
  "@stepperize/react": "^5.1.5",
@@ -1 +0,0 @@
1
- var y=require("../assets/DateField.css");const v=require("react/jsx-runtime"),N=require("clsx"),d=require("react"),M=require("./classNames.DC8Ra4sw.js"),D=require("../lib/wip/DateField/DateField.utils.cjs.js"),F="date-field",{baseClassNamePrefix:R,classModifierPrefix:q,subElementClassPrefix:r}=M.getBEMClassNames(F),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:31,month:12,year:9999},P={day:"day",month:"month",year:"year"},k=({type:n,value:_,displayValue:t,isPlaceholder:g,isActive:a,disabled:l,readOnly:o,onFocus:C,onBlur:p,onInput:x,segmentRef:m})=>{const s=!l&&!o,f=d.useRef(null),E=d.useCallback(e=>{f.current=e,m(e)},[m]),h=e=>{if(!s)return;const b=e.currentTarget,i=e.nativeEvent.data;i!=null&&i.length===1&&x(n,i),b.textContent!==t&&(b.textContent=t)};return d.useLayoutEffect(()=>{if(!a||!s)return;const e=f.current;e&&D.selectElementContents(e)},[t,a,s]),v.jsx("span",{ref:E,role:"spinbutton","aria-label":P[n],"aria-valuenow":_??void 0,"aria-valuemin":1,"aria-valuemax":I[n],"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":g,onFocus:C,onBlur:p,onInput:h,onMouseUp:e=>e.preventDefault(),className:N(u[c.segment]),children:t})};exports.DateFieldSegment=k;exports.baseClassNamePrefix=R;exports.classModifierPrefix=q;exports.staticDateFieldClassNames=c;exports.styles=u;