@kidecms/core 0.1.10 → 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.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/admin/components/AssetsGrid.tsx +366 -173
  3. package/admin/components/BlockEditor.tsx +260 -679
  4. package/admin/components/CheckboxField.tsx +2 -2
  5. package/admin/components/CollaborationReviewBar.tsx +384 -0
  6. package/admin/components/ColorField.tsx +87 -0
  7. package/admin/components/CommandPalette.tsx +169 -0
  8. package/admin/components/ContentEditor.tsx +687 -0
  9. package/admin/components/DocumentActions.tsx +4 -2
  10. package/admin/components/DocumentsDataTable.tsx +91 -10
  11. package/admin/components/FieldControl.astro +151 -26
  12. package/admin/components/FocalPointSelector.tsx +27 -1
  13. package/admin/components/InternalLinkPicker.tsx +4 -3
  14. package/admin/components/LinkField.tsx +126 -0
  15. package/admin/components/RelationField.tsx +105 -26
  16. package/admin/components/RepeaterInput.tsx +46 -0
  17. package/admin/components/RichTextEditor.tsx +44 -9
  18. package/admin/components/SharedSectionBlockField.tsx +93 -0
  19. package/admin/components/SidebarUserMenu.tsx +1 -1
  20. package/admin/components/Toast.astro +1 -1
  21. package/admin/components/TreeItemsEditor.tsx +20 -19
  22. package/admin/components/TreeSelect.tsx +2 -2
  23. package/admin/components/YoutubeField.tsx +48 -0
  24. package/admin/components/block-fields.tsx +777 -0
  25. package/admin/components/content-block-spec.ts +114 -0
  26. package/admin/components/slash-command.tsx +242 -0
  27. package/admin/components/tree-utils.ts +14 -2
  28. package/admin/components/ui/badge.tsx +2 -3
  29. package/admin/components/ui/button.tsx +5 -4
  30. package/admin/components/ui/checkbox.tsx +1 -1
  31. package/admin/components/ui/input.tsx +1 -1
  32. package/admin/components/ui/select.tsx +1 -1
  33. package/admin/components/ui/table.tsx +1 -1
  34. package/admin/components/ui/textarea.tsx +1 -1
  35. package/admin/layouts/AdminLayout.astro +323 -123
  36. package/admin/lib/access.ts +54 -0
  37. package/admin/lib/collaboration.ts +178 -0
  38. package/admin/lib/edit-data.ts +448 -0
  39. package/admin/views/AccessDeniedView.astro +8 -0
  40. package/admin/views/EditView.astro +706 -0
  41. package/admin/views/ListView.astro +202 -0
  42. package/admin/views/RecentView.astro +76 -0
  43. package/admin/views/SinglesView.astro +65 -0
  44. package/admin/views/edit/EditScripts.astro +145 -0
  45. package/admin/views/edit/ReverseReferencesList.astro +68 -0
  46. package/core/admin.ts +193 -0
  47. package/core/ai.ts +87 -0
  48. package/core/api.ts +1392 -0
  49. package/core/assets.ts +336 -0
  50. package/core/audit.ts +84 -0
  51. package/core/auth-config.ts +44 -0
  52. package/core/auth.ts +303 -0
  53. package/core/collaboration.ts +276 -0
  54. package/core/content.ts +27 -0
  55. package/core/create-admin.ts +28 -0
  56. package/core/define.ts +625 -0
  57. package/core/field-model.ts +172 -0
  58. package/core/generator.ts +519 -0
  59. package/core/http.ts +42 -0
  60. package/core/image.ts +219 -0
  61. package/core/index.ts +211 -0
  62. package/core/locks.ts +52 -0
  63. package/core/log.ts +37 -0
  64. package/core/migrate.ts +278 -0
  65. package/core/rate-limit.ts +110 -0
  66. package/core/request-scope.ts +33 -0
  67. package/core/richtext.ts +1 -0
  68. package/core/runtime.ts +63 -0
  69. package/core/schema.ts +32 -0
  70. package/core/search.ts +489 -0
  71. package/core/seed.ts +101 -0
  72. package/core/shared-sections.ts +96 -0
  73. package/core/tasks.ts +176 -0
  74. package/core/values.ts +433 -0
  75. package/core/webhooks.ts +85 -0
  76. package/core/youtube.ts +39 -0
  77. package/internals/cli.mjs +34 -0
  78. package/internals/context.ts +67 -0
  79. package/internals/create-admin.ts +40 -0
  80. package/internals/describe.ts +25 -0
  81. package/internals/eject.ts +144 -0
  82. package/internals/generator.ts +11 -0
  83. package/internals/integration.ts +481 -0
  84. package/internals/mcp.ts +397 -0
  85. package/internals/project.ts +26 -0
  86. package/internals/push.ts +160 -0
  87. package/internals/reindex.ts +11 -0
  88. package/internals/restore.ts +257 -0
  89. package/internals/seed.data.ts +7 -0
  90. package/internals/seed.ts +11 -0
  91. package/internals/upgrade.ts +776 -0
  92. package/{virtual.d.ts → internals/virtual.d.ts} +39 -5
  93. package/middleware/auth.ts +130 -17
  94. package/middleware/push.ts +121 -0
  95. package/package.json +55 -67
  96. package/platform/cloudflare/cf-env.ts +60 -0
  97. package/platform/cloudflare/database.ts +28 -0
  98. package/platform/cloudflare/globals.d.ts +5 -0
  99. package/platform/cloudflare/storage.ts +33 -0
  100. package/platform/cloudflare/uploads-route.ts +37 -0
  101. package/platform/node/database.ts +39 -0
  102. package/platform/node/storage.ts +52 -0
  103. package/routes/admin/[...path].astro +71 -0
  104. package/routes/{pages/admin → admin}/assets/[id].astro +25 -19
  105. package/routes/admin/assets/index.astro +90 -0
  106. package/routes/admin/forgot-password.astro +60 -0
  107. package/routes/{pages/admin → admin}/invite.astro +7 -6
  108. package/routes/admin/login.astro +103 -0
  109. package/routes/admin/reset-password.astro +73 -0
  110. package/routes/{pages/admin → admin}/setup.astro +32 -8
  111. package/routes/api/{cms/[collection] → [collection]}/[...path].ts +66 -14
  112. package/routes/api/admin/search.ts +89 -0
  113. package/routes/api/{cms/assets → assets}/[id].ts +24 -14
  114. package/routes/api/{cms/assets → assets}/index.ts +4 -2
  115. package/routes/api/assets/upload.ts +147 -0
  116. package/routes/api/auth/forgot-password.ts +77 -0
  117. package/routes/api/{cms/auth → auth}/invite.ts +41 -9
  118. package/routes/api/auth/login.ts +167 -0
  119. package/routes/api/{cms/auth → auth}/logout.ts +11 -2
  120. package/routes/api/auth/reset-password.ts +85 -0
  121. package/routes/api/auth/setup.ts +110 -0
  122. package/routes/api/auth/sso/[provider]/start.ts +34 -0
  123. package/routes/api/collaboration/index.ts +106 -0
  124. package/routes/api/cron/_authorize.ts +25 -0
  125. package/routes/api/{cms/cron → cron}/publish.ts +3 -9
  126. package/routes/api/cron/tasks.ts +33 -0
  127. package/routes/api/forms/submit/[slug].ts +143 -0
  128. package/routes/api/img/[...path].ts +65 -0
  129. package/routes/api/{cms/preview → preview}/render.ts +8 -3
  130. package/routes/api/{cms/references → references}/[collection]/[id].ts +31 -1
  131. package/routes/api/webhooks/[provider].ts +54 -0
  132. package/README.md +0 -28
  133. package/dist/admin.d.ts +0 -33
  134. package/dist/admin.js +0 -92
  135. package/dist/ai.d.ts +0 -15
  136. package/dist/ai.js +0 -70
  137. package/dist/api.d.ts +0 -14
  138. package/dist/api.js +0 -833
  139. package/dist/assets.d.ts +0 -51
  140. package/dist/assets.js +0 -163
  141. package/dist/auth.d.ts +0 -30
  142. package/dist/auth.js +0 -132
  143. package/dist/content.d.ts +0 -3
  144. package/dist/content.js +0 -29
  145. package/dist/create-admin.d.ts +0 -5
  146. package/dist/create-admin.js +0 -23
  147. package/dist/define.d.ts +0 -254
  148. package/dist/define.js +0 -36
  149. package/dist/generator.d.ts +0 -9
  150. package/dist/generator.js +0 -370
  151. package/dist/image.d.ts +0 -9
  152. package/dist/image.js +0 -69
  153. package/dist/index.d.ts +0 -28
  154. package/dist/index.js +0 -16
  155. package/dist/integration.d.ts +0 -14
  156. package/dist/integration.js +0 -327
  157. package/dist/locks.d.ts +0 -7
  158. package/dist/locks.js +0 -37
  159. package/dist/richtext.d.ts +0 -1
  160. package/dist/richtext.js +0 -1
  161. package/dist/runtime.d.ts +0 -24
  162. package/dist/runtime.js +0 -26
  163. package/dist/schema.d.ts +0 -17
  164. package/dist/schema.js +0 -13
  165. package/dist/seed.d.ts +0 -2
  166. package/dist/seed.js +0 -84
  167. package/dist/values.d.ts +0 -8
  168. package/dist/values.js +0 -102
  169. package/dist/webhooks.d.ts +0 -2
  170. package/dist/webhooks.js +0 -73
  171. package/routes/api/cms/assets/upload.ts +0 -112
  172. package/routes/api/cms/auth/login.ts +0 -124
  173. package/routes/api/cms/auth/setup.ts +0 -77
  174. package/routes/api/cms/img/[...path].ts +0 -24
  175. package/routes/pages/admin/[...path].astro +0 -1107
  176. package/routes/pages/admin/assets/index.astro +0 -63
  177. package/routes/pages/admin/login.astro +0 -57
  178. /package/routes/api/{cms/ai → ai}/alt-text.ts +0 -0
  179. /package/routes/api/{cms/ai → ai}/seo.ts +0 -0
  180. /package/routes/api/{cms/ai → ai}/translate.ts +0 -0
  181. /package/routes/api/{cms/assets → assets}/folders.ts +0 -0
  182. /package/routes/api/{cms/locks → locks}/[...path].ts +0 -0
@@ -0,0 +1,126 @@
1
+ "use client";
2
+
3
+ import { useEffect, useRef, useState } from "react";
4
+ import { Checkbox } from "./ui/checkbox";
5
+ import { Input } from "./ui/input";
6
+ import { Label } from "./ui/label";
7
+ import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
8
+ import InternalLinkPicker, { type LinkOptionGroup } from "./InternalLinkPicker";
9
+
10
+ // A structured link control: URL + label + open-in-new-tab, stored as
11
+ // { type, url, label, newTab }. A leading "/" is treated as an internal link.
12
+ // When linkOptions are provided, internal links are chosen with a document
13
+ // picker instead of a hand-typed path (which silently breaks on slug edits).
14
+ type LinkValue = { type?: string; url?: string; label?: string; newTab?: boolean };
15
+
16
+ type Props = {
17
+ name?: string;
18
+ value?: string | LinkValue;
19
+ onChange?: (value: LinkValue) => void;
20
+ linkOptions?: LinkOptionGroup[];
21
+ };
22
+
23
+ function parse(v: unknown): LinkValue {
24
+ if (!v) return {};
25
+ if (typeof v === "string") {
26
+ const s = v.trim();
27
+ if (!s) return {};
28
+ try {
29
+ return JSON.parse(s) as LinkValue;
30
+ } catch {
31
+ return { url: s };
32
+ }
33
+ }
34
+ return v as LinkValue;
35
+ }
36
+
37
+ export default function LinkField({ name, value: initial, onChange, linkOptions = [] }: Props) {
38
+ const [value, setValue] = useState<LinkValue>(parse(initial));
39
+ const [linkType, setLinkType] = useState<"internal" | "external">(() => {
40
+ const url = parse(initial).url ?? "";
41
+ if (url) return url.startsWith("/") ? "internal" : "external";
42
+ return linkOptions.length > 0 ? "internal" : "external";
43
+ });
44
+ const hiddenRef = useRef<HTMLInputElement>(null);
45
+ const isInitial = useRef(true);
46
+
47
+ useEffect(() => {
48
+ if (isInitial.current) {
49
+ isInitial.current = false;
50
+ return;
51
+ }
52
+ hiddenRef.current?.dispatchEvent(new Event("change", { bubbles: true }));
53
+ }, [value]);
54
+
55
+ const set = (patch: Partial<LinkValue>) => {
56
+ const next: LinkValue = { ...value, ...patch };
57
+ if (next.url) next.type = next.url.startsWith("/") ? "internal" : "external";
58
+ setValue(next);
59
+ onChange?.(next);
60
+ };
61
+
62
+ const hasPicker = linkOptions.length > 0;
63
+
64
+ return (
65
+ <div className="space-y-2 rounded-md border p-3">
66
+ {name && <input type="hidden" name={name} value={value.url ? JSON.stringify(value) : ""} ref={hiddenRef} />}
67
+ <div className="grid gap-1">
68
+ <Label className="text-xs">{hasPicker ? "Link" : "URL"}</Label>
69
+ {hasPicker ? (
70
+ <div className="flex items-center gap-2">
71
+ <Select
72
+ items={[
73
+ { value: "internal", label: "Internal" },
74
+ { value: "external", label: "External" },
75
+ ]}
76
+ value={linkType}
77
+ onValueChange={(v) => setLinkType((v as "internal" | "external") ?? "internal")}
78
+ >
79
+ <SelectTrigger className="w-28 shrink-0 text-sm">
80
+ <SelectValue />
81
+ </SelectTrigger>
82
+ <SelectContent>
83
+ <SelectGroup>
84
+ <SelectItem value="internal">Internal</SelectItem>
85
+ <SelectItem value="external">External</SelectItem>
86
+ </SelectGroup>
87
+ </SelectContent>
88
+ </Select>
89
+ {linkType === "internal" ? (
90
+ <InternalLinkPicker
91
+ editHref={value.url ?? ""}
92
+ linkOptions={linkOptions}
93
+ onSelect={(item) => set({ url: item.href, ...(value.label ? {} : { label: item.label }) })}
94
+ />
95
+ ) : (
96
+ <Input
97
+ value={value.url ?? ""}
98
+ placeholder="https://example.com"
99
+ onChange={(e) => set({ url: e.target.value })}
100
+ />
101
+ )}
102
+ </div>
103
+ ) : (
104
+ <Input
105
+ value={value.url ?? ""}
106
+ placeholder="https://example.com or /about"
107
+ onChange={(e) => set({ url: e.target.value })}
108
+ />
109
+ )}
110
+ </div>
111
+ <div className="grid gap-1">
112
+ <Label className="text-xs">Label</Label>
113
+ <Input value={value.label ?? ""} placeholder="Link text" onChange={(e) => set({ label: e.target.value })} />
114
+ </div>
115
+ <label className="text-muted-foreground group inline-flex cursor-pointer items-center gap-2 text-sm">
116
+ <Checkbox
117
+ className="group-hover:border-primary/60"
118
+ checked={!!value.newTab}
119
+ onCheckedChange={(checked) => set({ newTab: Boolean(checked) })}
120
+ />
121
+ Open in new tab
122
+ {value.url && <span className="ml-auto text-xs">({value.type})</span>}
123
+ </label>
124
+ </div>
125
+ );
126
+ }
@@ -1,7 +1,18 @@
1
1
  "use client";
2
2
 
3
3
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
4
- import { Check, ChevronsUpDown, Plus, X } from "lucide-react";
4
+ import {
5
+ DndContext,
6
+ KeyboardSensor,
7
+ PointerSensor,
8
+ closestCenter,
9
+ useSensor,
10
+ useSensors,
11
+ type DragEndEvent,
12
+ } from "@dnd-kit/core";
13
+ import { SortableContext, arrayMove, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
14
+ import { CSS } from "@dnd-kit/utilities";
15
+ import { Check, ChevronsUpDown, GripVertical, Plus, Trash2 } from "lucide-react";
5
16
 
6
17
  import { Button } from "./ui/button";
7
18
  import { Command, CommandEmpty, CommandInput, CommandItem, CommandList } from "./ui/command";
@@ -15,16 +26,72 @@ type Props = {
15
26
  name: string;
16
27
  value?: string;
17
28
  hasMany?: boolean;
29
+ maxItems?: number;
18
30
  options: Option[];
19
31
  collectionSlug: string;
20
32
  collectionLabel: string;
21
33
  labelField?: string;
22
34
  };
23
35
 
36
+ /**
37
+ * One selected document as a full-width draggable row — hasMany order is data,
38
+ * so it is editable. Mirrors the repeater's row anatomy (grip, #index, remove)
39
+ * for a consistent, easy-to-grab drag target.
40
+ */
41
+ function SortableRow({
42
+ id,
43
+ index,
44
+ label,
45
+ onRemove,
46
+ }: {
47
+ id: string;
48
+ index: number;
49
+ label: string;
50
+ onRemove: () => void;
51
+ }) {
52
+ const { attributes, listeners, setNodeRef, setActivatorNodeRef, transform, transition, isDragging } = useSortable({
53
+ id,
54
+ });
55
+ return (
56
+ <div
57
+ ref={setNodeRef}
58
+ style={{ transform: CSS.Transform.toString(transform), transition }}
59
+ className={cn(
60
+ "bg-muted-strong/50 has-[[data-drag-handle]:hover]:bg-muted-strong/70 flex items-center gap-2 rounded-lg border px-3 py-2 transition-colors",
61
+ isDragging && "z-10 opacity-90 shadow-lg",
62
+ )}
63
+ >
64
+ <button
65
+ type="button"
66
+ ref={setActivatorNodeRef}
67
+ data-drag-handle
68
+ className="text-muted-foreground/50 hover:text-muted-foreground -ml-1 cursor-grab touch-none rounded p-1 transition-colors active:cursor-grabbing"
69
+ {...attributes}
70
+ {...listeners}
71
+ >
72
+ <GripVertical className="size-4" />
73
+ </button>
74
+ <span className="text-muted-foreground text-xs font-medium">#{index + 1}</span>
75
+ <span className="min-w-0 flex-1 truncate text-sm">{label}</span>
76
+ <Button
77
+ type="button"
78
+ variant="ghost"
79
+ size="icon"
80
+ title="Remove"
81
+ className="text-muted-foreground hover:text-destructive size-7"
82
+ onClick={onRemove}
83
+ >
84
+ <Trash2 className="size-3.5" />
85
+ </Button>
86
+ </div>
87
+ );
88
+ }
89
+
24
90
  export default function RelationField({
25
91
  name,
26
92
  value: initialValue,
27
93
  hasMany = false,
94
+ maxItems,
28
95
  options: initialOptions,
29
96
  collectionSlug,
30
97
  collectionLabel,
@@ -57,15 +124,21 @@ export default function RelationField({
57
124
 
58
125
  const getLabel = useCallback((id: string) => options.find((o) => o.value === id)?.label ?? id, [options]);
59
126
 
127
+ const atMax = hasMany && maxItems !== undefined && selected.length >= maxItems;
128
+
60
129
  const displayLabel = useMemo(() => {
61
130
  if (selected.length === 0) return "";
62
- if (hasMany) return `${selected.length} selected`;
131
+ if (hasMany) return maxItems ? `${selected.length}/${maxItems} selected` : `${selected.length} selected`;
63
132
  return getLabel(selected[0]);
64
- }, [selected, hasMany, getLabel]);
133
+ }, [selected, hasMany, maxItems, getLabel]);
65
134
 
66
135
  const selectItem = (id: string) => {
67
136
  if (hasMany) {
68
- setSelected((prev) => (prev.includes(id) ? prev.filter((v) => v !== id) : [...prev, id]));
137
+ setSelected((prev) => {
138
+ if (prev.includes(id)) return prev.filter((v) => v !== id);
139
+ if (maxItems !== undefined && prev.length >= maxItems) return prev;
140
+ return [...prev, id];
141
+ });
69
142
  } else {
70
143
  setSelected((prev) => (prev[0] === id ? [] : [id]));
71
144
  setOpen(false);
@@ -76,6 +149,16 @@ export default function RelationField({
76
149
  setSelected((prev) => prev.filter((v) => v !== id));
77
150
  };
78
151
 
152
+ const sensors = useSensors(
153
+ useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
154
+ useSensor(KeyboardSensor),
155
+ );
156
+ const handleDragEnd = (event: DragEndEvent) => {
157
+ const { active, over } = event;
158
+ if (!over || active.id === over.id) return;
159
+ setSelected((prev) => arrayMove(prev, prev.indexOf(String(active.id)), prev.indexOf(String(over.id))));
160
+ };
161
+
79
162
  // Listen for postMessage from embedded iframe after successful save
80
163
  useEffect(() => {
81
164
  if (!sheetOpen) return;
@@ -112,37 +195,28 @@ export default function RelationField({
112
195
  <div className="space-y-2">
113
196
  <input ref={hiddenRef} type="hidden" name={name} value={hiddenValue} />
114
197
 
115
- {/* Selected items (hasMany chips) */}
198
+ {/* Selected items (hasMany rows) — drag to reorder; the stored order is the render order */}
116
199
  {hasMany && selected.length > 0 && (
117
- <div className="flex flex-wrap gap-1.5">
118
- {selected.map((id) => (
119
- <span
120
- key={id}
121
- className="bg-secondary text-secondary-foreground inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-sm"
122
- >
123
- {getLabel(id)}
124
- <button
125
- type="button"
126
- title="Remove"
127
- onClick={() => remove(id)}
128
- className="text-muted-foreground hover:text-foreground -mr-0.5 rounded p-0.5"
129
- >
130
- <X className="size-3" />
131
- </button>
132
- </span>
133
- ))}
134
- </div>
200
+ <DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={handleDragEnd}>
201
+ <SortableContext items={selected} strategy={verticalListSortingStrategy}>
202
+ <div className="grid gap-2">
203
+ {selected.map((id, index) => (
204
+ <SortableRow key={id} id={id} index={index} label={getLabel(id)} onRemove={() => remove(id)} />
205
+ ))}
206
+ </div>
207
+ </SortableContext>
208
+ </DndContext>
135
209
  )}
136
210
 
137
211
  {/* Combobox */}
138
212
  <Popover open={open} onOpenChange={setOpen}>
139
213
  <PopoverTrigger asChild>
140
214
  <Button
141
- variant="outline"
215
+ variant="input"
142
216
  role="combobox"
143
217
  aria-expanded={open}
144
218
  size="lg"
145
- className="border-input bg-muted/30 hover:bg-muted dark:bg-input/30 dark:hover:bg-input/50 w-full justify-between text-base font-normal"
219
+ className="w-full justify-between text-sm font-normal"
146
220
  >
147
221
  <span className={cn("truncate", !displayLabel && "text-muted-foreground")}>
148
222
  {displayLabel || `Search ${collectionLabel.toLowerCase()}...`}
@@ -156,7 +230,12 @@ export default function RelationField({
156
230
  <CommandList>
157
231
  <CommandEmpty>No results found.</CommandEmpty>
158
232
  {options.map((o) => (
159
- <CommandItem key={o.value} value={o.label} onSelect={() => selectItem(o.value)}>
233
+ <CommandItem
234
+ key={o.value}
235
+ value={o.label}
236
+ onSelect={() => selectItem(o.value)}
237
+ className={cn(atMax && !selected.includes(o.value) && "opacity-40")}
238
+ >
160
239
  <Check className={cn("ml-1 size-4", selected.includes(o.value) ? "opacity-100" : "opacity-0")} />
161
240
  {o.label}
162
241
  </CommandItem>
@@ -0,0 +1,46 @@
1
+ import { useState } from "react";
2
+
3
+ import { RepeaterField, type RelationOption, type SubFieldMeta } from "./block-fields";
4
+ import type { LinkOptionGroup } from "./InternalLinkPicker";
5
+
6
+ /**
7
+ * Standalone form control for top-level repeater fields —
8
+ * `fields.json({ admin: { component: "repeater" }, itemFields })` on a
9
+ * collection. Wraps the block editor's RepeaterField (sortable rows, typed
10
+ * sub-field controls, link picker) and mirrors its value into a hidden input
11
+ * so the plain document form submits it as JSON.
12
+ */
13
+ export default function RepeaterInput({
14
+ name,
15
+ value,
16
+ itemFields,
17
+ relationOptions,
18
+ linkOptions,
19
+ }: {
20
+ name: string;
21
+ value?: string;
22
+ itemFields?: Record<string, SubFieldMeta>;
23
+ relationOptions?: RelationOption[];
24
+ linkOptions?: LinkOptionGroup[];
25
+ }) {
26
+ const [items, setItems] = useState<unknown>(() => {
27
+ try {
28
+ return JSON.parse(value || "[]");
29
+ } catch {
30
+ return [];
31
+ }
32
+ });
33
+ return (
34
+ <div className="grid gap-2">
35
+ <input type="hidden" name={name} value={JSON.stringify(items ?? [])} />
36
+ <RepeaterField
37
+ blockKey={name}
38
+ itemFields={itemFields}
39
+ relationOptions={relationOptions}
40
+ linkOptions={linkOptions}
41
+ value={items}
42
+ onChange={setItems}
43
+ />
44
+ </div>
45
+ );
46
+ }
@@ -32,7 +32,7 @@ import ImageBrowseDialog from "./ImageBrowseDialog";
32
32
  // CMS AST ↔ Tiptap JSON conversion
33
33
  // -----------------------------------------------
34
34
 
35
- type CmsNode = {
35
+ export type CmsNode = {
36
36
  type: string;
37
37
  value?: string;
38
38
  level?: number;
@@ -43,12 +43,12 @@ type CmsNode = {
43
43
  [key: string]: unknown;
44
44
  };
45
45
 
46
- type CmsDocument = {
46
+ export type CmsDocument = {
47
47
  type: "root";
48
48
  children: CmsNode[];
49
49
  };
50
50
 
51
- const cmsNodeToTiptap = (node: CmsNode): any => {
51
+ export const cmsNodeToTiptap = (node: CmsNode): any => {
52
52
  if (node.type === "text") {
53
53
  const marks: any[] = [];
54
54
  if (node.bold) marks.push({ type: "bold" });
@@ -99,7 +99,7 @@ const cmsToTiptap = (doc: CmsDocument | null | undefined): any => {
99
99
  return { type: "doc", content: content.length > 0 ? content : [{ type: "paragraph" }] };
100
100
  };
101
101
 
102
- const tiptapNodeToCms = (node: any): CmsNode | null => {
102
+ export const tiptapNodeToCms = (node: any): CmsNode | null => {
103
103
  if (node.type === "text") {
104
104
  const result: CmsNode = { type: "text", value: node.text ?? "" };
105
105
  if (node.marks) {
@@ -176,11 +176,12 @@ const ToolbarButton = ({
176
176
  }) => (
177
177
  <button
178
178
  type="button"
179
+ data-slot="button"
179
180
  onClick={onClick}
180
181
  disabled={disabled}
181
182
  title={title}
182
183
  className={cn(
183
- "focus-visible:ring-ring/50 focus-visible:border-ring disabled:hover:text-muted-foreground inline-flex size-8 items-center justify-center rounded-md transition-colors outline-none focus-visible:ring-2 disabled:opacity-50 disabled:hover:bg-transparent",
184
+ "disabled:hover:text-muted-foreground inline-flex size-8 items-center justify-center rounded-md transition-colors outline-none disabled:opacity-50 disabled:hover:bg-transparent",
184
185
  active ? "bg-accent text-accent-foreground" : "text-muted-foreground hover:bg-accent/60 hover:text-foreground",
185
186
  )}
186
187
  >
@@ -192,7 +193,37 @@ const ToolbarButton = ({
192
193
  // Link dialog
193
194
  // -----------------------------------------------
194
195
 
195
- function LinkDialog({
196
+ export type LinkGroup = { label: string; items: Array<{ label: string; href: string }> };
197
+
198
+ /** Fetch published pages + posts for the internal-link picker. Shared by editors. */
199
+ export async function fetchLinkGroups(): Promise<LinkGroup[]> {
200
+ const [pagesRes, postsRes] = await Promise.all([
201
+ fetch("/api/cms/pages?status=published&limit=200").then((r) => (r.ok ? r.json() : { docs: [] })),
202
+ fetch("/api/cms/posts?status=published&limit=200").then((r) => (r.ok ? r.json() : { docs: [] })),
203
+ ]);
204
+ const groups: LinkGroup[] = [];
205
+ if (pagesRes.docs?.length) {
206
+ groups.push({
207
+ label: "Pages",
208
+ items: pagesRes.docs.map((p: Record<string, unknown>) => ({
209
+ label: String(p.title ?? p.slug),
210
+ href: `/${p.slug}`,
211
+ })),
212
+ });
213
+ }
214
+ if (postsRes.docs?.length) {
215
+ groups.push({
216
+ label: "Posts",
217
+ items: postsRes.docs.map((p: Record<string, unknown>) => ({
218
+ label: String(p.title ?? p.slug),
219
+ href: `/blog/${p.slug}`,
220
+ })),
221
+ });
222
+ }
223
+ return groups;
224
+ }
225
+
226
+ export function LinkDialog({
196
227
  open,
197
228
  onOpenChange,
198
229
  linkType,
@@ -287,7 +318,7 @@ function LinkDialog({
287
318
  role="combobox"
288
319
  aria-expanded={comboOpen}
289
320
  size="lg"
290
- className="border-input bg-muted/30 hover:bg-muted dark:bg-input/30 dark:hover:bg-input/50 w-full justify-between text-base font-normal"
321
+ className="border-input bg-muted/30 hover:bg-muted dark:bg-input/30 dark:hover:bg-input/50 w-full justify-between text-sm font-normal"
291
322
  >
292
323
  <span className={cn("truncate", !selectedLabel && "text-muted-foreground")}>
293
324
  {selectedLabel || "Search documents..."}
@@ -402,7 +433,8 @@ export default function RichTextEditor({ name, initialValue, rows = 10, onChange
402
433
  const editor = useEditor({
403
434
  immediatelyRender: false,
404
435
  extensions: [
405
- StarterKit,
436
+ // StarterKit bundles its own Link; disabled so the configured one below is the only registration.
437
+ StarterKit.configure({ link: false }),
406
438
  Image,
407
439
  Markdown,
408
440
  Link.configure({
@@ -473,7 +505,10 @@ export default function RichTextEditor({ name, initialValue, rows = 10, onChange
473
505
  const minHeight = `${rows * 1.5}rem`;
474
506
 
475
507
  return (
476
- <div className="border-input hover:border-foreground/20 focus-within:border-ring focus-within:ring-ring/50 overflow-hidden rounded-lg border transition-colors focus-within:ring-3">
508
+ <div
509
+ data-slot="editor"
510
+ className="border-input hover:border-foreground/20 overflow-hidden rounded-lg border transition-colors"
511
+ >
477
512
  <input ref={hiddenRef} type="hidden" name={name} value={cmsJson} />
478
513
 
479
514
  {/* Toolbar */}
@@ -0,0 +1,93 @@
1
+ "use client";
2
+
3
+ import { useMemo, useState } from "react";
4
+
5
+ import { SubField, blankBlockFields, humanize, type BlockTypesMeta, type RelationOption } from "./block-fields";
6
+ import SelectField from "./SelectField";
7
+
8
+ type Props = {
9
+ name: string;
10
+ value?: string;
11
+ types: BlockTypesMeta;
12
+ blockRelationOptions?: Record<string, RelationOption[]>;
13
+ };
14
+
15
+ type SharedBlock = {
16
+ type: string;
17
+ [field: string]: unknown;
18
+ };
19
+
20
+ function parseInitialBlock(value: string | undefined, types: BlockTypesMeta): SharedBlock {
21
+ // Default to no selection — the editor must actively choose a block type.
22
+ if (!value) return { type: "" };
23
+
24
+ try {
25
+ const parsed = JSON.parse(value) as Record<string, unknown>;
26
+ const type = String(parsed.type ?? "");
27
+ if (!type) return { type: "" };
28
+ return {
29
+ type,
30
+ ...blankBlockFields(types[type] ?? {}),
31
+ ...parsed,
32
+ };
33
+ } catch {
34
+ return { type: "" };
35
+ }
36
+ }
37
+
38
+ export default function SharedSectionBlockField({ name, value, types, blockRelationOptions = {} }: Props) {
39
+ const [block, setBlock] = useState<SharedBlock>(() => parseInitialBlock(value, types));
40
+ const typeNames = Object.keys(types);
41
+ const selectedType = block.type;
42
+ const fieldsMeta = types[selectedType] ?? {};
43
+ const serialized = useMemo(() => JSON.stringify(block), [block]);
44
+
45
+ const changeType = (typeName: string) => {
46
+ setBlock({ type: typeName, ...blankBlockFields(types[typeName] ?? {}) });
47
+ };
48
+
49
+ const updateField = (fieldName: string, fieldValue: unknown) => {
50
+ setBlock((prev) => ({ ...prev, [fieldName]: fieldValue }));
51
+ };
52
+
53
+ const relationOptionsFor = (fieldName: string) => blockRelationOptions[`shared:${selectedType}:${fieldName}`] ?? [];
54
+
55
+ if (typeNames.length === 0) {
56
+ return (
57
+ <div className="bg-muted/20 text-muted-foreground rounded-lg border border-dashed px-4 py-3 text-sm">
58
+ Add at least one block type to a collection before creating shared sections.
59
+ </div>
60
+ );
61
+ }
62
+
63
+ return (
64
+ <div className="space-y-4">
65
+ <input type="hidden" name="blockType" value={selectedType} />
66
+ <input type="hidden" name={name} value={serialized} />
67
+
68
+ <SelectField
69
+ name={`${name}_type`}
70
+ value={selectedType}
71
+ placeholder="Select a block type"
72
+ items={typeNames.map((typeName) => ({ value: typeName, label: humanize(typeName) }))}
73
+ onChange={changeType}
74
+ />
75
+
76
+ {selectedType && Object.keys(fieldsMeta).length > 0 && (
77
+ <div className="space-y-4 rounded-lg border px-4 py-4">
78
+ {Object.entries(fieldsMeta).map(([fieldName, meta]) => (
79
+ <SubField
80
+ key={fieldName}
81
+ blockKey={`shared_${selectedType}`}
82
+ fieldName={fieldName}
83
+ meta={meta}
84
+ value={block[fieldName]}
85
+ onChange={(v) => updateField(fieldName, v)}
86
+ relationOptions={meta.type === "relation" ? relationOptionsFor(fieldName) : []}
87
+ />
88
+ ))}
89
+ </div>
90
+ )}
91
+ </div>
92
+ );
93
+ }
@@ -62,7 +62,7 @@ export default function SidebarUserMenu({
62
62
  <ChevronsUpDown className="text-muted-foreground size-4 shrink-0" />
63
63
  </DropdownMenuTrigger>
64
64
 
65
- <DropdownMenuContent side="bottom" align="start" className="w-(--radix-dropdown-menu-trigger-width)">
65
+ <DropdownMenuContent side="top" align="start" sideOffset={6} className="w-(--radix-dropdown-menu-trigger-width)">
66
66
  <DropdownMenuItem onClick={() => changeTheme("light")}>
67
67
  <Sun className="text-muted-foreground size-3.5" />
68
68
  Light
@@ -16,7 +16,7 @@ const isError = status === "error";
16
16
  ---
17
17
 
18
18
  {/* Centering wrapper — keeps left-1/2 -translate-x-1/2 stable while inner div animates */}
19
- <div class="fixed top-4 left-1/2 z-50 w-full max-w-sm -translate-x-1/2">
19
+ <div class="fixed top-4 left-1/2 z-[60] w-full max-w-sm -translate-x-1/2">
20
20
  <div
21
21
  id="admin-toast"
22
22
  role={isError ? "alert" : "status"}