Use `moveBefore` when available to preserve DOM state by mathieumahe · Pull Request #2459 · SortableJS/Sortable
Description
This PR updates the code to use the new moveBefore() method when it is available, and falls back to insertBefore() otherwise.
Unlike insertBefore(), moveBefore() allows moving a node without removing it from the DOM, which preserves its internal state and ongoing behavior.
This has several important benefits:
- Component state is preserved
- CSS animations are not reset
- Embedded content such as iframes is not reloaded (e.g. TinyMCE editors, YouTube videos, etc.)
References
MDN: Element.moveBefore()
https://developer.mozilla.org/en-US/docs/Web/API/Element/moveBefore#movebefore_constraints