|
1 |
| -# Vue 3 + TypeScript + Vite |
| 1 | +# SortableJS-vue3 |
2 | 2 |
|
3 |
| -This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more. |
| 3 | +This is a thin wrapper around the great [SortableJS](https://github.com/SortableJS/Sortable) library. I had many issues migration from Vue.Draggable to vue.draggable.next, and after briefly investigating I decided that it was too complicated and a smaller solution was the answer. This wrapper tries to keep you as close to Sortable and vanilla JS as possible. |
4 | 4 |
|
5 |
| -## Recommended IDE Setup |
| 5 | +## Usage |
| 6 | +1. `yarn add sortablejs-vue3 sortablejs` or `npm install sortablejs-vue3 sortablejs` |
| 7 | +2. Import the component in your `<script setup>`: `import { Sortable } from 'sortablejs-vue'` |
| 8 | +3. Use the component: |
6 | 9 |
|
7 |
| -- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) |
| 10 | +```typescript |
| 11 | +<template> |
| 12 | + <main> |
| 13 | + <Sortable |
| 14 | + :list="elements" |
| 15 | + item-key="id" |
| 16 | + :options="options" |
| 17 | + @change="logEvent" |
| 18 | + @choose="logEvent" |
| 19 | + @unchoose="logEvent" |
| 20 | + @start="logEvent" |
| 21 | + @end="logEvent" |
| 22 | + @add="logEvent" |
| 23 | + @update="logEvent" |
| 24 | + @sort="logEvent" |
| 25 | + @remove="logEvent" |
| 26 | + @filter="logEvent" |
| 27 | + @move="logEvent" |
| 28 | + @clone="logEvent" |
| 29 | + > |
| 30 | + <template #item="{element, index}"> |
| 31 | + <div class="draggable" :key="element.id"> |
| 32 | + {{ element.name }} |
| 33 | + </div> |
| 34 | + </template> |
| 35 | + </Sortable> |
| 36 | +</template> |
| 37 | +``` |
8 | 38 |
|
9 |
| -## Type Support For `.vue` Imports in TS |
| 39 | +4. The `list` and `item-key` props are necessary. The `options` prop is an object that can contain any SortableJS option. You can find a full list of them here: https://github.com/SortableJS/Sortable#options |
10 | 40 |
|
11 |
| -Since TypeScript cannot handle type information for `.vue` imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in `.vue` imports (for example to get props validation when using manual `h(...)` calls), you can enable Volar's Take Over mode by following these steps: |
| 41 | +## Development |
| 42 | +1. Run `yarn` |
| 43 | +2. `yarn dev` will start a web server with live reloading |
| 44 | +3. `yarn build` will build the production files |
12 | 45 |
|
13 |
| -1. Run `Extensions: Show Built-in Extensions` from VS Code's command palette, look for `TypeScript and JavaScript Language Features`, then right click and select `Disable (Workspace)`. By default, Take Over mode will enable itself if the default TypeScript extension is disabled. |
14 |
| -2. Reload the VS Code window by running `Developer: Reload Window` from the command palette. |
| 46 | +### Recommended IDE Setup |
15 | 47 |
|
16 |
| -You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471). |
| 48 | +- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar) |
0 commit comments