Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

Svelte JS support

Open gufoscuro opened this issue 4 years ago • 10 comments

Hello, I see that Vue, React, Angular and others have their support and I was just thinking that it would be really great to have a SortableJS library for Svelte as well :) would it be difficult to add the support?

thanks in advance

gufoscuro avatar Jun 03 '20 19:06 gufoscuro

Very much support this!

zahachtah avatar Jun 22 '20 08:06 zahachtah

Came here to +1 this, but then realized.. There is nothing special needed, it works out of the box like this (pseudocode):

<script>
  import Sortable from 'sortablejs';
  import { onMount } from "svelte";
  let el;
  onMount(async () => {
    Sortable.create(el, { /* your sortable options here */ })
  });
</script>
<ul this={el}>
  <li>Reorder Me</li>
  <li>And me!</li>
</ul>

Working example:

https://svelte.dev/repl/9fe76dda194348d1acd6d2e336c30c22?version=3.24.0

acoyfellow avatar Jul 13 '20 10:07 acoyfellow

That is cool, however aside the "View side", the "model side" is missing (or at least must be somehow implemented)

Meaning: it would be great that every update the user performs to the DOM nodes could trigger a model update and vice-versa

gufoscuro avatar Aug 05 '20 17:08 gufoscuro

possibly with a more svelteish way using actions?

zahachtah avatar Aug 05 '20 19:08 zahachtah

That could be a good option. I will try to play with it in a few days and then post down here my successes/failures :)

gufoscuro avatar Aug 10 '20 07:08 gufoscuro

If anyone creates a working example, we can add it to the official repository :)

waynevanson avatar Sep 09 '20 07:09 waynevanson

Came here to +1 this, but then realized.. There is nothing special needed, it works out of the box like this (pseudocode):

<script>
  import Sortable from 'sortablejs';
  import { onMount } from "svelte";
  let el;
  onMount(async () => {
    Sortable.create(el, { /* your sortable options here */ })
  });
</script>
<ul this={el}>
  <li>Reorder Me</li>
  <li>And me!</li>
</ul>

Working example:

https://svelte.dev/repl/9fe76dda194348d1acd6d2e336c30c22?version=3.24.0

@acoyfellow would you know how to mount a plugin correctly. I'm trying to use the Swap plugin.

mkstix6 avatar Jul 23 '21 16:07 mkstix6

Works fine here: https://svelte.dev/repl/972fbd0754424124a94c47399826ddcd?version=3.40.2

harshmandan avatar Jul 24 '21 11:07 harshmandan

Hey. Just wanted to throw out that I put together a small Svelte library here.

jhubbardsf avatar May 05 '22 20:05 jhubbardsf

Hello!

Thought I'd just pop this here for anyone looking for a nice Svelte Action that provides a sortable-like functionality very easily: https://github.com/isaacHagoel/svelte-dnd-action 🥳

Although... Sortable can also work great in Svelte with the above solutions!

TomRadford avatar Sep 26 '23 14:09 TomRadford