svelte-dnd-action icon indicating copy to clipboard operation
svelte-dnd-action copied to clipboard

How to detect when an item is moved because of another item.

Open Zachiah opened this issue 2 years ago • 6 comments

Hi! I'm making a treeview and I need items to automatically open when they are hovered over or moved

Zachiah avatar Feb 02 '22 22:02 Zachiah

Normally such logic would go into the "consider" handler. If u have a concrete example i might be able to provide a better answer

On Thu, Feb 3, 2022, 09:52 Zachiah @.***> wrote:

Hi! I'm making a treeview and I need items to automatically open when they are hovered over or moved

— Reply to this email directly, view it on GitHub https://github.com/isaacHagoel/svelte-dnd-action/issues/349, or unsubscribe https://github.com/notifications/unsubscribe-auth/AE4OZC2QEBUNH65K6M54TM3UZGYR5ANCNFSM5NNLE3YA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you are subscribed to this thread.Message ID: @.***>

isaacHagoel avatar Feb 02 '22 23:02 isaacHagoel

Hi! I have an example with solid-dnd-directive I figure the answer would apply to both so that's why I made the issue here though.

https://codesandbox.io/s/adoring-shaw-somoc?file=/src/main.tsx

Zachiah avatar Feb 04 '22 13:02 Zachiah

so if i expand the top level and then drag child 1 over child 2 what should happen? should child 2 not move but expand instead?

isaacHagoel avatar Feb 05 '22 20:02 isaacHagoel

Ideally it would expand if it was less than half way over, and move when it's more than half way over, but just getting it to expand at all is the hard part

Zachiah avatar Feb 07 '22 16:02 Zachiah

@isaacHagoel

Zachiah avatar Feb 21 '22 16:02 Zachiah

sorry. logic that is based on the direction from which the element entered is going to be problematic. something that could work: when the element hovers over (== trying to change the index of) an expandable it gets detected in the consider handler, it should stay in place (set the items to themselves instead of e.detail.items), expand if collapsed, and the consider handler that's inside should notify the parent when either the item is dropped inside or when the item left (one of the triggers of consider is DRAGGED_LEFT). when the parent gets notified on either it should start allowing it's items to get re-sorted as normal (=== it stops insistings on items = [...items] and goes back to items=e.detail.items). i hope it is not to hand wavy.

isaacHagoel avatar Feb 21 '22 20:02 isaacHagoel