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

dragee

v1.1.12

Published

Dragee(drag&drop) library

Downloads

485

Readme

Getting Started

Install with npm

npm install dragee

Install with yarn

yarn add dragee

Usage

Draggable

import { Draggable } from 'dragee'
new Draggable(element[, options])

Listeners

new Draggable(element, {
    on: {
        'drag:start': () => addClass(element, 'is-dragging')
        'drag:move': () => console.log('drag:move')
        'drag:end': () => removeClass(element, 'is-dragging')
    }
})

bound

bound is function that restrict movements of Draggable. Bounding conception can help us to restrict draggable movements. We can set to move it insite rectangle, by circle, by line, etc. By default we will resctrict movements inside container rectangle

Скриншот 2019-11-04 20 10 03

import { BoundToCircle } from 'dragee'

new Draggable(element, {
    bound(point, size) {
        const retPoint = point.clone()
        retPoint.y = calculusFx(point.x)
        return retPoint
    }
})

new Draggable(element, {
    bound: BoundToCircle.bounding(new Dragee.Point(100, 90), 80)
})

Predefined boundings:

BoundToElemen.bounding(element, container)
BoundToRectangle.bounding(rectangle)
BoundTolineX.bounding(x, startY, endY)
BoundTolineY.bounding(y, startX, endX)
BoundToLine.bounding(startPoint, endPoint)
BoundToCircle.bounding(center, radius)
BoundToArc.bounding(center, radius, startAgle, endAngle)

Other Options

| Option | Type | Default | Description | | --- | :---: | :---: | --- | | handler | string/element | null | specifies on what element the drag interaction starts. | | container | element | auto | HTMLElement that define Cartesian coordinates system. It's upper left corner is taken as the origin. By default we calculate container automatically by finding first parentNode that have non static positioning. | | position | Point | auto | Start positioning. By default we automatically calculate position inside container element. | | nativeDragAndDrop | Boolean | false | There can be situations where we need to use html5 drag&drop instead of dragee realization. Example: table>tr have a lot of issues, so it's easier to fix them using html5 drag&drop realization or emulation. | | emulateNativeDragAndDropOnTouch | Boolean | true | Emulate native drag&drop on touch devices. |

List

During dragging we search nearest Draggable from list and if distance between them is less than radius, we excange their positions

Dragee.List(draggables[, options])

Example:

<ul id="listA" class="list">
    <li>↔ A</li>
    <li>↔ B</li>
    ...
    <li>↔ Z</li>
</ul>
const container = document.getElementById("listA")
const elements = [...container.querySelectorAll("li")]
const draggables = elements.map((element) => new Draggable(element, { container })

new List(draggables)

Options:

getDistance

Function that calculate distance from one draggable to other. We already implemented getDistance, getXDifference and getYDifference functions. By default we use getDistance function.

import { getYDifference, List } from 'dragee'

new List(draggables, {
    getDistance: getYDifference
})

new List(draggables, {
    getDistance: (p1, p2) => Math.abs(p1.x - p2.x)
})

sorting

By default we sort by y value. If it's equal, then by x. But it's possible to customize this behaviour

radius

radius that determine if we can excange two Draggable. Default: 30px

timeEnd

time to move draggable to endpoint Default: 200ms

timeExcange

time to exchange two draggables Default: 400ms