PuruVJ / neodrag

One Draggable to rule them all 💍
https://neodrag.dev
MIT License
1.57k stars 48 forks source link

Best pratice to get dragged element ? #58

Closed Subwaytime closed 1 year ago

Subwaytime commented 1 year ago

Hey there! Currently trying out neodrag to replace sortablejs, as i find it far more enjoyable and more responsive! :) Atm i am not 100% sure, whats the best way to get the currently dragged element (as a DomElement) or the dropzone..

Maybe it might be worth to add this directly to the eventData ?

PuruVJ commented 1 year ago

Just to clarify, do you refer to whether it's the handle, if handle or handles are provided? Or the whole element if no handle?

Glad you find this library useful, always open to improving it :)

Subwaytime commented 1 year ago

Hmm good question, i think it would be great if its always the dragged element, so if there is a handle include the handle otherwise the dragged element. It might be worth to check if there is a handle then get the parent element? Not sure, as it could be nested quite deeply.. Maybe get the element that v-draggable is attached too, that should give enough options to work with!

Yeah the library works quite well :) Great work here! :+1:

PuruVJ commented 1 year ago

I am thinking of this API surface

{
  currentTarget: HTMLElement // The actual element which is being dragged
  target: HTMLElement // The element being dragged, but either its the root node or one of the handles. 
  targetType: 'root' | 'handle'
}

No handles

currentTarget: The element on which the cursor was. Could be a child element of the root node, could be the node itself. Will give the precise element which triggered the dragging target: It's the root node, on which v-draggable was applied. target can either be the root node or a handle node only, not a child element. targetType: root. No need to explain

Uses handles

currentTarget: Same as the above scenario. Gives the exact element which triggered dragging target: It is one of the handles. Notice, it returns only one handle element, in case an array was provided or there just are multiple selectors for handle option targetType: handle

What do you think of this API surface?

Subwaytime commented 1 year ago

That looks great!

PuruVJ commented 1 year ago

Sorry for the delay, I'll add it to the 2.0 release. I have already added a node property internally in the event returned, I'll add this to the release

Subwaytime commented 1 year ago

No worries! Havent had the time to be working with the library anyways on said project.. :sweat_smile:

Any ETA for the 2.0 release?

PuruVJ commented 1 year ago

When docs are done

So no idea 😅

PuruVJ commented 1 year ago

It's been implemented