### Install Fluid DnD using package managers
Source: https://fluid-dnd.netlify.app/vue/introduction/introduction
Instructions for installing the Fluid DnD library into your project using npm, yarn, or pnpm, the most common JavaScript package managers.
```bash
# with npm:
npm i fluid-dnd
# with yarn:
yarn add fluid-dnd
# with pnpm:
pnpm i fluid-dnd
```
--------------------------------
### Global setup of Fluid DnD composable in Vue.js
Source: https://fluid-dnd.netlify.app/vue/introduction/introduction
Demonstrates how to make the `useDragAndDrop` composable available throughout your entire Vue.js application by using Vue's provide/inject mechanism in your main application entry file.
```javascript
import { createApp } from "vue";
import App from './App.vue';
import { useDragAndDrop } from "fluid-dnd/vue";
const app = createApp(App);
app.provide('useDragAndDrop', useDragAndDrop);
app.mount('#app');
```
--------------------------------
### Vue Script Setup for Editable Drag-and-Drop List
Source: https://fluid-dnd.netlify.app/vue/guides/listinputs
This Vue
```
--------------------------------
### Local import of Fluid DnD composable in Vue.js component
Source: https://fluid-dnd.netlify.app/vue/introduction/introduction
Illustrates how to import the `useDragAndDrop` composable directly into a specific Vue.js component's script section for localized usage, providing flexibility for component-specific drag-and-drop functionalities.
```vue
```
--------------------------------
### Configure Vue Drag and Drop with Handler Selector
Source: https://fluid-dnd.netlify.app/vue/guides/styles/listhandler
This snippet demonstrates how to initialize the `useDragAndDrop` composable in a Vue 3 setup script, passing a `handlerSelector` option to specify a draggable handle. It imports necessary components and sets up a reactive list.
```Vue
```
--------------------------------
### Initialize Fluid DnD for List Insertion in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/actions/listinsert
This snippet demonstrates the initial setup for using Fluid DnD to manage a list. It imports necessary functions from Vue and Fluid DnD, initializes a reactive list, and extracts the `parent` ref and `insertAt` function from `useDragAndDrop` for list manipulation.
```Vue
```
--------------------------------
### Define CSS Styles for Elements Being Removed
Source: https://fluid-dnd.netlify.app/vue/guides/actions/listremove
Provides example CSS to style elements that have the `removed` class applied. It includes a transition for opacity, creating a smooth visual effect as items fade out before being fully removed.
```CSS
```
--------------------------------
### Initialize Horizontal List with Fluid DnD in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/horizontallist
This Vue 3 setup script demonstrates how to create a reactive list of numbers and enable horizontal drag-and-drop functionality using the `useDragAndDrop` composable from Fluid DnD, specifying `direction: "horizontal"`.
```Vue
```
--------------------------------
### Initialize Fluid DnD for a Sortable List in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/verticallist
This snippet demonstrates how to set up a reactive list and initialize the useDragAndDrop composable from fluid-dnd/vue in a Vue 3
```
--------------------------------
### Configure Droppable Class for Vue Lists
Source: https://fluid-dnd.netlify.app/vue/guides/styles/droppableclass
This Vue `script setup` block initializes two reactive lists (`list1`, `list2`) using the `useDragAndDrop` composable. Both lists are assigned to `droppableGroup: "group1"` and configured with `droppableClass: 'droppable-hover'`, which specifies the CSS class to be applied to a droppable element when a draggable item is dragged over it, providing visual feedback.
```TypeScript
```
--------------------------------
### Chaining Multiple Coordinate Mappers in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/events/mapcoordinates
This example illustrates how to apply multiple coordinate transformation functions sequentially using `coordinateTransform`. It combines the `lockAxis` function with a `gridTranslate` function to snap the dragged item to a defined grid size after locking the axis, showcasing how outputs of one mapper become inputs for the next.
```Vue
```
--------------------------------
### Vue: Handling Drag Start and End Events to Toggle Classes
Source: https://fluid-dnd.netlify.app/vue/guides/events/ondrag
This snippet demonstrates how to use `onDragStart` and `onDragEnd` events with Fluid DnD to dynamically toggle a CSS class (`marked-droppable`) on droppable elements. It utilizes `useTemplateRef` to get a reference to a group of droppables and iterates through them to apply or remove the class based on the drag state. The `useDragAndDrop` composable is configured with these event handlers for two lists.
```Vue
```
--------------------------------
### Initialize Vue list for scrollable drag-and-drop
Source: https://fluid-dnd.netlify.app/vue/guides/verticallistautoscroll
This Vue 3 setup script initializes a large array of numbers and binds it to a draggable parent element using `useDragAndDrop`. This prepares the data and the DOM reference for a list that will support drag-and-drop interactions within a scrollable container.
```Vue
```
--------------------------------
### Vue Script Setup for Draggable Table Data
Source: https://fluid-dnd.netlify.app/vue/guides/sortingtable
This Vue script block initializes a reactive `table` array of `Person` objects and integrates the `useDragAndDrop` composable from `fluid-dnd/vue`. It sets up the data structure for the table rows and configures the drag-and-drop behavior, including a `draggingClass` for visual feedback during dragging. The `parent` ref returned by `useDragAndDrop` will be bound to the draggable container in the template.
```TypeScript
```
--------------------------------
### Define Grouped Lists for Drag and Drop in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/events/mapvalues
This snippet demonstrates how to initialize two separate lists (`list` and `list2`) using `useDragAndDrop` from Fluid DnD, assigning them to the same `droppableGroup` ('group1'). This setup allows elements to be dragged and dropped between these lists, forming a logical group.
```Vue
```
--------------------------------
### Configure Vue lists for multiple drag and drop groups
Source: https://fluid-dnd.netlify.app/vue/guides/listgroup
This example modifies the `droppableGroup` parameter for `list2` to include 'group2' in addition to 'group1'. This demonstrates how a list can belong to multiple groups, allowing for more complex conditional drag-and-drop interactions where elements can only be moved if groups overlap.
```Vue
```
--------------------------------
### Define lists with shared droppable group in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/listgroup
This snippet shows how to initialize two reactive lists (`list1`, `list2`) and associate them with a common `droppableGroup` named 'group1' using the `useDragAndDrop` composable. This setup enables elements to be dragged and dropped between these two lists.
```Vue
```
--------------------------------
### Vue: Accessing Drag Event Data (Value and Index)
Source: https://fluid-dnd.netlify.app/vue/guides/events/ondrag
This example illustrates how to access detailed information from `onDragStart` and `onDragEnd` events using `DragStartEventData` and `DragEndEventData` types from `fluid-dnd`. It demonstrates how to capture the `value` of the dragged element and the last dropped element, storing them in reactive references for display or further processing.
```Vue
```
--------------------------------
### Vue Drag and Drop with Conditional Draggability
Source: https://fluid-dnd.netlify.app/vue/example/vertical-list/single-vertical-list-component-with-is-draggable
This Vue component uses `fluid-dnd/vue` to create a vertical list of draggable Pokemon. It demonstrates the `isDraggable` option, which is a function that determines if an element can be dragged. In this example, Pokemon classified as 'L' (Large) based on their weight are made non-draggable by adding the `is-not-draggable` class.
```Vue
```
--------------------------------
### Define CSS Styles for Inserting Elements
Source: https://fluid-dnd.netlify.app/vue/guides/actions/listinsert
This CSS snippet provides styles for elements during the insertion process. The `.number` class defines a default opacity and transition, while the `.number.inserting` class sets the opacity to 0, creating a fade-in effect when an element is inserted and the 'inserting' class is applied.
```CSS
```
--------------------------------
### Create Vue Template for List and Insertion Button
Source: https://fluid-dnd.netlify.app/vue/guides/actions/listinsert
This template defines the user interface for the draggable list. It uses a `ul` element bound to the `parent` ref for Fluid DnD functionality and iterates through the `list` to display elements. An 'Add' button is included, which calls `insertAt` to append new elements to the list.
```Vue
{{ element }}
```
--------------------------------
### Initialize a Vue reactive list with mixed styles
Source: https://fluid-dnd.netlify.app/vue/guides/verticalliststyles
This JavaScript snippet defines a reactive `ref` named `list` in Vue, containing an array of objects. Each object represents a list item with a unique `id`, `content`, and an inline `style` string. This structure is crucial for maintaining distinct visual appearances for each element when using Fluid DnD, as it ensures styles are directly associated with the element rather than relying on positional CSS selectors.
```JavaScript
const list = ref([
{
id: "1",
style:
"margin: 30px 0px; border-style: solid; border-width: 0.8rem; padding: 5px;",
content: "1",
},
{
id: "2",
style:
"margin: 20px 0px; border-style: solid; border-width: 0.6rem; padding: 10px;",
content: "2",
},
{
id: "3",
style:
"margin: 10px 0px; border-style: solid; border-width: 0.4rem; padding: 15px;",
content: "3",
}
])
```
--------------------------------
### Vue.js Single Vertical Drag-and-Drop List Implementation
Source: https://fluid-dnd.netlify.app/vue/example/vertical-list/single-vertical-list
This Vue component demonstrates creating a draggable vertical list of Pokemon items. It uses `fluid-dnd/vue`'s `useDragAndDrop` composable to enable reordering, applies a `dragging-pokemon` class during drag, and allows configuring a `delayBeforeTouchMoveEvent` for touch devices. Data is fetched asynchronously, and individual items are rendered using `PokemonComponent.vue`.
```vue
```
--------------------------------
### Initialize Fluid DnD for List Element Removal (Vue)
Source: https://fluid-dnd.netlify.app/vue/guides/actions/listremove
Demonstrates how to set up a reactive list in Vue and extract the `removeAt` function from `fluid-dnd/vue`'s `useDragAndDrop` composable, which is essential for programmatically removing elements from the list.
```Vue
```
--------------------------------
### Implement Drag and Drop for Multiple Pokemon Lists in Vue
Source: https://fluid-dnd.netlify.app/vue/example/vertical-list/group-vertical-lists
This Vue.js component demonstrates how to create and manage multiple vertical lists of Pokemon using the `fluid-dnd` library for drag-and-drop functionality. It fetches Pokemon data for three different generations, initializes separate reactive arrays for each, and applies `useDragAndDrop` to enable seamless reordering and transfer of Pokemon between these lists.
```Vue
// ...
const { parent, removeAt } = useDragAndDrop(list,{
insertingFromClass: "inserting",
delayBeforeInsert: 800
});});
```
--------------------------------
### Vue Template and Styles for Horizontal List
Source: https://fluid-dnd.netlify.app/vue/guides/horizontallist
This snippet provides the Vue template structure and basic CSS for rendering the horizontal list. It uses a `div` with a `ref` for the drag-and-drop parent and iterates over the list elements, applying flexbox to ensure a horizontal layout.
```Vue
{{ element }}
```
--------------------------------
### Vue Component Iteration and Styling
Source: https://fluid-dnd.netlify.app/vue/example/vertical-list/group-vertical-lists
This Vue.js template fragment demonstrates how to apply Tailwind CSS-like utility classes for styling a container, followed by iterating over a 'pokemon3G' array using 'v-for' to render multiple 'PokemonComponent' instances. Each component receives 'pokemon' data and its 'index' as props, and the container is styled for overflow and responsiveness.
```Vue Template
class="bg-gray-200/60 border-solid border-black/40 rounded-2xl w-60 border-4 p-4 block overflow-auto max-h-[30rem] max-lg:p-1 max-sm:p-0.5 max-sm:border-2"
>
```
--------------------------------
### Render a Sortable Vertical List with Basic Styles in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/verticallist
This snippet shows the Vue template structure for rendering a sortable list of numbers, iterating over the list array. It also includes basic CSS styles to visually represent the list items and the container, making them suitable for drag-and-drop operations. This is the next step after initializing the list in the script.
```Vue
{{ element }}
```
```CSS
```
--------------------------------
### Render draggable and droppable lists in Vue template
Source: https://fluid-dnd.netlify.app/vue/guides/listgroup
This code defines the HTML template for displaying the two lists (`list1`, `list2`) configured for drag and drop. It uses `ref` to bind the parent elements to the `useDragAndDrop` composable and `v-for` to render individual list items, making them interactive.
```Vue
{{ element }}
{{ element }}
```
--------------------------------
### Render Draggable List and Define Dragging Styles in Vue Template
Source: https://fluid-dnd.netlify.app/vue/guides/styles/draggingclass
This snippet provides the Vue template structure for rendering the draggable list, binding the `ul` element to the `parent` ref for Fluid DnD functionality. It also includes the associated CSS, defining the `.dragging` class with transition, background-color, and color properties to visually highlight dragged items.
```Vue
{{ element }}
```
--------------------------------
### Vue Template and Styles for Editable Drag-and-Drop List Rendering
Source: https://fluid-dnd.netlify.app/vue/guides/listinputs
This snippet defines the Vue template and associated CSS for rendering the editable list. The
element is bound to the parent ref for drag-and-drop. Each
iterates over the list data, displaying an editable text input for the person's name and a checkbox to toggle edit mode, along with basic styling for the list and its items.
```Vue
```
--------------------------------
### Initialize Draggable List with Custom Dragging Class in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/styles/draggingclass
This Vue Composition API snippet demonstrates how to set up a reactive list of numbers and make it draggable using `useDragAndDrop` from `fluid-dnd/vue`. It configures the `draggingClass` option to apply a specific CSS class, 'dragging', to elements while they are being dragged, enabling custom visual feedback.
```Vue
```
--------------------------------
### Vue template for rendering a draggable list with mixed styles
Source: https://fluid-dnd.netlify.app/vue/guides/verticalliststyles
This Vue template demonstrates how to render the `list` defined previously, applying each element's unique `style` attribute. The `ul` element is referenced by `parent`, which is typically used with the `useDragAndDrop` composable to enable drag-and-drop functionality. The `v-for` directive iterates over the `list`, binding `index` and `style` to each `li` element, ensuring individual styling is preserved during reordering.
```Vue
{{ element.content }}
```
--------------------------------
### Define Vue Template and CSS for Droppable Styles
Source: https://fluid-dnd.netlify.app/vue/guides/styles/droppableclass
This snippet provides the Vue template structure for the two lists, `parent1` and `parent2`, which will serve as droppable containers. It also includes the corresponding CSS rules (`.number-list.droppable-hover` and `.number-list-h.droppable-hover`) that define the visual appearance (e.g., background color change) when a draggable element is hovered over these droppable areas, enhancing user interaction feedback.
```HTML
```
```CSS
```
--------------------------------
### Configure Inserting Class for Fluid DnD in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/actions/listinsert
This snippet shows how to configure `useDragAndDrop` to apply a specific CSS class when an element is being inserted. By setting `insertingFromClass` to 'inserting', developers can define custom styles that are active during the insertion animation.
```Vue
```
--------------------------------
### Vue: Defining Drag-and-Drop Lists in Template
Source: https://fluid-dnd.netlify.app/vue/guides/events/ondrag
This template snippet shows the HTML structure for the drag-and-drop lists. It defines a parent `div` with a `ref` attribute (`droppableGroup`) to be referenced in the script, and two `ul` and `div` elements with `ref` attributes (`parent1`, `parent2`) that serve as the drag-and-drop containers for the lists.
```Vue
```
--------------------------------
### Create Vue Template for Draggable List with Removal Buttons
Source: https://fluid-dnd.netlify.app/vue/guides/actions/listremove
Illustrates the Vue template structure for a draggable list. Each list item includes a button that triggers the `removeAt` function, allowing users to remove specific elements by their index.
```Vue
{{ element }}
```
--------------------------------
### Render Draggable List with Handler in Vue Template
Source: https://fluid-dnd.netlify.app/vue/guides/styles/listhandler
This Vue template snippet shows how to render a list of draggable items. Each list item includes a `Handler` component with the `handler` class, which corresponds to the `handlerSelector` defined in the script, making only this specific part of the item draggable.
```Vue
{{ element }}
```
--------------------------------
### Implement Horizontal Drag-and-Drop List in Vue
Source: https://fluid-dnd.netlify.app/vue/example/horizontal-list/single-horizontal-list
This Vue 3 component demonstrates how to create a horizontal drag-and-drop list using the 'fluid-dnd/vue' composable. It initializes a list of Pokemon, fetches data, and applies drag-and-drop functionality to the parent container, allowing items to be reordered horizontally with a custom dragging class.
```Vue
```
--------------------------------
### Vue Component for Draggable Vertical Pokemon List with Insert
Source: https://fluid-dnd.netlify.app/vue/example/vertical-list/single-vertical-list-with-insert
This Vue 3 component demonstrates how to create a draggable vertical list of Pokemon using the `fluid-dnd/vue` library. It fetches an initial set of Pokemon data and renders them as draggable items, allowing for reordering and insertion within the list. The `useDragAndDrop` composable is used to manage the drag-and-drop functionality, applying a 'dragging-pokemon' class during drag operations.
```Vue
```
--------------------------------
### Add Index and Key Attributes to List Items for Fluid DnD in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/verticallist
This snippet demonstrates how to add :index and :key attributes to each
element within the v-for loop. The index attribute provides the current position, and the key attribute uniquely identifies each element, both essential for Fluid DnD to manage sorting correctly and efficiently update the DOM.
```Vue
{{ element }}
```
--------------------------------
### Vue: Configure isDraggable property for list items
Source: https://fluid-dnd.netlify.app/vue/guides/isdraggable
This script demonstrates how to initialize a draggable list using `useDragAndDrop` from `fluid-dnd/vue`. The `isDraggable` option is configured with a callback function that prevents elements containing the 'is-not-draggable' class from being dragged, providing granular control over drag behavior.
```Vue
```
--------------------------------
### Map Values Between Drag and Drop Lists in Vue
Source: https://fluid-dnd.netlify.app/vue/guides/events/mapvalues
This snippet illustrates how to use the `mapFrom` parameter within `useDragAndDrop` to transform item data when moving between lists. It defines two mapping functions, `MapItemToMinifiedItem` and `MapMinifiedItemToItem`, to convert between different item structures (`Item` and `MinifiedItem`) during drag-and-drop operations, ensuring data consistency.
```Vue
```
--------------------------------
### Vue Component for Horizontal Drag-and-Drop Pokemon Lists
Source: https://fluid-dnd.netlify.app/vue/example/horizontal-list/group-horizontal-lists
This Vue component, `GroupOfHorizontalListOfPokemons.vue`, demonstrates how to create multiple independent horizontal lists of Pokemon that support drag-and-drop functionality. It uses the `fluid-dnd/vue` library to enable reordering within each list. The component fetches Pokemon data for three different generations and applies the drag-and-drop behavior to each list, all sharing the same `droppableGroup`.
```Vue
```
--------------------------------
### Attach Parent Reference for Fluid DnD in Vue Template
Source: https://fluid-dnd.netlify.app/vue/guides/verticallist
This snippet illustrates how to bind the parent reference obtained from useDragAndDrop to the
element in the Vue template. This step is crucial for Fluid DnD to identify the main container for drag-and-drop operations, enabling the library to manage the drag and drop behavior correctly within this element.
```Vue
{{ element }}
```
--------------------------------
### Vue Component for Draggable Vertical List with Remove
Source: https://fluid-dnd.netlify.app/vue/example/vertical-list/single-vertical-list-with-remove
This Vue component, `SingleVerticalListOfPokemons.vue`, demonstrates how to create a draggable vertical list using the `fluid-dnd/vue` library. It fetches a list of Pokemon, makes them draggable, and allows items to be removed from the list with a specified delay. The `useDragAndDrop` hook is configured with a `draggingClass` and `delayBeforeRemove`.
```Vue
```
--------------------------------
### Vue Horizontal Drag-and-Drop List with Autoscroll
Source: https://fluid-dnd.netlify.app/vue/example/horizontal-list/single-horizontal-list-autoscroll
This Vue component creates a horizontally scrollable and draggable list of Pokemon. It leverages the `useDragAndDrop` composable from `fluid-dnd/vue` to enable drag-and-drop functionality, configured for horizontal movement and applying a `dragging-pokemon` class during drag operations. The component fetches initial Pokemon data and renders each as a `PokemonComponent` within the draggable container.
```Vue
```
--------------------------------
### Configure Delay Before Element Removal (Vue)
Source: https://fluid-dnd.netlify.app/vue/guides/actions/listremove
Explains how to use the `delayBeforeRemove` option in `useDragAndDrop`. This setting controls the duration in milliseconds that an element remains visible with the `removingClass` applied before it is completely removed from the DOM.
```Vue
```