Drag & drop
moveTreeNode
Moves a node and its subtree to a new parent and index, in place. An impossible move, such as a folder into itself, changes nothing. Use it to apply a drag-and-drop move to your tree data.
Moves a node in a tree you can reorder. moveTreeNode moves a node and its subtree to a new parent and index, changing your array in place, as removeTreeNode does. Its to argument is the DropPosition that useSortable's onCommit receives, so the two connect directly. Tree commits its drag reordering through it, and Sortable uses it for flat lists. It runs isDescendantOf first, because dropping a folder into its own descendant would detach that branch and lose it. Nodes are read as { value, children } by default, the shape TreeNode and MenuItemData already have. Pass accessors for any other shape.
Install
import { moveTreeNode, isDescendantOf } from 'vael-ui'