Skip to content

Commit 2308b2d

Browse files
authored
chore: use vue-demi for backward compat with vue2 (#70)
* chore: use vue-demi for backward compat with vue2 * chore: set vue-demi version * docs: add vue 2 support section
1 parent a0856c4 commit 2308b2d

File tree

7 files changed

+40
-6
lines changed

7 files changed

+40
-6
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
![GIF of the demo being used](./readme/demo.gif)
66

7-
This is a thin wrapper around the great [SortableJS](https://github.com/SortableJS/Sortable) library. I had many issues migrating 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 attempts to keep you as close to Sortable as possible.
7+
This is a thin wrapper around the great [SortableJS](https://github.com/SortableJS/Sortable) library for Vue 2 & 3. I had many issues migrating 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 attempts to keep you as close to Sortable as possible.
88

99
### Why not use \<other library\>?
1010

@@ -124,6 +124,14 @@ onEnd(event) { moveItemInArray(store.state.items, event.oldIndex, event.newIndex
124124

125125
You may also want to see the SortableJS store documentation [here](https://github.com/SortableJS/Sortable#store).
126126

127+
## Vue 2 support
128+
129+
If you are using version prior to `[email protected]`, `@vue/composition-api` is required to be installed to use SortableJS-vue3 with Vue 2.
130+
131+
Everything else should be similar to the example above for Vue 3.
132+
133+
Under the hood, we use [Vue Demi](https://github.com/vueuse/vue-demi) a tool that allows us to write Universal Vue Libraries for Vue 2 & 3.
134+
127135
## Development
128136

129137
1. Run `yarn` to install dependencies

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,17 @@
3636
},
3737
"dependencies": {
3838
"sortablejs": "^1.15.0",
39-
"vue": "^3.2.37"
39+
"vue": "^3.2.37",
40+
"vue-demi": "^0.13.11"
4041
},
4142
"peerDependencies": {
4243
"sortablejs": "^1.15.0",
43-
"vue": "^3.2.25"
44+
"vue": "^2.0.0 || >=3.0.0"
45+
},
46+
"peerDependenciesMeta": {
47+
"@vue/composition-api": {
48+
"optional": true
49+
}
4450
},
4551
"devDependencies": {
4652
"@types/node": "18.11.18",

pnpm-lock.yaml

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/HelloWorld.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import Sortable from "./Sortable.vue";
3-
import { computed, ref } from "vue";
3+
import { computed, ref } from "vue-demi";
44
import type { SortableOptions } from "sortablejs";
55
import type { AutoScrollOptions } from "sortablejs/plugins";
66

src/components/Sortable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, PropType, watch, onUnmounted, computed, useAttrs, Ref } from "vue";
2+
import { ref, PropType, watch, onUnmounted, computed, useAttrs, Ref } from "vue-demi";
33
import Sortable, { SortableOptions } from "sortablejs";
44
import type { AutoScrollOptions } from "sortablejs/plugins";
55

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createApp } from "vue";
1+
import { createApp } from "vue-demi";
22
import App from "./App.vue";
33

44
createApp(App).mount("#app");

vite.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ export default defineConfig({
1010
preserveSymlinks: false,
1111
},
1212
logLevel: "info",
13+
optimizeDeps: {
14+
exclude: ['vue-demi']
15+
},
1316
build: {
1417
target: "esnext",
1518
minify: "terser",

0 commit comments

Comments
 (0)