raphaelApard

payload preview click

by raphaelApard
Publishing workflow
v3
^3.0.0
MIT

Overview

Summary generated from the README

Adds click-to-edit to Payload live preview. Clicking a block or field in the preview scrolls the admin form to it, expands it and focuses it, and links to other pages open that document in the admin. The admin side is a plugin configured per collection, while a framework-agnostic script and helpers run on the preview page. Requires Payload 3, Next.js 15 or later and React 19 in the admin; currently alpha.

Features

  • Selects a block, then array row, then field with successive clicks, and Escape goes back up
  • Scrolls, expands and focuses the matching field in the admin edit form
  • Opens linked pages as documents in the admin through a page resolver
  • Helpers to mark blocks with comments or attributes and fields with data attributes
  • Framework-agnostic preview script, with an Astro example and a global build
  • Posts messages only to configured origins and validates paths, ids and locales

Use cases

  • Help editors jump from a live preview section straight to its field in a long blocks form
  • Add visual editing to an Astro or other non-React frontend that uses Payload live preview
  • Navigate between pages from the preview to edit linked documents in the admin

From the author

Click a block or field in the Payload live preview to open it in the edit form. A free, framework-agnostic click-to-edit for Payload 3.

Installation

npm i payload-preview-click

0

Stars

0

Forks

0

Open Issues

4 weeks ago

Last Updated

7

Weekly Downloads

v0.1.0-alpha.1

npm Version

62.0 KB

Unpacked Size

0

Dependencies

GitHub stars

00 since Nov 1

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

7+7 since Nov 9

Show data
npm weekly downloads by day (UTC)
DateWeekly downloads
Dec 6, 20267
Dec 5, 20265
Dec 4, 202612
Dec 3, 202613
Dec 2, 202614
Dec 1, 202619
Nov 30, 202619
Nov 29, 202618
Nov 28, 202621
Nov 27, 202615
Nov 26, 202616
Nov 25, 202617
Nov 24, 202615
Nov 23, 202616
Nov 22, 202619
Nov 21, 202620
Nov 20, 202621
Nov 19, 202627
Nov 18, 202636
Nov 17, 202644
Nov 16, 2026348
Nov 15, 2026345
Nov 14, 2026341
Nov 13, 2026338
Nov 12, 2026330
Nov 11, 2026318
Nov 10, 2026307
Nov 9, 20260

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

Health Score

67/100Good

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

README

English · Français

payload-preview-click

Click a block or a field in the Payload live preview: the edit form scrolls to it, expands it and focuses it. Click a link to another page: that page opens in the admin.

Alpha. The API may change before 1.0.

A free, MIT-licensed alternative to part of Payload's Visual Editor (Enterprise). It does not edit in place: it takes editors to the right spot in the regular form. Not affiliated with Payload.

Install

pnpm add payload-preview-click

Requires Payload 3, Next.js ≥ 15 and React 19 on the admin side. The preview side has no dependencies.

1. Admin

// payload.config.ts
import { previewClickPlugin } from 'payload-preview-click'

export default buildConfig({
  plugins: [
    previewClickPlugin({ collections: { pages: 'layout' } }), // collection → its blocks field
  ],
})

Then run pnpm payload generate:importmap. Live preview must be set up for the collection (admin.livePreview.url).

2. Preview page

Mark the blocks: a comment before each block, and one after the last.

import { blockMarker, BLOCKS_END } from 'payload-preview-click/preview'

blockMarker(3, 'faq') // '<!--preview-block:3:faq-->', 3 = row of the block

Or, in React and similar, attributes on the block's root: blockAttributes(isPreview, index, blockType).

Mark the fields: paths relative to the block, array rows by index. Outside the preview, nothing is added.

import { editable } from 'payload-preview-click/preview'

const edit = editable(isPreview) // or Astro.locals, with a `preview` flag
edit('title')                    // { 'data-preview-field': 'title' }
edit(`items.${i}.question`)      // { 'data-preview-field': 'items.2.question' }

Run the script, on the preview page only:

import { initPreviewClick, pageLinks, pageResolver } from 'payload-preview-click/preview'

initPreviewClick({
  cmsOrigin: 'https://cms.example.com', // messages are posted to this origin only
  path: 'layout',                       // same blocks field as in the plugin
  current: { collection: 'pages', id: 4, locale: 'en' },
  // Optional: which links open which document. Without it, links are blocked.
  resolvePage: pageResolver({
    collection: 'pages',
    links: pageLinks([{ id: 4, paths: { en: '/about/', fr: '/fr/a-propos/' } }]),
  }),
})

Other options: labels (texts shown to the editor), color, keepState. Without a bundler, load payload-preview-click/preview.global.js and call window.PayloadPreviewClick.initPreviewClick().

Astro

Set Astro.locals.preview = true in the preview route, then:

---
// RenderBlocks.astro
import { blockMarker, BLOCKS_END } from 'payload-preview-click/preview'
const preview = !!Astro.locals.preview
---
{Astro.props.blocks.map((block, i) => (
  <>{preview && <Fragment set:html={blockMarker(i, block.blockType)} />}<Block block={block} /></>
))}
{preview && <Fragment set:html={BLOCKS_END} />}
---
// Faq.astro
import { editable } from 'payload-preview-click/preview'
const edit = editable(Astro.locals)
---
<h2 {...edit('title')}>{Astro.props.block.title}</h2>
<!-- PreviewHead.astro, in <head> on the preview only -->
<script>
  import { initPreviewClick } from 'payload-preview-click/preview'
  initPreviewClick({ cmsOrigin: import.meta.env.PUBLIC_CMS_URL, path: 'layout' })
</script>

How it works

In the preview, the first click selects a block, each next click goes one level down (array row, then field), and Escape goes back up. Each selection is posted to the admin:

{ type: 'payload-preview-click', path: 'layout', index: 3, field?: 'items.2.question' }
{ type: 'payload-preview-navigate', collection: 'pages', id: 4, locale?: 'fr' }

Links do not leave the preview: a link to a known page opens it in the admin (⌘/Ctrl + click inside a block), other links and forms are blocked.

Security

  • The admin only reads messages from the origin of the live preview URL; the preview only posts to cmsOrigin.
  • Paths, ids and locales are strictly validated; navigation stays within the edited collection.
  • This package does not protect your preview route: sign its links and serve drafts with no-store and noindex.

Limitations (alpha)

  • Collections only, one blocks field per collection.
  • Relies on Payload's DOM ids and @payloadcms/ui hooks; tested with Payload 3.93 and Next 16.
  • Fields in a closed tab cannot be reached.
  • Navigation assumes autosave on drafts.

Development

pnpm install && pnpm test && pnpm build

To try it in a Next.js app, install it with file:../payload-preview-click, not link: (Turbopack does not follow symlinks outside the project root).

License

MIT

Similar plugins