advanced-cropper / vue-advanced-cropper

The advanced vue cropper library that gives you opportunity to create your own croppers suited for any website design
https://advanced-cropper.github.io/vue-advanced-cropper/
Other
978 stars 132 forks source link

Feature Request: Propagate move/resize events #106

Open ionicsolutions opened 3 years ago

ionicsolutions commented 3 years ago

Currently, the Cropper component emits the change event once the stencil has been moved/resized. I would like to receive an event when the stencil starts changing as well, e.g., a changeStarted event. As far as I can see, this could be accomplished by propagating the move and resize events emitted by the stencil component.

If this is something you're interested in, I'm happy to provide a PR for it.

Norserium commented 3 years ago

@ionicsolutions, could you describe your use-case?

Actually, it's pretty easy to implement and it may be really useful, but there are questions:

This answers have no right answers, so I need pretty much time to choice the better solution.

ionicsolutions commented 3 years ago

I'm selecting a portion of an image and generate a prediction using an ML model (currently, there is an early demo publicly available here: https://test.xaidemo.de/inspection/). We would like to remove the prediction output as soon as the user moves/resizes the stencil, as it is no longer valid. I imagine that this is a somewhat common situation, e.g., let's say we show the size of the selected area next to the image.

Thus, I would like to access the move and resize events emitted here:

In my use case, I do not change the stencil using methods, so I don't have a strong opinion.

Norserium commented 3 years ago

Currently you can use the following workaround:

  1. Set debounce to false. In this case change will fire on each change immediately.
  2. Add to the callback function clearing of the current result and the debounced call of the image processing.

It's not the perfect solution, but it will create the illusion of the desired result.

Your feature request sounds pretty reasonable, I will try to figure out how resolve it, but I can't promise that it will be soon.

Nice project, by the way.

Norserium commented 3 years ago

I imagine that this is a somewhat common situation, e.g., let's say we show the size of the selected area next to the image.

In this case I would recommend to set debounce to false and display the size immediately. And it's won't be a workaround.

The same situation when you need to preview the image in real-time. There is the corresponding example in the documentation.

Maybe, the debounce will be disabled by default in this library in the next releases. But I decided to keep it for a while, because its disabling will be very painful breaking change.

Norserium commented 3 years ago

@ionicsolutions, could you give the feedback for the workaround above?

ionicsolutions commented 3 years ago

Hi Norserium, thanks for the hints! I haven't worked on that part of the app in the past week. I'll most likely get around to it over the next days (also the switch to 1.0) and will let you know as soon as I've tried.

Norserium commented 3 years ago

@ionicsolutions, any news?

ionicsolutions commented 3 years ago

Sorry that it took longer than expected, we have a deadline approaching so I needed to take care of some other issues first.

I've upgraded our project to 1.3.0 and tried the debounce workaround.

It has the desired effect, however, I would then need to handle waiting for the moving/resizing to stop in my part of the App. We trigger a backend request once there was a change and if I turn off the debounce, my backend API gets flooded with requests (as expected). Hence, I'd still like to be able to listen to a change-start event.

It's not a high priority for me right now, but as I offered in my initial post I'm happy to give it a try at some point in the future and provide a PR.

Norserium commented 3 years ago

@ionicsolutions I assume there is a little misunderstanding. You can clear the results on change and then call the debounced API request (I use debounce library for it in this library).

ionicsolutions commented 3 years ago

@Norserium Indeed, I didn't get that part!

Thanks for pointing this out, I was able to solve it in a matter of minutes now 👍

hanzhenfang commented 1 year ago

I face the same problem in my project.

I do blow this to prevent it from colliding with my scrolling logic.

image

then, I add a judgment code in my page scroll event.

image

something good work!