@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
|
@@ -12,7 +12,7 @@ export default function CheckboxField({ name, checked: initial = false, disabled
|
|
|
12
12
|
const hiddenRef = useRef<HTMLInputElement>(null);
|
|
13
13
|
|
|
14
14
|
return (
|
|
15
|
-
<label className="group inline-flex cursor-pointer items-center gap-
|
|
15
|
+
<label className="group inline-flex cursor-pointer items-center gap-3 text-sm">
|
|
16
16
|
<input type="hidden" name={name} value={checked ? "true" : "false"} ref={hiddenRef} />
|
|
17
17
|
<Checkbox
|
|
18
18
|
className="group-hover:border-primary/60 disabled:group-hover:border-input"
|
|
@@ -25,7 +25,7 @@ export default function CheckboxField({ name, checked: initial = false, disabled
|
|
|
25
25
|
}}
|
|
26
26
|
disabled={disabled}
|
|
27
27
|
/>
|
|
28
|
-
<span className="text-foreground select-none">{checked ? "
|
|
28
|
+
<span className="text-muted-foreground select-none">{checked ? "true" : "false"}</span>
|
|
29
29
|
</label>
|
|
30
30
|
);
|
|
31
31
|
}
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useRef, useState } from "react";
|
|
4
|
+
import { Check, ChevronDown, Clock, GitCommitVertical, MessageSquare, MessageSquarePlus } from "lucide-react";
|
|
5
|
+
|
|
6
|
+
import { cn } from "../lib/utils";
|
|
7
|
+
import { buttonVariants } from "./ui/button";
|
|
8
|
+
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "./ui/dropdown-menu";
|
|
9
|
+
import { Sheet, SheetContent, SheetTitle } from "./ui/sheet";
|
|
10
|
+
import { REVIEW_STATE_META, type CollabActivity, type CollabComment, type CollabUser } from "../lib/collaboration";
|
|
11
|
+
import type { ReviewState } from "../../core";
|
|
12
|
+
|
|
13
|
+
type Props = {
|
|
14
|
+
collection: string;
|
|
15
|
+
documentId: string;
|
|
16
|
+
reviewState: ReviewState;
|
|
17
|
+
editor: CollabUser | null;
|
|
18
|
+
assignableUsers: CollabUser[];
|
|
19
|
+
comments: CollabComment[];
|
|
20
|
+
activity: CollabActivity[];
|
|
21
|
+
currentUser: CollabUser | null;
|
|
22
|
+
// Whether the current user can approve / request changes (role-based).
|
|
23
|
+
canApprove: boolean;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
function Avatar({ initials, color, size = "size-6" }: { initials: string; color: string; size?: string }) {
|
|
27
|
+
return (
|
|
28
|
+
<span
|
|
29
|
+
className={cn(
|
|
30
|
+
color,
|
|
31
|
+
size,
|
|
32
|
+
"inline-flex shrink-0 items-center justify-center rounded-full text-[11px] font-medium text-white!",
|
|
33
|
+
)}
|
|
34
|
+
>
|
|
35
|
+
{initials}
|
|
36
|
+
</span>
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export default function CollaborationReviewBar(props: Props) {
|
|
41
|
+
const { collection, documentId, assignableUsers, activity, currentUser, canApprove } = props;
|
|
42
|
+
|
|
43
|
+
const [reviewState, setReviewState] = useState<ReviewState>(props.reviewState);
|
|
44
|
+
const [editor, setEditor] = useState<CollabUser | null>(props.editor);
|
|
45
|
+
const [comments, setComments] = useState<CollabComment[]>(props.comments);
|
|
46
|
+
const [open, setOpen] = useState(false);
|
|
47
|
+
const [tab, setTab] = useState<"comments" | "activity">("comments");
|
|
48
|
+
const [draft, setDraft] = useState("");
|
|
49
|
+
const [busy, setBusy] = useState(false);
|
|
50
|
+
|
|
51
|
+
const post = async (payload: Record<string, unknown>) => {
|
|
52
|
+
setBusy(true);
|
|
53
|
+
try {
|
|
54
|
+
const res = await fetch("/api/cms/collaboration", {
|
|
55
|
+
method: "POST",
|
|
56
|
+
credentials: "same-origin",
|
|
57
|
+
headers: { "Content-Type": "application/json" },
|
|
58
|
+
body: JSON.stringify({ collection, id: documentId, ...payload }),
|
|
59
|
+
});
|
|
60
|
+
if (!res.ok) {
|
|
61
|
+
const data = await res.json().catch(() => ({}));
|
|
62
|
+
throw new Error(data.error ?? "Request failed.");
|
|
63
|
+
}
|
|
64
|
+
return await res.json();
|
|
65
|
+
} finally {
|
|
66
|
+
setBusy(false);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const changeState = async (next: ReviewState) => {
|
|
71
|
+
const prev = reviewState;
|
|
72
|
+
setReviewState(next);
|
|
73
|
+
try {
|
|
74
|
+
await post({ action: "setReviewState", reviewState: next });
|
|
75
|
+
} catch (err) {
|
|
76
|
+
setReviewState(prev);
|
|
77
|
+
window.alert(err instanceof Error ? err.message : "Could not update review state.");
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const changeEditor = async (userId: string) => {
|
|
82
|
+
const prev = editor;
|
|
83
|
+
setEditor(assignableUsers.find((u) => u.id === userId) ?? null);
|
|
84
|
+
try {
|
|
85
|
+
await post({ action: "setEditor", editor: userId || null });
|
|
86
|
+
} catch (err) {
|
|
87
|
+
setEditor(prev);
|
|
88
|
+
window.alert(err instanceof Error ? err.message : "Could not update assignee.");
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const commentInputRef = useRef<HTMLInputElement>(null);
|
|
93
|
+
const openComments = (focus = false) => {
|
|
94
|
+
setTab("comments");
|
|
95
|
+
setOpen(true);
|
|
96
|
+
if (focus) setTimeout(() => commentInputRef.current?.focus(), 60);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const submitComment = async () => {
|
|
100
|
+
const body = draft.trim();
|
|
101
|
+
if (!body || busy) return;
|
|
102
|
+
try {
|
|
103
|
+
const { comment } = await post({ action: "addComment", body });
|
|
104
|
+
setComments((prev) => [
|
|
105
|
+
...prev,
|
|
106
|
+
{
|
|
107
|
+
id: String(comment._id),
|
|
108
|
+
author: currentUser ?? { id: "", name: "You", initials: "?", color: "bg-muted-foreground" },
|
|
109
|
+
time: "just now",
|
|
110
|
+
field: null,
|
|
111
|
+
body,
|
|
112
|
+
resolved: false,
|
|
113
|
+
},
|
|
114
|
+
]);
|
|
115
|
+
setDraft("");
|
|
116
|
+
} catch (err) {
|
|
117
|
+
window.alert(err instanceof Error ? err.message : "Could not add comment.");
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const toggleResolve = async (comment: CollabComment) => {
|
|
122
|
+
const next = !comment.resolved;
|
|
123
|
+
setComments((prev) => prev.map((c) => (c.id === comment.id ? { ...c, resolved: next } : c)));
|
|
124
|
+
try {
|
|
125
|
+
await post({ action: "resolveComment", commentId: comment.id, resolved: next });
|
|
126
|
+
} catch (err) {
|
|
127
|
+
setComments((prev) => prev.map((c) => (c.id === comment.id ? { ...c, resolved: !next } : c)));
|
|
128
|
+
window.alert(err instanceof Error ? err.message : "Could not update comment.");
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
const meta = REVIEW_STATE_META[reviewState];
|
|
133
|
+
const canEdit = reviewState === "in_progress" || reviewState === "changes_requested";
|
|
134
|
+
|
|
135
|
+
return (
|
|
136
|
+
<>
|
|
137
|
+
<div className="bg-muted/30 flex w-full flex-wrap items-center justify-between gap-x-4 gap-y-2 rounded-lg border px-4 py-2.5">
|
|
138
|
+
{/* Left — review status + the action for this stage */}
|
|
139
|
+
<div className="flex flex-wrap items-center gap-2.5">
|
|
140
|
+
{reviewState === "changes_requested" ? (
|
|
141
|
+
<button
|
|
142
|
+
type="button"
|
|
143
|
+
onClick={() => openComments()}
|
|
144
|
+
title="View the requested changes"
|
|
145
|
+
className={cn(
|
|
146
|
+
"inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs font-medium transition-opacity hover:opacity-80",
|
|
147
|
+
meta.badge,
|
|
148
|
+
)}
|
|
149
|
+
>
|
|
150
|
+
<span className={cn("size-1.5 rounded-full", meta.dot)} />
|
|
151
|
+
{meta.label}
|
|
152
|
+
<MessageSquare className="size-3 opacity-70" />
|
|
153
|
+
</button>
|
|
154
|
+
) : (
|
|
155
|
+
<span
|
|
156
|
+
className={cn(
|
|
157
|
+
"inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs font-medium",
|
|
158
|
+
meta.badge,
|
|
159
|
+
)}
|
|
160
|
+
>
|
|
161
|
+
<span className={cn("size-1.5 rounded-full", meta.dot)} />
|
|
162
|
+
{meta.label}
|
|
163
|
+
</span>
|
|
164
|
+
)}
|
|
165
|
+
|
|
166
|
+
{currentUser && <div className="bg-border mx-0.5 h-5 w-px" />}
|
|
167
|
+
|
|
168
|
+
{/* Editor submits for review — saves the draft AND flips the state
|
|
169
|
+
(a submit on the document form, so unsaved edits are persisted). */}
|
|
170
|
+
{currentUser && canEdit && (
|
|
171
|
+
<button
|
|
172
|
+
type="submit"
|
|
173
|
+
form="document-form"
|
|
174
|
+
name="_intent"
|
|
175
|
+
value="submit-review"
|
|
176
|
+
className={buttonVariants({ variant: "outline", size: "sm" })}
|
|
177
|
+
>
|
|
178
|
+
Submit for review
|
|
179
|
+
</button>
|
|
180
|
+
)}
|
|
181
|
+
|
|
182
|
+
{/* Ready for review → approvers decide, others can withdraw */}
|
|
183
|
+
{reviewState === "ready_for_review" &&
|
|
184
|
+
(canApprove ? (
|
|
185
|
+
<>
|
|
186
|
+
<button
|
|
187
|
+
type="button"
|
|
188
|
+
disabled={busy}
|
|
189
|
+
onClick={() => {
|
|
190
|
+
changeState("changes_requested");
|
|
191
|
+
openComments(true);
|
|
192
|
+
}}
|
|
193
|
+
className={cn(buttonVariants({ variant: "ghost", size: "sm" }), "text-muted-foreground")}
|
|
194
|
+
>
|
|
195
|
+
Request changes
|
|
196
|
+
</button>
|
|
197
|
+
<button
|
|
198
|
+
type="button"
|
|
199
|
+
disabled={busy}
|
|
200
|
+
onClick={() => changeState("approved")}
|
|
201
|
+
className={buttonVariants({ variant: "outline", size: "sm" })}
|
|
202
|
+
>
|
|
203
|
+
<Check className="size-4" />
|
|
204
|
+
Approve
|
|
205
|
+
</button>
|
|
206
|
+
</>
|
|
207
|
+
) : currentUser ? (
|
|
208
|
+
<button
|
|
209
|
+
type="button"
|
|
210
|
+
disabled={busy}
|
|
211
|
+
onClick={() => changeState("in_progress")}
|
|
212
|
+
className={cn(buttonVariants({ variant: "ghost", size: "sm" }), "text-muted-foreground")}
|
|
213
|
+
>
|
|
214
|
+
Withdraw
|
|
215
|
+
</button>
|
|
216
|
+
) : null)}
|
|
217
|
+
|
|
218
|
+
{/* Approved → reopen for more work */}
|
|
219
|
+
{currentUser && reviewState === "approved" && (
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
disabled={busy}
|
|
223
|
+
onClick={() => changeState("in_progress")}
|
|
224
|
+
className={cn(buttonVariants({ variant: "ghost", size: "sm" }), "text-muted-foreground")}
|
|
225
|
+
>
|
|
226
|
+
Reopen
|
|
227
|
+
</button>
|
|
228
|
+
)}
|
|
229
|
+
</div>
|
|
230
|
+
|
|
231
|
+
{/* Right — assignee + comments */}
|
|
232
|
+
<div className="flex flex-wrap items-center gap-2">
|
|
233
|
+
<DropdownMenu>
|
|
234
|
+
<DropdownMenuTrigger
|
|
235
|
+
disabled={busy || !currentUser}
|
|
236
|
+
className="hover:bg-foreground/5 flex items-center gap-1.5 rounded-md px-1.5 py-1 outline-none disabled:opacity-60"
|
|
237
|
+
>
|
|
238
|
+
<span className="text-muted-foreground text-xs">Assignee</span>
|
|
239
|
+
{editor && <Avatar initials={editor.initials} color={editor.color} />}
|
|
240
|
+
<span className={cn("text-sm", editor ? "font-medium" : "text-muted-foreground")}>
|
|
241
|
+
{editor?.name ?? "none"}
|
|
242
|
+
</span>
|
|
243
|
+
<ChevronDown className="text-muted-foreground size-3.5" />
|
|
244
|
+
</DropdownMenuTrigger>
|
|
245
|
+
<DropdownMenuContent align="end" className="min-w-48">
|
|
246
|
+
{currentUser && editor?.id !== currentUser.id && (
|
|
247
|
+
<DropdownMenuItem onClick={() => changeEditor(currentUser.id)}>
|
|
248
|
+
<Avatar initials={currentUser.initials} color={currentUser.color} size="size-5" />
|
|
249
|
+
<span className="flex-1">Assign to me</span>
|
|
250
|
+
</DropdownMenuItem>
|
|
251
|
+
)}
|
|
252
|
+
<DropdownMenuItem onClick={() => changeEditor("")}>
|
|
253
|
+
<span className="text-muted-foreground flex-1">Unassigned</span>
|
|
254
|
+
{!editor && <Check className="text-muted-foreground size-3.5" />}
|
|
255
|
+
</DropdownMenuItem>
|
|
256
|
+
{assignableUsers.map((u) => (
|
|
257
|
+
<DropdownMenuItem key={u.id} onClick={() => changeEditor(u.id)}>
|
|
258
|
+
<Avatar initials={u.initials} color={u.color} size="size-5" />
|
|
259
|
+
<span className="flex-1">{u.name}</span>
|
|
260
|
+
{editor?.id === u.id && <Check className="text-muted-foreground size-3.5" />}
|
|
261
|
+
</DropdownMenuItem>
|
|
262
|
+
))}
|
|
263
|
+
</DropdownMenuContent>
|
|
264
|
+
</DropdownMenu>
|
|
265
|
+
|
|
266
|
+
<button
|
|
267
|
+
type="button"
|
|
268
|
+
onClick={() => openComments()}
|
|
269
|
+
className={cn(buttonVariants({ variant: "ghost", size: "sm" }), "text-muted-foreground gap-1.5")}
|
|
270
|
+
>
|
|
271
|
+
<MessageSquare className="size-4" />
|
|
272
|
+
{comments.length}
|
|
273
|
+
</button>
|
|
274
|
+
</div>
|
|
275
|
+
</div>
|
|
276
|
+
|
|
277
|
+
{/* Comments / Activity drawer */}
|
|
278
|
+
<Sheet open={open} onOpenChange={setOpen}>
|
|
279
|
+
<SheetContent side="right" className="w-full gap-0 p-0 sm:max-w-md">
|
|
280
|
+
<SheetTitle className="sr-only">Comments and activity</SheetTitle>
|
|
281
|
+
|
|
282
|
+
<div className="flex border-b pr-12">
|
|
283
|
+
{(["comments", "activity"] as const).map((id) => {
|
|
284
|
+
const Icon = id === "comments" ? MessageSquare : Clock;
|
|
285
|
+
const isActive = tab === id;
|
|
286
|
+
return (
|
|
287
|
+
<button
|
|
288
|
+
key={id}
|
|
289
|
+
type="button"
|
|
290
|
+
onClick={() => setTab(id)}
|
|
291
|
+
className={cn(
|
|
292
|
+
"-mb-px flex items-center gap-1.5 border-b-2 px-4 py-3 text-xs font-medium capitalize transition-colors",
|
|
293
|
+
isActive
|
|
294
|
+
? "border-foreground text-foreground"
|
|
295
|
+
: "text-muted-foreground hover:text-foreground border-transparent",
|
|
296
|
+
)}
|
|
297
|
+
>
|
|
298
|
+
<Icon className="size-3.5" />
|
|
299
|
+
{id}
|
|
300
|
+
{id === "comments" && comments.length > 0 ? (
|
|
301
|
+
<span className="bg-muted text-muted-foreground rounded-full px-1.5 text-[10px]">
|
|
302
|
+
{comments.length}
|
|
303
|
+
</span>
|
|
304
|
+
) : null}
|
|
305
|
+
</button>
|
|
306
|
+
);
|
|
307
|
+
})}
|
|
308
|
+
</div>
|
|
309
|
+
|
|
310
|
+
{tab === "comments" && (
|
|
311
|
+
<div className="flex-1 overflow-y-auto">
|
|
312
|
+
<ul className="divide-y">
|
|
313
|
+
{comments.length === 0 && (
|
|
314
|
+
<li className="text-muted-foreground px-4 py-8 text-center text-sm">No comments yet.</li>
|
|
315
|
+
)}
|
|
316
|
+
{comments.map((c) => (
|
|
317
|
+
<li key={c.id} className="flex gap-3 px-4 py-3">
|
|
318
|
+
<Avatar initials={c.author.initials} color={c.author.color} size="size-7" />
|
|
319
|
+
<div className="min-w-0 flex-1">
|
|
320
|
+
<div className="flex flex-wrap items-center gap-x-2 gap-y-1">
|
|
321
|
+
<span className="text-sm font-medium">{c.author.name}</span>
|
|
322
|
+
<span className="text-muted-foreground text-xs">{c.time}</span>
|
|
323
|
+
{c.field && (
|
|
324
|
+
<span className="bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px]">
|
|
325
|
+
on {c.field}
|
|
326
|
+
</span>
|
|
327
|
+
)}
|
|
328
|
+
<button
|
|
329
|
+
type="button"
|
|
330
|
+
disabled={busy}
|
|
331
|
+
onClick={() => toggleResolve(c)}
|
|
332
|
+
className="text-muted-foreground hover:text-foreground ml-auto text-[10px] font-medium"
|
|
333
|
+
>
|
|
334
|
+
{c.resolved ? "Reopen" : "Resolve"}
|
|
335
|
+
</button>
|
|
336
|
+
</div>
|
|
337
|
+
<p className={cn("mt-1 text-sm", c.resolved && "text-muted-foreground line-through")}>{c.body}</p>
|
|
338
|
+
</div>
|
|
339
|
+
</li>
|
|
340
|
+
))}
|
|
341
|
+
</ul>
|
|
342
|
+
<div className="bg-background sticky bottom-0 flex items-center gap-2 border-t px-4 py-3">
|
|
343
|
+
<MessageSquarePlus className="text-muted-foreground size-4 shrink-0" />
|
|
344
|
+
<input
|
|
345
|
+
ref={commentInputRef}
|
|
346
|
+
type="text"
|
|
347
|
+
value={draft}
|
|
348
|
+
disabled={busy || !currentUser}
|
|
349
|
+
onChange={(e) => setDraft(e.target.value)}
|
|
350
|
+
onKeyDown={(e) => {
|
|
351
|
+
if (e.key === "Enter") submitComment();
|
|
352
|
+
}}
|
|
353
|
+
placeholder={currentUser ? "Write a comment…" : "Sign in to comment"}
|
|
354
|
+
className="border-input bg-background w-full rounded-md border px-3 py-1.5 text-sm outline-none"
|
|
355
|
+
/>
|
|
356
|
+
</div>
|
|
357
|
+
</div>
|
|
358
|
+
)}
|
|
359
|
+
|
|
360
|
+
{tab === "activity" && (
|
|
361
|
+
<ul className="flex-1 space-y-4 overflow-y-auto px-4 py-4">
|
|
362
|
+
{activity.length === 0 && <li className="text-muted-foreground text-center text-sm">No activity yet.</li>}
|
|
363
|
+
{activity.map((a, i) => (
|
|
364
|
+
<li key={i} className="flex gap-3">
|
|
365
|
+
<div className="flex flex-col items-center">
|
|
366
|
+
<Avatar initials={a.actor.initials} color={a.actor.color} />
|
|
367
|
+
{i < activity.length - 1 && <GitCommitVertical className="text-border mt-1 size-4" />}
|
|
368
|
+
</div>
|
|
369
|
+
<div className="min-w-0 flex-1 pt-0.5">
|
|
370
|
+
<p className="text-sm">
|
|
371
|
+
<span className="font-medium">{a.actor.name}</span>{" "}
|
|
372
|
+
<span className="text-muted-foreground">{a.text}</span>
|
|
373
|
+
</p>
|
|
374
|
+
<span className="text-muted-foreground text-xs">{a.time}</span>
|
|
375
|
+
</div>
|
|
376
|
+
</li>
|
|
377
|
+
))}
|
|
378
|
+
</ul>
|
|
379
|
+
)}
|
|
380
|
+
</SheetContent>
|
|
381
|
+
</Sheet>
|
|
382
|
+
</>
|
|
383
|
+
);
|
|
384
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
|
+
import { X } from "lucide-react";
|
|
5
|
+
import { cn } from "../lib/utils";
|
|
6
|
+
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger } from "./ui/select";
|
|
7
|
+
|
|
8
|
+
type ColorOption = { label: string; value: string };
|
|
9
|
+
|
|
10
|
+
type Props = {
|
|
11
|
+
name?: string;
|
|
12
|
+
value?: string;
|
|
13
|
+
placeholder?: string;
|
|
14
|
+
/** Predefined palette (from `admin.colors` in cms.config.ts). */
|
|
15
|
+
colors?: ColorOption[];
|
|
16
|
+
onChange?: (value: string) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function Swatch({ color }: { color: string }) {
|
|
20
|
+
return (
|
|
21
|
+
<span className="size-4 shrink-0 rounded border border-black/10" style={{ backgroundColor: color }} aria-hidden />
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export default function ColorField({ name, value: initial, placeholder, colors = [], onChange }: Props) {
|
|
26
|
+
const [value, setValue] = useState(initial ?? "");
|
|
27
|
+
const hiddenRef = useRef<HTMLInputElement>(null);
|
|
28
|
+
const isInitial = useRef(true);
|
|
29
|
+
|
|
30
|
+
// Mirror SelectField: notify the surrounding form when used as a top-level field.
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
if (isInitial.current) {
|
|
33
|
+
isInitial.current = false;
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
hiddenRef.current?.dispatchEvent(new Event("change", { bubbles: true }));
|
|
37
|
+
}, [value]);
|
|
38
|
+
|
|
39
|
+
const set = (v: string) => {
|
|
40
|
+
setValue(v);
|
|
41
|
+
onChange?.(v);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const selected = colors.find((c) => c.value.toLowerCase() === value.trim().toLowerCase());
|
|
45
|
+
|
|
46
|
+
return (
|
|
47
|
+
<div className="relative">
|
|
48
|
+
{name && <input type="hidden" name={name} value={value} ref={hiddenRef} />}
|
|
49
|
+
|
|
50
|
+
<Select items={colors} value={value} onValueChange={(v) => set((v as string) ?? "")}>
|
|
51
|
+
<SelectTrigger className={cn("w-full", value && "pr-14")}>
|
|
52
|
+
{selected ? (
|
|
53
|
+
<span className="flex flex-1 items-center gap-2">
|
|
54
|
+
<Swatch color={selected.value} />
|
|
55
|
+
<span>{selected.label}</span>
|
|
56
|
+
<span className="text-muted-foreground ml-auto font-mono text-xs">{selected.value}</span>
|
|
57
|
+
</span>
|
|
58
|
+
) : (
|
|
59
|
+
<span className="text-muted-foreground flex-1 text-left">{placeholder || "Select a colour…"}</span>
|
|
60
|
+
)}
|
|
61
|
+
</SelectTrigger>
|
|
62
|
+
<SelectContent>
|
|
63
|
+
<SelectGroup>
|
|
64
|
+
{colors.map((c) => (
|
|
65
|
+
<SelectItem key={c.value} value={c.value}>
|
|
66
|
+
<Swatch color={c.value} />
|
|
67
|
+
<span className="flex-1">{c.label}</span>
|
|
68
|
+
<span className="text-muted-foreground font-mono text-xs">{c.value}</span>
|
|
69
|
+
</SelectItem>
|
|
70
|
+
))}
|
|
71
|
+
</SelectGroup>
|
|
72
|
+
</SelectContent>
|
|
73
|
+
</Select>
|
|
74
|
+
|
|
75
|
+
{value && (
|
|
76
|
+
<button
|
|
77
|
+
type="button"
|
|
78
|
+
title="Clear"
|
|
79
|
+
onClick={() => set("")}
|
|
80
|
+
className="text-muted-foreground hover:text-foreground absolute top-1/2 right-8 -translate-y-1/2"
|
|
81
|
+
>
|
|
82
|
+
<X className="size-4" />
|
|
83
|
+
</button>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
|
|
5
|
+
import { Command, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList } from "./ui/command";
|
|
6
|
+
import { Dialog, DialogContent, DialogDescription, DialogTitle } from "./ui/dialog";
|
|
7
|
+
|
|
8
|
+
type Result = {
|
|
9
|
+
collection: string;
|
|
10
|
+
collectionLabel: string;
|
|
11
|
+
docId: string;
|
|
12
|
+
title: string;
|
|
13
|
+
editUrl: string;
|
|
14
|
+
status: string | null;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const MIN_QUERY_LENGTH = 2;
|
|
18
|
+
const DEBOUNCE_MS = 150;
|
|
19
|
+
|
|
20
|
+
export default function CommandPalette() {
|
|
21
|
+
const [open, setOpen] = React.useState(false);
|
|
22
|
+
const [query, setQuery] = React.useState("");
|
|
23
|
+
const [results, setResults] = React.useState<Result[]>([]);
|
|
24
|
+
const [loading, setLoading] = React.useState(false);
|
|
25
|
+
// Controlled cmdk selection so we can force "highlight first item" every time the result
|
|
26
|
+
// set changes — cmdk would otherwise hold onto the previous highlight even when that item
|
|
27
|
+
// is no longer in the list (especially with shouldFilter={false}).
|
|
28
|
+
const [selected, setSelected] = React.useState("");
|
|
29
|
+
|
|
30
|
+
const itemValue = (r: Result) => `${r.collection}:${r.docId}`;
|
|
31
|
+
|
|
32
|
+
React.useEffect(() => {
|
|
33
|
+
const keyHandler = (e: KeyboardEvent) => {
|
|
34
|
+
if ((e.metaKey || e.ctrlKey) && e.key.toLowerCase() === "k") {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
setOpen((v) => !v);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const openHandler = () => setOpen(true);
|
|
40
|
+
document.addEventListener("keydown", keyHandler);
|
|
41
|
+
window.addEventListener("cms:open-search", openHandler);
|
|
42
|
+
return () => {
|
|
43
|
+
document.removeEventListener("keydown", keyHandler);
|
|
44
|
+
window.removeEventListener("cms:open-search", openHandler);
|
|
45
|
+
};
|
|
46
|
+
}, []);
|
|
47
|
+
|
|
48
|
+
const handleOpenChange = React.useCallback((next: boolean) => {
|
|
49
|
+
setOpen(next);
|
|
50
|
+
if (!next) {
|
|
51
|
+
setQuery("");
|
|
52
|
+
setResults([]);
|
|
53
|
+
setLoading(false);
|
|
54
|
+
setSelected("");
|
|
55
|
+
}
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
const handleQueryChange = React.useCallback((next: string) => {
|
|
59
|
+
setQuery(next);
|
|
60
|
+
if (next.trim().length < MIN_QUERY_LENGTH) {
|
|
61
|
+
setResults([]);
|
|
62
|
+
setLoading(false);
|
|
63
|
+
setSelected("");
|
|
64
|
+
} else {
|
|
65
|
+
setLoading(true);
|
|
66
|
+
}
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
const trimmed = query.trim();
|
|
71
|
+
if (trimmed.length < MIN_QUERY_LENGTH) return;
|
|
72
|
+
|
|
73
|
+
const controller = new AbortController();
|
|
74
|
+
const timer = setTimeout(async () => {
|
|
75
|
+
try {
|
|
76
|
+
const res = await fetch(`/api/cms/admin/search?q=${encodeURIComponent(trimmed)}`, {
|
|
77
|
+
signal: controller.signal,
|
|
78
|
+
credentials: "same-origin",
|
|
79
|
+
});
|
|
80
|
+
if (!res.ok) {
|
|
81
|
+
setResults([]);
|
|
82
|
+
setLoading(false);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const data = (await res.json()) as { results?: Result[] };
|
|
86
|
+
const next = Array.isArray(data.results) ? data.results : [];
|
|
87
|
+
setResults(next);
|
|
88
|
+
setSelected(next.length > 0 ? itemValue(next[0]) : "");
|
|
89
|
+
setLoading(false);
|
|
90
|
+
} catch (err) {
|
|
91
|
+
if ((err as { name?: string })?.name !== "AbortError") {
|
|
92
|
+
setResults([]);
|
|
93
|
+
setLoading(false);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}, DEBOUNCE_MS);
|
|
97
|
+
return () => {
|
|
98
|
+
controller.abort();
|
|
99
|
+
clearTimeout(timer);
|
|
100
|
+
};
|
|
101
|
+
}, [query]);
|
|
102
|
+
|
|
103
|
+
const grouped = React.useMemo(() => {
|
|
104
|
+
// Group by collectionLabel rather than collection slug so that all singletons
|
|
105
|
+
// (each its own collection) collapse into a single "Singles" header.
|
|
106
|
+
const groups = new Map<string, { label: string; items: Result[] }>();
|
|
107
|
+
for (const r of results) {
|
|
108
|
+
let g = groups.get(r.collectionLabel);
|
|
109
|
+
if (!g) {
|
|
110
|
+
g = { label: r.collectionLabel, items: [] };
|
|
111
|
+
groups.set(r.collectionLabel, g);
|
|
112
|
+
}
|
|
113
|
+
g.items.push(r);
|
|
114
|
+
}
|
|
115
|
+
return Array.from(groups.entries()).map(([key, { label, items }]) => ({ key, label, items }));
|
|
116
|
+
}, [results]);
|
|
117
|
+
|
|
118
|
+
const trimmed = query.trim();
|
|
119
|
+
const showHint = trimmed.length < MIN_QUERY_LENGTH;
|
|
120
|
+
// Only show the loading state when there are no previous results to display —
|
|
121
|
+
// otherwise keep the stale list visible to avoid a jarring empty-then-fill flash.
|
|
122
|
+
const showLoading = !showHint && loading && results.length === 0;
|
|
123
|
+
const showEmpty = !showHint && !loading && results.length === 0;
|
|
124
|
+
|
|
125
|
+
return (
|
|
126
|
+
<Dialog open={open} onOpenChange={handleOpenChange}>
|
|
127
|
+
<DialogContent className="top-[18vh] max-w-xl translate-y-0 gap-0 overflow-hidden p-0">
|
|
128
|
+
<DialogTitle className="sr-only">Search content</DialogTitle>
|
|
129
|
+
<DialogDescription className="sr-only">
|
|
130
|
+
Search content collections by title and open the edit view.
|
|
131
|
+
</DialogDescription>
|
|
132
|
+
<Command shouldFilter={false} value={selected} onValueChange={setSelected}>
|
|
133
|
+
<CommandInput value={query} onValueChange={handleQueryChange} placeholder="Search content…" autoFocus />
|
|
134
|
+
<CommandList className="max-h-[60vh]">
|
|
135
|
+
{showHint && (
|
|
136
|
+
<div className="text-muted-foreground py-6 text-center text-sm">
|
|
137
|
+
Type at least {MIN_QUERY_LENGTH} characters to search.
|
|
138
|
+
</div>
|
|
139
|
+
)}
|
|
140
|
+
{showLoading && <div className="text-muted-foreground py-6 text-center text-sm">Searching…</div>}
|
|
141
|
+
{showEmpty && <CommandEmpty>No results.</CommandEmpty>}
|
|
142
|
+
{grouped.map((group) => (
|
|
143
|
+
<CommandGroup key={group.key} heading={group.label}>
|
|
144
|
+
{group.items.map((item) => (
|
|
145
|
+
<CommandItem
|
|
146
|
+
key={itemValue(item)}
|
|
147
|
+
value={itemValue(item)}
|
|
148
|
+
onSelect={() => {
|
|
149
|
+
window.location.href = item.editUrl;
|
|
150
|
+
setOpen(false);
|
|
151
|
+
}}
|
|
152
|
+
className="cursor-pointer px-3"
|
|
153
|
+
>
|
|
154
|
+
<span className="flex-1 truncate">{item.title}</span>
|
|
155
|
+
{item.status && item.status !== "published" && (
|
|
156
|
+
<span className="bg-muted text-muted-foreground rounded px-1.5 py-0.5 text-[10px] tracking-wide uppercase">
|
|
157
|
+
{item.status}
|
|
158
|
+
</span>
|
|
159
|
+
)}
|
|
160
|
+
</CommandItem>
|
|
161
|
+
))}
|
|
162
|
+
</CommandGroup>
|
|
163
|
+
))}
|
|
164
|
+
</CommandList>
|
|
165
|
+
</Command>
|
|
166
|
+
</DialogContent>
|
|
167
|
+
</Dialog>
|
|
168
|
+
);
|
|
169
|
+
}
|