@kidecms/core 0.32.0 → 0.33.1
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/ContentEditor.tsx +3 -10
- package/admin/components/DocumentsDataTable.tsx +38 -17
- package/admin/components/FieldControl.astro +12 -8
- package/admin/components/ReadOnlyRepeater.astro +41 -0
- package/admin/components/RichTextEditor.tsx +2 -131
- package/admin/components/block-fields.tsx +2 -11
- package/admin/components/block-values.ts +47 -1
- package/admin/components/richtext-tiptap.ts +164 -0
- package/admin/lib/access.ts +16 -0
- package/admin/views/EditView.astro +33 -17
- package/admin/views/ListView.astro +3 -2
- package/core/api.ts +5 -1
- package/core/generator.ts +29 -9
- package/core/values.ts +1 -1
- package/internals/context.ts +8 -3
- package/package.json +1 -1
|
@@ -30,14 +30,8 @@ import { toggleHeading } from "../lib/editor-commands";
|
|
|
30
30
|
import { openPreviewChannel } from "../lib/preview-channel";
|
|
31
31
|
import SharedSectionEditSheet from "./SharedSectionEditSheet";
|
|
32
32
|
import { useSharedSection } from "../lib/use-shared-section";
|
|
33
|
-
import {
|
|
34
|
-
|
|
35
|
-
fetchLinkGroups,
|
|
36
|
-
cmsNodeToTiptap,
|
|
37
|
-
tiptapNodeToCms,
|
|
38
|
-
type CmsNode,
|
|
39
|
-
type LinkGroup,
|
|
40
|
-
} from "./RichTextEditor";
|
|
33
|
+
import { LinkDialog, fetchLinkGroups, type LinkGroup } from "./RichTextEditor";
|
|
34
|
+
import { cmsNodeToTiptap, tiptapNodeToCms, starterKitOptions, type CmsNode } from "./richtext-tiptap";
|
|
41
35
|
import { SubField, humanize, type BlockTypesMeta, type SubFieldMeta } from "./block-fields";
|
|
42
36
|
import type { LinkableCollection } from "./InternalLinkPicker";
|
|
43
37
|
import { blockNodeSpec, BLOCK_NODE_NAME, SHARED_BLOCK_TYPE, type BlockNodeOptions } from "./content-block-spec";
|
|
@@ -495,8 +489,7 @@ export default function ContentEditor({
|
|
|
495
489
|
setBaseline(JSON.stringify(tiptapToContent(editor.getJSON())));
|
|
496
490
|
},
|
|
497
491
|
extensions: [
|
|
498
|
-
|
|
499
|
-
StarterKit.configure({ link: false }),
|
|
492
|
+
StarterKit.configure(starterKitOptions),
|
|
500
493
|
EditorImage,
|
|
501
494
|
Link.configure({
|
|
502
495
|
openOnClick: false,
|
|
@@ -85,6 +85,8 @@ type DocumentsDataTableProps = {
|
|
|
85
85
|
collectionSlug: string;
|
|
86
86
|
draftsEnabled?: boolean;
|
|
87
87
|
duplicateEnabled?: boolean;
|
|
88
|
+
/** Offer Delete on rows and selections; false when the collection's delete rule denies it. */
|
|
89
|
+
deleteEnabled?: boolean;
|
|
88
90
|
/** Show the Locales column. Defaults to true for callers (e.g. Recent) that mix collections. */
|
|
89
91
|
showLocalesColumn?: boolean;
|
|
90
92
|
defaultLocale?: string;
|
|
@@ -156,6 +158,7 @@ export default function DocumentsDataTable({
|
|
|
156
158
|
collectionSlug,
|
|
157
159
|
draftsEnabled = false,
|
|
158
160
|
duplicateEnabled = true,
|
|
161
|
+
deleteEnabled = true,
|
|
159
162
|
showLocalesColumn = true,
|
|
160
163
|
defaultLocale,
|
|
161
164
|
labelField = "title",
|
|
@@ -627,21 +630,35 @@ export default function DocumentsDataTable({
|
|
|
627
630
|
</DropdownMenuItem>
|
|
628
631
|
</>
|
|
629
632
|
)}
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
633
|
+
{deleteEnabled && (
|
|
634
|
+
<>
|
|
635
|
+
<DropdownMenuSeparator />
|
|
636
|
+
<DropdownMenuItem
|
|
637
|
+
variant="destructive"
|
|
638
|
+
disabled={isPending}
|
|
639
|
+
onClick={() => setDeleteConfirm([row.original])}
|
|
640
|
+
>
|
|
641
|
+
Delete
|
|
642
|
+
</DropdownMenuItem>
|
|
643
|
+
</>
|
|
644
|
+
)}
|
|
638
645
|
</DropdownMenuContent>
|
|
639
646
|
</DropdownMenu>
|
|
640
647
|
</div>
|
|
641
648
|
),
|
|
642
649
|
},
|
|
643
650
|
],
|
|
644
|
-
[
|
|
651
|
+
[
|
|
652
|
+
columns,
|
|
653
|
+
draftsEnabled,
|
|
654
|
+
duplicateEnabled,
|
|
655
|
+
deleteEnabled,
|
|
656
|
+
showLocalesColumn,
|
|
657
|
+
isPending,
|
|
658
|
+
primaryColumnKey,
|
|
659
|
+
isServerMode,
|
|
660
|
+
runAction,
|
|
661
|
+
],
|
|
645
662
|
);
|
|
646
663
|
|
|
647
664
|
const table = useReactTable({
|
|
@@ -796,14 +813,18 @@ export default function DocumentsDataTable({
|
|
|
796
813
|
))}
|
|
797
814
|
</>
|
|
798
815
|
)}
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
816
|
+
{deleteEnabled && (
|
|
817
|
+
<>
|
|
818
|
+
<DropdownMenuSeparator />
|
|
819
|
+
<DropdownMenuItem
|
|
820
|
+
variant="destructive"
|
|
821
|
+
disabled={isPending}
|
|
822
|
+
onClick={() => setDeleteConfirm(selectedRows)}
|
|
823
|
+
>
|
|
824
|
+
Delete selected
|
|
825
|
+
</DropdownMenuItem>
|
|
826
|
+
</>
|
|
827
|
+
)}
|
|
807
828
|
</DropdownMenuContent>
|
|
808
829
|
</DropdownMenu>
|
|
809
830
|
)}
|
|
@@ -17,6 +17,7 @@ import SharedSectionBlockField from "./SharedSectionBlockField";
|
|
|
17
17
|
import ColorField from "./ColorField";
|
|
18
18
|
import LinkField from "./LinkField";
|
|
19
19
|
import RepeaterInput from "./RepeaterInput";
|
|
20
|
+
import ReadOnlyRepeater from "./ReadOnlyRepeater.astro";
|
|
20
21
|
import type { SubFieldMeta } from "./block-fields";
|
|
21
22
|
import { Input } from "./ui/input";
|
|
22
23
|
import { Label } from "./ui/label";
|
|
@@ -141,6 +142,12 @@ const toBlockTypesMeta = (source: Record<string, Record<string, FieldConfig>> |
|
|
|
141
142
|
)
|
|
142
143
|
: {};
|
|
143
144
|
|
|
145
|
+
const repeaterItemFields =
|
|
146
|
+
"itemFields" in field && field.itemFields
|
|
147
|
+
? Object.fromEntries(
|
|
148
|
+
Object.entries(field.itemFields).map(([subName, subField]) => [subName, toSubFieldMeta(subField)]),
|
|
149
|
+
)
|
|
150
|
+
: undefined;
|
|
144
151
|
const blockTypesSource = field.type === "blocks" ? field.types : field.type === "content" ? field.blocks : null;
|
|
145
152
|
const blockTypesMeta = toBlockTypesMeta(blockTypesSource);
|
|
146
153
|
const sharedBlockTypesMeta = toBlockTypesMeta(sharedBlockTypes);
|
|
@@ -412,21 +419,18 @@ const sharedBlockTypesMeta = toBlockTypesMeta(sharedBlockTypes);
|
|
|
412
419
|
client:load
|
|
413
420
|
name={name}
|
|
414
421
|
value={serializedValue}
|
|
415
|
-
itemFields={
|
|
416
|
-
"itemFields" in field && field.itemFields
|
|
417
|
-
? Object.fromEntries(
|
|
418
|
-
Object.entries(field.itemFields).map(([subName, subField]) => [subName, toSubFieldMeta(subField)]),
|
|
419
|
-
)
|
|
420
|
-
: undefined
|
|
421
|
-
}
|
|
422
|
+
itemFields={repeaterItemFields}
|
|
422
423
|
linkOptions={linkableCollections}
|
|
423
424
|
/>
|
|
424
425
|
)}
|
|
425
426
|
|
|
427
|
+
{field.type === "json" && field.admin?.component === "repeater" && readOnly && (
|
|
428
|
+
<ReadOnlyRepeater name={name} value={serializedValue} itemFields={repeaterItemFields} />
|
|
429
|
+
)}
|
|
430
|
+
|
|
426
431
|
{field.type === "json" &&
|
|
427
432
|
(field.admin?.component === "menu-items" ||
|
|
428
433
|
field.admin?.component === "taxonomy-terms" ||
|
|
429
|
-
field.admin?.component === "repeater" ||
|
|
430
434
|
field.admin?.component === "shared-section-block") &&
|
|
431
435
|
readOnly && (
|
|
432
436
|
<Textarea
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
---
|
|
2
|
+
import { repeaterTable } from "./block-values";
|
|
3
|
+
import type { SubFieldMeta } from "./block-fields";
|
|
4
|
+
|
|
5
|
+
const { name, value, itemFields } = Astro.props as {
|
|
6
|
+
name: string;
|
|
7
|
+
value?: string;
|
|
8
|
+
itemFields?: Record<string, SubFieldMeta>;
|
|
9
|
+
};
|
|
10
|
+
const { columns, rows } = repeaterTable(value, itemFields);
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
<input type="hidden" name={name} value={value ?? "[]"} />
|
|
14
|
+
{
|
|
15
|
+
rows.length === 0 ? (
|
|
16
|
+
<p class="text-muted-foreground text-sm">No items</p>
|
|
17
|
+
) : (
|
|
18
|
+
<div class="bg-muted/40 overflow-x-auto rounded-md border">
|
|
19
|
+
<table class="w-full text-sm">
|
|
20
|
+
<thead>
|
|
21
|
+
<tr class="border-b">
|
|
22
|
+
{columns.map((column) => (
|
|
23
|
+
<th scope="col" class="text-muted-foreground px-3 py-2 text-left font-medium whitespace-nowrap">
|
|
24
|
+
{column.label}
|
|
25
|
+
</th>
|
|
26
|
+
))}
|
|
27
|
+
</tr>
|
|
28
|
+
</thead>
|
|
29
|
+
<tbody class="divide-y">
|
|
30
|
+
{rows.map((row) => (
|
|
31
|
+
<tr>
|
|
32
|
+
{row.map((cell) => (
|
|
33
|
+
<td class="text-muted-foreground px-3 py-2 align-top">{cell}</td>
|
|
34
|
+
))}
|
|
35
|
+
</tr>
|
|
36
|
+
))}
|
|
37
|
+
</tbody>
|
|
38
|
+
</table>
|
|
39
|
+
</div>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
@@ -29,135 +29,7 @@ import { cn } from "../lib/utils";
|
|
|
29
29
|
import { toggleHeading } from "../lib/editor-commands";
|
|
30
30
|
import { openPreviewChannel } from "../lib/preview-channel";
|
|
31
31
|
import ImageBrowseDialog from "./ImageBrowseDialog";
|
|
32
|
-
|
|
33
|
-
// -----------------------------------------------
|
|
34
|
-
// CMS AST ↔ Tiptap JSON conversion
|
|
35
|
-
// -----------------------------------------------
|
|
36
|
-
|
|
37
|
-
export type CmsNode = {
|
|
38
|
-
type: string;
|
|
39
|
-
value?: string;
|
|
40
|
-
level?: number;
|
|
41
|
-
ordered?: boolean;
|
|
42
|
-
bold?: boolean;
|
|
43
|
-
italic?: boolean;
|
|
44
|
-
children?: CmsNode[];
|
|
45
|
-
[key: string]: unknown;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export type CmsDocument = {
|
|
49
|
-
type: "root";
|
|
50
|
-
children: CmsNode[];
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
export const cmsNodeToTiptap = (node: CmsNode): any => {
|
|
54
|
-
if (node.type === "text") {
|
|
55
|
-
const marks: any[] = [];
|
|
56
|
-
if (node.bold) marks.push({ type: "bold" });
|
|
57
|
-
if (node.italic) marks.push({ type: "italic" });
|
|
58
|
-
if (node.href) marks.push({ type: "link", attrs: { href: node.href, target: node.target ?? null } });
|
|
59
|
-
return { type: "text", text: node.value ?? "", ...(marks.length > 0 ? { marks } : {}) };
|
|
60
|
-
}
|
|
61
|
-
if (node.type === "paragraph") {
|
|
62
|
-
const content = (node.children ?? []).map(cmsNodeToTiptap).filter(Boolean);
|
|
63
|
-
return { type: "paragraph", ...(content.length > 0 ? { content } : {}) };
|
|
64
|
-
}
|
|
65
|
-
if (node.type === "heading") {
|
|
66
|
-
const content = (node.children ?? []).map(cmsNodeToTiptap).filter(Boolean);
|
|
67
|
-
return {
|
|
68
|
-
type: "heading",
|
|
69
|
-
attrs: { level: node.level ?? 2 },
|
|
70
|
-
...(content.length > 0 ? { content } : {}),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
if (node.type === "list") {
|
|
74
|
-
const content = (node.children ?? []).map(cmsNodeToTiptap).filter(Boolean);
|
|
75
|
-
return {
|
|
76
|
-
type: node.ordered ? "orderedList" : "bulletList",
|
|
77
|
-
...(content.length > 0 ? { content } : {}),
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
if (node.type === "list-item") {
|
|
81
|
-
const content = (node.children ?? []).map(cmsNodeToTiptap).filter(Boolean);
|
|
82
|
-
// Tiptap expects list items to contain paragraphs
|
|
83
|
-
const wrapped = content.map((c: any) => (c.type === "paragraph" ? c : { type: "paragraph", content: [c] }));
|
|
84
|
-
return { type: "listItem", ...(wrapped.length > 0 ? { content: wrapped } : {}) };
|
|
85
|
-
}
|
|
86
|
-
if (node.type === "quote") {
|
|
87
|
-
const content = (node.children ?? []).map(cmsNodeToTiptap).filter(Boolean);
|
|
88
|
-
return { type: "blockquote", ...(content.length > 0 ? { content } : {}) };
|
|
89
|
-
}
|
|
90
|
-
if (node.type === "image") {
|
|
91
|
-
return { type: "image", attrs: { src: node.src ?? "", alt: node.alt ?? "", title: node.title ?? "" } };
|
|
92
|
-
}
|
|
93
|
-
return null;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const cmsToTiptap = (doc: CmsDocument | null | undefined): any => {
|
|
97
|
-
if (!doc || doc.type !== "root") {
|
|
98
|
-
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
99
|
-
}
|
|
100
|
-
const content = doc.children.map(cmsNodeToTiptap).filter(Boolean);
|
|
101
|
-
return { type: "doc", content: content.length > 0 ? content : [{ type: "paragraph" }] };
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
export const tiptapNodeToCms = (node: any): CmsNode | null => {
|
|
105
|
-
if (node.type === "text") {
|
|
106
|
-
const result: CmsNode = { type: "text", value: node.text ?? "" };
|
|
107
|
-
if (node.marks) {
|
|
108
|
-
for (const mark of node.marks) {
|
|
109
|
-
if (mark.type === "bold") result.bold = true;
|
|
110
|
-
if (mark.type === "italic") result.italic = true;
|
|
111
|
-
if (mark.type === "link") {
|
|
112
|
-
result.href = mark.attrs?.href ?? "";
|
|
113
|
-
if (mark.attrs?.target) result.target = mark.attrs.target;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
if (node.type === "paragraph") {
|
|
120
|
-
return {
|
|
121
|
-
type: "paragraph",
|
|
122
|
-
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
if (node.type === "heading") {
|
|
126
|
-
return {
|
|
127
|
-
type: "heading",
|
|
128
|
-
level: node.attrs?.level ?? 2,
|
|
129
|
-
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
130
|
-
};
|
|
131
|
-
}
|
|
132
|
-
if (node.type === "bulletList" || node.type === "orderedList") {
|
|
133
|
-
return {
|
|
134
|
-
type: "list",
|
|
135
|
-
ordered: node.type === "orderedList",
|
|
136
|
-
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
if (node.type === "listItem") {
|
|
140
|
-
return {
|
|
141
|
-
type: "list-item",
|
|
142
|
-
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
if (node.type === "blockquote") {
|
|
146
|
-
return {
|
|
147
|
-
type: "quote",
|
|
148
|
-
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
if (node.type === "image") {
|
|
152
|
-
return { type: "image", src: node.attrs?.src ?? "", alt: node.attrs?.alt ?? "", title: node.attrs?.title ?? "" };
|
|
153
|
-
}
|
|
154
|
-
return null;
|
|
155
|
-
};
|
|
156
|
-
|
|
157
|
-
const tiptapToCms = (json: any): CmsDocument => ({
|
|
158
|
-
type: "root",
|
|
159
|
-
children: (json.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
160
|
-
});
|
|
32
|
+
import { starterKitOptions, cmsToTiptap, tiptapToCms } from "./richtext-tiptap";
|
|
161
33
|
|
|
162
34
|
// -----------------------------------------------
|
|
163
35
|
// Toolbar button
|
|
@@ -458,8 +330,7 @@ export default function RichTextEditor({ name, initialValue, rows = 10, onChange
|
|
|
458
330
|
setBaseline(JSON.stringify(tiptapToCms(editor.getJSON())));
|
|
459
331
|
},
|
|
460
332
|
extensions: [
|
|
461
|
-
|
|
462
|
-
StarterKit.configure({ link: false }),
|
|
333
|
+
StarterKit.configure(starterKitOptions),
|
|
463
334
|
EditorImage,
|
|
464
335
|
Markdown,
|
|
465
336
|
Link.configure({
|
|
@@ -71,18 +71,9 @@ export function generateKey() {
|
|
|
71
71
|
return "blk_" + Math.random().toString(36).slice(2, 9);
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
export function humanize(value: string) {
|
|
75
|
-
return value
|
|
76
|
-
.replace(/^_+/, "")
|
|
77
|
-
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
78
|
-
.replace(/[-_]/g, " ")
|
|
79
|
-
.replace(/\s+/g, " ")
|
|
80
|
-
.trim()
|
|
81
|
-
.replace(/^\w/, (char) => char.toUpperCase());
|
|
82
|
-
}
|
|
83
|
-
|
|
84
74
|
// Pure value helpers live in a React-free module so they can be unit-tested.
|
|
85
|
-
export { blankBlockFields, getPreviewText } from "./block-values";
|
|
75
|
+
export { blankBlockFields, getPreviewText, humanize } from "./block-values";
|
|
76
|
+
import { humanize } from "./block-values";
|
|
86
77
|
|
|
87
78
|
// -----------------------------------------------
|
|
88
79
|
// Sub-field label + control wrapper
|
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
// from block-fields.tsx) and unit-tested directly.
|
|
3
3
|
import type { SubFieldMeta } from "./block-fields";
|
|
4
4
|
|
|
5
|
+
export function humanize(value: string) {
|
|
6
|
+
return value
|
|
7
|
+
.replace(/^_+/, "")
|
|
8
|
+
.replace(/([a-z0-9])([A-Z])/g, "$1 $2")
|
|
9
|
+
.replace(/[-_]/g, " ")
|
|
10
|
+
.replace(/\s+/g, " ")
|
|
11
|
+
.trim()
|
|
12
|
+
.replace(/^\w/, (char) => char.toUpperCase());
|
|
13
|
+
}
|
|
14
|
+
|
|
5
15
|
/** Build a blank value object for a freshly inserted block of the given type. */
|
|
6
16
|
export function blankBlockFields(fieldsMeta: Record<string, SubFieldMeta>): Record<string, unknown> {
|
|
7
17
|
const out: Record<string, unknown> = {};
|
|
@@ -27,7 +37,11 @@ const richTextPreview = (value: unknown): string => {
|
|
|
27
37
|
}
|
|
28
38
|
const collect = (node: PreviewNode): string =>
|
|
29
39
|
typeof node.value === "string" ? node.value : (node.children ?? []).map(collect).join(" ");
|
|
30
|
-
return doc && typeof doc === "object"
|
|
40
|
+
return doc && typeof doc === "object"
|
|
41
|
+
? collect(doc as PreviewNode)
|
|
42
|
+
.replace(/\s+/g, " ")
|
|
43
|
+
.trim()
|
|
44
|
+
: "";
|
|
31
45
|
};
|
|
32
46
|
|
|
33
47
|
/**
|
|
@@ -50,3 +64,35 @@ export function getPreviewText(values: Record<string, unknown>, fieldsMeta: Reco
|
|
|
50
64
|
}
|
|
51
65
|
return "";
|
|
52
66
|
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Rows of a repeater value as display text, for read-only rendering. Columns
|
|
70
|
+
* follow `itemFields` when declared, otherwise every key seen in the rows.
|
|
71
|
+
*/
|
|
72
|
+
export function repeaterTable(
|
|
73
|
+
value: unknown,
|
|
74
|
+
itemFields?: Record<string, SubFieldMeta>,
|
|
75
|
+
): { columns: { key: string; label: string }[]; rows: string[][] } {
|
|
76
|
+
let items: unknown = value;
|
|
77
|
+
if (typeof items === "string") {
|
|
78
|
+
try {
|
|
79
|
+
items = JSON.parse(items || "[]");
|
|
80
|
+
} catch {
|
|
81
|
+
items = [];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const rows = (Array.isArray(items) ? items : []).filter(
|
|
85
|
+
(row): row is Record<string, unknown> => !!row && typeof row === "object" && !Array.isArray(row),
|
|
86
|
+
);
|
|
87
|
+
const keys = itemFields ? Object.keys(itemFields) : [...new Set(rows.flatMap((row) => Object.keys(row)))];
|
|
88
|
+
const text = (cell: unknown) => {
|
|
89
|
+
if (cell === null || cell === undefined || cell === "") return "–";
|
|
90
|
+
if (typeof cell === "boolean") return cell ? "Yes" : "No";
|
|
91
|
+
if (typeof cell === "object") return JSON.stringify(cell);
|
|
92
|
+
return String(cell);
|
|
93
|
+
};
|
|
94
|
+
return {
|
|
95
|
+
columns: keys.map((key) => ({ key, label: itemFields?.[key]?.label ?? humanize(key) })),
|
|
96
|
+
rows: rows.map((row) => keys.map((key) => text(row[key]))),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import type { StarterKitOptions } from "@tiptap/starter-kit";
|
|
2
|
+
|
|
3
|
+
// Link is configured separately by each editor. The rest have no CMS AST equivalent and would vanish on save.
|
|
4
|
+
export const starterKitOptions: Partial<StarterKitOptions> = {
|
|
5
|
+
link: false,
|
|
6
|
+
strike: false,
|
|
7
|
+
code: false,
|
|
8
|
+
underline: false,
|
|
9
|
+
codeBlock: false,
|
|
10
|
+
horizontalRule: false,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type CmsNode = {
|
|
14
|
+
type: string;
|
|
15
|
+
value?: string;
|
|
16
|
+
level?: number;
|
|
17
|
+
ordered?: boolean;
|
|
18
|
+
bold?: boolean;
|
|
19
|
+
italic?: boolean;
|
|
20
|
+
children?: CmsNode[];
|
|
21
|
+
[key: string]: unknown;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export type CmsDocument = {
|
|
25
|
+
type: "root";
|
|
26
|
+
children: CmsNode[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const cmsNodeToTiptap = (node: CmsNode): any => {
|
|
30
|
+
if (node.type === "text") {
|
|
31
|
+
const marks: any[] = [];
|
|
32
|
+
if (node.bold) marks.push({ type: "bold" });
|
|
33
|
+
if (node.italic) marks.push({ type: "italic" });
|
|
34
|
+
if (node.href) marks.push({ type: "link", attrs: { href: node.href, target: node.target ?? null } });
|
|
35
|
+
return { type: "text", text: node.value ?? "", ...(marks.length > 0 ? { marks } : {}) };
|
|
36
|
+
}
|
|
37
|
+
if (node.type === "paragraph") {
|
|
38
|
+
const content = cmsChildrenToTiptap(node.children);
|
|
39
|
+
return { type: "paragraph", ...(content.length > 0 ? { content } : {}) };
|
|
40
|
+
}
|
|
41
|
+
if (node.type === "heading") {
|
|
42
|
+
const content = cmsChildrenToTiptap(node.children);
|
|
43
|
+
return {
|
|
44
|
+
type: "heading",
|
|
45
|
+
attrs: { level: node.level ?? 2 },
|
|
46
|
+
...(content.length > 0 ? { content } : {}),
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (node.type === "list") {
|
|
50
|
+
const content = cmsChildrenToTiptap(node.children);
|
|
51
|
+
return {
|
|
52
|
+
type: node.ordered ? "orderedList" : "bulletList",
|
|
53
|
+
...(content.length > 0 ? { content } : {}),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (node.type === "list-item") {
|
|
57
|
+
const content = cmsChildrenToTiptap(node.children);
|
|
58
|
+
// Tiptap expects list items to contain paragraphs; consecutive inline nodes share one.
|
|
59
|
+
const wrapped: any[] = [];
|
|
60
|
+
let inline: any = null;
|
|
61
|
+
for (const c of content) {
|
|
62
|
+
if (c.type === "paragraph") {
|
|
63
|
+
wrapped.push(c);
|
|
64
|
+
inline = null;
|
|
65
|
+
} else if (inline) {
|
|
66
|
+
inline.content.push(c);
|
|
67
|
+
} else {
|
|
68
|
+
inline = { type: "paragraph", content: [c] };
|
|
69
|
+
wrapped.push(inline);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { type: "listItem", ...(wrapped.length > 0 ? { content: wrapped } : {}) };
|
|
73
|
+
}
|
|
74
|
+
if (node.type === "quote") {
|
|
75
|
+
const content = cmsChildrenToTiptap(node.children);
|
|
76
|
+
return { type: "blockquote", ...(content.length > 0 ? { content } : {}) };
|
|
77
|
+
}
|
|
78
|
+
if (node.type === "image") {
|
|
79
|
+
return { type: "image", attrs: { src: node.src ?? "", alt: node.alt ?? "", title: node.title ?? "" } };
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
// Line breaks are stored as "\n" inside text values; Tiptap needs hardBreak nodes.
|
|
85
|
+
const cmsChildrenToTiptap = (children: CmsNode[] = []): any[] =>
|
|
86
|
+
children
|
|
87
|
+
.flatMap((child) => {
|
|
88
|
+
const value = String(child.value ?? "");
|
|
89
|
+
if (child.type !== "text" || !value.includes("\n")) return [cmsNodeToTiptap(child)];
|
|
90
|
+
return value
|
|
91
|
+
.split("\n")
|
|
92
|
+
.flatMap((line, i) => [
|
|
93
|
+
...(i > 0 ? [{ type: "hardBreak" }] : []),
|
|
94
|
+
...(line ? [cmsNodeToTiptap({ ...child, value: line })] : []),
|
|
95
|
+
]);
|
|
96
|
+
})
|
|
97
|
+
.filter(Boolean);
|
|
98
|
+
|
|
99
|
+
export const cmsToTiptap = (doc: CmsDocument | null | undefined): any => {
|
|
100
|
+
if (!doc || doc.type !== "root") {
|
|
101
|
+
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
102
|
+
}
|
|
103
|
+
const content = doc.children.map(cmsNodeToTiptap).filter(Boolean);
|
|
104
|
+
return { type: "doc", content: content.length > 0 ? content : [{ type: "paragraph" }] };
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export const tiptapNodeToCms = (node: any): CmsNode | null => {
|
|
108
|
+
if (node.type === "text") {
|
|
109
|
+
const result: CmsNode = { type: "text", value: node.text ?? "" };
|
|
110
|
+
if (node.marks) {
|
|
111
|
+
for (const mark of node.marks) {
|
|
112
|
+
if (mark.type === "bold") result.bold = true;
|
|
113
|
+
if (mark.type === "italic") result.italic = true;
|
|
114
|
+
if (mark.type === "link") {
|
|
115
|
+
result.href = mark.attrs?.href ?? "";
|
|
116
|
+
if (mark.attrs?.target) result.target = mark.attrs.target;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
if (node.type === "hardBreak") return { type: "text", value: "\n" };
|
|
123
|
+
if (node.type === "paragraph") {
|
|
124
|
+
return {
|
|
125
|
+
type: "paragraph",
|
|
126
|
+
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
if (node.type === "heading") {
|
|
130
|
+
return {
|
|
131
|
+
type: "heading",
|
|
132
|
+
level: node.attrs?.level ?? 2,
|
|
133
|
+
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (node.type === "bulletList" || node.type === "orderedList") {
|
|
137
|
+
return {
|
|
138
|
+
type: "list",
|
|
139
|
+
ordered: node.type === "orderedList",
|
|
140
|
+
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
if (node.type === "listItem") {
|
|
144
|
+
return {
|
|
145
|
+
type: "list-item",
|
|
146
|
+
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
if (node.type === "blockquote") {
|
|
150
|
+
return {
|
|
151
|
+
type: "quote",
|
|
152
|
+
children: (node.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
if (node.type === "image") {
|
|
156
|
+
return { type: "image", src: node.attrs?.src ?? "", alt: node.attrs?.alt ?? "", title: node.attrs?.title ?? "" };
|
|
157
|
+
}
|
|
158
|
+
return null;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const tiptapToCms = (json: any): CmsDocument => ({
|
|
162
|
+
type: "root",
|
|
163
|
+
children: (json.content ?? []).map(tiptapNodeToCms).filter(Boolean),
|
|
164
|
+
});
|
package/admin/lib/access.ts
CHANGED
|
@@ -19,6 +19,22 @@ export function canWrite(config: CMSConfig, user: User, slug: string): boolean {
|
|
|
19
19
|
return rule({ user: user ?? null, doc: null, operation: "create", collection: slug }) as boolean;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
/** Whether the collection's update rule lets this user edit the document. */
|
|
23
|
+
export function canUpdate(config: CMSConfig, user: User, slug: string, doc?: Record<string, unknown> | null): boolean {
|
|
24
|
+
const c = config.collections.find((col) => col.slug === slug);
|
|
25
|
+
const rule = c?.access?.update;
|
|
26
|
+
if (!rule) return c?.auth ? user?.role === "admin" || (!!doc && doc._id === user?.id) : true;
|
|
27
|
+
return rule({ user: user ?? null, doc: doc ?? null, operation: "update", collection: slug }) as boolean;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Whether the collection's delete rule lets this user delete (the document, when given). */
|
|
31
|
+
export function canDelete(config: CMSConfig, user: User, slug: string, doc?: Record<string, unknown> | null): boolean {
|
|
32
|
+
const c = config.collections.find((col) => col.slug === slug);
|
|
33
|
+
const rule = c?.access?.delete;
|
|
34
|
+
if (!rule) return c?.auth ? user?.role === "admin" : true;
|
|
35
|
+
return rule({ user: user ?? null, doc: doc ?? null, operation: "delete", collection: slug }) as boolean;
|
|
36
|
+
}
|
|
37
|
+
|
|
22
38
|
export function isFieldHidden(
|
|
23
39
|
collection: { slug: string; fields: Record<string, any> } | null,
|
|
24
40
|
user: User,
|
|
@@ -26,6 +26,9 @@ import {
|
|
|
26
26
|
resolveCollaboration,
|
|
27
27
|
} from "../../core";
|
|
28
28
|
import {
|
|
29
|
+
canDelete,
|
|
30
|
+
canUpdate,
|
|
31
|
+
canWrite,
|
|
29
32
|
getFormAction,
|
|
30
33
|
getVisualStatus,
|
|
31
34
|
isFieldHidden as isFieldHiddenFn,
|
|
@@ -80,7 +83,8 @@ const collectionApi = cmsRuntime[collection.slug];
|
|
|
80
83
|
const isSingleton = collection.singleton === true;
|
|
81
84
|
|
|
82
85
|
const isFieldHidden = (fieldName: string) => isFieldHiddenFn(collection, user, fieldName);
|
|
83
|
-
|
|
86
|
+
// A document the collection rules won't let this user change renders every field read-only
|
|
87
|
+
const isFieldReadOnly = (fieldName: string) => !docEditable || isFieldReadOnlyFn(collection, user, fieldName);
|
|
84
88
|
|
|
85
89
|
// --- Data loading ---
|
|
86
90
|
let doc: Record<string, unknown> | null = null;
|
|
@@ -104,6 +108,16 @@ if (mode === "edit" && documentId) {
|
|
|
104
108
|
}
|
|
105
109
|
}
|
|
106
110
|
|
|
111
|
+
// Hide actions the access rules would refuse anyway: a document nobody may
|
|
112
|
+
// edit (an ERP mirror, say) gets no Save, and Delete/Duplicate follow their rules
|
|
113
|
+
const docEditable =
|
|
114
|
+
mode === "new" ? canWrite(config, user, collection.slug) : canUpdate(config, user, collection.slug, doc);
|
|
115
|
+
const canSave = Object.keys(collection.fields).some(
|
|
116
|
+
(fieldName) => !isFieldHidden(fieldName) && !isFieldReadOnly(fieldName),
|
|
117
|
+
);
|
|
118
|
+
const canDeleteDoc = canDelete(config, user, collection.slug, doc);
|
|
119
|
+
const canDuplicate = canWrite(config, user, collection.slug);
|
|
120
|
+
|
|
107
121
|
const relationMetaByField = loadRelationMeta(collection, config, user);
|
|
108
122
|
// Seed labels for the ids this document already points at, so relation fields
|
|
109
123
|
// render named selections immediately instead of resolving them client-side.
|
|
@@ -330,20 +344,22 @@ const publishBlocked =
|
|
|
330
344
|
</form>
|
|
331
345
|
) : (
|
|
332
346
|
<>
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
+
{canSave && (
|
|
348
|
+
<button
|
|
349
|
+
class={buttonVariants({ variant: "outline" })}
|
|
350
|
+
type="submit"
|
|
351
|
+
form="document-form"
|
|
352
|
+
name="_intent"
|
|
353
|
+
value="save"
|
|
354
|
+
disabled={mode === "edit"}
|
|
355
|
+
>
|
|
356
|
+
{collection.slug === "users" && mode === "new"
|
|
357
|
+
? "Send invite"
|
|
358
|
+
: collection.drafts
|
|
359
|
+
? "Save draft"
|
|
360
|
+
: "Save"}
|
|
361
|
+
</button>
|
|
362
|
+
)}
|
|
347
363
|
{collection.drafts &&
|
|
348
364
|
(publishBlocked ? (
|
|
349
365
|
<button
|
|
@@ -384,8 +400,8 @@ const publishBlocked =
|
|
|
384
400
|
documentId={documentId}
|
|
385
401
|
showUnpublish={collection.drafts && doc?._status === "published"}
|
|
386
402
|
showDiscardDraft={Boolean(collection.drafts && doc?._status === "published" && doc?._published)}
|
|
387
|
-
showDelete={!isSingleton}
|
|
388
|
-
showDuplicate={!isSingleton && !collection.auth}
|
|
403
|
+
showDelete={!isSingleton && canDeleteDoc}
|
|
404
|
+
showDuplicate={!isSingleton && !collection.auth && canDuplicate}
|
|
389
405
|
showSchedule={!!collection.drafts}
|
|
390
406
|
showCancelSchedule={collection.drafts && doc?._status === "scheduled"}
|
|
391
407
|
currentPublishAt={doc?._publishAt ? String(doc._publishAt) : undefined}
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
humanize,
|
|
19
19
|
resolveCollaboration,
|
|
20
20
|
} from "../../core";
|
|
21
|
-
import { canWrite, getVisualStatus } from "../lib/access";
|
|
21
|
+
import { canDelete, canWrite, getVisualStatus } from "../lib/access";
|
|
22
22
|
import { loadRelationOptionList, loadSharedSectionUsageCounts } from "../lib/edit-data";
|
|
23
23
|
|
|
24
24
|
type CollectionLike = {
|
|
@@ -238,7 +238,8 @@ const tableRows = docs.map((entry: Record<string, unknown>) => {
|
|
|
238
238
|
client:load
|
|
239
239
|
collectionSlug={collection.slug}
|
|
240
240
|
draftsEnabled={collection.drafts}
|
|
241
|
-
duplicateEnabled={!collection.auth}
|
|
241
|
+
duplicateEnabled={!collection.auth && canWrite(config, user, collection.slug)}
|
|
242
|
+
deleteEnabled={canDelete(config, user, collection.slug)}
|
|
242
243
|
showLocalesColumn={showLocalesColumn}
|
|
243
244
|
defaultLocale={locales.length > 1 ? defaultLocale : undefined}
|
|
244
245
|
labelField={getLabelField(collection)}
|
package/core/api.ts
CHANGED
|
@@ -1341,11 +1341,15 @@ export const createCms = (config: CMSConfig) => {
|
|
|
1341
1341
|
}
|
|
1342
1342
|
|
|
1343
1343
|
const timestamp = now();
|
|
1344
|
+
// A pending end date survives publishing, whether the publish comes from
|
|
1345
|
+
// the schedule cron or an editor publishing new edits
|
|
1346
|
+
const unpublishAt =
|
|
1347
|
+
typeof existing._unpublishAt === "string" && existing._unpublishAt > timestamp ? existing._unpublishAt : null;
|
|
1344
1348
|
const updateValues: Record<string, unknown> = {
|
|
1345
1349
|
_status: "published",
|
|
1346
1350
|
_publishedAt: timestamp,
|
|
1347
1351
|
_publishAt: null,
|
|
1348
|
-
_unpublishAt:
|
|
1352
|
+
_unpublishAt: unpublishAt,
|
|
1349
1353
|
_published: null,
|
|
1350
1354
|
};
|
|
1351
1355
|
if (collection.timestamps !== false) updateValues._updatedAt = timestamp;
|
package/core/generator.ts
CHANGED
|
@@ -201,12 +201,10 @@ const generateVersionsTable = (collection: CollectionConfig): string | null => {
|
|
|
201
201
|
});`;
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
+
const SCHEMA_IMPORT_PLACEHOLDER = "/* kide:schema-imports */";
|
|
205
|
+
|
|
204
206
|
const generateSchemaFile = (config: CMSConfig): string => {
|
|
205
|
-
const parts: string[] = [
|
|
206
|
-
`// auto-generated — do not edit`,
|
|
207
|
-
`import { sqliteTable, text, integer, real, unique, index, primaryKey } from "drizzle-orm/sqlite-core";`,
|
|
208
|
-
``,
|
|
209
|
-
];
|
|
207
|
+
const parts: string[] = [`// auto-generated — do not edit`, SCHEMA_IMPORT_PLACEHOLDER, ``];
|
|
210
208
|
|
|
211
209
|
const authSpecs = getAuthSpecs(config);
|
|
212
210
|
|
|
@@ -390,7 +388,12 @@ const generateSchemaFile = (config: CMSConfig): string => {
|
|
|
390
388
|
}
|
|
391
389
|
parts.push(`export const cmsTables = {\n${tableExports.join("\n")}\n};`);
|
|
392
390
|
|
|
393
|
-
|
|
391
|
+
// Import only the builders the schema calls, so generated code lints clean
|
|
392
|
+
const body = parts.join("\n");
|
|
393
|
+
const builders = ["sqliteTable", "text", "integer", "real", "unique", "index", "primaryKey"].filter((name) =>
|
|
394
|
+
new RegExp(`(?<![.\\w])${name}\\(`).test(body),
|
|
395
|
+
);
|
|
396
|
+
return body.replace(SCHEMA_IMPORT_PLACEHOLDER, `import { ${builders.join(", ")} } from "drizzle-orm/sqlite-core";`);
|
|
394
397
|
};
|
|
395
398
|
|
|
396
399
|
const zodTypeForField = (field: FieldConfig): string => {
|
|
@@ -498,10 +501,12 @@ const typeForField = (field: FieldConfig): string => {
|
|
|
498
501
|
return "unknown";
|
|
499
502
|
};
|
|
500
503
|
|
|
504
|
+
const TYPES_IMPORT_PLACEHOLDER = "/* kide:types-imports */";
|
|
505
|
+
|
|
501
506
|
const generateTypesFile = (config: CMSConfig, coreImportPath: string): string => {
|
|
502
507
|
const parts: string[] = [
|
|
503
508
|
`// auto-generated — do not edit`,
|
|
504
|
-
|
|
509
|
+
TYPES_IMPORT_PLACEHOLDER,
|
|
505
510
|
``,
|
|
506
511
|
`export type CMSCollectionSlug = ${config.collections.map((collection) => JSON.stringify(collection.slug)).join(" | ")};`,
|
|
507
512
|
``,
|
|
@@ -551,7 +556,11 @@ const generateTypesFile = (config: CMSConfig, coreImportPath: string): string =>
|
|
|
551
556
|
snapshot: Record<string, unknown>;
|
|
552
557
|
};`);
|
|
553
558
|
|
|
554
|
-
|
|
559
|
+
const body = parts.join("\n");
|
|
560
|
+
const used = ["RichTextDocument", "ContentDocument"].filter((name) => new RegExp(`\\b${name}\\b`).test(body));
|
|
561
|
+
return used.length > 0
|
|
562
|
+
? body.replace(TYPES_IMPORT_PLACEHOLDER, `import type { ${used.join(", ")} } from "${coreImportPath}";`)
|
|
563
|
+
: body.replace(`${TYPES_IMPORT_PLACEHOLDER}\n`, "");
|
|
555
564
|
};
|
|
556
565
|
|
|
557
566
|
const generateApiFile = (
|
|
@@ -570,7 +579,7 @@ const generateApiFile = (
|
|
|
570
579
|
const apiTypes = config.collections
|
|
571
580
|
.map((collection) => {
|
|
572
581
|
const baseName = pascalCase(collection.slug);
|
|
573
|
-
const ctx = `context?:
|
|
582
|
+
const ctx = `context?: CmsContext`;
|
|
574
583
|
const apiKey = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(collection.slug) ? collection.slug : `"${collection.slug}"`;
|
|
575
584
|
return ` ${apiKey}: {
|
|
576
585
|
find(options?: import("${coreImportPath}").FindOptions, ${ctx}): Promise<${baseName}Document[]>;
|
|
@@ -581,6 +590,7 @@ const generateApiFile = (
|
|
|
581
590
|
upsert(data: ${baseName}Input & { _id?: string }, ${ctx}): Promise<${baseName}Document>;
|
|
582
591
|
update(id: string, data: Partial<${baseName}Input>, ${ctx}): Promise<${baseName}Document>;
|
|
583
592
|
delete(id: string, ${ctx}): Promise<void>;
|
|
593
|
+
deleteMany(where?: import("${coreImportPath}").FindOptions["where"], ${ctx}): Promise<number>;
|
|
584
594
|
count(filter?: Omit<import("${coreImportPath}").FindOptions, "limit" | "offset" | "sort">, ${ctx}): Promise<number>;
|
|
585
595
|
versions(id: string, ${ctx}): Promise<import("./types").StoredVersion[]>;
|
|
586
596
|
restore(id: string, versionNumber: number, ${ctx}): Promise<${baseName}Document>;
|
|
@@ -600,10 +610,20 @@ import type {
|
|
|
600
610
|
${imports.map((entry) => `${entry},`).join("\n ")}
|
|
601
611
|
} from "./types";
|
|
602
612
|
|
|
613
|
+
export type CmsContext = {
|
|
614
|
+
user?: { id: string; role?: string; email?: string; [key: string]: unknown } | null;
|
|
615
|
+
cache?: { invalidate: (opts: { tags: string[] }) => void | Promise<void> };
|
|
616
|
+
/** Bypass access rules (server-side / system operations). */
|
|
617
|
+
_system?: boolean;
|
|
618
|
+
/** Skip search indexing for bulk writes; reindex once afterwards. */
|
|
619
|
+
_skipSearch?: boolean;
|
|
620
|
+
};
|
|
621
|
+
|
|
603
622
|
export const cms = createCms(config) as {
|
|
604
623
|
${apiTypes}
|
|
605
624
|
meta: ReturnType<typeof createCms>["meta"];
|
|
606
625
|
scheduled: ReturnType<typeof createCms>["scheduled"];
|
|
626
|
+
tasks: ReturnType<typeof createCms>["tasks"];
|
|
607
627
|
};
|
|
608
628
|
`;
|
|
609
629
|
};
|
package/core/values.ts
CHANGED
|
@@ -309,7 +309,7 @@ export const resolveLinkUrl = async (
|
|
|
309
309
|
|
|
310
310
|
const renderNode = (node: RichTextNode): string => {
|
|
311
311
|
if (node.type === "text") {
|
|
312
|
-
let content = escapeHtml(String(node.value ?? ""));
|
|
312
|
+
let content = escapeHtml(String(node.value ?? "")).replaceAll("\n", "<br />");
|
|
313
313
|
if (node.bold) content = `<strong>${content}</strong>`;
|
|
314
314
|
if (node.italic) content = `<em>${content}</em>`;
|
|
315
315
|
if (node.href) {
|
package/internals/context.ts
CHANGED
|
@@ -32,10 +32,15 @@ import {
|
|
|
32
32
|
} from "../core";
|
|
33
33
|
import { loadProjectConfig, loadProjectRuntime } from "./project";
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Pass the generated API type to get typed collections in scripts:
|
|
37
|
+
*
|
|
38
|
+
* const { cms } = await createCmsContext<typeof import("@/cms/.generated/api").cms>();
|
|
39
|
+
*/
|
|
40
|
+
export const createCmsContext = async <TCms = ReturnType<typeof createCms>>() => {
|
|
36
41
|
await loadProjectRuntime(); // side effect: configureCmsRuntime()
|
|
37
42
|
const config = await loadProjectConfig();
|
|
38
|
-
const cms = createCms(config);
|
|
43
|
+
const cms = createCms(config) as TCms;
|
|
39
44
|
const db = await getDb();
|
|
40
45
|
return {
|
|
41
46
|
/** Typed local API: `cms.posts.create(...)`, `cms.pages.deleteMany(...)`, … */
|
|
@@ -51,7 +56,7 @@ export const createCmsContext = async () => {
|
|
|
51
56
|
load: (
|
|
52
57
|
items: ImportItem[],
|
|
53
58
|
options?: { dryRun?: boolean; throwOnFailed?: boolean; context?: Record<string, unknown> },
|
|
54
|
-
) => importDocuments(cms as Record<string, any>, config, items, options),
|
|
59
|
+
) => importDocuments(cms as unknown as Record<string, any>, config, items, options),
|
|
55
60
|
/** The machine-readable content model (same as `.kide/model.json`). */
|
|
56
61
|
model: () => describeModel(config),
|
|
57
62
|
/** Rebuild the search index for all searchable collections (uses this config's locales). */
|