Skip to content

feat(admin): add an image toolbar and inline captions to the editor - #3657

Merged
ascorbic merged 17 commits into
mainfrom
noah/editor-media/image-toolbar
Sep 30, 2026
Merged

ascorbic merged 17 commits into
mainfrom
noah/editor-media/image-toolbar

Conversation

@khoinguyenpham04

@khoinguyenpham04 khoinguyenpham04 commented Sep 29, 2026 •

Copy link
Copy Markdown
Collaborator

What does this PR do?

Replaces the selected-image controls in the Portable Text editor with one floating toolbar, and lets authors type captions directly under images.

  • Toolbar: selecting an image shows a toolbar above it with Replace, Alt text, alignment (None, Left, Center, Right), Link, Image settings and Delete. It replaces the pencil, sliders and trash buttons in the image's corner. The text formatting bubble no longer appears for a selected image.
  • Alt text: the Alt text button edits the description in the toolbar. It is highlighted once the image has a description, and its hint shows that description, or "No description yet". Alt text that is only the Media Library file name doesn't count as a description.
  • Link: the Link button edits the image link in the toolbar with the existing search-or-URL field, plus Remove link, Cancel and Apply.
  • Captions: a caption field sits under every image while the editor is editable, bound to the existing caption attribute. An empty caption shows a placeholder, and Enter starts a new paragraph after the image. A read-only editor shows the caption as text only when it isn't empty.
  • Keyboard: Tab moves from the selected image to its caption and then into the toolbar. Shift+Tab and Escape move back.
  • Focus: the toolbar and the image's selection ring show only while focus is inside the editor, its captions or the toolbar.
  • Small screens: below 640px the text buttons show only their icons, and below 480px the controls wrap onto two rows.
  • Settings panel: the image settings panel now closes when the image is changed outside it, so Apply can no longer overwrite those changes with stale values.

Stored Portable Text is unchanged. Wide and Full alignment stay hidden (#2931). The settings panel keeps every advanced field.

There is no linked issue.

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 (Claude Code), with a separate Claude Opus 5.5 adversarial review pass

Screenshots / test output

The selected image with its toolbar and caption. The Alt text button is highlighted because the image has a description.

Editor with a selected photo of workshop tools: a toolbar above it with Replace, a highlighted Alt text button, four alignment buttons with None pressed, Link, Image settings and Delete, and the caption typed under the photo

Alt text edited in the toolbar, with Cancel and Save.

The image toolbar replaced by an alt text field holding the image's description, with Cancel and Save buttons

The link row, with Cancel and Apply.

The image toolbar replaced by a "Search or type a URL" field with Cancel and Apply buttons

On a phone (iPhone 13 emulation) the controls show only their icons and wrap onto two rows. Here the toolbar sits below the image because there is no room above it.

Phone-width editor with the image selected and the toolbar below the caption, icons only, wrapped onto two rows

In Arabic the toolbar mirrors, with Replace at the start.

Arabic admin with the image toolbar mirrored right to left: Replace and Alt text labels in Arabic on the right, Delete on the left

Test output:

  • packages/admin vitest (Chromium): 207 files, 2829 tests passed
  • e2e/tests/editor-image-toolbar.spec.ts: 1 passed (caption and alt text persist through save and reload)
  • pnpm build, pnpm typecheck, pnpm lint:quick and pnpm lint:json (0 diagnostics) pass
  • Firefox (manual Playwright check): drag-selecting caption text works; before the fix, Firefox couldn't select text in a field inside the draggable image node

Selecting an image in a Portable Text field now shows one floating toolbar
above it: Replace, Alt text, alignment (None, Left, Center, Right), Link,
Image settings and Delete. It replaces the three corner buttons, the quick
alt text overlay and the link-only text bubble, which is text-only again.

The toolbar hides when focus leaves it for another field, stays put while
the Replace picker is open so focus can return to the button, and is
reachable from a selected image with Tab. The settings panel now closes
when the image changes outside it or is removed, so Apply can no longer
write stale values back.
An image's caption is now a field directly under it, with the placeholder
"Type caption for image (optional)" while empty, and saves to the existing
caption attribute. Enter starts a new paragraph after the image. Tab moves
from a selected image to its caption and then the toolbar; Shift+Tab and
Escape move back. Read-only editors show the caption as text only.

The selection ring moves from the block to the image, and text dropped on
a caption stays in the caption instead of landing in the document.
The toolbar's alt text button reads "Add alt text", with a warning dot,
when an image has no description or, for a Media Library image, only its
file name. The file name comes from the media item the image already
loads, so no extra request is made.

Documents the image toolbar and inline captions, and adds the changeset
for the whole capability.
On phones and narrow windows the toolbar was wider than the screen and
scrolled sideways, hiding Link, Settings and Delete. Below 640px, Replace
and Alt text now show only their icons (their names stay available to
screen readers), and below 480px the controls wrap onto two centered
rows: Replace, Alt text and alignment, then Link, Settings and Delete.
The alt text and link fields shrink to fit.
Hovering or focusing "Add alt text" now shows "This image has no
description for screen readers". Hints on the image toolbar open after a
200 ms rest instead of Base UI's 600 ms default, open at once when moving
between buttons, and close when the toolbar hides instead of staying
behind in the corner of the page.
The link row had only an Apply button, drawn with an "open in new tab"
arrow, so there was no visible way to back out. It now ends with Cancel
and a check-mark Apply link, like the alt text row. Remove link still
shows when the image has a link.
The toolbar now fades and scales in from the edge nearest the image each
time it appears, with the same 150 ms entrance as Kumo tooltips. It is
skipped when the system asks for reduced motion.
Switching straight from one image to another kept the toolbar attached,
so the entrance never replayed there, and the 10% scale-up felt slow on a
toolbar this wide. The toolbar now fades and scales in from 97% over
150 ms with a strong ease-out whenever it appears or moves to another
image. Edits to the same image, such as alignment, don't replay it.
Reduced motion keeps only the fade.
The alt text button switched between "Alt text" and "Add alt text" with a
yellow dot, so the toolbar changed width from one image to the next and
re-centered mid-entrance, making Replace and the alt text icon jump. The
button now always reads "Alt text" and is highlighted once the image has
a description, like Link when a link is set. Hovering it shows the
description, or "No description yet".

Escape in the toolbar now returns to the editor even when a button's
hint is open; the hint used to swallow the key.
ProseMirror keeps an image selected after focus moves elsewhere, so its
ring stayed on while the author typed in another field. The ring now
shows only while focus is inside the editor, including its captions and
toolbar, matching when the image toolbar is visible.
… keyboard

Pressing Enter on Alt text or Add link swapped the focused button out, and
the focus gate read the lost focus as leaving the editor, so the toolbar
hid before the input could take focus. Focus now waits on the toolbar
while the row changes.
…lves

A pick disables the link input until its URL resolves, which moves focus
to the page. The focus gate hid the toolbar and remounted the row, so an
entry without a URL yet lost its error message. The gate now ignores that
focus loss, hides once focus lands anywhere outside the editor, and skips
the work when the toolbar is already hidden.
Firefox can't drag-select text inside a draggable element, and the image
node view is draggable. The node view stops being draggable while a mouse
pointer is over the caption.
The media picker can park focus on its own dialog while it closes, before
returning focus to Replace or the editor. The focus gate treated that
focus, and the focus loss when the dialog unmounted, as leaving the
editor and hid the toolbar, so focus had nowhere to return. While the
picker is closing, focus in its dialog no longer ends the pause; focus
anywhere else outside the editor still hides the toolbar.
…ge-toolbar

# Conflicts:
#	packages/admin/src/components/PortableTextEditor.tsx
@changeset-bot

changeset-bot Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 4c19870

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 added review/needs-review No maintainer or bot review yet cla: signed labels Sep 29, 2026
@cloudflare-workers-and-pages

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 7c166db Sep 29 2026, 07:34 PM

@github-actions

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 1,728 lines across 11 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 Sep 29, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview URL: https://noah-editor-media-image-toolbar.try.emdashcms.com, https://noah-editor-media-image-toolbar-emdash-playground.emdash-cms.workers.dev (commit 4c19870)

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://9b28d3de.try.emdashcms.com, https://9b28d3de-emdash-playground.emdash-cms.workers.dev 4c19870 2026-09-29T20:20:59.019Z Visit the dashboard ↗
  • Build: Success ✅
  • Deployment: Success ✅

View logs ↗
https://d689381e.try.emdashcms.com, https://d689381e-emdash-playground.emdash-cms.workers.dev 7c166db 2026-09-29T19:35:27.510Z Visit the dashboard ↗

@pkg-pr-new

pkg-pr-new Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/auth-atproto

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

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

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

emdash

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

create-emdash

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

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

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

@emdash-cms/plugin-cli

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

@emdash-cms/plugin-test

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

@emdash-cms/plugin-types

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

@emdash-cms/registry-client

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

@emdash-cms/registry-lexicons

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

@emdash-cms/registry-loader

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

@emdash-cms/registry-moderation

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

@emdash-cms/registry-verification

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

@emdash-cms/sandbox-workerd

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-field-kit

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: 4c19870

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reasonable, well-scoped admin UX improvement: it consolidates scattered image controls into one discoverable toolbar, keeps captions editable inline, and fixes the stale-settings-panel problem by closing the panel when the node changes outside it. The implementation follows existing TipTap/Kumo patterns, the new tests cover the key interactions, and the docs prose is updated to match.

The main concern is procedural: AGENTS.md/CONTRIBUTING requires a prior maintainer-approved Discussion for a new feature, and the PR body explicitly says “no Discussion link yet.” That should be resolved before merge.

I also found one real correctness bug: the Alt text highlight decides whether a local image is “described” by comparing the alt text to the fetched media filename, but the toolbar’s media query is enabled: false, so when the cache hasn’t loaded yet the comparison treats a filename-only alt as a description. The current unit test pre-warms the cache, so it doesn’t catch this race. Details and a fix are in the line comment.

Changeset: the description is accurate but is one long paragraph; splitting it would make the CHANGELOG entry easier to scan. Not blocking.

@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-review No maintainer or bot review yet labels Sep 29, 2026
The Alt text button compared the alt text with the Media Library file name
from the node view's cached media item. Until that item loaded, a file-name
alt counted as a description, so the button lit up and then turned off,
most visibly right after Replace. A Media Library image now counts as
described only once its media item has loaded, and Replace seeds the cache
with the picked item so the state is right straight away.
A bullet list is easier to scan in the CHANGELOG than one paragraph.
@github-actions github-actions Bot added review/needs-rereview New commits since the last review and removed review/awaiting-author Reviewed; waiting on the author to respond labels Sep 29, 2026
@khoinguyenpham04 khoinguyenpham04 added the bot:review Trigger an emdashbot code review on this PR label Sep 29, 2026

@emdashbot emdashbot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a reasonable, well-scoped admin UX improvement. The previous needs_fixing bug is fixed: the Alt-text highlight now waits for a cached media item before deciding whether a local image's alt matches the Media Library file name, so it no longer treats a filename-only alt as a real description while the item is loading. The new regression test explicitly exercises that loading gap, and the expanded test suite covers keyboard focus, replacement, link editing, settings-panel staleness, captions, and responsive layout.

Code quality is solid: the toolbar follows existing BubbleMenu patterns, the caption node view keeps WYSIWYG parity with the published renderer, RTL-safe logical Tailwind classes are used, all UI strings go through Lingui, and the changeset and docs prose have been updated and split into helpful bullets.

The one unresolved procedural concern from the prior review is still the missing maintainer-approved Discussion link. CONTRIBUTING.md § Contribution Policy requires one for feature PRs, and the PR template checkbox for it is still unchecked. That should be resolved before merge.

So: the implementation looks correct and the tests pass structurally; once the Discussion link is added/verified, this is ready for approval.

@emdashbot emdashbot Bot removed the bot:review Trigger an emdashbot code review on this PR label Sep 29, 2026
@github-actions github-actions Bot added review/awaiting-author Reviewed; waiting on the author to respond and removed review/needs-rereview New commits since the last review labels Sep 29, 2026

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Works well

@ascorbic
ascorbic merged commit 2288fa6 into main Sep 30, 2026
46 checks passed
@ascorbic
ascorbic deleted the noah/editor-media/image-toolbar branch September 30, 2026 11:50
@github-actions github-actions Bot added review/approved Approved; no new commits since and removed review/awaiting-author Reviewed; waiting on the author to respond labels Sep 30, 2026
@emdashbot emdashbot Bot mentioned this pull request Sep 30, 2026
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