npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@jhubbardsf/svelte-sortablejs

v1.1.0

Published

A Svelte wrapper for the Sortable.js library

Downloads

2,230

Readme

svelte-sortablejs

npm npm bundle size Netlify GitHub last commit

Unofficial Svelte package for the SortableJS library.

Demo

See a live demo on Netlify.

Quick Start

  1. Install with npm, pnpm, or yarn.

    npm i -D @jhubbardsf/svelte-sortablejs

  2. Import SortableList from package.

    import { SortableList } from '@jhubbardsf/svelte-sortablejs';

  3. Use the SortableList component in your svelte file.

    <SortableList>
        <div> List Item 1 </div>
        <div> List Item 2 </div>
        <div> List Item 3 </div>
    </SortableList>

Example Use

Look in src/routes/index.svelte to see Svelte implementations of the SortableJS examples.

SortableList Parameters

Below is a list explaining the SortableList component parameters. All parameters are optional. Check out the official SortableJS github for more in depth information on the parameters.


multiDragClass option

Type: string

Default Value: null

Add a multiDrag class. Automatically mounts the multiDrag Plugin, sets it to true and sets fallbackTolerance to 3.


swapClass option

Type: string

Default Value: null

Add a swap class. Automatically mounts the swap Plugin, sets it to true.


group option

Type: string | GroupOptions

Default Value:

"name" OR { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] }


sort option

Type: boolean

Default Value: true

Sorting inside list


disabled option

Type: boolean

Default Value: false

Disables the sortable if set to true.


store option

Type: undefined

Default Value:


handle option

Type: string

Default Value:

Drag handle selector within list items


swapThreshold option

Type: number

Default Value: 1

Threshold of the swap zone. Must be between 0 and 1.


invertSwap option

Type: boolean

Default Value: false

Will always use inverted swap zone if set to true.


invertedSwapThreshold option

Type: number

Default Value:

Threshold of the inverted swap zone (will be set to swapThreshold value by default).


removeCloneOnHide option

Type: boolean

Default Value: true

Remove the clone element when it is not showing, rather than just hiding it


ghostClass option

Type: string

Default Value: "sortable-ghost"

Class name for the drop placeholder.


chosenClass option

Type: string

Default Value: "sortable-chosen"

Class name for the chosen item.


dragClass option

Type: string

Default Value: "sortable-drag"

Class name for the dragging item.


ignore option

Type: string

Default Value: "a; img"

Elements to ignore


filter option

Type: string | Function

Default Value:

Selectors that do not lead to dragging (String or Function)


preventOnFilter option

Type: boolean

Default Value: true


animation option

Type: number

Default Value: 0


easing option

Type: string | function

Default Value:

Easing for animation. Defaults to null. See https://easings.net/ for examples. For other possible values, see https://www.w3schools.com/cssref/css3_pr_animation-timing-function.asp


dataIdAttr option

Type: string

Default Value: "data-id"

HTML attribute that is used by the toArray() method.


delay option

Type: number

Default Value: 0

Time in milliseconds to define when the sorting should start


delayOnTouchOnly option

Type: boolean

Default Value: false

Whether or not the delay should be applied only if the user is using touch (eg. on a mobile device). No delay will be applied in any other case.


forceFallback option

Type: boolean

Default Value: false

Ignore the HTML5 DnD behaviour and force the fallback to kick in


fallbackClass option

Type: string

Default Value: "sortable-fallback"

Class name for the cloned DOM Element when using forceFallback.


fallbackOnBody option

Type: boolean

Default Value: false

Appends the cloned DOM Element into the Document's Body.


fallbackTolerance option

Type: number

Default Value: 0

Specify in pixels how far the mouse should move before it's considered as a drag.


fallbackOffset option

Type: { x: 0, y: 0 }

Default Value: { x: 0, y: 0 }


emptyInsertThreshold option

Type: number

Default Value: 5

Pixel distance mouse must be from empty sortable to insert drag element into it


direction option

Type: undefined

Default Value:

Direction that the Sortable should sort in. Can be set to 'vertical', 'horizontal', or a function, which will be called whenever a target is dragged over. Must return 'vertical' or 'horizontal'. Leave blank to auto detect.


touchStartThreshold option

Type: undefined

Default Value:

How many pixels the point should move before cancelling a delayed drag event


setData option

Type: undefined

Default Value:


draggable option

Type: undefined

Default Value: null

Specifies which items inside the element should be draggable.


onChoose option

Type: fn(event: SortableEvent) => void

Default Value:

Element is chosen


onUnchoose option

Type: fn(event: SortableEvent) => void

Default Value:

Element is unchosen


onStart option

Type: fn(event: SortableEvent) => void

Default Value:

Element dragging started


onEnd option

Type: fn(event: SortableEvent) => void

Default Value:

Element dragging ended


onAdd option

Type: fn(event: SortableEvent) => void

Default Value:

Element is dropped into the list from another list


onUpdate option

Type: fn(event: SortableEvent) => void

Default Value:

Changed sorting within list


onRemove option

Type: fn(event: SortableEvent) => void

Default Value:

Element is removed from the list into another list


onFilter option

Type: fn(event: SortableEvent) => void

Default Value:

Attempt to drag a filtered element


onSort option

Type: fn(event: SortableEvent) => void

Default Value:

Called by any change to the list (add / update / remove)


onClone option

Type: fn(event: SortableEvent) => void

Default Value:

Called when creating a clone of element


onMove option

Type: fn(event: SortableEvent) => void

Default Value:

Event when you move an item in the list or between lists


onChange option

Type: fn(event: SortableEvent) => void

Default Value:

Called when dragging element changes position