Skip to content

⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.

feat(web): write agent instructions in the markdown editor (#164)

Croffdbb5f1398c8c
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md
index 7b3c8c5f..bc649be6 100644
--- a/apps/web/AGENTS.md
+++ b/apps/web/AGENTS.md
@@ -41,8 +41,8 @@ Next.js App Router, SSR (not SPA). Tailwind v4 + shadcn/ui. See root `AGENTS.md`
packages (`api.ts`, `auth-client.ts`, `markdown.ts`, `dnd.ts`) plus shadcn's `utils.ts` (`cn`,
fixed by `components.json`); `src/utils` holds own helpers and constants with no external
package behind them. `src/context` holds shared React contexts and their `use*` readers.
-- `components/common` groups by purpose: `agent-chat/`, `fields/`, `inputs/`, `page/`, `overlay/`,
- `permissions/`, `hotkeys/`, `skeleton/`. A component that fits none of them stays at the
+- `components/common` groups by purpose: `agent-chat/`, `editor/`, `fields/`, `inputs/`, `page/`,
+ `overlay/`, `permissions/`, `hotkeys/`, `skeleton/`. A component that fits none of them stays at the
`common/` root.
Imports of a sibling in the same folder are relative; everything else uses `@/`.
- Component files use the feature name as a PascalCase prefix, file name = exported name. Service
diff --git a/apps/web/messages/ar/common.json b/apps/web/messages/ar/common.json
index d2ba9ecd..abd9ed17 100644
--- a/apps/web/messages/ar/common.json
+++ b/apps/web/messages/ar/common.json
@@ -132,5 +132,9 @@
"commandPalette": "لوحة الأوامر",
"commandPaletteHint": "دوّر على أمر تشغّله…",
"scrollToEnd": "التمرير إلى النهاية",
- "scrollToStart": "التمرير إلى البداية"
+ "scrollToStart": "التمرير إلى البداية",
+ "editor": {
+ "linkUrl": "عنوان الرابط",
+ "codeBlock": "كتلة برمجية"
+ }
}
diff --git a/apps/web/messages/ar/issue.json b/apps/web/messages/ar/issue.json
index 112b8660..702f171c 100644
--- a/apps/web/messages/ar/issue.json
+++ b/apps/web/messages/ar/issue.json
@@ -206,12 +206,10 @@
"endTime": "وقت الانتهاء"
},
"editor": {
- "linkUrl": "عنوان الرابط",
"insertImage": "إدراج صورة",
"insertNamed": "إدراج {name}",
"descriptionPlaceholder": "إضافة وصف…",
"noImages": "مفيش صور مرفقة لسه. ارفع صورة من لوحة المرفقات، أو ارميها على المحرر على طول.",
- "codeBlock": "كتلة برمجية",
"image": "صورة"
},
"cycleSelect": {
diff --git a/apps/web/messages/en/common.json b/apps/web/messages/en/common.json
index 44805386..47e56c17 100644
--- a/apps/web/messages/en/common.json
+++ b/apps/web/messages/en/common.json
@@ -132,5 +132,9 @@
"commandPalette": "Command palette",
"commandPaletteHint": "Search for a command to run…",
"scrollToEnd": "Scroll to end",
- "scrollToStart": "Scroll to start"
+ "scrollToStart": "Scroll to start",
+ "editor": {
+ "linkUrl": "Link URL",
+ "codeBlock": "Code block"
+ }
}
diff --git a/apps/web/messages/en/issue.json b/apps/web/messages/en/issue.json
index 69c7b4cb..a2210dfd 100644
--- a/apps/web/messages/en/issue.json
+++ b/apps/web/messages/en/issue.json
@@ -206,12 +206,10 @@
"endTime": "End time"
},
"editor": {
- "linkUrl": "Link URL",
"insertImage": "Insert image",
"insertNamed": "Insert {name}",
"descriptionPlaceholder": "Add description…",
"noImages": "No images attached yet. Upload one from the Attachments panel, or drop it straight onto the editor.",
- "codeBlock": "Code block",
"image": "Image"
},
"cycleSelect": {
diff --git a/apps/web/messages/ru/common.json b/apps/web/messages/ru/common.json
index f105a68f..1aaefa8a 100644
--- a/apps/web/messages/ru/common.json
+++ b/apps/web/messages/ru/common.json
@@ -132,5 +132,9 @@
"commandPalette": "Палитра команд",
"commandPaletteHint": "Найдите команду для выполнения…",
"scrollToEnd": "Прокрутить вниз",
- "scrollToStart": "Прокрутить вверх"
+ "scrollToStart": "Прокрутить вверх",
+ "editor": {
+ "linkUrl": "URL ссылки",
+ "codeBlock": "Блок кода"
+ }
}
diff --git a/apps/web/messages/ru/issue.json b/apps/web/messages/ru/issue.json
index b4a794f7..e58fe4ef 100644
--- a/apps/web/messages/ru/issue.json
+++ b/apps/web/messages/ru/issue.json
@@ -206,12 +206,10 @@
"endTime": "Окончание"
},
"editor": {
- "linkUrl": "URL ссылки",
"insertImage": "Вставить изображение",
"insertNamed": "Вставить {name}",
"descriptionPlaceholder": "Добавьте описание…",
"noImages": "Изображений пока нет. Загрузите из панели вложений или перетащите прямо в редактор.",
- "codeBlock": "Блок кода",
"image": "Изображение"
},
"cycleSelect": {
diff --git a/apps/web/messages/uk/common.json b/apps/web/messages/uk/common.json
index 1b2c30b8..08f739f7 100644
--- a/apps/web/messages/uk/common.json
+++ b/apps/web/messages/uk/common.json
@@ -132,5 +132,9 @@
"commandPalette": "Палітра команд",
"commandPaletteHint": "Знайдіть команду для виконання…",
"scrollToEnd": "Прокрутити вниз",
- "scrollToStart": "Прокрутити вгору"
+ "scrollToStart": "Прокрутити вгору",
+ "editor": {
+ "linkUrl": "URL посилання",
+ "codeBlock": "Блок коду"
+ }
}
diff --git a/apps/web/messages/uk/issue.json b/apps/web/messages/uk/issue.json
index 79fa3dbc..15bb6745 100644
--- a/apps/web/messages/uk/issue.json
+++ b/apps/web/messages/uk/issue.json
@@ -206,12 +206,10 @@
"endTime": "Завершення"
},
"editor": {
- "linkUrl": "URL посилання",
"insertImage": "Вставити зображення",
"insertNamed": "Вставити {name}",
"descriptionPlaceholder": "Додайте опис…",
"noImages": "Зображень ще немає. Завантажте з панелі вкладень або перетягніть просто в редактор.",
- "codeBlock": "Блок коду",
"image": "Зображення"
},
"cycleSelect": {
diff --git a/apps/web/messages/zh-CN/common.json b/apps/web/messages/zh-CN/common.json
index 393fe7fa..9123954b 100644
--- a/apps/web/messages/zh-CN/common.json
+++ b/apps/web/messages/zh-CN/common.json
@@ -132,5 +132,9 @@
"commandPalette": "命令面板",
"commandPaletteHint": "搜索要运行的命令…",
"scrollToEnd": "滚动到底部",
- "scrollToStart": "滚动到顶部"
+ "scrollToStart": "滚动到顶部",
+ "editor": {
+ "linkUrl": "链接 URL",
+ "codeBlock": "代码块"
+ }
}
diff --git a/apps/web/messages/zh-CN/issue.json b/apps/web/messages/zh-CN/issue.json
index b43b89c7..3242567d 100644
--- a/apps/web/messages/zh-CN/issue.json
+++ b/apps/web/messages/zh-CN/issue.json
@@ -206,12 +206,10 @@
"endTime": "结束时间"
},
"editor": {
- "linkUrl": "链接 URL",
"insertImage": "插入图片",
"insertNamed": "插入 {name}",
"descriptionPlaceholder": "添加描述…",
"noImages": "暂无已附加图片。请从附件面板上传,或直接拖入编辑器。",
- "codeBlock": "代码块",
"image": "图片"
},
"cycleSelect": {
diff --git a/apps/web/package.json b/apps/web/package.json
index e8ffd121..09b38617 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -35,11 +35,13 @@
"@tanstack/react-virtual": "^3.14.9",
"@tiptap/core": "^3.30.0",
"@tiptap/extension-code-block-lowlight": "^3.30.0",
+ "@tiptap/extension-hard-break": "^3.30.0",
"@tiptap/extension-image": "^3.30.0",
"@tiptap/extension-link": "^3.30.0",
"@tiptap/extension-placeholder": "^3.30.0",
"@tiptap/extension-task-item": "^3.30.0",
"@tiptap/extension-task-list": "^3.30.0",
+ "@tiptap/extension-text": "^3.30.0",
"@tiptap/pm": "^3.30.0",
"@tiptap/react": "^3.30.0",
"@tiptap/starter-kit": "^3.30.0",
diff --git a/apps/web/src/features/issue/components/editor/EditorSelectionMenu.tsx b/apps/web/src/components/common/editor/EditorSelectionMenu.tsx
similarity index 88%
rename from apps/web/src/features/issue/components/editor/EditorSelectionMenu.tsx
rename to apps/web/src/components/common/editor/EditorSelectionMenu.tsx
index 58fff56a..71db6552 100644
--- a/apps/web/src/features/issue/components/editor/EditorSelectionMenu.tsx
+++ b/apps/web/src/components/common/editor/EditorSelectionMenu.tsx
@@ -74,12 +74,20 @@ const ITEMS: {
},
];
-export default function EditorSelectionMenu({ editor }: { editor: Editor }) {
- const t = useTranslations('issue.editor');
+export default function EditorSelectionMenu({
+ editor,
+ placement = 'top',
+}: {
+ editor: Editor;
+ // Above the selection by default. A field with a label right over it passes
+ // "bottom" so the menu does not cover the label.
+ placement?: 'top' | 'bottom';
+}) {
+ const t = useTranslations('common.editor');
return (
<BubbleMenu
editor={editor}
- options={{ placement: 'top' }}
+ options={{ placement }}
className="flex items-center gap-0.5 rounded-md border bg-popover p-1 shadow-md"
>
{ITEMS.map((item) => (
diff --git a/apps/web/src/features/issue/components/editor/EditorSlashMenu.tsx b/apps/web/src/components/common/editor/EditorSlashMenu.tsx
similarity index 96%
rename from apps/web/src/features/issue/components/editor/EditorSlashMenu.tsx
rename to apps/web/src/components/common/editor/EditorSlashMenu.tsx
index d39e4d24..223abb6d 100644
--- a/apps/web/src/features/issue/components/editor/EditorSlashMenu.tsx
+++ b/apps/web/src/components/common/editor/EditorSlashMenu.tsx
@@ -1,6 +1,6 @@
import { useEffect, useImperativeHandle, useState, type Ref } from 'react';
import { cn } from '@/lib/utils';
-import { type SlashItem } from '../../utils/tiptap-slash-command';
+import { type SlashItem } from '@/lib/tiptap-slash-command';
export type SlashMenuRef = { onKeyDown: (props: { event: KeyboardEvent }) => boolean };
diff --git a/apps/web/src/features/issue/components/editor/EditorToolbarButton.tsx b/apps/web/src/components/common/editor/EditorToolbarButton.tsx
similarity index 100%
rename from apps/web/src/features/issue/components/editor/EditorToolbarButton.tsx
rename to apps/web/src/components/common/editor/EditorToolbarButton.tsx
diff --git a/apps/web/src/features/issue/components/IssueImageAnnotatorToolbar.tsx b/apps/web/src/features/issue/components/IssueImageAnnotatorToolbar.tsx
index 76a951dc..09043b2c 100644
--- a/apps/web/src/features/issue/components/IssueImageAnnotatorToolbar.tsx
+++ b/apps/web/src/features/issue/components/IssueImageAnnotatorToolbar.tsx
@@ -2,7 +2,7 @@
import { Circle, Highlighter, Square, Undo2, type LucideIcon } from 'lucide-react';
import { ANNOTATION_COLORS, type AnnotationTool } from '../utils/annotations';
-import EditorToolbarButton from './editor/EditorToolbarButton';
+import EditorToolbarButton from '@/components/common/editor/EditorToolbarButton';
import { Button } from '@/components/ui/button';
import { cn } from '@/lib/utils';
import { useTranslations } from 'next-intl';
diff --git a/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.tsx b/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.tsx
index 0a73d722..b1b02c6b 100644
--- a/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.tsx
+++ b/apps/web/src/features/issue/components/editor/IssueMarkdownEditor.tsx
@@ -7,11 +7,11 @@ import Link from '@tiptap/extension-link';
import { common, createLowlight } from 'lowlight';
import { Markdown } from 'tiptap-markdown';
import { ResizableImage } from '../../utils/tiptap-image';
-import { SlashCommand } from '../../utils/tiptap-slash-command';
+import { SlashCommand } from '@/lib/tiptap-slash-command';
import { Video } from '../../utils/tiptap-video';
import { attachmentHtml, type Embeddable } from '../../utils/attachmentEmbed';
import EditorImagePicker from './EditorImagePicker';
-import EditorSelectionMenu from './EditorSelectionMenu';
+import EditorSelectionMenu from '@/components/common/editor/EditorSelectionMenu';
import { useTranslations } from 'next-intl';
// Shared by every editor instance. A block with no language is detected by
@@ -52,6 +52,7 @@ export default function IssueMarkdownEditor({
imageAttachments?: Embeddable[];
}) {
const t = useTranslations('issue.editor');
+ const tCommon = useTranslations('common.editor');
const editorRef = useRef<Editor | null>(null);
const [imagePickerOpen, setImagePickerOpen] = useState(false);
@@ -82,8 +83,10 @@ export default function IssueMarkdownEditor({
// Renders video attachments as an inline <video> player.
Video,
SlashCommand.configure({
- onPickImage: imageAttachments ? () => setImagePickerOpen(true) : undefined,
- labels: { codeBlock: t('codeBlock'), image: t('image') },
+ codeBlockLabel: tCommon('codeBlock'),
+ image: imageAttachments
+ ? { label: t('image'), onPick: () => setImagePickerOpen(true) }
+ : undefined,
}),
// html:true so the custom <video> tag survives the markdown round-trip.
// tiptap only instantiates nodes declared in its schema (there is no
diff --git a/apps/web/src/features/settings/components/ai-agents/AgentInstructionsEditor.tsx b/apps/web/src/features/settings/components/ai-agents/AgentInstructionsEditor.tsx
new file mode 100644
index 00000000..9672a28c
--- /dev/null
+++ b/apps/web/src/features/settings/components/ai-agents/AgentInstructionsEditor.tsx
@@ -0,0 +1,122 @@
+import { useEffect, useRef } from 'react';
+import { useEditor, EditorContent, type Editor } from '@tiptap/react';
+import StarterKit from '@tiptap/starter-kit';
+import HardBreak from '@tiptap/extension-hard-break';
+import Text from '@tiptap/extension-text';
+import Placeholder from '@tiptap/extension-placeholder';
+import Link from '@tiptap/extension-link';
+import type { Node as ProseMirrorNode } from '@tiptap/pm/model';
+import { Markdown } from 'tiptap-markdown';
+import { useTranslations } from 'next-intl';
+import EditorSelectionMenu from '@/components/common/editor/EditorSelectionMenu';
+import { SlashCommand } from '@/lib/tiptap-slash-command';
+
+// The two nodes below replace the serializers tiptap-markdown installs for them,
+// because this value is not rendered as markdown anywhere — the agent runtime puts it
+// into the model's system prompt as it is stored, so every character it adds is a
+// character the model reads.
+
+// tiptap-markdown writes text as HTML-escaped, turning a prompt's <thinking> into
+// &lt;thinking&gt;. Markdown-it already keeps such a tag literal on the way in
+// (html:false), so the text goes back out exactly as it was typed.
+const PromptText = Text.extend({
+ addStorage: () => ({
+ markdown: {
+ serialize: (state: { text: (text: string) => void }, node: ProseMirrorNode) =>
+ state.text(node.text ?? ''),
+ },
+ }),
+});
+
+// tiptap-markdown ends a hard break with a backslash. With breaks:true a bare newline
+// parses back as the same hard break, so the prompt keeps plain line breaks. A break
+// at the end of a block is dropped, as markdown has nothing to attach it to.
+const PromptHardBreak = HardBreak.extend({
+ addStorage: () => ({
+ markdown: {
+ serialize(
+ state: { write: (text: string) => void },
+ node: ProseMirrorNode,
+ parent: ProseMirrorNode,
+ index: number,
+ ) {
+ for (let i = index + 1; i < parent.childCount; i++) {
+ if (parent.child(i).type !== node.type) {
+ state.write('\n');
+ return;
+ }
+ }
+ },
+ },
+ }),
+});
+
+// The agent's system prompt as markdown, edited the way an issue description is: a
+// bubble menu on selection and a "/" command list, no persistent toolbar. Content in
+// and out is markdown, the format the agent runtime reads.
+export default function AgentInstructionsEditor({
+ defaultValue,
+ onChange,
+ placeholder,
+ ariaLabel,
+ className,
+ autoFocus,
+ slashContainer,
+}: {
+ defaultValue: string;
+ onChange: (markdown: string) => void;
+ placeholder: string;
+ // The editing area is a contenteditable, not a form control a <label> can name.
+ ariaLabel: string;
+ className?: string;
+ autoFocus?: boolean;
+ // The overlay this editor sits in, where the "/" list mounts.
+ slashContainer: string;
+}) {
+ const t = useTranslations('common.editor');
+ const editorRef = useRef<Editor | null>(null);
+ const editor = useEditor({
+ immediatelyRender: false,
+ extensions: [
+ // link: the extension below configures it; StarterKit's copy would be a duplicate.
+ StarterKit.configure({ text: false, hardBreak: false, link: false }),
+ PromptText,
+ PromptHardBreak,
+ Placeholder.configure({ placeholder }),
+ Link.configure({ openOnClick: false, autolink: true }),
+ SlashCommand.configure({ container: slashContainer, codeBlockLabel: t('codeBlock') }),
+ Markdown.configure({ html: false, linkify: true, breaks: true }),
+ ],
+ content: defaultValue,
+ autofocus: autoFocus,
+ editorProps: {
+ attributes: { class: 'md-content flex-1 focus:outline-none', 'aria-label': ariaLabel },
+ // A prompt is markdown source, so paste its text as markdown. An editor or a
+ // web page also puts HTML on the clipboard, which ProseMirror would prefer and
+ // which carries none of the "#" and ">" structure. Inside a code block the
+ // text stays literal.
+ handlePaste(view, event) {
+ const text = event.clipboardData?.getData('text/plain');
+ if (!text || view.state.selection.$from.parent.type.spec.code) return false;
+ const { from, to } = view.state.selection;
+ // insertContentAt is the command tiptap-markdown overrides to read markdown.
+ return (
+ editorRef.current?.chain().focus().insertContentAt({ from, to }, text).run() ?? false
+ );
+ },
+ },
+ onUpdate: ({ editor }) => onChange(editor.storage.markdown.getMarkdown()),
+ });
+
+ useEffect(() => {
+ editorRef.current = editor;
+ }, [editor]);
+
+ if (!editor) return null;
+ return (
+ <div className={className}>
+ <EditorSelectionMenu editor={editor} placement="bottom" />
+ <EditorContent editor={editor} className="flex min-h-full flex-col" />
+ </div>
+ );
+}
diff --git a/apps/web/src/features/settings/components/ai-agents/AgentInstructionsField.tsx b/apps/web/src/features/settings/components/ai-agents/AgentInstructionsField.tsx
index 210eced2..909ee7ac 100644
--- a/apps/web/src/features/settings/components/ai-agents/AgentInstructionsField.tsx
+++ b/apps/web/src/features/settings/components/ai-agents/AgentInstructionsField.tsx
@@ -1,6 +1,5 @@
import { useState } from 'react';
import { Maximize2 } from 'lucide-react';
-import { Textarea } from '@/components/ui/textarea';
import { Button } from '@/components/ui/button';
import {
Dialog,
@@ -10,11 +9,12 @@ import {
DialogTitle,
} from '@/components/ui/dialog';
import { useTranslations } from 'next-intl';
+import AgentInstructionsEditor from './AgentInstructionsEditor';
-// The agent's system-prompt field. An inline textarea plus a maximize control next
-// to the label that opens the same value in a large dialog for comfortable editing.
-// Both editors are bound to the same value/onChange, so edits stay in sync. Used in
-// both the compact side panel and the full-width layout.
+// The agent's system-prompt field, written as markdown. An inline editor plus a
+// maximize control next to the label that opens the same value in a large dialog
+// for comfortable editing. Used in both the compact side panel and the full-width
+// layout.
export function AgentInstructionsField({
value,
onChange,
@@ -27,9 +27,7 @@ export function AgentInstructionsField({
return (
<div className="space-y-1.5">
<div className="flex items-center justify-between">
- <label htmlFor="agent-instructions" className="text-sm font-medium">
- {t('instructionsLabel')}
- </label>
+ <span className="text-sm font-medium">{t('instructionsLabel')}</span>
<button
type="button"
onClick={() => setOpen(true)}
@@ -40,13 +38,18 @@ export function AgentInstructionsField({
<Maximize2 className="size-3.5" />
</button>
</div>
- <Textarea
- id="agent-instructions"
- placeholder={t('instructionsPlaceholder')}
- value={value}
- onChange={(e) => onChange(e.target.value)}
- className="min-h-24"
- />
+ {/* Only one of the two editors exists at a time: the editor reads its content
+ on mount, so the inline one has to remount to pick up the dialog's edits. */}
+ {!open && (
+ <AgentInstructionsEditor
+ defaultValue={value}
+ onChange={onChange}
+ placeholder={t('instructionsPlaceholder')}
+ ariaLabel={t('instructionsLabel')}
+ slashContainer='[data-slot="sheet-content"]'
+ className="flex min-h-24 w-full flex-col rounded-md border border-input px-3 py-2 text-sm shadow-xs transition-[color,box-shadow] focus-within:border-ring focus-within:ring-[3px] focus-within:ring-ring/50"
+ />
+ )}
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent
@@ -61,12 +64,14 @@ export function AgentInstructionsField({
</Button>
</DialogClose>
</DialogHeader>
- <Textarea
+ <AgentInstructionsEditor
autoFocus
+ defaultValue={value}
+ onChange={onChange}
placeholder={t('instructionsPlaceholder')}
- value={value}
- onChange={(e) => onChange(e.target.value)}
- className="min-h-0 flex-1 resize-none border-0 bg-transparent px-0 text-base leading-relaxed shadow-none focus-visible:ring-0"
+ ariaLabel={t('instructionsLabel')}
+ slashContainer='[data-slot="dialog-content"]'
+ className="flex min-h-0 flex-1 flex-col overflow-y-auto text-base leading-relaxed"
/>
</DialogContent>
</Dialog>
diff --git a/apps/web/src/features/issue/utils/tiptap-slash-command.ts b/apps/web/src/lib/tiptap-slash-command.ts
similarity index 77%
rename from apps/web/src/features/issue/utils/tiptap-slash-command.ts
rename to apps/web/src/lib/tiptap-slash-command.ts
index fe3203ce..14c4c2f3 100644
--- a/apps/web/src/features/issue/utils/tiptap-slash-command.ts
+++ b/apps/web/src/lib/tiptap-slash-command.ts
@@ -2,7 +2,7 @@ import { Extension, type Editor, type Range } from '@tiptap/core';
import { ReactRenderer } from '@tiptap/react';
import Suggestion from '@tiptap/suggestion';
import { Image as ImageIcon, SquareCode, type LucideIcon } from 'lucide-react';
-import EditorSlashMenu, { type SlashMenuRef } from '../components/editor/EditorSlashMenu';
+import EditorSlashMenu, { type SlashMenuRef } from '@/components/common/editor/EditorSlashMenu';
export type SlashItem = {
title: string;
@@ -12,10 +12,14 @@ export type SlashItem = {
};
export type SlashCommandOptions = {
+ // Where the list mounts. Radix makes everything outside the open overlay inert,
+ // so it has to be that overlay's element. Defaults to an open dialog, falling
+ // back to document.body when the selector matches nothing.
+ container?: string;
+ // The name of the item, in the reader's language.
+ codeBlockLabel: string;
// Omitted where there is nothing to pick from, which drops the Image item.
- onPickImage?: () => void;
- // The names of the items, in the reader's language.
- labels: { codeBlock: string; image: string };
+ image?: { label: string; onPick: () => void };
};
// Typing "/" opens a list of blocks to insert — how they are reached with nothing
@@ -24,31 +28,29 @@ export const SlashCommand = Extension.create<SlashCommandOptions>({
name: 'slashCommand',
addProseMirrorPlugins() {
- const { onPickImage, labels } = this.options;
+ const { codeBlockLabel, image, container } = this.options;
return [
Suggestion<SlashItem, SlashItem>({
editor: this.editor,
char: '/',
- // In a dialog the list must mount inside it — Radix makes the rest of the
- // page inert. Falls back to document.body when no dialog is open.
- container: '[data-slot="dialog-content"]',
+ container: container ?? '[data-slot="dialog-content"]',
items: ({ query }) => {
const items: SlashItem[] = [
{
- title: labels.codeBlock,
+ title: codeBlockLabel,
icon: SquareCode,
run: ({ editor, range }) =>
editor.chain().focus().deleteRange(range).toggleCodeBlock().run(),
},
];
- if (onPickImage) {
+ if (image) {
items.push({
- title: labels.image,
+ title: image.label,
icon: ImageIcon,
run: ({ editor, range }) => {
editor.chain().focus().deleteRange(range).run();
- onPickImage();
+ image.onPick();
},
});
}
diff --git a/bun.lock b/bun.lock
index 67c9d3b8..64bda76b 100644
--- a/bun.lock
+++ b/bun.lock
@@ -84,11 +84,13 @@
"@tanstack/react-virtual": "^3.14.9",
"@tiptap/core": "^3.30.0",
"@tiptap/extension-code-block-lowlight": "^3.30.0",
+ "@tiptap/extension-hard-break": "^3.30.0",
"@tiptap/extension-image": "^3.30.0",
"@tiptap/extension-link": "^3.30.0",
"@tiptap/extension-placeholder": "^3.30.0",
"@tiptap/extension-task-item": "^3.30.0",
"@tiptap/extension-task-list": "^3.30.0",
+ "@tiptap/extension-text": "^3.30.0",
"@tiptap/pm": "^3.30.0",
"@tiptap/react": "^3.30.0",
"@tiptap/starter-kit": "^3.30.0",