All Projects → Aletheios → v-drag-drop

Aletheios / v-drag-drop

Licence: MIT license
Minimalistic drag & drop directives for Vue.js

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to v-drag-drop

Draggable Vue Directive
Vue2 directive that handles drag & drop
Stars: ✭ 286 (+1582.35%)
Mutual labels:  drag-and-drop, directive
angular-barcode
An angular directive for lindell's JsBarcode
Stars: ✭ 25 (+47.06%)
Mutual labels:  directive
zero-drag
Minimal abstraction of DOM drag-and-drop interactions
Stars: ✭ 17 (+0%)
Mutual labels:  drag-and-drop
vue-body-scroll-lock
A Vue directive to lock the body scroll without stopping the target element from scrolling.
Stars: ✭ 30 (+76.47%)
Mutual labels:  directive
react-dnd-treeview
A draggable / droppable React-based treeview component. You can use render props to create each node freely.
Stars: ✭ 207 (+1117.65%)
Mutual labels:  drag-and-drop
react-web-editor
The react-web-editor is a WYSIWYG editor library. you can resize and drag your component. It also has simple rich text editor
Stars: ✭ 191 (+1023.53%)
Mutual labels:  drag-and-drop
dflex
The sophisticated Drag and Drop library you've been waiting for 🥳
Stars: ✭ 806 (+4641.18%)
Mutual labels:  drag-and-drop
graphql-directive-sql
Unify your SQL schema and your GraphQL Schema. Use GraphQL SDL as the lingua franca to define your data requirements.
Stars: ✭ 28 (+64.71%)
Mutual labels:  directive
nextjs-shopify
The ultimate starter for headless Shopify stores
Stars: ✭ 231 (+1258.82%)
Mutual labels:  drag-and-drop
dockview
Zero dependency layout manager and builder with ReactJS support
Stars: ✭ 45 (+164.71%)
Mutual labels:  drag-and-drop
iOS11-Demos
Collection of samples and demos of features introduced in iOS 11
Stars: ✭ 16 (-5.88%)
Mutual labels:  drag-and-drop
qt-tile-layout
A tile layout for PyQt5
Stars: ✭ 18 (+5.88%)
Mutual labels:  drag-and-drop
email-editor
Email Editor to embed in your SaaS application. Fully customizable and lightweight.
Stars: ✭ 28 (+64.71%)
Mutual labels:  drag-and-drop
ngx-dnd
Angular 6+ Drag-And-Drop Library without dependencies. Based on akserg/ng2-dnd
Stars: ✭ 31 (+82.35%)
Mutual labels:  drag-and-drop
signdocs
Full-stack clone of DocuSign
Stars: ✭ 58 (+241.18%)
Mutual labels:  drag-and-drop
TKinterDesigner
TKinterDesigner is a tool software to develop the Python User Interface for Python programmer.
Stars: ✭ 663 (+3800%)
Mutual labels:  drag-and-drop
Modern-UI-Components-for-VBA
A helper dll for VBA users to design modern UI components. No install required!
Stars: ✭ 139 (+717.65%)
Mutual labels:  drag-and-drop
react-native-ios-drag-drop
Support for the iOS 11+ inter-app drag and drop
Stars: ✭ 94 (+452.94%)
Mutual labels:  drag-and-drop
reactodo
Multiple localStorage TODO lists, built with React
Stars: ✭ 28 (+64.71%)
Mutual labels:  drag-and-drop
graphql-directive-computed-property
GraphQL directive for create computed property
Stars: ✭ 32 (+88.24%)
Mutual labels:  directive

v-drag-drop

Minimalistic drag & drop directives for Vue.js

Note: Versions 2.x and above of v-drag-drop are compatible with Vue 3 only. Install version 1.x if you use Vue 2.

Designed to encapsulate some of the peculiarities of the native Drag & Drop API and make it easier to use with Vue.js. Also adds some handy features like namespaces.

Table of Contents

Installation

Install v-drag-drop:

npm install --save v-drag-drop

Then import it in your project:

import { createApp } from 'vue';
import vDragDrop from 'v-drag-drop';

const app = Vue.createApp(App);
app.use(vDragDrop);
app.mount('#app');

Or include the files via <script> tag:

<script src="https://unpkg.com/[email protected]/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/v-drag-drop/dist/vDragDrop.min.js"></script>
<script>
    const app = Vue.createApp(App);
    app.use(vDragDrop);
    app.mount('#app');
</script>

You can also register the directives locally in your Vue component:

import { draggable, droppable } from 'v-drag-drop';
export default {
    name: 'MyComponent',
    directives: {
        draggable, droppable
    }
};

Usage

The following template example is the minimum setup required to get a draggable element and a drop zone with v-drag-drop:

<div v-draggable="myData"></div>
<div v-droppable @v-drag-drop="handleDrop"></div>

This template example shows all the features supported by v-drag-drop. Check the API section for details.

<div
    v-draggable:namespace.dynamic.move="myData"
    @v-drag-start="onDragStart"
    @v-drag-move="onDragMove"
    @v-drag-end="onDragEnd"
>
</div>

<div
    v-droppable:namespace.dynamic
    @v-drag-enter="onDragEnter"
    @v-drag-over="onDragOver"
    @v-drag-leave="onDragLeave"
    @v-drag-drop="onDragDrop"
>
</div>

Also check the demos in the demo directory. You can run the demos with npm run demo. Open your browser at http://127.0.0.1:1337/demo.

Migration from version 3

In version 4 and above, custom events have been renamed to avoid clashes with the native events. Therefore, when migrating to the new version, you will have to give all event names a v- prefix. For example, @drag-start will become @v-drag-start.

API

v-drag-drop provides two directives: v-draggable for draggable elements and v-droppable for drop zones.

v-draggable

Value

This is the data you want to transfer to the drop zone. The data can be arbitrary objects or primitives.

Example:

export default {
    template: '<div v-draggable="myData"></div>',
    data() {
        return {
            myData: { foobar: 42 }
        };
    }
};

Argument

You can pass an argument to v-draggable. This argument is a namespace that defines in which drop zones the draggable item can be dropped (requires the drop zone to have the same namespace). Namespaces allow you to place multiple drop zones on the same page that accept different items.

If no namespace is defined (default), the items can be dropped on any drop zone. Namespaces can be assigned dynamically, see the dynamic modifier.

Example:

<div v-draggable:foo="myData"></div>
<div v-droppable:foo @v-drag-drop="handleDrop"></div> <!-- supports drop -->
<div v-droppable:bar @v-drag-drop="handleDrop"></div> <!-- drop prevented -->

Namespaces can also be assigned dynamically using dynamic arguments starting with Vue 2.6:

<div v-draggable:[namespaceName]="myData"></div>
<div v-droppable:[namespaceName] @v-drag-drop="handleDrop"></div> <!-- supports drop -->
<div v-droppable:foobar @v-drag-drop="handleDrop"></div> <!-- drop prevented -->

Modifiers

  • move: Optional. Add this modifier to get a crosshair cursor on the element: v-draggable.move

  • image: Optional. Use a drag image that is shown while dragging is in progress. If this modifier is set, the data to be transferred must be an object containing data and image.

    Example:

    <div v-draggable.image="{ data: myData, image: myImage }"></div>
  • dynamic: Optional. Enables dynamic namespace names. When dynamic is set, the given namespace attribute is treated as a property ("variable") name; the property must be of type String and must be present in the parent component (can be a computed property).

    Example:

    export default {
        template: '<div v-draggable:myNamespace.dynamic="myData"></div>',
        data() {
            return {
                myData: { foobar: 42 },
                myNamespace: 'actualNamespaceName' // can be changed later
            };
        }
    };

    Note: The dynamic modifier is required to enable truly dynamic arguments whose values can change later in time. By contrast, "dynamic" arguments in Vue 2.6+ are evaluated only once at the beginning and then statically passed to the directive. You can use those with v-drag-drop if you want, but they won't have the same effect as you'd get with the dynamic modifier.

Events

  • drag-start: Fired when the user starts dragging.

  • drag-move: Fired repeatedly while dragging is in progress.

  • drag-end: Fired when dragging is finished.

All event listeners are called with two arguments:

  1. The dragged data
  2. The native JavaScript event

v-droppable

Value

Unused.

Argument

The namespace of the drop zone, see v-draggable. If no namespace is given, all items can be dropped on this drop zone.

Modifiers

  • dynamic: Optional. Enables dynamic namespace names. See v-draggable.

Events

  • drag-enter: Fired when a dragged item enters the drop zone.

  • drag-over: Fired repeatedly while a dragged item is over the drop zone.

  • drag-leave: Fired when a dragged item leaves the drop zone.

  • drag-drop: Fired when an item has been dropped on the drop zone. Called with the dragged data and the original drop event. This enables you for example to retrieve the precise mouse coordinates of the drop.

All event listeners are called with three parameters:

  1. The dragged data
  2. Whether or not dropping will be possible (i.e. the namespaces of the dragged item and the drop zone match)
  3. The native JavaScript event
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].