ultisuite-client/lib/drive/richtext-extensions.ts
R3D347HR4Y 79bb6193fc
Some checks are pending
E2E / Playwright e2e (push) Waiting to run
menus1
2026-06-09 18:27:10 +02:00

76 lines
2.5 KiB
TypeScript

import type { Extensions } from "@tiptap/core"
import StarterKit from "@tiptap/starter-kit"
import Underline from "@tiptap/extension-underline"
import Link from "@tiptap/extension-link"
import TextAlign from "@tiptap/extension-text-align"
import { TextStyle, Color, BackgroundColor, FontSize, FontFamily } from "@tiptap/extension-text-style"
import Highlight from "@tiptap/extension-highlight"
import Image from "@tiptap/extension-image"
import Placeholder from "@tiptap/extension-placeholder"
import { Table } from "@tiptap/extension-table"
import TableRow from "@tiptap/extension-table-row"
import TableCell from "@tiptap/extension-table-cell"
import TableHeader from "@tiptap/extension-table-header"
import Collaboration from "@tiptap/extension-collaboration"
import CollaborationCaret from "@tiptap/extension-collaboration-caret"
import type { HocuspocusProvider } from "@hocuspocus/provider"
import type * as Y from "yjs"
import { DocsEditorShortcuts } from "@/lib/drive/docs-editor-shortcuts"
export function buildRichTextExtensions(options?: {
collaboration?: { document: Y.Doc }
collaborationCaret?: { provider: HocuspocusProvider; user: { name: string; color: string } }
placeholder?: string
editable?: boolean
}): Extensions {
const extensions: Extensions = [
StarterKit.configure({
undoRedo: options?.collaboration ? false : undefined,
}),
]
// Collaboration must register right after StarterKit (y-prosemirror binding).
if (options?.collaboration) {
extensions.push(
Collaboration.configure({
document: options.collaboration.document,
field: "default",
})
)
}
if (options?.collaborationCaret) {
extensions.push(
CollaborationCaret.configure({
provider: options.collaborationCaret.provider,
user: options.collaborationCaret.user,
})
)
}
extensions.push(
Underline,
Link.configure({ openOnClick: false }),
TextStyle,
FontFamily,
FontSize,
Color,
BackgroundColor,
Highlight.configure({ multicolor: true }),
TextAlign.configure({ types: ["heading", "paragraph"], alignments: ["left", "center", "right", "justify"] }),
Table.configure({ resizable: true }),
TableRow,
TableCell,
TableHeader,
Image.configure({ inline: true, allowBase64: true }),
Placeholder.configure({
placeholder: options?.placeholder ?? "Commencez à écrire…",
}),
DocsEditorShortcuts
)
return extensions
}
export const RICHTEXT_EDITOR_CLASS =
"ultidrive-richtext-editor max-w-none outline-none focus:outline-none prose prose-sm"