@kidecms/core 0.1.11 → 0.13.0
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/LICENSE +21 -0
- package/admin/components/AssetsGrid.tsx +366 -173
- package/admin/components/BlockEditor.tsx +260 -679
- package/admin/components/CheckboxField.tsx +2 -2
- package/admin/components/CollaborationReviewBar.tsx +384 -0
- package/admin/components/ColorField.tsx +87 -0
- package/admin/components/CommandPalette.tsx +169 -0
- package/admin/components/ContentEditor.tsx +687 -0
- package/admin/components/DocumentActions.tsx +4 -2
- package/admin/components/DocumentsDataTable.tsx +91 -10
- package/admin/components/FieldControl.astro +151 -26
- package/admin/components/FocalPointSelector.tsx +27 -1
- package/admin/components/InternalLinkPicker.tsx +4 -3
- package/admin/components/LinkField.tsx +126 -0
- package/admin/components/RelationField.tsx +105 -26
- package/admin/components/RepeaterInput.tsx +46 -0
- package/admin/components/RichTextEditor.tsx +44 -9
- package/admin/components/SharedSectionBlockField.tsx +93 -0
- package/admin/components/SidebarUserMenu.tsx +1 -1
- package/admin/components/Toast.astro +1 -1
- package/admin/components/TreeItemsEditor.tsx +20 -19
- package/admin/components/TreeSelect.tsx +2 -2
- package/admin/components/YoutubeField.tsx +48 -0
- package/admin/components/block-fields.tsx +777 -0
- package/admin/components/content-block-spec.ts +114 -0
- package/admin/components/slash-command.tsx +242 -0
- package/admin/components/tree-utils.ts +14 -2
- package/admin/components/ui/badge.tsx +2 -3
- package/admin/components/ui/button.tsx +5 -4
- package/admin/components/ui/checkbox.tsx +1 -1
- package/admin/components/ui/input.tsx +1 -1
- package/admin/components/ui/select.tsx +1 -1
- package/admin/components/ui/table.tsx +1 -1
- package/admin/components/ui/textarea.tsx +1 -1
- package/admin/layouts/AdminLayout.astro +323 -123
- package/admin/lib/access.ts +54 -0
- package/admin/lib/collaboration.ts +178 -0
- package/admin/lib/edit-data.ts +448 -0
- package/admin/views/AccessDeniedView.astro +8 -0
- package/admin/views/EditView.astro +706 -0
- package/admin/views/ListView.astro +202 -0
- package/admin/views/RecentView.astro +76 -0
- package/admin/views/SinglesView.astro +65 -0
- package/admin/views/edit/EditScripts.astro +145 -0
- package/admin/views/edit/ReverseReferencesList.astro +68 -0
- package/core/admin.ts +193 -0
- package/core/ai.ts +87 -0
- package/core/api.ts +1392 -0
- package/core/assets.ts +336 -0
- package/core/audit.ts +84 -0
- package/core/auth-config.ts +44 -0
- package/core/auth.ts +303 -0
- package/core/collaboration.ts +276 -0
- package/core/content.ts +27 -0
- package/core/create-admin.ts +28 -0
- package/core/define.ts +625 -0
- package/core/field-model.ts +172 -0
- package/core/generator.ts +519 -0
- package/core/http.ts +42 -0
- package/core/image.ts +219 -0
- package/core/index.ts +211 -0
- package/core/locks.ts +52 -0
- package/core/log.ts +37 -0
- package/core/migrate.ts +278 -0
- package/core/rate-limit.ts +110 -0
- package/core/request-scope.ts +33 -0
- package/core/richtext.ts +1 -0
- package/core/runtime.ts +63 -0
- package/core/schema.ts +32 -0
- package/core/search.ts +489 -0
- package/core/seed.ts +101 -0
- package/core/shared-sections.ts +96 -0
- package/core/tasks.ts +176 -0
- package/core/values.ts +433 -0
- package/core/webhooks.ts +85 -0
- package/core/youtube.ts +39 -0
- package/internals/cli.mjs +34 -0
- package/internals/context.ts +67 -0
- package/internals/create-admin.ts +40 -0
- package/internals/describe.ts +25 -0
- package/internals/eject.ts +144 -0
- package/internals/generator.ts +11 -0
- package/internals/integration.ts +481 -0
- package/internals/mcp.ts +397 -0
- package/internals/project.ts +26 -0
- package/internals/push.ts +160 -0
- package/internals/reindex.ts +11 -0
- package/internals/restore.ts +257 -0
- package/internals/seed.data.ts +7 -0
- package/internals/seed.ts +11 -0
- package/internals/upgrade.ts +776 -0
- package/{virtual.d.ts → internals/virtual.d.ts} +39 -5
- package/middleware/auth.ts +130 -17
- package/middleware/push.ts +121 -0
- package/package.json +55 -67
- package/platform/cloudflare/cf-env.ts +60 -0
- package/platform/cloudflare/database.ts +28 -0
- package/platform/cloudflare/globals.d.ts +5 -0
- package/platform/cloudflare/storage.ts +33 -0
- package/platform/cloudflare/uploads-route.ts +37 -0
- package/platform/node/database.ts +39 -0
- package/platform/node/storage.ts +52 -0
- package/routes/admin/[...path].astro +71 -0
- package/routes/{pages/admin → admin}/assets/[id].astro +25 -19
- package/routes/admin/assets/index.astro +90 -0
- package/routes/{pages/admin/login.astro → admin/forgot-password.astro} +21 -19
- package/routes/{pages/admin → admin}/invite.astro +6 -6
- package/routes/admin/login.astro +103 -0
- package/routes/admin/reset-password.astro +73 -0
- package/routes/{pages/admin → admin}/setup.astro +31 -8
- package/routes/api/{cms/[collection] → [collection]}/[...path].ts +66 -14
- package/routes/api/admin/search.ts +89 -0
- package/routes/api/{cms/assets → assets}/[id].ts +24 -14
- package/routes/api/{cms/assets → assets}/index.ts +4 -2
- package/routes/api/assets/upload.ts +147 -0
- package/routes/api/auth/forgot-password.ts +77 -0
- package/routes/api/{cms/auth → auth}/invite.ts +41 -9
- package/routes/api/auth/login.ts +167 -0
- package/routes/api/{cms/auth → auth}/logout.ts +11 -2
- package/routes/api/auth/reset-password.ts +85 -0
- package/routes/api/auth/setup.ts +110 -0
- package/routes/api/auth/sso/[provider]/start.ts +34 -0
- package/routes/api/collaboration/index.ts +106 -0
- package/routes/api/cron/_authorize.ts +25 -0
- package/routes/api/{cms/cron → cron}/publish.ts +3 -9
- package/routes/api/cron/tasks.ts +33 -0
- package/routes/api/forms/submit/[slug].ts +143 -0
- package/routes/api/img/[...path].ts +65 -0
- package/routes/api/{cms/preview → preview}/render.ts +8 -3
- package/routes/api/{cms/references → references}/[collection]/[id].ts +31 -1
- package/routes/api/webhooks/[provider].ts +54 -0
- package/README.md +0 -28
- package/dist/admin.d.ts +0 -33
- package/dist/admin.js +0 -92
- package/dist/ai.d.ts +0 -15
- package/dist/ai.js +0 -70
- package/dist/api.d.ts +0 -14
- package/dist/api.js +0 -833
- package/dist/assets.d.ts +0 -51
- package/dist/assets.js +0 -163
- package/dist/auth.d.ts +0 -30
- package/dist/auth.js +0 -132
- package/dist/content.d.ts +0 -3
- package/dist/content.js +0 -29
- package/dist/create-admin.d.ts +0 -5
- package/dist/create-admin.js +0 -23
- package/dist/define.d.ts +0 -254
- package/dist/define.js +0 -36
- package/dist/generator.d.ts +0 -9
- package/dist/generator.js +0 -370
- package/dist/image.d.ts +0 -9
- package/dist/image.js +0 -69
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -16
- package/dist/integration.d.ts +0 -14
- package/dist/integration.js +0 -327
- package/dist/locks.d.ts +0 -7
- package/dist/locks.js +0 -37
- package/dist/richtext.d.ts +0 -1
- package/dist/richtext.js +0 -1
- package/dist/runtime.d.ts +0 -24
- package/dist/runtime.js +0 -26
- package/dist/schema.d.ts +0 -17
- package/dist/schema.js +0 -13
- package/dist/seed.d.ts +0 -2
- package/dist/seed.js +0 -84
- package/dist/values.d.ts +0 -8
- package/dist/values.js +0 -102
- package/dist/webhooks.d.ts +0 -2
- package/dist/webhooks.js +0 -73
- package/routes/api/cms/assets/upload.ts +0 -112
- package/routes/api/cms/auth/login.ts +0 -124
- package/routes/api/cms/auth/setup.ts +0 -77
- package/routes/api/cms/img/[...path].ts +0 -24
- package/routes/pages/admin/[...path].astro +0 -1107
- package/routes/pages/admin/assets/index.astro +0 -63
- /package/routes/api/{cms/ai → ai}/alt-text.ts +0 -0
- /package/routes/api/{cms/ai → ai}/seo.ts +0 -0
- /package/routes/api/{cms/ai → ai}/translate.ts +0 -0
- /package/routes/api/{cms/assets → assets}/folders.ts +0 -0
- /package/routes/api/{cms/locks → locks}/[...path].ts +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { Checkbox } from "./ui/checkbox";
|
|
5
|
+
import { Input } from "./ui/input";
|
|
6
|
+
import { Label } from "./ui/label";
|
|
7
|
+
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
|
|
8
|
+
import InternalLinkPicker, { type LinkOptionGroup } from "./InternalLinkPicker";
|
|
9
|
+
|
|
10
|
+
// A structured link control: URL + label + open-in-new-tab, stored as
|
|
11
|
+
// { type, url, label, newTab }. A leading "/" is treated as an internal link.
|
|
12
|
+
// When linkOptions are provided, internal links are chosen with a document
|
|
13
|
+
// picker instead of a hand-typed path (which silently breaks on slug edits).
|
|
14
|
+
type LinkValue = { type?: string; url?: string; label?: string; newTab?: boolean };
|
|
15
|
+
|
|
16
|
+
type Props = {
|
|
17
|
+
name?: string;
|
|
18
|
+
value?: string | LinkValue;
|
|
19
|
+
onChange?: (value: LinkValue) => void;
|
|
20
|
+
linkOptions?: LinkOptionGroup[];
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
function parse(v: unknown): LinkValue {
|
|
24
|
+
if (!v) return {};
|
|
25
|
+
if (typeof v === "string") {
|
|
26
|
+
const s = v.trim();
|
|
27
|
+
if (!s) return {};
|
|
28
|
+
try {
|
|
29
|
+
return JSON.parse(s) as LinkValue;
|
|
30
|
+
} catch {
|
|
31
|
+
return { url: s };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return v as LinkValue;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default function LinkField({ name, value: initial, onChange, linkOptions = [] }: Props) {
|
|
38
|
+
const [value, setValue] = useState<LinkValue>(parse(initial));
|
|
39
|
+
const [linkType, setLinkType] = useState<"internal" | "external">(() => {
|
|
40
|
+
const url = parse(initial).url ?? "";
|
|
41
|
+
if (url) return url.startsWith("/") ? "internal" : "external";
|
|
42
|
+
return linkOptions.length > 0 ? "internal" : "external";
|
|
43
|
+
});
|
|
44
|
+
const hiddenRef = useRef<HTMLInputElement>(null);
|
|
45
|
+
const isInitial = useRef(true);
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (isInitial.current) {
|
|
49
|
+
isInitial.current = false;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
hiddenRef.current?.dispatchEvent(new Event("change", { bubbles: true }));
|
|
53
|
+
}, [value]);
|
|
54
|
+
|
|
55
|
+
const set = (patch: Partial<LinkValue>) => {
|
|
56
|
+
const next: LinkValue = { ...value, ...patch };
|
|
57
|
+
if (next.url) next.type = next.url.startsWith("/") ? "internal" : "external";
|
|
58
|
+
setValue(next);
|
|
59
|
+
onChange?.(next);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const hasPicker = linkOptions.length > 0;
|
|
63
|
+
|
|
64
|
+
return (
|
|
65
|
+
<div className="space-y-2 rounded-md border p-3">
|
|
66
|
+
{name && <input type="hidden" name={name} value={value.url ? JSON.stringify(value) : ""} ref={hiddenRef} />}
|
|
67
|
+
<div className="grid gap-1">
|
|
68
|
+
<Label className="text-xs">{hasPicker ? "Link" : "URL"}</Label>
|
|
69
|
+
{hasPicker ? (
|
|
70
|
+
<div className="flex items-center gap-2">
|
|
71
|
+
<Select
|
|
72
|
+
items={[
|
|
73
|
+
{ value: "internal", label: "Internal" },
|
|
74
|
+
{ value: "external", label: "External" },
|
|
75
|
+
]}
|
|
76
|
+
value={linkType}
|
|
77
|
+
onValueChange={(v) => setLinkType((v as "internal" | "external") ?? "internal")}
|
|
78
|
+
>
|
|
79
|
+
<SelectTrigger className="w-28 shrink-0 text-sm">
|
|
80
|
+
<SelectValue />
|
|
81
|
+
</SelectTrigger>
|
|
82
|
+
<SelectContent>
|
|
83
|
+
<SelectGroup>
|
|
84
|
+
<SelectItem value="internal">Internal</SelectItem>
|
|
85
|
+
<SelectItem value="external">External</SelectItem>
|
|
86
|
+
</SelectGroup>
|
|
87
|
+
</SelectContent>
|
|
88
|
+
</Select>
|
|
89
|
+
{linkType === "internal" ? (
|
|
90
|
+
<InternalLinkPicker
|
|
91
|
+
editHref={value.url ?? ""}
|
|
92
|
+
linkOptions={linkOptions}
|
|
93
|
+
onSelect={(item) => set({ url: item.href, ...(value.label ? {} : { label: item.label }) })}
|
|
94
|
+
/>
|
|
95
|
+
) : (
|
|
96
|
+
<Input
|
|
97
|
+
value={value.url ?? ""}
|
|
98
|
+
placeholder="https://example.com"
|
|
99
|
+
onChange={(e) => set({ url: e.target.value })}
|
|
100
|
+
/>
|
|
101
|
+
)}
|
|
102
|
+
</div>
|
|
103
|
+
) : (
|
|
104
|
+
<Input
|
|
105
|
+
value={value.url ?? ""}
|
|
106
|
+
placeholder="https://example.com or /about"
|
|
107
|
+
onChange={(e) => set({ url: e.target.value })}
|
|
108
|
+
/>
|
|
109
|
+
)}
|
|
110
|
+
</div>
|
|
111
|
+
<div className="grid gap-1">
|
|
112
|
+
<Label className="text-xs">Label</Label>
|
|
113
|
+
<Input value={value.label ?? ""} placeholder="Link text" onChange={(e) => set({ label: e.target.value })} />
|
|
114
|
+
</div>
|
|
115
|
+
<label className="text-muted-foreground group inline-flex cursor-pointer items-center gap-2 text-sm">
|
|
116
|
+
<Checkbox
|
|
117
|
+
className="group-hover:border-primary/60"
|
|
118
|
+
checked={!!value.newTab}
|
|
119
|
+
onCheckedChange={(checked) => set({ newTab: Boolean(checked) })}
|
|
120
|
+
/>
|
|
121
|
+
Open in new tab
|
|
122
|
+
{value.url && <span className="ml-auto text-xs">({value.type})</span>}
|
|
123
|
+
</label>
|
|
124
|
+
</div>
|
|
125
|
+
);
|
|
126
|
+
}
|
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
DndContext,
|
|
6
|
+
KeyboardSensor,
|
|
7
|
+
PointerSensor,
|
|
8
|
+
closestCenter,
|
|
9
|
+
useSensor,
|
|
10
|
+
useSensors,
|
|
11
|
+
type DragEndEvent,
|
|
12
|
+
} from "@dnd-kit/core";
|
|
13
|
+
import { SortableContext, arrayMove, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
14
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
15
|
+
import { Check, ChevronsUpDown, GripVertical, Plus, Trash2 } from "lucide-react";
|
|
5
16
|
|
|
6
17
|
import { Button } from "./ui/button";
|
|
7
18
|
import { Command, CommandEmpty, CommandInput, CommandItem, CommandList } from "./ui/command";
|
|
@@ -15,16 +26,72 @@ type Props = {
|
|
|
15
26
|
name: string;
|
|
16
27
|
value?: string;
|
|
17
28
|
hasMany?: boolean;
|
|
29
|
+
maxItems?: number;
|
|
18
30
|
options: Option[];
|
|
19
31
|
collectionSlug: string;
|
|
20
32
|
collectionLabel: string;
|
|
21
33
|
labelField?: string;
|
|
22
34
|
};
|
|
23
35
|
|
|
36
|
+
/**
|
|
37
|
+
* One selected document as a full-width draggable row — hasMany order is data,
|
|
38
|
+
* so it is editable. Mirrors the repeater's row anatomy (grip, #index, remove)
|
|
39
|
+
* for a consistent, easy-to-grab drag target.
|
|
40
|
+
*/
|
|
41
|
+
function SortableRow({
|
|
42
|
+
id,
|
|
43
|
+
index,
|
|
44
|
+
label,
|
|
45
|
+
onRemove,
|
|
46
|
+
}: {
|
|
47
|
+
id: string;
|
|
48
|
+
index: number;
|
|
49
|
+
label: string;
|
|
50
|
+
onRemove: () => void;
|
|
51
|
+
}) {
|
|
52
|
+
const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
|
|
53
|
+
id,
|
|
54
|
+
});
|
|
55
|
+
return (
|
|
56
|
+
<div
|
|
57
|
+
ref={setNodeRef}
|
|
58
|
+
style={{ transform: CSS.Transform.toString(transform), transition }}
|
|
59
|
+
className={cn(
|
|
60
|
+
"bg-muted-strong/50 has-[[data-drag-handle]:hover]:bg-muted-strong/70 flex items-center gap-2 rounded-lg border px-3 py-2 transition-colors",
|
|
61
|
+
isDragging && "z-10 opacity-90 shadow-lg",
|
|
62
|
+
)}
|
|
63
|
+
>
|
|
64
|
+
<button
|
|
65
|
+
type="button"
|
|
66
|
+
ref={setActivatorNodeRef}
|
|
67
|
+
data-drag-handle
|
|
68
|
+
className="text-muted-foreground/50 hover:text-muted-foreground -ml-1 cursor-grab touch-none rounded p-1 transition-colors active:cursor-grabbing"
|
|
69
|
+
{...attributes}
|
|
70
|
+
{...listeners}
|
|
71
|
+
>
|
|
72
|
+
<GripVertical className="size-4" />
|
|
73
|
+
</button>
|
|
74
|
+
<span className="text-muted-foreground text-xs font-medium">#{index + 1}</span>
|
|
75
|
+
<span className="min-w-0 flex-1 truncate text-sm">{label}</span>
|
|
76
|
+
<Button
|
|
77
|
+
type="button"
|
|
78
|
+
variant="ghost"
|
|
79
|
+
size="icon"
|
|
80
|
+
title="Remove"
|
|
81
|
+
className="text-muted-foreground hover:text-destructive size-7"
|
|
82
|
+
onClick={onRemove}
|
|
83
|
+
>
|
|
84
|
+
<Trash2 className="size-3.5" />
|
|
85
|
+
</Button>
|
|
86
|
+
</div>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
24
90
|
export default function RelationField({
|
|
25
91
|
name,
|
|
26
92
|
value: initialValue,
|
|
27
93
|
hasMany = false,
|
|
94
|
+
maxItems,
|
|
28
95
|
options: initialOptions,
|
|
29
96
|
collectionSlug,
|
|
30
97
|
collectionLabel,
|
|
@@ -57,15 +124,21 @@ export default function RelationField({
|
|
|
57
124
|
|
|
58
125
|
const getLabel = useCallback((id: string) => options.find((o) => o.value === id)?.label ?? id, [options]);
|
|
59
126
|
|
|
127
|
+
const atMax = hasMany && maxItems !== undefined && selected.length >= maxItems;
|
|
128
|
+
|
|
60
129
|
const displayLabel = useMemo(() => {
|
|
61
130
|
if (selected.length === 0) return "";
|
|
62
|
-
if (hasMany) return `${selected.length} selected`;
|
|
131
|
+
if (hasMany) return maxItems ? `${selected.length}/${maxItems} selected` : `${selected.length} selected`;
|
|
63
132
|
return getLabel(selected[0]);
|
|
64
|
-
}, [selected, hasMany, getLabel]);
|
|
133
|
+
}, [selected, hasMany, maxItems, getLabel]);
|
|
65
134
|
|
|
66
135
|
const selectItem = (id: string) => {
|
|
67
136
|
if (hasMany) {
|
|
68
|
-
setSelected((prev) =>
|
|
137
|
+
setSelected((prev) => {
|
|
138
|
+
if (prev.includes(id)) return prev.filter((v) => v !== id);
|
|
139
|
+
if (maxItems !== undefined && prev.length >= maxItems) return prev;
|
|
140
|
+
return [...prev, id];
|
|
141
|
+
});
|
|
69
142
|
} else {
|
|
70
143
|
setSelected((prev) => (prev[0] === id ? [] : [id]));
|
|
71
144
|
setOpen(false);
|
|
@@ -76,6 +149,16 @@ export default function RelationField({
|
|
|
76
149
|
setSelected((prev) => prev.filter((v) => v !== id));
|
|
77
150
|
};
|
|
78
151
|
|
|
152
|
+
const sensors = useSensors(
|
|
153
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
|
|
154
|
+
useSensor(KeyboardSensor),
|
|
155
|
+
);
|
|
156
|
+
const handleDragEnd = (event: DragEndEvent) => {
|
|
157
|
+
const { active, over } = event;
|
|
158
|
+
if (!over || active.id === over.id) return;
|
|
159
|
+
setSelected((prev) => arrayMove(prev, prev.indexOf(String(active.id)), prev.indexOf(String(over.id))));
|
|
160
|
+
};
|
|
161
|
+
|
|
79
162
|
// Listen for postMessage from embedded iframe after successful save
|
|
80
163
|
useEffect(() => {
|
|
81
164
|
if (!sheetOpen) return;
|
|
@@ -112,37 +195,28 @@ export default function RelationField({
|
|
|
112
195
|
<div className="space-y-2">
|
|
113
196
|
<input ref={hiddenRef} type="hidden" name={name} value={hiddenValue} />
|
|
114
197
|
|
|
115
|
-
{/* Selected items (hasMany
|
|
198
|
+
{/* Selected items (hasMany rows) — drag to reorder; the stored order is the render order */}
|
|
116
199
|
{hasMany && selected.length > 0 && (
|
|
117
|
-
<
|
|
118
|
-
{selected
|
|
119
|
-
<
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
title="Remove"
|
|
127
|
-
onClick={() => remove(id)}
|
|
128
|
-
className="text-muted-foreground hover:text-foreground -mr-0.5 rounded p-0.5"
|
|
129
|
-
>
|
|
130
|
-
<X className="size-3" />
|
|
131
|
-
</button>
|
|
132
|
-
</span>
|
|
133
|
-
))}
|
|
134
|
-
</div>
|
|
200
|
+
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
|
|
201
|
+
<SortableContext items={selected} strategy={verticalListSortingStrategy}>
|
|
202
|
+
<div className="grid gap-2">
|
|
203
|
+
{selected.map((id, index) => (
|
|
204
|
+
<SortableRow key={id} id={id} index={index} label={getLabel(id)} onRemove={() => remove(id)} />
|
|
205
|
+
))}
|
|
206
|
+
</div>
|
|
207
|
+
</SortableContext>
|
|
208
|
+
</DndContext>
|
|
135
209
|
)}
|
|
136
210
|
|
|
137
211
|
{/* Combobox */}
|
|
138
212
|
<Popover open={open} onOpenChange={setOpen}>
|
|
139
213
|
<PopoverTrigger asChild>
|
|
140
214
|
<Button
|
|
141
|
-
variant="
|
|
215
|
+
variant="input"
|
|
142
216
|
role="combobox"
|
|
143
217
|
aria-expanded={open}
|
|
144
218
|
size="lg"
|
|
145
|
-
className="
|
|
219
|
+
className="w-full justify-between text-sm font-normal"
|
|
146
220
|
>
|
|
147
221
|
<span className={cn("truncate", !displayLabel && "text-muted-foreground")}>
|
|
148
222
|
{displayLabel || `Search ${collectionLabel.toLowerCase()}...`}
|
|
@@ -156,7 +230,12 @@ export default function RelationField({
|
|
|
156
230
|
<CommandList>
|
|
157
231
|
<CommandEmpty>No results found.</CommandEmpty>
|
|
158
232
|
{options.map((o) => (
|
|
159
|
-
<CommandItem
|
|
233
|
+
<CommandItem
|
|
234
|
+
key={o.value}
|
|
235
|
+
value={o.label}
|
|
236
|
+
onSelect={() => selectItem(o.value)}
|
|
237
|
+
className={cn(atMax && !selected.includes(o.value) && "opacity-40")}
|
|
238
|
+
>
|
|
160
239
|
<Check className={cn("ml-1 size-4", selected.includes(o.value) ? "opacity-100" : "opacity-0")} />
|
|
161
240
|
{o.label}
|
|
162
241
|
</CommandItem>
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
|
|
3
|
+
import { RepeaterField, type RelationOption, type SubFieldMeta } from "./block-fields";
|
|
4
|
+
import type { LinkOptionGroup } from "./InternalLinkPicker";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Standalone form control for top-level repeater fields —
|
|
8
|
+
* `fields.json({ admin: { component: "repeater" }, itemFields })` on a
|
|
9
|
+
* collection. Wraps the block editor's RepeaterField (sortable rows, typed
|
|
10
|
+
* sub-field controls, link picker) and mirrors its value into a hidden input
|
|
11
|
+
* so the plain document form submits it as JSON.
|
|
12
|
+
*/
|
|
13
|
+
export default function RepeaterInput({
|
|
14
|
+
name,
|
|
15
|
+
value,
|
|
16
|
+
itemFields,
|
|
17
|
+
relationOptions,
|
|
18
|
+
linkOptions,
|
|
19
|
+
}: {
|
|
20
|
+
name: string;
|
|
21
|
+
value?: string;
|
|
22
|
+
itemFields?: Record<string, SubFieldMeta>;
|
|
23
|
+
relationOptions?: RelationOption[];
|
|
24
|
+
linkOptions?: LinkOptionGroup[];
|
|
25
|
+
}) {
|
|
26
|
+
const [items, setItems] = useState<unknown>(() => {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(value || "[]");
|
|
29
|
+
} catch {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return (
|
|
34
|
+
<div className="grid gap-2">
|
|
35
|
+
<input type="hidden" name={name} value={JSON.stringify(items ?? [])} />
|
|
36
|
+
<RepeaterField
|
|
37
|
+
blockKey={name}
|
|
38
|
+
itemFields={itemFields}
|
|
39
|
+
relationOptions={relationOptions}
|
|
40
|
+
linkOptions={linkOptions}
|
|
41
|
+
value={items}
|
|
42
|
+
onChange={setItems}
|
|
43
|
+
/>
|
|
44
|
+
</div>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -32,7 +32,7 @@ import ImageBrowseDialog from "./ImageBrowseDialog";
|
|
|
32
32
|
// CMS AST ↔ Tiptap JSON conversion
|
|
33
33
|
// -----------------------------------------------
|
|
34
34
|
|
|
35
|
-
type CmsNode = {
|
|
35
|
+
export type CmsNode = {
|
|
36
36
|
type: string;
|
|
37
37
|
value?: string;
|
|
38
38
|
level?: number;
|
|
@@ -43,12 +43,12 @@ type CmsNode = {
|
|
|
43
43
|
[key: string]: unknown;
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
type CmsDocument = {
|
|
46
|
+
export type CmsDocument = {
|
|
47
47
|
type: "root";
|
|
48
48
|
children: CmsNode[];
|
|
49
49
|
};
|
|
50
50
|
|
|
51
|
-
const cmsNodeToTiptap = (node: CmsNode): any => {
|
|
51
|
+
export const cmsNodeToTiptap = (node: CmsNode): any => {
|
|
52
52
|
if (node.type === "text") {
|
|
53
53
|
const marks: any[] = [];
|
|
54
54
|
if (node.bold) marks.push({ type: "bold" });
|
|
@@ -99,7 +99,7 @@ const cmsToTiptap = (doc: CmsDocument | null | undefined): any => {
|
|
|
99
99
|
return { type: "doc", content: content.length > 0 ? content : [{ type: "paragraph" }] };
|
|
100
100
|
};
|
|
101
101
|
|
|
102
|
-
const tiptapNodeToCms = (node: any): CmsNode | null => {
|
|
102
|
+
export const tiptapNodeToCms = (node: any): CmsNode | null => {
|
|
103
103
|
if (node.type === "text") {
|
|
104
104
|
const result: CmsNode = { type: "text", value: node.text ?? "" };
|
|
105
105
|
if (node.marks) {
|
|
@@ -176,11 +176,12 @@ const ToolbarButton = ({
|
|
|
176
176
|
}) => (
|
|
177
177
|
<button
|
|
178
178
|
type="button"
|
|
179
|
+
data-slot="button"
|
|
179
180
|
onClick={onClick}
|
|
180
181
|
disabled={disabled}
|
|
181
182
|
title={title}
|
|
182
183
|
className={cn(
|
|
183
|
-
"
|
|
184
|
+
"disabled:hover:text-muted-foreground inline-flex size-8 items-center justify-center rounded-md transition-colors outline-none disabled:opacity-50 disabled:hover:bg-transparent",
|
|
184
185
|
active ? "bg-accent text-accent-foreground" : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
|
|
185
186
|
)}
|
|
186
187
|
>
|
|
@@ -192,7 +193,37 @@ const ToolbarButton = ({
|
|
|
192
193
|
// Link dialog
|
|
193
194
|
// -----------------------------------------------
|
|
194
195
|
|
|
195
|
-
|
|
196
|
+
export type LinkGroup = { label: string; items: Array<{ label: string; href: string }> };
|
|
197
|
+
|
|
198
|
+
/** Fetch published pages + posts for the internal-link picker. Shared by editors. */
|
|
199
|
+
export async function fetchLinkGroups(): Promise<LinkGroup[]> {
|
|
200
|
+
const [pagesRes, postsRes] = await Promise.all([
|
|
201
|
+
fetch("/api/cms/pages?status=published&limit=200").then((r) => (r.ok ? r.json() : { docs: [] })),
|
|
202
|
+
fetch("/api/cms/posts?status=published&limit=200").then((r) => (r.ok ? r.json() : { docs: [] })),
|
|
203
|
+
]);
|
|
204
|
+
const groups: LinkGroup[] = [];
|
|
205
|
+
if (pagesRes.docs?.length) {
|
|
206
|
+
groups.push({
|
|
207
|
+
label: "Pages",
|
|
208
|
+
items: pagesRes.docs.map((p: Record<string, unknown>) => ({
|
|
209
|
+
label: String(p.title ?? p.slug),
|
|
210
|
+
href: `/${p.slug}`,
|
|
211
|
+
})),
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
if (postsRes.docs?.length) {
|
|
215
|
+
groups.push({
|
|
216
|
+
label: "Posts",
|
|
217
|
+
items: postsRes.docs.map((p: Record<string, unknown>) => ({
|
|
218
|
+
label: String(p.title ?? p.slug),
|
|
219
|
+
href: `/blog/${p.slug}`,
|
|
220
|
+
})),
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return groups;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function LinkDialog({
|
|
196
227
|
open,
|
|
197
228
|
onOpenChange,
|
|
198
229
|
linkType,
|
|
@@ -287,7 +318,7 @@ function LinkDialog({
|
|
|
287
318
|
role="combobox"
|
|
288
319
|
aria-expanded={comboOpen}
|
|
289
320
|
size="lg"
|
|
290
|
-
className="border-input bg-muted/30 hover:bg-muted dark:bg-input/30 dark:hover:bg-input/50 w-full justify-between text-
|
|
321
|
+
className="border-input bg-muted/30 hover:bg-muted dark:bg-input/30 dark:hover:bg-input/50 w-full justify-between text-sm font-normal"
|
|
291
322
|
>
|
|
292
323
|
<span className={cn("truncate", !selectedLabel && "text-muted-foreground")}>
|
|
293
324
|
{selectedLabel || "Search documents..."}
|
|
@@ -402,7 +433,8 @@ export default function RichTextEditor({ name, initialValue, rows = 10, onChange
|
|
|
402
433
|
const editor = useEditor({
|
|
403
434
|
immediatelyRender: false,
|
|
404
435
|
extensions: [
|
|
405
|
-
StarterKit
|
|
436
|
+
// StarterKit bundles its own Link; disabled so the configured one below is the only registration.
|
|
437
|
+
StarterKit.configure({ link: false }),
|
|
406
438
|
Image,
|
|
407
439
|
Markdown,
|
|
408
440
|
Link.configure({
|
|
@@ -473,7 +505,10 @@ export default function RichTextEditor({ name, initialValue, rows = 10, onChange
|
|
|
473
505
|
const minHeight = `${rows * 1.5}rem`;
|
|
474
506
|
|
|
475
507
|
return (
|
|
476
|
-
<div
|
|
508
|
+
<div
|
|
509
|
+
data-slot="editor"
|
|
510
|
+
className="border-input hover:border-foreground/20 overflow-hidden rounded-lg border transition-colors"
|
|
511
|
+
>
|
|
477
512
|
<input ref={hiddenRef} type="hidden" name={name} value={cmsJson} />
|
|
478
513
|
|
|
479
514
|
{/* Toolbar */}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
|
|
5
|
+
import { SubField, blankBlockFields, humanize, type BlockTypesMeta, type RelationOption } from "./block-fields";
|
|
6
|
+
import SelectField from "./SelectField";
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
name: string;
|
|
10
|
+
value?: string;
|
|
11
|
+
types: BlockTypesMeta;
|
|
12
|
+
blockRelationOptions?: Record<string, RelationOption[]>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type SharedBlock = {
|
|
16
|
+
type: string;
|
|
17
|
+
[field: string]: unknown;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
function parseInitialBlock(value: string | undefined, types: BlockTypesMeta): SharedBlock {
|
|
21
|
+
// Default to no selection — the editor must actively choose a block type.
|
|
22
|
+
if (!value) return { type: "" };
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const parsed = JSON.parse(value) as Record<string, unknown>;
|
|
26
|
+
const type = String(parsed.type ?? "");
|
|
27
|
+
if (!type) return { type: "" };
|
|
28
|
+
return {
|
|
29
|
+
type,
|
|
30
|
+
...blankBlockFields(types[type] ?? {}),
|
|
31
|
+
...parsed,
|
|
32
|
+
};
|
|
33
|
+
} catch {
|
|
34
|
+
return { type: "" };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default function SharedSectionBlockField({ name, value, types, blockRelationOptions = {} }: Props) {
|
|
39
|
+
const [block, setBlock] = useState<SharedBlock>(() => parseInitialBlock(value, types));
|
|
40
|
+
const typeNames = Object.keys(types);
|
|
41
|
+
const selectedType = block.type;
|
|
42
|
+
const fieldsMeta = types[selectedType] ?? {};
|
|
43
|
+
const serialized = useMemo(() => JSON.stringify(block), [block]);
|
|
44
|
+
|
|
45
|
+
const changeType = (typeName: string) => {
|
|
46
|
+
setBlock({ type: typeName, ...blankBlockFields(types[typeName] ?? {}) });
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const updateField = (fieldName: string, fieldValue: unknown) => {
|
|
50
|
+
setBlock((prev) => ({ ...prev, [fieldName]: fieldValue }));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const relationOptionsFor = (fieldName: string) => blockRelationOptions[`shared:${selectedType}:${fieldName}`] ?? [];
|
|
54
|
+
|
|
55
|
+
if (typeNames.length === 0) {
|
|
56
|
+
return (
|
|
57
|
+
<div className="bg-muted/20 text-muted-foreground rounded-lg border border-dashed px-4 py-3 text-sm">
|
|
58
|
+
Add at least one block type to a collection before creating shared sections.
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div className="space-y-4">
|
|
65
|
+
<input type="hidden" name="blockType" value={selectedType} />
|
|
66
|
+
<input type="hidden" name={name} value={serialized} />
|
|
67
|
+
|
|
68
|
+
<SelectField
|
|
69
|
+
name={`${name}_type`}
|
|
70
|
+
value={selectedType}
|
|
71
|
+
placeholder="Select a block type"
|
|
72
|
+
items={typeNames.map((typeName) => ({ value: typeName, label: humanize(typeName) }))}
|
|
73
|
+
onChange={changeType}
|
|
74
|
+
/>
|
|
75
|
+
|
|
76
|
+
{selectedType && Object.keys(fieldsMeta).length > 0 && (
|
|
77
|
+
<div className="space-y-4 rounded-lg border px-4 py-4">
|
|
78
|
+
{Object.entries(fieldsMeta).map(([fieldName, meta]) => (
|
|
79
|
+
<SubField
|
|
80
|
+
key={fieldName}
|
|
81
|
+
blockKey={`shared_${selectedType}`}
|
|
82
|
+
fieldName={fieldName}
|
|
83
|
+
meta={meta}
|
|
84
|
+
value={block[fieldName]}
|
|
85
|
+
onChange={(v) => updateField(fieldName, v)}
|
|
86
|
+
relationOptions={meta.type === "relation" ? relationOptionsFor(fieldName) : []}
|
|
87
|
+
/>
|
|
88
|
+
))}
|
|
89
|
+
</div>
|
|
90
|
+
)}
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -62,7 +62,7 @@ export default function SidebarUserMenu({
|
|
|
62
62
|
<ChevronsUpDown className="text-muted-foreground size-4 shrink-0" />
|
|
63
63
|
</DropdownMenuTrigger>
|
|
64
64
|
|
|
65
|
-
<DropdownMenuContent side="
|
|
65
|
+
<DropdownMenuContent side="top" align="start" sideOffset={6} className="w-(--radix-dropdown-menu-trigger-width)">
|
|
66
66
|
<DropdownMenuItem onClick={() => changeTheme("light")}>
|
|
67
67
|
<Sun className="text-muted-foreground size-3.5" />
|
|
68
68
|
Light
|
|
@@ -16,7 +16,7 @@ const isError = status === "error";
|
|
|
16
16
|
---
|
|
17
17
|
|
|
18
18
|
{/* Centering wrapper — keeps left-1/2 -translate-x-1/2 stable while inner div animates */}
|
|
19
|
-
<div class="fixed top-4 left-1/2 z-
|
|
19
|
+
<div class="fixed top-4 left-1/2 z-[60] w-full max-w-sm -translate-x-1/2">
|
|
20
20
|
<div
|
|
21
21
|
id="admin-toast"
|
|
22
22
|
role={isError ? "alert" : "status"}
|