@reactloom/editor
v1.3.0
Published
Accessible React rich-text editor for ReactLoom on Tiptap (ProseMirror): labelled field, keyboard-friendly toolbar, link dialog, JSON values and server-side validation and HTML rendering.
Maintainers
Readme
@reactloom/editor
An accessible rich-text editor for ReactLoom, built on Tiptap (ProseMirror): a labelled field, a toolbar with roving focus, a link dialog, and JSON values you can validate and render to safe HTML on the server.
pnpm add @reactloom/editor @reactloom/ui @reactloom/themeimport '@reactloom/editor/styles.css';
import { RichTextEditor, type RichTextDocument } from '@reactloom/editor';
const [doc, setDoc] = useState<RichTextDocument | null>(null);
<RichTextEditor
label="Release notes"
value={doc}
onValueChange={setDoc}
formats={['bold', 'italic', 'link', 'heading', 'bulletList', 'orderedList']}
headingLevels={[2, 3]}
/>;Only the formats you allow:
formatssets both the toolbar and what the document may contain; pasted content outside it is dropped.Safe on the server: import from
@reactloom/editor/server(no React, no DOM) to check what a client sent and to render stored documents:import { validateDocument, renderHtml } from '@reactloom/editor/server'; const result = validateDocument(body.notes, { formats, maxLength: 10_000 }); if (!result.valid) return error(result.errors); const html = renderHtml(result.doc, { formats });renderHtmlescapes text and only writes safe link URLs (nojavascript:), so never render editor HTML that came from the browser.
Documentation and live examples: https://www.reactloom.dev/components/rich-text-editor
