@kidecms/core 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/components/BlockEditor.tsx +3 -12
- package/admin/components/CommandPalette.tsx +19 -72
- package/admin/components/ContentEditor.tsx +4 -10
- package/admin/components/DocumentCombobox.tsx +171 -0
- package/admin/components/FieldControl.astro +16 -32
- package/admin/components/InternalLinkPicker.tsx +30 -62
- package/admin/components/LinkField.tsx +6 -5
- package/admin/components/RelationField.tsx +32 -58
- package/admin/components/RepeaterInput.tsx +3 -6
- package/admin/components/SharedSectionBlockField.tsx +2 -6
- package/admin/components/TreeItemsEditor.tsx +4 -4
- package/admin/components/TreeSelect.tsx +33 -19
- package/admin/components/block-fields.tsx +21 -50
- package/admin/components/content-block-spec.ts +5 -6
- package/admin/lib/edit-data.ts +84 -129
- package/admin/lib/use-document-search.ts +107 -0
- package/admin/views/EditView.astro +18 -27
- package/admin/views/ListView.astro +3 -1
- package/admin/views/RecentView.astro +32 -9
- package/core/generator.ts +7 -1
- package/package.json +1 -1
- package/routes/api/admin/search.ts +102 -45
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import {
|
|
5
5
|
DndContext,
|
|
6
6
|
KeyboardSensor,
|
|
@@ -12,13 +12,12 @@ import {
|
|
|
12
12
|
} from "@dnd-kit/core";
|
|
13
13
|
import { SortableContext, arrayMove, useSortable, verticalListSortingStrategy } from "@dnd-kit/sortable";
|
|
14
14
|
import { CSS } from "@dnd-kit/utilities";
|
|
15
|
-
import {
|
|
15
|
+
import { GripVertical, Plus, Trash2 } from "lucide-react";
|
|
16
16
|
|
|
17
17
|
import { Button } from "./ui/button";
|
|
18
|
-
import { Command, CommandEmpty, CommandInput, CommandItem, CommandList } from "./ui/command";
|
|
19
|
-
import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
|
|
20
18
|
import { Sheet, SheetContent, SheetHeader, SheetTitle } from "./ui/sheet";
|
|
21
19
|
import { cn } from "../lib/utils";
|
|
20
|
+
import DocumentCombobox, { useRelationLabels } from "./DocumentCombobox";
|
|
22
21
|
|
|
23
22
|
type Option = { value: string; label: string };
|
|
24
23
|
|
|
@@ -27,7 +26,8 @@ type Props = {
|
|
|
27
26
|
value?: string;
|
|
28
27
|
hasMany?: boolean;
|
|
29
28
|
maxItems?: number;
|
|
30
|
-
|
|
29
|
+
/** Labels already known for selected values (optional seed — anything missing is resolved on mount). */
|
|
30
|
+
options?: Option[];
|
|
31
31
|
collectionSlug: string;
|
|
32
32
|
collectionLabel: string;
|
|
33
33
|
labelField?: string;
|
|
@@ -92,12 +92,11 @@ export default function RelationField({
|
|
|
92
92
|
value: initialValue,
|
|
93
93
|
hasMany = false,
|
|
94
94
|
maxItems,
|
|
95
|
-
options: initialOptions,
|
|
95
|
+
options: initialOptions = [],
|
|
96
96
|
collectionSlug,
|
|
97
97
|
collectionLabel,
|
|
98
98
|
labelField = "title",
|
|
99
99
|
}: Props) {
|
|
100
|
-
const [options, setOptions] = useState(initialOptions);
|
|
101
100
|
const [selected, setSelected] = useState<string[]>(() => {
|
|
102
101
|
if (!initialValue) return [];
|
|
103
102
|
if (hasMany) {
|
|
@@ -110,8 +109,9 @@ export default function RelationField({
|
|
|
110
109
|
}
|
|
111
110
|
return initialValue ? [initialValue] : [];
|
|
112
111
|
});
|
|
113
|
-
const
|
|
112
|
+
const { getLabel: findLabel, remember } = useRelationLabels(collectionSlug, selected, initialOptions);
|
|
114
113
|
const [sheetOpen, setSheetOpen] = useState(false);
|
|
114
|
+
|
|
115
115
|
const hiddenRef = useRef<HTMLInputElement>(null);
|
|
116
116
|
const iframeRef = useRef<HTMLIFrameElement>(null);
|
|
117
117
|
|
|
@@ -122,15 +122,18 @@ export default function RelationField({
|
|
|
122
122
|
hiddenRef.current?.dispatchEvent(new Event("change", { bubbles: true }));
|
|
123
123
|
}, [hiddenValue]);
|
|
124
124
|
|
|
125
|
-
const getLabel =
|
|
125
|
+
const getLabel = (id: string) => findLabel(id) ?? "…";
|
|
126
126
|
|
|
127
127
|
const atMax = hasMany && maxItems !== undefined && selected.length >= maxItems;
|
|
128
128
|
|
|
129
|
-
const displayLabel =
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
const displayLabel =
|
|
130
|
+
selected.length === 0
|
|
131
|
+
? ""
|
|
132
|
+
: hasMany
|
|
133
|
+
? maxItems
|
|
134
|
+
? `${selected.length}/${maxItems} selected`
|
|
135
|
+
: `${selected.length} selected`
|
|
136
|
+
: getLabel(selected[0]);
|
|
134
137
|
|
|
135
138
|
const selectItem = (id: string) => {
|
|
136
139
|
if (hasMany) {
|
|
@@ -141,7 +144,6 @@ export default function RelationField({
|
|
|
141
144
|
});
|
|
142
145
|
} else {
|
|
143
146
|
setSelected((prev) => (prev[0] === id ? [] : [id]));
|
|
144
|
-
setOpen(false);
|
|
145
147
|
}
|
|
146
148
|
};
|
|
147
149
|
|
|
@@ -171,12 +173,7 @@ export default function RelationField({
|
|
|
171
173
|
.then((doc) => {
|
|
172
174
|
if (doc) {
|
|
173
175
|
const label = String(doc[labelField] ?? doc.slug ?? docId);
|
|
174
|
-
|
|
175
|
-
const exists = prev.some((o) => o.value === docId);
|
|
176
|
-
return exists
|
|
177
|
-
? prev.map((o) => (o.value === docId ? { ...o, label } : o))
|
|
178
|
-
: [{ value: docId, label }, ...prev];
|
|
179
|
-
});
|
|
176
|
+
remember([{ docId, title: label }]);
|
|
180
177
|
if (hasMany) {
|
|
181
178
|
setSelected((prev) => (prev.includes(docId) ? prev : [...prev, docId]));
|
|
182
179
|
} else {
|
|
@@ -189,7 +186,7 @@ export default function RelationField({
|
|
|
189
186
|
|
|
190
187
|
window.addEventListener("message", handleMessage);
|
|
191
188
|
return () => window.removeEventListener("message", handleMessage);
|
|
192
|
-
}, [sheetOpen, collectionSlug, hasMany, labelField]);
|
|
189
|
+
}, [sheetOpen, collectionSlug, hasMany, labelField, remember]);
|
|
193
190
|
|
|
194
191
|
return (
|
|
195
192
|
<div className="space-y-2">
|
|
@@ -208,42 +205,19 @@ export default function RelationField({
|
|
|
208
205
|
</DndContext>
|
|
209
206
|
)}
|
|
210
207
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
<ChevronsUpDown className="ml-2 size-4 shrink-0 opacity-50" />
|
|
225
|
-
</Button>
|
|
226
|
-
</PopoverTrigger>
|
|
227
|
-
<PopoverContent className="w-(--radix-popover-trigger-width) p-0" align="start">
|
|
228
|
-
<Command>
|
|
229
|
-
<CommandInput placeholder={`Search ${collectionLabel.toLowerCase()}...`} />
|
|
230
|
-
<CommandList>
|
|
231
|
-
<CommandEmpty>No results found.</CommandEmpty>
|
|
232
|
-
{options.map((o) => (
|
|
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
|
-
>
|
|
239
|
-
<Check className={cn("ml-1 size-4", selected.includes(o.value) ? "opacity-100" : "opacity-0")} />
|
|
240
|
-
{o.label}
|
|
241
|
-
</CommandItem>
|
|
242
|
-
))}
|
|
243
|
-
</CommandList>
|
|
244
|
-
</Command>
|
|
245
|
-
</PopoverContent>
|
|
246
|
-
</Popover>
|
|
208
|
+
<DocumentCombobox
|
|
209
|
+
collections={[collectionSlug]}
|
|
210
|
+
placeholder={`Search ${collectionLabel.toLowerCase()}...`}
|
|
211
|
+
display={displayLabel}
|
|
212
|
+
isSelected={(hit) => selected.includes(hit.docId)}
|
|
213
|
+
onPick={(hit) => {
|
|
214
|
+
remember([hit]);
|
|
215
|
+
selectItem(hit.docId);
|
|
216
|
+
}}
|
|
217
|
+
closeOnPick={!hasMany}
|
|
218
|
+
dimUnselected={atMax}
|
|
219
|
+
size="lg"
|
|
220
|
+
/>
|
|
247
221
|
|
|
248
222
|
{/* Create new button */}
|
|
249
223
|
<Button
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useState } from "react";
|
|
2
2
|
|
|
3
|
-
import { RepeaterField, type
|
|
4
|
-
import type {
|
|
3
|
+
import { RepeaterField, type SubFieldMeta } from "./block-fields";
|
|
4
|
+
import type { LinkableCollection } from "./InternalLinkPicker";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Standalone form control for top-level repeater fields —
|
|
@@ -14,14 +14,12 @@ export default function RepeaterInput({
|
|
|
14
14
|
name,
|
|
15
15
|
value,
|
|
16
16
|
itemFields,
|
|
17
|
-
relationOptions,
|
|
18
17
|
linkOptions,
|
|
19
18
|
}: {
|
|
20
19
|
name: string;
|
|
21
20
|
value?: string;
|
|
22
21
|
itemFields?: Record<string, SubFieldMeta>;
|
|
23
|
-
|
|
24
|
-
linkOptions?: LinkOptionGroup[];
|
|
22
|
+
linkOptions?: LinkableCollection[];
|
|
25
23
|
}) {
|
|
26
24
|
const [items, setItems] = useState<unknown>(() => {
|
|
27
25
|
try {
|
|
@@ -36,7 +34,6 @@ export default function RepeaterInput({
|
|
|
36
34
|
<RepeaterField
|
|
37
35
|
blockKey={name}
|
|
38
36
|
itemFields={itemFields}
|
|
39
|
-
relationOptions={relationOptions}
|
|
40
37
|
linkOptions={linkOptions}
|
|
41
38
|
value={items}
|
|
42
39
|
onChange={setItems}
|
|
@@ -2,14 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
import { useMemo, useState } from "react";
|
|
4
4
|
|
|
5
|
-
import { SubField, blankBlockFields, humanize, type BlockTypesMeta
|
|
5
|
+
import { SubField, blankBlockFields, humanize, type BlockTypesMeta } from "./block-fields";
|
|
6
6
|
import SelectField from "./SelectField";
|
|
7
7
|
|
|
8
8
|
type Props = {
|
|
9
9
|
name: string;
|
|
10
10
|
value?: string;
|
|
11
11
|
types: BlockTypesMeta;
|
|
12
|
-
blockRelationOptions?: Record<string, RelationOption[]>;
|
|
13
12
|
};
|
|
14
13
|
|
|
15
14
|
type SharedBlock = {
|
|
@@ -35,7 +34,7 @@ function parseInitialBlock(value: string | undefined, types: BlockTypesMeta): Sh
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
|
|
38
|
-
export default function SharedSectionBlockField({ name, value, types
|
|
37
|
+
export default function SharedSectionBlockField({ name, value, types }: Props) {
|
|
39
38
|
const [block, setBlock] = useState<SharedBlock>(() => parseInitialBlock(value, types));
|
|
40
39
|
const typeNames = Object.keys(types);
|
|
41
40
|
const selectedType = block.type;
|
|
@@ -50,8 +49,6 @@ export default function SharedSectionBlockField({ name, value, types, blockRelat
|
|
|
50
49
|
setBlock((prev) => ({ ...prev, [fieldName]: fieldValue }));
|
|
51
50
|
};
|
|
52
51
|
|
|
53
|
-
const relationOptionsFor = (fieldName: string) => blockRelationOptions[`shared:${selectedType}:${fieldName}`] ?? [];
|
|
54
|
-
|
|
55
52
|
if (typeNames.length === 0) {
|
|
56
53
|
return (
|
|
57
54
|
<div className="bg-field-subtle text-muted-foreground rounded-lg border border-dashed px-4 py-3 text-sm">
|
|
@@ -83,7 +80,6 @@ export default function SharedSectionBlockField({ name, value, types, blockRelat
|
|
|
83
80
|
meta={meta}
|
|
84
81
|
value={block[fieldName]}
|
|
85
82
|
onChange={(v) => updateField(fieldName, v)}
|
|
86
|
-
relationOptions={meta.type === "relation" ? relationOptionsFor(fieldName) : []}
|
|
87
83
|
/>
|
|
88
84
|
))}
|
|
89
85
|
</div>
|
|
@@ -30,7 +30,7 @@ import { Input } from "./ui/input";
|
|
|
30
30
|
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "./ui/select";
|
|
31
31
|
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from "./ui/collapsible";
|
|
32
32
|
import { cn } from "../lib/utils";
|
|
33
|
-
import InternalLinkPicker, { type
|
|
33
|
+
import InternalLinkPicker, { type LinkableCollection } from "./InternalLinkPicker";
|
|
34
34
|
import {
|
|
35
35
|
type TreeItem,
|
|
36
36
|
generateId,
|
|
@@ -67,7 +67,7 @@ type Props = {
|
|
|
67
67
|
value?: string;
|
|
68
68
|
variant: "menu" | "taxonomy";
|
|
69
69
|
label?: string;
|
|
70
|
-
linkOptions?:
|
|
70
|
+
linkOptions?: LinkableCollection[];
|
|
71
71
|
};
|
|
72
72
|
|
|
73
73
|
function blankEdit(id: string): EditState {
|
|
@@ -298,7 +298,7 @@ export default function TreeItemsEditor({ name, value, variant, label, linkOptio
|
|
|
298
298
|
|
|
299
299
|
const startEdit = (item: TreeItem) => {
|
|
300
300
|
if (variant === "menu") {
|
|
301
|
-
const isInternal =
|
|
301
|
+
const isInternal = String(item.href ?? "").startsWith("/");
|
|
302
302
|
setEditing({
|
|
303
303
|
...blankEdit(item.id),
|
|
304
304
|
label: String(item.label ?? ""),
|
|
@@ -470,7 +470,7 @@ export default function TreeItemsEditor({ name, value, variant, label, linkOptio
|
|
|
470
470
|
) : (
|
|
471
471
|
<InternalLinkPicker
|
|
472
472
|
editHref={editing.href}
|
|
473
|
-
|
|
473
|
+
collections={linkOptions}
|
|
474
474
|
className="flex-3"
|
|
475
475
|
triggerClassName="bg-background h-7 rounded-md"
|
|
476
476
|
onSelect={(item) => {
|
|
@@ -78,6 +78,7 @@ export default function TreeSelect({
|
|
|
78
78
|
}: Props) {
|
|
79
79
|
const [value, setValue] = useState(initialValue ?? "");
|
|
80
80
|
const [open, setOpen] = useState(false);
|
|
81
|
+
const [query, setQuery] = useState("");
|
|
81
82
|
const hiddenRef = useRef<HTMLInputElement>(null);
|
|
82
83
|
const isInitial = useRef(true);
|
|
83
84
|
|
|
@@ -91,10 +92,21 @@ export default function TreeSelect({
|
|
|
91
92
|
|
|
92
93
|
const selected = items.find((i) => i.value === value);
|
|
93
94
|
|
|
95
|
+
// Filtering is ours, not cmdk's: cmdk reorders the DOM while filtering (and
|
|
96
|
+
// doesn't restore it when the query clears), which would bump the pinned
|
|
97
|
+
// "None" row around — and "None" is a clear-action, not a match for any query.
|
|
98
|
+
const q = query.trim().toLowerCase();
|
|
99
|
+
const filtered = q ? items.filter((item) => item.path.join(" / ").toLowerCase().includes(q)) : items;
|
|
100
|
+
|
|
101
|
+
const handleOpenChange = (next: boolean) => {
|
|
102
|
+
setOpen(next);
|
|
103
|
+
if (!next) setQuery("");
|
|
104
|
+
};
|
|
105
|
+
|
|
94
106
|
return (
|
|
95
107
|
<div className="space-y-2">
|
|
96
108
|
<input ref={hiddenRef} type="hidden" name={name} value={value} />
|
|
97
|
-
<Popover open={open} onOpenChange={
|
|
109
|
+
<Popover open={open} onOpenChange={handleOpenChange}>
|
|
98
110
|
<PopoverTrigger asChild>
|
|
99
111
|
<Button
|
|
100
112
|
variant="input"
|
|
@@ -122,31 +134,33 @@ export default function TreeSelect({
|
|
|
122
134
|
</Button>
|
|
123
135
|
</PopoverTrigger>
|
|
124
136
|
<PopoverContent className="w-(--radix-popover-trigger-width) p-0" align="start">
|
|
125
|
-
<Command>
|
|
126
|
-
<CommandInput placeholder={searchPlaceholder} />
|
|
137
|
+
<Command shouldFilter={false}>
|
|
138
|
+
<CommandInput value={query} onValueChange={setQuery} placeholder={searchPlaceholder} />
|
|
127
139
|
<CommandList>
|
|
128
|
-
<CommandEmpty>{emptyMessage}</CommandEmpty>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
140
|
+
{filtered.length === 0 && <CommandEmpty>{emptyMessage}</CommandEmpty>}
|
|
141
|
+
{!q && (
|
|
142
|
+
<CommandItem
|
|
143
|
+
value="__none__"
|
|
144
|
+
onSelect={() => {
|
|
145
|
+
setValue("");
|
|
146
|
+
onChangeProp?.("");
|
|
147
|
+
handleOpenChange(false);
|
|
148
|
+
}}
|
|
149
|
+
>
|
|
150
|
+
<div className="flex items-center">
|
|
151
|
+
<Check className={cn("mr-2 ml-1 size-4 shrink-0", !value ? "opacity-100" : "opacity-0")} />
|
|
152
|
+
<span className="text-muted-foreground">None</span>
|
|
153
|
+
</div>
|
|
154
|
+
</CommandItem>
|
|
155
|
+
)}
|
|
156
|
+
{filtered.map((item) => (
|
|
143
157
|
<CommandItem
|
|
144
158
|
key={item.value}
|
|
145
159
|
value={item.path.join(" / ")}
|
|
146
160
|
onSelect={() => {
|
|
147
161
|
setValue(item.value === value ? "" : item.value);
|
|
148
162
|
onChangeProp?.(item.value === value ? "" : item.value);
|
|
149
|
-
|
|
163
|
+
handleOpenChange(false);
|
|
150
164
|
}}
|
|
151
165
|
>
|
|
152
166
|
<div className="flex items-center" style={{ paddingLeft: `${item.depth * 1.25}rem` }}>
|
|
@@ -24,7 +24,8 @@ import ImagePicker from "./ImagePicker";
|
|
|
24
24
|
import SelectField from "./SelectField";
|
|
25
25
|
import ColorField from "./ColorField";
|
|
26
26
|
import LinkField from "./LinkField";
|
|
27
|
-
import type {
|
|
27
|
+
import type { LinkableCollection } from "./InternalLinkPicker";
|
|
28
|
+
import DocumentCombobox, { useRelationLabels } from "./DocumentCombobox";
|
|
28
29
|
import YoutubeField from "./YoutubeField";
|
|
29
30
|
|
|
30
31
|
// -----------------------------------------------
|
|
@@ -51,8 +52,6 @@ export type SubFieldMeta = {
|
|
|
51
52
|
|
|
52
53
|
export type BlockTypesMeta = Record<string, Record<string, SubFieldMeta>>;
|
|
53
54
|
|
|
54
|
-
export type RelationOption = { value: string; label: string };
|
|
55
|
-
|
|
56
55
|
export function generateKey() {
|
|
57
56
|
return "blk_" + Math.random().toString(36).slice(2, 9);
|
|
58
57
|
}
|
|
@@ -100,7 +99,6 @@ export function SubField({
|
|
|
100
99
|
meta,
|
|
101
100
|
value,
|
|
102
101
|
onChange,
|
|
103
|
-
relationOptions = [],
|
|
104
102
|
linkOptions = [],
|
|
105
103
|
}: {
|
|
106
104
|
blockKey: string;
|
|
@@ -108,8 +106,7 @@ export function SubField({
|
|
|
108
106
|
meta: SubFieldMeta;
|
|
109
107
|
value: unknown;
|
|
110
108
|
onChange: (value: unknown) => void;
|
|
111
|
-
|
|
112
|
-
linkOptions?: LinkOptionGroup[];
|
|
109
|
+
linkOptions?: LinkableCollection[];
|
|
113
110
|
}) {
|
|
114
111
|
const label = meta.label ?? humanize(fieldName);
|
|
115
112
|
const fieldId = `${blockKey}_${fieldName}`;
|
|
@@ -121,14 +118,7 @@ export function SubField({
|
|
|
121
118
|
{meta.required ? " *" : ""}
|
|
122
119
|
</Label>
|
|
123
120
|
{meta.admin?.help && <p className="text-muted-foreground text-xs leading-5">{meta.admin.help}</p>}
|
|
124
|
-
<SubFieldControl
|
|
125
|
-
fieldId={fieldId}
|
|
126
|
-
meta={meta}
|
|
127
|
-
value={value}
|
|
128
|
-
onChange={onChange}
|
|
129
|
-
relationOptions={relationOptions}
|
|
130
|
-
linkOptions={linkOptions}
|
|
131
|
-
/>
|
|
121
|
+
<SubFieldControl fieldId={fieldId} meta={meta} value={value} onChange={onChange} linkOptions={linkOptions} />
|
|
132
122
|
</div>
|
|
133
123
|
);
|
|
134
124
|
}
|
|
@@ -181,16 +171,15 @@ function RelationControl({
|
|
|
181
171
|
meta,
|
|
182
172
|
value,
|
|
183
173
|
onChange,
|
|
184
|
-
relationOptions,
|
|
185
174
|
}: {
|
|
186
175
|
fieldId: string;
|
|
187
176
|
meta: SubFieldMeta;
|
|
188
177
|
value: unknown;
|
|
189
178
|
onChange: (value: unknown) => void;
|
|
190
|
-
relationOptions: RelationOption[];
|
|
191
179
|
}) {
|
|
192
180
|
const selected = parseSelected(meta, value);
|
|
193
|
-
const
|
|
181
|
+
const collectionSlug = meta.collection ?? "";
|
|
182
|
+
const { getLabel, remember } = useRelationLabels(collectionSlug, selected);
|
|
194
183
|
const toggle = (id: string) => {
|
|
195
184
|
if (meta.hasMany) {
|
|
196
185
|
const next = selected.includes(id) ? selected.filter((v) => v !== id) : [...selected, id];
|
|
@@ -208,7 +197,7 @@ function RelationControl({
|
|
|
208
197
|
key={id}
|
|
209
198
|
className="bg-card text-secondary-foreground inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-sm"
|
|
210
199
|
>
|
|
211
|
-
{getLabel(id)}
|
|
200
|
+
{getLabel(id) ?? "…"}
|
|
212
201
|
<button
|
|
213
202
|
type="button"
|
|
214
203
|
onClick={() => toggle(id)}
|
|
@@ -220,18 +209,17 @@ function RelationControl({
|
|
|
220
209
|
))}
|
|
221
210
|
</div>
|
|
222
211
|
)}
|
|
223
|
-
<
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
} else {
|
|
232
|
-
onChange(v);
|
|
233
|
-
}
|
|
212
|
+
<DocumentCombobox
|
|
213
|
+
collections={[collectionSlug]}
|
|
214
|
+
placeholder={`Search ${meta.label?.toLowerCase() ?? "documents"}...`}
|
|
215
|
+
display={meta.hasMany ? "" : selected[0] ? (getLabel(selected[0]) ?? "…") : ""}
|
|
216
|
+
isSelected={(hit) => selected.includes(hit.docId)}
|
|
217
|
+
onPick={(hit) => {
|
|
218
|
+
remember([hit]);
|
|
219
|
+
toggle(hit.docId);
|
|
234
220
|
}}
|
|
221
|
+
closeOnPick={!meta.hasMany}
|
|
222
|
+
triggerId={fieldId}
|
|
235
223
|
/>
|
|
236
224
|
</div>
|
|
237
225
|
);
|
|
@@ -278,15 +266,13 @@ export function SubFieldControl({
|
|
|
278
266
|
meta,
|
|
279
267
|
value,
|
|
280
268
|
onChange,
|
|
281
|
-
relationOptions = [],
|
|
282
269
|
linkOptions = [],
|
|
283
270
|
}: {
|
|
284
271
|
fieldId: string;
|
|
285
272
|
meta: SubFieldMeta;
|
|
286
273
|
value: unknown;
|
|
287
274
|
onChange: (value: unknown) => void;
|
|
288
|
-
|
|
289
|
-
linkOptions?: LinkOptionGroup[];
|
|
275
|
+
linkOptions?: LinkableCollection[];
|
|
290
276
|
}) {
|
|
291
277
|
const strValue = value == null ? "" : String(value);
|
|
292
278
|
|
|
@@ -384,15 +370,7 @@ export function SubFieldControl({
|
|
|
384
370
|
);
|
|
385
371
|
|
|
386
372
|
case "relation":
|
|
387
|
-
return
|
|
388
|
-
<RelationControl
|
|
389
|
-
fieldId={fieldId}
|
|
390
|
-
meta={meta}
|
|
391
|
-
value={value}
|
|
392
|
-
onChange={onChange}
|
|
393
|
-
relationOptions={relationOptions}
|
|
394
|
-
/>
|
|
395
|
-
);
|
|
373
|
+
return <RelationControl fieldId={fieldId} meta={meta} value={value} onChange={onChange} />;
|
|
396
374
|
|
|
397
375
|
case "array":
|
|
398
376
|
return <ArrayControl fieldId={fieldId} meta={meta} value={value} onChange={onChange} />;
|
|
@@ -403,7 +381,6 @@ export function SubFieldControl({
|
|
|
403
381
|
<RepeaterField
|
|
404
382
|
blockKey={fieldId}
|
|
405
383
|
itemFields={meta.itemFields}
|
|
406
|
-
relationOptions={relationOptions}
|
|
407
384
|
linkOptions={linkOptions}
|
|
408
385
|
value={value}
|
|
409
386
|
onChange={onChange}
|
|
@@ -440,7 +417,6 @@ function SortableRepeaterItem({
|
|
|
440
417
|
item,
|
|
441
418
|
fieldKeys,
|
|
442
419
|
itemFields,
|
|
443
|
-
relationOptions,
|
|
444
420
|
linkOptions,
|
|
445
421
|
index,
|
|
446
422
|
isExpanded,
|
|
@@ -454,8 +430,7 @@ function SortableRepeaterItem({
|
|
|
454
430
|
item: Record<string, unknown>;
|
|
455
431
|
fieldKeys: string[];
|
|
456
432
|
itemFields?: Record<string, SubFieldMeta>;
|
|
457
|
-
|
|
458
|
-
linkOptions?: LinkOptionGroup[];
|
|
433
|
+
linkOptions?: LinkableCollection[];
|
|
459
434
|
index: number;
|
|
460
435
|
isExpanded: boolean;
|
|
461
436
|
autoFocus?: boolean;
|
|
@@ -552,7 +527,6 @@ function SortableRepeaterItem({
|
|
|
552
527
|
meta={itemFields[key]}
|
|
553
528
|
value={item[key]}
|
|
554
529
|
onChange={(v) => onUpdate(key, v)}
|
|
555
|
-
relationOptions={relationOptions}
|
|
556
530
|
linkOptions={linkOptions}
|
|
557
531
|
/>
|
|
558
532
|
))
|
|
@@ -593,15 +567,13 @@ function parseArray(value: unknown): unknown[] {
|
|
|
593
567
|
export function RepeaterField({
|
|
594
568
|
blockKey,
|
|
595
569
|
itemFields,
|
|
596
|
-
relationOptions,
|
|
597
570
|
linkOptions,
|
|
598
571
|
value,
|
|
599
572
|
onChange,
|
|
600
573
|
}: {
|
|
601
574
|
blockKey: string;
|
|
602
575
|
itemFields?: Record<string, SubFieldMeta>;
|
|
603
|
-
|
|
604
|
-
linkOptions?: LinkOptionGroup[];
|
|
576
|
+
linkOptions?: LinkableCollection[];
|
|
605
577
|
value: unknown;
|
|
606
578
|
onChange: (value: unknown) => void;
|
|
607
579
|
}) {
|
|
@@ -707,7 +679,6 @@ export function RepeaterField({
|
|
|
707
679
|
item={item}
|
|
708
680
|
fieldKeys={fieldKeys}
|
|
709
681
|
itemFields={itemFields}
|
|
710
|
-
relationOptions={relationOptions}
|
|
711
682
|
linkOptions={linkOptions}
|
|
712
683
|
index={index}
|
|
713
684
|
isExpanded={expandedKeys.has(String(item._key))}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mergeAttributes, isNodeSelection, type Editor } from "@tiptap/core";
|
|
2
2
|
import { NodeSelection, TextSelection } from "@tiptap/pm/state";
|
|
3
|
-
import type { BlockTypesMeta
|
|
4
|
-
import type {
|
|
3
|
+
import type { BlockTypesMeta } from "./block-fields";
|
|
4
|
+
import type { LinkableCollection } from "./InternalLinkPicker";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Schema/serialization spec for the inline `content` block node — kept free of React
|
|
@@ -23,9 +23,8 @@ export const SHARED_BLOCK_TYPE = "__shared";
|
|
|
23
23
|
|
|
24
24
|
export type BlockNodeOptions = {
|
|
25
25
|
types: BlockTypesMeta;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
/** Name of the `content` field this editor belongs to — namespaces relation-option keys. */
|
|
26
|
+
linkOptions?: LinkableCollection[];
|
|
27
|
+
/** Name of the `content` field this editor belongs to — namespaces sub-field DOM ids. */
|
|
29
28
|
fieldName: string;
|
|
30
29
|
};
|
|
31
30
|
|
|
@@ -37,7 +36,7 @@ export const blockNodeSpec = {
|
|
|
37
36
|
selectable: true,
|
|
38
37
|
|
|
39
38
|
addOptions(): BlockNodeOptions {
|
|
40
|
-
return { types: {},
|
|
39
|
+
return { types: {}, fieldName: "" };
|
|
41
40
|
},
|
|
42
41
|
|
|
43
42
|
addAttributes() {
|