Skip to content

Commit

Permalink
Add and run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxLeiter committed Jul 28, 2022
1 parent 63f18a7 commit 7f2c70b
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 200 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '16'
registry-url: 'https://registry.npmjs.org'
node-version: "16"
registry-url: "https://registry.npmjs.org"
- run: yarn
- run: yarn build
- run: yarn publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
20 changes: 20 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

.vercel

# Custom
sortablejs-*.tgz
1 change: 1 addition & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,25 @@ Note that this library is small enough (see [Sortable.vue](https://github.com/Ma
- `shopify/draggable` and [`vue-shopify-dragable`](https://github.com/zjffun/vue-shopify-draggable) seemed promising but they don't supported nested components

## Usage

You can see a demo with more complete code at [https://sortablejs-vue3.maxleiter.com](https://sortablejs-vue3.maxleiter.com).

1. Install the package:

```bash
yarn add sortablejs-vue3 sortablejs
```
```bash
yarn add sortablejs-vue3 sortablejs
```

or
or

```bash
npm install sortablejs-vue3 sortablejs
```
```bash
npm install sortablejs-vue3 sortablejs
```

2. Import the component in your `<script setup>` (or `<script>`):

```typescript
import { Sortable } from 'sortablejs-vue3'
import { Sortable } from "sortablejs-vue3";
```

3. Use the component:
Expand Down Expand Up @@ -59,6 +61,7 @@ import { Sortable } from 'sortablejs-vue3'
5. The `tag` prop is an optional prop, it's the HTML node type of the element that creates an outer element for the included slot. the default value is `div`

### Events

You can listen to Sortable events by adding the listeners to the `Sortable` component. For example:

```typescript
Expand All @@ -81,6 +84,7 @@ You can listen to Sortable events by adding the listeners to the `Sortable` comp
```

### Vuex

No changes are necessary to work with Vuex. Just pass `store.state.item` as your list. To modify your data you need to manually listen to the events and calculate the new position with `event.oldIndex` and `event.newIndex` with something like the following:

```typescript
Expand All @@ -91,7 +95,9 @@ const moveItemInArray = <T>(array: T[], from: number, to: number) => {

onEnd(event) { moveItemInArray(store.state.items, event.oldIndex, event.newIndex) }
```

## Development

1. Run `yarn` to install dependencies
2. `yarn dev` will start a web server with live reloading
3. `yarn build` will build the production library files
Expand Down
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
<title>sortablejs-vue3</title>

<!-- SEO -->
<meta name="description" content="sortablejs-vue3 - A Vue 3 wrapper for SortableJS written in TypeScript." />
<meta
name="description"
content="sortablejs-vue3 - A Vue 3 wrapper for SortableJS written in TypeScript."
/>
<meta name="robots" content="index, follow" />
</head>
<body>
Expand Down
4 changes: 2 additions & 2 deletions lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import Sortable from '../src/components/Sortable.vue'
import Sortable from "../src/components/Sortable.vue";

export { Sortable }
export { Sortable };
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"dev": "vite",
"build": "vite build && vue-tsc --emitDeclarationOnly --project tsconfig.dist.json && mv dist/lib dist/types && rm -rf favicon.ico",
"build:site": "vue-tsc --noEmit --project tsconfig.site.json && vite --config vite.site.config.ts build",
"preview": "vite preview"
"preview": "vite preview",
"lint": "vite lint"
},
"types": "./dist/types/main.d.ts",
"files": [
Expand All @@ -45,6 +46,7 @@
"@types/node": "17.0.40",
"@types/sortablejs": "1.13.0",
"@vitejs/plugin-vue": "2.3.3",
"prettier": "2.7.1",
"typescript": "4.7.4",
"vite": "3.0.0",
"vue-tsc": "0.38.5"
Expand Down
5 changes: 1 addition & 4 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"group:allNonMajor",
"config:base"
]
"extends": ["group:allNonMajor", "config:base"]
}
163 changes: 12 additions & 151 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import HelloWorld from "./components/HelloWorld.vue";

<template>
<h1>SortableJS-vue3 demo</h1>
<h2>Source on <a href="https://github.com/maxleiter/sortablejs-vue3">GitHub</a></h2>
<h2>
Source on <a href="https://github.com/maxleiter/sortablejs-vue3">GitHub</a>
</h2>
<ol class="instructions">
<li>First run <code>yarn add sortablejs-vue3 sortablejs</code></li>
<li>
Expand Down Expand Up @@ -55,153 +57,6 @@ import HelloWorld from "./components/HelloWorld.vue";
</li>
</ul>
</details>
<details>
<summary>Code for the below demo</summary>
<aside>Also available on <a href="https://github.com/MaxLeiter/sortablejs-vue3/blob/main/src/components/HelloWorld.vue">GitHub</a></aside>
<pre>
{{ `<script setup lang="ts">
import Sortable from "./Sortable.vue";
import { computed } from 'vue'
import type { SortableOptions } from "sortablejs";
const elements = computed(() => {
return [
{
id: '1',
text: 'One',
children: [
{
id: '1-1',
text: 'One-One',
children: [
{
id: '1-1-1',
text: 'One-One-One',
},
{
id: '1-1-2',
text: 'One-One-Two',
},
],
},
{
id: '1-2',
text: 'One-Two',
},
],
},
{
id: '2',
text: 'Two'
},
{
id: '3',
text: 'Three'
}
]
})
const logEvent = (evt: Event, evt2?: Event) => {
if (evt2) {
console.log(evt, evt2);
} else {
console.log(evt);
}
}
const options = computed(() => {
return {
draggable: '.draggable',
animation: 150,
ghostClass: 'ghost',
dragClass: 'drag',
} as SortableOptions
})
</script>

<style lang="css" scoped>
main {
max-width: 800px;
margin: 0 auto;
}
.draggable {
background: #fff;
padding: 10px;
margin: 10px;
border: 1px solid #ccc;
cursor: move;
}
.ghost {
opacity: 0.5;
background: #fff;
border: 1px dashed #ccc;
}
.drag {
background: #f5f5f5;
}
</style>

<template>
<main>
<Sortable
:list="elements"
item-key="id"
:options="options"
@change="logEvent"
@choose="logEvent"
@unchoose="logEvent"
@start="logEvent"
@end="logEvent"
@add="logEvent"
@update="logEvent"
@sort="logEvent"
@remove="logEvent"
@filter="logEvent"
@move="logEvent"
@clone="logEvent"
>
<template #item="{element, index}">
<div class="draggable" :key="element.id">
&#123;&#123; element.text &#125;&#125;
<Sortable
v-if="element.children"
:list="element.children"
item-key="id"
:options="options"
@change="logEvent"
@choose="logEvent"
@unchoose="logEvent"
@start="logEvent"
@end="logEvent"
@add="logEvent"
@update="logEvent"
@sort="logEvent"
@remove="logEvent"
@filter="logEvent"
@move="logEvent"
@clone="logEvent"
>
<template #item="{element, index}">
<div class="draggable" :key="element.id">
&#123;&#123; element.text &#125;&#125;
</div>
</template>
</Sortable>
</div>
</template>
</Sortable>
</main>
</template>

<style scoped>
</style>
`}}
</pre>
</details>
<p>
Open your console to view the events being logged while you interact with
the list below.
Expand All @@ -210,7 +65,13 @@ main {
<HelloWorld />
<footer>
<p>
Made by <a href="https://twitter.com/max_leiter">@Max_Leiter</a>
Made by <a href="https://twitter.com/max_leiter">@Max_Leiter</a> &mdash;
Code for this page is available on
<a
href="https://github.com/MaxLeiter/sortablejs-vue3/blob/main/src/components/HelloWorld.vue"
>
GitHub
</a>
</p>
</footer>
</template>
Expand Down Expand Up @@ -247,7 +108,7 @@ main {
}
#app .instructions code {
font-size: .9rem;
font-size: 0.9rem;
}
#app .instructions li {
Expand Down Expand Up @@ -308,7 +169,7 @@ main {
}
#app a:after {
content: '';
content: "";
position: absolute;
width: 100%;
transform: scaleX(0);
Expand Down
3 changes: 0 additions & 3 deletions src/components/Sortable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,6 @@ watch(
if (options && sortable?.value) {
sortable.value.options = { ...sortable.value.options, ...options };
}
},
{
deep: true,
}
);
Expand Down
8 changes: 4 additions & 4 deletions src/env.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// <reference types="vite/client" />

declare module '*.vue' {
import type { DefineComponent } from 'vue'
declare module "*.vue" {
import type { DefineComponent } from "vue";
// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
const component: DefineComponent<{}, {}, any>
export default component
const component: DefineComponent<{}, {}, any>;
export default component;
}
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'
import { createApp } from "vue";
import App from "./App.vue";

createApp(App).mount('#app')
createApp(App).mount("#app");
Loading

1 comment on commit 7f2c70b

@vercel
Copy link

@vercel vercel bot commented on 7f2c70b Jul 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.