Skip to content

Commit

Permalink
Fix for issue #603
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Desmaisons committed Jun 23, 2019
1 parent d0c98d6 commit 198376c
Show file tree
Hide file tree
Showing 9 changed files with 311 additions and 39 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VUE_APP_SHOW_ALL_EXAMPLES=false
1 change: 1 addition & 0 deletions .env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VUE_APP_SHOW_ALL_EXAMPLES=true
73 changes: 46 additions & 27 deletions example/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div id="app">
<a href="https://github.com/SortableJS/Vue.Draggable" target="_blank">
<a
href="https://github.com/SortableJS/Vue.Draggable"
target="_blank"
>
<img
style="position: fixed; top: 0; right: 0; border: 0; z-index:99999"
width="149"
Expand All @@ -24,51 +27,50 @@
<a
target="_blank"
href="https://circleci.com/gh/SortableJS/Vue.Draggable"
><img
src="https://circleci.com/gh/SortableJS/Vue.Draggable.svg?style=shield"
/>
><img src="https://circleci.com/gh/SortableJS/Vue.Draggable.svg?style=shield" />
</a>
<a
target="_blank"
href="https://codecov.io/gh/SortableJS/Vue.Draggable"
><img
src="https://codecov.io/gh/SortableJS/Vue.Draggable/branch/master/graph/badge.svg"
/>
><img src="https://codecov.io/gh/SortableJS/Vue.Draggable/branch/master/graph/badge.svg" />
</a>
<a
target="_blank"
href="https://codebeat.co/projects/github-com-sortablejs-vue-draggable-master"
><img
src="https://codebeat.co/badges/7a6c27c8-2d0b-47b9-af55-c2eea966e713"
/>
><img src="https://codebeat.co/badges/7a6c27c8-2d0b-47b9-af55-c2eea966e713" />
</a>
<a
target="_blank"
href="https://github.com/SortableJS/Vue.Draggable/issues?q=is%3Aopen+is%3Aissue"
><img
src="https://img.shields.io/github/issues/SortableJS/Vue.Draggable.svg"
/>
><img src="https://img.shields.io/github/issues/SortableJS/Vue.Draggable.svg" />
</a>
<a target="_blank" href="https://www.npmjs.com/package/vuedraggable"
><img src="https://img.shields.io/npm/dt/vuedraggable.svg" />
<a
target="_blank"
href="https://www.npmjs.com/package/vuedraggable"
><img src="https://img.shields.io/npm/dt/vuedraggable.svg" />
</a>
<a target="_blank" href="https://www.npmjs.com/package/vuedraggable"
><img src="https://img.shields.io/npm/dm/vuedraggable.svg" />
<a
target="_blank"
href="https://www.npmjs.com/package/vuedraggable"
><img src="https://img.shields.io/npm/dm/vuedraggable.svg" />
</a>
<a target="_blank" href="https://www.npmjs.com/package/vuedraggable"
><img src="https://img.shields.io/npm/v/vuedraggable.svg" />
<a
target="_blank"
href="https://www.npmjs.com/package/vuedraggable"
><img src="https://img.shields.io/npm/v/vuedraggable.svg" />
</a>
<a
target="_blank"
href="https://github.com/SortableJS/Vue.Draggable/blob/master/LICENSE"
><img
src="https://img.shields.io/github/license/SortableJS/Vue.Draggable.svg"
/>
><img src="https://img.shields.io/github/license/SortableJS/Vue.Draggable.svg" />
</a>
</div>
</div>

<ul class="nav nav-tabs" role="tablist">
<ul
class="nav nav-tabs"
role="tablist"
>
<li
class="nav-item"
v-for="component in componentList"
Expand All @@ -81,12 +83,14 @@
:href="`#${component.name}`"
role="tab"
aria-controls="profile"
>{{ component.display }}</a
>
>{{ component.display }}</a>
</li>
</ul>

<div class="tab-content" id="tab-content">
<div
class="tab-content"
id="tab-content"
>
<div
class="tab-pane show"
:id="component.name"
Expand Down Expand Up @@ -127,13 +131,28 @@
import $ from "jquery";
const requireContext = require.context("./components/", false, /\.vue$/);
const components = requireContext.keys().reduce((acc, key) => {
const component = requireContext(key).default;
acc[component.name] = component;
return acc;
}, {});
const showAll = process.env.VUE_APP_SHOW_ALL_EXAMPLES === "true";
if (showAll) {
const order = Object.keys(components);
const requireContextDebug = require.context(
"./debug-components/",
false,
/\.vue$/
);
requireContextDebug.keys().reduce((acc, key) => {
const component = requireContextDebug(key).default;
component.order += order;
acc[component.name] = component;
return acc;
}, components);
}
export default {
name: "app",
components,
Expand Down
68 changes: 68 additions & 0 deletions example/components/nested/draggable-list.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>

<draggable
:list="list"
:disabled="!enabled"
class="list-group"
ghost-class="ghost"
:move="checkMove"
@start="dragging = true"
@end="dragging = false"
>
<div
class="list-group-item"
v-for="element in list"
:key="element.name"
>
{{ element.name }}
</div>
</draggable>
</template>

<script>
import draggable from "@/vuedraggable";
let id = 1;
export default {
name: "draggable-list",
components: {
draggable
},
props: {
list: {
type: Array,
required: true
},
enabled: {
type: Boolean,
required: true
}
},
data() {
return {
dragging: false
};
},
computed: {
draggingInfo() {
return this.dragging ? "under drag" : "";
}
},
methods: {
add: function() {
this.list.push({ name: "Juan " + id, id: id++ });
},
replace: function() {
this.list = [{ name: "Edgard", id: id++ }];
},
checkMove: function(e) {
window.console.log("Future index: " + e.draggedContext.futureIndex);
}
}
};
</script>
<style scoped>
.ghost {
opacity: 0.5;
background: #c8ebfb;
}
</style>
25 changes: 21 additions & 4 deletions example/components/simple.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,14 @@
role="group"
aria-label="Basic example"
>
<button class="btn btn-secondary" @click="add">Add</button>
<button class="btn btn-secondary" @click="replace">Replace</button>
<button
class="btn btn-secondary"
@click="add"
>Add</button>
<button
class="btn btn-secondary"
@click="replace"
>Replace</button>
</div>

<div class="form-check">
Expand All @@ -18,7 +24,10 @@
v-model="enabled"
class="form-check-input"
/>
<label class="form-check-label" for="disabled">DnD enabled</label>
<label
class="form-check-label"
for="disabled"
>DnD enabled</label>
</div>
</div>
</div>
Expand All @@ -31,6 +40,7 @@
:disabled="!enabled"
class="list-group"
ghost-class="ghost"
:move="checkMove"
@start="dragging = true"
@end="dragging = false"
>
Expand All @@ -44,7 +54,11 @@
</draggable>
</div>

<rawDisplayer class="col-3" :value="list" title="List" />
<rawDisplayer
class="col-3"
:value="list"
title="List"
/>
</div>
</template>

Expand Down Expand Up @@ -80,6 +94,9 @@ export default {
},
replace: function() {
this.list = [{ name: "Edgard", id: id++ }];
},
checkMove: function(e) {
window.console.log("Future index: " + e.draggedContext.futureIndex);
}
}
};
Expand Down
68 changes: 68 additions & 0 deletions example/debug-components/nested/draggable-list.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>

<draggable
:list="list"
:disabled="!enabled"
class="list-group"
ghost-class="ghost"
:move="checkMove"
@start="dragging = true"
@end="dragging = false"
>
<div
class="list-group-item"
v-for="element in list"
:key="element.name"
>
{{ element.name }}
</div>
</draggable>
</template>

<script>
import draggable from "@/vuedraggable";
let id = 1;
export default {
name: "draggable-list",
components: {
draggable
},
props: {
list: {
type: Array,
required: true
},
enabled: {
type: Boolean,
required: true
}
},
data() {
return {
dragging: false
};
},
computed: {
draggingInfo() {
return this.dragging ? "under drag" : "";
}
},
methods: {
add: function() {
this.list.push({ name: "Juan " + id, id: id++ });
},
replace: function() {
this.list = [{ name: "Edgard", id: id++ }];
},
checkMove: function(e) {
window.console.log("Future index: " + e.draggedContext.futureIndex);
}
}
};
</script>
<style scoped>
.ghost {
opacity: 0.5;
background: #c8ebfb;
}
</style>
Loading

0 comments on commit 198376c

Please sign in to comment.