admin-lib-cms 1.1.2 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +94 -43
- package/dist/index.mjs +95 -43
- package/dist/storage.js +13 -10
- package/dist/storage.mjs +13 -10
- package/dist/types.d.mts +2 -1
- package/dist/types.d.ts +2 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -752,6 +752,7 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
752
752
|
const [registered, setRegistered] = (0, import_react5.useState)([]);
|
|
753
753
|
const [selectedId, setSelectedId] = (0, import_react5.useState)(null);
|
|
754
754
|
const [preview, setPreview] = (0, import_react5.useState)(false);
|
|
755
|
+
const [drawerState, setDrawerState] = (0, import_react5.useState)("half");
|
|
755
756
|
const src = (0, import_react5.useMemo)(
|
|
756
757
|
() => `${page.path}${preview ? "" : "?__cms=edit"}`,
|
|
757
758
|
[page.path, preview]
|
|
@@ -765,6 +766,9 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
765
766
|
setRegistered(d.items);
|
|
766
767
|
} else if (d.type === "cms:select") {
|
|
767
768
|
setSelectedId(d.id ?? null);
|
|
769
|
+
if (d.id) {
|
|
770
|
+
setDrawerState((prev) => prev === "min" ? "half" : prev);
|
|
771
|
+
}
|
|
768
772
|
} else if (d.type === "cms:ready") {
|
|
769
773
|
iframeRef.current?.contentWindow?.postMessage(
|
|
770
774
|
{ __cms: true, type: "cms:set-all-overrides", overrides: ctx.overrides },
|
|
@@ -855,8 +859,8 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
855
859
|
)
|
|
856
860
|
] })
|
|
857
861
|
] }),
|
|
858
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-col
|
|
859
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex-1 overflow-hidden bg-slate-100/80 p-2
|
|
862
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex flex-col sm:flex-row flex-1 overflow-hidden", children: [
|
|
863
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "flex-1 overflow-hidden bg-slate-100/80 p-2 sm:p-4 flex flex-col items-center", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: `flex-1 rounded-xl overflow-hidden border border-slate-200 bg-white shadow-lg ring-1 ring-slate-900/5 min-h-[300px] transition-all duration-300 w-full ${viewMode === "mobile" ? "max-w-[375px]" : viewMode === "tablet" ? "max-w-[768px]" : "w-full"}`, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
860
864
|
"iframe",
|
|
861
865
|
{
|
|
862
866
|
ref: iframeRef,
|
|
@@ -866,47 +870,70 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
866
870
|
},
|
|
867
871
|
src
|
|
868
872
|
) }) }),
|
|
869
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("aside", { className:
|
|
870
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "sticky top-0 bg-white/90 backdrop-blur border-b border-slate-200 px-5 py-3 md:py-4 z-10", children: [
|
|
871
|
-
/* @__PURE__ */ (0, import_jsx_runtime5.
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
] }),
|
|
877
|
-
selectedMeta ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
878
|
-
FieldEditor,
|
|
879
|
-
{
|
|
880
|
-
meta: selectedMeta,
|
|
881
|
-
value: ctx.overrides[selectedMeta.id] ?? selectedMeta.defaultValue,
|
|
882
|
-
onChange: (v) => updateOverride(selectedMeta.id, v),
|
|
883
|
-
onReset: () => {
|
|
884
|
-
ctx.reset(selectedMeta.id);
|
|
885
|
-
iframeRef.current?.contentWindow?.postMessage(
|
|
873
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("aside", { className: `w-full sm:w-[320px] lg:w-[360px] shrink-0 overflow-y-auto border-t sm:border-t-0 sm:border-l border-slate-200 bg-white shadow-[-4px_0_15px_-3px_rgba(0,0,0,0.05)] z-10 hide-scrollbar transition-all duration-300 ${drawerState === "min" ? "max-h-[52px] sm:max-h-none" : drawerState === "full" ? "max-h-[85vh] sm:max-h-none" : "max-h-[50vh] sm:max-h-none"}`, children: [
|
|
874
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "sticky top-0 bg-white/90 backdrop-blur border-b border-slate-200 px-5 py-3 md:py-4 z-10 flex items-center justify-between", children: [
|
|
875
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "text-xs font-bold uppercase tracking-widest text-slate-500", children: selectedMeta ? "Edit Field" : "Editable Elements" }),
|
|
876
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-3", children: [
|
|
877
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex items-center gap-1 sm:hidden", children: [
|
|
878
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
879
|
+
"button",
|
|
886
880
|
{
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
}
|
|
892
|
-
|
|
893
|
-
)
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
881
|
+
onClick: () => setDrawerState((prev) => prev === "full" ? "half" : prev === "half" ? "min" : "half"),
|
|
882
|
+
className: "p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded",
|
|
883
|
+
title: "Shrink",
|
|
884
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronDown, { className: "w-4 h-4" })
|
|
885
|
+
}
|
|
886
|
+
),
|
|
887
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
888
|
+
"button",
|
|
889
|
+
{
|
|
890
|
+
onClick: () => setDrawerState((prev) => prev === "min" ? "half" : prev === "half" ? "full" : "half"),
|
|
891
|
+
className: "p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded",
|
|
892
|
+
title: "Expand",
|
|
893
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_lucide_react2.ChevronUp, { className: "w-4 h-4" })
|
|
894
|
+
}
|
|
895
|
+
)
|
|
896
|
+
] }),
|
|
897
|
+
selectedMeta && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { onClick: () => setSelectedId(null), className: "sm:hidden text-slate-400 hover:text-slate-700 text-xs font-bold uppercase tracking-widest", children: "Close" })
|
|
898
|
+
] })
|
|
899
|
+
] }),
|
|
900
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: drawerState === "min" ? "hidden sm:block" : "block", children: [
|
|
901
|
+
!selectedMeta && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "px-5 mt-1 mb-2", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "text-[10px] md:text-xs text-slate-400", children: "Select an element on the left to edit it." }) }),
|
|
902
|
+
selectedMeta ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
903
|
+
FieldEditor,
|
|
904
|
+
{
|
|
905
|
+
meta: selectedMeta,
|
|
906
|
+
value: ctx.overrides[selectedMeta.id] ?? selectedMeta.defaultValue,
|
|
907
|
+
onChange: (v) => updateOverride(selectedMeta.id, v),
|
|
908
|
+
onReset: () => {
|
|
909
|
+
ctx.reset(selectedMeta.id);
|
|
910
|
+
iframeRef.current?.contentWindow?.postMessage(
|
|
911
|
+
{
|
|
912
|
+
__cms: true,
|
|
913
|
+
type: "cms:set-override",
|
|
914
|
+
id: selectedMeta.id,
|
|
915
|
+
value: selectedMeta.defaultValue
|
|
916
|
+
},
|
|
917
|
+
"*"
|
|
918
|
+
);
|
|
919
|
+
},
|
|
920
|
+
onClose: () => setSelectedId(null)
|
|
907
921
|
}
|
|
908
|
-
|
|
909
|
-
|
|
922
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
923
|
+
SectionAccordion,
|
|
924
|
+
{
|
|
925
|
+
registered,
|
|
926
|
+
onSelect: (id) => {
|
|
927
|
+
setSelectedId(id);
|
|
928
|
+
setDrawerState((prev) => prev === "min" ? "half" : prev);
|
|
929
|
+
iframeRef.current?.contentWindow?.postMessage(
|
|
930
|
+
{ __cms: true, type: "cms:select", id },
|
|
931
|
+
"*"
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
)
|
|
936
|
+
] })
|
|
910
937
|
] })
|
|
911
938
|
] })
|
|
912
939
|
] });
|
|
@@ -1496,7 +1523,31 @@ function CollectionEditor({ collection }) {
|
|
|
1496
1523
|
placeholder: `Search ${f.label.toLowerCase()}...`,
|
|
1497
1524
|
iconMap: ctx.iconMap
|
|
1498
1525
|
}
|
|
1499
|
-
) : f.type === "
|
|
1526
|
+
) : f.type === "slug" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "flex gap-2", children: [
|
|
1527
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1528
|
+
"input",
|
|
1529
|
+
{
|
|
1530
|
+
type: "text",
|
|
1531
|
+
value: String(editing[f.id] ?? ""),
|
|
1532
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
1533
|
+
className: "flex-1 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"
|
|
1534
|
+
}
|
|
1535
|
+
),
|
|
1536
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1537
|
+
"button",
|
|
1538
|
+
{
|
|
1539
|
+
type: "button",
|
|
1540
|
+
onClick: () => {
|
|
1541
|
+
const sourceField = f.source || "title";
|
|
1542
|
+
let val = String(editing[sourceField] || editing.id || "");
|
|
1543
|
+
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
1544
|
+
setEditing({ ...editing, [f.id]: val });
|
|
1545
|
+
},
|
|
1546
|
+
className: "px-4 py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm font-semibold rounded-xl border border-slate-200 transition-colors",
|
|
1547
|
+
children: "Generate"
|
|
1548
|
+
}
|
|
1549
|
+
)
|
|
1550
|
+
] }) : f.type === "select" ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { children: [
|
|
1500
1551
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
1501
1552
|
"input",
|
|
1502
1553
|
{
|
|
@@ -2167,7 +2218,7 @@ function AdminLogin({
|
|
|
2167
2218
|
const [loading, setLoading] = (0, import_react6.useState)(false);
|
|
2168
2219
|
const [view, setView] = (0, import_react6.useState)("checking");
|
|
2169
2220
|
(0, import_react6.useEffect)(() => {
|
|
2170
|
-
fetch(authApiRoute).then((res) => res.json()).then((data) => {
|
|
2221
|
+
fetch(authApiRoute, { cache: "no-store" }).then((res) => res.json()).then((data) => {
|
|
2171
2222
|
if (data.hasUsers) {
|
|
2172
2223
|
setView("login");
|
|
2173
2224
|
} else {
|
package/dist/index.mjs
CHANGED
|
@@ -362,6 +362,7 @@ import {
|
|
|
362
362
|
PanelLeftOpen,
|
|
363
363
|
Search,
|
|
364
364
|
ChevronDown,
|
|
365
|
+
ChevronUp,
|
|
365
366
|
Inbox,
|
|
366
367
|
RefreshCw,
|
|
367
368
|
Eye,
|
|
@@ -749,6 +750,7 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
749
750
|
const [registered, setRegistered] = useState4([]);
|
|
750
751
|
const [selectedId, setSelectedId] = useState4(null);
|
|
751
752
|
const [preview, setPreview] = useState4(false);
|
|
753
|
+
const [drawerState, setDrawerState] = useState4("half");
|
|
752
754
|
const src = useMemo2(
|
|
753
755
|
() => `${page.path}${preview ? "" : "?__cms=edit"}`,
|
|
754
756
|
[page.path, preview]
|
|
@@ -762,6 +764,9 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
762
764
|
setRegistered(d.items);
|
|
763
765
|
} else if (d.type === "cms:select") {
|
|
764
766
|
setSelectedId(d.id ?? null);
|
|
767
|
+
if (d.id) {
|
|
768
|
+
setDrawerState((prev) => prev === "min" ? "half" : prev);
|
|
769
|
+
}
|
|
765
770
|
} else if (d.type === "cms:ready") {
|
|
766
771
|
iframeRef.current?.contentWindow?.postMessage(
|
|
767
772
|
{ __cms: true, type: "cms:set-all-overrides", overrides: ctx.overrides },
|
|
@@ -852,8 +857,8 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
852
857
|
)
|
|
853
858
|
] })
|
|
854
859
|
] }),
|
|
855
|
-
/* @__PURE__ */ jsxs2("div", { className: "flex flex-col
|
|
856
|
-
/* @__PURE__ */ jsx5("div", { className: "flex-1 overflow-hidden bg-slate-100/80 p-2
|
|
860
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex flex-col sm:flex-row flex-1 overflow-hidden", children: [
|
|
861
|
+
/* @__PURE__ */ jsx5("div", { className: "flex-1 overflow-hidden bg-slate-100/80 p-2 sm:p-4 flex flex-col items-center", children: /* @__PURE__ */ jsx5("div", { className: `flex-1 rounded-xl overflow-hidden border border-slate-200 bg-white shadow-lg ring-1 ring-slate-900/5 min-h-[300px] transition-all duration-300 w-full ${viewMode === "mobile" ? "max-w-[375px]" : viewMode === "tablet" ? "max-w-[768px]" : "w-full"}`, children: /* @__PURE__ */ jsx5(
|
|
857
862
|
"iframe",
|
|
858
863
|
{
|
|
859
864
|
ref: iframeRef,
|
|
@@ -863,47 +868,70 @@ function PageEditor({ page, showList, onToggleList }) {
|
|
|
863
868
|
},
|
|
864
869
|
src
|
|
865
870
|
) }) }),
|
|
866
|
-
/* @__PURE__ */ jsxs2("aside", { className:
|
|
867
|
-
/* @__PURE__ */ jsxs2("div", { className: "sticky top-0 bg-white/90 backdrop-blur border-b border-slate-200 px-5 py-3 md:py-4 z-10", children: [
|
|
868
|
-
/* @__PURE__ */
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
] }),
|
|
874
|
-
selectedMeta ? /* @__PURE__ */ jsx5(
|
|
875
|
-
FieldEditor,
|
|
876
|
-
{
|
|
877
|
-
meta: selectedMeta,
|
|
878
|
-
value: ctx.overrides[selectedMeta.id] ?? selectedMeta.defaultValue,
|
|
879
|
-
onChange: (v) => updateOverride(selectedMeta.id, v),
|
|
880
|
-
onReset: () => {
|
|
881
|
-
ctx.reset(selectedMeta.id);
|
|
882
|
-
iframeRef.current?.contentWindow?.postMessage(
|
|
871
|
+
/* @__PURE__ */ jsxs2("aside", { className: `w-full sm:w-[320px] lg:w-[360px] shrink-0 overflow-y-auto border-t sm:border-t-0 sm:border-l border-slate-200 bg-white shadow-[-4px_0_15px_-3px_rgba(0,0,0,0.05)] z-10 hide-scrollbar transition-all duration-300 ${drawerState === "min" ? "max-h-[52px] sm:max-h-none" : drawerState === "full" ? "max-h-[85vh] sm:max-h-none" : "max-h-[50vh] sm:max-h-none"}`, children: [
|
|
872
|
+
/* @__PURE__ */ jsxs2("div", { className: "sticky top-0 bg-white/90 backdrop-blur border-b border-slate-200 px-5 py-3 md:py-4 z-10 flex items-center justify-between", children: [
|
|
873
|
+
/* @__PURE__ */ jsx5("div", { className: "text-xs font-bold uppercase tracking-widest text-slate-500", children: selectedMeta ? "Edit Field" : "Editable Elements" }),
|
|
874
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-3", children: [
|
|
875
|
+
/* @__PURE__ */ jsxs2("div", { className: "flex items-center gap-1 sm:hidden", children: [
|
|
876
|
+
/* @__PURE__ */ jsx5(
|
|
877
|
+
"button",
|
|
883
878
|
{
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
879
|
+
onClick: () => setDrawerState((prev) => prev === "full" ? "half" : prev === "half" ? "min" : "half"),
|
|
880
|
+
className: "p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded",
|
|
881
|
+
title: "Shrink",
|
|
882
|
+
children: /* @__PURE__ */ jsx5(ChevronDown, { className: "w-4 h-4" })
|
|
883
|
+
}
|
|
884
|
+
),
|
|
885
|
+
/* @__PURE__ */ jsx5(
|
|
886
|
+
"button",
|
|
887
|
+
{
|
|
888
|
+
onClick: () => setDrawerState((prev) => prev === "min" ? "half" : prev === "half" ? "full" : "half"),
|
|
889
|
+
className: "p-1 text-slate-400 hover:text-slate-700 hover:bg-slate-100 rounded",
|
|
890
|
+
title: "Expand",
|
|
891
|
+
children: /* @__PURE__ */ jsx5(ChevronUp, { className: "w-4 h-4" })
|
|
892
|
+
}
|
|
893
|
+
)
|
|
894
|
+
] }),
|
|
895
|
+
selectedMeta && /* @__PURE__ */ jsx5("button", { onClick: () => setSelectedId(null), className: "sm:hidden text-slate-400 hover:text-slate-700 text-xs font-bold uppercase tracking-widest", children: "Close" })
|
|
896
|
+
] })
|
|
897
|
+
] }),
|
|
898
|
+
/* @__PURE__ */ jsxs2("div", { className: drawerState === "min" ? "hidden sm:block" : "block", children: [
|
|
899
|
+
!selectedMeta && /* @__PURE__ */ jsx5("div", { className: "px-5 mt-1 mb-2", children: /* @__PURE__ */ jsx5("p", { className: "text-[10px] md:text-xs text-slate-400", children: "Select an element on the left to edit it." }) }),
|
|
900
|
+
selectedMeta ? /* @__PURE__ */ jsx5(
|
|
901
|
+
FieldEditor,
|
|
902
|
+
{
|
|
903
|
+
meta: selectedMeta,
|
|
904
|
+
value: ctx.overrides[selectedMeta.id] ?? selectedMeta.defaultValue,
|
|
905
|
+
onChange: (v) => updateOverride(selectedMeta.id, v),
|
|
906
|
+
onReset: () => {
|
|
907
|
+
ctx.reset(selectedMeta.id);
|
|
908
|
+
iframeRef.current?.contentWindow?.postMessage(
|
|
909
|
+
{
|
|
910
|
+
__cms: true,
|
|
911
|
+
type: "cms:set-override",
|
|
912
|
+
id: selectedMeta.id,
|
|
913
|
+
value: selectedMeta.defaultValue
|
|
914
|
+
},
|
|
915
|
+
"*"
|
|
916
|
+
);
|
|
917
|
+
},
|
|
918
|
+
onClose: () => setSelectedId(null)
|
|
904
919
|
}
|
|
905
|
-
|
|
906
|
-
|
|
920
|
+
) : /* @__PURE__ */ jsx5(
|
|
921
|
+
SectionAccordion,
|
|
922
|
+
{
|
|
923
|
+
registered,
|
|
924
|
+
onSelect: (id) => {
|
|
925
|
+
setSelectedId(id);
|
|
926
|
+
setDrawerState((prev) => prev === "min" ? "half" : prev);
|
|
927
|
+
iframeRef.current?.contentWindow?.postMessage(
|
|
928
|
+
{ __cms: true, type: "cms:select", id },
|
|
929
|
+
"*"
|
|
930
|
+
);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
)
|
|
934
|
+
] })
|
|
907
935
|
] })
|
|
908
936
|
] })
|
|
909
937
|
] });
|
|
@@ -1493,7 +1521,31 @@ function CollectionEditor({ collection }) {
|
|
|
1493
1521
|
placeholder: `Search ${f.label.toLowerCase()}...`,
|
|
1494
1522
|
iconMap: ctx.iconMap
|
|
1495
1523
|
}
|
|
1496
|
-
) : f.type === "
|
|
1524
|
+
) : f.type === "slug" ? /* @__PURE__ */ jsxs2("div", { className: "flex gap-2", children: [
|
|
1525
|
+
/* @__PURE__ */ jsx5(
|
|
1526
|
+
"input",
|
|
1527
|
+
{
|
|
1528
|
+
type: "text",
|
|
1529
|
+
value: String(editing[f.id] ?? ""),
|
|
1530
|
+
onChange: (e) => setEditing({ ...editing, [f.id]: e.target.value }),
|
|
1531
|
+
className: "flex-1 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"
|
|
1532
|
+
}
|
|
1533
|
+
),
|
|
1534
|
+
/* @__PURE__ */ jsx5(
|
|
1535
|
+
"button",
|
|
1536
|
+
{
|
|
1537
|
+
type: "button",
|
|
1538
|
+
onClick: () => {
|
|
1539
|
+
const sourceField = f.source || "title";
|
|
1540
|
+
let val = String(editing[sourceField] || editing.id || "");
|
|
1541
|
+
val = val.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/(^-|-$)+/g, "");
|
|
1542
|
+
setEditing({ ...editing, [f.id]: val });
|
|
1543
|
+
},
|
|
1544
|
+
className: "px-4 py-2.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-sm font-semibold rounded-xl border border-slate-200 transition-colors",
|
|
1545
|
+
children: "Generate"
|
|
1546
|
+
}
|
|
1547
|
+
)
|
|
1548
|
+
] }) : f.type === "select" ? /* @__PURE__ */ jsxs2("div", { children: [
|
|
1497
1549
|
/* @__PURE__ */ jsx5(
|
|
1498
1550
|
"input",
|
|
1499
1551
|
{
|
|
@@ -2164,7 +2216,7 @@ function AdminLogin({
|
|
|
2164
2216
|
const [loading, setLoading] = useState5(false);
|
|
2165
2217
|
const [view, setView] = useState5("checking");
|
|
2166
2218
|
useEffect5(() => {
|
|
2167
|
-
fetch(authApiRoute).then((res) => res.json()).then((data) => {
|
|
2219
|
+
fetch(authApiRoute, { cache: "no-store" }).then((res) => res.json()).then((data) => {
|
|
2168
2220
|
if (data.hasUsers) {
|
|
2169
2221
|
setView("login");
|
|
2170
2222
|
} else {
|
package/dist/storage.js
CHANGED
|
@@ -186,8 +186,11 @@ function createSanityAdapter(config) {
|
|
|
186
186
|
const readClient = createReadClient(config);
|
|
187
187
|
const writeClient = config.token ? createWriteClient(config) : null;
|
|
188
188
|
const apiBase = config.apiBase?.replace(/\/$/, "");
|
|
189
|
+
function canUseApi() {
|
|
190
|
+
return !!apiBase && (typeof window !== "undefined" || apiBase.startsWith("http"));
|
|
191
|
+
}
|
|
189
192
|
async function writeOverrides(map) {
|
|
190
|
-
if (
|
|
193
|
+
if (canUseApi()) {
|
|
191
194
|
await apiRequest(apiBase, "/overrides", {
|
|
192
195
|
method: "PUT",
|
|
193
196
|
headers: { "Content-Type": "application/json" },
|
|
@@ -202,7 +205,7 @@ function createSanityAdapter(config) {
|
|
|
202
205
|
await writeClient.transaction().createIfNotExists({ _id: OVERRIDES_DOC_ID, _type: "cms_overrides" }).patch(OVERRIDES_DOC_ID, (p) => p.set({ data: JSON.stringify(map) })).commit();
|
|
203
206
|
}
|
|
204
207
|
async function writeEntry(collectionId, entry) {
|
|
205
|
-
if (
|
|
208
|
+
if (canUseApi()) {
|
|
206
209
|
await apiRequest(apiBase, "/entries", {
|
|
207
210
|
method: "PUT",
|
|
208
211
|
headers: { "Content-Type": "application/json" },
|
|
@@ -223,7 +226,7 @@ function createSanityAdapter(config) {
|
|
|
223
226
|
}).patch(docId, (p) => p.set({ data: JSON.stringify(entry) })).commit();
|
|
224
227
|
}
|
|
225
228
|
async function removeEntry(collectionId, entryId) {
|
|
226
|
-
if (
|
|
229
|
+
if (canUseApi()) {
|
|
227
230
|
await apiRequest(
|
|
228
231
|
apiBase,
|
|
229
232
|
`/entries?collectionId=${encodeURIComponent(collectionId)}&entryId=${encodeURIComponent(entryId)}`,
|
|
@@ -241,7 +244,7 @@ function createSanityAdapter(config) {
|
|
|
241
244
|
name: "sanity",
|
|
242
245
|
async getOverrides() {
|
|
243
246
|
try {
|
|
244
|
-
if (
|
|
247
|
+
if (canUseApi()) {
|
|
245
248
|
return await apiRequest(apiBase, "/overrides");
|
|
246
249
|
}
|
|
247
250
|
const doc = await readClient.getDocument(OVERRIDES_DOC_ID);
|
|
@@ -262,7 +265,7 @@ function createSanityAdapter(config) {
|
|
|
262
265
|
},
|
|
263
266
|
async listEntries(collectionId) {
|
|
264
267
|
try {
|
|
265
|
-
if (
|
|
268
|
+
if (canUseApi()) {
|
|
266
269
|
return await apiRequest(
|
|
267
270
|
apiBase,
|
|
268
271
|
`/entries?collectionId=${encodeURIComponent(collectionId)}`
|
|
@@ -295,7 +298,7 @@ function createSanityAdapter(config) {
|
|
|
295
298
|
},
|
|
296
299
|
async saveSubmission(submission) {
|
|
297
300
|
try {
|
|
298
|
-
if (
|
|
301
|
+
if (canUseApi()) {
|
|
299
302
|
await apiRequest(apiBase, "/submissions", {
|
|
300
303
|
method: "POST",
|
|
301
304
|
headers: { "Content-Type": "application/json" },
|
|
@@ -327,7 +330,7 @@ function createSanityAdapter(config) {
|
|
|
327
330
|
},
|
|
328
331
|
async listSubmissions(formId) {
|
|
329
332
|
try {
|
|
330
|
-
if (
|
|
333
|
+
if (canUseApi()) {
|
|
331
334
|
const qs = formId ? `?formId=${encodeURIComponent(formId)}` : "";
|
|
332
335
|
return await apiRequest(apiBase, `/submissions${qs}`);
|
|
333
336
|
}
|
|
@@ -349,7 +352,7 @@ function createSanityAdapter(config) {
|
|
|
349
352
|
},
|
|
350
353
|
async deleteSubmission(id) {
|
|
351
354
|
try {
|
|
352
|
-
if (
|
|
355
|
+
if (canUseApi()) {
|
|
353
356
|
await apiRequest(
|
|
354
357
|
apiBase,
|
|
355
358
|
`/submissions?id=${encodeURIComponent(id)}`,
|
|
@@ -365,7 +368,7 @@ function createSanityAdapter(config) {
|
|
|
365
368
|
},
|
|
366
369
|
async markSubmissionRead(id) {
|
|
367
370
|
try {
|
|
368
|
-
if (
|
|
371
|
+
if (canUseApi()) {
|
|
369
372
|
await apiRequest(apiBase, "/submissions", {
|
|
370
373
|
method: "PATCH",
|
|
371
374
|
headers: { "Content-Type": "application/json" },
|
|
@@ -380,7 +383,7 @@ function createSanityAdapter(config) {
|
|
|
380
383
|
}
|
|
381
384
|
},
|
|
382
385
|
async uploadImage(file) {
|
|
383
|
-
if (
|
|
386
|
+
if (canUseApi()) {
|
|
384
387
|
const formData = new FormData();
|
|
385
388
|
formData.append("file", file);
|
|
386
389
|
const res = await fetch(`${apiBase}/upload`, {
|
package/dist/storage.mjs
CHANGED
|
@@ -158,8 +158,11 @@ function createSanityAdapter(config) {
|
|
|
158
158
|
const readClient = createReadClient(config);
|
|
159
159
|
const writeClient = config.token ? createWriteClient(config) : null;
|
|
160
160
|
const apiBase = config.apiBase?.replace(/\/$/, "");
|
|
161
|
+
function canUseApi() {
|
|
162
|
+
return !!apiBase && (typeof window !== "undefined" || apiBase.startsWith("http"));
|
|
163
|
+
}
|
|
161
164
|
async function writeOverrides(map) {
|
|
162
|
-
if (
|
|
165
|
+
if (canUseApi()) {
|
|
163
166
|
await apiRequest(apiBase, "/overrides", {
|
|
164
167
|
method: "PUT",
|
|
165
168
|
headers: { "Content-Type": "application/json" },
|
|
@@ -174,7 +177,7 @@ function createSanityAdapter(config) {
|
|
|
174
177
|
await writeClient.transaction().createIfNotExists({ _id: OVERRIDES_DOC_ID, _type: "cms_overrides" }).patch(OVERRIDES_DOC_ID, (p) => p.set({ data: JSON.stringify(map) })).commit();
|
|
175
178
|
}
|
|
176
179
|
async function writeEntry(collectionId, entry) {
|
|
177
|
-
if (
|
|
180
|
+
if (canUseApi()) {
|
|
178
181
|
await apiRequest(apiBase, "/entries", {
|
|
179
182
|
method: "PUT",
|
|
180
183
|
headers: { "Content-Type": "application/json" },
|
|
@@ -195,7 +198,7 @@ function createSanityAdapter(config) {
|
|
|
195
198
|
}).patch(docId, (p) => p.set({ data: JSON.stringify(entry) })).commit();
|
|
196
199
|
}
|
|
197
200
|
async function removeEntry(collectionId, entryId) {
|
|
198
|
-
if (
|
|
201
|
+
if (canUseApi()) {
|
|
199
202
|
await apiRequest(
|
|
200
203
|
apiBase,
|
|
201
204
|
`/entries?collectionId=${encodeURIComponent(collectionId)}&entryId=${encodeURIComponent(entryId)}`,
|
|
@@ -213,7 +216,7 @@ function createSanityAdapter(config) {
|
|
|
213
216
|
name: "sanity",
|
|
214
217
|
async getOverrides() {
|
|
215
218
|
try {
|
|
216
|
-
if (
|
|
219
|
+
if (canUseApi()) {
|
|
217
220
|
return await apiRequest(apiBase, "/overrides");
|
|
218
221
|
}
|
|
219
222
|
const doc = await readClient.getDocument(OVERRIDES_DOC_ID);
|
|
@@ -234,7 +237,7 @@ function createSanityAdapter(config) {
|
|
|
234
237
|
},
|
|
235
238
|
async listEntries(collectionId) {
|
|
236
239
|
try {
|
|
237
|
-
if (
|
|
240
|
+
if (canUseApi()) {
|
|
238
241
|
return await apiRequest(
|
|
239
242
|
apiBase,
|
|
240
243
|
`/entries?collectionId=${encodeURIComponent(collectionId)}`
|
|
@@ -267,7 +270,7 @@ function createSanityAdapter(config) {
|
|
|
267
270
|
},
|
|
268
271
|
async saveSubmission(submission) {
|
|
269
272
|
try {
|
|
270
|
-
if (
|
|
273
|
+
if (canUseApi()) {
|
|
271
274
|
await apiRequest(apiBase, "/submissions", {
|
|
272
275
|
method: "POST",
|
|
273
276
|
headers: { "Content-Type": "application/json" },
|
|
@@ -299,7 +302,7 @@ function createSanityAdapter(config) {
|
|
|
299
302
|
},
|
|
300
303
|
async listSubmissions(formId) {
|
|
301
304
|
try {
|
|
302
|
-
if (
|
|
305
|
+
if (canUseApi()) {
|
|
303
306
|
const qs = formId ? `?formId=${encodeURIComponent(formId)}` : "";
|
|
304
307
|
return await apiRequest(apiBase, `/submissions${qs}`);
|
|
305
308
|
}
|
|
@@ -321,7 +324,7 @@ function createSanityAdapter(config) {
|
|
|
321
324
|
},
|
|
322
325
|
async deleteSubmission(id) {
|
|
323
326
|
try {
|
|
324
|
-
if (
|
|
327
|
+
if (canUseApi()) {
|
|
325
328
|
await apiRequest(
|
|
326
329
|
apiBase,
|
|
327
330
|
`/submissions?id=${encodeURIComponent(id)}`,
|
|
@@ -337,7 +340,7 @@ function createSanityAdapter(config) {
|
|
|
337
340
|
},
|
|
338
341
|
async markSubmissionRead(id) {
|
|
339
342
|
try {
|
|
340
|
-
if (
|
|
343
|
+
if (canUseApi()) {
|
|
341
344
|
await apiRequest(apiBase, "/submissions", {
|
|
342
345
|
method: "PATCH",
|
|
343
346
|
headers: { "Content-Type": "application/json" },
|
|
@@ -352,7 +355,7 @@ function createSanityAdapter(config) {
|
|
|
352
355
|
}
|
|
353
356
|
},
|
|
354
357
|
async uploadImage(file) {
|
|
355
|
-
if (
|
|
358
|
+
if (canUseApi()) {
|
|
356
359
|
const formData = new FormData();
|
|
357
360
|
formData.append("file", file);
|
|
358
361
|
const res = await fetch(`${apiBase}/upload`, {
|
package/dist/types.d.mts
CHANGED
|
@@ -23,11 +23,12 @@ interface PageDef {
|
|
|
23
23
|
interface CollectionField {
|
|
24
24
|
id: string;
|
|
25
25
|
label: string;
|
|
26
|
-
type: FieldType | "number" | "boolean" | "select" | "icon";
|
|
26
|
+
type: FieldType | "number" | "boolean" | "select" | "icon" | "slug";
|
|
27
27
|
options?: string[] | {
|
|
28
28
|
label: string;
|
|
29
29
|
value: string;
|
|
30
30
|
}[];
|
|
31
|
+
source?: string;
|
|
31
32
|
defaultValue?: unknown;
|
|
32
33
|
}
|
|
33
34
|
interface CollectionDef {
|
package/dist/types.d.ts
CHANGED
|
@@ -23,11 +23,12 @@ interface PageDef {
|
|
|
23
23
|
interface CollectionField {
|
|
24
24
|
id: string;
|
|
25
25
|
label: string;
|
|
26
|
-
type: FieldType | "number" | "boolean" | "select" | "icon";
|
|
26
|
+
type: FieldType | "number" | "boolean" | "select" | "icon" | "slug";
|
|
27
27
|
options?: string[] | {
|
|
28
28
|
label: string;
|
|
29
29
|
value: string;
|
|
30
30
|
}[];
|
|
31
|
+
source?: string;
|
|
31
32
|
defaultValue?: unknown;
|
|
32
33
|
}
|
|
33
34
|
interface CollectionDef {
|