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

vue-draggable

v2.0.6

Published

Vue drag and drop library without any dependency

Downloads

71,805

Readme

npm version vue2 GitHub open issues npm download MIT License

Description

Vue Drag and Drop library without any dependency.

Native HTML5 drag and drop implementation made for Vue.

Examples 🎪

Installation

npm install vue-draggable
<!-- or -->
yarn add vue-draggable

Setup

Setup plugin

import Vue from 'vue'
import VueDraggable from 'vue-draggable'

Vue.use(VueDraggable)

Setup directive locally

import { VueDraggableDirective } from 'vue-draggable'

export default {
  directives: {
    dragAndDrop: VueDraggableDirective
  }
}

Usage

In the template, use the v-drag-and-drop directive:

HTML

<div v-drag-and-drop:options="options">
  <ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
  </ul>
  <ul>
      <li>Item 4</li>
      <li>Item 5</li>
      <li>Item 6</li>
  </ul>
</div>

Options

Directive v-drag-and-drop available options

{
  dropzoneSelector: 'ul',
  draggableSelector: 'li',
  handlerSelector: null,
  reactivityEnabled: true,
  multipleDropzonesItemsDraggingEnabled: true,
  showDropzoneAreas: true,
  onDrop: function(event) {},
  onDragstart: function(event) {},
  onDragenter: function(event) {},
  onDragover: function(event) {},
  onDragend: function(event) {}
}

Dropzone events (added, removed, reordered)

<div v-drag-and-drop:options="options">
  <ul
    @added="added"
    @removed="removed"
    @reordered="reordered"
  >
    <li data-id="1">Item 1</li>
    <li data-id="2">Item 2</li>
    <li data-id="3">Item 3</li>
  </ul>
</div>

These three custom events have additional ids and index params. Ids is an array of defined data-id attributes and index represents drop intersection. For more info check out example

Reactivity handling and renderless component

There is available VueDraggableGroup component so you don't need to write your own model manipulation logic. However, usage of this component is optional. Use only with Vue v2.6+. You can pass to component optional itemsKey prop if you want to change items collection property name. By default it's items.

<div v-drag-and-drop:options="options">
  <!-- optional renderless component -->
  <vue-draggable-group
    v-for="group in groups"
    v-model="group.items"
    :groups="groups"
    :key="group.id"
    :data-id="group.id"
    @change="onGroupsChange"
  >
    <ul>
      <li
        v-for="item in group.items"
        :key="item.id"
        :data-id="item.id"
      >
        <label v-text="item.name"></label>
      </li>
    </ul>
  </vue-draggable-group>
</div>

Event Params for onDrop, onDragstart, onDragenter, onDragover, onDragend callbacks

{
  nativeEvent: {}, // native js event
  items: [], // list of selected draggable elements
  owner: null, // old dropzone element
  droptarget: null // new dropzone element,
  stop: () => {} // Stop D&D (available only for callbacks `onDragstart` and `onDragend`)
}

TypeScript

Included TypeScript definitions.

Browser Compatibility

Polyfills for IE9+ support are included in the repo.

If you need to support IE9 in your applications, import the polyfills:

import 'vue-draggable/polyfills'

Contributors 🎖

| | | | | :---:|:---:|:---:|:---:|:---:| nikolasp|tiagocsilva|piboistudios|swaroopjo|figurluk|


LICENCE MIT - Created by Nikola Spalevic ([email protected])