@kidecms/core 0.14.2 → 0.15.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/README.md +26 -0
- package/admin/components/AssetsGrid.tsx +195 -44
- package/admin/components/ContentEditor.tsx +1 -1
- package/admin/components/DocumentsDataTable.tsx +65 -32
- package/admin/components/FieldControl.astro +2 -9
- package/admin/components/ImageBrowseDialog.tsx +1 -1
- package/admin/components/ImagePicker.tsx +1 -1
- package/admin/components/InternalLinkPicker.tsx +2 -2
- package/admin/components/RichTextEditor.tsx +3 -1
- package/admin/components/TreeItemsEditor.tsx +13 -7
- package/admin/layouts/AdminLayout.astro +3 -3
- package/admin/views/EditView.astro +10 -7
- package/admin/views/ListView.astro +65 -42
- package/admin/views/RecentView.astro +7 -1
- package/admin/views/SinglesView.astro +22 -4
- package/core/admin.ts +9 -1
- package/core/index.ts +1 -0
- package/package.json +11 -1
- package/routes/admin/assets/index.astro +2 -0
- package/routes/admin/invite.astro +8 -10
- package/routes/admin/login.astro +7 -12
- package/routes/admin/reset-password.astro +7 -10
- package/routes/admin/setup.astro +6 -8
- package/routes/api/[collection]/[...path].ts +36 -18
- package/routes/api/assets/upload.ts +6 -2
|
@@ -332,11 +332,11 @@ const navGroups = [...new Set(navItems.map((item) => item.group))]
|
|
|
332
332
|
</main>
|
|
333
333
|
) : (
|
|
334
334
|
<div
|
|
335
|
-
class="min-h-screen
|
|
335
|
+
class="min-h-screen min-[1400px]:grid"
|
|
336
336
|
style="grid-template-columns: 17rem 1fr; transition: grid-template-columns 150ms ease;"
|
|
337
337
|
>
|
|
338
338
|
{/* ── Desktop sidebar ──────────────────────────────────────────── */}
|
|
339
|
-
<aside class="bg-sidebar/40 sticky top-0 mt-1 hidden h-screen overflow-hidden border-r backdrop-blur transition-transform duration-150 ease-in-out
|
|
339
|
+
<aside class="bg-sidebar/40 sticky top-0 mt-1 hidden h-screen overflow-hidden border-r backdrop-blur transition-transform duration-150 ease-in-out min-[1400px]:flex min-[1400px]:flex-col">
|
|
340
340
|
<div class="px-3 pt-4 pb-1">
|
|
341
341
|
<button
|
|
342
342
|
type="button"
|
|
@@ -422,7 +422,7 @@ const navGroups = [...new Set(navItems.map((item) => item.group))]
|
|
|
422
422
|
|
|
423
423
|
<div class="min-w-0">
|
|
424
424
|
{/* ── Mobile header ────────────────────────────────────────── */}
|
|
425
|
-
<header class="bg-background/95 supports-backdrop-filter:bg-background/75 flex items-center gap-3 border-b px-4 py-3 backdrop-blur
|
|
425
|
+
<header class="bg-background/95 supports-backdrop-filter:bg-background/75 flex items-center gap-3 border-b px-4 py-3 backdrop-blur min-[1400px]:hidden">
|
|
426
426
|
<MobileSidebar client:load>
|
|
427
427
|
<div class="px-3 pt-4 pb-1">
|
|
428
428
|
<button
|
|
@@ -47,6 +47,7 @@ type CollectionLike = {
|
|
|
47
47
|
labels: { singular: string; plural: string };
|
|
48
48
|
singleton?: boolean;
|
|
49
49
|
drafts?: boolean;
|
|
50
|
+
auth?: boolean;
|
|
50
51
|
preview?: boolean | string;
|
|
51
52
|
pathPrefix?: string;
|
|
52
53
|
fields: Record<string, any>;
|
|
@@ -214,8 +215,8 @@ const publishBlocked =
|
|
|
214
215
|
variant === "editorial" && "bg-background sticky top-0 z-30 backdrop-blur-md",
|
|
215
216
|
]}
|
|
216
217
|
>
|
|
217
|
-
<div class="flex items-center justify-between
|
|
218
|
-
<div class="min-w-0">
|
|
218
|
+
<div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between">
|
|
219
|
+
<div class="min-w-0 flex-1">
|
|
219
220
|
<div class="flex items-center gap-2.5">
|
|
220
221
|
<h1 class="truncate text-lg font-semibold tracking-tight md:text-xl">
|
|
221
222
|
{mode === "new" && <LiveHeading client:load initial={`New ${collection.labels.singular}`} />}
|
|
@@ -247,7 +248,7 @@ const publishBlocked =
|
|
|
247
248
|
|
|
248
249
|
{
|
|
249
250
|
formTab !== "submissions" && (
|
|
250
|
-
<div class="flex flex-
|
|
251
|
+
<div class="flex flex-wrap items-center gap-2 sm:flex-shrink-0 sm:justify-end">
|
|
251
252
|
{hasPreview && previewUrl && !translationMode && (
|
|
252
253
|
<>
|
|
253
254
|
<a href={previewUrl} target="_blank" class={buttonVariants({ variant: "outline" })}>
|
|
@@ -340,7 +341,7 @@ const publishBlocked =
|
|
|
340
341
|
showUnpublish={collection.drafts && doc?._status === "published"}
|
|
341
342
|
showDiscardDraft={Boolean(collection.drafts && doc?._status === "published" && doc?._published)}
|
|
342
343
|
showDelete={!isSingleton}
|
|
343
|
-
showDuplicate={!isSingleton}
|
|
344
|
+
showDuplicate={!isSingleton && !collection.auth}
|
|
344
345
|
showSchedule={!!collection.drafts}
|
|
345
346
|
showCancelSchedule={collection.drafts && doc?._status === "scheduled"}
|
|
346
347
|
currentPublishAt={doc?._publishAt ? String(doc._publishAt) : undefined}
|
|
@@ -357,7 +358,7 @@ const publishBlocked =
|
|
|
357
358
|
</div>
|
|
358
359
|
|
|
359
360
|
{/* Body — everything below the sticky bar, inset from the page edges */}
|
|
360
|
-
<div class="space-y-6 px-4 pb-8 lg:
|
|
361
|
+
<div class="space-y-6 px-4 pb-8 lg:px-8 lg:pb-12 2xl:px-20">
|
|
361
362
|
{
|
|
362
363
|
/* Collaboration review strip. Margins live on this wrapper, which only
|
|
363
364
|
renders when collaboration is enabled, so non-collab edit views are
|
|
@@ -424,7 +425,9 @@ const publishBlocked =
|
|
|
424
425
|
action={getFormAction(collection.slug, mode === "edit" ? documentId : undefined)}
|
|
425
426
|
class:list={[
|
|
426
427
|
"grid items-start gap-y-10",
|
|
427
|
-
hasSidebarColumn
|
|
428
|
+
hasSidebarColumn
|
|
429
|
+
? "gap-x-8 lg:grid-cols-[minmax(0,1fr)_minmax(320px,400px)] 2xl:gap-x-20"
|
|
430
|
+
: "max-w-3xl",
|
|
428
431
|
]}
|
|
429
432
|
>
|
|
430
433
|
<input type="hidden" name="_action" value={mode === "new" ? "create" : "update"} />
|
|
@@ -532,7 +535,7 @@ const publishBlocked =
|
|
|
532
535
|
</div>
|
|
533
536
|
|
|
534
537
|
{hasSidebarColumn && (
|
|
535
|
-
<div class="text-sm
|
|
538
|
+
<div class="text-sm lg:border-l lg:pl-8 [&_button]:text-sm [&_input]:text-sm [&_select]:text-sm [&_textarea]:text-sm">
|
|
536
539
|
<div class="space-y-6">
|
|
537
540
|
{effectiveSidebarFieldSets.map((set) => {
|
|
538
541
|
const fields = (
|
|
@@ -10,8 +10,10 @@ import { REVIEW_STATE_META } from "../lib/collaboration";
|
|
|
10
10
|
import {
|
|
11
11
|
formatDate,
|
|
12
12
|
formatFieldValue,
|
|
13
|
+
formatPagePath,
|
|
13
14
|
getLabelField,
|
|
14
15
|
getListColumns,
|
|
16
|
+
getTranslatableFieldNames,
|
|
15
17
|
humanize,
|
|
16
18
|
resolveCollaboration,
|
|
17
19
|
} from "../../core";
|
|
@@ -22,6 +24,9 @@ type CollectionLike = {
|
|
|
22
24
|
slug: string;
|
|
23
25
|
labels: { singular: string; plural: string };
|
|
24
26
|
drafts?: boolean;
|
|
27
|
+
auth?: boolean;
|
|
28
|
+
preview?: boolean | string;
|
|
29
|
+
pathPrefix?: string;
|
|
25
30
|
fields: Record<string, any>;
|
|
26
31
|
views?: Record<string, any>;
|
|
27
32
|
};
|
|
@@ -32,6 +37,9 @@ const runtimeContext = user ? { user } : {};
|
|
|
32
37
|
const cmsRuntime = cms as Record<string, any>;
|
|
33
38
|
const defaultLocale = config.locales?.default ?? "en";
|
|
34
39
|
const locales = config.locales?.supported ?? [];
|
|
40
|
+
// The Locales column only means something when there's more than one locale
|
|
41
|
+
// and this collection actually has translatable fields to show per-locale.
|
|
42
|
+
const showLocalesColumn = locales.length > 1 && getTranslatableFieldNames(collection).length > 0;
|
|
35
43
|
|
|
36
44
|
const viewConfig = collection.views ?? {};
|
|
37
45
|
const defaultSort = viewConfig.list?.defaultSort ?? { field: "_updatedAt", direction: "desc" };
|
|
@@ -117,40 +125,60 @@ const sharedSectionUsageCounts =
|
|
|
117
125
|
runtimeContext,
|
|
118
126
|
)
|
|
119
127
|
: {};
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
)
|
|
153
|
-
|
|
128
|
+
const hasPageColumn = displayColumns.includes("__page");
|
|
129
|
+
|
|
130
|
+
// Mirrors EditView's own hasPreview/previewUrl logic, so the listed URL matches
|
|
131
|
+
// what the document's own "Preview" button links to.
|
|
132
|
+
const getPagePath = (entry: Record<string, unknown>): string | null => {
|
|
133
|
+
const hasPreview = hasPageColumn && !!(collection.preview || (collection.pathPrefix && entry?.slug));
|
|
134
|
+
if (!hasPreview) return null;
|
|
135
|
+
return typeof collection.preview === "string"
|
|
136
|
+
? collection.preview
|
|
137
|
+
: cms.meta.getRouteForDocument(collection.slug, entry);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const COLUMN_LABELS: Record<string, string> = {
|
|
141
|
+
__usage: "Used in",
|
|
142
|
+
__review: "Review",
|
|
143
|
+
__editor: "Editor",
|
|
144
|
+
__page: "URL",
|
|
145
|
+
};
|
|
146
|
+
const getColumnLabel = (column: string) => COLUMN_LABELS[column] ?? humanize(column);
|
|
147
|
+
|
|
148
|
+
const formatColumnValue = (column: string, entry: Record<string, unknown>, pagePath: string | null): string => {
|
|
149
|
+
if (column === "__review") {
|
|
150
|
+
const reviewState = collabStates[String(entry._id)]?.reviewState ?? "in_progress";
|
|
151
|
+
return REVIEW_STATE_META[reviewState as keyof typeof REVIEW_STATE_META].label;
|
|
152
|
+
}
|
|
153
|
+
if (column === "__editor") {
|
|
154
|
+
const editorId = collabStates[String(entry._id)]?.editor;
|
|
155
|
+
return editorId ? (collabUserNames[editorId] ?? "—") : "Unassigned";
|
|
156
|
+
}
|
|
157
|
+
if (column === "_status") return getVisualStatus(entry);
|
|
158
|
+
if (column === "__usage") return `${sharedSectionUsageCounts[String(entry._id)] ?? 0} places`;
|
|
159
|
+
if (column === "__page") return formatPagePath(pagePath);
|
|
160
|
+
if (column === "_updatedAt" || column === "_createdAt") return formatDate(entry[column]);
|
|
161
|
+
if (column.startsWith("_")) return String(entry[column] ?? "—");
|
|
162
|
+
return formatFieldValue(collection.fields[column], entry[column], relationLabels);
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
const tableRows = docs.map((entry: Record<string, unknown>) => {
|
|
166
|
+
const pagePath = getPagePath(entry);
|
|
167
|
+
return {
|
|
168
|
+
id: String(entry._id),
|
|
169
|
+
editHref: `/admin/${collection.slug}/${entry._id}`,
|
|
170
|
+
status: getVisualStatus(entry),
|
|
171
|
+
locales: [
|
|
172
|
+
defaultLocale,
|
|
173
|
+
...(Array.isArray(entry._availableLocales)
|
|
174
|
+
? entry._availableLocales.map((l) => String(l)).filter((l) => l !== defaultLocale)
|
|
175
|
+
: []),
|
|
176
|
+
],
|
|
177
|
+
searchText: String(entry[getLabelField(collection)] ?? entry.slug ?? entry._id ?? ""),
|
|
178
|
+
pageHref: pagePath ? `${pagePath}?preview=true` : undefined,
|
|
179
|
+
values: Object.fromEntries(displayColumns.map((column) => [column, formatColumnValue(column, entry, pagePath)])),
|
|
180
|
+
};
|
|
181
|
+
});
|
|
154
182
|
---
|
|
155
183
|
|
|
156
184
|
<section class="space-y-6 px-4 py-6 lg:py-8 lg:pr-8 lg:pl-12">
|
|
@@ -173,20 +201,15 @@ const tableRows = docs.map((entry: Record<string, unknown>) => ({
|
|
|
173
201
|
client:load
|
|
174
202
|
collectionSlug={collection.slug}
|
|
175
203
|
draftsEnabled={collection.drafts}
|
|
204
|
+
duplicateEnabled={!collection.auth}
|
|
205
|
+
showLocalesColumn={showLocalesColumn}
|
|
176
206
|
defaultLocale={locales.length > 1 ? defaultLocale : undefined}
|
|
177
207
|
labelField={getLabelField(collection)}
|
|
178
208
|
newHref={`/admin/${collection.slug}/new`}
|
|
179
209
|
title={collection.labels.plural}
|
|
180
210
|
columns={displayColumns.map((column) => ({
|
|
181
211
|
key: column,
|
|
182
|
-
label:
|
|
183
|
-
column === "__usage"
|
|
184
|
-
? "Used in"
|
|
185
|
-
: column === "__review"
|
|
186
|
-
? "Review"
|
|
187
|
-
: column === "__editor"
|
|
188
|
-
? "Editor"
|
|
189
|
-
: humanize(column),
|
|
212
|
+
label: getColumnLabel(column),
|
|
190
213
|
sortable: !column.startsWith("__"),
|
|
191
214
|
}))}
|
|
192
215
|
data={tableRows}
|
|
@@ -2,18 +2,23 @@
|
|
|
2
2
|
import DocumentsDataTable from "../components/DocumentsDataTable";
|
|
3
3
|
import config from "virtual:kide/config";
|
|
4
4
|
import { cms } from "virtual:kide/api";
|
|
5
|
-
import { formatDate, getLabelField } from "../../core";
|
|
5
|
+
import { formatDate, getLabelField, getTranslatableFieldNames } from "../../core";
|
|
6
6
|
import { canRead, getVisualStatus } from "../lib/access";
|
|
7
7
|
|
|
8
8
|
const user = Astro.locals.user;
|
|
9
9
|
const runtimeContext = user ? { user } : {};
|
|
10
10
|
const cmsRuntime = cms as Record<string, any>;
|
|
11
11
|
const defaultLocale = config.locales?.default ?? "en";
|
|
12
|
+
const locales = config.locales?.supported ?? [];
|
|
12
13
|
|
|
13
14
|
const pinnedSlugs = new Set(["taxonomies", "menus", "authors", "users"]);
|
|
14
15
|
const contentCollections = config.collections.filter(
|
|
15
16
|
(c) => !c.auth && !pinnedSlugs.has(c.slug) && canRead(config, user, c.slug),
|
|
16
17
|
);
|
|
18
|
+
// Same rule as ListView: a Locales column is only meaningful with more than one
|
|
19
|
+
// locale and at least one of the mixed-in collections having translatable fields.
|
|
20
|
+
const showLocalesColumn =
|
|
21
|
+
locales.length > 1 && contentCollections.some((cc) => getTranslatableFieldNames(cc).length > 0);
|
|
17
22
|
|
|
18
23
|
const allEntries: Array<{ doc: Record<string, unknown>; collection: (typeof contentCollections)[0] }> = [];
|
|
19
24
|
for (const cc of contentCollections) {
|
|
@@ -72,5 +77,6 @@ const recentRows = allEntries.slice(0, 50).map(({ doc, collection: cc }) => {
|
|
|
72
77
|
]}
|
|
73
78
|
data={recentRows}
|
|
74
79
|
searchPlaceholder="Filter recent entries..."
|
|
80
|
+
showLocalesColumn={showLocalesColumn}
|
|
75
81
|
/>
|
|
76
82
|
</section>
|
|
@@ -2,20 +2,34 @@
|
|
|
2
2
|
import DocumentsDataTable from "../components/DocumentsDataTable";
|
|
3
3
|
import config from "virtual:kide/config";
|
|
4
4
|
import { cms } from "virtual:kide/api";
|
|
5
|
-
import { formatDate } from "../../core";
|
|
5
|
+
import { formatDate, formatPagePath, getTranslatableFieldNames } from "../../core";
|
|
6
6
|
import { canRead } from "../lib/access";
|
|
7
7
|
|
|
8
8
|
const user = Astro.locals.user;
|
|
9
9
|
const runtimeContext = user ? { user } : {};
|
|
10
10
|
const cmsRuntime = cms as Record<string, any>;
|
|
11
11
|
const defaultLocale = config.locales?.default ?? "en";
|
|
12
|
+
const locales = config.locales?.supported ?? [];
|
|
12
13
|
|
|
13
14
|
const singletonCollections = config.collections.filter((c) => c.singleton && canRead(config, user, c.slug));
|
|
15
|
+
// Same rule as ListView: a Locales column is only meaningful with more than one
|
|
16
|
+
// locale and at least one singleton having translatable fields.
|
|
17
|
+
const showLocalesColumn =
|
|
18
|
+
locales.length > 1 && singletonCollections.some((c) => getTranslatableFieldNames(c).length > 0);
|
|
19
|
+
// Mirrors ListView's own getPagePath, so the listed URL matches what the
|
|
20
|
+
// singleton's own "Preview" button links to.
|
|
21
|
+
const getPagePath = (sc: (typeof singletonCollections)[number], doc: Record<string, unknown> | null): string | null => {
|
|
22
|
+
if (!sc.preview) return null;
|
|
23
|
+
if (typeof sc.preview === "string") return sc.preview;
|
|
24
|
+
return doc ? cms.meta.getRouteForDocument(sc.slug, doc) : null;
|
|
25
|
+
};
|
|
26
|
+
|
|
14
27
|
const singletonsData = await Promise.all(
|
|
15
28
|
singletonCollections.map(async (sc) => {
|
|
16
29
|
const api = cmsRuntime[sc.slug];
|
|
17
30
|
const singleDocs = await api.find({ status: "any", limit: 1, locale: defaultLocale }, runtimeContext);
|
|
18
31
|
const singleDoc = singleDocs[0] ?? null;
|
|
32
|
+
const pagePath = getPagePath(sc, singleDoc);
|
|
19
33
|
return {
|
|
20
34
|
id: singleDoc ? String(singleDoc._id) : "",
|
|
21
35
|
collectionSlug: sc.slug,
|
|
@@ -31,6 +45,8 @@ const singletonsData = await Promise.all(
|
|
|
31
45
|
: [],
|
|
32
46
|
updatedAt: singleDoc ? formatDate(singleDoc._updatedAt) : "—",
|
|
33
47
|
editHref: `/admin/${sc.slug}`,
|
|
48
|
+
page: pagePath,
|
|
49
|
+
pageHref: pagePath ? `${pagePath}?preview=true` : null,
|
|
34
50
|
};
|
|
35
51
|
}),
|
|
36
52
|
);
|
|
@@ -48,9 +64,9 @@ const singletonsData = await Promise.all(
|
|
|
48
64
|
title="Singles"
|
|
49
65
|
columns={[
|
|
50
66
|
{ key: "name", label: "Name" },
|
|
51
|
-
{ key: "
|
|
67
|
+
{ key: "__page", label: "URL" },
|
|
52
68
|
...(singletonCollections.some((c) => c.drafts) ? [{ key: "_status", label: "Status" }] : []),
|
|
53
|
-
{ key: "updatedAt", label: "
|
|
69
|
+
{ key: "updatedAt", label: "Updated At" },
|
|
54
70
|
]}
|
|
55
71
|
data={singletonsData.map((s) => ({
|
|
56
72
|
id: s.id,
|
|
@@ -58,8 +74,10 @@ const singletonsData = await Promise.all(
|
|
|
58
74
|
editHref: s.editHref,
|
|
59
75
|
locales: s.locales,
|
|
60
76
|
searchText: `${s.label} ${s.collectionSlug}`,
|
|
61
|
-
values: { name: s.label,
|
|
77
|
+
values: { name: s.label, __page: formatPagePath(s.page), _status: s.status, updatedAt: s.updatedAt },
|
|
78
|
+
pageHref: s.pageHref ?? undefined,
|
|
62
79
|
}))}
|
|
63
80
|
searchPlaceholder="Filter singles..."
|
|
81
|
+
showLocalesColumn={showLocalesColumn}
|
|
64
82
|
/>
|
|
65
83
|
</section>
|
package/core/admin.ts
CHANGED
|
@@ -103,6 +103,9 @@ export const resolveAdminRoute = (path: string | undefined): AdminRoute => {
|
|
|
103
103
|
};
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
+
/** Display text for a document's public URL in list tables — the bare root path reads as "Homepage" instead of "/". */
|
|
107
|
+
export const formatPagePath = (path: string | null | undefined) => (path === "/" ? "Homepage" : (path ?? "—"));
|
|
108
|
+
|
|
106
109
|
export const humanize = (value: string) =>
|
|
107
110
|
value
|
|
108
111
|
.replace(/^_+/, "")
|
|
@@ -150,7 +153,12 @@ export const getListColumns = (collection: CollectionConfig, viewConfig?: { colu
|
|
|
150
153
|
return collection.drafts ? viewConfig.columns : viewConfig.columns.filter((column) => column !== "_status");
|
|
151
154
|
}
|
|
152
155
|
const firstField = "title" in collection.fields ? "title" : Object.keys(collection.fields)[0];
|
|
153
|
-
|
|
156
|
+
const columns = [firstField];
|
|
157
|
+
if (collection.preview || collection.pathPrefix) columns.push("__page");
|
|
158
|
+
if (collection.drafts) columns.push("_status");
|
|
159
|
+
if (collection.timestamps !== false) columns.push("_createdAt");
|
|
160
|
+
columns.push("_updatedAt");
|
|
161
|
+
return columns;
|
|
154
162
|
};
|
|
155
163
|
|
|
156
164
|
/**
|
package/core/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kidecms/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Kide CMS runtime — core library, admin UI, routes, and middleware for Astro. Shipped as TypeScript source.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cms",
|
|
7
|
+
"astro",
|
|
8
|
+
"headless-cms",
|
|
9
|
+
"content-management",
|
|
10
|
+
"typescript",
|
|
11
|
+
"admin-panel"
|
|
12
|
+
],
|
|
5
13
|
"type": "module",
|
|
6
14
|
"license": "MIT",
|
|
15
|
+
"homepage": "https://docs.kide.dev/",
|
|
7
16
|
"repository": {
|
|
8
17
|
"type": "git",
|
|
9
18
|
"url": "https://github.com/mhernesniemi/kide-cms.git"
|
|
10
19
|
},
|
|
20
|
+
"bugs": "https://github.com/mhernesniemi/kide-cms/issues",
|
|
11
21
|
"engines": {
|
|
12
22
|
"node": ">=22.12.0"
|
|
13
23
|
},
|
|
@@ -32,16 +32,14 @@ if (token) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
? "This invite link has expired or already been used."
|
|
44
|
-
: null;
|
|
35
|
+
const ERROR_MESSAGES: Record<string, string> = {
|
|
36
|
+
missing: "Name and password are required.",
|
|
37
|
+
password: "Passwords do not match.",
|
|
38
|
+
short: `Password must be at least ${MIN_PASSWORD_LENGTH} characters.`,
|
|
39
|
+
expired: "This invite link has expired or already been used.",
|
|
40
|
+
invalid: "This invite link has expired or already been used.",
|
|
41
|
+
};
|
|
42
|
+
const errorMessage = error ? (ERROR_MESSAGES[error] ?? null) : null;
|
|
45
43
|
---
|
|
46
44
|
|
|
47
45
|
<!doctype html>
|
package/routes/admin/login.astro
CHANGED
|
@@ -10,19 +10,14 @@ import config from "virtual:kide/config";
|
|
|
10
10
|
|
|
11
11
|
export const prerender = false;
|
|
12
12
|
|
|
13
|
+
const ERROR_MESSAGES: Record<string, string> = {
|
|
14
|
+
invalid: "Invalid email or password.",
|
|
15
|
+
missing: "Email and password are required.",
|
|
16
|
+
disabled: "Password login is disabled.",
|
|
17
|
+
"rate-limited": "Too many attempts. Try again in a few minutes.",
|
|
18
|
+
};
|
|
13
19
|
const error = Astro.url.searchParams.get("error");
|
|
14
|
-
const errorMessage =
|
|
15
|
-
error === "invalid"
|
|
16
|
-
? "Invalid email or password."
|
|
17
|
-
: error === "missing"
|
|
18
|
-
? "Email and password are required."
|
|
19
|
-
: error === "disabled"
|
|
20
|
-
? "Password login is disabled."
|
|
21
|
-
: error === "rate-limited"
|
|
22
|
-
? "Too many attempts. Try again in a few minutes."
|
|
23
|
-
: error
|
|
24
|
-
? "Sign-in failed. Try again."
|
|
25
|
-
: null;
|
|
20
|
+
const errorMessage = error ? (ERROR_MESSAGES[error] ?? "Sign-in failed. Try again.") : null;
|
|
26
21
|
const auth = resolveAdminAuth(config);
|
|
27
22
|
---
|
|
28
23
|
|
|
@@ -15,16 +15,13 @@ if (!auth.password.forgotPassword) return Astro.redirect("/admin/login");
|
|
|
15
15
|
|
|
16
16
|
const token = Astro.url.searchParams.get("token") ?? "";
|
|
17
17
|
const error = Astro.url.searchParams.get("error");
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
: error === "invalid"
|
|
26
|
-
? "This reset link is invalid or expired."
|
|
27
|
-
: null;
|
|
18
|
+
const ERROR_MESSAGES: Record<string, string> = {
|
|
19
|
+
missing: "Password is required.",
|
|
20
|
+
password: "Passwords do not match.",
|
|
21
|
+
short: `Password must be at least ${MIN_PASSWORD_LENGTH} characters.`,
|
|
22
|
+
invalid: "This reset link is invalid or expired.",
|
|
23
|
+
};
|
|
24
|
+
const errorMessage = error ? (ERROR_MESSAGES[error] ?? null) : null;
|
|
28
25
|
---
|
|
29
26
|
|
|
30
27
|
<!doctype html>
|
package/routes/admin/setup.astro
CHANGED
|
@@ -21,15 +21,13 @@ if (tables.users) {
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
const ERROR_MESSAGES: Record<string, string> = {
|
|
25
|
+
missing: "All fields are required.",
|
|
26
|
+
password: "Passwords do not match.",
|
|
27
|
+
short: `Password must be at least ${MIN_PASSWORD_LENGTH} characters.`,
|
|
28
|
+
};
|
|
24
29
|
const error = Astro.url.searchParams.get("error");
|
|
25
|
-
const errorMessage =
|
|
26
|
-
error === "missing"
|
|
27
|
-
? "All fields are required."
|
|
28
|
-
: error === "password"
|
|
29
|
-
? "Passwords do not match."
|
|
30
|
-
: error === "short"
|
|
31
|
-
? `Password must be at least ${MIN_PASSWORD_LENGTH} characters.`
|
|
32
|
-
: null;
|
|
30
|
+
const errorMessage = error ? (ERROR_MESSAGES[error] ?? null) : null;
|
|
33
31
|
---
|
|
34
32
|
|
|
35
33
|
<!doctype html>
|
|
@@ -3,7 +3,7 @@ import type { APIRoute } from "astro";
|
|
|
3
3
|
import config from "virtual:kide/config";
|
|
4
4
|
import { cms } from "virtual:kide/api";
|
|
5
5
|
import { collaboration } from "virtual:kide/runtime";
|
|
6
|
-
import { isApprover, resolveCollaboration } from "../../../core";
|
|
6
|
+
import { formatPagePath, isApprover, resolveCollaboration } from "../../../core";
|
|
7
7
|
import { loadSharedSectionUsageCounts } from "../../../admin/lib/edit-data";
|
|
8
8
|
|
|
9
9
|
export const prerender = false;
|
|
@@ -124,13 +124,13 @@ const handleHtmlMutation = async (
|
|
|
124
124
|
ctx,
|
|
125
125
|
);
|
|
126
126
|
}
|
|
127
|
+
const CREATE_MESSAGES: Record<string, string> = {
|
|
128
|
+
publish: `${name} created and published`,
|
|
129
|
+
schedule: `${name} scheduled`,
|
|
130
|
+
};
|
|
127
131
|
const msg = blocked
|
|
128
132
|
? `${name} saved as draft — needs review approval before publishing`
|
|
129
|
-
: intent
|
|
130
|
-
? `${name} created and published`
|
|
131
|
-
: intent === "schedule"
|
|
132
|
-
? `${name} scheduled`
|
|
133
|
-
: `${name} created`;
|
|
133
|
+
: (CREATE_MESSAGES[intent] ?? `${name} created`);
|
|
134
134
|
return redirect(`/admin/${collectionSlug}/${created._id}`, { status: blocked ? "error" : "success", msg });
|
|
135
135
|
}
|
|
136
136
|
|
|
@@ -158,19 +158,15 @@ const handleHtmlMutation = async (
|
|
|
158
158
|
const actor = locals.user ? { id: locals.user.id, email: locals.user.email, role: locals.user.role } : null;
|
|
159
159
|
await collaboration.submitForReview(collectionSlug, documentId, actor);
|
|
160
160
|
}
|
|
161
|
+
const UPDATE_MESSAGES: Record<string, string> = {
|
|
162
|
+
publish: `${name} published`,
|
|
163
|
+
unpublish: `${name} unpublished`,
|
|
164
|
+
schedule: `${name} scheduled`,
|
|
165
|
+
"submit-review": "Saved and submitted for review",
|
|
166
|
+
};
|
|
161
167
|
const msg = blocked
|
|
162
168
|
? `Saved — needs review approval before publishing`
|
|
163
|
-
: intent
|
|
164
|
-
? `${name} published`
|
|
165
|
-
: intent === "unpublish"
|
|
166
|
-
? `${name} unpublished`
|
|
167
|
-
: intent === "schedule"
|
|
168
|
-
? `${name} scheduled`
|
|
169
|
-
: intent === "submit-review"
|
|
170
|
-
? `Saved and submitted for review`
|
|
171
|
-
: collection.drafts
|
|
172
|
-
? `${name} saved as draft`
|
|
173
|
-
: `${name} saved`;
|
|
169
|
+
: (UPDATE_MESSAGES[intent] ?? (collection.drafts ? `${name} saved as draft` : `${name} saved`));
|
|
174
170
|
return redirect(redirectTo, { status: blocked ? "error" : "success", msg });
|
|
175
171
|
}
|
|
176
172
|
|
|
@@ -287,6 +283,23 @@ export const GET: APIRoute = async ({ params, url, locals }) => {
|
|
|
287
283
|
}
|
|
288
284
|
}
|
|
289
285
|
|
|
286
|
+
// The list table's "URL" column is computed, not stored — resolve it here too so
|
|
287
|
+
// client-side re-fetches (sort/search/page changes) keep showing it. Mirrors
|
|
288
|
+
// ListView.astro's own getPagePath, since both run server-side against the same collection config.
|
|
289
|
+
const collection = getCollection(collectionSlug);
|
|
290
|
+
if (collection.preview || collection.pathPrefix) {
|
|
291
|
+
for (const entry of docs as Array<Record<string, unknown>>) {
|
|
292
|
+
const hasPreview = !!(collection.preview || (collection.pathPrefix && entry.slug));
|
|
293
|
+
const pagePath = hasPreview
|
|
294
|
+
? typeof collection.preview === "string"
|
|
295
|
+
? collection.preview
|
|
296
|
+
: cmsRuntime.meta.getRouteForDocument(collectionSlug, entry)
|
|
297
|
+
: null;
|
|
298
|
+
if (pagePath) entry._pageHref = `${pagePath}?preview=true`;
|
|
299
|
+
entry.__page = formatPagePath(pagePath);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
290
303
|
const page = Math.floor(offset / limit) + 1;
|
|
291
304
|
const totalPages = Math.ceil(totalDocs / limit);
|
|
292
305
|
|
|
@@ -330,11 +343,16 @@ export const POST: APIRoute = async ({ params, request, locals, cache }) => {
|
|
|
330
343
|
}
|
|
331
344
|
|
|
332
345
|
if (pathAction === "duplicate" && documentId) {
|
|
346
|
+
const collection = getCollection(collectionSlug);
|
|
347
|
+
if (collection.auth) {
|
|
348
|
+
// Duplicating a user would copy its password hash onto a new account —
|
|
349
|
+
// never useful, and not something field-stripping alone can make safe.
|
|
350
|
+
return Response.json({ error: "Auth collections can't be duplicated." }, { status: 400 });
|
|
351
|
+
}
|
|
333
352
|
const original = await collectionApi.findById(documentId, { status: "any" }, ctx);
|
|
334
353
|
if (!original) {
|
|
335
354
|
return Response.json({ error: "Not found." }, { status: 404 });
|
|
336
355
|
}
|
|
337
|
-
const collection = getCollection(collectionSlug);
|
|
338
356
|
|
|
339
357
|
// Strip system fields and unique values that would conflict
|
|
340
358
|
const stripFields = (source: Record<string, any>) => {
|
|
@@ -131,11 +131,15 @@ export const POST: APIRoute = async ({ request, locals }) => {
|
|
|
131
131
|
);
|
|
132
132
|
}
|
|
133
133
|
|
|
134
|
+
// Dev only: let Vite's dev server catch up on the new files before the client
|
|
135
|
+
// reloads, or the just-uploaded asset renders broken until a manual refresh.
|
|
136
|
+
if (import.meta.env.DEV) {
|
|
137
|
+
await new Promise((r) => setTimeout(r, 1000));
|
|
138
|
+
}
|
|
139
|
+
|
|
134
140
|
const redirectTo = formData.get("redirectTo");
|
|
135
141
|
|
|
136
142
|
if (redirectTo) {
|
|
137
|
-
// Delay so Vite's dev server picks up the new files before the redirect
|
|
138
|
-
await new Promise((r) => setTimeout(r, 1000));
|
|
139
143
|
const location =
|
|
140
144
|
uploaded.length === 1
|
|
141
145
|
? `/admin/assets/${uploaded[0]._id}?_toast=success&_msg=Asset+uploaded`
|