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.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
9
|
var __export = (target, all) => {
|
|
8
10
|
for (var name in all)
|
|
@@ -16,6 +18,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
18
|
}
|
|
17
19
|
return to;
|
|
18
20
|
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
19
29
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
30
|
|
|
21
31
|
// src/index.ts
|
|
@@ -639,7 +649,17 @@ function EditableLink({
|
|
|
639
649
|
className,
|
|
640
650
|
target
|
|
641
651
|
}) {
|
|
642
|
-
|
|
652
|
+
let defaultText = text ?? "";
|
|
653
|
+
if (!defaultText) {
|
|
654
|
+
if (typeof children === "string") {
|
|
655
|
+
defaultText = children;
|
|
656
|
+
} else if (Array.isArray(children)) {
|
|
657
|
+
const strChild = children.find((c) => typeof c === "string");
|
|
658
|
+
if (typeof strChild === "string") {
|
|
659
|
+
defaultText = strChild.trim();
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
}
|
|
643
663
|
const ctx = useRegister(id, "link", label, section, pageId, { href, text: defaultText });
|
|
644
664
|
const override = ctx?.overrides[id];
|
|
645
665
|
const hrefValue = override?.href ?? href;
|
|
@@ -655,8 +675,34 @@ function EditableLink({
|
|
|
655
675
|
const isExternal = hrefValue.startsWith("http");
|
|
656
676
|
const computedTarget = target || (isExternal ? "_blank" : void 0);
|
|
657
677
|
const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
|
|
658
|
-
|
|
659
|
-
|
|
678
|
+
let content;
|
|
679
|
+
if (typeof children === "function") {
|
|
680
|
+
content = children(textValue);
|
|
681
|
+
} else if (override && typeof override.text === "string" && override.text !== "") {
|
|
682
|
+
if (Array.isArray(children)) {
|
|
683
|
+
let replaced = false;
|
|
684
|
+
content = children.map((c) => {
|
|
685
|
+
if (typeof c === "string" && !replaced) {
|
|
686
|
+
replaced = true;
|
|
687
|
+
return override.text;
|
|
688
|
+
}
|
|
689
|
+
return c;
|
|
690
|
+
});
|
|
691
|
+
} else if ((0, import_react4.isValidElement)(children)) {
|
|
692
|
+
content = /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
|
|
693
|
+
override.text,
|
|
694
|
+
" ",
|
|
695
|
+
children
|
|
696
|
+
] });
|
|
697
|
+
} else {
|
|
698
|
+
content = override.text;
|
|
699
|
+
}
|
|
700
|
+
} else if (typeof children !== "undefined") {
|
|
701
|
+
content = children;
|
|
702
|
+
} else {
|
|
703
|
+
content = textValue;
|
|
704
|
+
}
|
|
705
|
+
const isEmpty = !content || typeof content === "string" && content.trim() === "";
|
|
660
706
|
const renderContent = active && isEmpty ? `[Empty Link: ${label || id}]` : content;
|
|
661
707
|
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
|
662
708
|
"a",
|
|
@@ -781,9 +827,72 @@ function EditableReference({
|
|
|
781
827
|
|
|
782
828
|
// src/admin/AdminApp.tsx
|
|
783
829
|
var import_react5 = require("react");
|
|
830
|
+
var import_antd = require("antd");
|
|
831
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
784
832
|
var import_lucide_react2 = require("lucide-react");
|
|
785
833
|
var import_lucide_react3 = require("lucide-react");
|
|
786
834
|
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
835
|
+
var TIME_STORAGE_FORMAT = "HH:mm";
|
|
836
|
+
var TIME_DISPLAY_FORMAT = "h:mm A";
|
|
837
|
+
var TIME_PICKER_THEME = {
|
|
838
|
+
token: {
|
|
839
|
+
borderRadius: 12,
|
|
840
|
+
colorBgContainer: "#ffffff",
|
|
841
|
+
colorBorder: "#e2e8f0",
|
|
842
|
+
colorPrimary: "#6366f1",
|
|
843
|
+
colorText: "#1e293b",
|
|
844
|
+
colorTextPlaceholder: "#94a3b8",
|
|
845
|
+
controlHeight: 42,
|
|
846
|
+
controlOutline: "rgba(99, 102, 241, 0.1)",
|
|
847
|
+
fontFamily: "inherit",
|
|
848
|
+
fontSize: 14,
|
|
849
|
+
lineWidth: 1
|
|
850
|
+
},
|
|
851
|
+
components: {
|
|
852
|
+
DatePicker: {
|
|
853
|
+
activeBorderColor: "#6366f1",
|
|
854
|
+
activeShadow: "0 0 0 4px rgba(99, 102, 241, 0.1)",
|
|
855
|
+
hoverBg: "#ffffff",
|
|
856
|
+
hoverBorderColor: "#cbd5e1",
|
|
857
|
+
paddingBlock: 9,
|
|
858
|
+
paddingInline: 14
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
};
|
|
862
|
+
function AdminTimeRangePicker(props) {
|
|
863
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd.ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
864
|
+
import_antd.TimePicker.RangePicker,
|
|
865
|
+
{
|
|
866
|
+
...props,
|
|
867
|
+
className: `w-full min-w-0 ${props.className ?? ""}`,
|
|
868
|
+
style: {
|
|
869
|
+
boxShadow: "0 1px 2px rgba(15, 23, 42, 0.08)",
|
|
870
|
+
...props.style
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
) });
|
|
874
|
+
}
|
|
875
|
+
function AdminTimePicker(props) {
|
|
876
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd.ConfigProvider, { theme: TIME_PICKER_THEME, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
877
|
+
import_antd.TimePicker,
|
|
878
|
+
{
|
|
879
|
+
...props,
|
|
880
|
+
className: `w-full min-w-0 ${props.className ?? ""}`,
|
|
881
|
+
style: {
|
|
882
|
+
boxShadow: "0 1px 2px rgba(15, 23, 42, 0.08)",
|
|
883
|
+
...props.style
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
) });
|
|
887
|
+
}
|
|
888
|
+
function toDayjsTime(value) {
|
|
889
|
+
const match = /^([01]\d|2[0-3]):([0-5]\d)$/.exec(String(value ?? ""));
|
|
890
|
+
if (!match) return null;
|
|
891
|
+
return (0, import_dayjs.default)().hour(Number(match[1])).minute(Number(match[2])).second(0).millisecond(0);
|
|
892
|
+
}
|
|
893
|
+
function toStoredTime(value) {
|
|
894
|
+
return value?.format(TIME_STORAGE_FORMAT) ?? "";
|
|
895
|
+
}
|
|
787
896
|
async function handleImageFile(file, onUrl, uploadImage) {
|
|
788
897
|
if (uploadImage) {
|
|
789
898
|
try {
|
|
@@ -798,17 +907,67 @@ async function handleImageFile(file, onUrl, uploadImage) {
|
|
|
798
907
|
reader.onload = (ev) => onUrl(ev.target?.result);
|
|
799
908
|
reader.readAsDataURL(file);
|
|
800
909
|
}
|
|
801
|
-
function
|
|
802
|
-
|
|
803
|
-
|
|
910
|
+
function FilePickerButton({
|
|
911
|
+
accept,
|
|
912
|
+
children,
|
|
913
|
+
className,
|
|
914
|
+
multiple = false,
|
|
915
|
+
onFiles
|
|
916
|
+
}) {
|
|
917
|
+
const inputRef = (0, import_react5.useRef)(null);
|
|
918
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
919
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
920
|
+
"button",
|
|
921
|
+
{
|
|
922
|
+
type: "button",
|
|
923
|
+
onClick: () => inputRef.current?.click(),
|
|
924
|
+
className,
|
|
925
|
+
children
|
|
926
|
+
}
|
|
927
|
+
),
|
|
928
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
929
|
+
"input",
|
|
930
|
+
{
|
|
931
|
+
ref: inputRef,
|
|
932
|
+
type: "file",
|
|
933
|
+
accept,
|
|
934
|
+
multiple,
|
|
935
|
+
className: "hidden",
|
|
936
|
+
onChange: (event) => {
|
|
937
|
+
onFiles(Array.from(event.currentTarget.files ?? []));
|
|
938
|
+
event.currentTarget.value = "";
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
)
|
|
942
|
+
] });
|
|
943
|
+
}
|
|
944
|
+
function AdminApp(props) {
|
|
945
|
+
if (props.projectId) {
|
|
946
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AdminAppContent, { ...props }) });
|
|
804
947
|
}
|
|
805
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AdminAppContent, {});
|
|
948
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AdminAppContent, { ...props });
|
|
806
949
|
}
|
|
807
|
-
function AdminAppContent() {
|
|
808
|
-
const
|
|
950
|
+
function AdminAppContent(props) {
|
|
951
|
+
const ctx = useCmsContext();
|
|
952
|
+
const hasDashboard = Boolean(props.dashboard);
|
|
953
|
+
const [section, setSection] = (0, import_react5.useState)(hasDashboard ? "dashboard" : "pages");
|
|
809
954
|
const [authChecking, setAuthChecking] = (0, import_react5.useState)(true);
|
|
810
955
|
const [authenticated, setAuthenticated] = (0, import_react5.useState)(false);
|
|
811
|
-
const
|
|
956
|
+
const hideSettings = props.hideSettings ?? ctx.config.hideSettings ?? false;
|
|
957
|
+
const hideData = props.hideData ?? ctx.config.hideData ?? false;
|
|
958
|
+
const hideGlobals = props.hideGlobals ?? ctx.config.hideGlobals ?? false;
|
|
959
|
+
const hideConfig = props.hideConfig ?? ctx.config.hideConfig ?? false;
|
|
960
|
+
const menuLabels = {
|
|
961
|
+
dashboard: "Dashboard",
|
|
962
|
+
pages: "P\xE1ginas",
|
|
963
|
+
collections: "Colecciones",
|
|
964
|
+
data: "Datos",
|
|
965
|
+
config: "Configuraci\xF3n",
|
|
966
|
+
settings: "Ajustes",
|
|
967
|
+
subscription: "Suscripci\xF3n",
|
|
968
|
+
...ctx.config.menuLabels,
|
|
969
|
+
...props.menuLabels
|
|
970
|
+
};
|
|
812
971
|
(0, import_react5.useEffect)(() => {
|
|
813
972
|
fetch("/api/admin/auth").then((res) => res.json()).then((data) => {
|
|
814
973
|
if (data && data.authenticated) {
|
|
@@ -858,13 +1017,22 @@ function AdminAppContent() {
|
|
|
858
1017
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "truncate font-bold text-lg text-slate-900", children: ctx.config.siteName ?? "Site Administration" })
|
|
859
1018
|
] }),
|
|
860
1019
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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: [
|
|
1020
|
+
hasDashboard && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1021
|
+
SideItem,
|
|
1022
|
+
{
|
|
1023
|
+
active: section === "dashboard",
|
|
1024
|
+
onClick: () => setSection("dashboard"),
|
|
1025
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react3.BarChart3, { className: "h-4 w-4 shrink-0" }),
|
|
1026
|
+
children: menuLabels.dashboard
|
|
1027
|
+
}
|
|
1028
|
+
),
|
|
861
1029
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
862
1030
|
SideItem,
|
|
863
1031
|
{
|
|
864
1032
|
active: section === "pages",
|
|
865
1033
|
onClick: () => setSection("pages"),
|
|
866
1034
|
icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.FileText, { className: "h-4 w-4 shrink-0" }),
|
|
867
|
-
children:
|
|
1035
|
+
children: menuLabels.pages
|
|
868
1036
|
}
|
|
869
1037
|
),
|
|
870
1038
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
@@ -873,34 +1041,34 @@ function AdminAppContent() {
|
|
|
873
1041
|
active: section === "collections",
|
|
874
1042
|
onClick: () => setSection("collections"),
|
|
875
1043
|
icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Boxes, { className: "h-4 w-4 shrink-0" }),
|
|
876
|
-
children:
|
|
1044
|
+
children: menuLabels.collections
|
|
877
1045
|
}
|
|
878
1046
|
),
|
|
879
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1047
|
+
!hideData && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
880
1048
|
SideItem,
|
|
881
1049
|
{
|
|
882
1050
|
active: section === "submissions",
|
|
883
1051
|
onClick: () => setSection("submissions"),
|
|
884
1052
|
icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Inbox, { className: "h-4 w-4 shrink-0" }),
|
|
885
|
-
children:
|
|
1053
|
+
children: menuLabels.data
|
|
886
1054
|
}
|
|
887
1055
|
),
|
|
888
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1056
|
+
!hideConfig && !hideGlobals && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
889
1057
|
SideItem,
|
|
890
1058
|
{
|
|
891
1059
|
active: section === "config",
|
|
892
1060
|
onClick: () => setSection("config"),
|
|
893
1061
|
icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.SlidersHorizontal, { className: "h-4 w-4 shrink-0" }),
|
|
894
|
-
children:
|
|
1062
|
+
children: menuLabels.config
|
|
895
1063
|
}
|
|
896
1064
|
),
|
|
897
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1065
|
+
!hideSettings && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
898
1066
|
SideItem,
|
|
899
1067
|
{
|
|
900
1068
|
active: section === "settings",
|
|
901
1069
|
onClick: () => setSection("settings"),
|
|
902
1070
|
icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Settings, { className: "h-4 w-4 shrink-0" }),
|
|
903
|
-
children:
|
|
1071
|
+
children: menuLabels.settings
|
|
904
1072
|
}
|
|
905
1073
|
),
|
|
906
1074
|
subscriptionCtx && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
@@ -909,37 +1077,32 @@ function AdminAppContent() {
|
|
|
909
1077
|
active: section === "subscription",
|
|
910
1078
|
onClick: () => setSection("subscription"),
|
|
911
1079
|
icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react3.CreditCard, { className: "h-4 w-4 shrink-0" }),
|
|
912
|
-
children:
|
|
1080
|
+
children: menuLabels.subscription
|
|
913
1081
|
}
|
|
914
1082
|
)
|
|
915
1083
|
] }),
|
|
916
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.LogOut, { className: "w-4 h-4" }),
|
|
931
|
-
"Logout"
|
|
932
|
-
]
|
|
933
|
-
}
|
|
934
|
-
)
|
|
935
|
-
] })
|
|
1084
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "hidden lg:block mt-auto border-t border-slate-200 p-4 bg-slate-50/50", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
1085
|
+
"button",
|
|
1086
|
+
{
|
|
1087
|
+
onClick: async () => {
|
|
1088
|
+
await fetch("/api/admin/auth?action=logout", { method: "POST" });
|
|
1089
|
+
window.location.href = "/admin/login";
|
|
1090
|
+
},
|
|
1091
|
+
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",
|
|
1092
|
+
children: [
|
|
1093
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.LogOut, { className: "w-4 h-4" }),
|
|
1094
|
+
"Logout"
|
|
1095
|
+
]
|
|
1096
|
+
}
|
|
1097
|
+
) })
|
|
936
1098
|
] }),
|
|
937
1099
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("main", { className: "flex-1 overflow-hidden relative flex flex-col", children: [
|
|
1100
|
+
section === "dashboard" && hasDashboard && (typeof props.dashboard === "function" ? (0, import_react5.createElement)(props.dashboard) : props.dashboard),
|
|
938
1101
|
section === "pages" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PagesSection, {}),
|
|
939
1102
|
section === "collections" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CollectionsSection, {}),
|
|
940
|
-
section === "submissions" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubmissionsSection, {}),
|
|
941
|
-
section === "config" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ConfigSection, {}),
|
|
942
|
-
section === "settings" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SettingsSection, {}),
|
|
1103
|
+
!hideData && section === "submissions" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubmissionsSection, {}),
|
|
1104
|
+
!hideConfig && !hideGlobals && section === "config" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ConfigSection, {}),
|
|
1105
|
+
!hideSettings && section === "settings" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SettingsSection, {}),
|
|
943
1106
|
section === "subscription" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SubscriptionPage, {})
|
|
944
1107
|
] })
|
|
945
1108
|
] })
|
|
@@ -1170,7 +1333,8 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
1170
1333
|
ref: iframeRef,
|
|
1171
1334
|
src,
|
|
1172
1335
|
title: page.name,
|
|
1173
|
-
className: "h-full w-full bg-white"
|
|
1336
|
+
className: "h-full w-full bg-white",
|
|
1337
|
+
allow: "autoplay; encrypted-media; fullscreen"
|
|
1174
1338
|
},
|
|
1175
1339
|
src
|
|
1176
1340
|
) }) }),
|
|
@@ -1497,66 +1661,121 @@ function FieldEditor({
|
|
|
1497
1661
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "absolute inset-0 bg-black/40 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-white text-xs font-medium px-2 py-1 bg-black/50 rounded backdrop-blur", children: "Preview" }) })
|
|
1498
1662
|
] }) : null
|
|
1499
1663
|
] }),
|
|
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__ */ (0, import_jsx_runtime5.jsxs)("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",
|
|
1664
|
+
meta.type === "file" && (() => {
|
|
1665
|
+
const currentVal = value ?? meta.defaultValue;
|
|
1666
|
+
const strVal = String(currentVal ?? "");
|
|
1667
|
+
const isVideo = strVal.match(/\.(mp4|webm|ogg|mov)(\?.*)?$/i) || strVal.includes("video");
|
|
1668
|
+
const isImg = strVal.match(/\.(jpe?g|png|webp|avif|gif|svg)(\?.*)?$/i) || strVal.includes("image");
|
|
1669
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
|
|
1670
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
1514
1671
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1515
1672
|
"input",
|
|
1516
1673
|
{
|
|
1517
|
-
type: "
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1674
|
+
type: "url",
|
|
1675
|
+
value: strVal,
|
|
1676
|
+
onChange: (e) => onChange(e.target.value),
|
|
1677
|
+
placeholder: "https://... o subir video/imagen",
|
|
1678
|
+
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"
|
|
1679
|
+
}
|
|
1680
|
+
),
|
|
1681
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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: [
|
|
1682
|
+
"Subir",
|
|
1683
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1684
|
+
"input",
|
|
1685
|
+
{
|
|
1686
|
+
type: "file",
|
|
1687
|
+
accept: "video/*,image/*,application/pdf,.pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
1688
|
+
className: "hidden",
|
|
1689
|
+
onChange: (e) => {
|
|
1690
|
+
const file = e.target.files?.[0];
|
|
1691
|
+
if (file) {
|
|
1692
|
+
void handleImageFile(file, onChange, ctx.uploadImage);
|
|
1693
|
+
}
|
|
1524
1694
|
}
|
|
1525
1695
|
}
|
|
1696
|
+
)
|
|
1697
|
+
] })
|
|
1698
|
+
] }),
|
|
1699
|
+
currentVal ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "space-y-2", children: isVideo ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "rounded-xl border border-slate-200 p-2 bg-slate-900 overflow-hidden shadow-sm", children: [
|
|
1700
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1701
|
+
"video",
|
|
1702
|
+
{
|
|
1703
|
+
src: strVal,
|
|
1704
|
+
controls: true,
|
|
1705
|
+
autoPlay: true,
|
|
1706
|
+
muted: true,
|
|
1707
|
+
loop: true,
|
|
1708
|
+
playsInline: true,
|
|
1709
|
+
className: "max-h-52 w-full object-contain rounded-lg bg-black"
|
|
1710
|
+
},
|
|
1711
|
+
strVal
|
|
1712
|
+
),
|
|
1713
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "text-[10px] text-slate-300 font-mono truncate px-1 pt-1.5 flex items-center gap-1.5", children: [
|
|
1714
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inline-block w-2 h-2 rounded-full bg-emerald-400 animate-pulse" }),
|
|
1715
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "truncate", children: [
|
|
1716
|
+
"\u{1F3AC} ",
|
|
1717
|
+
strVal
|
|
1718
|
+
] })
|
|
1719
|
+
] })
|
|
1720
|
+
] }) : isImg ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "rounded-xl border border-slate-200 p-2 bg-slate-50 overflow-hidden shadow-sm", children: [
|
|
1721
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1722
|
+
"img",
|
|
1723
|
+
{
|
|
1724
|
+
src: strVal,
|
|
1725
|
+
alt: "Preview",
|
|
1726
|
+
className: "max-h-52 w-full object-contain rounded-lg"
|
|
1727
|
+
}
|
|
1728
|
+
),
|
|
1729
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "text-[10px] text-slate-500 font-mono truncate px-1 pt-1.5", children: [
|
|
1730
|
+
"\u{1F5BC}\uFE0F ",
|
|
1731
|
+
strVal
|
|
1732
|
+
] })
|
|
1733
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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: [
|
|
1734
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u{1F4C4} Archivo:" }),
|
|
1735
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "truncate text-indigo-600 font-semibold", children: strVal })
|
|
1736
|
+
] }) }) : null
|
|
1737
|
+
] });
|
|
1738
|
+
})(),
|
|
1739
|
+
meta.type === "link" && (() => {
|
|
1740
|
+
const defaultObj = meta.defaultValue || {};
|
|
1741
|
+
const currentObj = value || {};
|
|
1742
|
+
const currentText = currentObj.text !== void 0 ? currentObj.text : defaultObj.text ?? "";
|
|
1743
|
+
const currentHref = currentObj.href !== void 0 ? currentObj.href : defaultObj.href ?? "";
|
|
1744
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4 bg-slate-50 p-4 rounded-xl border border-slate-100", children: [
|
|
1745
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block", children: [
|
|
1746
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "Texto del Enlace" }),
|
|
1747
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1748
|
+
"input",
|
|
1749
|
+
{
|
|
1750
|
+
value: currentText,
|
|
1751
|
+
onChange: (e) => onChange({
|
|
1752
|
+
...defaultObj,
|
|
1753
|
+
...currentObj,
|
|
1754
|
+
text: e.target.value
|
|
1755
|
+
}),
|
|
1756
|
+
placeholder: "Texto del enlace",
|
|
1757
|
+
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"
|
|
1758
|
+
}
|
|
1759
|
+
)
|
|
1760
|
+
] }),
|
|
1761
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block", children: [
|
|
1762
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "URL de Destino" }),
|
|
1763
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1764
|
+
"input",
|
|
1765
|
+
{
|
|
1766
|
+
value: currentHref,
|
|
1767
|
+
onChange: (e) => onChange({
|
|
1768
|
+
...defaultObj,
|
|
1769
|
+
...currentObj,
|
|
1770
|
+
href: e.target.value
|
|
1771
|
+
}),
|
|
1772
|
+
placeholder: "https:// o /ruta",
|
|
1773
|
+
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
1774
|
}
|
|
1527
1775
|
)
|
|
1528
1776
|
] })
|
|
1529
|
-
] })
|
|
1530
|
-
|
|
1531
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "\u{1F4C4} File URL:" }),
|
|
1532
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "truncate text-indigo-600 font-semibold", children: String(value) })
|
|
1533
|
-
] }) : null
|
|
1534
|
-
] }),
|
|
1535
|
-
meta.type === "link" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4 bg-slate-50 p-4 rounded-xl border border-slate-100", children: [
|
|
1536
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block", children: [
|
|
1537
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "Link Text" }),
|
|
1538
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block", children: [
|
|
1548
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "URL Target" }),
|
|
1549
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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
|
-
] }),
|
|
1777
|
+
] });
|
|
1778
|
+
})(),
|
|
1560
1779
|
meta.type === "color" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-3 bg-slate-50 p-2 rounded-xl border border-slate-100", children: [
|
|
1561
1780
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1562
1781
|
"input",
|
|
@@ -1811,6 +2030,18 @@ function FieldEditor({
|
|
|
1811
2030
|
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
2031
|
children: schemaField.options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: opt, children: opt }, opt))
|
|
1813
2032
|
}
|
|
2033
|
+
) : schemaField.type === "number" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2034
|
+
FormattedNumberInput,
|
|
2035
|
+
{
|
|
2036
|
+
value: item?.[schemaField.key],
|
|
2037
|
+
onChange: (val) => {
|
|
2038
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
2039
|
+
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
|
|
2040
|
+
onChange(arr);
|
|
2041
|
+
},
|
|
2042
|
+
isPrice: schemaField.key.toLowerCase().includes("price") || schemaField.key.toLowerCase().includes("precio"),
|
|
2043
|
+
className: "rounded-lg px-3 py-2 text-sm"
|
|
2044
|
+
}
|
|
1814
2045
|
) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1815
2046
|
"input",
|
|
1816
2047
|
{
|
|
@@ -1919,11 +2150,11 @@ function CollectionsSection() {
|
|
|
1919
2150
|
const ctx = useCmsContext();
|
|
1920
2151
|
const collections = ctx.config.collections ?? [];
|
|
1921
2152
|
const [selected, setSelected] = (0, import_react5.useState)(
|
|
1922
|
-
collections
|
|
2153
|
+
collections.find((c) => !c.isSeparator) ?? null
|
|
1923
2154
|
);
|
|
1924
2155
|
const [counts, setCounts] = (0, import_react5.useState)({});
|
|
1925
2156
|
(0, import_react5.useEffect)(() => {
|
|
1926
|
-
collections.forEach((c) => {
|
|
2157
|
+
collections.filter((c) => !c.isSeparator).forEach((c) => {
|
|
1927
2158
|
ctx.adapter.listEntries(c.id).then((entries) => {
|
|
1928
2159
|
setCounts((prev) => ({ ...prev, [c.id]: entries.length }));
|
|
1929
2160
|
});
|
|
@@ -1933,20 +2164,43 @@ function CollectionsSection() {
|
|
|
1933
2164
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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
2165
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
|
|
1935
2166
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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
|
-
]
|
|
2167
|
+
collections.map((c, idx) => {
|
|
2168
|
+
if (c.isSeparator) {
|
|
2169
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2170
|
+
"li",
|
|
2171
|
+
{
|
|
2172
|
+
className: "my-2 border-t border-slate-200/80"
|
|
2173
|
+
},
|
|
2174
|
+
c.id || `sep-${idx}`
|
|
2175
|
+
);
|
|
1948
2176
|
}
|
|
1949
|
-
|
|
2177
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "shrink-0 min-w-[140px] md:w-full md:min-w-0", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2178
|
+
"button",
|
|
2179
|
+
{
|
|
2180
|
+
onClick: () => setSelected(c),
|
|
2181
|
+
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"}`,
|
|
2182
|
+
children: [
|
|
2183
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2184
|
+
"div",
|
|
2185
|
+
{
|
|
2186
|
+
className: selected?.id === c.id ? "text-slate-900" : "text-slate-700",
|
|
2187
|
+
children: c.name
|
|
2188
|
+
}
|
|
2189
|
+
),
|
|
2190
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2191
|
+
"div",
|
|
2192
|
+
{
|
|
2193
|
+
className: `text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-500" : "text-slate-400"}`,
|
|
2194
|
+
children: [
|
|
2195
|
+
counts[c.id] ?? 0,
|
|
2196
|
+
" items"
|
|
2197
|
+
]
|
|
2198
|
+
}
|
|
2199
|
+
)
|
|
2200
|
+
]
|
|
2201
|
+
}
|
|
2202
|
+
) }, c.id);
|
|
2203
|
+
}),
|
|
1950
2204
|
collections.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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
2205
|
] })
|
|
1952
2206
|
] }),
|
|
@@ -1989,8 +2243,24 @@ function CollectionEditor({ collection }) {
|
|
|
1989
2243
|
collection.fields.forEach((f) => {
|
|
1990
2244
|
if (f.id === "order") {
|
|
1991
2245
|
base[f.id] = entries.length;
|
|
2246
|
+
} else if (f.type === "time-range") {
|
|
2247
|
+
if (f.startField) base[f.startField] = "";
|
|
2248
|
+
if (f.endField) base[f.endField] = "";
|
|
1992
2249
|
} else if (f.defaultValue !== void 0) {
|
|
1993
2250
|
base[f.id] = f.defaultValue;
|
|
2251
|
+
} else if (f.type === "branch-settings") {
|
|
2252
|
+
base[f.id] = {
|
|
2253
|
+
allBranches: true,
|
|
2254
|
+
branches: [],
|
|
2255
|
+
useBranchPricing: false,
|
|
2256
|
+
priceBranches: [],
|
|
2257
|
+
prices: {},
|
|
2258
|
+
useBranchDiscounts: false,
|
|
2259
|
+
discountBranches: [],
|
|
2260
|
+
discounts: {}
|
|
2261
|
+
};
|
|
2262
|
+
} else if (f.multiple) {
|
|
2263
|
+
base[f.id] = [];
|
|
1994
2264
|
} else {
|
|
1995
2265
|
base[f.id] = f.type === "boolean" ? false : f.type === "number" ? 0 : f.type === "select" ? f.options?.[0] ?? "" : "";
|
|
1996
2266
|
}
|
|
@@ -2003,7 +2273,9 @@ function CollectionEditor({ collection }) {
|
|
|
2003
2273
|
try {
|
|
2004
2274
|
const finalEditing = { ...editing };
|
|
2005
2275
|
collection.fields.forEach((f) => {
|
|
2006
|
-
if (f.type === "
|
|
2276
|
+
if (f.type === "time-range") {
|
|
2277
|
+
delete finalEditing[f.id];
|
|
2278
|
+
} else if (f.type === "slug" && !finalEditing[f.id]) {
|
|
2007
2279
|
const sourceField = f.source || "title";
|
|
2008
2280
|
let val = String(finalEditing[sourceField] || finalEditing.id || "");
|
|
2009
2281
|
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
@@ -2064,6 +2336,7 @@ function CollectionEditor({ collection }) {
|
|
|
2064
2336
|
setDragOverIdx(null);
|
|
2065
2337
|
};
|
|
2066
2338
|
const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 5);
|
|
2339
|
+
const isCreatingEntry = editing ? !entries.some((entry) => entry.id === editing.id) : false;
|
|
2067
2340
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mx-auto max-w-5xl", children: [
|
|
2068
2341
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-8 flex items-center justify-between", children: [
|
|
2069
2342
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
@@ -2126,260 +2399,298 @@ function CollectionEditor({ collection }) {
|
|
|
2126
2399
|
] }, f);
|
|
2127
2400
|
})
|
|
2128
2401
|
] }),
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
f.label,
|
|
2137
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
|
|
2402
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2403
|
+
import_antd.Modal,
|
|
2404
|
+
{
|
|
2405
|
+
open: Boolean(editing),
|
|
2406
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "flex items-center gap-2 text-slate-900", children: [
|
|
2407
|
+
isCreatingEntry ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "h-4 w-4 text-indigo-600" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4 text-indigo-600" }),
|
|
2408
|
+
isCreatingEntry ? "Create Entry" : "Edit Entry"
|
|
2138
2409
|
] }),
|
|
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__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
2173
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(
|
|
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 })
|
|
2410
|
+
onCancel: () => {
|
|
2411
|
+
if (!saving) setEditing(null);
|
|
2412
|
+
},
|
|
2413
|
+
footer: null,
|
|
2414
|
+
centered: true,
|
|
2415
|
+
width: "min(900px, calc(100vw - 32px))",
|
|
2416
|
+
mask: { blur: true },
|
|
2417
|
+
keyboard: !saving,
|
|
2418
|
+
closable: !saving,
|
|
2419
|
+
styles: {
|
|
2420
|
+
body: {
|
|
2421
|
+
maxHeight: "calc(100dvh - 180px)",
|
|
2422
|
+
display: "flex",
|
|
2423
|
+
flexDirection: "column",
|
|
2424
|
+
overflow: "hidden",
|
|
2425
|
+
padding: 0
|
|
2426
|
+
},
|
|
2427
|
+
mask: {
|
|
2428
|
+
backgroundColor: "rgba(15, 23, 42, 0.82)",
|
|
2429
|
+
backdropFilter: "blur(8px)"
|
|
2203
2430
|
}
|
|
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__ */ (0, import_jsx_runtime5.jsxs)("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__ */ (0, import_jsx_runtime5.jsx)("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
|
|
2224
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.X, { className: "w-3 h-3" })
|
|
2235
|
-
}
|
|
2236
|
-
)
|
|
2237
|
-
] }, i);
|
|
2238
|
-
}) }),
|
|
2239
|
-
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
2240
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2431
|
+
},
|
|
2432
|
+
children: editing && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex max-h-[calc(100dvh-180px)] min-h-0 flex-col", children: [
|
|
2433
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "min-h-0 flex-1 overflow-y-auto px-6 py-5", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `block ${f.type === "richtext" || f.type === "branch-settings" || f.type === "time-range" ? "lg:col-span-2" : ""}`, children: [
|
|
2434
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
|
|
2435
|
+
f.label,
|
|
2436
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
|
|
2437
|
+
] }),
|
|
2438
|
+
f.type === "branch-settings" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2439
|
+
BranchSettingsEditor,
|
|
2440
|
+
{
|
|
2441
|
+
collectionId: f.collection || "",
|
|
2442
|
+
value: editing[f.id],
|
|
2443
|
+
globalPrice: Number(editing.price) || 0,
|
|
2444
|
+
globalDiscount: Number(editing.discountPercent) || 0,
|
|
2445
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2446
|
+
}
|
|
2447
|
+
) : f.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-1 h-10 flex items-center", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2241
2448
|
"input",
|
|
2242
2449
|
{
|
|
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"
|
|
2450
|
+
type: "checkbox",
|
|
2451
|
+
checked: !!editing[f.id],
|
|
2452
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.checked }),
|
|
2453
|
+
className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
2254
2454
|
}
|
|
2255
|
-
),
|
|
2256
|
-
|
|
2257
|
-
|
|
2455
|
+
) }) : f.type === "number" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2456
|
+
FormattedNumberInput,
|
|
2457
|
+
{
|
|
2458
|
+
value: editing[f.id],
|
|
2459
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2460
|
+
isPrice: f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.toLowerCase().includes("valor") || f.label.includes("$"),
|
|
2461
|
+
isPercent: f.id.toLowerCase().includes("discount") || f.id.toLowerCase().includes("descuento") || f.label.toLowerCase().includes("descuento")
|
|
2462
|
+
}
|
|
2463
|
+
) : f.type === "time-range" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-1.5", children: [
|
|
2258
2464
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2259
|
-
|
|
2465
|
+
AdminTimeRangePicker,
|
|
2260
2466
|
{
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
onChange: (
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
ctx.uploadImage
|
|
2279
|
-
);
|
|
2280
|
-
});
|
|
2281
|
-
}
|
|
2467
|
+
value: [
|
|
2468
|
+
toDayjsTime(f.startField ? editing[f.startField] : ""),
|
|
2469
|
+
toDayjsTime(f.endField ? editing[f.endField] : "")
|
|
2470
|
+
],
|
|
2471
|
+
onChange: (times) => setEditing(
|
|
2472
|
+
(current) => current ? {
|
|
2473
|
+
...current,
|
|
2474
|
+
...f.startField ? { [f.startField]: toStoredTime(times?.[0]) } : {},
|
|
2475
|
+
...f.endField ? { [f.endField]: toStoredTime(times?.[1]) } : {}
|
|
2476
|
+
} : current
|
|
2477
|
+
),
|
|
2478
|
+
allowEmpty: [true, true],
|
|
2479
|
+
className: "w-full",
|
|
2480
|
+
format: TIME_DISPLAY_FORMAT,
|
|
2481
|
+
order: false,
|
|
2482
|
+
placeholder: ["Hora de inicio", "Hora de cierre"],
|
|
2483
|
+
use12Hours: true
|
|
2282
2484
|
}
|
|
2283
|
-
)
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2485
|
+
),
|
|
2486
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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." })
|
|
2487
|
+
] }) : f.type === "time" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2488
|
+
AdminTimePicker,
|
|
2489
|
+
{
|
|
2490
|
+
value: toDayjsTime(editing[f.id]),
|
|
2491
|
+
onChange: (time) => setEditing({ ...editing, [f.id]: toStoredTime(time) }),
|
|
2492
|
+
className: "w-full",
|
|
2493
|
+
format: TIME_DISPLAY_FORMAT,
|
|
2494
|
+
use12Hours: true
|
|
2495
|
+
}
|
|
2496
|
+
) : f.type === "richtext" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2497
|
+
"textarea",
|
|
2290
2498
|
{
|
|
2291
|
-
type: "url",
|
|
2292
2499
|
value: String(editing[f.id] ?? ""),
|
|
2293
2500
|
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2294
|
-
|
|
2295
|
-
className: "w-full rounded-xl border border-slate-200 px-4 py-
|
|
2501
|
+
rows: 4,
|
|
2502
|
+
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
2503
|
}
|
|
2297
|
-
),
|
|
2298
|
-
|
|
2299
|
-
|
|
2504
|
+
) : f.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2505
|
+
SearchableSelect,
|
|
2506
|
+
{
|
|
2507
|
+
value: String(editing[f.id] ?? ""),
|
|
2508
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val }),
|
|
2509
|
+
options: f.options || [],
|
|
2510
|
+
placeholder: `Search ${f.label.toLowerCase()}...`,
|
|
2511
|
+
iconMap: ctx.iconMap
|
|
2512
|
+
}
|
|
2513
|
+
) : f.type === "slug" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
2300
2514
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2301
2515
|
"input",
|
|
2302
2516
|
{
|
|
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
|
-
}
|
|
2517
|
+
type: "text",
|
|
2518
|
+
value: String(editing[f.id] ?? ""),
|
|
2519
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2520
|
+
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
2521
|
}
|
|
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
|
-
|
|
2522
|
+
),
|
|
2523
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2524
|
+
"button",
|
|
2525
|
+
{
|
|
2526
|
+
type: "button",
|
|
2527
|
+
onClick: () => {
|
|
2528
|
+
const sourceField = f.source || "title";
|
|
2529
|
+
let val = String(editing[sourceField] || editing.id || "");
|
|
2530
|
+
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
2531
|
+
setEditing({ ...editing, [f.id]: val });
|
|
2532
|
+
},
|
|
2533
|
+
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",
|
|
2534
|
+
children: "Generate"
|
|
2535
|
+
}
|
|
2536
|
+
)
|
|
2537
|
+
] }) : f.type === "reference" || f.type === "select" && f.collection ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2538
|
+
ReferenceSelect,
|
|
2539
|
+
{
|
|
2540
|
+
collectionId: f.collection,
|
|
2541
|
+
displayField: f.displayField,
|
|
2542
|
+
valueField: f.valueField,
|
|
2543
|
+
fallbackOptions: f.options,
|
|
2544
|
+
multiple: f.multiple,
|
|
2545
|
+
searchable: f.searchable,
|
|
2546
|
+
max: f.max,
|
|
2547
|
+
value: editing[f.id],
|
|
2548
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2549
|
+
}
|
|
2550
|
+
) : f.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
|
|
2551
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2552
|
+
"select",
|
|
2553
|
+
{
|
|
2554
|
+
value: String(editing[f.id] ?? ""),
|
|
2555
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2556
|
+
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",
|
|
2557
|
+
children: [
|
|
2558
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: "-- Selecciona una opci\xF3n --" }),
|
|
2559
|
+
f.options?.map((opt) => {
|
|
2560
|
+
const val = typeof opt === "string" ? opt : opt.value;
|
|
2561
|
+
const lab = typeof opt === "string" ? opt : opt.label;
|
|
2562
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: val, children: lab }, val);
|
|
2563
|
+
})
|
|
2564
|
+
]
|
|
2565
|
+
}
|
|
2566
|
+
),
|
|
2567
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
|
|
2568
|
+
] }) : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
|
|
2569
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
|
|
2570
|
+
const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
|
|
2571
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
|
|
2572
|
+
isVideo ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("video", { src: url, className: "w-full h-full object-cover rounded-lg", autoPlay: true, muted: true, loop: true, playsInline: true }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
|
|
2573
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2574
|
+
"button",
|
|
2575
|
+
{
|
|
2576
|
+
type: "button",
|
|
2577
|
+
onClick: () => {
|
|
2578
|
+
const arr = [...editing[f.id] || []];
|
|
2579
|
+
arr.splice(i, 1);
|
|
2580
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2581
|
+
},
|
|
2582
|
+
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",
|
|
2583
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.X, { className: "w-3 h-3" })
|
|
2584
|
+
}
|
|
2585
|
+
)
|
|
2586
|
+
] }, i);
|
|
2587
|
+
}) }),
|
|
2588
|
+
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
2589
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2590
|
+
"input",
|
|
2591
|
+
{
|
|
2592
|
+
type: "url",
|
|
2593
|
+
placeholder: "Add media URL and press Enter...",
|
|
2594
|
+
onKeyDown: (e) => {
|
|
2595
|
+
if (e.key === "Enter" && e.currentTarget.value) {
|
|
2596
|
+
e.preventDefault();
|
|
2597
|
+
const arr = [...editing[f.id] || [], e.currentTarget.value];
|
|
2598
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2599
|
+
e.currentTarget.value = "";
|
|
2600
|
+
}
|
|
2601
|
+
},
|
|
2602
|
+
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"
|
|
2603
|
+
}
|
|
2604
|
+
),
|
|
2605
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2606
|
+
FilePickerButton,
|
|
2607
|
+
{
|
|
2608
|
+
accept: "image/*,video/*",
|
|
2609
|
+
multiple: true,
|
|
2610
|
+
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",
|
|
2611
|
+
onFiles: (files) => {
|
|
2612
|
+
files.forEach((file) => {
|
|
2613
|
+
void handleImageFile(
|
|
2614
|
+
file,
|
|
2615
|
+
(url) => {
|
|
2616
|
+
setEditing((prev) => {
|
|
2617
|
+
if (!prev) return prev;
|
|
2618
|
+
const current = prev[f.id] || [];
|
|
2619
|
+
if (f.max && current.length >= f.max) {
|
|
2620
|
+
return prev;
|
|
2621
|
+
}
|
|
2622
|
+
return { ...prev, [f.id]: [...current, url] };
|
|
2623
|
+
});
|
|
2624
|
+
},
|
|
2625
|
+
ctx.uploadImage
|
|
2626
|
+
);
|
|
2627
|
+
});
|
|
2628
|
+
},
|
|
2629
|
+
children: "Upload"
|
|
2630
|
+
}
|
|
2631
|
+
)
|
|
2632
|
+
] })
|
|
2633
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
|
|
2634
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
2635
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2636
|
+
"input",
|
|
2637
|
+
{
|
|
2638
|
+
type: "url",
|
|
2639
|
+
value: String(editing[f.id] ?? ""),
|
|
2640
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2641
|
+
placeholder: "https://...",
|
|
2642
|
+
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"
|
|
2643
|
+
}
|
|
2644
|
+
),
|
|
2645
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2646
|
+
FilePickerButton,
|
|
2647
|
+
{
|
|
2648
|
+
accept: "image/*,video/*",
|
|
2649
|
+
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",
|
|
2650
|
+
onFiles: (files) => {
|
|
2651
|
+
const file = files[0];
|
|
2652
|
+
if (file) {
|
|
2653
|
+
void handleImageFile(
|
|
2654
|
+
file,
|
|
2655
|
+
(url) => setEditing(
|
|
2656
|
+
(current) => current ? { ...current, [f.id]: url } : current
|
|
2657
|
+
),
|
|
2658
|
+
ctx.uploadImage
|
|
2659
|
+
);
|
|
2660
|
+
}
|
|
2661
|
+
},
|
|
2662
|
+
children: "Upload"
|
|
2663
|
+
}
|
|
2664
|
+
)
|
|
2665
|
+
] }),
|
|
2666
|
+
editing[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)(
|
|
2667
|
+
"video",
|
|
2668
|
+
{
|
|
2669
|
+
src: String(editing[f.id]),
|
|
2670
|
+
controls: true,
|
|
2671
|
+
className: "w-full h-auto max-h-48 object-contain rounded-lg"
|
|
2672
|
+
}
|
|
2673
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2674
|
+
"img",
|
|
2675
|
+
{
|
|
2676
|
+
src: String(editing[f.id]),
|
|
2677
|
+
alt: "",
|
|
2678
|
+
className: "w-full h-auto max-h-48 object-contain rounded-lg"
|
|
2679
|
+
}
|
|
2680
|
+
) }) : null
|
|
2681
|
+
] }) : f.type === "password" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2682
|
+
PasswordField,
|
|
2683
|
+
{
|
|
2684
|
+
value: String(editing[f.id] ?? ""),
|
|
2685
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2686
|
+
}
|
|
2687
|
+
) : f.type === "color" && !f.multiple ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-3", children: [
|
|
2373
2688
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2374
2689
|
"input",
|
|
2375
2690
|
{
|
|
2376
2691
|
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
|
-
},
|
|
2692
|
+
value: String(editing[f.id] ?? "#000000").startsWith("#") && String(editing[f.id] ?? "").length === 7 ? String(editing[f.id]) : "#000000",
|
|
2693
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2383
2694
|
className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
|
|
2384
2695
|
}
|
|
2385
2696
|
),
|
|
@@ -2387,135 +2698,172 @@ function CollectionEditor({ collection }) {
|
|
|
2387
2698
|
"input",
|
|
2388
2699
|
{
|
|
2389
2700
|
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"
|
|
2701
|
+
value: String(editing[f.id] ?? ""),
|
|
2702
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2703
|
+
placeholder: "#000000",
|
|
2704
|
+
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
2705
|
}
|
|
2399
2706
|
),
|
|
2400
2707
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2401
2708
|
"div",
|
|
2402
2709
|
{
|
|
2403
|
-
className: "w-
|
|
2404
|
-
style: { backgroundColor:
|
|
2710
|
+
className: "w-8 h-8 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
|
|
2711
|
+
style: { backgroundColor: String(editing[f.id] ?? "#000000") }
|
|
2405
2712
|
}
|
|
2406
|
-
)
|
|
2407
|
-
|
|
2713
|
+
)
|
|
2714
|
+
] }) : f.type === "color" && f.multiple || f.type === "list" && f.id === "colors" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
|
|
2715
|
+
(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) => {
|
|
2716
|
+
const colorVal = String(item ?? "").trim();
|
|
2717
|
+
const validHex = colorVal.startsWith("#") && (colorVal.length === 4 || colorVal.length === 7) ? colorVal : "#000000";
|
|
2718
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2 items-center", children: [
|
|
2719
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2720
|
+
"input",
|
|
2721
|
+
{
|
|
2722
|
+
type: "color",
|
|
2723
|
+
value: validHex.length === 7 ? validHex : "#000000",
|
|
2724
|
+
onChange: (e) => {
|
|
2725
|
+
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) : [];
|
|
2726
|
+
arr[idx] = e.target.value;
|
|
2727
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2728
|
+
},
|
|
2729
|
+
className: "w-10 h-10 rounded-xl border border-slate-200 p-0.5 cursor-pointer shadow-sm flex-shrink-0"
|
|
2730
|
+
}
|
|
2731
|
+
),
|
|
2732
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2733
|
+
"input",
|
|
2734
|
+
{
|
|
2735
|
+
type: "text",
|
|
2736
|
+
value: colorVal,
|
|
2737
|
+
onChange: (e) => {
|
|
2738
|
+
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) : [];
|
|
2739
|
+
arr[idx] = e.target.value;
|
|
2740
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2741
|
+
},
|
|
2742
|
+
placeholder: "#1c2a44",
|
|
2743
|
+
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"
|
|
2744
|
+
}
|
|
2745
|
+
),
|
|
2746
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2747
|
+
"div",
|
|
2748
|
+
{
|
|
2749
|
+
className: "w-7 h-7 rounded-full border border-slate-300 shadow-inner flex-shrink-0",
|
|
2750
|
+
style: { backgroundColor: colorVal || "#000000" }
|
|
2751
|
+
}
|
|
2752
|
+
),
|
|
2753
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2754
|
+
"button",
|
|
2755
|
+
{
|
|
2756
|
+
type: "button",
|
|
2757
|
+
onClick: () => {
|
|
2758
|
+
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) : [];
|
|
2759
|
+
arr.splice(idx, 1);
|
|
2760
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2761
|
+
},
|
|
2762
|
+
className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
|
|
2763
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
|
|
2764
|
+
}
|
|
2765
|
+
)
|
|
2766
|
+
] }, idx);
|
|
2767
|
+
}),
|
|
2768
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2408
2769
|
"button",
|
|
2409
2770
|
{
|
|
2410
2771
|
type: "button",
|
|
2411
2772
|
onClick: () => {
|
|
2412
2773
|
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.
|
|
2774
|
+
arr.push("#000000");
|
|
2414
2775
|
setEditing({ ...editing, [f.id]: arr });
|
|
2415
2776
|
},
|
|
2416
|
-
className: "
|
|
2417
|
-
children:
|
|
2777
|
+
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",
|
|
2778
|
+
children: [
|
|
2779
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-3.5 h-3.5" }),
|
|
2780
|
+
" Add Color"
|
|
2781
|
+
]
|
|
2418
2782
|
}
|
|
2419
2783
|
)
|
|
2420
|
-
] },
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2784
|
+
] }) : f.type === "list" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
|
|
2785
|
+
(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__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2 items-center", children: [
|
|
2786
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2787
|
+
"input",
|
|
2788
|
+
{
|
|
2789
|
+
type: "text",
|
|
2790
|
+
value: String(item ?? ""),
|
|
2791
|
+
onChange: (e) => {
|
|
2792
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
|
|
2793
|
+
arr[idx] = e.target.value;
|
|
2794
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2795
|
+
},
|
|
2796
|
+
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"
|
|
2797
|
+
}
|
|
2798
|
+
),
|
|
2799
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2800
|
+
"button",
|
|
2801
|
+
{
|
|
2802
|
+
type: "button",
|
|
2803
|
+
onClick: () => {
|
|
2804
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
|
|
2805
|
+
arr.splice(idx, 1);
|
|
2806
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2807
|
+
},
|
|
2808
|
+
className: "p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-xl transition-colors",
|
|
2809
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
|
|
2810
|
+
}
|
|
2811
|
+
)
|
|
2812
|
+
] }, idx)),
|
|
2813
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
2814
|
+
"button",
|
|
2815
|
+
{
|
|
2816
|
+
type: "button",
|
|
2817
|
+
onClick: () => {
|
|
2818
|
+
let arr = Array.isArray(editing[f.id]) ? [...editing[f.id]] : typeof editing[f.id] === "string" ? String(editing[f.id]).split("\n").filter(Boolean) : [];
|
|
2819
|
+
arr.push("");
|
|
2820
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2821
|
+
},
|
|
2822
|
+
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",
|
|
2823
|
+
children: [
|
|
2824
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-3.5 h-3.5" }),
|
|
2825
|
+
" Add Item"
|
|
2826
|
+
]
|
|
2827
|
+
}
|
|
2828
|
+
)
|
|
2829
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2441
2830
|
"input",
|
|
2442
2831
|
{
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
|
|
2449
|
-
|
|
2450
|
-
|
|
2832
|
+
value: String(editing[f.id] ?? ""),
|
|
2833
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
2834
|
+
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"
|
|
2835
|
+
}
|
|
2836
|
+
)
|
|
2837
|
+
] }, f.id)) }) }),
|
|
2838
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex shrink-0 justify-end gap-3 border-t border-slate-200 bg-white px-6 py-4", children: [
|
|
2839
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2840
|
+
"button",
|
|
2841
|
+
{
|
|
2842
|
+
onClick: () => setEditing(null),
|
|
2843
|
+
disabled: saving,
|
|
2844
|
+
className: "rounded-xl px-5 py-2.5 text-sm font-semibold text-slate-600 hover:bg-slate-100 transition-colors disabled:opacity-50",
|
|
2845
|
+
children: "Cancel"
|
|
2451
2846
|
}
|
|
2452
2847
|
),
|
|
2453
2848
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2454
2849
|
"button",
|
|
2455
2850
|
{
|
|
2456
|
-
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
2851
|
+
onClick: save,
|
|
2852
|
+
disabled: saving,
|
|
2853
|
+
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",
|
|
2854
|
+
children: saving ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
2855
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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: [
|
|
2856
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
2857
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
|
|
2858
|
+
] }),
|
|
2859
|
+
"Saving..."
|
|
2860
|
+
] }) : "Save Entry"
|
|
2464
2861
|
}
|
|
2465
2862
|
)
|
|
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__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Plus, { className: "w-3.5 h-3.5" }),
|
|
2479
|
-
" Add Item"
|
|
2480
|
-
]
|
|
2481
|
-
}
|
|
2482
|
-
)
|
|
2483
|
-
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mt-8 flex justify-end gap-3 pt-5 border-t border-slate-100", children: [
|
|
2493
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsx)(
|
|
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__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
2509
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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__ */ (0, import_jsx_runtime5.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
2511
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
|
|
2512
|
-
] }),
|
|
2513
|
-
"Saving..."
|
|
2514
|
-
] }) : "Save Entry"
|
|
2515
|
-
}
|
|
2516
|
-
)
|
|
2517
|
-
] })
|
|
2518
|
-
] }),
|
|
2863
|
+
] })
|
|
2864
|
+
] })
|
|
2865
|
+
}
|
|
2866
|
+
),
|
|
2519
2867
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "overflow-x-auto rounded-2xl border border-slate-200 bg-white shadow-sm", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("table", { className: "w-full text-sm text-left", children: [
|
|
2520
2868
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("thead", { className: "bg-slate-50/80 border-b border-slate-200", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("tr", { children: [
|
|
2521
2869
|
visibleFields.map((f) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("th", { className: "px-6 py-4 text-xs font-bold text-slate-500 uppercase tracking-wider", children: f.label }, f.id)),
|
|
@@ -2553,7 +2901,10 @@ function CollectionEditor({ collection }) {
|
|
|
2553
2901
|
onDragEnd,
|
|
2554
2902
|
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
2903
|
children: [
|
|
2556
|
-
visibleFields.map((f) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)(ReferenceTableCell, { collectionId: f.collection, entryId:
|
|
2904
|
+
visibleFields.map((f) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "branch-settings" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(BranchSettingsSummary, { value: e[f.id] }) : f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : f.id === "status" && e[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "font-semibold text-slate-800", children: [
|
|
2905
|
+
"$ ",
|
|
2906
|
+
Number(e[f.id]).toLocaleString("es-CO")
|
|
2907
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: Number(e[f.id]).toLocaleString("es-CO") }) : String(e[f.id] ?? "") }, f.id)),
|
|
2557
2908
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-end gap-2", children: [
|
|
2558
2909
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "p-2 text-slate-300 cursor-grab active:cursor-grabbing", title: "Drag to reorder", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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__ */ (0, import_jsx_runtime5.jsx)("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
2910
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
@@ -2970,7 +3321,6 @@ function SettingsSection() {
|
|
|
2970
3321
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "px-6 py-4 border-b border-slate-100 bg-slate-50/50", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { className: "font-bold text-slate-800", children: "Configuration Snapshot" }) }),
|
|
2971
3322
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("dl", { className: "divide-y divide-slate-100 text-sm", children: [
|
|
2972
3323
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { label: "Site Name", value: ctx.config.siteName ?? "\u2014" }),
|
|
2973
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { label: "Active Storage Adapter", value: ctx.adapter.name, highlight: true }),
|
|
2974
3324
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Row, { label: "Registered Pages", value: String(ctx.config.pages.length) }),
|
|
2975
3325
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
2976
3326
|
Row,
|
|
@@ -3199,49 +3549,802 @@ function PasswordField({ value, onChange }) {
|
|
|
3199
3549
|
)
|
|
3200
3550
|
] });
|
|
3201
3551
|
}
|
|
3202
|
-
function
|
|
3552
|
+
function FormattedNumberInput({
|
|
3553
|
+
value,
|
|
3554
|
+
onChange,
|
|
3555
|
+
isPrice = false,
|
|
3556
|
+
isPercent = false,
|
|
3557
|
+
allowEmpty = false,
|
|
3558
|
+
placeholder = "0",
|
|
3559
|
+
className = "",
|
|
3560
|
+
containerClassName = "w-full"
|
|
3561
|
+
}) {
|
|
3562
|
+
const formatWithDots = (num) => {
|
|
3563
|
+
if (num === void 0 || num === null || num === "") return "";
|
|
3564
|
+
const cleanDigits = String(num).replace(/\D/g, "");
|
|
3565
|
+
if (!cleanDigits) return "";
|
|
3566
|
+
return cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
3567
|
+
};
|
|
3568
|
+
const [displayVal, setDisplayVal] = (0, import_react5.useState)(() => formatWithDots(value));
|
|
3569
|
+
(0, import_react5.useEffect)(() => {
|
|
3570
|
+
setDisplayVal(formatWithDots(value));
|
|
3571
|
+
}, [value]);
|
|
3572
|
+
const handleChange = (e) => {
|
|
3573
|
+
const rawText = e.target.value;
|
|
3574
|
+
const cleanDigits = rawText.replace(/\D/g, "");
|
|
3575
|
+
if (!cleanDigits) {
|
|
3576
|
+
setDisplayVal("");
|
|
3577
|
+
onChange(allowEmpty ? null : 0);
|
|
3578
|
+
return;
|
|
3579
|
+
}
|
|
3580
|
+
const parsed = Number(cleanDigits);
|
|
3581
|
+
if (isPercent && parsed > 100) {
|
|
3582
|
+
setDisplayVal("100");
|
|
3583
|
+
onChange(100);
|
|
3584
|
+
return;
|
|
3585
|
+
}
|
|
3586
|
+
const formatted = isPercent ? cleanDigits : cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
3587
|
+
setDisplayVal(formatted);
|
|
3588
|
+
onChange(parsed);
|
|
3589
|
+
};
|
|
3590
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: `relative flex items-center ${containerClassName}`, children: [
|
|
3591
|
+
isPrice && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "absolute left-3.5 text-sm font-bold text-slate-400 pointer-events-none select-none", children: "$" }),
|
|
3592
|
+
isPercent && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "absolute right-3.5 text-sm font-bold text-slate-400 pointer-events-none select-none", children: "%" }),
|
|
3593
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3594
|
+
"input",
|
|
3595
|
+
{
|
|
3596
|
+
type: "text",
|
|
3597
|
+
inputMode: "numeric",
|
|
3598
|
+
pattern: "[0-9.]*",
|
|
3599
|
+
autoComplete: "off",
|
|
3600
|
+
value: displayVal,
|
|
3601
|
+
onChange: handleChange,
|
|
3602
|
+
placeholder,
|
|
3603
|
+
"aria-valuemin": isPercent ? 0 : void 0,
|
|
3604
|
+
"aria-valuemax": isPercent ? 100 : void 0,
|
|
3605
|
+
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}`
|
|
3606
|
+
}
|
|
3607
|
+
)
|
|
3608
|
+
] });
|
|
3609
|
+
}
|
|
3610
|
+
function BranchSettingsEditor({
|
|
3611
|
+
collectionId,
|
|
3612
|
+
value,
|
|
3613
|
+
globalPrice,
|
|
3614
|
+
globalDiscount,
|
|
3615
|
+
onChange
|
|
3616
|
+
}) {
|
|
3617
|
+
const ctx = useCmsContext();
|
|
3618
|
+
const [branches, setBranches] = (0, import_react5.useState)([]);
|
|
3619
|
+
const [loading, setLoading] = (0, import_react5.useState)(true);
|
|
3620
|
+
const [loadError, setLoadError] = (0, import_react5.useState)("");
|
|
3621
|
+
const settings = value && typeof value === "object" ? value : {};
|
|
3622
|
+
const selectedBranches = Array.isArray(settings.branches) ? settings.branches.map(String) : [];
|
|
3623
|
+
const prices = settings.prices && typeof settings.prices === "object" ? settings.prices : {};
|
|
3624
|
+
const selectedPriceBranches = [
|
|
3625
|
+
.../* @__PURE__ */ new Set([
|
|
3626
|
+
...Array.isArray(settings.priceBranches) ? settings.priceBranches.map(String) : [],
|
|
3627
|
+
...Object.keys(prices)
|
|
3628
|
+
])
|
|
3629
|
+
];
|
|
3630
|
+
const discounts = settings.discounts && typeof settings.discounts === "object" ? settings.discounts : {};
|
|
3631
|
+
const selectedDiscountBranches = [
|
|
3632
|
+
.../* @__PURE__ */ new Set([
|
|
3633
|
+
...Array.isArray(settings.discountBranches) ? settings.discountBranches.map(String) : [],
|
|
3634
|
+
...Object.keys(discounts)
|
|
3635
|
+
])
|
|
3636
|
+
];
|
|
3637
|
+
const branchAvailability = settings.branchAvailability && typeof settings.branchAvailability === "object" ? settings.branchAvailability : {};
|
|
3638
|
+
const selectedAvailabilityBranches = Object.keys(branchAvailability);
|
|
3639
|
+
const allBranches = settings.allBranches !== false;
|
|
3640
|
+
const useBranchPricing = settings.useBranchPricing === true;
|
|
3641
|
+
const useBranchDiscounts = settings.useBranchDiscounts === true;
|
|
3642
|
+
(0, import_react5.useEffect)(() => {
|
|
3643
|
+
let active = true;
|
|
3644
|
+
setLoading(true);
|
|
3645
|
+
setLoadError("");
|
|
3646
|
+
ctx.adapter.listEntries(collectionId).then((entries) => {
|
|
3647
|
+
if (active) setBranches(entries);
|
|
3648
|
+
}).catch((error) => {
|
|
3649
|
+
console.error("Could not load branches for product settings:", error);
|
|
3650
|
+
if (active) setLoadError("No se pudieron cargar las sedes.");
|
|
3651
|
+
}).finally(() => {
|
|
3652
|
+
if (active) setLoading(false);
|
|
3653
|
+
});
|
|
3654
|
+
return () => {
|
|
3655
|
+
active = false;
|
|
3656
|
+
};
|
|
3657
|
+
}, [collectionId, ctx.adapter]);
|
|
3658
|
+
const getBranchName = (branch) => String(branch.name || branch.id);
|
|
3659
|
+
const updateSettings = (patch) => {
|
|
3660
|
+
onChange({
|
|
3661
|
+
allBranches,
|
|
3662
|
+
branches: selectedBranches,
|
|
3663
|
+
useBranchPricing,
|
|
3664
|
+
priceBranches: selectedPriceBranches,
|
|
3665
|
+
prices: { ...prices },
|
|
3666
|
+
useBranchDiscounts,
|
|
3667
|
+
discountBranches: selectedDiscountBranches,
|
|
3668
|
+
discounts: { ...discounts },
|
|
3669
|
+
branchAvailability: { ...branchAvailability },
|
|
3670
|
+
...patch
|
|
3671
|
+
});
|
|
3672
|
+
};
|
|
3673
|
+
const updateBranchAvailability = (name, start, end) => {
|
|
3674
|
+
updateSettings({
|
|
3675
|
+
branchAvailability: {
|
|
3676
|
+
...branchAvailability,
|
|
3677
|
+
[name]: {
|
|
3678
|
+
start: toStoredTime(start),
|
|
3679
|
+
end: toStoredTime(end)
|
|
3680
|
+
}
|
|
3681
|
+
}
|
|
3682
|
+
});
|
|
3683
|
+
};
|
|
3684
|
+
const updateBranchPrice = (name, value2) => {
|
|
3685
|
+
const nextPrices = { ...prices };
|
|
3686
|
+
if (value2.trim() === "") {
|
|
3687
|
+
delete nextPrices[name];
|
|
3688
|
+
} else {
|
|
3689
|
+
const parsed = Number(value2);
|
|
3690
|
+
if (Number.isFinite(parsed) && parsed >= 0) nextPrices[name] = parsed;
|
|
3691
|
+
}
|
|
3692
|
+
updateSettings({ prices: nextPrices });
|
|
3693
|
+
};
|
|
3694
|
+
const updateBranchDiscount = (name, value2) => {
|
|
3695
|
+
const nextDiscounts = { ...discounts };
|
|
3696
|
+
if (value2.trim() === "") {
|
|
3697
|
+
delete nextDiscounts[name];
|
|
3698
|
+
} else {
|
|
3699
|
+
const parsed = Number(value2);
|
|
3700
|
+
if (Number.isFinite(parsed) && parsed >= 0 && parsed <= 100) {
|
|
3701
|
+
nextDiscounts[name] = parsed;
|
|
3702
|
+
}
|
|
3703
|
+
}
|
|
3704
|
+
updateSettings({ discounts: nextDiscounts });
|
|
3705
|
+
};
|
|
3706
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4 rounded-xl border border-slate-200 bg-slate-50/50 p-4", children: [
|
|
3707
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
3708
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3709
|
+
"input",
|
|
3710
|
+
{
|
|
3711
|
+
type: "checkbox",
|
|
3712
|
+
checked: allBranches,
|
|
3713
|
+
onChange: (event) => updateSettings({ allBranches: event.target.checked }),
|
|
3714
|
+
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
3715
|
+
}
|
|
3716
|
+
),
|
|
3717
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
|
|
3718
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "block font-semibold", children: "Disponible en todas las sedes" }),
|
|
3719
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "mt-0.5 block text-xs text-slate-500", children: "Desactiva esta opci\xF3n para elegir una o varias sedes." })
|
|
3720
|
+
] })
|
|
3721
|
+
] }),
|
|
3722
|
+
!allBranches && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3723
|
+
SearchableMultiSelect,
|
|
3724
|
+
{
|
|
3725
|
+
options: branches.map((branch) => ({
|
|
3726
|
+
value: getBranchName(branch),
|
|
3727
|
+
label: getBranchName(branch)
|
|
3728
|
+
})),
|
|
3729
|
+
value: selectedBranches,
|
|
3730
|
+
onChange: (next) => updateSettings({ branches: next }),
|
|
3731
|
+
loading,
|
|
3732
|
+
error: loadError,
|
|
3733
|
+
placeholder: "Seleccionar sedes...",
|
|
3734
|
+
searchPlaceholder: "Buscar sede...",
|
|
3735
|
+
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3736
|
+
}
|
|
3737
|
+
),
|
|
3738
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
3739
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-sm font-semibold text-slate-700", children: "Horario diferente por sede (opcional)" }),
|
|
3740
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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." }),
|
|
3741
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-3", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3742
|
+
SearchableMultiSelect,
|
|
3743
|
+
{
|
|
3744
|
+
options: branches.map((branch) => ({
|
|
3745
|
+
value: getBranchName(branch),
|
|
3746
|
+
label: getBranchName(branch)
|
|
3747
|
+
})),
|
|
3748
|
+
value: selectedAvailabilityBranches,
|
|
3749
|
+
onChange: (next) => {
|
|
3750
|
+
const nextSchedules = Object.fromEntries(
|
|
3751
|
+
next.map((name) => [
|
|
3752
|
+
name,
|
|
3753
|
+
branchAvailability[name] ?? { start: "", end: "" }
|
|
3754
|
+
])
|
|
3755
|
+
);
|
|
3756
|
+
updateSettings({ branchAvailability: nextSchedules });
|
|
3757
|
+
},
|
|
3758
|
+
loading,
|
|
3759
|
+
error: loadError,
|
|
3760
|
+
placeholder: "Buscar sedes para configurar su horario...",
|
|
3761
|
+
searchPlaceholder: "Buscar sede...",
|
|
3762
|
+
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3763
|
+
}
|
|
3764
|
+
) }),
|
|
3765
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-3 space-y-2", children: branches.filter(
|
|
3766
|
+
(branch) => selectedAvailabilityBranches.includes(getBranchName(branch))
|
|
3767
|
+
).map((branch) => {
|
|
3768
|
+
const name = getBranchName(branch);
|
|
3769
|
+
const schedule = branchAvailability[name] ?? {};
|
|
3770
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
3771
|
+
"div",
|
|
3772
|
+
{
|
|
3773
|
+
className: "space-y-3 rounded-lg border border-slate-200 bg-white p-3",
|
|
3774
|
+
children: [
|
|
3775
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
3776
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
3777
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3778
|
+
"button",
|
|
3779
|
+
{
|
|
3780
|
+
type: "button",
|
|
3781
|
+
onClick: () => {
|
|
3782
|
+
const nextSchedules = { ...branchAvailability };
|
|
3783
|
+
delete nextSchedules[name];
|
|
3784
|
+
updateSettings({ branchAvailability: nextSchedules });
|
|
3785
|
+
},
|
|
3786
|
+
"aria-label": `Quitar horario de ${name}`,
|
|
3787
|
+
title: `Quitar horario de ${name}`,
|
|
3788
|
+
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",
|
|
3789
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.X, { className: "h-4 w-4" })
|
|
3790
|
+
}
|
|
3791
|
+
)
|
|
3792
|
+
] }),
|
|
3793
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3794
|
+
AdminTimeRangePicker,
|
|
3795
|
+
{
|
|
3796
|
+
value: [
|
|
3797
|
+
toDayjsTime(schedule.start),
|
|
3798
|
+
toDayjsTime(schedule.end)
|
|
3799
|
+
],
|
|
3800
|
+
onChange: (times) => updateBranchAvailability(
|
|
3801
|
+
name,
|
|
3802
|
+
times?.[0] ?? null,
|
|
3803
|
+
times?.[1] ?? null
|
|
3804
|
+
),
|
|
3805
|
+
allowEmpty: [true, true],
|
|
3806
|
+
className: "w-full",
|
|
3807
|
+
format: TIME_DISPLAY_FORMAT,
|
|
3808
|
+
order: false,
|
|
3809
|
+
placeholder: ["Hora de inicio", "Hora de cierre"],
|
|
3810
|
+
use12Hours: true
|
|
3811
|
+
}
|
|
3812
|
+
)
|
|
3813
|
+
]
|
|
3814
|
+
},
|
|
3815
|
+
branch.id
|
|
3816
|
+
);
|
|
3817
|
+
}) })
|
|
3818
|
+
] }),
|
|
3819
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
3820
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
3821
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3822
|
+
"input",
|
|
3823
|
+
{
|
|
3824
|
+
type: "checkbox",
|
|
3825
|
+
checked: useBranchPricing,
|
|
3826
|
+
onChange: (event) => updateSettings({ useBranchPricing: event.target.checked }),
|
|
3827
|
+
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
3828
|
+
}
|
|
3829
|
+
),
|
|
3830
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
|
|
3831
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "block font-semibold", children: "Usar precio diferente por sede" }),
|
|
3832
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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." })
|
|
3833
|
+
] })
|
|
3834
|
+
] }),
|
|
3835
|
+
useBranchPricing && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-3 space-y-2", children: loading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "py-2 text-center text-xs text-slate-400", children: "Cargando sedes..." }) : loadError ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "alert", className: "py-2 text-center text-xs text-red-600", children: loadError }) : branches.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "py-2 text-center text-xs text-slate-400", children: "Agrega sedes a la colecci\xF3n antes de definir precios." }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
3836
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "text-xs text-slate-500", children: [
|
|
3837
|
+
"Precio global actual: $",
|
|
3838
|
+
globalPrice.toLocaleString("es-CO")
|
|
3839
|
+
] }),
|
|
3840
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3841
|
+
SearchableMultiSelect,
|
|
3842
|
+
{
|
|
3843
|
+
options: branches.map((branch) => ({
|
|
3844
|
+
value: getBranchName(branch),
|
|
3845
|
+
label: getBranchName(branch)
|
|
3846
|
+
})),
|
|
3847
|
+
value: selectedPriceBranches,
|
|
3848
|
+
onChange: (next) => {
|
|
3849
|
+
const removed = selectedPriceBranches.filter(
|
|
3850
|
+
(name) => !next.includes(name)
|
|
3851
|
+
);
|
|
3852
|
+
const nextPrices = { ...prices };
|
|
3853
|
+
removed.forEach((name) => delete nextPrices[name]);
|
|
3854
|
+
updateSettings({
|
|
3855
|
+
priceBranches: next,
|
|
3856
|
+
prices: nextPrices
|
|
3857
|
+
});
|
|
3858
|
+
},
|
|
3859
|
+
loading,
|
|
3860
|
+
error: loadError,
|
|
3861
|
+
placeholder: "Buscar y agregar sedes...",
|
|
3862
|
+
searchPlaceholder: "Buscar sede...",
|
|
3863
|
+
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3864
|
+
}
|
|
3865
|
+
),
|
|
3866
|
+
branches.filter(
|
|
3867
|
+
(branch) => selectedPriceBranches.includes(getBranchName(branch))
|
|
3868
|
+
).map((branch) => {
|
|
3869
|
+
const name = getBranchName(branch);
|
|
3870
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
3871
|
+
"div",
|
|
3872
|
+
{
|
|
3873
|
+
className: "space-y-2 rounded-lg border border-slate-200 bg-white p-3",
|
|
3874
|
+
children: [
|
|
3875
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
3876
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
3877
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3878
|
+
"button",
|
|
3879
|
+
{
|
|
3880
|
+
type: "button",
|
|
3881
|
+
onClick: () => {
|
|
3882
|
+
const nextPrices = { ...prices };
|
|
3883
|
+
delete nextPrices[name];
|
|
3884
|
+
updateSettings({
|
|
3885
|
+
priceBranches: selectedPriceBranches.filter(
|
|
3886
|
+
(selected) => selected !== name
|
|
3887
|
+
),
|
|
3888
|
+
prices: nextPrices
|
|
3889
|
+
});
|
|
3890
|
+
},
|
|
3891
|
+
"aria-label": `Quitar ${name} de precios por sede`,
|
|
3892
|
+
title: `Quitar ${name}`,
|
|
3893
|
+
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",
|
|
3894
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.X, { className: "h-4 w-4" })
|
|
3895
|
+
}
|
|
3896
|
+
)
|
|
3897
|
+
] }),
|
|
3898
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block w-full", children: [
|
|
3899
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "sr-only", children: [
|
|
3900
|
+
"Precio para ",
|
|
3901
|
+
name
|
|
3902
|
+
] }),
|
|
3903
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3904
|
+
FormattedNumberInput,
|
|
3905
|
+
{
|
|
3906
|
+
value: prices[name] ?? "",
|
|
3907
|
+
onChange: (price) => updateBranchPrice(
|
|
3908
|
+
name,
|
|
3909
|
+
price === null ? "" : String(price)
|
|
3910
|
+
),
|
|
3911
|
+
isPrice: true,
|
|
3912
|
+
allowEmpty: true,
|
|
3913
|
+
placeholder: String(globalPrice),
|
|
3914
|
+
className: "bg-white text-right",
|
|
3915
|
+
containerClassName: "w-full"
|
|
3916
|
+
}
|
|
3917
|
+
)
|
|
3918
|
+
] })
|
|
3919
|
+
]
|
|
3920
|
+
},
|
|
3921
|
+
branch.id
|
|
3922
|
+
);
|
|
3923
|
+
})
|
|
3924
|
+
] }) })
|
|
3925
|
+
] }),
|
|
3926
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "border-t border-slate-200 pt-4", children: [
|
|
3927
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-start gap-3 text-sm text-slate-700", children: [
|
|
3928
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3929
|
+
"input",
|
|
3930
|
+
{
|
|
3931
|
+
type: "checkbox",
|
|
3932
|
+
checked: useBranchDiscounts,
|
|
3933
|
+
onChange: (event) => updateSettings({ useBranchDiscounts: event.target.checked }),
|
|
3934
|
+
className: "mt-0.5 h-4 w-4 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
|
|
3935
|
+
}
|
|
3936
|
+
),
|
|
3937
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
|
|
3938
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "block font-semibold", children: "Usar descuento diferente por sede" }),
|
|
3939
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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." })
|
|
3940
|
+
] })
|
|
3941
|
+
] }),
|
|
3942
|
+
useBranchDiscounts && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mt-3 space-y-2", children: loading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "py-2 text-center text-xs text-slate-400", children: "Cargando sedes..." }) : loadError ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "alert", className: "py-2 text-center text-xs text-red-600", children: loadError }) : branches.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "py-2 text-center text-xs text-slate-400", children: "Agrega sedes a la colecci\xF3n antes de definir descuentos." }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
3943
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "text-xs text-slate-500", children: [
|
|
3944
|
+
"Descuento global actual: ",
|
|
3945
|
+
globalDiscount,
|
|
3946
|
+
"%"
|
|
3947
|
+
] }),
|
|
3948
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3949
|
+
SearchableMultiSelect,
|
|
3950
|
+
{
|
|
3951
|
+
options: branches.map((branch) => ({
|
|
3952
|
+
value: getBranchName(branch),
|
|
3953
|
+
label: getBranchName(branch)
|
|
3954
|
+
})),
|
|
3955
|
+
value: selectedDiscountBranches,
|
|
3956
|
+
onChange: (next) => {
|
|
3957
|
+
const removed = selectedDiscountBranches.filter(
|
|
3958
|
+
(name) => !next.includes(name)
|
|
3959
|
+
);
|
|
3960
|
+
const nextDiscounts = { ...discounts };
|
|
3961
|
+
removed.forEach((name) => delete nextDiscounts[name]);
|
|
3962
|
+
updateSettings({
|
|
3963
|
+
discountBranches: next,
|
|
3964
|
+
discounts: nextDiscounts
|
|
3965
|
+
});
|
|
3966
|
+
},
|
|
3967
|
+
loading,
|
|
3968
|
+
error: loadError,
|
|
3969
|
+
placeholder: "Buscar y agregar sedes...",
|
|
3970
|
+
searchPlaceholder: "Buscar sede...",
|
|
3971
|
+
emptyMessage: "No hay sedes registradas todav\xEDa."
|
|
3972
|
+
}
|
|
3973
|
+
),
|
|
3974
|
+
branches.filter(
|
|
3975
|
+
(branch) => selectedDiscountBranches.includes(getBranchName(branch))
|
|
3976
|
+
).map((branch) => {
|
|
3977
|
+
const name = getBranchName(branch);
|
|
3978
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
3979
|
+
"div",
|
|
3980
|
+
{
|
|
3981
|
+
className: "space-y-2 rounded-lg border border-slate-200 bg-white p-3",
|
|
3982
|
+
children: [
|
|
3983
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex min-w-0 items-center justify-between gap-3", children: [
|
|
3984
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "min-w-0 whitespace-normal break-words text-sm font-semibold leading-5 text-slate-800", children: name }),
|
|
3985
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
3986
|
+
"button",
|
|
3987
|
+
{
|
|
3988
|
+
type: "button",
|
|
3989
|
+
onClick: () => {
|
|
3990
|
+
const nextDiscounts = { ...discounts };
|
|
3991
|
+
delete nextDiscounts[name];
|
|
3992
|
+
updateSettings({
|
|
3993
|
+
discountBranches: selectedDiscountBranches.filter(
|
|
3994
|
+
(selected) => selected !== name
|
|
3995
|
+
),
|
|
3996
|
+
discounts: nextDiscounts
|
|
3997
|
+
});
|
|
3998
|
+
},
|
|
3999
|
+
"aria-label": `Quitar descuento de ${name}`,
|
|
4000
|
+
title: `Quitar ${name}`,
|
|
4001
|
+
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",
|
|
4002
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.X, { className: "h-4 w-4" })
|
|
4003
|
+
}
|
|
4004
|
+
)
|
|
4005
|
+
] }),
|
|
4006
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "block w-full", children: [
|
|
4007
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "sr-only", children: [
|
|
4008
|
+
"Descuento para ",
|
|
4009
|
+
name
|
|
4010
|
+
] }),
|
|
4011
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4012
|
+
FormattedNumberInput,
|
|
4013
|
+
{
|
|
4014
|
+
value: discounts[name] ?? "",
|
|
4015
|
+
onChange: (discount) => updateBranchDiscount(
|
|
4016
|
+
name,
|
|
4017
|
+
discount === null ? "" : String(discount)
|
|
4018
|
+
),
|
|
4019
|
+
isPercent: true,
|
|
4020
|
+
allowEmpty: true,
|
|
4021
|
+
placeholder: String(globalDiscount),
|
|
4022
|
+
className: "bg-white text-right",
|
|
4023
|
+
containerClassName: "w-full"
|
|
4024
|
+
}
|
|
4025
|
+
)
|
|
4026
|
+
] })
|
|
4027
|
+
]
|
|
4028
|
+
},
|
|
4029
|
+
branch.id
|
|
4030
|
+
);
|
|
4031
|
+
})
|
|
4032
|
+
] }) })
|
|
4033
|
+
] })
|
|
4034
|
+
] });
|
|
4035
|
+
}
|
|
4036
|
+
function BranchSettingsSummary({ value }) {
|
|
4037
|
+
if (!value || typeof value !== "object") return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "Todas las sedes" });
|
|
4038
|
+
const settings = value;
|
|
4039
|
+
const names = Array.isArray(settings.branches) ? settings.branches : [];
|
|
4040
|
+
const locationSummary = settings.allBranches === false ? names.length > 0 ? names.join(", ") : "Sin sedes" : "Todas las sedes";
|
|
4041
|
+
const pricingSummary = settings.useBranchPricing ? " \xB7 Precio por sede" : " \xB7 Precio global";
|
|
4042
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: locationSummary + pricingSummary });
|
|
4043
|
+
}
|
|
4044
|
+
function SearchableMultiSelect({
|
|
4045
|
+
options,
|
|
4046
|
+
value,
|
|
4047
|
+
onChange,
|
|
4048
|
+
placeholder,
|
|
4049
|
+
searchable = true,
|
|
4050
|
+
searchPlaceholder = "Buscar...",
|
|
4051
|
+
emptyMessage = "No hay opciones registradas todav\xEDa.",
|
|
4052
|
+
loading = false,
|
|
4053
|
+
error,
|
|
4054
|
+
max
|
|
4055
|
+
}) {
|
|
4056
|
+
const [open, setOpen] = (0, import_react5.useState)(false);
|
|
4057
|
+
const [search, setSearch] = (0, import_react5.useState)("");
|
|
4058
|
+
const rootRef = (0, import_react5.useRef)(null);
|
|
4059
|
+
(0, import_react5.useEffect)(() => {
|
|
4060
|
+
if (!open) return;
|
|
4061
|
+
const handlePointerDown = (event) => {
|
|
4062
|
+
if (event.target instanceof Node && !rootRef.current?.contains(event.target)) {
|
|
4063
|
+
setOpen(false);
|
|
4064
|
+
}
|
|
4065
|
+
};
|
|
4066
|
+
const handleKeyDown = (event) => {
|
|
4067
|
+
if (event.key === "Escape") setOpen(false);
|
|
4068
|
+
};
|
|
4069
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
4070
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
4071
|
+
return () => {
|
|
4072
|
+
document.removeEventListener("pointerdown", handlePointerDown);
|
|
4073
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
4074
|
+
};
|
|
4075
|
+
}, [open]);
|
|
4076
|
+
const normalize = (text) => text.toLocaleLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
|
4077
|
+
const normalizedSearch = searchable ? normalize(search.trim()) : "";
|
|
4078
|
+
const visibleOptions = options.filter(
|
|
4079
|
+
(option) => normalize(option.label).includes(normalizedSearch)
|
|
4080
|
+
);
|
|
4081
|
+
const selectedOptions = value.map(
|
|
4082
|
+
(selected) => options.find((option) => option.value === selected) || {
|
|
4083
|
+
value: selected,
|
|
4084
|
+
label: selected
|
|
4085
|
+
}
|
|
4086
|
+
).filter(Boolean);
|
|
4087
|
+
const toggleOption = (optionValue) => {
|
|
4088
|
+
if (value.includes(optionValue)) {
|
|
4089
|
+
onChange(value.filter((selected) => selected !== optionValue));
|
|
4090
|
+
return;
|
|
4091
|
+
}
|
|
4092
|
+
if (!max || value.length < max) {
|
|
4093
|
+
onChange([...value, optionValue]);
|
|
4094
|
+
}
|
|
4095
|
+
};
|
|
4096
|
+
const toggleVisibleOptions = () => {
|
|
4097
|
+
const visibleValues = visibleOptions.map((option) => option.value);
|
|
4098
|
+
const hasUnselected = visibleValues.some(
|
|
4099
|
+
(optionValue) => !value.includes(optionValue)
|
|
4100
|
+
);
|
|
4101
|
+
if (hasUnselected) {
|
|
4102
|
+
const merged = [.../* @__PURE__ */ new Set([...value, ...visibleValues])];
|
|
4103
|
+
onChange(max ? merged.slice(0, max) : merged);
|
|
4104
|
+
} else {
|
|
4105
|
+
onChange(value.filter((selected) => !visibleValues.includes(selected)));
|
|
4106
|
+
}
|
|
4107
|
+
};
|
|
4108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { ref: rootRef, className: "relative", children: [
|
|
4109
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
4110
|
+
"button",
|
|
4111
|
+
{
|
|
4112
|
+
type: "button",
|
|
4113
|
+
"aria-haspopup": "listbox",
|
|
4114
|
+
"aria-expanded": open,
|
|
4115
|
+
onClick: () => setOpen((isOpen) => !isOpen),
|
|
4116
|
+
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",
|
|
4117
|
+
children: [
|
|
4118
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "flex min-w-0 flex-1 flex-wrap items-center gap-1.5", children: selectedOptions.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-slate-400", children: placeholder }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
4119
|
+
selectedOptions.slice(0, 2).map((option) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4120
|
+
"span",
|
|
4121
|
+
{
|
|
4122
|
+
className: "max-w-full truncate rounded-md bg-indigo-50 px-2 py-1 text-xs font-medium text-indigo-700",
|
|
4123
|
+
children: option.label
|
|
4124
|
+
},
|
|
4125
|
+
option.value
|
|
4126
|
+
)),
|
|
4127
|
+
selectedOptions.length > 2 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "rounded-md bg-slate-100 px-2 py-1 text-xs font-semibold text-slate-600", children: [
|
|
4128
|
+
"+",
|
|
4129
|
+
selectedOptions.length - 2
|
|
4130
|
+
] })
|
|
4131
|
+
] }) }),
|
|
4132
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "flex shrink-0 items-center gap-2 text-xs text-slate-400", children: [
|
|
4133
|
+
selectedOptions.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { children: [
|
|
4134
|
+
selectedOptions.length,
|
|
4135
|
+
" seleccionada",
|
|
4136
|
+
selectedOptions.length === 1 ? "" : "s"
|
|
4137
|
+
] }),
|
|
4138
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4139
|
+
import_lucide_react2.ChevronDown,
|
|
4140
|
+
{
|
|
4141
|
+
className: `h-4 w-4 transition-transform ${open ? "rotate-180" : ""}`
|
|
4142
|
+
}
|
|
4143
|
+
)
|
|
4144
|
+
] })
|
|
4145
|
+
]
|
|
4146
|
+
}
|
|
4147
|
+
),
|
|
4148
|
+
open && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("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: [
|
|
4149
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-2 border-b border-slate-100 p-3", children: [
|
|
4150
|
+
searchable && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
|
|
4151
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Search, { className: "pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-slate-400" }),
|
|
4152
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4153
|
+
"input",
|
|
4154
|
+
{
|
|
4155
|
+
type: "search",
|
|
4156
|
+
autoFocus: true,
|
|
4157
|
+
value: search,
|
|
4158
|
+
onChange: (event) => setSearch(event.target.value),
|
|
4159
|
+
placeholder: searchPlaceholder,
|
|
4160
|
+
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"
|
|
4161
|
+
}
|
|
4162
|
+
)
|
|
4163
|
+
] }),
|
|
4164
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-between gap-2 text-xs", children: [
|
|
4165
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "font-medium text-slate-500", children: [
|
|
4166
|
+
value.length,
|
|
4167
|
+
" seleccionada",
|
|
4168
|
+
value.length === 1 ? "" : "s",
|
|
4169
|
+
max ? ` \xB7 m\xE1ximo ${max}` : ""
|
|
4170
|
+
] }),
|
|
4171
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
|
|
4172
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4173
|
+
"button",
|
|
4174
|
+
{
|
|
4175
|
+
type: "button",
|
|
4176
|
+
disabled: visibleOptions.length === 0 || loading || !!error,
|
|
4177
|
+
onClick: toggleVisibleOptions,
|
|
4178
|
+
className: "font-semibold text-indigo-600 hover:text-indigo-800 disabled:cursor-not-allowed disabled:text-slate-300",
|
|
4179
|
+
children: visibleOptions.length > 0 && visibleOptions.every((option) => value.includes(option.value)) ? searchable ? "Quitar visibles" : "Quitar todas" : searchable ? "Seleccionar visibles" : "Seleccionar todas"
|
|
4180
|
+
}
|
|
4181
|
+
),
|
|
4182
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-slate-300", children: "\xB7" }),
|
|
4183
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4184
|
+
"button",
|
|
4185
|
+
{
|
|
4186
|
+
type: "button",
|
|
4187
|
+
disabled: value.length === 0,
|
|
4188
|
+
onClick: () => onChange([]),
|
|
4189
|
+
className: "font-semibold text-slate-500 hover:text-slate-700 disabled:cursor-not-allowed disabled:text-slate-300",
|
|
4190
|
+
children: "Limpiar"
|
|
4191
|
+
}
|
|
4192
|
+
)
|
|
4193
|
+
] })
|
|
4194
|
+
] })
|
|
4195
|
+
] }),
|
|
4196
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { role: "listbox", "aria-multiselectable": "true", className: "max-h-56 overflow-y-auto p-2", children: loading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "py-4 text-center text-xs text-slate-400", children: "Cargando opciones..." }) : error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { role: "alert", className: "py-4 text-center text-xs text-red-600", children: error }) : visibleOptions.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "py-4 text-center text-xs text-slate-400", children: options.length === 0 ? emptyMessage : "No hay resultados para la b\xFAsqueda." }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "space-y-1", children: visibleOptions.map((option) => {
|
|
4197
|
+
const isSelected = value.includes(option.value);
|
|
4198
|
+
const isAtMax = !!max && value.length >= max && !isSelected;
|
|
4199
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
4200
|
+
"button",
|
|
4201
|
+
{
|
|
4202
|
+
type: "button",
|
|
4203
|
+
role: "option",
|
|
4204
|
+
"aria-selected": isSelected,
|
|
4205
|
+
disabled: isAtMax,
|
|
4206
|
+
onClick: () => toggleOption(option.value),
|
|
4207
|
+
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`,
|
|
4208
|
+
children: [
|
|
4209
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4210
|
+
"span",
|
|
4211
|
+
{
|
|
4212
|
+
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"}`,
|
|
4213
|
+
children: isSelected && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Check, { className: "h-3 w-3" })
|
|
4214
|
+
}
|
|
4215
|
+
),
|
|
4216
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "truncate", children: option.label })
|
|
4217
|
+
]
|
|
4218
|
+
},
|
|
4219
|
+
option.value
|
|
4220
|
+
);
|
|
4221
|
+
}) }) })
|
|
4222
|
+
] })
|
|
4223
|
+
] });
|
|
4224
|
+
}
|
|
4225
|
+
function ReferenceSelect({
|
|
4226
|
+
collectionId,
|
|
4227
|
+
displayField = "name",
|
|
4228
|
+
valueField = "name",
|
|
4229
|
+
fallbackOptions,
|
|
4230
|
+
multiple = false,
|
|
4231
|
+
searchable = false,
|
|
4232
|
+
max,
|
|
4233
|
+
value,
|
|
4234
|
+
onChange
|
|
4235
|
+
}) {
|
|
3203
4236
|
const ctx = useCmsContext();
|
|
3204
4237
|
const [options, setOptions] = (0, import_react5.useState)([]);
|
|
3205
4238
|
const [loading, setLoading] = (0, import_react5.useState)(true);
|
|
3206
4239
|
(0, import_react5.useEffect)(() => {
|
|
3207
4240
|
if (!collectionId) {
|
|
4241
|
+
if (fallbackOptions && fallbackOptions.length > 0) {
|
|
4242
|
+
setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
|
|
4243
|
+
}
|
|
3208
4244
|
setLoading(false);
|
|
3209
4245
|
return;
|
|
3210
4246
|
}
|
|
3211
4247
|
setLoading(true);
|
|
3212
4248
|
ctx.adapter.listEntries(collectionId).then((res) => {
|
|
3213
|
-
|
|
4249
|
+
const fromCollection = res.map((r) => {
|
|
4250
|
+
const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
|
|
4251
|
+
const lab = String(r[displayField] || r.name || r.id);
|
|
4252
|
+
return { value: val, label: lab };
|
|
4253
|
+
});
|
|
4254
|
+
const fallbackList = (fallbackOptions || []).map(
|
|
4255
|
+
(opt) => typeof opt === "string" ? { value: opt, label: opt } : opt
|
|
4256
|
+
);
|
|
4257
|
+
const combined = [...fromCollection];
|
|
4258
|
+
for (const fb of fallbackList) {
|
|
4259
|
+
if (!combined.some((c) => c.value === fb.value || c.label === fb.label)) {
|
|
4260
|
+
combined.push(fb);
|
|
4261
|
+
}
|
|
4262
|
+
}
|
|
4263
|
+
setOptions(combined);
|
|
4264
|
+
setLoading(false);
|
|
4265
|
+
}).catch(() => {
|
|
4266
|
+
if (fallbackOptions && fallbackOptions.length > 0) {
|
|
4267
|
+
setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
|
|
4268
|
+
}
|
|
3214
4269
|
setLoading(false);
|
|
3215
|
-
})
|
|
3216
|
-
}, [collectionId, displayField, ctx.adapter]);
|
|
4270
|
+
});
|
|
4271
|
+
}, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter]);
|
|
4272
|
+
if (multiple) {
|
|
4273
|
+
const selectedList = Array.isArray(value) ? value.map(String) : typeof value === "string" && value.trim() ? value.split(",").map((s) => s.trim()).filter(Boolean) : [];
|
|
4274
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4275
|
+
SearchableMultiSelect,
|
|
4276
|
+
{
|
|
4277
|
+
options,
|
|
4278
|
+
value: selectedList,
|
|
4279
|
+
onChange,
|
|
4280
|
+
loading,
|
|
4281
|
+
searchable,
|
|
4282
|
+
placeholder: "Seleccionar opciones...",
|
|
4283
|
+
searchPlaceholder: `Buscar ${collectionId === "sauces" ? "salsa" : collectionId === "extras" ? "adicional" : "opci\xF3n"}...`,
|
|
4284
|
+
emptyMessage: "No hay opciones registradas todav\xEDa.",
|
|
4285
|
+
max
|
|
4286
|
+
}
|
|
4287
|
+
);
|
|
4288
|
+
}
|
|
4289
|
+
const singleVal = String(value ?? "");
|
|
4290
|
+
const displayOptions = [...options];
|
|
4291
|
+
if (singleVal && !displayOptions.some((o) => o.value === singleVal)) {
|
|
4292
|
+
displayOptions.unshift({ value: singleVal, label: singleVal });
|
|
4293
|
+
}
|
|
3217
4294
|
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
|
|
3218
4295
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
|
|
3219
4296
|
"select",
|
|
3220
4297
|
{
|
|
3221
|
-
value,
|
|
4298
|
+
value: singleVal,
|
|
3222
4299
|
onChange: (e) => onChange(e.target.value),
|
|
3223
4300
|
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
4301
|
children: [
|
|
3225
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: loading ? "
|
|
3226
|
-
|
|
4302
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: loading ? "Cargando opciones..." : "-- Selecciona una opci\xF3n --" }),
|
|
4303
|
+
displayOptions.map((o, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: o.value, children: o.label }, `${o.value}-${idx}`))
|
|
3227
4304
|
]
|
|
3228
4305
|
}
|
|
3229
4306
|
),
|
|
3230
4307
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
|
|
3231
4308
|
] });
|
|
3232
4309
|
}
|
|
3233
|
-
function ReferenceTableCell({
|
|
4310
|
+
function ReferenceTableCell({
|
|
4311
|
+
collectionId,
|
|
4312
|
+
entryId,
|
|
4313
|
+
displayField = "name",
|
|
4314
|
+
valueField = "name",
|
|
4315
|
+
multiple = false
|
|
4316
|
+
}) {
|
|
3234
4317
|
const ctx = useCmsContext();
|
|
3235
|
-
const [
|
|
4318
|
+
const [labels, setLabels] = (0, import_react5.useState)([]);
|
|
4319
|
+
const ids = Array.isArray(entryId) ? entryId.map(String) : typeof entryId === "string" && entryId.trim() ? multiple ? entryId.split(",").map((s) => s.trim()).filter(Boolean) : [entryId] : [];
|
|
3236
4320
|
(0, import_react5.useEffect)(() => {
|
|
3237
|
-
if (!collectionId ||
|
|
4321
|
+
if (!collectionId || ids.length === 0) {
|
|
4322
|
+
setLabels(ids);
|
|
4323
|
+
return;
|
|
4324
|
+
}
|
|
3238
4325
|
ctx.adapter.listEntries(collectionId).then((res) => {
|
|
3239
|
-
const
|
|
3240
|
-
|
|
4326
|
+
const resolved = ids.map((id) => {
|
|
4327
|
+
const match = res.find(
|
|
4328
|
+
(r) => valueField && String(r[valueField]) === id || r.id === id || String(r.name) === id || String(r.slug) === id
|
|
4329
|
+
);
|
|
4330
|
+
return match ? String(match[displayField] || match.name || match.id) : id;
|
|
4331
|
+
});
|
|
4332
|
+
setLabels(resolved);
|
|
3241
4333
|
}).catch(() => {
|
|
4334
|
+
setLabels(ids);
|
|
3242
4335
|
});
|
|
3243
|
-
}, [collectionId,
|
|
3244
|
-
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children:
|
|
4336
|
+
}, [collectionId, displayField, valueField, JSON.stringify(ids), ctx.adapter]);
|
|
4337
|
+
if (labels.length === 0) return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: "-" });
|
|
4338
|
+
if (multiple || labels.length > 1) {
|
|
4339
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-wrap gap-1 max-w-[260px]", children: [
|
|
4340
|
+
labels.slice(0, 3).map((lbl, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("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)),
|
|
4341
|
+
labels.length > 3 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "inline-flex px-1.5 py-0.5 rounded bg-slate-200 text-slate-600 text-[10px] font-bold", children: [
|
|
4342
|
+
"+",
|
|
4343
|
+
labels.length - 3
|
|
4344
|
+
] })
|
|
4345
|
+
] });
|
|
4346
|
+
}
|
|
4347
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: labels[0] });
|
|
3245
4348
|
}
|
|
3246
4349
|
|
|
3247
4350
|
// src/admin/AdminLogin.tsx
|