admin-lib-cms 1.2.6 → 1.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +29 -22
- package/dist/index.d.ts +29 -22
- package/dist/index.js +1569 -466
- package/dist/index.mjs +1568 -475
- package/dist/types.d.mts +22 -2
- package/dist/types.d.ts +22 -2
- package/package.json +3 -1
- package/dist/chunk-6DZX6EAA.mjs +0 -37
- package/dist/chunk-CQW7KMB2.mjs +0 -120
- package/dist/chunk-Y6FXYEAI.mjs +0 -10
- package/dist/chunk-ZG5XBIW7.mjs +0 -152
- package/dist/email.d.mts +0 -3
- package/dist/email.d.ts +0 -3
- package/dist/email.js +0 -144
- package/dist/email.mjs +0 -6
- package/dist/types-uBvGNd4_.d.mts +0 -78
- package/dist/types-uBvGNd4_.d.ts +0 -78
package/dist/index.mjs
CHANGED
|
@@ -444,8 +444,8 @@ function useSubmit(formId) {
|
|
|
444
444
|
}
|
|
445
445
|
|
|
446
446
|
// src/editable.tsx
|
|
447
|
-
import { createElement, useEffect as useEffect3, useState as useState4, Fragment as Fragment2 } from "react";
|
|
448
|
-
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
447
|
+
import { createElement, isValidElement, useEffect as useEffect3, useState as useState4, Fragment as Fragment2 } from "react";
|
|
448
|
+
import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
449
449
|
function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable) {
|
|
450
450
|
const ctx = useCmsOptional();
|
|
451
451
|
useEffect3(() => {
|
|
@@ -610,7 +610,17 @@ function EditableLink({
|
|
|
610
610
|
className,
|
|
611
611
|
target
|
|
612
612
|
}) {
|
|
613
|
-
|
|
613
|
+
let defaultText = text ?? "";
|
|
614
|
+
if (!defaultText) {
|
|
615
|
+
if (typeof children === "string") {
|
|
616
|
+
defaultText = children;
|
|
617
|
+
} else if (Array.isArray(children)) {
|
|
618
|
+
const strChild = children.find((c) => typeof c === "string");
|
|
619
|
+
if (typeof strChild === "string") {
|
|
620
|
+
defaultText = strChild.trim();
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
}
|
|
614
624
|
const ctx = useRegister(id, "link", label, section, pageId, { href, text: defaultText });
|
|
615
625
|
const override = ctx?.overrides[id];
|
|
616
626
|
const hrefValue = override?.href ?? href;
|
|
@@ -626,8 +636,34 @@ function EditableLink({
|
|
|
626
636
|
const isExternal = hrefValue.startsWith("http");
|
|
627
637
|
const computedTarget = target || (isExternal ? "_blank" : void 0);
|
|
628
638
|
const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
|
|
629
|
-
|
|
630
|
-
|
|
639
|
+
let content;
|
|
640
|
+
if (typeof children === "function") {
|
|
641
|
+
content = children(textValue);
|
|
642
|
+
} else if (override && typeof override.text === "string" && override.text !== "") {
|
|
643
|
+
if (Array.isArray(children)) {
|
|
644
|
+
let replaced = false;
|
|
645
|
+
content = children.map((c) => {
|
|
646
|
+
if (typeof c === "string" && !replaced) {
|
|
647
|
+
replaced = true;
|
|
648
|
+
return override.text;
|
|
649
|
+
}
|
|
650
|
+
return c;
|
|
651
|
+
});
|
|
652
|
+
} else if (isValidElement(children)) {
|
|
653
|
+
content = /* @__PURE__ */ jsxs3(Fragment3, { children: [
|
|
654
|
+
override.text,
|
|
655
|
+
" ",
|
|
656
|
+
children
|
|
657
|
+
] });
|
|
658
|
+
} else {
|
|
659
|
+
content = override.text;
|
|
660
|
+
}
|
|
661
|
+
} else if (typeof children !== "undefined") {
|
|
662
|
+
content = children;
|
|
663
|
+
} else {
|
|
664
|
+
content = textValue;
|
|
665
|
+
}
|
|
666
|
+
const isEmpty = !content || typeof content === "string" && content.trim() === "";
|
|
631
667
|
const renderContent = active && isEmpty ? `[Empty Link: ${label || id}]` : content;
|
|
632
668
|
return /* @__PURE__ */ jsx4(
|
|
633
669
|
"a",
|
|
@@ -751,7 +787,9 @@ function EditableReference({
|
|
|
751
787
|
}
|
|
752
788
|
|
|
753
789
|
// src/admin/AdminApp.tsx
|
|
754
|
-
import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef2, useState as useState5 } from "react";
|
|
790
|
+
import { createElement as createElement2, useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef2, useState as useState5 } from "react";
|
|
791
|
+
import { ConfigProvider, Modal, TimePicker } from "antd";
|
|
792
|
+
import dayjs from "dayjs";
|
|
755
793
|
import {
|
|
756
794
|
FileText,
|
|
757
795
|
Boxes,
|
|
@@ -782,8 +820,69 @@ import {
|
|
|
782
820
|
Check,
|
|
783
821
|
GripVertical
|
|
784
822
|
} from "lucide-react";
|
|
785
|
-
import { CreditCard as CreditCard2 } from "lucide-react";
|
|
786
|
-
import { Fragment as
|
|
823
|
+
import { CreditCard as CreditCard2, BarChart3 } from "lucide-react";
|
|
824
|
+
import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
825
|
+
var TIME_STORAGE_FORMAT = "HH:mm";
|
|
826
|
+
var TIME_DISPLAY_FORMAT = "h:mm A";
|
|
827
|
+
var TIME_PICKER_THEME = {
|
|
828
|
+
token: {
|
|
829
|
+
borderRadius: 12,
|
|
830
|
+
colorBgContainer: "#ffffff",
|
|
831
|
+
colorBorder: "#e2e8f0",
|
|
832
|
+
colorPrimary: "#6366f1",
|
|
833
|
+
colorText: "#1e293b",
|
|
834
|
+
colorTextPlaceholder: "#94a3b8",
|
|
835
|
+
controlHeight: 42,
|
|
836
|
+
controlOutline: "rgba(99, 102, 241, 0.1)",
|
|
837
|
+
fontFamily: "inherit",
|
|
838
|
+
fontSize: 14,
|
|
839
|
+
lineWidth: 1
|
|
840
|
+
},
|
|
841
|
+
components: {
|
|
842
|
+
DatePicker: {
|
|
843
|
+
activeBorderColor: "#6366f1",
|
|
844
|
+
activeShadow: "0 0 0 4px rgba(99, 102, 241, 0.1)",
|
|
845
|
+
hoverBg: "#ffffff",
|
|
846
|
+
hoverBorderColor: "#cbd5e1",
|
|
847
|
+
paddingBlock: 9,
|
|
848
|
+
paddingInline: 14
|
|
849
|
+
}
|
|
850
|
+
}
|
|
851
|
+
};
|
|
852
|
+
function AdminTimeRangePicker(props) {
|
|
853
|
+
return /* @__PURE__ */ jsx5(ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ jsx5(
|
|
854
|
+
TimePicker.RangePicker,
|
|
855
|
+
{
|
|
856
|
+
...props,
|
|
857
|
+
className: `w-full min-w-0 ${props.className ?? ""}`,
|
|
858
|
+
style: {
|
|
859
|
+
boxShadow: "0 1px 2px rgba(15, 23, 42, 0.08)",
|
|
860
|
+
...props.style
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
) });
|
|
864
|
+
}
|
|
865
|
+
function AdminTimePicker(props) {
|
|
866
|
+
return /* @__PURE__ */ jsx5(ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ jsx5(
|
|
867
|
+
TimePicker,
|
|
868
|
+
{
|
|
869
|
+
...props,
|
|
870
|
+
className: `w-full min-w-0 ${props.className ?? ""}`,
|
|
871
|
+
style: {
|
|
872
|
+
boxShadow: "0 1px 2px rgba(15, 23, 42, 0.08)",
|
|
873
|
+
...props.style
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
) });
|
|
877
|
+
}
|
|
878
|
+
function toDayjsTime(value) {
|
|
879
|
+
const match = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(String(value ?? ""));
|
|
880
|
+
if (!match) return null;
|
|
881
|
+
return dayjs().hour(Number(match[1])).minute(Number(match[2])).second(0).millisecond(0);
|
|
882
|
+
}
|
|
883
|
+
function toStoredTime(value) {
|
|
884
|
+
return value?.format(TIME_STORAGE_FORMAT) ?? "";
|
|
885
|
+
}
|
|
787
886
|
async function handleImageFile(file, onUrl, uploadImage) {
|
|
788
887
|
if (uploadImage) {
|
|
789
888
|
try {
|
|
@@ -798,17 +897,67 @@ async function handleImageFile(file, onUrl, uploadImage) {
|
|
|
798
897
|
reader.onload = (ev) => onUrl(ev.target?.result);
|
|
799
898
|
reader.readAsDataURL(file);
|
|
800
899
|
}
|
|
801
|
-
function
|
|
802
|
-
|
|
803
|
-
|
|
900
|
+
function FilePickerButton({
|
|
901
|
+
accept,
|
|
902
|
+
children,
|
|
903
|
+
className,
|
|
904
|
+
multiple = false,
|
|
905
|
+
onFiles
|
|
906
|
+
}) {
|
|
907
|
+
const inputRef = useRef2(null);
|
|
908
|
+
return /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
909
|
+
/* @__PURE__ */ jsx5(
|
|
910
|
+
"button",
|
|
911
|
+
{
|
|
912
|
+
type: "button",
|
|
913
|
+
onClick: () => inputRef.current?.click(),
|
|
914
|
+
className,
|
|
915
|
+
children
|
|
916
|
+
}
|
|
917
|
+
),
|
|
918
|
+
/* @__PURE__ */ jsx5(
|
|
919
|
+
"input",
|
|
920
|
+
{
|
|
921
|
+
ref: inputRef,
|
|
922
|
+
type: "file",
|
|
923
|
+
accept,
|
|
924
|
+
multiple,
|
|
925
|
+
className: "hidden",
|
|
926
|
+
onChange: (event) => {
|
|
927
|
+
onFiles(Array.from(event.currentTarget.files ?? []));
|
|
928
|
+
event.currentTarget.value = "";
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
)
|
|
932
|
+
] });
|
|
933
|
+
}
|
|
934
|
+
function AdminApp(props) {
|
|
935
|
+
if (props.projectId) {
|
|
936
|
+
return /* @__PURE__ */ jsx5(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: /* @__PURE__ */ jsx5(AdminAppContent, { ...props }) });
|
|
804
937
|
}
|
|
805
|
-
return /* @__PURE__ */ jsx5(AdminAppContent, {});
|
|
938
|
+
return /* @__PURE__ */ jsx5(AdminAppContent, { ...props });
|
|
806
939
|
}
|
|
807
|
-
function AdminAppContent() {
|
|
808
|
-
const
|
|
940
|
+
function AdminAppContent(props) {
|
|
941
|
+
const ctx = useCmsContext();
|
|
942
|
+
const hasDashboard = Boolean(props.dashboard);
|
|
943
|
+
const [section, setSection] = useState5(hasDashboard ? "dashboard" : "pages");
|
|
809
944
|
const [authChecking, setAuthChecking] = useState5(true);
|
|
810
945
|
const [authenticated, setAuthenticated] = useState5(false);
|
|
811
|
-
const
|
|
946
|
+
const hideSettings = props.hideSettings ?? ctx.config.hideSettings ?? false;
|
|
947
|
+
const hideData = props.hideData ?? ctx.config.hideData ?? false;
|
|
948
|
+
const hideGlobals = props.hideGlobals ?? ctx.config.hideGlobals ?? false;
|
|
949
|
+
const hideConfig = props.hideConfig ?? ctx.config.hideConfig ?? false;
|
|
950
|
+
const menuLabels = {
|
|
951
|
+
dashboard: "Dashboard",
|
|
952
|
+
pages: "P\xE1ginas",
|
|
953
|
+
collections: "Colecciones",
|
|
954
|
+
data: "Datos",
|
|
955
|
+
config: "Configuraci\xF3n",
|
|
956
|
+
settings: "Ajustes",
|
|
957
|
+
subscription: "Suscripci\xF3n",
|
|
958
|
+
...ctx.config.menuLabels,
|
|
959
|
+
...props.menuLabels
|
|
960
|
+
};
|
|
812
961
|
useEffect4(() => {
|
|
813
962
|
fetch("/api/admin/auth").then((res) => res.json()).then((data) => {
|
|
814
963
|
if (data && data.authenticated) {
|
|
@@ -858,13 +1007,22 @@ function AdminAppContent() {
|
|
|
858
1007
|
/* @__PURE__ */ jsx5("div", { className: "truncate font-bold text-lg text-slate-900", children: ctx.config.siteName ?? "Site Administration" })
|
|
859
1008
|
] }),
|
|
860
1009
|
/* @__PURE__ */ jsxs4("nav", { className: "flex flex-row lg:flex-col overflow-x-auto lg:overflow-visible space-x-2 lg:space-x-0 lg:space-y-1.5 p-3 lg:p-4 text-sm font-medium hide-scrollbar", children: [
|
|
1010
|
+
hasDashboard && /* @__PURE__ */ jsx5(
|
|
1011
|
+
SideItem,
|
|
1012
|
+
{
|
|
1013
|
+
active: section === "dashboard",
|
|
1014
|
+
onClick: () => setSection("dashboard"),
|
|
1015
|
+
icon: /* @__PURE__ */ jsx5(BarChart3, { className: "h-4 w-4 shrink-0" }),
|
|
1016
|
+
children: menuLabels.dashboard
|
|
1017
|
+
}
|
|
1018
|
+
),
|
|
861
1019
|
/* @__PURE__ */ jsx5(
|
|
862
1020
|
SideItem,
|
|
863
1021
|
{
|
|
864
1022
|
active: section === "pages",
|
|
865
1023
|
onClick: () => setSection("pages"),
|
|
866
1024
|
icon: /* @__PURE__ */ jsx5(FileText, { className: "h-4 w-4 shrink-0" }),
|
|
867
|
-
children:
|
|
1025
|
+
children: menuLabels.pages
|
|
868
1026
|
}
|
|
869
1027
|
),
|
|
870
1028
|
/* @__PURE__ */ jsx5(
|
|
@@ -873,34 +1031,34 @@ function AdminAppContent() {
|
|
|
873
1031
|
active: section === "collections",
|
|
874
1032
|
onClick: () => setSection("collections"),
|
|
875
1033
|
icon: /* @__PURE__ */ jsx5(Boxes, { className: "h-4 w-4 shrink-0" }),
|
|
876
|
-
children:
|
|
1034
|
+
children: menuLabels.collections
|
|
877
1035
|
}
|
|
878
1036
|
),
|
|
879
|
-
/* @__PURE__ */ jsx5(
|
|
1037
|
+
!hideData && /* @__PURE__ */ jsx5(
|
|
880
1038
|
SideItem,
|
|
881
1039
|
{
|
|
882
1040
|
active: section === "submissions",
|
|
883
1041
|
onClick: () => setSection("submissions"),
|
|
884
1042
|
icon: /* @__PURE__ */ jsx5(Inbox, { className: "h-4 w-4 shrink-0" }),
|
|
885
|
-
children:
|
|
1043
|
+
children: menuLabels.data
|
|
886
1044
|
}
|
|
887
1045
|
),
|
|
888
|
-
/* @__PURE__ */ jsx5(
|
|
1046
|
+
!hideConfig && !hideGlobals && /* @__PURE__ */ jsx5(
|
|
889
1047
|
SideItem,
|
|
890
1048
|
{
|
|
891
1049
|
active: section === "config",
|
|
892
1050
|
onClick: () => setSection("config"),
|
|
893
1051
|
icon: /* @__PURE__ */ jsx5(SlidersHorizontal, { className: "h-4 w-4 shrink-0" }),
|
|
894
|
-
children:
|
|
1052
|
+
children: menuLabels.config
|
|
895
1053
|
}
|
|
896
1054
|
),
|
|
897
|
-
/* @__PURE__ */ jsx5(
|
|
1055
|
+
!hideSettings && /* @__PURE__ */ jsx5(
|
|
898
1056
|
SideItem,
|
|
899
1057
|
{
|
|
900
1058
|
active: section === "settings",
|
|
901
1059
|
onClick: () => setSection("settings"),
|
|
902
1060
|
icon: /* @__PURE__ */ jsx5(SettingsIcon, { className: "h-4 w-4 shrink-0" }),
|
|
903
|
-
children:
|
|
1061
|
+
children: menuLabels.settings
|
|
904
1062
|
}
|
|
905
1063
|
),
|
|
906
1064
|
subscriptionCtx && /* @__PURE__ */ jsx5(
|
|
@@ -909,37 +1067,32 @@ function AdminAppContent() {
|
|
|
909
1067
|
active: section === "subscription",
|
|
910
1068
|
onClick: () => setSection("subscription"),
|
|
911
1069
|
icon: /* @__PURE__ */ jsx5(CreditCard2, { className: "h-4 w-4 shrink-0" }),
|
|
912
|
-
children:
|
|
1070
|
+
children: menuLabels.subscription
|
|
913
1071
|
}
|
|
914
1072
|
)
|
|
915
1073
|
] }),
|
|
916
|
-
/* @__PURE__ */
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
/* @__PURE__ */ jsx5(LogOut, { className: "w-4 h-4" }),
|
|
931
|
-
"Logout"
|
|
932
|
-
]
|
|
933
|
-
}
|
|
934
|
-
)
|
|
935
|
-
] })
|
|
1074
|
+
/* @__PURE__ */ jsx5("div", { className: "hidden lg:block mt-auto border-t border-slate-200 p-4 bg-slate-50/50", children: /* @__PURE__ */ jsxs4(
|
|
1075
|
+
"button",
|
|
1076
|
+
{
|
|
1077
|
+
onClick: async () => {
|
|
1078
|
+
await fetch("/api/admin/auth?action=logout", { method: "POST" });
|
|
1079
|
+
window.location.href = "/admin/login";
|
|
1080
|
+
},
|
|
1081
|
+
className: "flex items-center justify-center gap-2 w-full px-3 py-2 text-sm font-medium text-red-600 bg-red-50 hover:bg-red-100 rounded-lg transition-colors",
|
|
1082
|
+
children: [
|
|
1083
|
+
/* @__PURE__ */ jsx5(LogOut, { className: "w-4 h-4" }),
|
|
1084
|
+
"Logout"
|
|
1085
|
+
]
|
|
1086
|
+
}
|
|
1087
|
+
) })
|
|
936
1088
|
] }),
|
|
937
1089
|
/* @__PURE__ */ jsxs4("main", { className: "flex-1 overflow-hidden relative flex flex-col", children: [
|
|
1090
|
+
section === "dashboard" && hasDashboard && (typeof props.dashboard === "function" ? createElement2(props.dashboard) : props.dashboard),
|
|
938
1091
|
section === "pages" && /* @__PURE__ */ jsx5(PagesSection, {}),
|
|
939
1092
|
section === "collections" && /* @__PURE__ */ jsx5(CollectionsSection, {}),
|
|
940
|
-
section === "submissions" && /* @__PURE__ */ jsx5(SubmissionsSection, {}),
|
|
941
|
-
section === "config" && /* @__PURE__ */ jsx5(ConfigSection, {}),
|
|
942
|
-
section === "settings" && /* @__PURE__ */ jsx5(SettingsSection, {}),
|
|
1093
|
+
!hideData && section === "submissions" && /* @__PURE__ */ jsx5(SubmissionsSection, {}),
|
|
1094
|
+
!hideConfig && !hideGlobals && section === "config" && /* @__PURE__ */ jsx5(ConfigSection, {}),
|
|
1095
|
+
!hideSettings && section === "settings" && /* @__PURE__ */ jsx5(SettingsSection, {}),
|
|
943
1096
|
section === "subscription" && /* @__PURE__ */ jsx5(SubscriptionPage, {})
|
|
944
1097
|
] })
|
|
945
1098
|
] })
|
|
@@ -1170,7 +1323,8 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
1170
1323
|
ref: iframeRef,
|
|
1171
1324
|
src,
|
|
1172
1325
|
title: page.name,
|
|
1173
|
-
className: "h-full w-full bg-white"
|
|
1326
|
+
className: "h-full w-full bg-white",
|
|
1327
|
+
allow: "autoplay; encrypted-media; fullscreen"
|
|
1174
1328
|
},
|
|
1175
1329
|
src
|
|
1176
1330
|
) }) }),
|
|
@@ -1223,7 +1377,7 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
1223
1377
|
},
|
|
1224
1378
|
onClose: () => setSelectedId(null)
|
|
1225
1379
|
}
|
|
1226
|
-
) : /* @__PURE__ */ jsxs4(
|
|
1380
|
+
) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
1227
1381
|
page.hideable && /* @__PURE__ */ jsxs4("div", { className: "px-5 py-4 border-b border-slate-100 bg-slate-50/50", children: [
|
|
1228
1382
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center space-x-3", children: [
|
|
1229
1383
|
/* @__PURE__ */ jsx5(
|
|
@@ -1497,66 +1651,121 @@ function FieldEditor({
|
|
|
1497
1651
|
/* @__PURE__ */ jsx5("div", { className: "absolute inset-0 bg-black/40 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity", children: /* @__PURE__ */ jsx5("span", { className: "text-white text-xs font-medium px-2 py-1 bg-black/50 rounded backdrop-blur", children: "Preview" }) })
|
|
1498
1652
|
] }) : null
|
|
1499
1653
|
] }),
|
|
1500
|
-
meta.type === "file" &&
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
onChange: (e) => onChange(e.target.value),
|
|
1508
|
-
placeholder: "https://... or upload PDF/file",
|
|
1509
|
-
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
1510
|
-
}
|
|
1511
|
-
),
|
|
1512
|
-
/* @__PURE__ */ jsxs4("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-indigo-50 px-4 py-2.5 text-sm font-semibold text-indigo-700 hover:bg-indigo-100 transition-colors border border-indigo-100 flex items-center justify-center", children: [
|
|
1513
|
-
"Upload File",
|
|
1654
|
+
meta.type === "file" && (() => {
|
|
1655
|
+
const currentVal = value ?? meta.defaultValue;
|
|
1656
|
+
const strVal = String(currentVal ?? "");
|
|
1657
|
+
const isVideo = strVal.match(/\.(mp4|webm|ogg|mov)(\?.*)?$/i) || strVal.includes("video");
|
|
1658
|
+
const isImg = strVal.match(/\.(jpe?g|png|webp|avif|gif|svg)(\?.*)?$/i) || strVal.includes("image");
|
|
1659
|
+
return /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
1660
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
1514
1661
|
/* @__PURE__ */ jsx5(
|
|
1515
1662
|
"input",
|
|
1516
1663
|
{
|
|
1517
|
-
type: "
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1664
|
+
type: "url",
|
|
1665
|
+
value: strVal,
|
|
1666
|
+
onChange: (e) => onChange(e.target.value),
|
|
1667
|
+
placeholder: "https://... o subir video/imagen",
|
|
1668
|
+
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all font-mono text-xs"
|
|
1669
|
+
}
|
|
1670
|
+
),
|
|
1671
|
+
/* @__PURE__ */ jsxs4("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-indigo-50 px-4 py-2.5 text-sm font-semibold text-indigo-700 hover:bg-indigo-100 transition-colors border border-indigo-100 flex items-center justify-center", children: [
|
|
1672
|
+
"Subir",
|
|
1673
|
+
/* @__PURE__ */ jsx5(
|
|
1674
|
+
"input",
|
|
1675
|
+
{
|
|
1676
|
+
type: "file",
|
|
1677
|
+
accept: "video/*,image/*,application/pdf,.pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
1678
|
+
className: "hidden",
|
|
1679
|
+
onChange: (e) => {
|
|
1680
|
+
const file = e.target.files?.[0];
|
|
1681
|
+
if (file) {
|
|
1682
|
+
void handleImageFile(file, onChange, ctx.uploadImage);
|
|
1683
|
+
}
|
|
1524
1684
|
}
|
|
1525
1685
|
}
|
|
1686
|
+
)
|
|
1687
|
+
] })
|
|
1688
|
+
] }),
|
|
1689
|
+
currentVal ? /* @__PURE__ */ jsx5("div", { className: "space-y-2", children: isVideo ? /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-2 bg-slate-900 overflow-hidden shadow-sm", children: [
|
|
1690
|
+
/* @__PURE__ */ jsx5(
|
|
1691
|
+
"video",
|
|
1692
|
+
{
|
|
1693
|
+
src: strVal,
|
|
1694
|
+
controls: true,
|
|
1695
|
+
autoPlay: true,
|
|
1696
|
+
muted: true,
|
|
1697
|
+
loop: true,
|
|
1698
|
+
playsInline: true,
|
|
1699
|
+
className: "max-h-52 w-full object-contain rounded-lg bg-black"
|
|
1700
|
+
},
|
|
1701
|
+
strVal
|
|
1702
|
+
),
|
|
1703
|
+
/* @__PURE__ */ jsxs4("div", { className: "text-[10px] text-slate-300 font-mono truncate px-1 pt-1.5 flex items-center gap-1.5", children: [
|
|
1704
|
+
/* @__PURE__ */ jsx5("span", { className: "inline-block w-2 h-2 rounded-full bg-emerald-400 animate-pulse" }),
|
|
1705
|
+
/* @__PURE__ */ jsxs4("span", { className: "truncate", children: [
|
|
1706
|
+
"\u{1F3AC} ",
|
|
1707
|
+
strVal
|
|
1708
|
+
] })
|
|
1709
|
+
] })
|
|
1710
|
+
] }) : isImg ? /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-2 bg-slate-50 overflow-hidden shadow-sm", children: [
|
|
1711
|
+
/* @__PURE__ */ jsx5(
|
|
1712
|
+
"img",
|
|
1713
|
+
{
|
|
1714
|
+
src: strVal,
|
|
1715
|
+
alt: "Preview",
|
|
1716
|
+
className: "max-h-52 w-full object-contain rounded-lg"
|
|
1717
|
+
}
|
|
1718
|
+
),
|
|
1719
|
+
/* @__PURE__ */ jsxs4("div", { className: "text-[10px] text-slate-500 font-mono truncate px-1 pt-1.5", children: [
|
|
1720
|
+
"\u{1F5BC}\uFE0F ",
|
|
1721
|
+
strVal
|
|
1722
|
+
] })
|
|
1723
|
+
] }) : /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-3 bg-slate-50 text-xs font-mono text-slate-600 truncate flex items-center gap-2", children: [
|
|
1724
|
+
/* @__PURE__ */ jsx5("span", { children: "\u{1F4C4} Archivo:" }),
|
|
1725
|
+
/* @__PURE__ */ jsx5("span", { className: "truncate text-indigo-600 font-semibold", children: strVal })
|
|
1726
|
+
] }) }) : null
|
|
1727
|
+
] });
|
|
1728
|
+
})(),
|
|
1729
|
+
meta.type === "link" && (() => {
|
|
1730
|
+
const defaultObj = meta.defaultValue || {};
|
|
1731
|
+
const currentObj = value || {};
|
|
1732
|
+
const currentText = currentObj.text !== void 0 ? currentObj.text : defaultObj.text ?? "";
|
|
1733
|
+
const currentHref = currentObj.href !== void 0 ? currentObj.href : defaultObj.href ?? "";
|
|
1734
|
+
return /* @__PURE__ */ jsxs4("div", { className: "space-y-4 bg-slate-50 p-4 rounded-xl border border-slate-100", children: [
|
|
1735
|
+
/* @__PURE__ */ jsxs4("label", { className: "block", children: [
|
|
1736
|
+
/* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "Texto del Enlace" }),
|
|
1737
|
+
/* @__PURE__ */ jsx5(
|
|
1738
|
+
"input",
|
|
1739
|
+
{
|
|
1740
|
+
value: currentText,
|
|
1741
|
+
onChange: (e) => onChange({
|
|
1742
|
+
...defaultObj,
|
|
1743
|
+
...currentObj,
|
|
1744
|
+
text: e.target.value
|
|
1745
|
+
}),
|
|
1746
|
+
placeholder: "Texto del enlace",
|
|
1747
|
+
className: "mt-1.5 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
|
|
1748
|
+
}
|
|
1749
|
+
)
|
|
1750
|
+
] }),
|
|
1751
|
+
/* @__PURE__ */ jsxs4("label", { className: "block", children: [
|
|
1752
|
+
/* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "URL de Destino" }),
|
|
1753
|
+
/* @__PURE__ */ jsx5(
|
|
1754
|
+
"input",
|
|
1755
|
+
{
|
|
1756
|
+
value: currentHref,
|
|
1757
|
+
onChange: (e) => onChange({
|
|
1758
|
+
...defaultObj,
|
|
1759
|
+
...currentObj,
|
|
1760
|
+
href: e.target.value
|
|
1761
|
+
}),
|
|
1762
|
+
placeholder: "https:// o /ruta",
|
|
1763
|
+
className: "mt-1.5 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
|
|
1526
1764
|
}
|
|
1527
1765
|
)
|
|
1528
1766
|
] })
|
|
1529
|
-
] })
|
|
1530
|
-
|
|
1531
|
-
/* @__PURE__ */ jsx5("span", { children: "\u{1F4C4} File URL:" }),
|
|
1532
|
-
/* @__PURE__ */ jsx5("span", { className: "truncate text-indigo-600 font-semibold", children: String(value) })
|
|
1533
|
-
] }) : null
|
|
1534
|
-
] }),
|
|
1535
|
-
meta.type === "link" && /* @__PURE__ */ jsxs4("div", { className: "space-y-4 bg-slate-50 p-4 rounded-xl border border-slate-100", children: [
|
|
1536
|
-
/* @__PURE__ */ jsxs4("label", { className: "block", children: [
|
|
1537
|
-
/* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "Link Text" }),
|
|
1538
|
-
/* @__PURE__ */ jsx5(
|
|
1539
|
-
"input",
|
|
1540
|
-
{
|
|
1541
|
-
value: value?.text ?? "",
|
|
1542
|
-
onChange: (e) => onChange({ ...value, text: e.target.value }),
|
|
1543
|
-
className: "mt-1.5 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
|
|
1544
|
-
}
|
|
1545
|
-
)
|
|
1546
|
-
] }),
|
|
1547
|
-
/* @__PURE__ */ jsxs4("label", { className: "block", children: [
|
|
1548
|
-
/* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "URL Target" }),
|
|
1549
|
-
/* @__PURE__ */ jsx5(
|
|
1550
|
-
"input",
|
|
1551
|
-
{
|
|
1552
|
-
value: value?.href ?? "",
|
|
1553
|
-
onChange: (e) => onChange({ ...value, href: e.target.value }),
|
|
1554
|
-
placeholder: "https:// or /path",
|
|
1555
|
-
className: "mt-1.5 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
|
|
1556
|
-
}
|
|
1557
|
-
)
|
|
1558
|
-
] })
|
|
1559
|
-
] }),
|
|
1767
|
+
] });
|
|
1768
|
+
})(),
|
|
1560
1769
|
meta.type === "color" && /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-3 bg-slate-50 p-2 rounded-xl border border-slate-100", children: [
|
|
1561
1770
|
/* @__PURE__ */ jsx5(
|
|
1562
1771
|
"input",
|
|
@@ -1811,6 +2020,18 @@ function FieldEditor({
|
|
|
1811
2020
|
className: "w-full rounded-lg border border-slate-200 px-3 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20 bg-white",
|
|
1812
2021
|
children: schemaField.options?.map((opt) => /* @__PURE__ */ jsx5("option", { value: opt, children: opt }, opt))
|
|
1813
2022
|
}
|
|
2023
|
+
) : schemaField.type === "number" ? /* @__PURE__ */ jsx5(
|
|
2024
|
+
FormattedNumberInput,
|
|
2025
|
+
{
|
|
2026
|
+
value: item?.[schemaField.key],
|
|
2027
|
+
onChange: (val) => {
|
|
2028
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
2029
|
+
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
|
|
2030
|
+
onChange(arr);
|
|
2031
|
+
},
|
|
2032
|
+
isPrice: schemaField.key.toLowerCase().includes("price") || schemaField.key.toLowerCase().includes("precio"),
|
|
2033
|
+
className: "rounded-lg px-3 py-2 text-sm"
|
|
2034
|
+
}
|
|
1814
2035
|
) : /* @__PURE__ */ jsx5(
|
|
1815
2036
|
"input",
|
|
1816
2037
|
{
|
|
@@ -1919,11 +2140,11 @@ function CollectionsSection() {
|
|
|
1919
2140
|
const ctx = useCmsContext();
|
|
1920
2141
|
const collections = ctx.config.collections ?? [];
|
|
1921
2142
|
const [selected, setSelected] = useState5(
|
|
1922
|
-
collections
|
|
2143
|
+
collections.find((c) => !c.isSeparator) ?? null
|
|
1923
2144
|
);
|
|
1924
2145
|
const [counts, setCounts] = useState5({});
|
|
1925
2146
|
useEffect4(() => {
|
|
1926
|
-
collections.forEach((c) => {
|
|
2147
|
+
collections.filter((c) => !c.isSeparator).forEach((c) => {
|
|
1927
2148
|
ctx.adapter.listEntries(c.id).then((entries) => {
|
|
1928
2149
|
setCounts((prev) => ({ ...prev, [c.id]: entries.length }));
|
|
1929
2150
|
});
|
|
@@ -1933,20 +2154,43 @@ function CollectionsSection() {
|
|
|
1933
2154
|
/* @__PURE__ */ jsxs4("div", { className: "w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-slate-200 bg-white/50 p-4", children: [
|
|
1934
2155
|
/* @__PURE__ */ jsx5("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
|
|
1935
2156
|
/* @__PURE__ */ jsxs4("ul", { className: "flex overflow-x-auto gap-2 pb-2 md:block md:space-x-0 md:space-y-1 md:pb-0 md:overflow-visible", children: [
|
|
1936
|
-
collections.map((c) =>
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
" items"
|
|
1946
|
-
] })
|
|
1947
|
-
]
|
|
2157
|
+
collections.map((c, idx) => {
|
|
2158
|
+
if (c.isSeparator) {
|
|
2159
|
+
return /* @__PURE__ */ jsx5(
|
|
2160
|
+
"li",
|
|
2161
|
+
{
|
|
2162
|
+
className: "my-2 border-t border-slate-200/80"
|
|
2163
|
+
},
|
|
2164
|
+
c.id || `sep-${idx}`
|
|
2165
|
+
);
|
|
1948
2166
|
}
|
|
1949
|
-
|
|
2167
|
+
return /* @__PURE__ */ jsx5("li", { className: "shrink-0 min-w-[140px] md:w-full md:min-w-0", children: /* @__PURE__ */ jsxs4(
|
|
2168
|
+
"button",
|
|
2169
|
+
{
|
|
2170
|
+
onClick: () => setSelected(c),
|
|
2171
|
+
className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selected?.id === c.id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
|
|
2172
|
+
children: [
|
|
2173
|
+
/* @__PURE__ */ jsx5(
|
|
2174
|
+
"div",
|
|
2175
|
+
{
|
|
2176
|
+
className: selected?.id === c.id ? "text-slate-900" : "text-slate-700",
|
|
2177
|
+
children: c.name
|
|
2178
|
+
}
|
|
2179
|
+
),
|
|
2180
|
+
/* @__PURE__ */ jsxs4(
|
|
2181
|
+
"div",
|
|
2182
|
+
{
|
|
2183
|
+
className: `text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-500" : "text-slate-400"}`,
|
|
2184
|
+
children: [
|
|
2185
|
+
counts[c.id] ?? 0,
|
|
2186
|
+
" items"
|
|
2187
|
+
]
|
|
2188
|
+
}
|
|
2189
|
+
)
|
|
2190
|
+
]
|
|
2191
|
+
}
|
|
2192
|
+
) }, c.id);
|
|
2193
|
+
}),
|
|
1950
2194
|
collections.length === 0 && /* @__PURE__ */ jsx5("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200", children: "No collections registered." })
|
|
1951
2195
|
] })
|
|
1952
2196
|
] }),
|
|
@@ -1989,8 +2233,24 @@ function CollectionEditor({ collection }) {
|
|
|
1989
2233
|
collection.fields.forEach((f) => {
|
|
1990
2234
|
if (f.id === "order") {
|
|
1991
2235
|
base[f.id] = entries.length;
|
|
2236
|
+
} else if (f.type === "time-range") {
|
|
2237
|
+
if (f.startField) base[f.startField] = "";
|
|
2238
|
+
if (f.endField) base[f.endField] = "";
|
|
1992
2239
|
} else if (f.defaultValue !== void 0) {
|
|
1993
2240
|
base[f.id] = f.defaultValue;
|
|
2241
|
+
} else if (f.type === "branch-settings") {
|
|
2242
|
+
base[f.id] = {
|
|
2243
|
+
allBranches: true,
|
|
2244
|
+
branches: [],
|
|
2245
|
+
useBranchPricing: false,
|
|
2246
|
+
priceBranches: [],
|
|
2247
|
+
prices: {},
|
|
2248
|
+
useBranchDiscounts: false,
|
|
2249
|
+
discountBranches: [],
|
|
2250
|
+
discounts: {}
|
|
2251
|
+
};
|
|
2252
|
+
} else if (f.multiple) {
|
|
2253
|
+
base[f.id] = [];
|
|
1994
2254
|
} else {
|
|
1995
2255
|
base[f.id] = f.type === "boolean" ? false : f.type === "number" ? 0 : f.type === "select" ? f.options?.[0] ?? "" : "";
|
|
1996
2256
|
}
|
|
@@ -2003,7 +2263,9 @@ function CollectionEditor({ collection }) {
|
|
|
2003
2263
|
try {
|
|
2004
2264
|
const finalEditing = { ...editing };
|
|
2005
2265
|
collection.fields.forEach((f) => {
|
|
2006
|
-
if (f.type === "
|
|
2266
|
+
if (f.type === "time-range") {
|
|
2267
|
+
delete finalEditing[f.id];
|
|
2268
|
+
} else if (f.type === "slug" && !finalEditing[f.id]) {
|
|
2007
2269
|
const sourceField = f.source || "title";
|
|
2008
2270
|
let val = String(finalEditing[sourceField] || finalEditing.id || "");
|
|
2009
2271
|
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
@@ -2064,6 +2326,7 @@ function CollectionEditor({ collection }) {
|
|
|
2064
2326
|
setDragOverIdx(null);
|
|
2065
2327
|
};
|
|
2066
2328
|
const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 5);
|
|
2329
|
+
const isCreatingEntry = editing ? !entries.some((entry) => entry.id === editing.id) : false;
|
|
2067
2330
|
return /* @__PURE__ */ jsxs4("div", { className: "mx-auto max-w-5xl", children: [
|
|
2068
2331
|
/* @__PURE__ */ jsxs4("div", { className: "mb-8 flex items-center justify-between", children: [
|
|
2069
2332
|
/* @__PURE__ */ jsxs4("div", { children: [
|
|
@@ -2126,260 +2389,298 @@ function CollectionEditor({ collection }) {
|
|
|
2126
2389
|
] }, f);
|
|
2127
2390
|
})
|
|
2128
2391
|
] }),
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
f.label,
|
|
2137
|
-
/* @__PURE__ */ jsx5("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
|
|
2392
|
+
/* @__PURE__ */ jsx5(
|
|
2393
|
+
Modal,
|
|
2394
|
+
{
|
|
2395
|
+
open: Boolean(editing),
|
|
2396
|
+
title: /* @__PURE__ */ jsxs4("span", { className: "flex items-center gap-2 text-slate-900", children: [
|
|
2397
|
+
isCreatingEntry ? /* @__PURE__ */ jsx5(Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ jsx5(Pencil, { className: "h-4 w-4 text-indigo-600" }),
|
|
2398
|
+
isCreatingEntry ? "Create Entry" : "Edit Entry"
|
|
2138
2399
|
] }),
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
{
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2160
|
-
rows: 4,
|
|
2161
|
-
className: "w-full rounded-xl border border-slate-200 px-4 py-3 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all font-mono text-xs"
|
|
2162
|
-
}
|
|
2163
|
-
) : f.type === "icon" ? /* @__PURE__ */ jsx5(
|
|
2164
|
-
SearchableSelect,
|
|
2165
|
-
{
|
|
2166
|
-
value: String(editing[f.id] ?? ""),
|
|
2167
|
-
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2168
|
-
options: f.options || [],
|
|
2169
|
-
placeholder: `Search ${f.label.toLowerCase()}...`,
|
|
2170
|
-
iconMap: ctx.iconMap
|
|
2171
|
-
}
|
|
2172
|
-
) : f.type === "slug" ? /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2173
|
-
/* @__PURE__ */ jsx5(
|
|
2174
|
-
"input",
|
|
2175
|
-
{
|
|
2176
|
-
type: "text",
|
|
2177
|
-
value: String(editing[f.id] ?? ""),
|
|
2178
|
-
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2179
|
-
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2180
|
-
}
|
|
2181
|
-
),
|
|
2182
|
-
/* @__PURE__ */ jsx5(
|
|
2183
|
-
"button",
|
|
2184
|
-
{
|
|
2185
|
-
type: "button",
|
|
2186
|
-
onClick: () => {
|
|
2187
|
-
const sourceField = f.source || "title";
|
|
2188
|
-
let val = String(editing[sourceField] || editing.id || "");
|
|
2189
|
-
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
2190
|
-
setEditing({ ...editing, [f.id]: val });
|
|
2191
|
-
},
|
|
2192
|
-
className: "px-4 py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm font-semibold rounded-xl border border-slate-200 transition-colors",
|
|
2193
|
-
children: "Generate"
|
|
2194
|
-
}
|
|
2195
|
-
)
|
|
2196
|
-
] }) : f.type === "reference" ? /* @__PURE__ */ jsx5(
|
|
2197
|
-
ReferenceSelect,
|
|
2198
|
-
{
|
|
2199
|
-
collectionId: f.collection,
|
|
2200
|
-
displayField: f.displayField,
|
|
2201
|
-
value: String(editing[f.id] ?? ""),
|
|
2202
|
-
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2400
|
+
onCancel: () => {
|
|
2401
|
+
if (!saving) setEditing(null);
|
|
2402
|
+
},
|
|
2403
|
+
footer: null,
|
|
2404
|
+
centered: true,
|
|
2405
|
+
width: "min(900px, calc(100vw - 32px))",
|
|
2406
|
+
mask: { blur: true },
|
|
2407
|
+
keyboard: !saving,
|
|
2408
|
+
closable: !saving,
|
|
2409
|
+
styles: {
|
|
2410
|
+
body: {
|
|
2411
|
+
maxHeight: "calc(100dvh - 180px)",
|
|
2412
|
+
display: "flex",
|
|
2413
|
+
flexDirection: "column",
|
|
2414
|
+
overflow: "hidden",
|
|
2415
|
+
padding: 0
|
|
2416
|
+
},
|
|
2417
|
+
mask: {
|
|
2418
|
+
backgroundColor: "rgba(15, 23, 42, 0.82)",
|
|
2419
|
+
backdropFilter: "blur(8px)"
|
|
2203
2420
|
}
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
{
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
|
|
2222
|
-
return /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
|
|
2223
|
-
isVideo ? /* @__PURE__ */ jsx5("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ jsx5("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
|
|
2224
|
-
/* @__PURE__ */ jsx5(
|
|
2225
|
-
"button",
|
|
2226
|
-
{
|
|
2227
|
-
type: "button",
|
|
2228
|
-
onClick: () => {
|
|
2229
|
-
const arr = [...editing[f.id] || []];
|
|
2230
|
-
arr.splice(i, 1);
|
|
2231
|
-
setEditing({ ...editing, [f.id]: arr });
|
|
2232
|
-
},
|
|
2233
|
-
className: "absolute top-2 right-2 bg-red-500/80 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500",
|
|
2234
|
-
children: /* @__PURE__ */ jsx5(X, { className: "w-3 h-3" })
|
|
2235
|
-
}
|
|
2236
|
-
)
|
|
2237
|
-
] }, i);
|
|
2238
|
-
}) }),
|
|
2239
|
-
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2240
|
-
/* @__PURE__ */ jsx5(
|
|
2421
|
+
},
|
|
2422
|
+
children: editing && /* @__PURE__ */ jsxs4("div", { className: "flex max-h-[calc(100dvh-180px)] min-h-0 flex-col", children: [
|
|
2423
|
+
/* @__PURE__ */ jsx5("div", { className: "min-h-0 flex-1 overflow-y-auto px-6 py-5", children: /* @__PURE__ */ jsx5("div", { className: "grid grid-cols-1 gap-5 lg:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order" && !f.hidden).map((f) => /* @__PURE__ */ jsxs4("div", { className: `block ${f.type === "richtext" || f.type === "branch-settings" || f.type === "time-range" ? "lg:col-span-2" : ""}`, children: [
|
|
2424
|
+
/* @__PURE__ */ jsxs4("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
|
|
2425
|
+
f.label,
|
|
2426
|
+
/* @__PURE__ */ jsx5("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
|
|
2427
|
+
] }),
|
|
2428
|
+
f.type === "branch-settings" ? /* @__PURE__ */ jsx5(
|
|
2429
|
+
BranchSettingsEditor,
|
|
2430
|
+
{
|
|
2431
|
+
collectionId: f.collection || "",
|
|
2432
|
+
value: editing[f.id],
|
|
2433
|
+
globalPrice: Number(editing.price) || 0,
|
|
2434
|
+
globalDiscount: Number(editing.discountPercent) || 0,
|
|
2435
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2436
|
+
}
|
|
2437
|
+
) : f.type === "boolean" ? /* @__PURE__ */ jsx5("div", { className: "mt-1 h-10 flex items-center", children: /* @__PURE__ */ jsx5(
|
|
2241
2438
|
"input",
|
|
2242
2439
|
{
|
|
2243
|
-
type: "
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
e.preventDefault();
|
|
2248
|
-
const arr = [...editing[f.id] || [], e.currentTarget.value];
|
|
2249
|
-
setEditing({ ...editing, [f.id]: arr });
|
|
2250
|
-
e.currentTarget.value = "";
|
|
2251
|
-
}
|
|
2252
|
-
},
|
|
2253
|
-
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2440
|
+
type: "checkbox",
|
|
2441
|
+
checked: !!editing[f.id],
|
|
2442
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.checked }),
|
|
2443
|
+
className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
2254
2444
|
}
|
|
2255
|
-
)
|
|
2256
|
-
|
|
2257
|
-
|
|
2445
|
+
) }) : f.type === "number" ? /* @__PURE__ */ jsx5(
|
|
2446
|
+
FormattedNumberInput,
|
|
2447
|
+
{
|
|
2448
|
+
value: editing[f.id],
|
|
2449
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2450
|
+
isPrice: f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.toLowerCase().includes("valor") || f.label.includes("$"),
|
|
2451
|
+
isPercent: f.id.toLowerCase().includes("discount") || f.id.toLowerCase().includes("descuento") || f.label.toLowerCase().includes("descuento")
|
|
2452
|
+
}
|
|
2453
|
+
) : f.type === "time-range" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-1.5", children: [
|
|
2258
2454
|
/* @__PURE__ */ jsx5(
|
|
2259
|
-
|
|
2455
|
+
AdminTimeRangePicker,
|
|
2260
2456
|
{
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
onChange: (
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
ctx.uploadImage
|
|
2279
|
-
);
|
|
2280
|
-
});
|
|
2281
|
-
}
|
|
2457
|
+
value: [
|
|
2458
|
+
toDayjsTime(f.startField ? editing[f.startField] : ""),
|
|
2459
|
+
toDayjsTime(f.endField ? editing[f.endField] : "")
|
|
2460
|
+
],
|
|
2461
|
+
onChange: (times) => setEditing(
|
|
2462
|
+
(current) => current ? {
|
|
2463
|
+
...current,
|
|
2464
|
+
...f.startField ? { [f.startField]: toStoredTime(times?.[0]) } : {},
|
|
2465
|
+
...f.endField ? { [f.endField]: toStoredTime(times?.[1]) } : {}
|
|
2466
|
+
} : current
|
|
2467
|
+
),
|
|
2468
|
+
allowEmpty: [true, true],
|
|
2469
|
+
className: "w-full",
|
|
2470
|
+
format: TIME_DISPLAY_FORMAT,
|
|
2471
|
+
order: false,
|
|
2472
|
+
placeholder: ["Hora de inicio", "Hora de cierre"],
|
|
2473
|
+
use12Hours: true
|
|
2282
2474
|
}
|
|
2283
|
-
)
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2475
|
+
),
|
|
2476
|
+
/* @__PURE__ */ jsx5("p", { className: "text-xs text-slate-500", children: "Selecciona inicio y cierre en un mismo control. Usa AM/PM; si el cierre es anterior al inicio, el horario cruza medianoche. Deja ambos vac\xEDos para mantenerlo siempre disponible." })
|
|
2477
|
+
] }) : f.type === "time" ? /* @__PURE__ */ jsx5(
|
|
2478
|
+
AdminTimePicker,
|
|
2479
|
+
{
|
|
2480
|
+
value: toDayjsTime(editing[f.id]),
|
|
2481
|
+
onChange: (time) => setEditing({ ...editing, [f.id]: toStoredTime(time) }),
|
|
2482
|
+
className: "w-full",
|
|
2483
|
+
format: TIME_DISPLAY_FORMAT,
|
|
2484
|
+
use12Hours: true
|
|
2485
|
+
}
|
|
2486
|
+
) : f.type === "richtext" ? /* @__PURE__ */ jsx5(
|
|
2487
|
+
"textarea",
|
|
2290
2488
|
{
|
|
2291
|
-
type: "url",
|
|
2292
2489
|
value: String(editing[f.id] ?? ""),
|
|
2293
2490
|
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2294
|
-
|
|
2295
|
-
className: "w-full rounded-xl border border-slate-200 px-4 py-
|
|
2491
|
+
rows: 4,
|
|
2492
|
+
className: "w-full rounded-xl border border-slate-200 px-4 py-3 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all font-mono text-xs"
|
|
2296
2493
|
}
|
|
2297
|
-
)
|
|
2298
|
-
|
|
2299
|
-
|
|
2494
|
+
) : f.type === "icon" ? /* @__PURE__ */ jsx5(
|
|
2495
|
+
SearchableSelect,
|
|
2496
|
+
{
|
|
2497
|
+
value: String(editing[f.id] ?? ""),
|
|
2498
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2499
|
+
options: f.options || [],
|
|
2500
|
+
placeholder: `Search ${f.label.toLowerCase()}...`,
|
|
2501
|
+
iconMap: ctx.iconMap
|
|
2502
|
+
}
|
|
2503
|
+
) : f.type === "slug" ? /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2300
2504
|
/* @__PURE__ */ jsx5(
|
|
2301
2505
|
"input",
|
|
2302
2506
|
{
|
|
2303
|
-
type: "
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
const file = e.target.files?.[0];
|
|
2308
|
-
if (file) {
|
|
2309
|
-
void handleImageFile(
|
|
2310
|
-
file,
|
|
2311
|
-
(url) => setEditing({ ...editing, [f.id]: url }),
|
|
2312
|
-
ctx.uploadImage
|
|
2313
|
-
);
|
|
2314
|
-
}
|
|
2315
|
-
}
|
|
2507
|
+
type: "text",
|
|
2508
|
+
value: String(editing[f.id] ?? ""),
|
|
2509
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2510
|
+
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2316
2511
|
}
|
|
2317
|
-
)
|
|
2318
|
-
|
|
2319
|
-
|
|
2320
|
-
|
|
2321
|
-
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
|
|
2325
|
-
|
|
2326
|
-
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
|
|
2349
|
-
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2353
|
-
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
|
|
2363
|
-
{
|
|
2364
|
-
className: "
|
|
2365
|
-
|
|
2366
|
-
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2512
|
+
),
|
|
2513
|
+
/* @__PURE__ */ jsx5(
|
|
2514
|
+
"button",
|
|
2515
|
+
{
|
|
2516
|
+
type: "button",
|
|
2517
|
+
onClick: () => {
|
|
2518
|
+
const sourceField = f.source || "title";
|
|
2519
|
+
let val = String(editing[sourceField] || editing.id || "");
|
|
2520
|
+
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
2521
|
+
setEditing({ ...editing, [f.id]: val });
|
|
2522
|
+
},
|
|
2523
|
+
className: "px-4 py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm font-semibold rounded-xl border border-slate-200 transition-colors",
|
|
2524
|
+
children: "Generate"
|
|
2525
|
+
}
|
|
2526
|
+
)
|
|
2527
|
+
] }) : f.type === "reference" || f.type === "select" && f.collection ? /* @__PURE__ */ jsx5(
|
|
2528
|
+
ReferenceSelect,
|
|
2529
|
+
{
|
|
2530
|
+
collectionId: f.collection,
|
|
2531
|
+
displayField: f.displayField,
|
|
2532
|
+
valueField: f.valueField,
|
|
2533
|
+
fallbackOptions: f.options,
|
|
2534
|
+
multiple: f.multiple,
|
|
2535
|
+
searchable: f.searchable,
|
|
2536
|
+
max: f.max,
|
|
2537
|
+
value: editing[f.id],
|
|
2538
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2539
|
+
}
|
|
2540
|
+
) : f.type === "select" ? /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
|
|
2541
|
+
/* @__PURE__ */ jsxs4(
|
|
2542
|
+
"select",
|
|
2543
|
+
{
|
|
2544
|
+
value: String(editing[f.id] ?? ""),
|
|
2545
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2546
|
+
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all bg-white appearance-none pr-10 cursor-pointer text-slate-800",
|
|
2547
|
+
children: [
|
|
2548
|
+
/* @__PURE__ */ jsx5("option", { value: "", children: "-- Selecciona una opci\xF3n --" }),
|
|
2549
|
+
f.options?.map((opt) => {
|
|
2550
|
+
const val = typeof opt === "string" ? opt : opt.value;
|
|
2551
|
+
const lab = typeof opt === "string" ? opt : opt.label;
|
|
2552
|
+
return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
|
|
2553
|
+
})
|
|
2554
|
+
]
|
|
2555
|
+
}
|
|
2556
|
+
),
|
|
2557
|
+
/* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
|
|
2558
|
+
] }) : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2559
|
+
/* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
|
|
2560
|
+
const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
|
|
2561
|
+
return /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
|
|
2562
|
+
isVideo ? /* @__PURE__ */ jsx5("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ jsx5("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
|
|
2563
|
+
/* @__PURE__ */ jsx5(
|
|
2564
|
+
"button",
|
|
2565
|
+
{
|
|
2566
|
+
type: "button",
|
|
2567
|
+
onClick: () => {
|
|
2568
|
+
const arr = [...editing[f.id] || []];
|
|
2569
|
+
arr.splice(i, 1);
|
|
2570
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2571
|
+
},
|
|
2572
|
+
className: "absolute top-2 right-2 bg-red-500/80 text-white rounded-full p-1 opacity-0 group-hover:opacity-100 transition-opacity hover:bg-red-500",
|
|
2573
|
+
children: /* @__PURE__ */ jsx5(X, { className: "w-3 h-3" })
|
|
2574
|
+
}
|
|
2575
|
+
)
|
|
2576
|
+
] }, i);
|
|
2577
|
+
}) }),
|
|
2578
|
+
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2579
|
+
/* @__PURE__ */ jsx5(
|
|
2580
|
+
"input",
|
|
2581
|
+
{
|
|
2582
|
+
type: "url",
|
|
2583
|
+
placeholder: "Add media URL and press Enter...",
|
|
2584
|
+
onKeyDown: (e) => {
|
|
2585
|
+
if (e.key === "Enter" && e.currentTarget.value) {
|
|
2586
|
+
e.preventDefault();
|
|
2587
|
+
const arr = [...editing[f.id] || [], e.currentTarget.value];
|
|
2588
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2589
|
+
e.currentTarget.value = "";
|
|
2590
|
+
}
|
|
2591
|
+
},
|
|
2592
|
+
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2593
|
+
}
|
|
2594
|
+
),
|
|
2595
|
+
/* @__PURE__ */ jsx5(
|
|
2596
|
+
FilePickerButton,
|
|
2597
|
+
{
|
|
2598
|
+
accept: "image/*,video/*",
|
|
2599
|
+
multiple: true,
|
|
2600
|
+
className: "flex-shrink-0 cursor-pointer rounded-xl border border-slate-200 bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-200",
|
|
2601
|
+
onFiles: (files) => {
|
|
2602
|
+
files.forEach((file) => {
|
|
2603
|
+
void handleImageFile(
|
|
2604
|
+
file,
|
|
2605
|
+
(url) => {
|
|
2606
|
+
setEditing((prev) => {
|
|
2607
|
+
if (!prev) return prev;
|
|
2608
|
+
const current = prev[f.id] || [];
|
|
2609
|
+
if (f.max && current.length >= f.max) {
|
|
2610
|
+
return prev;
|
|
2611
|
+
}
|
|
2612
|
+
return { ...prev, [f.id]: [...current, url] };
|
|
2613
|
+
});
|
|
2614
|
+
},
|
|
2615
|
+
ctx.uploadImage
|
|
2616
|
+
);
|
|
2617
|
+
});
|
|
2618
|
+
},
|
|
2619
|
+
children: "Upload"
|
|
2620
|
+
}
|
|
2621
|
+
)
|
|
2622
|
+
] })
|
|
2623
|
+
] }) : /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2624
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2625
|
+
/* @__PURE__ */ jsx5(
|
|
2626
|
+
"input",
|
|
2627
|
+
{
|
|
2628
|
+
type: "url",
|
|
2629
|
+
value: String(editing[f.id] ?? ""),
|
|
2630
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2631
|
+
placeholder: "https://...",
|
|
2632
|
+
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2633
|
+
}
|
|
2634
|
+
),
|
|
2635
|
+
/* @__PURE__ */ jsx5(
|
|
2636
|
+
FilePickerButton,
|
|
2637
|
+
{
|
|
2638
|
+
accept: "image/*,video/*",
|
|
2639
|
+
className: "flex-shrink-0 cursor-pointer rounded-xl border border-slate-200 bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-200",
|
|
2640
|
+
onFiles: (files) => {
|
|
2641
|
+
const file = files[0];
|
|
2642
|
+
if (file) {
|
|
2643
|
+
void handleImageFile(
|
|
2644
|
+
file,
|
|
2645
|
+
(url) => setEditing(
|
|
2646
|
+
(current) => current ? { ...current, [f.id]: url } : current
|
|
2647
|
+
),
|
|
2648
|
+
ctx.uploadImage
|
|
2649
|
+
);
|
|
2650
|
+
}
|
|
2651
|
+
},
|
|
2652
|
+
children: "Upload"
|
|
2653
|
+
}
|
|
2654
|
+
)
|
|
2655
|
+
] }),
|
|
2656
|
+
editing[f.id] ? /* @__PURE__ */ jsx5("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: String(editing[f.id]).match(/\.(mp4|webm|mov|ogg)$/i) || String(editing[f.id]).includes("video") ? /* @__PURE__ */ jsx5(
|
|
2657
|
+
"video",
|
|
2658
|
+
{
|
|
2659
|
+
src: String(editing[f.id]),
|
|
2660
|
+
controls: true,
|
|
2661
|
+
className: "w-full h-auto max-h-48 object-contain rounded-lg"
|
|
2662
|
+
}
|
|
2663
|
+
) : /* @__PURE__ */ jsx5(
|
|
2664
|
+
"img",
|
|
2665
|
+
{
|
|
2666
|
+
src: String(editing[f.id]),
|
|
2667
|
+
alt: "",
|
|
2668
|
+
className: "w-full h-auto max-h-48 object-contain rounded-lg"
|
|
2669
|
+
}
|
|
2670
|
+
) }) : null
|
|
2671
|
+
] }) : f.type === "password" ? /* @__PURE__ */ jsx5(
|
|
2672
|
+
PasswordField,
|
|
2673
|
+
{
|
|
2674
|
+
value: String(editing[f.id] ?? ""),
|
|
2675
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2676
|
+
}
|
|
2677
|
+
) : f.type === "color" && !f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-3", children: [
|
|
2373
2678
|
/* @__PURE__ */ jsx5(
|
|
2374
2679
|
"input",
|
|
2375
2680
|
{
|
|
2376
2681
|
type: "color",
|
|
2377
|
-
value:
|
|
2378
|
-
onChange: (e) => {
|
|
2379
|
-
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
2380
|
-
arr[idx] = e.target.value;
|
|
2381
|
-
setEditing({ ...editing, [f.id]: arr });
|
|
2382
|
-
},
|
|
2682
|
+
value: String(editing[f.id] ?? "#000000").startsWith("#") && String(editing[f.id] ?? "").length === 7 ? String(editing[f.id]) : "#000000",
|
|
2683
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2383
2684
|
className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
|
|
2384
2685
|
}
|
|
2385
2686
|
),
|
|
@@ -2387,135 +2688,172 @@ function CollectionEditor({ collection }) {
|
|
|
2387
2688
|
"input",
|
|
2388
2689
|
{
|
|
2389
2690
|
type: "text",
|
|
2390
|
-
value:
|
|
2391
|
-
onChange: (e) => {
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
setEditing({ ...editing, [f.id]: arr });
|
|
2395
|
-
},
|
|
2396
|
-
placeholder: "#1c2a44",
|
|
2397
|
-
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2691
|
+
value: String(editing[f.id] ?? ""),
|
|
2692
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2693
|
+
placeholder: "#000000",
|
|
2694
|
+
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2398
2695
|
}
|
|
2399
2696
|
),
|
|
2400
2697
|
/* @__PURE__ */ jsx5(
|
|
2401
2698
|
"div",
|
|
2402
2699
|
{
|
|
2403
|
-
className: "w-
|
|
2404
|
-
style: { backgroundColor:
|
|
2700
|
+
className: "w-8 h-8 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
|
|
2701
|
+
style: { backgroundColor: String(editing[f.id] ?? "#000000") }
|
|
2405
2702
|
}
|
|
2406
|
-
)
|
|
2407
|
-
|
|
2703
|
+
)
|
|
2704
|
+
] }) : f.type === "color" && f.multiple || f.type === "list" && f.id === "colors" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2705
|
+
(Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : []).map((item, idx) => {
|
|
2706
|
+
const colorVal = String(item ?? "").trim();
|
|
2707
|
+
const validHex = colorVal.startsWith("#") && (colorVal.length === 4 || colorVal.length === 7) ? colorVal : "#000000";
|
|
2708
|
+
return /* @__PURE__ */ jsxs4("div", { className: "flex gap-2 items-center", children: [
|
|
2709
|
+
/* @__PURE__ */ jsx5(
|
|
2710
|
+
"input",
|
|
2711
|
+
{
|
|
2712
|
+
type: "color",
|
|
2713
|
+
value: validHex.length === 7 ? validHex : "#000000",
|
|
2714
|
+
onChange: (e) => {
|
|
2715
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
2716
|
+
arr[idx] = e.target.value;
|
|
2717
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2718
|
+
},
|
|
2719
|
+
className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
|
|
2720
|
+
}
|
|
2721
|
+
),
|
|
2722
|
+
/* @__PURE__ */ jsx5(
|
|
2723
|
+
"input",
|
|
2724
|
+
{
|
|
2725
|
+
type: "text",
|
|
2726
|
+
value: colorVal,
|
|
2727
|
+
onChange: (e) => {
|
|
2728
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
2729
|
+
arr[idx] = e.target.value;
|
|
2730
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2731
|
+
},
|
|
2732
|
+
placeholder: "#1c2a44",
|
|
2733
|
+
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-800 font-mono shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2734
|
+
}
|
|
2735
|
+
),
|
|
2736
|
+
/* @__PURE__ */ jsx5(
|
|
2737
|
+
"div",
|
|
2738
|
+
{
|
|
2739
|
+
className: "w-7 h-7 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
|
|
2740
|
+
style: { backgroundColor: colorVal || "#000000" }
|
|
2741
|
+
}
|
|
2742
|
+
),
|
|
2743
|
+
/* @__PURE__ */ jsx5(
|
|
2744
|
+
"button",
|
|
2745
|
+
{
|
|
2746
|
+
type: "button",
|
|
2747
|
+
onClick: () => {
|
|
2748
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
2749
|
+
arr.splice(idx, 1);
|
|
2750
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2751
|
+
},
|
|
2752
|
+
className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
|
|
2753
|
+
children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
|
|
2754
|
+
}
|
|
2755
|
+
)
|
|
2756
|
+
] }, idx);
|
|
2757
|
+
}),
|
|
2758
|
+
/* @__PURE__ */ jsxs4(
|
|
2408
2759
|
"button",
|
|
2409
2760
|
{
|
|
2410
2761
|
type: "button",
|
|
2411
2762
|
onClick: () => {
|
|
2412
2763
|
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
2413
|
-
arr.
|
|
2764
|
+
arr.push("#000000");
|
|
2414
2765
|
setEditing({ ...editing, [f.id]: arr });
|
|
2415
2766
|
},
|
|
2416
|
-
className: "
|
|
2417
|
-
children:
|
|
2767
|
+
className: "inline-flex items-center gap-1.5 px-3 py-1.5 text-xs font-semibold text-indigo-600 bg-indigo-50 hover:bg-indigo-100 rounded-lg border border-indigo-100 transition-colors",
|
|
2768
|
+
children: [
|
|
2769
|
+
/* @__PURE__ */ jsx5(Plus, { className: "w-3.5 h-3.5" }),
|
|
2770
|
+
" Add Color"
|
|
2771
|
+
]
|
|
2418
2772
|
}
|
|
2419
2773
|
)
|
|
2420
|
-
] },
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2774
|
+
] }) : f.type === "list" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2775
|
+
(Array.isArray(editing[f.id]) ? editing[f.id] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : []).map((item, idx) => /* @__PURE__ */ jsxs4("div", { className: "flex gap-2 items-center", children: [
|
|
2776
|
+
/* @__PURE__ */ jsx5(
|
|
2777
|
+
"input",
|
|
2778
|
+
{
|
|
2779
|
+
type: "text",
|
|
2780
|
+
value: String(item ?? ""),
|
|
2781
|
+
onChange: (e) => {
|
|
2782
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
|
|
2783
|
+
arr[idx] = e.target.value;
|
|
2784
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2785
|
+
},
|
|
2786
|
+
className: "flex-1 rounded-xl border border-slate-200 px-4 py-2 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2787
|
+
}
|
|
2788
|
+
),
|
|
2789
|
+
/* @__PURE__ */ jsx5(
|
|
2790
|
+
"button",
|
|
2791
|
+
{
|
|
2792
|
+
type: "button",
|
|
2793
|
+
onClick: () => {
|
|
2794
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
|
|
2795
|
+
arr.splice(idx, 1);
|
|
2796
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2797
|
+
},
|
|
2798
|
+
className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
|
|
2799
|
+
children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
|
|
2800
|
+
}
|
|
2801
|
+
)
|
|
2802
|
+
] }, idx)),
|
|
2803
|
+
/* @__PURE__ */ jsxs4(
|
|
2804
|
+
"button",
|
|
2805
|
+
{
|
|
2806
|
+
type: "button",
|
|
2807
|
+
onClick: () => {
|
|
2808
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
|
|
2809
|
+
arr.push("");
|
|
2810
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2811
|
+
},
|
|
2812
|
+
className: "inline-flex items-center gap-1.5 px-3 py-2 bg-indigo-50 hover:bg-indigo-100 text-indigo-700 text-xs font-semibold rounded-xl transition-colors",
|
|
2813
|
+
children: [
|
|
2814
|
+
/* @__PURE__ */ jsx5(Plus, { className: "w-3.5 h-3.5" }),
|
|
2815
|
+
" Add Item"
|
|
2816
|
+
]
|
|
2817
|
+
}
|
|
2818
|
+
)
|
|
2819
|
+
] }) : /* @__PURE__ */ jsx5(
|
|
2441
2820
|
"input",
|
|
2442
2821
|
{
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2822
|
+
value: String(editing[f.id] ?? ""),
|
|
2823
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2824
|
+
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2825
|
+
}
|
|
2826
|
+
)
|
|
2827
|
+
] }, f.id)) }) }),
|
|
2828
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex shrink-0 justify-end gap-3 border-t border-slate-200 bg-white px-6 py-4", children: [
|
|
2829
|
+
/* @__PURE__ */ jsx5(
|
|
2830
|
+
"button",
|
|
2831
|
+
{
|
|
2832
|
+
onClick: () => setEditing(null),
|
|
2833
|
+
disabled: saving,
|
|
2834
|
+
className: "rounded-xl px-5 py-2.5 text-sm font-semibold text-slate-600 hover:bg-slate-100 transition-colors disabled:opacity-50",
|
|
2835
|
+
children: "Cancel"
|
|
2451
2836
|
}
|
|
2452
2837
|
),
|
|
2453
2838
|
/* @__PURE__ */ jsx5(
|
|
2454
2839
|
"button",
|
|
2455
2840
|
{
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2841
|
+
onClick: save,
|
|
2842
|
+
disabled: saving,
|
|
2843
|
+
className: "inline-flex items-center gap-2 rounded-xl bg-slate-900 px-6 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-slate-800 hover:shadow transition-all disabled:opacity-60",
|
|
2844
|
+
children: saving ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
2845
|
+
/* @__PURE__ */ jsxs4("svg", { className: "animate-spin h-4 w-4 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
|
|
2846
|
+
/* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
2847
|
+
/* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
|
|
2848
|
+
] }),
|
|
2849
|
+
"Saving..."
|
|
2850
|
+
] }) : "Save Entry"
|
|
2464
2851
|
}
|
|
2465
2852
|
)
|
|
2466
|
-
] }
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
type: "button",
|
|
2471
|
-
onClick: () => {
|
|
2472
|
-
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
|
|
2473
|
-
arr.push("");
|
|
2474
|
-
setEditing({ ...editing, [f.id]: arr });
|
|
2475
|
-
},
|
|
2476
|
-
className: "inline-flex items-center gap-1.5 px-3 py-2 bg-indigo-50 hover:bg-indigo-100 text-indigo-700 text-xs font-semibold rounded-xl transition-colors",
|
|
2477
|
-
children: [
|
|
2478
|
-
/* @__PURE__ */ jsx5(Plus, { className: "w-3.5 h-3.5" }),
|
|
2479
|
-
" Add Item"
|
|
2480
|
-
]
|
|
2481
|
-
}
|
|
2482
|
-
)
|
|
2483
|
-
] }) : /* @__PURE__ */ jsx5(
|
|
2484
|
-
"input",
|
|
2485
|
-
{
|
|
2486
|
-
value: String(editing[f.id] ?? ""),
|
|
2487
|
-
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2488
|
-
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all"
|
|
2489
|
-
}
|
|
2490
|
-
)
|
|
2491
|
-
] }, f.id)) }),
|
|
2492
|
-
/* @__PURE__ */ jsxs4("div", { className: "mt-8 flex justify-end gap-3 pt-5 border-t border-slate-100", children: [
|
|
2493
|
-
/* @__PURE__ */ jsx5(
|
|
2494
|
-
"button",
|
|
2495
|
-
{
|
|
2496
|
-
onClick: () => setEditing(null),
|
|
2497
|
-
disabled: saving,
|
|
2498
|
-
className: "rounded-xl px-5 py-2.5 text-sm font-semibold text-slate-600 hover:bg-slate-100 transition-colors disabled:opacity-50",
|
|
2499
|
-
children: "Cancel"
|
|
2500
|
-
}
|
|
2501
|
-
),
|
|
2502
|
-
/* @__PURE__ */ jsx5(
|
|
2503
|
-
"button",
|
|
2504
|
-
{
|
|
2505
|
-
onClick: save,
|
|
2506
|
-
disabled: saving,
|
|
2507
|
-
className: "inline-flex items-center gap-2 rounded-xl bg-slate-900 px-6 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-slate-800 hover:shadow transition-all disabled:opacity-60",
|
|
2508
|
-
children: saving ? /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2509
|
-
/* @__PURE__ */ jsxs4("svg", { className: "animate-spin h-4 w-4 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
|
|
2510
|
-
/* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
2511
|
-
/* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
|
|
2512
|
-
] }),
|
|
2513
|
-
"Saving..."
|
|
2514
|
-
] }) : "Save Entry"
|
|
2515
|
-
}
|
|
2516
|
-
)
|
|
2517
|
-
] })
|
|
2518
|
-
] }),
|
|
2853
|
+
] })
|
|
2854
|
+
] })
|
|
2855
|
+
}
|
|
2856
|
+
),
|
|
2519
2857
|
/* @__PURE__ */ jsx5("div", { className: "overflow-x-auto rounded-2xl border border-slate-200 bg-white shadow-sm", children: /* @__PURE__ */ jsxs4("table", { className: "w-full text-sm text-left", children: [
|
|
2520
2858
|
/* @__PURE__ */ jsx5("thead", { className: "bg-slate-50/80 border-b border-slate-200", children: /* @__PURE__ */ jsxs4("tr", { children: [
|
|
2521
2859
|
visibleFields.map((f) => /* @__PURE__ */ jsx5("th", { className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider", children: f.label }, f.id)),
|
|
@@ -2527,7 +2865,7 @@ function CollectionEditor({ collection }) {
|
|
|
2527
2865
|
visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4", children: /* @__PURE__ */ jsx5("div", { className: "h-4 bg-slate-100 rounded animate-pulse", style: { width: `${60 + i * 13 % 30}%` } }) }, f.id)),
|
|
2528
2866
|
/* @__PURE__ */ jsx5("td", { className: "px-6 py-4 sticky right-0 bg-white border-l border-slate-100", children: /* @__PURE__ */ jsx5("div", { className: "h-4 w-16 bg-slate-100 rounded animate-pulse ml-auto" }) })
|
|
2529
2867
|
] }, i))
|
|
2530
|
-
) : /* @__PURE__ */ jsxs4(
|
|
2868
|
+
) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
2531
2869
|
(() => {
|
|
2532
2870
|
let res = entries;
|
|
2533
2871
|
if (search && collection.searchBy?.length) {
|
|
@@ -2543,7 +2881,7 @@ function CollectionEditor({ collection }) {
|
|
|
2543
2881
|
});
|
|
2544
2882
|
}
|
|
2545
2883
|
const paginatedRes = res.slice((page - 1) * itemsPerPage, page * itemsPerPage);
|
|
2546
|
-
return /* @__PURE__ */ jsx5(
|
|
2884
|
+
return /* @__PURE__ */ jsx5(Fragment4, { children: paginatedRes.map((e, idx) => /* @__PURE__ */ jsxs4(
|
|
2547
2885
|
"tr",
|
|
2548
2886
|
{
|
|
2549
2887
|
draggable: true,
|
|
@@ -2553,7 +2891,10 @@ function CollectionEditor({ collection }) {
|
|
|
2553
2891
|
onDragEnd,
|
|
2554
2892
|
className: `hover:bg-slate-50/50 transition-colors group cursor-grab active:cursor-grabbing ${deletingId === e.id ? "opacity-50" : ""} ${dragOverIdx === idx ? "border-t-2 border-t-indigo-500" : ""}`,
|
|
2555
2893
|
children: [
|
|
2556
|
-
visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx5("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx5("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : f.type === "reference" && e[f.id] ? /* @__PURE__ */ jsx5(ReferenceTableCell, { collectionId: f.collection, entryId:
|
|
2894
|
+
visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "branch-settings" ? /* @__PURE__ */ jsx5(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx5("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx5("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : (f.type === "reference" || f.type === "select" && f.collection) && e[f.id] ? /* @__PURE__ */ jsx5(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : f.id === "status" && e[f.id] ? /* @__PURE__ */ jsx5("span", { className: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold ${String(e[f.id]).includes("Entregado") ? "bg-emerald-100 text-emerald-800 border border-emerald-300" : String(e[f.id]).includes("Preparaci\xF3n") ? "bg-amber-100 text-amber-800 border border-amber-300" : String(e[f.id]).includes("Camino") ? "bg-blue-100 text-blue-800 border border-blue-300" : String(e[f.id]).includes("Confirmado") ? "bg-indigo-100 text-indigo-800 border border-indigo-300" : String(e[f.id]).includes("Cancelado") ? "bg-rose-100 text-rose-800 border border-rose-300" : "bg-amber-50 text-amber-800 border border-amber-200"}`, children: String(e[f.id]) }) : f.type === "number" && e[f.id] !== void 0 && e[f.id] !== null && String(e[f.id]) !== "" ? f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.includes("$") || f.id.toLowerCase().includes("amount") || f.id.toLowerCase().includes("total") ? /* @__PURE__ */ jsxs4("span", { className: "font-semibold text-slate-800", children: [
|
|
2895
|
+
"$ ",
|
|
2896
|
+
Number(e[f.id]).toLocaleString("es-CO")
|
|
2897
|
+
] }) : /* @__PURE__ */ jsx5("span", { children: Number(e[f.id]).toLocaleString("es-CO") }) : String(e[f.id] ?? "") }, f.id)),
|
|
2557
2898
|
/* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-right sticky right-0 bg-white border-l border-slate-100 group-hover:bg-slate-50/50 transition-colors", children: /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-end gap-2", children: [
|
|
2558
2899
|
/* @__PURE__ */ jsx5("div", { className: "p-2 text-slate-300 cursor-grab active:cursor-grabbing", title: "Drag to reorder", children: /* @__PURE__ */ jsx5("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "w-4 h-4", children: /* @__PURE__ */ jsx5("path", { d: "M5.5 3C6.32843 3 7 3.67157 7 4.5C7 5.32843 6.32843 6 5.5 6C4.67157 6 4 5.32843 4 4.5C4 3.67157 4.67157 3 5.5 3ZM9.5 3C10.3284 3 11 3.67157 11 4.5C11 5.32843 10.3284 6 9.5 6C8.67157 6 8 5.32843 8 4.5C8 3.67157 8.67157 3 9.5 3ZM5.5 7.5C6.32843 7.5 7 8.17157 7 9C7 9.82843 6.32843 10.5 5.5 10.5C4.67157 10.5 4 9.82843 4 9C4 8.17157 4.67157 7.5 5.5 7.5ZM9.5 7.5C10.3284 7.5 11 8.17157 11 9C11 9.82843 10.3284 10.5 9.5 10.5C8.67157 10.5 8 9.82843 8 9C8 8.17157 8.67157 7.5 9.5 7.5ZM5.5 12C6.32843 12 7 12.6716 7 13.5C7 14.3284 6.32843 15 5.5 15C4.67157 15 4 14.3284 4 13.5C4 12.6716 4.67157 12 5.5 12ZM9.5 12C10.3284 12 11 12.6716 11 13.5C11 14.3284 10.3284 15 9.5 15C8.67157 15 8 14.3284 8 13.5C8 12.6716 8.67157 12 9.5 12Z", fill: "currentColor", fillRule: "evenodd", clipRule: "evenodd" }) }) }),
|
|
2559
2900
|
/* @__PURE__ */ jsx5(
|
|
@@ -2970,7 +3311,6 @@ function SettingsSection() {
|
|
|
2970
3311
|
/* @__PURE__ */ jsx5("div", { className: "px-6 py-4 border-b border-slate-100 bg-slate-50/50", children: /* @__PURE__ */ jsx5("h3", { className: "font-bold text-slate-800", children: "Configuration Snapshot" }) }),
|
|
2971
3312
|
/* @__PURE__ */ jsxs4("dl", { className: "divide-y divide-slate-100 text-sm", children: [
|
|
2972
3313
|
/* @__PURE__ */ jsx5(Row, { label: "Site Name", value: ctx.config.siteName ?? "\u2014" }),
|
|
2973
|
-
/* @__PURE__ */ jsx5(Row, { label: "Active Storage Adapter", value: ctx.adapter.name, highlight: true }),
|
|
2974
3314
|
/* @__PURE__ */ jsx5(Row, { label: "Registered Pages", value: String(ctx.config.pages.length) }),
|
|
2975
3315
|
/* @__PURE__ */ jsx5(
|
|
2976
3316
|
Row,
|
|
@@ -3115,7 +3455,7 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
3115
3455
|
]
|
|
3116
3456
|
}
|
|
3117
3457
|
),
|
|
3118
|
-
open && /* @__PURE__ */ jsxs4(
|
|
3458
|
+
open && /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
3119
3459
|
/* @__PURE__ */ jsx5("div", { className: "fixed inset-0 z-[100]", onClick: () => setOpen(false) }),
|
|
3120
3460
|
/* @__PURE__ */ jsxs4("div", { className: "absolute z-[101] mt-1 w-full rounded-xl border border-slate-200 bg-white shadow-2xl max-h-72 flex flex-col overflow-hidden animate-in fade-in slide-in-from-top-1 duration-150", children: [
|
|
3121
3461
|
/* @__PURE__ */ jsxs4("div", { className: "p-2 border-b border-slate-100 flex items-center gap-2", children: [
|
|
@@ -3199,49 +3539,802 @@ function PasswordField({ value, onChange }) {
|
|
|
3199
3539
|
)
|
|
3200
3540
|
] });
|
|
3201
3541
|
}
|
|
3202
|
-
function
|
|
3542
|
+
function FormattedNumberInput({
|
|
3543
|
+
value,
|
|
3544
|
+
onChange,
|
|
3545
|
+
isPrice = false,
|
|
3546
|
+
isPercent = false,
|
|
3547
|
+
allowEmpty = false,
|
|
3548
|
+
placeholder = "0",
|
|
3549
|
+
className = "",
|
|
3550
|
+
containerClassName = "w-full"
|
|
3551
|
+
}) {
|
|
3552
|
+
const formatWithDots = (num) => {
|
|
3553
|
+
if (num === void 0 || num === null || num === "") return "";
|
|
3554
|
+
const cleanDigits = String(num).replace(/\D/g, "");
|
|
3555
|
+
if (!cleanDigits) return "";
|
|
3556
|
+
return cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
3557
|
+
};
|
|
3558
|
+
const [displayVal, setDisplayVal] = useState5(() => formatWithDots(value));
|
|
3559
|
+
useEffect4(() => {
|
|
3560
|
+
setDisplayVal(formatWithDots(value));
|
|
3561
|
+
}, [value]);
|
|
3562
|
+
const handleChange = (e) => {
|
|
3563
|
+
const rawText = e.target.value;
|
|
3564
|
+
const cleanDigits = rawText.replace(/\D/g, "");
|
|
3565
|
+
if (!cleanDigits) {
|
|
3566
|
+
setDisplayVal("");
|
|
3567
|
+
onChange(allowEmpty ? null : 0);
|
|
3568
|
+
return;
|
|
3569
|
+
}
|
|
3570
|
+
const parsed = Number(cleanDigits);
|
|
3571
|
+
if (isPercent && parsed > 100) {
|
|
3572
|
+
setDisplayVal("100");
|
|
3573
|
+
onChange(100);
|
|
3574
|
+
return;
|
|
3575
|
+
}
|
|
3576
|
+
const formatted = isPercent ? cleanDigits : cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
3577
|
+
setDisplayVal(formatted);
|
|
3578
|
+
onChange(parsed);
|
|
3579
|
+
};
|
|
3580
|
+
return /* @__PURE__ */ jsxs4("div", { className: `relative flex items-center ${containerClassName}`, children: [
|
|
3581
|
+
isPrice && /* @__PURE__ */ jsx5("span", { className: "absolute left-3.5 text-sm font-bold text-slate-400 pointer-events-none select-none", children: "$" }),
|
|
3582
|
+
isPercent && /* @__PURE__ */ jsx5("span", { className: "absolute right-3.5 text-sm font-bold text-slate-400 pointer-events-none select-none", children: "%" }),
|
|
3583
|
+
/* @__PURE__ */ jsx5(
|
|
3584
|
+
"input",
|
|
3585
|
+
{
|
|
3586
|
+
type: "text",
|
|
3587
|
+
inputMode: "numeric",
|
|
3588
|
+
pattern: "[0-9.]*",
|
|
3589
|
+
autoComplete: "off",
|
|
3590
|
+
value: displayVal,
|
|
3591
|
+
onChange: handleChange,
|
|
3592
|
+
placeholder,
|
|
3593
|
+
"aria-valuemin": isPercent ? 0 : void 0,
|
|
3594
|
+
"aria-valuemax": isPercent ? 100 : void 0,
|
|
3595
|
+
className: `w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm font-medium text-slate-800 shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all ${isPrice ? "pl-8" : ""} ${isPercent ? "pr-8" : ""} ${className}`
|
|
3596
|
+
}
|
|
3597
|
+
)
|
|
3598
|
+
] });
|
|
3599
|
+
}
|
|
3600
|
+
function BranchSettingsEditor({
|
|
3601
|
+
collectionId,
|
|
3602
|
+
value,
|
|
3603
|
+
globalPrice,
|
|
3604
|
+
globalDiscount,
|
|
3605
|
+
onChange
|
|
3606
|
+
}) {
|
|
3607
|
+
const ctx = useCmsContext();
|
|
3608
|
+
const [branches, setBranches] = useState5([]);
|
|
3609
|
+
const [loading, setLoading] = useState5(true);
|
|
3610
|
+
const [loadError, setLoadError] = useState5("");
|
|
3611
|
+
const settings = value && typeof value === "object" ? value : {};
|
|
3612
|
+
const selectedBranches = Array.isArray(settings.branches) ? settings.branches.map(String) : [];
|
|
3613
|
+
const prices = settings.prices && typeof settings.prices === "object" ? settings.prices : {};
|
|
3614
|
+
const selectedPriceBranches = [
|
|
3615
|
+
.../* @__PURE__ */ new Set([
|
|
3616
|
+
...Array.isArray(settings.priceBranches) ? settings.priceBranches.map(String) : [],
|
|
3617
|
+
...Object.keys(prices)
|
|
3618
|
+
])
|
|
3619
|
+
];
|
|
3620
|
+
const discounts = settings.discounts && typeof settings.discounts === "object" ? settings.discounts : {};
|
|
3621
|
+
const selectedDiscountBranches = [
|
|
3622
|
+
.../* @__PURE__ */ new Set([
|
|
3623
|
+
...Array.isArray(settings.discountBranches) ? settings.discountBranches.map(String) : [],
|
|
3624
|
+
...Object.keys(discounts)
|
|
3625
|
+
])
|
|
3626
|
+
];
|
|
3627
|
+
const branchAvailability = settings.branchAvailability && typeof settings.branchAvailability === "object" ? settings.branchAvailability : {};
|
|
3628
|
+
const selectedAvailabilityBranches = Object.keys(branchAvailability);
|
|
3629
|
+
const allBranches = settings.allBranches !== false;
|
|
3630
|
+
const useBranchPricing = settings.useBranchPricing === true;
|
|
3631
|
+
const useBranchDiscounts = settings.useBranchDiscounts === true;
|
|
3632
|
+
useEffect4(() => {
|
|
3633
|
+
let active = true;
|
|
3634
|
+
setLoading(true);
|
|
3635
|
+
setLoadError("");
|
|
3636
|
+
ctx.adapter.listEntries(collectionId).then((entries) => {
|
|
3637
|
+
if (active) setBranches(entries);
|
|
3638
|
+
}).catch((error) => {
|
|
3639
|
+
console.error("Could not load branches for product settings:", error);
|
|
3640
|
+
if (active) setLoadError("No se pudieron cargar las sedes.");
|
|
3641
|
+
}).finally(() => {
|
|
3642
|
+
if (active) setLoading(false);
|
|
3643
|
+
});
|
|
3644
|
+
return () => {
|
|
3645
|
+
active = false;
|
|
3646
|
+
};
|
|
3647
|
+
}, [collectionId, ctx.adapter]);
|
|
3648
|
+
const getBranchName = (branch) => String(branch.name || branch.id);
|
|
3649
|
+
const updateSettings = (patch) => {
|
|
3650
|
+
onChange({
|
|
3651
|
+
allBranches,
|
|
3652
|
+
branches: selectedBranches,
|
|
3653
|
+
useBranchPricing,
|
|
3654
|
+
priceBranches: selectedPriceBranches,
|
|
3655
|
+
prices: { ...prices },
|
|
3656
|
+
useBranchDiscounts,
|
|
3657
|
+
discountBranches: selectedDiscountBranches,
|
|
3658
|
+
discounts: { ...discounts },
|
|
3659
|
+
branchAvailability: { ...branchAvailability },
|
|
3660
|
+
...patch
|
|
3661
|
+
});
|
|
3662
|
+
};
|
|
3663
|
+
const updateBranchAvailability = (name, start, end) => {
|
|
3664
|
+
updateSettings({
|
|
3665
|
+
branchAvailability: {
|
|
3666
|
+
...branchAvailability,
|
|
3667
|
+
[name]: {
|
|
3668
|
+
start: toStoredTime(start),
|
|
3669
|
+
end: toStoredTime(end)
|
|
3670
|
+
}
|
|
3671
|
+
}
|
|
3672
|
+
});
|
|
3673
|
+
};
|
|
3674
|
+
const updateBranchPrice = (name, value2) => {
|
|
3675
|
+
const nextPrices = { ...prices };
|
|
3676
|
+
if (value2.trim() === "") {
|
|
3677
|
+
delete nextPrices[name];
|
|
3678
|
+
} else {
|
|
3679
|
+
const parsed = Number(value2);
|
|
3680
|
+
if (Number.isFinite(parsed) && parsed >= 0) nextPrices[name] = parsed;
|
|
3681
|
+
}
|
|
3682
|
+
updateSettings({ prices: nextPrices });
|
|
3683
|
+
};
|
|
3684
|
+
const updateBranchDiscount = (name, value2) => {
|
|
3685
|
+
const nextDiscounts = { ...discounts };
|
|
3686
|
+
if (value2.trim() === "") {
|
|
3687
|
+
delete nextDiscounts[name];
|
|
3688
|
+
} else {
|
|
3689
|
+
const parsed = Number(value2);
|
|
3690
|
+
if (Number.isFinite(parsed) && parsed >= 0 && parsed <= 100) {
|
|
3691
|
+
nextDiscounts[name] = parsed;
|
|
3692
|
+
}
|
|
3693
|
+
}
|
|
3694
|
+
updateSettings({ discounts: nextDiscounts });
|
|
3695
|
+
};
|
|
3696
|
+
return /* @__PURE__ */ jsxs4("div", { className: "space-y-4 rounded-xl border border-slate-200 bg-slate-50/50 p-4", children: [
|
|
3697
|
+
/* @__PURE__ */ jsxs4("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
3698
|
+
/* @__PURE__ */ jsx5(
|
|
3699
|
+
"input",
|
|
3700
|
+
{
|
|
3701
|
+
type: "checkbox",
|
|
3702
|
+
checked: allBranches,
|
|
3703
|
+
onChange: (event) => updateSettings({ allBranches: event.target.checked }),
|
|
3704
|
+
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
3705
|
+
}
|
|
3706
|
+
),
|
|
3707
|
+
/* @__PURE__ */ jsxs4("span", { children: [
|
|
3708
|
+
/* @__PURE__ */ jsx5("span", { className: "block font-semibold", children: "Disponible en todas las sedes" }),
|
|
3709
|
+
/* @__PURE__ */ jsx5("span", { className: "mt-0.5 block text-xs text-slate-500", children: "Desactiva esta opci\xF3n para elegir una o varias sedes." })
|
|
3710
|
+
] })
|
|
3711
|
+
] }),
|
|
3712
|
+
!allBranches && /* @__PURE__ */ jsx5(
|
|
3713
|
+
SearchableMultiSelect,
|
|
3714
|
+
{
|
|
3715
|
+
options: branches.map((branch) => ({
|
|
3716
|
+
value: getBranchName(branch),
|
|
3717
|
+
label: getBranchName(branch)
|
|
3718
|
+
})),
|
|
3719
|
+
value: selectedBranches,
|
|
3720
|
+
onChange: (next) => updateSettings({ branches: next }),
|
|
3721
|
+
loading,
|
|
3722
|
+
error: loadError,
|
|
3723
|
+
placeholder: "Seleccionar sedes...",
|
|
3724
|
+
searchPlaceholder: "Buscar sede...",
|
|
3725
|
+
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3726
|
+
}
|
|
3727
|
+
),
|
|
3728
|
+
/* @__PURE__ */ jsxs4("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
3729
|
+
/* @__PURE__ */ jsx5("p", { className: "text-sm font-semibold text-slate-700", children: "Horario diferente por sede (opcional)" }),
|
|
3730
|
+
/* @__PURE__ */ jsx5("p", { className: "mt-1 text-xs text-slate-500", children: "Deja ambas horas vac\xEDas para heredar el horario general. Si defines una hora, el horario de esa sede reemplaza por completo al general." }),
|
|
3731
|
+
/* @__PURE__ */ jsx5("div", { className: "mt-3", children: /* @__PURE__ */ jsx5(
|
|
3732
|
+
SearchableMultiSelect,
|
|
3733
|
+
{
|
|
3734
|
+
options: branches.map((branch) => ({
|
|
3735
|
+
value: getBranchName(branch),
|
|
3736
|
+
label: getBranchName(branch)
|
|
3737
|
+
})),
|
|
3738
|
+
value: selectedAvailabilityBranches,
|
|
3739
|
+
onChange: (next) => {
|
|
3740
|
+
const nextSchedules = Object.fromEntries(
|
|
3741
|
+
next.map((name) => [
|
|
3742
|
+
name,
|
|
3743
|
+
branchAvailability[name] ?? { start: "", end: "" }
|
|
3744
|
+
])
|
|
3745
|
+
);
|
|
3746
|
+
updateSettings({ branchAvailability: nextSchedules });
|
|
3747
|
+
},
|
|
3748
|
+
loading,
|
|
3749
|
+
error: loadError,
|
|
3750
|
+
placeholder: "Buscar sedes para configurar su horario...",
|
|
3751
|
+
searchPlaceholder: "Buscar sede...",
|
|
3752
|
+
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3753
|
+
}
|
|
3754
|
+
) }),
|
|
3755
|
+
/* @__PURE__ */ jsx5("div", { className: "mt-3 space-y-2", children: branches.filter(
|
|
3756
|
+
(branch) => selectedAvailabilityBranches.includes(getBranchName(branch))
|
|
3757
|
+
).map((branch) => {
|
|
3758
|
+
const name = getBranchName(branch);
|
|
3759
|
+
const schedule = branchAvailability[name] ?? {};
|
|
3760
|
+
return /* @__PURE__ */ jsxs4(
|
|
3761
|
+
"div",
|
|
3762
|
+
{
|
|
3763
|
+
className: "space-y-3 rounded-lg border border-slate-200 bg-white p-3",
|
|
3764
|
+
children: [
|
|
3765
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
3766
|
+
/* @__PURE__ */ jsx5("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
3767
|
+
/* @__PURE__ */ jsx5(
|
|
3768
|
+
"button",
|
|
3769
|
+
{
|
|
3770
|
+
type: "button",
|
|
3771
|
+
onClick: () => {
|
|
3772
|
+
const nextSchedules = { ...branchAvailability };
|
|
3773
|
+
delete nextSchedules[name];
|
|
3774
|
+
updateSettings({ branchAvailability: nextSchedules });
|
|
3775
|
+
},
|
|
3776
|
+
"aria-label": `Quitar horario de ${name}`,
|
|
3777
|
+
title: `Quitar horario de ${name}`,
|
|
3778
|
+
className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
|
|
3779
|
+
children: /* @__PURE__ */ jsx5(X, { className: "h-4 w-4" })
|
|
3780
|
+
}
|
|
3781
|
+
)
|
|
3782
|
+
] }),
|
|
3783
|
+
/* @__PURE__ */ jsx5(
|
|
3784
|
+
AdminTimeRangePicker,
|
|
3785
|
+
{
|
|
3786
|
+
value: [
|
|
3787
|
+
toDayjsTime(schedule.start),
|
|
3788
|
+
toDayjsTime(schedule.end)
|
|
3789
|
+
],
|
|
3790
|
+
onChange: (times) => updateBranchAvailability(
|
|
3791
|
+
name,
|
|
3792
|
+
times?.[0] ?? null,
|
|
3793
|
+
times?.[1] ?? null
|
|
3794
|
+
),
|
|
3795
|
+
allowEmpty: [true, true],
|
|
3796
|
+
className: "w-full",
|
|
3797
|
+
format: TIME_DISPLAY_FORMAT,
|
|
3798
|
+
order: false,
|
|
3799
|
+
placeholder: ["Hora de inicio", "Hora de cierre"],
|
|
3800
|
+
use12Hours: true
|
|
3801
|
+
}
|
|
3802
|
+
)
|
|
3803
|
+
]
|
|
3804
|
+
},
|
|
3805
|
+
branch.id
|
|
3806
|
+
);
|
|
3807
|
+
}) })
|
|
3808
|
+
] }),
|
|
3809
|
+
/* @__PURE__ */ jsxs4("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
3810
|
+
/* @__PURE__ */ jsxs4("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
3811
|
+
/* @__PURE__ */ jsx5(
|
|
3812
|
+
"input",
|
|
3813
|
+
{
|
|
3814
|
+
type: "checkbox",
|
|
3815
|
+
checked: useBranchPricing,
|
|
3816
|
+
onChange: (event) => updateSettings({ useBranchPricing: event.target.checked }),
|
|
3817
|
+
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
3818
|
+
}
|
|
3819
|
+
),
|
|
3820
|
+
/* @__PURE__ */ jsxs4("span", { children: [
|
|
3821
|
+
/* @__PURE__ */ jsx5("span", { className: "block font-semibold", children: "Usar precio diferente por sede" }),
|
|
3822
|
+
/* @__PURE__ */ jsx5("span", { className: "mt-0.5 block text-xs text-slate-500", children: "El precio global se usa como base; deja una sede vac\xEDa para conservarlo." })
|
|
3823
|
+
] })
|
|
3824
|
+
] }),
|
|
3825
|
+
useBranchPricing && /* @__PURE__ */ jsx5("div", { className: "mt-3 space-y-2", children: loading ? /* @__PURE__ */ jsx5("p", { className: "py-2 text-center text-xs text-slate-400", children: "Cargando sedes..." }) : loadError ? /* @__PURE__ */ jsx5("p", { role: "alert", className: "py-2 text-center text-xs text-red-600", children: loadError }) : branches.length === 0 ? /* @__PURE__ */ jsx5("p", { className: "py-2 text-center text-xs text-slate-400", children: "Agrega sedes a la colecci\xF3n antes de definir precios." }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
3826
|
+
/* @__PURE__ */ jsxs4("p", { className: "text-xs text-slate-500", children: [
|
|
3827
|
+
"Precio global actual: $",
|
|
3828
|
+
globalPrice.toLocaleString("es-CO")
|
|
3829
|
+
] }),
|
|
3830
|
+
/* @__PURE__ */ jsx5(
|
|
3831
|
+
SearchableMultiSelect,
|
|
3832
|
+
{
|
|
3833
|
+
options: branches.map((branch) => ({
|
|
3834
|
+
value: getBranchName(branch),
|
|
3835
|
+
label: getBranchName(branch)
|
|
3836
|
+
})),
|
|
3837
|
+
value: selectedPriceBranches,
|
|
3838
|
+
onChange: (next) => {
|
|
3839
|
+
const removed = selectedPriceBranches.filter(
|
|
3840
|
+
(name) => !next.includes(name)
|
|
3841
|
+
);
|
|
3842
|
+
const nextPrices = { ...prices };
|
|
3843
|
+
removed.forEach((name) => delete nextPrices[name]);
|
|
3844
|
+
updateSettings({
|
|
3845
|
+
priceBranches: next,
|
|
3846
|
+
prices: nextPrices
|
|
3847
|
+
});
|
|
3848
|
+
},
|
|
3849
|
+
loading,
|
|
3850
|
+
error: loadError,
|
|
3851
|
+
placeholder: "Buscar y agregar sedes...",
|
|
3852
|
+
searchPlaceholder: "Buscar sede...",
|
|
3853
|
+
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3854
|
+
}
|
|
3855
|
+
),
|
|
3856
|
+
branches.filter(
|
|
3857
|
+
(branch) => selectedPriceBranches.includes(getBranchName(branch))
|
|
3858
|
+
).map((branch) => {
|
|
3859
|
+
const name = getBranchName(branch);
|
|
3860
|
+
return /* @__PURE__ */ jsxs4(
|
|
3861
|
+
"div",
|
|
3862
|
+
{
|
|
3863
|
+
className: "space-y-2 rounded-lg border border-slate-200 bg-white p-3",
|
|
3864
|
+
children: [
|
|
3865
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
3866
|
+
/* @__PURE__ */ jsx5("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
3867
|
+
/* @__PURE__ */ jsx5(
|
|
3868
|
+
"button",
|
|
3869
|
+
{
|
|
3870
|
+
type: "button",
|
|
3871
|
+
onClick: () => {
|
|
3872
|
+
const nextPrices = { ...prices };
|
|
3873
|
+
delete nextPrices[name];
|
|
3874
|
+
updateSettings({
|
|
3875
|
+
priceBranches: selectedPriceBranches.filter(
|
|
3876
|
+
(selected) => selected !== name
|
|
3877
|
+
),
|
|
3878
|
+
prices: nextPrices
|
|
3879
|
+
});
|
|
3880
|
+
},
|
|
3881
|
+
"aria-label": `Quitar ${name} de precios por sede`,
|
|
3882
|
+
title: `Quitar ${name}`,
|
|
3883
|
+
className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
|
|
3884
|
+
children: /* @__PURE__ */ jsx5(X, { className: "h-4 w-4" })
|
|
3885
|
+
}
|
|
3886
|
+
)
|
|
3887
|
+
] }),
|
|
3888
|
+
/* @__PURE__ */ jsxs4("label", { className: "block w-full", children: [
|
|
3889
|
+
/* @__PURE__ */ jsxs4("span", { className: "sr-only", children: [
|
|
3890
|
+
"Precio para ",
|
|
3891
|
+
name
|
|
3892
|
+
] }),
|
|
3893
|
+
/* @__PURE__ */ jsx5(
|
|
3894
|
+
FormattedNumberInput,
|
|
3895
|
+
{
|
|
3896
|
+
value: prices[name] ?? "",
|
|
3897
|
+
onChange: (price) => updateBranchPrice(
|
|
3898
|
+
name,
|
|
3899
|
+
price === null ? "" : String(price)
|
|
3900
|
+
),
|
|
3901
|
+
isPrice: true,
|
|
3902
|
+
allowEmpty: true,
|
|
3903
|
+
placeholder: String(globalPrice),
|
|
3904
|
+
className: "bg-white text-right",
|
|
3905
|
+
containerClassName: "w-full"
|
|
3906
|
+
}
|
|
3907
|
+
)
|
|
3908
|
+
] })
|
|
3909
|
+
]
|
|
3910
|
+
},
|
|
3911
|
+
branch.id
|
|
3912
|
+
);
|
|
3913
|
+
})
|
|
3914
|
+
] }) })
|
|
3915
|
+
] }),
|
|
3916
|
+
/* @__PURE__ */ jsxs4("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
3917
|
+
/* @__PURE__ */ jsxs4("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
3918
|
+
/* @__PURE__ */ jsx5(
|
|
3919
|
+
"input",
|
|
3920
|
+
{
|
|
3921
|
+
type: "checkbox",
|
|
3922
|
+
checked: useBranchDiscounts,
|
|
3923
|
+
onChange: (event) => updateSettings({ useBranchDiscounts: event.target.checked }),
|
|
3924
|
+
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
3925
|
+
}
|
|
3926
|
+
),
|
|
3927
|
+
/* @__PURE__ */ jsxs4("span", { children: [
|
|
3928
|
+
/* @__PURE__ */ jsx5("span", { className: "block font-semibold", children: "Usar descuento diferente por sede" }),
|
|
3929
|
+
/* @__PURE__ */ jsx5("span", { className: "mt-0.5 block text-xs text-slate-500", children: "El descuento global aplica como base; una sede vac\xEDa hereda ese porcentaje." })
|
|
3930
|
+
] })
|
|
3931
|
+
] }),
|
|
3932
|
+
useBranchDiscounts && /* @__PURE__ */ jsx5("div", { className: "mt-3 space-y-2", children: loading ? /* @__PURE__ */ jsx5("p", { className: "py-2 text-center text-xs text-slate-400", children: "Cargando sedes..." }) : loadError ? /* @__PURE__ */ jsx5("p", { role: "alert", className: "py-2 text-center text-xs text-red-600", children: loadError }) : branches.length === 0 ? /* @__PURE__ */ jsx5("p", { className: "py-2 text-center text-xs text-slate-400", children: "Agrega sedes a la colecci\xF3n antes de definir descuentos." }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
3933
|
+
/* @__PURE__ */ jsxs4("p", { className: "text-xs text-slate-500", children: [
|
|
3934
|
+
"Descuento global actual: ",
|
|
3935
|
+
globalDiscount,
|
|
3936
|
+
"%"
|
|
3937
|
+
] }),
|
|
3938
|
+
/* @__PURE__ */ jsx5(
|
|
3939
|
+
SearchableMultiSelect,
|
|
3940
|
+
{
|
|
3941
|
+
options: branches.map((branch) => ({
|
|
3942
|
+
value: getBranchName(branch),
|
|
3943
|
+
label: getBranchName(branch)
|
|
3944
|
+
})),
|
|
3945
|
+
value: selectedDiscountBranches,
|
|
3946
|
+
onChange: (next) => {
|
|
3947
|
+
const removed = selectedDiscountBranches.filter(
|
|
3948
|
+
(name) => !next.includes(name)
|
|
3949
|
+
);
|
|
3950
|
+
const nextDiscounts = { ...discounts };
|
|
3951
|
+
removed.forEach((name) => delete nextDiscounts[name]);
|
|
3952
|
+
updateSettings({
|
|
3953
|
+
discountBranches: next,
|
|
3954
|
+
discounts: nextDiscounts
|
|
3955
|
+
});
|
|
3956
|
+
},
|
|
3957
|
+
loading,
|
|
3958
|
+
error: loadError,
|
|
3959
|
+
placeholder: "Buscar y agregar sedes...",
|
|
3960
|
+
searchPlaceholder: "Buscar sede...",
|
|
3961
|
+
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3962
|
+
}
|
|
3963
|
+
),
|
|
3964
|
+
branches.filter(
|
|
3965
|
+
(branch) => selectedDiscountBranches.includes(getBranchName(branch))
|
|
3966
|
+
).map((branch) => {
|
|
3967
|
+
const name = getBranchName(branch);
|
|
3968
|
+
return /* @__PURE__ */ jsxs4(
|
|
3969
|
+
"div",
|
|
3970
|
+
{
|
|
3971
|
+
className: "space-y-2 rounded-lg border border-slate-200 bg-white p-3",
|
|
3972
|
+
children: [
|
|
3973
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
3974
|
+
/* @__PURE__ */ jsx5("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
3975
|
+
/* @__PURE__ */ jsx5(
|
|
3976
|
+
"button",
|
|
3977
|
+
{
|
|
3978
|
+
type: "button",
|
|
3979
|
+
onClick: () => {
|
|
3980
|
+
const nextDiscounts = { ...discounts };
|
|
3981
|
+
delete nextDiscounts[name];
|
|
3982
|
+
updateSettings({
|
|
3983
|
+
discountBranches: selectedDiscountBranches.filter(
|
|
3984
|
+
(selected) => selected !== name
|
|
3985
|
+
),
|
|
3986
|
+
discounts: nextDiscounts
|
|
3987
|
+
});
|
|
3988
|
+
},
|
|
3989
|
+
"aria-label": `Quitar descuento de ${name}`,
|
|
3990
|
+
title: `Quitar ${name}`,
|
|
3991
|
+
className: "inline-flex h-9 w-9 shrink-0 items-center justify-center rounded-lg border border-slate-200 text-slate-500 transition-colors hover:border-red-200 hover:bg-red-50 hover:text-red-700",
|
|
3992
|
+
children: /* @__PURE__ */ jsx5(X, { className: "h-4 w-4" })
|
|
3993
|
+
}
|
|
3994
|
+
)
|
|
3995
|
+
] }),
|
|
3996
|
+
/* @__PURE__ */ jsxs4("label", { className: "block w-full", children: [
|
|
3997
|
+
/* @__PURE__ */ jsxs4("span", { className: "sr-only", children: [
|
|
3998
|
+
"Descuento para ",
|
|
3999
|
+
name
|
|
4000
|
+
] }),
|
|
4001
|
+
/* @__PURE__ */ jsx5(
|
|
4002
|
+
FormattedNumberInput,
|
|
4003
|
+
{
|
|
4004
|
+
value: discounts[name] ?? "",
|
|
4005
|
+
onChange: (discount) => updateBranchDiscount(
|
|
4006
|
+
name,
|
|
4007
|
+
discount === null ? "" : String(discount)
|
|
4008
|
+
),
|
|
4009
|
+
isPercent: true,
|
|
4010
|
+
allowEmpty: true,
|
|
4011
|
+
placeholder: String(globalDiscount),
|
|
4012
|
+
className: "bg-white text-right",
|
|
4013
|
+
containerClassName: "w-full"
|
|
4014
|
+
}
|
|
4015
|
+
)
|
|
4016
|
+
] })
|
|
4017
|
+
]
|
|
4018
|
+
},
|
|
4019
|
+
branch.id
|
|
4020
|
+
);
|
|
4021
|
+
})
|
|
4022
|
+
] }) })
|
|
4023
|
+
] })
|
|
4024
|
+
] });
|
|
4025
|
+
}
|
|
4026
|
+
function BranchSettingsSummary({ value }) {
|
|
4027
|
+
if (!value || typeof value !== "object") return /* @__PURE__ */ jsx5("span", { children: "Todas las sedes" });
|
|
4028
|
+
const settings = value;
|
|
4029
|
+
const names = Array.isArray(settings.branches) ? settings.branches : [];
|
|
4030
|
+
const locationSummary = settings.allBranches === false ? names.length > 0 ? names.join(", ") : "Sin sedes" : "Todas las sedes";
|
|
4031
|
+
const pricingSummary = settings.useBranchPricing ? " \xB7 Precio por sede" : " \xB7 Precio global";
|
|
4032
|
+
return /* @__PURE__ */ jsx5("span", { children: locationSummary + pricingSummary });
|
|
4033
|
+
}
|
|
4034
|
+
function SearchableMultiSelect({
|
|
4035
|
+
options,
|
|
4036
|
+
value,
|
|
4037
|
+
onChange,
|
|
4038
|
+
placeholder,
|
|
4039
|
+
searchable = true,
|
|
4040
|
+
searchPlaceholder = "Buscar...",
|
|
4041
|
+
emptyMessage = "No hay opciones registradas todav\xEDa.",
|
|
4042
|
+
loading = false,
|
|
4043
|
+
error,
|
|
4044
|
+
max
|
|
4045
|
+
}) {
|
|
4046
|
+
const [open, setOpen] = useState5(false);
|
|
4047
|
+
const [search, setSearch] = useState5("");
|
|
4048
|
+
const rootRef = useRef2(null);
|
|
4049
|
+
useEffect4(() => {
|
|
4050
|
+
if (!open) return;
|
|
4051
|
+
const handlePointerDown = (event) => {
|
|
4052
|
+
if (event.target instanceof Node && !rootRef.current?.contains(event.target)) {
|
|
4053
|
+
setOpen(false);
|
|
4054
|
+
}
|
|
4055
|
+
};
|
|
4056
|
+
const handleKeyDown = (event) => {
|
|
4057
|
+
if (event.key === "Escape") setOpen(false);
|
|
4058
|
+
};
|
|
4059
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
4060
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
4061
|
+
return () => {
|
|
4062
|
+
document.removeEventListener("pointerdown", handlePointerDown);
|
|
4063
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
4064
|
+
};
|
|
4065
|
+
}, [open]);
|
|
4066
|
+
const normalize = (text) => text.toLocaleLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
4067
|
+
const normalizedSearch = searchable ? normalize(search.trim()) : "";
|
|
4068
|
+
const visibleOptions = options.filter(
|
|
4069
|
+
(option) => normalize(option.label).includes(normalizedSearch)
|
|
4070
|
+
);
|
|
4071
|
+
const selectedOptions = value.map(
|
|
4072
|
+
(selected) => options.find((option) => option.value === selected) || {
|
|
4073
|
+
value: selected,
|
|
4074
|
+
label: selected
|
|
4075
|
+
}
|
|
4076
|
+
).filter(Boolean);
|
|
4077
|
+
const toggleOption = (optionValue) => {
|
|
4078
|
+
if (value.includes(optionValue)) {
|
|
4079
|
+
onChange(value.filter((selected) => selected !== optionValue));
|
|
4080
|
+
return;
|
|
4081
|
+
}
|
|
4082
|
+
if (!max || value.length < max) {
|
|
4083
|
+
onChange([...value, optionValue]);
|
|
4084
|
+
}
|
|
4085
|
+
};
|
|
4086
|
+
const toggleVisibleOptions = () => {
|
|
4087
|
+
const visibleValues = visibleOptions.map((option) => option.value);
|
|
4088
|
+
const hasUnselected = visibleValues.some(
|
|
4089
|
+
(optionValue) => !value.includes(optionValue)
|
|
4090
|
+
);
|
|
4091
|
+
if (hasUnselected) {
|
|
4092
|
+
const merged = [.../* @__PURE__ */ new Set([...value, ...visibleValues])];
|
|
4093
|
+
onChange(max ? merged.slice(0, max) : merged);
|
|
4094
|
+
} else {
|
|
4095
|
+
onChange(value.filter((selected) => !visibleValues.includes(selected)));
|
|
4096
|
+
}
|
|
4097
|
+
};
|
|
4098
|
+
return /* @__PURE__ */ jsxs4("div", { ref: rootRef, className: "relative", children: [
|
|
4099
|
+
/* @__PURE__ */ jsxs4(
|
|
4100
|
+
"button",
|
|
4101
|
+
{
|
|
4102
|
+
type: "button",
|
|
4103
|
+
"aria-haspopup": "listbox",
|
|
4104
|
+
"aria-expanded": open,
|
|
4105
|
+
onClick: () => setOpen((isOpen) => !isOpen),
|
|
4106
|
+
className: "flex min-h-11 w-full items-center justify-between gap-3 rounded-xl border border-slate-200 bg-white px-3 py-2.5 text-left text-sm shadow-sm transition-colors hover:border-slate-300 focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10",
|
|
4107
|
+
children: [
|
|
4108
|
+
/* @__PURE__ */ jsx5("span", { className: "flex min-w-0 flex-1 flex-wrap items-center gap-1.5", children: selectedOptions.length === 0 ? /* @__PURE__ */ jsx5("span", { className: "text-slate-400", children: placeholder }) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
|
|
4109
|
+
selectedOptions.slice(0, 2).map((option) => /* @__PURE__ */ jsx5(
|
|
4110
|
+
"span",
|
|
4111
|
+
{
|
|
4112
|
+
className: "max-w-full truncate rounded-md bg-indigo-50 px-2 py-1 text-xs font-medium text-indigo-700",
|
|
4113
|
+
children: option.label
|
|
4114
|
+
},
|
|
4115
|
+
option.value
|
|
4116
|
+
)),
|
|
4117
|
+
selectedOptions.length > 2 && /* @__PURE__ */ jsxs4("span", { className: "rounded-md bg-slate-100 px-2 py-1 text-xs font-semibold text-slate-600", children: [
|
|
4118
|
+
"+",
|
|
4119
|
+
selectedOptions.length - 2
|
|
4120
|
+
] })
|
|
4121
|
+
] }) }),
|
|
4122
|
+
/* @__PURE__ */ jsxs4("span", { className: "flex shrink-0 items-center gap-2 text-xs text-slate-400", children: [
|
|
4123
|
+
selectedOptions.length > 0 && /* @__PURE__ */ jsxs4("span", { children: [
|
|
4124
|
+
selectedOptions.length,
|
|
4125
|
+
" seleccionada",
|
|
4126
|
+
selectedOptions.length === 1 ? "" : "s"
|
|
4127
|
+
] }),
|
|
4128
|
+
/* @__PURE__ */ jsx5(
|
|
4129
|
+
ChevronDown,
|
|
4130
|
+
{
|
|
4131
|
+
className: `h-4 w-4 transition-transform ${open ? "rotate-180" : ""}`
|
|
4132
|
+
}
|
|
4133
|
+
)
|
|
4134
|
+
] })
|
|
4135
|
+
]
|
|
4136
|
+
}
|
|
4137
|
+
),
|
|
4138
|
+
open && /* @__PURE__ */ jsxs4("div", { className: "absolute left-0 right-0 top-full z-[70] mt-1 overflow-hidden rounded-xl border border-slate-200 bg-white shadow-xl", children: [
|
|
4139
|
+
/* @__PURE__ */ jsxs4("div", { className: "space-y-2 border-b border-slate-100 p-3", children: [
|
|
4140
|
+
searchable && /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
|
|
4141
|
+
/* @__PURE__ */ jsx5(Search, { className: "pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400" }),
|
|
4142
|
+
/* @__PURE__ */ jsx5(
|
|
4143
|
+
"input",
|
|
4144
|
+
{
|
|
4145
|
+
type: "search",
|
|
4146
|
+
autoFocus: true,
|
|
4147
|
+
value: search,
|
|
4148
|
+
onChange: (event) => setSearch(event.target.value),
|
|
4149
|
+
placeholder: searchPlaceholder,
|
|
4150
|
+
className: "w-full rounded-lg border border-slate-200 bg-white py-2 pl-9 pr-3 text-sm outline-none focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10"
|
|
4151
|
+
}
|
|
4152
|
+
)
|
|
4153
|
+
] }),
|
|
4154
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between gap-2 text-xs", children: [
|
|
4155
|
+
/* @__PURE__ */ jsxs4("span", { className: "font-medium text-slate-500", children: [
|
|
4156
|
+
value.length,
|
|
4157
|
+
" seleccionada",
|
|
4158
|
+
value.length === 1 ? "" : "s",
|
|
4159
|
+
max ? ` \xB7 m\xE1ximo ${max}` : ""
|
|
4160
|
+
] }),
|
|
4161
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
|
|
4162
|
+
/* @__PURE__ */ jsx5(
|
|
4163
|
+
"button",
|
|
4164
|
+
{
|
|
4165
|
+
type: "button",
|
|
4166
|
+
disabled: visibleOptions.length === 0 || loading || !!error,
|
|
4167
|
+
onClick: toggleVisibleOptions,
|
|
4168
|
+
className: "font-semibold text-indigo-600 hover:text-indigo-800 disabled:cursor-not-allowed disabled:text-slate-300",
|
|
4169
|
+
children: visibleOptions.length > 0 && visibleOptions.every((option) => value.includes(option.value)) ? searchable ? "Quitar visibles" : "Quitar todas" : searchable ? "Seleccionar visibles" : "Seleccionar todas"
|
|
4170
|
+
}
|
|
4171
|
+
),
|
|
4172
|
+
/* @__PURE__ */ jsx5("span", { className: "text-slate-300", children: "\xB7" }),
|
|
4173
|
+
/* @__PURE__ */ jsx5(
|
|
4174
|
+
"button",
|
|
4175
|
+
{
|
|
4176
|
+
type: "button",
|
|
4177
|
+
disabled: value.length === 0,
|
|
4178
|
+
onClick: () => onChange([]),
|
|
4179
|
+
className: "font-semibold text-slate-500 hover:text-slate-700 disabled:cursor-not-allowed disabled:text-slate-300",
|
|
4180
|
+
children: "Limpiar"
|
|
4181
|
+
}
|
|
4182
|
+
)
|
|
4183
|
+
] })
|
|
4184
|
+
] })
|
|
4185
|
+
] }),
|
|
4186
|
+
/* @__PURE__ */ jsx5("div", { role: "listbox", "aria-multiselectable": "true", className: "max-h-56 overflow-y-auto p-2", children: loading ? /* @__PURE__ */ jsx5("p", { className: "py-4 text-center text-xs text-slate-400", children: "Cargando opciones..." }) : error ? /* @__PURE__ */ jsx5("p", { role: "alert", className: "py-4 text-center text-xs text-red-600", children: error }) : visibleOptions.length === 0 ? /* @__PURE__ */ jsx5("p", { className: "py-4 text-center text-xs text-slate-400", children: options.length === 0 ? emptyMessage : "No hay resultados para la b\xFAsqueda." }) : /* @__PURE__ */ jsx5("div", { className: "space-y-1", children: visibleOptions.map((option) => {
|
|
4187
|
+
const isSelected = value.includes(option.value);
|
|
4188
|
+
const isAtMax = !!max && value.length >= max && !isSelected;
|
|
4189
|
+
return /* @__PURE__ */ jsxs4(
|
|
4190
|
+
"button",
|
|
4191
|
+
{
|
|
4192
|
+
type: "button",
|
|
4193
|
+
role: "option",
|
|
4194
|
+
"aria-selected": isSelected,
|
|
4195
|
+
disabled: isAtMax,
|
|
4196
|
+
onClick: () => toggleOption(option.value),
|
|
4197
|
+
className: `flex w-full items-center gap-2.5 rounded-lg px-3 py-2.5 text-left text-sm transition-colors ${isSelected ? "bg-indigo-50 font-semibold text-indigo-900" : "text-slate-700 hover:bg-slate-50"} disabled:cursor-not-allowed disabled:opacity-50`,
|
|
4198
|
+
children: [
|
|
4199
|
+
/* @__PURE__ */ jsx5(
|
|
4200
|
+
"span",
|
|
4201
|
+
{
|
|
4202
|
+
className: `flex h-4 w-4 shrink-0 items-center justify-center rounded border ${isSelected ? "border-indigo-600 bg-indigo-600 text-white" : "border-slate-300 bg-white"}`,
|
|
4203
|
+
children: isSelected && /* @__PURE__ */ jsx5(Check, { className: "h-3 w-3" })
|
|
4204
|
+
}
|
|
4205
|
+
),
|
|
4206
|
+
/* @__PURE__ */ jsx5("span", { className: "truncate", children: option.label })
|
|
4207
|
+
]
|
|
4208
|
+
},
|
|
4209
|
+
option.value
|
|
4210
|
+
);
|
|
4211
|
+
}) }) })
|
|
4212
|
+
] })
|
|
4213
|
+
] });
|
|
4214
|
+
}
|
|
4215
|
+
function ReferenceSelect({
|
|
4216
|
+
collectionId,
|
|
4217
|
+
displayField = "name",
|
|
4218
|
+
valueField = "name",
|
|
4219
|
+
fallbackOptions,
|
|
4220
|
+
multiple = false,
|
|
4221
|
+
searchable = false,
|
|
4222
|
+
max,
|
|
4223
|
+
value,
|
|
4224
|
+
onChange
|
|
4225
|
+
}) {
|
|
3203
4226
|
const ctx = useCmsContext();
|
|
3204
4227
|
const [options, setOptions] = useState5([]);
|
|
3205
4228
|
const [loading, setLoading] = useState5(true);
|
|
3206
4229
|
useEffect4(() => {
|
|
3207
4230
|
if (!collectionId) {
|
|
4231
|
+
if (fallbackOptions && fallbackOptions.length > 0) {
|
|
4232
|
+
setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
|
|
4233
|
+
}
|
|
3208
4234
|
setLoading(false);
|
|
3209
4235
|
return;
|
|
3210
4236
|
}
|
|
3211
4237
|
setLoading(true);
|
|
3212
4238
|
ctx.adapter.listEntries(collectionId).then((res) => {
|
|
3213
|
-
|
|
4239
|
+
const fromCollection = res.map((r) => {
|
|
4240
|
+
const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
|
|
4241
|
+
const lab = String(r[displayField] || r.name || r.id);
|
|
4242
|
+
return { value: val, label: lab };
|
|
4243
|
+
});
|
|
4244
|
+
const fallbackList = (fallbackOptions || []).map(
|
|
4245
|
+
(opt) => typeof opt === "string" ? { value: opt, label: opt } : opt
|
|
4246
|
+
);
|
|
4247
|
+
const combined = [...fromCollection];
|
|
4248
|
+
for (const fb of fallbackList) {
|
|
4249
|
+
if (!combined.some((c) => c.value === fb.value || c.label === fb.label)) {
|
|
4250
|
+
combined.push(fb);
|
|
4251
|
+
}
|
|
4252
|
+
}
|
|
4253
|
+
setOptions(combined);
|
|
4254
|
+
setLoading(false);
|
|
4255
|
+
}).catch(() => {
|
|
4256
|
+
if (fallbackOptions && fallbackOptions.length > 0) {
|
|
4257
|
+
setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
|
|
4258
|
+
}
|
|
3214
4259
|
setLoading(false);
|
|
3215
|
-
})
|
|
3216
|
-
}, [collectionId, displayField, ctx.adapter]);
|
|
4260
|
+
});
|
|
4261
|
+
}, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter]);
|
|
4262
|
+
if (multiple) {
|
|
4263
|
+
const selectedList = Array.isArray(value) ? value.map(String) : typeof value === "string" && value.trim() ? value.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
4264
|
+
return /* @__PURE__ */ jsx5(
|
|
4265
|
+
SearchableMultiSelect,
|
|
4266
|
+
{
|
|
4267
|
+
options,
|
|
4268
|
+
value: selectedList,
|
|
4269
|
+
onChange,
|
|
4270
|
+
loading,
|
|
4271
|
+
searchable,
|
|
4272
|
+
placeholder: "Seleccionar opciones...",
|
|
4273
|
+
searchPlaceholder: `Buscar ${collectionId === "sauces" ? "salsa" : collectionId === "extras" ? "adicional" : "opci\xF3n"}...`,
|
|
4274
|
+
emptyMessage: "No hay opciones registradas todav\xEDa.",
|
|
4275
|
+
max
|
|
4276
|
+
}
|
|
4277
|
+
);
|
|
4278
|
+
}
|
|
4279
|
+
const singleVal = String(value ?? "");
|
|
4280
|
+
const displayOptions = [...options];
|
|
4281
|
+
if (singleVal && !displayOptions.some((o) => o.value === singleVal)) {
|
|
4282
|
+
displayOptions.unshift({ value: singleVal, label: singleVal });
|
|
4283
|
+
}
|
|
3217
4284
|
return /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
|
|
3218
4285
|
/* @__PURE__ */ jsxs4(
|
|
3219
4286
|
"select",
|
|
3220
4287
|
{
|
|
3221
|
-
value,
|
|
4288
|
+
value: singleVal,
|
|
3222
4289
|
onChange: (e) => onChange(e.target.value),
|
|
3223
4290
|
className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm shadow-sm focus:border-indigo-500 focus:ring-4 focus:ring-indigo-500/10 transition-all bg-white appearance-none pr-10",
|
|
3224
4291
|
children: [
|
|
3225
|
-
/* @__PURE__ */ jsx5("option", { value: "", children: loading ? "
|
|
3226
|
-
|
|
4292
|
+
/* @__PURE__ */ jsx5("option", { value: "", children: loading ? "Cargando opciones..." : "-- Selecciona una opci\xF3n --" }),
|
|
4293
|
+
displayOptions.map((o, idx) => /* @__PURE__ */ jsx5("option", { value: o.value, children: o.label }, `${o.value}-${idx}`))
|
|
3227
4294
|
]
|
|
3228
4295
|
}
|
|
3229
4296
|
),
|
|
3230
4297
|
/* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
|
|
3231
4298
|
] });
|
|
3232
4299
|
}
|
|
3233
|
-
function ReferenceTableCell({
|
|
4300
|
+
function ReferenceTableCell({
|
|
4301
|
+
collectionId,
|
|
4302
|
+
entryId,
|
|
4303
|
+
displayField = "name",
|
|
4304
|
+
valueField = "name",
|
|
4305
|
+
multiple = false
|
|
4306
|
+
}) {
|
|
3234
4307
|
const ctx = useCmsContext();
|
|
3235
|
-
const [
|
|
4308
|
+
const [labels, setLabels] = useState5([]);
|
|
4309
|
+
const ids = Array.isArray(entryId) ? entryId.map(String) : typeof entryId === "string" && entryId.trim() ? multiple ? entryId.split(",").map((s) => s.trim()).filter(Boolean) : [entryId] : [];
|
|
3236
4310
|
useEffect4(() => {
|
|
3237
|
-
if (!collectionId ||
|
|
4311
|
+
if (!collectionId || ids.length === 0) {
|
|
4312
|
+
setLabels(ids);
|
|
4313
|
+
return;
|
|
4314
|
+
}
|
|
3238
4315
|
ctx.adapter.listEntries(collectionId).then((res) => {
|
|
3239
|
-
const
|
|
3240
|
-
|
|
4316
|
+
const resolved = ids.map((id) => {
|
|
4317
|
+
const match = res.find(
|
|
4318
|
+
(r) => valueField && String(r[valueField]) === id || r.id === id || String(r.name) === id || String(r.slug) === id
|
|
4319
|
+
);
|
|
4320
|
+
return match ? String(match[displayField] || match.name || match.id) : id;
|
|
4321
|
+
});
|
|
4322
|
+
setLabels(resolved);
|
|
3241
4323
|
}).catch(() => {
|
|
4324
|
+
setLabels(ids);
|
|
3242
4325
|
});
|
|
3243
|
-
}, [collectionId,
|
|
3244
|
-
return /* @__PURE__ */ jsx5("span", { children:
|
|
4326
|
+
}, [collectionId, displayField, valueField, JSON.stringify(ids), ctx.adapter]);
|
|
4327
|
+
if (labels.length === 0) return /* @__PURE__ */ jsx5("span", { children: "-" });
|
|
4328
|
+
if (multiple || labels.length > 1) {
|
|
4329
|
+
return /* @__PURE__ */ jsxs4("div", { className: "flex flex-wrap gap-1 max-w-[260px]", children: [
|
|
4330
|
+
labels.slice(0, 3).map((lbl, idx) => /* @__PURE__ */ jsx5("span", { className: "inline-flex px-1.5 py-0.5 rounded bg-slate-100 text-slate-700 text-[11px] font-medium truncate max-w-[120px]", children: lbl }, idx)),
|
|
4331
|
+
labels.length > 3 && /* @__PURE__ */ jsxs4("span", { className: "inline-flex px-1.5 py-0.5 rounded bg-slate-200 text-slate-600 text-[10px] font-bold", children: [
|
|
4332
|
+
"+",
|
|
4333
|
+
labels.length - 3
|
|
4334
|
+
] })
|
|
4335
|
+
] });
|
|
4336
|
+
}
|
|
4337
|
+
return /* @__PURE__ */ jsx5("span", { children: labels[0] });
|
|
3245
4338
|
}
|
|
3246
4339
|
|
|
3247
4340
|
// src/admin/AdminLogin.tsx
|