@kidecms/core 0.14.3 → 0.16.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/admin/components/AssetsGrid.tsx +196 -45
- 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/components/ui/button.tsx +1 -1
- package/admin/layouts/AdminLayout.astro +3 -3
- package/admin/views/EditView.astro +10 -7
- package/admin/views/ListView.astro +66 -42
- package/admin/views/RecentView.astro +7 -1
- package/admin/views/SinglesView.astro +24 -4
- package/client/preview.ts +55 -0
- package/core/admin.ts +12 -1
- package/core/define.ts +2 -0
- package/core/index.ts +2 -0
- package/internals/integration.ts +4 -0
- package/middleware/auth.ts +18 -2
- package/package.json +1 -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 +38 -18
- package/routes/api/assets/upload.ts +6 -2
- package/routes/api/edit-bar.ts +46 -0
|
@@ -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,11 @@ import { REVIEW_STATE_META } from "../lib/collaboration";
|
|
|
10
10
|
import {
|
|
11
11
|
formatDate,
|
|
12
12
|
formatFieldValue,
|
|
13
|
+
formatPagePath,
|
|
14
|
+
getPageHref,
|
|
13
15
|
getLabelField,
|
|
14
16
|
getListColumns,
|
|
17
|
+
getTranslatableFieldNames,
|
|
15
18
|
humanize,
|
|
16
19
|
resolveCollaboration,
|
|
17
20
|
} from "../../core";
|
|
@@ -22,6 +25,9 @@ type CollectionLike = {
|
|
|
22
25
|
slug: string;
|
|
23
26
|
labels: { singular: string; plural: string };
|
|
24
27
|
drafts?: boolean;
|
|
28
|
+
auth?: boolean;
|
|
29
|
+
preview?: boolean | string;
|
|
30
|
+
pathPrefix?: string;
|
|
25
31
|
fields: Record<string, any>;
|
|
26
32
|
views?: Record<string, any>;
|
|
27
33
|
};
|
|
@@ -32,6 +38,9 @@ const runtimeContext = user ? { user } : {};
|
|
|
32
38
|
const cmsRuntime = cms as Record<string, any>;
|
|
33
39
|
const defaultLocale = config.locales?.default ?? "en";
|
|
34
40
|
const locales = config.locales?.supported ?? [];
|
|
41
|
+
// The Locales column only means something when there's more than one locale
|
|
42
|
+
// and this collection actually has translatable fields to show per-locale.
|
|
43
|
+
const showLocalesColumn = locales.length > 1 && getTranslatableFieldNames(collection).length > 0;
|
|
35
44
|
|
|
36
45
|
const viewConfig = collection.views ?? {};
|
|
37
46
|
const defaultSort = viewConfig.list?.defaultSort ?? { field: "_updatedAt", direction: "desc" };
|
|
@@ -117,40 +126,60 @@ const sharedSectionUsageCounts =
|
|
|
117
126
|
runtimeContext,
|
|
118
127
|
)
|
|
119
128
|
: {};
|
|
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
|
-
|
|
129
|
+
const hasPageColumn = displayColumns.includes("__page");
|
|
130
|
+
|
|
131
|
+
// Mirrors EditView's own hasPreview/previewUrl logic, so the listed URL matches
|
|
132
|
+
// what the document's own "Preview" button links to.
|
|
133
|
+
const getPagePath = (entry: Record<string, unknown>): string | null => {
|
|
134
|
+
const hasPreview = hasPageColumn && !!(collection.preview || (collection.pathPrefix && entry?.slug));
|
|
135
|
+
if (!hasPreview) return null;
|
|
136
|
+
return typeof collection.preview === "string"
|
|
137
|
+
? collection.preview
|
|
138
|
+
: cms.meta.getRouteForDocument(collection.slug, entry);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const COLUMN_LABELS: Record<string, string> = {
|
|
142
|
+
__usage: "Used in",
|
|
143
|
+
__review: "Review",
|
|
144
|
+
__editor: "Editor",
|
|
145
|
+
__page: "URL",
|
|
146
|
+
};
|
|
147
|
+
const getColumnLabel = (column: string) => COLUMN_LABELS[column] ?? humanize(column);
|
|
148
|
+
|
|
149
|
+
const formatColumnValue = (column: string, entry: Record<string, unknown>, pagePath: string | null): string => {
|
|
150
|
+
if (column === "__review") {
|
|
151
|
+
const reviewState = collabStates[String(entry._id)]?.reviewState ?? "in_progress";
|
|
152
|
+
return REVIEW_STATE_META[reviewState as keyof typeof REVIEW_STATE_META].label;
|
|
153
|
+
}
|
|
154
|
+
if (column === "__editor") {
|
|
155
|
+
const editorId = collabStates[String(entry._id)]?.editor;
|
|
156
|
+
return editorId ? (collabUserNames[editorId] ?? "—") : "Unassigned";
|
|
157
|
+
}
|
|
158
|
+
if (column === "_status") return getVisualStatus(entry);
|
|
159
|
+
if (column === "__usage") return `${sharedSectionUsageCounts[String(entry._id)] ?? 0} places`;
|
|
160
|
+
if (column === "__page") return formatPagePath(pagePath);
|
|
161
|
+
if (column === "_updatedAt" || column === "_createdAt") return formatDate(entry[column]);
|
|
162
|
+
if (column.startsWith("_")) return String(entry[column] ?? "—");
|
|
163
|
+
return formatFieldValue(collection.fields[column], entry[column], relationLabels);
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const tableRows = docs.map((entry: Record<string, unknown>) => {
|
|
167
|
+
const pagePath = getPagePath(entry);
|
|
168
|
+
return {
|
|
169
|
+
id: String(entry._id),
|
|
170
|
+
editHref: `/admin/${collection.slug}/${entry._id}`,
|
|
171
|
+
status: getVisualStatus(entry),
|
|
172
|
+
locales: [
|
|
173
|
+
defaultLocale,
|
|
174
|
+
...(Array.isArray(entry._availableLocales)
|
|
175
|
+
? entry._availableLocales.map((l) => String(l)).filter((l) => l !== defaultLocale)
|
|
176
|
+
: []),
|
|
177
|
+
],
|
|
178
|
+
searchText: String(entry[getLabelField(collection)] ?? entry.slug ?? entry._id ?? ""),
|
|
179
|
+
pageHref: pagePath ? getPageHref(pagePath, !collection.drafts || entry._status === "published") : undefined,
|
|
180
|
+
values: Object.fromEntries(displayColumns.map((column) => [column, formatColumnValue(column, entry, pagePath)])),
|
|
181
|
+
};
|
|
182
|
+
});
|
|
154
183
|
---
|
|
155
184
|
|
|
156
185
|
<section class="space-y-6 px-4 py-6 lg:py-8 lg:pr-8 lg:pl-12">
|
|
@@ -173,20 +202,15 @@ const tableRows = docs.map((entry: Record<string, unknown>) => ({
|
|
|
173
202
|
client:load
|
|
174
203
|
collectionSlug={collection.slug}
|
|
175
204
|
draftsEnabled={collection.drafts}
|
|
205
|
+
duplicateEnabled={!collection.auth}
|
|
206
|
+
showLocalesColumn={showLocalesColumn}
|
|
176
207
|
defaultLocale={locales.length > 1 ? defaultLocale : undefined}
|
|
177
208
|
labelField={getLabelField(collection)}
|
|
178
209
|
newHref={`/admin/${collection.slug}/new`}
|
|
179
210
|
title={collection.labels.plural}
|
|
180
211
|
columns={displayColumns.map((column) => ({
|
|
181
212
|
key: column,
|
|
182
|
-
label:
|
|
183
|
-
column === "__usage"
|
|
184
|
-
? "Used in"
|
|
185
|
-
: column === "__review"
|
|
186
|
-
? "Review"
|
|
187
|
-
: column === "__editor"
|
|
188
|
-
? "Editor"
|
|
189
|
-
: humanize(column),
|
|
213
|
+
label: getColumnLabel(column),
|
|
190
214
|
sortable: !column.startsWith("__"),
|
|
191
215
|
}))}
|
|
192
216
|
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, getPageHref, 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,10 @@ 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
|
|
50
|
+
? getPageHref(pagePath, !!singleDoc && (!sc.drafts || singleDoc._status === "published"))
|
|
51
|
+
: null,
|
|
34
52
|
};
|
|
35
53
|
}),
|
|
36
54
|
);
|
|
@@ -48,9 +66,9 @@ const singletonsData = await Promise.all(
|
|
|
48
66
|
title="Singles"
|
|
49
67
|
columns={[
|
|
50
68
|
{ key: "name", label: "Name" },
|
|
51
|
-
{ key: "
|
|
69
|
+
{ key: "__page", label: "URL" },
|
|
52
70
|
...(singletonCollections.some((c) => c.drafts) ? [{ key: "_status", label: "Status" }] : []),
|
|
53
|
-
{ key: "updatedAt", label: "
|
|
71
|
+
{ key: "updatedAt", label: "Updated At" },
|
|
54
72
|
]}
|
|
55
73
|
data={singletonsData.map((s) => ({
|
|
56
74
|
id: s.id,
|
|
@@ -58,8 +76,10 @@ const singletonsData = await Promise.all(
|
|
|
58
76
|
editHref: s.editHref,
|
|
59
77
|
locales: s.locales,
|
|
60
78
|
searchText: `${s.label} ${s.collectionSlug}`,
|
|
61
|
-
values: { name: s.label,
|
|
79
|
+
values: { name: s.label, __page: formatPagePath(s.page), _status: s.status, updatedAt: s.updatedAt },
|
|
80
|
+
pageHref: s.pageHref ?? undefined,
|
|
62
81
|
}))}
|
|
63
82
|
searchPlaceholder="Filter singles..."
|
|
83
|
+
showLocalesColumn={showLocalesColumn}
|
|
64
84
|
/>
|
|
65
85
|
</section>
|
package/client/preview.ts
CHANGED
|
@@ -33,3 +33,58 @@ if (new URLSearchParams(location.search).has("preview")) {
|
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
+
|
|
37
|
+
// --- Edit bar: "Edit this page" chip on public pages for logged-in editors ---
|
|
38
|
+
// Zero-cost for anonymous visitors: only acts when the non-httpOnly `kide-editor`
|
|
39
|
+
// hint cookie (set by the auth middleware on admin visits) is present, and only
|
|
40
|
+
// then verifies the real session via the edit-bar endpoint. Renders into a shadow
|
|
41
|
+
// root so site CSS can't leak in. Skipped in preview mode (the editor is already
|
|
42
|
+
// editing in another tab) and on admin pages.
|
|
43
|
+
if (
|
|
44
|
+
!new URLSearchParams(location.search).has("preview") &&
|
|
45
|
+
!location.pathname.startsWith("/admin") &&
|
|
46
|
+
document.cookie.split("; ").includes("kide-editor=1")
|
|
47
|
+
) {
|
|
48
|
+
const marker = document.querySelector("[data-cms-doc]");
|
|
49
|
+
const ref = marker?.getAttribute("data-cms-doc");
|
|
50
|
+
if (ref) {
|
|
51
|
+
fetch(`/api/cms/edit-bar?doc=${encodeURIComponent(ref)}`)
|
|
52
|
+
.then((r) => {
|
|
53
|
+
if (r.status === 401) {
|
|
54
|
+
// Session gone — drop the hint so future page views stay request-free.
|
|
55
|
+
document.cookie = "kide-editor=; Path=/; Max-Age=0";
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return r.ok ? r.json() : null;
|
|
59
|
+
})
|
|
60
|
+
.then((data: { editUrl: string; status: string | null } | null) => {
|
|
61
|
+
if (!data) return;
|
|
62
|
+
const host = document.createElement("div");
|
|
63
|
+
const shadow = host.attachShadow({ mode: "open" });
|
|
64
|
+
// Static markup only — editUrl embeds a caller-suppliable document id, so
|
|
65
|
+
// it goes through setAttribute, never into an HTML string.
|
|
66
|
+
shadow.innerHTML = `
|
|
67
|
+
<style>
|
|
68
|
+
a {
|
|
69
|
+
position: fixed; right: 16px; bottom: 16px; z-index: 2147483647;
|
|
70
|
+
display: inline-flex; align-items: center; gap: 8px;
|
|
71
|
+
padding: 8px 14px; border-radius: 999px;
|
|
72
|
+
background: #18181b; color: #fafafa;
|
|
73
|
+
font: 500 13px/1 system-ui, sans-serif; text-decoration: none;
|
|
74
|
+
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
|
|
75
|
+
}
|
|
76
|
+
a:hover { background: #303036; }
|
|
77
|
+
svg { width: 13px; height: 13px; }
|
|
78
|
+
</style>
|
|
79
|
+
<a>
|
|
80
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
|
|
81
|
+
<path d="M17 3a2.85 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z" />
|
|
82
|
+
</svg>
|
|
83
|
+
Edit this page
|
|
84
|
+
</a>`;
|
|
85
|
+
shadow.querySelector("a")!.setAttribute("href", data.editUrl);
|
|
86
|
+
document.body.appendChild(host);
|
|
87
|
+
})
|
|
88
|
+
.catch(() => {});
|
|
89
|
+
}
|
|
90
|
+
}
|
package/core/admin.ts
CHANGED
|
@@ -103,6 +103,12 @@ 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
|
+
|
|
109
|
+
/** Link target for the URL column: live documents open the real page; never-published drafts only exist behind ?preview. */
|
|
110
|
+
export const getPageHref = (pagePath: string, isLive: boolean) => (isLive ? pagePath : `${pagePath}?preview=true`);
|
|
111
|
+
|
|
106
112
|
export const humanize = (value: string) =>
|
|
107
113
|
value
|
|
108
114
|
.replace(/^_+/, "")
|
|
@@ -150,7 +156,12 @@ export const getListColumns = (collection: CollectionConfig, viewConfig?: { colu
|
|
|
150
156
|
return collection.drafts ? viewConfig.columns : viewConfig.columns.filter((column) => column !== "_status");
|
|
151
157
|
}
|
|
152
158
|
const firstField = "title" in collection.fields ? "title" : Object.keys(collection.fields)[0];
|
|
153
|
-
|
|
159
|
+
const columns = [firstField];
|
|
160
|
+
if (collection.preview || collection.pathPrefix) columns.push("__page");
|
|
161
|
+
if (collection.drafts) columns.push("_status");
|
|
162
|
+
if (collection.timestamps !== false) columns.push("_createdAt");
|
|
163
|
+
columns.push("_updatedAt");
|
|
164
|
+
return columns;
|
|
154
165
|
};
|
|
155
166
|
|
|
156
167
|
/**
|
package/core/define.ts
CHANGED
|
@@ -382,6 +382,8 @@ export type AdminConfig = {
|
|
|
382
382
|
*/
|
|
383
383
|
dateTimePattern?: string;
|
|
384
384
|
nav?: AdminNavItem[];
|
|
385
|
+
/** "Edit this page" chip on public pages for logged-in editors (default: true). */
|
|
386
|
+
editBar?: boolean;
|
|
385
387
|
uploads?: AdminUploadConfig;
|
|
386
388
|
rateLimit?: AdminRateLimitConfig;
|
|
387
389
|
auth?: AdminAuthConfig;
|
package/core/index.ts
CHANGED
package/internals/integration.ts
CHANGED
|
@@ -312,6 +312,10 @@ export default function cmsIntegration(options?: CmsIntegrationOptions): AstroIn
|
|
|
312
312
|
pattern: "/api/cms/collaboration",
|
|
313
313
|
entrypoint: new URL("../routes/api/collaboration/index.ts", import.meta.url),
|
|
314
314
|
});
|
|
315
|
+
injectRoute({
|
|
316
|
+
pattern: "/api/cms/edit-bar",
|
|
317
|
+
entrypoint: new URL("../routes/api/edit-bar.ts", import.meta.url),
|
|
318
|
+
});
|
|
315
319
|
injectRoute({
|
|
316
320
|
pattern: "/api/cms/ai/alt-text",
|
|
317
321
|
entrypoint: new URL("../routes/api/ai/alt-text.ts", import.meta.url),
|
package/middleware/auth.ts
CHANGED
|
@@ -200,6 +200,22 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
|
|
|
200
200
|
? normalizeCustomUser(await customProvider.getSession(context.request))
|
|
201
201
|
: await getSessionUser(context.request);
|
|
202
202
|
|
|
203
|
+
// Non-httpOnly hint for the public-site edit bar: lets the injected client skip
|
|
204
|
+
// the session check entirely for anonymous visitors. Carries no auth value — the
|
|
205
|
+
// edit-bar endpoint verifies the real session. Only ever set/cleared on /admin
|
|
206
|
+
// responses, which are never cached, so it can't poison the shared cache.
|
|
207
|
+
const hasEditorHint = (context.request.headers.get("cookie") ?? "").split(/;\s*/).includes("kide-editor=1");
|
|
208
|
+
const editBarEnabled = config.admin?.editBar !== false;
|
|
209
|
+
const secure = process.env.NODE_ENV === "production" ? "; Secure" : "";
|
|
210
|
+
const withEditorHint = (response: Response, loggedIn: boolean) => {
|
|
211
|
+
if (loggedIn && editBarEnabled && !hasEditorHint) {
|
|
212
|
+
response.headers.append("Set-Cookie", `kide-editor=1; Path=/; SameSite=Strict${secure}; Max-Age=2592000`);
|
|
213
|
+
} else if (hasEditorHint && (!loggedIn || !editBarEnabled)) {
|
|
214
|
+
response.headers.append("Set-Cookie", `kide-editor=; Path=/; SameSite=Strict${secure}; Max-Age=0`);
|
|
215
|
+
}
|
|
216
|
+
return response;
|
|
217
|
+
};
|
|
218
|
+
|
|
203
219
|
if (!user) {
|
|
204
220
|
// API routes → 401
|
|
205
221
|
if (isAdminApiRoute) {
|
|
@@ -209,11 +225,11 @@ const handle = async (context: APIContext, next: MiddlewareNext) => {
|
|
|
209
225
|
});
|
|
210
226
|
}
|
|
211
227
|
// Admin pages → redirect to login
|
|
212
|
-
return context.redirect("/admin/login");
|
|
228
|
+
return withEditorHint(context.redirect("/admin/login"), false);
|
|
213
229
|
}
|
|
214
230
|
|
|
215
231
|
// Attach user to locals for downstream use
|
|
216
232
|
context.locals.user = user;
|
|
217
233
|
|
|
218
|
-
return serve();
|
|
234
|
+
return withEditorHint(await serve(), true);
|
|
219
235
|
};
|
package/package.json
CHANGED
|
@@ -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>
|