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

sortable-dnd-lock-axis-fork

v0.6.0

Published

JS library for drag-and-drop lists, supports sortable and draggable

Downloads

8

Readme

npm npm Software License

A JS Library for Drag and Drop, supports Sortable and Draggable

Live Demo

Usage

HTML

<ul id="group">
  <li class="item">
    <i id="handle" class="handle">drag me</i>
    <p>1</p>
  </li>
  <li class="item">
    <i id="handle" class="handle">drag me</i>
    <p>2</p>
  </li>
  <li class="item">
    <i id="handle" class="handle">drag me</i>
    <p>3</p>
  </li>
</ul>

JavaScript

import Sortable from 'sortable-dnd'

var DND = new Sortable(
  document.getElementById('group'),
  {
    chosenClass: 'chosen',
    draggable: (e) => e.target.tagName === 'LI' ? true : false, // use function
    // draggable: 'li' // use tagName 
    // draggable: '.item' // use class
    // draggable: '#item' // use id
    // draggable: (e) => e.target // use function to set drag Element
    handle: (e) => e.target.tagName === 'I' ? true : false, // use function
    // handle: 'I', // use tagName
    // handle: '.handle', // use class
    // handle: '#handle', // use id
    onDrag: ({ from, event }) => {
      // code
    },
    onMove: ({ from, event }) => {
      // code
    },
    onDrop: ({ from, to, changed, event }) => {
      // code
    },
    onAdd: ({ from, to, event }) => {
      // code
    },
    onRemove: ({ from, to, event }) => {
      // code
    },
    onChange: ({ from, to, event }) => {
      // code
    },
    onSelect: (params) => {
      // code
    },
    onDeselect: (params) => {
      // code
    }
  }
)

Methods

| Method | Description | |--------------|--------------| | destroy() | Manually clear all the state of the component, using this method the component will not be draggable | | option(key, value?) | Get or set the option value, depending on whether the value is passed in |

Options

Common used

| Option | Type | Default | Description | |-------------------|-------------------|-------------|--------------| | draggable | String/Function | - | Specifies which items inside the element should be draggable | | handle | String/Funnction| - | Drag handle selector within list items | | group | String/Object | - | string: 'name' or object: { name: 'group', put: true/false, pull: true/false } | | multiple | Boolean | false | Enable multiple drag | | animation | Number | 150 | Animation speed moving items when sorting | | onDrag | Function | - | The callback function when the drag is started | | onMove | Function | - | The callback function when the dragged element is moving | | onDrop | Function | - | The callback function when the drag is completed | | onAdd | Function | - | The callback function when element is dropped into the list from another list | | onRemove | Function | - | The callback function when element is removed from the list into another list | | onChange | Function | - | The callback function when the dragged element changes position in the list | | onSelect | Function | - | The callback function when element is selected | | onDeselect | Function | - | The callback function when element is unselected |

Others

| Option | Type | Default | Description | |-------------------|-------------------|-------------|--------------| | disabled | Boolean | false | Disables the sortable if set to true | | chosenClass | String | '' | Class name for the dragging item | | selectedClass | String | '' | The class of the element when it is selected, it is usually used when multiple drag | | ghostStyle | Object | {} | The style of the mask element when dragging | | ghostClass | String | '' | The class of the mask element when dragging | | autoScroll | Boolean | true | Automatic scrolling when moving to the edge of the container | | scrollThreshold | Number | 55 | Threshold to trigger autoscroll | | delay | Number | 0 | Time in milliseconds to define when the sorting should start | | delayOnTouchOnly| Boolean | false | Only delay if user is using touch | | fallbackOnBody | Boolean | false | Appends the cloned DOM Element into the Document's Body | | stopPropagation | Boolean | false | The stopPropagation() method of the Event interface prevents further propagation of the current event in the capturing and bubbling phases | | swapOnDrop | Boolean | true | When the value is false, the dragged element will return to the starting position of the drag |