RichTextEditor (toolbar + slash menu + async mentions, SSR-safe via immediatelyRender:false) + RichTextViewer (generateHTML, server-renderable) + standalone Toolbar. Pure filterSlashItems/filterUsers helpers. 12/12 vitest (incl. live editor mount + bold toggle in happy-dom); tsc clean; published to Gitea.
27 lines
954 B
TypeScript
27 lines
954 B
TypeScript
import StarterKit from '@tiptap/starter-kit';
|
|
import Link from '@tiptap/extension-link';
|
|
import Placeholder from '@tiptap/extension-placeholder';
|
|
import type { AnyExtension } from '@tiptap/core';
|
|
|
|
export interface BuildExtensionsOptions {
|
|
/** Placeholder text shown when the doc is empty. */
|
|
placeholder?: string;
|
|
/** Extra extensions to append (e.g. a configured Mention or SlashCommands). */
|
|
extra?: AnyExtension[];
|
|
}
|
|
|
|
/**
|
|
* The canonical extension set shared by `<RichTextEditor>` and
|
|
* `<RichTextViewer>` — keeping them in sync guarantees that serialised HTML
|
|
* matches what the editor produced.
|
|
*/
|
|
export function buildExtensions(options: BuildExtensionsOptions = {}): AnyExtension[] {
|
|
const { placeholder = 'Write something…', extra = [] } = options;
|
|
return [
|
|
StarterKit.configure({ link: false }),
|
|
Link.configure({ openOnClick: false, autolink: true }),
|
|
Placeholder.configure({ placeholder }),
|
|
...extra,
|
|
];
|
|
}
|