2023-10-02 23:10:49 +03:00
|
|
|
<script>
|
|
|
|
|
import Sortable from "sortablejs";
|
2024-08-16 16:00:48 +03:00
|
|
|
import {createEventDispatcher, onMount} from "svelte";
|
|
|
|
|
|
2023-10-30 14:33:35 +02:00
|
|
|
export let sortableClass = "";
|
2023-10-02 23:10:49 +03:00
|
|
|
// export let handle;
|
|
|
|
|
export let isTable = false;
|
|
|
|
|
export let sortableInstance;
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
let sortableContainer;
|
|
|
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
|
let options = {
|
|
|
|
|
animation: 150, // ms, animation speed moving items when sorting, `0` — without animation
|
|
|
|
|
easing: "cubic-bezier(1, 0, 0, 1)",
|
2024-08-16 16:00:48 +03:00
|
|
|
direction: 'vertical',
|
2023-10-02 23:10:49 +03:00
|
|
|
onUpdate: function (/**Event*/ evt) {
|
|
|
|
|
dispatch("update", {
|
|
|
|
|
source: evt.oldIndex,
|
|
|
|
|
target: evt.newIndex,
|
|
|
|
|
});
|
2024-08-16 16:00:48 +03:00
|
|
|
}
|
2023-10-02 23:10:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
sortableInstance = Sortable.create(sortableContainer, options);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
{#if isTable}
|
2024-08-16 16:00:48 +03:00
|
|
|
<tbody class="sortable-container {sortableClass}" bind:this={sortableContainer}>
|
|
|
|
|
<slot/>
|
|
|
|
|
</tbody>
|
2023-10-02 23:10:49 +03:00
|
|
|
{:else}
|
2024-08-16 16:00:48 +03:00
|
|
|
<div class="sortable-container {sortableClass}" bind:this={sortableContainer}>
|
|
|
|
|
<slot/>
|
|
|
|
|
</div>
|
2023-10-02 23:10:49 +03:00
|
|
|
{/if}
|
|
|
|
|
|