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

@wudev/drag-drop

v1.0.0

Published

Classes to apply drag and drop an element or an all of in a list of HTML elements.

Downloads

1

Readme

Drag and Drop

Version Author

This is a small library to enable drag and drop functionality in lists of HTML elements.

This library use the polyfill DragDropTouch by Bernardo-Castilho to support touch.

Installation

To install Drag and Drop you can use npm:

npm install @wudev/drag-drop

Or you can copy the code of the files:

  • drag-drop.min.js This file includes the polyfill DragDropTouch by Bernardo-Castilho
  • drag-drop-no-polyfill.min.js This file doesn't include the polyfill so you have to add support touch.

Examples

Check online

Usage

The library consists of the following files:

  • DragDrop.ts Main class to enable drag and drop on a container element.
  • DragDropItem.ts Helper class to enable drag and drop on a single item.
  • types.ts Some types used in the classes.

DragDrop class

This class enables drag and drop on a list of elements inside a container.

import DragDrop from '@wudev/drag-drop';

const container = document.getElementById('list');
const dragDrop = new DragDrop(container, 'li');

The DragDrop class handles:

  • Adding draggable attributes and listeners to items
  • Swapping positions of elements when dropping
  • CSS classes for drag and drop states

Parameters

  • container: The container element
  • itemClassName: CSS class name for the draggable items
  • attributeKey: Custom attribute to store position. Default: 'data-position'
  • parentClassName: CSS class name for parent elements. If null, uses container element.

Methods

  • destroy(): Removes listeners
  • exchangePosition(): Swaps position of two elements

DragDropItem helper

The DragDropItem class handles drag and drop functionality for a single item. This is used internally by DragDrop.

import {DragDropItem} from '@wudev/drag-drop';

const item = document.getElementById('item');
const dragDropItem = new DragDropItem(item, container, (origin, destiny) => {
	//code to exchange elements...
});

Parameters

  • item: The element to apply drag drop.
  • parent: Name of the CSS class of the parent or parent element of the item.
  • exchangePosition: Function to swap position of two elements.
  • positionAttribute: Custom attribute to store position. Default: 'data-position'

Methods

  • destroy(): Removes listeners

CSS

The DragDropItem class add to the item the next css classes:

  • drag-start: To indicate that an element started its drag.
  • drag-over: To indicate that an item is over another item.

Example

/* Generates an opacity on the element that is being dragged */
.drag-start {
	opacity: 0.5;
}

/* Displays a dotted border on the element below the element being dragged */
.drag-over {
	border-color: 1px dotted #5fa8d3;
}

Author

sgb004

License

MIT