@servicetitan/anvil2 1.27.2 → 1.29.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/CHANGELOG.md +76 -0
- package/dist/AnvilProvider-C7Li86-d.js +16 -0
- package/dist/AnvilProvider-C7Li86-d.js.map +1 -0
- package/dist/AnvilProvider.js +1 -1
- package/dist/{Combobox-DnTI2I3L.js → Combobox-DCrEfyl2.js} +2209 -228
- package/dist/Combobox-DCrEfyl2.js.map +1 -0
- package/dist/Combobox.css +443 -69
- package/dist/Combobox.js +1 -1
- package/dist/DateField-4jR9NvbC.js +1109 -0
- package/dist/DateField-4jR9NvbC.js.map +1 -0
- package/dist/DateField.js +1 -1
- package/dist/{Dialog-DQ9QXB5D.js → Dialog-CL3bfZuB.js} +2 -2
- package/dist/{Dialog-DQ9QXB5D.js.map → Dialog-CL3bfZuB.js.map} +1 -1
- package/dist/{Dialog-Kh2tcVWz-DqcNnouf.js → Dialog-CYBt_JdP-CmF0MUHL.js} +80 -51
- package/dist/Dialog-CYBt_JdP-CmF0MUHL.js.map +1 -0
- package/dist/Dialog.js +1 -1
- package/dist/Drawer-8nHrKktU.js +66 -0
- package/dist/Drawer-8nHrKktU.js.map +1 -0
- package/dist/{Drawer-C6fpnRDX.js → Drawer-UQlX-LQG-BSCnMRad.js} +97 -130
- package/dist/Drawer-UQlX-LQG-BSCnMRad.js.map +1 -0
- package/dist/{Drawer.css → Drawer-UQlX-LQG.css} +26 -25
- package/dist/Drawer.js +1 -1
- package/dist/{AnvilProvider-DNJk1Ait.js → HammerProvider-DuxhW0gv-C2voN5ro.js} +26 -15
- package/dist/HammerProvider-DuxhW0gv-C2voN5ro.js.map +1 -0
- package/dist/InputMask-B8N8PP1W-DlUKpMR4.js +323 -0
- package/dist/InputMask-B8N8PP1W-DlUKpMR4.js.map +1 -0
- package/dist/{InputMask-Ceh574pv.js → InputMask-jsL7rSOk.js} +2 -2
- package/dist/{InputMask-Ceh574pv.js.map → InputMask-jsL7rSOk.js.map} +1 -1
- package/dist/InputMask.js +1 -1
- package/dist/{Label-DWF2pXeG-1BhzVgZG.js → Label-CUVr-jvI-BXhER5eQ.js} +3 -3
- package/dist/{Label-DWF2pXeG-1BhzVgZG.js.map → Label-CUVr-jvI-BXhER5eQ.js.map} +1 -1
- package/dist/Menu-CsfX8-_z.js +1091 -0
- package/dist/Menu-CsfX8-_z.js.map +1 -0
- package/dist/Menu.css +116 -1
- package/dist/Menu.js +1 -1
- package/dist/{Page-BGkLs3bR.js → Page-vKi5JkDS.js} +70 -54
- package/dist/Page-vKi5JkDS.js.map +1 -0
- package/dist/Page.css +103 -70
- package/dist/Page.js +1 -1
- package/dist/{Popover-DzEc_Muv.js → Popover-OFlyW8gN.js} +2 -2
- package/dist/{Popover-DzEc_Muv.js.map → Popover-OFlyW8gN.js.map} +1 -1
- package/dist/{Popover-QKZtjN4_-CETYlWwq.js → Popover-tu_N1aS6-CSLR1Xzc.js} +351 -12
- package/dist/Popover-tu_N1aS6-CSLR1Xzc.js.map +1 -0
- package/dist/{Popover-QKZtjN4_.css → Popover-tu_N1aS6.css} +53 -1
- package/dist/Popover.js +1 -1
- package/dist/{ProgressBar-cKtBso7j-3CDyBaAN.js → ProgressBar-DQ1lsFk2-Ci4eqzM0.js} +3 -3
- package/dist/{ProgressBar-cKtBso7j-3CDyBaAN.js.map → ProgressBar-DQ1lsFk2-Ci4eqzM0.js.map} +1 -1
- package/dist/{ProgressBar-IItIByYc.js → ProgressBar-gVRLaKPz.js} +2 -2
- package/dist/{ProgressBar-IItIByYc.js.map → ProgressBar-gVRLaKPz.js.map} +1 -1
- package/dist/ProgressBar.js +1 -1
- package/dist/{SearchField-CWb0kaV8.js → SearchField-C-4icPUa.js} +2 -2
- package/dist/{SearchField-CWb0kaV8.js.map → SearchField-C-4icPUa.js.map} +1 -1
- package/dist/SearchField.js +1 -1
- package/dist/{TextField-D53XNiCi-C6_A5VRq.js → TextField-B8LHWOoC-DSV9zY-z.js} +2 -2
- package/dist/{TextField-D53XNiCi-C6_A5VRq.js.map → TextField-B8LHWOoC-DSV9zY-z.js.map} +1 -1
- package/dist/{TextField-s92xHzb3.js → TextField-DgxJO1a7.js} +2 -2
- package/dist/{TextField-s92xHzb3.js.map → TextField-DgxJO1a7.js.map} +1 -1
- package/dist/TextField.js +1 -1
- package/dist/{Textarea-B61wNIFr.js → Textarea-B-Dv2RXs.js} +2 -2
- package/dist/{Textarea-B61wNIFr.js.map → Textarea-B-Dv2RXs.js.map} +1 -1
- package/dist/Textarea.js +1 -1
- package/dist/Toast.js +1 -1
- package/dist/{Toolbar-Cge6Nznj.js → Toolbar-7BeCY61H.js} +2 -2
- package/dist/{Toolbar-Cge6Nznj.js.map → Toolbar-7BeCY61H.js.map} +1 -1
- package/dist/Toolbar.js +1 -1
- package/dist/{Tooltip-89FIvMG0.js → Tooltip-BVBq-KxK.js} +2 -2
- package/dist/{Tooltip-89FIvMG0.js.map → Tooltip-BVBq-KxK.js.map} +1 -1
- package/dist/{Tooltip-DgM8NSPm-CRIQbuTm.js → Tooltip-C8sCGmKM-CLrDofvy.js} +222 -22
- package/dist/Tooltip-C8sCGmKM-CLrDofvy.js.map +1 -0
- package/dist/{Tooltip-DgM8NSPm.css → Tooltip-C8sCGmKM.css} +43 -1
- package/dist/Tooltip.js +1 -1
- package/dist/components/Dialog/Dialog.d.ts +1 -0
- package/dist/components/Drawer/Drawer.d.ts +1 -0
- package/dist/components/Page/Page.d.ts +4 -1
- package/dist/floating-ui.react-4AwURJA3.js +5989 -0
- package/dist/floating-ui.react-4AwURJA3.js.map +1 -0
- package/dist/{useKeyboardFocusables-CwVMAe5C-CIHqixNA.js → index.esm-CunAFnrh.js} +11 -59
- package/dist/index.esm-CunAFnrh.js.map +1 -0
- package/dist/index.js +16 -16
- package/dist/supportsPopover-8aJR37cf-8aJR37cf.js +6 -0
- package/dist/supportsPopover-8aJR37cf-8aJR37cf.js.map +1 -0
- package/dist/{toast-CHld8RKY.js → toast-CbokOkfo.js} +6 -2
- package/dist/toast-CbokOkfo.js.map +1 -0
- package/dist/useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js +61 -0
- package/dist/useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js.map +1 -0
- package/package.json +3 -3
- package/dist/AnvilProvider-DNJk1Ait.js.map +0 -1
- package/dist/Combobox-DnTI2I3L.js.map +0 -1
- package/dist/DateField-DocC46Mw.js +0 -565
- package/dist/DateField-DocC46Mw.js.map +0 -1
- package/dist/Dialog-Kh2tcVWz-DqcNnouf.js.map +0 -1
- package/dist/Drawer-C6fpnRDX.js.map +0 -1
- package/dist/InputMask-DQXw5qvG-BH4P-Woc.js +0 -195
- package/dist/InputMask-DQXw5qvG-BH4P-Woc.js.map +0 -1
- package/dist/Menu-D8SDm9s9.js +0 -706
- package/dist/Menu-D8SDm9s9.js.map +0 -1
- package/dist/Page-BGkLs3bR.js.map +0 -1
- package/dist/Popover-QKZtjN4_-CETYlWwq.js.map +0 -1
- package/dist/Tooltip-DgM8NSPm-CRIQbuTm.js.map +0 -1
- package/dist/floating-ui.react-P5949bpO.js +0 -28
- package/dist/floating-ui.react-P5949bpO.js.map +0 -1
- package/dist/floating-ui.react-dom-D912oS4K.js +0 -1841
- package/dist/floating-ui.react-dom-D912oS4K.js.map +0 -1
- package/dist/toast-CHld8RKY.js.map +0 -1
- package/dist/useKeyboardFocusables-CwVMAe5C-CIHqixNA.js.map +0 -1
- /package/dist/{Dialog-Kh2tcVWz.css → Dialog-CYBt_JdP.css} +0 -0
- /package/dist/{Label-DWF2pXeG.css → Label-CUVr-jvI.css} +0 -0
- /package/dist/{ProgressBar-cKtBso7j.css → ProgressBar-DQ1lsFk2.css} +0 -0
|
@@ -0,0 +1,1109 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { forwardRef, useState, useRef, useMemo, useEffect } from 'react';
|
|
4
|
+
import { useTrackingId } from './useTrackingId.js';
|
|
5
|
+
import { c as childrenToString } from './childrenToString-Bz9MqbHb-Bz9MqbHb.js';
|
|
6
|
+
import { I as InputMask } from './InputMask-B8N8PP1W-DlUKpMR4.js';
|
|
7
|
+
import { D as DateTime, t as toDateString, i as isValidDate, C as Calendar } from './Calendar-9iYMS0Iw-D_XWYjOE.js';
|
|
8
|
+
import { I as Icon } from './Icon-DbHA5GV1-DwO2aGkj.js';
|
|
9
|
+
import { s as supportsPopover } from './supportsPopover-8aJR37cf-8aJR37cf.js';
|
|
10
|
+
import { T as TextField } from './TextField-B8LHWOoC-DSV9zY-z.js';
|
|
11
|
+
import { e as PopoverLegacy, d as Popover } from './Popover-tu_N1aS6-CSLR1Xzc.js';
|
|
12
|
+
import { u as useMergeRefs } from './floating-ui.react-4AwURJA3.js';
|
|
13
|
+
import { u as useKeyboardFocusables } from './useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js';
|
|
14
|
+
import { u as useMergeRefs$1 } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
|
|
15
|
+
|
|
16
|
+
const SvgEvent = (props) => /* @__PURE__ */ React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "1em", height: "1em", viewBox: "0 0 24 24", ...props }, /* @__PURE__ */ React.createElement("path", { d: "M16 13h-3c-.55 0-1 .45-1 1v3c0 .55.45 1 1 1h3c.55 0 1-.45 1-1v-3c0-.55-.45-1-1-1zm0-10v1H8V3c0-.55-.45-1-1-1s-1 .45-1 1v1H5c-1.11 0-1.99.9-1.99 2L3 20a2 2 0 0 0 2 2h14c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2h-1V3c0-.55-.45-1-1-1s-1 .45-1 1zm2 17H6c-.55 0-1-.45-1-1V9h14v10c0 .55-.45 1-1 1z" }));
|
|
17
|
+
|
|
18
|
+
const RANGE_DIVIDER$1 = " — ";
|
|
19
|
+
const DateFieldLegacy = forwardRef(
|
|
20
|
+
({
|
|
21
|
+
// DateFieldLegacy
|
|
22
|
+
openCalendar,
|
|
23
|
+
onFocus,
|
|
24
|
+
onBlur,
|
|
25
|
+
onChange,
|
|
26
|
+
format = "MM/dd/yyyy",
|
|
27
|
+
disableHint,
|
|
28
|
+
// Calendar
|
|
29
|
+
minDate,
|
|
30
|
+
maxDate,
|
|
31
|
+
unavailableDates,
|
|
32
|
+
unavailable,
|
|
33
|
+
startDay,
|
|
34
|
+
defaultValue,
|
|
35
|
+
value: inputValue,
|
|
36
|
+
// Shared
|
|
37
|
+
locale = Intl.DateTimeFormat().resolvedOptions().locale,
|
|
38
|
+
defaultTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
39
|
+
range,
|
|
40
|
+
// Input
|
|
41
|
+
required,
|
|
42
|
+
...inputProps
|
|
43
|
+
}, ref) => {
|
|
44
|
+
const [open, setOpen] = useState(openCalendar || false);
|
|
45
|
+
const [internalValue, setInternalValue] = useState();
|
|
46
|
+
const [disableFocusLock, setDisableFocusLock] = useState(true);
|
|
47
|
+
const inputRef = useRef(null);
|
|
48
|
+
const calRef = useRef(null);
|
|
49
|
+
const iconRef = useRef(null);
|
|
50
|
+
const docRef = useRef(null);
|
|
51
|
+
const floatRef = useRef(null);
|
|
52
|
+
const isClickOutside = useRef(false);
|
|
53
|
+
const formatMask = format.replace(/[^/]/g, "_");
|
|
54
|
+
const hint = useMemo(
|
|
55
|
+
() => disableHint ? undefined : `format: ${format.replace(/M/g, "m")}`,
|
|
56
|
+
[format, disableHint]
|
|
57
|
+
);
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (!docRef.current) {
|
|
60
|
+
if (document != null) {
|
|
61
|
+
docRef.current = document;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const doc = inputRef.current?.closest("body")?.ownerDocument;
|
|
65
|
+
doc && (docRef.current = doc);
|
|
66
|
+
if (docRef.current == null && inputRef.current?.parentNode != null) {
|
|
67
|
+
let node = inputRef.current?.parentNode;
|
|
68
|
+
while (node.parentNode != null) {
|
|
69
|
+
node = node.parentNode;
|
|
70
|
+
}
|
|
71
|
+
docRef.current = node;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const clickOutHandler = (ev) => {
|
|
75
|
+
const realTarget = ev.composedPath()[0];
|
|
76
|
+
if (!floatRef.current?.contains(realTarget) && !iconRef.current?.contains(realTarget) && inputRef.current !== realTarget) {
|
|
77
|
+
setOpen(false);
|
|
78
|
+
setDisableFocusLock(true);
|
|
79
|
+
onBlur?.(ev);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
if (open) {
|
|
83
|
+
docRef.current?.addEventListener("click", clickOutHandler);
|
|
84
|
+
} else {
|
|
85
|
+
docRef.current?.removeEventListener("click", clickOutHandler);
|
|
86
|
+
}
|
|
87
|
+
return () => {
|
|
88
|
+
docRef.current?.removeEventListener("click", clickOutHandler);
|
|
89
|
+
};
|
|
90
|
+
}, [open, onBlur]);
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
if (range) {
|
|
93
|
+
let start;
|
|
94
|
+
let end;
|
|
95
|
+
if (typeof inputValue === "string") {
|
|
96
|
+
const parts = inputValue.split(RANGE_DIVIDER$1);
|
|
97
|
+
start = parts[0];
|
|
98
|
+
end = parts[1];
|
|
99
|
+
} else {
|
|
100
|
+
start = inputValue?.start ?? "";
|
|
101
|
+
end = inputValue?.end ?? "";
|
|
102
|
+
}
|
|
103
|
+
const startDate = DateTime.fromFormat(start ?? "", format, {
|
|
104
|
+
zone: defaultTimeZone
|
|
105
|
+
}).startOf("day");
|
|
106
|
+
const endDate = DateTime.fromFormat(end ?? "", format, {
|
|
107
|
+
zone: defaultTimeZone
|
|
108
|
+
}).startOf("day");
|
|
109
|
+
const newData = {
|
|
110
|
+
start: {
|
|
111
|
+
value: start,
|
|
112
|
+
date: toDateString(startDate),
|
|
113
|
+
isValid: startDate.isValid && isValidDate(
|
|
114
|
+
startDate,
|
|
115
|
+
minDate,
|
|
116
|
+
maxDate,
|
|
117
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
118
|
+
{
|
|
119
|
+
dates: new Set(unavailable?.dates),
|
|
120
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
121
|
+
},
|
|
122
|
+
defaultTimeZone
|
|
123
|
+
)
|
|
124
|
+
},
|
|
125
|
+
end: {
|
|
126
|
+
value: end,
|
|
127
|
+
date: toDateString(endDate),
|
|
128
|
+
isValid: startDate.isValid && isValidDate(
|
|
129
|
+
endDate,
|
|
130
|
+
minDate,
|
|
131
|
+
maxDate,
|
|
132
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
133
|
+
{
|
|
134
|
+
dates: new Set(unavailable?.dates),
|
|
135
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
136
|
+
},
|
|
137
|
+
defaultTimeZone
|
|
138
|
+
)
|
|
139
|
+
},
|
|
140
|
+
value: `${start || formatMask}${RANGE_DIVIDER$1}${end || formatMask}`
|
|
141
|
+
};
|
|
142
|
+
setInternalValue(newData);
|
|
143
|
+
} else {
|
|
144
|
+
if (typeof inputValue !== "string") return;
|
|
145
|
+
const inputDate = DateTime.fromFormat(inputValue, format, {
|
|
146
|
+
zone: defaultTimeZone
|
|
147
|
+
}).startOf("day");
|
|
148
|
+
const newData = {
|
|
149
|
+
value: inputValue,
|
|
150
|
+
date: toDateString(inputDate),
|
|
151
|
+
isValid: inputDate.isValid && isValidDate(
|
|
152
|
+
inputDate,
|
|
153
|
+
minDate,
|
|
154
|
+
maxDate,
|
|
155
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
156
|
+
{
|
|
157
|
+
dates: new Set(unavailable?.dates),
|
|
158
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
159
|
+
},
|
|
160
|
+
defaultTimeZone
|
|
161
|
+
)
|
|
162
|
+
};
|
|
163
|
+
setInternalValue(newData);
|
|
164
|
+
}
|
|
165
|
+
}, [inputValue]);
|
|
166
|
+
const mask = useMemo(() => {
|
|
167
|
+
const maskPart = format.replace(/[Mdy]/g, "9");
|
|
168
|
+
if (range) {
|
|
169
|
+
return maskPart + RANGE_DIVIDER$1 + maskPart;
|
|
170
|
+
} else {
|
|
171
|
+
return maskPart;
|
|
172
|
+
}
|
|
173
|
+
}, [format, range]);
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
if (typeof inputValue === "string") return;
|
|
176
|
+
if (defaultValue) {
|
|
177
|
+
if (range) {
|
|
178
|
+
const defValStart = defaultValue.start;
|
|
179
|
+
const defValEnd = defaultValue.end;
|
|
180
|
+
const initValStart = defValStart + (formatMask + RANGE_DIVIDER$1 + formatMask).slice(
|
|
181
|
+
defValStart?.length
|
|
182
|
+
);
|
|
183
|
+
const initValEnd = defValEnd + (formatMask + RANGE_DIVIDER$1 + formatMask).slice(defValEnd?.length);
|
|
184
|
+
const newValue = initValStart + RANGE_DIVIDER$1 + initValEnd;
|
|
185
|
+
const inputDateStart = DateTime.fromFormat(
|
|
186
|
+
defValStart || "",
|
|
187
|
+
format,
|
|
188
|
+
{
|
|
189
|
+
zone: defaultTimeZone
|
|
190
|
+
}
|
|
191
|
+
).startOf("day");
|
|
192
|
+
const inputDateEnd = DateTime.fromFormat(defValEnd || "", format, {
|
|
193
|
+
zone: defaultTimeZone
|
|
194
|
+
}).startOf("day");
|
|
195
|
+
const isValidStart = inputDateStart.isValid && isValidDate(
|
|
196
|
+
inputDateStart,
|
|
197
|
+
minDate,
|
|
198
|
+
maxDate,
|
|
199
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
200
|
+
{
|
|
201
|
+
dates: new Set(unavailable?.dates),
|
|
202
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
203
|
+
},
|
|
204
|
+
defaultTimeZone
|
|
205
|
+
);
|
|
206
|
+
const isValidEnd = inputDateEnd.isValid && isValidDate(
|
|
207
|
+
inputDateEnd,
|
|
208
|
+
minDate,
|
|
209
|
+
maxDate,
|
|
210
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
211
|
+
{
|
|
212
|
+
dates: new Set(unavailable?.dates),
|
|
213
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
214
|
+
},
|
|
215
|
+
defaultTimeZone
|
|
216
|
+
);
|
|
217
|
+
const initCalendarValue = {
|
|
218
|
+
start: {
|
|
219
|
+
value: initValStart,
|
|
220
|
+
date: toDateString(inputDateStart),
|
|
221
|
+
isValid: isValidStart
|
|
222
|
+
},
|
|
223
|
+
end: {
|
|
224
|
+
value: initValEnd,
|
|
225
|
+
date: toDateString(inputDateEnd),
|
|
226
|
+
isValid: isValidEnd
|
|
227
|
+
},
|
|
228
|
+
value: newValue
|
|
229
|
+
};
|
|
230
|
+
setInternalValue(initCalendarValue);
|
|
231
|
+
} else {
|
|
232
|
+
const defVal = defaultValue;
|
|
233
|
+
const initVal = defVal + formatMask.slice(defVal.length);
|
|
234
|
+
const inputDate = DateTime.fromFormat(defVal, format, {
|
|
235
|
+
zone: defaultTimeZone
|
|
236
|
+
}).startOf("day");
|
|
237
|
+
const isValid = inputDate.isValid && isValidDate(
|
|
238
|
+
inputDate,
|
|
239
|
+
minDate,
|
|
240
|
+
maxDate,
|
|
241
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
242
|
+
{
|
|
243
|
+
dates: new Set(unavailable?.dates),
|
|
244
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
245
|
+
},
|
|
246
|
+
defaultTimeZone
|
|
247
|
+
);
|
|
248
|
+
const initCalendarValue = {
|
|
249
|
+
value: initVal,
|
|
250
|
+
date: toDateString(inputDate),
|
|
251
|
+
isValid
|
|
252
|
+
};
|
|
253
|
+
setInternalValue(initCalendarValue);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}, []);
|
|
257
|
+
const focusToCalendar = () => {
|
|
258
|
+
if (calRef.current) {
|
|
259
|
+
const currentFocusable = calRef.current.querySelectorAll('[tabindex = "0"]')[0];
|
|
260
|
+
if (currentFocusable) {
|
|
261
|
+
currentFocusable.focus();
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
const handleInputKeyDown = (ev) => {
|
|
266
|
+
switch (ev.key) {
|
|
267
|
+
case "Tab":
|
|
268
|
+
setOpen(false);
|
|
269
|
+
break;
|
|
270
|
+
case "ArrowDown":
|
|
271
|
+
if (!open) {
|
|
272
|
+
setOpen(true);
|
|
273
|
+
setTimeout(focusToCalendar, 100);
|
|
274
|
+
} else {
|
|
275
|
+
focusToCalendar();
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
const handleInputChange = (ev) => {
|
|
280
|
+
if (range) {
|
|
281
|
+
const parts = ev.target.value.split(RANGE_DIVIDER$1);
|
|
282
|
+
if (parts.length !== 2) return;
|
|
283
|
+
const startDate = DateTime.fromFormat(parts[0], format, {
|
|
284
|
+
zone: defaultTimeZone
|
|
285
|
+
}).startOf("day");
|
|
286
|
+
const endDate = DateTime.fromFormat(parts[1], format, {
|
|
287
|
+
zone: defaultTimeZone
|
|
288
|
+
}).startOf("day");
|
|
289
|
+
const returnValue = {
|
|
290
|
+
start: {
|
|
291
|
+
value: parts[0],
|
|
292
|
+
date: toDateString(startDate),
|
|
293
|
+
isValid: startDate.isValid && isValidDate(
|
|
294
|
+
startDate,
|
|
295
|
+
minDate,
|
|
296
|
+
maxDate,
|
|
297
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
298
|
+
{
|
|
299
|
+
dates: new Set(unavailable?.dates),
|
|
300
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
301
|
+
},
|
|
302
|
+
defaultTimeZone
|
|
303
|
+
)
|
|
304
|
+
},
|
|
305
|
+
end: {
|
|
306
|
+
value: parts[1],
|
|
307
|
+
date: toDateString(endDate),
|
|
308
|
+
isValid: startDate.isValid && isValidDate(
|
|
309
|
+
endDate,
|
|
310
|
+
minDate,
|
|
311
|
+
maxDate,
|
|
312
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
313
|
+
{
|
|
314
|
+
dates: new Set(unavailable?.dates),
|
|
315
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
316
|
+
},
|
|
317
|
+
defaultTimeZone
|
|
318
|
+
)
|
|
319
|
+
},
|
|
320
|
+
value: ev.target.value
|
|
321
|
+
};
|
|
322
|
+
if (!inputValue) {
|
|
323
|
+
setInternalValue(returnValue);
|
|
324
|
+
}
|
|
325
|
+
onChange?.(ev, returnValue);
|
|
326
|
+
} else {
|
|
327
|
+
if (ev.target.value === internalValue?.date) return;
|
|
328
|
+
const inputDate = DateTime.fromFormat(ev.target.value, format, {
|
|
329
|
+
zone: defaultTimeZone
|
|
330
|
+
}).startOf("day");
|
|
331
|
+
const returnValue = {
|
|
332
|
+
value: ev.target.value,
|
|
333
|
+
date: toDateString(inputDate),
|
|
334
|
+
isValid: inputDate.isValid && isValidDate(
|
|
335
|
+
inputDate,
|
|
336
|
+
minDate,
|
|
337
|
+
maxDate,
|
|
338
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
339
|
+
{
|
|
340
|
+
dates: new Set(unavailable?.dates),
|
|
341
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
342
|
+
},
|
|
343
|
+
defaultTimeZone
|
|
344
|
+
)
|
|
345
|
+
};
|
|
346
|
+
if (!inputValue) {
|
|
347
|
+
setInternalValue(returnValue);
|
|
348
|
+
}
|
|
349
|
+
onChange?.(ev, returnValue);
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
const handleInputBlur = (ev) => {
|
|
353
|
+
if (isClickOutside.current) {
|
|
354
|
+
isClickOutside.current = false;
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
if (!calRef.current?.contains(ev.relatedTarget)) {
|
|
358
|
+
setOpen(false);
|
|
359
|
+
onBlur?.(ev);
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
const handleCalendarKeyDown = (ev) => {
|
|
363
|
+
switch (ev.key) {
|
|
364
|
+
case "Escape":
|
|
365
|
+
setDisableFocusLock(true);
|
|
366
|
+
inputRef.current?.focus();
|
|
367
|
+
break;
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
const handleCalendarBlur = (ev) => {
|
|
371
|
+
if (!(inputRef.current === ev.currentTarget || calRef.current === ev.currentTarget)) {
|
|
372
|
+
setOpen(false);
|
|
373
|
+
onBlur?.(ev);
|
|
374
|
+
}
|
|
375
|
+
if (!(calRef.current === ev.currentTarget)) {
|
|
376
|
+
setDisableFocusLock(true);
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const handleCalendarFocus = (ev) => {
|
|
380
|
+
disableFocusLock && setDisableFocusLock(false);
|
|
381
|
+
};
|
|
382
|
+
const handleCalendarSelection = (data) => {
|
|
383
|
+
if (range) {
|
|
384
|
+
const calSelectData = data;
|
|
385
|
+
const startVal = DateTime.fromISO(calSelectData?.value?.start || "", {
|
|
386
|
+
zone: defaultTimeZone
|
|
387
|
+
});
|
|
388
|
+
const endVal = DateTime.fromISO(calSelectData?.value?.end || "", {
|
|
389
|
+
zone: defaultTimeZone
|
|
390
|
+
});
|
|
391
|
+
let newValue = "";
|
|
392
|
+
const newInternalValue = { value: "" };
|
|
393
|
+
if (startVal.isValid) {
|
|
394
|
+
newInternalValue.start = {
|
|
395
|
+
value: startVal.toFormat(format),
|
|
396
|
+
date: calSelectData?.value?.start,
|
|
397
|
+
isValid: true
|
|
398
|
+
};
|
|
399
|
+
newValue += startVal.toFormat(format);
|
|
400
|
+
} else {
|
|
401
|
+
newValue += formatMask;
|
|
402
|
+
}
|
|
403
|
+
newValue += RANGE_DIVIDER$1;
|
|
404
|
+
if (endVal.isValid) {
|
|
405
|
+
newInternalValue.end = {
|
|
406
|
+
value: endVal.toFormat(format),
|
|
407
|
+
date: calSelectData?.value?.end,
|
|
408
|
+
isValid: true
|
|
409
|
+
};
|
|
410
|
+
newValue += endVal.toFormat(format);
|
|
411
|
+
} else {
|
|
412
|
+
newValue += formatMask;
|
|
413
|
+
}
|
|
414
|
+
if (typeof inputValue !== "string") {
|
|
415
|
+
setInternalValue(newInternalValue);
|
|
416
|
+
}
|
|
417
|
+
newInternalValue.value = newValue;
|
|
418
|
+
const event = {
|
|
419
|
+
target: {
|
|
420
|
+
value: newValue
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
onChange?.(event, newInternalValue);
|
|
424
|
+
} else {
|
|
425
|
+
const calSelectData = data;
|
|
426
|
+
const val = DateTime.fromISO(calSelectData.value || "", {
|
|
427
|
+
zone: defaultTimeZone
|
|
428
|
+
});
|
|
429
|
+
const newValue = val.toFormat(format);
|
|
430
|
+
const newInternalValue = {
|
|
431
|
+
value: newValue,
|
|
432
|
+
date: calSelectData.value,
|
|
433
|
+
isValid: val.isValid && isValidDate(
|
|
434
|
+
val,
|
|
435
|
+
minDate,
|
|
436
|
+
maxDate,
|
|
437
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
438
|
+
{
|
|
439
|
+
dates: new Set(unavailable?.dates),
|
|
440
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
441
|
+
},
|
|
442
|
+
defaultTimeZone
|
|
443
|
+
)
|
|
444
|
+
};
|
|
445
|
+
if (typeof inputValue !== "string") {
|
|
446
|
+
setInternalValue(newInternalValue);
|
|
447
|
+
}
|
|
448
|
+
const event = {
|
|
449
|
+
target: {
|
|
450
|
+
value: newValue
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
onChange?.(event, newInternalValue);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
const handleInputFocus = (ev) => {
|
|
457
|
+
if (!open) {
|
|
458
|
+
setOpen(true);
|
|
459
|
+
onFocus?.(ev);
|
|
460
|
+
}
|
|
461
|
+
};
|
|
462
|
+
return /* @__PURE__ */ jsxs(
|
|
463
|
+
PopoverLegacy,
|
|
464
|
+
{
|
|
465
|
+
open: openCalendar || open,
|
|
466
|
+
modal: true,
|
|
467
|
+
placement: "bottom-start",
|
|
468
|
+
disableTriggerFocus: true,
|
|
469
|
+
disableFocusLock,
|
|
470
|
+
children: [
|
|
471
|
+
/* @__PURE__ */ jsx(PopoverLegacy.Trigger, { children: ({ ref: popoverRef, ...props }) => /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
472
|
+
InputMask,
|
|
473
|
+
{
|
|
474
|
+
mask,
|
|
475
|
+
inputProps: {
|
|
476
|
+
onKeyDown: handleInputKeyDown,
|
|
477
|
+
onBlur: handleInputBlur,
|
|
478
|
+
onChange: handleInputChange,
|
|
479
|
+
onFocus: handleInputFocus
|
|
480
|
+
},
|
|
481
|
+
value: internalValue?.value || "",
|
|
482
|
+
...props,
|
|
483
|
+
ref: useMergeRefs([popoverRef, inputRef]),
|
|
484
|
+
children: /* @__PURE__ */ jsx(
|
|
485
|
+
TextField,
|
|
486
|
+
{
|
|
487
|
+
hint,
|
|
488
|
+
ref,
|
|
489
|
+
prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent, ref: iconRef }),
|
|
490
|
+
...inputProps,
|
|
491
|
+
required
|
|
492
|
+
}
|
|
493
|
+
)
|
|
494
|
+
}
|
|
495
|
+
) }) }),
|
|
496
|
+
/* @__PURE__ */ jsx(PopoverLegacy.Content, { ref: floatRef, children: !range ? /* @__PURE__ */ jsx(
|
|
497
|
+
Calendar,
|
|
498
|
+
{
|
|
499
|
+
ref: calRef,
|
|
500
|
+
onKeyDown: handleCalendarKeyDown,
|
|
501
|
+
defaultFocusedDate: internalValue?.date,
|
|
502
|
+
value: internalValue?.date || undefined,
|
|
503
|
+
locale,
|
|
504
|
+
onBlur: handleCalendarBlur,
|
|
505
|
+
onSelection: handleCalendarSelection,
|
|
506
|
+
onFocus: handleCalendarFocus,
|
|
507
|
+
minDate,
|
|
508
|
+
maxDate,
|
|
509
|
+
unavailableDates,
|
|
510
|
+
unavailable,
|
|
511
|
+
defaultTimeZone,
|
|
512
|
+
startDay
|
|
513
|
+
}
|
|
514
|
+
) : /* @__PURE__ */ jsx(
|
|
515
|
+
Calendar,
|
|
516
|
+
{
|
|
517
|
+
ref: calRef,
|
|
518
|
+
onKeyDown: handleCalendarKeyDown,
|
|
519
|
+
defaultFocusedDate: internalValue?.start?.date,
|
|
520
|
+
value: internalValue ? {
|
|
521
|
+
start: internalValue?.start?.date || undefined,
|
|
522
|
+
end: internalValue?.end?.date || undefined
|
|
523
|
+
} : undefined,
|
|
524
|
+
locale,
|
|
525
|
+
onBlur: handleCalendarBlur,
|
|
526
|
+
onSelection: handleCalendarSelection,
|
|
527
|
+
onFocus: handleCalendarFocus,
|
|
528
|
+
minDate,
|
|
529
|
+
maxDate,
|
|
530
|
+
unavailableDates,
|
|
531
|
+
unavailable,
|
|
532
|
+
defaultTimeZone,
|
|
533
|
+
startDay,
|
|
534
|
+
range: true
|
|
535
|
+
}
|
|
536
|
+
) })
|
|
537
|
+
]
|
|
538
|
+
}
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
);
|
|
542
|
+
DateFieldLegacy.displayName = "DateFieldLegacy";
|
|
543
|
+
|
|
544
|
+
const RANGE_DIVIDER = " – ";
|
|
545
|
+
const DateField$1 = forwardRef(
|
|
546
|
+
(props, ref) => {
|
|
547
|
+
const {
|
|
548
|
+
// DateField
|
|
549
|
+
openCalendar,
|
|
550
|
+
onFocus,
|
|
551
|
+
onBlur,
|
|
552
|
+
onChange,
|
|
553
|
+
onClick,
|
|
554
|
+
format = "MM/dd/yyyy",
|
|
555
|
+
disableHint,
|
|
556
|
+
// Calendar
|
|
557
|
+
minDate,
|
|
558
|
+
maxDate,
|
|
559
|
+
unavailableDates,
|
|
560
|
+
unavailable,
|
|
561
|
+
startDay,
|
|
562
|
+
defaultValue,
|
|
563
|
+
value: inputValue,
|
|
564
|
+
// Shared
|
|
565
|
+
locale = Intl.DateTimeFormat().resolvedOptions().locale,
|
|
566
|
+
defaultTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
567
|
+
range,
|
|
568
|
+
// Input
|
|
569
|
+
required,
|
|
570
|
+
...inputProps
|
|
571
|
+
} = props;
|
|
572
|
+
const [open, _setOpen] = useState(openCalendar || false);
|
|
573
|
+
const setOpen = (val) => {
|
|
574
|
+
if (open && !val) {
|
|
575
|
+
inputRef.current?.focus();
|
|
576
|
+
}
|
|
577
|
+
_setOpen(val);
|
|
578
|
+
};
|
|
579
|
+
const [internalValue, setInternalValue] = useState();
|
|
580
|
+
const inputRef = useRef(null);
|
|
581
|
+
const popperRef = useRef(null);
|
|
582
|
+
const documentRef = useRef(document.body);
|
|
583
|
+
const hint = useMemo(
|
|
584
|
+
() => disableHint ? undefined : `format: ${format.replace(/M/g, "m")}`,
|
|
585
|
+
[format, disableHint]
|
|
586
|
+
);
|
|
587
|
+
const { focusables } = useKeyboardFocusables(documentRef, {
|
|
588
|
+
observeChange: true
|
|
589
|
+
});
|
|
590
|
+
const { focusables: popoverFocusables } = useKeyboardFocusables(popperRef, {
|
|
591
|
+
observeChange: true
|
|
592
|
+
});
|
|
593
|
+
const pageFocusables = focusables?.filter(
|
|
594
|
+
(item) => !popoverFocusables?.includes(item)
|
|
595
|
+
);
|
|
596
|
+
const [popoverRef, setPopoverRef] = useState();
|
|
597
|
+
const combinedRef = useMergeRefs$1([popoverRef, inputRef]);
|
|
598
|
+
useEffect(() => {
|
|
599
|
+
if (!defaultValue) return;
|
|
600
|
+
if (range) {
|
|
601
|
+
const startDate = DateTime.fromFormat(
|
|
602
|
+
defaultValue.start ?? "",
|
|
603
|
+
format,
|
|
604
|
+
{
|
|
605
|
+
zone: defaultTimeZone
|
|
606
|
+
}
|
|
607
|
+
).startOf("day");
|
|
608
|
+
const endDate = DateTime.fromFormat(defaultValue.end ?? "", format, {
|
|
609
|
+
zone: defaultTimeZone
|
|
610
|
+
}).startOf("day");
|
|
611
|
+
const newValue2 = {
|
|
612
|
+
start: {
|
|
613
|
+
value: defaultValue.start ?? "",
|
|
614
|
+
date: toDateString(startDate),
|
|
615
|
+
isValid: startDate.isValid && isValidDate(
|
|
616
|
+
startDate,
|
|
617
|
+
minDate,
|
|
618
|
+
maxDate,
|
|
619
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
620
|
+
{
|
|
621
|
+
dates: new Set(unavailable?.dates),
|
|
622
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
623
|
+
},
|
|
624
|
+
defaultTimeZone
|
|
625
|
+
)
|
|
626
|
+
},
|
|
627
|
+
end: {
|
|
628
|
+
value: defaultValue.end ?? "",
|
|
629
|
+
date: toDateString(endDate),
|
|
630
|
+
isValid: startDate.isValid && isValidDate(
|
|
631
|
+
endDate,
|
|
632
|
+
minDate,
|
|
633
|
+
maxDate,
|
|
634
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
635
|
+
{
|
|
636
|
+
dates: new Set(unavailable?.dates),
|
|
637
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
638
|
+
},
|
|
639
|
+
defaultTimeZone
|
|
640
|
+
)
|
|
641
|
+
},
|
|
642
|
+
value: defaultValue.start + RANGE_DIVIDER + defaultValue.end
|
|
643
|
+
};
|
|
644
|
+
setInternalValue(newValue2);
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
const date = DateTime.fromFormat(defaultValue, format, {
|
|
648
|
+
zone: defaultTimeZone
|
|
649
|
+
}).startOf("day");
|
|
650
|
+
const newValue = {
|
|
651
|
+
value: defaultValue,
|
|
652
|
+
date: toDateString(date),
|
|
653
|
+
isValid: date.isValid && isValidDate(
|
|
654
|
+
date,
|
|
655
|
+
minDate,
|
|
656
|
+
maxDate,
|
|
657
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
658
|
+
{
|
|
659
|
+
dates: new Set(unavailable?.dates),
|
|
660
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
661
|
+
},
|
|
662
|
+
defaultTimeZone
|
|
663
|
+
)
|
|
664
|
+
};
|
|
665
|
+
setInternalValue(newValue);
|
|
666
|
+
}, []);
|
|
667
|
+
const getCurrentValue = () => {
|
|
668
|
+
if (inputValue !== undefined) {
|
|
669
|
+
if (range) {
|
|
670
|
+
const startDate = DateTime.fromFormat(
|
|
671
|
+
inputValue.start ?? "",
|
|
672
|
+
format,
|
|
673
|
+
{
|
|
674
|
+
zone: defaultTimeZone
|
|
675
|
+
}
|
|
676
|
+
).startOf("day");
|
|
677
|
+
const endDate = DateTime.fromFormat(inputValue.end ?? "", format, {
|
|
678
|
+
zone: defaultTimeZone
|
|
679
|
+
}).startOf("day");
|
|
680
|
+
const returnValue = {
|
|
681
|
+
start: {
|
|
682
|
+
value: inputValue.start ?? "",
|
|
683
|
+
date: toDateString(startDate),
|
|
684
|
+
isValid: startDate.isValid && isValidDate(
|
|
685
|
+
startDate,
|
|
686
|
+
minDate,
|
|
687
|
+
maxDate,
|
|
688
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
689
|
+
{
|
|
690
|
+
dates: new Set(unavailable?.dates),
|
|
691
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
692
|
+
},
|
|
693
|
+
defaultTimeZone
|
|
694
|
+
)
|
|
695
|
+
},
|
|
696
|
+
end: {
|
|
697
|
+
value: inputValue.end ?? "",
|
|
698
|
+
date: toDateString(endDate),
|
|
699
|
+
isValid: startDate.isValid && isValidDate(
|
|
700
|
+
endDate,
|
|
701
|
+
minDate,
|
|
702
|
+
maxDate,
|
|
703
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
704
|
+
{
|
|
705
|
+
dates: new Set(unavailable?.dates),
|
|
706
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
707
|
+
},
|
|
708
|
+
defaultTimeZone
|
|
709
|
+
)
|
|
710
|
+
},
|
|
711
|
+
value: inputValue.start + RANGE_DIVIDER + inputValue.end
|
|
712
|
+
};
|
|
713
|
+
return returnValue;
|
|
714
|
+
}
|
|
715
|
+
const date = DateTime.fromFormat(inputValue, format, {
|
|
716
|
+
zone: defaultTimeZone
|
|
717
|
+
}).startOf("day");
|
|
718
|
+
return {
|
|
719
|
+
value: inputValue,
|
|
720
|
+
date: toDateString(date),
|
|
721
|
+
isValid: date.isValid && isValidDate(
|
|
722
|
+
date,
|
|
723
|
+
minDate,
|
|
724
|
+
maxDate,
|
|
725
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
726
|
+
{
|
|
727
|
+
dates: new Set(unavailable?.dates),
|
|
728
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
729
|
+
},
|
|
730
|
+
defaultTimeZone
|
|
731
|
+
)
|
|
732
|
+
};
|
|
733
|
+
}
|
|
734
|
+
return internalValue;
|
|
735
|
+
};
|
|
736
|
+
const handleInputFocus = (ev) => {
|
|
737
|
+
onFocus?.(ev);
|
|
738
|
+
};
|
|
739
|
+
const handleInputBlur = (ev) => {
|
|
740
|
+
if (!popperRef.current?.contains(ev.relatedTarget)) {
|
|
741
|
+
setOpen(false);
|
|
742
|
+
onBlur?.(ev);
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
const handleInputKeyDown = (ev) => {
|
|
746
|
+
let currentFocusIndex = 0;
|
|
747
|
+
switch (ev.key) {
|
|
748
|
+
case "Escape":
|
|
749
|
+
setOpen(false);
|
|
750
|
+
break;
|
|
751
|
+
case "Tab":
|
|
752
|
+
if (!open || !pageFocusables?.length) {
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
ev.preventDefault();
|
|
756
|
+
currentFocusIndex = pageFocusables.indexOf(inputRef.current) || 0;
|
|
757
|
+
setOpen(false);
|
|
758
|
+
if (ev.shiftKey) {
|
|
759
|
+
if (currentFocusIndex === 0) {
|
|
760
|
+
requestAnimationFrame(
|
|
761
|
+
() => pageFocusables[pageFocusables.length - 1].focus()
|
|
762
|
+
);
|
|
763
|
+
} else {
|
|
764
|
+
requestAnimationFrame(
|
|
765
|
+
() => pageFocusables[currentFocusIndex - 1].focus()
|
|
766
|
+
);
|
|
767
|
+
}
|
|
768
|
+
break;
|
|
769
|
+
}
|
|
770
|
+
if (pageFocusables.length > currentFocusIndex + 1) {
|
|
771
|
+
requestAnimationFrame(
|
|
772
|
+
() => pageFocusables[currentFocusIndex + 1].focus()
|
|
773
|
+
);
|
|
774
|
+
} else {
|
|
775
|
+
requestAnimationFrame(() => pageFocusables[0].focus());
|
|
776
|
+
}
|
|
777
|
+
break;
|
|
778
|
+
case "ArrowDown":
|
|
779
|
+
if (!open) {
|
|
780
|
+
setOpen(true);
|
|
781
|
+
setTimeout(focusToCalendar, 200);
|
|
782
|
+
} else {
|
|
783
|
+
focusToCalendar();
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
};
|
|
787
|
+
const handleCalendarKeyDown = (ev) => {
|
|
788
|
+
switch (ev.key) {
|
|
789
|
+
case "Escape":
|
|
790
|
+
setOpen(false);
|
|
791
|
+
inputRef.current?.focus();
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
const handleInputClick = (ev) => {
|
|
795
|
+
setOpen(true);
|
|
796
|
+
onClick?.(ev);
|
|
797
|
+
};
|
|
798
|
+
const handleInputChange = (ev) => {
|
|
799
|
+
if (range) {
|
|
800
|
+
const parts = ev.target.value.split(RANGE_DIVIDER);
|
|
801
|
+
if (parts.length !== 2) return;
|
|
802
|
+
const startDate = DateTime.fromFormat(parts[0], format, {
|
|
803
|
+
zone: defaultTimeZone
|
|
804
|
+
}).startOf("day");
|
|
805
|
+
const endDate = DateTime.fromFormat(parts[1], format, {
|
|
806
|
+
zone: defaultTimeZone
|
|
807
|
+
}).startOf("day");
|
|
808
|
+
const returnValue = {
|
|
809
|
+
start: {
|
|
810
|
+
value: parts[0],
|
|
811
|
+
date: toDateString(startDate),
|
|
812
|
+
isValid: startDate.isValid && isValidDate(
|
|
813
|
+
startDate,
|
|
814
|
+
minDate,
|
|
815
|
+
maxDate,
|
|
816
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
817
|
+
{
|
|
818
|
+
dates: new Set(unavailable?.dates),
|
|
819
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
820
|
+
},
|
|
821
|
+
defaultTimeZone
|
|
822
|
+
)
|
|
823
|
+
},
|
|
824
|
+
end: {
|
|
825
|
+
value: parts[1],
|
|
826
|
+
date: toDateString(endDate),
|
|
827
|
+
isValid: startDate.isValid && isValidDate(
|
|
828
|
+
endDate,
|
|
829
|
+
minDate,
|
|
830
|
+
maxDate,
|
|
831
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
832
|
+
{
|
|
833
|
+
dates: new Set(unavailable?.dates),
|
|
834
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
835
|
+
},
|
|
836
|
+
defaultTimeZone
|
|
837
|
+
)
|
|
838
|
+
},
|
|
839
|
+
value: ev.target.value
|
|
840
|
+
};
|
|
841
|
+
setInternalValue(returnValue);
|
|
842
|
+
onChange?.(ev, returnValue);
|
|
843
|
+
return;
|
|
844
|
+
}
|
|
845
|
+
const date = DateTime.fromFormat(ev.target.value, format, {
|
|
846
|
+
zone: defaultTimeZone
|
|
847
|
+
}).startOf("day");
|
|
848
|
+
const newDate = {
|
|
849
|
+
value: ev.target.value,
|
|
850
|
+
date: toDateString(date),
|
|
851
|
+
isValid: date.isValid && isValidDate(
|
|
852
|
+
date,
|
|
853
|
+
minDate,
|
|
854
|
+
maxDate,
|
|
855
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
856
|
+
{
|
|
857
|
+
dates: new Set(unavailable?.dates),
|
|
858
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
859
|
+
},
|
|
860
|
+
defaultTimeZone
|
|
861
|
+
)
|
|
862
|
+
};
|
|
863
|
+
setInternalValue(newDate);
|
|
864
|
+
onChange?.(ev, newDate);
|
|
865
|
+
};
|
|
866
|
+
const handleCalendarSelection = (data) => {
|
|
867
|
+
if (range) {
|
|
868
|
+
const startDate = data.value?.start ?? "";
|
|
869
|
+
const endDate = data.value?.end ?? "";
|
|
870
|
+
const startVal = DateTime.fromISO(startDate, {
|
|
871
|
+
zone: defaultTimeZone
|
|
872
|
+
});
|
|
873
|
+
const startValue = startVal.toFormat(format);
|
|
874
|
+
const endVal = DateTime.fromISO(endDate, {
|
|
875
|
+
zone: defaultTimeZone
|
|
876
|
+
});
|
|
877
|
+
const endValue = endVal.toFormat(format);
|
|
878
|
+
const newDateRange = {
|
|
879
|
+
start: {
|
|
880
|
+
value: startValue,
|
|
881
|
+
date: startDate,
|
|
882
|
+
isValid: true
|
|
883
|
+
},
|
|
884
|
+
end: {
|
|
885
|
+
value: endValue,
|
|
886
|
+
date: endDate,
|
|
887
|
+
isValid: true
|
|
888
|
+
},
|
|
889
|
+
value: startValue + RANGE_DIVIDER + endValue
|
|
890
|
+
};
|
|
891
|
+
setInternalValue(newDateRange);
|
|
892
|
+
const event2 = {
|
|
893
|
+
target: {
|
|
894
|
+
value: startValue + RANGE_DIVIDER + endValue
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
handleInputChange(event2);
|
|
898
|
+
return;
|
|
899
|
+
}
|
|
900
|
+
const date = data.value;
|
|
901
|
+
const val = DateTime.fromISO(date || "", {
|
|
902
|
+
zone: defaultTimeZone
|
|
903
|
+
});
|
|
904
|
+
const value = val.toFormat(format);
|
|
905
|
+
const newDate = {
|
|
906
|
+
value,
|
|
907
|
+
date,
|
|
908
|
+
isValid: true
|
|
909
|
+
};
|
|
910
|
+
setInternalValue(newDate);
|
|
911
|
+
const event = {
|
|
912
|
+
target: {
|
|
913
|
+
value
|
|
914
|
+
}
|
|
915
|
+
};
|
|
916
|
+
handleInputChange(event);
|
|
917
|
+
};
|
|
918
|
+
const focusToCalendar = () => {
|
|
919
|
+
if (popperRef.current) {
|
|
920
|
+
const currentFocusable = popperRef.current.querySelectorAll('[tabindex = "0"]')[0];
|
|
921
|
+
if (currentFocusable) {
|
|
922
|
+
currentFocusable.focus();
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
const handleClickOutside = () => {
|
|
927
|
+
setOpen(false);
|
|
928
|
+
};
|
|
929
|
+
const currentValue = getCurrentValue();
|
|
930
|
+
if (!supportsPopover())
|
|
931
|
+
return /* @__PURE__ */ jsx(DateFieldLegacy, { ...props, ref });
|
|
932
|
+
return /* @__PURE__ */ jsxs(
|
|
933
|
+
Popover,
|
|
934
|
+
{
|
|
935
|
+
open: openCalendar ?? open,
|
|
936
|
+
modal: true,
|
|
937
|
+
placement: "bottom-start",
|
|
938
|
+
disableTriggerFocus: true,
|
|
939
|
+
onOutsidePress: handleClickOutside,
|
|
940
|
+
children: [
|
|
941
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { children: ({ ref: iRef, ...props2 }) => {
|
|
942
|
+
setPopoverRef(iRef);
|
|
943
|
+
return range ? /* @__PURE__ */ jsx(
|
|
944
|
+
InputMask,
|
|
945
|
+
{
|
|
946
|
+
mask: "99/99/9999" + RANGE_DIVIDER + "99/99/9999",
|
|
947
|
+
ref: combinedRef,
|
|
948
|
+
onChange: handleInputChange,
|
|
949
|
+
value: currentValue?.value,
|
|
950
|
+
inputProps: {
|
|
951
|
+
onFocus: handleInputFocus,
|
|
952
|
+
prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent }),
|
|
953
|
+
onBlur: handleInputBlur,
|
|
954
|
+
onKeyDown: handleInputKeyDown,
|
|
955
|
+
onClick: handleInputClick,
|
|
956
|
+
hint,
|
|
957
|
+
...inputProps
|
|
958
|
+
},
|
|
959
|
+
customMaskHandler: [
|
|
960
|
+
{
|
|
961
|
+
match: {
|
|
962
|
+
matchPattern: new RegExp(/^(\d)\//),
|
|
963
|
+
startPosition: 0,
|
|
964
|
+
endPosition: 2
|
|
965
|
+
},
|
|
966
|
+
apply: {
|
|
967
|
+
applyPattern: "0$1",
|
|
968
|
+
caretOffset: 2
|
|
969
|
+
}
|
|
970
|
+
},
|
|
971
|
+
{
|
|
972
|
+
match: {
|
|
973
|
+
matchPattern: new RegExp(/^(\d)\//),
|
|
974
|
+
startPosition: 3,
|
|
975
|
+
endPosition: 5
|
|
976
|
+
},
|
|
977
|
+
apply: {
|
|
978
|
+
applyPattern: "0$1",
|
|
979
|
+
caretOffset: 2
|
|
980
|
+
}
|
|
981
|
+
},
|
|
982
|
+
{
|
|
983
|
+
match: {
|
|
984
|
+
matchPattern: new RegExp(/^(\d)\//),
|
|
985
|
+
startPosition: 13,
|
|
986
|
+
endPosition: 15
|
|
987
|
+
},
|
|
988
|
+
apply: {
|
|
989
|
+
applyPattern: "0$1",
|
|
990
|
+
caretOffset: 2
|
|
991
|
+
}
|
|
992
|
+
},
|
|
993
|
+
{
|
|
994
|
+
match: {
|
|
995
|
+
matchPattern: new RegExp(/^(\d)\//),
|
|
996
|
+
startPosition: 16,
|
|
997
|
+
endPosition: 18
|
|
998
|
+
},
|
|
999
|
+
apply: {
|
|
1000
|
+
applyPattern: "0$1",
|
|
1001
|
+
caretOffset: 2
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
]
|
|
1005
|
+
}
|
|
1006
|
+
) : /* @__PURE__ */ jsx(
|
|
1007
|
+
InputMask,
|
|
1008
|
+
{
|
|
1009
|
+
mask: "99/99/9999",
|
|
1010
|
+
ref: combinedRef,
|
|
1011
|
+
onChange: handleInputChange,
|
|
1012
|
+
value: currentValue?.value,
|
|
1013
|
+
inputProps: {
|
|
1014
|
+
onFocus: handleInputFocus,
|
|
1015
|
+
prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent }),
|
|
1016
|
+
onBlur: handleInputBlur,
|
|
1017
|
+
onKeyDown: handleInputKeyDown,
|
|
1018
|
+
onClick: handleInputClick,
|
|
1019
|
+
hint,
|
|
1020
|
+
autoComplete: "off",
|
|
1021
|
+
...inputProps
|
|
1022
|
+
},
|
|
1023
|
+
customMaskHandler: [
|
|
1024
|
+
{
|
|
1025
|
+
match: {
|
|
1026
|
+
matchPattern: new RegExp(/^(\d)\//),
|
|
1027
|
+
startPosition: 0,
|
|
1028
|
+
endPosition: 2
|
|
1029
|
+
},
|
|
1030
|
+
apply: {
|
|
1031
|
+
applyPattern: "0$1",
|
|
1032
|
+
caretOffset: 2
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
match: {
|
|
1037
|
+
matchPattern: new RegExp(/^(\d)\//),
|
|
1038
|
+
startPosition: 3,
|
|
1039
|
+
endPosition: 5
|
|
1040
|
+
},
|
|
1041
|
+
apply: {
|
|
1042
|
+
applyPattern: "0$1",
|
|
1043
|
+
caretOffset: 2
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
]
|
|
1047
|
+
}
|
|
1048
|
+
);
|
|
1049
|
+
} }),
|
|
1050
|
+
/* @__PURE__ */ jsx(Popover.Content, { ref: popperRef, "data-calendar-popover": true, children: range ? /* @__PURE__ */ jsx(
|
|
1051
|
+
Calendar,
|
|
1052
|
+
{
|
|
1053
|
+
range: true,
|
|
1054
|
+
onKeyDown: handleCalendarKeyDown,
|
|
1055
|
+
defaultFocusedDate: internalValue?.start?.date,
|
|
1056
|
+
value: {
|
|
1057
|
+
start: currentValue?.start?.date || undefined,
|
|
1058
|
+
end: currentValue?.end?.date || undefined
|
|
1059
|
+
},
|
|
1060
|
+
onSelection: handleCalendarSelection,
|
|
1061
|
+
minDate,
|
|
1062
|
+
maxDate,
|
|
1063
|
+
unavailableDates,
|
|
1064
|
+
unavailable,
|
|
1065
|
+
defaultTimeZone,
|
|
1066
|
+
startDay
|
|
1067
|
+
}
|
|
1068
|
+
) : /* @__PURE__ */ jsx(
|
|
1069
|
+
Calendar,
|
|
1070
|
+
{
|
|
1071
|
+
onKeyDown: handleCalendarKeyDown,
|
|
1072
|
+
defaultFocusedDate: internalValue?.date,
|
|
1073
|
+
value: currentValue?.date || undefined,
|
|
1074
|
+
onSelection: handleCalendarSelection,
|
|
1075
|
+
minDate,
|
|
1076
|
+
maxDate,
|
|
1077
|
+
unavailableDates,
|
|
1078
|
+
unavailable,
|
|
1079
|
+
defaultTimeZone,
|
|
1080
|
+
startDay
|
|
1081
|
+
}
|
|
1082
|
+
) })
|
|
1083
|
+
]
|
|
1084
|
+
}
|
|
1085
|
+
);
|
|
1086
|
+
}
|
|
1087
|
+
);
|
|
1088
|
+
DateField$1.displayName = "DateField";
|
|
1089
|
+
|
|
1090
|
+
const DateField = forwardRef(
|
|
1091
|
+
(props, ref) => {
|
|
1092
|
+
const data = {
|
|
1093
|
+
label: childrenToString(props.label),
|
|
1094
|
+
labelProps: props.labelProps,
|
|
1095
|
+
description: childrenToString(props.description),
|
|
1096
|
+
size: props.size,
|
|
1097
|
+
type: props.type
|
|
1098
|
+
};
|
|
1099
|
+
const trackingId = useTrackingId({
|
|
1100
|
+
name: "DateField",
|
|
1101
|
+
data,
|
|
1102
|
+
hasOverride: !!props["data-tracking-id"]
|
|
1103
|
+
});
|
|
1104
|
+
return /* @__PURE__ */ jsx(DateField$1, { ref, "data-tracking-id": trackingId, ...props });
|
|
1105
|
+
}
|
|
1106
|
+
);
|
|
1107
|
+
|
|
1108
|
+
export { DateField as D };
|
|
1109
|
+
//# sourceMappingURL=DateField-4jR9NvbC.js.map
|