admin-lib-cms 1.2.0 → 1.2.2

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.js CHANGED
@@ -28,6 +28,7 @@ __export(index_exports, {
28
28
  EditableImage: () => EditableImage,
29
29
  EditableLink: () => EditableLink,
30
30
  EditableList: () => EditableList,
31
+ EditableReference: () => EditableReference,
31
32
  EditableText: () => EditableText,
32
33
  SubscriptionPage: () => SubscriptionPage,
33
34
  SubscriptionProvider: () => SubscriptionProvider,
@@ -451,13 +452,13 @@ function useSubmit(formId) {
451
452
  // src/editable.tsx
452
453
  var import_react4 = require("react");
453
454
  var import_jsx_runtime4 = require("react/jsx-runtime");
454
- function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength) {
455
+ function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField) {
455
456
  const ctx = useCmsOptional();
456
457
  (0, import_react4.useEffect)(() => {
457
458
  if (!ctx) return;
458
- ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength });
459
+ ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField });
459
460
  return () => ctx.unregisterEditable(id);
460
- }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength]);
461
+ }, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField]);
461
462
  return ctx;
462
463
  }
463
464
  function editableClasses(active, selected) {
@@ -474,26 +475,40 @@ function EditableText({
474
475
  pageId,
475
476
  children,
476
477
  as = "span",
477
- className
478
+ className,
479
+ type = "text"
478
480
  }) {
479
- const ctx = useRegister(id, "text", label, section, pageId, children);
481
+ const ctx = useRegister(id, type, label, section, pageId, children);
480
482
  const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? String(ctx.overrides[id] ?? "") : children;
481
483
  const active = !!ctx?.editMode;
482
484
  const selected = ctx?.selectedId === id;
485
+ const isEmpty = !value || String(value).trim() === "";
486
+ const renderValue = active && isEmpty ? `[Empty: ${label || id}]` : value;
483
487
  const onClick = (e) => {
484
488
  if (!active || !ctx) return;
485
489
  e.preventDefault();
486
490
  e.stopPropagation();
487
491
  ctx.setSelectedId(id);
488
492
  };
493
+ let finalChildren = renderValue;
494
+ if (typeof renderValue === "string" && renderValue.includes("\n")) {
495
+ finalChildren = renderValue.split("\n").map((line, i, arr) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_react4.Fragment, { children: [
496
+ line,
497
+ i < arr.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("br", {})
498
+ ] }, i));
499
+ }
489
500
  return (0, import_react4.createElement)(
490
501
  as,
491
502
  {
492
- className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
503
+ className: [
504
+ className,
505
+ editableClasses(active, selected),
506
+ active && isEmpty ? "opacity-50" : ""
507
+ ].filter(Boolean).join(" "),
493
508
  "data-cms-id": id,
494
509
  onClick: active ? onClick : void 0
495
510
  },
496
- value
511
+ finalChildren
497
512
  );
498
513
  }
499
514
  function EditableImage({
@@ -520,7 +535,7 @@ function EditableImage({
520
535
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
521
536
  "img",
522
537
  {
523
- src: value,
538
+ src: value || void 0,
524
539
  alt,
525
540
  width,
526
541
  height,
@@ -606,6 +621,9 @@ function EditableLink({
606
621
  const isExternal = hrefValue.startsWith("http");
607
622
  const computedTarget = target || (isExternal ? "_blank" : void 0);
608
623
  const computedRel = computedTarget === "_blank" ? "noopener noreferrer" : void 0;
624
+ const content = typeof children !== "undefined" ? children : textValue;
625
+ const isEmpty = !content || String(content).trim() === "";
626
+ const renderContent = active && isEmpty ? `[Empty Link: ${label || id}]` : content;
609
627
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
610
628
  "a",
611
629
  {
@@ -614,8 +632,12 @@ function EditableLink({
614
632
  rel: computedRel,
615
633
  "data-cms-id": id,
616
634
  onClick: active ? onClick : void 0,
617
- className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
618
- children: typeof children !== "undefined" ? children : textValue
635
+ className: [
636
+ className,
637
+ editableClasses(active, selected),
638
+ active && isEmpty ? "opacity-50" : ""
639
+ ].filter(Boolean).join(" "),
640
+ children: renderContent
619
641
  }
620
642
  );
621
643
  }
@@ -630,9 +652,10 @@ function EditableList({
630
652
  itemSchema,
631
653
  fixedLength,
632
654
  className,
633
- listClassName
655
+ listClassName,
656
+ search
634
657
  }) {
635
- const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength);
658
+ const ctx = useRegister(id, "list", label, section, pageId, initialItems, itemSchema, fixedLength, search);
636
659
  const rawValue = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : initialItems;
637
660
  const value = Array.isArray(rawValue) ? rawValue : initialItems;
638
661
  const active = !!ctx?.editMode;
@@ -643,13 +666,72 @@ function EditableList({
643
666
  e.stopPropagation();
644
667
  ctx.setSelectedId(id);
645
668
  };
646
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
669
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
670
+ "div",
671
+ {
672
+ "data-cms-id": id,
673
+ onClick: active ? onClick : void 0,
674
+ className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
675
+ children: [
676
+ renderList ? renderList(value) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: listClassName, children: renderItem && value.map(renderItem) }),
677
+ active && value.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { padding: "2rem", textAlign: "center", fontSize: "0.875rem", color: "#737373", backgroundColor: "rgba(245, 245, 245, 0.5)", border: "2px dashed #d4d4d4", borderRadius: "0.75rem", width: "100%", cursor: "pointer" }, children: [
678
+ "Empty List ",
679
+ label ? `(${label})` : "",
680
+ " \u2014 Click to add items"
681
+ ] })
682
+ ]
683
+ }
684
+ );
685
+ }
686
+ function EditableReference({
687
+ id,
688
+ label,
689
+ section,
690
+ pageId,
691
+ collection,
692
+ max,
693
+ displayField,
694
+ className,
695
+ children
696
+ }) {
697
+ const ctx = useRegister(id, "reference", label, section, pageId, max === 1 ? "" : [], void 0, void 0, void 0, collection, max, displayField);
698
+ const active = !!ctx?.editMode;
699
+ const selected = ctx?.selectedId === id;
700
+ const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : void 0;
701
+ const [resolvedItems, setResolvedItems] = (0, import_react4.useState)([]);
702
+ (0, import_react4.useEffect)(() => {
703
+ if (!ctx) return;
704
+ const ids = Array.isArray(value) ? value : value ? [value] : [];
705
+ if (ids.length === 0) {
706
+ setResolvedItems([]);
707
+ return;
708
+ }
709
+ ctx.adapter.listEntries(collection).then((res) => {
710
+ setResolvedItems(res.filter((r) => ids.includes(r.id)));
711
+ }).catch(() => {
712
+ });
713
+ }, [value, collection, ctx]);
714
+ const onClick = (e) => {
715
+ if (!active || !ctx) return;
716
+ e.preventDefault();
717
+ e.stopPropagation();
718
+ ctx.setSelectedId(id);
719
+ };
720
+ const childContent = typeof children === "function" ? children(resolvedItems) : children;
721
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
647
722
  "div",
648
723
  {
649
724
  "data-cms-id": id,
650
725
  onClick: active ? onClick : void 0,
651
726
  className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
652
- children: renderList ? renderList(value) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: listClassName, children: renderItem && value.map(renderItem) })
727
+ children: [
728
+ childContent,
729
+ active && (!resolvedItems || resolvedItems.length === 0) && /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { style: { padding: "2rem", textAlign: "center", fontSize: "0.875rem", color: "#737373", backgroundColor: "rgba(245, 245, 245, 0.5)", border: "2px dashed #d4d4d4", borderRadius: "0.75rem", width: "100%", cursor: "pointer" }, children: [
730
+ "Empty Reference ",
731
+ label ? `(${label})` : "",
732
+ " \u2014 Click to select"
733
+ ] })
734
+ ]
653
735
  }
654
736
  );
655
737
  }
@@ -838,6 +920,61 @@ function SideItem({
838
920
  }
839
921
  );
840
922
  }
923
+ function PageListItem({
924
+ p,
925
+ selected,
926
+ onSelect,
927
+ depth = 0
928
+ }) {
929
+ const [expanded, setExpanded] = (0, import_react5.useState)(false);
930
+ if (p.isSeparator) {
931
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "my-2 border-t border-slate-200/60" });
932
+ }
933
+ const hasChildren = p.children && p.children.length > 0;
934
+ const isSelected = selected?.id === p.id;
935
+ const hasSelectedChild = hasChildren && p.children?.some((child) => child.id === selected?.id);
936
+ (0, import_react5.useEffect)(() => {
937
+ if (hasSelectedChild) {
938
+ setExpanded(true);
939
+ }
940
+ }, [hasSelectedChild]);
941
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { className: "shrink-0 lg:w-full", children: [
942
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex items-center", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
943
+ "button",
944
+ {
945
+ onClick: () => {
946
+ if (hasChildren) {
947
+ setExpanded(!expanded);
948
+ }
949
+ if (p.path || !hasChildren) {
950
+ onSelect(p);
951
+ }
952
+ },
953
+ className: `flex-1 w-full rounded-lg py-2.5 text-left text-sm transition-all duration-200 ${depth === 0 ? "px-3" : "px-3 ml-2"} ${isSelected ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
954
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-between", children: [
955
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
956
+ "div",
957
+ {
958
+ className: `truncate ${isSelected ? "text-slate-900" : "text-slate-700"}`,
959
+ children: p.name
960
+ }
961
+ ),
962
+ hasChildren && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-slate-400", children: expanded ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronUp, { size: 14 }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { size: 14 }) })
963
+ ] })
964
+ }
965
+ ) }),
966
+ hasChildren && expanded && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ul", { className: `mt-1 space-y-1 ${depth === 0 ? "ml-4 border-l-2 border-slate-100 pl-1" : "ml-2"}`, children: p.children.map((child) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
967
+ PageListItem,
968
+ {
969
+ p: child,
970
+ selected,
971
+ onSelect,
972
+ depth: depth + 1
973
+ },
974
+ child.id
975
+ )) })
976
+ ] });
977
+ }
841
978
  function PagesSection() {
842
979
  const ctx = useCmsContext();
843
980
  const [selected, setSelected] = (0, import_react5.useState)(
@@ -848,14 +985,15 @@ function PagesSection() {
848
985
  showList && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "w-full lg:w-72 shrink-0 border-b lg:border-b-0 lg:border-r border-slate-200 bg-white/50 p-3 lg:p-4 overflow-x-auto lg:overflow-y-auto hide-scrollbar", children: [
849
986
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500 hidden lg:block", children: "Pages" }),
850
987
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("ul", { className: "flex flex-row lg:flex-col space-x-2 lg:space-x-0 lg:space-y-1", children: [
851
- ctx.config.pages.map((p) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("li", { className: "shrink-0 w-32 lg:w-full", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
852
- "button",
988
+ ctx.config.pages.map((p) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
989
+ PageListItem,
853
990
  {
854
- onClick: () => setSelected(p),
855
- className: `w-full rounded-lg px-3 py-2.5 text-left text-sm transition-all duration-200 ${selected?.id === p.id ? "bg-white shadow-sm ring-1 ring-slate-200 font-semibold" : "hover:bg-slate-100"}`,
856
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `truncate ${selected?.id === p.id ? "text-slate-900" : "text-slate-700"}`, children: p.name })
857
- }
858
- ) }, p.id)),
991
+ p,
992
+ selected,
993
+ onSelect: setSelected
994
+ },
995
+ p.id
996
+ )),
859
997
  ctx.config.pages.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 w-full", children: "No pages registered." })
860
998
  ] })
861
999
  ] }),
@@ -1042,20 +1180,38 @@ function PageEditor({ page, showList, onToggleList }) {
1042
1180
  },
1043
1181
  onClose: () => setSelectedId(null)
1044
1182
  }
1045
- ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1046
- SectionAccordion,
1047
- {
1048
- registered,
1049
- onSelect: (id) => {
1050
- setSelectedId(id);
1051
- setDrawerState((prev) => prev === "min" ? "half" : prev);
1052
- iframeRef.current?.contentWindow?.postMessage(
1053
- { __cms: true, type: "cms:select", id },
1054
- "*"
1055
- );
1183
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1184
+ page.hideable && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "px-5 py-4 border-b border-slate-100 bg-slate-50/50", children: [
1185
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center space-x-3", children: [
1186
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1187
+ "input",
1188
+ {
1189
+ type: "checkbox",
1190
+ id: `page-visible-toggle-${page.id}`,
1191
+ checked: ctx.overrides[`page-${page.id}-visible`] !== false,
1192
+ onChange: (e) => updateOverride(`page-${page.id}-visible`, e.target.checked),
1193
+ className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-600 focus:ring-offset-0"
1194
+ }
1195
+ ),
1196
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: `page-visible-toggle-${page.id}`, className: "text-sm font-medium text-slate-800 cursor-pointer flex-1", children: "Page is Visible" })
1197
+ ] }),
1198
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-[11px] text-slate-500 mt-1.5 pl-8", children: "If unchecked, this page will be hidden from navigation and URL access." })
1199
+ ] }),
1200
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1201
+ SectionAccordion,
1202
+ {
1203
+ registered,
1204
+ onSelect: (id) => {
1205
+ setSelectedId(id);
1206
+ setDrawerState((prev) => prev === "min" ? "half" : prev);
1207
+ iframeRef.current?.contentWindow?.postMessage(
1208
+ { __cms: true, type: "cms:select", id },
1209
+ "*"
1210
+ );
1211
+ }
1056
1212
  }
1057
- }
1058
- )
1213
+ )
1214
+ ] })
1059
1215
  ] })
1060
1216
  ] })
1061
1217
  ] })
@@ -1138,6 +1294,74 @@ function FieldListItem({ meta, onSelect }) {
1138
1294
  }
1139
1295
  ) });
1140
1296
  }
1297
+ function SidebarReferenceSelect({ meta, value, onChange }) {
1298
+ const ctx = useCmsContext();
1299
+ const collection = ctx.config.collections?.find((c) => c.id === meta.collection);
1300
+ const [items, setItems] = (0, import_react5.useState)([]);
1301
+ const [search, setSearch] = (0, import_react5.useState)("");
1302
+ const [loading, setLoading] = (0, import_react5.useState)(true);
1303
+ (0, import_react5.useEffect)(() => {
1304
+ if (!meta.collection) return;
1305
+ setLoading(true);
1306
+ ctx.adapter.listEntries(meta.collection).then((res) => {
1307
+ setItems(res);
1308
+ setLoading(false);
1309
+ });
1310
+ }, [meta.collection, ctx.adapter]);
1311
+ const selectedIds = Array.isArray(value) ? value : value ? [value] : [];
1312
+ const max = meta.max ?? 1;
1313
+ const toggle = (id) => {
1314
+ if (max === 1) {
1315
+ onChange([id]);
1316
+ } else {
1317
+ if (selectedIds.includes(id)) {
1318
+ onChange(selectedIds.filter((s) => s !== id));
1319
+ } else if (selectedIds.length < max) {
1320
+ onChange([...selectedIds, id]);
1321
+ }
1322
+ }
1323
+ };
1324
+ const imgField = collection?.fields.find((f) => f.type === "image");
1325
+ const txtField = collection?.fields.find((f) => f.type === "text" || f.type === "textarea" || f.type === "richtext");
1326
+ const filtered = items.filter((it) => {
1327
+ if (!search) return true;
1328
+ const q = search.toLowerCase();
1329
+ const txt = String(it[txtField?.id || "id"] || "");
1330
+ return txt.toLowerCase().includes(q);
1331
+ });
1332
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
1333
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1334
+ "input",
1335
+ {
1336
+ placeholder: "Search...",
1337
+ value: search,
1338
+ onChange: (e) => setSearch(e.target.value),
1339
+ 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"
1340
+ }
1341
+ ),
1342
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-2 max-h-60 overflow-y-auto pr-1", children: [
1343
+ loading ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-500", children: "Loading..." }) : filtered.map((it) => {
1344
+ const isSelected = selectedIds.includes(it.id);
1345
+ const imgSrc = imgField ? it[imgField.id] : null;
1346
+ const label = txtField ? it[txtField.id] : it.id;
1347
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1348
+ "div",
1349
+ {
1350
+ onClick: () => toggle(it.id),
1351
+ className: `flex items-center gap-3 p-2 rounded-xl cursor-pointer border ${isSelected ? "border-indigo-500 bg-indigo-50" : "border-slate-100 bg-slate-50 hover:border-slate-300"}`,
1352
+ children: [
1353
+ !!imgSrc && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: Array.isArray(imgSrc) ? String(imgSrc[0]) : String(imgSrc), alt: "", className: "w-10 h-10 rounded-lg object-cover bg-white border border-slate-200" }),
1354
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: `text-sm ${isSelected ? "font-semibold text-indigo-900" : "text-slate-700"}`, children: String(label) }),
1355
+ isSelected && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Check, { className: "w-4 h-4 text-indigo-600 ml-auto" })
1356
+ ]
1357
+ },
1358
+ it.id
1359
+ );
1360
+ }),
1361
+ !loading && filtered.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-xs text-slate-500 text-center py-4", children: "No items found." })
1362
+ ] })
1363
+ ] });
1364
+ }
1141
1365
  function FieldEditor({
1142
1366
  meta,
1143
1367
  value,
@@ -1146,6 +1370,8 @@ function FieldEditor({
1146
1370
  onClose
1147
1371
  }) {
1148
1372
  const ctx = useCmsContext();
1373
+ const [expandedItems, setExpandedItems] = (0, import_react5.useState)({});
1374
+ const [searchQuery, setSearchQuery] = (0, import_react5.useState)("");
1149
1375
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
1150
1376
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-5", children: [
1151
1377
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "inline-flex items-center gap-1.5 px-2 py-1 rounded bg-indigo-50 text-indigo-700 text-[10px] font-bold uppercase tracking-wider mb-2", children: meta.type }),
@@ -1153,6 +1379,19 @@ function FieldEditor({
1153
1379
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "text-xs font-mono text-slate-400 mt-1", children: meta.id })
1154
1380
  ] }),
1155
1381
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4", children: [
1382
+ meta.type === "boolean" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center space-x-3 py-1", children: [
1383
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1384
+ "input",
1385
+ {
1386
+ type: "checkbox",
1387
+ id: meta.id,
1388
+ checked: value === void 0 ? meta.defaultValue : !!value,
1389
+ onChange: (e) => onChange(e.target.checked),
1390
+ className: "w-5 h-5 rounded border-slate-300 text-indigo-600 focus:ring-indigo-600 focus:ring-offset-0"
1391
+ }
1392
+ ),
1393
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { htmlFor: meta.id, className: "text-sm font-medium text-slate-700 cursor-pointer", children: meta.label || "Enabled" })
1394
+ ] }),
1156
1395
  meta.type === "text" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1157
1396
  "input",
1158
1397
  {
@@ -1303,138 +1542,183 @@ function FieldEditor({
1303
1542
  }
1304
1543
  ),
1305
1544
  meta.type === "list" && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-4", children: [
1306
- (Array.isArray(value) ? value : []).map((item, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-3 items-start bg-slate-50 p-3 rounded-xl border border-slate-100 relative group", children: [
1307
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex-1 space-y-3 w-full", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1308
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1309
- schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1310
- SearchableSelect,
1311
- {
1312
- value: String(item?.[schemaField.key] ?? ""),
1313
- options: schemaField.options ?? [],
1314
- placeholder: "Search icon...",
1315
- iconMap: ctx.iconMap,
1316
- onChange: (val) => {
1317
- const arr = Array.isArray(value) ? [...value] : [];
1318
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1319
- onChange(arr);
1320
- }
1321
- }
1322
- ) : schemaField.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1323
- "textarea",
1324
- {
1325
- rows: 3,
1326
- value: String(item?.[schemaField.key] ?? ""),
1327
- onChange: (e) => {
1328
- const arr = Array.isArray(value) ? [...value] : [];
1329
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1330
- onChange(arr);
1331
- },
1332
- 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"
1333
- }
1334
- ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1335
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1336
- "input",
1545
+ meta.search && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
1546
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Search, { className: "absolute left-3 top-2.5 h-4 w-4 text-slate-400" }),
1547
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1548
+ "input",
1549
+ {
1550
+ type: "text",
1551
+ placeholder: "Search by title...",
1552
+ value: searchQuery,
1553
+ onChange: (e) => setSearchQuery(e.target.value),
1554
+ className: "w-full rounded-lg border border-slate-200 pl-9 pr-3 py-2 text-sm shadow-sm focus:border-indigo-500 focus:outline-none focus:ring-2 focus:ring-indigo-500/20"
1555
+ }
1556
+ )
1557
+ ] }),
1558
+ (Array.isArray(value) ? value : []).map((item, idx) => {
1559
+ if (meta.search && searchQuery) {
1560
+ const title = String(item?.title || item?.name || "").toLowerCase();
1561
+ if (!title.includes(searchQuery.toLowerCase())) return null;
1562
+ }
1563
+ const isExpanded = expandedItems[idx] ?? false;
1564
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-3 items-start bg-slate-50 p-3 rounded-xl border border-slate-100 relative group", children: [
1565
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex-1 space-y-3 w-full", children: [
1566
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1567
+ "div",
1337
1568
  {
1338
- type: "checkbox",
1339
- checked: !!item?.[schemaField.key],
1340
- onChange: (e) => {
1341
- const arr = Array.isArray(value) ? [...value] : [];
1342
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1343
- onChange(arr);
1344
- },
1345
- className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1569
+ className: "flex items-center justify-between cursor-pointer py-1 select-none",
1570
+ onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
1571
+ children: [
1572
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "font-semibold text-slate-700 text-sm flex-1 truncate pr-4", children: meta.itemSchema ? item?.title || item?.name || `Item ${idx + 1}` : String(item) }),
1573
+ isExpanded ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronUp, { className: "w-4 h-4 text-slate-500 shrink-0" }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { className: "w-4 h-4 text-slate-500 shrink-0" })
1574
+ ]
1346
1575
  }
1347
1576
  ),
1348
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1349
- ] }) : schemaField.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
1350
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1351
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1352
- "input",
1577
+ isExpanded && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "pt-3 border-t border-slate-200 mt-2 space-y-3", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1578
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
1579
+ schemaField.type === "icon" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1580
+ SearchableSelect,
1353
1581
  {
1354
- type: "url",
1582
+ value: String(item?.[schemaField.key] ?? ""),
1583
+ options: schemaField.options ?? [],
1584
+ placeholder: "Search icon...",
1585
+ iconMap: ctx.iconMap,
1586
+ onChange: (val) => {
1587
+ const arr = Array.isArray(value) ? [...value] : [];
1588
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
1589
+ onChange(arr);
1590
+ }
1591
+ }
1592
+ ) : schemaField.type === "textarea" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1593
+ "textarea",
1594
+ {
1595
+ rows: 3,
1355
1596
  value: String(item?.[schemaField.key] ?? ""),
1356
1597
  onChange: (e) => {
1357
1598
  const arr = Array.isArray(value) ? [...value] : [];
1358
1599
  arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1359
1600
  onChange(arr);
1360
1601
  },
1361
- placeholder: "https://...",
1362
1602
  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"
1363
1603
  }
1364
- ),
1365
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex-shrink-0 cursor-pointer rounded-lg bg-slate-100 px-3 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
1366
- "Upload",
1604
+ ) : schemaField.type === "boolean" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
1367
1605
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1368
1606
  "input",
1369
1607
  {
1370
- type: "file",
1371
- accept: "image/*",
1372
- className: "hidden",
1608
+ type: "checkbox",
1609
+ checked: !!item?.[schemaField.key],
1373
1610
  onChange: (e) => {
1374
- const file = e.target.files?.[0];
1375
- if (file) {
1376
- void handleImageFile(
1377
- file,
1378
- (url) => {
1379
- const arr = Array.isArray(value) ? [...value] : [];
1380
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1381
- onChange(arr);
1382
- },
1383
- ctx.uploadImage
1384
- );
1385
- }
1611
+ const arr = Array.isArray(value) ? [...value] : [];
1612
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
1613
+ onChange(arr);
1614
+ },
1615
+ className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
1616
+ }
1617
+ ),
1618
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
1619
+ ] }) : schemaField.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3 mt-1", children: [
1620
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1621
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1622
+ "input",
1623
+ {
1624
+ type: "url",
1625
+ value: String(item?.[schemaField.key] ?? ""),
1626
+ onChange: (e) => {
1627
+ const arr = Array.isArray(value) ? [...value] : [];
1628
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1629
+ onChange(arr);
1630
+ },
1631
+ placeholder: "https://...",
1632
+ 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"
1386
1633
  }
1634
+ ),
1635
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex-shrink-0 cursor-pointer rounded-lg bg-slate-100 px-3 py-2 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
1636
+ "Upload",
1637
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1638
+ "input",
1639
+ {
1640
+ type: "file",
1641
+ accept: "image/*",
1642
+ className: "hidden",
1643
+ onChange: (e) => {
1644
+ const file = e.target.files?.[0];
1645
+ if (file) {
1646
+ void handleImageFile(
1647
+ file,
1648
+ (url) => {
1649
+ const arr = Array.isArray(value) ? [...value] : [];
1650
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
1651
+ onChange(arr);
1652
+ },
1653
+ ctx.uploadImage
1654
+ );
1655
+ }
1656
+ }
1657
+ }
1658
+ )
1659
+ ] })
1660
+ ] }),
1661
+ item?.[schemaField.key] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1662
+ "img",
1663
+ {
1664
+ src: String(item?.[schemaField.key]),
1665
+ alt: "",
1666
+ className: "w-full h-auto max-h-32 object-contain rounded-md"
1387
1667
  }
1388
- )
1389
- ] })
1390
- ] }),
1391
- item?.[schemaField.key] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1392
- "img",
1668
+ ) }) : null
1669
+ ] }) : schemaField.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1670
+ "select",
1671
+ {
1672
+ value: String(item?.[schemaField.key] ?? ""),
1673
+ onChange: (e) => {
1674
+ const arr = Array.isArray(value) ? [...value] : [];
1675
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1676
+ onChange(arr);
1677
+ },
1678
+ 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",
1679
+ children: schemaField.options?.map((opt) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: opt, children: opt }, opt))
1680
+ }
1681
+ ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1682
+ "input",
1683
+ {
1684
+ type: "text",
1685
+ value: String(item?.[schemaField.key] ?? ""),
1686
+ onChange: (e) => {
1687
+ const arr = Array.isArray(value) ? [...value] : [];
1688
+ arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1689
+ onChange(arr);
1690
+ },
1691
+ 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"
1692
+ }
1693
+ )
1694
+ ] }, schemaField.key)) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1695
+ "input",
1393
1696
  {
1394
- src: String(item?.[schemaField.key]),
1395
- alt: "",
1396
- className: "w-full h-auto max-h-32 object-contain rounded-md"
1697
+ type: "text",
1698
+ value: String(item),
1699
+ onChange: (e) => {
1700
+ const arr = Array.isArray(value) ? [...value] : [];
1701
+ arr[idx] = e.target.value;
1702
+ onChange(arr);
1703
+ },
1704
+ 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"
1397
1705
  }
1398
- ) }) : null
1399
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1400
- "input",
1706
+ ) })
1707
+ ] }),
1708
+ !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1709
+ "button",
1401
1710
  {
1402
- type: "text",
1403
- value: String(item?.[schemaField.key] ?? ""),
1404
- onChange: (e) => {
1711
+ onClick: () => {
1405
1712
  const arr = Array.isArray(value) ? [...value] : [];
1406
- arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
1713
+ arr.splice(idx, 1);
1407
1714
  onChange(arr);
1408
1715
  },
1409
- 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"
1716
+ className: "p-1.5 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors absolute top-2 right-2 opacity-0 group-hover:opacity-100",
1717
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
1410
1718
  }
1411
1719
  )
1412
- ] }, schemaField.key)) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1413
- "input",
1414
- {
1415
- type: "text",
1416
- value: String(item),
1417
- onChange: (e) => {
1418
- const arr = Array.isArray(value) ? [...value] : [];
1419
- arr[idx] = e.target.value;
1420
- onChange(arr);
1421
- },
1422
- 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"
1423
- }
1424
- ) }),
1425
- !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1426
- "button",
1427
- {
1428
- onClick: () => {
1429
- const arr = Array.isArray(value) ? [...value] : [];
1430
- arr.splice(idx, 1);
1431
- onChange(arr);
1432
- },
1433
- className: "p-1.5 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors absolute top-2 right-2 opacity-0 group-hover:opacity-100",
1434
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "w-4 h-4" })
1435
- }
1436
- )
1437
- ] }, idx)),
1720
+ ] }, idx);
1721
+ }),
1438
1722
  !meta.fixedLength && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1439
1723
  "button",
1440
1724
  {
@@ -1459,7 +1743,7 @@ function FieldEditor({
1459
1743
  }
1460
1744
  )
1461
1745
  ] }),
1462
- " "
1746
+ meta.type === "reference" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SidebarReferenceSelect, { meta, value, onChange })
1463
1747
  ] }),
1464
1748
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-between pt-6 mt-6 border-t border-slate-100", children: [
1465
1749
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
@@ -1534,6 +1818,10 @@ function CollectionEditor({ collection }) {
1534
1818
  const [loadingEntries, setLoadingEntries] = (0, import_react5.useState)(true);
1535
1819
  const [draggedIdx, setDraggedIdx] = (0, import_react5.useState)(null);
1536
1820
  const [dragOverIdx, setDragOverIdx] = (0, import_react5.useState)(null);
1821
+ const [search, setSearch] = (0, import_react5.useState)("");
1822
+ const [filters, setFilters] = (0, import_react5.useState)({});
1823
+ const [page, setPage] = (0, import_react5.useState)(1);
1824
+ const itemsPerPage = 10;
1537
1825
  const load = (0, import_react5.useCallback)(() => {
1538
1826
  setLoadingEntries(true);
1539
1827
  ctx.adapter.listEntries(collection.id).then((res) => {
@@ -1557,7 +1845,7 @@ function CollectionEditor({ collection }) {
1557
1845
  } else if (f.defaultValue !== void 0) {
1558
1846
  base[f.id] = f.defaultValue;
1559
1847
  } else {
1560
- base[f.id] = f.type === "boolean" ? false : f.type === "number" ? 0 : "";
1848
+ base[f.id] = f.type === "boolean" ? false : f.type === "number" ? 0 : f.type === "select" ? f.options?.[0] ?? "" : "";
1561
1849
  }
1562
1850
  });
1563
1851
  setEditing(base);
@@ -1566,7 +1854,16 @@ function CollectionEditor({ collection }) {
1566
1854
  if (!editing) return;
1567
1855
  setSaving(true);
1568
1856
  try {
1569
- await ctx.adapter.putEntry(collection.id, editing);
1857
+ const finalEditing = { ...editing };
1858
+ collection.fields.forEach((f) => {
1859
+ if (f.type === "slug" && !finalEditing[f.id]) {
1860
+ const sourceField = f.source || "title";
1861
+ let val = String(finalEditing[sourceField] || finalEditing.id || "");
1862
+ val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
1863
+ finalEditing[f.id] = val;
1864
+ }
1865
+ });
1866
+ await ctx.adapter.putEntry(collection.id, finalEditing);
1570
1867
  ctx.notifyCollectionChanged();
1571
1868
  setEditing(null);
1572
1869
  load();
@@ -1619,7 +1916,7 @@ function CollectionEditor({ collection }) {
1619
1916
  setDraggedIdx(null);
1620
1917
  setDragOverIdx(null);
1621
1918
  };
1622
- const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order").slice(0, 5);
1919
+ const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 5);
1623
1920
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mx-auto max-w-5xl", children: [
1624
1921
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-8 flex items-center justify-between", children: [
1625
1922
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
@@ -1638,12 +1935,56 @@ function CollectionEditor({ collection }) {
1638
1935
  }
1639
1936
  )
1640
1937
  ] }),
1938
+ !editing && (collection.searchBy?.length || collection.filterBy?.length) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-6 flex flex-wrap gap-4 items-center p-4 bg-white rounded-2xl border border-slate-200 shadow-sm animate-in fade-in slide-in-from-top-2", children: [
1939
+ collection.searchBy?.length ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative flex-1 min-w-[200px]", children: [
1940
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Search, { className: "absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" }),
1941
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1942
+ "input",
1943
+ {
1944
+ type: "text",
1945
+ placeholder: `Search by ${collection.searchBy.join(", ")}...`,
1946
+ value: search,
1947
+ onChange: (e) => {
1948
+ setSearch(e.target.value);
1949
+ setPage(1);
1950
+ },
1951
+ className: "w-full rounded-xl border border-slate-200 bg-slate-50 py-2.5 pl-10 pr-4 text-sm focus:border-indigo-500 focus:bg-white focus:ring-4 focus:ring-indigo-500/10 outline-none transition-all"
1952
+ }
1953
+ )
1954
+ ] }) : null,
1955
+ collection.filterBy?.map((f) => {
1956
+ const fieldDef = collection.fields.find((cf) => cf.id === f);
1957
+ const uniqueVals = Array.from(new Set(entries.map((e) => String(e[f] || "")))).filter(Boolean);
1958
+ if (!fieldDef || uniqueVals.length === 0) return null;
1959
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "min-w-[150px] relative", children: [
1960
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1961
+ "select",
1962
+ {
1963
+ value: filters[f] || "",
1964
+ onChange: (e) => {
1965
+ setFilters((prev) => ({ ...prev, [f]: e.target.value }));
1966
+ setPage(1);
1967
+ },
1968
+ className: "w-full rounded-xl border border-slate-200 bg-slate-50 py-2.5 px-4 pr-10 text-sm focus:border-indigo-500 focus:bg-white focus:ring-4 focus:ring-indigo-500/10 outline-none transition-all appearance-none",
1969
+ children: [
1970
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("option", { value: "", children: [
1971
+ "All ",
1972
+ fieldDef.label
1973
+ ] }),
1974
+ uniqueVals.map((v) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: v, children: v }, v))
1975
+ ]
1976
+ }
1977
+ ),
1978
+ /* @__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" })
1979
+ ] }, f);
1980
+ })
1981
+ ] }),
1641
1982
  editing && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-8 rounded-2xl border border-indigo-100 bg-white p-6 shadow-xl shadow-indigo-100/50 animate-in fade-in slide-in-from-top-4", children: [
1642
1983
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2 mb-6", children: [
1643
1984
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "w-4 h-4" }) }),
1644
1985
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { className: "text-lg font-bold text-slate-900", children: "Edit Entry" })
1645
1986
  ] }),
1646
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "grid gap-5 md:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order").map((f) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: `block ${f.type === "richtext" ? "md:col-span-2" : ""}`, children: [
1987
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "grid gap-5 md:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order" && !f.hidden).map((f) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: `block ${f.type === "richtext" ? "md:col-span-2" : ""}`, children: [
1647
1988
  /* @__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: [
1648
1989
  f.label,
1649
1990
  /* @__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 })
@@ -1705,7 +2046,15 @@ function CollectionEditor({ collection }) {
1705
2046
  children: "Generate"
1706
2047
  }
1707
2048
  )
1708
- ] }) : f.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
2049
+ ] }) : f.type === "reference" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2050
+ ReferenceSelect,
2051
+ {
2052
+ collectionId: f.collection,
2053
+ displayField: f.displayField,
2054
+ value: String(editing[f.id] ?? ""),
2055
+ onChange: (val) => setEditing({ ...editing, [f.id]: val })
2056
+ }
2057
+ ) : f.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
1709
2058
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1710
2059
  "input",
1711
2060
  {
@@ -1720,7 +2069,71 @@ function CollectionEditor({ collection }) {
1720
2069
  const lab = typeof opt === "string" ? opt : opt.label;
1721
2070
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: val, children: lab }, val);
1722
2071
  }) })
1723
- ] }) : f.type === "image" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
2072
+ ] }) : f.type === "image" ? f.multiple ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
2073
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => /* @__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: [
2074
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
2075
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2076
+ "button",
2077
+ {
2078
+ type: "button",
2079
+ onClick: () => {
2080
+ const arr = [...editing[f.id] || []];
2081
+ arr.splice(i, 1);
2082
+ setEditing({ ...editing, [f.id]: arr });
2083
+ },
2084
+ 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",
2085
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.X, { className: "w-3 h-3" })
2086
+ }
2087
+ )
2088
+ ] }, i)) }),
2089
+ (!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
2090
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2091
+ "input",
2092
+ {
2093
+ type: "url",
2094
+ placeholder: "Add image URL and press Enter...",
2095
+ onKeyDown: (e) => {
2096
+ if (e.key === "Enter" && e.currentTarget.value) {
2097
+ e.preventDefault();
2098
+ const arr = [...editing[f.id] || [], e.currentTarget.value];
2099
+ setEditing({ ...editing, [f.id]: arr });
2100
+ e.currentTarget.value = "";
2101
+ }
2102
+ },
2103
+ 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"
2104
+ }
2105
+ ),
2106
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { className: "flex-shrink-0 cursor-pointer rounded-xl bg-slate-100 px-4 py-2.5 text-sm font-medium text-slate-700 hover:bg-slate-200 transition-colors border border-slate-200 flex items-center justify-center", children: [
2107
+ "Upload",
2108
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2109
+ "input",
2110
+ {
2111
+ type: "file",
2112
+ accept: "image/*",
2113
+ multiple: true,
2114
+ className: "hidden",
2115
+ onChange: (e) => {
2116
+ const files = Array.from(e.target.files || []);
2117
+ files.forEach((file) => {
2118
+ void handleImageFile(
2119
+ file,
2120
+ (url) => {
2121
+ setEditing((prev) => {
2122
+ if (!prev) return prev;
2123
+ const current = prev[f.id] || [];
2124
+ if (f.max && current.length >= f.max) return prev;
2125
+ return { ...prev, [f.id]: [...current, url] };
2126
+ });
2127
+ },
2128
+ ctx.uploadImage
2129
+ );
2130
+ });
2131
+ }
2132
+ }
2133
+ )
2134
+ ] })
2135
+ ] })
2136
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "space-y-3", children: [
1724
2137
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1725
2138
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1726
2139
  "input",
@@ -1958,47 +2371,63 @@ function CollectionEditor({ collection }) {
1958
2371
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { className: "px-6 py-4 sticky right-0 bg-white border-l border-slate-100", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "h-4 w-16 bg-slate-100 rounded animate-pulse ml-auto" }) })
1959
2372
  ] }, i))
1960
2373
  ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1961
- entries.map((e, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1962
- "tr",
1963
- {
1964
- draggable: true,
1965
- onDragStart: (evt) => onDragStart(evt, idx),
1966
- onDragOver: (evt) => onDragOver(evt, idx),
1967
- onDrop: (evt) => onDrop(evt, idx),
1968
- onDragEnd,
1969
- 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" : ""}`,
1970
- children: [
1971
- 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" && e[f.id] ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("img", { src: 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" }) }) }) : String(e[f.id] ?? "") }, f.id)),
1972
- /* @__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: [
1973
- /* @__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" }) }) }),
1974
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1975
- "button",
1976
- {
1977
- onClick: () => setEditing(e),
1978
- className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
1979
- title: "Edit",
1980
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4" })
1981
- }
1982
- ),
1983
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1984
- "button",
1985
- {
1986
- onClick: () => remove(e.id),
1987
- disabled: deletingId === e.id,
1988
- className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors disabled:opacity-50",
1989
- title: "Delete",
1990
- children: deletingId === e.id ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("svg", { className: "animate-spin h-4 w-4", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
1991
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
1992
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
1993
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "h-4 w-4" })
1994
- }
1995
- )
1996
- ] }) })
1997
- ]
1998
- },
1999
- e.id
2000
- )),
2001
- entries.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2374
+ (() => {
2375
+ let res = entries;
2376
+ if (search && collection.searchBy?.length) {
2377
+ const q = search.toLowerCase();
2378
+ res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
2379
+ }
2380
+ if (Object.keys(filters).length > 0) {
2381
+ res = res.filter((e) => {
2382
+ for (const [k, v] of Object.entries(filters)) {
2383
+ if (v && String(e[k] || "") !== v) return false;
2384
+ }
2385
+ return true;
2386
+ });
2387
+ }
2388
+ const paginatedRes = res.slice((page - 1) * itemsPerPage, page * itemsPerPage);
2389
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_jsx_runtime5.Fragment, { children: paginatedRes.map((e, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2390
+ "tr",
2391
+ {
2392
+ draggable: true,
2393
+ onDragStart: (evt) => onDragStart(evt, idx),
2394
+ onDragOver: (evt) => onDragOver(evt, idx),
2395
+ onDrop: (evt) => onDrop(evt, idx),
2396
+ onDragEnd,
2397
+ 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" : ""}`,
2398
+ children: [
2399
+ 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: String(e[f.id]), displayField: f.displayField }) : String(e[f.id] ?? "") }, f.id)),
2400
+ /* @__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: [
2401
+ /* @__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" }) }) }),
2402
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2403
+ "button",
2404
+ {
2405
+ onClick: () => setEditing(e),
2406
+ className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
2407
+ title: "Edit",
2408
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4" })
2409
+ }
2410
+ ),
2411
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2412
+ "button",
2413
+ {
2414
+ onClick: () => remove(e.id),
2415
+ disabled: deletingId === e.id,
2416
+ className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors disabled:opacity-50",
2417
+ title: "Delete",
2418
+ children: deletingId === e.id ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("svg", { className: "animate-spin h-4 w-4", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
2419
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2420
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
2421
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "h-4 w-4" })
2422
+ }
2423
+ )
2424
+ ] }) })
2425
+ ]
2426
+ },
2427
+ e.id
2428
+ )) });
2429
+ })(),
2430
+ entries.length === 0 && !search && Object.values(filters).every((v) => !v) && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2002
2431
  "td",
2003
2432
  {
2004
2433
  colSpan: visibleFields.length + 1,
@@ -2010,7 +2439,68 @@ function CollectionEditor({ collection }) {
2010
2439
  }
2011
2440
  ) })
2012
2441
  ] }) })
2013
- ] }) })
2442
+ ] }) }),
2443
+ !loadingEntries && entries.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-between text-sm text-slate-500 mt-4 px-2", children: [
2444
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: (() => {
2445
+ let res = entries;
2446
+ if (search && collection.searchBy?.length) {
2447
+ const q = search.toLowerCase();
2448
+ res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
2449
+ }
2450
+ if (Object.keys(filters).length > 0) {
2451
+ res = res.filter((e) => {
2452
+ for (const [k, v] of Object.entries(filters)) {
2453
+ if (v && String(e[k] || "") !== v) return false;
2454
+ }
2455
+ return true;
2456
+ });
2457
+ }
2458
+ return `${res.length} item${res.length !== 1 ? "s" : ""}`;
2459
+ })() }),
2460
+ (() => {
2461
+ let res = entries;
2462
+ if (search && collection.searchBy?.length) {
2463
+ const q = search.toLowerCase();
2464
+ res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
2465
+ }
2466
+ if (Object.keys(filters).length > 0) {
2467
+ res = res.filter((e) => {
2468
+ for (const [k, v] of Object.entries(filters)) {
2469
+ if (v && String(e[k] || "") !== v) return false;
2470
+ }
2471
+ return true;
2472
+ });
2473
+ }
2474
+ const totalPages = Math.max(1, Math.ceil(res.length / itemsPerPage));
2475
+ if (totalPages <= 1) return null;
2476
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2", children: [
2477
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2478
+ "button",
2479
+ {
2480
+ onClick: () => setPage((p) => Math.max(1, p - 1)),
2481
+ disabled: page === 1,
2482
+ className: "p-2 rounded-lg hover:bg-slate-100 disabled:opacity-30 transition-colors",
2483
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronLeft, { className: "h-4 w-4" })
2484
+ }
2485
+ ),
2486
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "font-medium text-slate-700", children: [
2487
+ "Page ",
2488
+ page,
2489
+ " of ",
2490
+ totalPages
2491
+ ] }),
2492
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2493
+ "button",
2494
+ {
2495
+ onClick: () => setPage((p) => Math.min(totalPages, p + 1)),
2496
+ disabled: page === totalPages,
2497
+ className: "p-2 rounded-lg hover:bg-slate-100 disabled:opacity-30 transition-colors",
2498
+ children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronRight, { className: "h-4 w-4" })
2499
+ }
2500
+ )
2501
+ ] });
2502
+ })()
2503
+ ] })
2014
2504
  ] });
2015
2505
  }
2016
2506
  var PAGE_SIZE = 10;
@@ -2552,6 +3042,50 @@ function PasswordField({ value, onChange }) {
2552
3042
  )
2553
3043
  ] });
2554
3044
  }
3045
+ function ReferenceSelect({ collectionId, displayField = "id", value, onChange }) {
3046
+ const ctx = useCmsContext();
3047
+ const [options, setOptions] = (0, import_react5.useState)([]);
3048
+ const [loading, setLoading] = (0, import_react5.useState)(true);
3049
+ (0, import_react5.useEffect)(() => {
3050
+ if (!collectionId) {
3051
+ setLoading(false);
3052
+ return;
3053
+ }
3054
+ setLoading(true);
3055
+ ctx.adapter.listEntries(collectionId).then((res) => {
3056
+ setOptions(res.map((r) => ({ id: r.id, label: String(r[displayField] || r.id) })));
3057
+ setLoading(false);
3058
+ }).catch(() => setLoading(false));
3059
+ }, [collectionId, displayField, ctx.adapter]);
3060
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "relative", children: [
3061
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
3062
+ "select",
3063
+ {
3064
+ value,
3065
+ onChange: (e) => onChange(e.target.value),
3066
+ 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",
3067
+ children: [
3068
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: "", children: loading ? "Loading..." : "Select..." }),
3069
+ options.map((o) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: o.id, children: o.label }, o.id))
3070
+ ]
3071
+ }
3072
+ ),
3073
+ /* @__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" })
3074
+ ] });
3075
+ }
3076
+ function ReferenceTableCell({ collectionId, entryId, displayField = "id" }) {
3077
+ const ctx = useCmsContext();
3078
+ const [label, setLabel] = (0, import_react5.useState)(entryId);
3079
+ (0, import_react5.useEffect)(() => {
3080
+ if (!collectionId || !entryId) return;
3081
+ ctx.adapter.listEntries(collectionId).then((res) => {
3082
+ const match = res.find((r) => r.id === entryId);
3083
+ if (match) setLabel(String(match[displayField] || match.id));
3084
+ }).catch(() => {
3085
+ });
3086
+ }, [collectionId, entryId, displayField, ctx.adapter]);
3087
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: label });
3088
+ }
2555
3089
 
2556
3090
  // src/admin/AdminLogin.tsx
2557
3091
  var import_react6 = require("react");
@@ -2817,6 +3351,7 @@ async function sendEmailNotification(content, apiUrl) {
2817
3351
  EditableImage,
2818
3352
  EditableLink,
2819
3353
  EditableList,
3354
+ EditableReference,
2820
3355
  EditableText,
2821
3356
  SubscriptionPage,
2822
3357
  SubscriptionProvider,