### Install vue-draggable-plus Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/guide/index.en-US.md Install the vue-draggable-plus package using npm. ```bash npm install vue-draggable-plus ``` -------------------------------- ### Event Handling with v-on Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/api/index.zh-CN.md Demonstrates how to use v-on to listen for drag events like 'start' and 'end' emitted by the VueDraggable component. The 'onStart' and 'onEnd' functions are called when the respective events are triggered. ```APIDOC ## Event Handling with v-on ### Description All event functions starting with `on` can be passed to the component using `v-on`. ### Example Usage ```vue ``` > For Hooks and directive usage, please refer to the documentation. ``` -------------------------------- ### Incorrect Usage: Multiple Root Elements Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/target-container/index.en-US.md This example demonstrates an incorrect usage pattern where the component contains multiple root elements, which can lead to issues when specifying a target container. ```vue ``` -------------------------------- ### Correct Usage: Single Root Element Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/target-container/index.en-US.md This example shows the correct way to structure a component with a single root element, ensuring proper functionality when specifying a target container for drag operations. ```vue ``` -------------------------------- ### Vue Component with Drag and Drop Events Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/api/index.zh-CN.md Demonstrates how to use the VueDraggable component with v-on to handle start and end drag events. Ensure the component is imported and the list data is reactive. ```vue ``` -------------------------------- ### VueDraggable Component Usage Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/api/index.en-US.md Demonstrates how to use the VueDraggable component in a Vue template, including binding a model and handling drag start and end events. ```APIDOC ## VueDraggable Component Usage ### Description This example shows how to integrate the `VueDraggable` component into a Vue application. It demonstrates how to bind a list to the `v-model` directive and how to listen for drag events like `start` and `end` using `v-on`. ### Component `` ### Props - `v-model`: Binds the list data to the draggable component. ### Events - `@start`: Emitted when dragging starts. Accepts a callback function. - `@end`: Emitted when dragging ends. Accepts a callback function. ### Request Example ```vue ``` ``` -------------------------------- ### Implemented Using Directive Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/transitions/index.en-US.md Implement transition effects using a directive for drag-and-drop and restoration. ```vue ``` -------------------------------- ### Function Usage: Using function Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/transition/index.en-US.md Implement transition animations by using a function. This allows for dynamic control over transition properties. ```vue ``` -------------------------------- ### Basic Vue Draggable Usage with Event Handling Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/api/index.en-US.md Demonstrates how to use the VueDraggable component with v-model for data binding and @start/@end events for drag-and-drop lifecycle hooks. Ensure VueDraggable and DraggableEvent are imported. ```vue ``` -------------------------------- ### Handling Drag Events with VueDraggable Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/README.md Attach event listeners like @start and @end to the VueDraggable component to react to drag and drop actions. The event object provides details about the drag operation. ```vue ``` -------------------------------- ### Configuration Props Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/api/index.en-US.md These props allow you to configure the behavior of the draggable component. ```APIDOC ## Props ### removeCloneOnHide - **Description**: Remove instead of hiding cloned element when not displayed - **Type**: `Boolean` - **Default**: `true` ### sort - **Description**: Allow list items to be sorted within container - **Type**: `Boolean` - **Default**: `true` ### swapThreshold - **Description**: Swap zone threshold - **Type**: `Number` - **Default**: `1` ### touchStartThreshold - **Description**: Pixels before cancelling delay touch event - **Type**: `Number` - **Default**: `1` ### setData - **Description**: Pass a function where the first argument is of type `DataTransfer` and the second argument is of type `HTMLElement` - **Type**: `Function` ### scroll - **Description**: Enable scrolling - **Type**: `Boolean` - **Default**: `true` ### scrollFn - **Description**: Custom scroll function - **Type**: `ScrollFn` ### scrollSensitivity - **Description**: The distance in pixels the mouse must be to the edge to start scrolling - **Type**: `Number` ### scrollSpeed - **Description**: The scrolling speed in ms/px - **Type**: `number` ### bubbleScroll - **Description**: Enables automatic scrolling for all parent elements to make it easier to move items - **Type**: `Boolean` - **Default**: `true` ``` -------------------------------- ### Combining Transitions Using Function Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/transitions/index.en-US.md Combine transitions using a function for dynamic control over animation and restoration effects. ```vue ``` -------------------------------- ### Configuration Properties Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/README.md These properties allow you to customize the drag-and-drop functionality, such as controlling element visibility, sorting, and scroll behavior. ```APIDOC ## Configuration Properties | Property Name | Description | Type | Default Value | |-------------------------|------------------------------------------------------------------------------------------------------------|----------|---------------| | `removeCloneOnHide` | Remove instead of hiding cloned element when not displayed | `Boolean` | `true` | | `sort` | Allow list items to be sorted within container | `Boolean` | `true` | | `swapThreshold` | Swap zone threshold | `Number` | `1` | | `touchStartThreshold` | Pixels before cancelling delay touch event | `Number` | `1` | | `setData` | Pass a function where the first argument is of type `DataTransfer` and the second argument is of type `HTMLElement` | `Function` | `-` | | `scroll` | Enable scrolling | `Boolean` | `true` | | `scrollFn` | Custom scroll function | `ScrollFn` | `-` | | `scrollSensitivity` | The distance in pixels the mouse must be to the edge to start scrolling | `Number` | `-` | | `scrollSpeed` | The scrolling speed in ms/px | `number` | `-` | | `bubbleScroll` | Enables automatic scrolling for all parent elements to make it easier to move items | `Boolean` | `true` | ``` -------------------------------- ### Vue Draggable Plus Configuration Options Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/api/index.en-US.md This section details the various parameters that can be used to configure the Vue Draggable Plus component. ```APIDOC ## Vue Draggable Plus Configuration This document outlines the various parameters available for configuring the Vue Draggable Plus component. ### Parameters - **animation** (Number) - Show animation while dragging. Default: 0 - **chosenClass** (String) - CSS class name for chosen item. Default: 'sortable-chosen' - **delay** (Number) - Delay in milliseconds before drag starts. Default: 0 - **delayOnTouchOnly** (Number) - Delay on touch event. Default: 0 - **direction** (String) - Dragging direction, `vertical` or `horizontal` (default auto detect). Default: auto detect - **disabled** (Boolean) - Disable dragging. Default: false - **dragClass** (String) - CSS class name for dragged item. Default: 'sortable-drag' - **draggable** (String) - Selector for draggable items within element. Default: - - **emptyInsertThreshold** (Number) - Distance (in pixels) from empty sortable items where dragging element should be inserted. Set to `0` to disable this feature. Default: 5 - **easing** (Easing) - Animation easing. Default: - - **fallbackClass** (String) - CSS class name for cloned DOM elements when using forceFallback. Default: 'sortable-fallback' - **fallbackOnBody** (Boolean) - Append cloned DOM element to body element. Default: false - **fallbackTolerance** (Number) - Pixels mouse must move before drag start when using forceFallback. Default: 0 - **filter** (String) - Selector for items that should not be draggable. Default: - - **forceFallback** (Boolean) - Ignore HTML5 drag and drop behavior and force fallback. Default: false - **ghostClass** (String) - CSS class name for drop placeholder. Default: 'sortable-ghost' - **group** (Group) - Group items to drag between sortable lists. Both lists must have the same `group` value. Also define whether lists can be dragged out of, cloned, or receive elements from other lists. See TypeScript type definition above for details. Default: - - **handle** (String) - Selector for handle to initiate drag. If not set, the target element's children are used. Default: - - **invertSwap** (Boolean) - Always use inverted swap zone if set to true. Default: false - **invertedSwapThreshold** (Number) - Inverted swap zone threshold, defaults to `swapThreshold` value. Default: - - **preventOnFilter** (Boolean) - Call `event.preventDefault()` on filter event. Default: true ``` -------------------------------- ### Component Composition Transition Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/transitions/index.en-US.md Use this component to implement transition effects when dragging and sorting items, and use the transition attribute for restoration. ```vue ``` -------------------------------- ### Global Registration Source: https://context7.com/alfred-skyblue/vue-draggable-plus/llms.txt Register `VueDraggable` and `vDraggable` globally so they are available in every component without per-file imports. ```APIDOC ## Global Registration Register `VueDraggable` and `vDraggable` globally so they are available in every component without per-file imports. ```ts // main.ts import { createApp } from 'vue' import App from './App.vue' import { VueDraggable, vDraggable } from 'vue-draggable-plus' const app = createApp(App) app.component('VueDraggable', VueDraggable) app.directive('draggable', vDraggable) app.mount('#app') ``` ``` -------------------------------- ### Component Usage for Target Container Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/target-container/index.en-US.md Demonstrates using Vue Draggable as the root element to find the nearest '.el-table' selector as the target container. ```vue ``` -------------------------------- ### Group Options Interface Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/README.md Configuration options for defining groups of sortable elements, including name, pull, put, and revertClone. ```APIDOC ## Interface: GroupOptions ```ts interface GroupOptions { /** * Group name. */ name: string; /** * The ability to move from the list. Clone - copy the item instead of moving it. */ pull?: PullResult | ((to: Sortable, from: Sortable, dragEl: HTMLElement, event: SortableEvent) => PullResult) | undefined; /** * Whether elements can be added from other lists, or an array of group names from which elements can be obtained. */ put?: PutResult | ((to: Sortable, from: Sortable, dragEl: HTMLElement, event: SortableEvent) => PutResult) | undefined; /** * After moving to another list, the cloned element is restored to its initial position. */ revertClone?: boolean | undefined; } ``` ``` -------------------------------- ### Clone using components Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/custom-clone/index.en-US.md Pass the `pull.clone` attribute of the group to realize cloning. Ensure the `pull` attribute is set to `clone` and the `name` attribute in the `group` is consistent for cloning to work. ```vue ``` -------------------------------- ### Function Usage for Target Container Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/target-container/index.en-US.md Illustrates using a function to specify the target container, ensuring it can be obtained by adding an ID 'my-container' to the parent div. This method is suitable when the target container might not be directly accessible. ```vue ``` -------------------------------- ### Clone using Components Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/clone/index.en-US.md Use the `pull.clone` attribute within the `group` configuration to enable cloning when using components. Ensure the `pull` attribute is set to `clone` for this functionality. ```vue ``` -------------------------------- ### Clone using Directive Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/clone/index.en-US.md Implement cloning functionality using directives by passing options to the `clone` attribute. This method requires the `pull` attribute in the `group` to be set to `clone`. ```vue ``` -------------------------------- ### Event Handlers Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/README.md These events are triggered by various user interactions during the drag-and-drop process, allowing for custom logic execution. ```APIDOC ## Event Handlers | Event Name | Description | Type | |------------|--------------------------------------------------------------------------|------------------------------------| | `onChoose` | Triggered when an item is selected | `((event: SortableEvent) => void)` | | `onUnchoose` | Triggered when an item is deselected | `((event: SortableEvent) => void)` | | `onStart` | Triggered when an item is picked up for drag and drop | `((event: SortableEvent) => void)` | | `onEnd` | Triggered when an item is no longer being dragged | `((event: SortableEvent) => void)` | | `onAdd` | Triggered when an item is moved from one list to another | `((event: SortableEvent) => void)` | | `onUpdate` | Triggered when the order of the items is updated | `((event: SortableEvent) => void)` | | `onSort` | Triggered whenever any changes are made to the list | `((event: SortableEvent) => void)` | | `onRemove` | Triggered when an item is removed from the list and moved to another | `((event: SortableEvent) => void)` | | `onFilter` | Triggered when trying to drag a filtered item | `((event: SortableEvent) => void)` | | `onMove` | Triggered while an item is being dragged | `((event: MoveEvent,originalEvent: Event) => void)` | | `onClone` | Triggered when an item is cloned | `((event: SortableEvent) => void)` | | `onChange` | Triggered when an item is dragged and changes position | `((event: SortableEvent) => void)` | ``` -------------------------------- ### Cloning using Function Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/clone/index.en-US.md Achieve cloning by passing a custom function to the `clone` attribute. This allows for more control over the cloning process. Ensure the `pull` attribute in the `group` is set to `clone`. ```vue ``` -------------------------------- ### Cloning using function Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/custom-clone/index.en-US.md Use a function passed to the `clone` attribute to achieve custom cloning logic. This function receives the item to be cloned and should return the cloned item, ensuring a unique key is regenerated. ```vue ``` -------------------------------- ### Integrating VueDraggable with TransitionGroup for Animations Source: https://context7.com/alfred-skyblue/vue-draggable-plus/llms.txt Combine `VueDraggable` with Vue's `` component to achieve CSS enter/leave animations for items added or removed, alongside smooth drag reordering. Point the `target` prop to the `TransitionGroup`'s rendered element. ```vue ``` -------------------------------- ### DraggableEvent — Enhanced Sortable Event Source: https://context7.com/alfred-skyblue/vue-draggable-plus/llms.txt Every event callback receives a `DraggableEvent` that extends the native `SortableEvent` with two extra properties: `data` (the reactive data item that was dragged) and `clonedData` (the clone used for cross-list moves). ```APIDOC ## `DraggableEvent` — Enhanced Sortable Event Every event callback receives a `DraggableEvent` that extends the native `SortableEvent` with two extra properties: `data` (the reactive data item that was dragged) and `clonedData` (the clone used for cross-list moves). ### Event Properties - **data** (T) - The reactive data item that was dragged. - **clonedData** - The clone used for cross-list moves. - **newIndex** (number) - Index in the destination list (standard SortableEvent). ``` -------------------------------- ### Group Type Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/README.md Defines the type for group configuration, which can be a string name or a GroupOptions object. ```APIDOC ## Type: Group ```ts type Group = string | GroupOptions | undefined; ``` ``` -------------------------------- ### useDraggable Options Type Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/api/index.en-US.md Defines the options available for the `useDraggable` composable, including custom cloning behavior, immediate execution, and custom update callbacks. ```APIDOC ## `useDraggable` Options ### Description This interface defines the optional configuration parameters for the `useDraggable` composable, extending the base `Options` from Sortablejs. ### Type Definition ```typescript export interface UseDraggableOptions extends Options { clone?: (element: T) => T immediate?: boolean customUpdate?: (event: DraggableEvent) => void } ``` ### Properties - `clone`: A function to customize the cloning of elements during drag operations. - `immediate`: A boolean flag to determine if dragging should start immediately. - `customUpdate`: A callback function to handle custom update logic during drag events. ``` -------------------------------- ### Sortablejs Options - Group Source: https://github.com/alfred-skyblue/vue-draggable-plus/blob/main/src/__docs__/api/index.en-US.md Details the `GroupOptions` interface for configuring group behavior in Sortablejs, including name, pull, and put properties for managing interactions between lists. ```APIDOC ## Sortablejs Options - `GroupOptions` ### Description This interface defines the configuration for grouping sortable lists, allowing control over how items can be moved between different lists. ### Type Definition ```typescript interface GroupOptions { /** * Group name. */ name: string; /** * The ability to move from the list. Clone - copy the item instead of moving it. */ pull?: PullResult | ((to: Sortable, from: Sortable, dragEl: HTMLElement, event: SortableEvent) => PullResult) | undefined; /** * Whether elements can be added from other lists, or an array of group names from which elements can be obtained. */ put?: PutResult | ((to: Sortable, from: Sortable, dragEl: HTMLElement, event: SortableEvent) => PutResult) | undefined; /** * After moving to another list, the cloned element is restored to its initial position. */ revertClone?: boolean | undefined; } type Group = string | GroupOptions | undefined; ``` ### Properties - `name`: The name of the group. - `pull`: Determines if and how items can be moved out of the list (e.g., `true`, `false`, `'clone'`). Can also be a function for custom logic. - `put`: Determines if and from which groups items can be added to this list. Can be `true`, `false`, an array of group names, or a function for custom logic. - `revertClone`: If `true`, the cloned element returns to its original position after being moved to another list. ``` -------------------------------- ### Cloning Items Between Lists Source: https://context7.com/alfred-skyblue/vue-draggable-plus/llms.txt Configure a list to clone items instead of moving them by setting `group.pull: 'clone'`. Use the `clone` option with a factory function to generate new item data, ensuring unique IDs for cloned elements. ```vue ``` -------------------------------- ### Drag Handle for Specific Elements Source: https://context7.com/alfred-skyblue/vue-draggable-plus/llms.txt Limit drag initiation to specific child elements by providing a CSS selector to the `handle` option. This allows other parts of the item, like input fields, to remain interactive. ```vue ```