@viasat/beam-react 2.39.2 → 2.40.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.
- package/chunks/{DateField.Segment.BVKky9IE.js → DateField.Segment.BaAwH6ov.js} +35 -33
- package/chunks/DateField.Segment.Df8aTzNW.js +1 -0
- package/lib/wip/DateField/DateField.Segment.cjs.js +1 -1
- package/lib/wip/DateField/DateField.Segment.d.ts +1 -1
- package/lib/wip/DateField/DateField.Segment.es.js +1 -1
- package/lib/wip/DateField/DateField.Segments.cjs.js +1 -1
- package/lib/wip/DateField/DateField.Segments.d.ts +7 -2
- package/lib/wip/DateField/DateField.Segments.es.js +19 -17
- package/lib/wip/DateField/DateField.cjs.js +1 -1
- package/lib/wip/DateField/DateField.es.js +141 -133
- package/lib/wip/DateField/DateField.types.d.ts +9 -1
- package/lib/wip/DateField/DateField.utils.cjs.js +1 -1
- package/lib/wip/DateField/DateField.utils.d.ts +5 -0
- package/lib/wip/DateField/DateField.utils.es.js +19 -13
- package/lib/wip/DateField/useDateFieldFocus.cjs.js +1 -1
- package/lib/wip/DateField/useDateFieldFocus.d.ts +3 -2
- package/lib/wip/DateField/useDateFieldFocus.es.js +56 -44
- package/lib/wip/DateField/useDateFieldKeyboard.cjs.js +1 -0
- package/lib/wip/DateField/useDateFieldKeyboard.d.ts +24 -0
- package/lib/wip/DateField/useDateFieldKeyboard.es.js +33 -0
- package/package.json +6 -6
- package/chunks/DateField.Segment.BBcn6sug.js +0 -1
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import "../assets/DateField.css";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import
|
|
4
|
-
import { useRef as
|
|
5
|
-
import { g as
|
|
2
|
+
import { jsx as x } from "react/jsx-runtime";
|
|
3
|
+
import h from "clsx";
|
|
4
|
+
import { useRef as v, useCallback as M, useLayoutEffect as N } from "react";
|
|
5
|
+
import { g as D } from "./classNames.ZWNk1hey.js";
|
|
6
6
|
import { selectElementContents as I } from "../lib/wip/DateField/DateField.utils.es.js";
|
|
7
|
-
const k = "date-field", { baseClassNamePrefix: F, classModifierPrefix: G, subElementClassPrefix: s } =
|
|
7
|
+
const k = "date-field", { baseClassNamePrefix: F, classModifierPrefix: G, subElementClassPrefix: s } = D(k), R = {
|
|
8
8
|
field: `${s}field`,
|
|
9
9
|
segments: `${s}segments`,
|
|
10
10
|
segment: `${s}segment`,
|
|
11
11
|
separator: `${s}separator`
|
|
12
|
-
},
|
|
12
|
+
}, $ = {
|
|
13
13
|
"bm-light": "bm-light",
|
|
14
14
|
"bm-dark": "bm-dark",
|
|
15
15
|
"bm-inverse": "bm-inverse",
|
|
@@ -24,76 +24,78 @@ const k = "date-field", { baseClassNamePrefix: F, classModifierPrefix: G, subEle
|
|
|
24
24
|
"bm-date-field--fluid": "bm-date-field--fluid",
|
|
25
25
|
"bm-date-field__segments": "bm-date-field__segments",
|
|
26
26
|
"bm-date-field__separator": "bm-date-field__separator"
|
|
27
|
-
},
|
|
27
|
+
}, y = {
|
|
28
28
|
day: 31,
|
|
29
29
|
month: 12,
|
|
30
30
|
year: 9999
|
|
31
|
-
},
|
|
31
|
+
}, B = {
|
|
32
32
|
day: "day",
|
|
33
33
|
month: "month",
|
|
34
34
|
year: "year"
|
|
35
35
|
}, j = ({
|
|
36
|
-
type:
|
|
36
|
+
type: t,
|
|
37
37
|
value: b,
|
|
38
|
-
displayValue:
|
|
38
|
+
displayValue: a,
|
|
39
39
|
isPlaceholder: c,
|
|
40
|
-
isActive:
|
|
40
|
+
isActive: n,
|
|
41
41
|
disabled: o,
|
|
42
42
|
readOnly: i,
|
|
43
43
|
onFocus: u,
|
|
44
44
|
onBlur: _,
|
|
45
|
-
onInput:
|
|
45
|
+
onInput: g,
|
|
46
|
+
onKeyDown: p,
|
|
46
47
|
segmentRef: m
|
|
47
48
|
}) => {
|
|
48
|
-
const
|
|
49
|
+
const r = !o && !i, l = v(null), C = M(
|
|
49
50
|
(e) => {
|
|
50
51
|
l.current = e, m(e);
|
|
51
52
|
},
|
|
52
53
|
[m]
|
|
53
|
-
),
|
|
54
|
-
if (!
|
|
54
|
+
), E = (e) => {
|
|
55
|
+
if (!r) return;
|
|
55
56
|
const f = e.currentTarget, d = e.nativeEvent.data;
|
|
56
|
-
d != null && d.length === 1 &&
|
|
57
|
+
d != null && d.length === 1 && g(t, d), f.textContent !== a && (f.textContent = a);
|
|
57
58
|
};
|
|
58
|
-
return
|
|
59
|
-
if (!
|
|
59
|
+
return N(() => {
|
|
60
|
+
if (!n || !r) return;
|
|
60
61
|
const e = l.current;
|
|
61
62
|
e && I(e);
|
|
62
|
-
}, [
|
|
63
|
+
}, [a, n, r]), /* @__PURE__ */ x(
|
|
63
64
|
"span",
|
|
64
65
|
{
|
|
65
|
-
ref:
|
|
66
|
+
ref: C,
|
|
66
67
|
role: "spinbutton",
|
|
67
|
-
"aria-label":
|
|
68
|
+
"aria-label": B[t],
|
|
68
69
|
"aria-valuenow": b ?? void 0,
|
|
69
70
|
"aria-valuemin": 1,
|
|
70
|
-
"aria-valuemax":
|
|
71
|
-
"aria-valuetext":
|
|
71
|
+
"aria-valuemax": y[t],
|
|
72
|
+
"aria-valuetext": a,
|
|
72
73
|
"aria-disabled": o || void 0,
|
|
73
74
|
"aria-readonly": i || void 0,
|
|
74
|
-
contentEditable:
|
|
75
|
+
contentEditable: r && n,
|
|
75
76
|
suppressContentEditableWarning: !0,
|
|
76
|
-
tabIndex:
|
|
77
|
-
inputMode:
|
|
77
|
+
tabIndex: n ? 0 : -1,
|
|
78
|
+
inputMode: r ? "numeric" : void 0,
|
|
78
79
|
spellCheck: !1,
|
|
79
80
|
autoCorrect: "off",
|
|
80
81
|
autoCapitalize: "off",
|
|
81
|
-
"data-segment":
|
|
82
|
-
"data-active":
|
|
82
|
+
"data-segment": t,
|
|
83
|
+
"data-active": n,
|
|
83
84
|
"data-placeholder": c,
|
|
84
85
|
onFocus: u,
|
|
85
86
|
onBlur: _,
|
|
86
|
-
onInput:
|
|
87
|
+
onInput: E,
|
|
88
|
+
onKeyDown: (e) => p(t, e),
|
|
87
89
|
onMouseUp: (e) => e.preventDefault(),
|
|
88
|
-
className:
|
|
89
|
-
children:
|
|
90
|
+
className: h($[R.segment]),
|
|
91
|
+
children: a
|
|
90
92
|
}
|
|
91
93
|
);
|
|
92
94
|
};
|
|
93
95
|
export {
|
|
94
96
|
j as D,
|
|
95
|
-
|
|
97
|
+
R as a,
|
|
96
98
|
F as b,
|
|
97
99
|
G as c,
|
|
98
|
-
|
|
100
|
+
$ as s
|
|
99
101
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var S=require("../assets/DateField.css");const N=require("react/jsx-runtime"),D=require("clsx"),d=require("react"),M=require("./classNames.DC8Ra4sw.js"),F=require("../lib/wip/DateField/DateField.utils.cjs.js"),R="date-field",{baseClassNamePrefix:q,classModifierPrefix:I,subElementClassPrefix:r}=M.getBEMClassNames(R),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"},P={day:31,month:12,year:9999},k={day:"day",month:"month",year:"year"},y=({type:t,value:_,displayValue:a,isPlaceholder:g,isActive:s,disabled:l,readOnly:o,onFocus:C,onBlur:p,onInput:x,onKeyDown:E,segmentRef:m})=>{const n=!l&&!o,f=d.useRef(null),h=d.useCallback(e=>{f.current=e,m(e)},[m]),v=e=>{if(!n)return;const b=e.currentTarget,i=e.nativeEvent.data;i!=null&&i.length===1&&x(t,i),b.textContent!==a&&(b.textContent=a)};return d.useLayoutEffect(()=>{if(!s||!n)return;const e=f.current;e&&F.selectElementContents(e)},[a,s,n]),N.jsx("span",{ref:h,role:"spinbutton","aria-label":k[t],"aria-valuenow":_??void 0,"aria-valuemin":1,"aria-valuemax":P[t],"aria-valuetext":a,"aria-disabled":l||void 0,"aria-readonly":o||void 0,contentEditable:n&&s,suppressContentEditableWarning:!0,tabIndex:s?0:-1,inputMode:n?"numeric":void 0,spellCheck:!1,autoCorrect:"off",autoCapitalize:"off","data-segment":t,"data-active":s,"data-placeholder":g,onFocus:C,onBlur:p,onInput:v,onKeyDown:e=>E(t,e),onMouseUp:e=>e.preventDefault(),className:D(u[c.segment]),children:a})};exports.DateFieldSegment=y;exports.baseClassNamePrefix=q;exports.classModifierPrefix=I;exports.staticDateFieldClassNames=c;exports.styles=u;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react/jsx-runtime");require("clsx");require("react");const e=require("../../../chunks/DateField.Segment.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("react/jsx-runtime");require("clsx");require("react");const e=require("../../../chunks/DateField.Segment.Df8aTzNW.js");require("./DateField.utils.cjs.js");exports.DateFieldSegment=e.DateFieldSegment;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { DateFieldSegmentProps } from './DateField.types';
|
|
2
|
-
export declare const DateFieldSegment: ({ type, value, displayValue, isPlaceholder, isActive, disabled, readOnly, onFocus, onBlur, onInput, segmentRef, }: DateFieldSegmentProps) => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const DateFieldSegment: ({ type, value, displayValue, isPlaceholder, isActive, disabled, readOnly, onFocus, onBlur, onInput, onKeyDown, segmentRef, }: DateFieldSegmentProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "react/jsx-runtime";
|
|
2
2
|
import "clsx";
|
|
3
3
|
import "react";
|
|
4
|
-
import { D as p } from "../../../chunks/DateField.Segment.
|
|
4
|
+
import { D as p } from "../../../chunks/DateField.Segment.BaAwH6ov.js";
|
|
5
5
|
import "./DateField.utils.es.js";
|
|
6
6
|
export {
|
|
7
7
|
p as DateFieldSegment
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),t=require("../../../chunks/DateField.Segment.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),t=require("../../../chunks/DateField.Segment.Df8aTzNW.js"),l=require("./DateField.utils.cjs.js"),n=[{type:"month",value:""},{type:"literal",value:"/"},{type:"day",value:""},{type:"literal",value:"/"},{type:"year",value:""}],R={month:"MM",day:"DD",year:"YYYY"},v=l.getSegmentOrder(n),h=({segmentText:i,segmentValues:r,focusedSegment:o,disabled:u,readOnly:c,onSegmentFocus:d,onSegmentBlur:y,onSegmentInput:m,onSegmentKeyDown:p,registerSegmentRef:D})=>a.jsx("span",{className:t.styles[t.staticDateFieldClassNames.segments],children:n.map((s,g)=>{if(s.type==="literal")return a.jsx("span",{"aria-hidden":"true",className:t.styles[t.staticDateFieldClassNames.separator],children:s.value},`literal-${g}`);const e=s.type,S=R[e],{displayValue:_,isPlaceholder:F}=l.getSegmentDisplay(e,i[e],S);return a.jsx(t.DateFieldSegment,{type:e,value:r[e],displayValue:_,isPlaceholder:F,isActive:o===e,disabled:u,readOnly:c,onFocus:()=>d(e),onBlur:y,onInput:m,onKeyDown:p,segmentRef:D(e)},e)})});exports.DateFieldSegments=h;exports.PARTS_ORDER=v;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FocusEvent } from 'react';
|
|
1
|
+
import { FocusEvent, KeyboardEvent } from 'react';
|
|
2
2
|
import { FocusTarget, SegmentText, SegmentType, SegmentValues } from './DateField.types';
|
|
3
3
|
export declare const PARTS_ORDER: ReadonlyArray<SegmentType>;
|
|
4
4
|
export interface DateFieldSegmentsProps {
|
|
@@ -9,9 +9,14 @@ export interface DateFieldSegmentsProps {
|
|
|
9
9
|
focusedSegment: FocusTarget;
|
|
10
10
|
disabled: boolean;
|
|
11
11
|
readOnly: boolean;
|
|
12
|
+
/** Forwarded to each segment's focus handler. */
|
|
12
13
|
onSegmentFocus: (segment: SegmentType) => void;
|
|
14
|
+
/** Forwarded to each segment's blur handler. */
|
|
13
15
|
onSegmentBlur: (event: FocusEvent<HTMLSpanElement>) => void;
|
|
16
|
+
/** Forwarded to each segment's single-digit input handler. */
|
|
14
17
|
onSegmentInput: (segment: SegmentType, char: string) => void;
|
|
18
|
+
/** Keyboard handler from `useDateFieldKeyboard`, forwarded to each segment. */
|
|
19
|
+
onSegmentKeyDown: (segment: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
|
|
15
20
|
registerSegmentRef: (segment: SegmentType) => (element: HTMLSpanElement | null) => void;
|
|
16
21
|
}
|
|
17
|
-
export declare const DateFieldSegments: ({ segmentText, segmentValues, focusedSegment, disabled, readOnly, onSegmentFocus, onSegmentBlur, onSegmentInput, registerSegmentRef, }: DateFieldSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare const DateFieldSegments: ({ segmentText, segmentValues, focusedSegment, disabled, readOnly, onSegmentFocus, onSegmentBlur, onSegmentInput, onSegmentKeyDown, registerSegmentRef, }: DateFieldSegmentsProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,26 +1,27 @@
|
|
|
1
1
|
import { jsx as a } from "react/jsx-runtime";
|
|
2
|
-
import { s, a as l, D as
|
|
3
|
-
import { getSegmentOrder as
|
|
2
|
+
import { s, a as l, D as R } from "../../../chunks/DateField.Segment.BaAwH6ov.js";
|
|
3
|
+
import { getSegmentOrder as f, getSegmentDisplay as A } from "./DateField.utils.es.js";
|
|
4
4
|
const n = [
|
|
5
5
|
{ type: "month", value: "" },
|
|
6
6
|
{ type: "literal", value: "/" },
|
|
7
7
|
{ type: "day", value: "" },
|
|
8
8
|
{ type: "literal", value: "/" },
|
|
9
9
|
{ type: "year", value: "" }
|
|
10
|
-
],
|
|
10
|
+
], E = {
|
|
11
11
|
month: "MM",
|
|
12
12
|
day: "DD",
|
|
13
13
|
year: "YYYY"
|
|
14
|
-
},
|
|
14
|
+
}, Y = f(n), O = ({
|
|
15
15
|
segmentText: r,
|
|
16
16
|
segmentValues: o,
|
|
17
17
|
focusedSegment: i,
|
|
18
18
|
disabled: m,
|
|
19
19
|
readOnly: p,
|
|
20
|
-
onSegmentFocus:
|
|
21
|
-
onSegmentBlur:
|
|
20
|
+
onSegmentFocus: y,
|
|
21
|
+
onSegmentBlur: c,
|
|
22
22
|
onSegmentInput: u,
|
|
23
|
-
|
|
23
|
+
onSegmentKeyDown: d,
|
|
24
|
+
registerSegmentRef: D
|
|
24
25
|
}) => /* @__PURE__ */ a("span", { className: s[l.segments], children: n.map((t, g) => {
|
|
25
26
|
if (t.type === "literal")
|
|
26
27
|
return /* @__PURE__ */ a(
|
|
@@ -32,30 +33,31 @@ const n = [
|
|
|
32
33
|
},
|
|
33
34
|
`literal-${g}`
|
|
34
35
|
);
|
|
35
|
-
const e = t.type,
|
|
36
|
+
const e = t.type, v = E[e], { displayValue: S, isPlaceholder: h } = A(
|
|
36
37
|
e,
|
|
37
38
|
r[e],
|
|
38
|
-
|
|
39
|
+
v
|
|
39
40
|
);
|
|
40
41
|
return /* @__PURE__ */ a(
|
|
41
|
-
|
|
42
|
+
R,
|
|
42
43
|
{
|
|
43
44
|
type: e,
|
|
44
45
|
value: o[e],
|
|
45
|
-
displayValue:
|
|
46
|
-
isPlaceholder:
|
|
46
|
+
displayValue: S,
|
|
47
|
+
isPlaceholder: h,
|
|
47
48
|
isActive: i === e,
|
|
48
49
|
disabled: m,
|
|
49
50
|
readOnly: p,
|
|
50
|
-
onFocus: () =>
|
|
51
|
-
onBlur:
|
|
51
|
+
onFocus: () => y(e),
|
|
52
|
+
onBlur: c,
|
|
52
53
|
onInput: u,
|
|
53
|
-
|
|
54
|
+
onKeyDown: d,
|
|
55
|
+
segmentRef: D(e)
|
|
54
56
|
},
|
|
55
57
|
e
|
|
56
58
|
);
|
|
57
59
|
}) });
|
|
58
60
|
export {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
O as DateFieldSegments,
|
|
62
|
+
Y as PARTS_ORDER
|
|
61
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),_e=require("clsx"),be=require("react"),e=require("../../../chunks/DateField.Segment.Df8aTzNW.js"),De=require("../../../chunks/constants.CgMu0_1M.js"),fe=require("../../../chunks/form.context.D5XrYvpI.js"),me=require("../../Form/contexts/label.context.cjs.js"),pe=require("../../Form/contexts/helperText.context.cjs.js"),xe=require("../../Form/hooks/useUniversalRef.hook.cjs.js"),t=require("./DateField.Segments.cjs.js"),ge=require("./DateField.utils.cjs.js"),ve=require("./useDateFieldFocus.cjs.js"),ye=require("./useDateFieldForm.cjs.js"),Se=require("./useDateFieldKeyboard.cjs.js"),qe=require("./useDateFieldSegments.cjs.js"),he=require("./useDateFieldValidity.cjs.js"),we=require("./useDateFieldValue.cjs.js"),Ie=require("./useInvalidState.cjs.js"),Re=be.forwardRef(function({value:S,defaultValue:q,onChange:h,label:r=null,helperText:d=null,error:n,hideRequiredMarker:w=!1,validationRules:I,width:R,theme:o,fluid:P=!1,disabled:T=!1,readOnly:V=!1,required:M=!1,name:u,id:j,className:N,style:O,"aria-label":B,"aria-describedby":C,"aria-labelledby":E,...H},K){const{disabled:i,readOnly:c,required:F,invalid:L,errorMessageProvided:_,defaultValue:$,errorId:b,helperTextId:k,validationErrorsId:A,labelId:D,ariaDescribedBy:U,ariaLabelledBy:W,showErrors:z}=ye.useDateFieldForm({name:u,disabled:T,readOnly:V,required:M,defaultValue:q,error:n,hasHelperText:!!d,hasLabel:!!r,validationRules:I,ariaDescribedBy:C,ariaLabelledBy:E}),{refFn:G,ref:f}=xe.useUniversalRef(K),{segmentRefs:J,registerSegmentRef:Q}=qe.useDateFieldSegments(),{segmentText:X,segmentValues:m,currentValue:p,wasTouched:Y,appendDigit:Z,beginSegmentEdit:ee,commitOnBlur:ie}=we.useDateFieldValue({value:S,defaultValue:$,onChange:h}),{focusedSegment:x,fieldTabIndex:le,handleSegmentFocus:g,handleFieldFocus:ae,handleFieldBlur:se,handleFieldMouseDown:te,focusNext:v,focusPrevious:re}=ve.useDateFieldFocus({disabled:i,fieldRef:f,segmentRefs:J,partsOrder:t.PARTS_ORDER,onSegmentFocusChange:ee,onFieldBlur:ie}),de=Se.useDateFieldKeyboard({disabled:i,fieldRef:f,focusNext:v,focusPrevious:re}),{isInvalid:ne}=he.useDateFieldValidity({segments:m,currentValue:p,wasTouched:Y,isFocused:x!==null}),oe=(a,s)=>{const{advanced:Fe}=Z(a,s);Fe&&v(a)},y=Ie.useInvalidState({formInvalid:L,valueInvalid:ne}),ue=a=>{if(i)return;const s=a.target.closest("label");!s||s.id!==D||(a.preventDefault(),g(t.PARTS_ORDER[0]))},ce=_e(e.styles[e.baseClassNamePrefix],o&&De.themeClassName(o),P&&e.styles[`${e.classModifierPrefix}fluid`],y&&e.styles[`${e.classModifierPrefix}error`],i&&e.styles[`${e.classModifierPrefix}disabled`],c&&e.styles[`${e.classModifierPrefix}read-only`],N);return l.jsxs("div",{className:ce,style:{...O,maxWidth:R},onMouseDownCapture:ue,children:[l.jsx(me.LabelProvider,{ctxId:D,ctxDisabled:i,ctxRequired:F&&!w,children:r}),l.jsx("div",{...H,ref:G,id:j,role:"group","aria-label":B,"aria-labelledby":W,"aria-disabled":i||void 0,"aria-required":F||void 0,"aria-invalid":y||void 0,"aria-describedby":U,"aria-errormessage":_?b:void 0,tabIndex:le,className:e.styles[e.staticDateFieldClassNames.field],onMouseDown:te,onFocus:ae,children:l.jsx(t.DateFieldSegments,{segmentText:X,segmentValues:m,focusedSegment:x,disabled:i,readOnly:c,onSegmentFocus:g,onSegmentBlur:se,onSegmentInput:oe,onSegmentKeyDown:de,registerSegmentRef:Q})}),l.jsx("input",{type:"hidden",name:u,value:ge.toISODateString(p),disabled:i}),l.jsxs(pe.HelperTextProvider,{ctxId:k,ctxDisabled:i,children:[d,_&&l.jsx(fe.HelperText,{id:b,appearance:"negative",children:n})]}),z(A)]})});exports.DateField=Re;
|
|
@@ -1,168 +1,176 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { s as a, b as
|
|
5
|
-
import { t as
|
|
6
|
-
import { H as
|
|
7
|
-
import { LabelProvider as
|
|
8
|
-
import { HelperTextProvider as
|
|
9
|
-
import { useUniversalRef as
|
|
10
|
-
import { DateFieldSegments as
|
|
11
|
-
import { toISODateString as
|
|
12
|
-
import { useDateFieldFocus as
|
|
13
|
-
import { useDateFieldForm as
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
|
|
1
|
+
import { jsxs as I, jsx as l } from "react/jsx-runtime";
|
|
2
|
+
import be from "clsx";
|
|
3
|
+
import { forwardRef as ge } from "react";
|
|
4
|
+
import { s as a, b as ve, c as s, a as De } from "../../../chunks/DateField.Segment.BaAwH6ov.js";
|
|
5
|
+
import { t as Fe } from "../../../chunks/constants.Cruz2A1w.js";
|
|
6
|
+
import { H as he } from "../../../chunks/form.context.cEuTL68U.js";
|
|
7
|
+
import { LabelProvider as xe } from "../../Form/contexts/label.context.es.js";
|
|
8
|
+
import { HelperTextProvider as ye } from "../../Form/contexts/helperText.context.es.js";
|
|
9
|
+
import { useUniversalRef as Ie } from "../../Form/hooks/useUniversalRef.hook.es.js";
|
|
10
|
+
import { DateFieldSegments as Se, PARTS_ORDER as S } from "./DateField.Segments.es.js";
|
|
11
|
+
import { toISODateString as we } from "./DateField.utils.es.js";
|
|
12
|
+
import { useDateFieldFocus as Re } from "./useDateFieldFocus.es.js";
|
|
13
|
+
import { useDateFieldForm as Ne } from "./useDateFieldForm.es.js";
|
|
14
|
+
import { useDateFieldKeyboard as Ve } from "./useDateFieldKeyboard.es.js";
|
|
15
|
+
import { useDateFieldSegments as Be } from "./useDateFieldSegments.es.js";
|
|
16
|
+
import { useDateFieldValidity as Ce } from "./useDateFieldValidity.es.js";
|
|
17
|
+
import { useDateFieldValue as Oe } from "./useDateFieldValue.es.js";
|
|
18
|
+
import { useInvalidState as Pe } from "./useInvalidState.es.js";
|
|
19
|
+
const Ye = ge(
|
|
19
20
|
function({
|
|
20
|
-
value:
|
|
21
|
-
defaultValue:
|
|
22
|
-
onChange:
|
|
21
|
+
value: w,
|
|
22
|
+
defaultValue: R,
|
|
23
|
+
onChange: N,
|
|
23
24
|
label: d = null,
|
|
24
|
-
helperText:
|
|
25
|
-
error:
|
|
26
|
-
hideRequiredMarker:
|
|
27
|
-
validationRules:
|
|
28
|
-
width:
|
|
25
|
+
helperText: o = null,
|
|
26
|
+
error: t,
|
|
27
|
+
hideRequiredMarker: V = !1,
|
|
28
|
+
validationRules: B,
|
|
29
|
+
width: C,
|
|
29
30
|
theme: n,
|
|
30
|
-
fluid:
|
|
31
|
-
disabled:
|
|
32
|
-
readOnly:
|
|
33
|
-
required:
|
|
34
|
-
name:
|
|
35
|
-
id:
|
|
36
|
-
className:
|
|
37
|
-
style:
|
|
38
|
-
"aria-label":
|
|
39
|
-
"aria-describedby":
|
|
40
|
-
"aria-labelledby":
|
|
41
|
-
|
|
42
|
-
},
|
|
31
|
+
fluid: O = !1,
|
|
32
|
+
disabled: P = !1,
|
|
33
|
+
readOnly: T = !1,
|
|
34
|
+
required: M = !1,
|
|
35
|
+
name: m,
|
|
36
|
+
id: q,
|
|
37
|
+
className: E,
|
|
38
|
+
style: H,
|
|
39
|
+
"aria-label": L,
|
|
40
|
+
"aria-describedby": $,
|
|
41
|
+
"aria-labelledby": K,
|
|
42
|
+
...j
|
|
43
|
+
}, W) {
|
|
43
44
|
const {
|
|
44
45
|
disabled: e,
|
|
45
|
-
readOnly:
|
|
46
|
+
readOnly: u,
|
|
46
47
|
required: f,
|
|
47
|
-
invalid:
|
|
48
|
+
invalid: A,
|
|
48
49
|
errorMessageProvided: c,
|
|
49
|
-
defaultValue:
|
|
50
|
+
defaultValue: U,
|
|
50
51
|
errorId: p,
|
|
51
|
-
helperTextId:
|
|
52
|
-
validationErrorsId:
|
|
52
|
+
helperTextId: _,
|
|
53
|
+
validationErrorsId: k,
|
|
53
54
|
labelId: b,
|
|
54
|
-
ariaDescribedBy:
|
|
55
|
-
ariaLabelledBy:
|
|
56
|
-
showErrors:
|
|
57
|
-
} =
|
|
58
|
-
name:
|
|
59
|
-
disabled:
|
|
60
|
-
readOnly:
|
|
61
|
-
required:
|
|
62
|
-
defaultValue:
|
|
63
|
-
error:
|
|
64
|
-
hasHelperText: !!
|
|
55
|
+
ariaDescribedBy: z,
|
|
56
|
+
ariaLabelledBy: G,
|
|
57
|
+
showErrors: J
|
|
58
|
+
} = Ne({
|
|
59
|
+
name: m,
|
|
60
|
+
disabled: P,
|
|
61
|
+
readOnly: T,
|
|
62
|
+
required: M,
|
|
63
|
+
defaultValue: R,
|
|
64
|
+
error: t,
|
|
65
|
+
hasHelperText: !!o,
|
|
65
66
|
hasLabel: !!d,
|
|
66
|
-
validationRules:
|
|
67
|
-
ariaDescribedBy:
|
|
68
|
-
ariaLabelledBy:
|
|
69
|
-
}), { refFn:
|
|
70
|
-
segmentText:
|
|
71
|
-
segmentValues:
|
|
72
|
-
currentValue:
|
|
73
|
-
wasTouched:
|
|
74
|
-
appendDigit:
|
|
75
|
-
beginSegmentEdit:
|
|
76
|
-
commitOnBlur:
|
|
77
|
-
} =
|
|
78
|
-
value:
|
|
79
|
-
defaultValue:
|
|
80
|
-
onChange:
|
|
67
|
+
validationRules: B,
|
|
68
|
+
ariaDescribedBy: $,
|
|
69
|
+
ariaLabelledBy: K
|
|
70
|
+
}), { refFn: Q, ref: g } = Ie(W), { segmentRefs: X, registerSegmentRef: Y } = Be(), {
|
|
71
|
+
segmentText: Z,
|
|
72
|
+
segmentValues: v,
|
|
73
|
+
currentValue: D,
|
|
74
|
+
wasTouched: ee,
|
|
75
|
+
appendDigit: ae,
|
|
76
|
+
beginSegmentEdit: re,
|
|
77
|
+
commitOnBlur: le
|
|
78
|
+
} = Oe({
|
|
79
|
+
value: w,
|
|
80
|
+
defaultValue: U,
|
|
81
|
+
onChange: N
|
|
81
82
|
}), {
|
|
82
83
|
focusedSegment: F,
|
|
83
|
-
fieldTabIndex:
|
|
84
|
-
handleSegmentFocus:
|
|
85
|
-
handleFieldFocus:
|
|
86
|
-
handleFieldBlur:
|
|
87
|
-
handleFieldMouseDown:
|
|
88
|
-
focusNext:
|
|
89
|
-
|
|
84
|
+
fieldTabIndex: ie,
|
|
85
|
+
handleSegmentFocus: h,
|
|
86
|
+
handleFieldFocus: se,
|
|
87
|
+
handleFieldBlur: de,
|
|
88
|
+
handleFieldMouseDown: oe,
|
|
89
|
+
focusNext: x,
|
|
90
|
+
focusPrevious: te
|
|
91
|
+
} = Re({
|
|
92
|
+
disabled: e,
|
|
93
|
+
fieldRef: g,
|
|
94
|
+
segmentRefs: X,
|
|
95
|
+
partsOrder: S,
|
|
96
|
+
onSegmentFocusChange: re,
|
|
97
|
+
onFieldBlur: le
|
|
98
|
+
}), ne = Ve({
|
|
90
99
|
disabled: e,
|
|
91
|
-
fieldRef:
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
currentValue: v,
|
|
99
|
-
wasTouched: Z,
|
|
100
|
+
fieldRef: g,
|
|
101
|
+
focusNext: x,
|
|
102
|
+
focusPrevious: te
|
|
103
|
+
}), { isInvalid: me } = Ce({
|
|
104
|
+
segments: v,
|
|
105
|
+
currentValue: D,
|
|
106
|
+
wasTouched: ee,
|
|
100
107
|
isFocused: F !== null
|
|
101
|
-
}),
|
|
102
|
-
const { advanced:
|
|
103
|
-
|
|
104
|
-
},
|
|
105
|
-
formInvalid:
|
|
106
|
-
valueInvalid:
|
|
107
|
-
}),
|
|
108
|
+
}), ue = (r, i) => {
|
|
109
|
+
const { advanced: pe } = ae(r, i);
|
|
110
|
+
pe && x(r);
|
|
111
|
+
}, y = Pe({
|
|
112
|
+
formInvalid: A,
|
|
113
|
+
valueInvalid: me
|
|
114
|
+
}), fe = (r) => {
|
|
108
115
|
if (e) return;
|
|
109
116
|
const i = r.target.closest("label");
|
|
110
|
-
!i || i.id !== b || (r.preventDefault(),
|
|
111
|
-
},
|
|
112
|
-
a[
|
|
113
|
-
n &&
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
!i || i.id !== b || (r.preventDefault(), h(S[0]));
|
|
118
|
+
}, ce = be(
|
|
119
|
+
a[ve],
|
|
120
|
+
n && Fe(n),
|
|
121
|
+
O && a[`${s}fluid`],
|
|
122
|
+
y && a[`${s}error`],
|
|
116
123
|
e && a[`${s}disabled`],
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
u && a[`${s}read-only`],
|
|
125
|
+
E
|
|
119
126
|
);
|
|
120
|
-
return /* @__PURE__ */
|
|
127
|
+
return /* @__PURE__ */ I(
|
|
121
128
|
"div",
|
|
122
129
|
{
|
|
123
|
-
className:
|
|
124
|
-
style: { ...
|
|
125
|
-
onMouseDownCapture:
|
|
130
|
+
className: ce,
|
|
131
|
+
style: { ...H, maxWidth: C },
|
|
132
|
+
onMouseDownCapture: fe,
|
|
126
133
|
children: [
|
|
127
134
|
/* @__PURE__ */ l(
|
|
128
|
-
|
|
135
|
+
xe,
|
|
129
136
|
{
|
|
130
137
|
ctxId: b,
|
|
131
138
|
ctxDisabled: e,
|
|
132
|
-
ctxRequired: f && !
|
|
139
|
+
ctxRequired: f && !V,
|
|
133
140
|
children: d
|
|
134
141
|
}
|
|
135
142
|
),
|
|
136
143
|
/* @__PURE__ */ l(
|
|
137
144
|
"div",
|
|
138
145
|
{
|
|
139
|
-
|
|
140
|
-
ref:
|
|
141
|
-
id:
|
|
146
|
+
...j,
|
|
147
|
+
ref: Q,
|
|
148
|
+
id: q,
|
|
142
149
|
role: "group",
|
|
143
|
-
"aria-label":
|
|
144
|
-
"aria-labelledby":
|
|
150
|
+
"aria-label": L,
|
|
151
|
+
"aria-labelledby": G,
|
|
145
152
|
"aria-disabled": e || void 0,
|
|
146
153
|
"aria-required": f || void 0,
|
|
147
|
-
"aria-invalid":
|
|
148
|
-
"aria-describedby":
|
|
154
|
+
"aria-invalid": y || void 0,
|
|
155
|
+
"aria-describedby": z,
|
|
149
156
|
"aria-errormessage": c ? p : void 0,
|
|
150
|
-
tabIndex:
|
|
151
|
-
className: a[
|
|
152
|
-
onMouseDown:
|
|
153
|
-
onFocus:
|
|
157
|
+
tabIndex: ie,
|
|
158
|
+
className: a[De.field],
|
|
159
|
+
onMouseDown: oe,
|
|
160
|
+
onFocus: se,
|
|
154
161
|
children: /* @__PURE__ */ l(
|
|
155
|
-
|
|
162
|
+
Se,
|
|
156
163
|
{
|
|
157
|
-
segmentText:
|
|
158
|
-
segmentValues:
|
|
164
|
+
segmentText: Z,
|
|
165
|
+
segmentValues: v,
|
|
159
166
|
focusedSegment: F,
|
|
160
167
|
disabled: e,
|
|
161
|
-
readOnly:
|
|
162
|
-
onSegmentFocus:
|
|
163
|
-
onSegmentBlur:
|
|
164
|
-
onSegmentInput:
|
|
165
|
-
|
|
168
|
+
readOnly: u,
|
|
169
|
+
onSegmentFocus: h,
|
|
170
|
+
onSegmentBlur: de,
|
|
171
|
+
onSegmentInput: ue,
|
|
172
|
+
onSegmentKeyDown: ne,
|
|
173
|
+
registerSegmentRef: Y
|
|
166
174
|
}
|
|
167
175
|
)
|
|
168
176
|
}
|
|
@@ -171,21 +179,21 @@ const Je = pe(
|
|
|
171
179
|
"input",
|
|
172
180
|
{
|
|
173
181
|
type: "hidden",
|
|
174
|
-
name:
|
|
175
|
-
value:
|
|
182
|
+
name: m,
|
|
183
|
+
value: we(D),
|
|
176
184
|
disabled: e
|
|
177
185
|
}
|
|
178
186
|
),
|
|
179
|
-
/* @__PURE__ */
|
|
180
|
-
|
|
181
|
-
c && /* @__PURE__ */ l(
|
|
187
|
+
/* @__PURE__ */ I(ye, { ctxId: _, ctxDisabled: e, children: [
|
|
188
|
+
o,
|
|
189
|
+
c && /* @__PURE__ */ l(he, { id: p, appearance: "negative", children: t })
|
|
182
190
|
] }),
|
|
183
|
-
|
|
191
|
+
J(k)
|
|
184
192
|
]
|
|
185
193
|
}
|
|
186
194
|
);
|
|
187
195
|
}
|
|
188
196
|
);
|
|
189
197
|
export {
|
|
190
|
-
|
|
198
|
+
Ye as DateField
|
|
191
199
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
@@ -104,7 +104,9 @@ export interface DateFieldSegmentProps {
|
|
|
104
104
|
isActive: boolean;
|
|
105
105
|
disabled: boolean;
|
|
106
106
|
readOnly: boolean;
|
|
107
|
+
/** Fires when the segment gains focus (Tab, click, or programmatic). */
|
|
107
108
|
onFocus: () => void;
|
|
109
|
+
/** Fires when focus leaves the segment; `relatedTarget` drives field-exit detection. */
|
|
108
110
|
onBlur: (event: FocusEvent<HTMLSpanElement>) => void;
|
|
109
111
|
/**
|
|
110
112
|
* Single-character input callback. DF-2 single-digit typing path. The
|
|
@@ -113,6 +115,12 @@ export interface DateFieldSegmentProps {
|
|
|
113
115
|
* DF-13 will add a paste-aware branch for whole-value parsing.
|
|
114
116
|
*/
|
|
115
117
|
onInput: (type: SegmentType, char: string) => void;
|
|
118
|
+
/**
|
|
119
|
+
* Fires on segment keydown. The orchestrator routes it into
|
|
120
|
+
* `useDateFieldKeyboard` (DF-3: ArrowLeft/Right segment nav, RTL-aware;
|
|
121
|
+
* DF-4/DF-5 extend with increment/clear).
|
|
122
|
+
*/
|
|
123
|
+
onKeyDown: (type: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
|
|
116
124
|
segmentRef: (element: HTMLSpanElement | null) => void;
|
|
117
125
|
}
|
|
118
126
|
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(),
|
|
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(),c=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}`},m=e=>e.filter(t=>t.type!=="literal").map(t=>t.type),d=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},N=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.clearSelectionWithin=f;exports.deriveValue=s;exports.deriveValueFromText=S;exports.getSegmentDisplay=T;exports.getSegmentOrder=m;exports.isSameDateValue=g;exports.normalizeSegmentText=y;exports.segmentNumber=l;exports.segmentTextFromValue=d;exports.selectElementContents=N;exports.toISODateString=c;
|
|
@@ -24,3 +24,8 @@ export interface SegmentDisplay {
|
|
|
24
24
|
export declare const getSegmentDisplay: (type: SegmentType, text: string, placeholder: string) => SegmentDisplay;
|
|
25
25
|
/** Selects an element's entire textContent (whole-segment highlight). */
|
|
26
26
|
export declare const selectElementContents: (element: HTMLElement) => void;
|
|
27
|
+
/** Clears the DOM selection when it currently lives inside `container`. Chrome
|
|
28
|
+
* leaves the whole-segment Range highlighted after the field blurs; Safari
|
|
29
|
+
* clears it automatically. Scoped to `container` so a selection elsewhere on
|
|
30
|
+
* the page is untouched. */
|
|
31
|
+
export declare const clearSelectionWithin: (container: HTMLElement | null) => void;
|
|
@@ -4,13 +4,13 @@ const s = { day: "", month: "", year: "" }, i = (e) => e instanceof Date && !Num
|
|
|
4
4
|
if (t == null || n == null || r == null) return null;
|
|
5
5
|
const a = new Date(r, n - 1, t);
|
|
6
6
|
return a.setFullYear(r), Number.isNaN(a.getTime()) || a.getFullYear() !== r || a.getMonth() !== n - 1 || a.getDate() !== t ? null : a;
|
|
7
|
-
},
|
|
7
|
+
}, g = (e, t) => e == null && t == null ? !0 : e == null || t == null ? !1 : e.getTime() === t.getTime(), d = (e) => {
|
|
8
8
|
if (!i(e)) return "";
|
|
9
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
10
|
return `${t}-${n}-${r}`;
|
|
11
|
-
},
|
|
11
|
+
}, m = (e) => e.filter(
|
|
12
12
|
(t) => t.type !== "literal"
|
|
13
|
-
).map((t) => t.type),
|
|
13
|
+
).map((t) => t.type), S = (e) => i(e) ? {
|
|
14
14
|
day: String(e.getDate()).padStart(2, "0"),
|
|
15
15
|
month: String(e.getMonth() + 1).padStart(2, "0"),
|
|
16
16
|
year: String(e.getFullYear()).padStart(4, "0")
|
|
@@ -18,28 +18,34 @@ const s = { day: "", month: "", year: "" }, i = (e) => e instanceof Date && !Num
|
|
|
18
18
|
if (t === "" || e === "year" && t.length < o.year) return null;
|
|
19
19
|
const n = parseInt(t, 10);
|
|
20
20
|
return Number.isNaN(n) || n === 0 ? null : n;
|
|
21
|
-
},
|
|
21
|
+
}, y = (e) => u({
|
|
22
22
|
day: l("day", e.day),
|
|
23
23
|
month: l("month", e.month),
|
|
24
24
|
year: l("year", e.year)
|
|
25
|
-
}),
|
|
25
|
+
}), f = (e, t) => t === "" ? "" : t.padStart(o[e], "0"), p = (e, t, n) => t === "" ? { displayValue: n, isPlaceholder: !0 } : {
|
|
26
26
|
displayValue: t.padStart(o[e], "0"),
|
|
27
27
|
isPlaceholder: !1
|
|
28
|
-
},
|
|
28
|
+
}, h = (e) => {
|
|
29
29
|
const t = window.getSelection();
|
|
30
30
|
if (!t) return;
|
|
31
31
|
const n = document.createRange();
|
|
32
32
|
n.selectNodeContents(e), t.removeAllRanges(), t.addRange(n);
|
|
33
|
+
}, N = (e) => {
|
|
34
|
+
var n;
|
|
35
|
+
if (!e) return;
|
|
36
|
+
const t = (n = window.getSelection) == null ? void 0 : n.call(window);
|
|
37
|
+
t && t.rangeCount > 0 && e.contains(t.anchorNode) && t.removeAllRanges();
|
|
33
38
|
};
|
|
34
39
|
export {
|
|
40
|
+
N as clearSelectionWithin,
|
|
35
41
|
u as deriveValue,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
y as deriveValueFromText,
|
|
43
|
+
p as getSegmentDisplay,
|
|
44
|
+
m as getSegmentOrder,
|
|
45
|
+
g as isSameDateValue,
|
|
46
|
+
f as normalizeSegmentText,
|
|
41
47
|
l as segmentNumber,
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
S as segmentTextFromValue,
|
|
49
|
+
h as selectElementContents,
|
|
44
50
|
d as toISODateString
|
|
45
51
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
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:
|
|
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
|
|
2
|
-
|
|
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:
|
|
5
|
-
segmentRefs:
|
|
6
|
-
partsOrder:
|
|
7
|
-
onSegmentFocusChange:
|
|
8
|
-
onFieldBlur:
|
|
5
|
+
fieldRef: i,
|
|
6
|
+
segmentRefs: v,
|
|
7
|
+
partsOrder: f,
|
|
8
|
+
onSegmentFocusChange: T,
|
|
9
|
+
onFieldBlur: D
|
|
9
10
|
}) {
|
|
10
|
-
const [
|
|
11
|
-
|
|
12
|
-
r.current =
|
|
13
|
-
}, [
|
|
14
|
-
if (
|
|
15
|
-
const t =
|
|
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
|
-
}, [
|
|
18
|
-
const
|
|
18
|
+
}, [s, v]);
|
|
19
|
+
const k = e(
|
|
19
20
|
(t) => {
|
|
20
|
-
var
|
|
21
|
-
n || (
|
|
21
|
+
var c;
|
|
22
|
+
n || (l(t), (c = r.current) == null || c.call(r, t));
|
|
22
23
|
},
|
|
23
24
|
[n]
|
|
24
|
-
),
|
|
25
|
+
), w = e(
|
|
25
26
|
(t) => {
|
|
26
|
-
var
|
|
27
|
-
n || t.target ===
|
|
27
|
+
var c;
|
|
28
|
+
n || t.target === i.current && (l(o), (c = r.current) == null || c.call(r, o));
|
|
28
29
|
},
|
|
29
|
-
[n,
|
|
30
|
-
),
|
|
30
|
+
[n, i, o]
|
|
31
|
+
), M = e(
|
|
31
32
|
(t) => {
|
|
32
|
-
var
|
|
33
|
-
(
|
|
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
|
-
[
|
|
36
|
-
),
|
|
36
|
+
[i]
|
|
37
|
+
), N = e(
|
|
37
38
|
(t) => {
|
|
38
|
-
var
|
|
39
|
+
var u;
|
|
39
40
|
if (n) return;
|
|
40
|
-
t.target.closest("[data-segment]") || (t.preventDefault(),
|
|
41
|
+
t.target.closest("[data-segment]") || (t.preventDefault(), l(o), (u = r.current) == null || u.call(r, o));
|
|
41
42
|
},
|
|
42
|
-
[n,
|
|
43
|
-
),
|
|
44
|
-
(t) => {
|
|
45
|
-
var
|
|
46
|
-
const u =
|
|
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
|
|
49
|
-
|
|
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
|
-
[
|
|
62
|
+
[x]
|
|
52
63
|
);
|
|
53
64
|
return {
|
|
54
|
-
focusedSegment:
|
|
55
|
-
fieldTabIndex: n ? -1 :
|
|
56
|
-
handleSegmentFocus:
|
|
57
|
-
handleFieldFocus:
|
|
58
|
-
handleFieldBlur:
|
|
59
|
-
handleFieldMouseDown:
|
|
60
|
-
focusNext:
|
|
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
|
-
|
|
76
|
+
G as useDateFieldFocus
|
|
65
77
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react");function s({disabled:l,fieldRef:o,focusNext:e,focusPrevious:i}){const a=u.useMemo(()=>({ArrowRight:({segment:r,isRTL:t})=>(t?i:e)(r),ArrowLeft:({segment:r,isRTL:t})=>(t?e:i)(r)}),[e,i]);return u.useCallback((r,t)=>{if(l||t.altKey||t.ctrlKey||t.metaKey||t.shiftKey)return;const c=a[t.key];if(!c)return;t.preventDefault();const n=o.current,y=!!n&&(getComputedStyle(n).direction==="rtl"||!!n.closest('[dir="rtl"]'));c({segment:r,event:t,isRTL:y})},[l,a,o])}exports.useDateFieldKeyboard=s;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { KeyboardEvent, RefObject } from 'react';
|
|
2
|
+
import { 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
|
+
/** A key binding: runs the action for one key, given the call context. */
|
|
13
|
+
export type SegmentKeyBinding = (ctx: SegmentKeyContext) => void;
|
|
14
|
+
export interface UseDateFieldKeyboardArgs {
|
|
15
|
+
/** When true, the dispatcher ignores all keys. */
|
|
16
|
+
disabled: boolean;
|
|
17
|
+
/** Field root ref, used to detect RTL direction. */
|
|
18
|
+
fieldRef: RefObject<HTMLDivElement>;
|
|
19
|
+
/** Move focus to the next segment in `PARTS_ORDER`. */
|
|
20
|
+
focusNext: (segment: SegmentType) => void;
|
|
21
|
+
/** Move focus to the previous segment in `PARTS_ORDER`. */
|
|
22
|
+
focusPrevious: (segment: SegmentType) => void;
|
|
23
|
+
}
|
|
24
|
+
export declare function useDateFieldKeyboard({ disabled, fieldRef, focusNext, focusPrevious, }: UseDateFieldKeyboardArgs): (segment: SegmentType, event: KeyboardEvent<HTMLSpanElement>) => void;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useMemo as m, useCallback as s } from "react";
|
|
2
|
+
function K({
|
|
3
|
+
disabled: l,
|
|
4
|
+
fieldRef: o,
|
|
5
|
+
focusNext: i,
|
|
6
|
+
focusPrevious: n
|
|
7
|
+
}) {
|
|
8
|
+
const y = m(
|
|
9
|
+
() => ({
|
|
10
|
+
ArrowRight: ({ segment: t, isRTL: r }) => (r ? n : i)(t),
|
|
11
|
+
ArrowLeft: ({ segment: t, isRTL: r }) => (r ? i : n)(t)
|
|
12
|
+
// ── Extension points ─────────────────────────────────────────────
|
|
13
|
+
// DF-4: ArrowUp / ArrowDown (increment/decrement), PageUp / PageDown,
|
|
14
|
+
// Home / End (min/max of current segment) → value actions
|
|
15
|
+
// DF-5: Backspace / Delete (clear segment) → value action
|
|
16
|
+
}),
|
|
17
|
+
[i, n]
|
|
18
|
+
);
|
|
19
|
+
return s(
|
|
20
|
+
(t, r) => {
|
|
21
|
+
if (l || r.altKey || r.ctrlKey || r.metaKey || r.shiftKey) return;
|
|
22
|
+
const a = y[r.key];
|
|
23
|
+
if (!a) return;
|
|
24
|
+
r.preventDefault();
|
|
25
|
+
const e = o.current, c = !!e && (getComputedStyle(e).direction === "rtl" || !!e.closest('[dir="rtl"]'));
|
|
26
|
+
a({ segment: t, event: r, isRTL: c });
|
|
27
|
+
},
|
|
28
|
+
[l, y, o]
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
K as useDateFieldKeyboard
|
|
33
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viasat/beam-react",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.40.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.
|
|
63
|
-
"@viasat/beam-shared": "2.
|
|
64
|
-
"@viasat/beam-styles": "2.
|
|
65
|
-
"@viasat/beam-tokens": "2.
|
|
66
|
-
"@viasat/beam-icons": "2.
|
|
62
|
+
"@viasat/beam-fonts": "2.40.0",
|
|
63
|
+
"@viasat/beam-shared": "2.40.0",
|
|
64
|
+
"@viasat/beam-styles": "2.40.0",
|
|
65
|
+
"@viasat/beam-tokens": "2.40.0",
|
|
66
|
+
"@viasat/beam-icons": "2.40.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;
|