isaacHagoel / svelte-dnd-action

An action based drag and drop container for Svelte
MIT License
1.76k stars 105 forks source link

SvelteDndAction vs SortableJS wrapper #412

Closed lucadalli closed 1 year ago

lucadalli commented 1 year ago

I will soon commerce building an app where drag 'n drop is the primary way users interact with the product. Naturally, I intend to leverage a robust library for this behavior and I am trying to decide between SvelteDndAction and SortableJS.

What is the motivation behind this library and why is it favored over a SortableJS wrapper? Is it the elegance of having the API being a Svelte action? Perhaps a small comparison of the two can be added to the Readme?

lucadalli commented 1 year ago

After trying out both, here's my key takeaways:

SortableJS shines if you want to work with the HTML5 Drag n' drop behavior SvelteDndAction intentionally does not use that API, presumably due to its rigidness

SortableJS manipulates the DOM directly and updates to the data layer must be done retroactively to keep things in sync SvelteDndAction adopts a more data-first approach, providing you with callbacks in which you reassign the items array with one reordered according to the user's interactions

SortableJS provides a lot of configuration options to address the most common use cases. One example would be the handle-option to define the drag handle element. SvelteDndAction is more lean and provides a powerful set of primitives instead. This demo shows how to implement drag handles