ThibaultJanBeyer / DragSelect

An easy JavaScript library for selecting and moving elements. With no dependencies. Drag-Select & Drag-And-Drop. – Examples:
https://dragselect.com/
Other
715 stars 81 forks source link

Add support for pointerEvents #128

Closed HollowMan6 closed 2 years ago

HollowMan6 commented 2 years ago

Hi, thanks for this great library. I'm now preparing to use DragSelect for implementing Google Blockly's multiselection project. However, DragSelect can't work on Blockly as of now, Google Blockly uses the pointerEvents:

https://github.com/google/blockly/blob/24a808d54eef1711801ff3b7e6082409a8a78666/core/browser_events.js#L95-L100 https://github.com/google/blockly/blob/master/core/touch.js#L58-L69

So this PR makes DragSelect also listen to the pointerEvents so that it can work for the Blockly. It would be great if this PR can get merged and a new release can be drafted for this. Thank you!

HollowMan6 commented 2 years ago

https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events

I have created a new option to enable replacing mouse events with pointer events, as they are replaceable, and currently there's a BUG in handling the touch event, and which also applies to the pointer event:

GIF 14-06-2022 16-18-57

As you can see, for the latest release version (not because of my PR), the object doesn't always follow the touch point move when dragging, which is different from the mouse events.

For the drawing a rectangle to drag and select behavior, it behave as expected. Since my project only uses that feature, and I have no bandwidth to fix the drag and move (I have no pen/stylus to test), then making it an option which is disabled by default is the best solution for me and other users.

ThibaultJanBeyer commented 2 years ago

I'll try to merge it as soon as I've time, thanks for your contribution! 💪

ThibaultJanBeyer commented 2 years ago

sorry for the delay, life happened. Unfortunately had to create a new branch as I could not push to yours. Continuing this here: https://github.com/ThibaultJanBeyer/DragSelect/pull/143