Lexical Vue Editor

0.14.1 · active · verified Sun Apr 19

Lexical Vue is an extensible web text-editor component library for Vue 3, built upon Facebook's Lexical framework. It provides Vue components that wrap Lexical's core functionalities and plugins, allowing developers to integrate rich-text editing capabilities into their Vue applications. The current stable version is 0.14.1. The package follows Lexical's rapid release cadence, frequently bumping its dependency on `lexical` to keep up with the upstream project's evolution, often leading to minor version bumps with breaking changes from the underlying Lexical library. Key differentiators include its declarative Vue component API for managing editor state and plugins, and its direct integration with the powerful, extensible, and accessible Lexical editor core, contrasting with other Vue-specific editor solutions that might use different underlying architectures or are less frequently updated.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic plain-text Lexical editor in Vue 3, including initial configuration, content editable area, and change event handling.

<script setup lang="ts">
import { $getRoot, $getSelection } from 'lexical'

import { LexicalComposer } from 'lexical-vue/LexicalComposer'
import { AutoFocusPlugin } from 'lexical-vue/LexicalAutoFocusPlugin'
import { ContentEditable } from 'lexical-vue/LexicalContentEditable'
import { HistoryPlugin } from 'lexical-vue/LexicalHistoryPlugin'
import { OnChangePlugin } from 'lexical-vue/LexicalOnChangePlugin'
import { PlainTextPlugin } from 'lexical-vue/LexicalPlainTextPlugin'

const config = {
  editable: true,
  theme: {
    // Theme styling goes here
  }
}

// When the editor changes, you can get notified via the
// LexicalOnChangePlugin!
function onChange(editorState) {
  editorState.read(() => {
    // Read the contents of the EditorState here.
    const root = $getRoot()
    const selection = $getSelection()

    console.log(root, selection)
  })
}
</script>

<template>
  <LexicalComposer :initial-config="config">
    <PlainTextPlugin>
      <template #contentEditable>
        <ContentEditable>
          <template #placeholder>
            <div>Enter some text...</div>
          </template>
        </ContentEditable >
      </template>
    </PlainTextPlugin>
    <OnChangePlugin @change="onChange" />
    <HistoryPlugin />
    <AutoFocusPlugin />
  </LexicalComposer>
</template>

view raw JSON →