Rich Text Editor
Alignment target:@astryxdesign/richtext v0.7.1 · RichTextEditor
Install #
pnpm add @astryx-vue/richtextnpm install @astryx-vue/richtextyarn add @astryx-vue/richtextbun add @astryx-vue/richtextRichTextEditor is built on Lexical. Install lexical and the @lexical/* packages required by the features you use, all pinned to 0.52.0.
Create an editor #
Import the stylesheet once in your application entry, then render RichTextEditor. The required label prop provides the editor's accessible name.
<script setup lang="ts">
import { RichTextEditor } from '@astryx-vue/richtext'
import '@astryx-vue/richtext/richtext.css'
</script>
<template>
<RichTextEditor label="Publish content" placeholder="Write something..." />
</template>Add RichTextEditorToolbar through the #toolbar slot to provide undo, block formats, inline styles, and link actions. The toolbar scrolls horizontally when space is limited.
Rich Text Editor — Editor with a toolbar
Add a formatting toolbar through the #toolbar slot.
Save and display content #
The editor and read-only view use the same Lexical state JSON:
- Listen to the editor's
@changeevent and saveeditorState.toJSON()to your backend. - To edit the content again, pass the saved JSON string to
defaultValue. This prop is read only when the editor mounts. - For read-only display, pass the same string to
RichTextViewthroughvalueinstead of rendering a read-only editor.
When you register custom nodes through nodes, register the same set on both the editor and the read-only view so content round-trips without data loss.
Rich Text Editor — Display saved content
Render saved Lexical state JSON with RichTextView.
Keyboard commands #
| Action | Keys |
|---|---|
| Insert a newline inside a code block | Enter |
| Move between table cells | Arrow keys |
| Create and move to a paragraph below a code block or table | ArrowDown at the block's end |
| Open or close the link dialog | Cmd/Ctrl + K |
| Leave the editor | Press Escape, then Tab; use Shift + Tab for the reverse direction |
At the end of a code block or table, ArrowDown inserts a paragraph when no content follows or when another code block or table immediately follows. This lets you place prose between these blocks. When ordinary content already follows, the arrow keys retain Lexical's native navigation.
Automatic links and server-side conversion #
Place RichTextEditorAutoLinkPlugin in the editor's default slot to turn typed URLs and email addresses into links. Use matchers to add custom matching rules.
Rich Text Editor — Recognize URLs and email addresses
Enable the automatic link plugin in the default slot.
To convert Markdown on the server, import markdownToEditorStateJSON and editorStateJSONToMarkdown from @astryx-vue/richtext/markdown. Neither function requires a browser DOM.
See the props documentation for all properties, events, and slots.