Skip to content

Commit 68d022c

Browse files
Toward a solution for issue #118
1 parent 4729bb0 commit 68d022c

File tree

6 files changed

+52
-7
lines changed

6 files changed

+52
-7
lines changed

dist/vuedraggable.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
4+
35
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
46

57
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
@@ -77,6 +79,10 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
7779
required: false,
7880
default: null
7981
},
82+
noTransitionOnDrag: {
83+
type: Boolean,
84+
default: false
85+
},
8086
clone: {
8187
type: Function,
8288
default: function _default(original) {
@@ -243,6 +249,20 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
243249
var numberIndexes = indexes.length;
244250
return domIndex > numberIndexes - 1 ? numberIndexes : indexes[domIndex];
245251
},
252+
getComponent: function getComponent() {
253+
return this.$slots.default[0].componentInstance;
254+
},
255+
resetTransitionData: function resetTransitionData(index) {
256+
if (!this.noTransitionOnDrag || !this.transitionMode) {
257+
return;
258+
}
259+
var nodes = this.getChildrenNodes();
260+
nodes[index].data = null;
261+
var transitionContainer = this.getComponent();
262+
var oldChildren = transitionContainer.children;
263+
transitionContainer.children = [];
264+
transitionContainer.kept = undefined;
265+
},
246266
onDragStart: function onDragStart(evt) {
247267
this.context = this.getUnderlyingVm(evt.item);
248268
evt.item._underlying_vm_ = this.clone(this.context.element);
@@ -269,6 +289,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
269289
var oldIndex = this.context.index;
270290
this.spliceList(oldIndex, 1);
271291
var removed = { element: this.context.element, oldIndex: oldIndex };
292+
this.resetTransitionData(oldIndex);
272293
this.emitChanges({ removed: removed });
273294
},
274295
onDragUpdate: function onDragUpdate(evt) {
@@ -312,7 +333,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
312333
return draggableComponent;
313334
}
314335

315-
if (typeof exports == "object") {
336+
if ((typeof exports === 'undefined' ? 'undefined' : _typeof(exports)) == "object") {
316337
var Sortable = require("sortablejs");
317338
module.exports = buildDraggable(Sortable);
318339
} else if (typeof define == "function" && define.amd) {

dist/vuedraggable.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/Transition_example_2.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<div id="main">
1717
<div class="container-fluid machine-contents">
18-
<draggable :list="jobs" :options="{animation:150}" :no-default-animation-on-drag="true" @start="drag=true" @end="drag=false">
18+
<draggable :list="jobs" :options="{animation:150}" :no-transition-on-drag="true" @start="drag=true" @end="drag=false">
1919
<transition-group :name="!drag? 'list-complete' : null" :class="{'no' : drag}" :css="true">
2020
<div v-for="(job, index) in jobs" :key="job.jobNumber" :class="drag? 'item' : 'list-complete-item'">
2121
<div>

examples/Transition_example_3.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<div id="areas">
1818
<div id="columns">
1919
<div class="container-fluid machine-contents list">
20-
<draggable :list="jobs" :options="{group:'a', animation:150}" :no-default-animation-on-drag="true" @start="drag=true" @end="drag=false">
20+
<draggable :list="jobs" :options="{group:'a', animation:150}" :no-transition-on-drag="true" @start="drag=true" @end="drag=false">
2121
<transition-group :name="!drag? 'list-complete' : null" :class="{'no' : drag}" :css="true">
2222
<div v-for="(job, index) in jobs" :key="job.jobNumber" :class="drag? 'item' : 'list-complete-item'">
2323
<div>
@@ -33,7 +33,7 @@
3333
</div>
3434

3535
<div class="container-fluid machine-contents list">
36-
<draggable :list="jobs2" :options="{group:'a', animation:150}" :no-default-animation-on-drag="true" @start="drag=true" @end="drag=false">
36+
<draggable v-model="jobs2" :options="{group:'a', animation:150}" :no-transition-on-drag="true" @start="drag=true" @end="drag=false">
3737
<transition-group :name="!drag? 'list-complete' : null" :class="{'no' : drag}" :css="true">
3838
<div v-for="(job, index) in jobs2" :key="job.jobNumber" :class="drag? 'item' : 'list-complete-item'">
3939
<div>
@@ -50,7 +50,8 @@
5050

5151
</div>
5252
</div>
53-
<button v-on:click="add">Add</button>
53+
<button v-on:click="add">Add list 1</button>
54+
<button v-on:click="add2">Add list 2</button>
5455
</div>
5556
<script type="text/javascript" src="libs\vue\dist\vue.js"></script>
5657
<script type="text/javascript" src="libs\Sortable\Sortable.js"></script>

examples/script/transition3.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ var vm = new Vue({
3131
arr.splice(index, 1);
3232
},
3333
add: function () {
34-
this.jobs.push({jobNumber: "14037-"+ count++})
34+
this.jobs.push({jobNumber: "14022-"+ count++})
35+
},
36+
add2: function () {
37+
this.jobs2.push({jobNumber: "14046-"+ count++})
3538
}
3639
}
3740
})

src/vuedraggable.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@
5757
required: false,
5858
default: null
5959
},
60+
noTransitionOnDrag: {
61+
type: Boolean,
62+
default: false
63+
},
6064
clone: {
6165
type: Function,
6266
default: (original) => { return original; }
@@ -218,6 +222,21 @@
218222
return (domIndex > numberIndexes - 1) ? numberIndexes : indexes[domIndex]
219223
},
220224

225+
getComponent() {
226+
return this.$slots.default[0].componentInstance
227+
},
228+
229+
resetTransitionData(index) {
230+
if (!this.noTransitionOnDrag || !this.transitionMode) {
231+
return
232+
}
233+
var nodes = this.getChildrenNodes()
234+
nodes[index].data = null
235+
const transitionContainer = this.getComponent()
236+
transitionContainer.children = []
237+
transitionContainer.kept = undefined
238+
},
239+
221240
onDragStart(evt) {
222241
this.context = this.getUnderlyingVm(evt.item)
223242
evt.item._underlying_vm_ = this.clone(this.context.element)
@@ -246,6 +265,7 @@
246265
const oldIndex = this.context.index
247266
this.spliceList(oldIndex, 1)
248267
const removed = { element: this.context.element, oldIndex }
268+
this.resetTransitionData(oldIndex)
249269
this.emitChanges({ removed })
250270
},
251271

0 commit comments

Comments
 (0)