@bookinglab/booking-ui-react 1.9.0 → 1.11.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/dist/index.d.cts +511 -3
- package/dist/index.d.ts +511 -3
- package/dist/index.js +4299 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4300 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { forwardRef, useId, useState, useCallback, useImperativeHandle, useEffect } from 'react';
|
|
2
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
1
|
+
import { forwardRef, useId, useState, useCallback, useImperativeHandle, useEffect, useRef } from 'react';
|
|
2
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
7
|
var cx = (...classes) => classes.filter(Boolean).join(" ");
|
|
6
8
|
function FormField({
|
|
7
9
|
question,
|
|
@@ -33,7 +35,13 @@ function FormField({
|
|
|
33
35
|
};
|
|
34
36
|
const renderHelpText = () => {
|
|
35
37
|
if (!question.help_text) return null;
|
|
36
|
-
return /* @__PURE__ */ jsx(
|
|
38
|
+
return /* @__PURE__ */ jsx(
|
|
39
|
+
"p",
|
|
40
|
+
{
|
|
41
|
+
className: classNames?.helpText ?? defaultHelpText,
|
|
42
|
+
dangerouslySetInnerHTML: { __html: question.help_text }
|
|
43
|
+
}
|
|
44
|
+
);
|
|
37
45
|
};
|
|
38
46
|
const renderError = () => {
|
|
39
47
|
if (!error) return null;
|
|
@@ -103,6 +111,39 @@ function FormField({
|
|
|
103
111
|
renderHelpText(),
|
|
104
112
|
renderError()
|
|
105
113
|
] });
|
|
114
|
+
case "radio":
|
|
115
|
+
return /* @__PURE__ */ jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
|
|
116
|
+
renderLabel(),
|
|
117
|
+
/* @__PURE__ */ jsx(
|
|
118
|
+
"div",
|
|
119
|
+
{
|
|
120
|
+
role: "radiogroup",
|
|
121
|
+
"aria-labelledby": inputId,
|
|
122
|
+
className: classNames?.radioGroup ?? "flex flex-col gap-2 mt-1",
|
|
123
|
+
children: question.options?.map((option) => {
|
|
124
|
+
const optionId = `${inputId}-${option.id}`;
|
|
125
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
126
|
+
/* @__PURE__ */ jsx(
|
|
127
|
+
"input",
|
|
128
|
+
{
|
|
129
|
+
id: optionId,
|
|
130
|
+
type: "radio",
|
|
131
|
+
name: inputId,
|
|
132
|
+
value: option.id,
|
|
133
|
+
checked: String(value ?? "") === String(option.id),
|
|
134
|
+
onChange: () => onChange(option.id),
|
|
135
|
+
className: classNames?.radio ?? "h-4 w-4 border-gray-300 text-blue-600 focus:ring-blue-500",
|
|
136
|
+
...ariaProps
|
|
137
|
+
}
|
|
138
|
+
),
|
|
139
|
+
/* @__PURE__ */ jsx("label", { htmlFor: optionId, className: classNames?.radioLabel ?? cx("text-sm", classNames?.label ?? "text-gray-700"), children: option.name })
|
|
140
|
+
] }, option.id);
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
),
|
|
144
|
+
renderHelpText(),
|
|
145
|
+
renderError()
|
|
146
|
+
] });
|
|
106
147
|
case "date":
|
|
107
148
|
return /* @__PURE__ */ jsxs("div", { className: classNames?.fieldWrapper ?? defaultFieldWrapper, children: [
|
|
108
149
|
renderLabel(),
|
|
@@ -172,6 +213,7 @@ function BookingForm({
|
|
|
172
213
|
questions,
|
|
173
214
|
onSubmit,
|
|
174
215
|
submitLabel = "Submit",
|
|
216
|
+
isAdmin = false,
|
|
175
217
|
className = "",
|
|
176
218
|
labelClassName,
|
|
177
219
|
classNames: classNamesProp
|
|
@@ -245,7 +287,7 @@ function BookingForm({
|
|
|
245
287
|
},
|
|
246
288
|
[values, questions]
|
|
247
289
|
);
|
|
248
|
-
const visibleQuestions = questions.filter(isQuestionVisible);
|
|
290
|
+
const visibleQuestions = questions.filter((q) => isAdmin || !q.admin_only).filter(isQuestionVisible);
|
|
249
291
|
const validateField = useCallback((question, value) => {
|
|
250
292
|
if (question.detail_type === "heading") return null;
|
|
251
293
|
if (question.required) {
|
|
@@ -269,16 +311,16 @@ function BookingForm({
|
|
|
269
311
|
}, []);
|
|
270
312
|
const validateAll = useCallback(() => {
|
|
271
313
|
const newErrors = {};
|
|
272
|
-
let
|
|
314
|
+
let isValid2 = true;
|
|
273
315
|
visibleQuestions.forEach((question) => {
|
|
274
316
|
const error = validateField(question, values[question.id]);
|
|
275
317
|
if (error) {
|
|
276
318
|
newErrors[question.id] = error;
|
|
277
|
-
|
|
319
|
+
isValid2 = false;
|
|
278
320
|
}
|
|
279
321
|
});
|
|
280
322
|
setErrors(newErrors);
|
|
281
|
-
return
|
|
323
|
+
return isValid2;
|
|
282
324
|
}, [visibleQuestions, values, validateField]);
|
|
283
325
|
useEffect(() => {
|
|
284
326
|
const visibleIds = new Set(visibleQuestions.map((q) => q.id));
|
|
@@ -540,17 +582,17 @@ var RegistrationForm = forwardRef(
|
|
|
540
582
|
);
|
|
541
583
|
const validateAll = useCallback(() => {
|
|
542
584
|
const newErrors = {};
|
|
543
|
-
let
|
|
585
|
+
let isValid2 = true;
|
|
544
586
|
for (const field of allFields) {
|
|
545
587
|
const value = values[field.name] || "";
|
|
546
588
|
const error = validateField(field, value, values);
|
|
547
589
|
if (error) {
|
|
548
590
|
newErrors[field.name] = error;
|
|
549
|
-
|
|
591
|
+
isValid2 = false;
|
|
550
592
|
}
|
|
551
593
|
}
|
|
552
594
|
setErrors(newErrors);
|
|
553
|
-
return
|
|
595
|
+
return isValid2;
|
|
554
596
|
}, [allFields, values, validateField]);
|
|
555
597
|
const checkIsValid = useCallback(
|
|
556
598
|
(currentValues) => {
|
|
@@ -611,8 +653,8 @@ var RegistrationForm = forwardRef(
|
|
|
611
653
|
}
|
|
612
654
|
}
|
|
613
655
|
if (onChange) {
|
|
614
|
-
const
|
|
615
|
-
onChange(newValues,
|
|
656
|
+
const isValid2 = checkIsValid(newValues);
|
|
657
|
+
onChange(newValues, isValid2);
|
|
616
658
|
}
|
|
617
659
|
},
|
|
618
660
|
[values, touched, allFields, validateField, onChange, checkIsValid]
|
|
@@ -787,7 +829,8 @@ var ContactDetailsForm = forwardRef(
|
|
|
787
829
|
className = "",
|
|
788
830
|
classNames = {},
|
|
789
831
|
fieldSettings = {},
|
|
790
|
-
hideSubmitButton = false
|
|
832
|
+
hideSubmitButton = false,
|
|
833
|
+
isSubmitted = false
|
|
791
834
|
}, ref) => {
|
|
792
835
|
const formId = useId();
|
|
793
836
|
const [firstName, setFirstName] = useState(initialValues?.firstName || "");
|
|
@@ -1007,7 +1050,7 @@ var ContactDetailsForm = forwardRef(
|
|
|
1007
1050
|
const errorId = `${fieldId}-error`;
|
|
1008
1051
|
const isDisabled = getFieldDisabled(name);
|
|
1009
1052
|
const isRequired = getFieldRequired(name);
|
|
1010
|
-
const error = contactTouched[name] ? contactErrors[name] : void 0;
|
|
1053
|
+
const error = contactTouched[name] || isSubmitted ? contactErrors[name] : void 0;
|
|
1011
1054
|
const hasError = !!error;
|
|
1012
1055
|
return /* @__PURE__ */ jsxs("div", { className: styles.fieldWrapper, children: [
|
|
1013
1056
|
/* @__PURE__ */ jsxs("label", { htmlFor: fieldId, className: styles.label, children: [
|
|
@@ -1037,7 +1080,7 @@ var ContactDetailsForm = forwardRef(
|
|
|
1037
1080
|
const fieldId = `${formId}-q-${question.id}`;
|
|
1038
1081
|
const errorId = `${fieldId}-error`;
|
|
1039
1082
|
const value = questionValues[question.id];
|
|
1040
|
-
const error = questionTouched[question.id] ? questionErrors[question.id] : void 0;
|
|
1083
|
+
const error = questionTouched[question.id] || isSubmitted ? questionErrors[question.id] : void 0;
|
|
1041
1084
|
const hasError = !!error;
|
|
1042
1085
|
const isDisabled = !!question.disabled;
|
|
1043
1086
|
const ariaProps = {
|
|
@@ -1194,6 +1237,12 @@ var ContactDetailsForm = forwardRef(
|
|
|
1194
1237
|
return null;
|
|
1195
1238
|
}
|
|
1196
1239
|
};
|
|
1240
|
+
useEffect(() => {
|
|
1241
|
+
if (isSubmitted) {
|
|
1242
|
+
validateAllContacts();
|
|
1243
|
+
validateAllQuestions();
|
|
1244
|
+
}
|
|
1245
|
+
}, [isSubmitted]);
|
|
1197
1246
|
useEffect(() => {
|
|
1198
1247
|
if (hideSubmitButton && _onChange) {
|
|
1199
1248
|
const contactValid = !contactFields.some((f) => {
|
|
@@ -1310,18 +1359,18 @@ var ResetPasswordForm = forwardRef(
|
|
|
1310
1359
|
e.preventDefault();
|
|
1311
1360
|
const allTouched = {};
|
|
1312
1361
|
const newErrors = {};
|
|
1313
|
-
let
|
|
1362
|
+
let isValid2 = true;
|
|
1314
1363
|
for (const field of FIELDS) {
|
|
1315
1364
|
allTouched[field.name] = true;
|
|
1316
1365
|
const error = validateField(field.name, values[field.name], values);
|
|
1317
1366
|
if (error) {
|
|
1318
1367
|
newErrors[field.name] = error;
|
|
1319
|
-
|
|
1368
|
+
isValid2 = false;
|
|
1320
1369
|
}
|
|
1321
1370
|
}
|
|
1322
1371
|
setTouched(allTouched);
|
|
1323
1372
|
setErrors(newErrors);
|
|
1324
|
-
if (
|
|
1373
|
+
if (isValid2) {
|
|
1325
1374
|
onSubmit(values);
|
|
1326
1375
|
setValues({ currentPassword: "", newPassword: "", confirmNewPassword: "" });
|
|
1327
1376
|
setErrors({});
|
|
@@ -1393,6 +1442,4237 @@ var ResetPasswordForm = forwardRef(
|
|
|
1393
1442
|
);
|
|
1394
1443
|
ResetPasswordForm.displayName = "ResetPasswordForm";
|
|
1395
1444
|
|
|
1396
|
-
|
|
1445
|
+
// ../../node_modules/date-fns/toDate.mjs
|
|
1446
|
+
function toDate(argument) {
|
|
1447
|
+
const argStr = Object.prototype.toString.call(argument);
|
|
1448
|
+
if (argument instanceof Date || typeof argument === "object" && argStr === "[object Date]") {
|
|
1449
|
+
return new argument.constructor(+argument);
|
|
1450
|
+
} else if (typeof argument === "number" || argStr === "[object Number]" || typeof argument === "string" || argStr === "[object String]") {
|
|
1451
|
+
return new Date(argument);
|
|
1452
|
+
} else {
|
|
1453
|
+
return /* @__PURE__ */ new Date(NaN);
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
// ../../node_modules/date-fns/constructFrom.mjs
|
|
1458
|
+
function constructFrom(date, value) {
|
|
1459
|
+
if (date instanceof Date) {
|
|
1460
|
+
return new date.constructor(value);
|
|
1461
|
+
} else {
|
|
1462
|
+
return new Date(value);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
// ../../node_modules/date-fns/addDays.mjs
|
|
1467
|
+
function addDays(date, amount) {
|
|
1468
|
+
const _date = toDate(date);
|
|
1469
|
+
if (isNaN(amount)) return constructFrom(date, NaN);
|
|
1470
|
+
if (!amount) {
|
|
1471
|
+
return _date;
|
|
1472
|
+
}
|
|
1473
|
+
_date.setDate(_date.getDate() + amount);
|
|
1474
|
+
return _date;
|
|
1475
|
+
}
|
|
1476
|
+
var millisecondsInWeek = 6048e5;
|
|
1477
|
+
var millisecondsInMinute = 6e4;
|
|
1478
|
+
var millisecondsInHour = 36e5;
|
|
1479
|
+
var millisecondsInSecond = 1e3;
|
|
1480
|
+
|
|
1481
|
+
// ../../node_modules/date-fns/_lib/defaultOptions.mjs
|
|
1482
|
+
var defaultOptions = {};
|
|
1483
|
+
function getDefaultOptions() {
|
|
1484
|
+
return defaultOptions;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
// ../../node_modules/date-fns/startOfWeek.mjs
|
|
1488
|
+
function startOfWeek(date, options) {
|
|
1489
|
+
const defaultOptions2 = getDefaultOptions();
|
|
1490
|
+
const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
|
|
1491
|
+
const _date = toDate(date);
|
|
1492
|
+
const day = _date.getDay();
|
|
1493
|
+
const diff = (day < weekStartsOn ? 7 : 0) + day - weekStartsOn;
|
|
1494
|
+
_date.setDate(_date.getDate() - diff);
|
|
1495
|
+
_date.setHours(0, 0, 0, 0);
|
|
1496
|
+
return _date;
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
// ../../node_modules/date-fns/startOfISOWeek.mjs
|
|
1500
|
+
function startOfISOWeek(date) {
|
|
1501
|
+
return startOfWeek(date, { weekStartsOn: 1 });
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
// ../../node_modules/date-fns/getISOWeekYear.mjs
|
|
1505
|
+
function getISOWeekYear(date) {
|
|
1506
|
+
const _date = toDate(date);
|
|
1507
|
+
const year = _date.getFullYear();
|
|
1508
|
+
const fourthOfJanuaryOfNextYear = constructFrom(date, 0);
|
|
1509
|
+
fourthOfJanuaryOfNextYear.setFullYear(year + 1, 0, 4);
|
|
1510
|
+
fourthOfJanuaryOfNextYear.setHours(0, 0, 0, 0);
|
|
1511
|
+
const startOfNextYear = startOfISOWeek(fourthOfJanuaryOfNextYear);
|
|
1512
|
+
const fourthOfJanuaryOfThisYear = constructFrom(date, 0);
|
|
1513
|
+
fourthOfJanuaryOfThisYear.setFullYear(year, 0, 4);
|
|
1514
|
+
fourthOfJanuaryOfThisYear.setHours(0, 0, 0, 0);
|
|
1515
|
+
const startOfThisYear = startOfISOWeek(fourthOfJanuaryOfThisYear);
|
|
1516
|
+
if (_date.getTime() >= startOfNextYear.getTime()) {
|
|
1517
|
+
return year + 1;
|
|
1518
|
+
} else if (_date.getTime() >= startOfThisYear.getTime()) {
|
|
1519
|
+
return year;
|
|
1520
|
+
} else {
|
|
1521
|
+
return year - 1;
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
// ../../node_modules/date-fns/startOfDay.mjs
|
|
1526
|
+
function startOfDay(date) {
|
|
1527
|
+
const _date = toDate(date);
|
|
1528
|
+
_date.setHours(0, 0, 0, 0);
|
|
1529
|
+
return _date;
|
|
1530
|
+
}
|
|
1531
|
+
|
|
1532
|
+
// ../../node_modules/date-fns/_lib/getTimezoneOffsetInMilliseconds.mjs
|
|
1533
|
+
function getTimezoneOffsetInMilliseconds(date) {
|
|
1534
|
+
const _date = toDate(date);
|
|
1535
|
+
const utcDate = new Date(
|
|
1536
|
+
Date.UTC(
|
|
1537
|
+
_date.getFullYear(),
|
|
1538
|
+
_date.getMonth(),
|
|
1539
|
+
_date.getDate(),
|
|
1540
|
+
_date.getHours(),
|
|
1541
|
+
_date.getMinutes(),
|
|
1542
|
+
_date.getSeconds(),
|
|
1543
|
+
_date.getMilliseconds()
|
|
1544
|
+
)
|
|
1545
|
+
);
|
|
1546
|
+
utcDate.setUTCFullYear(_date.getFullYear());
|
|
1547
|
+
return +date - +utcDate;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
// ../../node_modules/date-fns/startOfISOWeekYear.mjs
|
|
1551
|
+
function startOfISOWeekYear(date) {
|
|
1552
|
+
const year = getISOWeekYear(date);
|
|
1553
|
+
const fourthOfJanuary = constructFrom(date, 0);
|
|
1554
|
+
fourthOfJanuary.setFullYear(year, 0, 4);
|
|
1555
|
+
fourthOfJanuary.setHours(0, 0, 0, 0);
|
|
1556
|
+
return startOfISOWeek(fourthOfJanuary);
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
// ../../node_modules/date-fns/isDate.mjs
|
|
1560
|
+
function isDate(value) {
|
|
1561
|
+
return value instanceof Date || typeof value === "object" && Object.prototype.toString.call(value) === "[object Date]";
|
|
1562
|
+
}
|
|
1563
|
+
|
|
1564
|
+
// ../../node_modules/date-fns/isValid.mjs
|
|
1565
|
+
function isValid(date) {
|
|
1566
|
+
if (!isDate(date) && typeof date !== "number") {
|
|
1567
|
+
return false;
|
|
1568
|
+
}
|
|
1569
|
+
const _date = toDate(date);
|
|
1570
|
+
return !isNaN(Number(_date));
|
|
1571
|
+
}
|
|
1572
|
+
|
|
1573
|
+
// ../../node_modules/date-fns/locale/en-US/_lib/formatDistance.mjs
|
|
1574
|
+
var formatDistanceLocale = {
|
|
1575
|
+
lessThanXSeconds: {
|
|
1576
|
+
one: "less than a second",
|
|
1577
|
+
other: "less than {{count}} seconds"
|
|
1578
|
+
},
|
|
1579
|
+
xSeconds: {
|
|
1580
|
+
one: "1 second",
|
|
1581
|
+
other: "{{count}} seconds"
|
|
1582
|
+
},
|
|
1583
|
+
halfAMinute: "half a minute",
|
|
1584
|
+
lessThanXMinutes: {
|
|
1585
|
+
one: "less than a minute",
|
|
1586
|
+
other: "less than {{count}} minutes"
|
|
1587
|
+
},
|
|
1588
|
+
xMinutes: {
|
|
1589
|
+
one: "1 minute",
|
|
1590
|
+
other: "{{count}} minutes"
|
|
1591
|
+
},
|
|
1592
|
+
aboutXHours: {
|
|
1593
|
+
one: "about 1 hour",
|
|
1594
|
+
other: "about {{count}} hours"
|
|
1595
|
+
},
|
|
1596
|
+
xHours: {
|
|
1597
|
+
one: "1 hour",
|
|
1598
|
+
other: "{{count}} hours"
|
|
1599
|
+
},
|
|
1600
|
+
xDays: {
|
|
1601
|
+
one: "1 day",
|
|
1602
|
+
other: "{{count}} days"
|
|
1603
|
+
},
|
|
1604
|
+
aboutXWeeks: {
|
|
1605
|
+
one: "about 1 week",
|
|
1606
|
+
other: "about {{count}} weeks"
|
|
1607
|
+
},
|
|
1608
|
+
xWeeks: {
|
|
1609
|
+
one: "1 week",
|
|
1610
|
+
other: "{{count}} weeks"
|
|
1611
|
+
},
|
|
1612
|
+
aboutXMonths: {
|
|
1613
|
+
one: "about 1 month",
|
|
1614
|
+
other: "about {{count}} months"
|
|
1615
|
+
},
|
|
1616
|
+
xMonths: {
|
|
1617
|
+
one: "1 month",
|
|
1618
|
+
other: "{{count}} months"
|
|
1619
|
+
},
|
|
1620
|
+
aboutXYears: {
|
|
1621
|
+
one: "about 1 year",
|
|
1622
|
+
other: "about {{count}} years"
|
|
1623
|
+
},
|
|
1624
|
+
xYears: {
|
|
1625
|
+
one: "1 year",
|
|
1626
|
+
other: "{{count}} years"
|
|
1627
|
+
},
|
|
1628
|
+
overXYears: {
|
|
1629
|
+
one: "over 1 year",
|
|
1630
|
+
other: "over {{count}} years"
|
|
1631
|
+
},
|
|
1632
|
+
almostXYears: {
|
|
1633
|
+
one: "almost 1 year",
|
|
1634
|
+
other: "almost {{count}} years"
|
|
1635
|
+
}
|
|
1636
|
+
};
|
|
1637
|
+
var formatDistance = (token, count, options) => {
|
|
1638
|
+
let result;
|
|
1639
|
+
const tokenValue = formatDistanceLocale[token];
|
|
1640
|
+
if (typeof tokenValue === "string") {
|
|
1641
|
+
result = tokenValue;
|
|
1642
|
+
} else if (count === 1) {
|
|
1643
|
+
result = tokenValue.one;
|
|
1644
|
+
} else {
|
|
1645
|
+
result = tokenValue.other.replace("{{count}}", count.toString());
|
|
1646
|
+
}
|
|
1647
|
+
if (options?.addSuffix) {
|
|
1648
|
+
if (options.comparison && options.comparison > 0) {
|
|
1649
|
+
return "in " + result;
|
|
1650
|
+
} else {
|
|
1651
|
+
return result + " ago";
|
|
1652
|
+
}
|
|
1653
|
+
}
|
|
1654
|
+
return result;
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
// ../../node_modules/date-fns/locale/_lib/buildFormatLongFn.mjs
|
|
1658
|
+
function buildFormatLongFn(args) {
|
|
1659
|
+
return (options = {}) => {
|
|
1660
|
+
const width = options.width ? String(options.width) : args.defaultWidth;
|
|
1661
|
+
const format = args.formats[width] || args.formats[args.defaultWidth];
|
|
1662
|
+
return format;
|
|
1663
|
+
};
|
|
1664
|
+
}
|
|
1665
|
+
|
|
1666
|
+
// ../../node_modules/date-fns/locale/en-US/_lib/formatLong.mjs
|
|
1667
|
+
var dateFormats = {
|
|
1668
|
+
full: "EEEE, MMMM do, y",
|
|
1669
|
+
long: "MMMM do, y",
|
|
1670
|
+
medium: "MMM d, y",
|
|
1671
|
+
short: "MM/dd/yyyy"
|
|
1672
|
+
};
|
|
1673
|
+
var timeFormats = {
|
|
1674
|
+
full: "h:mm:ss a zzzz",
|
|
1675
|
+
long: "h:mm:ss a z",
|
|
1676
|
+
medium: "h:mm:ss a",
|
|
1677
|
+
short: "h:mm a"
|
|
1678
|
+
};
|
|
1679
|
+
var dateTimeFormats = {
|
|
1680
|
+
full: "{{date}} 'at' {{time}}",
|
|
1681
|
+
long: "{{date}} 'at' {{time}}",
|
|
1682
|
+
medium: "{{date}}, {{time}}",
|
|
1683
|
+
short: "{{date}}, {{time}}"
|
|
1684
|
+
};
|
|
1685
|
+
var formatLong = {
|
|
1686
|
+
date: buildFormatLongFn({
|
|
1687
|
+
formats: dateFormats,
|
|
1688
|
+
defaultWidth: "full"
|
|
1689
|
+
}),
|
|
1690
|
+
time: buildFormatLongFn({
|
|
1691
|
+
formats: timeFormats,
|
|
1692
|
+
defaultWidth: "full"
|
|
1693
|
+
}),
|
|
1694
|
+
dateTime: buildFormatLongFn({
|
|
1695
|
+
formats: dateTimeFormats,
|
|
1696
|
+
defaultWidth: "full"
|
|
1697
|
+
})
|
|
1698
|
+
};
|
|
1699
|
+
|
|
1700
|
+
// ../../node_modules/date-fns/locale/en-US/_lib/formatRelative.mjs
|
|
1701
|
+
var formatRelativeLocale = {
|
|
1702
|
+
lastWeek: "'last' eeee 'at' p",
|
|
1703
|
+
yesterday: "'yesterday at' p",
|
|
1704
|
+
today: "'today at' p",
|
|
1705
|
+
tomorrow: "'tomorrow at' p",
|
|
1706
|
+
nextWeek: "eeee 'at' p",
|
|
1707
|
+
other: "P"
|
|
1708
|
+
};
|
|
1709
|
+
var formatRelative = (token, _date, _baseDate, _options) => formatRelativeLocale[token];
|
|
1710
|
+
|
|
1711
|
+
// ../../node_modules/date-fns/locale/_lib/buildLocalizeFn.mjs
|
|
1712
|
+
function buildLocalizeFn(args) {
|
|
1713
|
+
return (value, options) => {
|
|
1714
|
+
const context = options?.context ? String(options.context) : "standalone";
|
|
1715
|
+
let valuesArray;
|
|
1716
|
+
if (context === "formatting" && args.formattingValues) {
|
|
1717
|
+
const defaultWidth = args.defaultFormattingWidth || args.defaultWidth;
|
|
1718
|
+
const width = options?.width ? String(options.width) : defaultWidth;
|
|
1719
|
+
valuesArray = args.formattingValues[width] || args.formattingValues[defaultWidth];
|
|
1720
|
+
} else {
|
|
1721
|
+
const defaultWidth = args.defaultWidth;
|
|
1722
|
+
const width = options?.width ? String(options.width) : args.defaultWidth;
|
|
1723
|
+
valuesArray = args.values[width] || args.values[defaultWidth];
|
|
1724
|
+
}
|
|
1725
|
+
const index = args.argumentCallback ? args.argumentCallback(value) : value;
|
|
1726
|
+
return valuesArray[index];
|
|
1727
|
+
};
|
|
1728
|
+
}
|
|
1729
|
+
|
|
1730
|
+
// ../../node_modules/date-fns/locale/en-US/_lib/localize.mjs
|
|
1731
|
+
var eraValues = {
|
|
1732
|
+
narrow: ["B", "A"],
|
|
1733
|
+
abbreviated: ["BC", "AD"],
|
|
1734
|
+
wide: ["Before Christ", "Anno Domini"]
|
|
1735
|
+
};
|
|
1736
|
+
var quarterValues = {
|
|
1737
|
+
narrow: ["1", "2", "3", "4"],
|
|
1738
|
+
abbreviated: ["Q1", "Q2", "Q3", "Q4"],
|
|
1739
|
+
wide: ["1st quarter", "2nd quarter", "3rd quarter", "4th quarter"]
|
|
1740
|
+
};
|
|
1741
|
+
var monthValues = {
|
|
1742
|
+
narrow: ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"],
|
|
1743
|
+
abbreviated: [
|
|
1744
|
+
"Jan",
|
|
1745
|
+
"Feb",
|
|
1746
|
+
"Mar",
|
|
1747
|
+
"Apr",
|
|
1748
|
+
"May",
|
|
1749
|
+
"Jun",
|
|
1750
|
+
"Jul",
|
|
1751
|
+
"Aug",
|
|
1752
|
+
"Sep",
|
|
1753
|
+
"Oct",
|
|
1754
|
+
"Nov",
|
|
1755
|
+
"Dec"
|
|
1756
|
+
],
|
|
1757
|
+
wide: [
|
|
1758
|
+
"January",
|
|
1759
|
+
"February",
|
|
1760
|
+
"March",
|
|
1761
|
+
"April",
|
|
1762
|
+
"May",
|
|
1763
|
+
"June",
|
|
1764
|
+
"July",
|
|
1765
|
+
"August",
|
|
1766
|
+
"September",
|
|
1767
|
+
"October",
|
|
1768
|
+
"November",
|
|
1769
|
+
"December"
|
|
1770
|
+
]
|
|
1771
|
+
};
|
|
1772
|
+
var dayValues = {
|
|
1773
|
+
narrow: ["S", "M", "T", "W", "T", "F", "S"],
|
|
1774
|
+
short: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"],
|
|
1775
|
+
abbreviated: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
|
|
1776
|
+
wide: [
|
|
1777
|
+
"Sunday",
|
|
1778
|
+
"Monday",
|
|
1779
|
+
"Tuesday",
|
|
1780
|
+
"Wednesday",
|
|
1781
|
+
"Thursday",
|
|
1782
|
+
"Friday",
|
|
1783
|
+
"Saturday"
|
|
1784
|
+
]
|
|
1785
|
+
};
|
|
1786
|
+
var dayPeriodValues = {
|
|
1787
|
+
narrow: {
|
|
1788
|
+
am: "a",
|
|
1789
|
+
pm: "p",
|
|
1790
|
+
midnight: "mi",
|
|
1791
|
+
noon: "n",
|
|
1792
|
+
morning: "morning",
|
|
1793
|
+
afternoon: "afternoon",
|
|
1794
|
+
evening: "evening",
|
|
1795
|
+
night: "night"
|
|
1796
|
+
},
|
|
1797
|
+
abbreviated: {
|
|
1798
|
+
am: "AM",
|
|
1799
|
+
pm: "PM",
|
|
1800
|
+
midnight: "midnight",
|
|
1801
|
+
noon: "noon",
|
|
1802
|
+
morning: "morning",
|
|
1803
|
+
afternoon: "afternoon",
|
|
1804
|
+
evening: "evening",
|
|
1805
|
+
night: "night"
|
|
1806
|
+
},
|
|
1807
|
+
wide: {
|
|
1808
|
+
am: "a.m.",
|
|
1809
|
+
pm: "p.m.",
|
|
1810
|
+
midnight: "midnight",
|
|
1811
|
+
noon: "noon",
|
|
1812
|
+
morning: "morning",
|
|
1813
|
+
afternoon: "afternoon",
|
|
1814
|
+
evening: "evening",
|
|
1815
|
+
night: "night"
|
|
1816
|
+
}
|
|
1817
|
+
};
|
|
1818
|
+
var formattingDayPeriodValues = {
|
|
1819
|
+
narrow: {
|
|
1820
|
+
am: "a",
|
|
1821
|
+
pm: "p",
|
|
1822
|
+
midnight: "mi",
|
|
1823
|
+
noon: "n",
|
|
1824
|
+
morning: "in the morning",
|
|
1825
|
+
afternoon: "in the afternoon",
|
|
1826
|
+
evening: "in the evening",
|
|
1827
|
+
night: "at night"
|
|
1828
|
+
},
|
|
1829
|
+
abbreviated: {
|
|
1830
|
+
am: "AM",
|
|
1831
|
+
pm: "PM",
|
|
1832
|
+
midnight: "midnight",
|
|
1833
|
+
noon: "noon",
|
|
1834
|
+
morning: "in the morning",
|
|
1835
|
+
afternoon: "in the afternoon",
|
|
1836
|
+
evening: "in the evening",
|
|
1837
|
+
night: "at night"
|
|
1838
|
+
},
|
|
1839
|
+
wide: {
|
|
1840
|
+
am: "a.m.",
|
|
1841
|
+
pm: "p.m.",
|
|
1842
|
+
midnight: "midnight",
|
|
1843
|
+
noon: "noon",
|
|
1844
|
+
morning: "in the morning",
|
|
1845
|
+
afternoon: "in the afternoon",
|
|
1846
|
+
evening: "in the evening",
|
|
1847
|
+
night: "at night"
|
|
1848
|
+
}
|
|
1849
|
+
};
|
|
1850
|
+
var ordinalNumber = (dirtyNumber, _options) => {
|
|
1851
|
+
const number = Number(dirtyNumber);
|
|
1852
|
+
const rem100 = number % 100;
|
|
1853
|
+
if (rem100 > 20 || rem100 < 10) {
|
|
1854
|
+
switch (rem100 % 10) {
|
|
1855
|
+
case 1:
|
|
1856
|
+
return number + "st";
|
|
1857
|
+
case 2:
|
|
1858
|
+
return number + "nd";
|
|
1859
|
+
case 3:
|
|
1860
|
+
return number + "rd";
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1863
|
+
return number + "th";
|
|
1864
|
+
};
|
|
1865
|
+
var localize = {
|
|
1866
|
+
ordinalNumber,
|
|
1867
|
+
era: buildLocalizeFn({
|
|
1868
|
+
values: eraValues,
|
|
1869
|
+
defaultWidth: "wide"
|
|
1870
|
+
}),
|
|
1871
|
+
quarter: buildLocalizeFn({
|
|
1872
|
+
values: quarterValues,
|
|
1873
|
+
defaultWidth: "wide",
|
|
1874
|
+
argumentCallback: (quarter) => quarter - 1
|
|
1875
|
+
}),
|
|
1876
|
+
month: buildLocalizeFn({
|
|
1877
|
+
values: monthValues,
|
|
1878
|
+
defaultWidth: "wide"
|
|
1879
|
+
}),
|
|
1880
|
+
day: buildLocalizeFn({
|
|
1881
|
+
values: dayValues,
|
|
1882
|
+
defaultWidth: "wide"
|
|
1883
|
+
}),
|
|
1884
|
+
dayPeriod: buildLocalizeFn({
|
|
1885
|
+
values: dayPeriodValues,
|
|
1886
|
+
defaultWidth: "wide",
|
|
1887
|
+
formattingValues: formattingDayPeriodValues,
|
|
1888
|
+
defaultFormattingWidth: "wide"
|
|
1889
|
+
})
|
|
1890
|
+
};
|
|
1891
|
+
|
|
1892
|
+
// ../../node_modules/date-fns/locale/_lib/buildMatchFn.mjs
|
|
1893
|
+
function buildMatchFn(args) {
|
|
1894
|
+
return (string, options = {}) => {
|
|
1895
|
+
const width = options.width;
|
|
1896
|
+
const matchPattern = width && args.matchPatterns[width] || args.matchPatterns[args.defaultMatchWidth];
|
|
1897
|
+
const matchResult = string.match(matchPattern);
|
|
1898
|
+
if (!matchResult) {
|
|
1899
|
+
return null;
|
|
1900
|
+
}
|
|
1901
|
+
const matchedString = matchResult[0];
|
|
1902
|
+
const parsePatterns = width && args.parsePatterns[width] || args.parsePatterns[args.defaultParseWidth];
|
|
1903
|
+
const key = Array.isArray(parsePatterns) ? findIndex(parsePatterns, (pattern) => pattern.test(matchedString)) : (
|
|
1904
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type
|
|
1905
|
+
findKey(parsePatterns, (pattern) => pattern.test(matchedString))
|
|
1906
|
+
);
|
|
1907
|
+
let value;
|
|
1908
|
+
value = args.valueCallback ? args.valueCallback(key) : key;
|
|
1909
|
+
value = options.valueCallback ? (
|
|
1910
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- I challange you to fix the type
|
|
1911
|
+
options.valueCallback(value)
|
|
1912
|
+
) : value;
|
|
1913
|
+
const rest = string.slice(matchedString.length);
|
|
1914
|
+
return { value, rest };
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
function findKey(object, predicate) {
|
|
1918
|
+
for (const key in object) {
|
|
1919
|
+
if (Object.prototype.hasOwnProperty.call(object, key) && predicate(object[key])) {
|
|
1920
|
+
return key;
|
|
1921
|
+
}
|
|
1922
|
+
}
|
|
1923
|
+
return void 0;
|
|
1924
|
+
}
|
|
1925
|
+
function findIndex(array, predicate) {
|
|
1926
|
+
for (let key = 0; key < array.length; key++) {
|
|
1927
|
+
if (predicate(array[key])) {
|
|
1928
|
+
return key;
|
|
1929
|
+
}
|
|
1930
|
+
}
|
|
1931
|
+
return void 0;
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
// ../../node_modules/date-fns/locale/_lib/buildMatchPatternFn.mjs
|
|
1935
|
+
function buildMatchPatternFn(args) {
|
|
1936
|
+
return (string, options = {}) => {
|
|
1937
|
+
const matchResult = string.match(args.matchPattern);
|
|
1938
|
+
if (!matchResult) return null;
|
|
1939
|
+
const matchedString = matchResult[0];
|
|
1940
|
+
const parseResult = string.match(args.parsePattern);
|
|
1941
|
+
if (!parseResult) return null;
|
|
1942
|
+
let value = args.valueCallback ? args.valueCallback(parseResult[0]) : parseResult[0];
|
|
1943
|
+
value = options.valueCallback ? options.valueCallback(value) : value;
|
|
1944
|
+
const rest = string.slice(matchedString.length);
|
|
1945
|
+
return { value, rest };
|
|
1946
|
+
};
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
// ../../node_modules/date-fns/locale/en-US/_lib/match.mjs
|
|
1950
|
+
var matchOrdinalNumberPattern = /^(\d+)(th|st|nd|rd)?/i;
|
|
1951
|
+
var parseOrdinalNumberPattern = /\d+/i;
|
|
1952
|
+
var matchEraPatterns = {
|
|
1953
|
+
narrow: /^(b|a)/i,
|
|
1954
|
+
abbreviated: /^(b\.?\s?c\.?|b\.?\s?c\.?\s?e\.?|a\.?\s?d\.?|c\.?\s?e\.?)/i,
|
|
1955
|
+
wide: /^(before christ|before common era|anno domini|common era)/i
|
|
1956
|
+
};
|
|
1957
|
+
var parseEraPatterns = {
|
|
1958
|
+
any: [/^b/i, /^(a|c)/i]
|
|
1959
|
+
};
|
|
1960
|
+
var matchQuarterPatterns = {
|
|
1961
|
+
narrow: /^[1234]/i,
|
|
1962
|
+
abbreviated: /^q[1234]/i,
|
|
1963
|
+
wide: /^[1234](th|st|nd|rd)? quarter/i
|
|
1964
|
+
};
|
|
1965
|
+
var parseQuarterPatterns = {
|
|
1966
|
+
any: [/1/i, /2/i, /3/i, /4/i]
|
|
1967
|
+
};
|
|
1968
|
+
var matchMonthPatterns = {
|
|
1969
|
+
narrow: /^[jfmasond]/i,
|
|
1970
|
+
abbreviated: /^(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/i,
|
|
1971
|
+
wide: /^(january|february|march|april|may|june|july|august|september|october|november|december)/i
|
|
1972
|
+
};
|
|
1973
|
+
var parseMonthPatterns = {
|
|
1974
|
+
narrow: [
|
|
1975
|
+
/^j/i,
|
|
1976
|
+
/^f/i,
|
|
1977
|
+
/^m/i,
|
|
1978
|
+
/^a/i,
|
|
1979
|
+
/^m/i,
|
|
1980
|
+
/^j/i,
|
|
1981
|
+
/^j/i,
|
|
1982
|
+
/^a/i,
|
|
1983
|
+
/^s/i,
|
|
1984
|
+
/^o/i,
|
|
1985
|
+
/^n/i,
|
|
1986
|
+
/^d/i
|
|
1987
|
+
],
|
|
1988
|
+
any: [
|
|
1989
|
+
/^ja/i,
|
|
1990
|
+
/^f/i,
|
|
1991
|
+
/^mar/i,
|
|
1992
|
+
/^ap/i,
|
|
1993
|
+
/^may/i,
|
|
1994
|
+
/^jun/i,
|
|
1995
|
+
/^jul/i,
|
|
1996
|
+
/^au/i,
|
|
1997
|
+
/^s/i,
|
|
1998
|
+
/^o/i,
|
|
1999
|
+
/^n/i,
|
|
2000
|
+
/^d/i
|
|
2001
|
+
]
|
|
2002
|
+
};
|
|
2003
|
+
var matchDayPatterns = {
|
|
2004
|
+
narrow: /^[smtwf]/i,
|
|
2005
|
+
short: /^(su|mo|tu|we|th|fr|sa)/i,
|
|
2006
|
+
abbreviated: /^(sun|mon|tue|wed|thu|fri|sat)/i,
|
|
2007
|
+
wide: /^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/i
|
|
2008
|
+
};
|
|
2009
|
+
var parseDayPatterns = {
|
|
2010
|
+
narrow: [/^s/i, /^m/i, /^t/i, /^w/i, /^t/i, /^f/i, /^s/i],
|
|
2011
|
+
any: [/^su/i, /^m/i, /^tu/i, /^w/i, /^th/i, /^f/i, /^sa/i]
|
|
2012
|
+
};
|
|
2013
|
+
var matchDayPeriodPatterns = {
|
|
2014
|
+
narrow: /^(a|p|mi|n|(in the|at) (morning|afternoon|evening|night))/i,
|
|
2015
|
+
any: /^([ap]\.?\s?m\.?|midnight|noon|(in the|at) (morning|afternoon|evening|night))/i
|
|
2016
|
+
};
|
|
2017
|
+
var parseDayPeriodPatterns = {
|
|
2018
|
+
any: {
|
|
2019
|
+
am: /^a/i,
|
|
2020
|
+
pm: /^p/i,
|
|
2021
|
+
midnight: /^mi/i,
|
|
2022
|
+
noon: /^no/i,
|
|
2023
|
+
morning: /morning/i,
|
|
2024
|
+
afternoon: /afternoon/i,
|
|
2025
|
+
evening: /evening/i,
|
|
2026
|
+
night: /night/i
|
|
2027
|
+
}
|
|
2028
|
+
};
|
|
2029
|
+
var match = {
|
|
2030
|
+
ordinalNumber: buildMatchPatternFn({
|
|
2031
|
+
matchPattern: matchOrdinalNumberPattern,
|
|
2032
|
+
parsePattern: parseOrdinalNumberPattern,
|
|
2033
|
+
valueCallback: (value) => parseInt(value, 10)
|
|
2034
|
+
}),
|
|
2035
|
+
era: buildMatchFn({
|
|
2036
|
+
matchPatterns: matchEraPatterns,
|
|
2037
|
+
defaultMatchWidth: "wide",
|
|
2038
|
+
parsePatterns: parseEraPatterns,
|
|
2039
|
+
defaultParseWidth: "any"
|
|
2040
|
+
}),
|
|
2041
|
+
quarter: buildMatchFn({
|
|
2042
|
+
matchPatterns: matchQuarterPatterns,
|
|
2043
|
+
defaultMatchWidth: "wide",
|
|
2044
|
+
parsePatterns: parseQuarterPatterns,
|
|
2045
|
+
defaultParseWidth: "any",
|
|
2046
|
+
valueCallback: (index) => index + 1
|
|
2047
|
+
}),
|
|
2048
|
+
month: buildMatchFn({
|
|
2049
|
+
matchPatterns: matchMonthPatterns,
|
|
2050
|
+
defaultMatchWidth: "wide",
|
|
2051
|
+
parsePatterns: parseMonthPatterns,
|
|
2052
|
+
defaultParseWidth: "any"
|
|
2053
|
+
}),
|
|
2054
|
+
day: buildMatchFn({
|
|
2055
|
+
matchPatterns: matchDayPatterns,
|
|
2056
|
+
defaultMatchWidth: "wide",
|
|
2057
|
+
parsePatterns: parseDayPatterns,
|
|
2058
|
+
defaultParseWidth: "any"
|
|
2059
|
+
}),
|
|
2060
|
+
dayPeriod: buildMatchFn({
|
|
2061
|
+
matchPatterns: matchDayPeriodPatterns,
|
|
2062
|
+
defaultMatchWidth: "any",
|
|
2063
|
+
parsePatterns: parseDayPeriodPatterns,
|
|
2064
|
+
defaultParseWidth: "any"
|
|
2065
|
+
})
|
|
2066
|
+
};
|
|
2067
|
+
|
|
2068
|
+
// ../../node_modules/date-fns/locale/en-US.mjs
|
|
2069
|
+
var enUS = {
|
|
2070
|
+
code: "en-US",
|
|
2071
|
+
formatDistance,
|
|
2072
|
+
formatLong,
|
|
2073
|
+
formatRelative,
|
|
2074
|
+
localize,
|
|
2075
|
+
match,
|
|
2076
|
+
options: {
|
|
2077
|
+
weekStartsOn: 0,
|
|
2078
|
+
firstWeekContainsDate: 1
|
|
2079
|
+
}
|
|
2080
|
+
};
|
|
2081
|
+
|
|
2082
|
+
// ../../node_modules/date-fns/getISOWeek.mjs
|
|
2083
|
+
function getISOWeek(date) {
|
|
2084
|
+
const _date = toDate(date);
|
|
2085
|
+
const diff = +startOfISOWeek(_date) - +startOfISOWeekYear(_date);
|
|
2086
|
+
return Math.round(diff / millisecondsInWeek) + 1;
|
|
2087
|
+
}
|
|
2088
|
+
|
|
2089
|
+
// ../../node_modules/date-fns/getWeekYear.mjs
|
|
2090
|
+
function getWeekYear(date, options) {
|
|
2091
|
+
const _date = toDate(date);
|
|
2092
|
+
const year = _date.getFullYear();
|
|
2093
|
+
const defaultOptions2 = getDefaultOptions();
|
|
2094
|
+
const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
|
|
2095
|
+
const firstWeekOfNextYear = constructFrom(date, 0);
|
|
2096
|
+
firstWeekOfNextYear.setFullYear(year + 1, 0, firstWeekContainsDate);
|
|
2097
|
+
firstWeekOfNextYear.setHours(0, 0, 0, 0);
|
|
2098
|
+
const startOfNextYear = startOfWeek(firstWeekOfNextYear, options);
|
|
2099
|
+
const firstWeekOfThisYear = constructFrom(date, 0);
|
|
2100
|
+
firstWeekOfThisYear.setFullYear(year, 0, firstWeekContainsDate);
|
|
2101
|
+
firstWeekOfThisYear.setHours(0, 0, 0, 0);
|
|
2102
|
+
const startOfThisYear = startOfWeek(firstWeekOfThisYear, options);
|
|
2103
|
+
if (_date.getTime() >= startOfNextYear.getTime()) {
|
|
2104
|
+
return year + 1;
|
|
2105
|
+
} else if (_date.getTime() >= startOfThisYear.getTime()) {
|
|
2106
|
+
return year;
|
|
2107
|
+
} else {
|
|
2108
|
+
return year - 1;
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
// ../../node_modules/date-fns/startOfWeekYear.mjs
|
|
2113
|
+
function startOfWeekYear(date, options) {
|
|
2114
|
+
const defaultOptions2 = getDefaultOptions();
|
|
2115
|
+
const firstWeekContainsDate = options?.firstWeekContainsDate ?? options?.locale?.options?.firstWeekContainsDate ?? defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
|
|
2116
|
+
const year = getWeekYear(date, options);
|
|
2117
|
+
const firstWeek = constructFrom(date, 0);
|
|
2118
|
+
firstWeek.setFullYear(year, 0, firstWeekContainsDate);
|
|
2119
|
+
firstWeek.setHours(0, 0, 0, 0);
|
|
2120
|
+
const _date = startOfWeek(firstWeek, options);
|
|
2121
|
+
return _date;
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
// ../../node_modules/date-fns/getWeek.mjs
|
|
2125
|
+
function getWeek(date, options) {
|
|
2126
|
+
const _date = toDate(date);
|
|
2127
|
+
const diff = +startOfWeek(_date, options) - +startOfWeekYear(_date, options);
|
|
2128
|
+
return Math.round(diff / millisecondsInWeek) + 1;
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2131
|
+
// ../../node_modules/date-fns/_lib/format/longFormatters.mjs
|
|
2132
|
+
var dateLongFormatter = (pattern, formatLong2) => {
|
|
2133
|
+
switch (pattern) {
|
|
2134
|
+
case "P":
|
|
2135
|
+
return formatLong2.date({ width: "short" });
|
|
2136
|
+
case "PP":
|
|
2137
|
+
return formatLong2.date({ width: "medium" });
|
|
2138
|
+
case "PPP":
|
|
2139
|
+
return formatLong2.date({ width: "long" });
|
|
2140
|
+
case "PPPP":
|
|
2141
|
+
default:
|
|
2142
|
+
return formatLong2.date({ width: "full" });
|
|
2143
|
+
}
|
|
2144
|
+
};
|
|
2145
|
+
var timeLongFormatter = (pattern, formatLong2) => {
|
|
2146
|
+
switch (pattern) {
|
|
2147
|
+
case "p":
|
|
2148
|
+
return formatLong2.time({ width: "short" });
|
|
2149
|
+
case "pp":
|
|
2150
|
+
return formatLong2.time({ width: "medium" });
|
|
2151
|
+
case "ppp":
|
|
2152
|
+
return formatLong2.time({ width: "long" });
|
|
2153
|
+
case "pppp":
|
|
2154
|
+
default:
|
|
2155
|
+
return formatLong2.time({ width: "full" });
|
|
2156
|
+
}
|
|
2157
|
+
};
|
|
2158
|
+
var dateTimeLongFormatter = (pattern, formatLong2) => {
|
|
2159
|
+
const matchResult = pattern.match(/(P+)(p+)?/) || [];
|
|
2160
|
+
const datePattern = matchResult[1];
|
|
2161
|
+
const timePattern = matchResult[2];
|
|
2162
|
+
if (!timePattern) {
|
|
2163
|
+
return dateLongFormatter(pattern, formatLong2);
|
|
2164
|
+
}
|
|
2165
|
+
let dateTimeFormat;
|
|
2166
|
+
switch (datePattern) {
|
|
2167
|
+
case "P":
|
|
2168
|
+
dateTimeFormat = formatLong2.dateTime({ width: "short" });
|
|
2169
|
+
break;
|
|
2170
|
+
case "PP":
|
|
2171
|
+
dateTimeFormat = formatLong2.dateTime({ width: "medium" });
|
|
2172
|
+
break;
|
|
2173
|
+
case "PPP":
|
|
2174
|
+
dateTimeFormat = formatLong2.dateTime({ width: "long" });
|
|
2175
|
+
break;
|
|
2176
|
+
case "PPPP":
|
|
2177
|
+
default:
|
|
2178
|
+
dateTimeFormat = formatLong2.dateTime({ width: "full" });
|
|
2179
|
+
break;
|
|
2180
|
+
}
|
|
2181
|
+
return dateTimeFormat.replace("{{date}}", dateLongFormatter(datePattern, formatLong2)).replace("{{time}}", timeLongFormatter(timePattern, formatLong2));
|
|
2182
|
+
};
|
|
2183
|
+
var longFormatters = {
|
|
2184
|
+
p: timeLongFormatter,
|
|
2185
|
+
P: dateTimeLongFormatter
|
|
2186
|
+
};
|
|
2187
|
+
|
|
2188
|
+
// ../../node_modules/date-fns/_lib/protectedTokens.mjs
|
|
2189
|
+
var dayOfYearTokenRE = /^D+$/;
|
|
2190
|
+
var weekYearTokenRE = /^Y+$/;
|
|
2191
|
+
var throwTokens = ["D", "DD", "YY", "YYYY"];
|
|
2192
|
+
function isProtectedDayOfYearToken(token) {
|
|
2193
|
+
return dayOfYearTokenRE.test(token);
|
|
2194
|
+
}
|
|
2195
|
+
function isProtectedWeekYearToken(token) {
|
|
2196
|
+
return weekYearTokenRE.test(token);
|
|
2197
|
+
}
|
|
2198
|
+
function warnOrThrowProtectedError(token, format, input) {
|
|
2199
|
+
const _message = message(token, format, input);
|
|
2200
|
+
console.warn(_message);
|
|
2201
|
+
if (throwTokens.includes(token)) throw new RangeError(_message);
|
|
2202
|
+
}
|
|
2203
|
+
function message(token, format, input) {
|
|
2204
|
+
const subject = token[0] === "Y" ? "years" : "days of the month";
|
|
2205
|
+
return `Use \`${token.toLowerCase()}\` instead of \`${token}\` (in \`${format}\`) for formatting ${subject} to the input \`${input}\`; see: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md`;
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
// ../../node_modules/date-fns/getDefaultOptions.mjs
|
|
2209
|
+
function getDefaultOptions2() {
|
|
2210
|
+
return Object.assign({}, getDefaultOptions());
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
// ../../node_modules/date-fns/getISODay.mjs
|
|
2214
|
+
function getISODay(date) {
|
|
2215
|
+
const _date = toDate(date);
|
|
2216
|
+
let day = _date.getDay();
|
|
2217
|
+
if (day === 0) {
|
|
2218
|
+
day = 7;
|
|
2219
|
+
}
|
|
2220
|
+
return day;
|
|
2221
|
+
}
|
|
2222
|
+
|
|
2223
|
+
// ../../node_modules/date-fns/isAfter.mjs
|
|
2224
|
+
function isAfter(date, dateToCompare) {
|
|
2225
|
+
const _date = toDate(date);
|
|
2226
|
+
const _dateToCompare = toDate(dateToCompare);
|
|
2227
|
+
return _date.getTime() > _dateToCompare.getTime();
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
// ../../node_modules/date-fns/isBefore.mjs
|
|
2231
|
+
function isBefore(date, dateToCompare) {
|
|
2232
|
+
const _date = toDate(date);
|
|
2233
|
+
const _dateToCompare = toDate(dateToCompare);
|
|
2234
|
+
return +_date < +_dateToCompare;
|
|
2235
|
+
}
|
|
2236
|
+
|
|
2237
|
+
// ../../node_modules/date-fns/transpose.mjs
|
|
2238
|
+
function transpose(fromDate, constructor) {
|
|
2239
|
+
const date = constructor instanceof Date ? constructFrom(constructor, 0) : new constructor(0);
|
|
2240
|
+
date.setFullYear(
|
|
2241
|
+
fromDate.getFullYear(),
|
|
2242
|
+
fromDate.getMonth(),
|
|
2243
|
+
fromDate.getDate()
|
|
2244
|
+
);
|
|
2245
|
+
date.setHours(
|
|
2246
|
+
fromDate.getHours(),
|
|
2247
|
+
fromDate.getMinutes(),
|
|
2248
|
+
fromDate.getSeconds(),
|
|
2249
|
+
fromDate.getMilliseconds()
|
|
2250
|
+
);
|
|
2251
|
+
return date;
|
|
2252
|
+
}
|
|
2253
|
+
|
|
2254
|
+
// ../../node_modules/date-fns/parse/_lib/Setter.mjs
|
|
2255
|
+
var TIMEZONE_UNIT_PRIORITY = 10;
|
|
2256
|
+
var Setter = class {
|
|
2257
|
+
constructor() {
|
|
2258
|
+
__publicField(this, "subPriority", 0);
|
|
2259
|
+
}
|
|
2260
|
+
validate(_utcDate, _options) {
|
|
2261
|
+
return true;
|
|
2262
|
+
}
|
|
2263
|
+
};
|
|
2264
|
+
var ValueSetter = class extends Setter {
|
|
2265
|
+
constructor(value, validateValue, setValue, priority, subPriority) {
|
|
2266
|
+
super();
|
|
2267
|
+
this.value = value;
|
|
2268
|
+
this.validateValue = validateValue;
|
|
2269
|
+
this.setValue = setValue;
|
|
2270
|
+
this.priority = priority;
|
|
2271
|
+
if (subPriority) {
|
|
2272
|
+
this.subPriority = subPriority;
|
|
2273
|
+
}
|
|
2274
|
+
}
|
|
2275
|
+
validate(date, options) {
|
|
2276
|
+
return this.validateValue(date, this.value, options);
|
|
2277
|
+
}
|
|
2278
|
+
set(date, flags, options) {
|
|
2279
|
+
return this.setValue(date, flags, this.value, options);
|
|
2280
|
+
}
|
|
2281
|
+
};
|
|
2282
|
+
var DateToSystemTimezoneSetter = class extends Setter {
|
|
2283
|
+
constructor() {
|
|
2284
|
+
super(...arguments);
|
|
2285
|
+
__publicField(this, "priority", TIMEZONE_UNIT_PRIORITY);
|
|
2286
|
+
__publicField(this, "subPriority", -1);
|
|
2287
|
+
}
|
|
2288
|
+
set(date, flags) {
|
|
2289
|
+
if (flags.timestampIsSet) return date;
|
|
2290
|
+
return constructFrom(date, transpose(date, Date));
|
|
2291
|
+
}
|
|
2292
|
+
};
|
|
2293
|
+
|
|
2294
|
+
// ../../node_modules/date-fns/parse/_lib/Parser.mjs
|
|
2295
|
+
var Parser = class {
|
|
2296
|
+
run(dateString, token, match2, options) {
|
|
2297
|
+
const result = this.parse(dateString, token, match2, options);
|
|
2298
|
+
if (!result) {
|
|
2299
|
+
return null;
|
|
2300
|
+
}
|
|
2301
|
+
return {
|
|
2302
|
+
setter: new ValueSetter(
|
|
2303
|
+
result.value,
|
|
2304
|
+
this.validate,
|
|
2305
|
+
this.set,
|
|
2306
|
+
this.priority,
|
|
2307
|
+
this.subPriority
|
|
2308
|
+
),
|
|
2309
|
+
rest: result.rest
|
|
2310
|
+
};
|
|
2311
|
+
}
|
|
2312
|
+
validate(_utcDate, _value, _options) {
|
|
2313
|
+
return true;
|
|
2314
|
+
}
|
|
2315
|
+
};
|
|
2316
|
+
|
|
2317
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/EraParser.mjs
|
|
2318
|
+
var EraParser = class extends Parser {
|
|
2319
|
+
constructor() {
|
|
2320
|
+
super(...arguments);
|
|
2321
|
+
__publicField(this, "priority", 140);
|
|
2322
|
+
__publicField(this, "incompatibleTokens", ["R", "u", "t", "T"]);
|
|
2323
|
+
}
|
|
2324
|
+
parse(dateString, token, match2) {
|
|
2325
|
+
switch (token) {
|
|
2326
|
+
// AD, BC
|
|
2327
|
+
case "G":
|
|
2328
|
+
case "GG":
|
|
2329
|
+
case "GGG":
|
|
2330
|
+
return match2.era(dateString, { width: "abbreviated" }) || match2.era(dateString, { width: "narrow" });
|
|
2331
|
+
// A, B
|
|
2332
|
+
case "GGGGG":
|
|
2333
|
+
return match2.era(dateString, { width: "narrow" });
|
|
2334
|
+
// Anno Domini, Before Christ
|
|
2335
|
+
case "GGGG":
|
|
2336
|
+
default:
|
|
2337
|
+
return match2.era(dateString, { width: "wide" }) || match2.era(dateString, { width: "abbreviated" }) || match2.era(dateString, { width: "narrow" });
|
|
2338
|
+
}
|
|
2339
|
+
}
|
|
2340
|
+
set(date, flags, value) {
|
|
2341
|
+
flags.era = value;
|
|
2342
|
+
date.setFullYear(value, 0, 1);
|
|
2343
|
+
date.setHours(0, 0, 0, 0);
|
|
2344
|
+
return date;
|
|
2345
|
+
}
|
|
2346
|
+
};
|
|
2347
|
+
|
|
2348
|
+
// ../../node_modules/date-fns/parse/_lib/constants.mjs
|
|
2349
|
+
var numericPatterns = {
|
|
2350
|
+
month: /^(1[0-2]|0?\d)/,
|
|
2351
|
+
// 0 to 12
|
|
2352
|
+
date: /^(3[0-1]|[0-2]?\d)/,
|
|
2353
|
+
// 0 to 31
|
|
2354
|
+
dayOfYear: /^(36[0-6]|3[0-5]\d|[0-2]?\d?\d)/,
|
|
2355
|
+
// 0 to 366
|
|
2356
|
+
week: /^(5[0-3]|[0-4]?\d)/,
|
|
2357
|
+
// 0 to 53
|
|
2358
|
+
hour23h: /^(2[0-3]|[0-1]?\d)/,
|
|
2359
|
+
// 0 to 23
|
|
2360
|
+
hour24h: /^(2[0-4]|[0-1]?\d)/,
|
|
2361
|
+
// 0 to 24
|
|
2362
|
+
hour11h: /^(1[0-1]|0?\d)/,
|
|
2363
|
+
// 0 to 11
|
|
2364
|
+
hour12h: /^(1[0-2]|0?\d)/,
|
|
2365
|
+
// 0 to 12
|
|
2366
|
+
minute: /^[0-5]?\d/,
|
|
2367
|
+
// 0 to 59
|
|
2368
|
+
second: /^[0-5]?\d/,
|
|
2369
|
+
// 0 to 59
|
|
2370
|
+
singleDigit: /^\d/,
|
|
2371
|
+
// 0 to 9
|
|
2372
|
+
twoDigits: /^\d{1,2}/,
|
|
2373
|
+
// 0 to 99
|
|
2374
|
+
threeDigits: /^\d{1,3}/,
|
|
2375
|
+
// 0 to 999
|
|
2376
|
+
fourDigits: /^\d{1,4}/,
|
|
2377
|
+
// 0 to 9999
|
|
2378
|
+
anyDigitsSigned: /^-?\d+/,
|
|
2379
|
+
singleDigitSigned: /^-?\d/,
|
|
2380
|
+
// 0 to 9, -0 to -9
|
|
2381
|
+
twoDigitsSigned: /^-?\d{1,2}/,
|
|
2382
|
+
// 0 to 99, -0 to -99
|
|
2383
|
+
threeDigitsSigned: /^-?\d{1,3}/,
|
|
2384
|
+
// 0 to 999, -0 to -999
|
|
2385
|
+
fourDigitsSigned: /^-?\d{1,4}/
|
|
2386
|
+
// 0 to 9999, -0 to -9999
|
|
2387
|
+
};
|
|
2388
|
+
var timezonePatterns = {
|
|
2389
|
+
basicOptionalMinutes: /^([+-])(\d{2})(\d{2})?|Z/,
|
|
2390
|
+
basic: /^([+-])(\d{2})(\d{2})|Z/,
|
|
2391
|
+
basicOptionalSeconds: /^([+-])(\d{2})(\d{2})((\d{2}))?|Z/,
|
|
2392
|
+
extended: /^([+-])(\d{2}):(\d{2})|Z/,
|
|
2393
|
+
extendedOptionalSeconds: /^([+-])(\d{2}):(\d{2})(:(\d{2}))?|Z/
|
|
2394
|
+
};
|
|
2395
|
+
|
|
2396
|
+
// ../../node_modules/date-fns/parse/_lib/utils.mjs
|
|
2397
|
+
function mapValue(parseFnResult, mapFn) {
|
|
2398
|
+
if (!parseFnResult) {
|
|
2399
|
+
return parseFnResult;
|
|
2400
|
+
}
|
|
2401
|
+
return {
|
|
2402
|
+
value: mapFn(parseFnResult.value),
|
|
2403
|
+
rest: parseFnResult.rest
|
|
2404
|
+
};
|
|
2405
|
+
}
|
|
2406
|
+
function parseNumericPattern(pattern, dateString) {
|
|
2407
|
+
const matchResult = dateString.match(pattern);
|
|
2408
|
+
if (!matchResult) {
|
|
2409
|
+
return null;
|
|
2410
|
+
}
|
|
2411
|
+
return {
|
|
2412
|
+
value: parseInt(matchResult[0], 10),
|
|
2413
|
+
rest: dateString.slice(matchResult[0].length)
|
|
2414
|
+
};
|
|
2415
|
+
}
|
|
2416
|
+
function parseTimezonePattern(pattern, dateString) {
|
|
2417
|
+
const matchResult = dateString.match(pattern);
|
|
2418
|
+
if (!matchResult) {
|
|
2419
|
+
return null;
|
|
2420
|
+
}
|
|
2421
|
+
if (matchResult[0] === "Z") {
|
|
2422
|
+
return {
|
|
2423
|
+
value: 0,
|
|
2424
|
+
rest: dateString.slice(1)
|
|
2425
|
+
};
|
|
2426
|
+
}
|
|
2427
|
+
const sign = matchResult[1] === "+" ? 1 : -1;
|
|
2428
|
+
const hours = matchResult[2] ? parseInt(matchResult[2], 10) : 0;
|
|
2429
|
+
const minutes = matchResult[3] ? parseInt(matchResult[3], 10) : 0;
|
|
2430
|
+
const seconds = matchResult[5] ? parseInt(matchResult[5], 10) : 0;
|
|
2431
|
+
return {
|
|
2432
|
+
value: sign * (hours * millisecondsInHour + minutes * millisecondsInMinute + seconds * millisecondsInSecond),
|
|
2433
|
+
rest: dateString.slice(matchResult[0].length)
|
|
2434
|
+
};
|
|
2435
|
+
}
|
|
2436
|
+
function parseAnyDigitsSigned(dateString) {
|
|
2437
|
+
return parseNumericPattern(numericPatterns.anyDigitsSigned, dateString);
|
|
2438
|
+
}
|
|
2439
|
+
function parseNDigits(n, dateString) {
|
|
2440
|
+
switch (n) {
|
|
2441
|
+
case 1:
|
|
2442
|
+
return parseNumericPattern(numericPatterns.singleDigit, dateString);
|
|
2443
|
+
case 2:
|
|
2444
|
+
return parseNumericPattern(numericPatterns.twoDigits, dateString);
|
|
2445
|
+
case 3:
|
|
2446
|
+
return parseNumericPattern(numericPatterns.threeDigits, dateString);
|
|
2447
|
+
case 4:
|
|
2448
|
+
return parseNumericPattern(numericPatterns.fourDigits, dateString);
|
|
2449
|
+
default:
|
|
2450
|
+
return parseNumericPattern(new RegExp("^\\d{1," + n + "}"), dateString);
|
|
2451
|
+
}
|
|
2452
|
+
}
|
|
2453
|
+
function parseNDigitsSigned(n, dateString) {
|
|
2454
|
+
switch (n) {
|
|
2455
|
+
case 1:
|
|
2456
|
+
return parseNumericPattern(numericPatterns.singleDigitSigned, dateString);
|
|
2457
|
+
case 2:
|
|
2458
|
+
return parseNumericPattern(numericPatterns.twoDigitsSigned, dateString);
|
|
2459
|
+
case 3:
|
|
2460
|
+
return parseNumericPattern(numericPatterns.threeDigitsSigned, dateString);
|
|
2461
|
+
case 4:
|
|
2462
|
+
return parseNumericPattern(numericPatterns.fourDigitsSigned, dateString);
|
|
2463
|
+
default:
|
|
2464
|
+
return parseNumericPattern(new RegExp("^-?\\d{1," + n + "}"), dateString);
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
function dayPeriodEnumToHours(dayPeriod) {
|
|
2468
|
+
switch (dayPeriod) {
|
|
2469
|
+
case "morning":
|
|
2470
|
+
return 4;
|
|
2471
|
+
case "evening":
|
|
2472
|
+
return 17;
|
|
2473
|
+
case "pm":
|
|
2474
|
+
case "noon":
|
|
2475
|
+
case "afternoon":
|
|
2476
|
+
return 12;
|
|
2477
|
+
case "am":
|
|
2478
|
+
case "midnight":
|
|
2479
|
+
case "night":
|
|
2480
|
+
default:
|
|
2481
|
+
return 0;
|
|
2482
|
+
}
|
|
2483
|
+
}
|
|
2484
|
+
function normalizeTwoDigitYear(twoDigitYear, currentYear) {
|
|
2485
|
+
const isCommonEra = currentYear > 0;
|
|
2486
|
+
const absCurrentYear = isCommonEra ? currentYear : 1 - currentYear;
|
|
2487
|
+
let result;
|
|
2488
|
+
if (absCurrentYear <= 50) {
|
|
2489
|
+
result = twoDigitYear || 100;
|
|
2490
|
+
} else {
|
|
2491
|
+
const rangeEnd = absCurrentYear + 50;
|
|
2492
|
+
const rangeEndCentury = Math.trunc(rangeEnd / 100) * 100;
|
|
2493
|
+
const isPreviousCentury = twoDigitYear >= rangeEnd % 100;
|
|
2494
|
+
result = twoDigitYear + rangeEndCentury - (isPreviousCentury ? 100 : 0);
|
|
2495
|
+
}
|
|
2496
|
+
return isCommonEra ? result : 1 - result;
|
|
2497
|
+
}
|
|
2498
|
+
function isLeapYearIndex(year) {
|
|
2499
|
+
return year % 400 === 0 || year % 4 === 0 && year % 100 !== 0;
|
|
2500
|
+
}
|
|
2501
|
+
|
|
2502
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/YearParser.mjs
|
|
2503
|
+
var YearParser = class extends Parser {
|
|
2504
|
+
constructor() {
|
|
2505
|
+
super(...arguments);
|
|
2506
|
+
__publicField(this, "priority", 130);
|
|
2507
|
+
__publicField(this, "incompatibleTokens", ["Y", "R", "u", "w", "I", "i", "e", "c", "t", "T"]);
|
|
2508
|
+
}
|
|
2509
|
+
parse(dateString, token, match2) {
|
|
2510
|
+
const valueCallback = (year) => ({
|
|
2511
|
+
year,
|
|
2512
|
+
isTwoDigitYear: token === "yy"
|
|
2513
|
+
});
|
|
2514
|
+
switch (token) {
|
|
2515
|
+
case "y":
|
|
2516
|
+
return mapValue(parseNDigits(4, dateString), valueCallback);
|
|
2517
|
+
case "yo":
|
|
2518
|
+
return mapValue(
|
|
2519
|
+
match2.ordinalNumber(dateString, {
|
|
2520
|
+
unit: "year"
|
|
2521
|
+
}),
|
|
2522
|
+
valueCallback
|
|
2523
|
+
);
|
|
2524
|
+
default:
|
|
2525
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
2526
|
+
}
|
|
2527
|
+
}
|
|
2528
|
+
validate(_date, value) {
|
|
2529
|
+
return value.isTwoDigitYear || value.year > 0;
|
|
2530
|
+
}
|
|
2531
|
+
set(date, flags, value) {
|
|
2532
|
+
const currentYear = date.getFullYear();
|
|
2533
|
+
if (value.isTwoDigitYear) {
|
|
2534
|
+
const normalizedTwoDigitYear = normalizeTwoDigitYear(
|
|
2535
|
+
value.year,
|
|
2536
|
+
currentYear
|
|
2537
|
+
);
|
|
2538
|
+
date.setFullYear(normalizedTwoDigitYear, 0, 1);
|
|
2539
|
+
date.setHours(0, 0, 0, 0);
|
|
2540
|
+
return date;
|
|
2541
|
+
}
|
|
2542
|
+
const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
|
|
2543
|
+
date.setFullYear(year, 0, 1);
|
|
2544
|
+
date.setHours(0, 0, 0, 0);
|
|
2545
|
+
return date;
|
|
2546
|
+
}
|
|
2547
|
+
};
|
|
2548
|
+
|
|
2549
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/LocalWeekYearParser.mjs
|
|
2550
|
+
var LocalWeekYearParser = class extends Parser {
|
|
2551
|
+
constructor() {
|
|
2552
|
+
super(...arguments);
|
|
2553
|
+
__publicField(this, "priority", 130);
|
|
2554
|
+
__publicField(this, "incompatibleTokens", [
|
|
2555
|
+
"y",
|
|
2556
|
+
"R",
|
|
2557
|
+
"u",
|
|
2558
|
+
"Q",
|
|
2559
|
+
"q",
|
|
2560
|
+
"M",
|
|
2561
|
+
"L",
|
|
2562
|
+
"I",
|
|
2563
|
+
"d",
|
|
2564
|
+
"D",
|
|
2565
|
+
"i",
|
|
2566
|
+
"t",
|
|
2567
|
+
"T"
|
|
2568
|
+
]);
|
|
2569
|
+
}
|
|
2570
|
+
parse(dateString, token, match2) {
|
|
2571
|
+
const valueCallback = (year) => ({
|
|
2572
|
+
year,
|
|
2573
|
+
isTwoDigitYear: token === "YY"
|
|
2574
|
+
});
|
|
2575
|
+
switch (token) {
|
|
2576
|
+
case "Y":
|
|
2577
|
+
return mapValue(parseNDigits(4, dateString), valueCallback);
|
|
2578
|
+
case "Yo":
|
|
2579
|
+
return mapValue(
|
|
2580
|
+
match2.ordinalNumber(dateString, {
|
|
2581
|
+
unit: "year"
|
|
2582
|
+
}),
|
|
2583
|
+
valueCallback
|
|
2584
|
+
);
|
|
2585
|
+
default:
|
|
2586
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
validate(_date, value) {
|
|
2590
|
+
return value.isTwoDigitYear || value.year > 0;
|
|
2591
|
+
}
|
|
2592
|
+
set(date, flags, value, options) {
|
|
2593
|
+
const currentYear = getWeekYear(date, options);
|
|
2594
|
+
if (value.isTwoDigitYear) {
|
|
2595
|
+
const normalizedTwoDigitYear = normalizeTwoDigitYear(
|
|
2596
|
+
value.year,
|
|
2597
|
+
currentYear
|
|
2598
|
+
);
|
|
2599
|
+
date.setFullYear(
|
|
2600
|
+
normalizedTwoDigitYear,
|
|
2601
|
+
0,
|
|
2602
|
+
options.firstWeekContainsDate
|
|
2603
|
+
);
|
|
2604
|
+
date.setHours(0, 0, 0, 0);
|
|
2605
|
+
return startOfWeek(date, options);
|
|
2606
|
+
}
|
|
2607
|
+
const year = !("era" in flags) || flags.era === 1 ? value.year : 1 - value.year;
|
|
2608
|
+
date.setFullYear(year, 0, options.firstWeekContainsDate);
|
|
2609
|
+
date.setHours(0, 0, 0, 0);
|
|
2610
|
+
return startOfWeek(date, options);
|
|
2611
|
+
}
|
|
2612
|
+
};
|
|
2613
|
+
|
|
2614
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/ISOWeekYearParser.mjs
|
|
2615
|
+
var ISOWeekYearParser = class extends Parser {
|
|
2616
|
+
constructor() {
|
|
2617
|
+
super(...arguments);
|
|
2618
|
+
__publicField(this, "priority", 130);
|
|
2619
|
+
__publicField(this, "incompatibleTokens", [
|
|
2620
|
+
"G",
|
|
2621
|
+
"y",
|
|
2622
|
+
"Y",
|
|
2623
|
+
"u",
|
|
2624
|
+
"Q",
|
|
2625
|
+
"q",
|
|
2626
|
+
"M",
|
|
2627
|
+
"L",
|
|
2628
|
+
"w",
|
|
2629
|
+
"d",
|
|
2630
|
+
"D",
|
|
2631
|
+
"e",
|
|
2632
|
+
"c",
|
|
2633
|
+
"t",
|
|
2634
|
+
"T"
|
|
2635
|
+
]);
|
|
2636
|
+
}
|
|
2637
|
+
parse(dateString, token) {
|
|
2638
|
+
if (token === "R") {
|
|
2639
|
+
return parseNDigitsSigned(4, dateString);
|
|
2640
|
+
}
|
|
2641
|
+
return parseNDigitsSigned(token.length, dateString);
|
|
2642
|
+
}
|
|
2643
|
+
set(date, _flags, value) {
|
|
2644
|
+
const firstWeekOfYear = constructFrom(date, 0);
|
|
2645
|
+
firstWeekOfYear.setFullYear(value, 0, 4);
|
|
2646
|
+
firstWeekOfYear.setHours(0, 0, 0, 0);
|
|
2647
|
+
return startOfISOWeek(firstWeekOfYear);
|
|
2648
|
+
}
|
|
2649
|
+
};
|
|
2650
|
+
|
|
2651
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/ExtendedYearParser.mjs
|
|
2652
|
+
var ExtendedYearParser = class extends Parser {
|
|
2653
|
+
constructor() {
|
|
2654
|
+
super(...arguments);
|
|
2655
|
+
__publicField(this, "priority", 130);
|
|
2656
|
+
__publicField(this, "incompatibleTokens", ["G", "y", "Y", "R", "w", "I", "i", "e", "c", "t", "T"]);
|
|
2657
|
+
}
|
|
2658
|
+
parse(dateString, token) {
|
|
2659
|
+
if (token === "u") {
|
|
2660
|
+
return parseNDigitsSigned(4, dateString);
|
|
2661
|
+
}
|
|
2662
|
+
return parseNDigitsSigned(token.length, dateString);
|
|
2663
|
+
}
|
|
2664
|
+
set(date, _flags, value) {
|
|
2665
|
+
date.setFullYear(value, 0, 1);
|
|
2666
|
+
date.setHours(0, 0, 0, 0);
|
|
2667
|
+
return date;
|
|
2668
|
+
}
|
|
2669
|
+
};
|
|
2670
|
+
|
|
2671
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/QuarterParser.mjs
|
|
2672
|
+
var QuarterParser = class extends Parser {
|
|
2673
|
+
constructor() {
|
|
2674
|
+
super(...arguments);
|
|
2675
|
+
__publicField(this, "priority", 120);
|
|
2676
|
+
__publicField(this, "incompatibleTokens", [
|
|
2677
|
+
"Y",
|
|
2678
|
+
"R",
|
|
2679
|
+
"q",
|
|
2680
|
+
"M",
|
|
2681
|
+
"L",
|
|
2682
|
+
"w",
|
|
2683
|
+
"I",
|
|
2684
|
+
"d",
|
|
2685
|
+
"D",
|
|
2686
|
+
"i",
|
|
2687
|
+
"e",
|
|
2688
|
+
"c",
|
|
2689
|
+
"t",
|
|
2690
|
+
"T"
|
|
2691
|
+
]);
|
|
2692
|
+
}
|
|
2693
|
+
parse(dateString, token, match2) {
|
|
2694
|
+
switch (token) {
|
|
2695
|
+
// 1, 2, 3, 4
|
|
2696
|
+
case "Q":
|
|
2697
|
+
case "QQ":
|
|
2698
|
+
return parseNDigits(token.length, dateString);
|
|
2699
|
+
// 1st, 2nd, 3rd, 4th
|
|
2700
|
+
case "Qo":
|
|
2701
|
+
return match2.ordinalNumber(dateString, { unit: "quarter" });
|
|
2702
|
+
// Q1, Q2, Q3, Q4
|
|
2703
|
+
case "QQQ":
|
|
2704
|
+
return match2.quarter(dateString, {
|
|
2705
|
+
width: "abbreviated",
|
|
2706
|
+
context: "formatting"
|
|
2707
|
+
}) || match2.quarter(dateString, {
|
|
2708
|
+
width: "narrow",
|
|
2709
|
+
context: "formatting"
|
|
2710
|
+
});
|
|
2711
|
+
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
2712
|
+
case "QQQQQ":
|
|
2713
|
+
return match2.quarter(dateString, {
|
|
2714
|
+
width: "narrow",
|
|
2715
|
+
context: "formatting"
|
|
2716
|
+
});
|
|
2717
|
+
// 1st quarter, 2nd quarter, ...
|
|
2718
|
+
case "QQQQ":
|
|
2719
|
+
default:
|
|
2720
|
+
return match2.quarter(dateString, {
|
|
2721
|
+
width: "wide",
|
|
2722
|
+
context: "formatting"
|
|
2723
|
+
}) || match2.quarter(dateString, {
|
|
2724
|
+
width: "abbreviated",
|
|
2725
|
+
context: "formatting"
|
|
2726
|
+
}) || match2.quarter(dateString, {
|
|
2727
|
+
width: "narrow",
|
|
2728
|
+
context: "formatting"
|
|
2729
|
+
});
|
|
2730
|
+
}
|
|
2731
|
+
}
|
|
2732
|
+
validate(_date, value) {
|
|
2733
|
+
return value >= 1 && value <= 4;
|
|
2734
|
+
}
|
|
2735
|
+
set(date, _flags, value) {
|
|
2736
|
+
date.setMonth((value - 1) * 3, 1);
|
|
2737
|
+
date.setHours(0, 0, 0, 0);
|
|
2738
|
+
return date;
|
|
2739
|
+
}
|
|
2740
|
+
};
|
|
2741
|
+
|
|
2742
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/StandAloneQuarterParser.mjs
|
|
2743
|
+
var StandAloneQuarterParser = class extends Parser {
|
|
2744
|
+
constructor() {
|
|
2745
|
+
super(...arguments);
|
|
2746
|
+
__publicField(this, "priority", 120);
|
|
2747
|
+
__publicField(this, "incompatibleTokens", [
|
|
2748
|
+
"Y",
|
|
2749
|
+
"R",
|
|
2750
|
+
"Q",
|
|
2751
|
+
"M",
|
|
2752
|
+
"L",
|
|
2753
|
+
"w",
|
|
2754
|
+
"I",
|
|
2755
|
+
"d",
|
|
2756
|
+
"D",
|
|
2757
|
+
"i",
|
|
2758
|
+
"e",
|
|
2759
|
+
"c",
|
|
2760
|
+
"t",
|
|
2761
|
+
"T"
|
|
2762
|
+
]);
|
|
2763
|
+
}
|
|
2764
|
+
parse(dateString, token, match2) {
|
|
2765
|
+
switch (token) {
|
|
2766
|
+
// 1, 2, 3, 4
|
|
2767
|
+
case "q":
|
|
2768
|
+
case "qq":
|
|
2769
|
+
return parseNDigits(token.length, dateString);
|
|
2770
|
+
// 1st, 2nd, 3rd, 4th
|
|
2771
|
+
case "qo":
|
|
2772
|
+
return match2.ordinalNumber(dateString, { unit: "quarter" });
|
|
2773
|
+
// Q1, Q2, Q3, Q4
|
|
2774
|
+
case "qqq":
|
|
2775
|
+
return match2.quarter(dateString, {
|
|
2776
|
+
width: "abbreviated",
|
|
2777
|
+
context: "standalone"
|
|
2778
|
+
}) || match2.quarter(dateString, {
|
|
2779
|
+
width: "narrow",
|
|
2780
|
+
context: "standalone"
|
|
2781
|
+
});
|
|
2782
|
+
// 1, 2, 3, 4 (narrow quarter; could be not numerical)
|
|
2783
|
+
case "qqqqq":
|
|
2784
|
+
return match2.quarter(dateString, {
|
|
2785
|
+
width: "narrow",
|
|
2786
|
+
context: "standalone"
|
|
2787
|
+
});
|
|
2788
|
+
// 1st quarter, 2nd quarter, ...
|
|
2789
|
+
case "qqqq":
|
|
2790
|
+
default:
|
|
2791
|
+
return match2.quarter(dateString, {
|
|
2792
|
+
width: "wide",
|
|
2793
|
+
context: "standalone"
|
|
2794
|
+
}) || match2.quarter(dateString, {
|
|
2795
|
+
width: "abbreviated",
|
|
2796
|
+
context: "standalone"
|
|
2797
|
+
}) || match2.quarter(dateString, {
|
|
2798
|
+
width: "narrow",
|
|
2799
|
+
context: "standalone"
|
|
2800
|
+
});
|
|
2801
|
+
}
|
|
2802
|
+
}
|
|
2803
|
+
validate(_date, value) {
|
|
2804
|
+
return value >= 1 && value <= 4;
|
|
2805
|
+
}
|
|
2806
|
+
set(date, _flags, value) {
|
|
2807
|
+
date.setMonth((value - 1) * 3, 1);
|
|
2808
|
+
date.setHours(0, 0, 0, 0);
|
|
2809
|
+
return date;
|
|
2810
|
+
}
|
|
2811
|
+
};
|
|
2812
|
+
|
|
2813
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/MonthParser.mjs
|
|
2814
|
+
var MonthParser = class extends Parser {
|
|
2815
|
+
constructor() {
|
|
2816
|
+
super(...arguments);
|
|
2817
|
+
__publicField(this, "incompatibleTokens", [
|
|
2818
|
+
"Y",
|
|
2819
|
+
"R",
|
|
2820
|
+
"q",
|
|
2821
|
+
"Q",
|
|
2822
|
+
"L",
|
|
2823
|
+
"w",
|
|
2824
|
+
"I",
|
|
2825
|
+
"D",
|
|
2826
|
+
"i",
|
|
2827
|
+
"e",
|
|
2828
|
+
"c",
|
|
2829
|
+
"t",
|
|
2830
|
+
"T"
|
|
2831
|
+
]);
|
|
2832
|
+
__publicField(this, "priority", 110);
|
|
2833
|
+
}
|
|
2834
|
+
parse(dateString, token, match2) {
|
|
2835
|
+
const valueCallback = (value) => value - 1;
|
|
2836
|
+
switch (token) {
|
|
2837
|
+
// 1, 2, ..., 12
|
|
2838
|
+
case "M":
|
|
2839
|
+
return mapValue(
|
|
2840
|
+
parseNumericPattern(numericPatterns.month, dateString),
|
|
2841
|
+
valueCallback
|
|
2842
|
+
);
|
|
2843
|
+
// 01, 02, ..., 12
|
|
2844
|
+
case "MM":
|
|
2845
|
+
return mapValue(parseNDigits(2, dateString), valueCallback);
|
|
2846
|
+
// 1st, 2nd, ..., 12th
|
|
2847
|
+
case "Mo":
|
|
2848
|
+
return mapValue(
|
|
2849
|
+
match2.ordinalNumber(dateString, {
|
|
2850
|
+
unit: "month"
|
|
2851
|
+
}),
|
|
2852
|
+
valueCallback
|
|
2853
|
+
);
|
|
2854
|
+
// Jan, Feb, ..., Dec
|
|
2855
|
+
case "MMM":
|
|
2856
|
+
return match2.month(dateString, {
|
|
2857
|
+
width: "abbreviated",
|
|
2858
|
+
context: "formatting"
|
|
2859
|
+
}) || match2.month(dateString, { width: "narrow", context: "formatting" });
|
|
2860
|
+
// J, F, ..., D
|
|
2861
|
+
case "MMMMM":
|
|
2862
|
+
return match2.month(dateString, {
|
|
2863
|
+
width: "narrow",
|
|
2864
|
+
context: "formatting"
|
|
2865
|
+
});
|
|
2866
|
+
// January, February, ..., December
|
|
2867
|
+
case "MMMM":
|
|
2868
|
+
default:
|
|
2869
|
+
return match2.month(dateString, { width: "wide", context: "formatting" }) || match2.month(dateString, {
|
|
2870
|
+
width: "abbreviated",
|
|
2871
|
+
context: "formatting"
|
|
2872
|
+
}) || match2.month(dateString, { width: "narrow", context: "formatting" });
|
|
2873
|
+
}
|
|
2874
|
+
}
|
|
2875
|
+
validate(_date, value) {
|
|
2876
|
+
return value >= 0 && value <= 11;
|
|
2877
|
+
}
|
|
2878
|
+
set(date, _flags, value) {
|
|
2879
|
+
date.setMonth(value, 1);
|
|
2880
|
+
date.setHours(0, 0, 0, 0);
|
|
2881
|
+
return date;
|
|
2882
|
+
}
|
|
2883
|
+
};
|
|
2884
|
+
|
|
2885
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/StandAloneMonthParser.mjs
|
|
2886
|
+
var StandAloneMonthParser = class extends Parser {
|
|
2887
|
+
constructor() {
|
|
2888
|
+
super(...arguments);
|
|
2889
|
+
__publicField(this, "priority", 110);
|
|
2890
|
+
__publicField(this, "incompatibleTokens", [
|
|
2891
|
+
"Y",
|
|
2892
|
+
"R",
|
|
2893
|
+
"q",
|
|
2894
|
+
"Q",
|
|
2895
|
+
"M",
|
|
2896
|
+
"w",
|
|
2897
|
+
"I",
|
|
2898
|
+
"D",
|
|
2899
|
+
"i",
|
|
2900
|
+
"e",
|
|
2901
|
+
"c",
|
|
2902
|
+
"t",
|
|
2903
|
+
"T"
|
|
2904
|
+
]);
|
|
2905
|
+
}
|
|
2906
|
+
parse(dateString, token, match2) {
|
|
2907
|
+
const valueCallback = (value) => value - 1;
|
|
2908
|
+
switch (token) {
|
|
2909
|
+
// 1, 2, ..., 12
|
|
2910
|
+
case "L":
|
|
2911
|
+
return mapValue(
|
|
2912
|
+
parseNumericPattern(numericPatterns.month, dateString),
|
|
2913
|
+
valueCallback
|
|
2914
|
+
);
|
|
2915
|
+
// 01, 02, ..., 12
|
|
2916
|
+
case "LL":
|
|
2917
|
+
return mapValue(parseNDigits(2, dateString), valueCallback);
|
|
2918
|
+
// 1st, 2nd, ..., 12th
|
|
2919
|
+
case "Lo":
|
|
2920
|
+
return mapValue(
|
|
2921
|
+
match2.ordinalNumber(dateString, {
|
|
2922
|
+
unit: "month"
|
|
2923
|
+
}),
|
|
2924
|
+
valueCallback
|
|
2925
|
+
);
|
|
2926
|
+
// Jan, Feb, ..., Dec
|
|
2927
|
+
case "LLL":
|
|
2928
|
+
return match2.month(dateString, {
|
|
2929
|
+
width: "abbreviated",
|
|
2930
|
+
context: "standalone"
|
|
2931
|
+
}) || match2.month(dateString, { width: "narrow", context: "standalone" });
|
|
2932
|
+
// J, F, ..., D
|
|
2933
|
+
case "LLLLL":
|
|
2934
|
+
return match2.month(dateString, {
|
|
2935
|
+
width: "narrow",
|
|
2936
|
+
context: "standalone"
|
|
2937
|
+
});
|
|
2938
|
+
// January, February, ..., December
|
|
2939
|
+
case "LLLL":
|
|
2940
|
+
default:
|
|
2941
|
+
return match2.month(dateString, { width: "wide", context: "standalone" }) || match2.month(dateString, {
|
|
2942
|
+
width: "abbreviated",
|
|
2943
|
+
context: "standalone"
|
|
2944
|
+
}) || match2.month(dateString, { width: "narrow", context: "standalone" });
|
|
2945
|
+
}
|
|
2946
|
+
}
|
|
2947
|
+
validate(_date, value) {
|
|
2948
|
+
return value >= 0 && value <= 11;
|
|
2949
|
+
}
|
|
2950
|
+
set(date, _flags, value) {
|
|
2951
|
+
date.setMonth(value, 1);
|
|
2952
|
+
date.setHours(0, 0, 0, 0);
|
|
2953
|
+
return date;
|
|
2954
|
+
}
|
|
2955
|
+
};
|
|
2956
|
+
|
|
2957
|
+
// ../../node_modules/date-fns/setWeek.mjs
|
|
2958
|
+
function setWeek(date, week, options) {
|
|
2959
|
+
const _date = toDate(date);
|
|
2960
|
+
const diff = getWeek(_date, options) - week;
|
|
2961
|
+
_date.setDate(_date.getDate() - diff * 7);
|
|
2962
|
+
return _date;
|
|
2963
|
+
}
|
|
2964
|
+
|
|
2965
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/LocalWeekParser.mjs
|
|
2966
|
+
var LocalWeekParser = class extends Parser {
|
|
2967
|
+
constructor() {
|
|
2968
|
+
super(...arguments);
|
|
2969
|
+
__publicField(this, "priority", 100);
|
|
2970
|
+
__publicField(this, "incompatibleTokens", [
|
|
2971
|
+
"y",
|
|
2972
|
+
"R",
|
|
2973
|
+
"u",
|
|
2974
|
+
"q",
|
|
2975
|
+
"Q",
|
|
2976
|
+
"M",
|
|
2977
|
+
"L",
|
|
2978
|
+
"I",
|
|
2979
|
+
"d",
|
|
2980
|
+
"D",
|
|
2981
|
+
"i",
|
|
2982
|
+
"t",
|
|
2983
|
+
"T"
|
|
2984
|
+
]);
|
|
2985
|
+
}
|
|
2986
|
+
parse(dateString, token, match2) {
|
|
2987
|
+
switch (token) {
|
|
2988
|
+
case "w":
|
|
2989
|
+
return parseNumericPattern(numericPatterns.week, dateString);
|
|
2990
|
+
case "wo":
|
|
2991
|
+
return match2.ordinalNumber(dateString, { unit: "week" });
|
|
2992
|
+
default:
|
|
2993
|
+
return parseNDigits(token.length, dateString);
|
|
2994
|
+
}
|
|
2995
|
+
}
|
|
2996
|
+
validate(_date, value) {
|
|
2997
|
+
return value >= 1 && value <= 53;
|
|
2998
|
+
}
|
|
2999
|
+
set(date, _flags, value, options) {
|
|
3000
|
+
return startOfWeek(setWeek(date, value, options), options);
|
|
3001
|
+
}
|
|
3002
|
+
};
|
|
3003
|
+
|
|
3004
|
+
// ../../node_modules/date-fns/setISOWeek.mjs
|
|
3005
|
+
function setISOWeek(date, week) {
|
|
3006
|
+
const _date = toDate(date);
|
|
3007
|
+
const diff = getISOWeek(_date) - week;
|
|
3008
|
+
_date.setDate(_date.getDate() - diff * 7);
|
|
3009
|
+
return _date;
|
|
3010
|
+
}
|
|
3011
|
+
|
|
3012
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/ISOWeekParser.mjs
|
|
3013
|
+
var ISOWeekParser = class extends Parser {
|
|
3014
|
+
constructor() {
|
|
3015
|
+
super(...arguments);
|
|
3016
|
+
__publicField(this, "priority", 100);
|
|
3017
|
+
__publicField(this, "incompatibleTokens", [
|
|
3018
|
+
"y",
|
|
3019
|
+
"Y",
|
|
3020
|
+
"u",
|
|
3021
|
+
"q",
|
|
3022
|
+
"Q",
|
|
3023
|
+
"M",
|
|
3024
|
+
"L",
|
|
3025
|
+
"w",
|
|
3026
|
+
"d",
|
|
3027
|
+
"D",
|
|
3028
|
+
"e",
|
|
3029
|
+
"c",
|
|
3030
|
+
"t",
|
|
3031
|
+
"T"
|
|
3032
|
+
]);
|
|
3033
|
+
}
|
|
3034
|
+
parse(dateString, token, match2) {
|
|
3035
|
+
switch (token) {
|
|
3036
|
+
case "I":
|
|
3037
|
+
return parseNumericPattern(numericPatterns.week, dateString);
|
|
3038
|
+
case "Io":
|
|
3039
|
+
return match2.ordinalNumber(dateString, { unit: "week" });
|
|
3040
|
+
default:
|
|
3041
|
+
return parseNDigits(token.length, dateString);
|
|
3042
|
+
}
|
|
3043
|
+
}
|
|
3044
|
+
validate(_date, value) {
|
|
3045
|
+
return value >= 1 && value <= 53;
|
|
3046
|
+
}
|
|
3047
|
+
set(date, _flags, value) {
|
|
3048
|
+
return startOfISOWeek(setISOWeek(date, value));
|
|
3049
|
+
}
|
|
3050
|
+
};
|
|
3051
|
+
|
|
3052
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/DateParser.mjs
|
|
3053
|
+
var DAYS_IN_MONTH = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
3054
|
+
var DAYS_IN_MONTH_LEAP_YEAR = [
|
|
3055
|
+
31,
|
|
3056
|
+
29,
|
|
3057
|
+
31,
|
|
3058
|
+
30,
|
|
3059
|
+
31,
|
|
3060
|
+
30,
|
|
3061
|
+
31,
|
|
3062
|
+
31,
|
|
3063
|
+
30,
|
|
3064
|
+
31,
|
|
3065
|
+
30,
|
|
3066
|
+
31
|
|
3067
|
+
];
|
|
3068
|
+
var DateParser = class extends Parser {
|
|
3069
|
+
constructor() {
|
|
3070
|
+
super(...arguments);
|
|
3071
|
+
__publicField(this, "priority", 90);
|
|
3072
|
+
__publicField(this, "subPriority", 1);
|
|
3073
|
+
__publicField(this, "incompatibleTokens", [
|
|
3074
|
+
"Y",
|
|
3075
|
+
"R",
|
|
3076
|
+
"q",
|
|
3077
|
+
"Q",
|
|
3078
|
+
"w",
|
|
3079
|
+
"I",
|
|
3080
|
+
"D",
|
|
3081
|
+
"i",
|
|
3082
|
+
"e",
|
|
3083
|
+
"c",
|
|
3084
|
+
"t",
|
|
3085
|
+
"T"
|
|
3086
|
+
]);
|
|
3087
|
+
}
|
|
3088
|
+
parse(dateString, token, match2) {
|
|
3089
|
+
switch (token) {
|
|
3090
|
+
case "d":
|
|
3091
|
+
return parseNumericPattern(numericPatterns.date, dateString);
|
|
3092
|
+
case "do":
|
|
3093
|
+
return match2.ordinalNumber(dateString, { unit: "date" });
|
|
3094
|
+
default:
|
|
3095
|
+
return parseNDigits(token.length, dateString);
|
|
3096
|
+
}
|
|
3097
|
+
}
|
|
3098
|
+
validate(date, value) {
|
|
3099
|
+
const year = date.getFullYear();
|
|
3100
|
+
const isLeapYear = isLeapYearIndex(year);
|
|
3101
|
+
const month = date.getMonth();
|
|
3102
|
+
if (isLeapYear) {
|
|
3103
|
+
return value >= 1 && value <= DAYS_IN_MONTH_LEAP_YEAR[month];
|
|
3104
|
+
} else {
|
|
3105
|
+
return value >= 1 && value <= DAYS_IN_MONTH[month];
|
|
3106
|
+
}
|
|
3107
|
+
}
|
|
3108
|
+
set(date, _flags, value) {
|
|
3109
|
+
date.setDate(value);
|
|
3110
|
+
date.setHours(0, 0, 0, 0);
|
|
3111
|
+
return date;
|
|
3112
|
+
}
|
|
3113
|
+
};
|
|
3114
|
+
|
|
3115
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/DayOfYearParser.mjs
|
|
3116
|
+
var DayOfYearParser = class extends Parser {
|
|
3117
|
+
constructor() {
|
|
3118
|
+
super(...arguments);
|
|
3119
|
+
__publicField(this, "priority", 90);
|
|
3120
|
+
__publicField(this, "subpriority", 1);
|
|
3121
|
+
__publicField(this, "incompatibleTokens", [
|
|
3122
|
+
"Y",
|
|
3123
|
+
"R",
|
|
3124
|
+
"q",
|
|
3125
|
+
"Q",
|
|
3126
|
+
"M",
|
|
3127
|
+
"L",
|
|
3128
|
+
"w",
|
|
3129
|
+
"I",
|
|
3130
|
+
"d",
|
|
3131
|
+
"E",
|
|
3132
|
+
"i",
|
|
3133
|
+
"e",
|
|
3134
|
+
"c",
|
|
3135
|
+
"t",
|
|
3136
|
+
"T"
|
|
3137
|
+
]);
|
|
3138
|
+
}
|
|
3139
|
+
parse(dateString, token, match2) {
|
|
3140
|
+
switch (token) {
|
|
3141
|
+
case "D":
|
|
3142
|
+
case "DD":
|
|
3143
|
+
return parseNumericPattern(numericPatterns.dayOfYear, dateString);
|
|
3144
|
+
case "Do":
|
|
3145
|
+
return match2.ordinalNumber(dateString, { unit: "date" });
|
|
3146
|
+
default:
|
|
3147
|
+
return parseNDigits(token.length, dateString);
|
|
3148
|
+
}
|
|
3149
|
+
}
|
|
3150
|
+
validate(date, value) {
|
|
3151
|
+
const year = date.getFullYear();
|
|
3152
|
+
const isLeapYear = isLeapYearIndex(year);
|
|
3153
|
+
if (isLeapYear) {
|
|
3154
|
+
return value >= 1 && value <= 366;
|
|
3155
|
+
} else {
|
|
3156
|
+
return value >= 1 && value <= 365;
|
|
3157
|
+
}
|
|
3158
|
+
}
|
|
3159
|
+
set(date, _flags, value) {
|
|
3160
|
+
date.setMonth(0, value);
|
|
3161
|
+
date.setHours(0, 0, 0, 0);
|
|
3162
|
+
return date;
|
|
3163
|
+
}
|
|
3164
|
+
};
|
|
3165
|
+
|
|
3166
|
+
// ../../node_modules/date-fns/setDay.mjs
|
|
3167
|
+
function setDay(date, day, options) {
|
|
3168
|
+
const defaultOptions2 = getDefaultOptions();
|
|
3169
|
+
const weekStartsOn = options?.weekStartsOn ?? options?.locale?.options?.weekStartsOn ?? defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
|
|
3170
|
+
const _date = toDate(date);
|
|
3171
|
+
const currentDay = _date.getDay();
|
|
3172
|
+
const remainder = day % 7;
|
|
3173
|
+
const dayIndex = (remainder + 7) % 7;
|
|
3174
|
+
const delta = 7 - weekStartsOn;
|
|
3175
|
+
const diff = day < 0 || day > 6 ? day - (currentDay + delta) % 7 : (dayIndex + delta) % 7 - (currentDay + delta) % 7;
|
|
3176
|
+
return addDays(_date, diff);
|
|
3177
|
+
}
|
|
3178
|
+
|
|
3179
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/DayParser.mjs
|
|
3180
|
+
var DayParser = class extends Parser {
|
|
3181
|
+
constructor() {
|
|
3182
|
+
super(...arguments);
|
|
3183
|
+
__publicField(this, "priority", 90);
|
|
3184
|
+
__publicField(this, "incompatibleTokens", ["D", "i", "e", "c", "t", "T"]);
|
|
3185
|
+
}
|
|
3186
|
+
parse(dateString, token, match2) {
|
|
3187
|
+
switch (token) {
|
|
3188
|
+
// Tue
|
|
3189
|
+
case "E":
|
|
3190
|
+
case "EE":
|
|
3191
|
+
case "EEE":
|
|
3192
|
+
return match2.day(dateString, {
|
|
3193
|
+
width: "abbreviated",
|
|
3194
|
+
context: "formatting"
|
|
3195
|
+
}) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
|
|
3196
|
+
// T
|
|
3197
|
+
case "EEEEE":
|
|
3198
|
+
return match2.day(dateString, {
|
|
3199
|
+
width: "narrow",
|
|
3200
|
+
context: "formatting"
|
|
3201
|
+
});
|
|
3202
|
+
// Tu
|
|
3203
|
+
case "EEEEEE":
|
|
3204
|
+
return match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
|
|
3205
|
+
// Tuesday
|
|
3206
|
+
case "EEEE":
|
|
3207
|
+
default:
|
|
3208
|
+
return match2.day(dateString, { width: "wide", context: "formatting" }) || match2.day(dateString, {
|
|
3209
|
+
width: "abbreviated",
|
|
3210
|
+
context: "formatting"
|
|
3211
|
+
}) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
|
|
3212
|
+
}
|
|
3213
|
+
}
|
|
3214
|
+
validate(_date, value) {
|
|
3215
|
+
return value >= 0 && value <= 6;
|
|
3216
|
+
}
|
|
3217
|
+
set(date, _flags, value, options) {
|
|
3218
|
+
date = setDay(date, value, options);
|
|
3219
|
+
date.setHours(0, 0, 0, 0);
|
|
3220
|
+
return date;
|
|
3221
|
+
}
|
|
3222
|
+
};
|
|
3223
|
+
|
|
3224
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/LocalDayParser.mjs
|
|
3225
|
+
var LocalDayParser = class extends Parser {
|
|
3226
|
+
constructor() {
|
|
3227
|
+
super(...arguments);
|
|
3228
|
+
__publicField(this, "priority", 90);
|
|
3229
|
+
__publicField(this, "incompatibleTokens", [
|
|
3230
|
+
"y",
|
|
3231
|
+
"R",
|
|
3232
|
+
"u",
|
|
3233
|
+
"q",
|
|
3234
|
+
"Q",
|
|
3235
|
+
"M",
|
|
3236
|
+
"L",
|
|
3237
|
+
"I",
|
|
3238
|
+
"d",
|
|
3239
|
+
"D",
|
|
3240
|
+
"E",
|
|
3241
|
+
"i",
|
|
3242
|
+
"c",
|
|
3243
|
+
"t",
|
|
3244
|
+
"T"
|
|
3245
|
+
]);
|
|
3246
|
+
}
|
|
3247
|
+
parse(dateString, token, match2, options) {
|
|
3248
|
+
const valueCallback = (value) => {
|
|
3249
|
+
const wholeWeekDays = Math.floor((value - 1) / 7) * 7;
|
|
3250
|
+
return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
|
|
3251
|
+
};
|
|
3252
|
+
switch (token) {
|
|
3253
|
+
// 3
|
|
3254
|
+
case "e":
|
|
3255
|
+
case "ee":
|
|
3256
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
3257
|
+
// 3rd
|
|
3258
|
+
case "eo":
|
|
3259
|
+
return mapValue(
|
|
3260
|
+
match2.ordinalNumber(dateString, {
|
|
3261
|
+
unit: "day"
|
|
3262
|
+
}),
|
|
3263
|
+
valueCallback
|
|
3264
|
+
);
|
|
3265
|
+
// Tue
|
|
3266
|
+
case "eee":
|
|
3267
|
+
return match2.day(dateString, {
|
|
3268
|
+
width: "abbreviated",
|
|
3269
|
+
context: "formatting"
|
|
3270
|
+
}) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
|
|
3271
|
+
// T
|
|
3272
|
+
case "eeeee":
|
|
3273
|
+
return match2.day(dateString, {
|
|
3274
|
+
width: "narrow",
|
|
3275
|
+
context: "formatting"
|
|
3276
|
+
});
|
|
3277
|
+
// Tu
|
|
3278
|
+
case "eeeeee":
|
|
3279
|
+
return match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
|
|
3280
|
+
// Tuesday
|
|
3281
|
+
case "eeee":
|
|
3282
|
+
default:
|
|
3283
|
+
return match2.day(dateString, { width: "wide", context: "formatting" }) || match2.day(dateString, {
|
|
3284
|
+
width: "abbreviated",
|
|
3285
|
+
context: "formatting"
|
|
3286
|
+
}) || match2.day(dateString, { width: "short", context: "formatting" }) || match2.day(dateString, { width: "narrow", context: "formatting" });
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
validate(_date, value) {
|
|
3290
|
+
return value >= 0 && value <= 6;
|
|
3291
|
+
}
|
|
3292
|
+
set(date, _flags, value, options) {
|
|
3293
|
+
date = setDay(date, value, options);
|
|
3294
|
+
date.setHours(0, 0, 0, 0);
|
|
3295
|
+
return date;
|
|
3296
|
+
}
|
|
3297
|
+
};
|
|
3298
|
+
|
|
3299
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/StandAloneLocalDayParser.mjs
|
|
3300
|
+
var StandAloneLocalDayParser = class extends Parser {
|
|
3301
|
+
constructor() {
|
|
3302
|
+
super(...arguments);
|
|
3303
|
+
__publicField(this, "priority", 90);
|
|
3304
|
+
__publicField(this, "incompatibleTokens", [
|
|
3305
|
+
"y",
|
|
3306
|
+
"R",
|
|
3307
|
+
"u",
|
|
3308
|
+
"q",
|
|
3309
|
+
"Q",
|
|
3310
|
+
"M",
|
|
3311
|
+
"L",
|
|
3312
|
+
"I",
|
|
3313
|
+
"d",
|
|
3314
|
+
"D",
|
|
3315
|
+
"E",
|
|
3316
|
+
"i",
|
|
3317
|
+
"e",
|
|
3318
|
+
"t",
|
|
3319
|
+
"T"
|
|
3320
|
+
]);
|
|
3321
|
+
}
|
|
3322
|
+
parse(dateString, token, match2, options) {
|
|
3323
|
+
const valueCallback = (value) => {
|
|
3324
|
+
const wholeWeekDays = Math.floor((value - 1) / 7) * 7;
|
|
3325
|
+
return (value + options.weekStartsOn + 6) % 7 + wholeWeekDays;
|
|
3326
|
+
};
|
|
3327
|
+
switch (token) {
|
|
3328
|
+
// 3
|
|
3329
|
+
case "c":
|
|
3330
|
+
case "cc":
|
|
3331
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
3332
|
+
// 3rd
|
|
3333
|
+
case "co":
|
|
3334
|
+
return mapValue(
|
|
3335
|
+
match2.ordinalNumber(dateString, {
|
|
3336
|
+
unit: "day"
|
|
3337
|
+
}),
|
|
3338
|
+
valueCallback
|
|
3339
|
+
);
|
|
3340
|
+
// Tue
|
|
3341
|
+
case "ccc":
|
|
3342
|
+
return match2.day(dateString, {
|
|
3343
|
+
width: "abbreviated",
|
|
3344
|
+
context: "standalone"
|
|
3345
|
+
}) || match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
|
|
3346
|
+
// T
|
|
3347
|
+
case "ccccc":
|
|
3348
|
+
return match2.day(dateString, {
|
|
3349
|
+
width: "narrow",
|
|
3350
|
+
context: "standalone"
|
|
3351
|
+
});
|
|
3352
|
+
// Tu
|
|
3353
|
+
case "cccccc":
|
|
3354
|
+
return match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
|
|
3355
|
+
// Tuesday
|
|
3356
|
+
case "cccc":
|
|
3357
|
+
default:
|
|
3358
|
+
return match2.day(dateString, { width: "wide", context: "standalone" }) || match2.day(dateString, {
|
|
3359
|
+
width: "abbreviated",
|
|
3360
|
+
context: "standalone"
|
|
3361
|
+
}) || match2.day(dateString, { width: "short", context: "standalone" }) || match2.day(dateString, { width: "narrow", context: "standalone" });
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
validate(_date, value) {
|
|
3365
|
+
return value >= 0 && value <= 6;
|
|
3366
|
+
}
|
|
3367
|
+
set(date, _flags, value, options) {
|
|
3368
|
+
date = setDay(date, value, options);
|
|
3369
|
+
date.setHours(0, 0, 0, 0);
|
|
3370
|
+
return date;
|
|
3371
|
+
}
|
|
3372
|
+
};
|
|
3373
|
+
|
|
3374
|
+
// ../../node_modules/date-fns/setISODay.mjs
|
|
3375
|
+
function setISODay(date, day) {
|
|
3376
|
+
const _date = toDate(date);
|
|
3377
|
+
const currentDay = getISODay(_date);
|
|
3378
|
+
const diff = day - currentDay;
|
|
3379
|
+
return addDays(_date, diff);
|
|
3380
|
+
}
|
|
3381
|
+
|
|
3382
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/ISODayParser.mjs
|
|
3383
|
+
var ISODayParser = class extends Parser {
|
|
3384
|
+
constructor() {
|
|
3385
|
+
super(...arguments);
|
|
3386
|
+
__publicField(this, "priority", 90);
|
|
3387
|
+
__publicField(this, "incompatibleTokens", [
|
|
3388
|
+
"y",
|
|
3389
|
+
"Y",
|
|
3390
|
+
"u",
|
|
3391
|
+
"q",
|
|
3392
|
+
"Q",
|
|
3393
|
+
"M",
|
|
3394
|
+
"L",
|
|
3395
|
+
"w",
|
|
3396
|
+
"d",
|
|
3397
|
+
"D",
|
|
3398
|
+
"E",
|
|
3399
|
+
"e",
|
|
3400
|
+
"c",
|
|
3401
|
+
"t",
|
|
3402
|
+
"T"
|
|
3403
|
+
]);
|
|
3404
|
+
}
|
|
3405
|
+
parse(dateString, token, match2) {
|
|
3406
|
+
const valueCallback = (value) => {
|
|
3407
|
+
if (value === 0) {
|
|
3408
|
+
return 7;
|
|
3409
|
+
}
|
|
3410
|
+
return value;
|
|
3411
|
+
};
|
|
3412
|
+
switch (token) {
|
|
3413
|
+
// 2
|
|
3414
|
+
case "i":
|
|
3415
|
+
case "ii":
|
|
3416
|
+
return parseNDigits(token.length, dateString);
|
|
3417
|
+
// 2nd
|
|
3418
|
+
case "io":
|
|
3419
|
+
return match2.ordinalNumber(dateString, { unit: "day" });
|
|
3420
|
+
// Tue
|
|
3421
|
+
case "iii":
|
|
3422
|
+
return mapValue(
|
|
3423
|
+
match2.day(dateString, {
|
|
3424
|
+
width: "abbreviated",
|
|
3425
|
+
context: "formatting"
|
|
3426
|
+
}) || match2.day(dateString, {
|
|
3427
|
+
width: "short",
|
|
3428
|
+
context: "formatting"
|
|
3429
|
+
}) || match2.day(dateString, {
|
|
3430
|
+
width: "narrow",
|
|
3431
|
+
context: "formatting"
|
|
3432
|
+
}),
|
|
3433
|
+
valueCallback
|
|
3434
|
+
);
|
|
3435
|
+
// T
|
|
3436
|
+
case "iiiii":
|
|
3437
|
+
return mapValue(
|
|
3438
|
+
match2.day(dateString, {
|
|
3439
|
+
width: "narrow",
|
|
3440
|
+
context: "formatting"
|
|
3441
|
+
}),
|
|
3442
|
+
valueCallback
|
|
3443
|
+
);
|
|
3444
|
+
// Tu
|
|
3445
|
+
case "iiiiii":
|
|
3446
|
+
return mapValue(
|
|
3447
|
+
match2.day(dateString, {
|
|
3448
|
+
width: "short",
|
|
3449
|
+
context: "formatting"
|
|
3450
|
+
}) || match2.day(dateString, {
|
|
3451
|
+
width: "narrow",
|
|
3452
|
+
context: "formatting"
|
|
3453
|
+
}),
|
|
3454
|
+
valueCallback
|
|
3455
|
+
);
|
|
3456
|
+
// Tuesday
|
|
3457
|
+
case "iiii":
|
|
3458
|
+
default:
|
|
3459
|
+
return mapValue(
|
|
3460
|
+
match2.day(dateString, {
|
|
3461
|
+
width: "wide",
|
|
3462
|
+
context: "formatting"
|
|
3463
|
+
}) || match2.day(dateString, {
|
|
3464
|
+
width: "abbreviated",
|
|
3465
|
+
context: "formatting"
|
|
3466
|
+
}) || match2.day(dateString, {
|
|
3467
|
+
width: "short",
|
|
3468
|
+
context: "formatting"
|
|
3469
|
+
}) || match2.day(dateString, {
|
|
3470
|
+
width: "narrow",
|
|
3471
|
+
context: "formatting"
|
|
3472
|
+
}),
|
|
3473
|
+
valueCallback
|
|
3474
|
+
);
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
validate(_date, value) {
|
|
3478
|
+
return value >= 1 && value <= 7;
|
|
3479
|
+
}
|
|
3480
|
+
set(date, _flags, value) {
|
|
3481
|
+
date = setISODay(date, value);
|
|
3482
|
+
date.setHours(0, 0, 0, 0);
|
|
3483
|
+
return date;
|
|
3484
|
+
}
|
|
3485
|
+
};
|
|
3486
|
+
|
|
3487
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/AMPMParser.mjs
|
|
3488
|
+
var AMPMParser = class extends Parser {
|
|
3489
|
+
constructor() {
|
|
3490
|
+
super(...arguments);
|
|
3491
|
+
__publicField(this, "priority", 80);
|
|
3492
|
+
__publicField(this, "incompatibleTokens", ["b", "B", "H", "k", "t", "T"]);
|
|
3493
|
+
}
|
|
3494
|
+
parse(dateString, token, match2) {
|
|
3495
|
+
switch (token) {
|
|
3496
|
+
case "a":
|
|
3497
|
+
case "aa":
|
|
3498
|
+
case "aaa":
|
|
3499
|
+
return match2.dayPeriod(dateString, {
|
|
3500
|
+
width: "abbreviated",
|
|
3501
|
+
context: "formatting"
|
|
3502
|
+
}) || match2.dayPeriod(dateString, {
|
|
3503
|
+
width: "narrow",
|
|
3504
|
+
context: "formatting"
|
|
3505
|
+
});
|
|
3506
|
+
case "aaaaa":
|
|
3507
|
+
return match2.dayPeriod(dateString, {
|
|
3508
|
+
width: "narrow",
|
|
3509
|
+
context: "formatting"
|
|
3510
|
+
});
|
|
3511
|
+
case "aaaa":
|
|
3512
|
+
default:
|
|
3513
|
+
return match2.dayPeriod(dateString, {
|
|
3514
|
+
width: "wide",
|
|
3515
|
+
context: "formatting"
|
|
3516
|
+
}) || match2.dayPeriod(dateString, {
|
|
3517
|
+
width: "abbreviated",
|
|
3518
|
+
context: "formatting"
|
|
3519
|
+
}) || match2.dayPeriod(dateString, {
|
|
3520
|
+
width: "narrow",
|
|
3521
|
+
context: "formatting"
|
|
3522
|
+
});
|
|
3523
|
+
}
|
|
3524
|
+
}
|
|
3525
|
+
set(date, _flags, value) {
|
|
3526
|
+
date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
|
|
3527
|
+
return date;
|
|
3528
|
+
}
|
|
3529
|
+
};
|
|
3530
|
+
|
|
3531
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/AMPMMidnightParser.mjs
|
|
3532
|
+
var AMPMMidnightParser = class extends Parser {
|
|
3533
|
+
constructor() {
|
|
3534
|
+
super(...arguments);
|
|
3535
|
+
__publicField(this, "priority", 80);
|
|
3536
|
+
__publicField(this, "incompatibleTokens", ["a", "B", "H", "k", "t", "T"]);
|
|
3537
|
+
}
|
|
3538
|
+
parse(dateString, token, match2) {
|
|
3539
|
+
switch (token) {
|
|
3540
|
+
case "b":
|
|
3541
|
+
case "bb":
|
|
3542
|
+
case "bbb":
|
|
3543
|
+
return match2.dayPeriod(dateString, {
|
|
3544
|
+
width: "abbreviated",
|
|
3545
|
+
context: "formatting"
|
|
3546
|
+
}) || match2.dayPeriod(dateString, {
|
|
3547
|
+
width: "narrow",
|
|
3548
|
+
context: "formatting"
|
|
3549
|
+
});
|
|
3550
|
+
case "bbbbb":
|
|
3551
|
+
return match2.dayPeriod(dateString, {
|
|
3552
|
+
width: "narrow",
|
|
3553
|
+
context: "formatting"
|
|
3554
|
+
});
|
|
3555
|
+
case "bbbb":
|
|
3556
|
+
default:
|
|
3557
|
+
return match2.dayPeriod(dateString, {
|
|
3558
|
+
width: "wide",
|
|
3559
|
+
context: "formatting"
|
|
3560
|
+
}) || match2.dayPeriod(dateString, {
|
|
3561
|
+
width: "abbreviated",
|
|
3562
|
+
context: "formatting"
|
|
3563
|
+
}) || match2.dayPeriod(dateString, {
|
|
3564
|
+
width: "narrow",
|
|
3565
|
+
context: "formatting"
|
|
3566
|
+
});
|
|
3567
|
+
}
|
|
3568
|
+
}
|
|
3569
|
+
set(date, _flags, value) {
|
|
3570
|
+
date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
|
|
3571
|
+
return date;
|
|
3572
|
+
}
|
|
3573
|
+
};
|
|
3574
|
+
|
|
3575
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/DayPeriodParser.mjs
|
|
3576
|
+
var DayPeriodParser = class extends Parser {
|
|
3577
|
+
constructor() {
|
|
3578
|
+
super(...arguments);
|
|
3579
|
+
__publicField(this, "priority", 80);
|
|
3580
|
+
__publicField(this, "incompatibleTokens", ["a", "b", "t", "T"]);
|
|
3581
|
+
}
|
|
3582
|
+
parse(dateString, token, match2) {
|
|
3583
|
+
switch (token) {
|
|
3584
|
+
case "B":
|
|
3585
|
+
case "BB":
|
|
3586
|
+
case "BBB":
|
|
3587
|
+
return match2.dayPeriod(dateString, {
|
|
3588
|
+
width: "abbreviated",
|
|
3589
|
+
context: "formatting"
|
|
3590
|
+
}) || match2.dayPeriod(dateString, {
|
|
3591
|
+
width: "narrow",
|
|
3592
|
+
context: "formatting"
|
|
3593
|
+
});
|
|
3594
|
+
case "BBBBB":
|
|
3595
|
+
return match2.dayPeriod(dateString, {
|
|
3596
|
+
width: "narrow",
|
|
3597
|
+
context: "formatting"
|
|
3598
|
+
});
|
|
3599
|
+
case "BBBB":
|
|
3600
|
+
default:
|
|
3601
|
+
return match2.dayPeriod(dateString, {
|
|
3602
|
+
width: "wide",
|
|
3603
|
+
context: "formatting"
|
|
3604
|
+
}) || match2.dayPeriod(dateString, {
|
|
3605
|
+
width: "abbreviated",
|
|
3606
|
+
context: "formatting"
|
|
3607
|
+
}) || match2.dayPeriod(dateString, {
|
|
3608
|
+
width: "narrow",
|
|
3609
|
+
context: "formatting"
|
|
3610
|
+
});
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
set(date, _flags, value) {
|
|
3614
|
+
date.setHours(dayPeriodEnumToHours(value), 0, 0, 0);
|
|
3615
|
+
return date;
|
|
3616
|
+
}
|
|
3617
|
+
};
|
|
3618
|
+
|
|
3619
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/Hour1to12Parser.mjs
|
|
3620
|
+
var Hour1to12Parser = class extends Parser {
|
|
3621
|
+
constructor() {
|
|
3622
|
+
super(...arguments);
|
|
3623
|
+
__publicField(this, "priority", 70);
|
|
3624
|
+
__publicField(this, "incompatibleTokens", ["H", "K", "k", "t", "T"]);
|
|
3625
|
+
}
|
|
3626
|
+
parse(dateString, token, match2) {
|
|
3627
|
+
switch (token) {
|
|
3628
|
+
case "h":
|
|
3629
|
+
return parseNumericPattern(numericPatterns.hour12h, dateString);
|
|
3630
|
+
case "ho":
|
|
3631
|
+
return match2.ordinalNumber(dateString, { unit: "hour" });
|
|
3632
|
+
default:
|
|
3633
|
+
return parseNDigits(token.length, dateString);
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
validate(_date, value) {
|
|
3637
|
+
return value >= 1 && value <= 12;
|
|
3638
|
+
}
|
|
3639
|
+
set(date, _flags, value) {
|
|
3640
|
+
const isPM = date.getHours() >= 12;
|
|
3641
|
+
if (isPM && value < 12) {
|
|
3642
|
+
date.setHours(value + 12, 0, 0, 0);
|
|
3643
|
+
} else if (!isPM && value === 12) {
|
|
3644
|
+
date.setHours(0, 0, 0, 0);
|
|
3645
|
+
} else {
|
|
3646
|
+
date.setHours(value, 0, 0, 0);
|
|
3647
|
+
}
|
|
3648
|
+
return date;
|
|
3649
|
+
}
|
|
3650
|
+
};
|
|
3651
|
+
|
|
3652
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/Hour0to23Parser.mjs
|
|
3653
|
+
var Hour0to23Parser = class extends Parser {
|
|
3654
|
+
constructor() {
|
|
3655
|
+
super(...arguments);
|
|
3656
|
+
__publicField(this, "priority", 70);
|
|
3657
|
+
__publicField(this, "incompatibleTokens", ["a", "b", "h", "K", "k", "t", "T"]);
|
|
3658
|
+
}
|
|
3659
|
+
parse(dateString, token, match2) {
|
|
3660
|
+
switch (token) {
|
|
3661
|
+
case "H":
|
|
3662
|
+
return parseNumericPattern(numericPatterns.hour23h, dateString);
|
|
3663
|
+
case "Ho":
|
|
3664
|
+
return match2.ordinalNumber(dateString, { unit: "hour" });
|
|
3665
|
+
default:
|
|
3666
|
+
return parseNDigits(token.length, dateString);
|
|
3667
|
+
}
|
|
3668
|
+
}
|
|
3669
|
+
validate(_date, value) {
|
|
3670
|
+
return value >= 0 && value <= 23;
|
|
3671
|
+
}
|
|
3672
|
+
set(date, _flags, value) {
|
|
3673
|
+
date.setHours(value, 0, 0, 0);
|
|
3674
|
+
return date;
|
|
3675
|
+
}
|
|
3676
|
+
};
|
|
3677
|
+
|
|
3678
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/Hour0To11Parser.mjs
|
|
3679
|
+
var Hour0To11Parser = class extends Parser {
|
|
3680
|
+
constructor() {
|
|
3681
|
+
super(...arguments);
|
|
3682
|
+
__publicField(this, "priority", 70);
|
|
3683
|
+
__publicField(this, "incompatibleTokens", ["h", "H", "k", "t", "T"]);
|
|
3684
|
+
}
|
|
3685
|
+
parse(dateString, token, match2) {
|
|
3686
|
+
switch (token) {
|
|
3687
|
+
case "K":
|
|
3688
|
+
return parseNumericPattern(numericPatterns.hour11h, dateString);
|
|
3689
|
+
case "Ko":
|
|
3690
|
+
return match2.ordinalNumber(dateString, { unit: "hour" });
|
|
3691
|
+
default:
|
|
3692
|
+
return parseNDigits(token.length, dateString);
|
|
3693
|
+
}
|
|
3694
|
+
}
|
|
3695
|
+
validate(_date, value) {
|
|
3696
|
+
return value >= 0 && value <= 11;
|
|
3697
|
+
}
|
|
3698
|
+
set(date, _flags, value) {
|
|
3699
|
+
const isPM = date.getHours() >= 12;
|
|
3700
|
+
if (isPM && value < 12) {
|
|
3701
|
+
date.setHours(value + 12, 0, 0, 0);
|
|
3702
|
+
} else {
|
|
3703
|
+
date.setHours(value, 0, 0, 0);
|
|
3704
|
+
}
|
|
3705
|
+
return date;
|
|
3706
|
+
}
|
|
3707
|
+
};
|
|
3708
|
+
|
|
3709
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/Hour1To24Parser.mjs
|
|
3710
|
+
var Hour1To24Parser = class extends Parser {
|
|
3711
|
+
constructor() {
|
|
3712
|
+
super(...arguments);
|
|
3713
|
+
__publicField(this, "priority", 70);
|
|
3714
|
+
__publicField(this, "incompatibleTokens", ["a", "b", "h", "H", "K", "t", "T"]);
|
|
3715
|
+
}
|
|
3716
|
+
parse(dateString, token, match2) {
|
|
3717
|
+
switch (token) {
|
|
3718
|
+
case "k":
|
|
3719
|
+
return parseNumericPattern(numericPatterns.hour24h, dateString);
|
|
3720
|
+
case "ko":
|
|
3721
|
+
return match2.ordinalNumber(dateString, { unit: "hour" });
|
|
3722
|
+
default:
|
|
3723
|
+
return parseNDigits(token.length, dateString);
|
|
3724
|
+
}
|
|
3725
|
+
}
|
|
3726
|
+
validate(_date, value) {
|
|
3727
|
+
return value >= 1 && value <= 24;
|
|
3728
|
+
}
|
|
3729
|
+
set(date, _flags, value) {
|
|
3730
|
+
const hours = value <= 24 ? value % 24 : value;
|
|
3731
|
+
date.setHours(hours, 0, 0, 0);
|
|
3732
|
+
return date;
|
|
3733
|
+
}
|
|
3734
|
+
};
|
|
3735
|
+
|
|
3736
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/MinuteParser.mjs
|
|
3737
|
+
var MinuteParser = class extends Parser {
|
|
3738
|
+
constructor() {
|
|
3739
|
+
super(...arguments);
|
|
3740
|
+
__publicField(this, "priority", 60);
|
|
3741
|
+
__publicField(this, "incompatibleTokens", ["t", "T"]);
|
|
3742
|
+
}
|
|
3743
|
+
parse(dateString, token, match2) {
|
|
3744
|
+
switch (token) {
|
|
3745
|
+
case "m":
|
|
3746
|
+
return parseNumericPattern(numericPatterns.minute, dateString);
|
|
3747
|
+
case "mo":
|
|
3748
|
+
return match2.ordinalNumber(dateString, { unit: "minute" });
|
|
3749
|
+
default:
|
|
3750
|
+
return parseNDigits(token.length, dateString);
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
validate(_date, value) {
|
|
3754
|
+
return value >= 0 && value <= 59;
|
|
3755
|
+
}
|
|
3756
|
+
set(date, _flags, value) {
|
|
3757
|
+
date.setMinutes(value, 0, 0);
|
|
3758
|
+
return date;
|
|
3759
|
+
}
|
|
3760
|
+
};
|
|
3761
|
+
|
|
3762
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/SecondParser.mjs
|
|
3763
|
+
var SecondParser = class extends Parser {
|
|
3764
|
+
constructor() {
|
|
3765
|
+
super(...arguments);
|
|
3766
|
+
__publicField(this, "priority", 50);
|
|
3767
|
+
__publicField(this, "incompatibleTokens", ["t", "T"]);
|
|
3768
|
+
}
|
|
3769
|
+
parse(dateString, token, match2) {
|
|
3770
|
+
switch (token) {
|
|
3771
|
+
case "s":
|
|
3772
|
+
return parseNumericPattern(numericPatterns.second, dateString);
|
|
3773
|
+
case "so":
|
|
3774
|
+
return match2.ordinalNumber(dateString, { unit: "second" });
|
|
3775
|
+
default:
|
|
3776
|
+
return parseNDigits(token.length, dateString);
|
|
3777
|
+
}
|
|
3778
|
+
}
|
|
3779
|
+
validate(_date, value) {
|
|
3780
|
+
return value >= 0 && value <= 59;
|
|
3781
|
+
}
|
|
3782
|
+
set(date, _flags, value) {
|
|
3783
|
+
date.setSeconds(value, 0);
|
|
3784
|
+
return date;
|
|
3785
|
+
}
|
|
3786
|
+
};
|
|
3787
|
+
|
|
3788
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/FractionOfSecondParser.mjs
|
|
3789
|
+
var FractionOfSecondParser = class extends Parser {
|
|
3790
|
+
constructor() {
|
|
3791
|
+
super(...arguments);
|
|
3792
|
+
__publicField(this, "priority", 30);
|
|
3793
|
+
__publicField(this, "incompatibleTokens", ["t", "T"]);
|
|
3794
|
+
}
|
|
3795
|
+
parse(dateString, token) {
|
|
3796
|
+
const valueCallback = (value) => Math.trunc(value * Math.pow(10, -token.length + 3));
|
|
3797
|
+
return mapValue(parseNDigits(token.length, dateString), valueCallback);
|
|
3798
|
+
}
|
|
3799
|
+
set(date, _flags, value) {
|
|
3800
|
+
date.setMilliseconds(value);
|
|
3801
|
+
return date;
|
|
3802
|
+
}
|
|
3803
|
+
};
|
|
3804
|
+
|
|
3805
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/ISOTimezoneWithZParser.mjs
|
|
3806
|
+
var ISOTimezoneWithZParser = class extends Parser {
|
|
3807
|
+
constructor() {
|
|
3808
|
+
super(...arguments);
|
|
3809
|
+
__publicField(this, "priority", 10);
|
|
3810
|
+
__publicField(this, "incompatibleTokens", ["t", "T", "x"]);
|
|
3811
|
+
}
|
|
3812
|
+
parse(dateString, token) {
|
|
3813
|
+
switch (token) {
|
|
3814
|
+
case "X":
|
|
3815
|
+
return parseTimezonePattern(
|
|
3816
|
+
timezonePatterns.basicOptionalMinutes,
|
|
3817
|
+
dateString
|
|
3818
|
+
);
|
|
3819
|
+
case "XX":
|
|
3820
|
+
return parseTimezonePattern(timezonePatterns.basic, dateString);
|
|
3821
|
+
case "XXXX":
|
|
3822
|
+
return parseTimezonePattern(
|
|
3823
|
+
timezonePatterns.basicOptionalSeconds,
|
|
3824
|
+
dateString
|
|
3825
|
+
);
|
|
3826
|
+
case "XXXXX":
|
|
3827
|
+
return parseTimezonePattern(
|
|
3828
|
+
timezonePatterns.extendedOptionalSeconds,
|
|
3829
|
+
dateString
|
|
3830
|
+
);
|
|
3831
|
+
case "XXX":
|
|
3832
|
+
default:
|
|
3833
|
+
return parseTimezonePattern(timezonePatterns.extended, dateString);
|
|
3834
|
+
}
|
|
3835
|
+
}
|
|
3836
|
+
set(date, flags, value) {
|
|
3837
|
+
if (flags.timestampIsSet) return date;
|
|
3838
|
+
return constructFrom(
|
|
3839
|
+
date,
|
|
3840
|
+
date.getTime() - getTimezoneOffsetInMilliseconds(date) - value
|
|
3841
|
+
);
|
|
3842
|
+
}
|
|
3843
|
+
};
|
|
3844
|
+
|
|
3845
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/ISOTimezoneParser.mjs
|
|
3846
|
+
var ISOTimezoneParser = class extends Parser {
|
|
3847
|
+
constructor() {
|
|
3848
|
+
super(...arguments);
|
|
3849
|
+
__publicField(this, "priority", 10);
|
|
3850
|
+
__publicField(this, "incompatibleTokens", ["t", "T", "X"]);
|
|
3851
|
+
}
|
|
3852
|
+
parse(dateString, token) {
|
|
3853
|
+
switch (token) {
|
|
3854
|
+
case "x":
|
|
3855
|
+
return parseTimezonePattern(
|
|
3856
|
+
timezonePatterns.basicOptionalMinutes,
|
|
3857
|
+
dateString
|
|
3858
|
+
);
|
|
3859
|
+
case "xx":
|
|
3860
|
+
return parseTimezonePattern(timezonePatterns.basic, dateString);
|
|
3861
|
+
case "xxxx":
|
|
3862
|
+
return parseTimezonePattern(
|
|
3863
|
+
timezonePatterns.basicOptionalSeconds,
|
|
3864
|
+
dateString
|
|
3865
|
+
);
|
|
3866
|
+
case "xxxxx":
|
|
3867
|
+
return parseTimezonePattern(
|
|
3868
|
+
timezonePatterns.extendedOptionalSeconds,
|
|
3869
|
+
dateString
|
|
3870
|
+
);
|
|
3871
|
+
case "xxx":
|
|
3872
|
+
default:
|
|
3873
|
+
return parseTimezonePattern(timezonePatterns.extended, dateString);
|
|
3874
|
+
}
|
|
3875
|
+
}
|
|
3876
|
+
set(date, flags, value) {
|
|
3877
|
+
if (flags.timestampIsSet) return date;
|
|
3878
|
+
return constructFrom(
|
|
3879
|
+
date,
|
|
3880
|
+
date.getTime() - getTimezoneOffsetInMilliseconds(date) - value
|
|
3881
|
+
);
|
|
3882
|
+
}
|
|
3883
|
+
};
|
|
3884
|
+
|
|
3885
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/TimestampSecondsParser.mjs
|
|
3886
|
+
var TimestampSecondsParser = class extends Parser {
|
|
3887
|
+
constructor() {
|
|
3888
|
+
super(...arguments);
|
|
3889
|
+
__publicField(this, "priority", 40);
|
|
3890
|
+
__publicField(this, "incompatibleTokens", "*");
|
|
3891
|
+
}
|
|
3892
|
+
parse(dateString) {
|
|
3893
|
+
return parseAnyDigitsSigned(dateString);
|
|
3894
|
+
}
|
|
3895
|
+
set(date, _flags, value) {
|
|
3896
|
+
return [constructFrom(date, value * 1e3), { timestampIsSet: true }];
|
|
3897
|
+
}
|
|
3898
|
+
};
|
|
3899
|
+
|
|
3900
|
+
// ../../node_modules/date-fns/parse/_lib/parsers/TimestampMillisecondsParser.mjs
|
|
3901
|
+
var TimestampMillisecondsParser = class extends Parser {
|
|
3902
|
+
constructor() {
|
|
3903
|
+
super(...arguments);
|
|
3904
|
+
__publicField(this, "priority", 20);
|
|
3905
|
+
__publicField(this, "incompatibleTokens", "*");
|
|
3906
|
+
}
|
|
3907
|
+
parse(dateString) {
|
|
3908
|
+
return parseAnyDigitsSigned(dateString);
|
|
3909
|
+
}
|
|
3910
|
+
set(date, _flags, value) {
|
|
3911
|
+
return [constructFrom(date, value), { timestampIsSet: true }];
|
|
3912
|
+
}
|
|
3913
|
+
};
|
|
3914
|
+
|
|
3915
|
+
// ../../node_modules/date-fns/parse/_lib/parsers.mjs
|
|
3916
|
+
var parsers = {
|
|
3917
|
+
G: new EraParser(),
|
|
3918
|
+
y: new YearParser(),
|
|
3919
|
+
Y: new LocalWeekYearParser(),
|
|
3920
|
+
R: new ISOWeekYearParser(),
|
|
3921
|
+
u: new ExtendedYearParser(),
|
|
3922
|
+
Q: new QuarterParser(),
|
|
3923
|
+
q: new StandAloneQuarterParser(),
|
|
3924
|
+
M: new MonthParser(),
|
|
3925
|
+
L: new StandAloneMonthParser(),
|
|
3926
|
+
w: new LocalWeekParser(),
|
|
3927
|
+
I: new ISOWeekParser(),
|
|
3928
|
+
d: new DateParser(),
|
|
3929
|
+
D: new DayOfYearParser(),
|
|
3930
|
+
E: new DayParser(),
|
|
3931
|
+
e: new LocalDayParser(),
|
|
3932
|
+
c: new StandAloneLocalDayParser(),
|
|
3933
|
+
i: new ISODayParser(),
|
|
3934
|
+
a: new AMPMParser(),
|
|
3935
|
+
b: new AMPMMidnightParser(),
|
|
3936
|
+
B: new DayPeriodParser(),
|
|
3937
|
+
h: new Hour1to12Parser(),
|
|
3938
|
+
H: new Hour0to23Parser(),
|
|
3939
|
+
K: new Hour0To11Parser(),
|
|
3940
|
+
k: new Hour1To24Parser(),
|
|
3941
|
+
m: new MinuteParser(),
|
|
3942
|
+
s: new SecondParser(),
|
|
3943
|
+
S: new FractionOfSecondParser(),
|
|
3944
|
+
X: new ISOTimezoneWithZParser(),
|
|
3945
|
+
x: new ISOTimezoneParser(),
|
|
3946
|
+
t: new TimestampSecondsParser(),
|
|
3947
|
+
T: new TimestampMillisecondsParser()
|
|
3948
|
+
};
|
|
3949
|
+
|
|
3950
|
+
// ../../node_modules/date-fns/parse.mjs
|
|
3951
|
+
var formattingTokensRegExp = /[yYQqMLwIdDecihHKkms]o|(\w)\1*|''|'(''|[^'])+('|$)|./g;
|
|
3952
|
+
var longFormattingTokensRegExp = /P+p+|P+|p+|''|'(''|[^'])+('|$)|./g;
|
|
3953
|
+
var escapedStringRegExp = /^'([^]*?)'?$/;
|
|
3954
|
+
var doubleQuoteRegExp = /''/g;
|
|
3955
|
+
var notWhitespaceRegExp = /\S/;
|
|
3956
|
+
var unescapedLatinCharacterRegExp = /[a-zA-Z]/;
|
|
3957
|
+
function parse(dateStr, formatStr, referenceDate, options) {
|
|
3958
|
+
const defaultOptions2 = getDefaultOptions2();
|
|
3959
|
+
const locale = defaultOptions2.locale ?? enUS;
|
|
3960
|
+
const firstWeekContainsDate = defaultOptions2.firstWeekContainsDate ?? defaultOptions2.locale?.options?.firstWeekContainsDate ?? 1;
|
|
3961
|
+
const weekStartsOn = defaultOptions2.weekStartsOn ?? defaultOptions2.locale?.options?.weekStartsOn ?? 0;
|
|
3962
|
+
const subFnOptions = {
|
|
3963
|
+
firstWeekContainsDate,
|
|
3964
|
+
weekStartsOn,
|
|
3965
|
+
locale
|
|
3966
|
+
};
|
|
3967
|
+
const setters = [new DateToSystemTimezoneSetter()];
|
|
3968
|
+
const tokens = formatStr.match(longFormattingTokensRegExp).map((substring) => {
|
|
3969
|
+
const firstCharacter = substring[0];
|
|
3970
|
+
if (firstCharacter in longFormatters) {
|
|
3971
|
+
const longFormatter = longFormatters[firstCharacter];
|
|
3972
|
+
return longFormatter(substring, locale.formatLong);
|
|
3973
|
+
}
|
|
3974
|
+
return substring;
|
|
3975
|
+
}).join("").match(formattingTokensRegExp);
|
|
3976
|
+
const usedTokens = [];
|
|
3977
|
+
for (let token of tokens) {
|
|
3978
|
+
if (isProtectedWeekYearToken(token)) {
|
|
3979
|
+
warnOrThrowProtectedError(token, formatStr, dateStr);
|
|
3980
|
+
}
|
|
3981
|
+
if (isProtectedDayOfYearToken(token)) {
|
|
3982
|
+
warnOrThrowProtectedError(token, formatStr, dateStr);
|
|
3983
|
+
}
|
|
3984
|
+
const firstCharacter = token[0];
|
|
3985
|
+
const parser = parsers[firstCharacter];
|
|
3986
|
+
if (parser) {
|
|
3987
|
+
const { incompatibleTokens } = parser;
|
|
3988
|
+
if (Array.isArray(incompatibleTokens)) {
|
|
3989
|
+
const incompatibleToken = usedTokens.find(
|
|
3990
|
+
(usedToken) => incompatibleTokens.includes(usedToken.token) || usedToken.token === firstCharacter
|
|
3991
|
+
);
|
|
3992
|
+
if (incompatibleToken) {
|
|
3993
|
+
throw new RangeError(
|
|
3994
|
+
`The format string mustn't contain \`${incompatibleToken.fullToken}\` and \`${token}\` at the same time`
|
|
3995
|
+
);
|
|
3996
|
+
}
|
|
3997
|
+
} else if (parser.incompatibleTokens === "*" && usedTokens.length > 0) {
|
|
3998
|
+
throw new RangeError(
|
|
3999
|
+
`The format string mustn't contain \`${token}\` and any other token at the same time`
|
|
4000
|
+
);
|
|
4001
|
+
}
|
|
4002
|
+
usedTokens.push({ token: firstCharacter, fullToken: token });
|
|
4003
|
+
const parseResult = parser.run(
|
|
4004
|
+
dateStr,
|
|
4005
|
+
token,
|
|
4006
|
+
locale.match,
|
|
4007
|
+
subFnOptions
|
|
4008
|
+
);
|
|
4009
|
+
if (!parseResult) {
|
|
4010
|
+
return constructFrom(referenceDate, NaN);
|
|
4011
|
+
}
|
|
4012
|
+
setters.push(parseResult.setter);
|
|
4013
|
+
dateStr = parseResult.rest;
|
|
4014
|
+
} else {
|
|
4015
|
+
if (firstCharacter.match(unescapedLatinCharacterRegExp)) {
|
|
4016
|
+
throw new RangeError(
|
|
4017
|
+
"Format string contains an unescaped latin alphabet character `" + firstCharacter + "`"
|
|
4018
|
+
);
|
|
4019
|
+
}
|
|
4020
|
+
if (token === "''") {
|
|
4021
|
+
token = "'";
|
|
4022
|
+
} else if (firstCharacter === "'") {
|
|
4023
|
+
token = cleanEscapedString(token);
|
|
4024
|
+
}
|
|
4025
|
+
if (dateStr.indexOf(token) === 0) {
|
|
4026
|
+
dateStr = dateStr.slice(token.length);
|
|
4027
|
+
} else {
|
|
4028
|
+
return constructFrom(referenceDate, NaN);
|
|
4029
|
+
}
|
|
4030
|
+
}
|
|
4031
|
+
}
|
|
4032
|
+
if (dateStr.length > 0 && notWhitespaceRegExp.test(dateStr)) {
|
|
4033
|
+
return constructFrom(referenceDate, NaN);
|
|
4034
|
+
}
|
|
4035
|
+
const uniquePrioritySetters = setters.map((setter) => setter.priority).sort((a, b) => b - a).filter((priority, index, array) => array.indexOf(priority) === index).map(
|
|
4036
|
+
(priority) => setters.filter((setter) => setter.priority === priority).sort((a, b) => b.subPriority - a.subPriority)
|
|
4037
|
+
).map((setterArray) => setterArray[0]);
|
|
4038
|
+
let date = toDate(referenceDate);
|
|
4039
|
+
if (isNaN(date.getTime())) {
|
|
4040
|
+
return constructFrom(referenceDate, NaN);
|
|
4041
|
+
}
|
|
4042
|
+
const flags = {};
|
|
4043
|
+
for (const setter of uniquePrioritySetters) {
|
|
4044
|
+
if (!setter.validate(date, subFnOptions)) {
|
|
4045
|
+
return constructFrom(referenceDate, NaN);
|
|
4046
|
+
}
|
|
4047
|
+
const result = setter.set(date, flags, subFnOptions);
|
|
4048
|
+
if (Array.isArray(result)) {
|
|
4049
|
+
date = result[0];
|
|
4050
|
+
Object.assign(flags, result[1]);
|
|
4051
|
+
} else {
|
|
4052
|
+
date = result;
|
|
4053
|
+
}
|
|
4054
|
+
}
|
|
4055
|
+
return constructFrom(referenceDate, date);
|
|
4056
|
+
}
|
|
4057
|
+
function cleanEscapedString(input) {
|
|
4058
|
+
return input.match(escapedStringRegExp)[1].replace(doubleQuoteRegExp, "'");
|
|
4059
|
+
}
|
|
4060
|
+
|
|
4061
|
+
// src/types/schema-form-builder.ts
|
|
4062
|
+
function hydrateField(raw, currentPage) {
|
|
4063
|
+
return {
|
|
4064
|
+
...raw,
|
|
4065
|
+
rules_count: Object.keys(raw.show ?? {}).length,
|
|
4066
|
+
show_on_this_page: raw.page === currentPage,
|
|
4067
|
+
visible: false,
|
|
4068
|
+
is_visible: false,
|
|
4069
|
+
aws_lookup: raw.lookup?.aws_table != null
|
|
4070
|
+
};
|
|
4071
|
+
}
|
|
4072
|
+
|
|
4073
|
+
// src/utils/formSchemaApi.ts
|
|
4074
|
+
function isApiError(result) {
|
|
4075
|
+
return result.error === true;
|
|
4076
|
+
}
|
|
4077
|
+
async function getFormSchema(formId, appConfig) {
|
|
4078
|
+
try {
|
|
4079
|
+
const response = await fetch(`${appConfig.apiBaseUrl}/form/schema`, {
|
|
4080
|
+
method: "POST",
|
|
4081
|
+
headers: {
|
|
4082
|
+
"Content-Type": "application/json",
|
|
4083
|
+
clienttoken: appConfig.blApiToken
|
|
4084
|
+
},
|
|
4085
|
+
body: JSON.stringify({
|
|
4086
|
+
company: appConfig.company_id,
|
|
4087
|
+
client: appConfig.customer_name,
|
|
4088
|
+
form_name: formId
|
|
4089
|
+
})
|
|
4090
|
+
});
|
|
4091
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
4092
|
+
return await response.json();
|
|
4093
|
+
} catch (err) {
|
|
4094
|
+
return { error: true, message: err.message };
|
|
4095
|
+
}
|
|
4096
|
+
}
|
|
4097
|
+
async function getAddressLookup(postcode, appConfig) {
|
|
4098
|
+
try {
|
|
4099
|
+
const response = await fetch(
|
|
4100
|
+
`${appConfig.apiBaseUrl}/ordnance_survey/postcode/${encodeURIComponent(postcode)}`,
|
|
4101
|
+
{
|
|
4102
|
+
headers: {
|
|
4103
|
+
"Content-Type": "application/json",
|
|
4104
|
+
clienttoken: appConfig.blApiToken
|
|
4105
|
+
}
|
|
4106
|
+
}
|
|
4107
|
+
);
|
|
4108
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
4109
|
+
const data = await response.json();
|
|
4110
|
+
return Array.isArray(data) ? data : data.results ?? [];
|
|
4111
|
+
} catch (err) {
|
|
4112
|
+
return { error: true, message: err.message };
|
|
4113
|
+
}
|
|
4114
|
+
}
|
|
4115
|
+
async function awsLookup(appConfig, table, field, reference, referenceExtra, fieldExtra) {
|
|
4116
|
+
try {
|
|
4117
|
+
const body = {
|
|
4118
|
+
client: appConfig.customer_name,
|
|
4119
|
+
reference,
|
|
4120
|
+
table,
|
|
4121
|
+
field
|
|
4122
|
+
};
|
|
4123
|
+
if (referenceExtra && fieldExtra) {
|
|
4124
|
+
body["referenceExtra"] = fieldExtra;
|
|
4125
|
+
body["field_extra"] = referenceExtra;
|
|
4126
|
+
}
|
|
4127
|
+
const response = await fetch(`${appConfig.apiBaseUrl}/eligibility_reference_lookup`, {
|
|
4128
|
+
method: "POST",
|
|
4129
|
+
headers: {
|
|
4130
|
+
"Content-Type": "application/json",
|
|
4131
|
+
clienttoken: appConfig.blApiToken
|
|
4132
|
+
},
|
|
4133
|
+
body: JSON.stringify(body)
|
|
4134
|
+
});
|
|
4135
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
4136
|
+
return await response.json();
|
|
4137
|
+
} catch (err) {
|
|
4138
|
+
return { error: true, message: err.message };
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
async function getExtraItemProperties(bookingQuestionCode, companyId, serviceId, appConfig) {
|
|
4142
|
+
try {
|
|
4143
|
+
const response = await fetch(
|
|
4144
|
+
`${appConfig.apiBaseUrl}/company/${companyId}/extra-item/${bookingQuestionCode}/service/${serviceId}`,
|
|
4145
|
+
{
|
|
4146
|
+
headers: {
|
|
4147
|
+
"Content-Type": "application/json",
|
|
4148
|
+
clienttoken: appConfig.blApiToken
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
);
|
|
4152
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
4153
|
+
return await response.json();
|
|
4154
|
+
} catch (err) {
|
|
4155
|
+
return { error: true, message: err.message };
|
|
4156
|
+
}
|
|
4157
|
+
}
|
|
4158
|
+
async function searchVenue(companyId, query, appConfig) {
|
|
4159
|
+
try {
|
|
4160
|
+
const response = await fetch(
|
|
4161
|
+
`${appConfig.apiBaseUrl}/company/${companyId}/venue-lookup?search=${encodeURIComponent(query.toLowerCase())}`,
|
|
4162
|
+
{
|
|
4163
|
+
headers: {
|
|
4164
|
+
"Content-Type": "application/json",
|
|
4165
|
+
"x-company-id": companyId,
|
|
4166
|
+
clienttoken: appConfig.blApiToken
|
|
4167
|
+
}
|
|
4168
|
+
}
|
|
4169
|
+
);
|
|
4170
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
4171
|
+
const data = await response.json();
|
|
4172
|
+
return Array.isArray(data) ? data : [];
|
|
4173
|
+
} catch (err) {
|
|
4174
|
+
return { error: true, message: err.message };
|
|
4175
|
+
}
|
|
4176
|
+
}
|
|
4177
|
+
function requiredValidator(value) {
|
|
4178
|
+
if (value === "" || value == null) return { key: "required" };
|
|
4179
|
+
return null;
|
|
4180
|
+
}
|
|
4181
|
+
var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
4182
|
+
function emailValidator(value) {
|
|
4183
|
+
if (!value) return null;
|
|
4184
|
+
return EMAIL_REGEX.test(value) ? null : { key: "email" };
|
|
4185
|
+
}
|
|
4186
|
+
var UK_MOBILE_REGEX = /^(?:0|\+44)7\d{9}$/;
|
|
4187
|
+
function mobileValidator(value) {
|
|
4188
|
+
if (!value) return null;
|
|
4189
|
+
return UK_MOBILE_REGEX.test(value) ? null : { key: "pattern", message: "Enter a valid UK mobile number." };
|
|
4190
|
+
}
|
|
4191
|
+
var UK_PHONE_REGEX = /^(?:0|\+44)\s?\d{10}$/;
|
|
4192
|
+
function phoneValidator(value) {
|
|
4193
|
+
if (!value) return null;
|
|
4194
|
+
return UK_PHONE_REGEX.test(value) ? null : { key: "pattern", message: "Enter a valid UK phone number." };
|
|
4195
|
+
}
|
|
4196
|
+
function minLengthValidator(min) {
|
|
4197
|
+
return (value) => {
|
|
4198
|
+
if (!value) return null;
|
|
4199
|
+
return value.length >= min ? null : { key: "minlength", requiredLength: min };
|
|
4200
|
+
};
|
|
4201
|
+
}
|
|
4202
|
+
function maxLengthValidator(max) {
|
|
4203
|
+
return (value) => {
|
|
4204
|
+
if (!value) return null;
|
|
4205
|
+
return value.length <= max ? null : { key: "maxlength", requiredLength: max };
|
|
4206
|
+
};
|
|
4207
|
+
}
|
|
4208
|
+
function minDateValidator(minDateStr) {
|
|
4209
|
+
return (value) => {
|
|
4210
|
+
if (!value) return null;
|
|
4211
|
+
const controlDate = startOfDay(new Date(value));
|
|
4212
|
+
const minDate = startOfDay(parse(minDateStr, "dd-MM-yyyy", /* @__PURE__ */ new Date()));
|
|
4213
|
+
if (!isValid(controlDate)) return { key: "invalidDate", message: "Invalid date format" };
|
|
4214
|
+
return isBefore(controlDate, minDate) ? { key: "minDate", message: "Date cannot be in the past" } : null;
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
function maxDateValidator(noOfDays) {
|
|
4218
|
+
return (value) => {
|
|
4219
|
+
if (!value) return null;
|
|
4220
|
+
const maxDate = startOfDay(addDays(/* @__PURE__ */ new Date(), noOfDays));
|
|
4221
|
+
const controlDate = startOfDay(new Date(value));
|
|
4222
|
+
return isAfter(controlDate, maxDate) ? { key: "maxDate", message: "Date cannot be in the future" } : null;
|
|
4223
|
+
};
|
|
4224
|
+
}
|
|
4225
|
+
function buildValidators(field) {
|
|
4226
|
+
const validators = [];
|
|
4227
|
+
if (field.required) validators.push(requiredValidator);
|
|
4228
|
+
if (!Array.isArray(field.validation)) return validators;
|
|
4229
|
+
for (const rule of field.validation) {
|
|
4230
|
+
if (typeof rule === "string") {
|
|
4231
|
+
switch (rule) {
|
|
4232
|
+
case "email":
|
|
4233
|
+
validators.push(emailValidator);
|
|
4234
|
+
break;
|
|
4235
|
+
case "mobile":
|
|
4236
|
+
validators.push(mobileValidator);
|
|
4237
|
+
break;
|
|
4238
|
+
case "phone":
|
|
4239
|
+
case "contact":
|
|
4240
|
+
validators.push(phoneValidator);
|
|
4241
|
+
break;
|
|
4242
|
+
case "length":
|
|
4243
|
+
validators.push(maxLengthValidator(255));
|
|
4244
|
+
break;
|
|
4245
|
+
}
|
|
4246
|
+
} else if (typeof rule === "object" && rule !== null) {
|
|
4247
|
+
if ("minLength" in rule) validators.push(minLengthValidator(rule.minLength));
|
|
4248
|
+
if ("maxLength" in rule) validators.push(maxLengthValidator(rule.maxLength));
|
|
4249
|
+
if ("minDate" in rule) validators.push(minDateValidator(rule.minDate));
|
|
4250
|
+
if ("maxDate" in rule) validators.push(maxDateValidator(rule.maxDate));
|
|
4251
|
+
}
|
|
4252
|
+
}
|
|
4253
|
+
return validators;
|
|
4254
|
+
}
|
|
4255
|
+
function getErrorMessage(error) {
|
|
4256
|
+
switch (error.key) {
|
|
4257
|
+
case "required":
|
|
4258
|
+
return "This field is required.";
|
|
4259
|
+
case "minlength":
|
|
4260
|
+
return `Minimum length is ${error.requiredLength ?? 0} characters.`;
|
|
4261
|
+
case "maxlength":
|
|
4262
|
+
return `Maximum length is ${error.requiredLength ?? 0} characters.`;
|
|
4263
|
+
case "email":
|
|
4264
|
+
return "Enter a valid email address.";
|
|
4265
|
+
case "pattern":
|
|
4266
|
+
return error.message ?? "Invalid format.";
|
|
4267
|
+
case "minDate":
|
|
4268
|
+
return error.message ?? "Date cannot be in the past.";
|
|
4269
|
+
case "maxDate":
|
|
4270
|
+
return error.message ?? "Date cannot be in the future.";
|
|
4271
|
+
case "invalidDate":
|
|
4272
|
+
return error.message ?? "Enter a valid date.";
|
|
4273
|
+
default:
|
|
4274
|
+
return error.message ?? "Invalid input.";
|
|
4275
|
+
}
|
|
4276
|
+
}
|
|
4277
|
+
function getInputType(field) {
|
|
4278
|
+
if (field.type === "number" && Array.isArray(field.validation) && field.validation.some((v) => typeof v === "string" && ["phone", "mobile", "contact"].includes(v))) {
|
|
4279
|
+
return "tel";
|
|
4280
|
+
}
|
|
4281
|
+
return field.type;
|
|
4282
|
+
}
|
|
4283
|
+
var SESSION_STORAGE_KEY = "form_builder_answers";
|
|
4284
|
+
function getAnswerStore() {
|
|
4285
|
+
try {
|
|
4286
|
+
const raw = sessionStorage.getItem(SESSION_STORAGE_KEY);
|
|
4287
|
+
return raw ? JSON.parse(raw) : {};
|
|
4288
|
+
} catch {
|
|
4289
|
+
return {};
|
|
4290
|
+
}
|
|
4291
|
+
}
|
|
4292
|
+
function getStoredAnswer(formId, fieldName) {
|
|
4293
|
+
const store = getAnswerStore();
|
|
4294
|
+
const value = store?.[formId]?.[fieldName];
|
|
4295
|
+
return value != null ? String(value) : null;
|
|
4296
|
+
}
|
|
4297
|
+
function persistAnswer(formId, fieldName, value) {
|
|
4298
|
+
if (!formId) return;
|
|
4299
|
+
const store = getAnswerStore();
|
|
4300
|
+
if (!store[formId]) store[formId] = {};
|
|
4301
|
+
store[formId][fieldName] = value;
|
|
4302
|
+
try {
|
|
4303
|
+
sessionStorage.setItem(SESSION_STORAGE_KEY, JSON.stringify(store));
|
|
4304
|
+
} catch (err) {
|
|
4305
|
+
console.warn("[FormBuilder] Failed to persist answer to sessionStorage:", err);
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
function SchemaFormBuilder(props) {
|
|
4309
|
+
const {
|
|
4310
|
+
formId,
|
|
4311
|
+
appConfig,
|
|
4312
|
+
currentPage,
|
|
4313
|
+
companyId,
|
|
4314
|
+
formData,
|
|
4315
|
+
showSubmit: showSubmitProp,
|
|
4316
|
+
formUpdateId,
|
|
4317
|
+
initialSchema,
|
|
4318
|
+
onFormSubmit,
|
|
4319
|
+
onFormStatus,
|
|
4320
|
+
onSchema,
|
|
4321
|
+
onCompanySet,
|
|
4322
|
+
onServiceSet,
|
|
4323
|
+
onResourceSet,
|
|
4324
|
+
onStaffSet,
|
|
4325
|
+
onAddDuration,
|
|
4326
|
+
onFormReady,
|
|
4327
|
+
onUpdateDatastore,
|
|
4328
|
+
onAddressSet,
|
|
4329
|
+
onAwsLookupSet,
|
|
4330
|
+
onExtraItemSet,
|
|
4331
|
+
onExtraItemChanged,
|
|
4332
|
+
onVenueSet,
|
|
4333
|
+
onProcessing
|
|
4334
|
+
} = props;
|
|
4335
|
+
const [formValues, setFormValues] = useState({});
|
|
4336
|
+
const [formFields, setFormFields] = useState([]);
|
|
4337
|
+
const [schema, setSchema] = useState(null);
|
|
4338
|
+
const [showSubmit, setShowSubmit] = useState(showSubmitProp ?? false);
|
|
4339
|
+
const [loading, setLoading] = useState(true);
|
|
4340
|
+
const [suggestions, setSuggestions] = useState([]);
|
|
4341
|
+
const [, _setSearching] = useState(false);
|
|
4342
|
+
const [searchText, setSearchText] = useState("");
|
|
4343
|
+
const [touchedFields, setTouchedFields] = useState(/* @__PURE__ */ new Set());
|
|
4344
|
+
const [dirtyFields, setDirtyFields] = useState(/* @__PURE__ */ new Set());
|
|
4345
|
+
const formServicesRef = useRef({});
|
|
4346
|
+
const extraItemsRef = useRef([]);
|
|
4347
|
+
const pendingExtraItemFetchesRef = useRef(/* @__PURE__ */ new Set());
|
|
4348
|
+
const venueSearchTimerRef = useRef(null);
|
|
4349
|
+
const activeFormIdRef = useRef("");
|
|
4350
|
+
const initialisedRef = useRef(false);
|
|
4351
|
+
const validatorMapRef = useRef(/* @__PURE__ */ new Map());
|
|
4352
|
+
useEffect(() => {
|
|
4353
|
+
if (initialisedRef.current && formUpdateId === activeFormIdRef.current && !initialSchema) return;
|
|
4354
|
+
initialisedRef.current = true;
|
|
4355
|
+
activeFormIdRef.current = formUpdateId ?? formId;
|
|
4356
|
+
initialiseForm(formUpdateId ?? formId);
|
|
4357
|
+
}, [formId, formUpdateId, initialSchema]);
|
|
4358
|
+
useEffect(() => {
|
|
4359
|
+
if (formFields.length > 0) {
|
|
4360
|
+
refreshVisibility();
|
|
4361
|
+
}
|
|
4362
|
+
if (formFields.length > 0) {
|
|
4363
|
+
const errors = [];
|
|
4364
|
+
for (const field of formFields) {
|
|
4365
|
+
if (field.page !== currentPage) continue;
|
|
4366
|
+
if (!field.visible && !field.is_visible) continue;
|
|
4367
|
+
const value = formValues[field.field] ?? "";
|
|
4368
|
+
const fieldErrors = validateField(field, value);
|
|
4369
|
+
if (fieldErrors) {
|
|
4370
|
+
errors.push({ fieldName: field.field, errors: fieldErrors });
|
|
4371
|
+
}
|
|
4372
|
+
}
|
|
4373
|
+
const serviceSetField = formFields.find(
|
|
4374
|
+
(f) => f.page === currentPage && f.service_set && (f.visible || f.is_visible)
|
|
4375
|
+
);
|
|
4376
|
+
onFormStatus?.({
|
|
4377
|
+
status: errors.length === 0,
|
|
4378
|
+
errors,
|
|
4379
|
+
formData: formValues,
|
|
4380
|
+
extraItems: extraItemsRef.current,
|
|
4381
|
+
setService: serviceSetField?.service_set
|
|
4382
|
+
});
|
|
4383
|
+
}
|
|
4384
|
+
}, [formValues]);
|
|
4385
|
+
useEffect(() => {
|
|
4386
|
+
if (!formFields.length) return;
|
|
4387
|
+
const visibleFieldsWithExtraItems = formFields.filter(
|
|
4388
|
+
(f) => f.page === currentPage && (f.visible || f.is_visible) && (f["extra-item"] || f.resource_ids)
|
|
4389
|
+
);
|
|
4390
|
+
for (const field of visibleFieldsWithExtraItems) {
|
|
4391
|
+
void setExtraItems(field);
|
|
4392
|
+
}
|
|
4393
|
+
}, [formFields, formValues]);
|
|
4394
|
+
useEffect(() => {
|
|
4395
|
+
return () => {
|
|
4396
|
+
if (venueSearchTimerRef.current) {
|
|
4397
|
+
clearTimeout(venueSearchTimerRef.current);
|
|
4398
|
+
}
|
|
4399
|
+
};
|
|
4400
|
+
}, []);
|
|
4401
|
+
const setFieldValue = useCallback(
|
|
4402
|
+
(fieldName, value, _options) => {
|
|
4403
|
+
setFormValues((prev) => ({ ...prev, [fieldName]: value }));
|
|
4404
|
+
persistAnswer(formId, fieldName, value);
|
|
4405
|
+
},
|
|
4406
|
+
[formId]
|
|
4407
|
+
);
|
|
4408
|
+
async function initialiseForm(resolvedFormId) {
|
|
4409
|
+
var _a;
|
|
4410
|
+
setLoading(true);
|
|
4411
|
+
setFormFields([]);
|
|
4412
|
+
setFormValues({});
|
|
4413
|
+
setSchema(null);
|
|
4414
|
+
setShowSubmit(false);
|
|
4415
|
+
extraItemsRef.current = [];
|
|
4416
|
+
pendingExtraItemFetchesRef.current = /* @__PURE__ */ new Set();
|
|
4417
|
+
(_a = formServicesRef.current)[resolvedFormId] ?? (_a[resolvedFormId] = {});
|
|
4418
|
+
let result;
|
|
4419
|
+
if (initialSchema) {
|
|
4420
|
+
result = initialSchema;
|
|
4421
|
+
} else {
|
|
4422
|
+
const apiResult = await getFormSchema(resolvedFormId, appConfig);
|
|
4423
|
+
if (isApiError(apiResult)) {
|
|
4424
|
+
console.error("[FormBuilder] Failed to fetch form schema:", apiResult.message);
|
|
4425
|
+
setLoading(false);
|
|
4426
|
+
return;
|
|
4427
|
+
}
|
|
4428
|
+
result = apiResult;
|
|
4429
|
+
}
|
|
4430
|
+
const rawFields = result.schema.fields.filter((f) => f.field !== "haf_id");
|
|
4431
|
+
const hydrated = rawFields.map((f) => hydrateField(f, currentPage));
|
|
4432
|
+
const initialValues = {};
|
|
4433
|
+
for (const field of hydrated) {
|
|
4434
|
+
if (!field.show_on_this_page) continue;
|
|
4435
|
+
initialValues[field.field] = "";
|
|
4436
|
+
if (field.address_lookup) {
|
|
4437
|
+
initialValues[`${field.field}_postcode`] = "";
|
|
4438
|
+
}
|
|
4439
|
+
}
|
|
4440
|
+
if (formData) {
|
|
4441
|
+
for (const [key, value] of Object.entries(formData)) {
|
|
4442
|
+
if (key in initialValues) {
|
|
4443
|
+
initialValues[key] = String(value ?? "");
|
|
4444
|
+
}
|
|
4445
|
+
}
|
|
4446
|
+
}
|
|
4447
|
+
const copyDataTargets = /* @__PURE__ */ new Set();
|
|
4448
|
+
for (const field of hydrated) {
|
|
4449
|
+
if (field.copy_data?.to) {
|
|
4450
|
+
for (const target of field.copy_data.to) {
|
|
4451
|
+
copyDataTargets.add(target);
|
|
4452
|
+
}
|
|
4453
|
+
}
|
|
4454
|
+
}
|
|
4455
|
+
if (copyDataTargets.size > 0) {
|
|
4456
|
+
const storedAnswers = getAnswerStore()[resolvedFormId] ?? {};
|
|
4457
|
+
for (const target of copyDataTargets) {
|
|
4458
|
+
if (target in initialValues && !initialValues[target] && storedAnswers[target] != null) {
|
|
4459
|
+
initialValues[target] = String(storedAnswers[target]);
|
|
4460
|
+
}
|
|
4461
|
+
}
|
|
4462
|
+
}
|
|
4463
|
+
validatorMapRef.current = /* @__PURE__ */ new Map();
|
|
4464
|
+
for (const field of hydrated) {
|
|
4465
|
+
validatorMapRef.current.set(field.field, buildValidators(field));
|
|
4466
|
+
}
|
|
4467
|
+
setSchema(result);
|
|
4468
|
+
setFormFields(hydrated);
|
|
4469
|
+
setFormValues(initialValues);
|
|
4470
|
+
setTouchedFields(/* @__PURE__ */ new Set());
|
|
4471
|
+
setDirtyFields(/* @__PURE__ */ new Set());
|
|
4472
|
+
onFormReady?.({
|
|
4473
|
+
form_id: resolvedFormId,
|
|
4474
|
+
extra_items: extraItemsRef.current
|
|
4475
|
+
});
|
|
4476
|
+
setLoading(false);
|
|
4477
|
+
}
|
|
4478
|
+
function validateField(field, value) {
|
|
4479
|
+
if (!field.visible && !field.is_visible) return null;
|
|
4480
|
+
const validators = validatorMapRef.current.get(field.field) ?? buildValidators(field);
|
|
4481
|
+
for (const validator of validators) {
|
|
4482
|
+
const error = validator(value);
|
|
4483
|
+
if (error) return error;
|
|
4484
|
+
}
|
|
4485
|
+
return null;
|
|
4486
|
+
}
|
|
4487
|
+
function markAsTouched(fieldName) {
|
|
4488
|
+
setTouchedFields((prev) => new Set(prev).add(fieldName));
|
|
4489
|
+
}
|
|
4490
|
+
function markAsDirty(fieldName) {
|
|
4491
|
+
setDirtyFields((prev) => new Set(prev).add(fieldName));
|
|
4492
|
+
}
|
|
4493
|
+
function markAllAsTouched() {
|
|
4494
|
+
const allFieldNames = formFields.filter((f) => f.show_on_this_page).map((f) => f.field);
|
|
4495
|
+
setTouchedFields(new Set(allFieldNames));
|
|
4496
|
+
}
|
|
4497
|
+
function shouldShowError(fieldName) {
|
|
4498
|
+
return touchedFields.has(fieldName) || dirtyFields.has(fieldName);
|
|
4499
|
+
}
|
|
4500
|
+
function refreshVisibility() {
|
|
4501
|
+
if (!formFields.length) return;
|
|
4502
|
+
let continueVisible = false;
|
|
4503
|
+
const schemaType = schema?.schema?.type ?? "extended";
|
|
4504
|
+
const updatedFields = formFields.map((field) => {
|
|
4505
|
+
if (field.page !== currentPage) return field;
|
|
4506
|
+
const wasVisible = field.visible;
|
|
4507
|
+
const hasShowRules = field.show != null && Object.keys(field.show).length > 0;
|
|
4508
|
+
let isVisible;
|
|
4509
|
+
if (schemaType === "extended") {
|
|
4510
|
+
isVisible = hasShowRules ? evaluateExtendedConditional(field) : evaluateAlwaysVisible(field);
|
|
4511
|
+
} else {
|
|
4512
|
+
isVisible = evaluateLegacyConditional(field);
|
|
4513
|
+
}
|
|
4514
|
+
if (!isVisible && wasVisible) {
|
|
4515
|
+
setFormValues((prev) => {
|
|
4516
|
+
if (prev[field.field] === "" || prev[field.field] == null) return prev;
|
|
4517
|
+
const next = { ...prev, [field.field]: "" };
|
|
4518
|
+
return next;
|
|
4519
|
+
});
|
|
4520
|
+
}
|
|
4521
|
+
if (isVisible && field.continue === true) {
|
|
4522
|
+
continueVisible = true;
|
|
4523
|
+
}
|
|
4524
|
+
return { ...field, visible: isVisible, is_visible: isVisible };
|
|
4525
|
+
});
|
|
4526
|
+
setFormFields(updatedFields);
|
|
4527
|
+
setShowSubmit(continueVisible);
|
|
4528
|
+
}
|
|
4529
|
+
function evaluateAlwaysVisible(field) {
|
|
4530
|
+
resolveDynamicTitle(field);
|
|
4531
|
+
fireVisibleSideEffects(field, true);
|
|
4532
|
+
if (isAppointmentTypeFiltered(field)) return false;
|
|
4533
|
+
return true;
|
|
4534
|
+
}
|
|
4535
|
+
function evaluateExtendedConditional(field) {
|
|
4536
|
+
resolveDynamicTitle(field);
|
|
4537
|
+
const rules = field.show;
|
|
4538
|
+
const customResults = [];
|
|
4539
|
+
const simpleResults = [];
|
|
4540
|
+
if ("custom_all_lookups_successful" in rules) {
|
|
4541
|
+
customResults.push(checkAllLookupsSuccessful(field.field));
|
|
4542
|
+
}
|
|
4543
|
+
if (rules.custom) {
|
|
4544
|
+
customResults.push(evaluateCustomCondition(rules.custom));
|
|
4545
|
+
}
|
|
4546
|
+
if (rules.custom_multiple_condition) {
|
|
4547
|
+
customResults.push(evaluateAndGroup(rules.custom_multiple_condition));
|
|
4548
|
+
}
|
|
4549
|
+
if (rules.custom_multiple_conditions) {
|
|
4550
|
+
customResults.push(evaluateOrOfAndGroups(rules.custom_multiple_conditions));
|
|
4551
|
+
}
|
|
4552
|
+
if (rules.custom_or_condition) {
|
|
4553
|
+
customResults.push(evaluateOrGroup(rules.custom_or_condition));
|
|
4554
|
+
}
|
|
4555
|
+
const RESERVED_RULE_KEYS = /* @__PURE__ */ new Set([
|
|
4556
|
+
"custom",
|
|
4557
|
+
"custom_multiple_condition",
|
|
4558
|
+
"custom_multiple_conditions",
|
|
4559
|
+
"custom_or_condition",
|
|
4560
|
+
"custom_all_lookups_successful"
|
|
4561
|
+
]);
|
|
4562
|
+
for (const [targetField, expectedValue] of Object.entries(rules)) {
|
|
4563
|
+
if (RESERVED_RULE_KEYS.has(targetField)) continue;
|
|
4564
|
+
simpleResults.push(evaluateSimpleRule(targetField, expectedValue));
|
|
4565
|
+
}
|
|
4566
|
+
let isVisible;
|
|
4567
|
+
const simplePass = simpleResults.length === 0 || simpleResults.some((r) => r);
|
|
4568
|
+
const customPass = customResults.length === 0 || customResults.every((r) => r);
|
|
4569
|
+
if (simpleResults.length > 0 && customResults.length > 0) {
|
|
4570
|
+
isVisible = simplePass && customPass;
|
|
4571
|
+
} else if (customResults.length > 0) {
|
|
4572
|
+
isVisible = customPass;
|
|
4573
|
+
} else {
|
|
4574
|
+
isVisible = simplePass;
|
|
4575
|
+
}
|
|
4576
|
+
fireVisibleSideEffects(field, isVisible);
|
|
4577
|
+
if (isVisible && isAppointmentTypeFiltered(field)) return false;
|
|
4578
|
+
if (isVisible && field.appointment_type && currentPage === "services") {
|
|
4579
|
+
const stored = sessionStorage.getItem("appointment_type");
|
|
4580
|
+
if (!stored) {
|
|
4581
|
+
sessionStorage.setItem("appointment_type", field.appointment_type);
|
|
4582
|
+
}
|
|
4583
|
+
}
|
|
4584
|
+
return isVisible;
|
|
4585
|
+
}
|
|
4586
|
+
function evaluateSimpleRule(targetField, expectedValue) {
|
|
4587
|
+
const currentValue = formValues[targetField] ?? "";
|
|
4588
|
+
if (expectedValue === "*") {
|
|
4589
|
+
return currentValue !== "" && currentValue !== null && currentValue !== void 0;
|
|
4590
|
+
}
|
|
4591
|
+
if (typeof expectedValue === "string" && expectedValue.includes(" OR ")) {
|
|
4592
|
+
const options = expectedValue.split(" OR ").map((s) => s.trim());
|
|
4593
|
+
return options.some((opt) => {
|
|
4594
|
+
if (opt === "*") return currentValue !== "" && currentValue != null;
|
|
4595
|
+
return String(currentValue) === opt;
|
|
4596
|
+
});
|
|
4597
|
+
}
|
|
4598
|
+
return String(currentValue) === String(expectedValue);
|
|
4599
|
+
}
|
|
4600
|
+
function resolveNumericForComparison(fieldName, rawValue) {
|
|
4601
|
+
const field = formFields.find((f) => f.field === fieldName);
|
|
4602
|
+
if (field?.type === "date" && rawValue) {
|
|
4603
|
+
const dateVal = new Date(rawValue);
|
|
4604
|
+
if (isValid(dateVal)) {
|
|
4605
|
+
const today = startOfDay(/* @__PURE__ */ new Date());
|
|
4606
|
+
const target = startOfDay(dateVal);
|
|
4607
|
+
const diffMs = target.getTime() - today.getTime();
|
|
4608
|
+
return Math.round(diffMs / (1e3 * 60 * 60 * 24));
|
|
4609
|
+
}
|
|
4610
|
+
}
|
|
4611
|
+
return Number(rawValue);
|
|
4612
|
+
}
|
|
4613
|
+
function evaluateCustomExpression(fieldName, expression) {
|
|
4614
|
+
const rawValue = formValues[fieldName] ?? "";
|
|
4615
|
+
if (expression === "*") {
|
|
4616
|
+
return rawValue !== "" && rawValue != null;
|
|
4617
|
+
}
|
|
4618
|
+
if (expression.includes(" and ")) {
|
|
4619
|
+
const parts = expression.split(" and ").map((s) => s.trim());
|
|
4620
|
+
return parts.every((part) => evaluateCustomExpression(fieldName, part));
|
|
4621
|
+
}
|
|
4622
|
+
const match2 = expression.trim().match(/^([<>!=]=?)\s*(.+)$/);
|
|
4623
|
+
if (match2) {
|
|
4624
|
+
const [, operator, operand] = match2;
|
|
4625
|
+
const numericValue = resolveNumericForComparison(fieldName, rawValue);
|
|
4626
|
+
const numericOperand = Number(operand.trim());
|
|
4627
|
+
switch (operator) {
|
|
4628
|
+
case "<":
|
|
4629
|
+
return numericValue < numericOperand;
|
|
4630
|
+
case ">":
|
|
4631
|
+
return numericValue > numericOperand;
|
|
4632
|
+
case "<=":
|
|
4633
|
+
return numericValue <= numericOperand;
|
|
4634
|
+
case ">=":
|
|
4635
|
+
return numericValue >= numericOperand;
|
|
4636
|
+
case "==":
|
|
4637
|
+
return String(rawValue) === operand.trim();
|
|
4638
|
+
case "!=":
|
|
4639
|
+
return String(rawValue) !== operand.trim();
|
|
4640
|
+
default:
|
|
4641
|
+
return false;
|
|
4642
|
+
}
|
|
4643
|
+
}
|
|
4644
|
+
return String(rawValue) === expression.trim();
|
|
4645
|
+
}
|
|
4646
|
+
function evaluateCustomCondition(custom) {
|
|
4647
|
+
if (Array.isArray(custom)) {
|
|
4648
|
+
return custom.every((clause) => evaluateClause(clause));
|
|
4649
|
+
}
|
|
4650
|
+
if (typeof custom === "object" && custom !== null) {
|
|
4651
|
+
const entries = Object.entries(custom);
|
|
4652
|
+
return entries.every(
|
|
4653
|
+
([fieldName, expression]) => evaluateCustomExpression(fieldName, String(expression))
|
|
4654
|
+
);
|
|
4655
|
+
}
|
|
4656
|
+
return false;
|
|
4657
|
+
}
|
|
4658
|
+
function evaluateAndGroup(data) {
|
|
4659
|
+
if (Array.isArray(data)) {
|
|
4660
|
+
return data.every((clause) => evaluateClause(clause));
|
|
4661
|
+
}
|
|
4662
|
+
if (typeof data === "object" && data !== null && "conditions" in data) {
|
|
4663
|
+
const conditions = data.conditions;
|
|
4664
|
+
return conditions.every((condObj) => {
|
|
4665
|
+
const entries = Object.entries(condObj);
|
|
4666
|
+
return entries.every(
|
|
4667
|
+
([fieldName, expectedValue]) => evaluateSimpleRule(fieldName, String(expectedValue))
|
|
4668
|
+
);
|
|
4669
|
+
});
|
|
4670
|
+
}
|
|
4671
|
+
return false;
|
|
4672
|
+
}
|
|
4673
|
+
function evaluateOrOfAndGroups(data) {
|
|
4674
|
+
if (Array.isArray(data)) {
|
|
4675
|
+
return data.some(
|
|
4676
|
+
(group) => Array.isArray(group) && group.every((clause) => evaluateClause(clause))
|
|
4677
|
+
);
|
|
4678
|
+
}
|
|
4679
|
+
if (typeof data === "object" && data !== null && "groups" in data) {
|
|
4680
|
+
const groups = data.groups;
|
|
4681
|
+
return groups.some((group) => {
|
|
4682
|
+
if (!group.conditions || !Array.isArray(group.conditions)) return false;
|
|
4683
|
+
return group.conditions.every((condObj) => {
|
|
4684
|
+
const entries = Object.entries(condObj);
|
|
4685
|
+
return entries.every(
|
|
4686
|
+
([fieldName, expectedValue]) => evaluateSimpleRule(fieldName, String(expectedValue))
|
|
4687
|
+
);
|
|
4688
|
+
});
|
|
4689
|
+
});
|
|
4690
|
+
}
|
|
4691
|
+
return false;
|
|
4692
|
+
}
|
|
4693
|
+
function evaluateOrGroup(clauses) {
|
|
4694
|
+
return clauses.some((clause) => evaluateClause(clause));
|
|
4695
|
+
}
|
|
4696
|
+
function evaluateClause(clause) {
|
|
4697
|
+
const rawValue = formValues[clause.field] ?? "";
|
|
4698
|
+
const operator = clause.operator ?? "==";
|
|
4699
|
+
if (clause.value === "*") {
|
|
4700
|
+
return rawValue !== "" && rawValue != null;
|
|
4701
|
+
}
|
|
4702
|
+
switch (operator) {
|
|
4703
|
+
case "==":
|
|
4704
|
+
return String(rawValue) === String(clause.value);
|
|
4705
|
+
case "!=":
|
|
4706
|
+
return String(rawValue) !== String(clause.value);
|
|
4707
|
+
case ">":
|
|
4708
|
+
return Number(rawValue) > Number(clause.value);
|
|
4709
|
+
case "<":
|
|
4710
|
+
return Number(rawValue) < Number(clause.value);
|
|
4711
|
+
case ">=":
|
|
4712
|
+
return Number(rawValue) >= Number(clause.value);
|
|
4713
|
+
case "<=":
|
|
4714
|
+
return Number(rawValue) <= Number(clause.value);
|
|
4715
|
+
default:
|
|
4716
|
+
return false;
|
|
4717
|
+
}
|
|
4718
|
+
}
|
|
4719
|
+
function checkAllLookupsSuccessful(excludeFieldName) {
|
|
4720
|
+
const allLookupFields = formFields.filter(
|
|
4721
|
+
(f) => f.lookup?.aws_table && f.page === currentPage
|
|
4722
|
+
);
|
|
4723
|
+
const visibleLookupFields = allLookupFields.filter(
|
|
4724
|
+
(f) => (f.visible === true || f.is_visible === true) && f.field !== excludeFieldName
|
|
4725
|
+
);
|
|
4726
|
+
if (visibleLookupFields.length === 0) return false;
|
|
4727
|
+
return visibleLookupFields.every((f) => f.lookupSuccess === true);
|
|
4728
|
+
}
|
|
4729
|
+
function resolveDynamicTitle(field) {
|
|
4730
|
+
const TOKEN_REGEX = /\{([^}]+)\}/g;
|
|
4731
|
+
field.rendered_title = field.title.replace(TOKEN_REGEX, (_, fieldName) => {
|
|
4732
|
+
const value = formValues[fieldName];
|
|
4733
|
+
return value != null && value !== "" ? String(value) : "";
|
|
4734
|
+
});
|
|
4735
|
+
}
|
|
4736
|
+
function isAppointmentTypeFiltered(field) {
|
|
4737
|
+
if (currentPage !== "booking-details") return false;
|
|
4738
|
+
if (!field.appointment_type) return false;
|
|
4739
|
+
const storedType = sessionStorage.getItem("appointment_type");
|
|
4740
|
+
if (!storedType) return false;
|
|
4741
|
+
return field.appointment_type !== storedType;
|
|
4742
|
+
}
|
|
4743
|
+
function evaluateLegacyConditional(field) {
|
|
4744
|
+
if (!field.conditional) {
|
|
4745
|
+
resolveDynamicTitle(field);
|
|
4746
|
+
fireVisibleSideEffects(field, true);
|
|
4747
|
+
return true;
|
|
4748
|
+
}
|
|
4749
|
+
if (!field.trigger || !field.trigger_value) {
|
|
4750
|
+
return true;
|
|
4751
|
+
}
|
|
4752
|
+
const triggerFields = field.trigger.split("|");
|
|
4753
|
+
const triggerExpressions = String(field.trigger_value).split("|");
|
|
4754
|
+
const results = [];
|
|
4755
|
+
triggerFields.forEach((triggerFieldName, i) => {
|
|
4756
|
+
const expression = triggerExpressions[i] ?? "";
|
|
4757
|
+
const parts = expression.split("&");
|
|
4758
|
+
for (const part of parts) {
|
|
4759
|
+
const trimmedPart = part.trim();
|
|
4760
|
+
const parentValue = formValues[triggerFieldName] ?? "";
|
|
4761
|
+
if (trimmedPart === "*") {
|
|
4762
|
+
results.push(parentValue !== "" && parentValue != null && parentValue !== void 0);
|
|
4763
|
+
continue;
|
|
4764
|
+
}
|
|
4765
|
+
const firstChar = trimmedPart[0];
|
|
4766
|
+
if (["<", ">", "!"].includes(firstChar)) {
|
|
4767
|
+
const operand = Number(trimmedPart.substring(1));
|
|
4768
|
+
const numericParentValue = Number(parentValue);
|
|
4769
|
+
switch (firstChar) {
|
|
4770
|
+
case "<":
|
|
4771
|
+
if (numericParentValue < operand) results.push(true);
|
|
4772
|
+
break;
|
|
4773
|
+
case ">":
|
|
4774
|
+
if (numericParentValue > operand) results.push(true);
|
|
4775
|
+
break;
|
|
4776
|
+
case "!":
|
|
4777
|
+
if (String(parentValue) !== String(operand)) results.push(true);
|
|
4778
|
+
break;
|
|
4779
|
+
}
|
|
4780
|
+
} else {
|
|
4781
|
+
results.push(String(parentValue) === String(trimmedPart));
|
|
4782
|
+
}
|
|
4783
|
+
}
|
|
4784
|
+
});
|
|
4785
|
+
const isVisible = results.filter(Boolean).length >= 1;
|
|
4786
|
+
fireVisibleSideEffects(field, isVisible);
|
|
4787
|
+
return isVisible;
|
|
4788
|
+
}
|
|
4789
|
+
const BOOKER_FIELD_KEYS = [
|
|
4790
|
+
"booker_first_name",
|
|
4791
|
+
"booker_last_name",
|
|
4792
|
+
"booker_email",
|
|
4793
|
+
"booker_phone"
|
|
4794
|
+
];
|
|
4795
|
+
function fireVisibleSideEffects(field, isVisible) {
|
|
4796
|
+
if (isVisible) {
|
|
4797
|
+
handleCompanySet(field);
|
|
4798
|
+
handleServiceSet(field);
|
|
4799
|
+
handleResourceSet(field);
|
|
4800
|
+
handleStaffSet(field);
|
|
4801
|
+
handleAddDuration(field);
|
|
4802
|
+
handleBookerFields(field);
|
|
4803
|
+
handleCopyData(field);
|
|
4804
|
+
handleAppointmentTypeStore(field);
|
|
4805
|
+
} else {
|
|
4806
|
+
handleRemoveDuration(field);
|
|
4807
|
+
}
|
|
4808
|
+
}
|
|
4809
|
+
function handleCompanySet(field) {
|
|
4810
|
+
var _a;
|
|
4811
|
+
if (!field.company_set || !field.company_set.length) return;
|
|
4812
|
+
const formService = (_a = formServicesRef.current)[formId] ?? (_a[formId] = {});
|
|
4813
|
+
if (formService.company_id === field.company_set) return;
|
|
4814
|
+
formService.company_id = field.company_set;
|
|
4815
|
+
field.company_id = field.company_set;
|
|
4816
|
+
onCompanySet?.(field.company_set);
|
|
4817
|
+
}
|
|
4818
|
+
function handleServiceSet(field) {
|
|
4819
|
+
var _a;
|
|
4820
|
+
if (!field.service_set) return;
|
|
4821
|
+
const formService = (_a = formServicesRef.current)[formId] ?? (_a[formId] = {});
|
|
4822
|
+
if (formService.service_id === field.service_set) return;
|
|
4823
|
+
formService.service_id = field.service_set;
|
|
4824
|
+
field.service_id = field.service_set;
|
|
4825
|
+
onServiceSet?.(field.service_set);
|
|
4826
|
+
}
|
|
4827
|
+
function handleResourceSet(field) {
|
|
4828
|
+
var _a;
|
|
4829
|
+
if (!field.resource_set || !field.resource_set.length) return;
|
|
4830
|
+
const formService = (_a = formServicesRef.current)[formId] ?? (_a[formId] = {});
|
|
4831
|
+
if (formService.resource_id === field.resource_set) return;
|
|
4832
|
+
formService.resource_id = field.resource_set;
|
|
4833
|
+
field.resource_id = field.resource_set;
|
|
4834
|
+
onResourceSet?.(field.resource_set);
|
|
4835
|
+
}
|
|
4836
|
+
function handleStaffSet(field) {
|
|
4837
|
+
if (!field.staff_set || !field.staff_set.length) return;
|
|
4838
|
+
onStaffSet?.(field.staff_set);
|
|
4839
|
+
}
|
|
4840
|
+
function handleAddDuration(field) {
|
|
4841
|
+
if (!field.add_duration) return;
|
|
4842
|
+
if (field.duration_added) return;
|
|
4843
|
+
field.duration_added = true;
|
|
4844
|
+
onAddDuration?.(field.add_duration);
|
|
4845
|
+
}
|
|
4846
|
+
function handleRemoveDuration(field) {
|
|
4847
|
+
if (!field.add_duration) return;
|
|
4848
|
+
if (!field.duration_added) return;
|
|
4849
|
+
field.duration_added = false;
|
|
4850
|
+
onAddDuration?.(String(-Number(field.add_duration)));
|
|
4851
|
+
}
|
|
4852
|
+
function handleBookerFields(field) {
|
|
4853
|
+
for (const key of BOOKER_FIELD_KEYS) {
|
|
4854
|
+
const isMarked = field[key] === true || field[key] === "true";
|
|
4855
|
+
if (!isMarked) continue;
|
|
4856
|
+
const value = formValues[field.field];
|
|
4857
|
+
if (value) {
|
|
4858
|
+
onUpdateDatastore?.({ [key]: value });
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
}
|
|
4862
|
+
function handleCopyData(field) {
|
|
4863
|
+
const copyData = field.copy_data;
|
|
4864
|
+
if (!copyData?.from || !copyData?.to) return;
|
|
4865
|
+
const currentValue = formValues[field.field] ?? "";
|
|
4866
|
+
let shouldCopy;
|
|
4867
|
+
if (copyData.answer !== void 0 && copyData.answer !== null) {
|
|
4868
|
+
shouldCopy = String(currentValue) === String(copyData.answer);
|
|
4869
|
+
} else {
|
|
4870
|
+
shouldCopy = currentValue !== "" && currentValue != null;
|
|
4871
|
+
}
|
|
4872
|
+
if (!shouldCopy) return;
|
|
4873
|
+
copyData.from.forEach((fromFieldName, index) => {
|
|
4874
|
+
const toFieldName = copyData.to[index];
|
|
4875
|
+
if (!toFieldName) return;
|
|
4876
|
+
const sourceValue = formValues[fromFieldName] ?? getStoredAnswer(formId, fromFieldName);
|
|
4877
|
+
if (sourceValue == null || sourceValue === "") return;
|
|
4878
|
+
if (toFieldName in formValues) {
|
|
4879
|
+
const existingValue = formValues[toFieldName];
|
|
4880
|
+
if (!existingValue) {
|
|
4881
|
+
setFormValues((prev) => ({ ...prev, [toFieldName]: sourceValue }));
|
|
4882
|
+
}
|
|
4883
|
+
}
|
|
4884
|
+
persistAnswer(formId, toFieldName, sourceValue);
|
|
4885
|
+
});
|
|
4886
|
+
}
|
|
4887
|
+
function handleAppointmentTypeStore(field) {
|
|
4888
|
+
if (!field.appointment_type) return;
|
|
4889
|
+
if (currentPage !== "services") return;
|
|
4890
|
+
const existing = sessionStorage.getItem("appointment_type");
|
|
4891
|
+
if (!existing) {
|
|
4892
|
+
sessionStorage.setItem("appointment_type", field.appointment_type);
|
|
4893
|
+
}
|
|
4894
|
+
}
|
|
4895
|
+
async function setExtraItems(field) {
|
|
4896
|
+
if (field.page !== currentPage) return;
|
|
4897
|
+
if (!field.visible && !field.is_visible) return;
|
|
4898
|
+
let extraItemId = field["extra-item"] ?? "";
|
|
4899
|
+
const serviceId = field["service-id"] ?? "";
|
|
4900
|
+
if (field.resource_ids) {
|
|
4901
|
+
const activeResourceId = formServicesRef.current[formId]?.resource_id;
|
|
4902
|
+
if (activeResourceId) {
|
|
4903
|
+
const resourceEntry = field.resource_ids[activeResourceId];
|
|
4904
|
+
if (resourceEntry?.["extra-item"]) {
|
|
4905
|
+
extraItemId = resourceEntry["extra-item"];
|
|
4906
|
+
}
|
|
4907
|
+
}
|
|
4908
|
+
}
|
|
4909
|
+
if (!extraItemId) return;
|
|
4910
|
+
const rawValue = field.type === "heading" ? "1" : formValues[field.field] ?? "0";
|
|
4911
|
+
const numericValue = Number(rawValue);
|
|
4912
|
+
let shouldBeActive;
|
|
4913
|
+
if (isNaN(numericValue)) {
|
|
4914
|
+
const boolResult = evaluateBooleanCondition(rawValue);
|
|
4915
|
+
if (boolResult !== void 0) {
|
|
4916
|
+
shouldBeActive = boolResult;
|
|
4917
|
+
} else {
|
|
4918
|
+
const firstShowKey = field.show ? Object.keys(field.show)[0] : null;
|
|
4919
|
+
shouldBeActive = firstShowKey != null ? String(field.show[firstShowKey]) === String(rawValue) : false;
|
|
4920
|
+
}
|
|
4921
|
+
} else {
|
|
4922
|
+
shouldBeActive = numericValue > 0;
|
|
4923
|
+
}
|
|
4924
|
+
const existingEntry = extraItemsRef.current.find(
|
|
4925
|
+
(item) => item.extraItemId === extraItemId
|
|
4926
|
+
);
|
|
4927
|
+
if (!existingEntry) {
|
|
4928
|
+
if (!shouldBeActive) return;
|
|
4929
|
+
const activeServiceId = formServicesRef.current[formId]?.service_id;
|
|
4930
|
+
if (!activeServiceId) {
|
|
4931
|
+
console.error(
|
|
4932
|
+
"[FormBuilder] Cannot fetch extra item \u2014 no service_id set for form:",
|
|
4933
|
+
formId
|
|
4934
|
+
);
|
|
4935
|
+
return;
|
|
4936
|
+
}
|
|
4937
|
+
if (pendingExtraItemFetchesRef.current.has(extraItemId)) {
|
|
4938
|
+
console.log("[FormBuilder] Skipping duplicate extra item fetch for:", extraItemId);
|
|
4939
|
+
return;
|
|
4940
|
+
}
|
|
4941
|
+
pendingExtraItemFetchesRef.current.add(extraItemId);
|
|
4942
|
+
onProcessing?.(true);
|
|
4943
|
+
const result = await getExtraItemProperties(
|
|
4944
|
+
extraItemId,
|
|
4945
|
+
companyId,
|
|
4946
|
+
activeServiceId,
|
|
4947
|
+
appConfig
|
|
4948
|
+
);
|
|
4949
|
+
pendingExtraItemFetchesRef.current.delete(extraItemId);
|
|
4950
|
+
if (isApiError(result)) {
|
|
4951
|
+
console.error("[FormBuilder] Failed to fetch extra item:", result.message);
|
|
4952
|
+
onProcessing?.(false);
|
|
4953
|
+
return;
|
|
4954
|
+
}
|
|
4955
|
+
const qty = field.type === "heading" ? 1 : numericValue;
|
|
4956
|
+
extraItemsRef.current.push({
|
|
4957
|
+
field: field.field,
|
|
4958
|
+
serviceId,
|
|
4959
|
+
extraItemId,
|
|
4960
|
+
qty
|
|
4961
|
+
});
|
|
4962
|
+
onExtraItemSet?.({
|
|
4963
|
+
item_id: extraItemId,
|
|
4964
|
+
item: { ...result, qty, field: field.field }
|
|
4965
|
+
});
|
|
4966
|
+
onProcessing?.(false);
|
|
4967
|
+
} else if (!shouldBeActive) {
|
|
4968
|
+
extraItemsRef.current = extraItemsRef.current.filter(
|
|
4969
|
+
(item) => item.extraItemId !== extraItemId
|
|
4970
|
+
);
|
|
4971
|
+
onExtraItemSet?.({ item_id: extraItemId, item: null });
|
|
4972
|
+
} else if (existingEntry.qty !== numericValue && field.type !== "heading") {
|
|
4973
|
+
extraItemsRef.current = extraItemsRef.current.filter(
|
|
4974
|
+
(item) => item.extraItemId !== extraItemId
|
|
4975
|
+
);
|
|
4976
|
+
const updatedEntry = {
|
|
4977
|
+
field: field.field,
|
|
4978
|
+
serviceId,
|
|
4979
|
+
extraItemId,
|
|
4980
|
+
qty: numericValue
|
|
4981
|
+
};
|
|
4982
|
+
extraItemsRef.current.push(updatedEntry);
|
|
4983
|
+
onExtraItemChanged?.({ item_id: extraItemId, item: updatedEntry });
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
function evaluateBooleanCondition(value) {
|
|
4987
|
+
const normalised = value?.toLowerCase().trim();
|
|
4988
|
+
if (["true", "yes", "1"].includes(normalised)) return true;
|
|
4989
|
+
if (["false", "no", "0", ""].includes(normalised)) return false;
|
|
4990
|
+
return void 0;
|
|
4991
|
+
}
|
|
4992
|
+
const UK_POSTCODE_REGEX = /^([Gg][Ii][Rr] 0[Aa]{2}|((([A-Za-z][0-9]{1,2})|([A-Za-z][A-HJ-Ya-hj-y][0-9]{1,2})|([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-HJ-Ya-hj-y][0-9]?[A-Za-z]))\s?[0-9][A-Za-z]{2}))$/;
|
|
4993
|
+
function isValidUkPostcode(postcode) {
|
|
4994
|
+
return UK_POSTCODE_REGEX.test(postcode.trim());
|
|
4995
|
+
}
|
|
4996
|
+
function updateFieldState(fieldName, updates) {
|
|
4997
|
+
setFormFields(
|
|
4998
|
+
(prev) => prev.map((f) => f.field === fieldName ? { ...f, ...updates } : f)
|
|
4999
|
+
);
|
|
5000
|
+
}
|
|
5001
|
+
async function performAddressLookup(fieldName) {
|
|
5002
|
+
const field = formFields.find((f) => f.field === fieldName);
|
|
5003
|
+
if (!field) return;
|
|
5004
|
+
const postcodeKey = `${fieldName}_postcode`;
|
|
5005
|
+
const postcodeValue = (formValues[postcodeKey] ?? "").trim();
|
|
5006
|
+
updateFieldState(fieldName, { badPostcode: false, addresses: void 0 });
|
|
5007
|
+
if (!postcodeValue) {
|
|
5008
|
+
updateFieldState(fieldName, { badPostcode: true });
|
|
5009
|
+
return;
|
|
5010
|
+
}
|
|
5011
|
+
if (!isValidUkPostcode(postcodeValue)) {
|
|
5012
|
+
console.error(`[FormBuilder] Invalid postcode format for field "${fieldName}": ${postcodeValue}`);
|
|
5013
|
+
updateFieldState(fieldName, { badPostcode: true });
|
|
5014
|
+
return;
|
|
5015
|
+
}
|
|
5016
|
+
updateFieldState(fieldName, { addressLoading: true });
|
|
5017
|
+
onProcessing?.(true);
|
|
5018
|
+
const result = await getAddressLookup(postcodeValue, appConfig);
|
|
5019
|
+
if (isApiError(result)) {
|
|
5020
|
+
console.error("[FormBuilder] Address lookup failed:", result.message);
|
|
5021
|
+
updateFieldState(fieldName, { addressLoading: false, badPostcode: true });
|
|
5022
|
+
onProcessing?.(false);
|
|
5023
|
+
return;
|
|
5024
|
+
}
|
|
5025
|
+
const addresses = result.map((item) => ({
|
|
5026
|
+
address: item.DPA ?? item.LPI ?? { ADDRESS: "" }
|
|
5027
|
+
}));
|
|
5028
|
+
updateFieldState(fieldName, { addressLoading: false, addresses });
|
|
5029
|
+
onProcessing?.(false);
|
|
5030
|
+
}
|
|
5031
|
+
function handleAddressSelected(event, fieldName) {
|
|
5032
|
+
const selectedAddress = event.target.value;
|
|
5033
|
+
setFieldValue(fieldName, selectedAddress);
|
|
5034
|
+
updateFieldState(fieldName, { selected_address: selectedAddress });
|
|
5035
|
+
onAddressSet?.(selectedAddress);
|
|
5036
|
+
}
|
|
5037
|
+
async function performAwsLookup(fieldName) {
|
|
5038
|
+
const field = formFields.find((f) => f.field === fieldName);
|
|
5039
|
+
if (!field?.lookup?.aws_table) return;
|
|
5040
|
+
const lookup = field.lookup;
|
|
5041
|
+
const matchFields = lookup.match ?? [];
|
|
5042
|
+
updateFieldState(fieldName, {
|
|
5043
|
+
lookupError: false,
|
|
5044
|
+
lookupUsed: false,
|
|
5045
|
+
lookupLoading: true,
|
|
5046
|
+
lookupResponse: null,
|
|
5047
|
+
lookupNameMismatch: false
|
|
5048
|
+
});
|
|
5049
|
+
let primaryReference = "";
|
|
5050
|
+
let primaryDynamoField = "";
|
|
5051
|
+
let secondaryReference = "";
|
|
5052
|
+
let secondaryDynamoField = "";
|
|
5053
|
+
for (const match2 of matchFields) {
|
|
5054
|
+
const { form_field, dynamodb_field } = match2;
|
|
5055
|
+
const value = formValues[form_field] ?? getStoredAnswer(formId, form_field) ?? "";
|
|
5056
|
+
if (form_field === fieldName) {
|
|
5057
|
+
primaryReference = value;
|
|
5058
|
+
primaryDynamoField = dynamodb_field;
|
|
5059
|
+
} else if (!secondaryReference) {
|
|
5060
|
+
secondaryReference = value;
|
|
5061
|
+
secondaryDynamoField = dynamodb_field;
|
|
5062
|
+
}
|
|
5063
|
+
}
|
|
5064
|
+
if (!primaryReference) {
|
|
5065
|
+
console.error(`[FormBuilder] No reference value for field "${fieldName}"`);
|
|
5066
|
+
updateFieldState(fieldName, { lookupError: true, lookupLoading: false });
|
|
5067
|
+
return;
|
|
5068
|
+
}
|
|
5069
|
+
const result = await awsLookup(
|
|
5070
|
+
appConfig,
|
|
5071
|
+
lookup.aws_table,
|
|
5072
|
+
primaryDynamoField,
|
|
5073
|
+
primaryReference,
|
|
5074
|
+
secondaryReference || void 0,
|
|
5075
|
+
secondaryDynamoField || void 0
|
|
5076
|
+
);
|
|
5077
|
+
if (isApiError(result)) {
|
|
5078
|
+
console.error(`[FormBuilder] AWS lookup error for field "${fieldName}":`, result.message);
|
|
5079
|
+
updateFieldState(fieldName, { lookupError: true, lookupLoading: false });
|
|
5080
|
+
return;
|
|
5081
|
+
}
|
|
5082
|
+
updateFieldState(fieldName, { lookupLoading: false });
|
|
5083
|
+
if (result.custom_response_code !== 1) {
|
|
5084
|
+
updateFieldState(fieldName, { lookupError: true });
|
|
5085
|
+
return;
|
|
5086
|
+
}
|
|
5087
|
+
if (result.reference?.used === true) {
|
|
5088
|
+
updateFieldState(fieldName, { lookupUsed: true, lookupError: true });
|
|
5089
|
+
return;
|
|
5090
|
+
}
|
|
5091
|
+
if (secondaryReference && secondaryDynamoField === "name" && result.reference?.name) {
|
|
5092
|
+
const responseName = result.reference.name.toLowerCase().trim();
|
|
5093
|
+
const enteredName = secondaryReference.toLowerCase().trim();
|
|
5094
|
+
if (responseName !== enteredName) {
|
|
5095
|
+
updateFieldState(fieldName, { lookupNameMismatch: true, lookupError: true });
|
|
5096
|
+
return;
|
|
5097
|
+
}
|
|
5098
|
+
}
|
|
5099
|
+
const updatedFields = formFields.map((f) => {
|
|
5100
|
+
const isSecondaryMatch = matchFields.some(
|
|
5101
|
+
(m) => m.form_field === f.field && m.form_field !== fieldName
|
|
5102
|
+
);
|
|
5103
|
+
return isSecondaryMatch ? { ...f, lookupValidated: true } : f;
|
|
5104
|
+
});
|
|
5105
|
+
const storedFieldKey = lookup.store_response_field;
|
|
5106
|
+
let resolvedValue;
|
|
5107
|
+
if (storedFieldKey && result.reference?.[storedFieldKey]) {
|
|
5108
|
+
resolvedValue = String(result.reference[storedFieldKey]);
|
|
5109
|
+
} else if (result.reference?.home_office) {
|
|
5110
|
+
resolvedValue = result.reference.home_office;
|
|
5111
|
+
} else {
|
|
5112
|
+
resolvedValue = primaryReference;
|
|
5113
|
+
}
|
|
5114
|
+
setFormFields(
|
|
5115
|
+
updatedFields.map(
|
|
5116
|
+
(f) => f.field === fieldName ? {
|
|
5117
|
+
...f,
|
|
5118
|
+
lookupSuccess: true,
|
|
5119
|
+
lookupError: false,
|
|
5120
|
+
lookupLoading: false,
|
|
5121
|
+
lookupResponse: result.reference ?? null
|
|
5122
|
+
} : f
|
|
5123
|
+
)
|
|
5124
|
+
);
|
|
5125
|
+
setFieldValue(fieldName, resolvedValue);
|
|
5126
|
+
onAwsLookupSet?.({
|
|
5127
|
+
field: fieldName,
|
|
5128
|
+
reference: result.reference ?? null,
|
|
5129
|
+
success: true
|
|
5130
|
+
});
|
|
5131
|
+
onUpdateDatastore?.({
|
|
5132
|
+
type: "lookupResponse",
|
|
5133
|
+
field: fieldName,
|
|
5134
|
+
lookupResponse: result.reference
|
|
5135
|
+
});
|
|
5136
|
+
refreshVisibility();
|
|
5137
|
+
}
|
|
5138
|
+
function clearAwsLookup(fieldName) {
|
|
5139
|
+
const field = formFields.find((f) => f.field === fieldName);
|
|
5140
|
+
if (!field) return;
|
|
5141
|
+
const matchFields = field.lookup?.match ?? [];
|
|
5142
|
+
const updatedFields = formFields.map((f) => {
|
|
5143
|
+
const isSecondaryMatch = matchFields.some(
|
|
5144
|
+
(m) => m.form_field === f.field && m.form_field !== fieldName
|
|
5145
|
+
);
|
|
5146
|
+
if (isSecondaryMatch) {
|
|
5147
|
+
return { ...f, lookupValidated: false };
|
|
5148
|
+
}
|
|
5149
|
+
if (f.field === fieldName) {
|
|
5150
|
+
return {
|
|
5151
|
+
...f,
|
|
5152
|
+
lookupError: false,
|
|
5153
|
+
lookupUsed: false,
|
|
5154
|
+
lookupLoading: false,
|
|
5155
|
+
lookupResponse: null,
|
|
5156
|
+
lookupSuccess: false,
|
|
5157
|
+
lookupNameMismatch: false
|
|
5158
|
+
};
|
|
5159
|
+
}
|
|
5160
|
+
return f;
|
|
5161
|
+
});
|
|
5162
|
+
setFormFields(updatedFields);
|
|
5163
|
+
const secondaryMatchFieldNames = matchFields.filter((m) => m.form_field !== fieldName).map((m) => m.form_field);
|
|
5164
|
+
setFormValues((prev) => {
|
|
5165
|
+
const next = { ...prev };
|
|
5166
|
+
for (const name of secondaryMatchFieldNames) {
|
|
5167
|
+
next[name] = "";
|
|
5168
|
+
}
|
|
5169
|
+
return next;
|
|
5170
|
+
});
|
|
5171
|
+
setFieldValue(fieldName, "");
|
|
5172
|
+
onAwsLookupSet?.({ field: fieldName, reference: null, success: false });
|
|
5173
|
+
}
|
|
5174
|
+
const VENUE_SEARCH_DEBOUNCE_MS = 500;
|
|
5175
|
+
async function handleVenueSearchInput(event, field) {
|
|
5176
|
+
const IGNORED_KEYS = /* @__PURE__ */ new Set([
|
|
5177
|
+
"ArrowUp",
|
|
5178
|
+
"ArrowDown",
|
|
5179
|
+
"Enter",
|
|
5180
|
+
"Escape",
|
|
5181
|
+
"Tab",
|
|
5182
|
+
"Shift",
|
|
5183
|
+
"Control",
|
|
5184
|
+
"Alt",
|
|
5185
|
+
"Meta"
|
|
5186
|
+
]);
|
|
5187
|
+
if (IGNORED_KEYS.has(event.key)) return;
|
|
5188
|
+
updateFieldState(field.field, {
|
|
5189
|
+
selected_resource: void 0,
|
|
5190
|
+
searching: true,
|
|
5191
|
+
noResults: false,
|
|
5192
|
+
answer: void 0
|
|
5193
|
+
});
|
|
5194
|
+
if (venueSearchTimerRef.current) {
|
|
5195
|
+
clearTimeout(venueSearchTimerRef.current);
|
|
5196
|
+
}
|
|
5197
|
+
venueSearchTimerRef.current = setTimeout(async () => {
|
|
5198
|
+
const query = event.target.value.trim();
|
|
5199
|
+
setSearchText(query);
|
|
5200
|
+
if (!query) {
|
|
5201
|
+
setSuggestions([]);
|
|
5202
|
+
updateFieldState(field.field, { searching: false });
|
|
5203
|
+
return;
|
|
5204
|
+
}
|
|
5205
|
+
try {
|
|
5206
|
+
const result = await searchVenue(companyId, query, appConfig);
|
|
5207
|
+
if (isApiError(result)) {
|
|
5208
|
+
console.error("[FormBuilder] Venue search failed:", result.message);
|
|
5209
|
+
updateFieldState(field.field, { searching: false, noResults: true });
|
|
5210
|
+
setSuggestions([]);
|
|
5211
|
+
return;
|
|
5212
|
+
}
|
|
5213
|
+
let venues = result;
|
|
5214
|
+
if (field.filter_by) {
|
|
5215
|
+
const filterValue = (formValues[field.filter_by] ?? "").toLowerCase().trim();
|
|
5216
|
+
if (filterValue) {
|
|
5217
|
+
venues = venues.filter(
|
|
5218
|
+
(v) => v.venue_type?.toLowerCase().trim() === filterValue
|
|
5219
|
+
);
|
|
5220
|
+
}
|
|
5221
|
+
}
|
|
5222
|
+
setSuggestions(venues);
|
|
5223
|
+
updateFieldState(field.field, {
|
|
5224
|
+
searching: false,
|
|
5225
|
+
noResults: venues.length === 0
|
|
5226
|
+
});
|
|
5227
|
+
} catch (err) {
|
|
5228
|
+
console.error("[FormBuilder] Venue search error:", err);
|
|
5229
|
+
setSuggestions([]);
|
|
5230
|
+
updateFieldState(field.field, { searching: false, noResults: true });
|
|
5231
|
+
}
|
|
5232
|
+
}, VENUE_SEARCH_DEBOUNCE_MS);
|
|
5233
|
+
}
|
|
5234
|
+
function selectVenueSuggestion(suggestion, field) {
|
|
5235
|
+
setSuggestions([]);
|
|
5236
|
+
const displayName = suggestion.pretty_name ?? suggestion.venue_name;
|
|
5237
|
+
setSearchText(displayName);
|
|
5238
|
+
updateFieldState(field.field, {
|
|
5239
|
+
selected_resource: suggestion,
|
|
5240
|
+
answer: displayName,
|
|
5241
|
+
searching: false,
|
|
5242
|
+
noResults: false
|
|
5243
|
+
});
|
|
5244
|
+
setFieldValue(field.field, displayName);
|
|
5245
|
+
onVenueSet?.({
|
|
5246
|
+
venue: suggestion,
|
|
5247
|
+
field: field.field,
|
|
5248
|
+
companyId: suggestion.company_id,
|
|
5249
|
+
resourceId: suggestion.resource_id
|
|
5250
|
+
});
|
|
5251
|
+
}
|
|
5252
|
+
function clearVenueSearch(field) {
|
|
5253
|
+
if (venueSearchTimerRef.current) {
|
|
5254
|
+
clearTimeout(venueSearchTimerRef.current);
|
|
5255
|
+
}
|
|
5256
|
+
setSearchText("");
|
|
5257
|
+
setSuggestions([]);
|
|
5258
|
+
updateFieldState(field.field, {
|
|
5259
|
+
selected_resource: void 0,
|
|
5260
|
+
searching: false,
|
|
5261
|
+
noResults: false,
|
|
5262
|
+
answer: void 0
|
|
5263
|
+
});
|
|
5264
|
+
setFieldValue(field.field, "");
|
|
5265
|
+
onVenueSet?.({ venue: null, field: field.field });
|
|
5266
|
+
}
|
|
5267
|
+
function handleFieldChange(fieldName, value) {
|
|
5268
|
+
setFormValues((prev) => ({ ...prev, [fieldName]: value }));
|
|
5269
|
+
persistAnswer(formId, fieldName, value);
|
|
5270
|
+
}
|
|
5271
|
+
const formErrors = {};
|
|
5272
|
+
for (const field of formFields) {
|
|
5273
|
+
if (field.page !== currentPage) continue;
|
|
5274
|
+
if (!field.visible && !field.is_visible) continue;
|
|
5275
|
+
const value = formValues[field.field] ?? "";
|
|
5276
|
+
const error = validateField(field, value);
|
|
5277
|
+
if (error) formErrors[field.field] = true;
|
|
5278
|
+
}
|
|
5279
|
+
function getFieldWrapperClassName(field) {
|
|
5280
|
+
const classes = ["govuk-form-group"];
|
|
5281
|
+
const isInvalid = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
|
|
5282
|
+
if (isInvalid) {
|
|
5283
|
+
classes.push("govuk-form-group--error");
|
|
5284
|
+
}
|
|
5285
|
+
const isHidden = field.hidden_field || field.rules_count > 0 && !field.is_visible || field.lookupValidated;
|
|
5286
|
+
if (isHidden) {
|
|
5287
|
+
classes.push("hidden-field");
|
|
5288
|
+
}
|
|
5289
|
+
return classes.join(" ");
|
|
5290
|
+
}
|
|
5291
|
+
function renderLabel(field) {
|
|
5292
|
+
return /* @__PURE__ */ jsx("div", { className: "govuk-label-wrapper", children: /* @__PURE__ */ jsxs("label", { className: "govuk-label govuk-label--m", htmlFor: field.field, children: [
|
|
5293
|
+
field.rendered_title ?? field.title,
|
|
5294
|
+
field.required && " *"
|
|
5295
|
+
] }) });
|
|
5296
|
+
}
|
|
5297
|
+
function renderHint(field) {
|
|
5298
|
+
if (!field.helptext) return null;
|
|
5299
|
+
return /* @__PURE__ */ jsx("div", { id: `${field.field}-hint`, className: "govuk-hint", dangerouslySetInnerHTML: { __html: field.helptext } });
|
|
5300
|
+
}
|
|
5301
|
+
function renderErrors(field) {
|
|
5302
|
+
if (!shouldShowError(field.field)) return null;
|
|
5303
|
+
const error = validateField(field, formValues[field.field] ?? "");
|
|
5304
|
+
if (!error) return null;
|
|
5305
|
+
return /* @__PURE__ */ jsxs("p", { className: "govuk-error-message", children: [
|
|
5306
|
+
/* @__PURE__ */ jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
|
|
5307
|
+
getErrorMessage(error)
|
|
5308
|
+
] });
|
|
5309
|
+
}
|
|
5310
|
+
function renderField(field) {
|
|
5311
|
+
switch (field.type) {
|
|
5312
|
+
case "text":
|
|
5313
|
+
case "number":
|
|
5314
|
+
case "email":
|
|
5315
|
+
case "date":
|
|
5316
|
+
return renderTextualField(field);
|
|
5317
|
+
case "textarea":
|
|
5318
|
+
return renderTextarea(field);
|
|
5319
|
+
case "radio":
|
|
5320
|
+
return renderRadio(field);
|
|
5321
|
+
case "checkbox":
|
|
5322
|
+
return renderCheckbox(field);
|
|
5323
|
+
case "dropdown":
|
|
5324
|
+
return renderDropdown(field);
|
|
5325
|
+
case "heading":
|
|
5326
|
+
return renderHeading(field);
|
|
5327
|
+
case "submit":
|
|
5328
|
+
return renderSubmitField(field);
|
|
5329
|
+
default:
|
|
5330
|
+
return null;
|
|
5331
|
+
}
|
|
5332
|
+
}
|
|
5333
|
+
function renderTextualField(field) {
|
|
5334
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5335
|
+
renderLabel(field),
|
|
5336
|
+
renderHint(field),
|
|
5337
|
+
renderErrors(field),
|
|
5338
|
+
field.address_lookup ? renderAddressLookup(field) : field.lookup?.aws_table ? renderAwsLookup(field) : field.resource_lookup ? renderVenueSearch(field) : renderPlainInput(field)
|
|
5339
|
+
] });
|
|
5340
|
+
}
|
|
5341
|
+
function renderPlainInput(field) {
|
|
5342
|
+
const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
|
|
5343
|
+
const inputProps = {
|
|
5344
|
+
id: field.field,
|
|
5345
|
+
type: getInputType(field),
|
|
5346
|
+
"aria-required": field.required,
|
|
5347
|
+
value: formValues[field.field] ?? "",
|
|
5348
|
+
className: ["govuk-input", isError ? "govuk-input--error" : ""].join(" ").trim(),
|
|
5349
|
+
onChange: (e) => {
|
|
5350
|
+
handleFieldChange(field.field, e.target.value);
|
|
5351
|
+
markAsDirty(field.field);
|
|
5352
|
+
},
|
|
5353
|
+
onBlur: () => markAsTouched(field.field)
|
|
5354
|
+
};
|
|
5355
|
+
if (field.type === "date" && field.hide_dates_in_future) {
|
|
5356
|
+
inputProps.max = (/* @__PURE__ */ new Date()).toISOString().split("T")[0];
|
|
5357
|
+
}
|
|
5358
|
+
return /* @__PURE__ */ jsx("input", { ...inputProps });
|
|
5359
|
+
}
|
|
5360
|
+
function renderTextarea(field) {
|
|
5361
|
+
const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
|
|
5362
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5363
|
+
renderLabel(field),
|
|
5364
|
+
renderHint(field),
|
|
5365
|
+
renderErrors(field),
|
|
5366
|
+
/* @__PURE__ */ jsx(
|
|
5367
|
+
"textarea",
|
|
5368
|
+
{
|
|
5369
|
+
id: field.field,
|
|
5370
|
+
className: ["govuk-textarea", isError ? "govuk-textarea--error" : ""].join(" ").trim(),
|
|
5371
|
+
rows: 5,
|
|
5372
|
+
"aria-required": field.required,
|
|
5373
|
+
value: formValues[field.field] ?? "",
|
|
5374
|
+
onChange: (e) => {
|
|
5375
|
+
handleFieldChange(field.field, e.target.value);
|
|
5376
|
+
markAsDirty(field.field);
|
|
5377
|
+
},
|
|
5378
|
+
onBlur: () => markAsTouched(field.field)
|
|
5379
|
+
}
|
|
5380
|
+
)
|
|
5381
|
+
] });
|
|
5382
|
+
}
|
|
5383
|
+
function renderRadio(field) {
|
|
5384
|
+
const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
|
|
5385
|
+
return /* @__PURE__ */ jsx("div", { className: "govuk-form-group", children: /* @__PURE__ */ jsxs("fieldset", { className: "govuk-fieldset", "aria-required": field.required, children: [
|
|
5386
|
+
/* @__PURE__ */ jsxs("legend", { className: "govuk-fieldset__legend govuk-fieldset__legend--m govuk-fieldset__legend--m-inverse", children: [
|
|
5387
|
+
field.rendered_title ?? field.title,
|
|
5388
|
+
field.required && " *"
|
|
5389
|
+
] }),
|
|
5390
|
+
renderHint(field),
|
|
5391
|
+
isError && /* @__PURE__ */ jsxs("p", { className: "govuk-error-message", children: [
|
|
5392
|
+
/* @__PURE__ */ jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
|
|
5393
|
+
getErrorMessage(validateField(field, formValues[field.field] ?? ""))
|
|
5394
|
+
] }),
|
|
5395
|
+
/* @__PURE__ */ jsx("div", { className: "govuk-radios", children: (field.radio_options ?? []).map((option) => /* @__PURE__ */ jsxs("div", { className: "govuk-radios__item", children: [
|
|
5396
|
+
/* @__PURE__ */ jsx(
|
|
5397
|
+
"input",
|
|
5398
|
+
{
|
|
5399
|
+
className: "govuk-radios__input",
|
|
5400
|
+
type: "radio",
|
|
5401
|
+
id: `${field.field}_${option.value}`,
|
|
5402
|
+
name: field.field,
|
|
5403
|
+
value: option.value,
|
|
5404
|
+
checked: formValues[field.field] === option.value,
|
|
5405
|
+
onChange: () => {
|
|
5406
|
+
handleFieldChange(field.field, option.value);
|
|
5407
|
+
markAsDirty(field.field);
|
|
5408
|
+
markAsTouched(field.field);
|
|
5409
|
+
}
|
|
5410
|
+
}
|
|
5411
|
+
),
|
|
5412
|
+
/* @__PURE__ */ jsx("label", { className: "govuk-label govuk-radios__label", htmlFor: `${field.field}_${option.value}`, children: option.title })
|
|
5413
|
+
] }, option.value)) })
|
|
5414
|
+
] }) });
|
|
5415
|
+
}
|
|
5416
|
+
function renderCheckbox(field) {
|
|
5417
|
+
const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
|
|
5418
|
+
return /* @__PURE__ */ jsxs("div", { className: "govuk-form-group", children: [
|
|
5419
|
+
renderHint(field),
|
|
5420
|
+
isError && /* @__PURE__ */ jsxs("p", { className: "govuk-error-message", children: [
|
|
5421
|
+
/* @__PURE__ */ jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
|
|
5422
|
+
"This field is required."
|
|
5423
|
+
] }),
|
|
5424
|
+
/* @__PURE__ */ jsx("div", { className: "govuk-checkboxes", children: /* @__PURE__ */ jsxs("div", { className: "govuk-checkboxes__item", children: [
|
|
5425
|
+
/* @__PURE__ */ jsx(
|
|
5426
|
+
"input",
|
|
5427
|
+
{
|
|
5428
|
+
className: "govuk-checkboxes__input",
|
|
5429
|
+
id: field.field,
|
|
5430
|
+
type: "checkbox",
|
|
5431
|
+
checked: formValues[field.field] === "true",
|
|
5432
|
+
onChange: (e) => {
|
|
5433
|
+
handleFieldChange(field.field, String(e.target.checked));
|
|
5434
|
+
markAsDirty(field.field);
|
|
5435
|
+
markAsTouched(field.field);
|
|
5436
|
+
}
|
|
5437
|
+
}
|
|
5438
|
+
),
|
|
5439
|
+
/* @__PURE__ */ jsxs("label", { className: "govuk-label govuk-checkboxes__label govuk-label--m--inverse", htmlFor: field.field, children: [
|
|
5440
|
+
field.rendered_title ?? field.title,
|
|
5441
|
+
field.required && " *"
|
|
5442
|
+
] })
|
|
5443
|
+
] }) })
|
|
5444
|
+
] });
|
|
5445
|
+
}
|
|
5446
|
+
function renderDropdown(field) {
|
|
5447
|
+
const isError = shouldShowError(field.field) && validateField(field, formValues[field.field] ?? "") != null;
|
|
5448
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5449
|
+
renderLabel(field),
|
|
5450
|
+
renderHint(field),
|
|
5451
|
+
renderErrors(field),
|
|
5452
|
+
/* @__PURE__ */ jsxs(
|
|
5453
|
+
"select",
|
|
5454
|
+
{
|
|
5455
|
+
id: field.field,
|
|
5456
|
+
className: ["govuk-select govuk-select--inverse", isError ? "govuk-select--error" : ""].join(" ").trim(),
|
|
5457
|
+
"aria-required": field.required ? "true" : void 0,
|
|
5458
|
+
value: formValues[field.field] ?? "",
|
|
5459
|
+
onChange: (e) => {
|
|
5460
|
+
handleFieldChange(field.field, e.target.value);
|
|
5461
|
+
markAsDirty(field.field);
|
|
5462
|
+
markAsTouched(field.field);
|
|
5463
|
+
},
|
|
5464
|
+
children: [
|
|
5465
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "Please select" }),
|
|
5466
|
+
(field.options ?? []).filter((opt) => opt.visible).map((opt) => /* @__PURE__ */ jsx("option", { value: opt.value, children: opt.title }, opt.value))
|
|
5467
|
+
]
|
|
5468
|
+
}
|
|
5469
|
+
)
|
|
5470
|
+
] });
|
|
5471
|
+
}
|
|
5472
|
+
function renderHeading(field) {
|
|
5473
|
+
const componentType = field.component_type;
|
|
5474
|
+
if (componentType === "govbook-warning_box") {
|
|
5475
|
+
return /* @__PURE__ */ jsx("div", { className: "warning-box", children: /* @__PURE__ */ jsxs("div", { className: "content", children: [
|
|
5476
|
+
/* @__PURE__ */ jsx("span", { className: "warning-box__title", children: field.rendered_title ?? field.title }),
|
|
5477
|
+
/* @__PURE__ */ jsx("span", { className: "warning-box__message", dangerouslySetInnerHTML: { __html: field.component_text ?? "" } })
|
|
5478
|
+
] }) });
|
|
5479
|
+
}
|
|
5480
|
+
if (componentType === "govbook-information_box") {
|
|
5481
|
+
return /* @__PURE__ */ jsx("div", { className: "information-box", children: /* @__PURE__ */ jsxs("div", { className: "content", children: [
|
|
5482
|
+
/* @__PURE__ */ jsx("span", { className: "information-box__title", children: field.rendered_title ?? field.title }),
|
|
5483
|
+
/* @__PURE__ */ jsx("span", { className: "information-box__message", dangerouslySetInnerHTML: { __html: field.component_text ?? "" } })
|
|
5484
|
+
] }) });
|
|
5485
|
+
}
|
|
5486
|
+
if (componentType === "body") {
|
|
5487
|
+
return /* @__PURE__ */ jsx("div", { className: "govuk-body govuk-body--inverse", dangerouslySetInnerHTML: { __html: field.component_text ?? "" } });
|
|
5488
|
+
}
|
|
5489
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5490
|
+
/* @__PURE__ */ jsx("h3", { className: "govuk-heading-m govuk-heading-m--inverse", children: field.rendered_title ?? field.title }),
|
|
5491
|
+
renderHint(field)
|
|
5492
|
+
] });
|
|
5493
|
+
}
|
|
5494
|
+
function renderSubmitField(field) {
|
|
5495
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5496
|
+
renderHint(field),
|
|
5497
|
+
showSubmit && /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx("button", { type: "button", className: "nhsuk-button govuk-button", onClick: handleSubmit, children: field.rendered_title ?? field.title }) })
|
|
5498
|
+
] });
|
|
5499
|
+
}
|
|
5500
|
+
function renderAddressLookup(field) {
|
|
5501
|
+
return /* @__PURE__ */ jsxs("div", { className: "address-lookup", children: [
|
|
5502
|
+
/* @__PURE__ */ jsxs("div", { className: "govuk-input__wrapper", children: [
|
|
5503
|
+
/* @__PURE__ */ jsx("div", { className: "govuk-form-group", children: /* @__PURE__ */ jsx(
|
|
5504
|
+
"input",
|
|
5505
|
+
{
|
|
5506
|
+
id: `${field.field}_postcode`,
|
|
5507
|
+
type: "text",
|
|
5508
|
+
value: formValues[`${field.field}_postcode`] ?? "",
|
|
5509
|
+
onChange: (e) => handleFieldChange(`${field.field}_postcode`, e.target.value),
|
|
5510
|
+
className: ["govuk-input", field.badPostcode ? "govuk-input--error" : ""].join(" ").trim()
|
|
5511
|
+
}
|
|
5512
|
+
) }),
|
|
5513
|
+
/* @__PURE__ */ jsx(
|
|
5514
|
+
"button",
|
|
5515
|
+
{
|
|
5516
|
+
type: "button",
|
|
5517
|
+
className: "govuk-button govuk-button--secondary",
|
|
5518
|
+
disabled: field.addressLoading,
|
|
5519
|
+
onClick: () => performAddressLookup(field.field),
|
|
5520
|
+
children: field.addressLoading ? "Searching..." : "Find address"
|
|
5521
|
+
}
|
|
5522
|
+
)
|
|
5523
|
+
] }),
|
|
5524
|
+
field.badPostcode && /* @__PURE__ */ jsxs("p", { className: "govuk-error-message", children: [
|
|
5525
|
+
/* @__PURE__ */ jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
|
|
5526
|
+
"Please enter a valid UK postcode."
|
|
5527
|
+
] }),
|
|
5528
|
+
field.addresses && field.addresses.length > 0 && /* @__PURE__ */ jsxs("div", { className: "govuk-form-group", children: [
|
|
5529
|
+
/* @__PURE__ */ jsx("label", { className: "govuk-label", htmlFor: `${field.field}_select`, children: "Select address below" }),
|
|
5530
|
+
/* @__PURE__ */ jsxs(
|
|
5531
|
+
"select",
|
|
5532
|
+
{
|
|
5533
|
+
id: `${field.field}_select`,
|
|
5534
|
+
className: "govuk-select",
|
|
5535
|
+
onChange: (e) => handleAddressSelected(e, field.field),
|
|
5536
|
+
children: [
|
|
5537
|
+
/* @__PURE__ */ jsx("option", { value: "", children: "Select address" }),
|
|
5538
|
+
field.addresses.map((item, idx) => /* @__PURE__ */ jsx("option", { value: item.address.ADDRESS, children: item.address.ADDRESS }, idx))
|
|
5539
|
+
]
|
|
5540
|
+
}
|
|
5541
|
+
)
|
|
5542
|
+
] })
|
|
5543
|
+
] });
|
|
5544
|
+
}
|
|
5545
|
+
function renderAwsLookup(field) {
|
|
5546
|
+
return /* @__PURE__ */ jsxs("div", { className: "aws-lookup", children: [
|
|
5547
|
+
!field.lookupSuccess && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
5548
|
+
/* @__PURE__ */ jsx("div", { className: "govuk-input__wrapper", children: /* @__PURE__ */ jsx(
|
|
5549
|
+
"input",
|
|
5550
|
+
{
|
|
5551
|
+
id: field.field,
|
|
5552
|
+
type: field.type,
|
|
5553
|
+
"aria-required": field.required,
|
|
5554
|
+
value: formValues[field.field] ?? "",
|
|
5555
|
+
onChange: (e) => handleFieldChange(field.field, e.target.value),
|
|
5556
|
+
className: ["govuk-input", field.lookupError || formErrors[field.field] ? "govuk-input--error" : ""].join(" ").trim()
|
|
5557
|
+
}
|
|
5558
|
+
) }),
|
|
5559
|
+
/* @__PURE__ */ jsx("div", { className: "govuk-button-group", children: /* @__PURE__ */ jsx(
|
|
5560
|
+
"button",
|
|
5561
|
+
{
|
|
5562
|
+
type: "button",
|
|
5563
|
+
className: "govuk-button govuk-button--secondary lookup-reference",
|
|
5564
|
+
disabled: field.lookupLoading,
|
|
5565
|
+
onClick: () => performAwsLookup(field.field),
|
|
5566
|
+
children: field.lookupLoading ? "Checking..." : "Check reference"
|
|
5567
|
+
}
|
|
5568
|
+
) })
|
|
5569
|
+
] }),
|
|
5570
|
+
field.lookupLoading && /* @__PURE__ */ jsx("div", { className: "govuk-hint", children: "Checking reference..." }),
|
|
5571
|
+
field.lookupError && !field.lookupUsed && !field.lookupNameMismatch && /* @__PURE__ */ jsxs("p", { className: "govuk-error-message", children: [
|
|
5572
|
+
/* @__PURE__ */ jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
|
|
5573
|
+
"Reference not found. Please check and try again."
|
|
5574
|
+
] }),
|
|
5575
|
+
field.lookupUsed && /* @__PURE__ */ jsxs("p", { className: "govuk-error-message", children: [
|
|
5576
|
+
/* @__PURE__ */ jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
|
|
5577
|
+
"This reference has already been used."
|
|
5578
|
+
] }),
|
|
5579
|
+
field.lookupNameMismatch && /* @__PURE__ */ jsxs("p", { className: "govuk-error-message", children: [
|
|
5580
|
+
/* @__PURE__ */ jsx("span", { className: "govuk-visually-hidden", children: "Error:" }),
|
|
5581
|
+
"The name does not match the reference. Please check and try again."
|
|
5582
|
+
] }),
|
|
5583
|
+
field.lookupSuccess && field.lookupResponse && /* @__PURE__ */ jsxs("div", { className: "govuk-inset-text", children: [
|
|
5584
|
+
/* @__PURE__ */ jsx("p", { className: "govuk-body", children: /* @__PURE__ */ jsx("strong", { children: "Reference verified" }) }),
|
|
5585
|
+
field.lookupResponse.name && /* @__PURE__ */ jsxs("p", { className: "govuk-body", children: [
|
|
5586
|
+
"Name: ",
|
|
5587
|
+
field.lookupResponse.name
|
|
5588
|
+
] }),
|
|
5589
|
+
field.lookupResponse.home_office && /* @__PURE__ */ jsxs("p", { className: "govuk-body", children: [
|
|
5590
|
+
"Reference: ",
|
|
5591
|
+
field.lookupResponse.home_office
|
|
5592
|
+
] }),
|
|
5593
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "govuk-button govuk-button--secondary", onClick: () => clearAwsLookup(field.field), children: "Clear" })
|
|
5594
|
+
] })
|
|
5595
|
+
] });
|
|
5596
|
+
}
|
|
5597
|
+
function renderVenueSearch(field) {
|
|
5598
|
+
return /* @__PURE__ */ jsxs("div", { className: "govuk-form-group resource-lookup", children: [
|
|
5599
|
+
/* @__PURE__ */ jsxs("div", { className: "govuk-input__wrapper", children: [
|
|
5600
|
+
/* @__PURE__ */ jsx(
|
|
5601
|
+
"input",
|
|
5602
|
+
{
|
|
5603
|
+
id: field.field,
|
|
5604
|
+
type: "text",
|
|
5605
|
+
className: "govuk-input govuk-input--with-clear",
|
|
5606
|
+
value: searchText,
|
|
5607
|
+
placeholder: "Start typing to search...",
|
|
5608
|
+
autoComplete: "off",
|
|
5609
|
+
onChange: () => {
|
|
5610
|
+
},
|
|
5611
|
+
onKeyDown: (e) => handleVenueSearchInput(e, field)
|
|
5612
|
+
}
|
|
5613
|
+
),
|
|
5614
|
+
searchText && /* @__PURE__ */ jsx(
|
|
5615
|
+
"div",
|
|
5616
|
+
{
|
|
5617
|
+
role: "button",
|
|
5618
|
+
tabIndex: 0,
|
|
5619
|
+
className: "govuk-input__suffix",
|
|
5620
|
+
"aria-label": "Clear search",
|
|
5621
|
+
onClick: () => clearVenueSearch(field),
|
|
5622
|
+
onKeyDown: (e) => {
|
|
5623
|
+
if (e.key === "Enter" || e.key === " ") clearVenueSearch(field);
|
|
5624
|
+
},
|
|
5625
|
+
children: /* @__PURE__ */ jsx("b", { "aria-hidden": "true", children: "\xD7" })
|
|
5626
|
+
}
|
|
5627
|
+
)
|
|
5628
|
+
] }),
|
|
5629
|
+
field.searching && /* @__PURE__ */ jsx("span", { className: "govuk-hint", children: "Searching\u2026" }),
|
|
5630
|
+
field.noResults && /* @__PURE__ */ jsx("span", { className: "govuk-hint", children: "No results found" }),
|
|
5631
|
+
suggestions.length > 0 && /* @__PURE__ */ jsx("ul", { className: "resource-suggestions", role: "listbox", children: suggestions.map((suggestion, idx) => /* @__PURE__ */ jsx(
|
|
5632
|
+
"li",
|
|
5633
|
+
{
|
|
5634
|
+
role: "option",
|
|
5635
|
+
tabIndex: 0,
|
|
5636
|
+
className: "resource-suggestion",
|
|
5637
|
+
onClick: () => selectVenueSuggestion(suggestion, field),
|
|
5638
|
+
onKeyDown: (e) => {
|
|
5639
|
+
if (e.key === "Enter") selectVenueSuggestion(suggestion, field);
|
|
5640
|
+
},
|
|
5641
|
+
children: suggestion.pretty_name ?? suggestion.venue_name
|
|
5642
|
+
},
|
|
5643
|
+
idx
|
|
5644
|
+
)) }),
|
|
5645
|
+
field.answer && field.selected_resource?.description && /* @__PURE__ */ jsxs("div", { className: "selected-venue-detail", children: [
|
|
5646
|
+
/* @__PURE__ */ jsx("p", { className: "govuk-label govuk-fieldset__legend--m pt-3", children: "Description" }),
|
|
5647
|
+
/* @__PURE__ */ jsx("p", { children: field.selected_resource.description }),
|
|
5648
|
+
field.selected_resource.image && /* @__PURE__ */ jsx("img", { className: "selected-venue", src: field.selected_resource.image, alt: "" })
|
|
5649
|
+
] })
|
|
5650
|
+
] });
|
|
5651
|
+
}
|
|
5652
|
+
function handleSubmit() {
|
|
5653
|
+
const isFormValid = formFields.filter((f) => f.show_on_this_page && (f.visible || f.is_visible)).every((f) => validateField(f, formValues[f.field] ?? "") === null);
|
|
5654
|
+
if (!isFormValid) {
|
|
5655
|
+
markAllAsTouched();
|
|
5656
|
+
return;
|
|
5657
|
+
}
|
|
5658
|
+
onFormSubmit?.(formValues);
|
|
5659
|
+
onSchema?.(schema);
|
|
5660
|
+
}
|
|
5661
|
+
if (loading) {
|
|
5662
|
+
return /* @__PURE__ */ jsx("div", { className: "govuk-body", children: "Loading form..." });
|
|
5663
|
+
}
|
|
5664
|
+
if (!formFields.length) {
|
|
5665
|
+
return null;
|
|
5666
|
+
}
|
|
5667
|
+
return /* @__PURE__ */ jsxs("form", { className: "govuk-form", onSubmit: (e) => {
|
|
5668
|
+
e.preventDefault();
|
|
5669
|
+
handleSubmit();
|
|
5670
|
+
}, children: [
|
|
5671
|
+
formFields.filter((field) => field.show_on_this_page).map((field, index) => /* @__PURE__ */ jsx("div", { className: getFieldWrapperClassName(field), children: (field.is_visible || !field.rules_count) && renderField(field) }, field.field || index)),
|
|
5672
|
+
showSubmit && /* @__PURE__ */ jsx("button", { type: "submit", className: "nhsuk-button govuk-button", children: "Continue" })
|
|
5673
|
+
] });
|
|
5674
|
+
}
|
|
5675
|
+
|
|
5676
|
+
export { BookingForm, ContactDetailsForm, RegistrationForm, ResetPasswordForm, SchemaFormBuilder, compose, email, hydrateField, minLen, phone, required, ukPostcode };
|
|
1397
5677
|
//# sourceMappingURL=index.mjs.map
|
|
1398
5678
|
//# sourceMappingURL=index.mjs.map
|