admin-lib-cms 1.2.6 → 1.2.7

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.mjs CHANGED
@@ -444,8 +444,8 @@ function useSubmit(formId) {
444
444
  }
445
445
 
446
446
  // src/editable.tsx
447
- import { createElement, useEffect as useEffect3, useState as useState4, Fragment as Fragment2 } from "react";
448
- import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
447
+ import { createElement, isValidElement, useEffect as useEffect3, useState as useState4, Fragment as Fragment2 } from "react";
448
+ import { Fragment as Fragment3, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
449
449
  function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField, reorderable, sortable) {
450
450
  const ctx = useCmsOptional();
451
451
  useEffect3(() => {
@@ -610,7 +610,17 @@ function EditableLink({
610
610
  className,
611
611
  target
612
612
  }) {
613
- const defaultText = text ?? (typeof children === "string" ? children : "");
613
+ let defaultText = text ?? "";
614
+ if (!defaultText) {
615
+ if (typeof children === "string") {
616
+ defaultText = children;
617
+ } else if (Array.isArray(children)) {
618
+ const strChild = children.find((c) => typeof c === "string");
619
+ if (typeof strChild === "string") {
620
+ defaultText = strChild.trim();
621
+ }
622
+ }
623
+ }
614
624
  const ctx = useRegister(id, "link", label, section, pageId, { href, text: defaultText });
615
625
  const override = ctx?.overrides[id];
616
626
  const hrefValue = override?.href ?? href;
@@ -626,8 +636,34 @@ function EditableLink({
626
636
  const isExternal = hrefValue.startsWith("http");
627
637
  const computedTarget = target || (isExternal ? "_blank" : void 0);
628
638
  const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
629
- const content = typeof children !== "undefined" ? children : textValue;
630
- const isEmpty = !content || String(content).trim() === "";
639
+ let content;
640
+ if (typeof children === "function") {
641
+ content = children(textValue);
642
+ } else if (override && typeof override.text === "string" && override.text !== "") {
643
+ if (Array.isArray(children)) {
644
+ let replaced = false;
645
+ content = children.map((c) => {
646
+ if (typeof c === "string" && !replaced) {
647
+ replaced = true;
648
+ return override.text;
649
+ }
650
+ return c;
651
+ });
652
+ } else if (isValidElement(children)) {
653
+ content = /* @__PURE__ */ jsxs3(Fragment3, { children: [
654
+ override.text,
655
+ " ",
656
+ children
657
+ ] });
658
+ } else {
659
+ content = override.text;
660
+ }
661
+ } else if (typeof children !== "undefined") {
662
+ content = children;
663
+ } else {
664
+ content = textValue;
665
+ }
666
+ const isEmpty = !content || typeof content === "string" && content.trim() === "";
631
667
  const renderContent = active && isEmpty ? `[Empty Link: ${label || id}]` : content;
632
668
  return /* @__PURE__ */ jsx4(
633
669
  "a",
@@ -751,7 +787,7 @@ function EditableReference({
751
787
  }
752
788
 
753
789
  // src/admin/AdminApp.tsx
754
- import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef2, useState as useState5 } from "react";
790
+ import { createElement as createElement2, useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef2, useState as useState5 } from "react";
755
791
  import {
756
792
  FileText,
757
793
  Boxes,
@@ -782,8 +818,8 @@ import {
782
818
  Check,
783
819
  GripVertical
784
820
  } from "lucide-react";
785
- import { CreditCard as CreditCard2 } from "lucide-react";
786
- import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
821
+ import { CreditCard as CreditCard2, BarChart3 } from "lucide-react";
822
+ import { Fragment as Fragment4, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
787
823
  async function handleImageFile(file, onUrl, uploadImage) {
788
824
  if (uploadImage) {
789
825
  try {
@@ -798,17 +834,32 @@ async function handleImageFile(file, onUrl, uploadImage) {
798
834
  reader.onload = (ev) => onUrl(ev.target?.result);
799
835
  reader.readAsDataURL(file);
800
836
  }
801
- function AdminApp({ apiUrl, projectId, email }) {
802
- if (projectId) {
803
- return /* @__PURE__ */ jsx5(SubscriptionProvider, { apiUrl, projectId, email, children: /* @__PURE__ */ jsx5(AdminAppContent, {}) });
837
+ function AdminApp(props) {
838
+ if (props.projectId) {
839
+ return /* @__PURE__ */ jsx5(SubscriptionProvider, { apiUrl: props.apiUrl, projectId: props.projectId, email: props.email, children: /* @__PURE__ */ jsx5(AdminAppContent, { ...props }) });
804
840
  }
805
- return /* @__PURE__ */ jsx5(AdminAppContent, {});
841
+ return /* @__PURE__ */ jsx5(AdminAppContent, { ...props });
806
842
  }
807
- function AdminAppContent() {
808
- const [section, setSection] = useState5("pages");
843
+ function AdminAppContent(props) {
844
+ const ctx = useCmsContext();
845
+ const hasDashboard = Boolean(props.dashboard);
846
+ const [section, setSection] = useState5(hasDashboard ? "dashboard" : "pages");
809
847
  const [authChecking, setAuthChecking] = useState5(true);
810
848
  const [authenticated, setAuthenticated] = useState5(false);
811
- const ctx = useCmsContext();
849
+ const hideSettings = props.hideSettings ?? ctx.config.hideSettings ?? false;
850
+ const hideData = props.hideData ?? ctx.config.hideData ?? false;
851
+ const hideConfig = props.hideConfig ?? ctx.config.hideConfig ?? false;
852
+ const menuLabels = {
853
+ dashboard: "Dashboard",
854
+ pages: "P\xE1ginas",
855
+ collections: "Colecciones",
856
+ data: "Datos",
857
+ config: "Configuraci\xF3n",
858
+ settings: "Ajustes",
859
+ subscription: "Suscripci\xF3n",
860
+ ...ctx.config.menuLabels,
861
+ ...props.menuLabels
862
+ };
812
863
  useEffect4(() => {
813
864
  fetch("/api/admin/auth").then((res) => res.json()).then((data) => {
814
865
  if (data && data.authenticated) {
@@ -858,13 +909,22 @@ function AdminAppContent() {
858
909
  /* @__PURE__ */ jsx5("div", { className: "truncate font-bold text-lg text-slate-900", children: ctx.config.siteName ?? "Site Administration" })
859
910
  ] }),
860
911
  /* @__PURE__ */ jsxs4("nav", { className: "flex flex-row lg:flex-col overflow-x-auto lg:overflow-visible space-x-2 lg:space-x-0 lg:space-y-1.5 p-3 lg:p-4 text-sm font-medium hide-scrollbar", children: [
912
+ hasDashboard && /* @__PURE__ */ jsx5(
913
+ SideItem,
914
+ {
915
+ active: section === "dashboard",
916
+ onClick: () => setSection("dashboard"),
917
+ icon: /* @__PURE__ */ jsx5(BarChart3, { className: "h-4 w-4 shrink-0" }),
918
+ children: menuLabels.dashboard
919
+ }
920
+ ),
861
921
  /* @__PURE__ */ jsx5(
862
922
  SideItem,
863
923
  {
864
924
  active: section === "pages",
865
925
  onClick: () => setSection("pages"),
866
926
  icon: /* @__PURE__ */ jsx5(FileText, { className: "h-4 w-4 shrink-0" }),
867
- children: "Pages"
927
+ children: menuLabels.pages
868
928
  }
869
929
  ),
870
930
  /* @__PURE__ */ jsx5(
@@ -873,34 +933,34 @@ function AdminAppContent() {
873
933
  active: section === "collections",
874
934
  onClick: () => setSection("collections"),
875
935
  icon: /* @__PURE__ */ jsx5(Boxes, { className: "h-4 w-4 shrink-0" }),
876
- children: "Collections"
936
+ children: menuLabels.collections
877
937
  }
878
938
  ),
879
- /* @__PURE__ */ jsx5(
939
+ !hideData && /* @__PURE__ */ jsx5(
880
940
  SideItem,
881
941
  {
882
942
  active: section === "submissions",
883
943
  onClick: () => setSection("submissions"),
884
944
  icon: /* @__PURE__ */ jsx5(Inbox, { className: "h-4 w-4 shrink-0" }),
885
- children: "Data"
945
+ children: menuLabels.data
886
946
  }
887
947
  ),
888
- /* @__PURE__ */ jsx5(
948
+ !hideConfig && /* @__PURE__ */ jsx5(
889
949
  SideItem,
890
950
  {
891
951
  active: section === "config",
892
952
  onClick: () => setSection("config"),
893
953
  icon: /* @__PURE__ */ jsx5(SlidersHorizontal, { className: "h-4 w-4 shrink-0" }),
894
- children: "Config"
954
+ children: menuLabels.config
895
955
  }
896
956
  ),
897
- /* @__PURE__ */ jsx5(
957
+ !hideSettings && /* @__PURE__ */ jsx5(
898
958
  SideItem,
899
959
  {
900
960
  active: section === "settings",
901
961
  onClick: () => setSection("settings"),
902
962
  icon: /* @__PURE__ */ jsx5(SettingsIcon, { className: "h-4 w-4 shrink-0" }),
903
- children: "Settings"
963
+ children: menuLabels.settings
904
964
  }
905
965
  ),
906
966
  subscriptionCtx && /* @__PURE__ */ jsx5(
@@ -909,7 +969,7 @@ function AdminAppContent() {
909
969
  active: section === "subscription",
910
970
  onClick: () => setSection("subscription"),
911
971
  icon: /* @__PURE__ */ jsx5(CreditCard2, { className: "h-4 w-4 shrink-0" }),
912
- children: "Subscription"
972
+ children: menuLabels.subscription
913
973
  }
914
974
  )
915
975
  ] }),
@@ -935,11 +995,12 @@ function AdminAppContent() {
935
995
  ] })
936
996
  ] }),
937
997
  /* @__PURE__ */ jsxs4("main", { className: "flex-1 overflow-hidden relative flex flex-col", children: [
998
+ section === "dashboard" && hasDashboard && (typeof props.dashboard === "function" ? createElement2(props.dashboard) : props.dashboard),
938
999
  section === "pages" && /* @__PURE__ */ jsx5(PagesSection, {}),
939
1000
  section === "collections" && /* @__PURE__ */ jsx5(CollectionsSection, {}),
940
- section === "submissions" && /* @__PURE__ */ jsx5(SubmissionsSection, {}),
941
- section === "config" && /* @__PURE__ */ jsx5(ConfigSection, {}),
942
- section === "settings" && /* @__PURE__ */ jsx5(SettingsSection, {}),
1001
+ !hideData && section === "submissions" && /* @__PURE__ */ jsx5(SubmissionsSection, {}),
1002
+ !hideConfig && section === "config" && /* @__PURE__ */ jsx5(ConfigSection, {}),
1003
+ !hideSettings && section === "settings" && /* @__PURE__ */ jsx5(SettingsSection, {}),
943
1004
  section === "subscription" && /* @__PURE__ */ jsx5(SubscriptionPage, {})
944
1005
  ] })
945
1006
  ] })
@@ -1170,7 +1231,8 @@ function PageEditor({ page, showList, onToggleList }) {
1170
1231
  ref: iframeRef,
1171
1232
  src,
1172
1233
  title: page.name,
1173
- className: "h-full w-full bg-white"
1234
+ className: "h-full w-full bg-white",
1235
+ allow: "autoplay; encrypted-media; fullscreen"
1174
1236
  },
1175
1237
  src
1176
1238
  ) }) }),
@@ -1223,7 +1285,7 @@ function PageEditor({ page, showList, onToggleList }) {
1223
1285
  },
1224
1286
  onClose: () => setSelectedId(null)
1225
1287
  }
1226
- ) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
1288
+ ) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
1227
1289
  page.hideable && /* @__PURE__ */ jsxs4("div", { className: "px-5 py-4 border-b border-slate-100 bg-slate-50/50", children: [
1228
1290
  /* @__PURE__ */ jsxs4("div", { className: "flex items-center space-x-3", children: [
1229
1291
  /* @__PURE__ */ jsx5(
@@ -1497,66 +1559,121 @@ function FieldEditor({
1497
1559
  /* @__PURE__ */ jsx5("div", { className: "absolute inset-0 bg-black/40 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity", children: /* @__PURE__ */ jsx5("span", { className: "text-white text-xs font-medium px-2 py-1 bg-black/50 rounded backdrop-blur", children: "Preview" }) })
1498
1560
  ] }) : null
1499
1561
  ] }),
1500
- meta.type === "file" && /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
1501
- /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
1502
- /* @__PURE__ */ jsx5(
1503
- "input",
1504
- {
1505
- type: "url",
1506
- value: String(value ?? ""),
1507
- onChange: (e) => onChange(e.target.value),
1508
- placeholder: "https://... or upload PDF/file",
1509
- className: "w-full rounded-xl border border-slate-200 px-4 py-2.5 text-sm text-slate-800 shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-4 focus:ring-indigo-500/10 transition-all"
1510
- }
1511
- ),
1512
- /* @__PURE__ */ jsxs4("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-indigo-50 px-4 py-2.5 text-sm font-semibold text-indigo-700 hover:bg-indigo-100 transition-colors border border-indigo-100 flex items-center justify-center", children: [
1513
- "Upload File",
1562
+ meta.type === "file" && (() => {
1563
+ const currentVal = value ?? meta.defaultValue;
1564
+ const strVal = String(currentVal ?? "");
1565
+ const isVideo = strVal.match(/\.(mp4|webm|ogg|mov)(\?.*)?$/i) || strVal.includes("video");
1566
+ const isImg = strVal.match(/\.(jpe?g|png|webp|avif|gif|svg)(\?.*)?$/i) || strVal.includes("image");
1567
+ return /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
1568
+ /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
1514
1569
  /* @__PURE__ */ jsx5(
1515
1570
  "input",
1516
1571
  {
1517
- type: "file",
1518
- accept: "application/pdf,.pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,image/*",
1519
- className: "hidden",
1520
- onChange: (e) => {
1521
- const file = e.target.files?.[0];
1522
- if (file) {
1523
- void handleImageFile(file, onChange, ctx.uploadImage);
1572
+ type: "url",
1573
+ value: strVal,
1574
+ onChange: (e) => onChange(e.target.value),
1575
+ placeholder: "https://... o subir video/imagen",
1576
+ 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"
1577
+ }
1578
+ ),
1579
+ /* @__PURE__ */ jsxs4("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-indigo-50 px-4 py-2.5 text-sm font-semibold text-indigo-700 hover:bg-indigo-100 transition-colors border border-indigo-100 flex items-center justify-center", children: [
1580
+ "Subir",
1581
+ /* @__PURE__ */ jsx5(
1582
+ "input",
1583
+ {
1584
+ type: "file",
1585
+ accept: "video/*,image/*,application/pdf,.pdf,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document",
1586
+ className: "hidden",
1587
+ onChange: (e) => {
1588
+ const file = e.target.files?.[0];
1589
+ if (file) {
1590
+ void handleImageFile(file, onChange, ctx.uploadImage);
1591
+ }
1524
1592
  }
1525
1593
  }
1594
+ )
1595
+ ] })
1596
+ ] }),
1597
+ currentVal ? /* @__PURE__ */ jsx5("div", { className: "space-y-2", children: isVideo ? /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-2 bg-slate-900 overflow-hidden shadow-sm", children: [
1598
+ /* @__PURE__ */ jsx5(
1599
+ "video",
1600
+ {
1601
+ src: strVal,
1602
+ controls: true,
1603
+ autoPlay: true,
1604
+ muted: true,
1605
+ loop: true,
1606
+ playsInline: true,
1607
+ className: "max-h-52 w-full object-contain rounded-lg bg-black"
1608
+ },
1609
+ strVal
1610
+ ),
1611
+ /* @__PURE__ */ jsxs4("div", { className: "text-[10px] text-slate-300 font-mono truncate px-1 pt-1.5 flex items-center gap-1.5", children: [
1612
+ /* @__PURE__ */ jsx5("span", { className: "inline-block w-2 h-2 rounded-full bg-emerald-400 animate-pulse" }),
1613
+ /* @__PURE__ */ jsxs4("span", { className: "truncate", children: [
1614
+ "\u{1F3AC} ",
1615
+ strVal
1616
+ ] })
1617
+ ] })
1618
+ ] }) : isImg ? /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-2 bg-slate-50 overflow-hidden shadow-sm", children: [
1619
+ /* @__PURE__ */ jsx5(
1620
+ "img",
1621
+ {
1622
+ src: strVal,
1623
+ alt: "Preview",
1624
+ className: "max-h-52 w-full object-contain rounded-lg"
1625
+ }
1626
+ ),
1627
+ /* @__PURE__ */ jsxs4("div", { className: "text-[10px] text-slate-500 font-mono truncate px-1 pt-1.5", children: [
1628
+ "\u{1F5BC}\uFE0F ",
1629
+ strVal
1630
+ ] })
1631
+ ] }) : /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-3 bg-slate-50 text-xs font-mono text-slate-600 truncate flex items-center gap-2", children: [
1632
+ /* @__PURE__ */ jsx5("span", { children: "\u{1F4C4} Archivo:" }),
1633
+ /* @__PURE__ */ jsx5("span", { className: "truncate text-indigo-600 font-semibold", children: strVal })
1634
+ ] }) }) : null
1635
+ ] });
1636
+ })(),
1637
+ meta.type === "link" && (() => {
1638
+ const defaultObj = meta.defaultValue || {};
1639
+ const currentObj = value || {};
1640
+ const currentText = currentObj.text !== void 0 ? currentObj.text : defaultObj.text ?? "";
1641
+ const currentHref = currentObj.href !== void 0 ? currentObj.href : defaultObj.href ?? "";
1642
+ return /* @__PURE__ */ jsxs4("div", { className: "space-y-4 bg-slate-50 p-4 rounded-xl border border-slate-100", children: [
1643
+ /* @__PURE__ */ jsxs4("label", { className: "block", children: [
1644
+ /* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "Texto del Enlace" }),
1645
+ /* @__PURE__ */ jsx5(
1646
+ "input",
1647
+ {
1648
+ value: currentText,
1649
+ onChange: (e) => onChange({
1650
+ ...defaultObj,
1651
+ ...currentObj,
1652
+ text: e.target.value
1653
+ }),
1654
+ placeholder: "Texto del enlace",
1655
+ 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"
1656
+ }
1657
+ )
1658
+ ] }),
1659
+ /* @__PURE__ */ jsxs4("label", { className: "block", children: [
1660
+ /* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "URL de Destino" }),
1661
+ /* @__PURE__ */ jsx5(
1662
+ "input",
1663
+ {
1664
+ value: currentHref,
1665
+ onChange: (e) => onChange({
1666
+ ...defaultObj,
1667
+ ...currentObj,
1668
+ href: e.target.value
1669
+ }),
1670
+ placeholder: "https:// o /ruta",
1671
+ 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
1672
  }
1527
1673
  )
1528
1674
  ] })
1529
- ] }),
1530
- value ? /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-3 bg-slate-50 text-xs font-mono text-slate-600 truncate flex items-center gap-2", children: [
1531
- /* @__PURE__ */ jsx5("span", { children: "\u{1F4C4} File URL:" }),
1532
- /* @__PURE__ */ jsx5("span", { className: "truncate text-indigo-600 font-semibold", children: String(value) })
1533
- ] }) : null
1534
- ] }),
1535
- meta.type === "link" && /* @__PURE__ */ jsxs4("div", { className: "space-y-4 bg-slate-50 p-4 rounded-xl border border-slate-100", children: [
1536
- /* @__PURE__ */ jsxs4("label", { className: "block", children: [
1537
- /* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "Link Text" }),
1538
- /* @__PURE__ */ jsx5(
1539
- "input",
1540
- {
1541
- value: value?.text ?? "",
1542
- onChange: (e) => onChange({ ...value, text: e.target.value }),
1543
- className: "mt-1.5 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1544
- }
1545
- )
1546
- ] }),
1547
- /* @__PURE__ */ jsxs4("label", { className: "block", children: [
1548
- /* @__PURE__ */ jsx5("span", { className: "text-xs font-semibold text-slate-500 uppercase tracking-wide", children: "URL Target" }),
1549
- /* @__PURE__ */ jsx5(
1550
- "input",
1551
- {
1552
- value: value?.href ?? "",
1553
- onChange: (e) => onChange({ ...value, href: e.target.value }),
1554
- placeholder: "https:// or /path",
1555
- className: "mt-1.5 w-full rounded-lg border border-slate-200 px-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1556
- }
1557
- )
1558
- ] })
1559
- ] }),
1675
+ ] });
1676
+ })(),
1560
1677
  meta.type === "color" && /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-3 bg-slate-50 p-2 rounded-xl border border-slate-100", children: [
1561
1678
  /* @__PURE__ */ jsx5(
1562
1679
  "input",
@@ -1811,6 +1928,18 @@ function FieldEditor({
1811
1928
  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
1929
  children: schemaField.options?.map((opt) => /* @__PURE__ */ jsx5("option", { value: opt, children: opt }, opt))
1813
1930
  }
1931
+ ) : schemaField.type === "number" ? /* @__PURE__ */ jsx5(
1932
+ FormattedNumberInput,
1933
+ {
1934
+ value: item?.[schemaField.key],
1935
+ onChange: (val) => {
1936
+ const arr = Array.isArray(value) ? [...value] : [];
1937
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1938
+ onChange(arr);
1939
+ },
1940
+ isPrice: schemaField.key.toLowerCase().includes("price") || schemaField.key.toLowerCase().includes("precio"),
1941
+ className: "rounded-lg px-3 py-2 text-sm"
1942
+ }
1814
1943
  ) : /* @__PURE__ */ jsx5(
1815
1944
  "input",
1816
1945
  {
@@ -1919,11 +2048,11 @@ function CollectionsSection() {
1919
2048
  const ctx = useCmsContext();
1920
2049
  const collections = ctx.config.collections ?? [];
1921
2050
  const [selected, setSelected] = useState5(
1922
- collections[0] ?? null
2051
+ collections.find((c) => !c.isSeparator) ?? null
1923
2052
  );
1924
2053
  const [counts, setCounts] = useState5({});
1925
2054
  useEffect4(() => {
1926
- collections.forEach((c) => {
2055
+ collections.filter((c) => !c.isSeparator).forEach((c) => {
1927
2056
  ctx.adapter.listEntries(c.id).then((entries) => {
1928
2057
  setCounts((prev) => ({ ...prev, [c.id]: entries.length }));
1929
2058
  });
@@ -1933,20 +2062,43 @@ function CollectionsSection() {
1933
2062
  /* @__PURE__ */ jsxs4("div", { className: "w-full md:w-72 shrink-0 border-b md:border-b-0 md:border-r border-slate-200 bg-white/50 p-4", children: [
1934
2063
  /* @__PURE__ */ jsx5("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500", children: "Collections" }),
1935
2064
  /* @__PURE__ */ jsxs4("ul", { className: "flex overflow-x-auto gap-2 pb-2 md:block md:space-x-0 md:space-y-1 md:pb-0 md:overflow-visible", children: [
1936
- collections.map((c) => /* @__PURE__ */ jsx5("li", { className: "shrink-0 min-w-[140px] md:w-full md:min-w-0", children: /* @__PURE__ */ jsxs4(
1937
- "button",
1938
- {
1939
- onClick: () => setSelected(c),
1940
- 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"}`,
1941
- children: [
1942
- /* @__PURE__ */ jsx5("div", { className: selected?.id === c.id ? "text-slate-900" : "text-slate-700", children: c.name }),
1943
- /* @__PURE__ */ jsxs4("div", { className: `text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-500" : "text-slate-400"}`, children: [
1944
- counts[c.id] ?? 0,
1945
- " items"
1946
- ] })
1947
- ]
2065
+ collections.map((c, idx) => {
2066
+ if (c.isSeparator) {
2067
+ return /* @__PURE__ */ jsx5(
2068
+ "li",
2069
+ {
2070
+ className: "my-2 border-t border-slate-200/80"
2071
+ },
2072
+ c.id || `sep-${idx}`
2073
+ );
1948
2074
  }
1949
- ) }, c.id)),
2075
+ return /* @__PURE__ */ jsx5("li", { className: "shrink-0 min-w-[140px] md:w-full md:min-w-0", children: /* @__PURE__ */ jsxs4(
2076
+ "button",
2077
+ {
2078
+ onClick: () => setSelected(c),
2079
+ 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"}`,
2080
+ children: [
2081
+ /* @__PURE__ */ jsx5(
2082
+ "div",
2083
+ {
2084
+ className: selected?.id === c.id ? "text-slate-900" : "text-slate-700",
2085
+ children: c.name
2086
+ }
2087
+ ),
2088
+ /* @__PURE__ */ jsxs4(
2089
+ "div",
2090
+ {
2091
+ className: `text-xs mt-0.5 ${selected?.id === c.id ? "text-indigo-500" : "text-slate-400"}`,
2092
+ children: [
2093
+ counts[c.id] ?? 0,
2094
+ " items"
2095
+ ]
2096
+ }
2097
+ )
2098
+ ]
2099
+ }
2100
+ ) }, c.id);
2101
+ }),
1950
2102
  collections.length === 0 && /* @__PURE__ */ jsx5("li", { className: "px-3 py-6 text-center text-sm text-slate-500 bg-slate-50 rounded-lg border border-dashed border-slate-200", children: "No collections registered." })
1951
2103
  ] })
1952
2104
  ] }),
@@ -1991,6 +2143,8 @@ function CollectionEditor({ collection }) {
1991
2143
  base[f.id] = entries.length;
1992
2144
  } else if (f.defaultValue !== void 0) {
1993
2145
  base[f.id] = f.defaultValue;
2146
+ } else if (f.multiple) {
2147
+ base[f.id] = [];
1994
2148
  } else {
1995
2149
  base[f.id] = f.type === "boolean" ? false : f.type === "number" ? 0 : f.type === "select" ? f.options?.[0] ?? "" : "";
1996
2150
  }
@@ -2145,12 +2299,11 @@ function CollectionEditor({ collection }) {
2145
2299
  className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-500"
2146
2300
  }
2147
2301
  ) }) : f.type === "number" ? /* @__PURE__ */ jsx5(
2148
- "input",
2302
+ FormattedNumberInput,
2149
2303
  {
2150
- type: "number",
2151
- value: Number(editing[f.id] ?? 0),
2152
- onChange: (e) => setEditing({ ...editing, [f.id]: Number(e.target.value) }),
2153
- 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"
2304
+ value: editing[f.id],
2305
+ onChange: (val) => setEditing({ ...editing, [f.id]: val }),
2306
+ isPrice: f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.toLowerCase().includes("valor") || f.label.includes("$")
2154
2307
  }
2155
2308
  ) : f.type === "richtext" ? /* @__PURE__ */ jsx5(
2156
2309
  "textarea",
@@ -2193,29 +2346,36 @@ function CollectionEditor({ collection }) {
2193
2346
  children: "Generate"
2194
2347
  }
2195
2348
  )
2196
- ] }) : f.type === "reference" ? /* @__PURE__ */ jsx5(
2349
+ ] }) : f.type === "reference" || f.type === "select" && f.collection ? /* @__PURE__ */ jsx5(
2197
2350
  ReferenceSelect,
2198
2351
  {
2199
2352
  collectionId: f.collection,
2200
2353
  displayField: f.displayField,
2201
- value: String(editing[f.id] ?? ""),
2354
+ valueField: f.valueField,
2355
+ fallbackOptions: f.options,
2356
+ multiple: f.multiple,
2357
+ max: f.max,
2358
+ value: editing[f.id],
2202
2359
  onChange: (val) => setEditing({ ...editing, [f.id]: val })
2203
2360
  }
2204
- ) : f.type === "select" ? /* @__PURE__ */ jsxs4("div", { children: [
2205
- /* @__PURE__ */ jsx5(
2206
- "input",
2361
+ ) : f.type === "select" ? /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
2362
+ /* @__PURE__ */ jsxs4(
2363
+ "select",
2207
2364
  {
2208
- list: `${f.id}-list`,
2209
2365
  value: String(editing[f.id] ?? ""),
2210
2366
  onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
2211
- 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"
2367
+ 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",
2368
+ children: [
2369
+ /* @__PURE__ */ jsx5("option", { value: "", children: "-- Selecciona una opci\xF3n --" }),
2370
+ f.options?.map((opt) => {
2371
+ const val = typeof opt === "string" ? opt : opt.value;
2372
+ const lab = typeof opt === "string" ? opt : opt.label;
2373
+ return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
2374
+ })
2375
+ ]
2212
2376
  }
2213
2377
  ),
2214
- /* @__PURE__ */ jsx5("datalist", { id: `${f.id}-list`, children: f.options?.map((opt) => {
2215
- const val = typeof opt === "string" ? opt : opt.value;
2216
- const lab = typeof opt === "string" ? opt : opt.label;
2217
- return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
2218
- }) })
2378
+ /* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
2219
2379
  ] }) : f.type === "image" || f.type === "file" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
2220
2380
  /* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => {
2221
2381
  const isVideo = typeof url === "string" && (url.match(/\.(mp4|webm|mov|ogg)$/i) || url.includes("video"));
@@ -2505,7 +2665,7 @@ function CollectionEditor({ collection }) {
2505
2665
  onClick: save,
2506
2666
  disabled: saving,
2507
2667
  className: "inline-flex items-center gap-2 rounded-xl bg-slate-900 px-6 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-slate-800 hover:shadow transition-all disabled:opacity-60",
2508
- children: saving ? /* @__PURE__ */ jsxs4(Fragment3, { children: [
2668
+ children: saving ? /* @__PURE__ */ jsxs4(Fragment4, { children: [
2509
2669
  /* @__PURE__ */ jsxs4("svg", { className: "animate-spin h-4 w-4 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
2510
2670
  /* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2511
2671
  /* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
@@ -2527,7 +2687,7 @@ function CollectionEditor({ collection }) {
2527
2687
  visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4", children: /* @__PURE__ */ jsx5("div", { className: "h-4 bg-slate-100 rounded animate-pulse", style: { width: `${60 + i * 13 % 30}%` } }) }, f.id)),
2528
2688
  /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 sticky right-0 bg-white border-l border-slate-100", children: /* @__PURE__ */ jsx5("div", { className: "h-4 w-16 bg-slate-100 rounded animate-pulse ml-auto" }) })
2529
2689
  ] }, i))
2530
- ) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
2690
+ ) : /* @__PURE__ */ jsxs4(Fragment4, { children: [
2531
2691
  (() => {
2532
2692
  let res = entries;
2533
2693
  if (search && collection.searchBy?.length) {
@@ -2543,7 +2703,7 @@ function CollectionEditor({ collection }) {
2543
2703
  });
2544
2704
  }
2545
2705
  const paginatedRes = res.slice((page - 1) * itemsPerPage, page * itemsPerPage);
2546
- return /* @__PURE__ */ jsx5(Fragment3, { children: paginatedRes.map((e, idx) => /* @__PURE__ */ jsxs4(
2706
+ return /* @__PURE__ */ jsx5(Fragment4, { children: paginatedRes.map((e, idx) => /* @__PURE__ */ jsxs4(
2547
2707
  "tr",
2548
2708
  {
2549
2709
  draggable: true,
@@ -2553,7 +2713,10 @@ function CollectionEditor({ collection }) {
2553
2713
  onDragEnd,
2554
2714
  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
2715
  children: [
2556
- visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx5("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx5("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : f.type === "reference" && e[f.id] ? /* @__PURE__ */ jsx5(ReferenceTableCell, { collectionId: f.collection, entryId: String(e[f.id]), displayField: f.displayField }) : String(e[f.id] ?? "") }, f.id)),
2716
+ visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx5("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx5("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : (f.type === "reference" || f.type === "select" && f.collection) && e[f.id] ? /* @__PURE__ */ jsx5(ReferenceTableCell, { collectionId: f.collection, entryId: e[f.id], displayField: f.displayField, valueField: f.valueField, multiple: f.multiple }) : f.id === "status" && e[f.id] ? /* @__PURE__ */ jsx5("span", { className: `inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-bold ${String(e[f.id]).includes("Entregado") ? "bg-emerald-100 text-emerald-800 border border-emerald-300" : String(e[f.id]).includes("Preparaci\xF3n") ? "bg-amber-100 text-amber-800 border border-amber-300" : String(e[f.id]).includes("Camino") ? "bg-blue-100 text-blue-800 border border-blue-300" : String(e[f.id]).includes("Confirmado") ? "bg-indigo-100 text-indigo-800 border border-indigo-300" : String(e[f.id]).includes("Cancelado") ? "bg-rose-100 text-rose-800 border border-rose-300" : "bg-amber-50 text-amber-800 border border-amber-200"}`, children: String(e[f.id]) }) : f.type === "number" && e[f.id] !== void 0 && e[f.id] !== null && String(e[f.id]) !== "" ? f.id.toLowerCase().includes("price") || f.id.toLowerCase().includes("precio") || f.label.toLowerCase().includes("precio") || f.label.includes("$") || f.id.toLowerCase().includes("amount") || f.id.toLowerCase().includes("total") ? /* @__PURE__ */ jsxs4("span", { className: "font-semibold text-slate-800", children: [
2717
+ "$ ",
2718
+ Number(e[f.id]).toLocaleString("es-CO")
2719
+ ] }) : /* @__PURE__ */ jsx5("span", { children: Number(e[f.id]).toLocaleString("es-CO") }) : String(e[f.id] ?? "") }, f.id)),
2557
2720
  /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-right sticky right-0 bg-white border-l border-slate-100 group-hover:bg-slate-50/50 transition-colors", children: /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-end gap-2", children: [
2558
2721
  /* @__PURE__ */ jsx5("div", { className: "p-2 text-slate-300 cursor-grab active:cursor-grabbing", title: "Drag to reorder", children: /* @__PURE__ */ jsx5("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "w-4 h-4", children: /* @__PURE__ */ jsx5("path", { d: "M5.5 3C6.32843 3 7 3.67157 7 4.5C7 5.32843 6.32843 6 5.5 6C4.67157 6 4 5.32843 4 4.5C4 3.67157 4.67157 3 5.5 3ZM9.5 3C10.3284 3 11 3.67157 11 4.5C11 5.32843 10.3284 6 9.5 6C8.67157 6 8 5.32843 8 4.5C8 3.67157 8.67157 3 9.5 3ZM5.5 7.5C6.32843 7.5 7 8.17157 7 9C7 9.82843 6.32843 10.5 5.5 10.5C4.67157 10.5 4 9.82843 4 9C4 8.17157 4.67157 7.5 5.5 7.5ZM9.5 7.5C10.3284 7.5 11 8.17157 11 9C11 9.82843 10.3284 10.5 9.5 10.5C8.67157 10.5 8 9.82843 8 9C8 8.17157 8.67157 7.5 9.5 7.5ZM5.5 12C6.32843 12 7 12.6716 7 13.5C7 14.3284 6.32843 15 5.5 15C4.67157 15 4 14.3284 4 13.5C4 12.6716 4.67157 12 5.5 12ZM9.5 12C10.3284 12 11 12.6716 11 13.5C11 14.3284 10.3284 15 9.5 15C8.67157 15 8 14.3284 8 13.5C8 12.6716 8.67157 12 9.5 12Z", fill: "currentColor", fillRule: "evenodd", clipRule: "evenodd" }) }) }),
2559
2722
  /* @__PURE__ */ jsx5(
@@ -3115,7 +3278,7 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
3115
3278
  ]
3116
3279
  }
3117
3280
  ),
3118
- open && /* @__PURE__ */ jsxs4(Fragment3, { children: [
3281
+ open && /* @__PURE__ */ jsxs4(Fragment4, { children: [
3119
3282
  /* @__PURE__ */ jsx5("div", { className: "fixed inset-0 z-[100]", onClick: () => setOpen(false) }),
3120
3283
  /* @__PURE__ */ jsxs4("div", { className: "absolute z-[101] mt-1 w-full rounded-xl border border-slate-200 bg-white shadow-2xl max-h-72 flex flex-col overflow-hidden animate-in fade-in slide-in-from-top-1 duration-150", children: [
3121
3284
  /* @__PURE__ */ jsxs4("div", { className: "p-2 border-b border-slate-100 flex items-center gap-2", children: [
@@ -3199,49 +3362,225 @@ function PasswordField({ value, onChange }) {
3199
3362
  )
3200
3363
  ] });
3201
3364
  }
3202
- function ReferenceSelect({ collectionId, displayField = "id", value, onChange }) {
3365
+ function FormattedNumberInput({
3366
+ value,
3367
+ onChange,
3368
+ isPrice = false,
3369
+ placeholder = "0",
3370
+ className = ""
3371
+ }) {
3372
+ const formatWithDots = (num) => {
3373
+ if (num === void 0 || num === null || num === "") return "";
3374
+ const cleanDigits = String(num).replace(/\D/g, "");
3375
+ if (!cleanDigits) return "";
3376
+ return cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
3377
+ };
3378
+ const [displayVal, setDisplayVal] = useState5(() => formatWithDots(value));
3379
+ useEffect4(() => {
3380
+ setDisplayVal(formatWithDots(value));
3381
+ }, [value]);
3382
+ const handleChange = (e) => {
3383
+ const rawText = e.target.value;
3384
+ const cleanDigits = rawText.replace(/\D/g, "");
3385
+ if (!cleanDigits) {
3386
+ setDisplayVal("");
3387
+ onChange(0);
3388
+ return;
3389
+ }
3390
+ const formatted = cleanDigits.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
3391
+ setDisplayVal(formatted);
3392
+ onChange(Number(cleanDigits));
3393
+ };
3394
+ return /* @__PURE__ */ jsxs4("div", { className: "relative flex items-center w-full", children: [
3395
+ isPrice && /* @__PURE__ */ jsx5("span", { className: "absolute left-3.5 text-sm font-bold text-slate-400 pointer-events-none select-none", children: "$" }),
3396
+ /* @__PURE__ */ jsx5(
3397
+ "input",
3398
+ {
3399
+ type: "text",
3400
+ inputMode: "numeric",
3401
+ value: displayVal,
3402
+ onChange: handleChange,
3403
+ placeholder,
3404
+ 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" : ""} ${className}`
3405
+ }
3406
+ )
3407
+ ] });
3408
+ }
3409
+ function ReferenceSelect({
3410
+ collectionId,
3411
+ displayField = "name",
3412
+ valueField = "name",
3413
+ fallbackOptions,
3414
+ multiple = false,
3415
+ max,
3416
+ value,
3417
+ onChange
3418
+ }) {
3203
3419
  const ctx = useCmsContext();
3204
3420
  const [options, setOptions] = useState5([]);
3205
3421
  const [loading, setLoading] = useState5(true);
3206
3422
  useEffect4(() => {
3207
3423
  if (!collectionId) {
3424
+ if (fallbackOptions && fallbackOptions.length > 0) {
3425
+ setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
3426
+ }
3208
3427
  setLoading(false);
3209
3428
  return;
3210
3429
  }
3211
3430
  setLoading(true);
3212
3431
  ctx.adapter.listEntries(collectionId).then((res) => {
3213
- setOptions(res.map((r) => ({ id: r.id, label: String(r[displayField] || r.id) })));
3432
+ const fromCollection = res.map((r) => {
3433
+ const val = valueField && r[valueField] !== void 0 ? String(r[valueField]) : r.name ? String(r.name) : r.id;
3434
+ const lab = String(r[displayField] || r.name || r.id);
3435
+ return { value: val, label: lab };
3436
+ });
3437
+ const fallbackList = (fallbackOptions || []).map(
3438
+ (opt) => typeof opt === "string" ? { value: opt, label: opt } : opt
3439
+ );
3440
+ const combined = [...fromCollection];
3441
+ for (const fb of fallbackList) {
3442
+ if (!combined.some((c) => c.value === fb.value || c.label === fb.label)) {
3443
+ combined.push(fb);
3444
+ }
3445
+ }
3446
+ setOptions(combined);
3214
3447
  setLoading(false);
3215
- }).catch(() => setLoading(false));
3216
- }, [collectionId, displayField, ctx.adapter]);
3448
+ }).catch(() => {
3449
+ if (fallbackOptions && fallbackOptions.length > 0) {
3450
+ setOptions(fallbackOptions.map((opt) => typeof opt === "string" ? { value: opt, label: opt } : opt));
3451
+ }
3452
+ setLoading(false);
3453
+ });
3454
+ }, [collectionId, displayField, valueField, fallbackOptions, ctx.adapter]);
3455
+ if (multiple) {
3456
+ const selectedList = Array.isArray(value) ? value.map(String) : typeof value === "string" && value.trim() ? value.split(",").map((s) => s.trim()).filter(Boolean) : [];
3457
+ const toggle = (optVal) => {
3458
+ if (selectedList.includes(optVal)) {
3459
+ onChange(selectedList.filter((s) => s !== optVal));
3460
+ } else {
3461
+ if (max && selectedList.length >= max) return;
3462
+ onChange([...selectedList, optVal]);
3463
+ }
3464
+ };
3465
+ const selectAll = () => {
3466
+ onChange(options.map((o) => o.value));
3467
+ };
3468
+ const clearAll = () => {
3469
+ onChange([]);
3470
+ };
3471
+ return /* @__PURE__ */ jsxs4("div", { className: "space-y-2.5 rounded-xl border border-slate-200 bg-slate-50/50 p-3", children: [
3472
+ /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between text-xs text-slate-500 font-medium pb-1.5 border-b border-slate-200/60", children: [
3473
+ /* @__PURE__ */ jsxs4("span", { className: "font-semibold text-slate-700", children: [
3474
+ selectedList.length,
3475
+ " seleccionada",
3476
+ selectedList.length === 1 ? "" : "s",
3477
+ max ? ` (m\xE1x. ${max})` : ""
3478
+ ] }),
3479
+ /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
3480
+ /* @__PURE__ */ jsx5(
3481
+ "button",
3482
+ {
3483
+ type: "button",
3484
+ onClick: selectAll,
3485
+ className: "text-[11px] font-semibold text-indigo-600 hover:text-indigo-800 transition-colors cursor-pointer",
3486
+ children: "Seleccionar todas"
3487
+ }
3488
+ ),
3489
+ /* @__PURE__ */ jsx5("span", { className: "text-slate-300", children: "\u2022" }),
3490
+ /* @__PURE__ */ jsx5(
3491
+ "button",
3492
+ {
3493
+ type: "button",
3494
+ onClick: clearAll,
3495
+ className: "text-[11px] font-semibold text-slate-400 hover:text-slate-600 transition-colors cursor-pointer",
3496
+ children: "Limpiar"
3497
+ }
3498
+ )
3499
+ ] })
3500
+ ] }),
3501
+ loading ? /* @__PURE__ */ jsx5("div", { className: "text-xs text-slate-400 py-3 text-center", children: "Cargando opciones..." }) : options.length === 0 ? /* @__PURE__ */ jsx5("div", { className: "text-xs text-slate-400 py-3 text-center", children: "No hay opciones registradas todav\xEDa." }) : /* @__PURE__ */ jsx5("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-2 max-h-52 overflow-y-auto pr-1", children: options.map((o) => {
3502
+ const isChecked = selectedList.includes(o.value);
3503
+ return /* @__PURE__ */ jsxs4(
3504
+ "label",
3505
+ {
3506
+ className: `flex items-center gap-2.5 p-2 rounded-lg border text-xs font-medium cursor-pointer transition-all ${isChecked ? "bg-indigo-50/70 border-indigo-200 text-indigo-950 font-semibold shadow-xs" : "bg-white border-slate-200 text-slate-700 hover:border-slate-300"}`,
3507
+ children: [
3508
+ /* @__PURE__ */ jsx5(
3509
+ "input",
3510
+ {
3511
+ type: "checkbox",
3512
+ checked: isChecked,
3513
+ onChange: () => toggle(o.value),
3514
+ className: "w-4 h-4 rounded text-indigo-600 border-slate-300 focus:ring-indigo-500"
3515
+ }
3516
+ ),
3517
+ /* @__PURE__ */ jsx5("span", { className: "truncate", children: o.label })
3518
+ ]
3519
+ },
3520
+ o.value
3521
+ );
3522
+ }) })
3523
+ ] });
3524
+ }
3525
+ const singleVal = String(value ?? "");
3526
+ const displayOptions = [...options];
3527
+ if (singleVal && !displayOptions.some((o) => o.value === singleVal)) {
3528
+ displayOptions.unshift({ value: singleVal, label: singleVal });
3529
+ }
3217
3530
  return /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
3218
3531
  /* @__PURE__ */ jsxs4(
3219
3532
  "select",
3220
3533
  {
3221
- value,
3534
+ value: singleVal,
3222
3535
  onChange: (e) => onChange(e.target.value),
3223
3536
  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
3537
  children: [
3225
- /* @__PURE__ */ jsx5("option", { value: "", children: loading ? "Loading..." : "Select..." }),
3226
- options.map((o) => /* @__PURE__ */ jsx5("option", { value: o.id, children: o.label }, o.id))
3538
+ /* @__PURE__ */ jsx5("option", { value: "", children: loading ? "Cargando opciones..." : "-- Selecciona una opci\xF3n --" }),
3539
+ displayOptions.map((o, idx) => /* @__PURE__ */ jsx5("option", { value: o.value, children: o.label }, `${o.value}-${idx}`))
3227
3540
  ]
3228
3541
  }
3229
3542
  ),
3230
3543
  /* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
3231
3544
  ] });
3232
3545
  }
3233
- function ReferenceTableCell({ collectionId, entryId, displayField = "id" }) {
3546
+ function ReferenceTableCell({
3547
+ collectionId,
3548
+ entryId,
3549
+ displayField = "name",
3550
+ valueField = "name",
3551
+ multiple = false
3552
+ }) {
3234
3553
  const ctx = useCmsContext();
3235
- const [label, setLabel] = useState5(entryId);
3554
+ const [labels, setLabels] = useState5([]);
3555
+ const ids = Array.isArray(entryId) ? entryId.map(String) : typeof entryId === "string" && entryId.trim() ? multiple ? entryId.split(",").map((s) => s.trim()).filter(Boolean) : [entryId] : [];
3236
3556
  useEffect4(() => {
3237
- if (!collectionId || !entryId) return;
3557
+ if (!collectionId || ids.length === 0) {
3558
+ setLabels(ids);
3559
+ return;
3560
+ }
3238
3561
  ctx.adapter.listEntries(collectionId).then((res) => {
3239
- const match = res.find((r) => r.id === entryId);
3240
- if (match) setLabel(String(match[displayField] || match.id));
3562
+ const resolved = ids.map((id) => {
3563
+ const match = res.find(
3564
+ (r) => valueField && String(r[valueField]) === id || r.id === id || String(r.name) === id || String(r.slug) === id
3565
+ );
3566
+ return match ? String(match[displayField] || match.name || match.id) : id;
3567
+ });
3568
+ setLabels(resolved);
3241
3569
  }).catch(() => {
3570
+ setLabels(ids);
3242
3571
  });
3243
- }, [collectionId, entryId, displayField, ctx.adapter]);
3244
- return /* @__PURE__ */ jsx5("span", { children: label });
3572
+ }, [collectionId, displayField, valueField, JSON.stringify(ids), ctx.adapter]);
3573
+ if (labels.length === 0) return /* @__PURE__ */ jsx5("span", { children: "-" });
3574
+ if (multiple || labels.length > 1) {
3575
+ return /* @__PURE__ */ jsxs4("div", { className: "flex flex-wrap gap-1 max-w-[260px]", children: [
3576
+ labels.slice(0, 3).map((lbl, idx) => /* @__PURE__ */ jsx5("span", { className: "inline-flex px-1.5 py-0.5 rounded bg-slate-100 text-slate-700 text-[11px] font-medium truncate max-w-[120px]", children: lbl }, idx)),
3577
+ labels.length > 3 && /* @__PURE__ */ jsxs4("span", { className: "inline-flex px-1.5 py-0.5 rounded bg-slate-200 text-slate-600 text-[10px] font-bold", children: [
3578
+ "+",
3579
+ labels.length - 3
3580
+ ] })
3581
+ ] });
3582
+ }
3583
+ return /* @__PURE__ */ jsx5("span", { children: labels[0] });
3245
3584
  }
3246
3585
 
3247
3586
  // src/admin/AdminLogin.tsx