admin-lib-cms 1.2.1 → 1.2.3
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 +647 -183
- package/dist/index.mjs +697 -232
- 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,12 @@ import {
|
|
|
675
735
|
ChevronRight,
|
|
676
736
|
SlidersHorizontal,
|
|
677
737
|
LogOut,
|
|
678
|
-
ExternalLink as ExternalLink2
|
|
738
|
+
ExternalLink as ExternalLink2,
|
|
739
|
+
Check,
|
|
740
|
+
GripVertical
|
|
679
741
|
} from "lucide-react";
|
|
680
742
|
import { CreditCard as CreditCard2 } from "lucide-react";
|
|
681
|
-
import { Fragment as
|
|
743
|
+
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
682
744
|
async function handleImageFile(file, onUrl, uploadImage) {
|
|
683
745
|
if (uploadImage) {
|
|
684
746
|
try {
|
|
@@ -700,9 +762,9 @@ function AdminApp({ apiUrl, projectId, email }) {
|
|
|
700
762
|
return /* @__PURE__ */ jsx5(AdminAppContent, {});
|
|
701
763
|
}
|
|
702
764
|
function AdminAppContent() {
|
|
703
|
-
const [section, setSection] =
|
|
704
|
-
const [authChecking, setAuthChecking] =
|
|
705
|
-
const [authenticated, setAuthenticated] =
|
|
765
|
+
const [section, setSection] = useState5("pages");
|
|
766
|
+
const [authChecking, setAuthChecking] = useState5(true);
|
|
767
|
+
const [authenticated, setAuthenticated] = useState5(false);
|
|
706
768
|
const ctx = useCmsContext();
|
|
707
769
|
useEffect4(() => {
|
|
708
770
|
fetch("/api/admin/auth").then((res) => res.json()).then((data) => {
|
|
@@ -864,7 +926,7 @@ function PageListItem({
|
|
|
864
926
|
onSelect,
|
|
865
927
|
depth = 0
|
|
866
928
|
}) {
|
|
867
|
-
const [expanded, setExpanded] =
|
|
929
|
+
const [expanded, setExpanded] = useState5(false);
|
|
868
930
|
if (p.isSeparator) {
|
|
869
931
|
return /* @__PURE__ */ jsx5("li", { className: "my-2 border-t border-slate-200/60" });
|
|
870
932
|
}
|
|
@@ -915,10 +977,10 @@ function PageListItem({
|
|
|
915
977
|
}
|
|
916
978
|
function PagesSection() {
|
|
917
979
|
const ctx = useCmsContext();
|
|
918
|
-
const [selected, setSelected] =
|
|
980
|
+
const [selected, setSelected] = useState5(
|
|
919
981
|
ctx.config.pages[0] ?? null
|
|
920
982
|
);
|
|
921
|
-
const [showList, setShowList] =
|
|
983
|
+
const [showList, setShowList] = useState5(true);
|
|
922
984
|
return /* @__PURE__ */ jsxs4("div", { className: "flex flex-col lg:flex-row h-full", children: [
|
|
923
985
|
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
986
|
/* @__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 +1010,10 @@ function PagesSection() {
|
|
|
948
1010
|
function PageEditor({ page, showList, onToggleList }) {
|
|
949
1011
|
const ctx = useCmsContext();
|
|
950
1012
|
const iframeRef = useRef2(null);
|
|
951
|
-
const [registered, setRegistered] =
|
|
952
|
-
const [selectedId, setSelectedId] =
|
|
953
|
-
const [preview, setPreview] =
|
|
954
|
-
const [drawerState, setDrawerState] =
|
|
1013
|
+
const [registered, setRegistered] = useState5([]);
|
|
1014
|
+
const [selectedId, setSelectedId] = useState5(null);
|
|
1015
|
+
const [preview, setPreview] = useState5(false);
|
|
1016
|
+
const [drawerState, setDrawerState] = useState5("half");
|
|
955
1017
|
const src = useMemo2(
|
|
956
1018
|
() => `${page.path}${preview ? "" : "?__cms=edit"}`,
|
|
957
1019
|
[page.path, preview]
|
|
@@ -993,7 +1055,7 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
993
1055
|
[ctx]
|
|
994
1056
|
);
|
|
995
1057
|
const selectedMeta = registered.find((r) => r.id === selectedId) ?? null;
|
|
996
|
-
const [viewMode, setViewMode] =
|
|
1058
|
+
const [viewMode, setViewMode] = useState5("desktop");
|
|
997
1059
|
return /* @__PURE__ */ jsxs4("div", { className: "flex h-full flex-col", children: [
|
|
998
1060
|
/* @__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
1061
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 text-sm shrink-0", children: [
|
|
@@ -1118,7 +1180,7 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
1118
1180
|
},
|
|
1119
1181
|
onClose: () => setSelectedId(null)
|
|
1120
1182
|
}
|
|
1121
|
-
) : /* @__PURE__ */ jsxs4(
|
|
1183
|
+
) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
1122
1184
|
page.hideable && /* @__PURE__ */ jsxs4("div", { className: "px-5 py-4 border-b border-slate-100 bg-slate-50/50", children: [
|
|
1123
1185
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center space-x-3", children: [
|
|
1124
1186
|
/* @__PURE__ */ jsx5(
|
|
@@ -1159,7 +1221,7 @@ function SectionAccordion({
|
|
|
1159
1221
|
registered,
|
|
1160
1222
|
onSelect
|
|
1161
1223
|
}) {
|
|
1162
|
-
const [expanded, setExpanded] =
|
|
1224
|
+
const [expanded, setExpanded] = useState5({});
|
|
1163
1225
|
if (registered.length === 0) {
|
|
1164
1226
|
return /* @__PURE__ */ jsxs4("div", { className: "px-4 py-8 text-center text-sm text-slate-500", children: [
|
|
1165
1227
|
/* @__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 +1294,74 @@ function FieldListItem({ meta, onSelect }) {
|
|
|
1232
1294
|
}
|
|
1233
1295
|
) });
|
|
1234
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] = useState5([]);
|
|
1301
|
+
const [search, setSearch] = useState5("");
|
|
1302
|
+
const [loading, setLoading] = useState5(true);
|
|
1303
|
+
useEffect4(() => {
|
|
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__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
1333
|
+
/* @__PURE__ */ jsx5(
|
|
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__ */ jsxs4("div", { className: "space-y-2 max-h-60 overflow-y-auto pr-1", children: [
|
|
1343
|
+
loading ? /* @__PURE__ */ jsx5("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__ */ jsxs4(
|
|
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__ */ 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" }),
|
|
1354
|
+
/* @__PURE__ */ jsx5("span", { className: `text-sm ${isSelected ? "font-semibold text-indigo-900" : "text-slate-700"}`, children: String(label) }),
|
|
1355
|
+
isSelected && /* @__PURE__ */ jsx5(Check, { className: "w-4 h-4 text-indigo-600 ml-auto" })
|
|
1356
|
+
]
|
|
1357
|
+
},
|
|
1358
|
+
it.id
|
|
1359
|
+
);
|
|
1360
|
+
}),
|
|
1361
|
+
!loading && filtered.length === 0 && /* @__PURE__ */ jsx5("p", { className: "text-xs text-slate-500 text-center py-4", children: "No items found." })
|
|
1362
|
+
] })
|
|
1363
|
+
] });
|
|
1364
|
+
}
|
|
1235
1365
|
function FieldEditor({
|
|
1236
1366
|
meta,
|
|
1237
1367
|
value,
|
|
@@ -1240,8 +1370,10 @@ function FieldEditor({
|
|
|
1240
1370
|
onClose
|
|
1241
1371
|
}) {
|
|
1242
1372
|
const ctx = useCmsContext();
|
|
1243
|
-
const [expandedItems, setExpandedItems] =
|
|
1244
|
-
const [searchQuery, setSearchQuery] =
|
|
1373
|
+
const [expandedItems, setExpandedItems] = useState5({});
|
|
1374
|
+
const [searchQuery, setSearchQuery] = useState5("");
|
|
1375
|
+
const [listDragIdx, setListDragIdx] = useState5(null);
|
|
1376
|
+
const [listDragOverIdx, setListDragOverIdx] = useState5(null);
|
|
1245
1377
|
return /* @__PURE__ */ jsxs4("div", { className: "p-5 animate-in slide-in-from-right-4 duration-200", children: [
|
|
1246
1378
|
/* @__PURE__ */ jsxs4("div", { className: "mb-5", children: [
|
|
1247
1379
|
/* @__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 }),
|
|
@@ -1431,163 +1563,245 @@ function FieldEditor({
|
|
|
1431
1563
|
if (!title.includes(searchQuery.toLowerCase())) return null;
|
|
1432
1564
|
}
|
|
1433
1565
|
const isExpanded = expandedItems[idx] ?? false;
|
|
1434
|
-
return /* @__PURE__ */ jsxs4(
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1566
|
+
return /* @__PURE__ */ jsxs4(
|
|
1567
|
+
"div",
|
|
1568
|
+
{
|
|
1569
|
+
draggable: true,
|
|
1570
|
+
onDragStart: (e) => {
|
|
1571
|
+
setListDragIdx(idx);
|
|
1572
|
+
e.dataTransfer.effectAllowed = "move";
|
|
1573
|
+
},
|
|
1574
|
+
onDragOver: (e) => {
|
|
1575
|
+
e.preventDefault();
|
|
1576
|
+
e.dataTransfer.dropEffect = "move";
|
|
1577
|
+
setListDragOverIdx(idx);
|
|
1578
|
+
},
|
|
1579
|
+
onDragEnd: () => {
|
|
1580
|
+
setListDragIdx(null);
|
|
1581
|
+
setListDragOverIdx(null);
|
|
1582
|
+
},
|
|
1583
|
+
onDrop: (e) => {
|
|
1584
|
+
e.preventDefault();
|
|
1585
|
+
if (listDragIdx === null || listDragIdx === idx) {
|
|
1586
|
+
setListDragOverIdx(null);
|
|
1587
|
+
return;
|
|
1445
1588
|
}
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
const arr = Array.isArray(value) ? [...value] : [];
|
|
1458
|
-
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
|
|
1459
|
-
onChange(arr);
|
|
1460
|
-
}
|
|
1461
|
-
}
|
|
1462
|
-
) : schemaField.type === "textarea" ? /* @__PURE__ */ jsx5(
|
|
1463
|
-
"textarea",
|
|
1589
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1590
|
+
const [moved] = arr.splice(listDragIdx, 1);
|
|
1591
|
+
arr.splice(idx, 0, moved);
|
|
1592
|
+
onChange(arr);
|
|
1593
|
+
setListDragIdx(null);
|
|
1594
|
+
setListDragOverIdx(null);
|
|
1595
|
+
},
|
|
1596
|
+
className: `bg-slate-50 p-3 rounded-xl border transition-all relative group ${listDragOverIdx === idx ? "border-indigo-500 border-2 bg-indigo-50/40" : "border-slate-200 hover:border-slate-300"} ${listDragIdx === idx ? "opacity-40" : ""}`,
|
|
1597
|
+
children: [
|
|
1598
|
+
/* @__PURE__ */ jsxs4(
|
|
1599
|
+
"div",
|
|
1464
1600
|
{
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1601
|
+
className: "absolute left-3 top-3.5 z-10 flex items-center gap-1 text-slate-400 opacity-0 group-hover:opacity-100 transition-opacity pointer-events-none group-hover:pointer-events-auto select-none",
|
|
1602
|
+
title: "Drag or use arrows to reorder",
|
|
1603
|
+
children: [
|
|
1604
|
+
/* @__PURE__ */ jsx5(GripVertical, { className: "w-4 h-4 cursor-grab active:cursor-grabbing hover:text-indigo-600" }),
|
|
1605
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-1", children: [
|
|
1606
|
+
/* @__PURE__ */ jsx5(
|
|
1607
|
+
"button",
|
|
1608
|
+
{
|
|
1609
|
+
type: "button",
|
|
1610
|
+
disabled: idx === 0,
|
|
1611
|
+
onClick: (e) => {
|
|
1612
|
+
e.stopPropagation();
|
|
1613
|
+
if (idx === 0) return;
|
|
1614
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1615
|
+
const [moved] = arr.splice(idx, 1);
|
|
1616
|
+
arr.splice(idx - 1, 0, moved);
|
|
1617
|
+
onChange(arr);
|
|
1618
|
+
},
|
|
1619
|
+
className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
|
|
1620
|
+
title: "Move Up",
|
|
1621
|
+
children: /* @__PURE__ */ jsx5(ChevronUp, { className: "w-3.5 h-3.5" })
|
|
1622
|
+
}
|
|
1623
|
+
),
|
|
1624
|
+
/* @__PURE__ */ jsx5(
|
|
1625
|
+
"button",
|
|
1626
|
+
{
|
|
1627
|
+
type: "button",
|
|
1628
|
+
disabled: idx === (Array.isArray(value) ? value.length - 1 : 0),
|
|
1629
|
+
onClick: (e) => {
|
|
1630
|
+
e.stopPropagation();
|
|
1631
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1632
|
+
if (idx >= arr.length - 1) return;
|
|
1633
|
+
const [moved] = arr.splice(idx, 1);
|
|
1634
|
+
arr.splice(idx + 1, 0, moved);
|
|
1635
|
+
onChange(arr);
|
|
1636
|
+
},
|
|
1637
|
+
className: "p-0.5 hover:text-indigo-600 disabled:opacity-20 transition-colors",
|
|
1638
|
+
title: "Move Down",
|
|
1639
|
+
children: /* @__PURE__ */ jsx5(ChevronDown, { className: "w-3.5 h-3.5" })
|
|
1640
|
+
}
|
|
1641
|
+
)
|
|
1642
|
+
] })
|
|
1643
|
+
]
|
|
1473
1644
|
}
|
|
1474
|
-
)
|
|
1475
|
-
|
|
1476
|
-
|
|
1645
|
+
),
|
|
1646
|
+
/* @__PURE__ */ jsxs4("div", { className: "space-y-3 w-full min-w-0", children: [
|
|
1647
|
+
/* @__PURE__ */ jsxs4(
|
|
1648
|
+
"div",
|
|
1477
1649
|
{
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
},
|
|
1485
|
-
className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
|
|
1650
|
+
className: "flex items-center justify-between cursor-pointer py-1 select-none",
|
|
1651
|
+
onClick: () => setExpandedItems((prev) => ({ ...prev, [idx]: !isExpanded })),
|
|
1652
|
+
children: [
|
|
1653
|
+
/* @__PURE__ */ jsx5("div", { className: "font-semibold text-slate-700 text-sm flex-1 truncate pr-6 pl-0.5 group-hover:pl-20 transition-all duration-200", children: meta.itemSchema ? item?.title || item?.name || `Item ${idx + 1}` : String(item) }),
|
|
1654
|
+
isExpanded ? /* @__PURE__ */ jsx5(ChevronUp, { className: "w-4 h-4 text-slate-500 shrink-0" }) : /* @__PURE__ */ jsx5(ChevronDown, { className: "w-4 h-4 text-slate-500 shrink-0" })
|
|
1655
|
+
]
|
|
1486
1656
|
}
|
|
1487
1657
|
),
|
|
1488
|
-
/* @__PURE__ */ jsx5("
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
"input",
|
|
1658
|
+
isExpanded && /* @__PURE__ */ jsx5("div", { className: "pt-3 border-t border-slate-200 mt-2 space-y-3", children: meta.itemSchema ? meta.itemSchema.map((schemaField) => /* @__PURE__ */ jsxs4("div", { children: [
|
|
1659
|
+
/* @__PURE__ */ jsx5("label", { className: "block text-[10px] font-bold text-slate-500 uppercase mb-1", children: schemaField.label || schemaField.key }),
|
|
1660
|
+
schemaField.type === "icon" ? /* @__PURE__ */ jsx5(
|
|
1661
|
+
SearchableSelect,
|
|
1493
1662
|
{
|
|
1494
|
-
|
|
1663
|
+
value: String(item?.[schemaField.key] ?? ""),
|
|
1664
|
+
options: schemaField.options ?? [],
|
|
1665
|
+
placeholder: "Search icon...",
|
|
1666
|
+
iconMap: ctx.iconMap,
|
|
1667
|
+
onChange: (val) => {
|
|
1668
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1669
|
+
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: val };
|
|
1670
|
+
onChange(arr);
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
) : schemaField.type === "textarea" ? /* @__PURE__ */ jsx5(
|
|
1674
|
+
"textarea",
|
|
1675
|
+
{
|
|
1676
|
+
rows: 3,
|
|
1495
1677
|
value: String(item?.[schemaField.key] ?? ""),
|
|
1496
1678
|
onChange: (e) => {
|
|
1497
1679
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1498
1680
|
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
|
|
1499
1681
|
onChange(arr);
|
|
1500
1682
|
},
|
|
1501
|
-
placeholder: "https://...",
|
|
1502
1683
|
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"
|
|
1503
1684
|
}
|
|
1504
|
-
),
|
|
1505
|
-
/* @__PURE__ */ jsxs4("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: [
|
|
1506
|
-
"Upload",
|
|
1685
|
+
) : schemaField.type === "boolean" ? /* @__PURE__ */ jsxs4("label", { className: "flex items-center gap-2 mt-1 cursor-pointer", children: [
|
|
1507
1686
|
/* @__PURE__ */ jsx5(
|
|
1508
1687
|
"input",
|
|
1509
1688
|
{
|
|
1510
|
-
type: "
|
|
1511
|
-
|
|
1512
|
-
className: "hidden",
|
|
1689
|
+
type: "checkbox",
|
|
1690
|
+
checked: !!item?.[schemaField.key],
|
|
1513
1691
|
onChange: (e) => {
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1692
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1693
|
+
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.checked };
|
|
1694
|
+
onChange(arr);
|
|
1695
|
+
},
|
|
1696
|
+
className: "w-4 h-4 text-indigo-600 border-slate-300 rounded focus:ring-indigo-500"
|
|
1697
|
+
}
|
|
1698
|
+
),
|
|
1699
|
+
/* @__PURE__ */ jsx5("span", { className: "text-sm text-slate-700", children: schemaField.label || schemaField.key })
|
|
1700
|
+
] }) : schemaField.type === "image" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3 mt-1", children: [
|
|
1701
|
+
/* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
1702
|
+
/* @__PURE__ */ jsx5(
|
|
1703
|
+
"input",
|
|
1704
|
+
{
|
|
1705
|
+
type: "url",
|
|
1706
|
+
value: String(item?.[schemaField.key] ?? ""),
|
|
1707
|
+
onChange: (e) => {
|
|
1708
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1709
|
+
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
|
|
1710
|
+
onChange(arr);
|
|
1711
|
+
},
|
|
1712
|
+
placeholder: "https://...",
|
|
1713
|
+
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"
|
|
1526
1714
|
}
|
|
1715
|
+
),
|
|
1716
|
+
/* @__PURE__ */ jsxs4("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: [
|
|
1717
|
+
"Upload",
|
|
1718
|
+
/* @__PURE__ */ jsx5(
|
|
1719
|
+
"input",
|
|
1720
|
+
{
|
|
1721
|
+
type: "file",
|
|
1722
|
+
accept: "image/*",
|
|
1723
|
+
className: "hidden",
|
|
1724
|
+
onChange: (e) => {
|
|
1725
|
+
const file = e.target.files?.[0];
|
|
1726
|
+
if (file) {
|
|
1727
|
+
void handleImageFile(
|
|
1728
|
+
file,
|
|
1729
|
+
(url) => {
|
|
1730
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1731
|
+
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: url };
|
|
1732
|
+
onChange(arr);
|
|
1733
|
+
},
|
|
1734
|
+
ctx.uploadImage
|
|
1735
|
+
);
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
)
|
|
1740
|
+
] })
|
|
1741
|
+
] }),
|
|
1742
|
+
item?.[schemaField.key] ? /* @__PURE__ */ jsx5("div", { className: "rounded-lg border border-slate-200 p-1 bg-slate-50 overflow-hidden relative group max-w-xs", children: /* @__PURE__ */ jsx5(
|
|
1743
|
+
"img",
|
|
1744
|
+
{
|
|
1745
|
+
src: String(item?.[schemaField.key]),
|
|
1746
|
+
alt: "",
|
|
1747
|
+
className: "w-full h-auto max-h-32 object-contain rounded-md"
|
|
1527
1748
|
}
|
|
1528
|
-
)
|
|
1529
|
-
] })
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1749
|
+
) }) : null
|
|
1750
|
+
] }) : schemaField.type === "select" ? /* @__PURE__ */ jsx5(
|
|
1751
|
+
"select",
|
|
1752
|
+
{
|
|
1753
|
+
value: String(item?.[schemaField.key] ?? ""),
|
|
1754
|
+
onChange: (e) => {
|
|
1755
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1756
|
+
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
|
|
1757
|
+
onChange(arr);
|
|
1758
|
+
},
|
|
1759
|
+
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",
|
|
1760
|
+
children: schemaField.options?.map((opt) => /* @__PURE__ */ jsx5("option", { value: opt, children: opt }, opt))
|
|
1761
|
+
}
|
|
1762
|
+
) : /* @__PURE__ */ jsx5(
|
|
1763
|
+
"input",
|
|
1764
|
+
{
|
|
1765
|
+
type: "text",
|
|
1766
|
+
value: String(item?.[schemaField.key] ?? ""),
|
|
1767
|
+
onChange: (e) => {
|
|
1768
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1769
|
+
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
|
|
1770
|
+
onChange(arr);
|
|
1771
|
+
},
|
|
1772
|
+
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"
|
|
1773
|
+
}
|
|
1774
|
+
)
|
|
1775
|
+
] }, schemaField.key)) : /* @__PURE__ */ jsx5(
|
|
1776
|
+
"input",
|
|
1533
1777
|
{
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1778
|
+
type: "text",
|
|
1779
|
+
value: String(item),
|
|
1780
|
+
onChange: (e) => {
|
|
1781
|
+
const arr = Array.isArray(value) ? [...value] : [];
|
|
1782
|
+
arr[idx] = e.target.value;
|
|
1783
|
+
onChange(arr);
|
|
1784
|
+
},
|
|
1785
|
+
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"
|
|
1537
1786
|
}
|
|
1538
|
-
) })
|
|
1539
|
-
] })
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
value: String(item?.[schemaField.key] ?? ""),
|
|
1543
|
-
onChange: (e) => {
|
|
1544
|
-
const arr = Array.isArray(value) ? [...value] : [];
|
|
1545
|
-
arr[idx] = { ...arr[idx] || {}, [schemaField.key]: e.target.value };
|
|
1546
|
-
onChange(arr);
|
|
1547
|
-
},
|
|
1548
|
-
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",
|
|
1549
|
-
children: schemaField.options?.map((opt) => /* @__PURE__ */ jsx5("option", { value: opt, children: opt }, opt))
|
|
1550
|
-
}
|
|
1551
|
-
) : /* @__PURE__ */ jsx5(
|
|
1552
|
-
"input",
|
|
1787
|
+
) })
|
|
1788
|
+
] }),
|
|
1789
|
+
!meta.fixedLength && /* @__PURE__ */ jsx5(
|
|
1790
|
+
"button",
|
|
1553
1791
|
{
|
|
1554
|
-
|
|
1555
|
-
value: String(item?.[schemaField.key] ?? ""),
|
|
1556
|
-
onChange: (e) => {
|
|
1792
|
+
onClick: () => {
|
|
1557
1793
|
const arr = Array.isArray(value) ? [...value] : [];
|
|
1558
|
-
arr
|
|
1794
|
+
arr.splice(idx, 1);
|
|
1559
1795
|
onChange(arr);
|
|
1560
1796
|
},
|
|
1561
|
-
className: "
|
|
1797
|
+
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",
|
|
1798
|
+
children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
|
|
1562
1799
|
}
|
|
1563
1800
|
)
|
|
1564
|
-
]
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
value: String(item),
|
|
1569
|
-
onChange: (e) => {
|
|
1570
|
-
const arr = Array.isArray(value) ? [...value] : [];
|
|
1571
|
-
arr[idx] = e.target.value;
|
|
1572
|
-
onChange(arr);
|
|
1573
|
-
},
|
|
1574
|
-
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"
|
|
1575
|
-
}
|
|
1576
|
-
) })
|
|
1577
|
-
] }),
|
|
1578
|
-
!meta.fixedLength && /* @__PURE__ */ jsx5(
|
|
1579
|
-
"button",
|
|
1580
|
-
{
|
|
1581
|
-
onClick: () => {
|
|
1582
|
-
const arr = Array.isArray(value) ? [...value] : [];
|
|
1583
|
-
arr.splice(idx, 1);
|
|
1584
|
-
onChange(arr);
|
|
1585
|
-
},
|
|
1586
|
-
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",
|
|
1587
|
-
children: /* @__PURE__ */ jsx5(Trash2, { className: "w-4 h-4" })
|
|
1588
|
-
}
|
|
1589
|
-
)
|
|
1590
|
-
] }, idx);
|
|
1801
|
+
]
|
|
1802
|
+
},
|
|
1803
|
+
idx
|
|
1804
|
+
);
|
|
1591
1805
|
}),
|
|
1592
1806
|
!meta.fixedLength && /* @__PURE__ */ jsxs4(
|
|
1593
1807
|
"button",
|
|
@@ -1613,7 +1827,7 @@ function FieldEditor({
|
|
|
1613
1827
|
}
|
|
1614
1828
|
)
|
|
1615
1829
|
] }),
|
|
1616
|
-
"
|
|
1830
|
+
meta.type === "reference" && /* @__PURE__ */ jsx5(SidebarReferenceSelect, { meta, value, onChange })
|
|
1617
1831
|
] }),
|
|
1618
1832
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between pt-6 mt-6 border-t border-slate-100", children: [
|
|
1619
1833
|
/* @__PURE__ */ jsxs4(
|
|
@@ -1641,10 +1855,10 @@ function FieldEditor({
|
|
|
1641
1855
|
function CollectionsSection() {
|
|
1642
1856
|
const ctx = useCmsContext();
|
|
1643
1857
|
const collections = ctx.config.collections ?? [];
|
|
1644
|
-
const [selected, setSelected] =
|
|
1858
|
+
const [selected, setSelected] = useState5(
|
|
1645
1859
|
collections[0] ?? null
|
|
1646
1860
|
);
|
|
1647
|
-
const [counts, setCounts] =
|
|
1861
|
+
const [counts, setCounts] = useState5({});
|
|
1648
1862
|
useEffect4(() => {
|
|
1649
1863
|
collections.forEach((c) => {
|
|
1650
1864
|
ctx.adapter.listEntries(c.id).then((entries) => {
|
|
@@ -1681,13 +1895,17 @@ function CollectionsSection() {
|
|
|
1681
1895
|
}
|
|
1682
1896
|
function CollectionEditor({ collection }) {
|
|
1683
1897
|
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] =
|
|
1898
|
+
const [entries, setEntries] = useState5([]);
|
|
1899
|
+
const [editing, setEditing] = useState5(null);
|
|
1900
|
+
const [saving, setSaving] = useState5(false);
|
|
1901
|
+
const [deletingId, setDeletingId] = useState5(null);
|
|
1902
|
+
const [loadingEntries, setLoadingEntries] = useState5(true);
|
|
1903
|
+
const [draggedIdx, setDraggedIdx] = useState5(null);
|
|
1904
|
+
const [dragOverIdx, setDragOverIdx] = useState5(null);
|
|
1905
|
+
const [search, setSearch] = useState5("");
|
|
1906
|
+
const [filters, setFilters] = useState5({});
|
|
1907
|
+
const [page, setPage] = useState5(1);
|
|
1908
|
+
const itemsPerPage = 10;
|
|
1691
1909
|
const load = useCallback3(() => {
|
|
1692
1910
|
setLoadingEntries(true);
|
|
1693
1911
|
ctx.adapter.listEntries(collection.id).then((res) => {
|
|
@@ -1720,7 +1938,16 @@ function CollectionEditor({ collection }) {
|
|
|
1720
1938
|
if (!editing) return;
|
|
1721
1939
|
setSaving(true);
|
|
1722
1940
|
try {
|
|
1723
|
-
|
|
1941
|
+
const finalEditing = { ...editing };
|
|
1942
|
+
collection.fields.forEach((f) => {
|
|
1943
|
+
if (f.type === "slug" && !finalEditing[f.id]) {
|
|
1944
|
+
const sourceField = f.source || "title";
|
|
1945
|
+
let val = String(finalEditing[sourceField] || finalEditing.id || "");
|
|
1946
|
+
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
1947
|
+
finalEditing[f.id] = val;
|
|
1948
|
+
}
|
|
1949
|
+
});
|
|
1950
|
+
await ctx.adapter.putEntry(collection.id, finalEditing);
|
|
1724
1951
|
ctx.notifyCollectionChanged();
|
|
1725
1952
|
setEditing(null);
|
|
1726
1953
|
load();
|
|
@@ -1773,7 +2000,7 @@ function CollectionEditor({ collection }) {
|
|
|
1773
2000
|
setDraggedIdx(null);
|
|
1774
2001
|
setDragOverIdx(null);
|
|
1775
2002
|
};
|
|
1776
|
-
const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order").slice(0, 5);
|
|
2003
|
+
const visibleFields = collection.fields.filter((f) => !["richtext", "list", "password"].includes(f.type) && f.id !== "order" && !f.hidden).slice(0, 5);
|
|
1777
2004
|
return /* @__PURE__ */ jsxs4("div", { className: "mx-auto max-w-5xl", children: [
|
|
1778
2005
|
/* @__PURE__ */ jsxs4("div", { className: "mb-8 flex items-center justify-between", children: [
|
|
1779
2006
|
/* @__PURE__ */ jsxs4("div", { children: [
|
|
@@ -1792,12 +2019,56 @@ function CollectionEditor({ collection }) {
|
|
|
1792
2019
|
}
|
|
1793
2020
|
)
|
|
1794
2021
|
] }),
|
|
2022
|
+
!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: [
|
|
2023
|
+
collection.searchBy?.length ? /* @__PURE__ */ jsxs4("div", { className: "relative flex-1 min-w-[200px]", children: [
|
|
2024
|
+
/* @__PURE__ */ jsx5(Search, { className: "absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" }),
|
|
2025
|
+
/* @__PURE__ */ jsx5(
|
|
2026
|
+
"input",
|
|
2027
|
+
{
|
|
2028
|
+
type: "text",
|
|
2029
|
+
placeholder: `Search by ${collection.searchBy.join(", ")}...`,
|
|
2030
|
+
value: search,
|
|
2031
|
+
onChange: (e) => {
|
|
2032
|
+
setSearch(e.target.value);
|
|
2033
|
+
setPage(1);
|
|
2034
|
+
},
|
|
2035
|
+
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"
|
|
2036
|
+
}
|
|
2037
|
+
)
|
|
2038
|
+
] }) : null,
|
|
2039
|
+
collection.filterBy?.map((f) => {
|
|
2040
|
+
const fieldDef = collection.fields.find((cf) => cf.id === f);
|
|
2041
|
+
const uniqueVals = Array.from(new Set(entries.map((e) => String(e[f] || "")))).filter(Boolean);
|
|
2042
|
+
if (!fieldDef || uniqueVals.length === 0) return null;
|
|
2043
|
+
return /* @__PURE__ */ jsxs4("div", { className: "min-w-[150px] relative", children: [
|
|
2044
|
+
/* @__PURE__ */ jsxs4(
|
|
2045
|
+
"select",
|
|
2046
|
+
{
|
|
2047
|
+
value: filters[f] || "",
|
|
2048
|
+
onChange: (e) => {
|
|
2049
|
+
setFilters((prev) => ({ ...prev, [f]: e.target.value }));
|
|
2050
|
+
setPage(1);
|
|
2051
|
+
},
|
|
2052
|
+
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",
|
|
2053
|
+
children: [
|
|
2054
|
+
/* @__PURE__ */ jsxs4("option", { value: "", children: [
|
|
2055
|
+
"All ",
|
|
2056
|
+
fieldDef.label
|
|
2057
|
+
] }),
|
|
2058
|
+
uniqueVals.map((v) => /* @__PURE__ */ jsx5("option", { value: v, children: v }, v))
|
|
2059
|
+
]
|
|
2060
|
+
}
|
|
2061
|
+
),
|
|
2062
|
+
/* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
|
|
2063
|
+
] }, f);
|
|
2064
|
+
})
|
|
2065
|
+
] }),
|
|
1795
2066
|
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
2067
|
/* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2 mb-6", children: [
|
|
1797
2068
|
/* @__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
2069
|
/* @__PURE__ */ jsx5("h3", { className: "text-lg font-bold text-slate-900", children: "Edit Entry" })
|
|
1799
2070
|
] }),
|
|
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: [
|
|
2071
|
+
/* @__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
2072
|
/* @__PURE__ */ jsxs4("span", { className: "text-xs font-bold text-slate-500 uppercase tracking-wide flex items-center justify-between mb-1.5", children: [
|
|
1802
2073
|
f.label,
|
|
1803
2074
|
/* @__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 +2130,15 @@ function CollectionEditor({ collection }) {
|
|
|
1859
2130
|
children: "Generate"
|
|
1860
2131
|
}
|
|
1861
2132
|
)
|
|
1862
|
-
] }) : f.type === "
|
|
2133
|
+
] }) : f.type === "reference" ? /* @__PURE__ */ jsx5(
|
|
2134
|
+
ReferenceSelect,
|
|
2135
|
+
{
|
|
2136
|
+
collectionId: f.collection,
|
|
2137
|
+
displayField: f.displayField,
|
|
2138
|
+
value: String(editing[f.id] ?? ""),
|
|
2139
|
+
onChange: (val) => setEditing({ ...editing, [f.id]: val })
|
|
2140
|
+
}
|
|
2141
|
+
) : f.type === "select" ? /* @__PURE__ */ jsxs4("div", { children: [
|
|
1863
2142
|
/* @__PURE__ */ jsx5(
|
|
1864
2143
|
"input",
|
|
1865
2144
|
{
|
|
@@ -1874,7 +2153,71 @@ function CollectionEditor({ collection }) {
|
|
|
1874
2153
|
const lab = typeof opt === "string" ? opt : opt.label;
|
|
1875
2154
|
return /* @__PURE__ */ jsx5("option", { value: val, children: lab }, val);
|
|
1876
2155
|
}) })
|
|
1877
|
-
] }) : f.type === "image" ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2156
|
+
] }) : f.type === "image" ? f.multiple ? /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
2157
|
+
/* @__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: [
|
|
2158
|
+
/* @__PURE__ */ jsx5("img", { src: url, alt: "", className: "w-full h-full object-cover rounded-lg" }),
|
|
2159
|
+
/* @__PURE__ */ jsx5(
|
|
2160
|
+
"button",
|
|
2161
|
+
{
|
|
2162
|
+
type: "button",
|
|
2163
|
+
onClick: () => {
|
|
2164
|
+
const arr = [...editing[f.id] || []];
|
|
2165
|
+
arr.splice(i, 1);
|
|
2166
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2167
|
+
},
|
|
2168
|
+
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",
|
|
2169
|
+
children: /* @__PURE__ */ jsx5(X, { className: "w-3 h-3" })
|
|
2170
|
+
}
|
|
2171
|
+
)
|
|
2172
|
+
] }, i)) }),
|
|
2173
|
+
(!f.max || (editing[f.id] || []).length < f.max) && /* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
2174
|
+
/* @__PURE__ */ jsx5(
|
|
2175
|
+
"input",
|
|
2176
|
+
{
|
|
2177
|
+
type: "url",
|
|
2178
|
+
placeholder: "Add image URL and press Enter...",
|
|
2179
|
+
onKeyDown: (e) => {
|
|
2180
|
+
if (e.key === "Enter" && e.currentTarget.value) {
|
|
2181
|
+
e.preventDefault();
|
|
2182
|
+
const arr = [...editing[f.id] || [], e.currentTarget.value];
|
|
2183
|
+
setEditing({ ...editing, [f.id]: arr });
|
|
2184
|
+
e.currentTarget.value = "";
|
|
2185
|
+
}
|
|
2186
|
+
},
|
|
2187
|
+
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"
|
|
2188
|
+
}
|
|
2189
|
+
),
|
|
2190
|
+
/* @__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: [
|
|
2191
|
+
"Upload",
|
|
2192
|
+
/* @__PURE__ */ jsx5(
|
|
2193
|
+
"input",
|
|
2194
|
+
{
|
|
2195
|
+
type: "file",
|
|
2196
|
+
accept: "image/*",
|
|
2197
|
+
multiple: true,
|
|
2198
|
+
className: "hidden",
|
|
2199
|
+
onChange: (e) => {
|
|
2200
|
+
const files = Array.from(e.target.files || []);
|
|
2201
|
+
files.forEach((file) => {
|
|
2202
|
+
void handleImageFile(
|
|
2203
|
+
file,
|
|
2204
|
+
(url) => {
|
|
2205
|
+
setEditing((prev) => {
|
|
2206
|
+
if (!prev) return prev;
|
|
2207
|
+
const current = prev[f.id] || [];
|
|
2208
|
+
if (f.max && current.length >= f.max) return prev;
|
|
2209
|
+
return { ...prev, [f.id]: [...current, url] };
|
|
2210
|
+
});
|
|
2211
|
+
},
|
|
2212
|
+
ctx.uploadImage
|
|
2213
|
+
);
|
|
2214
|
+
});
|
|
2215
|
+
}
|
|
2216
|
+
}
|
|
2217
|
+
)
|
|
2218
|
+
] })
|
|
2219
|
+
] })
|
|
2220
|
+
] }) : /* @__PURE__ */ jsxs4("div", { className: "space-y-3", children: [
|
|
1878
2221
|
/* @__PURE__ */ jsxs4("div", { className: "flex gap-2", children: [
|
|
1879
2222
|
/* @__PURE__ */ jsx5(
|
|
1880
2223
|
"input",
|
|
@@ -2089,7 +2432,7 @@ function CollectionEditor({ collection }) {
|
|
|
2089
2432
|
onClick: save,
|
|
2090
2433
|
disabled: saving,
|
|
2091
2434
|
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(
|
|
2435
|
+
children: saving ? /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2093
2436
|
/* @__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
2437
|
/* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
2095
2438
|
/* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
|
|
@@ -2111,48 +2454,64 @@ function CollectionEditor({ collection }) {
|
|
|
2111
2454
|
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
2455
|
/* @__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
2456
|
] }, 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
|
-
|
|
2457
|
+
) : /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2458
|
+
(() => {
|
|
2459
|
+
let res = entries;
|
|
2460
|
+
if (search && collection.searchBy?.length) {
|
|
2461
|
+
const q = search.toLowerCase();
|
|
2462
|
+
res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
|
|
2463
|
+
}
|
|
2464
|
+
if (Object.keys(filters).length > 0) {
|
|
2465
|
+
res = res.filter((e) => {
|
|
2466
|
+
for (const [k, v] of Object.entries(filters)) {
|
|
2467
|
+
if (v && String(e[k] || "") !== v) return false;
|
|
2468
|
+
}
|
|
2469
|
+
return true;
|
|
2470
|
+
});
|
|
2471
|
+
}
|
|
2472
|
+
const paginatedRes = res.slice((page - 1) * itemsPerPage, page * itemsPerPage);
|
|
2473
|
+
return /* @__PURE__ */ jsx5(Fragment3, { children: paginatedRes.map((e, idx) => /* @__PURE__ */ jsxs4(
|
|
2474
|
+
"tr",
|
|
2475
|
+
{
|
|
2476
|
+
draggable: true,
|
|
2477
|
+
onDragStart: (evt) => onDragStart(evt, idx),
|
|
2478
|
+
onDragOver: (evt) => onDragOver(evt, idx),
|
|
2479
|
+
onDrop: (evt) => onDrop(evt, idx),
|
|
2480
|
+
onDragEnd,
|
|
2481
|
+
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" : ""}`,
|
|
2482
|
+
children: [
|
|
2483
|
+
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)),
|
|
2484
|
+
/* @__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: [
|
|
2485
|
+
/* @__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" }) }) }),
|
|
2486
|
+
/* @__PURE__ */ jsx5(
|
|
2487
|
+
"button",
|
|
2488
|
+
{
|
|
2489
|
+
onClick: () => setEditing(e),
|
|
2490
|
+
className: "p-2 rounded-lg text-slate-400 hover:text-indigo-600 hover:bg-indigo-50 transition-colors",
|
|
2491
|
+
title: "Edit",
|
|
2492
|
+
children: /* @__PURE__ */ jsx5(Pencil, { className: "h-4 w-4" })
|
|
2493
|
+
}
|
|
2494
|
+
),
|
|
2495
|
+
/* @__PURE__ */ jsx5(
|
|
2496
|
+
"button",
|
|
2497
|
+
{
|
|
2498
|
+
onClick: () => remove(e.id),
|
|
2499
|
+
disabled: deletingId === e.id,
|
|
2500
|
+
className: "p-2 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-colors disabled:opacity-50",
|
|
2501
|
+
title: "Delete",
|
|
2502
|
+
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: [
|
|
2503
|
+
/* @__PURE__ */ jsx5("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }),
|
|
2504
|
+
/* @__PURE__ */ jsx5("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8v8H4z" })
|
|
2505
|
+
] }) : /* @__PURE__ */ jsx5(Trash2, { className: "h-4 w-4" })
|
|
2506
|
+
}
|
|
2507
|
+
)
|
|
2508
|
+
] }) })
|
|
2509
|
+
]
|
|
2510
|
+
},
|
|
2511
|
+
e.id
|
|
2512
|
+
)) });
|
|
2513
|
+
})(),
|
|
2514
|
+
entries.length === 0 && !search && Object.values(filters).every((v) => !v) && /* @__PURE__ */ jsx5("tr", { children: /* @__PURE__ */ jsx5(
|
|
2156
2515
|
"td",
|
|
2157
2516
|
{
|
|
2158
2517
|
colSpan: visibleFields.length + 1,
|
|
@@ -2164,15 +2523,76 @@ function CollectionEditor({ collection }) {
|
|
|
2164
2523
|
}
|
|
2165
2524
|
) })
|
|
2166
2525
|
] }) })
|
|
2167
|
-
] }) })
|
|
2526
|
+
] }) }),
|
|
2527
|
+
!loadingEntries && entries.length > 0 && /* @__PURE__ */ jsxs4("div", { className: "flex items-center justify-between text-sm text-slate-500 mt-4 px-2", children: [
|
|
2528
|
+
/* @__PURE__ */ jsx5("span", { children: (() => {
|
|
2529
|
+
let res = entries;
|
|
2530
|
+
if (search && collection.searchBy?.length) {
|
|
2531
|
+
const q = search.toLowerCase();
|
|
2532
|
+
res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
|
|
2533
|
+
}
|
|
2534
|
+
if (Object.keys(filters).length > 0) {
|
|
2535
|
+
res = res.filter((e) => {
|
|
2536
|
+
for (const [k, v] of Object.entries(filters)) {
|
|
2537
|
+
if (v && String(e[k] || "") !== v) return false;
|
|
2538
|
+
}
|
|
2539
|
+
return true;
|
|
2540
|
+
});
|
|
2541
|
+
}
|
|
2542
|
+
return `${res.length} item${res.length !== 1 ? "s" : ""}`;
|
|
2543
|
+
})() }),
|
|
2544
|
+
(() => {
|
|
2545
|
+
let res = entries;
|
|
2546
|
+
if (search && collection.searchBy?.length) {
|
|
2547
|
+
const q = search.toLowerCase();
|
|
2548
|
+
res = res.filter((e) => collection.searchBy.some((field) => String(e[field] || "").toLowerCase().includes(q)));
|
|
2549
|
+
}
|
|
2550
|
+
if (Object.keys(filters).length > 0) {
|
|
2551
|
+
res = res.filter((e) => {
|
|
2552
|
+
for (const [k, v] of Object.entries(filters)) {
|
|
2553
|
+
if (v && String(e[k] || "") !== v) return false;
|
|
2554
|
+
}
|
|
2555
|
+
return true;
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
const totalPages = Math.max(1, Math.ceil(res.length / itemsPerPage));
|
|
2559
|
+
if (totalPages <= 1) return null;
|
|
2560
|
+
return /* @__PURE__ */ jsxs4("div", { className: "flex items-center gap-2", children: [
|
|
2561
|
+
/* @__PURE__ */ jsx5(
|
|
2562
|
+
"button",
|
|
2563
|
+
{
|
|
2564
|
+
onClick: () => setPage((p) => Math.max(1, p - 1)),
|
|
2565
|
+
disabled: page === 1,
|
|
2566
|
+
className: "p-2 rounded-lg hover:bg-slate-100 disabled:opacity-30 transition-colors",
|
|
2567
|
+
children: /* @__PURE__ */ jsx5(ChevronLeft, { className: "h-4 w-4" })
|
|
2568
|
+
}
|
|
2569
|
+
),
|
|
2570
|
+
/* @__PURE__ */ jsxs4("span", { className: "font-medium text-slate-700", children: [
|
|
2571
|
+
"Page ",
|
|
2572
|
+
page,
|
|
2573
|
+
" of ",
|
|
2574
|
+
totalPages
|
|
2575
|
+
] }),
|
|
2576
|
+
/* @__PURE__ */ jsx5(
|
|
2577
|
+
"button",
|
|
2578
|
+
{
|
|
2579
|
+
onClick: () => setPage((p) => Math.min(totalPages, p + 1)),
|
|
2580
|
+
disabled: page === totalPages,
|
|
2581
|
+
className: "p-2 rounded-lg hover:bg-slate-100 disabled:opacity-30 transition-colors",
|
|
2582
|
+
children: /* @__PURE__ */ jsx5(ChevronRight, { className: "h-4 w-4" })
|
|
2583
|
+
}
|
|
2584
|
+
)
|
|
2585
|
+
] });
|
|
2586
|
+
})()
|
|
2587
|
+
] })
|
|
2168
2588
|
] });
|
|
2169
2589
|
}
|
|
2170
2590
|
var PAGE_SIZE = 10;
|
|
2171
2591
|
function SubmissionsSection() {
|
|
2172
2592
|
const ctx = useCmsContext();
|
|
2173
|
-
const [submissions, setSubmissions] =
|
|
2174
|
-
const [loading, setLoading] =
|
|
2175
|
-
const [selectedFormId, setSelectedFormId] =
|
|
2593
|
+
const [submissions, setSubmissions] = useState5([]);
|
|
2594
|
+
const [loading, setLoading] = useState5(false);
|
|
2595
|
+
const [selectedFormId, setSelectedFormId] = useState5(null);
|
|
2176
2596
|
const load = useCallback3(async () => {
|
|
2177
2597
|
setLoading(true);
|
|
2178
2598
|
const all = await ctx.adapter.listSubmissions();
|
|
@@ -2226,9 +2646,9 @@ function SubmissionsSection() {
|
|
|
2226
2646
|
}
|
|
2227
2647
|
function SubmissionsList({ formId, submissions, onLoad, loading }) {
|
|
2228
2648
|
const ctx = useCmsContext();
|
|
2229
|
-
const [search, setSearch] =
|
|
2230
|
-
const [page, setPage] =
|
|
2231
|
-
const [detail, setDetail] =
|
|
2649
|
+
const [search, setSearch] = useState5("");
|
|
2650
|
+
const [page, setPage] = useState5(1);
|
|
2651
|
+
const [detail, setDetail] = useState5(null);
|
|
2232
2652
|
const filtered = submissions.filter((s) => {
|
|
2233
2653
|
const q = search.toLowerCase();
|
|
2234
2654
|
if (!q) return true;
|
|
@@ -2508,7 +2928,7 @@ function SettingsSection() {
|
|
|
2508
2928
|
function ConfigSection() {
|
|
2509
2929
|
const ctx = useCmsContext();
|
|
2510
2930
|
const globals = ctx.config.globals ?? [];
|
|
2511
|
-
const [selectedGroupId, setSelectedGroupId] =
|
|
2931
|
+
const [selectedGroupId, setSelectedGroupId] = useState5(
|
|
2512
2932
|
globals[0]?.id ?? null
|
|
2513
2933
|
);
|
|
2514
2934
|
const selectedGroup = globals.find((g) => g.id === selectedGroupId) ?? null;
|
|
@@ -2598,8 +3018,8 @@ function Row({
|
|
|
2598
3018
|
] });
|
|
2599
3019
|
}
|
|
2600
3020
|
function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
2601
|
-
const [open, setOpen] =
|
|
2602
|
-
const [search, setSearch] =
|
|
3021
|
+
const [open, setOpen] = useState5(false);
|
|
3022
|
+
const [search, setSearch] = useState5("");
|
|
2603
3023
|
const filtered = options.filter((o) => o.toLowerCase().includes(search.toLowerCase()));
|
|
2604
3024
|
const capped = filtered.slice(0, 80);
|
|
2605
3025
|
const SelectedIcon = iconMap && value ? iconMap[value] : null;
|
|
@@ -2622,7 +3042,7 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
2622
3042
|
]
|
|
2623
3043
|
}
|
|
2624
3044
|
),
|
|
2625
|
-
open && /* @__PURE__ */ jsxs4(
|
|
3045
|
+
open && /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
2626
3046
|
/* @__PURE__ */ jsx5("div", { className: "fixed inset-0 z-[100]", onClick: () => setOpen(false) }),
|
|
2627
3047
|
/* @__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
3048
|
/* @__PURE__ */ jsxs4("div", { className: "p-2 border-b border-slate-100 flex items-center gap-2", children: [
|
|
@@ -2676,10 +3096,10 @@ function SearchableSelect({ value, onChange, options, placeholder, iconMap }) {
|
|
|
2676
3096
|
] });
|
|
2677
3097
|
}
|
|
2678
3098
|
function PasswordField({ value, onChange }) {
|
|
2679
|
-
const [show, setShow] =
|
|
3099
|
+
const [show, setShow] = useState5(false);
|
|
2680
3100
|
const isHash = value.startsWith("$2a$") || value.startsWith("$2b$");
|
|
2681
|
-
const [displayValue, setDisplayValue] =
|
|
2682
|
-
const [pristine, setPristine] =
|
|
3101
|
+
const [displayValue, setDisplayValue] = useState5(isHash ? "" : value);
|
|
3102
|
+
const [pristine, setPristine] = useState5(isHash);
|
|
2683
3103
|
return /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
|
|
2684
3104
|
/* @__PURE__ */ jsx5(
|
|
2685
3105
|
"input",
|
|
@@ -2706,20 +3126,64 @@ function PasswordField({ value, onChange }) {
|
|
|
2706
3126
|
)
|
|
2707
3127
|
] });
|
|
2708
3128
|
}
|
|
3129
|
+
function ReferenceSelect({ collectionId, displayField = "id", value, onChange }) {
|
|
3130
|
+
const ctx = useCmsContext();
|
|
3131
|
+
const [options, setOptions] = useState5([]);
|
|
3132
|
+
const [loading, setLoading] = useState5(true);
|
|
3133
|
+
useEffect4(() => {
|
|
3134
|
+
if (!collectionId) {
|
|
3135
|
+
setLoading(false);
|
|
3136
|
+
return;
|
|
3137
|
+
}
|
|
3138
|
+
setLoading(true);
|
|
3139
|
+
ctx.adapter.listEntries(collectionId).then((res) => {
|
|
3140
|
+
setOptions(res.map((r) => ({ id: r.id, label: String(r[displayField] || r.id) })));
|
|
3141
|
+
setLoading(false);
|
|
3142
|
+
}).catch(() => setLoading(false));
|
|
3143
|
+
}, [collectionId, displayField, ctx.adapter]);
|
|
3144
|
+
return /* @__PURE__ */ jsxs4("div", { className: "relative", children: [
|
|
3145
|
+
/* @__PURE__ */ jsxs4(
|
|
3146
|
+
"select",
|
|
3147
|
+
{
|
|
3148
|
+
value,
|
|
3149
|
+
onChange: (e) => onChange(e.target.value),
|
|
3150
|
+
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",
|
|
3151
|
+
children: [
|
|
3152
|
+
/* @__PURE__ */ jsx5("option", { value: "", children: loading ? "Loading..." : "Select..." }),
|
|
3153
|
+
options.map((o) => /* @__PURE__ */ jsx5("option", { value: o.id, children: o.label }, o.id))
|
|
3154
|
+
]
|
|
3155
|
+
}
|
|
3156
|
+
),
|
|
3157
|
+
/* @__PURE__ */ jsx5(ChevronDown, { className: "absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-slate-400 pointer-events-none" })
|
|
3158
|
+
] });
|
|
3159
|
+
}
|
|
3160
|
+
function ReferenceTableCell({ collectionId, entryId, displayField = "id" }) {
|
|
3161
|
+
const ctx = useCmsContext();
|
|
3162
|
+
const [label, setLabel] = useState5(entryId);
|
|
3163
|
+
useEffect4(() => {
|
|
3164
|
+
if (!collectionId || !entryId) return;
|
|
3165
|
+
ctx.adapter.listEntries(collectionId).then((res) => {
|
|
3166
|
+
const match = res.find((r) => r.id === entryId);
|
|
3167
|
+
if (match) setLabel(String(match[displayField] || match.id));
|
|
3168
|
+
}).catch(() => {
|
|
3169
|
+
});
|
|
3170
|
+
}, [collectionId, entryId, displayField, ctx.adapter]);
|
|
3171
|
+
return /* @__PURE__ */ jsx5("span", { children: label });
|
|
3172
|
+
}
|
|
2709
3173
|
|
|
2710
3174
|
// src/admin/AdminLogin.tsx
|
|
2711
|
-
import { useState as
|
|
3175
|
+
import { useState as useState6, useEffect as useEffect5 } from "react";
|
|
2712
3176
|
import { Lock, UserPlus } from "lucide-react";
|
|
2713
3177
|
import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2714
3178
|
function AdminLogin({
|
|
2715
3179
|
authApiRoute = "/api/admin/auth",
|
|
2716
3180
|
redirectRoute = "/admin"
|
|
2717
3181
|
}) {
|
|
2718
|
-
const [email, setEmail] =
|
|
2719
|
-
const [password, setPassword] =
|
|
2720
|
-
const [error, setError] =
|
|
2721
|
-
const [loading, setLoading] =
|
|
2722
|
-
const [view, setView] =
|
|
3182
|
+
const [email, setEmail] = useState6("");
|
|
3183
|
+
const [password, setPassword] = useState6("");
|
|
3184
|
+
const [error, setError] = useState6("");
|
|
3185
|
+
const [loading, setLoading] = useState6(false);
|
|
3186
|
+
const [view, setView] = useState6("checking");
|
|
2723
3187
|
useEffect5(() => {
|
|
2724
3188
|
fetch(authApiRoute, { cache: "no-store" }).then((res) => res.json()).then((data) => {
|
|
2725
3189
|
if (data.hasUsers) {
|
|
@@ -2821,6 +3285,7 @@ export {
|
|
|
2821
3285
|
EditableImage,
|
|
2822
3286
|
EditableLink,
|
|
2823
3287
|
EditableList,
|
|
3288
|
+
EditableReference,
|
|
2824
3289
|
EditableText,
|
|
2825
3290
|
SubscriptionPage,
|
|
2826
3291
|
SubscriptionProvider,
|