krzysztofradomski

payload visual editor

by krzysztofradomski
Publishing workflow
v3
^3.84.1

Overview

Summary generated from the README

Adds inline visual editing to Payload live preview. Editors click an Edit control in the admin document bar, then change text directly in the preview, and the changes sync to the admin form. Clicking Done saves a draft. A frontend listener component matches rendered text to field values automatically, so no data attributes are needed. Requires Payload 3, live preview configured on the collection, and the listener mounted in the preview layout.

Features

  • Edit text, textarea, number and richText fields directly in the live preview
  • Automatic case-insensitive text matching without data attributes or wrappers
  • Edit and Done control added to the admin document bar
  • Done commits active edits and saves a draft, with debounced saves while editing
  • Per-collection allowlists and excludes for editable field paths
  • Hooks to pause live-preview state updates while editing

Use cases

  • Let editors fix copy on a page by clicking text in the preview instead of hunting for form fields
  • Restrict inline editing to selected fields such as hero text while keeping slugs locked

From the author

Inline visual editing for Payload CMS live preview (text fields)

Installation

npm i payload-plugin-visual-editor

7

Stars

0

Forks

1

Open Issues

5 months ago

Last Updated

17

Weekly Downloads

v1.0.4

npm Version

235.8 KB

Unpacked Size

1

Dependencies

GitHub stars

7+2 since Sep 7

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

17−21 since Sep 7

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 202617
Dec 5, 202612
Dec 4, 20267
Dec 3, 20269
Dec 2, 202612
Dec 1, 202615
Nov 30, 202615
Nov 29, 202610
Nov 28, 202611
Nov 27, 202611
Nov 26, 202615
Nov 25, 202612
Nov 24, 20269
Nov 23, 20269
Nov 22, 202611
Nov 21, 202610
Nov 20, 202611
Nov 19, 202610
Nov 18, 202611
Nov 17, 202613
Nov 16, 202615
Nov 15, 202619
Nov 14, 202620
Nov 13, 202625
Nov 12, 202628
Nov 11, 202628
Nov 10, 202627
Nov 9, 202629
Nov 8, 202630
Nov 7, 202644
Nov 6, 202640
Nov 5, 202636
Nov 4, 202639
Nov 3, 202641
Nov 2, 202672
Nov 1, 202670
Oct 31, 202659
Oct 30, 202663
Oct 29, 202659
Oct 28, 202654
Oct 27, 202665
Oct 26, 202636
Oct 25, 202634
Oct 24, 202649
Oct 23, 202642
Oct 22, 202660
Oct 21, 202676
Oct 20, 202668
Oct 19, 202670
Oct 18, 202675
Oct 17, 202662
Oct 16, 202666
Oct 15, 202652
Oct 14, 202640
Oct 13, 202642
Oct 12, 202640
Oct 11, 202636
Oct 10, 202634
Oct 9, 202635
Oct 8, 202645
Oct 7, 202652
Oct 6, 202649
Oct 5, 202672
Oct 4, 202673
Oct 3, 202675
Oct 2, 202685
Oct 1, 202688
Sep 30, 202689
Sep 29, 2026112
Sep 28, 202689
Sep 27, 202695
Sep 26, 202698
Sep 25, 202690
Sep 24, 202685
Sep 23, 202683
Sep 22, 202677
Sep 21, 202676
Sep 20, 202672
Sep 19, 2026161
Sep 18, 2026177
Sep 17, 2026244
Sep 16, 2026258
Sep 15, 2026253
Sep 14, 2026254
Sep 13, 2026253
Sep 12, 2026162
Sep 11, 2026144
Sep 10, 202670
Sep 9, 202652
Sep 8, 202638
Sep 7, 202638

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

Health Score

43/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/1241429177-root.svg)](https://payloaddirectory.dev/plugins/1241429177-root)
HTML
<a href="https://payloaddirectory.dev/plugins/1241429177-root"><img src="https://payloaddirectory.dev/badge/1241429177-root.svg" alt="Payload Directory"></a>
Updated Jun 16, 2026Created May 17, 2026Published Jun 16, 2026

README

payload-plugin-visual-editor

Inline visual editing for Payload CMS live preview.

Payload admin preview toolbar closed Payload admin preview toolbar opened

Edit text directly in the preview iframe. Changes sync back to the admin document form and save as a draft when you click Done.

Features

  • Edit text, textarea, number, and richText fields from the live preview
  • Automatic text matching — no data-* attributes or field wrappers in your frontend
  • Case-insensitive matching (e.g. CSS text-transform: uppercase on titles)
  • Edit / Done control in the admin document bar when live preview is active
  • Commits in-progress edits and saves a draft when you click Done
  • Per-collection allowlists and blocklists for field paths

Requirements

  • Payload ^3.84.0
  • @payloadcms/ui and @payloadcms/live-preview (peer dependencies)
  • Live preview configured on the collection
  • VisualEditorListener mounted in the frontend layout used for preview URLs

Installation

pnpm add payload-plugin-visual-editor

Setup

1. Register the plugin

import { payloadVisualEditor } from 'payload-plugin-visual-editor'

export default buildConfig({
  plugins: [
    payloadVisualEditor({
      collections: {
        // Enable all editable field types for this collection
        articles: true,

        // Or restrict which fields can be edited in the preview
        'static-pages': {
          excludeFields: ['slug'],
        },

        // Allowlist only specific paths
        pages: {
          fields: ['title', 'hero.body'],
        },
      },

      // Optional — defaults to text, textarea, number, richText
      editableFieldTypes: ['text', 'textarea', 'number', 'richText'],
    }),
  ],
})

The plugin registers the Edit / Done admin control automatically. You do not need to wire admin components manually.

After adding the plugin, regenerate your project's import map so Payload can resolve the admin UI:

payload generate:importmap

2. Enable live preview on a collection

export const Articles: CollectionConfig = {
  slug: 'articles',
  admin: {
    livePreview: {
      url: ({ data }) => `/articles/${data?.slug}?payloadLivePreview=true`,
    },
  },
  fields: [
    { name: 'title', type: 'text', required: true },
    { name: 'slug', type: 'text', required: true },
    { name: 'content', type: 'richText' },
  ],
}

Preview URLs must be served by the same frontend layout where you mount VisualEditorListener.

3. Mount the frontend listener

Add the listener once to the root layout of your live-preview frontend (not the admin layout):

import { VisualEditorListener } from 'payload-plugin-visual-editor/client'

export default function RootLayout({ children }: { children: React.ReactNode }) {
  return (
    <html>
      <body>
        {children}
        <VisualEditorListener />
      </body>
    </html>
  )
}

Collection options

ValueDescription
trueAll fields matching editableFieldTypes are editable
{ fields?: string[] }Only these dot-paths (e.g. meta.title)
{ excludeFields?: string[] }Remove paths from the editable set (e.g. slug)

Usage

  1. Open a document that has live preview enabled.
  2. Click Edit in the admin bar (next to save / draft controls).
  3. In the preview, hover text that matches a configured field — it is outlined in blue.
  4. Click to edit inline, then blur to apply the change to the form.
  5. Click Done to exit edit mode, commit any active edit, and save the document as a draft.

Edits update the admin form immediately. Draft saves are debounced while editing; Done flushes any pending save.

Live preview pages with React state

If your preview page subscribes to @payloadcms/live-preview and stores document data in React state, pause updates while the user is editing. Otherwise incoming preview events will re-render the page, wipe contenteditable state, and lose the cursor.

Use the hooks exported from the client entry:

'use client'

import { subscribe, unsubscribe } from '@payloadcms/live-preview'
import { useVisualEditorEditMode, useVisualEditorMode } from 'payload-plugin-visual-editor/client'
import { useEffect, useRef, useState } from 'react'

export function ArticlePreview({ initialArticle, serverURL }) {
  const isLivePreview = useVisualEditorMode()
  const isVisualEditing = useVisualEditorEditMode()
  const [article, setArticle] = useState(initialArticle)
  const pendingRef = useRef<typeof initialArticle | null>(null)
  const editingRef = useRef(isVisualEditing)
  editingRef.current = isVisualEditing

  useEffect(() => {
    if (!isLivePreview) return

    const listener = subscribe({
      callback: (data) => {
        if (editingRef.current) {
          pendingRef.current = data
          return
        }
        setArticle(data)
      },
      initialData: initialArticle,
      serverURL,
    })

    return () => unsubscribe(listener)
  }, [initialArticle, isLivePreview, serverURL])

  useEffect(() => {
    if (!isVisualEditing && pendingRef.current) {
      setArticle(pendingRef.current)
      pendingRef.current = null
    }
  }, [isVisualEditing])

  return (
    <article>
      <h1>{article.title}</h1>
      {/* render other fields */}
    </article>
  )
}

See dev/components/PostPreview.tsx in this repo for a full working example.

How matching works

The listener loads editable field paths from the plugin API, subscribes to live-preview document data, and builds a lookup from field values (including rich text plain text and paragraph segments). Visible DOM text is matched case-insensitively.

Your templates only need to render the same text as stored in Payload — no special markup. Text that does not appear in the DOM (hidden fields, computed-only values) cannot be edited visually.

API

GET /api/visual-editor/fields?collection={slug}

Returns editable field descriptors for an enabled collection.

{
  "collection": "articles",
  "fields": [
    { "path": "title", "type": "text" },
    { "path": "richContent", "type": "richText" }
  ]
}

Returns 400 if the collection is not enabled for visual editing.

Exports

ImportDescription
payload-plugin-visual-editorPlugin (payloadVisualEditor) and types
payload-plugin-visual-editor/clientVisualEditorListener, hooks, VisualEditorAdmin (registered by the plugin)
payload-plugin-visual-editor/rscRe-exports for RSC-compatible setups

Troubleshooting

IssueWhat to check
Edit button missingCollection enabled in payloadVisualEditor({ collections }) and live preview configured
No blue outlines in previewVisualEditorListener mounted in the preview frontend layout; field text is visible in the DOM
Edits lost while typingPreview page re-renders on live-preview updates — use the pause/flush pattern above
Admin build error after installRun payload generate:importmap in your project

Contributing

This repository is also a Payload plugin template. For local development, testing, and release workflow, see development.sketch.md.

Local development setup

The plugin's source lives in src/, but the dev app in dev/ (and Payload's auto-generated dev/app/(payload)/admin/importMap.js) imports it under its published name — payload-plugin-visual-editor/client and payload-plugin-visual-editor/rsc — so the dev environment mirrors what consumers see in their own projects.

Because the plugin is not actually installed in node_modules during local development, those subpath imports are wired up through two small pieces of glue (instead of a link:. self-dependency in package.json, which would pollute the published manifest):

  • dev/tsconfig.json — compilerOptions.paths maps payload-plugin-visual-editor, …/client, and …/rsc to the matching files under ../src/. This is what TypeScript and editors use for type checking and go-to-definition.
  • dev/next.config.mjs — turbopack.resolveAlias and webpack.resolve.alias map the /client and /rsc subpaths to the same source files at runtime, so both pnpm dev --turbo and the standard webpack build resolve them without a real package install.

dev/payload.config.ts is loaded by the Payload CLI (Node, not Next), so it imports payloadVisualEditor via a plain relative path (../src/index.js) — Node never sees the package name.

If you add a new public entry point under src/exports/, update both the tsconfig paths and the alias map in dev/next.config.mjs to keep the dev app resolving it.

License

MIT

Note

This is open source work for self hosted Payload CMS instances. This plugin has no relation to the official Payload CMS enterprise visual editor.

Similar plugins