@underverse-ui/underverse 0.1.8 → 0.1.11
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.cjs +2373 -125
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +2357 -126
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3731,6 +3731,113 @@ var Pagination = ({
|
|
|
3731
3731
|
] })
|
|
3732
3732
|
] });
|
|
3733
3733
|
};
|
|
3734
|
+
var SimplePagination = ({
|
|
3735
|
+
page,
|
|
3736
|
+
totalPages,
|
|
3737
|
+
onChange,
|
|
3738
|
+
className,
|
|
3739
|
+
size = "md",
|
|
3740
|
+
variant = "outline",
|
|
3741
|
+
disabled = false,
|
|
3742
|
+
showInfo = false,
|
|
3743
|
+
totalItems,
|
|
3744
|
+
pageSize = 10
|
|
3745
|
+
}) => {
|
|
3746
|
+
if (totalPages <= 1) return null;
|
|
3747
|
+
return /* @__PURE__ */ jsxs22("div", { className: cn("flex flex-col gap-2", className), children: [
|
|
3748
|
+
showInfo && totalItems && /* @__PURE__ */ jsxs22("div", { className: "text-sm text-muted-foreground text-center", children: [
|
|
3749
|
+
"Page ",
|
|
3750
|
+
page,
|
|
3751
|
+
" of ",
|
|
3752
|
+
totalPages,
|
|
3753
|
+
" (",
|
|
3754
|
+
totalItems,
|
|
3755
|
+
" total items)"
|
|
3756
|
+
] }),
|
|
3757
|
+
/* @__PURE__ */ jsxs22("div", { className: "flex items-center justify-between", children: [
|
|
3758
|
+
/* @__PURE__ */ jsx24(Button_default, { variant, size, icon: ChevronLeft, onClick: () => onChange(Math.max(1, page - 1)), disabled: disabled || page === 1, children: "Previous" }),
|
|
3759
|
+
/* @__PURE__ */ jsxs22("div", { className: "flex items-center gap-2 text-sm text-muted-foreground", children: [
|
|
3760
|
+
/* @__PURE__ */ jsx24("span", { children: "Page" }),
|
|
3761
|
+
/* @__PURE__ */ jsx24("span", { className: "font-medium text-foreground", children: page }),
|
|
3762
|
+
/* @__PURE__ */ jsx24("span", { children: "of" }),
|
|
3763
|
+
/* @__PURE__ */ jsx24("span", { className: "font-medium text-foreground", children: totalPages })
|
|
3764
|
+
] }),
|
|
3765
|
+
/* @__PURE__ */ jsx24(
|
|
3766
|
+
Button_default,
|
|
3767
|
+
{
|
|
3768
|
+
variant,
|
|
3769
|
+
size,
|
|
3770
|
+
iconRight: ChevronRight2,
|
|
3771
|
+
onClick: () => onChange(Math.min(totalPages, page + 1)),
|
|
3772
|
+
disabled: disabled || page === totalPages,
|
|
3773
|
+
children: "Next"
|
|
3774
|
+
}
|
|
3775
|
+
)
|
|
3776
|
+
] })
|
|
3777
|
+
] });
|
|
3778
|
+
};
|
|
3779
|
+
var CompactPagination = ({
|
|
3780
|
+
page,
|
|
3781
|
+
totalPages,
|
|
3782
|
+
onChange,
|
|
3783
|
+
className,
|
|
3784
|
+
variant = "outline",
|
|
3785
|
+
disabled = false
|
|
3786
|
+
}) => {
|
|
3787
|
+
if (totalPages <= 1) return null;
|
|
3788
|
+
return /* @__PURE__ */ jsxs22("nav", { className: cn("flex items-center gap-1", className), "aria-label": "Compact Pagination", children: [
|
|
3789
|
+
/* @__PURE__ */ jsx24(
|
|
3790
|
+
Button_default,
|
|
3791
|
+
{
|
|
3792
|
+
variant,
|
|
3793
|
+
size: "icon",
|
|
3794
|
+
icon: ChevronsLeft,
|
|
3795
|
+
onClick: () => onChange(1),
|
|
3796
|
+
disabled: disabled || page === 1,
|
|
3797
|
+
title: "First page",
|
|
3798
|
+
"aria-label": "First page"
|
|
3799
|
+
}
|
|
3800
|
+
),
|
|
3801
|
+
/* @__PURE__ */ jsx24(
|
|
3802
|
+
Button_default,
|
|
3803
|
+
{
|
|
3804
|
+
variant,
|
|
3805
|
+
size: "icon",
|
|
3806
|
+
icon: ChevronLeft,
|
|
3807
|
+
onClick: () => onChange(Math.max(1, page - 1)),
|
|
3808
|
+
disabled: disabled || page === 1,
|
|
3809
|
+
title: "Previous page"
|
|
3810
|
+
}
|
|
3811
|
+
),
|
|
3812
|
+
/* @__PURE__ */ jsxs22("div", { className: "px-2 py-1 text-sm text-muted-foreground min-w-[4rem] text-center", children: [
|
|
3813
|
+
page,
|
|
3814
|
+
" / ",
|
|
3815
|
+
totalPages
|
|
3816
|
+
] }),
|
|
3817
|
+
/* @__PURE__ */ jsx24(
|
|
3818
|
+
Button_default,
|
|
3819
|
+
{
|
|
3820
|
+
variant,
|
|
3821
|
+
size: "icon",
|
|
3822
|
+
icon: ChevronRight2,
|
|
3823
|
+
onClick: () => onChange(Math.min(totalPages, page + 1)),
|
|
3824
|
+
disabled: disabled || page === totalPages,
|
|
3825
|
+
title: "Next page"
|
|
3826
|
+
}
|
|
3827
|
+
),
|
|
3828
|
+
/* @__PURE__ */ jsx24(
|
|
3829
|
+
Button_default,
|
|
3830
|
+
{
|
|
3831
|
+
variant,
|
|
3832
|
+
size: "icon",
|
|
3833
|
+
icon: ChevronsRight,
|
|
3834
|
+
onClick: () => onChange(totalPages),
|
|
3835
|
+
disabled: disabled || page === totalPages,
|
|
3836
|
+
title: "Last page"
|
|
3837
|
+
}
|
|
3838
|
+
)
|
|
3839
|
+
] });
|
|
3840
|
+
};
|
|
3734
3841
|
|
|
3735
3842
|
// ../../components/ui/Section.tsx
|
|
3736
3843
|
import React20 from "react";
|
|
@@ -4193,6 +4300,215 @@ var DatePicker = ({
|
|
|
4193
4300
|
isOpen && dropdownPosition && typeof window !== "undefined" && createPortal7(datePickerContent, document.body)
|
|
4194
4301
|
] });
|
|
4195
4302
|
};
|
|
4303
|
+
var DateRangePicker = ({ startDate, endDate, onChange, placeholder = "Select date range...", className }) => {
|
|
4304
|
+
const [isOpen, setIsOpen] = React21.useState(false);
|
|
4305
|
+
const [dropdownPosition, setDropdownPosition] = React21.useState(null);
|
|
4306
|
+
const triggerRef = React21.useRef(null);
|
|
4307
|
+
const panelRef = React21.useRef(null);
|
|
4308
|
+
const [viewDate, setViewDate] = React21.useState(startDate || /* @__PURE__ */ new Date());
|
|
4309
|
+
const [tempStart, setTempStart] = React21.useState(startDate || null);
|
|
4310
|
+
const [tempEnd, setTempEnd] = React21.useState(endDate || null);
|
|
4311
|
+
const [hoveredDate, setHoveredDate] = React21.useState(null);
|
|
4312
|
+
React21.useEffect(() => {
|
|
4313
|
+
setTempStart(startDate || null);
|
|
4314
|
+
}, [startDate]);
|
|
4315
|
+
React21.useEffect(() => {
|
|
4316
|
+
setTempEnd(endDate || null);
|
|
4317
|
+
}, [endDate]);
|
|
4318
|
+
const calculatePosition = React21.useCallback(() => {
|
|
4319
|
+
if (!triggerRef.current) return null;
|
|
4320
|
+
const rect = triggerRef.current.getBoundingClientRect();
|
|
4321
|
+
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
4322
|
+
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
|
4323
|
+
return { top: rect.bottom + scrollTop + 4, left: rect.left + scrollLeft, width: rect.width };
|
|
4324
|
+
}, []);
|
|
4325
|
+
React21.useEffect(() => {
|
|
4326
|
+
if (!isOpen) return;
|
|
4327
|
+
const handler = () => {
|
|
4328
|
+
const pos = calculatePosition();
|
|
4329
|
+
if (pos) setDropdownPosition(pos);
|
|
4330
|
+
};
|
|
4331
|
+
window.addEventListener("resize", handler);
|
|
4332
|
+
window.addEventListener("scroll", handler, true);
|
|
4333
|
+
return () => {
|
|
4334
|
+
window.removeEventListener("resize", handler);
|
|
4335
|
+
window.removeEventListener("scroll", handler, true);
|
|
4336
|
+
};
|
|
4337
|
+
}, [isOpen, calculatePosition]);
|
|
4338
|
+
React21.useEffect(() => {
|
|
4339
|
+
if (!isOpen) return;
|
|
4340
|
+
const handleClickOutside = (event) => {
|
|
4341
|
+
if (triggerRef.current && !triggerRef.current.contains(event.target) && panelRef.current && !panelRef.current.contains(event.target)) {
|
|
4342
|
+
setIsOpen(false);
|
|
4343
|
+
}
|
|
4344
|
+
};
|
|
4345
|
+
const handleEscape = (event) => {
|
|
4346
|
+
if (event.key === "Escape") setIsOpen(false);
|
|
4347
|
+
};
|
|
4348
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
4349
|
+
document.addEventListener("keydown", handleEscape);
|
|
4350
|
+
return () => {
|
|
4351
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
4352
|
+
document.removeEventListener("keydown", handleEscape);
|
|
4353
|
+
};
|
|
4354
|
+
}, [isOpen]);
|
|
4355
|
+
const isSameDay = (a, b) => {
|
|
4356
|
+
if (!a || !b) return false;
|
|
4357
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
4358
|
+
};
|
|
4359
|
+
const inRange = (d, s, e) => d > s && d < e;
|
|
4360
|
+
const getDaysInMonth = (d) => new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate();
|
|
4361
|
+
const getFirstDayOfMonth = (d) => new Date(d.getFullYear(), d.getMonth(), 1).getDay();
|
|
4362
|
+
const handleSelect = (date) => {
|
|
4363
|
+
if (!tempStart || tempStart && tempEnd) {
|
|
4364
|
+
setTempStart(date);
|
|
4365
|
+
setTempEnd(null);
|
|
4366
|
+
setHoveredDate(null);
|
|
4367
|
+
} else if (tempStart && !tempEnd) {
|
|
4368
|
+
if (date < tempStart) {
|
|
4369
|
+
setTempStart(date);
|
|
4370
|
+
} else {
|
|
4371
|
+
setTempEnd(date);
|
|
4372
|
+
onChange(tempStart, date);
|
|
4373
|
+
setIsOpen(false);
|
|
4374
|
+
}
|
|
4375
|
+
}
|
|
4376
|
+
};
|
|
4377
|
+
const renderGrid = () => {
|
|
4378
|
+
const nodes = [];
|
|
4379
|
+
const daysInMonth = getDaysInMonth(viewDate);
|
|
4380
|
+
const firstDay = getFirstDayOfMonth(viewDate);
|
|
4381
|
+
for (let i = 0; i < firstDay; i++) nodes.push(/* @__PURE__ */ jsx27("div", { className: "w-8 h-8" }, `e-${i}`));
|
|
4382
|
+
for (let d = 1; d <= daysInMonth; d++) {
|
|
4383
|
+
const date = new Date(viewDate.getFullYear(), viewDate.getMonth(), d);
|
|
4384
|
+
const isSelectedStart = isSameDay(date, tempStart);
|
|
4385
|
+
const isSelectedEnd = isSameDay(date, tempEnd);
|
|
4386
|
+
const isHovering = hoveredDate && tempStart && !tempEnd;
|
|
4387
|
+
let isInRange = false;
|
|
4388
|
+
let isRangeStart = false;
|
|
4389
|
+
let isRangeEnd = false;
|
|
4390
|
+
if (tempStart && tempEnd) {
|
|
4391
|
+
if (isSameDay(date, tempStart)) isRangeStart = true;
|
|
4392
|
+
if (isSameDay(date, tempEnd)) isRangeEnd = true;
|
|
4393
|
+
if (inRange(date, tempStart, tempEnd)) isInRange = true;
|
|
4394
|
+
} else if (isHovering) {
|
|
4395
|
+
if (hoveredDate > tempStart) {
|
|
4396
|
+
if (isSameDay(date, tempStart)) isRangeStart = true;
|
|
4397
|
+
if (isSameDay(date, hoveredDate)) isRangeEnd = true;
|
|
4398
|
+
if (inRange(date, tempStart, hoveredDate)) isInRange = true;
|
|
4399
|
+
} else {
|
|
4400
|
+
if (isSameDay(date, hoveredDate)) isRangeStart = true;
|
|
4401
|
+
if (isSameDay(date, tempStart)) isRangeEnd = true;
|
|
4402
|
+
if (inRange(date, hoveredDate, tempStart)) isInRange = true;
|
|
4403
|
+
}
|
|
4404
|
+
}
|
|
4405
|
+
nodes.push(
|
|
4406
|
+
/* @__PURE__ */ jsx27(
|
|
4407
|
+
"button",
|
|
4408
|
+
{
|
|
4409
|
+
onClick: () => handleSelect(date),
|
|
4410
|
+
onMouseEnter: () => tempStart && !tempEnd && setHoveredDate(date),
|
|
4411
|
+
onMouseLeave: () => tempStart && !tempEnd && setHoveredDate(null),
|
|
4412
|
+
className: cn(
|
|
4413
|
+
"w-8 h-8 text-sm transition-all duration-200 focus:outline-none relative font-medium",
|
|
4414
|
+
// Default state
|
|
4415
|
+
!isInRange && !isRangeStart && !isRangeEnd && "hover:bg-accent hover:text-accent-foreground rounded-md",
|
|
4416
|
+
// Range selection styling - smooth continuous background
|
|
4417
|
+
isInRange && "bg-primary/15 text-foreground shadow-sm",
|
|
4418
|
+
(isRangeStart || isRangeEnd) && "bg-primary text-primary-foreground hover:bg-primary/90 shadow-sm",
|
|
4419
|
+
// Only round the actual start and end of the range
|
|
4420
|
+
isRangeStart && !isRangeEnd && "rounded-l-md rounded-r-none",
|
|
4421
|
+
isRangeEnd && !isRangeStart && "rounded-r-md rounded-l-none",
|
|
4422
|
+
isRangeStart && isRangeEnd && "rounded-md",
|
|
4423
|
+
// Single day selection
|
|
4424
|
+
// Hover effects for range
|
|
4425
|
+
isInRange && "hover:bg-primary/25",
|
|
4426
|
+
"focus:bg-accent focus:text-accent-foreground focus:z-10 focus:shadow-md"
|
|
4427
|
+
),
|
|
4428
|
+
children: d
|
|
4429
|
+
},
|
|
4430
|
+
d
|
|
4431
|
+
)
|
|
4432
|
+
);
|
|
4433
|
+
}
|
|
4434
|
+
return nodes;
|
|
4435
|
+
};
|
|
4436
|
+
const panel = isOpen && dropdownPosition ? /* @__PURE__ */ jsx27(
|
|
4437
|
+
"div",
|
|
4438
|
+
{
|
|
4439
|
+
style: { position: "absolute", top: dropdownPosition.top, left: dropdownPosition.left, width: dropdownPosition.width || 256, zIndex: 9999 },
|
|
4440
|
+
"data-state": isOpen ? "open" : "closed",
|
|
4441
|
+
className: cn(
|
|
4442
|
+
"z-[9999]",
|
|
4443
|
+
"data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",
|
|
4444
|
+
"data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95"
|
|
4445
|
+
),
|
|
4446
|
+
children: /* @__PURE__ */ jsxs23(
|
|
4447
|
+
"div",
|
|
4448
|
+
{
|
|
4449
|
+
ref: panelRef,
|
|
4450
|
+
className: cn("rounded-md border bg-popover text-popover-foreground shadow-md", "backdrop-blur-sm bg-popover/95 border-border/60 p-4 w-64"),
|
|
4451
|
+
children: [
|
|
4452
|
+
/* @__PURE__ */ jsxs23("div", { className: "flex items-center justify-between mb-3", children: [
|
|
4453
|
+
/* @__PURE__ */ jsx27(
|
|
4454
|
+
Button_default,
|
|
4455
|
+
{
|
|
4456
|
+
variant: "ghost",
|
|
4457
|
+
size: "sm",
|
|
4458
|
+
onClick: () => setViewDate(new Date(viewDate.getFullYear(), viewDate.getMonth() - 1, 1)),
|
|
4459
|
+
className: "p-1 h-auto",
|
|
4460
|
+
children: /* @__PURE__ */ jsx27(ChevronLeft2, { className: "h-4 w-4" })
|
|
4461
|
+
}
|
|
4462
|
+
),
|
|
4463
|
+
/* @__PURE__ */ jsx27("div", { className: "text-sm font-semibold", children: viewDate.toLocaleDateString("en-US", { month: "long", year: "numeric" }) }),
|
|
4464
|
+
/* @__PURE__ */ jsx27(
|
|
4465
|
+
Button_default,
|
|
4466
|
+
{
|
|
4467
|
+
variant: "ghost",
|
|
4468
|
+
size: "sm",
|
|
4469
|
+
onClick: () => setViewDate(new Date(viewDate.getFullYear(), viewDate.getMonth() + 1, 1)),
|
|
4470
|
+
className: "p-1 h-auto",
|
|
4471
|
+
children: /* @__PURE__ */ jsx27(ChevronRight3, { className: "h-4 w-4" })
|
|
4472
|
+
}
|
|
4473
|
+
)
|
|
4474
|
+
] }),
|
|
4475
|
+
/* @__PURE__ */ jsx27("div", { className: "grid grid-cols-7 gap-1 mb-2", children: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"].map((d) => /* @__PURE__ */ jsx27("div", { className: "text-xs text-muted-foreground text-center py-1 font-medium", children: d }, d)) }),
|
|
4476
|
+
/* @__PURE__ */ jsx27("div", { className: "grid grid-cols-7", children: renderGrid() })
|
|
4477
|
+
]
|
|
4478
|
+
}
|
|
4479
|
+
)
|
|
4480
|
+
}
|
|
4481
|
+
) : null;
|
|
4482
|
+
const displayFormat = (date) => formatDateShort(date);
|
|
4483
|
+
const label = tempStart && tempEnd ? `${displayFormat(tempStart)} - ${displayFormat(tempEnd)}` : tempStart ? `${displayFormat(tempStart)} - ...` : placeholder;
|
|
4484
|
+
return /* @__PURE__ */ jsxs23(Fragment6, { children: [
|
|
4485
|
+
/* @__PURE__ */ jsxs23(
|
|
4486
|
+
"button",
|
|
4487
|
+
{
|
|
4488
|
+
ref: triggerRef,
|
|
4489
|
+
type: "button",
|
|
4490
|
+
onClick: () => {
|
|
4491
|
+
const next = !isOpen;
|
|
4492
|
+
if (next) {
|
|
4493
|
+
const pos = calculatePosition();
|
|
4494
|
+
if (pos) setDropdownPosition(pos);
|
|
4495
|
+
}
|
|
4496
|
+
setIsOpen(next);
|
|
4497
|
+
},
|
|
4498
|
+
className: cn(
|
|
4499
|
+
"flex w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm",
|
|
4500
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
4501
|
+
className
|
|
4502
|
+
),
|
|
4503
|
+
children: [
|
|
4504
|
+
/* @__PURE__ */ jsx27("span", { className: cn("truncate", !tempStart && !tempEnd && "text-muted-foreground"), children: label }),
|
|
4505
|
+
/* @__PURE__ */ jsx27(Calendar, { className: "h-4 w-4 text-muted-foreground ml-2" })
|
|
4506
|
+
]
|
|
4507
|
+
}
|
|
4508
|
+
),
|
|
4509
|
+
isOpen && dropdownPosition && typeof window !== "undefined" && createPortal7(panel, document.body)
|
|
4510
|
+
] });
|
|
4511
|
+
};
|
|
4196
4512
|
|
|
4197
4513
|
// ../../components/ui/MultiCombobox.tsx
|
|
4198
4514
|
import * as React22 from "react";
|
|
@@ -5929,117 +6245,2015 @@ function DataTable({
|
|
|
5929
6245
|
}
|
|
5930
6246
|
var DataTable_default = DataTable;
|
|
5931
6247
|
|
|
5932
|
-
// ../../components/ui/
|
|
5933
|
-
import
|
|
5934
|
-
import { useTranslations as useTranslations8 } from "next-intl";
|
|
5935
|
-
import { jsx as jsx39, jsxs as jsxs33 } from "react/jsx-runtime";
|
|
5936
|
-
function NotificationModal({ isOpen, onClose, notification, titleText, openLinkText, closeText }) {
|
|
5937
|
-
const t = useTranslations8("Common");
|
|
5938
|
-
if (!notification) return null;
|
|
5939
|
-
const formatTime2 = (dateString) => {
|
|
5940
|
-
const date = new Date(dateString);
|
|
5941
|
-
return date.toLocaleString(void 0, {
|
|
5942
|
-
year: "numeric",
|
|
5943
|
-
month: "2-digit",
|
|
5944
|
-
day: "2-digit",
|
|
5945
|
-
hour: "2-digit",
|
|
5946
|
-
minute: "2-digit"
|
|
5947
|
-
});
|
|
5948
|
-
};
|
|
5949
|
-
const hasLink = notification.metadata?.link;
|
|
5950
|
-
const handleLinkClick = () => {
|
|
5951
|
-
if (hasLink) {
|
|
5952
|
-
window.open(notification.metadata.link, "_blank");
|
|
5953
|
-
onClose();
|
|
5954
|
-
}
|
|
5955
|
-
};
|
|
5956
|
-
return /* @__PURE__ */ jsx39(
|
|
5957
|
-
Modal_default,
|
|
5958
|
-
{
|
|
5959
|
-
isOpen,
|
|
5960
|
-
onClose,
|
|
5961
|
-
title: titleText || t("notifications"),
|
|
5962
|
-
size: "md",
|
|
5963
|
-
children: /* @__PURE__ */ jsxs33("div", { className: "space-y-4", children: [
|
|
5964
|
-
/* @__PURE__ */ jsxs33("div", { className: "flex items-center gap-2 pb-2 border-b border-border", children: [
|
|
5965
|
-
/* @__PURE__ */ jsx39("div", { className: cn(
|
|
5966
|
-
"w-2 h-2 rounded-full",
|
|
5967
|
-
!notification.is_read ? "bg-primary" : "bg-border"
|
|
5968
|
-
) }),
|
|
5969
|
-
/* @__PURE__ */ jsx39("span", { className: "text-xs text-muted-foreground", children: !notification.is_read ? t("newNotification") : t("readStatus") })
|
|
5970
|
-
] }),
|
|
5971
|
-
notification.title && /* @__PURE__ */ jsx39("h3", { className: "text-lg font-semibold text-foreground", children: notification.title }),
|
|
5972
|
-
notification.body && /* @__PURE__ */ jsx39("div", { className: "text-sm text-muted-foreground whitespace-pre-wrap leading-relaxed", children: notification.body }),
|
|
5973
|
-
/* @__PURE__ */ jsx39("div", { className: "text-xs text-muted-foreground border-t border-border pt-2", children: formatTime2(notification.created_at) }),
|
|
5974
|
-
/* @__PURE__ */ jsxs33("div", { className: "flex gap-2 justify-end pt-2", children: [
|
|
5975
|
-
hasLink && /* @__PURE__ */ jsxs33(
|
|
5976
|
-
Button_default,
|
|
5977
|
-
{
|
|
5978
|
-
variant: "primary",
|
|
5979
|
-
size: "sm",
|
|
5980
|
-
onClick: handleLinkClick,
|
|
5981
|
-
className: "gap-2",
|
|
5982
|
-
children: [
|
|
5983
|
-
/* @__PURE__ */ jsx39(ExternalLink, { className: "w-4 h-4" }),
|
|
5984
|
-
openLinkText || t("openLink")
|
|
5985
|
-
]
|
|
5986
|
-
}
|
|
5987
|
-
),
|
|
5988
|
-
/* @__PURE__ */ jsx39(
|
|
5989
|
-
Button_default,
|
|
5990
|
-
{
|
|
5991
|
-
variant: "ghost",
|
|
5992
|
-
size: "sm",
|
|
5993
|
-
onClick: onClose,
|
|
5994
|
-
children: closeText || t("close")
|
|
5995
|
-
}
|
|
5996
|
-
)
|
|
5997
|
-
] })
|
|
5998
|
-
] })
|
|
5999
|
-
}
|
|
6000
|
-
);
|
|
6001
|
-
}
|
|
6002
|
-
var NotificationModal_default = NotificationModal;
|
|
6003
|
-
|
|
6004
|
-
// ../../components/ui/FloatingContacts.tsx
|
|
6005
|
-
import Link2 from "next/link";
|
|
6006
|
-
import { usePathname } from "next/navigation";
|
|
6007
|
-
import { Phone } from "lucide-react";
|
|
6008
|
-
|
|
6009
|
-
// ../../node_modules/react-icons/lib/iconBase.mjs
|
|
6010
|
-
import React31 from "react";
|
|
6248
|
+
// ../../components/ui/Form.tsx
|
|
6249
|
+
import * as React31 from "react";
|
|
6011
6250
|
|
|
6012
|
-
// ../../node_modules/react-
|
|
6251
|
+
// ../../node_modules/react-hook-form/dist/index.esm.mjs
|
|
6013
6252
|
import React30 from "react";
|
|
6014
|
-
var
|
|
6015
|
-
|
|
6016
|
-
|
|
6017
|
-
|
|
6018
|
-
|
|
6019
|
-
|
|
6253
|
+
var isCheckBoxInput = (element) => element.type === "checkbox";
|
|
6254
|
+
var isDateObject = (value) => value instanceof Date;
|
|
6255
|
+
var isNullOrUndefined = (value) => value == null;
|
|
6256
|
+
var isObjectType = (value) => typeof value === "object";
|
|
6257
|
+
var isObject = (value) => !isNullOrUndefined(value) && !Array.isArray(value) && isObjectType(value) && !isDateObject(value);
|
|
6258
|
+
var getEventValue = (event) => isObject(event) && event.target ? isCheckBoxInput(event.target) ? event.target.checked : event.target.value : event;
|
|
6259
|
+
var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
|
|
6260
|
+
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
6261
|
+
var isPlainObject = (tempObject) => {
|
|
6262
|
+
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
|
6263
|
+
return isObject(prototypeCopy) && prototypeCopy.hasOwnProperty("isPrototypeOf");
|
|
6020
6264
|
};
|
|
6021
|
-
var
|
|
6022
|
-
|
|
6023
|
-
|
|
6024
|
-
|
|
6025
|
-
|
|
6026
|
-
if (
|
|
6027
|
-
|
|
6028
|
-
|
|
6029
|
-
|
|
6030
|
-
|
|
6031
|
-
|
|
6032
|
-
|
|
6033
|
-
|
|
6034
|
-
|
|
6035
|
-
|
|
6265
|
+
var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
|
|
6266
|
+
function cloneObject(data) {
|
|
6267
|
+
let copy;
|
|
6268
|
+
const isArray = Array.isArray(data);
|
|
6269
|
+
const isFileListInstance = typeof FileList !== "undefined" ? data instanceof FileList : false;
|
|
6270
|
+
if (data instanceof Date) {
|
|
6271
|
+
copy = new Date(data);
|
|
6272
|
+
} else if (!(isWeb && (data instanceof Blob || isFileListInstance)) && (isArray || isObject(data))) {
|
|
6273
|
+
copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
6274
|
+
if (!isArray && !isPlainObject(data)) {
|
|
6275
|
+
copy = data;
|
|
6276
|
+
} else {
|
|
6277
|
+
for (const key in data) {
|
|
6278
|
+
if (data.hasOwnProperty(key)) {
|
|
6279
|
+
copy[key] = cloneObject(data[key]);
|
|
6280
|
+
}
|
|
6281
|
+
}
|
|
6036
6282
|
}
|
|
6283
|
+
} else {
|
|
6284
|
+
return data;
|
|
6037
6285
|
}
|
|
6038
|
-
return
|
|
6286
|
+
return copy;
|
|
6039
6287
|
}
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6288
|
+
var isKey = (value) => /^\w*$/.test(value);
|
|
6289
|
+
var isUndefined = (val) => val === void 0;
|
|
6290
|
+
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
6291
|
+
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, "").split(/\.|\[/));
|
|
6292
|
+
var get = (object, path, defaultValue) => {
|
|
6293
|
+
if (!path || !isObject(object)) {
|
|
6294
|
+
return defaultValue;
|
|
6295
|
+
}
|
|
6296
|
+
const result = (isKey(path) ? [path] : stringToPath(path)).reduce((result2, key) => isNullOrUndefined(result2) ? result2 : result2[key], object);
|
|
6297
|
+
return isUndefined(result) || result === object ? isUndefined(object[path]) ? defaultValue : object[path] : result;
|
|
6298
|
+
};
|
|
6299
|
+
var isBoolean = (value) => typeof value === "boolean";
|
|
6300
|
+
var set = (object, path, value) => {
|
|
6301
|
+
let index = -1;
|
|
6302
|
+
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
6303
|
+
const length = tempPath.length;
|
|
6304
|
+
const lastIndex = length - 1;
|
|
6305
|
+
while (++index < length) {
|
|
6306
|
+
const key = tempPath[index];
|
|
6307
|
+
let newValue = value;
|
|
6308
|
+
if (index !== lastIndex) {
|
|
6309
|
+
const objValue = object[key];
|
|
6310
|
+
newValue = isObject(objValue) || Array.isArray(objValue) ? objValue : !isNaN(+tempPath[index + 1]) ? [] : {};
|
|
6311
|
+
}
|
|
6312
|
+
if (key === "__proto__" || key === "constructor" || key === "prototype") {
|
|
6313
|
+
return;
|
|
6314
|
+
}
|
|
6315
|
+
object[key] = newValue;
|
|
6316
|
+
object = object[key];
|
|
6317
|
+
}
|
|
6318
|
+
};
|
|
6319
|
+
var EVENTS = {
|
|
6320
|
+
BLUR: "blur",
|
|
6321
|
+
FOCUS_OUT: "focusout",
|
|
6322
|
+
CHANGE: "change"
|
|
6323
|
+
};
|
|
6324
|
+
var VALIDATION_MODE = {
|
|
6325
|
+
onBlur: "onBlur",
|
|
6326
|
+
onChange: "onChange",
|
|
6327
|
+
onSubmit: "onSubmit",
|
|
6328
|
+
onTouched: "onTouched",
|
|
6329
|
+
all: "all"
|
|
6330
|
+
};
|
|
6331
|
+
var INPUT_VALIDATION_RULES = {
|
|
6332
|
+
max: "max",
|
|
6333
|
+
min: "min",
|
|
6334
|
+
maxLength: "maxLength",
|
|
6335
|
+
minLength: "minLength",
|
|
6336
|
+
pattern: "pattern",
|
|
6337
|
+
required: "required",
|
|
6338
|
+
validate: "validate"
|
|
6339
|
+
};
|
|
6340
|
+
var HookFormContext = React30.createContext(null);
|
|
6341
|
+
HookFormContext.displayName = "HookFormContext";
|
|
6342
|
+
var useFormContext = () => React30.useContext(HookFormContext);
|
|
6343
|
+
var FormProvider = (props) => {
|
|
6344
|
+
const { children, ...data } = props;
|
|
6345
|
+
return React30.createElement(HookFormContext.Provider, { value: data }, children);
|
|
6346
|
+
};
|
|
6347
|
+
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
6348
|
+
const result = {
|
|
6349
|
+
defaultValues: control._defaultValues
|
|
6350
|
+
};
|
|
6351
|
+
for (const key in formState) {
|
|
6352
|
+
Object.defineProperty(result, key, {
|
|
6353
|
+
get: () => {
|
|
6354
|
+
const _key = key;
|
|
6355
|
+
if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
|
|
6356
|
+
control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
|
|
6357
|
+
}
|
|
6358
|
+
localProxyFormState && (localProxyFormState[_key] = true);
|
|
6359
|
+
return formState[_key];
|
|
6360
|
+
}
|
|
6361
|
+
});
|
|
6362
|
+
}
|
|
6363
|
+
return result;
|
|
6364
|
+
};
|
|
6365
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? React30.useLayoutEffect : React30.useEffect;
|
|
6366
|
+
function useFormState(props) {
|
|
6367
|
+
const methods = useFormContext();
|
|
6368
|
+
const { control = methods.control, disabled, name, exact } = props || {};
|
|
6369
|
+
const [formState, updateFormState] = React30.useState(control._formState);
|
|
6370
|
+
const _localProxyFormState = React30.useRef({
|
|
6371
|
+
isDirty: false,
|
|
6372
|
+
isLoading: false,
|
|
6373
|
+
dirtyFields: false,
|
|
6374
|
+
touchedFields: false,
|
|
6375
|
+
validatingFields: false,
|
|
6376
|
+
isValidating: false,
|
|
6377
|
+
isValid: false,
|
|
6378
|
+
errors: false
|
|
6379
|
+
});
|
|
6380
|
+
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
6381
|
+
name,
|
|
6382
|
+
formState: _localProxyFormState.current,
|
|
6383
|
+
exact,
|
|
6384
|
+
callback: (formState2) => {
|
|
6385
|
+
!disabled && updateFormState({
|
|
6386
|
+
...control._formState,
|
|
6387
|
+
...formState2
|
|
6388
|
+
});
|
|
6389
|
+
}
|
|
6390
|
+
}), [name, disabled, exact]);
|
|
6391
|
+
React30.useEffect(() => {
|
|
6392
|
+
_localProxyFormState.current.isValid && control._setValid(true);
|
|
6393
|
+
}, [control]);
|
|
6394
|
+
return React30.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
|
|
6395
|
+
}
|
|
6396
|
+
var isString = (value) => typeof value === "string";
|
|
6397
|
+
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
|
|
6398
|
+
if (isString(names)) {
|
|
6399
|
+
isGlobal && _names.watch.add(names);
|
|
6400
|
+
return get(formValues, names, defaultValue);
|
|
6401
|
+
}
|
|
6402
|
+
if (Array.isArray(names)) {
|
|
6403
|
+
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName), get(formValues, fieldName)));
|
|
6404
|
+
}
|
|
6405
|
+
isGlobal && (_names.watchAll = true);
|
|
6406
|
+
return formValues;
|
|
6407
|
+
};
|
|
6408
|
+
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
6409
|
+
function deepEqual(object1, object2, _internal_visited = /* @__PURE__ */ new WeakSet()) {
|
|
6410
|
+
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
6411
|
+
return object1 === object2;
|
|
6412
|
+
}
|
|
6413
|
+
if (isDateObject(object1) && isDateObject(object2)) {
|
|
6414
|
+
return object1.getTime() === object2.getTime();
|
|
6415
|
+
}
|
|
6416
|
+
const keys1 = Object.keys(object1);
|
|
6417
|
+
const keys2 = Object.keys(object2);
|
|
6418
|
+
if (keys1.length !== keys2.length) {
|
|
6419
|
+
return false;
|
|
6420
|
+
}
|
|
6421
|
+
if (_internal_visited.has(object1) || _internal_visited.has(object2)) {
|
|
6422
|
+
return true;
|
|
6423
|
+
}
|
|
6424
|
+
_internal_visited.add(object1);
|
|
6425
|
+
_internal_visited.add(object2);
|
|
6426
|
+
for (const key of keys1) {
|
|
6427
|
+
const val1 = object1[key];
|
|
6428
|
+
if (!keys2.includes(key)) {
|
|
6429
|
+
return false;
|
|
6430
|
+
}
|
|
6431
|
+
if (key !== "ref") {
|
|
6432
|
+
const val2 = object2[key];
|
|
6433
|
+
if (isDateObject(val1) && isDateObject(val2) || isObject(val1) && isObject(val2) || Array.isArray(val1) && Array.isArray(val2) ? !deepEqual(val1, val2, _internal_visited) : val1 !== val2) {
|
|
6434
|
+
return false;
|
|
6435
|
+
}
|
|
6436
|
+
}
|
|
6437
|
+
}
|
|
6438
|
+
return true;
|
|
6439
|
+
}
|
|
6440
|
+
function useWatch(props) {
|
|
6441
|
+
const methods = useFormContext();
|
|
6442
|
+
const { control = methods.control, name, defaultValue, disabled, exact, compute } = props || {};
|
|
6443
|
+
const _defaultValue = React30.useRef(defaultValue);
|
|
6444
|
+
const _compute = React30.useRef(compute);
|
|
6445
|
+
const _computeFormValues = React30.useRef(void 0);
|
|
6446
|
+
_compute.current = compute;
|
|
6447
|
+
const defaultValueMemo = React30.useMemo(() => control._getWatch(name, _defaultValue.current), [control, name]);
|
|
6448
|
+
const [value, updateValue] = React30.useState(_compute.current ? _compute.current(defaultValueMemo) : defaultValueMemo);
|
|
6449
|
+
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
6450
|
+
name,
|
|
6451
|
+
formState: {
|
|
6452
|
+
values: true
|
|
6453
|
+
},
|
|
6454
|
+
exact,
|
|
6455
|
+
callback: (formState) => {
|
|
6456
|
+
if (!disabled) {
|
|
6457
|
+
const formValues = generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current);
|
|
6458
|
+
if (_compute.current) {
|
|
6459
|
+
const computedFormValues = _compute.current(formValues);
|
|
6460
|
+
if (!deepEqual(computedFormValues, _computeFormValues.current)) {
|
|
6461
|
+
updateValue(computedFormValues);
|
|
6462
|
+
_computeFormValues.current = computedFormValues;
|
|
6463
|
+
}
|
|
6464
|
+
} else {
|
|
6465
|
+
updateValue(formValues);
|
|
6466
|
+
}
|
|
6467
|
+
}
|
|
6468
|
+
}
|
|
6469
|
+
}), [control, disabled, name, exact]);
|
|
6470
|
+
React30.useEffect(() => control._removeUnmounted());
|
|
6471
|
+
return value;
|
|
6472
|
+
}
|
|
6473
|
+
function useController(props) {
|
|
6474
|
+
const methods = useFormContext();
|
|
6475
|
+
const { name, disabled, control = methods.control, shouldUnregister, defaultValue } = props;
|
|
6476
|
+
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
6477
|
+
const defaultValueMemo = React30.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
6478
|
+
const value = useWatch({
|
|
6479
|
+
control,
|
|
6480
|
+
name,
|
|
6481
|
+
defaultValue: defaultValueMemo,
|
|
6482
|
+
exact: true
|
|
6483
|
+
});
|
|
6484
|
+
const formState = useFormState({
|
|
6485
|
+
control,
|
|
6486
|
+
name,
|
|
6487
|
+
exact: true
|
|
6488
|
+
});
|
|
6489
|
+
const _props = React30.useRef(props);
|
|
6490
|
+
const _previousNameRef = React30.useRef(void 0);
|
|
6491
|
+
const _registerProps = React30.useRef(control.register(name, {
|
|
6492
|
+
...props.rules,
|
|
6493
|
+
value,
|
|
6494
|
+
...isBoolean(props.disabled) ? { disabled: props.disabled } : {}
|
|
6495
|
+
}));
|
|
6496
|
+
_props.current = props;
|
|
6497
|
+
const fieldState = React30.useMemo(() => Object.defineProperties({}, {
|
|
6498
|
+
invalid: {
|
|
6499
|
+
enumerable: true,
|
|
6500
|
+
get: () => !!get(formState.errors, name)
|
|
6501
|
+
},
|
|
6502
|
+
isDirty: {
|
|
6503
|
+
enumerable: true,
|
|
6504
|
+
get: () => !!get(formState.dirtyFields, name)
|
|
6505
|
+
},
|
|
6506
|
+
isTouched: {
|
|
6507
|
+
enumerable: true,
|
|
6508
|
+
get: () => !!get(formState.touchedFields, name)
|
|
6509
|
+
},
|
|
6510
|
+
isValidating: {
|
|
6511
|
+
enumerable: true,
|
|
6512
|
+
get: () => !!get(formState.validatingFields, name)
|
|
6513
|
+
},
|
|
6514
|
+
error: {
|
|
6515
|
+
enumerable: true,
|
|
6516
|
+
get: () => get(formState.errors, name)
|
|
6517
|
+
}
|
|
6518
|
+
}), [formState, name]);
|
|
6519
|
+
const onChange = React30.useCallback((event) => _registerProps.current.onChange({
|
|
6520
|
+
target: {
|
|
6521
|
+
value: getEventValue(event),
|
|
6522
|
+
name
|
|
6523
|
+
},
|
|
6524
|
+
type: EVENTS.CHANGE
|
|
6525
|
+
}), [name]);
|
|
6526
|
+
const onBlur = React30.useCallback(() => _registerProps.current.onBlur({
|
|
6527
|
+
target: {
|
|
6528
|
+
value: get(control._formValues, name),
|
|
6529
|
+
name
|
|
6530
|
+
},
|
|
6531
|
+
type: EVENTS.BLUR
|
|
6532
|
+
}), [name, control._formValues]);
|
|
6533
|
+
const ref = React30.useCallback((elm) => {
|
|
6534
|
+
const field2 = get(control._fields, name);
|
|
6535
|
+
if (field2 && elm) {
|
|
6536
|
+
field2._f.ref = {
|
|
6537
|
+
focus: () => elm.focus && elm.focus(),
|
|
6538
|
+
select: () => elm.select && elm.select(),
|
|
6539
|
+
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
6540
|
+
reportValidity: () => elm.reportValidity()
|
|
6541
|
+
};
|
|
6542
|
+
}
|
|
6543
|
+
}, [control._fields, name]);
|
|
6544
|
+
const field = React30.useMemo(() => ({
|
|
6545
|
+
name,
|
|
6546
|
+
value,
|
|
6547
|
+
...isBoolean(disabled) || formState.disabled ? { disabled: formState.disabled || disabled } : {},
|
|
6548
|
+
onChange,
|
|
6549
|
+
onBlur,
|
|
6550
|
+
ref
|
|
6551
|
+
}), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
|
|
6552
|
+
React30.useEffect(() => {
|
|
6553
|
+
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
6554
|
+
const previousName = _previousNameRef.current;
|
|
6555
|
+
if (previousName && previousName !== name && !isArrayField) {
|
|
6556
|
+
control.unregister(previousName);
|
|
6557
|
+
}
|
|
6558
|
+
control.register(name, {
|
|
6559
|
+
..._props.current.rules,
|
|
6560
|
+
...isBoolean(_props.current.disabled) ? { disabled: _props.current.disabled } : {}
|
|
6561
|
+
});
|
|
6562
|
+
const updateMounted = (name2, value2) => {
|
|
6563
|
+
const field2 = get(control._fields, name2);
|
|
6564
|
+
if (field2 && field2._f) {
|
|
6565
|
+
field2._f.mount = value2;
|
|
6566
|
+
}
|
|
6567
|
+
};
|
|
6568
|
+
updateMounted(name, true);
|
|
6569
|
+
if (_shouldUnregisterField) {
|
|
6570
|
+
const value2 = cloneObject(get(control._options.defaultValues, name, _props.current.defaultValue));
|
|
6571
|
+
set(control._defaultValues, name, value2);
|
|
6572
|
+
if (isUndefined(get(control._formValues, name))) {
|
|
6573
|
+
set(control._formValues, name, value2);
|
|
6574
|
+
}
|
|
6575
|
+
}
|
|
6576
|
+
!isArrayField && control.register(name);
|
|
6577
|
+
_previousNameRef.current = name;
|
|
6578
|
+
return () => {
|
|
6579
|
+
(isArrayField ? _shouldUnregisterField && !control._state.action : _shouldUnregisterField) ? control.unregister(name) : updateMounted(name, false);
|
|
6580
|
+
};
|
|
6581
|
+
}, [name, control, isArrayField, shouldUnregister]);
|
|
6582
|
+
React30.useEffect(() => {
|
|
6583
|
+
control._setDisabledField({
|
|
6584
|
+
disabled,
|
|
6585
|
+
name
|
|
6586
|
+
});
|
|
6587
|
+
}, [disabled, name, control]);
|
|
6588
|
+
return React30.useMemo(() => ({
|
|
6589
|
+
field,
|
|
6590
|
+
formState,
|
|
6591
|
+
fieldState
|
|
6592
|
+
}), [field, formState, fieldState]);
|
|
6593
|
+
}
|
|
6594
|
+
var Controller = (props) => props.render(useController(props));
|
|
6595
|
+
var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria ? {
|
|
6596
|
+
...errors[name],
|
|
6597
|
+
types: {
|
|
6598
|
+
...errors[name] && errors[name].types ? errors[name].types : {},
|
|
6599
|
+
[type]: message || true
|
|
6600
|
+
}
|
|
6601
|
+
} : {};
|
|
6602
|
+
var convertToArrayPayload = (value) => Array.isArray(value) ? value : [value];
|
|
6603
|
+
var createSubject = () => {
|
|
6604
|
+
let _observers = [];
|
|
6605
|
+
const next = (value) => {
|
|
6606
|
+
for (const observer of _observers) {
|
|
6607
|
+
observer.next && observer.next(value);
|
|
6608
|
+
}
|
|
6609
|
+
};
|
|
6610
|
+
const subscribe = (observer) => {
|
|
6611
|
+
_observers.push(observer);
|
|
6612
|
+
return {
|
|
6613
|
+
unsubscribe: () => {
|
|
6614
|
+
_observers = _observers.filter((o) => o !== observer);
|
|
6615
|
+
}
|
|
6616
|
+
};
|
|
6617
|
+
};
|
|
6618
|
+
const unsubscribe = () => {
|
|
6619
|
+
_observers = [];
|
|
6620
|
+
};
|
|
6621
|
+
return {
|
|
6622
|
+
get observers() {
|
|
6623
|
+
return _observers;
|
|
6624
|
+
},
|
|
6625
|
+
next,
|
|
6626
|
+
subscribe,
|
|
6627
|
+
unsubscribe
|
|
6628
|
+
};
|
|
6629
|
+
};
|
|
6630
|
+
function extractFormValues(fieldsState, formValues) {
|
|
6631
|
+
const values = {};
|
|
6632
|
+
for (const key in fieldsState) {
|
|
6633
|
+
if (fieldsState.hasOwnProperty(key)) {
|
|
6634
|
+
const fieldState = fieldsState[key];
|
|
6635
|
+
const fieldValue = formValues[key];
|
|
6636
|
+
if (fieldState && isObject(fieldState) && fieldValue) {
|
|
6637
|
+
const nestedFieldsState = extractFormValues(fieldState, fieldValue);
|
|
6638
|
+
if (isObject(nestedFieldsState)) {
|
|
6639
|
+
values[key] = nestedFieldsState;
|
|
6640
|
+
}
|
|
6641
|
+
} else if (fieldsState[key]) {
|
|
6642
|
+
values[key] = fieldValue;
|
|
6643
|
+
}
|
|
6644
|
+
}
|
|
6645
|
+
}
|
|
6646
|
+
return values;
|
|
6647
|
+
}
|
|
6648
|
+
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
|
6649
|
+
var isFileInput = (element) => element.type === "file";
|
|
6650
|
+
var isFunction = (value) => typeof value === "function";
|
|
6651
|
+
var isHTMLElement = (value) => {
|
|
6652
|
+
if (!isWeb) {
|
|
6653
|
+
return false;
|
|
6654
|
+
}
|
|
6655
|
+
const owner = value ? value.ownerDocument : 0;
|
|
6656
|
+
return value instanceof (owner && owner.defaultView ? owner.defaultView.HTMLElement : HTMLElement);
|
|
6657
|
+
};
|
|
6658
|
+
var isMultipleSelect = (element) => element.type === `select-multiple`;
|
|
6659
|
+
var isRadioInput = (element) => element.type === "radio";
|
|
6660
|
+
var isRadioOrCheckbox = (ref) => isRadioInput(ref) || isCheckBoxInput(ref);
|
|
6661
|
+
var live = (ref) => isHTMLElement(ref) && ref.isConnected;
|
|
6662
|
+
function baseGet(object, updatePath) {
|
|
6663
|
+
const length = updatePath.slice(0, -1).length;
|
|
6664
|
+
let index = 0;
|
|
6665
|
+
while (index < length) {
|
|
6666
|
+
object = isUndefined(object) ? index++ : object[updatePath[index++]];
|
|
6667
|
+
}
|
|
6668
|
+
return object;
|
|
6669
|
+
}
|
|
6670
|
+
function isEmptyArray(obj) {
|
|
6671
|
+
for (const key in obj) {
|
|
6672
|
+
if (obj.hasOwnProperty(key) && !isUndefined(obj[key])) {
|
|
6673
|
+
return false;
|
|
6674
|
+
}
|
|
6675
|
+
}
|
|
6676
|
+
return true;
|
|
6677
|
+
}
|
|
6678
|
+
function unset(object, path) {
|
|
6679
|
+
const paths = Array.isArray(path) ? path : isKey(path) ? [path] : stringToPath(path);
|
|
6680
|
+
const childObject = paths.length === 1 ? object : baseGet(object, paths);
|
|
6681
|
+
const index = paths.length - 1;
|
|
6682
|
+
const key = paths[index];
|
|
6683
|
+
if (childObject) {
|
|
6684
|
+
delete childObject[key];
|
|
6685
|
+
}
|
|
6686
|
+
if (index !== 0 && (isObject(childObject) && isEmptyObject(childObject) || Array.isArray(childObject) && isEmptyArray(childObject))) {
|
|
6687
|
+
unset(object, paths.slice(0, -1));
|
|
6688
|
+
}
|
|
6689
|
+
return object;
|
|
6690
|
+
}
|
|
6691
|
+
var objectHasFunction = (data) => {
|
|
6692
|
+
for (const key in data) {
|
|
6693
|
+
if (isFunction(data[key])) {
|
|
6694
|
+
return true;
|
|
6695
|
+
}
|
|
6696
|
+
}
|
|
6697
|
+
return false;
|
|
6698
|
+
};
|
|
6699
|
+
function isTraversable(value) {
|
|
6700
|
+
return Array.isArray(value) || isObject(value) && !objectHasFunction(value);
|
|
6701
|
+
}
|
|
6702
|
+
function markFieldsDirty(data, fields = {}) {
|
|
6703
|
+
for (const key in data) {
|
|
6704
|
+
if (isTraversable(data[key])) {
|
|
6705
|
+
fields[key] = Array.isArray(data[key]) ? [] : {};
|
|
6706
|
+
markFieldsDirty(data[key], fields[key]);
|
|
6707
|
+
} else if (!isUndefined(data[key])) {
|
|
6708
|
+
fields[key] = true;
|
|
6709
|
+
}
|
|
6710
|
+
}
|
|
6711
|
+
return fields;
|
|
6712
|
+
}
|
|
6713
|
+
function getDirtyFields(data, formValues, dirtyFieldsFromValues) {
|
|
6714
|
+
if (!dirtyFieldsFromValues) {
|
|
6715
|
+
dirtyFieldsFromValues = markFieldsDirty(formValues);
|
|
6716
|
+
}
|
|
6717
|
+
for (const key in data) {
|
|
6718
|
+
if (isTraversable(data[key])) {
|
|
6719
|
+
if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) {
|
|
6720
|
+
dirtyFieldsFromValues[key] = markFieldsDirty(data[key], Array.isArray(data[key]) ? [] : {});
|
|
6721
|
+
} else {
|
|
6722
|
+
getDirtyFields(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
|
6723
|
+
}
|
|
6724
|
+
} else {
|
|
6725
|
+
dirtyFieldsFromValues[key] = !deepEqual(data[key], formValues[key]);
|
|
6726
|
+
}
|
|
6727
|
+
}
|
|
6728
|
+
return dirtyFieldsFromValues;
|
|
6729
|
+
}
|
|
6730
|
+
var defaultResult = {
|
|
6731
|
+
value: false,
|
|
6732
|
+
isValid: false
|
|
6733
|
+
};
|
|
6734
|
+
var validResult = { value: true, isValid: true };
|
|
6735
|
+
var getCheckboxValue = (options) => {
|
|
6736
|
+
if (Array.isArray(options)) {
|
|
6737
|
+
if (options.length > 1) {
|
|
6738
|
+
const values = options.filter((option) => option && option.checked && !option.disabled).map((option) => option.value);
|
|
6739
|
+
return { value: values, isValid: !!values.length };
|
|
6740
|
+
}
|
|
6741
|
+
return options[0].checked && !options[0].disabled ? (
|
|
6742
|
+
// @ts-expect-error expected to work in the browser
|
|
6743
|
+
options[0].attributes && !isUndefined(options[0].attributes.value) ? isUndefined(options[0].value) || options[0].value === "" ? validResult : { value: options[0].value, isValid: true } : validResult
|
|
6744
|
+
) : defaultResult;
|
|
6745
|
+
}
|
|
6746
|
+
return defaultResult;
|
|
6747
|
+
};
|
|
6748
|
+
var getFieldValueAs = (value, { valueAsNumber, valueAsDate, setValueAs }) => isUndefined(value) ? value : valueAsNumber ? value === "" ? NaN : value ? +value : value : valueAsDate && isString(value) ? new Date(value) : setValueAs ? setValueAs(value) : value;
|
|
6749
|
+
var defaultReturn = {
|
|
6750
|
+
isValid: false,
|
|
6751
|
+
value: null
|
|
6752
|
+
};
|
|
6753
|
+
var getRadioValue = (options) => Array.isArray(options) ? options.reduce((previous, option) => option && option.checked && !option.disabled ? {
|
|
6754
|
+
isValid: true,
|
|
6755
|
+
value: option.value
|
|
6756
|
+
} : previous, defaultReturn) : defaultReturn;
|
|
6757
|
+
function getFieldValue(_f) {
|
|
6758
|
+
const ref = _f.ref;
|
|
6759
|
+
if (isFileInput(ref)) {
|
|
6760
|
+
return ref.files;
|
|
6761
|
+
}
|
|
6762
|
+
if (isRadioInput(ref)) {
|
|
6763
|
+
return getRadioValue(_f.refs).value;
|
|
6764
|
+
}
|
|
6765
|
+
if (isMultipleSelect(ref)) {
|
|
6766
|
+
return [...ref.selectedOptions].map(({ value }) => value);
|
|
6767
|
+
}
|
|
6768
|
+
if (isCheckBoxInput(ref)) {
|
|
6769
|
+
return getCheckboxValue(_f.refs).value;
|
|
6770
|
+
}
|
|
6771
|
+
return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
|
|
6772
|
+
}
|
|
6773
|
+
var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
|
|
6774
|
+
const fields = {};
|
|
6775
|
+
for (const name of fieldsNames) {
|
|
6776
|
+
const field = get(_fields, name);
|
|
6777
|
+
field && set(fields, name, field._f);
|
|
6778
|
+
}
|
|
6779
|
+
return {
|
|
6780
|
+
criteriaMode,
|
|
6781
|
+
names: [...fieldsNames],
|
|
6782
|
+
fields,
|
|
6783
|
+
shouldUseNativeValidation
|
|
6784
|
+
};
|
|
6785
|
+
};
|
|
6786
|
+
var isRegex = (value) => value instanceof RegExp;
|
|
6787
|
+
var getRuleValue = (rule) => isUndefined(rule) ? rule : isRegex(rule) ? rule.source : isObject(rule) ? isRegex(rule.value) ? rule.value.source : rule.value : rule;
|
|
6788
|
+
var getValidationModes = (mode) => ({
|
|
6789
|
+
isOnSubmit: !mode || mode === VALIDATION_MODE.onSubmit,
|
|
6790
|
+
isOnBlur: mode === VALIDATION_MODE.onBlur,
|
|
6791
|
+
isOnChange: mode === VALIDATION_MODE.onChange,
|
|
6792
|
+
isOnAll: mode === VALIDATION_MODE.all,
|
|
6793
|
+
isOnTouch: mode === VALIDATION_MODE.onTouched
|
|
6794
|
+
});
|
|
6795
|
+
var ASYNC_FUNCTION = "AsyncFunction";
|
|
6796
|
+
var hasPromiseValidation = (fieldReference) => !!fieldReference && !!fieldReference.validate && !!(isFunction(fieldReference.validate) && fieldReference.validate.constructor.name === ASYNC_FUNCTION || isObject(fieldReference.validate) && Object.values(fieldReference.validate).find((validateFunction) => validateFunction.constructor.name === ASYNC_FUNCTION));
|
|
6797
|
+
var hasValidation = (options) => options.mount && (options.required || options.min || options.max || options.maxLength || options.minLength || options.pattern || options.validate);
|
|
6798
|
+
var isWatched = (name, _names, isBlurEvent) => !isBlurEvent && (_names.watchAll || _names.watch.has(name) || [..._names.watch].some((watchName) => name.startsWith(watchName) && /^\.\w+/.test(name.slice(watchName.length))));
|
|
6799
|
+
var iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
|
|
6800
|
+
for (const key of fieldsNames || Object.keys(fields)) {
|
|
6801
|
+
const field = get(fields, key);
|
|
6802
|
+
if (field) {
|
|
6803
|
+
const { _f, ...currentField } = field;
|
|
6804
|
+
if (_f) {
|
|
6805
|
+
if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
|
|
6806
|
+
return true;
|
|
6807
|
+
} else if (_f.ref && action(_f.ref, _f.name) && !abortEarly) {
|
|
6808
|
+
return true;
|
|
6809
|
+
} else {
|
|
6810
|
+
if (iterateFieldsByAction(currentField, action)) {
|
|
6811
|
+
break;
|
|
6812
|
+
}
|
|
6813
|
+
}
|
|
6814
|
+
} else if (isObject(currentField)) {
|
|
6815
|
+
if (iterateFieldsByAction(currentField, action)) {
|
|
6816
|
+
break;
|
|
6817
|
+
}
|
|
6818
|
+
}
|
|
6819
|
+
}
|
|
6820
|
+
}
|
|
6821
|
+
return;
|
|
6822
|
+
};
|
|
6823
|
+
function schemaErrorLookup(errors, _fields, name) {
|
|
6824
|
+
const error = get(errors, name);
|
|
6825
|
+
if (error || isKey(name)) {
|
|
6826
|
+
return {
|
|
6827
|
+
error,
|
|
6828
|
+
name
|
|
6829
|
+
};
|
|
6830
|
+
}
|
|
6831
|
+
const names = name.split(".");
|
|
6832
|
+
while (names.length) {
|
|
6833
|
+
const fieldName = names.join(".");
|
|
6834
|
+
const field = get(_fields, fieldName);
|
|
6835
|
+
const foundError = get(errors, fieldName);
|
|
6836
|
+
if (field && !Array.isArray(field) && name !== fieldName) {
|
|
6837
|
+
return { name };
|
|
6838
|
+
}
|
|
6839
|
+
if (foundError && foundError.type) {
|
|
6840
|
+
return {
|
|
6841
|
+
name: fieldName,
|
|
6842
|
+
error: foundError
|
|
6843
|
+
};
|
|
6844
|
+
}
|
|
6845
|
+
if (foundError && foundError.root && foundError.root.type) {
|
|
6846
|
+
return {
|
|
6847
|
+
name: `${fieldName}.root`,
|
|
6848
|
+
error: foundError.root
|
|
6849
|
+
};
|
|
6850
|
+
}
|
|
6851
|
+
names.pop();
|
|
6852
|
+
}
|
|
6853
|
+
return {
|
|
6854
|
+
name
|
|
6855
|
+
};
|
|
6856
|
+
}
|
|
6857
|
+
var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
|
|
6858
|
+
updateFormState(formStateData);
|
|
6859
|
+
const { name, ...formState } = formStateData;
|
|
6860
|
+
return isEmptyObject(formState) || Object.keys(formState).length >= Object.keys(_proxyFormState).length || Object.keys(formState).find((key) => _proxyFormState[key] === (!isRoot || VALIDATION_MODE.all));
|
|
6861
|
+
};
|
|
6862
|
+
var shouldSubscribeByName = (name, signalName, exact) => !name || !signalName || name === signalName || convertToArrayPayload(name).some((currentName) => currentName && (exact ? currentName === signalName : currentName.startsWith(signalName) || signalName.startsWith(currentName)));
|
|
6863
|
+
var skipValidation = (isBlurEvent, isTouched, isSubmitted, reValidateMode, mode) => {
|
|
6864
|
+
if (mode.isOnAll) {
|
|
6865
|
+
return false;
|
|
6866
|
+
} else if (!isSubmitted && mode.isOnTouch) {
|
|
6867
|
+
return !(isTouched || isBlurEvent);
|
|
6868
|
+
} else if (isSubmitted ? reValidateMode.isOnBlur : mode.isOnBlur) {
|
|
6869
|
+
return !isBlurEvent;
|
|
6870
|
+
} else if (isSubmitted ? reValidateMode.isOnChange : mode.isOnChange) {
|
|
6871
|
+
return isBlurEvent;
|
|
6872
|
+
}
|
|
6873
|
+
return true;
|
|
6874
|
+
};
|
|
6875
|
+
var unsetEmptyArray = (ref, name) => !compact(get(ref, name)).length && unset(ref, name);
|
|
6876
|
+
var updateFieldArrayRootError = (errors, error, name) => {
|
|
6877
|
+
const fieldArrayErrors = convertToArrayPayload(get(errors, name));
|
|
6878
|
+
set(fieldArrayErrors, "root", error[name]);
|
|
6879
|
+
set(errors, name, fieldArrayErrors);
|
|
6880
|
+
return errors;
|
|
6881
|
+
};
|
|
6882
|
+
function getValidateError(result, ref, type = "validate") {
|
|
6883
|
+
if (isString(result) || Array.isArray(result) && result.every(isString) || isBoolean(result) && !result) {
|
|
6884
|
+
return {
|
|
6885
|
+
type,
|
|
6886
|
+
message: isString(result) ? result : "",
|
|
6887
|
+
ref
|
|
6888
|
+
};
|
|
6889
|
+
}
|
|
6890
|
+
}
|
|
6891
|
+
var getValueAndMessage = (validationData) => isObject(validationData) && !isRegex(validationData) ? validationData : {
|
|
6892
|
+
value: validationData,
|
|
6893
|
+
message: ""
|
|
6894
|
+
};
|
|
6895
|
+
var validateField = async (field, disabledFieldNames, formValues, validateAllFieldCriteria, shouldUseNativeValidation, isFieldArray) => {
|
|
6896
|
+
const { ref, refs, required, maxLength, minLength, min, max, pattern, validate, name, valueAsNumber, mount } = field._f;
|
|
6897
|
+
const inputValue = get(formValues, name);
|
|
6898
|
+
if (!mount || disabledFieldNames.has(name)) {
|
|
6899
|
+
return {};
|
|
6900
|
+
}
|
|
6901
|
+
const inputRef = refs ? refs[0] : ref;
|
|
6902
|
+
const setCustomValidity = (message) => {
|
|
6903
|
+
if (shouldUseNativeValidation && inputRef.reportValidity) {
|
|
6904
|
+
inputRef.setCustomValidity(isBoolean(message) ? "" : message || "");
|
|
6905
|
+
inputRef.reportValidity();
|
|
6906
|
+
}
|
|
6907
|
+
};
|
|
6908
|
+
const error = {};
|
|
6909
|
+
const isRadio = isRadioInput(ref);
|
|
6910
|
+
const isCheckBox = isCheckBoxInput(ref);
|
|
6911
|
+
const isRadioOrCheckbox2 = isRadio || isCheckBox;
|
|
6912
|
+
const isEmpty = (valueAsNumber || isFileInput(ref)) && isUndefined(ref.value) && isUndefined(inputValue) || isHTMLElement(ref) && ref.value === "" || inputValue === "" || Array.isArray(inputValue) && !inputValue.length;
|
|
6913
|
+
const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
|
|
6914
|
+
const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
|
|
6915
|
+
const message = exceedMax ? maxLengthMessage : minLengthMessage;
|
|
6916
|
+
error[name] = {
|
|
6917
|
+
type: exceedMax ? maxType : minType,
|
|
6918
|
+
message,
|
|
6919
|
+
ref,
|
|
6920
|
+
...appendErrorsCurry(exceedMax ? maxType : minType, message)
|
|
6921
|
+
};
|
|
6922
|
+
};
|
|
6923
|
+
if (isFieldArray ? !Array.isArray(inputValue) || !inputValue.length : required && (!isRadioOrCheckbox2 && (isEmpty || isNullOrUndefined(inputValue)) || isBoolean(inputValue) && !inputValue || isCheckBox && !getCheckboxValue(refs).isValid || isRadio && !getRadioValue(refs).isValid)) {
|
|
6924
|
+
const { value, message } = isString(required) ? { value: !!required, message: required } : getValueAndMessage(required);
|
|
6925
|
+
if (value) {
|
|
6926
|
+
error[name] = {
|
|
6927
|
+
type: INPUT_VALIDATION_RULES.required,
|
|
6928
|
+
message,
|
|
6929
|
+
ref: inputRef,
|
|
6930
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message)
|
|
6931
|
+
};
|
|
6932
|
+
if (!validateAllFieldCriteria) {
|
|
6933
|
+
setCustomValidity(message);
|
|
6934
|
+
return error;
|
|
6935
|
+
}
|
|
6936
|
+
}
|
|
6937
|
+
}
|
|
6938
|
+
if (!isEmpty && (!isNullOrUndefined(min) || !isNullOrUndefined(max))) {
|
|
6939
|
+
let exceedMax;
|
|
6940
|
+
let exceedMin;
|
|
6941
|
+
const maxOutput = getValueAndMessage(max);
|
|
6942
|
+
const minOutput = getValueAndMessage(min);
|
|
6943
|
+
if (!isNullOrUndefined(inputValue) && !isNaN(inputValue)) {
|
|
6944
|
+
const valueNumber = ref.valueAsNumber || (inputValue ? +inputValue : inputValue);
|
|
6945
|
+
if (!isNullOrUndefined(maxOutput.value)) {
|
|
6946
|
+
exceedMax = valueNumber > maxOutput.value;
|
|
6947
|
+
}
|
|
6948
|
+
if (!isNullOrUndefined(minOutput.value)) {
|
|
6949
|
+
exceedMin = valueNumber < minOutput.value;
|
|
6950
|
+
}
|
|
6951
|
+
} else {
|
|
6952
|
+
const valueDate = ref.valueAsDate || new Date(inputValue);
|
|
6953
|
+
const convertTimeToDate = (time) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + time);
|
|
6954
|
+
const isTime = ref.type == "time";
|
|
6955
|
+
const isWeek = ref.type == "week";
|
|
6956
|
+
if (isString(maxOutput.value) && inputValue) {
|
|
6957
|
+
exceedMax = isTime ? convertTimeToDate(inputValue) > convertTimeToDate(maxOutput.value) : isWeek ? inputValue > maxOutput.value : valueDate > new Date(maxOutput.value);
|
|
6958
|
+
}
|
|
6959
|
+
if (isString(minOutput.value) && inputValue) {
|
|
6960
|
+
exceedMin = isTime ? convertTimeToDate(inputValue) < convertTimeToDate(minOutput.value) : isWeek ? inputValue < minOutput.value : valueDate < new Date(minOutput.value);
|
|
6961
|
+
}
|
|
6962
|
+
}
|
|
6963
|
+
if (exceedMax || exceedMin) {
|
|
6964
|
+
getMinMaxMessage(!!exceedMax, maxOutput.message, minOutput.message, INPUT_VALIDATION_RULES.max, INPUT_VALIDATION_RULES.min);
|
|
6965
|
+
if (!validateAllFieldCriteria) {
|
|
6966
|
+
setCustomValidity(error[name].message);
|
|
6967
|
+
return error;
|
|
6968
|
+
}
|
|
6969
|
+
}
|
|
6970
|
+
}
|
|
6971
|
+
if ((maxLength || minLength) && !isEmpty && (isString(inputValue) || isFieldArray && Array.isArray(inputValue))) {
|
|
6972
|
+
const maxLengthOutput = getValueAndMessage(maxLength);
|
|
6973
|
+
const minLengthOutput = getValueAndMessage(minLength);
|
|
6974
|
+
const exceedMax = !isNullOrUndefined(maxLengthOutput.value) && inputValue.length > +maxLengthOutput.value;
|
|
6975
|
+
const exceedMin = !isNullOrUndefined(minLengthOutput.value) && inputValue.length < +minLengthOutput.value;
|
|
6976
|
+
if (exceedMax || exceedMin) {
|
|
6977
|
+
getMinMaxMessage(exceedMax, maxLengthOutput.message, minLengthOutput.message);
|
|
6978
|
+
if (!validateAllFieldCriteria) {
|
|
6979
|
+
setCustomValidity(error[name].message);
|
|
6980
|
+
return error;
|
|
6981
|
+
}
|
|
6982
|
+
}
|
|
6983
|
+
}
|
|
6984
|
+
if (pattern && !isEmpty && isString(inputValue)) {
|
|
6985
|
+
const { value: patternValue, message } = getValueAndMessage(pattern);
|
|
6986
|
+
if (isRegex(patternValue) && !inputValue.match(patternValue)) {
|
|
6987
|
+
error[name] = {
|
|
6988
|
+
type: INPUT_VALIDATION_RULES.pattern,
|
|
6989
|
+
message,
|
|
6990
|
+
ref,
|
|
6991
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message)
|
|
6992
|
+
};
|
|
6993
|
+
if (!validateAllFieldCriteria) {
|
|
6994
|
+
setCustomValidity(message);
|
|
6995
|
+
return error;
|
|
6996
|
+
}
|
|
6997
|
+
}
|
|
6998
|
+
}
|
|
6999
|
+
if (validate) {
|
|
7000
|
+
if (isFunction(validate)) {
|
|
7001
|
+
const result = await validate(inputValue, formValues);
|
|
7002
|
+
const validateError = getValidateError(result, inputRef);
|
|
7003
|
+
if (validateError) {
|
|
7004
|
+
error[name] = {
|
|
7005
|
+
...validateError,
|
|
7006
|
+
...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message)
|
|
7007
|
+
};
|
|
7008
|
+
if (!validateAllFieldCriteria) {
|
|
7009
|
+
setCustomValidity(validateError.message);
|
|
7010
|
+
return error;
|
|
7011
|
+
}
|
|
7012
|
+
}
|
|
7013
|
+
} else if (isObject(validate)) {
|
|
7014
|
+
let validationResult = {};
|
|
7015
|
+
for (const key in validate) {
|
|
7016
|
+
if (!isEmptyObject(validationResult) && !validateAllFieldCriteria) {
|
|
7017
|
+
break;
|
|
7018
|
+
}
|
|
7019
|
+
const validateError = getValidateError(await validate[key](inputValue, formValues), inputRef, key);
|
|
7020
|
+
if (validateError) {
|
|
7021
|
+
validationResult = {
|
|
7022
|
+
...validateError,
|
|
7023
|
+
...appendErrorsCurry(key, validateError.message)
|
|
7024
|
+
};
|
|
7025
|
+
setCustomValidity(validateError.message);
|
|
7026
|
+
if (validateAllFieldCriteria) {
|
|
7027
|
+
error[name] = validationResult;
|
|
7028
|
+
}
|
|
7029
|
+
}
|
|
7030
|
+
}
|
|
7031
|
+
if (!isEmptyObject(validationResult)) {
|
|
7032
|
+
error[name] = {
|
|
7033
|
+
ref: inputRef,
|
|
7034
|
+
...validationResult
|
|
7035
|
+
};
|
|
7036
|
+
if (!validateAllFieldCriteria) {
|
|
7037
|
+
return error;
|
|
7038
|
+
}
|
|
7039
|
+
}
|
|
7040
|
+
}
|
|
7041
|
+
}
|
|
7042
|
+
setCustomValidity(true);
|
|
7043
|
+
return error;
|
|
7044
|
+
};
|
|
7045
|
+
var defaultOptions = {
|
|
7046
|
+
mode: VALIDATION_MODE.onSubmit,
|
|
7047
|
+
reValidateMode: VALIDATION_MODE.onChange,
|
|
7048
|
+
shouldFocusError: true
|
|
7049
|
+
};
|
|
7050
|
+
function createFormControl(props = {}) {
|
|
7051
|
+
let _options = {
|
|
7052
|
+
...defaultOptions,
|
|
7053
|
+
...props
|
|
7054
|
+
};
|
|
7055
|
+
let _formState = {
|
|
7056
|
+
submitCount: 0,
|
|
7057
|
+
isDirty: false,
|
|
7058
|
+
isReady: false,
|
|
7059
|
+
isLoading: isFunction(_options.defaultValues),
|
|
7060
|
+
isValidating: false,
|
|
7061
|
+
isSubmitted: false,
|
|
7062
|
+
isSubmitting: false,
|
|
7063
|
+
isSubmitSuccessful: false,
|
|
7064
|
+
isValid: false,
|
|
7065
|
+
touchedFields: {},
|
|
7066
|
+
dirtyFields: {},
|
|
7067
|
+
validatingFields: {},
|
|
7068
|
+
errors: _options.errors || {},
|
|
7069
|
+
disabled: _options.disabled || false
|
|
7070
|
+
};
|
|
7071
|
+
let _fields = {};
|
|
7072
|
+
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values) ? cloneObject(_options.defaultValues || _options.values) || {} : {};
|
|
7073
|
+
let _formValues = _options.shouldUnregister ? {} : cloneObject(_defaultValues);
|
|
7074
|
+
let _state = {
|
|
7075
|
+
action: false,
|
|
7076
|
+
mount: false,
|
|
7077
|
+
watch: false
|
|
7078
|
+
};
|
|
7079
|
+
let _names = {
|
|
7080
|
+
mount: /* @__PURE__ */ new Set(),
|
|
7081
|
+
disabled: /* @__PURE__ */ new Set(),
|
|
7082
|
+
unMount: /* @__PURE__ */ new Set(),
|
|
7083
|
+
array: /* @__PURE__ */ new Set(),
|
|
7084
|
+
watch: /* @__PURE__ */ new Set()
|
|
7085
|
+
};
|
|
7086
|
+
let delayErrorCallback;
|
|
7087
|
+
let timer = 0;
|
|
7088
|
+
const _proxyFormState = {
|
|
7089
|
+
isDirty: false,
|
|
7090
|
+
dirtyFields: false,
|
|
7091
|
+
validatingFields: false,
|
|
7092
|
+
touchedFields: false,
|
|
7093
|
+
isValidating: false,
|
|
7094
|
+
isValid: false,
|
|
7095
|
+
errors: false
|
|
7096
|
+
};
|
|
7097
|
+
let _proxySubscribeFormState = {
|
|
7098
|
+
..._proxyFormState
|
|
7099
|
+
};
|
|
7100
|
+
const _subjects = {
|
|
7101
|
+
array: createSubject(),
|
|
7102
|
+
state: createSubject()
|
|
7103
|
+
};
|
|
7104
|
+
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
|
7105
|
+
const debounce = (callback) => (wait) => {
|
|
7106
|
+
clearTimeout(timer);
|
|
7107
|
+
timer = setTimeout(callback, wait);
|
|
7108
|
+
};
|
|
7109
|
+
const _setValid = async (shouldUpdateValid) => {
|
|
7110
|
+
if (!_options.disabled && (_proxyFormState.isValid || _proxySubscribeFormState.isValid || shouldUpdateValid)) {
|
|
7111
|
+
const isValid = _options.resolver ? isEmptyObject((await _runSchema()).errors) : await executeBuiltInValidation(_fields, true);
|
|
7112
|
+
if (isValid !== _formState.isValid) {
|
|
7113
|
+
_subjects.state.next({
|
|
7114
|
+
isValid
|
|
7115
|
+
});
|
|
7116
|
+
}
|
|
7117
|
+
}
|
|
7118
|
+
};
|
|
7119
|
+
const _updateIsValidating = (names, isValidating) => {
|
|
7120
|
+
if (!_options.disabled && (_proxyFormState.isValidating || _proxyFormState.validatingFields || _proxySubscribeFormState.isValidating || _proxySubscribeFormState.validatingFields)) {
|
|
7121
|
+
(names || Array.from(_names.mount)).forEach((name) => {
|
|
7122
|
+
if (name) {
|
|
7123
|
+
isValidating ? set(_formState.validatingFields, name, isValidating) : unset(_formState.validatingFields, name);
|
|
7124
|
+
}
|
|
7125
|
+
});
|
|
7126
|
+
_subjects.state.next({
|
|
7127
|
+
validatingFields: _formState.validatingFields,
|
|
7128
|
+
isValidating: !isEmptyObject(_formState.validatingFields)
|
|
7129
|
+
});
|
|
7130
|
+
}
|
|
7131
|
+
};
|
|
7132
|
+
const _setFieldArray = (name, values = [], method, args, shouldSetValues = true, shouldUpdateFieldsAndState = true) => {
|
|
7133
|
+
if (args && method && !_options.disabled) {
|
|
7134
|
+
_state.action = true;
|
|
7135
|
+
if (shouldUpdateFieldsAndState && Array.isArray(get(_fields, name))) {
|
|
7136
|
+
const fieldValues = method(get(_fields, name), args.argA, args.argB);
|
|
7137
|
+
shouldSetValues && set(_fields, name, fieldValues);
|
|
7138
|
+
}
|
|
7139
|
+
if (shouldUpdateFieldsAndState && Array.isArray(get(_formState.errors, name))) {
|
|
7140
|
+
const errors = method(get(_formState.errors, name), args.argA, args.argB);
|
|
7141
|
+
shouldSetValues && set(_formState.errors, name, errors);
|
|
7142
|
+
unsetEmptyArray(_formState.errors, name);
|
|
7143
|
+
}
|
|
7144
|
+
if ((_proxyFormState.touchedFields || _proxySubscribeFormState.touchedFields) && shouldUpdateFieldsAndState && Array.isArray(get(_formState.touchedFields, name))) {
|
|
7145
|
+
const touchedFields = method(get(_formState.touchedFields, name), args.argA, args.argB);
|
|
7146
|
+
shouldSetValues && set(_formState.touchedFields, name, touchedFields);
|
|
7147
|
+
}
|
|
7148
|
+
if (_proxyFormState.dirtyFields || _proxySubscribeFormState.dirtyFields) {
|
|
7149
|
+
_formState.dirtyFields = getDirtyFields(_defaultValues, _formValues);
|
|
7150
|
+
}
|
|
7151
|
+
_subjects.state.next({
|
|
7152
|
+
name,
|
|
7153
|
+
isDirty: _getDirty(name, values),
|
|
7154
|
+
dirtyFields: _formState.dirtyFields,
|
|
7155
|
+
errors: _formState.errors,
|
|
7156
|
+
isValid: _formState.isValid
|
|
7157
|
+
});
|
|
7158
|
+
} else {
|
|
7159
|
+
set(_formValues, name, values);
|
|
7160
|
+
}
|
|
7161
|
+
};
|
|
7162
|
+
const updateErrors = (name, error) => {
|
|
7163
|
+
set(_formState.errors, name, error);
|
|
7164
|
+
_subjects.state.next({
|
|
7165
|
+
errors: _formState.errors
|
|
7166
|
+
});
|
|
7167
|
+
};
|
|
7168
|
+
const _setErrors = (errors) => {
|
|
7169
|
+
_formState.errors = errors;
|
|
7170
|
+
_subjects.state.next({
|
|
7171
|
+
errors: _formState.errors,
|
|
7172
|
+
isValid: false
|
|
7173
|
+
});
|
|
7174
|
+
};
|
|
7175
|
+
const updateValidAndValue = (name, shouldSkipSetValueAs, value, ref) => {
|
|
7176
|
+
const field = get(_fields, name);
|
|
7177
|
+
if (field) {
|
|
7178
|
+
const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
|
|
7179
|
+
isUndefined(defaultValue) || ref && ref.defaultChecked || shouldSkipSetValueAs ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f)) : setFieldValue(name, defaultValue);
|
|
7180
|
+
_state.mount && _setValid();
|
|
7181
|
+
}
|
|
7182
|
+
};
|
|
7183
|
+
const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
|
|
7184
|
+
let shouldUpdateField = false;
|
|
7185
|
+
let isPreviousDirty = false;
|
|
7186
|
+
const output = {
|
|
7187
|
+
name
|
|
7188
|
+
};
|
|
7189
|
+
if (!_options.disabled) {
|
|
7190
|
+
if (!isBlurEvent || shouldDirty) {
|
|
7191
|
+
if (_proxyFormState.isDirty || _proxySubscribeFormState.isDirty) {
|
|
7192
|
+
isPreviousDirty = _formState.isDirty;
|
|
7193
|
+
_formState.isDirty = output.isDirty = _getDirty();
|
|
7194
|
+
shouldUpdateField = isPreviousDirty !== output.isDirty;
|
|
7195
|
+
}
|
|
7196
|
+
const isCurrentFieldPristine = deepEqual(get(_defaultValues, name), fieldValue);
|
|
7197
|
+
isPreviousDirty = !!get(_formState.dirtyFields, name);
|
|
7198
|
+
isCurrentFieldPristine ? unset(_formState.dirtyFields, name) : set(_formState.dirtyFields, name, true);
|
|
7199
|
+
output.dirtyFields = _formState.dirtyFields;
|
|
7200
|
+
shouldUpdateField = shouldUpdateField || (_proxyFormState.dirtyFields || _proxySubscribeFormState.dirtyFields) && isPreviousDirty !== !isCurrentFieldPristine;
|
|
7201
|
+
}
|
|
7202
|
+
if (isBlurEvent) {
|
|
7203
|
+
const isPreviousFieldTouched = get(_formState.touchedFields, name);
|
|
7204
|
+
if (!isPreviousFieldTouched) {
|
|
7205
|
+
set(_formState.touchedFields, name, isBlurEvent);
|
|
7206
|
+
output.touchedFields = _formState.touchedFields;
|
|
7207
|
+
shouldUpdateField = shouldUpdateField || (_proxyFormState.touchedFields || _proxySubscribeFormState.touchedFields) && isPreviousFieldTouched !== isBlurEvent;
|
|
7208
|
+
}
|
|
7209
|
+
}
|
|
7210
|
+
shouldUpdateField && shouldRender && _subjects.state.next(output);
|
|
7211
|
+
}
|
|
7212
|
+
return shouldUpdateField ? output : {};
|
|
7213
|
+
};
|
|
7214
|
+
const shouldRenderByError = (name, isValid, error, fieldState) => {
|
|
7215
|
+
const previousFieldError = get(_formState.errors, name);
|
|
7216
|
+
const shouldUpdateValid = (_proxyFormState.isValid || _proxySubscribeFormState.isValid) && isBoolean(isValid) && _formState.isValid !== isValid;
|
|
7217
|
+
if (_options.delayError && error) {
|
|
7218
|
+
delayErrorCallback = debounce(() => updateErrors(name, error));
|
|
7219
|
+
delayErrorCallback(_options.delayError);
|
|
7220
|
+
} else {
|
|
7221
|
+
clearTimeout(timer);
|
|
7222
|
+
delayErrorCallback = null;
|
|
7223
|
+
error ? set(_formState.errors, name, error) : unset(_formState.errors, name);
|
|
7224
|
+
}
|
|
7225
|
+
if ((error ? !deepEqual(previousFieldError, error) : previousFieldError) || !isEmptyObject(fieldState) || shouldUpdateValid) {
|
|
7226
|
+
const updatedFormState = {
|
|
7227
|
+
...fieldState,
|
|
7228
|
+
...shouldUpdateValid && isBoolean(isValid) ? { isValid } : {},
|
|
7229
|
+
errors: _formState.errors,
|
|
7230
|
+
name
|
|
7231
|
+
};
|
|
7232
|
+
_formState = {
|
|
7233
|
+
..._formState,
|
|
7234
|
+
...updatedFormState
|
|
7235
|
+
};
|
|
7236
|
+
_subjects.state.next(updatedFormState);
|
|
7237
|
+
}
|
|
7238
|
+
};
|
|
7239
|
+
const _runSchema = async (name) => {
|
|
7240
|
+
_updateIsValidating(name, true);
|
|
7241
|
+
const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
7242
|
+
_updateIsValidating(name);
|
|
7243
|
+
return result;
|
|
7244
|
+
};
|
|
7245
|
+
const executeSchemaAndUpdateState = async (names) => {
|
|
7246
|
+
const { errors } = await _runSchema(names);
|
|
7247
|
+
if (names) {
|
|
7248
|
+
for (const name of names) {
|
|
7249
|
+
const error = get(errors, name);
|
|
7250
|
+
error ? set(_formState.errors, name, error) : unset(_formState.errors, name);
|
|
7251
|
+
}
|
|
7252
|
+
} else {
|
|
7253
|
+
_formState.errors = errors;
|
|
7254
|
+
}
|
|
7255
|
+
return errors;
|
|
7256
|
+
};
|
|
7257
|
+
const executeBuiltInValidation = async (fields, shouldOnlyCheckValid, context = {
|
|
7258
|
+
valid: true
|
|
7259
|
+
}) => {
|
|
7260
|
+
for (const name in fields) {
|
|
7261
|
+
const field = fields[name];
|
|
7262
|
+
if (field) {
|
|
7263
|
+
const { _f, ...fieldValue } = field;
|
|
7264
|
+
if (_f) {
|
|
7265
|
+
const isFieldArrayRoot = _names.array.has(_f.name);
|
|
7266
|
+
const isPromiseFunction = field._f && hasPromiseValidation(field._f);
|
|
7267
|
+
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
|
7268
|
+
_updateIsValidating([_f.name], true);
|
|
7269
|
+
}
|
|
7270
|
+
const fieldError = await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation && !shouldOnlyCheckValid, isFieldArrayRoot);
|
|
7271
|
+
if (isPromiseFunction && _proxyFormState.validatingFields) {
|
|
7272
|
+
_updateIsValidating([_f.name]);
|
|
7273
|
+
}
|
|
7274
|
+
if (fieldError[_f.name]) {
|
|
7275
|
+
context.valid = false;
|
|
7276
|
+
if (shouldOnlyCheckValid) {
|
|
7277
|
+
break;
|
|
7278
|
+
}
|
|
7279
|
+
}
|
|
7280
|
+
!shouldOnlyCheckValid && (get(fieldError, _f.name) ? isFieldArrayRoot ? updateFieldArrayRootError(_formState.errors, fieldError, _f.name) : set(_formState.errors, _f.name, fieldError[_f.name]) : unset(_formState.errors, _f.name));
|
|
7281
|
+
}
|
|
7282
|
+
!isEmptyObject(fieldValue) && await executeBuiltInValidation(fieldValue, shouldOnlyCheckValid, context);
|
|
7283
|
+
}
|
|
7284
|
+
}
|
|
7285
|
+
return context.valid;
|
|
7286
|
+
};
|
|
7287
|
+
const _removeUnmounted = () => {
|
|
7288
|
+
for (const name of _names.unMount) {
|
|
7289
|
+
const field = get(_fields, name);
|
|
7290
|
+
field && (field._f.refs ? field._f.refs.every((ref) => !live(ref)) : !live(field._f.ref)) && unregister(name);
|
|
7291
|
+
}
|
|
7292
|
+
_names.unMount = /* @__PURE__ */ new Set();
|
|
7293
|
+
};
|
|
7294
|
+
const _getDirty = (name, data) => !_options.disabled && (name && data && set(_formValues, name, data), !deepEqual(getValues(), _defaultValues));
|
|
7295
|
+
const _getWatch = (names, defaultValue, isGlobal) => generateWatchOutput(names, _names, {
|
|
7296
|
+
..._state.mount ? _formValues : isUndefined(defaultValue) ? _defaultValues : isString(names) ? { [names]: defaultValue } : defaultValue
|
|
7297
|
+
}, isGlobal, defaultValue);
|
|
7298
|
+
const _getFieldArray = (name) => compact(get(_state.mount ? _formValues : _defaultValues, name, _options.shouldUnregister ? get(_defaultValues, name, []) : []));
|
|
7299
|
+
const setFieldValue = (name, value, options = {}) => {
|
|
7300
|
+
const field = get(_fields, name);
|
|
7301
|
+
let fieldValue = value;
|
|
7302
|
+
if (field) {
|
|
7303
|
+
const fieldReference = field._f;
|
|
7304
|
+
if (fieldReference) {
|
|
7305
|
+
!fieldReference.disabled && set(_formValues, name, getFieldValueAs(value, fieldReference));
|
|
7306
|
+
fieldValue = isHTMLElement(fieldReference.ref) && isNullOrUndefined(value) ? "" : value;
|
|
7307
|
+
if (isMultipleSelect(fieldReference.ref)) {
|
|
7308
|
+
[...fieldReference.ref.options].forEach((optionRef) => optionRef.selected = fieldValue.includes(optionRef.value));
|
|
7309
|
+
} else if (fieldReference.refs) {
|
|
7310
|
+
if (isCheckBoxInput(fieldReference.ref)) {
|
|
7311
|
+
fieldReference.refs.forEach((checkboxRef) => {
|
|
7312
|
+
if (!checkboxRef.defaultChecked || !checkboxRef.disabled) {
|
|
7313
|
+
if (Array.isArray(fieldValue)) {
|
|
7314
|
+
checkboxRef.checked = !!fieldValue.find((data) => data === checkboxRef.value);
|
|
7315
|
+
} else {
|
|
7316
|
+
checkboxRef.checked = fieldValue === checkboxRef.value || !!fieldValue;
|
|
7317
|
+
}
|
|
7318
|
+
}
|
|
7319
|
+
});
|
|
7320
|
+
} else {
|
|
7321
|
+
fieldReference.refs.forEach((radioRef) => radioRef.checked = radioRef.value === fieldValue);
|
|
7322
|
+
}
|
|
7323
|
+
} else if (isFileInput(fieldReference.ref)) {
|
|
7324
|
+
fieldReference.ref.value = "";
|
|
7325
|
+
} else {
|
|
7326
|
+
fieldReference.ref.value = fieldValue;
|
|
7327
|
+
if (!fieldReference.ref.type) {
|
|
7328
|
+
_subjects.state.next({
|
|
7329
|
+
name,
|
|
7330
|
+
values: cloneObject(_formValues)
|
|
7331
|
+
});
|
|
7332
|
+
}
|
|
7333
|
+
}
|
|
7334
|
+
}
|
|
7335
|
+
}
|
|
7336
|
+
(options.shouldDirty || options.shouldTouch) && updateTouchAndDirty(name, fieldValue, options.shouldTouch, options.shouldDirty, true);
|
|
7337
|
+
options.shouldValidate && trigger(name);
|
|
7338
|
+
};
|
|
7339
|
+
const setValues = (name, value, options) => {
|
|
7340
|
+
for (const fieldKey in value) {
|
|
7341
|
+
if (!value.hasOwnProperty(fieldKey)) {
|
|
7342
|
+
return;
|
|
7343
|
+
}
|
|
7344
|
+
const fieldValue = value[fieldKey];
|
|
7345
|
+
const fieldName = name + "." + fieldKey;
|
|
7346
|
+
const field = get(_fields, fieldName);
|
|
7347
|
+
(_names.array.has(name) || isObject(fieldValue) || field && !field._f) && !isDateObject(fieldValue) ? setValues(fieldName, fieldValue, options) : setFieldValue(fieldName, fieldValue, options);
|
|
7348
|
+
}
|
|
7349
|
+
};
|
|
7350
|
+
const setValue = (name, value, options = {}) => {
|
|
7351
|
+
const field = get(_fields, name);
|
|
7352
|
+
const isFieldArray = _names.array.has(name);
|
|
7353
|
+
const cloneValue = cloneObject(value);
|
|
7354
|
+
set(_formValues, name, cloneValue);
|
|
7355
|
+
if (isFieldArray) {
|
|
7356
|
+
_subjects.array.next({
|
|
7357
|
+
name,
|
|
7358
|
+
values: cloneObject(_formValues)
|
|
7359
|
+
});
|
|
7360
|
+
if ((_proxyFormState.isDirty || _proxyFormState.dirtyFields || _proxySubscribeFormState.isDirty || _proxySubscribeFormState.dirtyFields) && options.shouldDirty) {
|
|
7361
|
+
_subjects.state.next({
|
|
7362
|
+
name,
|
|
7363
|
+
dirtyFields: getDirtyFields(_defaultValues, _formValues),
|
|
7364
|
+
isDirty: _getDirty(name, cloneValue)
|
|
7365
|
+
});
|
|
7366
|
+
}
|
|
7367
|
+
} else {
|
|
7368
|
+
field && !field._f && !isNullOrUndefined(cloneValue) ? setValues(name, cloneValue, options) : setFieldValue(name, cloneValue, options);
|
|
7369
|
+
}
|
|
7370
|
+
isWatched(name, _names) && _subjects.state.next({ ..._formState, name });
|
|
7371
|
+
_subjects.state.next({
|
|
7372
|
+
name: _state.mount ? name : void 0,
|
|
7373
|
+
values: cloneObject(_formValues)
|
|
7374
|
+
});
|
|
7375
|
+
};
|
|
7376
|
+
const onChange = async (event) => {
|
|
7377
|
+
_state.mount = true;
|
|
7378
|
+
const target = event.target;
|
|
7379
|
+
let name = target.name;
|
|
7380
|
+
let isFieldValueUpdated = true;
|
|
7381
|
+
const field = get(_fields, name);
|
|
7382
|
+
const _updateIsFieldValueUpdated = (fieldValue) => {
|
|
7383
|
+
isFieldValueUpdated = Number.isNaN(fieldValue) || isDateObject(fieldValue) && isNaN(fieldValue.getTime()) || deepEqual(fieldValue, get(_formValues, name, fieldValue));
|
|
7384
|
+
};
|
|
7385
|
+
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
|
7386
|
+
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
|
7387
|
+
if (field) {
|
|
7388
|
+
let error;
|
|
7389
|
+
let isValid;
|
|
7390
|
+
const fieldValue = target.type ? getFieldValue(field._f) : getEventValue(event);
|
|
7391
|
+
const isBlurEvent = event.type === EVENTS.BLUR || event.type === EVENTS.FOCUS_OUT;
|
|
7392
|
+
const shouldSkipValidation = !hasValidation(field._f) && !_options.resolver && !get(_formState.errors, name) && !field._f.deps || skipValidation(isBlurEvent, get(_formState.touchedFields, name), _formState.isSubmitted, validationModeAfterSubmit, validationModeBeforeSubmit);
|
|
7393
|
+
const watched = isWatched(name, _names, isBlurEvent);
|
|
7394
|
+
set(_formValues, name, fieldValue);
|
|
7395
|
+
if (isBlurEvent) {
|
|
7396
|
+
if (!target || !target.readOnly) {
|
|
7397
|
+
field._f.onBlur && field._f.onBlur(event);
|
|
7398
|
+
delayErrorCallback && delayErrorCallback(0);
|
|
7399
|
+
}
|
|
7400
|
+
} else if (field._f.onChange) {
|
|
7401
|
+
field._f.onChange(event);
|
|
7402
|
+
}
|
|
7403
|
+
const fieldState = updateTouchAndDirty(name, fieldValue, isBlurEvent);
|
|
7404
|
+
const shouldRender = !isEmptyObject(fieldState) || watched;
|
|
7405
|
+
!isBlurEvent && _subjects.state.next({
|
|
7406
|
+
name,
|
|
7407
|
+
type: event.type,
|
|
7408
|
+
values: cloneObject(_formValues)
|
|
7409
|
+
});
|
|
7410
|
+
if (shouldSkipValidation) {
|
|
7411
|
+
if (_proxyFormState.isValid || _proxySubscribeFormState.isValid) {
|
|
7412
|
+
if (_options.mode === "onBlur") {
|
|
7413
|
+
if (isBlurEvent) {
|
|
7414
|
+
_setValid();
|
|
7415
|
+
}
|
|
7416
|
+
} else if (!isBlurEvent) {
|
|
7417
|
+
_setValid();
|
|
7418
|
+
}
|
|
7419
|
+
}
|
|
7420
|
+
return shouldRender && _subjects.state.next({ name, ...watched ? {} : fieldState });
|
|
7421
|
+
}
|
|
7422
|
+
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
|
7423
|
+
if (_options.resolver) {
|
|
7424
|
+
const { errors } = await _runSchema([name]);
|
|
7425
|
+
_updateIsFieldValueUpdated(fieldValue);
|
|
7426
|
+
if (isFieldValueUpdated) {
|
|
7427
|
+
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
7428
|
+
const errorLookupResult = schemaErrorLookup(errors, _fields, previousErrorLookupResult.name || name);
|
|
7429
|
+
error = errorLookupResult.error;
|
|
7430
|
+
name = errorLookupResult.name;
|
|
7431
|
+
isValid = isEmptyObject(errors);
|
|
7432
|
+
}
|
|
7433
|
+
} else {
|
|
7434
|
+
_updateIsValidating([name], true);
|
|
7435
|
+
error = (await validateField(field, _names.disabled, _formValues, shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation))[name];
|
|
7436
|
+
_updateIsValidating([name]);
|
|
7437
|
+
_updateIsFieldValueUpdated(fieldValue);
|
|
7438
|
+
if (isFieldValueUpdated) {
|
|
7439
|
+
if (error) {
|
|
7440
|
+
isValid = false;
|
|
7441
|
+
} else if (_proxyFormState.isValid || _proxySubscribeFormState.isValid) {
|
|
7442
|
+
isValid = await executeBuiltInValidation(_fields, true);
|
|
7443
|
+
}
|
|
7444
|
+
}
|
|
7445
|
+
}
|
|
7446
|
+
if (isFieldValueUpdated) {
|
|
7447
|
+
field._f.deps && (!Array.isArray(field._f.deps) || field._f.deps.length > 0) && trigger(field._f.deps);
|
|
7448
|
+
shouldRenderByError(name, isValid, error, fieldState);
|
|
7449
|
+
}
|
|
7450
|
+
}
|
|
7451
|
+
};
|
|
7452
|
+
const _focusInput = (ref, key) => {
|
|
7453
|
+
if (get(_formState.errors, key) && ref.focus) {
|
|
7454
|
+
ref.focus();
|
|
7455
|
+
return 1;
|
|
7456
|
+
}
|
|
7457
|
+
return;
|
|
7458
|
+
};
|
|
7459
|
+
const trigger = async (name, options = {}) => {
|
|
7460
|
+
let isValid;
|
|
7461
|
+
let validationResult;
|
|
7462
|
+
const fieldNames = convertToArrayPayload(name);
|
|
7463
|
+
if (_options.resolver) {
|
|
7464
|
+
const errors = await executeSchemaAndUpdateState(isUndefined(name) ? name : fieldNames);
|
|
7465
|
+
isValid = isEmptyObject(errors);
|
|
7466
|
+
validationResult = name ? !fieldNames.some((name2) => get(errors, name2)) : isValid;
|
|
7467
|
+
} else if (name) {
|
|
7468
|
+
validationResult = (await Promise.all(fieldNames.map(async (fieldName) => {
|
|
7469
|
+
const field = get(_fields, fieldName);
|
|
7470
|
+
return await executeBuiltInValidation(field && field._f ? { [fieldName]: field } : field);
|
|
7471
|
+
}))).every(Boolean);
|
|
7472
|
+
!(!validationResult && !_formState.isValid) && _setValid();
|
|
7473
|
+
} else {
|
|
7474
|
+
validationResult = isValid = await executeBuiltInValidation(_fields);
|
|
7475
|
+
}
|
|
7476
|
+
_subjects.state.next({
|
|
7477
|
+
...!isString(name) || (_proxyFormState.isValid || _proxySubscribeFormState.isValid) && isValid !== _formState.isValid ? {} : { name },
|
|
7478
|
+
..._options.resolver || !name ? { isValid } : {},
|
|
7479
|
+
errors: _formState.errors
|
|
7480
|
+
});
|
|
7481
|
+
options.shouldFocus && !validationResult && iterateFieldsByAction(_fields, _focusInput, name ? fieldNames : _names.mount);
|
|
7482
|
+
return validationResult;
|
|
7483
|
+
};
|
|
7484
|
+
const getValues = (fieldNames, config) => {
|
|
7485
|
+
let values = {
|
|
7486
|
+
..._state.mount ? _formValues : _defaultValues
|
|
7487
|
+
};
|
|
7488
|
+
if (config) {
|
|
7489
|
+
values = extractFormValues(config.dirtyFields ? _formState.dirtyFields : _formState.touchedFields, values);
|
|
7490
|
+
}
|
|
7491
|
+
return isUndefined(fieldNames) ? values : isString(fieldNames) ? get(values, fieldNames) : fieldNames.map((name) => get(values, name));
|
|
7492
|
+
};
|
|
7493
|
+
const getFieldState = (name, formState) => ({
|
|
7494
|
+
invalid: !!get((formState || _formState).errors, name),
|
|
7495
|
+
isDirty: !!get((formState || _formState).dirtyFields, name),
|
|
7496
|
+
error: get((formState || _formState).errors, name),
|
|
7497
|
+
isValidating: !!get(_formState.validatingFields, name),
|
|
7498
|
+
isTouched: !!get((formState || _formState).touchedFields, name)
|
|
7499
|
+
});
|
|
7500
|
+
const clearErrors = (name) => {
|
|
7501
|
+
name && convertToArrayPayload(name).forEach((inputName) => unset(_formState.errors, inputName));
|
|
7502
|
+
_subjects.state.next({
|
|
7503
|
+
errors: name ? _formState.errors : {}
|
|
7504
|
+
});
|
|
7505
|
+
};
|
|
7506
|
+
const setError = (name, error, options) => {
|
|
7507
|
+
const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
|
|
7508
|
+
const currentError = get(_formState.errors, name) || {};
|
|
7509
|
+
const { ref: currentRef, message, type, ...restOfErrorTree } = currentError;
|
|
7510
|
+
set(_formState.errors, name, {
|
|
7511
|
+
...restOfErrorTree,
|
|
7512
|
+
...error,
|
|
7513
|
+
ref
|
|
7514
|
+
});
|
|
7515
|
+
_subjects.state.next({
|
|
7516
|
+
name,
|
|
7517
|
+
errors: _formState.errors,
|
|
7518
|
+
isValid: false
|
|
7519
|
+
});
|
|
7520
|
+
options && options.shouldFocus && ref && ref.focus && ref.focus();
|
|
7521
|
+
};
|
|
7522
|
+
const watch = (name, defaultValue) => isFunction(name) ? _subjects.state.subscribe({
|
|
7523
|
+
next: (payload) => "values" in payload && name(_getWatch(void 0, defaultValue), payload)
|
|
7524
|
+
}) : _getWatch(name, defaultValue, true);
|
|
7525
|
+
const _subscribe = (props2) => _subjects.state.subscribe({
|
|
7526
|
+
next: (formState) => {
|
|
7527
|
+
if (shouldSubscribeByName(props2.name, formState.name, props2.exact) && shouldRenderFormState(formState, props2.formState || _proxyFormState, _setFormState, props2.reRenderRoot)) {
|
|
7528
|
+
props2.callback({
|
|
7529
|
+
values: { ..._formValues },
|
|
7530
|
+
..._formState,
|
|
7531
|
+
...formState,
|
|
7532
|
+
defaultValues: _defaultValues
|
|
7533
|
+
});
|
|
7534
|
+
}
|
|
7535
|
+
}
|
|
7536
|
+
}).unsubscribe;
|
|
7537
|
+
const subscribe = (props2) => {
|
|
7538
|
+
_state.mount = true;
|
|
7539
|
+
_proxySubscribeFormState = {
|
|
7540
|
+
..._proxySubscribeFormState,
|
|
7541
|
+
...props2.formState
|
|
7542
|
+
};
|
|
7543
|
+
return _subscribe({
|
|
7544
|
+
...props2,
|
|
7545
|
+
formState: _proxySubscribeFormState
|
|
7546
|
+
});
|
|
7547
|
+
};
|
|
7548
|
+
const unregister = (name, options = {}) => {
|
|
7549
|
+
for (const fieldName of name ? convertToArrayPayload(name) : _names.mount) {
|
|
7550
|
+
_names.mount.delete(fieldName);
|
|
7551
|
+
_names.array.delete(fieldName);
|
|
7552
|
+
if (!options.keepValue) {
|
|
7553
|
+
unset(_fields, fieldName);
|
|
7554
|
+
unset(_formValues, fieldName);
|
|
7555
|
+
}
|
|
7556
|
+
!options.keepError && unset(_formState.errors, fieldName);
|
|
7557
|
+
!options.keepDirty && unset(_formState.dirtyFields, fieldName);
|
|
7558
|
+
!options.keepTouched && unset(_formState.touchedFields, fieldName);
|
|
7559
|
+
!options.keepIsValidating && unset(_formState.validatingFields, fieldName);
|
|
7560
|
+
!_options.shouldUnregister && !options.keepDefaultValue && unset(_defaultValues, fieldName);
|
|
7561
|
+
}
|
|
7562
|
+
_subjects.state.next({
|
|
7563
|
+
values: cloneObject(_formValues)
|
|
7564
|
+
});
|
|
7565
|
+
_subjects.state.next({
|
|
7566
|
+
..._formState,
|
|
7567
|
+
...!options.keepDirty ? {} : { isDirty: _getDirty() }
|
|
7568
|
+
});
|
|
7569
|
+
!options.keepIsValid && _setValid();
|
|
7570
|
+
};
|
|
7571
|
+
const _setDisabledField = ({ disabled, name }) => {
|
|
7572
|
+
if (isBoolean(disabled) && _state.mount || !!disabled || _names.disabled.has(name)) {
|
|
7573
|
+
disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
|
|
7574
|
+
}
|
|
7575
|
+
};
|
|
7576
|
+
const register = (name, options = {}) => {
|
|
7577
|
+
let field = get(_fields, name);
|
|
7578
|
+
const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
|
|
7579
|
+
set(_fields, name, {
|
|
7580
|
+
...field || {},
|
|
7581
|
+
_f: {
|
|
7582
|
+
...field && field._f ? field._f : { ref: { name } },
|
|
7583
|
+
name,
|
|
7584
|
+
mount: true,
|
|
7585
|
+
...options
|
|
7586
|
+
}
|
|
7587
|
+
});
|
|
7588
|
+
_names.mount.add(name);
|
|
7589
|
+
if (field) {
|
|
7590
|
+
_setDisabledField({
|
|
7591
|
+
disabled: isBoolean(options.disabled) ? options.disabled : _options.disabled,
|
|
7592
|
+
name
|
|
7593
|
+
});
|
|
7594
|
+
} else {
|
|
7595
|
+
updateValidAndValue(name, true, options.value);
|
|
7596
|
+
}
|
|
7597
|
+
return {
|
|
7598
|
+
...disabledIsDefined ? { disabled: options.disabled || _options.disabled } : {},
|
|
7599
|
+
..._options.progressive ? {
|
|
7600
|
+
required: !!options.required,
|
|
7601
|
+
min: getRuleValue(options.min),
|
|
7602
|
+
max: getRuleValue(options.max),
|
|
7603
|
+
minLength: getRuleValue(options.minLength),
|
|
7604
|
+
maxLength: getRuleValue(options.maxLength),
|
|
7605
|
+
pattern: getRuleValue(options.pattern)
|
|
7606
|
+
} : {},
|
|
7607
|
+
name,
|
|
7608
|
+
onChange,
|
|
7609
|
+
onBlur: onChange,
|
|
7610
|
+
ref: (ref) => {
|
|
7611
|
+
if (ref) {
|
|
7612
|
+
register(name, options);
|
|
7613
|
+
field = get(_fields, name);
|
|
7614
|
+
const fieldRef = isUndefined(ref.value) ? ref.querySelectorAll ? ref.querySelectorAll("input,select,textarea")[0] || ref : ref : ref;
|
|
7615
|
+
const radioOrCheckbox = isRadioOrCheckbox(fieldRef);
|
|
7616
|
+
const refs = field._f.refs || [];
|
|
7617
|
+
if (radioOrCheckbox ? refs.find((option) => option === fieldRef) : fieldRef === field._f.ref) {
|
|
7618
|
+
return;
|
|
7619
|
+
}
|
|
7620
|
+
set(_fields, name, {
|
|
7621
|
+
_f: {
|
|
7622
|
+
...field._f,
|
|
7623
|
+
...radioOrCheckbox ? {
|
|
7624
|
+
refs: [
|
|
7625
|
+
...refs.filter(live),
|
|
7626
|
+
fieldRef,
|
|
7627
|
+
...Array.isArray(get(_defaultValues, name)) ? [{}] : []
|
|
7628
|
+
],
|
|
7629
|
+
ref: { type: fieldRef.type, name }
|
|
7630
|
+
} : { ref: fieldRef }
|
|
7631
|
+
}
|
|
7632
|
+
});
|
|
7633
|
+
updateValidAndValue(name, false, void 0, fieldRef);
|
|
7634
|
+
} else {
|
|
7635
|
+
field = get(_fields, name, {});
|
|
7636
|
+
if (field._f) {
|
|
7637
|
+
field._f.mount = false;
|
|
7638
|
+
}
|
|
7639
|
+
(_options.shouldUnregister || options.shouldUnregister) && !(isNameInFieldArray(_names.array, name) && _state.action) && _names.unMount.add(name);
|
|
7640
|
+
}
|
|
7641
|
+
}
|
|
7642
|
+
};
|
|
7643
|
+
};
|
|
7644
|
+
const _focusError = () => _options.shouldFocusError && iterateFieldsByAction(_fields, _focusInput, _names.mount);
|
|
7645
|
+
const _disableForm = (disabled) => {
|
|
7646
|
+
if (isBoolean(disabled)) {
|
|
7647
|
+
_subjects.state.next({ disabled });
|
|
7648
|
+
iterateFieldsByAction(_fields, (ref, name) => {
|
|
7649
|
+
const currentField = get(_fields, name);
|
|
7650
|
+
if (currentField) {
|
|
7651
|
+
ref.disabled = currentField._f.disabled || disabled;
|
|
7652
|
+
if (Array.isArray(currentField._f.refs)) {
|
|
7653
|
+
currentField._f.refs.forEach((inputRef) => {
|
|
7654
|
+
inputRef.disabled = currentField._f.disabled || disabled;
|
|
7655
|
+
});
|
|
7656
|
+
}
|
|
7657
|
+
}
|
|
7658
|
+
}, 0, false);
|
|
7659
|
+
}
|
|
7660
|
+
};
|
|
7661
|
+
const handleSubmit = (onValid, onInvalid) => async (e) => {
|
|
7662
|
+
let onValidError = void 0;
|
|
7663
|
+
if (e) {
|
|
7664
|
+
e.preventDefault && e.preventDefault();
|
|
7665
|
+
e.persist && e.persist();
|
|
7666
|
+
}
|
|
7667
|
+
let fieldValues = cloneObject(_formValues);
|
|
7668
|
+
_subjects.state.next({
|
|
7669
|
+
isSubmitting: true
|
|
7670
|
+
});
|
|
7671
|
+
if (_options.resolver) {
|
|
7672
|
+
const { errors, values } = await _runSchema();
|
|
7673
|
+
_formState.errors = errors;
|
|
7674
|
+
fieldValues = cloneObject(values);
|
|
7675
|
+
} else {
|
|
7676
|
+
await executeBuiltInValidation(_fields);
|
|
7677
|
+
}
|
|
7678
|
+
if (_names.disabled.size) {
|
|
7679
|
+
for (const name of _names.disabled) {
|
|
7680
|
+
unset(fieldValues, name);
|
|
7681
|
+
}
|
|
7682
|
+
}
|
|
7683
|
+
unset(_formState.errors, "root");
|
|
7684
|
+
if (isEmptyObject(_formState.errors)) {
|
|
7685
|
+
_subjects.state.next({
|
|
7686
|
+
errors: {}
|
|
7687
|
+
});
|
|
7688
|
+
try {
|
|
7689
|
+
await onValid(fieldValues, e);
|
|
7690
|
+
} catch (error) {
|
|
7691
|
+
onValidError = error;
|
|
7692
|
+
}
|
|
7693
|
+
} else {
|
|
7694
|
+
if (onInvalid) {
|
|
7695
|
+
await onInvalid({ ..._formState.errors }, e);
|
|
7696
|
+
}
|
|
7697
|
+
_focusError();
|
|
7698
|
+
setTimeout(_focusError);
|
|
7699
|
+
}
|
|
7700
|
+
_subjects.state.next({
|
|
7701
|
+
isSubmitted: true,
|
|
7702
|
+
isSubmitting: false,
|
|
7703
|
+
isSubmitSuccessful: isEmptyObject(_formState.errors) && !onValidError,
|
|
7704
|
+
submitCount: _formState.submitCount + 1,
|
|
7705
|
+
errors: _formState.errors
|
|
7706
|
+
});
|
|
7707
|
+
if (onValidError) {
|
|
7708
|
+
throw onValidError;
|
|
7709
|
+
}
|
|
7710
|
+
};
|
|
7711
|
+
const resetField = (name, options = {}) => {
|
|
7712
|
+
if (get(_fields, name)) {
|
|
7713
|
+
if (isUndefined(options.defaultValue)) {
|
|
7714
|
+
setValue(name, cloneObject(get(_defaultValues, name)));
|
|
7715
|
+
} else {
|
|
7716
|
+
setValue(name, options.defaultValue);
|
|
7717
|
+
set(_defaultValues, name, cloneObject(options.defaultValue));
|
|
7718
|
+
}
|
|
7719
|
+
if (!options.keepTouched) {
|
|
7720
|
+
unset(_formState.touchedFields, name);
|
|
7721
|
+
}
|
|
7722
|
+
if (!options.keepDirty) {
|
|
7723
|
+
unset(_formState.dirtyFields, name);
|
|
7724
|
+
_formState.isDirty = options.defaultValue ? _getDirty(name, cloneObject(get(_defaultValues, name))) : _getDirty();
|
|
7725
|
+
}
|
|
7726
|
+
if (!options.keepError) {
|
|
7727
|
+
unset(_formState.errors, name);
|
|
7728
|
+
_proxyFormState.isValid && _setValid();
|
|
7729
|
+
}
|
|
7730
|
+
_subjects.state.next({ ..._formState });
|
|
7731
|
+
}
|
|
7732
|
+
};
|
|
7733
|
+
const _reset = (formValues, keepStateOptions = {}) => {
|
|
7734
|
+
const updatedValues = formValues ? cloneObject(formValues) : _defaultValues;
|
|
7735
|
+
const cloneUpdatedValues = cloneObject(updatedValues);
|
|
7736
|
+
const isEmptyResetValues = isEmptyObject(formValues);
|
|
7737
|
+
const values = isEmptyResetValues ? _defaultValues : cloneUpdatedValues;
|
|
7738
|
+
if (!keepStateOptions.keepDefaultValues) {
|
|
7739
|
+
_defaultValues = updatedValues;
|
|
7740
|
+
}
|
|
7741
|
+
if (!keepStateOptions.keepValues) {
|
|
7742
|
+
if (keepStateOptions.keepDirtyValues) {
|
|
7743
|
+
const fieldsToCheck = /* @__PURE__ */ new Set([
|
|
7744
|
+
..._names.mount,
|
|
7745
|
+
...Object.keys(getDirtyFields(_defaultValues, _formValues))
|
|
7746
|
+
]);
|
|
7747
|
+
for (const fieldName of Array.from(fieldsToCheck)) {
|
|
7748
|
+
get(_formState.dirtyFields, fieldName) ? set(values, fieldName, get(_formValues, fieldName)) : setValue(fieldName, get(values, fieldName));
|
|
7749
|
+
}
|
|
7750
|
+
} else {
|
|
7751
|
+
if (isWeb && isUndefined(formValues)) {
|
|
7752
|
+
for (const name of _names.mount) {
|
|
7753
|
+
const field = get(_fields, name);
|
|
7754
|
+
if (field && field._f) {
|
|
7755
|
+
const fieldReference = Array.isArray(field._f.refs) ? field._f.refs[0] : field._f.ref;
|
|
7756
|
+
if (isHTMLElement(fieldReference)) {
|
|
7757
|
+
const form = fieldReference.closest("form");
|
|
7758
|
+
if (form) {
|
|
7759
|
+
form.reset();
|
|
7760
|
+
break;
|
|
7761
|
+
}
|
|
7762
|
+
}
|
|
7763
|
+
}
|
|
7764
|
+
}
|
|
7765
|
+
}
|
|
7766
|
+
if (keepStateOptions.keepFieldsRef) {
|
|
7767
|
+
for (const fieldName of _names.mount) {
|
|
7768
|
+
setValue(fieldName, get(values, fieldName));
|
|
7769
|
+
}
|
|
7770
|
+
} else {
|
|
7771
|
+
_fields = {};
|
|
7772
|
+
}
|
|
7773
|
+
}
|
|
7774
|
+
_formValues = _options.shouldUnregister ? keepStateOptions.keepDefaultValues ? cloneObject(_defaultValues) : {} : cloneObject(values);
|
|
7775
|
+
_subjects.array.next({
|
|
7776
|
+
values: { ...values }
|
|
7777
|
+
});
|
|
7778
|
+
_subjects.state.next({
|
|
7779
|
+
values: { ...values }
|
|
7780
|
+
});
|
|
7781
|
+
}
|
|
7782
|
+
_names = {
|
|
7783
|
+
mount: keepStateOptions.keepDirtyValues ? _names.mount : /* @__PURE__ */ new Set(),
|
|
7784
|
+
unMount: /* @__PURE__ */ new Set(),
|
|
7785
|
+
array: /* @__PURE__ */ new Set(),
|
|
7786
|
+
disabled: /* @__PURE__ */ new Set(),
|
|
7787
|
+
watch: /* @__PURE__ */ new Set(),
|
|
7788
|
+
watchAll: false,
|
|
7789
|
+
focus: ""
|
|
7790
|
+
};
|
|
7791
|
+
_state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid || !!keepStateOptions.keepDirtyValues;
|
|
7792
|
+
_state.watch = !!_options.shouldUnregister;
|
|
7793
|
+
_subjects.state.next({
|
|
7794
|
+
submitCount: keepStateOptions.keepSubmitCount ? _formState.submitCount : 0,
|
|
7795
|
+
isDirty: isEmptyResetValues ? false : keepStateOptions.keepDirty ? _formState.isDirty : !!(keepStateOptions.keepDefaultValues && !deepEqual(formValues, _defaultValues)),
|
|
7796
|
+
isSubmitted: keepStateOptions.keepIsSubmitted ? _formState.isSubmitted : false,
|
|
7797
|
+
dirtyFields: isEmptyResetValues ? {} : keepStateOptions.keepDirtyValues ? keepStateOptions.keepDefaultValues && _formValues ? getDirtyFields(_defaultValues, _formValues) : _formState.dirtyFields : keepStateOptions.keepDefaultValues && formValues ? getDirtyFields(_defaultValues, formValues) : keepStateOptions.keepDirty ? _formState.dirtyFields : {},
|
|
7798
|
+
touchedFields: keepStateOptions.keepTouched ? _formState.touchedFields : {},
|
|
7799
|
+
errors: keepStateOptions.keepErrors ? _formState.errors : {},
|
|
7800
|
+
isSubmitSuccessful: keepStateOptions.keepIsSubmitSuccessful ? _formState.isSubmitSuccessful : false,
|
|
7801
|
+
isSubmitting: false,
|
|
7802
|
+
defaultValues: _defaultValues
|
|
7803
|
+
});
|
|
7804
|
+
};
|
|
7805
|
+
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues) ? formValues(_formValues) : formValues, keepStateOptions);
|
|
7806
|
+
const setFocus = (name, options = {}) => {
|
|
7807
|
+
const field = get(_fields, name);
|
|
7808
|
+
const fieldReference = field && field._f;
|
|
7809
|
+
if (fieldReference) {
|
|
7810
|
+
const fieldRef = fieldReference.refs ? fieldReference.refs[0] : fieldReference.ref;
|
|
7811
|
+
if (fieldRef.focus) {
|
|
7812
|
+
fieldRef.focus();
|
|
7813
|
+
options.shouldSelect && isFunction(fieldRef.select) && fieldRef.select();
|
|
7814
|
+
}
|
|
7815
|
+
}
|
|
7816
|
+
};
|
|
7817
|
+
const _setFormState = (updatedFormState) => {
|
|
7818
|
+
_formState = {
|
|
7819
|
+
..._formState,
|
|
7820
|
+
...updatedFormState
|
|
7821
|
+
};
|
|
7822
|
+
};
|
|
7823
|
+
const _resetDefaultValues = () => isFunction(_options.defaultValues) && _options.defaultValues().then((values) => {
|
|
7824
|
+
reset(values, _options.resetOptions);
|
|
7825
|
+
_subjects.state.next({
|
|
7826
|
+
isLoading: false
|
|
7827
|
+
});
|
|
7828
|
+
});
|
|
7829
|
+
const methods = {
|
|
7830
|
+
control: {
|
|
7831
|
+
register,
|
|
7832
|
+
unregister,
|
|
7833
|
+
getFieldState,
|
|
7834
|
+
handleSubmit,
|
|
7835
|
+
setError,
|
|
7836
|
+
_subscribe,
|
|
7837
|
+
_runSchema,
|
|
7838
|
+
_focusError,
|
|
7839
|
+
_getWatch,
|
|
7840
|
+
_getDirty,
|
|
7841
|
+
_setValid,
|
|
7842
|
+
_setFieldArray,
|
|
7843
|
+
_setDisabledField,
|
|
7844
|
+
_setErrors,
|
|
7845
|
+
_getFieldArray,
|
|
7846
|
+
_reset,
|
|
7847
|
+
_resetDefaultValues,
|
|
7848
|
+
_removeUnmounted,
|
|
7849
|
+
_disableForm,
|
|
7850
|
+
_subjects,
|
|
7851
|
+
_proxyFormState,
|
|
7852
|
+
get _fields() {
|
|
7853
|
+
return _fields;
|
|
7854
|
+
},
|
|
7855
|
+
get _formValues() {
|
|
7856
|
+
return _formValues;
|
|
7857
|
+
},
|
|
7858
|
+
get _state() {
|
|
7859
|
+
return _state;
|
|
7860
|
+
},
|
|
7861
|
+
set _state(value) {
|
|
7862
|
+
_state = value;
|
|
7863
|
+
},
|
|
7864
|
+
get _defaultValues() {
|
|
7865
|
+
return _defaultValues;
|
|
7866
|
+
},
|
|
7867
|
+
get _names() {
|
|
7868
|
+
return _names;
|
|
7869
|
+
},
|
|
7870
|
+
set _names(value) {
|
|
7871
|
+
_names = value;
|
|
7872
|
+
},
|
|
7873
|
+
get _formState() {
|
|
7874
|
+
return _formState;
|
|
7875
|
+
},
|
|
7876
|
+
get _options() {
|
|
7877
|
+
return _options;
|
|
7878
|
+
},
|
|
7879
|
+
set _options(value) {
|
|
7880
|
+
_options = {
|
|
7881
|
+
..._options,
|
|
7882
|
+
...value
|
|
7883
|
+
};
|
|
7884
|
+
}
|
|
7885
|
+
},
|
|
7886
|
+
subscribe,
|
|
7887
|
+
trigger,
|
|
7888
|
+
register,
|
|
7889
|
+
handleSubmit,
|
|
7890
|
+
watch,
|
|
7891
|
+
setValue,
|
|
7892
|
+
getValues,
|
|
7893
|
+
reset,
|
|
7894
|
+
resetField,
|
|
7895
|
+
clearErrors,
|
|
7896
|
+
unregister,
|
|
7897
|
+
setError,
|
|
7898
|
+
setFocus,
|
|
7899
|
+
getFieldState
|
|
7900
|
+
};
|
|
7901
|
+
return {
|
|
7902
|
+
...methods,
|
|
7903
|
+
formControl: methods
|
|
7904
|
+
};
|
|
7905
|
+
}
|
|
7906
|
+
function useForm(props = {}) {
|
|
7907
|
+
const _formControl = React30.useRef(void 0);
|
|
7908
|
+
const _values = React30.useRef(void 0);
|
|
7909
|
+
const [formState, updateFormState] = React30.useState({
|
|
7910
|
+
isDirty: false,
|
|
7911
|
+
isValidating: false,
|
|
7912
|
+
isLoading: isFunction(props.defaultValues),
|
|
7913
|
+
isSubmitted: false,
|
|
7914
|
+
isSubmitting: false,
|
|
7915
|
+
isSubmitSuccessful: false,
|
|
7916
|
+
isValid: false,
|
|
7917
|
+
submitCount: 0,
|
|
7918
|
+
dirtyFields: {},
|
|
7919
|
+
touchedFields: {},
|
|
7920
|
+
validatingFields: {},
|
|
7921
|
+
errors: props.errors || {},
|
|
7922
|
+
disabled: props.disabled || false,
|
|
7923
|
+
isReady: false,
|
|
7924
|
+
defaultValues: isFunction(props.defaultValues) ? void 0 : props.defaultValues
|
|
7925
|
+
});
|
|
7926
|
+
if (!_formControl.current) {
|
|
7927
|
+
if (props.formControl) {
|
|
7928
|
+
_formControl.current = {
|
|
7929
|
+
...props.formControl,
|
|
7930
|
+
formState
|
|
7931
|
+
};
|
|
7932
|
+
if (props.defaultValues && !isFunction(props.defaultValues)) {
|
|
7933
|
+
props.formControl.reset(props.defaultValues, props.resetOptions);
|
|
7934
|
+
}
|
|
7935
|
+
} else {
|
|
7936
|
+
const { formControl, ...rest } = createFormControl(props);
|
|
7937
|
+
_formControl.current = {
|
|
7938
|
+
...rest,
|
|
7939
|
+
formState
|
|
7940
|
+
};
|
|
7941
|
+
}
|
|
7942
|
+
}
|
|
7943
|
+
const control = _formControl.current.control;
|
|
7944
|
+
control._options = props;
|
|
7945
|
+
useIsomorphicLayoutEffect(() => {
|
|
7946
|
+
const sub = control._subscribe({
|
|
7947
|
+
formState: control._proxyFormState,
|
|
7948
|
+
callback: () => updateFormState({ ...control._formState }),
|
|
7949
|
+
reRenderRoot: true
|
|
7950
|
+
});
|
|
7951
|
+
updateFormState((data) => ({
|
|
7952
|
+
...data,
|
|
7953
|
+
isReady: true
|
|
7954
|
+
}));
|
|
7955
|
+
control._formState.isReady = true;
|
|
7956
|
+
return sub;
|
|
7957
|
+
}, [control]);
|
|
7958
|
+
React30.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
|
|
7959
|
+
React30.useEffect(() => {
|
|
7960
|
+
if (props.mode) {
|
|
7961
|
+
control._options.mode = props.mode;
|
|
7962
|
+
}
|
|
7963
|
+
if (props.reValidateMode) {
|
|
7964
|
+
control._options.reValidateMode = props.reValidateMode;
|
|
7965
|
+
}
|
|
7966
|
+
}, [control, props.mode, props.reValidateMode]);
|
|
7967
|
+
React30.useEffect(() => {
|
|
7968
|
+
if (props.errors) {
|
|
7969
|
+
control._setErrors(props.errors);
|
|
7970
|
+
control._focusError();
|
|
7971
|
+
}
|
|
7972
|
+
}, [control, props.errors]);
|
|
7973
|
+
React30.useEffect(() => {
|
|
7974
|
+
props.shouldUnregister && control._subjects.state.next({
|
|
7975
|
+
values: control._getWatch()
|
|
7976
|
+
});
|
|
7977
|
+
}, [control, props.shouldUnregister]);
|
|
7978
|
+
React30.useEffect(() => {
|
|
7979
|
+
if (control._proxyFormState.isDirty) {
|
|
7980
|
+
const isDirty = control._getDirty();
|
|
7981
|
+
if (isDirty !== formState.isDirty) {
|
|
7982
|
+
control._subjects.state.next({
|
|
7983
|
+
isDirty
|
|
7984
|
+
});
|
|
7985
|
+
}
|
|
7986
|
+
}
|
|
7987
|
+
}, [control, formState.isDirty]);
|
|
7988
|
+
React30.useEffect(() => {
|
|
7989
|
+
if (props.values && !deepEqual(props.values, _values.current)) {
|
|
7990
|
+
control._reset(props.values, {
|
|
7991
|
+
keepFieldsRef: true,
|
|
7992
|
+
...control._options.resetOptions
|
|
7993
|
+
});
|
|
7994
|
+
_values.current = props.values;
|
|
7995
|
+
updateFormState((state) => ({ ...state }));
|
|
7996
|
+
} else {
|
|
7997
|
+
control._resetDefaultValues();
|
|
7998
|
+
}
|
|
7999
|
+
}, [control, props.values]);
|
|
8000
|
+
React30.useEffect(() => {
|
|
8001
|
+
if (!control._state.mount) {
|
|
8002
|
+
control._setValid();
|
|
8003
|
+
control._state.mount = true;
|
|
8004
|
+
}
|
|
8005
|
+
if (control._state.watch) {
|
|
8006
|
+
control._state.watch = false;
|
|
8007
|
+
control._subjects.state.next({ ...control._formState });
|
|
8008
|
+
}
|
|
8009
|
+
control._removeUnmounted();
|
|
8010
|
+
});
|
|
8011
|
+
_formControl.current.formState = getProxyFormState(formState, control);
|
|
8012
|
+
return _formControl.current;
|
|
8013
|
+
}
|
|
8014
|
+
|
|
8015
|
+
// ../../components/ui/Form.tsx
|
|
8016
|
+
import { useTranslations as useTranslations8 } from "next-intl";
|
|
8017
|
+
import { jsx as jsx39, jsxs as jsxs33 } from "react/jsx-runtime";
|
|
8018
|
+
var FormConfigContext = React31.createContext({ size: "md" });
|
|
8019
|
+
var FormWrapper = ({
|
|
8020
|
+
children,
|
|
8021
|
+
onSubmit,
|
|
8022
|
+
initialValues,
|
|
8023
|
+
validationSchema,
|
|
8024
|
+
className,
|
|
8025
|
+
size = "md",
|
|
8026
|
+
...props
|
|
8027
|
+
}) => {
|
|
8028
|
+
const methods = useForm({
|
|
8029
|
+
defaultValues: initialValues
|
|
8030
|
+
});
|
|
8031
|
+
React31.useEffect(() => {
|
|
8032
|
+
if (initialValues) {
|
|
8033
|
+
methods.reset(initialValues);
|
|
8034
|
+
}
|
|
8035
|
+
}, [JSON.stringify(initialValues)]);
|
|
8036
|
+
const { validationSchema: _, ...formProps } = props;
|
|
8037
|
+
return /* @__PURE__ */ jsx39(FormProvider, { ...methods, children: /* @__PURE__ */ jsx39(FormConfigContext.Provider, { value: { size }, children: /* @__PURE__ */ jsx39("form", { onSubmit: methods.handleSubmit(onSubmit), className, ...formProps, children }) }) });
|
|
8038
|
+
};
|
|
8039
|
+
var Form = FormWrapper;
|
|
8040
|
+
var FormFieldContext = React31.createContext({});
|
|
8041
|
+
var FormField = ({
|
|
8042
|
+
...props
|
|
8043
|
+
}) => {
|
|
8044
|
+
return /* @__PURE__ */ jsx39(FormFieldContext.Provider, { value: { name: props.name }, children: /* @__PURE__ */ jsx39(Controller, { ...props }) });
|
|
8045
|
+
};
|
|
8046
|
+
var useFormField = () => {
|
|
8047
|
+
const fieldContext = React31.useContext(FormFieldContext);
|
|
8048
|
+
const itemContext = React31.useContext(FormItemContext);
|
|
8049
|
+
const { getFieldState, formState } = useFormContext();
|
|
8050
|
+
const t = useTranslations8("Form");
|
|
8051
|
+
const fieldState = getFieldState(fieldContext.name, formState);
|
|
8052
|
+
if (!fieldContext) {
|
|
8053
|
+
throw new Error(t("validation.mustBeUsedWithinForm"));
|
|
8054
|
+
}
|
|
8055
|
+
const { id } = itemContext;
|
|
8056
|
+
return {
|
|
8057
|
+
id,
|
|
8058
|
+
name: fieldContext.name,
|
|
8059
|
+
formItemId: `${id}-form-item`,
|
|
8060
|
+
formDescriptionId: `${id}-form-item-description`,
|
|
8061
|
+
formMessageId: `${id}-form-item-message`,
|
|
8062
|
+
...fieldState
|
|
8063
|
+
};
|
|
8064
|
+
};
|
|
8065
|
+
var FormItemContext = React31.createContext({});
|
|
8066
|
+
var FormItem = React31.forwardRef(({ className, ...props }, ref) => {
|
|
8067
|
+
const id = React31.useId();
|
|
8068
|
+
return /* @__PURE__ */ jsx39(FormItemContext.Provider, { value: { id }, children: /* @__PURE__ */ jsx39("div", { ref, className: cn("space-y-2", className), ...props }) });
|
|
8069
|
+
});
|
|
8070
|
+
FormItem.displayName = "FormItem";
|
|
8071
|
+
var FormLabel = React31.forwardRef(({ className, ...props }, ref) => {
|
|
8072
|
+
const { error, formItemId } = useFormField();
|
|
8073
|
+
const config = React31.useContext(FormConfigContext);
|
|
8074
|
+
const sizeClass = config.size === "sm" ? "text-xs" : config.size === "lg" ? "text-base" : "text-sm";
|
|
8075
|
+
return /* @__PURE__ */ jsx39(Label, { ref, className: cn(sizeClass, error && "text-destructive", className), htmlFor: formItemId, ...props });
|
|
8076
|
+
});
|
|
8077
|
+
FormLabel.displayName = "FormLabel";
|
|
8078
|
+
var FormControl = React31.forwardRef(({ ...props }, ref) => {
|
|
8079
|
+
const { error, formItemId, formDescriptionId, formMessageId } = useFormField();
|
|
8080
|
+
return /* @__PURE__ */ jsx39(
|
|
8081
|
+
"div",
|
|
8082
|
+
{
|
|
8083
|
+
ref,
|
|
8084
|
+
id: formItemId,
|
|
8085
|
+
"aria-describedby": !error ? `${formDescriptionId}` : `${formDescriptionId} ${formMessageId}`,
|
|
8086
|
+
"aria-invalid": !!error,
|
|
8087
|
+
...props
|
|
8088
|
+
}
|
|
8089
|
+
);
|
|
8090
|
+
});
|
|
8091
|
+
FormControl.displayName = "FormControl";
|
|
8092
|
+
var FormDescription = React31.forwardRef(({ className, ...props }, ref) => {
|
|
8093
|
+
const { formDescriptionId } = useFormField();
|
|
8094
|
+
return /* @__PURE__ */ jsx39("p", { ref, id: formDescriptionId, className: cn("text-sm text-muted-foreground", className), ...props });
|
|
8095
|
+
});
|
|
8096
|
+
FormDescription.displayName = "FormDescription";
|
|
8097
|
+
var FormMessage = React31.forwardRef(({ className, children, ...props }, ref) => {
|
|
8098
|
+
const { error, formMessageId } = useFormField();
|
|
8099
|
+
const body = error ? String(error?.message) : children;
|
|
8100
|
+
if (!body) {
|
|
8101
|
+
return null;
|
|
8102
|
+
}
|
|
8103
|
+
return /* @__PURE__ */ jsx39("p", { ref, id: formMessageId, className: cn("text-sm font-medium text-destructive", className), ...props, children: body });
|
|
8104
|
+
});
|
|
8105
|
+
FormMessage.displayName = "FormMessage";
|
|
8106
|
+
var FormInput = React31.forwardRef(({ name, ...props }, ref) => /* @__PURE__ */ jsx39(FormConfigContext.Consumer, { children: ({ size }) => /* @__PURE__ */ jsx39(
|
|
8107
|
+
FormField,
|
|
8108
|
+
{
|
|
8109
|
+
name,
|
|
8110
|
+
render: ({ field }) => /* @__PURE__ */ jsxs33(FormItem, { children: [
|
|
8111
|
+
/* @__PURE__ */ jsx39(FormControl, { children: /* @__PURE__ */ jsx39(Input_default, { size: props.size ?? size, ...field, ...props }) }),
|
|
8112
|
+
/* @__PURE__ */ jsx39(FormMessage, {})
|
|
8113
|
+
] })
|
|
8114
|
+
}
|
|
8115
|
+
) }));
|
|
8116
|
+
FormInput.displayName = "FormInput";
|
|
8117
|
+
var FormCheckbox = React31.forwardRef(({ name, ...props }, ref) => /* @__PURE__ */ jsx39(FormConfigContext.Consumer, { children: ({ size }) => /* @__PURE__ */ jsx39(
|
|
8118
|
+
FormField,
|
|
8119
|
+
{
|
|
8120
|
+
name,
|
|
8121
|
+
render: ({ field }) => /* @__PURE__ */ jsxs33(FormItem, { children: [
|
|
8122
|
+
/* @__PURE__ */ jsx39(FormControl, { children: /* @__PURE__ */ jsx39(
|
|
8123
|
+
Checkbox,
|
|
8124
|
+
{
|
|
8125
|
+
ref,
|
|
8126
|
+
checked: field.value,
|
|
8127
|
+
onChange: (e) => field.onChange(e.target.checked),
|
|
8128
|
+
labelClassName: cn(
|
|
8129
|
+
// align label text size with inputs/buttons by form size
|
|
8130
|
+
size === "sm" ? "text-xs" : size === "lg" ? "text-base" : "text-sm",
|
|
8131
|
+
props.labelClassName
|
|
8132
|
+
),
|
|
8133
|
+
...props
|
|
8134
|
+
}
|
|
8135
|
+
) }),
|
|
8136
|
+
/* @__PURE__ */ jsx39(FormMessage, {})
|
|
8137
|
+
] })
|
|
8138
|
+
}
|
|
8139
|
+
) }));
|
|
8140
|
+
FormCheckbox.displayName = "FormCheckbox";
|
|
8141
|
+
var FormActions = React31.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsx39("div", { ref, className: cn("flex gap-2 justify-end", className), ...props }));
|
|
8142
|
+
FormActions.displayName = "FormActions";
|
|
8143
|
+
var FormSubmitButton = React31.forwardRef(({ children, loading: loading2, ...props }, ref) => /* @__PURE__ */ jsx39(FormConfigContext.Consumer, { children: ({ size }) => /* @__PURE__ */ jsx39(Button_default, { ref, type: "submit", size: props.size ?? size, disabled: loading2, ...props, children }) }));
|
|
8144
|
+
FormSubmitButton.displayName = "FormSubmitButton";
|
|
8145
|
+
|
|
8146
|
+
// ../../components/ui/NotificationModal.tsx
|
|
8147
|
+
import { ExternalLink } from "lucide-react";
|
|
8148
|
+
import { useTranslations as useTranslations9 } from "next-intl";
|
|
8149
|
+
import { jsx as jsx40, jsxs as jsxs34 } from "react/jsx-runtime";
|
|
8150
|
+
function NotificationModal({ isOpen, onClose, notification, titleText, openLinkText, closeText }) {
|
|
8151
|
+
const t = useTranslations9("Common");
|
|
8152
|
+
if (!notification) return null;
|
|
8153
|
+
const formatTime2 = (dateString) => {
|
|
8154
|
+
const date = new Date(dateString);
|
|
8155
|
+
return date.toLocaleString(void 0, {
|
|
8156
|
+
year: "numeric",
|
|
8157
|
+
month: "2-digit",
|
|
8158
|
+
day: "2-digit",
|
|
8159
|
+
hour: "2-digit",
|
|
8160
|
+
minute: "2-digit"
|
|
8161
|
+
});
|
|
8162
|
+
};
|
|
8163
|
+
const hasLink = notification.metadata?.link;
|
|
8164
|
+
const handleLinkClick = () => {
|
|
8165
|
+
if (hasLink) {
|
|
8166
|
+
window.open(notification.metadata.link, "_blank");
|
|
8167
|
+
onClose();
|
|
8168
|
+
}
|
|
8169
|
+
};
|
|
8170
|
+
return /* @__PURE__ */ jsx40(
|
|
8171
|
+
Modal_default,
|
|
8172
|
+
{
|
|
8173
|
+
isOpen,
|
|
8174
|
+
onClose,
|
|
8175
|
+
title: titleText || t("notifications"),
|
|
8176
|
+
size: "md",
|
|
8177
|
+
children: /* @__PURE__ */ jsxs34("div", { className: "space-y-4", children: [
|
|
8178
|
+
/* @__PURE__ */ jsxs34("div", { className: "flex items-center gap-2 pb-2 border-b border-border", children: [
|
|
8179
|
+
/* @__PURE__ */ jsx40("div", { className: cn(
|
|
8180
|
+
"w-2 h-2 rounded-full",
|
|
8181
|
+
!notification.is_read ? "bg-primary" : "bg-border"
|
|
8182
|
+
) }),
|
|
8183
|
+
/* @__PURE__ */ jsx40("span", { className: "text-xs text-muted-foreground", children: !notification.is_read ? t("newNotification") : t("readStatus") })
|
|
8184
|
+
] }),
|
|
8185
|
+
notification.title && /* @__PURE__ */ jsx40("h3", { className: "text-lg font-semibold text-foreground", children: notification.title }),
|
|
8186
|
+
notification.body && /* @__PURE__ */ jsx40("div", { className: "text-sm text-muted-foreground whitespace-pre-wrap leading-relaxed", children: notification.body }),
|
|
8187
|
+
/* @__PURE__ */ jsx40("div", { className: "text-xs text-muted-foreground border-t border-border pt-2", children: formatTime2(notification.created_at) }),
|
|
8188
|
+
/* @__PURE__ */ jsxs34("div", { className: "flex gap-2 justify-end pt-2", children: [
|
|
8189
|
+
hasLink && /* @__PURE__ */ jsxs34(
|
|
8190
|
+
Button_default,
|
|
8191
|
+
{
|
|
8192
|
+
variant: "primary",
|
|
8193
|
+
size: "sm",
|
|
8194
|
+
onClick: handleLinkClick,
|
|
8195
|
+
className: "gap-2",
|
|
8196
|
+
children: [
|
|
8197
|
+
/* @__PURE__ */ jsx40(ExternalLink, { className: "w-4 h-4" }),
|
|
8198
|
+
openLinkText || t("openLink")
|
|
8199
|
+
]
|
|
8200
|
+
}
|
|
8201
|
+
),
|
|
8202
|
+
/* @__PURE__ */ jsx40(
|
|
8203
|
+
Button_default,
|
|
8204
|
+
{
|
|
8205
|
+
variant: "ghost",
|
|
8206
|
+
size: "sm",
|
|
8207
|
+
onClick: onClose,
|
|
8208
|
+
children: closeText || t("close")
|
|
8209
|
+
}
|
|
8210
|
+
)
|
|
8211
|
+
] })
|
|
8212
|
+
] })
|
|
8213
|
+
}
|
|
8214
|
+
);
|
|
8215
|
+
}
|
|
8216
|
+
var NotificationModal_default = NotificationModal;
|
|
8217
|
+
|
|
8218
|
+
// ../../components/ui/FloatingContacts.tsx
|
|
8219
|
+
import Link2 from "next/link";
|
|
8220
|
+
import { usePathname } from "next/navigation";
|
|
8221
|
+
import { Phone } from "lucide-react";
|
|
8222
|
+
|
|
8223
|
+
// ../../node_modules/react-icons/lib/iconBase.mjs
|
|
8224
|
+
import React33 from "react";
|
|
8225
|
+
|
|
8226
|
+
// ../../node_modules/react-icons/lib/iconContext.mjs
|
|
8227
|
+
import React32 from "react";
|
|
8228
|
+
var DefaultContext = {
|
|
8229
|
+
color: void 0,
|
|
8230
|
+
size: void 0,
|
|
8231
|
+
className: void 0,
|
|
8232
|
+
style: void 0,
|
|
8233
|
+
attr: void 0
|
|
8234
|
+
};
|
|
8235
|
+
var IconContext = React32.createContext && /* @__PURE__ */ React32.createContext(DefaultContext);
|
|
8236
|
+
|
|
8237
|
+
// ../../node_modules/react-icons/lib/iconBase.mjs
|
|
8238
|
+
var _excluded = ["attr", "size", "title"];
|
|
8239
|
+
function _objectWithoutProperties(source, excluded) {
|
|
8240
|
+
if (source == null) return {};
|
|
8241
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
8242
|
+
var key, i;
|
|
8243
|
+
if (Object.getOwnPropertySymbols) {
|
|
8244
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
8245
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
8246
|
+
key = sourceSymbolKeys[i];
|
|
8247
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
8248
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
8249
|
+
target[key] = source[key];
|
|
8250
|
+
}
|
|
8251
|
+
}
|
|
8252
|
+
return target;
|
|
8253
|
+
}
|
|
8254
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
8255
|
+
if (source == null) return {};
|
|
8256
|
+
var target = {};
|
|
6043
8257
|
for (var key in source) {
|
|
6044
8258
|
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
6045
8259
|
if (excluded.indexOf(key) >= 0) continue;
|
|
@@ -6107,12 +8321,12 @@ function _toPrimitive(t, r) {
|
|
|
6107
8321
|
return ("string" === r ? String : Number)(t);
|
|
6108
8322
|
}
|
|
6109
8323
|
function Tree2Element(tree) {
|
|
6110
|
-
return tree && tree.map((node, i) => /* @__PURE__ */
|
|
8324
|
+
return tree && tree.map((node, i) => /* @__PURE__ */ React33.createElement(node.tag, _objectSpread({
|
|
6111
8325
|
key: i
|
|
6112
8326
|
}, node.attr), Tree2Element(node.child)));
|
|
6113
8327
|
}
|
|
6114
8328
|
function GenIcon(data) {
|
|
6115
|
-
return (props) => /* @__PURE__ */
|
|
8329
|
+
return (props) => /* @__PURE__ */ React33.createElement(IconBase, _extends({
|
|
6116
8330
|
attr: _objectSpread({}, data.attr)
|
|
6117
8331
|
}, props), Tree2Element(data.child));
|
|
6118
8332
|
}
|
|
@@ -6127,7 +8341,7 @@ function IconBase(props) {
|
|
|
6127
8341
|
var className;
|
|
6128
8342
|
if (conf.className) className = conf.className;
|
|
6129
8343
|
if (props.className) className = (className ? className + " " : "") + props.className;
|
|
6130
|
-
return /* @__PURE__ */
|
|
8344
|
+
return /* @__PURE__ */ React33.createElement("svg", _extends({
|
|
6131
8345
|
stroke: "currentColor",
|
|
6132
8346
|
fill: "currentColor",
|
|
6133
8347
|
strokeWidth: "0"
|
|
@@ -6139,9 +8353,9 @@ function IconBase(props) {
|
|
|
6139
8353
|
height: computedSize,
|
|
6140
8354
|
width: computedSize,
|
|
6141
8355
|
xmlns: "http://www.w3.org/2000/svg"
|
|
6142
|
-
}), title && /* @__PURE__ */
|
|
8356
|
+
}), title && /* @__PURE__ */ React33.createElement("title", null, title), props.children);
|
|
6143
8357
|
};
|
|
6144
|
-
return IconContext !== void 0 ? /* @__PURE__ */
|
|
8358
|
+
return IconContext !== void 0 ? /* @__PURE__ */ React33.createElement(IconContext.Consumer, null, (conf) => elem(conf)) : elem(DefaultContext);
|
|
6145
8359
|
}
|
|
6146
8360
|
|
|
6147
8361
|
// ../../node_modules/react-icons/fa/index.mjs
|
|
@@ -6155,9 +8369,9 @@ function SiZalo(props) {
|
|
|
6155
8369
|
}
|
|
6156
8370
|
|
|
6157
8371
|
// ../../components/ui/FloatingContacts.tsx
|
|
6158
|
-
import { jsx as
|
|
8372
|
+
import { jsx as jsx41, jsxs as jsxs35 } from "react/jsx-runtime";
|
|
6159
8373
|
function MessengerIcon(props) {
|
|
6160
|
-
return /* @__PURE__ */
|
|
8374
|
+
return /* @__PURE__ */ jsx41("svg", { viewBox: "0 0 24 24", width: 24, height: 24, "aria-hidden": "true", ...props, children: /* @__PURE__ */ jsx41(
|
|
6161
8375
|
"path",
|
|
6162
8376
|
{
|
|
6163
8377
|
d: "M12 2C6.477 2 2 6.145 2 11.235c0 2.93 1.35 5.542 3.464 7.25v3.515l3.344-1.836c.894.247 1.843.375 2.192.375 5.523 0 10-4.145 10-9.235S17.523 2 12 2zm.994 12.444l-2.563-2.73-5.004 2.73 5.507-5.84 2.626 2.729 4.942-2.729-5.508 5.84z",
|
|
@@ -6166,10 +8380,10 @@ function MessengerIcon(props) {
|
|
|
6166
8380
|
) });
|
|
6167
8381
|
}
|
|
6168
8382
|
function ZaloIcon(props) {
|
|
6169
|
-
return /* @__PURE__ */
|
|
8383
|
+
return /* @__PURE__ */ jsx41(SiZalo, { size: 20, ...props });
|
|
6170
8384
|
}
|
|
6171
8385
|
function InstagramIcon(props) {
|
|
6172
|
-
return /* @__PURE__ */
|
|
8386
|
+
return /* @__PURE__ */ jsx41(FaInstagram, { size: 20, ...props });
|
|
6173
8387
|
}
|
|
6174
8388
|
function FloatingContacts({ className }) {
|
|
6175
8389
|
const pathname = usePathname();
|
|
@@ -6204,8 +8418,8 @@ function FloatingContacts({ className }) {
|
|
|
6204
8418
|
external: true
|
|
6205
8419
|
}
|
|
6206
8420
|
];
|
|
6207
|
-
return /* @__PURE__ */
|
|
6208
|
-
/* @__PURE__ */
|
|
8421
|
+
return /* @__PURE__ */ jsxs35("div", { className: cn("fixed bottom-6 right-4 z-[100000]", "flex flex-col items-end gap-3", className), "aria-label": "Quick contacts", children: [
|
|
8422
|
+
/* @__PURE__ */ jsx41(
|
|
6209
8423
|
Link2,
|
|
6210
8424
|
{
|
|
6211
8425
|
href: `tel:${hotline.replace(/\D/g, "")}`,
|
|
@@ -6216,10 +8430,10 @@ function FloatingContacts({ className }) {
|
|
|
6216
8430
|
"hover:scale-105 active:scale-95 transition-transform",
|
|
6217
8431
|
"bg-[#22c55e]"
|
|
6218
8432
|
),
|
|
6219
|
-
children: /* @__PURE__ */
|
|
8433
|
+
children: /* @__PURE__ */ jsx41(Phone, { className: "w-6 h-6" })
|
|
6220
8434
|
}
|
|
6221
8435
|
),
|
|
6222
|
-
moreItems.map(({ key, href, label, bg, Icon, external }) => /* @__PURE__ */
|
|
8436
|
+
moreItems.map(({ key, href, label, bg, Icon, external }) => /* @__PURE__ */ jsx41(
|
|
6223
8437
|
Link2,
|
|
6224
8438
|
{
|
|
6225
8439
|
href,
|
|
@@ -6231,7 +8445,7 @@ function FloatingContacts({ className }) {
|
|
|
6231
8445
|
"hover:scale-105 active:scale-95 transition-transform",
|
|
6232
8446
|
bg
|
|
6233
8447
|
),
|
|
6234
|
-
children: /* @__PURE__ */
|
|
8448
|
+
children: /* @__PURE__ */ jsx41(Icon, { className: "w-6 h-6" })
|
|
6235
8449
|
},
|
|
6236
8450
|
key
|
|
6237
8451
|
))
|
|
@@ -6240,7 +8454,7 @@ function FloatingContacts({ className }) {
|
|
|
6240
8454
|
|
|
6241
8455
|
// ../../components/ui/AccessDenied.tsx
|
|
6242
8456
|
import { Lock, ShieldAlert, Ban } from "lucide-react";
|
|
6243
|
-
import { jsx as
|
|
8457
|
+
import { jsx as jsx42, jsxs as jsxs36 } from "react/jsx-runtime";
|
|
6244
8458
|
var VARIANT_STYLES = {
|
|
6245
8459
|
destructive: { bg: "bg-destructive/5", border: "border-destructive/20", text: "text-destructive" },
|
|
6246
8460
|
warning: { bg: "bg-warning/5", border: "border-warning/20", text: "text-warning" },
|
|
@@ -6261,13 +8475,13 @@ function AccessDenied({
|
|
|
6261
8475
|
}) {
|
|
6262
8476
|
const styles = VARIANT_STYLES[variant];
|
|
6263
8477
|
const UsedIcon = Icon || DEFAULT_ICONS[variant];
|
|
6264
|
-
return /* @__PURE__ */
|
|
6265
|
-
/* @__PURE__ */
|
|
6266
|
-
/* @__PURE__ */
|
|
6267
|
-
/* @__PURE__ */
|
|
6268
|
-
/* @__PURE__ */
|
|
8478
|
+
return /* @__PURE__ */ jsx42(Card_default, { className: cn("p-8 text-center shadow-sm", styles.bg, styles.border, className), children: /* @__PURE__ */ jsxs36("div", { className: "flex flex-col items-center gap-4", children: [
|
|
8479
|
+
/* @__PURE__ */ jsx42("div", { className: cn("p-3 rounded-lg", styles.bg.replace("/5", "/10")), children: /* @__PURE__ */ jsx42(UsedIcon, { className: cn("w-8 h-8", styles.text) }) }),
|
|
8480
|
+
/* @__PURE__ */ jsxs36("div", { children: [
|
|
8481
|
+
/* @__PURE__ */ jsx42("h3", { className: cn("font-semibold mb-2", styles.text), children: title }),
|
|
8482
|
+
/* @__PURE__ */ jsx42("p", { className: cn(styles.text.replace("text-", "text-") + "/80", "text-sm"), children: description })
|
|
6269
8483
|
] }),
|
|
6270
|
-
children && /* @__PURE__ */
|
|
8484
|
+
children && /* @__PURE__ */ jsx42("div", { className: "mt-2 flex flex-wrap gap-2 justify-center", children })
|
|
6271
8485
|
] }) });
|
|
6272
8486
|
}
|
|
6273
8487
|
|
|
@@ -6418,12 +8632,25 @@ export {
|
|
|
6418
8632
|
Checkbox,
|
|
6419
8633
|
ClientOnly,
|
|
6420
8634
|
Combobox,
|
|
8635
|
+
CompactPagination,
|
|
6421
8636
|
DataTable_default as DataTable,
|
|
6422
8637
|
DatePicker,
|
|
8638
|
+
DateRangePicker,
|
|
6423
8639
|
date_exports as DateUtils,
|
|
6424
8640
|
Drawer,
|
|
6425
8641
|
DropdownMenu_default as DropdownMenu,
|
|
6426
8642
|
FloatingContacts,
|
|
8643
|
+
Form,
|
|
8644
|
+
FormActions,
|
|
8645
|
+
FormCheckbox,
|
|
8646
|
+
FormControl,
|
|
8647
|
+
FormDescription,
|
|
8648
|
+
FormField,
|
|
8649
|
+
FormInput,
|
|
8650
|
+
FormItem,
|
|
8651
|
+
FormLabel,
|
|
8652
|
+
FormMessage,
|
|
8653
|
+
FormSubmitButton,
|
|
6427
8654
|
GlobalLoading,
|
|
6428
8655
|
GradientBadge,
|
|
6429
8656
|
ImageUpload,
|
|
@@ -6438,8 +8665,10 @@ export {
|
|
|
6438
8665
|
MultiCombobox,
|
|
6439
8666
|
NotificationBadge,
|
|
6440
8667
|
NotificationModal_default as NotificationModal,
|
|
8668
|
+
NumberInput,
|
|
6441
8669
|
PageLoading,
|
|
6442
8670
|
Pagination,
|
|
8671
|
+
PasswordInput,
|
|
6443
8672
|
PillTabs,
|
|
6444
8673
|
Popover,
|
|
6445
8674
|
Progress_default as Progress,
|
|
@@ -6450,6 +8679,7 @@ export {
|
|
|
6450
8679
|
Section_default as Section,
|
|
6451
8680
|
Sheet,
|
|
6452
8681
|
SidebarSheet,
|
|
8682
|
+
SimplePagination,
|
|
6453
8683
|
SimpleTabs,
|
|
6454
8684
|
Skeleton_default as Skeleton,
|
|
6455
8685
|
SlideOver,
|
|
@@ -6476,6 +8706,7 @@ export {
|
|
|
6476
8706
|
cn,
|
|
6477
8707
|
getUnderverseMessages,
|
|
6478
8708
|
underverseMessages,
|
|
8709
|
+
useFormField,
|
|
6479
8710
|
useToast
|
|
6480
8711
|
};
|
|
6481
8712
|
//# sourceMappingURL=index.js.map
|