AlessioGr

payload plugin lexical

by AlessioGr
Rich text & editors
v1
^1.6.32
MIT

Overview

Summary generated from the README

Adds a Lexical-based rich text editor to Payload CMS 1.x through a plugin and a lexicalRichTextField helper for collection fields. The editor mirrors the Lexical playground and exposes a feature API for toggling or adding features. It requires Payload 1.6.32 or later and does not support 2.x. Content can be migrated to Payload core Lexical with a converter.

Features

  • lexicalRichTextField helper to add the editor to any collection
  • Features such as tables, collapsibles, equations, emojis, and mentions
  • Embeds for YouTube, Twitter, and Figma
  • Markdown conversion, import and export, and speech-to-text actions
  • Optional AI suggestions through an OpenAI key
  • Editor config modifier to disable features or add custom ones

Use cases

  • Replace the Slate editor in a Payload 1.x project with a richer Lexical editor
  • Add tables, collapsible blocks, and embeds to editorial content
  • Build custom Lexical features and port them to Payload core Lexical later

From the author

Lexical plugin for Payload CMS

Installation

npm i payload-plugin-lexical

213

Stars

10

Forks

18

Open Issues

2 years ago

Last Updated

153

Weekly Downloads

v0.6.6

npm Version

2.1 MB

Unpacked Size

20

Dependencies

GitHub stars

213+3 since Sep 6

Show data
GitHub stars by day (UTC)
DateStars
Dec 5, 2026213
Dec 4, 2026213
Dec 3, 2026213
Dec 2, 2026213
Dec 1, 2026213
Nov 30, 2026213
Nov 29, 2026213
Nov 28, 2026213
Nov 27, 2026213
Nov 26, 2026213
Nov 25, 2026213
Nov 24, 2026214
Nov 23, 2026214
Nov 22, 2026214
Nov 21, 2026214
Nov 20, 2026214
Nov 19, 2026214
Nov 18, 2026214
Nov 17, 2026214
Nov 16, 2026214
Nov 15, 2026214
Nov 14, 2026214
Nov 13, 2026214
Nov 12, 2026214
Nov 11, 2026214
Nov 10, 2026214
Nov 9, 2026214
Nov 8, 2026214
Nov 7, 2026214
Nov 6, 2026214
Nov 5, 2026214
Nov 4, 2026214
Nov 3, 2026214
Nov 2, 2026214
Nov 1, 2026214
Oct 31, 2026214
Oct 30, 2026214
Oct 29, 2026214
Oct 28, 2026214
Oct 27, 2026214
Oct 26, 2026214
Oct 25, 2026214
Oct 24, 2026214
Oct 23, 2026214
Oct 22, 2026214
Oct 21, 2026213
Oct 20, 2026213
Oct 19, 2026213
Oct 18, 2026213
Oct 17, 2026213
Oct 16, 2026213
Oct 15, 2026213
Oct 14, 2026213
Oct 13, 2026213
Oct 12, 2026213
Oct 11, 2026212
Oct 10, 2026212
Oct 9, 2026212
Oct 8, 2026212
Oct 7, 2026212
Oct 6, 2026212
Oct 5, 2026212
Oct 4, 2026211
Oct 3, 2026211
Oct 2, 2026211
Oct 1, 2026211
Sep 30, 2026211
Sep 29, 2026211
Sep 28, 2026211
Sep 27, 2026211
Sep 26, 2026211
Sep 25, 2026211
Sep 24, 2026211
Sep 23, 2026211
Sep 22, 2026211
Sep 21, 2026211
Sep 20, 2026211
Sep 19, 2026211
Sep 18, 2026211
Sep 17, 2026211
Sep 16, 2026211
Sep 15, 2026211
Sep 14, 2026211
Sep 13, 2026210
Sep 12, 2026210
Sep 11, 2026210
Sep 10, 2026210
Sep 9, 2026210
Sep 8, 2026210
Sep 7, 2026210
Sep 6, 2026210
npm weekly downloads

160+138 since Sep 6

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 5, 2026160
Dec 4, 202678
Dec 3, 202683
Dec 2, 202675
Dec 1, 202667
Nov 30, 202669
Nov 29, 2026110
Nov 28, 202699
Nov 27, 202685
Nov 26, 202678
Nov 25, 202685
Nov 24, 202688
Nov 23, 202685
Nov 22, 202651
Nov 21, 202661
Nov 20, 202666
Nov 19, 202668
Nov 18, 202664
Nov 17, 202660
Nov 16, 202663
Nov 15, 202684
Nov 14, 202689
Nov 13, 202691
Nov 12, 2026101
Nov 11, 2026108
Nov 10, 2026114
Nov 9, 2026112
Nov 8, 202677
Nov 7, 202665
Nov 6, 202666
Nov 5, 202663
Nov 4, 202663
Nov 3, 202658
Nov 2, 202656
Nov 1, 202665
Oct 31, 202662
Oct 30, 202651
Oct 29, 202638
Oct 28, 202625
Oct 27, 202655
Oct 26, 202655
Oct 25, 202653
Oct 24, 202652
Oct 23, 202650
Oct 22, 202660
Oct 21, 2026127
Oct 20, 2026104
Oct 19, 2026110
Oct 18, 2026115
Oct 17, 2026115
Oct 16, 2026118
Oct 15, 2026117
Oct 14, 202697
Oct 13, 202689
Oct 12, 202680
Oct 11, 202673
Oct 10, 202676
Oct 9, 202677
Oct 8, 202674
Oct 7, 202634
Oct 6, 202634
Oct 5, 202636
Oct 4, 202641
Oct 3, 202654
Oct 2, 202661
Oct 1, 202662
Sep 30, 202665
Sep 29, 2026110
Sep 28, 2026109
Sep 27, 2026103
Sep 26, 202688
Sep 25, 202679
Sep 24, 202673
Sep 23, 202668
Sep 22, 202674
Sep 21, 202673
Sep 20, 202671
Sep 19, 202668
Sep 18, 202667
Sep 17, 202669
Sep 16, 202666
Sep 15, 202614
Sep 14, 202616
Sep 13, 202618
Sep 12, 202618
Sep 11, 202622
Sep 10, 202624
Sep 9, 202625
Sep 8, 202623
Sep 7, 202626
Sep 6, 202622

Each point is npm's rolling 7-day download count.

Health Score

35/100Fair

Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.

Badge for your README

Payload Directory health badge
Markdown
[![Payload Directory](https://payloaddirectory.dev/badge/570326999-root.svg)](https://payloaddirectory.dev/plugins/570326999-root)
HTML
<a href="https://payloaddirectory.dev/plugins/570326999-root"><img src="https://payloaddirectory.dev/badge/570326999-root.svg" alt="Payload Directory"></a>
Updated Jan 11, 2024Created Nov 24, 2022Published May 18, 2023

README

Payload Lexical Plugin GitHub Repo stars

npm npm NPM

A plugin for Payload CMS whichs adds a lexical-based richtext editor. Lexical is a lot nicer to use than Slate & more modern - it's also maintained by Meta.

This plugin only supports payload 1.x - not 2.x. While this plugin can still be used if you need extra features (tables, color picker, collapsibles etc. etc.), it will not receive further development or support. This plugin is also a great reference for building new Features in the new Lexical editor in Payload core 2.0. It has the same features as the lexical playground, but its API is closer to the new Lexical Payload 2.0 API (which was inspired by this plugin), which makes porting over Features easier.

Note: This plugin and the new lexical in Payload 2.0 Lexical is powering the next richtext editor in Payload 2.0 (I'm calling it Lexical core here). Future development is focused on the new lexical editor rather than the older Slate-based editor.

There is a converter you can use to migrate everything from this plugin to the new lexical core. You can find more info about it here: https://payloadcms.com/docs/rich-text/lexical#migrating-from-payload-plugin-lexical

Please note that this migrator only migrates data, not features. While lexical core is more stable and carefully crafted than this plugin, this plugin still has more features which lexical core does not have - for example tables or collapsibles.

If you use these features, the data can be migrated over, but it will not be displayed inside the core lexical editor until you migrate the Feature over from this plugin to lexical core as well.

Lexical 2.0 core will eventually get all the missing features, and thus the missing converters. The main focus right now is stability

This plugin already comes packed with a ton of features which the original 1.0 Slate editor doesn't have (from tables & markdown to stuff like speech-to-tech) - all customizable. It's also a lot easier to extend this editor and add new stuff to it!

Installation / How to use

Install the plugin using yarn add payload-plugin-lexical. You can find examples of how to use it below.

Minimum required payload version: 1.6.32

Screenshots

203127349-2be29de4-aff3-4e13-9ebe-56be5fc3fc97 (1) 203127640-caa1f279-1555-48e6-9465-8c441ea65149

How I'm using it in production - customized & with some features turned on or off:

Arc 2023-03-20 at 01 34 05@2x

https://user-images.githubusercontent.com/70709113/226221855-08e2efe3-3624-45a1-9ad2-8ff5cddbc843.mp4

Example - Basic

payload.config.ts:

import { buildConfig } from 'payload/config';
import { LexicalPlugin } from "payload-plugin-lexical";

export default buildConfig({
  ...
  plugins: [
    LexicalPlugin({
      // Only set this if you want to use the the AISuggest Feature
      ai: {
        openai_key: process.env.OPENAI_KEY,
      },
    }),
  ],
  typescript: {
    outputFile: path.resolve(__dirname, 'payload-types.ts'),
  },
});

Collection config:

import { CollectionConfig } from 'payload/types';
import { lexicalRichTextField } from 'payload-plugin-lexical';

const Lexical: CollectionConfig = {
  slug: 'lexicalRichText',
  admin: {
    useAsTitle: 'title',
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
    },
    lexicalRichTextField({
      name: 'lexicalRichTextEditor',
      label: 'Lexical Rich Text Editor',
    }),
  ],
};

export default Lexical;

Example - more customization and own, custom node:

import { CollectionConfig } from 'payload/types';
import {
  lexicalRichTextField,
  EquationsFeature,
  EmojisFeature,
  EmojiPickerFeature,
  HorizontalRuleFeature,
  FigmaFeature,
  YouTubeFeature,
  TwitterFeature,
  SpeechToTextFeature,
  ImportFeature,
  ExportFeature,
  ClearEditorFeature,
  ReadOnlyModeFeature,
  ConvertFromMarkdownFeature,
  MentionsFeature,
  TreeViewFeature,
  KeywordsFeature,
  AutoCompleteFeature,
  CollapsibleFeature,
  TypingPerfFeature,
  PasteLogFeature,
  TestRecorderFeature,
  LinkFeature,
  TableOfContentsFeature,
  AISuggestFeature,
} from 'payload-plugin-lexical';

const Lexical: CollectionConfig = {
  slug: 'lexicalRichText',
  admin: {
    useAsTitle: 'title',
  },
  fields: [
    {
      name: 'title',
      type: 'text',
      required: true,
    },
    lexicalRichTextField({
      name: 'lexicalRichTextEditor',
      label: 'cool richtext editor',
      localized: true,
      editorConfigModifier: (defaultEditorConfig) => {
        defaultEditorConfig.debug = false;
        defaultEditorConfig.toggles.textColor.enabled = false;
        defaultEditorConfig.toggles.textBackground.enabled = false;
        defaultEditorConfig.toggles.fontSize.enabled = false;
        defaultEditorConfig.toggles.font.enabled = false;
        defaultEditorConfig.toggles.align.enabled = false;
        defaultEditorConfig.toggles.tables.enabled = true;
        defaultEditorConfig.toggles.tables.display = false;

        // Optional: these are the default features. Feel free to customize them or remove the ones you do not like!
        defaultEditorConfig.features = [
          EquationsFeature({}), // LaTex (well KaTeX) equations
          EmojisFeature({}), // Adds new Emoji nodes with new, different-looking emojis
          EmojiPickerFeature({}), // Use in combination with EmojisPlugin. When you start typing ":" it will show you different emojis you can use. They also look different!
          HorizontalRuleFeature({}), // Horizontal rule in the editor.
          FigmaFeature({}), // Figma Embed
          YouTubeFeature({}), // YouTube Embed
          TwitterFeature({}), // Twitter Embed
          SpeechToTextFeature({}), // Adds a Speech-to-text button in the Actions menu (bottom right of the editor). When you click on it and speak, it converts the speech into text
          ImportFeature({}), // Acion button: import
          ExportFeature({}), // Acion button: export
          ClearEditorFeature({}), // Adds a button in the action menu which clears the editor
          ReadOnlyModeFeature({}), // Acion button: toggle read-only mode on or off
          ConvertFromMarkdownFeature({}), // Acion button: convert from markdown
          MentionsFeature({}), // Ability to mention someone when you type "@"
          TreeViewFeature({ enabled: defaultEditorConfig.debug }), // If enabled, will show the node representation of the editor under the editor. Good for debugging
          KeywordsFeature({}), // Highlights certain words
          AutoCompleteFeature({}), // Autocompletes certain words while typing
          CollapsibleFeature({}), // Adds a "collapsible" node
          TypingPerfFeature({ enabled: defaultEditorConfig.debug }), // Some debug tool for performance testing
          PasteLogFeature({ enabled: defaultEditorConfig.debug }), // Another debug tool
          TestRecorderFeature({ enabled: defaultEditorConfig.debug }), // Another debug tool used for lexical core development, with which you can automatically generate tests
          LinkFeature({}), // Obvious: hyperlinks! This includes the AutoLink plugin.
          TableOfContentsFeature({ enabled: false }), // Shows a table of contents on the right hand-side of the screen
          AISuggestFeature({}), // Make sure you set your openai key in the plugin config to be able to use it
        ];

        // A feature can consist of nodes, plugins, modals, toolbar elements and more! YourOwnCustomFeature must be of type "Feature"
        defaultEditorConfig.features.push(YourOwnCustomFeature({}));

        return defaultEditorConfig;
      },
    }),
  ],
};

export default Lexical;

This example can also be found in the demo!

Serializing

Feel free to use my serializer in the serialize-example folder of this repo. Lexical is using bitwise operations for the node formats.

This currently serialized the most important stuff, but not everything. Feel free to contribute to it if you add more!

Idea list:

  • Update slash commands to reflect the toolbar
  • Add wordcount, charactercount & preview to the json output
  • Commenting functionality
  • Upload plugin/node captions
  • Ability to add custom fields to uploads like captions
  • (relationship node?)
  • Fix internal collection search for internal link editor
  • Edit Upload Button
  • Improve design & UX of links. For example, clicking on the link button should open the link drawer immediately
  • (maybe?) lazy loading lexical editor to reduce load times. or maybe just the images?
  • New format/node: "highlight"/"mark" (WILL BE ADDED NATIVELY BY LEXICAL IN 0.7.8)
  • Increase customizability & DX. Plugins should all be set in the config. Slash commands & Toolbar items should come from the same place.
  • Add ExcaliDraw
  • Take a closer look at AutoLink. Is it necessary and what does it do?
  • Make extranodes, extraplugins ... config options hold the ENTIRE nodes, and rename to just "nodes" and "plugins". Makes it easier to remove them and start from scratch, or to insert one at a special position, instead of just pushing it to the end. Especially useful for the Toolbar plugin.
  • extraFloatingToolbarElements
  • Implement Table Cell Background Color PR

Updating lexical

Since this is based on their playground, you gotta upstream their changes. Then, the following is additionally copied over outside of the playground package - needs to be considered in lexical updates as well:

Similar plugins