Adds inline visual editing to Payload live preview. Editors click text in the preview iframe, and changes sync to the admin form and save as a draft when they click Done. A plugin config enables collections, and a listener component is mounted in the preview frontend layout. Requires Payload 3 with live preview configured.
Inline visual editing for Payload CMS live preview (text fields)
Installation
npm i payload-plugin-visual-editor5
Stars
0
Forks
1
Open Issues
4 months ago
Last Updated
0
Weekly Downloads
v1.0.4
npm Version
235.8 KB
Unpacked Size
1
Dependencies
Trends appear after 7 days of data. Daily snapshots have not started yet.
Trends appear after 7 days of data. Daily snapshots have not started yet.
Each point is npm's rolling 7-day download count.
Health Score
Composite score based on GitHub activity, stars, npm downloads, publish recency, dependency count, and package size.
Badge for your README
[](https://payloaddirectory.dev/plugins/1241429177-root)<a href="https://payloaddirectory.dev/plugins/1241429177-root"><img src="https://payloaddirectory.dev/badge/1241429177-root.svg" alt="Payload Directory"></a>README
Inline visual editing for Payload CMS live preview.

Edit text directly in the preview iframe. Changes sync back to the admin document form and save as a draft when you click Done.
data-* attributes or field wrappers in your frontendtext-transform: uppercase on titles)^3.84.0@payloadcms/ui and @payloadcms/live-preview (peer dependencies)VisualEditorListener mounted in the frontend layout used for preview URLspnpm add payload-plugin-visual-editor
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
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.
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>
)
}
| Value | Description |
|---|---|
true | All 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) |
Edits update the admin form immediately. Draft saves are debounced while editing; Done flushes any pending save.
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.
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.
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.
| Import | Description |
|---|---|
payload-plugin-visual-editor | Plugin (payloadVisualEditor) and types |
payload-plugin-visual-editor/client | VisualEditorListener, hooks, VisualEditorAdmin (registered by the plugin) |
payload-plugin-visual-editor/rsc | Re-exports for RSC-compatible setups |
| Issue | What to check |
|---|---|
| Edit button missing | Collection enabled in payloadVisualEditor({ collections }) and live preview configured |
| No blue outlines in preview | VisualEditorListener mounted in the preview frontend layout; field text is visible in the DOM |
| Edits lost while typing | Preview page re-renders on live-preview updates — use the pause/flush pattern above |
| Admin build error after install | Run payload generate:importmap in your project |
This repository is also a Payload plugin template. For local development, testing, and release workflow, see development.sketch.md.
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.
MIT
This is open source work for self hosted Payload CMS instances. This plugin has no relation to the official Payload CMS enterprise visual editor.
plugin
On-page editing and draft preview links for Payload pages rendered in a Next.js frontend
610/wk0v3 v4
payload better preview
Live preview with block hover highlighting and two-way scroll sync between the admin editor and the preview
490/wk16v3
payload better editor
Side-by-side live preview iframe with a sidebar for editing individual blocks in the Payload edit view
710/wk113v3
payload live nav
Section index and field focus bridge that syncs the Payload edit form with Live Preview
628/wk0v3
payload plugin html preview
Live preview and click-to-edit for Payload on any frontend that renders HTML, including static sites and template…
600/wk29v3
payload plugin visual editing
Click-to-edit overlays on your frontend that deep-link back to the matching field in the Payload admin
580/wk29v3