thisbeyond / solid-dnd

A lightweight, performant, extensible drag and drop toolkit for Solid JS.
https://solid-dnd.com
MIT License
504 stars 35 forks source link

Allowing access to mouse position on drag & drop context's events #106

Open gabrielmfern opened 7 months ago

gabrielmfern commented 7 months ago

I really needed a way to get the displacement of the mouse's position, without hacks preferably, on every onDragMove which, thinking from a perspective of a outsider to the code base here, could be trivial as it probably already uses some mouse event under the hood, the idea would be to just expose all of the data about the event, maybe through a different property that comes into the onDrag---- listeners.

LostKobrakai commented 3 months ago

Seems like you can use the following (even outside the callback)

const [state, _] = useDragDropContext();

let mousePos = () => state.active.sensor?.coordinates.current;
gabrielmfern commented 3 months ago

@LostKobrakai Interesting, thanks for letting me know!

Do you know how the active sensor works btw? I'm not sure what it is, like, are there multiple sensors or is it a single one, is it an event listener under the hood — not sure.

LostKobrakai commented 3 months ago

By my understanding the sensor is what watches out for drags to start and stop. The default one is pointer based, but seems like you could implement drag and drop controlled by different means by switching out the sensor implementation.