@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
|
@@ -266,10 +266,11 @@ export default function DocumentActions({
|
|
|
266
266
|
</label>
|
|
267
267
|
<input
|
|
268
268
|
id="schedule-publish-at"
|
|
269
|
+
data-slot="input"
|
|
269
270
|
type="datetime-local"
|
|
270
271
|
value={publishAt}
|
|
271
272
|
onChange={(e) => setPublishAt(e.target.value)}
|
|
272
|
-
className="border-input bg-background
|
|
273
|
+
className="border-input bg-background placeholder:text-muted-foreground flex h-9 w-full rounded-md border px-3 py-1 text-sm shadow-sm transition-colors"
|
|
273
274
|
/>
|
|
274
275
|
</div>
|
|
275
276
|
<div className="grid gap-2">
|
|
@@ -278,10 +279,11 @@ export default function DocumentActions({
|
|
|
278
279
|
</label>
|
|
279
280
|
<input
|
|
280
281
|
id="schedule-unpublish-at"
|
|
282
|
+
data-slot="input"
|
|
281
283
|
type="datetime-local"
|
|
282
284
|
value={unpublishAt}
|
|
283
285
|
onChange={(e) => setUnpublishAt(e.target.value)}
|
|
284
|
-
className="border-input bg-background
|
|
286
|
+
className="border-input bg-background placeholder:text-muted-foreground flex h-9 w-full rounded-md border px-3 py-1 text-sm shadow-sm transition-colors"
|
|
285
287
|
/>
|
|
286
288
|
</div>
|
|
287
289
|
</div>
|
|
@@ -52,6 +52,9 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from ".
|
|
|
52
52
|
type DataTableColumn = {
|
|
53
53
|
key: string;
|
|
54
54
|
label: string;
|
|
55
|
+
// Non-field columns (e.g. collaboration review state) opt out of sorting so
|
|
56
|
+
// they never send a sort-by request for a column the DB doesn't have.
|
|
57
|
+
sortable?: boolean;
|
|
55
58
|
};
|
|
56
59
|
|
|
57
60
|
type DataTableRow = {
|
|
@@ -68,11 +71,12 @@ type ServerPaginationConfig = {
|
|
|
68
71
|
totalDocs: number;
|
|
69
72
|
totalPages: number;
|
|
70
73
|
currentPage: number;
|
|
71
|
-
pageSize: number;
|
|
72
74
|
currentSort: { field: string; direction: "asc" | "desc" };
|
|
73
75
|
currentSearch: string;
|
|
74
76
|
};
|
|
75
77
|
|
|
78
|
+
export const PAGE_SIZE = 10;
|
|
79
|
+
|
|
76
80
|
type DocumentsDataTableProps = {
|
|
77
81
|
collectionSlug: string;
|
|
78
82
|
draftsEnabled?: boolean;
|
|
@@ -85,6 +89,8 @@ type DocumentsDataTableProps = {
|
|
|
85
89
|
columns: DataTableColumn[];
|
|
86
90
|
data: DataTableRow[];
|
|
87
91
|
serverPagination?: ServerPaginationConfig;
|
|
92
|
+
/** Bulk status change: if provided, renders "Mark as <status>" entries in the selection menu. */
|
|
93
|
+
statusOptions?: string[];
|
|
88
94
|
};
|
|
89
95
|
|
|
90
96
|
const formatDateClient = (value: unknown): string => {
|
|
@@ -140,6 +146,7 @@ export default function DocumentsDataTable({
|
|
|
140
146
|
columns,
|
|
141
147
|
data,
|
|
142
148
|
serverPagination,
|
|
149
|
+
statusOptions,
|
|
143
150
|
}: DocumentsDataTableProps) {
|
|
144
151
|
const isServerMode = !!serverPagination;
|
|
145
152
|
|
|
@@ -194,7 +201,6 @@ export default function DocumentsDataTable({
|
|
|
194
201
|
const [searchInput, setSearchInput] = React.useState(serverPagination?.currentSearch ?? "");
|
|
195
202
|
const [isLoading, setIsLoading] = React.useState(false);
|
|
196
203
|
const searchTimerRef = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
197
|
-
const pageSize = serverPagination?.pageSize ?? 20;
|
|
198
204
|
|
|
199
205
|
const fetchPage = React.useCallback(
|
|
200
206
|
async (page: number, sort: { field: string; direction: string } | null, search: string) => {
|
|
@@ -204,8 +210,8 @@ export default function DocumentsDataTable({
|
|
|
204
210
|
try {
|
|
205
211
|
const params = new URLSearchParams();
|
|
206
212
|
params.set("status", "any");
|
|
207
|
-
params.set("limit", String(
|
|
208
|
-
params.set("offset", String((page - 1) *
|
|
213
|
+
params.set("limit", String(PAGE_SIZE));
|
|
214
|
+
params.set("offset", String((page - 1) * PAGE_SIZE));
|
|
209
215
|
if (sort) {
|
|
210
216
|
params.set("sort", JSON.stringify(sort));
|
|
211
217
|
}
|
|
@@ -234,9 +240,11 @@ export default function DocumentsDataTable({
|
|
|
234
240
|
column.key,
|
|
235
241
|
column.key === "_status"
|
|
236
242
|
? getVisualStatus(entry)
|
|
237
|
-
: column.key === "
|
|
238
|
-
?
|
|
239
|
-
:
|
|
243
|
+
: column.key === "__usage"
|
|
244
|
+
? `${Number(entry.__usage ?? 0)} places`
|
|
245
|
+
: column.key === "_updatedAt" || column.key === "_createdAt"
|
|
246
|
+
? formatDateClient(entry[column.key])
|
|
247
|
+
: String(entry[column.key] ?? "\u2014"),
|
|
240
248
|
]),
|
|
241
249
|
),
|
|
242
250
|
})),
|
|
@@ -266,7 +274,7 @@ export default function DocumentsDataTable({
|
|
|
266
274
|
setIsLoading(false);
|
|
267
275
|
}
|
|
268
276
|
},
|
|
269
|
-
[isServerMode, collectionSlug, columns,
|
|
277
|
+
[isServerMode, collectionSlug, columns, defaultLocale, labelField],
|
|
270
278
|
);
|
|
271
279
|
|
|
272
280
|
// Cleanup debounce timer
|
|
@@ -323,6 +331,49 @@ export default function DocumentsDataTable({
|
|
|
323
331
|
[isServerMode, sorting, serverSearch, fetchPage],
|
|
324
332
|
);
|
|
325
333
|
|
|
334
|
+
const runStatusChange = React.useCallback(
|
|
335
|
+
async (newStatus: string, rows: DataTableRow[]) => {
|
|
336
|
+
if (!rows.length) return;
|
|
337
|
+
setActionError(null);
|
|
338
|
+
try {
|
|
339
|
+
await Promise.all(
|
|
340
|
+
rows.map(async (row) => {
|
|
341
|
+
const rowCollection = row.editHref.split("/")[2] ?? collectionSlug;
|
|
342
|
+
const body = new URLSearchParams({ _action: "update", status: newStatus });
|
|
343
|
+
const response = await fetch(`/api/cms/${rowCollection}/${row.id}`, {
|
|
344
|
+
method: "POST",
|
|
345
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
346
|
+
body: body.toString(),
|
|
347
|
+
});
|
|
348
|
+
if (!response.ok) throw new Error(`Failed to update status for ${row.id}.`);
|
|
349
|
+
}),
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
if (isServerMode) {
|
|
353
|
+
await fetchPage(serverPage, serverSort, serverSearch);
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
const count = rows.length;
|
|
357
|
+
const label = count === 1 ? "document" : "documents";
|
|
358
|
+
const url = new URL(window.location.href);
|
|
359
|
+
url.searchParams.set("_toast", "success");
|
|
360
|
+
url.searchParams.set("_msg", `${count} ${label} marked as ${newStatus}`);
|
|
361
|
+
window.location.assign(url.pathname + url.search);
|
|
362
|
+
} catch (error) {
|
|
363
|
+
const msg = error instanceof Error ? error.message : "Status change failed";
|
|
364
|
+
if (isServerMode) {
|
|
365
|
+
setActionError(msg);
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
const url = new URL(window.location.href);
|
|
369
|
+
url.searchParams.set("_toast", "error");
|
|
370
|
+
url.searchParams.set("_msg", msg);
|
|
371
|
+
window.location.assign(url.pathname + url.search);
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
[collectionSlug, isServerMode, serverPage, serverSort, serverSearch, fetchPage],
|
|
375
|
+
);
|
|
376
|
+
|
|
326
377
|
const runAction = React.useCallback(
|
|
327
378
|
async (action: "publish" | "unpublish" | "delete" | "duplicate", rows: DataTableRow[]) => {
|
|
328
379
|
if (!rows.length) {
|
|
@@ -437,6 +488,7 @@ export default function DocumentsDataTable({
|
|
|
437
488
|
...columns.map<ColumnDef<DataTableRow>>((column) => ({
|
|
438
489
|
accessorFn: (row) => row.values[column.key] ?? "",
|
|
439
490
|
id: column.key,
|
|
491
|
+
enableSorting: column.sortable !== false,
|
|
440
492
|
header: ({ column: headerColumn }) => <DataTableColumnHeader column={headerColumn} title={column.label} />,
|
|
441
493
|
cell: ({ row }) => {
|
|
442
494
|
const value = row.original.values[column.key] ?? "\u2014";
|
|
@@ -577,13 +629,14 @@ export default function DocumentsDataTable({
|
|
|
577
629
|
getPaginationRowModel: getPaginationRowModel(),
|
|
578
630
|
getSortedRowModel: getSortedRowModel(),
|
|
579
631
|
getFilteredRowModel: getFilteredRowModel(),
|
|
632
|
+
initialState: { pagination: { pageIndex: 0, pageSize: PAGE_SIZE } },
|
|
580
633
|
}),
|
|
581
634
|
state: {
|
|
582
635
|
sorting,
|
|
583
636
|
columnFilters,
|
|
584
637
|
columnVisibility,
|
|
585
638
|
rowSelection,
|
|
586
|
-
...(isServerMode ? { pagination: { pageIndex: serverPage - 1, pageSize } } : {}),
|
|
639
|
+
...(isServerMode ? { pagination: { pageIndex: serverPage - 1, pageSize: PAGE_SIZE } } : {}),
|
|
587
640
|
},
|
|
588
641
|
});
|
|
589
642
|
|
|
@@ -665,6 +718,25 @@ export default function DocumentsDataTable({
|
|
|
665
718
|
</DropdownMenuItem>
|
|
666
719
|
</>
|
|
667
720
|
)}
|
|
721
|
+
{statusOptions && statusOptions.length > 0 && (
|
|
722
|
+
<>
|
|
723
|
+
<DropdownMenuSeparator />
|
|
724
|
+
<DropdownMenuLabel>Set status</DropdownMenuLabel>
|
|
725
|
+
{statusOptions.map((status) => (
|
|
726
|
+
<DropdownMenuItem
|
|
727
|
+
key={status}
|
|
728
|
+
disabled={isPending}
|
|
729
|
+
onClick={() =>
|
|
730
|
+
startTransition(() => {
|
|
731
|
+
void runStatusChange(status, selectedRows);
|
|
732
|
+
})
|
|
733
|
+
}
|
|
734
|
+
>
|
|
735
|
+
Mark as {status}
|
|
736
|
+
</DropdownMenuItem>
|
|
737
|
+
))}
|
|
738
|
+
</>
|
|
739
|
+
)}
|
|
668
740
|
<DropdownMenuSeparator />
|
|
669
741
|
<DropdownMenuItem
|
|
670
742
|
variant="destructive"
|
|
@@ -708,7 +780,16 @@ export default function DocumentsDataTable({
|
|
|
708
780
|
.getVisibleCells()
|
|
709
781
|
.filter((cell) => cell.column.id !== "search")
|
|
710
782
|
.map((cell) => (
|
|
711
|
-
<TableCell
|
|
783
|
+
<TableCell
|
|
784
|
+
key={cell.id}
|
|
785
|
+
className={cn(
|
|
786
|
+
// Let long values (e.g. titles) wrap across lines instead of
|
|
787
|
+
// forcing one very wide row. Every column centers vertically,
|
|
788
|
+
// including a wrapped multi-line title, for a consistent row.
|
|
789
|
+
"align-middle break-words whitespace-normal",
|
|
790
|
+
cell.column.id === "select" && "w-10",
|
|
791
|
+
)}
|
|
792
|
+
>
|
|
712
793
|
{flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
713
794
|
</TableCell>
|
|
714
795
|
))}
|
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
---
|
|
2
|
-
import type { FieldConfig } from "
|
|
3
|
-
import { serializeFieldValue, humanize } from "
|
|
2
|
+
import type { FieldConfig } from "../../core";
|
|
3
|
+
import { serializeFieldValue, humanize } from "../../core";
|
|
4
4
|
import { customFields } from "virtual:kide/custom-fields";
|
|
5
|
+
import config from "virtual:kide/config";
|
|
5
6
|
import ImagePicker from "./ImagePicker";
|
|
6
7
|
import TreeItemsEditor from "./TreeItemsEditor";
|
|
7
8
|
import RichTextEditor from "./RichTextEditor";
|
|
9
|
+
import ContentEditor from "./ContentEditor";
|
|
8
10
|
import SelectField from "./SelectField";
|
|
9
11
|
import RelationField from "./RelationField";
|
|
10
12
|
import BlockEditor from "./BlockEditor";
|
|
11
13
|
import SlugField from "./SlugField";
|
|
12
14
|
import CheckboxField from "./CheckboxField";
|
|
13
15
|
import TaxonomySelect from "./TaxonomySelect";
|
|
16
|
+
import SharedSectionBlockField from "./SharedSectionBlockField";
|
|
17
|
+
import ColorField from "./ColorField";
|
|
18
|
+
import LinkField from "./LinkField";
|
|
19
|
+
import RepeaterInput from "./RepeaterInput";
|
|
20
|
+
import type { SubFieldMeta } from "./block-fields";
|
|
14
21
|
import { Input } from "./ui/input";
|
|
15
22
|
import { Label } from "./ui/label";
|
|
16
23
|
import { Textarea } from "./ui/textarea";
|
|
@@ -34,6 +41,13 @@ type LinkOptionGroup = {
|
|
|
34
41
|
items: Array<{ id: string; label: string; href: string }>;
|
|
35
42
|
};
|
|
36
43
|
|
|
44
|
+
type SharedSectionOption = {
|
|
45
|
+
id: string;
|
|
46
|
+
title: string;
|
|
47
|
+
blockType: string;
|
|
48
|
+
status?: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
37
51
|
const {
|
|
38
52
|
name,
|
|
39
53
|
field,
|
|
@@ -43,6 +57,9 @@ const {
|
|
|
43
57
|
readOnly = false,
|
|
44
58
|
menuLinkOptions = [],
|
|
45
59
|
blockRelationOptions = {},
|
|
60
|
+
sharedBlockTypes = {},
|
|
61
|
+
sharedBlockRelationOptions = {},
|
|
62
|
+
sharedSectionOptions = [],
|
|
46
63
|
} = Astro.props as {
|
|
47
64
|
name: string;
|
|
48
65
|
field: FieldConfig;
|
|
@@ -52,51 +69,81 @@ const {
|
|
|
52
69
|
readOnly?: boolean;
|
|
53
70
|
menuLinkOptions?: LinkOptionGroup[];
|
|
54
71
|
blockRelationOptions?: Record<string, RelationOption[]>;
|
|
72
|
+
sharedBlockTypes?: Record<string, Record<string, FieldConfig>>;
|
|
73
|
+
sharedBlockRelationOptions?: Record<string, RelationOption[]>;
|
|
74
|
+
sharedSectionOptions?: SharedSectionOption[];
|
|
55
75
|
};
|
|
56
76
|
|
|
57
77
|
const label = field.label ?? humanize(name);
|
|
58
78
|
const placeholder = field.admin?.placeholder ?? "";
|
|
59
79
|
const serializedValue = serializeFieldValue(field, value);
|
|
60
80
|
const rows =
|
|
61
|
-
field.admin?.rows ??
|
|
81
|
+
field.admin?.rows ??
|
|
82
|
+
(field.type === "richText" || field.type === "content"
|
|
83
|
+
? field.type === "content"
|
|
84
|
+
? 14
|
|
85
|
+
: 10
|
|
86
|
+
: field.type === "json" || field.type === "blocks"
|
|
87
|
+
? 12
|
|
88
|
+
: 5);
|
|
62
89
|
const inputMode = field.type === "number" ? "decimal" : undefined;
|
|
63
90
|
const controlClass = cn("w-full shadow-none", readOnly && "cursor-not-allowed bg-muted text-muted-foreground");
|
|
64
91
|
const isTreeEditor =
|
|
65
92
|
field.type === "json" && (field.admin?.component === "menu-items" || field.admin?.component === "taxonomy-terms");
|
|
66
93
|
|
|
67
94
|
// Custom field component: if admin.component is set and not a built-in variant, look for user-provided component
|
|
68
|
-
const builtInComponents = new Set([
|
|
95
|
+
const builtInComponents = new Set([
|
|
96
|
+
"radio",
|
|
97
|
+
"taxonomy-select",
|
|
98
|
+
"menu-items",
|
|
99
|
+
"taxonomy-terms",
|
|
100
|
+
"shared-section-block",
|
|
101
|
+
"color",
|
|
102
|
+
"link",
|
|
103
|
+
"repeater",
|
|
104
|
+
]);
|
|
69
105
|
const CustomComponent =
|
|
70
106
|
field.admin?.component && !builtInComponents.has(field.admin.component)
|
|
71
107
|
? (customFields[field.admin.component] ?? null)
|
|
72
108
|
: null;
|
|
73
109
|
|
|
74
|
-
// Build serializable block
|
|
75
|
-
|
|
76
|
-
|
|
110
|
+
// Build serializable block-types metadata for the BlockEditor (`blocks` field) and
|
|
111
|
+
// the inline block inserter (`content` field). Both share the same block-type shape.
|
|
112
|
+
const colorPalette = config.admin?.colors ?? [];
|
|
113
|
+
|
|
114
|
+
const toSubFieldMeta = (subField: FieldConfig): SubFieldMeta => ({
|
|
115
|
+
type: subField.type,
|
|
116
|
+
label: subField.label,
|
|
117
|
+
required: subField.required,
|
|
118
|
+
options: "options" in subField ? subField.options : undefined,
|
|
119
|
+
from: "from" in subField ? subField.from : undefined,
|
|
120
|
+
admin: subField.admin,
|
|
121
|
+
colors: subField.admin?.component === "color" ? (subField.admin?.colors ?? colorPalette) : undefined,
|
|
122
|
+
defaultValue: subField.defaultValue,
|
|
123
|
+
of: "of" in subField && subField.of ? { type: subField.of.type } : undefined,
|
|
124
|
+
collection: "collection" in subField ? subField.collection : undefined,
|
|
125
|
+
hasMany: "hasMany" in subField ? subField.hasMany : undefined,
|
|
126
|
+
itemFields:
|
|
127
|
+
"itemFields" in subField && subField.itemFields
|
|
128
|
+
? Object.fromEntries(Object.entries(subField.itemFields).map(([name, f]) => [name, toSubFieldMeta(f)]))
|
|
129
|
+
: undefined,
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
const toBlockTypesMeta = (source: Record<string, Record<string, FieldConfig>> | null | undefined) =>
|
|
133
|
+
source
|
|
77
134
|
? Object.fromEntries(
|
|
78
|
-
Object.entries(
|
|
135
|
+
Object.entries(source).map(([typeName, typeFields]) => [
|
|
79
136
|
typeName,
|
|
80
137
|
Object.fromEntries(
|
|
81
|
-
Object.entries(typeFields).map(([fieldName, subField]) => [
|
|
82
|
-
fieldName,
|
|
83
|
-
{
|
|
84
|
-
type: subField.type,
|
|
85
|
-
label: subField.label,
|
|
86
|
-
required: subField.required,
|
|
87
|
-
options: "options" in subField ? subField.options : undefined,
|
|
88
|
-
from: "from" in subField ? subField.from : undefined,
|
|
89
|
-
admin: subField.admin,
|
|
90
|
-
defaultValue: subField.defaultValue,
|
|
91
|
-
of: "of" in subField && subField.of ? { type: subField.of.type } : undefined,
|
|
92
|
-
collection: "collection" in subField ? subField.collection : undefined,
|
|
93
|
-
hasMany: "hasMany" in subField ? subField.hasMany : undefined,
|
|
94
|
-
},
|
|
95
|
-
]),
|
|
138
|
+
Object.entries(typeFields).map(([fieldName, subField]) => [fieldName, toSubFieldMeta(subField)]),
|
|
96
139
|
),
|
|
97
140
|
]),
|
|
98
141
|
)
|
|
99
142
|
: {};
|
|
143
|
+
|
|
144
|
+
const blockTypesSource = field.type === "blocks" ? field.types : field.type === "content" ? field.blocks : null;
|
|
145
|
+
const blockTypesMeta = toBlockTypesMeta(blockTypesSource);
|
|
146
|
+
const sharedBlockTypesMeta = toBlockTypesMeta(sharedBlockTypes);
|
|
100
147
|
---
|
|
101
148
|
|
|
102
149
|
<div
|
|
@@ -154,8 +201,19 @@ const blockTypesMeta =
|
|
|
154
201
|
/>
|
|
155
202
|
)}
|
|
156
203
|
|
|
204
|
+
{field.type === "text" && field.admin?.component === "color" && !readOnly && (
|
|
205
|
+
<ColorField
|
|
206
|
+
client:load
|
|
207
|
+
name={name}
|
|
208
|
+
value={serializedValue}
|
|
209
|
+
placeholder={placeholder}
|
|
210
|
+
colors={field.admin?.colors ?? colorPalette}
|
|
211
|
+
/>
|
|
212
|
+
)}
|
|
213
|
+
|
|
157
214
|
{(field.type === "text" || field.type === "email" || field.type === "date") &&
|
|
158
215
|
field.admin?.component !== "taxonomy-select" &&
|
|
216
|
+
field.admin?.component !== "color" &&
|
|
159
217
|
(field.type === "text" && field.admin?.rows ? (
|
|
160
218
|
<Textarea
|
|
161
219
|
className={controlClass}
|
|
@@ -226,7 +284,8 @@ const blockTypesMeta =
|
|
|
226
284
|
{field.options.map((option) => (
|
|
227
285
|
<label class="hover:text-foreground flex items-center gap-2 text-sm transition-colors has-disabled:cursor-not-allowed has-disabled:hover:text-current">
|
|
228
286
|
<input
|
|
229
|
-
|
|
287
|
+
data-slot="radio"
|
|
288
|
+
class="border-input hover:border-primary/60 checked:border-primary checked:hover:border-primary disabled:hover:border-input size-4 shrink-0 appearance-none rounded-full border transition-all checked:border-[5px] disabled:cursor-not-allowed"
|
|
230
289
|
type="radio"
|
|
231
290
|
name={name}
|
|
232
291
|
value={option}
|
|
@@ -245,6 +304,7 @@ const blockTypesMeta =
|
|
|
245
304
|
name={name}
|
|
246
305
|
value={Array.isArray(value) ? JSON.stringify(value) : String(value ?? "")}
|
|
247
306
|
hasMany={relationMeta.hasMany}
|
|
307
|
+
maxItems={"maxItems" in field ? field.maxItems : undefined}
|
|
248
308
|
options={relationOptions}
|
|
249
309
|
collectionSlug={relationMeta.collectionSlug}
|
|
250
310
|
collectionLabel={relationMeta.collectionLabel}
|
|
@@ -278,6 +338,32 @@ const blockTypesMeta =
|
|
|
278
338
|
/>
|
|
279
339
|
)}
|
|
280
340
|
|
|
341
|
+
{field.type === "content" && !readOnly && (
|
|
342
|
+
<ContentEditor
|
|
343
|
+
client:load
|
|
344
|
+
name={name}
|
|
345
|
+
label={label}
|
|
346
|
+
initialValue={value ? JSON.stringify(value) : ""}
|
|
347
|
+
rows={rows}
|
|
348
|
+
types={blockTypesMeta}
|
|
349
|
+
blockRelationOptions={blockRelationOptions}
|
|
350
|
+
linkOptions={menuLinkOptions}
|
|
351
|
+
sharedSections={sharedSectionOptions}
|
|
352
|
+
fullscreen={field.fullscreen !== false}
|
|
353
|
+
/>
|
|
354
|
+
)}
|
|
355
|
+
|
|
356
|
+
{field.type === "content" && readOnly && (
|
|
357
|
+
<Textarea
|
|
358
|
+
className={controlClass}
|
|
359
|
+
id={name}
|
|
360
|
+
name={name}
|
|
361
|
+
rows={rows}
|
|
362
|
+
readOnly={readOnly}
|
|
363
|
+
defaultValue={serializedValue}
|
|
364
|
+
/>
|
|
365
|
+
)}
|
|
366
|
+
|
|
281
367
|
{field.type === "json" && field.admin?.component === "menu-items" && !readOnly && (
|
|
282
368
|
<TreeItemsEditor
|
|
283
369
|
client:load
|
|
@@ -293,8 +379,41 @@ const blockTypesMeta =
|
|
|
293
379
|
<TreeItemsEditor client:load name={name} value={serializedValue} variant="taxonomy" label={label} />
|
|
294
380
|
)}
|
|
295
381
|
|
|
382
|
+
{field.type === "json" && field.admin?.component === "shared-section-block" && !readOnly && (
|
|
383
|
+
<SharedSectionBlockField
|
|
384
|
+
client:load
|
|
385
|
+
name={name}
|
|
386
|
+
value={serializedValue}
|
|
387
|
+
types={sharedBlockTypesMeta}
|
|
388
|
+
blockRelationOptions={sharedBlockRelationOptions}
|
|
389
|
+
/>
|
|
390
|
+
)}
|
|
391
|
+
|
|
392
|
+
{field.type === "json" && field.admin?.component === "link" && !readOnly && (
|
|
393
|
+
<LinkField client:load name={name} value={serializedValue} linkOptions={menuLinkOptions} />
|
|
394
|
+
)}
|
|
395
|
+
|
|
396
|
+
{field.type === "json" && field.admin?.component === "repeater" && !readOnly && (
|
|
397
|
+
<RepeaterInput
|
|
398
|
+
client:load
|
|
399
|
+
name={name}
|
|
400
|
+
value={serializedValue}
|
|
401
|
+
itemFields={
|
|
402
|
+
"itemFields" in field && field.itemFields
|
|
403
|
+
? Object.fromEntries(
|
|
404
|
+
Object.entries(field.itemFields).map(([subName, subField]) => [subName, toSubFieldMeta(subField)]),
|
|
405
|
+
)
|
|
406
|
+
: undefined
|
|
407
|
+
}
|
|
408
|
+
linkOptions={menuLinkOptions}
|
|
409
|
+
/>
|
|
410
|
+
)}
|
|
411
|
+
|
|
296
412
|
{field.type === "json" &&
|
|
297
|
-
(field.admin?.component === "menu-items" ||
|
|
413
|
+
(field.admin?.component === "menu-items" ||
|
|
414
|
+
field.admin?.component === "taxonomy-terms" ||
|
|
415
|
+
field.admin?.component === "repeater" ||
|
|
416
|
+
field.admin?.component === "shared-section-block") &&
|
|
298
417
|
readOnly && (
|
|
299
418
|
<Textarea
|
|
300
419
|
className={controlClass}
|
|
@@ -313,6 +432,9 @@ const blockTypesMeta =
|
|
|
313
432
|
value={serializedValue}
|
|
314
433
|
types={blockTypesMeta}
|
|
315
434
|
blockRelationOptions={blockRelationOptions}
|
|
435
|
+
linkOptions={menuLinkOptions}
|
|
436
|
+
sharedSections={"shared" in field && field.shared === false ? [] : sharedSectionOptions}
|
|
437
|
+
sharedEnabled={!("shared" in field && field.shared === false)}
|
|
316
438
|
/>
|
|
317
439
|
)}
|
|
318
440
|
|
|
@@ -342,7 +464,10 @@ const blockTypesMeta =
|
|
|
342
464
|
{((field.type === "array" && !("of" in field && field.of?.type === "text")) ||
|
|
343
465
|
(field.type === "json" &&
|
|
344
466
|
field.admin?.component !== "menu-items" &&
|
|
345
|
-
field.admin?.component !== "taxonomy-terms"
|
|
467
|
+
field.admin?.component !== "taxonomy-terms" &&
|
|
468
|
+
field.admin?.component !== "shared-section-block" &&
|
|
469
|
+
field.admin?.component !== "link" &&
|
|
470
|
+
field.admin?.component !== "repeater")) && (
|
|
346
471
|
<Textarea
|
|
347
472
|
className={controlClass}
|
|
348
473
|
id={name}
|
|
@@ -10,9 +10,11 @@ type Props = {
|
|
|
10
10
|
alt: string;
|
|
11
11
|
focalX: number | null;
|
|
12
12
|
focalY: number | null;
|
|
13
|
+
/** Aspect-ratio renditions to preview (e.g. [{ name: "hero", aspect: "21/9" }]). */
|
|
14
|
+
presets?: Array<{ name: string; aspect: string }>;
|
|
13
15
|
};
|
|
14
16
|
|
|
15
|
-
export default function FocalPointSelector({ src, alt, focalX: initialX, focalY: initialY }: Props) {
|
|
17
|
+
export default function FocalPointSelector({ src, alt, focalX: initialX, focalY: initialY, presets = [] }: Props) {
|
|
16
18
|
const [focalX, setFocalX] = useState<number | null>(initialX);
|
|
17
19
|
const [focalY, setFocalY] = useState<number | null>(initialY);
|
|
18
20
|
const imageRef = useRef<HTMLImageElement>(null);
|
|
@@ -93,6 +95,30 @@ export default function FocalPointSelector({ src, alt, focalX: initialX, focalY:
|
|
|
93
95
|
</div>
|
|
94
96
|
)}
|
|
95
97
|
</div>
|
|
98
|
+
{presets.length > 0 && (
|
|
99
|
+
<div className="space-y-1.5 pt-1">
|
|
100
|
+
<div className="text-muted-foreground text-xs">Crop preview</div>
|
|
101
|
+
<div className="flex flex-wrap gap-2">
|
|
102
|
+
{presets.map((preset) => (
|
|
103
|
+
<div key={preset.name} className="space-y-1">
|
|
104
|
+
<div
|
|
105
|
+
className="bg-muted/30 w-24 overflow-hidden rounded-sm"
|
|
106
|
+
style={{ aspectRatio: preset.aspect.replace(/[:x]/, "/") }}
|
|
107
|
+
>
|
|
108
|
+
<img
|
|
109
|
+
src={src}
|
|
110
|
+
alt=""
|
|
111
|
+
className="size-full object-cover"
|
|
112
|
+
style={{ objectPosition: `${focalX ?? 50}% ${focalY ?? 50}%` }}
|
|
113
|
+
draggable={false}
|
|
114
|
+
/>
|
|
115
|
+
</div>
|
|
116
|
+
<div className="text-muted-foreground text-center text-[10px] capitalize">{preset.name}</div>
|
|
117
|
+
</div>
|
|
118
|
+
))}
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
)}
|
|
96
122
|
<input ref={hiddenXRef} type="hidden" name="focalX" value={focalX ?? ""} />
|
|
97
123
|
<input type="hidden" name="focalY" value={focalY ?? ""} />
|
|
98
124
|
</div>
|
|
@@ -38,15 +38,16 @@ export default function InternalLinkPicker({
|
|
|
38
38
|
<Popover open={open} onOpenChange={setOpen}>
|
|
39
39
|
<PopoverTrigger asChild>
|
|
40
40
|
<Button
|
|
41
|
-
variant="
|
|
41
|
+
variant="input"
|
|
42
42
|
role="combobox"
|
|
43
43
|
aria-expanded={open}
|
|
44
|
-
|
|
44
|
+
size="lg"
|
|
45
|
+
className="w-full justify-between text-sm font-normal"
|
|
45
46
|
>
|
|
46
47
|
<span className={cn("truncate", !selectedLabel && "text-muted-foreground")}>
|
|
47
48
|
{selectedLabel || "Search documents..."}
|
|
48
49
|
</span>
|
|
49
|
-
<ChevronsUpDown className="ml-2 size-
|
|
50
|
+
<ChevronsUpDown className="ml-2 size-4 shrink-0 opacity-50" />
|
|
50
51
|
</Button>
|
|
51
52
|
</PopoverTrigger>
|
|
52
53
|
<PopoverContent className="w-(--radix-popover-trigger-width) p-0" align="start">
|