[WC-3435]: Image Cropper Design and feats#2280
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
60f8a9b to
2741159
Compare
… fix crop alignment Replace CSS-transform rotation with a pixel re-bake so the crop selection maps to the visible image, and add a blob-URL live preview so the rotation is visible before the deferred Mendix commit (Save). Reset now restores the true first-load original via an internal-change gate in useOriginalImage.
…used rotation state
…esign mode Simplify structure mode to a title row plus a single status/config row ([No attribute selected] vs config summary), dropping the icon and large image render. Rewrite design mode into a three-state preview driven by the bound image: static images render the real CropArea (non-interactive) with a config caption, while dynamic/unbound images show a placeholder glyph with [No image selected yet]. Extract shared describeConfig/aspectLabel into utils, add the cropper placeholder asset, declare the png module for TypeScript, and cover both editor surfaces with new specs.
…t fixes Terminology: - rename user-facing "Rotate" to "Flip" (toolbar, tooltips, enableFlip property) - rename "Black and white"/"B&W" toggle to "Grayscale" Toolbar: - single-row layout: flip-left, flip-right, grayscale, zoom slider, reset - flip buttons use SVG icons; square, icon-only styling - always-on native tooltips on every toolbar button Layout: - size widget to its image and render block-level so sibling widgets stack below - editor design-mode preview fills available width - remove redundant "Image cropper" label above the design-mode preview Behavior: - keep a color working image on flip so grayscale stays reversible; bake grayscale only into the committed file when the toggle is on - gate crop auto-commit on a genuine user drag so editing one cropper does not commit sibling instances in a list Tests: rename specs for flip/grayscale; add grayscale-reversibility and multi-instance commit regression specs.
2741159 to
1472687
Compare
This comment has been minimized.
This comment has been minimized.
Remove keepSelection and add MIN_CROP_PX min width/height so dragging on empty canvas starts a fresh selection instead of nudging the old one. A bare click (mousedown+mouseup, no drag) yields a ~0-size crop from react-image-crop that minWidth/minHeight does not catch, which would wipe the box. Guard it with isStrayCrop: crops below MIN_DRAW_FRACTION of the displayed image are ignored so the existing selection survives.
Reset previously cleared the selection, leaving no box. Restore the original bytes and re-seed the 80%-centered default via the extracted buildInitialCrop (now in utils/initialCrop). Two paths: when restoring changed the uri, CropArea's onLoad re-seeds against the correct dimensions; when nothing was edited the uri is unchanged and onLoad won't refire, so the container re-seeds directly from imageRef. Also mirror handleFlip and drive the live preview with the original bytes, so a stale rotated/flipped blob stops rendering after Reset.
Zoom now anchors on a fixed point (the crop-box center, captured when the zoom value changes and frozen while the box moves/draws), so scaling keeps that point on screen instead of drifting. The container owns the anchor and passes it to both CropArea's transformOrigin and the export math. Centralize the source-rect mapping into computeSourceRect, shared by cropImage and PreviewPane, so exported pixels match the on-screen framing. This also fixes a pre-existing off-center bug: the old pixelCrop.x / z math assumed a top-left origin while the CSS used center, giving the wrong region for any off-center crop. The read window is clamped into the image to guard zoom-out (z < 1) from reading off-canvas.
This comment has been minimized.
This comment has been minimized.
The buttons rotate the image by ±90° (via rotateImage), so "flip" was the wrong term. Rename it everywhere: the enableFlip XML property key becomes enableRotation, the rotate-left/rotate-right icon assets, CropToolbar props and aria-labels/titles, the container's handleRotate handler, and all affected tests, comments, and generated typings. Also polish the toolbar: render the "Zoom" label at regular weight (Atlas styles labels bold), and rename the Reset button caption to "Enable reset". The showResetButton property key is unchanged to avoid breaking existing app bindings.
This comment has been minimized.
This comment has been minimized.
AI Code Review
What was reviewed
Skipped (out of scope): Findings🔶 Medium — 3 unit tests failing in CIFile: Test 1 expects the text node The mismatch is between Fix: Bring the spec into sync with the actual // test 1 — title is embedded in the body string, not a separate node
expect(texts.some(t => t.includes("Image Cropper"))).toBe(true);
// test 2 — placeholder is different
expect(texts).toContain("[Configure Image Cropper]");
// test 3 — full caption string, not just the config part
expect(texts).toContain("Circle · 1:1 · JPEG · Viewport"); // this one only needs the full string to be present as a sub-item — check whether collectText splits itAlternatively, align the spec assertions to 🔶 Medium — Lint warning (import order) in CIFile: While this is a warning not an error, it contributes to the failed CI job and will accumulate technical debt. The auto-format hook does not fix import ordering. Fix: Move the import { isStrayCrop, MIN_CROP_PX } from "../utils/cropGuard";
import { CENTER_ANCHOR, type ZoomAnchor } from "../utils/cropImage";
|
Pull request type
New feature (non-breaking change which adds functionality)
Description
Initial development of the Image Cropper widget. This is a pre-release widget; the items below describe its current capabilities, not changes to a shipped version.
Cropping
Toolbar
Editor experience (Studio Pro)
Layout
Behavior
safeImageUriallowlistTesting
What should be covered while testing?