Skip to content

feat(admin): give image blocks an empty placeholder, like videos - #3888

Closed
khoinguyenpham04 wants to merge 37 commits into
mainfrom
noah/image-placeholder
Closed

khoinguyenpham04 wants to merge 37 commits into
mainfrom
noah/image-placeholder

Conversation

@khoinguyenpham04

@khoinguyenpham04 khoinguyenpham04 commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Gives image blocks the same empty placeholder as the video block in #3827, so editors can lay out where images go and add them later, as in Notion.

In the editor

  • /image, including from the + button, and the toolbar's Insert image add an image block and open the media picker straight away. Choosing an image fills the block, as before.
  • Closing the picker leaves the block as a dashed "Upload or choose an image" placeholder, still selected, so Enter reopens the picker. Clicking it, dropping image files on it, or pasting an image while it's selected also fills it.
  • From the selected block, Tab moves to the placeholder, and Escape or Shift+Tab return to the block. Backspace or Delete there removes only the block, and typing or input-method text there doesn't change the text around it.
  • The image toolbar appears once the block has an image. Read-only entries show "No image".
  • An insert undoes in one step, including from the + button.

Shared with the video block

  • The dashed placeholder, its drag highlight, its keys and the guard against native editing move from VideoNode into MediaPlaceholder.tsx, which both node views use. The video block behaves as it does in feat: add a video block to the rich text editor #3827.
  • Fixes a regression that main's editor redesign (feat(admin): lay out the content editor as a page #3710) brought into both blocks: its block selection moves a paste on a selected block to after it, so a file pasted on a selected empty image or video was uploaded below it. The upload extension now takes that paste first.

On the site

Image from emdash/ui renders nothing for an image block without a source. Before, an empty image block rendered an empty <img> and its caption.

Data (additive)

An empty image block is saved as { _type: "image", _key, asset: { _ref: "", url: "" } }, a shape the published PortableTextImageBlock type already allows, so the type doesn't change. No migration, and rendering adds no queries to logged-out pages. The changeset tells sites with their own image renderer to skip these blocks.

Markdown from the MCP server, the CLI and emdash/client writes an image block without a URL as an opaque <!--ec:block … --> comment instead of ![](), which read back as a paragraph of that text. An agent editing a post's text through Markdown would otherwise have put ![]() on the site in place of an empty image.

Known limit: the site's inline visual editor doesn't show a placeholder for an empty image block. Saving there keeps the block as it is.

Type of change

  • Bug fix
  • Feature (requires maintainer-approved Discussion)
  • Refactor (no behavior change)
  • Translation
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • I have read CONTRIBUTING.md
  • pnpm typecheck passes
  • pnpm lint passes
  • pnpm test passes (or targeted tests for my change)
  • pnpm format has been run
  • I have added/updated tests for my changes (if applicable)
  • User-visible strings in the admin UI are wrapped for translation (if applicable). Do not include messages.po changes except in translation PRs — a workflow extracts catalogs on merge to main.
  • I have added and reviewed the user-facing changeset (if this PR changes a published package)
  • New features link to an approved Discussion: https://github.com/emdash-cms/emdash/discussions/...
  • I have included screenshots below if this PR changes the UI

AI-generated code disclosure

  • This PR includes AI-generated code — model/tool: Claude Opus 5.5

Screenshots / test output

Typing /image adds an image block and opens the media picker straight away:

The "Select image" dialog over the post editor, listing Media Library images, with Library and From URL tabs, Upload files, Cancel and an "Insert image" button

Closing the picker leaves the empty block, selected, so Enter reopens it:

The post editor with an empty image block under a paragraph: a dashed box with an image icon and "Upload or choose an image", selected with a blue ring

Dragging a file over it highlights it as the drop target:

The empty image block while a file is dragged over it: a blue dashed border, a grey fill and the label "Drop to upload"

A dropped image uploads into the block's place:

The empty image block replaced by the dropped image, an orange-to-purple gradient, with its caption field under it

Choosing an image from the picker fills the block, and the image toolbar appears:

The filled image block, selected, with the image toolbar above it: Replace, Alt text, alignment, link, image settings and delete

In the Arabic admin the placeholder follows the admin's right-to-left layout. Its label isn't translated yet, since catalogs are extracted after merge:

The Arabic admin with the empty image block at the top of the content: the image icon on the right and the label "Upload or choose an image" aligned right

At phone width and in dark mode:

The empty image block at 390 pixels wide, full width under a paragraph

The empty image block in dark mode: a dark dashed box with a light grey label, selected with a blue ring

Tests: the full admin suite, core render and client tests, root pnpm typecheck, lint and the docs build pass. New tests in image-placeholder.test.tsx drive the full editor, and each fix's test fails without it.

Adds a `video` Portable Text block, `{ _type: "video", asset: { _ref, url?,
provider? }, caption?, width?, height? }`. `Video` from `emdash/ui` renders it
as a native player with controls and its caption, from the storage's public URL
when one is configured; a provider's video renders from the provider's embed.
A `video` block of any other shape still belongs to a plugin.

Core's converters map the block to a `videoBlock` ProseMirror node, the media
usage index records the video it uses (`portable_text_video`), and plain-text
extraction includes its caption.
Type `/video` to choose a Media Library video or upload one. The video
plays in the editor at the width of the text, with a caption field under
it and Replace and Delete in a pill that appears over its corner on hover,
focus or selection. From a selected video, Tab moves through the player,
the caption and the two buttons; Escape returns to the block. A video that
can't be played says so.

The block saves as Portable Text `video` and the editor's node is
`videoBlock`. A plugin that registers `video` keeps its own blocks and the
built-in command steps aside. The media picker gains video copy, and the
admin's CSP allows `blob:` media so the browser can read a video's size
before uploading it.
Video files dropped or pasted into a post now upload to the Media Library
like images do, behind a 16:9 placeholder, and become video blocks between
the surrounding blocks. Images and videos dropped together keep their order.
When a plugin registers its own `video` block, video files are refused as
before.

Adds the changeset for the video block and documents the editor schema
node, the media usage reference type, and the Safari and CSP notes.
The editor takes its direction from the text it contains, so the
"can't be played" message of a broken video at the top of a post could
make an Arabic post read left to right. The message and the action pill
now carry the admin's direction and no longer count as content.
A video block saved with a media ID but no file URL played in the editor
from the item's storage key, while the site, which can't look the key up,
rendered a broken player. The editor now shows such a block as unplayable,
so editors see what readers will. Replace fixes it.
Astro leaves `<` and `>` unescaped in attribute values, so `Video` now
percent-encodes them in the player's and its sources' URLs, as `Iframe`
escapes its attributes. Browsers encode them in URLs anyway, so no
address changes.
The Media Library and REST API pages now list video blocks among the
references **Used in** checks, and the changeset describes the Used in
list instead of a delete warning the admin doesn't show.
The file route takes a storage key, not the media id in `_ref`, so a
block saved without `asset.url` rendered a player that could never
load. The editor already shows such a block as unplayable.
A video block whose `asset.url` is on another https host played on the
site but showed as unplayable in a production admin, because the admin
policy only allowed same-origin and blob: media. Images already allow
https: sources.
A plugin's own video block keeps its fields to itself, as it does in
the renderer, converters and media usage.
A video block an editor hasn't filled yet is saved as
`{ _type: "video", _key }`, so `asset` becomes optional. The converters
round-trip it, and `Video` renders nothing for it instead of failing on
the missing asset.
…s on

/video now adds a dashed placeholder block instead of opening the
picker. Clicking it, or pressing Enter while it's selected, opens the
video picker, and choosing a video fills the block in place. Files
dropped on it, or pasted while it's selected, upload in its place. A
file drag highlights it, without the drop cursor's insertion line.
Like the iframe and HTML blocks, /video defers its insert so the gutter's
+ puts the block at its position in a single transaction, and the editor
keeps focus so Enter can open the picker.
Keys pressed on the placeholder don't reach ProseMirror, so Backspace and
Delete there remove the block directly, rather than depending on the
browser's own editing of the selected node.
…round it

Chromium's own editing of the focused placeholder deletes the block and
joins the paragraphs on either side. With a paragraph after the block,
the test now fails without the Backspace handler or its preventDefault;
before, it passed either way.
…xt around it

ProseMirror leaves keys on the player and the empty block's placeholder
to the browser, whose own editing then changed the document: a typed
letter replaced the block and joined it with the paragraphs on either
side, and Backspace on the player deleted the block and joined them.
The node view now cancels beforeinput from anything in the block but
the caption. Space still plays the video and Enter still opens the
picker.
…he document

An input method's composition can't be cancelled, so with the player or
an empty block's placeholder focused it went into the editor's text
selection: composing Japanese replaced the text of the paragraph above
the block. The node view now clears the selection when a composition
starts there, so the text has nowhere to go. The caption still
composes.
Choosing fills the new block. Closing the picker keeps the empty block
in place to fill later, selected so Enter reopens the picker. The insert
asks the new block to open its picker once it mounts, so loading, undo
and paste never open it.
An image block with neither a file URL nor a media id rendered an empty
<img> inside its figure, with the caption. The editor saves an image it
hasn't filled yet that way, as an asset with an empty _ref and url.
Moves the dashed placeholder, its drag highlight, its Backspace handling
and the guard against the browser editing around a node view into
MediaPlaceholder, so the image block can use the same empty state. The
video block behaves as before.
…m-uploads-8f5d39

Brings in the page layout for the content editor (#3710). Its slash
command list now builds each built-in top-level block from a
module-scope command wrapped by topLevelInsert, so Video follows that
pattern: a videoSlashCommand in Media, added after Gallery so the
category stays together for the arrow keys, and left out when a plugin
defines its own video block.
The slash menu marks each item's title with data-slash-item-title, and
its titles no longer use font-medium.
The slash menu ranks an exact alias above an exact title, so Iframe's
"video" alias put it ahead of the Video block, and /video then Enter
inserted an iframe. /youtube, /vimeo and /embed still find Iframe.
/_emdash/api/media/file/ answers Range requests (#3828), so Safari and
iOS play Media Library videos without a storage public URL, in the
editor and on the site.
The block menu titled a selected video "Block", because its list of
block names had no entry for videos.
/image, the gutter's + and the toolbar's Insert Image add an empty image
block and open the picker. Choosing fills that block; closing the picker
leaves a dashed placeholder to fill later by clicking it, pressing
Enter, or dropping or pasting an image on it. The image toolbar waits
until the block has an image.

An empty image is saved as an asset with an empty _ref and url. Loading
one no longer turns the empty _ref into a file URL. The toolbar and
slash-menu tests that used Image as a picker-only command now cover the
toolbar's insert and a Gallery command instead.
The editor's selection tint covered the player and the caption row of a
selected video, which already shows the selection with its own ring.
From a selected image, Tab moves to its caption, which an empty image
doesn't have, so Tab left the editor. Tab now moves to the placeholder,
and Escape or Shift+Tab return to the block, as in the video block.
…placeholder

Brings in main's page layout for the content editor (#3710) through the
video branch. Image follows its slash command pattern: a module-scope
imageSlashCommand wrapped by topLevelInsert, like Video, so the insert
button's line becomes the image block. The tests follow the toolbar's
sentence-case "Insert image" label, the image controls' toolbar role
and the slash menu's data-slash-item-title.
The editor's block selection moves a paste on a selected block to after
it, so files pasted on a selected empty image or video were uploaded
below the block and left it empty. The upload extension now takes
those pastes before the editor's own paste handling.
…s now

The toolbar's Insert image adds an empty image block instead of opening a picker in the editor, so the mock's choose and cancel buttons had no test left to press.
Closing an image block's picker leaves an empty block to fill later, which the content guide now explains with the ways to fill it. The querying guide says an empty image block renders nothing, and what a replacement image renderer should do with one.
…document

The caption guard attached when the node view mounted, which for an image added through its placeholder was before the caption existed. Choosing an image filled the view in place, so text dropped on its caption went into the document. The guard now attaches again once the image is filled, as the video block's does.
Markdown wrote an image block without a URL as ![](), which reads back as a paragraph of that text, so an empty image written back from the MCP server, the CLI or emdash/client showed ![]() on the site. Such blocks now use the opaque block comment, as unknown blocks do.
@changeset-bot

changeset-bot Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e536873

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@emdash-cms/admin Minor
emdash Minor
@emdash-cms/cloudflare Minor
@emdash-cms/plugin-test Patch
@emdash-cms/sandbox-workerd Patch
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
create-emdash Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
@emdash-cms/auth-atproto Patch
@emdash-cms/plugin-embeds Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 1,327 lines across 17 files. Large PRs are harder to review and more likely to be closed without review.

If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs.

See CONTRIBUTING.md for contribution guidelines.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
docs fb91030 Oct 05 2026, 09:54 PM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://noah-image-placeholder.try.emdashcms.com, https://noah-image-placeholder-emdash-playground.emdash-cms.workers.dev (commit e536873)

This URL reflects your latest Preview deployment

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://3e303f34.try.emdashcms.com, https://3e303f34-emdash-playground.emdash-cms.workers.dev e536873 2026-10-05T22:17:32.780Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://5c359083.try.emdashcms.com, https://5c359083-emdash-playground.emdash-cms.workers.dev fb91030 2026-10-05T21:56:08.347Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://8f8d3ef9.try.emdashcms.com, https://8f8d3ef9-emdash-playground.emdash-cms.workers.dev 01d145d 2026-10-05T16:13:13.481Z Visit the dashboard ↗

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Overlapping PRs

This PR modifies files that are also changed by other open PRs:

This may cause merge conflicts or duplicated work. A maintainer will coordinate.

Base automatically changed from noah/cloudflare-stream-uploads-8f5d39 to main October 5, 2026 20:55
Brings in the squash-merged video block (#3827). The six conflicting
files were unchanged on main since #3827 landed, so each keeps this
branch's version, which already holds #3827's final code.
@pkg-pr-new

pkg-pr-new Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

npm i https://pkg.pr.new/@emdash-cms/admin@3888

@emdash-cms/auth

npm i https://pkg.pr.new/@emdash-cms/auth@3888

@emdash-cms/auth-atproto

npm i https://pkg.pr.new/@emdash-cms/auth-atproto@3888

@emdash-cms/blocks

npm i https://pkg.pr.new/@emdash-cms/blocks@3888

@emdash-cms/cloudflare

npm i https://pkg.pr.new/@emdash-cms/cloudflare@3888

@emdash-cms/contentful-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/contentful-to-portable-text@3888

emdash

npm i https://pkg.pr.new/emdash@3888

create-emdash

npm i https://pkg.pr.new/create-emdash@3888

@emdash-cms/gutenberg-to-portable-text

npm i https://pkg.pr.new/@emdash-cms/gutenberg-to-portable-text@3888

@emdash-cms/plugin-cli

npm i https://pkg.pr.new/@emdash-cms/plugin-cli@3888

@emdash-cms/plugin-test

npm i https://pkg.pr.new/@emdash-cms/plugin-test@3888

@emdash-cms/plugin-types

npm i https://pkg.pr.new/@emdash-cms/plugin-types@3888

@emdash-cms/registry-client

npm i https://pkg.pr.new/@emdash-cms/registry-client@3888

@emdash-cms/registry-lexicons

npm i https://pkg.pr.new/@emdash-cms/registry-lexicons@3888

@emdash-cms/registry-loader

npm i https://pkg.pr.new/@emdash-cms/registry-loader@3888

@emdash-cms/registry-moderation

npm i https://pkg.pr.new/@emdash-cms/registry-moderation@3888

@emdash-cms/registry-verification

npm i https://pkg.pr.new/@emdash-cms/registry-verification@3888

@emdash-cms/sandbox-workerd

npm i https://pkg.pr.new/@emdash-cms/sandbox-workerd@3888

@emdash-cms/x402

npm i https://pkg.pr.new/@emdash-cms/x402@3888

@emdash-cms/plugin-ai-moderation

npm i https://pkg.pr.new/@emdash-cms/plugin-ai-moderation@3888

@emdash-cms/plugin-atproto

npm i https://pkg.pr.new/@emdash-cms/plugin-atproto@3888

@emdash-cms/plugin-audit-log

npm i https://pkg.pr.new/@emdash-cms/plugin-audit-log@3888

@emdash-cms/plugin-color

npm i https://pkg.pr.new/@emdash-cms/plugin-color@3888

@emdash-cms/plugin-embeds

npm i https://pkg.pr.new/@emdash-cms/plugin-embeds@3888

@emdash-cms/plugin-field-kit

npm i https://pkg.pr.new/@emdash-cms/plugin-field-kit@3888

@emdash-cms/plugin-forms

npm i https://pkg.pr.new/@emdash-cms/plugin-forms@3888

@emdash-cms/plugin-webhook-notifier

npm i https://pkg.pr.new/@emdash-cms/plugin-webhook-notifier@3888

commit: e536873

Images and videos share the placeholder and its insert, so the video
block's tests already cover the gutter undo, input method text and the
read-only box. The right-to-left test never checked the placeholder's
direction. The upload extension's paste test ran without the editor's
block selection, so it couldn't catch the bug the full-editor paste test
covers, and the toolbar file's image test is a weaker copy of the one
that also checks the picker opens.
@khoinguyenpham04
khoinguyenpham04 removed this pull request from stack #3899 October 6, 2026 09:52
@ascorbic

ascorbic commented Oct 6, 2026

Copy link
Copy Markdown
Member

I'm not clear why we need this? I don't understand why we'd want to support empty image blocks, particularly when it's a breaking change for custom renderers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants