Rich Text Editor

Alignment target:@astryxdesign/richtext v0.7.1 · RichTextEditor

Capture formatted context for your team.
Press Escape then Tab to move focus out of the editor.

Install #

Shell
pnpm add @astryx-vue/richtext

RichTextEditor 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.

Vue
<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

Press Escape then Tab to move focus out of the editor.

Add a formatting toolbar through the #toolbar slot.

Save and display content #

The editor and read-only view use the same Lexical state JSON:

  1. Listen to the editor's @change event and save editorState.toJSON() to your backend.
  2. To edit the content again, pass the saved JSON string to defaultValue. This prop is read only when the editor mounts.
  3. For read-only display, pass the same string to RichTextView through value instead 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 #

ActionKeys
Insert a newline inside a code blockEnter
Move between table cellsArrow keys
Create and move to a paragraph below a code block or tableArrowDown at the block's end
Open or close the link dialogCmd/Ctrl + K
Leave the editorPress 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.

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

Press Escape then Tab to move focus out of the editor.

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.