admin-lib-cms 1.2.1 → 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, search) {
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, search });
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, search]);
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,9 +475,10 @@ 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;
@@ -488,6 +490,13 @@ function EditableText({
488
490
  e.stopPropagation();
489
491
  ctx.setSelectedId(id);
490
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
+ }
491
500
  return (0, import_react4.createElement)(
492
501
  as,
493
502
  {
@@ -499,7 +508,7 @@ function EditableText({
499
508
  "data-cms-id": id,
500
509
  onClick: active ? onClick : void 0
501
510
  },
502
- renderValue
511
+ finalChildren
503
512
  );
504
513
  }
505
514
  function EditableImage({
@@ -526,7 +535,7 @@ function EditableImage({
526
535
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
527
536
  "img",
528
537
  {
529
- src: value,
538
+ src: value || void 0,
530
539
  alt,
531
540
  width,
532
541
  height,
@@ -674,6 +683,58 @@ function EditableList({
674
683
  }
675
684
  );
676
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)(
722
+ "div",
723
+ {
724
+ "data-cms-id": id,
725
+ onClick: active ? onClick : void 0,
726
+ className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
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
+ ]
735
+ }
736
+ );
737
+ }
677
738
 
678
739
  // src/admin/AdminApp.tsx
679
740
  var import_react5 = require("react");
@@ -1233,6 +1294,74 @@ function FieldListItem({ meta, onSelect }) {
1233
1294
  }
1234
1295
  ) });
1235
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
+ }
1236
1365
  function FieldEditor({
1237
1366
  meta,
1238
1367
  value,
@@ -1614,7 +1743,7 @@ function FieldEditor({
1614
1743
  }
1615
1744
  )
1616
1745
  ] }),
1617
- " "
1746
+ meta.type === "reference" && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(SidebarReferenceSelect, { meta, value, onChange })
1618
1747
  ] }),
1619
1748
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center justify-between pt-6 mt-6 border-t border-slate-100", children: [
1620
1749
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
@@ -1689,6 +1818,10 @@ function CollectionEditor({ collection }) {
1689
1818
  const [loadingEntries, setLoadingEntries] = (0, import_react5.useState)(true);
1690
1819
  const [draggedIdx, setDraggedIdx] = (0, import_react5.useState)(null);
1691
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;
1692
1825
  const load = (0, import_react5.useCallback)(() => {
1693
1826
  setLoadingEntries(true);
1694
1827
  ctx.adapter.listEntries(collection.id).then((res) => {
@@ -1721,7 +1854,16 @@ function CollectionEditor({ collection }) {
1721
1854
  if (!editing) return;
1722
1855
  setSaving(true);
1723
1856
  try {
1724
- 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);
1725
1867
  ctx.notifyCollectionChanged();
1726
1868
  setEditing(null);
1727
1869
  load();
@@ -1774,7 +1916,7 @@ function CollectionEditor({ collection }) {
1774
1916
  setDraggedIdx(null);
1775
1917
  setDragOverIdx(null);
1776
1918
  };
1777
- 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);
1778
1920
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mx-auto max-w-5xl", children: [
1779
1921
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "mb-8 flex items-center justify-between", children: [
1780
1922
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
@@ -1793,12 +1935,56 @@ function CollectionEditor({ collection }) {
1793
1935
  }
1794
1936
  )
1795
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
+ ] }),
1796
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: [
1797
1983
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-2 mb-6", children: [
1798
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" }) }),
1799
1985
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("h3", { className: "text-lg font-bold text-slate-900", children: "Edit Entry" })
1800
1986
  ] }),
1801
- /* @__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: [
1802
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: [
1803
1989
  f.label,
1804
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 })
@@ -1860,7 +2046,15 @@ function CollectionEditor({ collection }) {
1860
2046
  children: "Generate"
1861
2047
  }
1862
2048
  )
1863
- ] }) : 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: [
1864
2058
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1865
2059
  "input",
1866
2060
  {
@@ -1875,7 +2069,71 @@ function CollectionEditor({ collection }) {
1875
2069
  const lab = typeof opt === "string" ? opt : opt.label;
1876
2070
  return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("option", { value: val, children: lab }, val);
1877
2071
  }) })
1878
- ] }) : 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: [
1879
2137
  /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
1880
2138
  /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1881
2139
  "input",
@@ -2113,47 +2371,63 @@ function CollectionEditor({ collection }) {
2113
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" }) })
2114
2372
  ] }, i))
2115
2373
  ) : /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
2116
- entries.map((e, idx) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
2117
- "tr",
2118
- {
2119
- draggable: true,
2120
- onDragStart: (evt) => onDragStart(evt, idx),
2121
- onDragOver: (evt) => onDragOver(evt, idx),
2122
- onDrop: (evt) => onDrop(evt, idx),
2123
- onDragEnd,
2124
- 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" : ""}`,
2125
- children: [
2126
- 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)),
2127
- /* @__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: [
2128
- /* @__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" }) }) }),
2129
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2130
- "button",
2131
- {
2132
- onClick: () => setEditing(e),
2133
- className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
2134
- title: "Edit",
2135
- children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Pencil, { className: "h-4 w-4" })
2136
- }
2137
- ),
2138
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
2139
- "button",
2140
- {
2141
- onClick: () => remove(e.id),
2142
- disabled: deletingId === e.id,
2143
- className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors disabled:opacity-50",
2144
- title: "Delete",
2145
- 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: [
2146
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
2147
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
2148
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.Trash2, { className: "h-4 w-4" })
2149
- }
2150
- )
2151
- ] }) })
2152
- ]
2153
- },
2154
- e.id
2155
- )),
2156
- 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)(
2157
2431
  "td",
2158
2432
  {
2159
2433
  colSpan: visibleFields.length + 1,
@@ -2165,7 +2439,68 @@ function CollectionEditor({ collection }) {
2165
2439
  }
2166
2440
  ) })
2167
2441
  ] }) })
2168
- ] }) })
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
+ ] })
2169
2504
  ] });
2170
2505
  }
2171
2506
  var PAGE_SIZE = 10;
@@ -2707,6 +3042,50 @@ function PasswordField({ value, onChange }) {
2707
3042
  )
2708
3043
  ] });
2709
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
+ }
2710
3089
 
2711
3090
  // src/admin/AdminLogin.tsx
2712
3091
  var import_react6 = require("react");
@@ -2972,6 +3351,7 @@ async function sendEmailNotification(content, apiUrl) {
2972
3351
  EditableImage,
2973
3352
  EditableLink,
2974
3353
  EditableList,
3354
+ EditableReference,
2975
3355
  EditableText,
2976
3356
  SubscriptionPage,
2977
3357
  SubscriptionProvider,