@servicetitan/anvil2 1.27.2 → 1.28.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 +46 -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-JAm3x-tw.js} +1986 -116
- package/dist/Combobox-JAm3x-tw.js.map +1 -0
- package/dist/Combobox.css +343 -1
- package/dist/Combobox.js +1 -1
- package/dist/{DateField-DocC46Mw.js → DateField-5mNXaJ7q.js} +548 -11
- package/dist/DateField-5mNXaJ7q.js.map +1 -0
- package/dist/DateField.js +1 -1
- package/dist/{Dialog-DQ9QXB5D.js → Dialog-B4M0DXxG.js} +2 -2
- package/dist/{Dialog-DQ9QXB5D.js.map → Dialog-B4M0DXxG.js.map} +1 -1
- package/dist/{Dialog-Kh2tcVWz-DqcNnouf.js → Dialog-CUK5YvVY-Dv5edacC.js} +5 -5
- package/dist/Dialog-CUK5YvVY-Dv5edacC.js.map +1 -0
- package/dist/Dialog.js +1 -1
- package/dist/Drawer-BqqZB3Sn.js +66 -0
- package/dist/Drawer-BqqZB3Sn.js.map +1 -0
- package/dist/{Drawer-C6fpnRDX.js → Drawer-CrXiK2w0-BMzKuNFt.js} +15 -75
- package/dist/Drawer-CrXiK2w0-BMzKuNFt.js.map +1 -0
- 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-Ceh574pv.js → InputMask-BmXj5mob.js} +2 -2
- package/dist/{InputMask-Ceh574pv.js.map → InputMask-BmXj5mob.js.map} +1 -1
- package/dist/{InputMask-DQXw5qvG-BH4P-Woc.js → InputMask-CQzrMoEy-CLNvXsm7.js} +3 -3
- package/dist/{InputMask-DQXw5qvG-BH4P-Woc.js.map → InputMask-CQzrMoEy-CLNvXsm7.js.map} +1 -1
- package/dist/InputMask.js +1 -1
- package/dist/{Label-DWF2pXeG-1BhzVgZG.js → Label-CbYy5kwu-BCTOKxOk.js} +3 -3
- package/dist/{Label-DWF2pXeG-1BhzVgZG.js.map → Label-CbYy5kwu-BCTOKxOk.js.map} +1 -1
- package/dist/Menu-IEBrkdoN.js +1090 -0
- package/dist/Menu-IEBrkdoN.js.map +1 -0
- package/dist/Menu.css +116 -1
- package/dist/Menu.js +1 -1
- package/dist/{Page-BGkLs3bR.js → Page-qlpHVAMH.js} +70 -54
- package/dist/Page-qlpHVAMH.js.map +1 -0
- package/dist/Page.css +103 -70
- package/dist/Page.js +1 -1
- package/dist/{Popover-DzEc_Muv.js → Popover-B7K3o_l4.js} +2 -2
- package/dist/{Popover-DzEc_Muv.js.map → Popover-B7K3o_l4.js.map} +1 -1
- package/dist/{Popover-QKZtjN4_-CETYlWwq.js → Popover-C1B3UJXp-B5obSIvA.js} +351 -12
- package/dist/Popover-C1B3UJXp-B5obSIvA.js.map +1 -0
- package/dist/{Popover-QKZtjN4_.css → Popover-C1B3UJXp.css} +53 -1
- package/dist/Popover.js +1 -1
- package/dist/{ProgressBar-cKtBso7j-3CDyBaAN.js → ProgressBar-BLg29adn-CMz5eu5f.js} +3 -3
- package/dist/{ProgressBar-cKtBso7j-3CDyBaAN.js.map → ProgressBar-BLg29adn-CMz5eu5f.js.map} +1 -1
- package/dist/{ProgressBar-IItIByYc.js → ProgressBar-_DyYSgfx.js} +2 -2
- package/dist/{ProgressBar-IItIByYc.js.map → ProgressBar-_DyYSgfx.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-Lwe9XAou-tH8gcQTq.js} +2 -2
- package/dist/{TextField-D53XNiCi-C6_A5VRq.js.map → TextField-Lwe9XAou-tH8gcQTq.js.map} +1 -1
- package/dist/{TextField-s92xHzb3.js → TextField-tF-ERwA8.js} +2 -2
- package/dist/{TextField-s92xHzb3.js.map → TextField-tF-ERwA8.js.map} +1 -1
- package/dist/TextField.js +1 -1
- package/dist/{Textarea-B61wNIFr.js → Textarea-BrzxOEx3.js} +2 -2
- package/dist/Textarea-BrzxOEx3.js.map +1 -0
- package/dist/Textarea.js +1 -1
- package/dist/Toast.js +1 -1
- package/dist/{Toolbar-Cge6Nznj.js → Toolbar-D9fMSiGU.js} +2 -2
- package/dist/{Toolbar-Cge6Nznj.js.map → Toolbar-D9fMSiGU.js.map} +1 -1
- package/dist/Toolbar.js +1 -1
- package/dist/{Tooltip-DgM8NSPm-CRIQbuTm.js → Tooltip-36nMbVT3-DMkvo60s.js} +222 -22
- package/dist/Tooltip-36nMbVT3-DMkvo60s.js.map +1 -0
- package/dist/{Tooltip-DgM8NSPm.css → Tooltip-36nMbVT3.css} +43 -1
- package/dist/{Tooltip-89FIvMG0.js → Tooltip-BEo0IRDf.js} +2 -2
- package/dist/{Tooltip-89FIvMG0.js.map → Tooltip-BEo0IRDf.js.map} +1 -1
- package/dist/Tooltip.js +1 -1
- 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-DkO9HWpH.js} +2 -2
- package/dist/{toast-CHld8RKY.js.map → toast-DkO9HWpH.js.map} +1 -1
- package/dist/useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js +61 -0
- package/dist/useKeyboardFocusables-CwVMAe5C-DtjYOAmt.js.map +1 -0
- package/package.json +2 -2
- package/dist/AnvilProvider-DNJk1Ait.js.map +0 -1
- package/dist/Combobox-DnTI2I3L.js.map +0 -1
- 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/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/Textarea-B61wNIFr.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/useKeyboardFocusables-CwVMAe5C-CIHqixNA.js.map +0 -1
- /package/dist/{Dialog-Kh2tcVWz.css → Dialog-CUK5YvVY.css} +0 -0
- /package/dist/{Drawer.css → Drawer-CrXiK2w0.css} +0 -0
- /package/dist/{Label-DWF2pXeG.css → Label-CbYy5kwu.css} +0 -0
- /package/dist/{ProgressBar-cKtBso7j.css → ProgressBar-BLg29adn.css} +0 -0
|
@@ -3,19 +3,21 @@ import * as React from 'react';
|
|
|
3
3
|
import { forwardRef, useState, useRef, useMemo, useEffect } from 'react';
|
|
4
4
|
import { useTrackingId } from './useTrackingId.js';
|
|
5
5
|
import { c as childrenToString } from './childrenToString-Bz9MqbHb-Bz9MqbHb.js';
|
|
6
|
-
import { I as InputMask } from './InputMask-
|
|
7
|
-
import { T as TextField } from './TextField-
|
|
8
|
-
import { d as Popover } from './Popover-QKZtjN4_-CETYlWwq.js';
|
|
6
|
+
import { I as InputMask } from './InputMask-CQzrMoEy-CLNvXsm7.js';
|
|
7
|
+
import { T as TextField } from './TextField-Lwe9XAou-tH8gcQTq.js';
|
|
9
8
|
import { D as DateTime, t as toDateString, i as isValidDate, C as Calendar } from './Calendar-9iYMS0Iw-D_XWYjOE.js';
|
|
10
9
|
import { I as Icon } from './Icon-DbHA5GV1-DwO2aGkj.js';
|
|
11
|
-
import {
|
|
10
|
+
import { s as supportsPopover } from './supportsPopover-8aJR37cf-8aJR37cf.js';
|
|
11
|
+
import { e as PopoverLegacy, d as Popover } from './Popover-C1B3UJXp-B5obSIvA.js';
|
|
12
|
+
import { u as useMergeRefs } from './floating-ui.react-4AwURJA3.js';
|
|
13
|
+
import { u as useMergeRefs$1 } from './useMergeRefs-Bde85AWI-Bde85AWI.js';
|
|
12
14
|
|
|
13
15
|
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" }));
|
|
14
16
|
|
|
15
|
-
const RANGE_DIVIDER = " — ";
|
|
16
|
-
const
|
|
17
|
+
const RANGE_DIVIDER$1 = " — ";
|
|
18
|
+
const DateFieldLegacy = forwardRef(
|
|
17
19
|
({
|
|
18
|
-
//
|
|
20
|
+
// DateFieldLegacy
|
|
19
21
|
openCalendar,
|
|
20
22
|
onFocus,
|
|
21
23
|
onBlur,
|
|
@@ -85,6 +87,539 @@ const DateField$1 = forwardRef(
|
|
|
85
87
|
docRef.current?.removeEventListener("click", clickOutHandler);
|
|
86
88
|
};
|
|
87
89
|
}, [open, onBlur]);
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
if (range) {
|
|
92
|
+
let start;
|
|
93
|
+
let end;
|
|
94
|
+
if (typeof inputValue === "string") {
|
|
95
|
+
const parts = inputValue.split(RANGE_DIVIDER$1);
|
|
96
|
+
start = parts[0];
|
|
97
|
+
end = parts[1];
|
|
98
|
+
} else {
|
|
99
|
+
start = inputValue?.start ?? "";
|
|
100
|
+
end = inputValue?.end ?? "";
|
|
101
|
+
}
|
|
102
|
+
const startDate = DateTime.fromFormat(start ?? "", format, {
|
|
103
|
+
zone: defaultTimeZone
|
|
104
|
+
}).startOf("day");
|
|
105
|
+
const endDate = DateTime.fromFormat(end ?? "", format, {
|
|
106
|
+
zone: defaultTimeZone
|
|
107
|
+
}).startOf("day");
|
|
108
|
+
const newData = {
|
|
109
|
+
start: {
|
|
110
|
+
value: start,
|
|
111
|
+
date: toDateString(startDate),
|
|
112
|
+
isValid: startDate.isValid && isValidDate(
|
|
113
|
+
startDate,
|
|
114
|
+
minDate,
|
|
115
|
+
maxDate,
|
|
116
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
117
|
+
{
|
|
118
|
+
dates: new Set(unavailable?.dates),
|
|
119
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
120
|
+
},
|
|
121
|
+
defaultTimeZone
|
|
122
|
+
)
|
|
123
|
+
},
|
|
124
|
+
end: {
|
|
125
|
+
value: end,
|
|
126
|
+
date: toDateString(endDate),
|
|
127
|
+
isValid: startDate.isValid && isValidDate(
|
|
128
|
+
endDate,
|
|
129
|
+
minDate,
|
|
130
|
+
maxDate,
|
|
131
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
132
|
+
{
|
|
133
|
+
dates: new Set(unavailable?.dates),
|
|
134
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
135
|
+
},
|
|
136
|
+
defaultTimeZone
|
|
137
|
+
)
|
|
138
|
+
},
|
|
139
|
+
value: `${start || formatMask}${RANGE_DIVIDER$1}${end || formatMask}`
|
|
140
|
+
};
|
|
141
|
+
setInternalValue(newData);
|
|
142
|
+
} else {
|
|
143
|
+
if (typeof inputValue !== "string") return;
|
|
144
|
+
const inputDate = DateTime.fromFormat(inputValue, format, {
|
|
145
|
+
zone: defaultTimeZone
|
|
146
|
+
}).startOf("day");
|
|
147
|
+
const newData = {
|
|
148
|
+
value: inputValue,
|
|
149
|
+
date: toDateString(inputDate),
|
|
150
|
+
isValid: inputDate.isValid && isValidDate(
|
|
151
|
+
inputDate,
|
|
152
|
+
minDate,
|
|
153
|
+
maxDate,
|
|
154
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
155
|
+
{
|
|
156
|
+
dates: new Set(unavailable?.dates),
|
|
157
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
158
|
+
},
|
|
159
|
+
defaultTimeZone
|
|
160
|
+
)
|
|
161
|
+
};
|
|
162
|
+
setInternalValue(newData);
|
|
163
|
+
}
|
|
164
|
+
}, [inputValue]);
|
|
165
|
+
const mask = useMemo(() => {
|
|
166
|
+
const maskPart = format.replace(/[Mdy]/g, "9");
|
|
167
|
+
if (range) {
|
|
168
|
+
return maskPart + RANGE_DIVIDER$1 + maskPart;
|
|
169
|
+
} else {
|
|
170
|
+
return maskPart;
|
|
171
|
+
}
|
|
172
|
+
}, [format, range]);
|
|
173
|
+
useEffect(() => {
|
|
174
|
+
if (typeof inputValue === "string") return;
|
|
175
|
+
if (defaultValue) {
|
|
176
|
+
if (range) {
|
|
177
|
+
const defValStart = defaultValue.start;
|
|
178
|
+
const defValEnd = defaultValue.end;
|
|
179
|
+
const initValStart = defValStart + (formatMask + RANGE_DIVIDER$1 + formatMask).slice(
|
|
180
|
+
defValStart?.length
|
|
181
|
+
);
|
|
182
|
+
const initValEnd = defValEnd + (formatMask + RANGE_DIVIDER$1 + formatMask).slice(defValEnd?.length);
|
|
183
|
+
const newValue = initValStart + RANGE_DIVIDER$1 + initValEnd;
|
|
184
|
+
const inputDateStart = DateTime.fromFormat(
|
|
185
|
+
defValStart || "",
|
|
186
|
+
format,
|
|
187
|
+
{
|
|
188
|
+
zone: defaultTimeZone
|
|
189
|
+
}
|
|
190
|
+
).startOf("day");
|
|
191
|
+
const inputDateEnd = DateTime.fromFormat(defValEnd || "", format, {
|
|
192
|
+
zone: defaultTimeZone
|
|
193
|
+
}).startOf("day");
|
|
194
|
+
const isValidStart = inputDateStart.isValid && isValidDate(
|
|
195
|
+
inputDateStart,
|
|
196
|
+
minDate,
|
|
197
|
+
maxDate,
|
|
198
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
199
|
+
{
|
|
200
|
+
dates: new Set(unavailable?.dates),
|
|
201
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
202
|
+
},
|
|
203
|
+
defaultTimeZone
|
|
204
|
+
);
|
|
205
|
+
const isValidEnd = inputDateEnd.isValid && isValidDate(
|
|
206
|
+
inputDateEnd,
|
|
207
|
+
minDate,
|
|
208
|
+
maxDate,
|
|
209
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
210
|
+
{
|
|
211
|
+
dates: new Set(unavailable?.dates),
|
|
212
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
213
|
+
},
|
|
214
|
+
defaultTimeZone
|
|
215
|
+
);
|
|
216
|
+
const initCalendarValue = {
|
|
217
|
+
start: {
|
|
218
|
+
value: initValStart,
|
|
219
|
+
date: toDateString(inputDateStart),
|
|
220
|
+
isValid: isValidStart
|
|
221
|
+
},
|
|
222
|
+
end: {
|
|
223
|
+
value: initValEnd,
|
|
224
|
+
date: toDateString(inputDateEnd),
|
|
225
|
+
isValid: isValidEnd
|
|
226
|
+
},
|
|
227
|
+
value: newValue
|
|
228
|
+
};
|
|
229
|
+
setInternalValue(initCalendarValue);
|
|
230
|
+
} else {
|
|
231
|
+
const defVal = defaultValue;
|
|
232
|
+
const initVal = defVal + formatMask.slice(defVal.length);
|
|
233
|
+
const inputDate = DateTime.fromFormat(defVal, format, {
|
|
234
|
+
zone: defaultTimeZone
|
|
235
|
+
}).startOf("day");
|
|
236
|
+
const isValid = inputDate.isValid && isValidDate(
|
|
237
|
+
inputDate,
|
|
238
|
+
minDate,
|
|
239
|
+
maxDate,
|
|
240
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
241
|
+
{
|
|
242
|
+
dates: new Set(unavailable?.dates),
|
|
243
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
244
|
+
},
|
|
245
|
+
defaultTimeZone
|
|
246
|
+
);
|
|
247
|
+
const initCalendarValue = {
|
|
248
|
+
value: initVal,
|
|
249
|
+
date: toDateString(inputDate),
|
|
250
|
+
isValid
|
|
251
|
+
};
|
|
252
|
+
setInternalValue(initCalendarValue);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}, []);
|
|
256
|
+
const focusToCalendar = () => {
|
|
257
|
+
if (calRef.current) {
|
|
258
|
+
const currentFocusable = calRef.current.querySelectorAll('[tabindex = "0"]')[0];
|
|
259
|
+
if (currentFocusable) {
|
|
260
|
+
currentFocusable.focus();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
const handleInputKeyDown = (ev) => {
|
|
265
|
+
switch (ev.key) {
|
|
266
|
+
case "Tab":
|
|
267
|
+
setOpen(false);
|
|
268
|
+
break;
|
|
269
|
+
case "ArrowDown":
|
|
270
|
+
if (!open) {
|
|
271
|
+
setOpen(true);
|
|
272
|
+
setTimeout(focusToCalendar, 100);
|
|
273
|
+
} else {
|
|
274
|
+
focusToCalendar();
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
const handleInputChange = (ev) => {
|
|
279
|
+
if (range) {
|
|
280
|
+
const parts = ev.target.value.split(RANGE_DIVIDER$1);
|
|
281
|
+
if (parts.length !== 2) return;
|
|
282
|
+
const startDate = DateTime.fromFormat(parts[0], format, {
|
|
283
|
+
zone: defaultTimeZone
|
|
284
|
+
}).startOf("day");
|
|
285
|
+
const endDate = DateTime.fromFormat(parts[1], format, {
|
|
286
|
+
zone: defaultTimeZone
|
|
287
|
+
}).startOf("day");
|
|
288
|
+
const returnValue = {
|
|
289
|
+
start: {
|
|
290
|
+
value: parts[0],
|
|
291
|
+
date: toDateString(startDate),
|
|
292
|
+
isValid: startDate.isValid && isValidDate(
|
|
293
|
+
startDate,
|
|
294
|
+
minDate,
|
|
295
|
+
maxDate,
|
|
296
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
297
|
+
{
|
|
298
|
+
dates: new Set(unavailable?.dates),
|
|
299
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
300
|
+
},
|
|
301
|
+
defaultTimeZone
|
|
302
|
+
)
|
|
303
|
+
},
|
|
304
|
+
end: {
|
|
305
|
+
value: parts[1],
|
|
306
|
+
date: toDateString(endDate),
|
|
307
|
+
isValid: startDate.isValid && isValidDate(
|
|
308
|
+
endDate,
|
|
309
|
+
minDate,
|
|
310
|
+
maxDate,
|
|
311
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
312
|
+
{
|
|
313
|
+
dates: new Set(unavailable?.dates),
|
|
314
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
315
|
+
},
|
|
316
|
+
defaultTimeZone
|
|
317
|
+
)
|
|
318
|
+
},
|
|
319
|
+
value: ev.target.value
|
|
320
|
+
};
|
|
321
|
+
if (!inputValue) {
|
|
322
|
+
setInternalValue(returnValue);
|
|
323
|
+
}
|
|
324
|
+
onChange?.(ev, returnValue);
|
|
325
|
+
} else {
|
|
326
|
+
if (ev.target.value === internalValue?.date) return;
|
|
327
|
+
const inputDate = DateTime.fromFormat(ev.target.value, format, {
|
|
328
|
+
zone: defaultTimeZone
|
|
329
|
+
}).startOf("day");
|
|
330
|
+
const returnValue = {
|
|
331
|
+
value: ev.target.value,
|
|
332
|
+
date: toDateString(inputDate),
|
|
333
|
+
isValid: inputDate.isValid && isValidDate(
|
|
334
|
+
inputDate,
|
|
335
|
+
minDate,
|
|
336
|
+
maxDate,
|
|
337
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
338
|
+
{
|
|
339
|
+
dates: new Set(unavailable?.dates),
|
|
340
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
341
|
+
},
|
|
342
|
+
defaultTimeZone
|
|
343
|
+
)
|
|
344
|
+
};
|
|
345
|
+
if (!inputValue) {
|
|
346
|
+
setInternalValue(returnValue);
|
|
347
|
+
}
|
|
348
|
+
onChange?.(ev, returnValue);
|
|
349
|
+
}
|
|
350
|
+
};
|
|
351
|
+
const handleInputBlur = (ev) => {
|
|
352
|
+
if (isClickOutside.current) {
|
|
353
|
+
isClickOutside.current = false;
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
if (!calRef.current?.contains(ev.relatedTarget)) {
|
|
357
|
+
setOpen(false);
|
|
358
|
+
onBlur?.(ev);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
const handleCalendarKeyDown = (ev) => {
|
|
362
|
+
switch (ev.key) {
|
|
363
|
+
case "Escape":
|
|
364
|
+
setDisableFocusLock(true);
|
|
365
|
+
inputRef.current?.focus();
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
};
|
|
369
|
+
const handleCalendarBlur = (ev) => {
|
|
370
|
+
if (!(inputRef.current === ev.currentTarget || calRef.current === ev.currentTarget)) {
|
|
371
|
+
setOpen(false);
|
|
372
|
+
onBlur?.(ev);
|
|
373
|
+
}
|
|
374
|
+
if (!(calRef.current === ev.currentTarget)) {
|
|
375
|
+
setDisableFocusLock(true);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
const handleCalendarFocus = (ev) => {
|
|
379
|
+
disableFocusLock && setDisableFocusLock(false);
|
|
380
|
+
};
|
|
381
|
+
const handleCalendarSelection = (data) => {
|
|
382
|
+
if (range) {
|
|
383
|
+
const calSelectData = data;
|
|
384
|
+
const startVal = DateTime.fromISO(calSelectData?.value?.start || "", {
|
|
385
|
+
zone: defaultTimeZone
|
|
386
|
+
});
|
|
387
|
+
const endVal = DateTime.fromISO(calSelectData?.value?.end || "", {
|
|
388
|
+
zone: defaultTimeZone
|
|
389
|
+
});
|
|
390
|
+
let newValue = "";
|
|
391
|
+
const newInternalValue = { value: "" };
|
|
392
|
+
if (startVal.isValid) {
|
|
393
|
+
newInternalValue.start = {
|
|
394
|
+
value: startVal.toFormat(format),
|
|
395
|
+
date: calSelectData?.value?.start,
|
|
396
|
+
isValid: true
|
|
397
|
+
};
|
|
398
|
+
newValue += startVal.toFormat(format);
|
|
399
|
+
} else {
|
|
400
|
+
newValue += formatMask;
|
|
401
|
+
}
|
|
402
|
+
newValue += RANGE_DIVIDER$1;
|
|
403
|
+
if (endVal.isValid) {
|
|
404
|
+
newInternalValue.end = {
|
|
405
|
+
value: endVal.toFormat(format),
|
|
406
|
+
date: calSelectData?.value?.end,
|
|
407
|
+
isValid: true
|
|
408
|
+
};
|
|
409
|
+
newValue += endVal.toFormat(format);
|
|
410
|
+
} else {
|
|
411
|
+
newValue += formatMask;
|
|
412
|
+
}
|
|
413
|
+
if (typeof inputValue !== "string") {
|
|
414
|
+
setInternalValue(newInternalValue);
|
|
415
|
+
}
|
|
416
|
+
newInternalValue.value = newValue;
|
|
417
|
+
const event = {
|
|
418
|
+
target: {
|
|
419
|
+
value: newValue
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
onChange?.(event, newInternalValue);
|
|
423
|
+
} else {
|
|
424
|
+
const calSelectData = data;
|
|
425
|
+
const val = DateTime.fromISO(calSelectData.value || "", {
|
|
426
|
+
zone: defaultTimeZone
|
|
427
|
+
});
|
|
428
|
+
const newValue = val.toFormat(format);
|
|
429
|
+
const newInternalValue = {
|
|
430
|
+
value: newValue,
|
|
431
|
+
date: calSelectData.value,
|
|
432
|
+
isValid: val.isValid && isValidDate(
|
|
433
|
+
val,
|
|
434
|
+
minDate,
|
|
435
|
+
maxDate,
|
|
436
|
+
new Set(unavailableDates || unavailable?.dates),
|
|
437
|
+
{
|
|
438
|
+
dates: new Set(unavailable?.dates),
|
|
439
|
+
daysOfWeek: new Set(unavailable?.daysOfWeek)
|
|
440
|
+
},
|
|
441
|
+
defaultTimeZone
|
|
442
|
+
)
|
|
443
|
+
};
|
|
444
|
+
if (typeof inputValue !== "string") {
|
|
445
|
+
setInternalValue(newInternalValue);
|
|
446
|
+
}
|
|
447
|
+
const event = {
|
|
448
|
+
target: {
|
|
449
|
+
value: newValue
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
onChange?.(event, newInternalValue);
|
|
453
|
+
}
|
|
454
|
+
};
|
|
455
|
+
const handleInputFocus = (ev) => {
|
|
456
|
+
if (!open) {
|
|
457
|
+
setOpen(true);
|
|
458
|
+
onFocus?.(ev);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
return /* @__PURE__ */ jsxs(
|
|
462
|
+
PopoverLegacy,
|
|
463
|
+
{
|
|
464
|
+
open: openCalendar || open,
|
|
465
|
+
modal: true,
|
|
466
|
+
placement: "bottom-start",
|
|
467
|
+
disableTriggerFocus: true,
|
|
468
|
+
disableFocusLock,
|
|
469
|
+
children: [
|
|
470
|
+
/* @__PURE__ */ jsx(PopoverLegacy.Trigger, { children: ({ ref: popoverRef, ...props }) => /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
471
|
+
InputMask,
|
|
472
|
+
{
|
|
473
|
+
mask,
|
|
474
|
+
inputProps: {
|
|
475
|
+
onKeyDown: handleInputKeyDown,
|
|
476
|
+
onBlur: handleInputBlur,
|
|
477
|
+
onChange: handleInputChange,
|
|
478
|
+
onFocus: handleInputFocus
|
|
479
|
+
},
|
|
480
|
+
value: internalValue?.value || "",
|
|
481
|
+
...props,
|
|
482
|
+
ref: useMergeRefs([popoverRef, inputRef]),
|
|
483
|
+
children: /* @__PURE__ */ jsx(
|
|
484
|
+
TextField,
|
|
485
|
+
{
|
|
486
|
+
hint,
|
|
487
|
+
ref,
|
|
488
|
+
prefix: /* @__PURE__ */ jsx(Icon, { svg: SvgEvent, ref: iconRef }),
|
|
489
|
+
...inputProps,
|
|
490
|
+
required
|
|
491
|
+
}
|
|
492
|
+
)
|
|
493
|
+
}
|
|
494
|
+
) }) }),
|
|
495
|
+
/* @__PURE__ */ jsx(PopoverLegacy.Content, { ref: floatRef, children: !range ? /* @__PURE__ */ jsx(
|
|
496
|
+
Calendar,
|
|
497
|
+
{
|
|
498
|
+
ref: calRef,
|
|
499
|
+
onKeyDown: handleCalendarKeyDown,
|
|
500
|
+
defaultFocusedDate: internalValue?.date,
|
|
501
|
+
value: internalValue?.date || undefined,
|
|
502
|
+
locale,
|
|
503
|
+
onBlur: handleCalendarBlur,
|
|
504
|
+
onSelection: handleCalendarSelection,
|
|
505
|
+
onFocus: handleCalendarFocus,
|
|
506
|
+
minDate,
|
|
507
|
+
maxDate,
|
|
508
|
+
unavailableDates,
|
|
509
|
+
unavailable,
|
|
510
|
+
defaultTimeZone,
|
|
511
|
+
startDay
|
|
512
|
+
}
|
|
513
|
+
) : /* @__PURE__ */ jsx(
|
|
514
|
+
Calendar,
|
|
515
|
+
{
|
|
516
|
+
ref: calRef,
|
|
517
|
+
onKeyDown: handleCalendarKeyDown,
|
|
518
|
+
defaultFocusedDate: internalValue?.start?.date,
|
|
519
|
+
value: internalValue ? {
|
|
520
|
+
start: internalValue?.start?.date || undefined,
|
|
521
|
+
end: internalValue?.end?.date || undefined
|
|
522
|
+
} : undefined,
|
|
523
|
+
locale,
|
|
524
|
+
onBlur: handleCalendarBlur,
|
|
525
|
+
onSelection: handleCalendarSelection,
|
|
526
|
+
onFocus: handleCalendarFocus,
|
|
527
|
+
minDate,
|
|
528
|
+
maxDate,
|
|
529
|
+
unavailableDates,
|
|
530
|
+
unavailable,
|
|
531
|
+
defaultTimeZone,
|
|
532
|
+
startDay,
|
|
533
|
+
range: true
|
|
534
|
+
}
|
|
535
|
+
) })
|
|
536
|
+
]
|
|
537
|
+
}
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
);
|
|
541
|
+
DateFieldLegacy.displayName = "DateFieldLegacy";
|
|
542
|
+
|
|
543
|
+
const RANGE_DIVIDER = " — ";
|
|
544
|
+
const DateField$1 = forwardRef(
|
|
545
|
+
(props, ref) => {
|
|
546
|
+
const {
|
|
547
|
+
// DateField
|
|
548
|
+
openCalendar,
|
|
549
|
+
onFocus,
|
|
550
|
+
onBlur,
|
|
551
|
+
onChange,
|
|
552
|
+
format = "MM/dd/yyyy",
|
|
553
|
+
disableHint,
|
|
554
|
+
// Calendar
|
|
555
|
+
minDate,
|
|
556
|
+
maxDate,
|
|
557
|
+
unavailableDates,
|
|
558
|
+
unavailable,
|
|
559
|
+
startDay,
|
|
560
|
+
defaultValue,
|
|
561
|
+
value: inputValue,
|
|
562
|
+
// Shared
|
|
563
|
+
locale = Intl.DateTimeFormat().resolvedOptions().locale,
|
|
564
|
+
defaultTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
565
|
+
range,
|
|
566
|
+
// Input
|
|
567
|
+
required,
|
|
568
|
+
...inputProps
|
|
569
|
+
} = props;
|
|
570
|
+
const [open, _setOpen] = useState(openCalendar || false);
|
|
571
|
+
const setOpen = (val) => {
|
|
572
|
+
if (open && !val) {
|
|
573
|
+
inputRef.current?.focus();
|
|
574
|
+
}
|
|
575
|
+
_setOpen(val);
|
|
576
|
+
};
|
|
577
|
+
const [internalValue, setInternalValue] = useState();
|
|
578
|
+
const [disableFocusLock, setDisableFocusLock] = useState(true);
|
|
579
|
+
const inputRef = useRef(null);
|
|
580
|
+
const calRef = useRef(null);
|
|
581
|
+
const iconRef = useRef(null);
|
|
582
|
+
const docRef = useRef(null);
|
|
583
|
+
const floatRef = useRef(null);
|
|
584
|
+
const isClickOutside = useRef(false);
|
|
585
|
+
const formatMask = format.replace(/[^/]/g, "_");
|
|
586
|
+
const hint = useMemo(
|
|
587
|
+
() => disableHint ? undefined : `format: ${format.replace(/M/g, "m")}`,
|
|
588
|
+
[format, disableHint]
|
|
589
|
+
);
|
|
590
|
+
useEffect(() => {
|
|
591
|
+
if (!docRef.current) {
|
|
592
|
+
if (document != null) {
|
|
593
|
+
docRef.current = document;
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
const doc = inputRef.current?.closest("body")?.ownerDocument;
|
|
597
|
+
doc && (docRef.current = doc);
|
|
598
|
+
if (docRef.current == null && inputRef.current?.parentNode != null) {
|
|
599
|
+
let node = inputRef.current?.parentNode;
|
|
600
|
+
while (node.parentNode != null) {
|
|
601
|
+
node = node.parentNode;
|
|
602
|
+
}
|
|
603
|
+
docRef.current = node;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
const clickOutHandler = (ev) => {
|
|
607
|
+
const realTarget = ev.composedPath()[0];
|
|
608
|
+
if (!floatRef.current?.contains(realTarget) && !iconRef.current?.contains(realTarget) && inputRef.current !== realTarget) {
|
|
609
|
+
setOpen(false);
|
|
610
|
+
setDisableFocusLock(true);
|
|
611
|
+
onBlur?.(ev);
|
|
612
|
+
}
|
|
613
|
+
};
|
|
614
|
+
if (open) {
|
|
615
|
+
docRef.current?.addEventListener("click", clickOutHandler);
|
|
616
|
+
} else {
|
|
617
|
+
docRef.current?.removeEventListener("click", clickOutHandler);
|
|
618
|
+
}
|
|
619
|
+
return () => {
|
|
620
|
+
docRef.current?.removeEventListener("click", clickOutHandler);
|
|
621
|
+
};
|
|
622
|
+
}, [open, onBlur]);
|
|
88
623
|
useEffect(() => {
|
|
89
624
|
if (range) {
|
|
90
625
|
let start;
|
|
@@ -457,7 +992,9 @@ const DateField$1 = forwardRef(
|
|
|
457
992
|
}
|
|
458
993
|
};
|
|
459
994
|
const [popoverRef, setPopoverRef] = useState();
|
|
460
|
-
const combinedRef = useMergeRefs([popoverRef, inputRef]);
|
|
995
|
+
const combinedRef = useMergeRefs$1([popoverRef, inputRef]);
|
|
996
|
+
if (!supportsPopover())
|
|
997
|
+
return /* @__PURE__ */ jsx(DateFieldLegacy, { ...props, ref });
|
|
461
998
|
return /* @__PURE__ */ jsxs(
|
|
462
999
|
Popover,
|
|
463
1000
|
{
|
|
@@ -467,7 +1004,7 @@ const DateField$1 = forwardRef(
|
|
|
467
1004
|
disableTriggerFocus: true,
|
|
468
1005
|
disableFocusLock,
|
|
469
1006
|
children: [
|
|
470
|
-
/* @__PURE__ */ jsx(Popover.Trigger, { children: ({ ref: iRef, ...
|
|
1007
|
+
/* @__PURE__ */ jsx(Popover.Trigger, { children: ({ ref: iRef, ...props2 }) => {
|
|
471
1008
|
setPopoverRef(iRef);
|
|
472
1009
|
return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(
|
|
473
1010
|
InputMask,
|
|
@@ -480,7 +1017,7 @@ const DateField$1 = forwardRef(
|
|
|
480
1017
|
onFocus: handleInputFocus
|
|
481
1018
|
},
|
|
482
1019
|
value: internalValue?.value || "",
|
|
483
|
-
...
|
|
1020
|
+
...props2,
|
|
484
1021
|
ref: combinedRef,
|
|
485
1022
|
children: /* @__PURE__ */ jsx(
|
|
486
1023
|
TextField,
|
|
@@ -562,4 +1099,4 @@ const DateField = forwardRef(
|
|
|
562
1099
|
);
|
|
563
1100
|
|
|
564
1101
|
export { DateField as D };
|
|
565
|
-
//# sourceMappingURL=DateField-
|
|
1102
|
+
//# sourceMappingURL=DateField-5mNXaJ7q.js.map
|