smooth-dnd
smooth-dnd copied to clipboard
Svelte smooth-dnd
Hello! I understand that at the moment there are no components for Svelte, however, I would be satisfied with using it directly without them, if possible. The problem is that when I change the order of the elements in the array in the onDrop function, in the browser the moved element is returned to its original place (in the console in the array the order of the elements looks correct). And the moved element itself is returned exactly when I update the order of the elements in the array., where could there be an error? Thank you
`
import smoothDnD from 'smooth-dnd';
onMount(()=> {
const containerElement = document.getElementById('boxId');
const containerInstance = smoothDnD(containerElement, {
orientation: 'vertical',
behaviour: 'move',
lockAxis: 'y',
removeOnDropOut: true,
dragBeginDelay: 0,
animationDuration: 250,
autoScrollEnabled: false,
onDrop: function(dropResult) {
const item = included[dropResult.removedIndex];
included.splice(dropResult.removedIndex, 1);
included.splice(dropResult.addedIndex, 0, item);
},
getChildPayload: function(i) {
return { id: i, otherData: 'Other Data' };
},
});
})
let included = [
{ title: 'ITEM1', color: '#5aabff' },
{ title: 'ITEM2', color: '#5aff5d' },
{ title: 'ITEM23', color: '#ff5a5a'},
]
</script>
<div class="box12" id="boxId">
{#each included as item }
<div style="background-color: {item.color}" >{item.title}</div>
{/each}
</div>
`