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/chunk-Y6FXYEAI.mjs +10 -0
- package/dist/index.d.mts +11 -2
- package/dist/index.d.ts +11 -2
- package/dist/index.js +435 -55
- package/dist/index.mjs +484 -104
- package/dist/types.d.mts +10 -1
- package/dist/types.d.ts +10 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -421,15 +421,15 @@ function useSubmit(formId) {
|
|
|
421
421
|
}
|
|
422
422
|
|
|
423
423
|
// src/editable.tsx
|
|
424
|
-
import { createElement, useEffect as useEffect3 } from "react";
|
|
424
|
+
import { createElement, useEffect as useEffect3, useState as useState4, Fragment as Fragment2 } from "react";
|
|
425
425
|
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
426
|
-
function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search) {
|
|
426
|
+
function useRegister(id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField) {
|
|
427
427
|
const ctx = useCmsOptional();
|
|
428
428
|
useEffect3(() => {
|
|
429
429
|
if (!ctx) return;
|
|
430
|
-
ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search });
|
|
430
|
+
ctx.registerEditable({ id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField });
|
|
431
431
|
return () => ctx.unregisterEditable(id);
|
|
432
|
-
}, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search]);
|
|
432
|
+
}, [ctx?.registerEditable, ctx?.unregisterEditable, id, type, label, section, pageId, defaultValue, itemSchema, fixedLength, search, collection, max, displayField]);
|
|
433
433
|
return ctx;
|
|
434
434
|
}
|
|
435
435
|
function editableClasses(active, selected) {
|
|
@@ -446,9 +446,10 @@ function EditableText({
|
|
|
446
446
|
pageId,
|
|
447
447
|
children,
|
|
448
448
|
as = "span",
|
|
449
|
-
className
|
|
449
|
+
className,
|
|
450
|
+
type = "text"
|
|
450
451
|
}) {
|
|
451
|
-
const ctx = useRegister(id,
|
|
452
|
+
const ctx = useRegister(id, type, label, section, pageId, children);
|
|
452
453
|
const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? String(ctx.overrides[id] ?? "") : children;
|
|
453
454
|
const active = !!ctx?.editMode;
|
|
454
455
|
const selected = ctx?.selectedId === id;
|
|
@@ -460,6 +461,13 @@ function EditableText({
|
|
|
460
461
|
e.stopPropagation();
|
|
461
462
|
ctx.setSelectedId(id);
|
|
462
463
|
};
|
|
464
|
+
let finalChildren = renderValue;
|
|
465
|
+
if (typeof renderValue === "string" && renderValue.includes("\n")) {
|
|
466
|
+
finalChildren = renderValue.split("\n").map((line, i, arr) => /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
467
|
+
line,
|
|
468
|
+
i < arr.length - 1 && /* @__PURE__ */ jsx4("br", {})
|
|
469
|
+
] }, i));
|
|
470
|
+
}
|
|
463
471
|
return createElement(
|
|
464
472
|
as,
|
|
465
473
|
{
|
|
@@ -471,7 +479,7 @@ function EditableText({
|
|
|
471
479
|
"data-cms-id": id,
|
|
472
480
|
onClick: active ? onClick : void 0
|
|
473
481
|
},
|
|
474
|
-
|
|
482
|
+
finalChildren
|
|
475
483
|
);
|
|
476
484
|
}
|
|
477
485
|
function EditableImage({
|
|
@@ -498,7 +506,7 @@ function EditableImage({
|
|
|
498
506
|
return /* @__PURE__ */ jsx4(
|
|
499
507
|
"img",
|
|
500
508
|
{
|
|
501
|
-
src: value,
|
|
509
|
+
src: value || void 0,
|
|
502
510
|
alt,
|
|
503
511
|
width,
|
|
504
512
|
height,
|
|
@@ -646,9 +654,61 @@ function EditableList({
|
|
|
646
654
|
}
|
|
647
655
|
);
|
|
648
656
|
}
|
|
657
|
+
function EditableReference({
|
|
658
|
+
id,
|
|
659
|
+
label,
|
|
660
|
+
section,
|
|
661
|
+
pageId,
|
|
662
|
+
collection,
|
|
663
|
+
max,
|
|
664
|
+
displayField,
|
|
665
|
+
className,
|
|
666
|
+
children
|
|
667
|
+
}) {
|
|
668
|
+
const ctx = useRegister(id, "reference", label, section, pageId, max === 1 ? "" : [], void 0, void 0, void 0, collection, max, displayField);
|
|
669
|
+
const active = !!ctx?.editMode;
|
|
670
|
+
const selected = ctx?.selectedId === id;
|
|
671
|
+
const value = ctx && Object.prototype.hasOwnProperty.call(ctx.overrides, id) ? ctx.overrides[id] : void 0;
|
|
672
|
+
const [resolvedItems, setResolvedItems] = useState4([]);
|
|
673
|
+
useEffect3(() => {
|
|
674
|
+
if (!ctx) return;
|
|
675
|
+
const ids = Array.isArray(value) ? value : value ? [value] : [];
|
|
676
|
+
if (ids.length === 0) {
|
|
677
|
+
setResolvedItems([]);
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
ctx.adapter.listEntries(collection).then((res) => {
|
|
681
|
+
setResolvedItems(res.filter((r) => ids.includes(r.id)));
|
|
682
|
+
}).catch(() => {
|
|
683
|
+
});
|
|
684
|
+
}, [value, collection, ctx]);
|
|
685
|
+
const onClick = (e) => {
|
|
686
|
+
if (!active || !ctx) return;
|
|
687
|
+
e.preventDefault();
|
|
688
|
+
e.stopPropagation();
|
|
689
|
+
ctx.setSelectedId(id);
|
|
690
|
+
};
|
|
691
|
+
const childContent = typeof children === "function" ? children(resolvedItems) : children;
|
|
692
|
+
return /* @__PURE__ */ jsxs3(
|
|
693
|
+
"div",
|
|
694
|
+
{
|
|
695
|
+
"data-cms-id": id,
|
|
696
|
+
onClick: active ? onClick : void 0,
|
|
697
|
+
className: [className, editableClasses(active, selected)].filter(Boolean).join(" "),
|
|
698
|
+
children: [
|
|
699
|
+
childContent,
|
|
700
|
+
active && (!resolvedItems || resolvedItems.length === 0) && /* @__PURE__ */ jsxs3("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: [
|
|
701
|
+
"Empty Reference ",
|
|
702
|
+
label ? `(${label})` : "",
|
|
703
|
+
" \u2014 Click to select"
|
|
704
|
+
] })
|
|
705
|
+
]
|
|
706
|
+
}
|
|
707
|
+
);
|
|
708
|
+
}
|
|
649
709
|
|
|
650
710
|
// src/admin/AdminApp.tsx
|
|
651
|
-
import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef2, useState as
|
|
711
|
+
import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo2, useRef as useRef2, useState as useState5 } from "react";
|
|
652
712
|
import {
|
|
653
713
|
FileText,
|
|
654
714
|
Boxes,
|
|
@@ -675,10 +735,11 @@ import {
|
|
|
675
735
|
ChevronRight,
|
|
676
736
|
SlidersHorizontal,
|
|
677
737
|
LogOut,
|
|
678
|
-
ExternalLink as ExternalLink2
|
|
738
|
+
ExternalLink as ExternalLink2,
|
|
739
|
+
Check
|
|
679
740
|
} from "lucide-react";
|
|
680
741
|
import { CreditCard as CreditCard2 } from "lucide-react";
|
|
681
|
-
import { Fragment as
|
|
742
|
+
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
682
743
|
async function handleImageFile(file, onUrl, uploadImage) {
|
|
683
744
|
if (uploadImage) {
|
|
684
745
|
try {
|
|
@@ -700,9 +761,9 @@ function AdminApp({ apiUrl, projectId, email }) {
|
|
|
700
761
|
return /* @__PURE__ */ jsx5(AdminAppContent, {});
|
|
701
762
|
}
|
|
702
763
|
function AdminAppContent() {
|
|
703
|
-
const [section, setSection] =
|
|
704
|
-
const [authChecking, setAuthChecking] =
|
|
705
|
-
const [authenticated, setAuthenticated] =
|
|
764
|
+
const [section, setSection] = useState5("pages");
|
|
765
|
+
const [authChecking, setAuthChecking] = useState5(true);
|
|
766
|
+
const [authenticated, setAuthenticated] = useState5(false);
|
|
706
767
|
const ctx = useCmsContext();
|
|
707
768
|
useEffect4(() => {
|
|
708
769
|
fetch("/api/admin/auth").then((res) => res.json()).then((data) => {
|
|
@@ -864,7 +925,7 @@ function PageListItem({
|
|
|
864
925
|
onSelect,
|
|
865
926
|
depth = 0
|
|
866
927
|
}) {
|
|
867
|
-
const [expanded, setExpanded] =
|
|
928
|
+
const [expanded, setExpanded] = useState5(false);
|
|
868
929
|
if (p.isSeparator) {
|
|
869
930
|
return /* @__PURE__ */ jsx5("li", { className: "my-2 border-t border-slate-200/60" });
|
|
870
931
|
}
|
|
@@ -915,10 +976,10 @@ function PageListItem({
|
|
|
915
976
|
}
|
|
916
977
|
function PagesSection() {
|
|
917
978
|
const ctx = useCmsContext();
|
|
918
|
-
const [selected, setSelected] =
|
|
979
|
+
const [selected, setSelected] = useState5(
|
|
919
980
|
ctx.config.pages[0] ?? null
|
|
920
981
|
);
|
|
921
|
-
const [showList, setShowList] =
|
|
982
|
+
const [showList, setShowList] = useState5(true);
|
|
922
983
|
return /* @__PURE__ */ jsxs4("div", { className: "flex flex-col lg:flex-row h-full", children: [
|
|
923
984
|
showList && /* @__PURE__ */ jsxs4("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: [
|
|
924
985
|
/* @__PURE__ */ jsx5("div", { className: "mb-3 px-2 text-xs font-bold uppercase tracking-widest text-slate-500 hidden lg:block", children: "Pages" }),
|
|
@@ -948,10 +1009,10 @@ function PagesSection() {
|
|
|
948
1009
|
function PageEditor({ page, showList, onToggleList }) {
|
|
949
1010
|
const ctx = useCmsContext();
|
|
950
1011
|
const iframeRef = useRef2(null);
|
|
951
|
-
const [registered, setRegistered] =
|
|
952
|
-
const [selectedId, setSelectedId] =
|
|
953
|
-
const [preview, setPreview] =
|
|
954
|
-
const [drawerState, setDrawerState] =
|
|
1012
|
+
const [registered, setRegistered] = useState5([]);
|
|
1013
|
+
const [selectedId, setSelectedId] = useState5(null);
|
|
1014
|
+
const [preview, setPreview] = useState5(false);
|
|
1015
|
+
const [drawerState, setDrawerState] = useState5("half");
|
|
955
1016
|
const src = useMemo2(
|
|
956
1017
|
() => `${page.path}${preview ? "" : "?__cms=edit"}`,
|
|
957
1018
|
[page.path, preview]
|
|
@@ -993,7 +1054,7 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
993
1054
|
[ctx]
|
|
994
1055
|
);
|
|
995
1056
|
const selectedMeta = registered.find((r) => r.id === selectedId) ?? null;
|
|
996
|
-
const [viewMode, setViewMode] =
|
|
1057
|
+
const [viewMode, setViewMode] = useState5("desktop");
|
|
997
1058
|
return /* @__PURE__ */ jsxs4("div", { className: "flex h-full flex-col", children: [
|
|
998
1059
|
/* @__PURE__ */ jsxs4("div", { className: "flex flex-col sm:flex-row items-start sm:items-center justify-between gap-3 border-b border-slate-200 bg-white/80 backdrop-blur px-4 py-3 shadow-sm z-10 shrink-0", children: [
|
|
999
1060
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 text-sm shrink-0", children: [
|
|
@@ -1118,7 +1179,7 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
1118
1179
|
},
|
|
1119
1180
|
onClose: () => setSelectedId(null)
|
|
1120
1181
|
}
|
|
1121
|
-
) : /* @__PURE__ */ jsxs4(
|
|
1182
|
+
) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
1122
1183
|
page.hideable && /* @__PURE__ */ jsxs4("div", { className: "px-5 py-4 border-b border-slate-100 bg-slate-50/50", children: [
|
|
1123
1184
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center space-x-3", children: [
|
|
1124
1185
|
/* @__PURE__ */ jsx5(
|
|
@@ -1159,7 +1220,7 @@ function SectionAccordion({
|
|
|
1159
1220
|
registered,
|
|
1160
1221
|
onSelect
|
|
1161
1222
|
}) {
|
|
1162
|
-
const [expanded, setExpanded] =
|
|
1223
|
+
const [expanded, setExpanded] = useState5({});
|
|
1163
1224
|
if (registered.length === 0) {
|
|
1164
1225
|
return /* @__PURE__ */ jsxs4("div", { className: "px-4 py-8 text-center text-sm text-slate-500", children: [
|
|
1165
1226
|
/* @__PURE__ */ jsx5("div", { className: "w-12 h-12 bg-slate-100 rounded-full flex items-center justify-center mx-auto mb-3", children: /* @__PURE__ */ jsx5(Pencil, { className: "h-5 w-5 text-slate-400" }) }),
|
|
@@ -1232,6 +1293,74 @@ function FieldListItem({ meta, onSelect }) {
|
|
|
1232
1293
|
}
|
|
1233
1294
|
) });
|
|
1234
1295
|
}
|
|
1296
|
+
function SidebarReferenceSelect({ meta, value, onChange }) {
|
|
1297
|
+
const ctx = useCmsContext();
|
|
1298
|
+
const collection = ctx.config.collections?.find((c) => c.id === meta.collection);
|
|
1299
|
+
const [items, setItems] = useState5([]);
|
|
1300
|
+
const [search, setSearch] = useState5("");
|
|
1301
|
+
const [loading, setLoading] = useState5(true);
|
|
1302
|
+
useEffect4(() => {
|
|
1303
|
+
if (!meta.collection) return;
|
|
1304
|
+
setLoading(true);
|
|
1305
|
+
ctx.adapter.listEntries(meta.collection).then((res) => {
|
|
1306
|
+
setItems(res);
|
|
1307
|
+
setLoading(false);
|
|
1308
|
+
});
|
|
1309
|
+
}, [meta.collection, ctx.adapter]);
|
|
1310
|
+
const selectedIds = Array.isArray(value) ? value : value ? [value] : [];
|
|
1311
|
+
const max = meta.max ?? 1;
|
|
1312
|
+
const toggle = (id) => {
|
|
1313
|
+
if (max === 1) {
|
|
1314
|
+
onChange([id]);
|
|
1315
|
+
} else {
|
|
1316
|
+
if (selectedIds.includes(id)) {
|
|
1317
|
+
onChange(selectedIds.filter((s) => s !== id));
|
|
1318
|
+
} else if (selectedIds.length < max) {
|
|
1319
|
+
onChange([...selectedIds, id]);
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1322
|
+
};
|
|
1323
|
+
const imgField = collection?.fields.find((f) => f.type === "image");
|
|
1324
|
+
const txtField = collection?.fields.find((f) => f.type === "text" || f.type === "textarea" || f.type === "richtext");
|
|
1325
|
+
const filtered = items.filter((it) => {
|
|
1326
|
+
if (!search) return true;
|
|
1327
|
+
const q = search.toLowerCase();
|
|
1328
|
+
const txt = String(it[txtField?.id || "id"] || "");
|
|
1329
|
+
return txt.toLowerCase().includes(q);
|
|
1330
|
+
});
|
|
1331
|
+
return /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
1332
|
+
/* @__PURE__ */ jsx5(
|
|
1333
|
+
"input",
|
|
1334
|
+
{
|
|
1335
|
+
placeholder: "Search...",
|
|
1336
|
+
value: search,
|
|
1337
|
+
onChange: (e) => setSearch(e.target.value),
|
|
1338
|
+
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"
|
|
1339
|
+
}
|
|
1340
|
+
),
|
|
1341
|
+
/* @__PURE__ */ jsxs4("div", { className: "space-y-2 max-h-60 overflow-y-auto pr-1", children: [
|
|
1342
|
+
loading ? /* @__PURE__ */ jsx5("p", { className: "text-xs text-slate-500", children: "Loading..." }) : filtered.map((it) => {
|
|
1343
|
+
const isSelected = selectedIds.includes(it.id);
|
|
1344
|
+
const imgSrc = imgField ? it[imgField.id] : null;
|
|
1345
|
+
const label = txtField ? it[txtField.id] : it.id;
|
|
1346
|
+
return /* @__PURE__ */ jsxs4(
|
|
1347
|
+
"div",
|
|
1348
|
+
{
|
|
1349
|
+
onClick: () => toggle(it.id),
|
|
1350
|
+
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"}`,
|
|
1351
|
+
children: [
|
|
1352
|
+
!!imgSrc && /* @__PURE__ */ jsx5("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" }),
|
|
1353
|
+
/* @__PURE__ */ jsx5("span", { className: `text-sm ${isSelected ? "font-semibold text-indigo-900" : "text-slate-700"}`, children: String(label) }),
|
|
1354
|
+
isSelected && /* @__PURE__ */ jsx5(Check, { className: "w-4 h-4 text-indigo-600 ml-auto" })
|
|
1355
|
+
]
|
|
1356
|
+
},
|
|
1357
|
+
it.id
|
|
1358
|
+
);
|
|
1359
|
+
}),
|
|
1360
|
+
!loading && filtered.length === 0 && /* @__PURE__ */ jsx5("p", { className: "text-xs text-slate-500 text-center py-4", children: "No items found." })
|
|
1361
|
+
] })
|
|
1362
|
+
] });
|
|
1363
|
+
}
|
|
1235
1364
|
function FieldEditor({
|
|
1236
1365
|
meta,
|
|
1237
1366
|
value,
|
|
@@ -1240,8 +1369,8 @@ function FieldEditor({
|
|
|
1240
1369
|
onClose
|
|
1241
1370
|
}) {
|
|
1242
1371
|
const ctx = useCmsContext();
|
|
1243
|
-
const [expandedItems, setExpandedItems] =
|
|
1244
|
-
const [searchQuery, setSearchQuery] =
|
|
1372
|
+
const [expandedItems, setExpandedItems] = useState5({});
|
|
1373
|
+
const [searchQuery, setSearchQuery] = useState5("");
|
|
1245
1374
|
return /* @__PURE__ */ jsxs4("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
|
|
1246
1375
|
/* @__PURE__ */ jsxs4("div", { className: "mb-5", children: [
|
|
1247
1376
|
/* @__PURE__ */ jsx5("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 }),
|
|
@@ -1613,7 +1742,7 @@ function FieldEditor({
|
|
|
1613
1742
|
}
|
|
1614
1743
|
)
|
|
1615
1744
|
] }),
|
|
1616
|
-
"
|
|
1745
|
+
meta.type === "reference" && /* @__PURE__ */ jsx5(SidebarReferenceSelect, { meta, value, onChange })
|
|
1617
1746
|
] }),
|
|
1618
1747
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between pt-6 mt-6 border-t border-slate-100", children: [
|
|
1619
1748
|
/* @__PURE__ */ jsxs4(
|
|
@@ -1641,10 +1770,10 @@ function FieldEditor({
|
|
|
1641
1770
|
function CollectionsSection() {
|
|
1642
1771
|
const ctx = useCmsContext();
|
|
1643
1772
|
const collections = ctx.config.collections ?? [];
|
|
1644
|
-
const [selected, setSelected] =
|
|
1773
|
+
const [selected, setSelected] = useState5(
|
|
1645
1774
|
collections[0] ?? null
|
|
1646
1775
|
);
|
|
1647
|
-
const [counts, setCounts] =
|
|
1776
|
+
const [counts, setCounts] = useState5({});
|
|
1648
1777
|
useEffect4(() => {
|
|
1649
1778
|
collections.forEach((c) => {
|
|
1650
1779
|
ctx.adapter.listEntries(c.id).then((entries) => {
|
|
@@ -1681,13 +1810,17 @@ function CollectionsSection() {
|
|
|
1681
1810
|
}
|
|
1682
1811
|
function CollectionEditor({ collection }) {
|
|
1683
1812
|
const ctx = useCmsContext();
|
|
1684
|
-
const [entries, setEntries] =
|
|
1685
|
-
const [editing, setEditing] =
|
|
1686
|
-
const [saving, setSaving] =
|
|
1687
|
-
const [deletingId, setDeletingId] =
|
|
1688
|
-
const [loadingEntries, setLoadingEntries] =
|
|
1689
|
-
const [draggedIdx, setDraggedIdx] =
|
|
1690
|
-
const [dragOverIdx, setDragOverIdx] =
|
|
1813
|
+
const [entries, setEntries] = useState5([]);
|
|
1814
|
+
const [editing, setEditing] = useState5(null);
|
|
1815
|
+
const [saving, setSaving] = useState5(false);
|
|
1816
|
+
const [deletingId, setDeletingId] = useState5(null);
|
|
1817
|
+
const [loadingEntries, setLoadingEntries] = useState5(true);
|
|
1818
|
+
const [draggedIdx, setDraggedIdx] = useState5(null);
|
|
1819
|
+
const [dragOverIdx, setDragOverIdx] = useState5(null);
|
|
1820
|
+
const [search, setSearch] = useState5("");
|
|
1821
|
+
const [filters, setFilters] = useState5({});
|
|
1822
|
+
const [page, setPage] = useState5(1);
|
|
1823
|
+
const itemsPerPage = 10;
|
|
1691
1824
|
const load = useCallback3(() => {
|
|
1692
1825
|
setLoadingEntries(true);
|
|
1693
1826
|
ctx.adapter.listEntries(collection.id).then((res) => {
|
|
@@ -1720,7 +1853,16 @@ function CollectionEditor({ collection }) {
|
|
|
1720
1853
|
if (!editing) return;
|
|
1721
1854
|
setSaving(true);
|
|
1722
1855
|
try {
|
|
1723
|
-
|
|
1856
|
+
const finalEditing = { ...editing };
|
|
1857
|
+
collection.fields.forEach((f) => {
|
|
1858
|
+
if (f.type === "slug" && !finalEditing[f.id]) {
|
|
1859
|
+
const sourceField = f.source || "title";
|
|
1860
|
+
let val = String(finalEditing[sourceField] || finalEditing.id || "");
|
|
1861
|
+
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
1862
|
+
finalEditing[f.id] = val;
|
|
1863
|
+
}
|
|
1864
|
+
});
|
|
1865
|
+
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
1724
1866
|
ctx.notifyCollectionChanged();
|
|
1725
1867
|
setEditing(null);
|
|
1726
1868
|
load();
|
|
@@ -1773,7 +1915,7 @@ function CollectionEditor({ collection }) {
|
|
|
1773
1915
|
setDraggedIdx(null);
|
|
1774
1916
|
setDragOverIdx(null);
|
|
1775
1917
|
};
|
|
1776
|
-
const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order").slice(0, 5);
|
|
1918
|
+
const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 5);
|
|
1777
1919
|
return /* @__PURE__ */ jsxs4("div", { className: "mx-auto max-w-5xl", children: [
|
|
1778
1920
|
/* @__PURE__ */ jsxs4("div", { className: "mb-8 flex items-center justify-between", children: [
|
|
1779
1921
|
/* @__PURE__ */ jsxs4("div", { children: [
|
|
@@ -1792,12 +1934,56 @@ function CollectionEditor({ collection }) {
|
|
|
1792
1934
|
}
|
|
1793
1935
|
)
|
|
1794
1936
|
] }),
|
|
1937
|
+
!editing && (collection.searchBy?.length || collection.filterBy?.length) && /* @__PURE__ */ jsxs4("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: [
|
|
1938
|
+
collection.searchBy?.length ? /* @__PURE__ */ jsxs4("div", { className: "relative flex-1 min-w-[200px]", children: [
|
|
1939
|
+
/* @__PURE__ */ jsx5(Search, { className: "absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" }),
|
|
1940
|
+
/* @__PURE__ */ jsx5(
|
|
1941
|
+
"input",
|
|
1942
|
+
{
|
|
1943
|
+
type: "text",
|
|
1944
|
+
placeholder: `Search by ${collection.searchBy.join(", ")}...`,
|
|
1945
|
+
value: search,
|
|
1946
|
+
onChange: (e) => {
|
|
1947
|
+
setSearch(e.target.value);
|
|
1948
|
+
setPage(1);
|
|
1949
|
+
},
|
|
1950
|
+
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"
|
|
1951
|
+
}
|
|
1952
|
+
)
|
|
1953
|
+
] }) : null,
|
|
1954
|
+
collection.filterBy?.map((f) => {
|
|
1955
|
+
const fieldDef = collection.fields.find((cf) => cf.id === f);
|
|
1956
|
+
const uniqueVals = Array.from(new Set(entries.map((e) => String(e[f] || "")))).filter(Boolean);
|
|
1957
|
+
if (!fieldDef || uniqueVals.length === 0) return null;
|
|
1958
|
+
return /* @__PURE__ */ jsxs4("div", { className: "min-w-[150px] relative", children: [
|
|
1959
|
+
/* @__PURE__ */ jsxs4(
|
|
1960
|
+
"select",
|
|
1961
|
+
{
|
|
1962
|
+
value: filters[f] || "",
|
|
1963
|
+
onChange: (e) => {
|
|
1964
|
+
setFilters((prev) => ({ ...prev, [f]: e.target.value }));
|
|
1965
|
+
setPage(1);
|
|
1966
|
+
},
|
|
1967
|
+
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",
|
|
1968
|
+
children: [
|
|
1969
|
+
/* @__PURE__ */ jsxs4("option", { value: "", children: [
|
|
1970
|
+
"All ",
|
|
1971
|
+
fieldDef.label
|
|
1972
|
+
] }),
|
|
1973
|
+
uniqueVals.map((v) => /* @__PURE__ */ jsx5("option", { value: v, children: v }, v))
|
|
1974
|
+
]
|
|
1975
|
+
}
|
|
1976
|
+
),
|
|
1977
|
+
/* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
|
|
1978
|
+
] }, f);
|
|
1979
|
+
})
|
|
1980
|
+
] }),
|
|
1795
1981
|
editing && /* @__PURE__ */ jsxs4("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: [
|
|
1796
1982
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 mb-6", children: [
|
|
1797
1983
|
/* @__PURE__ */ jsx5("div", { className: "w-8 h-8 rounded-full bg-indigo-100 flex items-center justify-center text-indigo-600", children: /* @__PURE__ */ jsx5(Pencil, { className: "w-4 h-4" }) }),
|
|
1798
1984
|
/* @__PURE__ */ jsx5("h3", { className: "text-lg font-bold text-slate-900", children: "Edit Entry" })
|
|
1799
1985
|
] }),
|
|
1800
|
-
/* @__PURE__ */ jsx5("div", { className: "grid gap-5 md:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order").map((f) => /* @__PURE__ */ jsxs4("label", { className: `block ${f.type === "richtext" ? "md:col-span-2" : ""}`, children: [
|
|
1986
|
+
/* @__PURE__ */ jsx5("div", { className: "grid gap-5 md:grid-cols-2", children: collection.fields.filter((f) => f.id !== "order" && !f.hidden).map((f) => /* @__PURE__ */ jsxs4("label", { className: `block ${f.type === "richtext" ? "md:col-span-2" : ""}`, children: [
|
|
1801
1987
|
/* @__PURE__ */ jsxs4("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
|
|
1802
1988
|
f.label,
|
|
1803
1989
|
/* @__PURE__ */ jsx5("span", { className: "text-[10px] font-mono text-slate-300 bg-slate-50 px-1.5 py-0.5 rounded", children: f.type })
|
|
@@ -1859,7 +2045,15 @@ function CollectionEditor({ collection }) {
|
|
|
1859
2045
|
children: "Generate"
|
|
1860
2046
|
}
|
|
1861
2047
|
)
|
|
1862
|
-
] }) : f.type === "
|
|
2048
|
+
] }) : f.type === "reference" ? /* @__PURE__ */ jsx5(
|
|
2049
|
+
ReferenceSelect,
|
|
2050
|
+
{
|
|
2051
|
+
collectionId: f.collection,
|
|
2052
|
+
displayField: f.displayField,
|
|
2053
|
+
value: String(editing[f.id] ?? ""),
|
|
2054
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2055
|
+
}
|
|
2056
|
+
) : f.type === "select" ? /* @__PURE__ */ jsxs4("div", { children: [
|
|
1863
2057
|
/* @__PURE__ */ jsx5(
|
|
1864
2058
|
"input",
|
|
1865
2059
|
{
|
|
@@ -1874,7 +2068,71 @@ function CollectionEditor({ collection }) {
|
|
|
1874
2068
|
const lab = typeof opt === "string" ? opt : opt.label;
|
|
1875
2069
|
return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
|
|
1876
2070
|
}) })
|
|
1877
|
-
] }) : f.type === "image" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2071
|
+
] }) : f.type === "image" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2072
|
+
/* @__PURE__ */ jsx5("div", { className: "flex flex-wrap gap-3", children: (editing[f.id] || []).map((url, i) => /* @__PURE__ */ jsxs4("div", { className: "rounded-xl border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group w-32 h-32", children: [
|
|
2073
|
+
/* @__PURE__ */ jsx5("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
|
|
2074
|
+
/* @__PURE__ */ jsx5(
|
|
2075
|
+
"button",
|
|
2076
|
+
{
|
|
2077
|
+
type: "button",
|
|
2078
|
+
onClick: () => {
|
|
2079
|
+
const arr = [...editing[f.id] || []];
|
|
2080
|
+
arr.splice(i, 1);
|
|
2081
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2082
|
+
},
|
|
2083
|
+
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",
|
|
2084
|
+
children: /* @__PURE__ */ jsx5(X, { className: "w-3 h-3" })
|
|
2085
|
+
}
|
|
2086
|
+
)
|
|
2087
|
+
] }, i)) }),
|
|
2088
|
+
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2089
|
+
/* @__PURE__ */ jsx5(
|
|
2090
|
+
"input",
|
|
2091
|
+
{
|
|
2092
|
+
type: "url",
|
|
2093
|
+
placeholder: "Add image URL and press Enter...",
|
|
2094
|
+
onKeyDown: (e) => {
|
|
2095
|
+
if (e.key === "Enter" && e.currentTarget.value) {
|
|
2096
|
+
e.preventDefault();
|
|
2097
|
+
const arr = [...editing[f.id] || [], e.currentTarget.value];
|
|
2098
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2099
|
+
e.currentTarget.value = "";
|
|
2100
|
+
}
|
|
2101
|
+
},
|
|
2102
|
+
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"
|
|
2103
|
+
}
|
|
2104
|
+
),
|
|
2105
|
+
/* @__PURE__ */ jsxs4("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: [
|
|
2106
|
+
"Upload",
|
|
2107
|
+
/* @__PURE__ */ jsx5(
|
|
2108
|
+
"input",
|
|
2109
|
+
{
|
|
2110
|
+
type: "file",
|
|
2111
|
+
accept: "image/*",
|
|
2112
|
+
multiple: true,
|
|
2113
|
+
className: "hidden",
|
|
2114
|
+
onChange: (e) => {
|
|
2115
|
+
const files = Array.from(e.target.files || []);
|
|
2116
|
+
files.forEach((file) => {
|
|
2117
|
+
void handleImageFile(
|
|
2118
|
+
file,
|
|
2119
|
+
(url) => {
|
|
2120
|
+
setEditing((prev) => {
|
|
2121
|
+
if (!prev) return prev;
|
|
2122
|
+
const current = prev[f.id] || [];
|
|
2123
|
+
if (f.max && current.length >= f.max) return prev;
|
|
2124
|
+
return { ...prev, [f.id]: [...current, url] };
|
|
2125
|
+
});
|
|
2126
|
+
},
|
|
2127
|
+
ctx.uploadImage
|
|
2128
|
+
);
|
|
2129
|
+
});
|
|
2130
|
+
}
|
|
2131
|
+
}
|
|
2132
|
+
)
|
|
2133
|
+
] })
|
|
2134
|
+
] })
|
|
2135
|
+
] }) : /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
1878
2136
|
/* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
1879
2137
|
/* @__PURE__ */ jsx5(
|
|
1880
2138
|
"input",
|
|
@@ -2089,7 +2347,7 @@ function CollectionEditor({ collection }) {
|
|
|
2089
2347
|
onClick: save,
|
|
2090
2348
|
disabled: saving,
|
|
2091
2349
|
className: "inline-flex items-center gap-2 rounded-xl bg-slate-900 px-6 py-2.5 text-sm font-bold text-white shadow-sm hover:bg-slate-800 hover:shadow transition-all disabled:opacity-60",
|
|
2092
|
-
children: saving ? /* @__PURE__ */ jsxs4(
|
|
2350
|
+
children: saving ? /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2093
2351
|
/* @__PURE__ */ jsxs4("svg", { className: "animate-spin h-4 w-4 text-white", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
|
|
2094
2352
|
/* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
2095
2353
|
/* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
|
|
@@ -2111,48 +2369,64 @@ function CollectionEditor({ collection }) {
|
|
|
2111
2369
|
visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4", children: /* @__PURE__ */ jsx5("div", { className: "h-4 bg-slate-100 rounded animate-pulse", style: { width: `${60 + i * 13 % 30}%` } }) }, f.id)),
|
|
2112
2370
|
/* @__PURE__ */ jsx5("td", { className: "px-6 py-4 sticky right-0 bg-white border-l border-slate-100", children: /* @__PURE__ */ jsx5("div", { className: "h-4 w-16 bg-slate-100 rounded animate-pulse ml-auto" }) })
|
|
2113
2371
|
] }, i))
|
|
2114
|
-
) : /* @__PURE__ */ jsxs4(
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
{
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
|
|
2121
|
-
|
|
2122
|
-
|
|
2123
|
-
|
|
2124
|
-
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2372
|
+
) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2373
|
+
(() => {
|
|
2374
|
+
let res = entries;
|
|
2375
|
+
if (search && collection.searchBy?.length) {
|
|
2376
|
+
const q = search.toLowerCase();
|
|
2377
|
+
res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
|
|
2378
|
+
}
|
|
2379
|
+
if (Object.keys(filters).length > 0) {
|
|
2380
|
+
res = res.filter((e) => {
|
|
2381
|
+
for (const [k, v] of Object.entries(filters)) {
|
|
2382
|
+
if (v && String(e[k] || "") !== v) return false;
|
|
2383
|
+
}
|
|
2384
|
+
return true;
|
|
2385
|
+
});
|
|
2386
|
+
}
|
|
2387
|
+
const paginatedRes = res.slice((page - 1) * itemsPerPage, page * itemsPerPage);
|
|
2388
|
+
return /* @__PURE__ */ jsx5(Fragment3, { children: paginatedRes.map((e, idx) => /* @__PURE__ */ jsxs4(
|
|
2389
|
+
"tr",
|
|
2390
|
+
{
|
|
2391
|
+
draggable: true,
|
|
2392
|
+
onDragStart: (evt) => onDragStart(evt, idx),
|
|
2393
|
+
onDragOver: (evt) => onDragOver(evt, idx),
|
|
2394
|
+
onDrop: (evt) => onDrop(evt, idx),
|
|
2395
|
+
onDragEnd,
|
|
2396
|
+
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" : ""}`,
|
|
2397
|
+
children: [
|
|
2398
|
+
visibleFields.map((f) => /* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-slate-700 max-w-[200px] truncate", children: f.type === "boolean" ? e[f.id] ? /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-green-100 text-green-700 text-xs font-bold", children: "Yes" }) : /* @__PURE__ */ jsx5("span", { className: "inline-flex px-2 py-1 rounded bg-slate-100 text-slate-500 text-xs font-bold", children: "No" }) : f.type === "image" && (Array.isArray(e[f.id]) ? e[f.id].length > 0 : !!e[f.id]) ? /* @__PURE__ */ jsx5("img", { src: Array.isArray(e[f.id]) ? String(e[f.id][0]) : String(e[f.id]), alt: "", className: "h-8 w-8 object-cover rounded shadow-sm ring-1 ring-slate-200" }) : f.type === "image" ? /* @__PURE__ */ jsx5("div", { className: "h-8 w-8 rounded bg-slate-100 ring-1 ring-slate-200/50 flex items-center justify-center text-slate-300", children: /* @__PURE__ */ jsx5("svg", { className: "w-4 h-4", fill: "none", stroke: "currentColor", viewBox: "0 0 24 24", children: /* @__PURE__ */ jsx5("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: "2", d: "M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" }) }) }) : f.type === "reference" && e[f.id] ? /* @__PURE__ */ jsx5(ReferenceTableCell, { collectionId: f.collection, entryId: String(e[f.id]), displayField: f.displayField }) : String(e[f.id] ?? "") }, f.id)),
|
|
2399
|
+
/* @__PURE__ */ jsx5("td", { className: "px-6 py-4 text-right sticky right-0 bg-white border-l border-slate-100 group-hover:bg-slate-50/50 transition-colors", children: /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-end gap-2", children: [
|
|
2400
|
+
/* @__PURE__ */ jsx5("div", { className: "p-2 text-slate-300 cursor-grab active:cursor-grabbing", title: "Drag to reorder", children: /* @__PURE__ */ jsx5("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", className: "w-4 h-4", children: /* @__PURE__ */ jsx5("path", { d: "M5.5 3C6.32843 3 7 3.67157 7 4.5C7 5.32843 6.32843 6 5.5 6C4.67157 6 4 5.32843 4 4.5C4 3.67157 4.67157 3 5.5 3ZM9.5 3C10.3284 3 11 3.67157 11 4.5C11 5.32843 10.3284 6 9.5 6C8.67157 6 8 5.32843 8 4.5C8 3.67157 8.67157 3 9.5 3ZM5.5 7.5C6.32843 7.5 7 8.17157 7 9C7 9.82843 6.32843 10.5 5.5 10.5C4.67157 10.5 4 9.82843 4 9C4 8.17157 4.67157 7.5 5.5 7.5ZM9.5 7.5C10.3284 7.5 11 8.17157 11 9C11 9.82843 10.3284 10.5 9.5 10.5C8.67157 10.5 8 9.82843 8 9C8 8.17157 8.67157 7.5 9.5 7.5ZM5.5 12C6.32843 12 7 12.6716 7 13.5C7 14.3284 6.32843 15 5.5 15C4.67157 15 4 14.3284 4 13.5C4 12.6716 4.67157 12 5.5 12ZM9.5 12C10.3284 12 11 12.6716 11 13.5C11 14.3284 10.3284 15 9.5 15C8.67157 15 8 14.3284 8 13.5C8 12.6716 8.67157 12 9.5 12Z", fill: "currentColor", fillRule: "evenodd", clipRule: "evenodd" }) }) }),
|
|
2401
|
+
/* @__PURE__ */ jsx5(
|
|
2402
|
+
"button",
|
|
2403
|
+
{
|
|
2404
|
+
onClick: () => setEditing(e),
|
|
2405
|
+
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
2406
|
+
title: "Edit",
|
|
2407
|
+
children: /* @__PURE__ */ jsx5(Pencil, { className: "h-4 w-4" })
|
|
2408
|
+
}
|
|
2409
|
+
),
|
|
2410
|
+
/* @__PURE__ */ jsx5(
|
|
2411
|
+
"button",
|
|
2412
|
+
{
|
|
2413
|
+
onClick: () => remove(e.id),
|
|
2414
|
+
disabled: deletingId === e.id,
|
|
2415
|
+
className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors disabled:opacity-50",
|
|
2416
|
+
title: "Delete",
|
|
2417
|
+
children: deletingId === e.id ? /* @__PURE__ */ jsxs4("svg", { className: "animate-spin h-4 w-4", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [
|
|
2418
|
+
/* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
2419
|
+
/* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
|
|
2420
|
+
] }) : /* @__PURE__ */ jsx5(Trash2, { className: "h-4 w-4" })
|
|
2421
|
+
}
|
|
2422
|
+
)
|
|
2423
|
+
] }) })
|
|
2424
|
+
]
|
|
2425
|
+
},
|
|
2426
|
+
e.id
|
|
2427
|
+
)) });
|
|
2428
|
+
})(),
|
|
2429
|
+
entries.length === 0 && !search && Object.values(filters).every((v) => !v) && /* @__PURE__ */ jsx5("tr", { children: /* @__PURE__ */ jsx5(
|
|
2156
2430
|
"td",
|
|
2157
2431
|
{
|
|
2158
2432
|
colSpan: visibleFields.length + 1,
|
|
@@ -2164,15 +2438,76 @@ function CollectionEditor({ collection }) {
|
|
|
2164
2438
|
}
|
|
2165
2439
|
) })
|
|
2166
2440
|
] }) })
|
|
2167
|
-
] }) })
|
|
2441
|
+
] }) }),
|
|
2442
|
+
!loadingEntries && entries.length > 0 && /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between text-sm text-slate-500 mt-4 px-2", children: [
|
|
2443
|
+
/* @__PURE__ */ jsx5("span", { children: (() => {
|
|
2444
|
+
let res = entries;
|
|
2445
|
+
if (search && collection.searchBy?.length) {
|
|
2446
|
+
const q = search.toLowerCase();
|
|
2447
|
+
res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
|
|
2448
|
+
}
|
|
2449
|
+
if (Object.keys(filters).length > 0) {
|
|
2450
|
+
res = res.filter((e) => {
|
|
2451
|
+
for (const [k, v] of Object.entries(filters)) {
|
|
2452
|
+
if (v && String(e[k] || "") !== v) return false;
|
|
2453
|
+
}
|
|
2454
|
+
return true;
|
|
2455
|
+
});
|
|
2456
|
+
}
|
|
2457
|
+
return `${res.length} item${res.length !== 1 ? "s" : ""}`;
|
|
2458
|
+
})() }),
|
|
2459
|
+
(() => {
|
|
2460
|
+
let res = entries;
|
|
2461
|
+
if (search && collection.searchBy?.length) {
|
|
2462
|
+
const q = search.toLowerCase();
|
|
2463
|
+
res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
|
|
2464
|
+
}
|
|
2465
|
+
if (Object.keys(filters).length > 0) {
|
|
2466
|
+
res = res.filter((e) => {
|
|
2467
|
+
for (const [k, v] of Object.entries(filters)) {
|
|
2468
|
+
if (v && String(e[k] || "") !== v) return false;
|
|
2469
|
+
}
|
|
2470
|
+
return true;
|
|
2471
|
+
});
|
|
2472
|
+
}
|
|
2473
|
+
const totalPages = Math.max(1, Math.ceil(res.length / itemsPerPage));
|
|
2474
|
+
if (totalPages <= 1) return null;
|
|
2475
|
+
return /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
|
|
2476
|
+
/* @__PURE__ */ jsx5(
|
|
2477
|
+
"button",
|
|
2478
|
+
{
|
|
2479
|
+
onClick: () => setPage((p) => Math.max(1, p - 1)),
|
|
2480
|
+
disabled: page === 1,
|
|
2481
|
+
className: "p-2 rounded-lg hover:bg-slate-100 disabled:opacity-30 transition-colors",
|
|
2482
|
+
children: /* @__PURE__ */ jsx5(ChevronLeft, { className: "h-4 w-4" })
|
|
2483
|
+
}
|
|
2484
|
+
),
|
|
2485
|
+
/* @__PURE__ */ jsxs4("span", { className: "font-medium text-slate-700", children: [
|
|
2486
|
+
"Page ",
|
|
2487
|
+
page,
|
|
2488
|
+
" of ",
|
|
2489
|
+
totalPages
|
|
2490
|
+
] }),
|
|
2491
|
+
/* @__PURE__ */ jsx5(
|
|
2492
|
+
"button",
|
|
2493
|
+
{
|
|
2494
|
+
onClick: () => setPage((p) => Math.min(totalPages, p + 1)),
|
|
2495
|
+
disabled: page === totalPages,
|
|
2496
|
+
className: "p-2 rounded-lg hover:bg-slate-100 disabled:opacity-30 transition-colors",
|
|
2497
|
+
children: /* @__PURE__ */ jsx5(ChevronRight, { className: "h-4 w-4" })
|
|
2498
|
+
}
|
|
2499
|
+
)
|
|
2500
|
+
] });
|
|
2501
|
+
})()
|
|
2502
|
+
] })
|
|
2168
2503
|
] });
|
|
2169
2504
|
}
|
|
2170
2505
|
var PAGE_SIZE = 10;
|
|
2171
2506
|
function SubmissionsSection() {
|
|
2172
2507
|
const ctx = useCmsContext();
|
|
2173
|
-
const [submissions, setSubmissions] =
|
|
2174
|
-
const [loading, setLoading] =
|
|
2175
|
-
const [selectedFormId, setSelectedFormId] =
|
|
2508
|
+
const [submissions, setSubmissions] = useState5([]);
|
|
2509
|
+
const [loading, setLoading] = useState5(false);
|
|
2510
|
+
const [selectedFormId, setSelectedFormId] = useState5(null);
|
|
2176
2511
|
const load = useCallback3(async () => {
|
|
2177
2512
|
setLoading(true);
|
|
2178
2513
|
const all = await ctx.adapter.listSubmissions();
|
|
@@ -2226,9 +2561,9 @@ function SubmissionsSection() {
|
|
|
2226
2561
|
}
|
|
2227
2562
|
function SubmissionsList({ formId, submissions, onLoad, loading }) {
|
|
2228
2563
|
const ctx = useCmsContext();
|
|
2229
|
-
const [search, setSearch] =
|
|
2230
|
-
const [page, setPage] =
|
|
2231
|
-
const [detail, setDetail] =
|
|
2564
|
+
const [search, setSearch] = useState5("");
|
|
2565
|
+
const [page, setPage] = useState5(1);
|
|
2566
|
+
const [detail, setDetail] = useState5(null);
|
|
2232
2567
|
const filtered = submissions.filter((s) => {
|
|
2233
2568
|
const q = search.toLowerCase();
|
|
2234
2569
|
if (!q) return true;
|
|
@@ -2508,7 +2843,7 @@ function SettingsSection() {
|
|
|
2508
2843
|
function ConfigSection() {
|
|
2509
2844
|
const ctx = useCmsContext();
|
|
2510
2845
|
const globals = ctx.config.globals ?? [];
|
|
2511
|
-
const [selectedGroupId, setSelectedGroupId] =
|
|
2846
|
+
const [selectedGroupId, setSelectedGroupId] = useState5(
|
|
2512
2847
|
globals[0]?.id ?? null
|
|
2513
2848
|
);
|
|
2514
2849
|
const selectedGroup = globals.find((g) => g.id === selectedGroupId) ?? null;
|
|
@@ -2598,8 +2933,8 @@ function Row({
|
|
|
2598
2933
|
] });
|
|
2599
2934
|
}
|
|
2600
2935
|
function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
2601
|
-
const [open, setOpen] =
|
|
2602
|
-
const [search, setSearch] =
|
|
2936
|
+
const [open, setOpen] = useState5(false);
|
|
2937
|
+
const [search, setSearch] = useState5("");
|
|
2603
2938
|
const filtered = options.filter((o) => o.toLowerCase().includes(search.toLowerCase()));
|
|
2604
2939
|
const capped = filtered.slice(0, 80);
|
|
2605
2940
|
const SelectedIcon = iconMap && value ? iconMap[value] : null;
|
|
@@ -2622,7 +2957,7 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
2622
2957
|
]
|
|
2623
2958
|
}
|
|
2624
2959
|
),
|
|
2625
|
-
open && /* @__PURE__ */ jsxs4(
|
|
2960
|
+
open && /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2626
2961
|
/* @__PURE__ */ jsx5("div", { className: "fixed inset-0 z-[100]", onClick: () => setOpen(false) }),
|
|
2627
2962
|
/* @__PURE__ */ jsxs4("div", { className: "absolute z-[101] mt-1 w-full rounded-xl border border-slate-200 bg-white shadow-2xl max-h-72 flex flex-col overflow-hidden animate-in fade-in slide-in-from-top-1 duration-150", children: [
|
|
2628
2963
|
/* @__PURE__ */ jsxs4("div", { className: "p-2 border-b border-slate-100 flex items-center gap-2", children: [
|
|
@@ -2676,10 +3011,10 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
2676
3011
|
] });
|
|
2677
3012
|
}
|
|
2678
3013
|
function PasswordField({ value, onChange }) {
|
|
2679
|
-
const [show, setShow] =
|
|
3014
|
+
const [show, setShow] = useState5(false);
|
|
2680
3015
|
const isHash = value.startsWith("$2a$") || value.startsWith("$2b$");
|
|
2681
|
-
const [displayValue, setDisplayValue] =
|
|
2682
|
-
const [pristine, setPristine] =
|
|
3016
|
+
const [displayValue, setDisplayValue] = useState5(isHash ? "" : value);
|
|
3017
|
+
const [pristine, setPristine] = useState5(isHash);
|
|
2683
3018
|
return /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
|
|
2684
3019
|
/* @__PURE__ */ jsx5(
|
|
2685
3020
|
"input",
|
|
@@ -2706,20 +3041,64 @@ function PasswordField({ value, onChange }) {
|
|
|
2706
3041
|
)
|
|
2707
3042
|
] });
|
|
2708
3043
|
}
|
|
3044
|
+
function ReferenceSelect({ collectionId, displayField = "id", value, onChange }) {
|
|
3045
|
+
const ctx = useCmsContext();
|
|
3046
|
+
const [options, setOptions] = useState5([]);
|
|
3047
|
+
const [loading, setLoading] = useState5(true);
|
|
3048
|
+
useEffect4(() => {
|
|
3049
|
+
if (!collectionId) {
|
|
3050
|
+
setLoading(false);
|
|
3051
|
+
return;
|
|
3052
|
+
}
|
|
3053
|
+
setLoading(true);
|
|
3054
|
+
ctx.adapter.listEntries(collectionId).then((res) => {
|
|
3055
|
+
setOptions(res.map((r) => ({ id: r.id, label: String(r[displayField] || r.id) })));
|
|
3056
|
+
setLoading(false);
|
|
3057
|
+
}).catch(() => setLoading(false));
|
|
3058
|
+
}, [collectionId, displayField, ctx.adapter]);
|
|
3059
|
+
return /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
|
|
3060
|
+
/* @__PURE__ */ jsxs4(
|
|
3061
|
+
"select",
|
|
3062
|
+
{
|
|
3063
|
+
value,
|
|
3064
|
+
onChange: (e) => onChange(e.target.value),
|
|
3065
|
+
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",
|
|
3066
|
+
children: [
|
|
3067
|
+
/* @__PURE__ */ jsx5("option", { value: "", children: loading ? "Loading..." : "Select..." }),
|
|
3068
|
+
options.map((o) => /* @__PURE__ */ jsx5("option", { value: o.id, children: o.label }, o.id))
|
|
3069
|
+
]
|
|
3070
|
+
}
|
|
3071
|
+
),
|
|
3072
|
+
/* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
|
|
3073
|
+
] });
|
|
3074
|
+
}
|
|
3075
|
+
function ReferenceTableCell({ collectionId, entryId, displayField = "id" }) {
|
|
3076
|
+
const ctx = useCmsContext();
|
|
3077
|
+
const [label, setLabel] = useState5(entryId);
|
|
3078
|
+
useEffect4(() => {
|
|
3079
|
+
if (!collectionId || !entryId) return;
|
|
3080
|
+
ctx.adapter.listEntries(collectionId).then((res) => {
|
|
3081
|
+
const match = res.find((r) => r.id === entryId);
|
|
3082
|
+
if (match) setLabel(String(match[displayField] || match.id));
|
|
3083
|
+
}).catch(() => {
|
|
3084
|
+
});
|
|
3085
|
+
}, [collectionId, entryId, displayField, ctx.adapter]);
|
|
3086
|
+
return /* @__PURE__ */ jsx5("span", { children: label });
|
|
3087
|
+
}
|
|
2709
3088
|
|
|
2710
3089
|
// src/admin/AdminLogin.tsx
|
|
2711
|
-
import { useState as
|
|
3090
|
+
import { useState as useState6, useEffect as useEffect5 } from "react";
|
|
2712
3091
|
import { Lock, UserPlus } from "lucide-react";
|
|
2713
3092
|
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2714
3093
|
function AdminLogin({
|
|
2715
3094
|
authApiRoute = "/api/admin/auth",
|
|
2716
3095
|
redirectRoute = "/admin"
|
|
2717
3096
|
}) {
|
|
2718
|
-
const [email, setEmail] =
|
|
2719
|
-
const [password, setPassword] =
|
|
2720
|
-
const [error, setError] =
|
|
2721
|
-
const [loading, setLoading] =
|
|
2722
|
-
const [view, setView] =
|
|
3097
|
+
const [email, setEmail] = useState6("");
|
|
3098
|
+
const [password, setPassword] = useState6("");
|
|
3099
|
+
const [error, setError] = useState6("");
|
|
3100
|
+
const [loading, setLoading] = useState6(false);
|
|
3101
|
+
const [view, setView] = useState6("checking");
|
|
2723
3102
|
useEffect5(() => {
|
|
2724
3103
|
fetch(authApiRoute, { cache: "no-store" }).then((res) => res.json()).then((data) => {
|
|
2725
3104
|
if (data.hasUsers) {
|
|
@@ -2821,6 +3200,7 @@ export {
|
|
|
2821
3200
|
EditableImage,
|
|
2822
3201
|
EditableLink,
|
|
2823
3202
|
EditableList,
|
|
3203
|
+
EditableReference,
|
|
2824
3204
|
EditableText,
|
|
2825
3205
|
SubscriptionPage,
|
|
2826
3206
|
SubscriptionProvider,
|