feat: add image resizing functionality and styles for image tool - #395
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
widthfield (percentage, 15–100%) to the custom Editor.js image block's data model.widththroughsave()and restores it when a saved article is reopened for editing.<img>in both public-facing renderers (Renderer.tsxand the SSReditorjs-render.ts), so resized images display consistently on published articles.Pull request type
Please check the type of change your PR introduces:
How Has This Been Tested? How can the reviewer test it?
The article editor lives behind an authenticated
/adminroute 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/imagepackage in an isolated Playwright harness (same UMD bundle fromnode_modules, same handle-mounting code):widthcleared, "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'soverflow: hiddenclips — making it invisible/unclickable. It was repositioned inside the container (right: 4px; bottom: 4px) and re-verified.Also ran
tsc --noEmitandeslinton all touched files — no new errors or warnings introduced.Reviewer testing steps:
Checklist