Skip to content

Commit 541cfe0

Browse files
committed
initial commit
0 parents  commit 541cfe0

17 files changed

+1291
-0
lines changed

.gitignore

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
26+
.vercel

.vscode/extensions.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"recommendations": ["Vue.volar"]
3+
}

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Vue 3 + TypeScript + Vite
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.
4+
5+
## Recommended IDE Setup
6+
7+
- [VS Code](https://code.visualstudio.com/) + [Volar](https://marketplace.visualstudio.com/items?itemName=Vue.volar)
8+
9+
## Type Support For `.vue` Imports in TS
10+
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:
12+
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.
15+
16+
You can learn more about Take Over mode [here](https://github.com/johnsoncodehk/volar/discussions/471).

index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<link rel="icon" href="/favicon.ico" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Vite App</title>
8+
</head>
9+
<body>
10+
<div id="app"></div>
11+
<script type="module" src="/src/main.ts"></script>
12+
</body>
13+
</html>

lib/main.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export {default as Sortable} from '../src/components/Sortable.vue';

package.json

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "sortablejs-vue3",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"dev": "vite",
7+
"build": "vue-tsc --noEmit && vite build",
8+
"preview": "vite preview"
9+
},
10+
"types": "./dist/lib/main.d.ts",
11+
"files": [
12+
"dist"
13+
],
14+
"main": "./dist/sortablejs-vue3.umd.js",
15+
"module": "./dist/sortablejs-vue3.es.js",
16+
"exports": {
17+
".": {
18+
"import": "./dist/sortablejs-vue3.es.js",
19+
"require": "./dist/sortablejs-vue3.umd.js"
20+
}
21+
},
22+
"dependencies": {
23+
"sortablejs": "^1.15.0",
24+
"vue": "^3.2.25"
25+
},
26+
"devDependencies": {
27+
"@types/node": "^17.0.40",
28+
"@types/sortablejs": "^1.13.0",
29+
"@vitejs/plugin-vue": "^2.3.3",
30+
"rollup-plugin-typescript2": "0.31.2",
31+
"typescript": "^4.5.4",
32+
"vite": "^2.9.9",
33+
"vue-tsc": "^0.36.1"
34+
}
35+
}

public/favicon.ico

4.19 KB
Binary file not shown.

src/App.vue

+269
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
<script setup lang="ts">
2+
// This starter template is using Vue 3 <script setup> SFCs
3+
// Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
4+
import HelloWorld from "./components/HelloWorld.vue";
5+
</script>
6+
7+
<template>
8+
<h1>SortableJS-vue3 demo</h1>
9+
<ol class="instructions">
10+
<li>First run <code>yarn add sortablejs-vue3 sortablejs</code></li>
11+
<li>
12+
Then add
13+
<pre><code>import Sortable from "sortablejs-vue3"</code></pre>
14+
in your <code>&lt;script setup&gt;</code>
15+
</li>
16+
<li>
17+
Finally use the component:
18+
<pre>
19+
{{ `<Sortable
20+
:list="list"
21+
:itemKey="itemKey"
22+
options="options"
23+
@choose="(event) => console.log(event)"
24+
@end="(event) => console.log(event)">
25+
<template #item="{element, index}">
26+
<div class="draggable" :key="element.id">
27+
&#123;&#123; element.name &#125;&#125;
28+
</div>
29+
</template>
30+
</Sortable>` }}
31+
</pre>
32+
</li>
33+
</ol>
34+
<details>
35+
<summary>Props</summary>
36+
<ul>
37+
<li>
38+
<strong><code>options</code></strong
39+
>: An object supporting all SortedJS options. See Sortable on GitHub
40+
<a
41+
href="https://github.com/SortableJS/Sortable#options"
42+
rel="noreferrer"
43+
target="_blank"
44+
>for a full list</a
45+
>.
46+
</li>
47+
<li>
48+
<strong><code>list</code></strong
49+
>: An array-like object of elements to be made draggable.
50+
</li>
51+
<li>
52+
<strong><code>itemKey</code></strong
53+
>: A key to index the elements of the list.
54+
</li>
55+
</ul>
56+
</details>
57+
<details>
58+
<summary>Code for the below demo</summary>
59+
<pre>
60+
{{ `<script setup lang="ts">
61+
import Sortable from "./Sortable.vue";
62+
import { computed } from 'vue'
63+
import type { SortableOptions } from "sortablejs";
64+
65+
const elements = computed(() => {
66+
return [
67+
{
68+
id: '1',
69+
text: 'One',
70+
children: [
71+
{
72+
id: '1-1',
73+
text: 'One-One',
74+
children: [
75+
{
76+
id: '1-1-1',
77+
text: 'One-One-One',
78+
},
79+
{
80+
id: '1-1-2',
81+
text: 'One-One-Two',
82+
},
83+
],
84+
},
85+
{
86+
id: '1-2',
87+
text: 'One-Two',
88+
},
89+
],
90+
},
91+
{
92+
id: '2',
93+
text: 'Two'
94+
},
95+
{
96+
id: '3',
97+
text: 'Three'
98+
}
99+
]
100+
})
101+
102+
const logEvent = (evt: Event, evt2?: Event) => {
103+
if (evt2) {
104+
console.log(evt, evt2);
105+
} else {
106+
console.log(evt);
107+
}
108+
}
109+
110+
const options = computed(() => {
111+
return {
112+
draggable: '.draggable',
113+
animation: 150,
114+
ghostClass: 'ghost',
115+
dragClass: 'drag',
116+
} as SortableOptions
117+
})
118+
</script>
119+
120+
<style lang="css" scoped>
121+
main {
122+
max-width: 800px;
123+
margin: 0 auto;
124+
}
125+
126+
.draggable {
127+
background: #fff;
128+
padding: 10px;
129+
margin: 10px;
130+
border: 1px solid #ccc;
131+
cursor: move;
132+
}
133+
134+
.ghost {
135+
opacity: 0.5;
136+
background: #fff;
137+
border: 1px dashed #ccc;
138+
}
139+
140+
.drag {
141+
background: #f5f5f5;
142+
}
143+
</style>
144+
145+
<template>
146+
<main>
147+
<Sortable
148+
:list="elements"
149+
item-key="id"
150+
:options="options"
151+
@change="logEvent"
152+
@choose="logEvent"
153+
@unchoose="logEvent"
154+
@start="logEvent"
155+
@end="logEvent"
156+
@add="logEvent"
157+
@update="logEvent"
158+
@sort="logEvent"
159+
@remove="logEvent"
160+
@filter="logEvent"
161+
@move="logEvent"
162+
@clone="logEvent"
163+
>
164+
<template #item="{element, index}">
165+
<div class="draggable" :key="element.id">
166+
&#123;&#123; element.text &#125;&#125;
167+
<Sortable
168+
v-if="element.children"
169+
:list="element.children"
170+
item-key="id"
171+
:options="options"
172+
@change="logEvent"
173+
@choose="logEvent"
174+
@unchoose="logEvent"
175+
@start="logEvent"
176+
@end="logEvent"
177+
@add="logEvent"
178+
@update="logEvent"
179+
@sort="logEvent"
180+
@remove="logEvent"
181+
@filter="logEvent"
182+
@move="logEvent"
183+
@clone="logEvent"
184+
>
185+
<template #item="{element, index}">
186+
<div class="draggable" :key="element.id">
187+
&#123;&#123; element.text &#125;&#125;
188+
</div>
189+
</template>
190+
</Sortable>
191+
</div>
192+
</template>
193+
</Sortable>
194+
</main>
195+
</template>
196+
197+
<style scoped>
198+
199+
</style>
200+
`}}
201+
</pre>
202+
</details>
203+
<p>
204+
Open your console to view the events being logged while you interact with
205+
the list below.
206+
</p>
207+
208+
<HelloWorld />
209+
</template>
210+
211+
<style>
212+
#app {
213+
font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
214+
Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
215+
-webkit-font-smoothing: antialiased;
216+
-moz-osx-font-smoothing: grayscale;
217+
color: #2c3e50;
218+
margin: 0 auto;
219+
max-width: 800px;
220+
}
221+
222+
#app .instructions {
223+
font-size: 1.1rem;
224+
}
225+
226+
#app .instructions code {
227+
font-size: .9rem;
228+
}
229+
230+
#app .instructions li {
231+
margin-bottom: .5rem;
232+
}
233+
234+
#app details {
235+
margin: 20px 0;
236+
max-width: 800px;
237+
padding: 8px 10px;
238+
background: #f5f5f5;
239+
border: 1px solid #ccc;
240+
border-radius: 4px;
241+
cursor: pointer;
242+
}
243+
244+
#app pre {
245+
font-size: 14px;
246+
padding: 10px;
247+
margin: 0 auto;
248+
max-width: 800px;
249+
text-align: left;
250+
overflow-x: scroll;
251+
max-height: 500px;
252+
}
253+
254+
#app ul {
255+
list-style: none;
256+
padding: 0;
257+
text-align: left;
258+
max-width: 800px;
259+
margin: 8px auto;
260+
}
261+
262+
#app .draggable {
263+
border-radius: 4px;
264+
}
265+
266+
#app summary::after {
267+
content: " (click to expand)";
268+
}
269+
</style>

src/assets/logo.png

6.69 KB
Loading

0 commit comments

Comments
 (0)