Skip to content

feat(admin): optional link on portable-text image blocks - #704

Closed
drudge wants to merge 2 commits into
emdash-cms:mainfrom
drudge:drudge/image-link
Closed

drudge wants to merge 2 commits into
emdash-cms:mainfrom
drudge:drudge/image-link

Conversation

@drudge

@drudge drudge commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds an optional link: { href; blank? } on portable-text image blocks, round-tripped through the PT ↔ PM converters. The existing editor Link buttons (main toolbar and bubble menu) now operate on image selection: selecting an image and clicking Link opens the URL popover pre-populated with the image's current link, and apply/remove updates the image node's attrs. Image.astro wraps the rendered <img> in an <a> using sanitizeHref() when link.href is set. ImageDetailPanel gains a Link URL input and an "Open in new tab" checkbox as a secondary editing surface.

Split from #679 per @ascorbic's review ("it'd be worth opening those as separate PRs … the image link is definitely a separate concern"). The image-link portion and its Copilot follow-ups land here; the repeater BlockKit element will follow on the original PR #679 branch (force-pushed), and media_picker in a third PR.

Relative paths like /page are accepted — the Link URL input is type="text" (not type="url") so it matches how text-link inputs behave elsewhere in the editor. sanitizeHref() (already tested) enforces the allow-list at render time.

Copilot comments addressed in scope:

  • types.ts comment now describes real behavior ("the image is rendered inside an <a> using sanitizeHref-validated href")
  • ImageDetailPanel.tsx Link URL input is type="text" (was flagged when it was type="url" and rejected relative paths)
  • prosemirror-to-portable-text.ts drops half-populated or whitespace-only link objects on the way out — new round-trip test covers it

Closes #

Type of change

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

Maintainer sign-off for this scope is @ascorbic's review comment on #679 ("Thanks for this. It's a good addition.") combined with the instruction to split that PR into focused replacements.

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 and pnpm locale:extract has been run (if applicable)
  • I have added a changeset (if this PR changes a published package)
  • New features link to an approved Discussion: see maintainer sign-off note above

AI-generated code disclosure

  • This PR includes AI-generated code

Claude-authored, human-reviewed. Reviewers should pay extra attention to the converter round-trip logic (empty-href drop) and the bubble-menu/main-toolbar branching on editor.isActive("image").

Screenshots / test output

New tests — packages/core/tests/unit/converters/image-link.test.ts (5 cases, all passing):

  • Relative link round-trips (/page)
  • External link with blank: true round-trips
  • Absent link stays absent on the output (no empty link: {})
  • Empty href → link dropped
  • Whitespace-only href → link dropped

Also verified manually in demos/simple:

  • Select image → main toolbar Link → enter /about → Apply → rendered <figure> wraps <img> in <a href="/about">. Re-selecting the image shows the popover pre-filled.
  • Same flow via the EditorBubbleMenu Link button.
  • ImageDetailPanel: Link URL input + "Open in new tab" checkbox round-trips through save/reload.
  • Clearing the URL in either surface removes the anchor from the rendered output.
  • sanitizeHref() handles hostile inputs (covered by its own tests).
  • Switched admin to ar locale (RTL): layout stays clean, new strings extract into all 11 catalogs.

Copilot AI review requested due to automatic review settings April 21, 2026 14:05
@changeset-bot

changeset-bot Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ef391ff

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

This PR includes changesets to release 13 packages
Name Type
emdash Minor
@emdash-cms/admin Minor
@emdash-cms/cloudflare Minor
@emdash-cms/fixture-perf-site Patch
@emdash-cms/perf-demo-site Patch
@emdash-cms/cache-demo-site Patch
@emdash-cms/auth Minor
@emdash-cms/blocks Minor
@emdash-cms/gutenberg-to-portable-text Minor
@emdash-cms/x402 Minor
create-emdash 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

Copy link
Copy Markdown
Contributor

Scope check

This PR changes 2,648 lines across 23 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.

@github-actions

github-actions Bot commented Apr 21, 2026 •

Copy link
Copy Markdown
Contributor

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
packages/admin/src/locales/ar/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/de/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/en/messages.po Source changed, localizations will be marked as outdated.
packages/admin/src/locales/es-419/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/eu/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/fr/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/ja/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/ko/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/pseudo/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/pt-BR/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/zh-CN/messages.po Localization changed, will be marked as complete. 🔄️
packages/admin/src/locales/zh-TW/messages.po Localization changed, will be marked as complete. 🔄️
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@pkg-pr-new

pkg-pr-new Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@emdash-cms/admin

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

@emdash-cms/auth

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

@emdash-cms/blocks

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

@emdash-cms/cloudflare

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

emdash

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

create-emdash

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

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

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

@emdash-cms/x402

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

@emdash-cms/plugin-ai-moderation

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

@emdash-cms/plugin-atproto

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

@emdash-cms/plugin-audit-log

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

@emdash-cms/plugin-color

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

@emdash-cms/plugin-embeds

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

@emdash-cms/plugin-forms

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

@emdash-cms/plugin-webhook-notifier

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

commit: ef391ff

Copilot AI 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.

Pull request overview

Adds optional link support to portable-text image blocks across the admin editor, converter round-trips, and front-end rendering.

Changes:

  • Extend PT image block schema with optional link: { href, blank? } and round-trip it through PT ↔ ProseMirror converters (dropping empty/whitespace href).
  • Update admin editor link UI (toolbar + bubble menu) to operate on selected images and add link editing controls in ImageDetailPanel.
  • Render linked images by wrapping the <img> in an <a> with sanitizeHref() in Image.astro, plus update tests and locale catalogs.

Reviewed changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/core/tests/unit/converters/image-link.test.ts Adds unit coverage for image link round-tripping and empty/whitespace link dropping.
packages/core/src/content/converters/types.ts Extends PortableTextImageBlock with optional link metadata.
packages/core/src/content/converters/prosemirror-to-portable-text.ts Normalizes/drops invalid image link attrs when converting PM → PT.
packages/core/src/content/converters/portable-text-to-prosemirror.ts Emits PM image attrs.link (or null) when converting PT → PM.
packages/core/src/components/Image.astro Wraps rendered images in a sanitized <a> when link.href is present.
packages/admin/tests/editor/toolbar.test.tsx Updates link popover tests to match the text input/placeholder behavior.
packages/admin/tests/editor/bubble-menu.test.tsx Updates bubble-menu link tests to match the text input/placeholder behavior.
packages/admin/src/locales/ar/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/de/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/en/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/es-419/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/eu/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/fr/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/ko/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/pt-BR/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/pseudo/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/zh-CN/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/locales/zh-TW/messages.po Updates extracted strings/locations for new ImageDetailPanel link UI.
packages/admin/src/components/editor/ImageNode.tsx Adds link attribute support to the TipTap image node/command typing + defaults.
packages/admin/src/components/editor/ImageDetailPanel.tsx Adds link URL + “open in new tab” editing surface for images.
packages/admin/src/components/PortableTextEditor.tsx Adds image-aware link handling in toolbar/bubble menu and includes link in PT↔PM conversion helpers.
.changeset/image-link-field.md Publishes the feature as a minor change for emdash and @emdash-cms/admin.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1840 to +1843
editor
.chain()
.focus()
.updateAttributes("image", { link: trimmed ? { href: trimmed } : null })

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

When editing an image link via the bubble-menu popover, updateAttributes("image", { link: { href } }) overwrites the entire link object and will drop an existing blank: true flag. This causes unexpected data loss if an image was set to “open in new tab” (e.g. via ImageDetailPanel) and the user re-applies/edits the link here. Consider preserving the existing link.blank value when updating href, or adding a blank control in the popover so the full { href, blank? } object is maintained.

Suggested change
editor
.chain()
.focus()
.updateAttributes("image", { link: trimmed ? { href: trimmed } : null })
const existingImageLink = editor.getAttributes("image").link as
| { href?: string; blank?: boolean }
| null
| undefined;
editor
.chain()
.focus()
.updateAttributes("image", {
link: trimmed ? { ...existingImageLink, href: trimmed } : null,
})

Copilot uses AI. Check for mistakes.
Comment on lines +2070 to +2073
editor
.chain()
.focus()
.updateAttributes("image", { link: trimmed ? { href: trimmed } : null })

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

Same issue in the main toolbar link popover: when editor.isActive("image"), calling updateAttributes("image", { link: { href } }) will remove any existing blank: true on the image’s link attrs. This will silently change stored content if the user opens the popover and clicks Apply without intending to change the “open in new tab” setting. Preserve the prior blank value when updating href, or expose blank in this popover.

Suggested change
editor
.chain()
.focus()
.updateAttributes("image", { link: trimmed ? { href: trimmed } : null })
const existingImageLink = editor.getAttributes("image").link as
| { href?: string; blank?: boolean }
| null
| undefined;
editor
.chain()
.focus()
.updateAttributes("image", {
link: trimmed ? { ...existingImageLink, href: trimmed } : null,
})

Copilot uses AI. Check for mistakes.
Comment on lines 2303 to 2320
@@ -2260,8 +2314,8 @@ function EditorToolbar({
<div className="flex items-center gap-1">
<Input
ref={linkInputRef}
type="url"
placeholder="https://..."
type="text"
placeholder="https://example.com or /page"
value={linkUrl}
onChange={(e) => setLinkUrl(e.target.value)}

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

The link popover introduces/updates user-visible strings (e.g. "Image Link" title and the new placeholder text) that are not wrapped with Lingui (t/<Trans>), so they won’t be translated even though the project requires wrapping user-visible strings in packages/admin/src/ (see CONTRIBUTING.md i18n section). Please wrap the new/updated strings so locale catalogs can translate the toolbar/bubble link UI consistently.

Copilot uses AI. Check for mistakes.
@github-actions

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.

drudge added a commit to drudge/emdash that referenced this pull request Apr 22, 2026
Adds a `repeater` Block Kit element for plugin block forms: an
array-of-objects input with scalar sub-fields, drag-to-reorder
(dnd-kit), and collapsible item cards. Plugin blocks can now capture
repeating data (FAQ rows, carousel slides, card grids) inline in the
portable-text editor.

`@emdash-cms/blocks`
- `RepeaterElement` + `RepeaterSubField` types (text/number/select/
  toggle/checkbox/combobox/date/radio as sub-fields — no nested
  repeaters, no buttons)
- `elements.repeater(...)` builder
- Schema validation for the repeater: sub-field type whitelist,
  non-negative integer `min_items` / `max_items` with
  `min_items <= max_items`
- Exhaustive runtime `renderElement` arm (returns null — repeater is
  admin-authoring only)

`@emdash-cms/admin`
- `BlockKitRepeater` + `BlockKitRepeaterItem` rendered inside
  `PortableTextEditor`
- Drag-to-reorder handle, collapsible item cards, Add / Remove
  controls
- Keyboard-accessible item header (real `<button>` with
  `aria-expanded`, labeled drag handle)
- Stable `_key` preservation per item (same pattern as the merged
  `RepeaterField` fix in emdash-cms#678)
- `PluginBlockModal` body grows `max-h-[70vh] overflow-y-auto` so the
  modal scrolls when a repeater has many rows

Split from the original bundled emdash-cms#679 per maintainer review. Image-link
piece shipped in emdash-cms#704; `media_picker` follows in emdash-cms#731.
drudge added a commit to drudge/emdash that referenced this pull request Apr 23, 2026
Adds a `repeater` Block Kit element for plugin block forms: an
array-of-objects input with scalar sub-fields, drag-to-reorder
(dnd-kit), and collapsible item cards. Plugin blocks can now capture
repeating data (FAQ rows, carousel slides, card grids) inline in the
portable-text editor.

`@emdash-cms/blocks`
- `RepeaterElement` + `RepeaterSubField` types. Sub-fields are
  restricted to the four scalar inputs the admin widget renders
  inline: `text_input`, `number_input`, `select`, `toggle`. No
  nested repeaters, no buttons.
- `elements.repeater(...)` builder
- Schema validation for the repeater: non-empty `fields` array,
  sub-field type whitelist, non-negative integer `min_items` /
  `max_items` with `min_items <= max_items`, and `initial_value`
  entries must be objects
- Exhaustive runtime `renderElement` arm (returns null — repeater is
  admin-authoring only)

`@emdash-cms/admin`
- `BlockKitRepeater` + `BlockKitRepeaterItem` rendered inside
  `PortableTextEditor`
- Drag-to-reorder handle, collapsible item cards, Add / Remove
  controls
- Keyboard-accessible item header (real `<button>` with
  `aria-expanded`, labeled drag handle)
- `handleRemove` drops the removed item's key from the `expanded`
  Set so it doesn't retain stale entries
- Stable `_key` preservation per item (same pattern as the merged
  `RepeaterField` fix in emdash-cms#678)
- `PluginBlockModal` body grows `max-h-[70vh] overflow-y-auto` so the
  modal scrolls when a repeater has many rows

Split from the original bundled emdash-cms#679 per maintainer review. Image-link
piece shipped in emdash-cms#704; `media_picker` follows in emdash-cms#731.
drudge added a commit to drudge/emdash that referenced this pull request Apr 24, 2026
Adds a `repeater` Block Kit element for plugin block forms: an
array-of-objects input with scalar sub-fields, drag-to-reorder
(dnd-kit), and collapsible item cards. Plugin blocks can now capture
repeating data (FAQ rows, carousel slides, card grids) inline in the
portable-text editor.

`@emdash-cms/blocks`
- `RepeaterElement` + `RepeaterSubField` types. Sub-fields are
  restricted to the four scalar inputs the admin widget renders
  inline: `text_input`, `number_input`, `select`, `toggle`. No
  nested repeaters, no buttons.
- `elements.repeater(...)` builder
- Schema validation for the repeater: non-empty `fields` array,
  sub-field type whitelist, non-negative integer `min_items` /
  `max_items` with `min_items <= max_items`, and `initial_value`
  entries must be objects
- Unit tests in `tests/validation.test.ts` covering the new rules
  (valid repeater, empty fields, disallowed sub-field type,
  non-integer / inverted min/max, malformed `initial_value`)
- Exhaustive runtime `renderElement` arm (returns null — repeater is
  admin-authoring only)

`@emdash-cms/admin`
- `BlockKitRepeater` + `BlockKitRepeaterItem` rendered inside
  `PortableTextEditor`
- Drag-to-reorder handle, collapsible item cards, Add / Remove
  controls
- Keyboard-accessible item header (real `<button>` with
  `aria-expanded`, labeled drag handle)
- `handleRemove` drops the removed item's key from the `expanded`
  Set so it doesn't retain stale entries
- Item-card summary trims the first text_input before falling back
  to "Item N" so whitespace-only values still show the index
- Stable `_key` preservation per item (same pattern as the merged
  `RepeaterField` fix in emdash-cms#678)
- `PluginBlockModal` body grows `max-h-[70vh] overflow-y-auto` so the
  modal scrolls when a repeater has many rows

Split from the original bundled emdash-cms#679 per maintainer review. Image-link
piece shipped in emdash-cms#704; `media_picker` follows in emdash-cms#731.
Adds an optional `link: { href; blank? }` on portable-text image blocks,
round-tripped through the PT ↔ PM converters. The existing editor Link
buttons (main toolbar and bubble menu) now operate on image selection:
selecting an image and clicking Link opens the URL popover pre-populated
with the image's current link, and apply/remove updates the image node's
attrs. `Image.astro` wraps the rendered `<img>` in an `<a>` using
`sanitizeHref()` when `link.href` is set. `ImageDetailPanel` gains a
Link URL input and an "Open in new tab" checkbox as a secondary editing
surface.

Split from emdash-cms#679 per review; see discussion in that PR.
drudge added a commit to drudge/emdash that referenced this pull request Apr 24, 2026
Adds a `repeater` Block Kit element for plugin block forms: an
array-of-objects input with scalar sub-fields, drag-to-reorder
(dnd-kit), and collapsible item cards. Plugin blocks can now capture
repeating data (FAQ rows, carousel slides, card grids) inline in the
portable-text editor.

`@emdash-cms/blocks`
- `RepeaterElement` + `RepeaterSubField` types. Sub-fields are
  restricted to the four scalar inputs the admin widget renders
  inline: `text_input`, `number_input`, `select`, `toggle`. No
  nested repeaters, no buttons.
- `elements.repeater(...)` builder
- Schema validation for the repeater: non-empty `fields` array,
  sub-field type whitelist, non-negative integer `min_items` /
  `max_items` with `min_items <= max_items`, and `initial_value`
  entries must be objects
- Unit tests in `tests/validation.test.ts` covering the new rules
  (valid repeater, empty fields, disallowed sub-field type,
  non-integer / inverted min/max, malformed `initial_value`)
- Exhaustive runtime `renderElement` arm (returns null — repeater is
  admin-authoring only)

`@emdash-cms/admin`
- `BlockKitRepeater` + `BlockKitRepeaterItem` rendered inside
  `PortableTextEditor`
- Drag-to-reorder handle, collapsible item cards, Add / Remove
  controls
- Keyboard-accessible item header (real `<button>` with
  `aria-expanded`, labeled drag handle)
- `handleRemove` drops the removed item's key from the `expanded`
  Set so it doesn't retain stale entries
- Item-card summary trims the first text_input before falling back
  to "Item N" so whitespace-only values still show the index
- Stable `_key` preservation per item (same pattern as the merged
  `RepeaterField` fix in emdash-cms#678)
- `PluginBlockModal` body grows `max-h-[70vh] overflow-y-auto` so the
  modal scrolls when a repeater has many rows

Split from the original bundled emdash-cms#679 per maintainer review. Image-link
piece shipped in emdash-cms#704; `media_picker` follows in emdash-cms#731.
drudge added a commit to drudge/emdash that referenced this pull request Apr 24, 2026
Adds a `media_picker` Block Kit element: a thumbnail preview with a modal
library picker and mime-type filter. Usable in plugin block forms (inside
`PortableTextEditor`) and as a Block Kit field widget (`BlockKitFieldWidget`).

The stored value is the selected asset's URL string, so it is value-compatible
with a plain `text_input` — existing content continues to work after swapping.

Split from emdash-cms#679 per maintainer request. Image-link landed in emdash-cms#704; repeater
landed in the rescoped emdash-cms#679.
@drudge
drudge force-pushed the drudge/image-link branch from de1eb7c to c804623 Compare April 24, 2026 14:15
@kwmr

kwmr commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

@drudge Are you still planning to finish this? The remaining review feedback looks small (just wrapping the strings with Lingui), and this would fix #2497, which I also hit on my production site.

If you don't have the time, would you mind if I picked it up? I'd rebase onto current main, address the i18n comments, and open the required Ideas discussion — keeping your commits and credit, of course.

@drudge

drudge commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor Author

@drudge Are you still planning to finish this? The remaining review feedback looks small (just wrapping the strings with Lingui), and this would fix #2497, which I also hit on my production site.

If you don't have the time, would you mind if I picked it up? I'd rebase onto current main, address the i18n comments, and open the required Ideas discussion — keeping your commits and credit, of course.

Hi @kwmr - I've been fairly busy with other things. I'm totally happy for you to pick up where I left off and get it past the finish line if you have time. Thank you!

@kwmr

kwmr commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Opened the Ideas discussion for this: #2741

@github-actions github-actions Bot added stale and removed stale labels Sep 10, 2026
kwmr added a commit to kwmr/emdash that referenced this pull request Sep 16, 2026
Follow-up to the emdash-cms#704 port. Editing an image link's URL from the toolbar
or bubble menu replaced the whole `link` object, so an existing
`blank: true` ("open in new tab") was silently dropped. The existing
choice is now carried over.

`ImageDetailPanel` only includes `link` in its update payload when a link
is being set or an existing one cleared, so images without links keep the
same payload as before.

Adds tests for the panel's link fields and for the toolbar edit keeping
`blank`.

Co-Authored-By: Claude <[email protected]>
khoinguyenpham04 pushed a commit to kwmr/emdash that referenced this pull request Sep 20, 2026
Follow-up to the emdash-cms#704 port. Editing an image link's URL from the toolbar
or bubble menu replaced the whole `link` object, so an existing
`blank: true` ("open in new tab") was silently dropped. The existing
choice is now carried over.

`ImageDetailPanel` only includes `link` in its update payload when a link
is being set or an existing one cleared, so images without links keep the
same payload as before.

Adds tests for the panel's link fields and for the toolbar edit keeping
`blank`.

Co-Authored-By: Claude <[email protected]>
kwmr added a commit to kwmr/emdash that referenced this pull request Sep 21, 2026
Follow-up to the emdash-cms#704 port. Editing an image link's URL from the toolbar
or bubble menu replaced the whole `link` object, so an existing
`blank: true` ("open in new tab") was silently dropped. The existing
choice is now carried over.

`ImageDetailPanel` only includes `link` in its update payload when a link
is being set or an existing one cleared, so images without links keep the
same payload as before.

Adds tests for the panel's link fields and for the toolbar edit keeping
`blank`.

Co-Authored-By: Claude <[email protected]>
kwmr added a commit to kwmr/emdash that referenced this pull request Sep 21, 2026
Rebasing onto main brought in the link destination search (emdash-cms#3235), whose
`onPick` path sets a link mark directly. With an image selected that is
the wrong target: the mark goes nowhere and the image keeps its old
link, so picking an entry silently does nothing.

Both link controls now route every image link write through one
`setSelectedImageLink` helper, including the new pick path. That also
removes the duplicated "keep the blank flag" logic the emdash-cms#704 review
flagged in the toolbar and the bubble menu.

Tests: picking an entry with an image selected sets the image's link and
leaves text marks alone, and keeps an existing `blank`. The two existing
image link tests now address the destination field by its combobox role,
since emdash-cms#3235 replaced the plain URL input.

Co-Authored-By: Claude <[email protected]>
ascorbic added a commit that referenced this pull request Sep 25, 2026
* feat(admin): optional link on portable-text image blocks

Adds an optional `link: { href; blank? }` on portable-text image blocks,
round-tripped through the PT ↔ PM converters. The existing editor Link
buttons (main toolbar and bubble menu) now operate on image selection:
selecting an image and clicking Link opens the URL popover pre-populated
with the image's current link, and apply/remove updates the image node's
attrs. `Image.astro` wraps the rendered `<img>` in an `<a>` using
`sanitizeHref()` when `link.href` is set. `ImageDetailPanel` gains a
Link URL input and an "Open in new tab" checkbox as a secondary editing
surface.

Split from #679 per review; see discussion in that PR.

* fix(admin): keep an image link's blank flag when its URL is edited

Follow-up to the #704 port. Editing an image link's URL from the toolbar
or bubble menu replaced the whole `link` object, so an existing
`blank: true` ("open in new tab") was silently dropped. The existing
choice is now carried over.

`ImageDetailPanel` only includes `link` in its update payload when a link
is being set or an existing one cleared, so images without links keep the
same payload as before.

Adds tests for the panel's link fields and for the toolbar edit keeping
`blank`.

Co-Authored-By: Claude <[email protected]>

* fix: normalise legacy image links, resync panel link fields, keep anchors same-tab

Addresses the three review findings on #3167.

Legacy link shape: `gutenberg-to-portable-text` emits `link: "https://…"`
(a bare string) for linked images, so WordPress-imported content carries
that shape while the editor writes `{ href, blank? }`. The converters and
`Image.astro` read `link.href` directly, which silently dropped the link
on imported posts. A shared `normalizeImageLink()` now accepts both
shapes; the PT type, `Image.astro`, the PT→PM converter and the admin
editor go through it, so a legacy string renders and is upgraded to the
object shape on its next round-trip. The WordPress URL rewriter handles
both shapes too (it previously assumed a string). Admin has no dependency
on the core package, so it carries a small mirror of the helper.

Panel resync: `ImageDetailPanel`'s node-switch effect reset every field
except `linkHref`/`linkBlank`, leaving the previous image's link in the
form. Both are now reset with the rest.

Same-page anchors: `Image.astro` honoured `blank` unconditionally, unlike
`marks/Link.astro`, which never opens `#section` links in a new tab. The
image wrapper now mirrors that rule.

Tests: unit coverage for `normalizeImageLink` and the legacy-string
round-trip, URL rewriting for both link shapes, Astro render cases for
new-tab / same-page-anchor / legacy-string links, and the panel resync
test now covers the link fields.

Co-Authored-By: Claude <[email protected]>

* fix(admin): let the inline bubble menu open on a selected image

The bubble menu's `shouldShow` only admitted `TextSelection` and
`AllSelection`. A selected image is a `NodeSelection`, so the image
branches of the menu's link handling (added with the image link
feature) were never reachable: selecting an image never showed the
menu at all.

`shouldShow` now also admits a `NodeSelection` whose node is an image.
When the selection is an image, the menu renders only the link
control; the text-mark buttons (bold, italic, …) are meaningless on an
image and are hidden.

Adds bubble-menu tests for a selected image: the menu appears with the
link control only, applying a URL sets `link`, editing the URL keeps
`blank`, and Remove link clears it.

Co-Authored-By: Claude <[email protected]>

* fix(admin): link the selected image when a search result is picked

Rebasing onto main brought in the link destination search (#3235), whose
`onPick` path sets a link mark directly. With an image selected that is
the wrong target: the mark goes nowhere and the image keeps its old
link, so picking an entry silently does nothing.

Both link controls now route every image link write through one
`setSelectedImageLink` helper, including the new pick path. That also
removes the duplicated "keep the blank flag" logic the #704 review
flagged in the toolbar and the bubble menu.

Tests: picking an entry with an image selected sets the image's link and
leaves text marks alone, and keeps an existing `blank`. The two existing
image link tests now address the destination field by its combobox role,
since #3235 replaced the plain URL input.

Co-Authored-By: Claude <[email protected]>

* fix(admin): name the toolbar link button "Image link" while an image is selected

The toolbar link button already switched its tooltip to "Image link"
when an image is selected, but its accessible name stayed "Insert Link",
so screen reader users heard a different label from the one shown.
The aria-label now follows the same condition as the tooltip.

The three tests that open the link control with an image selected now
locate the button by the exact name "Image link", so they fail if the
two drift apart again.

Co-Authored-By: Claude <[email protected]>

* fix(admin): keep image link controls reachable

* fix(core): relativize portable image link objects

---------

Co-authored-by: Nicholas Penree <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Matt Kane <[email protected]>
@ascorbic

Copy link
Copy Markdown
Member

Superseded by #3167, which has now merged with the complete image-link implementation and regression coverage.

@ascorbic ascorbic closed this Sep 25, 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.

4 participants