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

svelte-sortable-items

v1.0.1

Published

svelte-sortable-items is a svelte/sveltekit package to create sortable drag-and-drop items. This package allows you to relate a javascript array to sortable HTML elements.

Downloads

449

Readme

svelte-sortable-items

GITHUB VERSION NPM VERSION NPM Downloads NPM License Twitter

svelte-sortable-items is a svelte/sveltekit package to create sortable drag-and-drop items. This package allows you to relate a javascript array to sortable HTML elements.

VERSIONS

  • VERSION 1.0.0 OR ABOVE WORKS WITH SVELTE 5 ONLY (NEWER AND RECOMMENDED VERSIONS WITH IMPROVEMENTS!)
  • PREVIOUS VERSIONS WORKS WITH SVELTE 3, 4 AND 5.

WHY ANOTHER SVELTE PACKAGE FOR SORTING?

svelte-sorting-items differs from other svelte sorting packages by not committing to a specific html structure (like "ul/li" lists). Furthermore, it promotes sorting from the child elements only, instead of sorting the children of a parent element. This allows a non-opinionated structure/styling and, consequently, the ordering of more flexible structures, such as the lines of a table for example.

FEATURES

  • NON-OPINIONATED STYLING.
  • NON-OPINIONATED HTML STRUCTURE.
  • WORKS ON MOBILE. YOU JUST HAVE TO LOAD svelte-drag-drop-touch
  • TYPESCRIPT SUPPORT.

DEMOS

INSTALLATION

npm install svelte-sortable-items

BASIC EXAMPLE

<script lang="ts">
	import { MoveIcon, SortableItem } from 'svelte-sortable-items';
	import { flip } from 'svelte/animate';

	let stateUsers = $state([
		{ id: 1, name: 'John', age: 45 },
		{ id: 2, name: 'Mark', age: 33 },
		{ id: 3, name: 'Jonas', age: 56 },
		{ id: 4, name: 'Mary', age: 76 },
	]);
	let stateHoveredItem = $state<number>(-1);
</script>

<svelte:head>
	<!-- MAKE IT WORK ON MOBILE DEVICES -->
	<script src="https://unpkg.com/svelte-drag-drop-touch"></script>
	<!---->
</svelte:head>

<p>MOVE THE <MoveIcon propSize={12} /> ICON TO REORDER ELEMENTS.</p>

{#each stateUsers as currentUser, numberCounter (currentUser.id)}
	<div animate:flip>
		<SortableItem
			propItemNumber={numberCounter}
			bind:propData={stateUsers}
			bind:propHoveredItemNumber={stateHoveredItem}
		>
			<div class:classHovered={stateHoveredItem === numberCounter}>
				<MoveIcon propSize={12} />
				{currentUser.name}
			</div>
		</SortableItem>
	</div>
{/each}

<p>{JSON.stringify(stateUsers)}</p>

<style>
	.classHovered {
		background-color: lightblue;
		color: white;
	}
</style>

MORE EXAMPLES

To run the examples from /src/routes:

git clone https://github.com/joaquimnetocel/svelte-sortable-items.git
cd svelte-sortable-items
npm install
npm run dev

COMPONENT STRUCTURE

  • SortableItem: A component to create sortable html elements.
  • MoveIcon: An icon commonly used to sort items.

PROPS

  • PROPS OF SortableItem:

| PROP | DESCRIPTION | TYPE | REQUIRED | DEFAULT | | ---------------------------------- | ----------------------------------------------------------------------------- | ----------- | -------- | ----------- | | propData (bindable) | AN ARRAY WITH THE DATA. | unknown[] | YES | - | | propItemNumber | THE INITIAL POSITION OF THE ITEM. | number | YES | undefined | | propHoveredItemNumber (bindable) | THE HOVERED ITEM NUMBER (GENERALY USED TO DO SPECIFIC STYLING WHEN HOVERING). | number | NO | -1 |

  • PROPS OF MoveIcon:

| PROP | DESCRIPTION | TYPE | REQUIRED | DEFAULT | | ---------- | --------------------- | -------- | -------- | ------- | | propSize | SIZE OF THE SORT ICON | number | NO | 12 |