Skip to content

V15: Improve the dropzone for Image Cropper #18838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 27, 2025

Conversation

iOvergaard
Copy link
Contributor

@iOvergaard iOvergaard commented Mar 27, 2025

Description

The Image Cropper now uses the new dropzone input <umb-dropzone-input /> to share the logic and user experience. The dropzone input features an uploader UI with manual and auto cancel of uploads, and users can follow the upload progress.

Additionally, the Image Cropper now supports hosting the Backoffice on another URL by prefixing the image URLs with the server URL.

Lastly, an update has been made to read the object URL directly from the File object rather than try to load the entire image into memory. This is usually not a problem for images, but we fixed it elsewhere as well, allowing browsers to handle files in the gigabyte range.

Fixes AB#49148

How to test

  1. Create an Image Cropper property and verify that you can drag & drop files
  2. Try, if you can, to navigate away from the page as a large upload is in progress and verify, that the network request was cancelled

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request improves the Image Cropper by integrating a new dropzone input component, streamlining the file handling via object URLs, and supporting backoffice hosting on an external URL.

  • Introduces a custom getter/setter for file handling that uses URL.createObjectURL for improved memory management.
  • Replaces the previous file uploading logic with a new dropzone mechanism and updates styling accordingly.
  • Adjusts the focal point getter order in the image cropper preview for cleaner code.

Reviewed Changes

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

File Description
src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper-field.element.ts Updates file property handling by creating object URLs and adding a server URL prefix to the source.
src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/input-image-cropper.element.ts Refines the dropzone handling to work with new uploadable items and integrates updated temporary file logic.
src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper-preview.element.ts Reorders the focalPoint getter implementation for consistency.

@iOvergaard iOvergaard requested a review from Copilot March 27, 2025 07:51
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request refactors the Image Cropper to use a new dropzone input component, improves file handling by generating object URLs directly from File objects, and adds support for hosting the Backoffice on a separate URL by prefixing image URLs.

  • Replaces FileReader logic with URL.createObjectURL and manages object URLs in the image cropper field.
  • Updates the dropzone component and upload cancellation behavior in the image cropper input.
  • Minor reordering of getter/setter implementation for the focal point in the preview component.

Reviewed Changes

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

File Description
src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper-field.element.ts Updates file handling to use object URLs and prefixes image URLs with a server URL from context.
src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/input-image-cropper.element.ts Adjusts dropzone behavior and file upload cancellation mechanism using the new dropzone input API.
src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper-preview.element.ts Reorders the getter/setter for focalPoint for improved clarity.
Comments suppressed due to low confidence (3)

src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper-field.element.ts:54

  • Consider revoking the object URL in the component's disconnectedCallback as well, to ensure no memory leak occurs if the component is removed before file cleanup.
this.fileDataUrl = URL.createObjectURL(file);

src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/input-image-cropper.element.ts:92

  • [nitpick] Verify that stopping immediate propagation is intentional, as it might prevent other important event listeners on the dropzone from executing.
e.stopImmediatePropagation();

src/Umbraco.Web.UI.Client/src/packages/media/media/components/input-image-cropper/image-cropper-preview.element.ts:25

  • [nitpick] For improved clarity and consistency, consider placing the getter for focalPoint before the setter.
get focalPoint() {

@iOvergaard iOvergaard enabled auto-merge (squash) March 27, 2025 08:46
Copy link
Member

@leekelleher leekelleher left a comment

Choose a reason for hiding this comment

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

Tested out, working as expected. 🚀

For testing the navigate away/cancelling, I used a 30Mb sample image and set Chrome network throttle to 4G for slower upload time. Navigating away cancels the request. 👍

@iOvergaard iOvergaard merged commit a71ebe1 into v15/dev Mar 27, 2025
23 checks passed
@iOvergaard iOvergaard deleted the v15/feature/image-cropper-dropzone-update branch March 27, 2025 10:11
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