erreib

payload lexical collaboration

by erreib
Publishing workflow
v3
^3.17.1
MIT

Overview

Summary generated from the README

Adds collaborative commenting to Payload's Lexical editor. It creates a comments collection and a CommentFeature that can be enabled globally or per richText field. Commented text is highlighted with mark nodes and managed from a comment panel. Requires Payload 3.17.1 or newer and the Lexical rich text package.

Features

  • Inline comments attached to selected text
  • Threaded replies and resolve status
  • Comments linked to Payload users as authors
  • Visual highlighting of commented text
  • Comment panel with a delete-all action
  • Disable option that keeps mark nodes registered

Use cases

  • Review draft copy with editors by commenting directly on text in the admin
  • Discuss and resolve feedback on a post without leaving Payload

From the author

A Payload CMS Lexical editor plugin that adds collaborative commenting functionality

Installation

npm i payload-lexical-collaboration

13

Stars

1

Forks

3

Open Issues

1 years ago

Last Updated

75

Weekly Downloads

v1.0.4

npm Version

265.1 KB

Unpacked Size

0

Dependencies

GitHub stars

130 since Sep 7

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

81−60 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202681
Dec 5, 202691
Dec 4, 202666
Dec 3, 202669
Dec 2, 202665
Dec 1, 202681
Nov 30, 202691
Nov 29, 202698
Nov 28, 202693
Nov 27, 202698
Nov 26, 2026119
Nov 25, 2026117
Nov 24, 2026109
Nov 23, 2026111
Nov 22, 2026128
Nov 21, 2026114
Nov 20, 2026108
Nov 19, 202696
Nov 18, 2026107
Nov 17, 2026125
Nov 16, 2026137
Nov 15, 2026159
Nov 14, 2026171
Nov 13, 2026188
Nov 12, 2026194
Nov 11, 2026189
Nov 10, 2026192
Nov 9, 2026184
Nov 8, 2026164
Nov 7, 2026167
Nov 6, 2026152
Nov 5, 2026158
Nov 4, 2026178
Nov 3, 2026177
Nov 2, 2026199
Nov 1, 2026206
Oct 31, 2026209
Oct 30, 2026222
Oct 29, 2026190
Oct 28, 2026155
Oct 27, 2026153
Oct 26, 2026134
Oct 25, 2026130
Oct 24, 2026120
Oct 23, 202696
Oct 22, 2026155
Oct 21, 2026210
Oct 20, 2026207
Oct 19, 2026202
Oct 18, 2026185
Oct 17, 2026215
Oct 16, 2026245
Oct 15, 2026228
Oct 14, 2026207
Oct 13, 2026208
Oct 12, 2026210
Oct 11, 2026224
Oct 10, 2026208
Oct 9, 2026205
Oct 8, 2026201
Oct 7, 2026198
Oct 6, 2026176
Oct 5, 2026177
Oct 4, 2026151
Oct 3, 2026129
Oct 2, 2026105
Oct 1, 202667
Sep 30, 202636
Sep 29, 202645
Sep 28, 202631
Sep 27, 202631
Sep 26, 202634
Sep 25, 202636
Sep 24, 202650
Sep 23, 202652
Sep 22, 202656
Sep 21, 202654
Sep 20, 202665
Sep 19, 202662
Sep 18, 202663
Sep 17, 202650
Sep 16, 202670
Sep 15, 202657
Sep 14, 202661
Sep 13, 202671
Sep 12, 2026111
Sep 11, 2026130
Sep 10, 2026145
Sep 9, 2026128
Sep 8, 2026140
Sep 7, 2026141

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

Health Score

31/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/953493610-root.svg)](https://payloaddirectory.dev/plugins/953493610-root)
HTML
<a href="https://payloaddirectory.dev/plugins/953493610-root"><img src="https://payloaddirectory.dev/badge/953493610-root.svg" alt="Payload Directory"></a>
Updated Apr 17, 2025Created Mar 23, 2025Published Mar 27, 2025

README

Payload Lexical Collaboration Plugin

A Payload CMS plugin that adds collaborative commenting functionality to the Lexical rich text editor, enabling content teams to discuss and collaborate on content directly within the editor. Based on the example on https://playground.lexical.dev/ and the Payload plugin template.

Features

  • Inline Comments: Add comments to specific text selections within the editor
  • Comment Threads: Create and manage threaded discussions on content
  • Comment Resolution: Mark comments as resolved to track progress
  • User Attribution: Comments are linked to Payload users for accountability
  • Real-time Updates: Comments update in real-time when using Payload's REST API
  • Visual Highlighting: Commented text is visually highlighted in the editor
  • Comment Panel: Dedicated panel for viewing and managing all comments
  • Seamless Integration: Works with Payload's existing user system and permissions

Installation

npm install payload-lexical-collaboration
# or
yarn add payload-lexical-collaboration
# or
pnpm add payload-lexical-collaboration

Usage

Add to your Payload config

import { buildConfig } from 'payload/config';
import { payloadLexicalCollaboration } from 'payload-lexical-collaboration';

export default buildConfig({
  // ... other config
  plugins: [
    payloadLexicalCollaboration({
      // Optional configuration options
      // disabled: false,
      // collections: { users: true } // Specify collections to add custom fields to
    }),
  ],
});

Add the CommentFeature to Lexical

You can add the CommentFeature in two ways:

Option 1: Globally for all richText fields
import { buildConfig } from 'payload/config';
import { lexicalEditor } from '@payloadcms/richtext-lexical';
import { CommentFeature } from 'payload-lexical-collaboration';

export default buildConfig({
  // ... other config
  editor: lexicalEditor({
    features: [
      // ... other global features
      CommentFeature({
        // Optional configuration options
        // enabled: true,
      }),
    ],
  }),
  // ... rest of config
});
Option 2: Per field configuration
import { CommentFeature } from 'payload-lexical-collaboration';

const Page = {
  slug: 'posts',
  fields: [
    {
      name: 'content',
      type: 'richText',
      features: [
        // ... other features
        CommentFeature({
          // Optional configuration options
          // enabled: true,
        }),
      ],
    },
  ],
};

How It Works

The plugin consists of several key components:

  1. Payload Plugin: Creates a new collection called lexical-collaboration-plugin-comments to store comments and their associated metadata.

  2. Lexical Feature: Adds UI components and functionality to the Lexical editor for creating, viewing, and managing comments.

  3. Comment Store: Manages the state of comments and provides methods for adding, deleting, and updating comments.

  4. Mark Nodes: Uses Lexical's mark nodes to highlight commented text in the editor.

  5. API Integration: Communicates with Payload's REST API to persist comments and sync them across users.

Comment Structure

Comments are stored with the following structure:

  • documentId: The ID of the document being commented on
  • threadId: The ID of the thread the comment belongs to
  • content: The text content of the comment
  • author: Relationship to the Payload user who created the comment
  • quote: The text that was selected when creating the comment
  • range: JSON data representing the selection range
  • resolved: Boolean indicating if the comment has been resolved
  • parentComment: Optional relationship to a parent comment (for threaded replies)

Configuration Options

Plugin Options

The payloadLexicalCollaboration function accepts the following options:

OptionTypeDefaultDescription
disabledbooleanfalseDisable the plugin entirely while preserving database schema
collectionsPartial<Record<CollectionSlug, true>>{}Specify collections to add custom fields to

Disabling the Plugin

When you need to disable the plugin, there are two recommended approaches:

payloadLexicalCollaboration({
  collections: {
    posts: true,
  },
  disabled: true, // This preserves comment marks in documents
})

This approach is recommended because it:

  • Preserves the database schema for migrations
  • Keeps the MarkNode registered to prevent "parseEditorState: type 'mark' not found" errors
  • Hides all comment highlights in the editor (they become transparent)
  • Disables all plugin functionality
Option 2: Use the CommentFeature with enabled: false
CommentFeature({ enabled: false })

This approach:

  • Registers the MarkNode to prevent errors
  • Hides all comment highlights in the editor (they become transparent)
  • Disables all commenting UI and functionality
  • Is useful when you want to disable commenting for specific fields

Important: Avoid completely commenting out the plugin in your config if you have documents with comment marks. This will cause "parseEditorState: type 'mark' not found" errors when loading those documents.

Feature Options

The CommentFeature function accepts the following options:

OptionTypeDefaultDescription
enabledbooleantrueEnable or disable the commenting feature for a specific field

Uninstallation

Before completely removing the plugin from your project, it's important to follow these steps to ensure your content remains accessible:

Important Warning

Leaving comment highlights in your documents will create node types that cannot be read without the plugin installed. This can cause errors when loading documents after the plugin is removed.

Safe Uninstallation Process

  1. Delete all comments: Before uninstalling, ensure all comments and their highlights are removed from your documents.

    • Open each document with comments and use the "Delete All" function available within each post's comment tray
    • Make sure to save each document after deleting the comments
  2. Temporarily disable the plugin: Use one of the disabling options mentioned above before completely removing it:

    payloadLexicalCollaboration({
      disabled: true
    })
    
  3. Verify content integrity: Open your documents to ensure they load correctly with the plugin disabled

  4. Remove the plugin: Once you've confirmed all documents load correctly, you can safely:

    • Remove the plugin from your Payload configuration
    • Uninstall the package with your package manager:
      npm uninstall payload-lexical-collaboration
      # or
      yarn remove payload-lexical-collaboration
      # or
      pnpm remove payload-lexical-collaboration
      

Note: If you've already uninstalled the plugin and are experiencing "parseEditorState: type 'mark' not found" errors, you'll need to reinstall the plugin, delete all comments, and then follow the safe uninstallation process.

Requirements

  • Payload CMS v3.17.1 or higher
  • @payloadcms/richtext-lexical v3.17.1 or higher
  • Node.js ^18.20.2 || >=20.9.0

Development

Project Structure

src/
├── index.ts                  # Main plugin entry point
├── exports/                  # Export files for client and RSC
└── features/
    └── commenting/           # Commenting feature implementation
        ├── api/              # API services
        ├── components/       # React components
        ├── hooks/            # React hooks
        ├── services/         # Service classes
        ├── types/            # TypeScript types
        ├── utils/            # Utility functions
        ├── command.ts        # Lexical commands
        ├── feature.client.tsx # Client-side feature implementation
        ├── feature.server.ts # Server-side feature implementation
        └── store.ts          # Comment state management

Building

# Install dependencies
pnpm install

# Build the plugin
pnpm build

Testing with the Dev Environment

This plugin includes a development environment with a pre-configured Payload CMS instance for testing:

  1. Create a .env file in the dev directory (you can copy from .env.example):

    DATABASE_URL=file:./payload.db
    PAYLOAD_SECRET=YOUR_SECRET_HERE
    
  2. Start the development server:

    pnpm dev
    
  3. The server will start at http://localhost:3000/admin with the following credentials:

  4. The dev environment includes:

    • A pre-configured posts collection with the commenting feature enabled
    • SQLite database for persistence
    • Next.js for the admin panel

This development environment is ideal for testing changes to the plugin or exploring its functionality before integrating it into your own project.

License

MIT

Similar plugins

payload lexical collaboration — Payload Directory