learning_ai_common_plat/packages/rich-text/src/extensions.ts
saravanakumardb1 fc8502ac0c feat(rich-text): @bytelyst/rich-text@0.1.0 on Tiptap v3
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.
2026-05-28 18:20:34 -07:00

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,
];
}