Repository navigation
feat(admin): give image blocks an empty placeholder, like videos - #3888
khoinguyenpham04 wants to merge 37 commits into
Conversation
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 detectedLatest commit: e536873 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
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 |
Scope checkThis 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. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | fb91030 | Oct 05 2026, 09:54 PM |
🚀 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 deploymentPreview Deployments by commit
|
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-test
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-loader
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
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.
|
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. |
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.Shared with the video block
VideoNodeintoMediaPlaceholder.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.On the site
Imagefromemdash/uirenders 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 publishedPortableTextImageBlocktype 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/clientwrites 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
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change)pnpm formathas been runmessages.pochanges except in translation PRs — a workflow extracts catalogs on merge tomain.AI-generated code disclosure
Screenshots / test output
Typing
/imageadds an image block and opens the media picker straight away:Closing the picker leaves the empty block, selected, so Enter reopens it:
Dragging a file over it highlights it as the drop target:
A dropped image uploads into the block's place:
Choosing an image from the picker fills the block, and the image toolbar appears:
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:
At phone width and in dark mode:
Tests: the full admin suite, core render and client tests, root
pnpm typecheck, lint and the docs build pass. New tests inimage-placeholder.test.tsxdrive the full editor, and each fix's test fails without it.