Skip to content

feat: add image resizing functionality and styles for image tool - #395

Merged
saa938 merged 2 commits into
AP-Students:mainfrom
Famousmaster206:resize-image
Sep 4, 2026
Merged

feat: add image resizing functionality and styles for image tool#395
saa938 merged 2 commits into
AP-Students:mainfrom
Famousmaster206:resize-image

Conversation

@Famousmaster206

Copy link
Copy Markdown
Contributor

Description

Resolves #336

Adds Google-Docs-style image resizing to the article editor. Images previously had no way to control their displayed size beyond the existing boolean "stretched" (full-width) toggle, which made it hard to get consistent, accurate image sizing across an article.

This PR:

  • Adds a width field (percentage, 15–100%) to the custom Editor.js image block's data model.
  • Adds a draggable resize handle to the bottom-right corner of the image in the editor (mouse drag or arrow keys), with aspect ratio locked and width clamped to 15–100% of the content column.
  • Setting a custom width automatically disables the existing "stretched" toggle, since the two are mutually exclusive ways of controlling width.
  • Persists width through save() and restores it when a saved article is reopened for editing.
  • Renders the saved width as an inline style on the <img> in both public-facing renderers (Renderer.tsx and the SSR editorjs-render.ts), so resized images display consistently on published articles.
  • Adds editor-only CSS so the handle is visually hidden until hover/focus and has no effect on the public article view.

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

How Has This Been Tested? How can the reviewer test it?

The article editor lives behind an authenticated /admin route gated on Firestore user roles, so it couldn't be exercised directly in this environment. Instead, the resize handle's logic was verified against the real @editorjs/image package in an isolated Playwright harness (same UMD bundle from node_modules, same handle-mounting code):

  • Dragging the handle shrinks the image and updates the container width live.
  • Releasing the drag persists the final width percentage into the block's data.
  • Dragging past the minimum clamps to 15%.
  • Dragging past the maximum snaps back to full width (width cleared, "stretched" behavior).

This process caught and fixed a real bug: the handle was initially positioned outside the image container's bounds (right: -6px), which .image-tool__image's overflow: hidden clips — making it invisible/unclickable. It was repositioned inside the container (right: 4px; bottom: 4px) and re-verified.

Also ran tsc --noEmit and eslint on all touched files — no new errors or warnings introduced.

Reviewer testing steps:

  1. Open an article in the admin article editor and insert/select an image block.
  2. Hover the image to reveal the resize handle at its bottom-right corner; drag it to resize, or focus it and use arrow keys.
  3. Save the article and view it on the public article page — the image should render at the chosen width.
  4. Toggle "stretched" after setting a custom width (or vice versa) to confirm the two don't conflict.

Checklist

  • I have performed a self-review of my own code

Famousmaster206 and others added 2 commits September 2, 2026 19:30
…ages

Three fixes to the new image resize handle, each reproduced in a browser
against the real @editorjs/image bundle before and after.

Images narrower than the content column could only be shrunk. The tool gives
its picture element only `max-width: 100%`, so setting a width on the
container grew the box while the image stayed at its natural size — a 300px
image in a 650px column left the drag handle 346px adrift in empty space.
The container now carries a `data-custom-width` marker and the stylesheet
makes the picture fill it, matching how the public renderers put the width
straight onto the <img>. As a consequence the width is now kept at 100%
rather than cleared, since clearing it would snap a narrow image back to its
natural size the moment the drag ended.

Resizing a stretched image wrote `_data.stretched = false` directly, which
left the tune's CSS class and the block's stretched layout in place. The
editor kept showing a full-bleed image while the article rendered it at the
custom width, and the tunes menu reported Stretch as off while it was
visibly on, so it took two clicks to turn off. Resizing now goes through the
base tool's `setTune`, which drops all three.

Turning Stretch on after a resize left both `width` and `stretched` set.
Because the renderers prefer an explicit width, the stretch was a silent
no-op on the published article. `setTune` now clears the custom width when
stretch is enabled, so the two stay mutually exclusive in both directions.

Claude-Session: https://claude.ai/code/session_01EdoAdNi9uZV4AfGcCgU8uc
@saa938
saa938 merged commit 4881a2b into AP-Students:main Sep 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Resize Images

2 participants