Skip to content

Commit b330f58

Browse files
based on issue #90: allow v-model usage
1 parent 29b7f0a commit b330f58

File tree

8 files changed

+489
-158
lines changed

8 files changed

+489
-158
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
],
2626
"dependencies": {
2727
"vue": "^2.0.2",
28-
"Sortable": "^1.5.0-rc1"
28+
"Sortable": "^1.5.1"
2929
}
3030
}

debug.log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[0304/225158:ERROR:tcp_listen_socket.cc(76)] Could not bind socket to 127.0.0.1:6004
2+
[0304/225158:ERROR:node_debugger.cc(86)] Cannot start debugger server

dist/vuedraggable.js

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
4040
var _this = this;
4141

4242
return function (evtData) {
43-
if (_this.list !== null) {
43+
if (_this.realList !== null) {
4444
_this['onDrag' + evtName](evtData);
4545
}
4646
emit.call(_this, evtName, evtData);
@@ -61,6 +61,11 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
6161
required: false,
6262
default: null
6363
},
64+
value: {
65+
type: Array,
66+
required: false,
67+
default: null
68+
},
6469
clone: {
6570
type: Function,
6671
default: function _default(original) {
@@ -123,6 +128,9 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
123128
},
124129
isCloning: function isCloning() {
125130
return !!this.options && this.options.group !== null && this.options.group.pull === 'clone';
131+
},
132+
realList: function realList() {
133+
return !!this.list ? this.list : this.value;
126134
}
127135
},
128136

@@ -134,7 +142,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
134142
}
135143
}
136144
},
137-
list: function list() {
145+
realList: function realList() {
138146
this.computeIndexes();
139147
}
140148
},
@@ -153,7 +161,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
153161
},
154162
getUnderlyingVm: function getUnderlyingVm(htmlElt) {
155163
var index = computeVmIndex(this.getChildrenNodes(), htmlElt);
156-
var element = this.list[index];
164+
var element = this.realList[index];
157165
return { index: index, element: element };
158166
},
159167
getUnderlyingPotencialDraggableComponent: function getUnderlyingPotencialDraggableComponent(_ref) {
@@ -171,23 +179,38 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
171179
_this4.$emit('change', evt);
172180
});
173181
},
182+
alterList: function alterList(onList) {
183+
if (!!this.list) {
184+
onList(this.list);
185+
} else {
186+
var newList = [].concat(_toConsumableArray(this.value));
187+
onList(newList);
188+
this.$emit('input', newList);
189+
}
190+
},
174191
spliceList: function spliceList() {
175-
var _list;
192+
var _arguments = arguments;
176193

177-
(_list = this.list).splice.apply(_list, arguments);
194+
var spliceList = function spliceList(list) {
195+
return list.splice.apply(list, _arguments);
196+
};
197+
this.alterList(spliceList);
178198
},
179199
updatePosition: function updatePosition(oldIndex, newIndex) {
180-
this.list.splice(newIndex, 0, this.list.splice(oldIndex, 1)[0]);
200+
var updatePosition = function updatePosition(list) {
201+
return list.splice(newIndex, 0, list.splice(oldIndex, 1)[0]);
202+
};
203+
this.alterList(updatePosition);
181204
},
182205
getRelatedContextFromMoveEvent: function getRelatedContextFromMoveEvent(_ref2) {
183-
var to = _ref2.to,
184-
related = _ref2.related;
206+
var to = _ref2.to;
207+
var related = _ref2.related;
185208

186209
var component = this.getUnderlyingPotencialDraggableComponent(to);
187210
if (!component) {
188211
return { component: component };
189212
}
190-
var list = component.list;
213+
var list = component.realList;
191214
var context = { list: list, component: component };
192215
if (to !== related && list && component.getUnderlyingVm) {
193216
var destination = component.getUnderlyingVm(related);
@@ -250,7 +273,7 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr
250273
},
251274
onDragMove: function onDragMove(evt) {
252275
var onMove = this.move;
253-
if (!onMove || !this.list) {
276+
if (!onMove || !this.realList) {
254277
return true;
255278
}
256279

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/Two_Lists_v_model.html

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!doctype html>
2+
<html class="no-js" lang="">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="x-ua-compatible" content="ie=edge">
6+
<title>Example two lists</title>
7+
<meta name="description" content="">
8+
<meta name="viewport" content="width=device-width, initial-scale=1">
9+
10+
<link rel="stylesheet" href="css/main.css">
11+
</head>
12+
<body>
13+
14+
<div id="main">
15+
<h1>Vue Dragable</h1>
16+
17+
<div class="drag">
18+
<h2>List 1 draggable</h2>
19+
<draggable class="dragArea" v-model="list1" :options="{group:'people'}" @change="log">
20+
<div v-for="(element, index) in list1" >
21+
{{element.name}} {{index}}
22+
</div>
23+
</draggable>
24+
25+
<h2>List 2 draggable</h2>
26+
<draggable class="dragArea" v-model="list2" :options="{group:'people'}" @change="log">
27+
<div v-for="(element, index) in list2" :key="index">{{element.name}}</div>
28+
</draggable>
29+
</div>
30+
31+
<div class="normal">
32+
<h2>List 1 v-for</h2>
33+
<div>
34+
<div v-for="element in list1" >{{element.name}}</div>
35+
</div>
36+
37+
<h2>List 2 v-for</h2>
38+
<div>
39+
<div v-for="element in list2" >{{element.name}}</div>
40+
</div>
41+
</div>
42+
43+
<a href="index.html">See basic example</a>
44+
<a href="Two_Lists_Clone.html">See clone element example</a>
45+
<a href="Two_Lists_Clone_If.html">See clone v-if element example</a>
46+
</div>
47+
<script type="text/javascript" src="libs\vue\dist\vue.js"></script>
48+
<script type="text/javascript" src="libs\Sortable\Sortable.js"></script>
49+
<script type="text/javascript" src="src\vuedraggable.js"></script>
50+
<script type="text/javascript" src="script\complex.js"></script>
51+
</body>
52+
</html>

0 commit comments

Comments
 (0)