Skip to content

Commit 5b40b7f

Browse files
committed
fix: render error when list change
1 parent 1a16a34 commit 5b40b7f

File tree

8 files changed

+38
-34
lines changed

8 files changed

+38
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Root component:
2727
<template slot="item" slot-scope="{ record, index, dataKey }">
2828
<div>
2929
<span class="handle">{{ record.id }}</span>
30-
{{ record.text }}
30+
<p>{{ record.text }}</p>
3131
</div>
3232
</template>
3333
<template slot="header">

dist/virtual-drag-list.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* vue-virtual-drag-list v2.9.6
2+
* vue-virtual-drag-list v2.9.7
33
* open source under the MIT license
44
* https://github.com/mfuu/vue-virtual-drag-list#readme
55
*/
@@ -79,7 +79,8 @@
7979
required: true
8080
},
8181
scroller: {
82-
type: [Document, HTMLElement]
82+
type: [Document, HTMLElement],
83+
"default": undefined
8384
},
8485
direction: {
8586
type: String,
@@ -90,7 +91,8 @@
9091
"default": 30
9192
},
9293
size: {
93-
type: Number
94+
type: Number,
95+
"default": undefined
9496
},
9597
keepOffset: {
9698
type: Boolean,
@@ -113,10 +115,12 @@
113115
"default": true
114116
},
115117
handle: {
116-
type: [Function, String]
118+
type: [Function, String],
119+
"default": undefined
117120
},
118121
group: {
119-
type: [String, Object]
122+
type: [String, Object],
123+
"default": undefined
120124
},
121125
lockAxis: {
122126
type: String,
@@ -206,10 +210,12 @@
206210
};
207211
var ItemProps = {
208212
dataKey: {
209-
type: [String, Number]
213+
type: [String, Number],
214+
"default": undefined
210215
},
211216
sizeKey: {
212-
type: String
217+
type: String,
218+
"default": undefined
213219
}
214220
};
215221

@@ -1069,14 +1075,14 @@
10691075
_classCallCheck(this, Sortable);
10701076
this.el = el;
10711077
this.options = options;
1072-
this.reRendered = false;
1078+
this.rangeChanged = false;
10731079
this.installSortable();
10741080
}
10751081
return _createClass(Sortable, [{
10761082
key: "destroy",
10771083
value: function destroy() {
10781084
this.sortable.destroy();
1079-
this.reRendered = false;
1085+
this.rangeChanged = false;
10801086
}
10811087
}, {
10821088
key: "option",
@@ -1169,13 +1175,13 @@
11691175
this.handleDropEvent(event, params, index);
11701176
}
11711177
this.dispatchEvent('onDrop', params);
1172-
if (event.from === this.el && this.reRendered) {
1178+
if (event.from === this.el && this.rangeChanged) {
11731179
(_b = Dnd.dragged) === null || _b === void 0 ? void 0 : _b.remove();
11741180
}
11751181
if (event.from !== event.to) {
11761182
(_c = Dnd.clone) === null || _c === void 0 ? void 0 : _c.remove();
11771183
}
1178-
this.reRendered = false;
1184+
this.rangeChanged = false;
11791185
}
11801186
}, {
11811187
key: "handleDropEvent",
@@ -1268,8 +1274,7 @@
12681274
start: 0,
12691275
end: 0,
12701276
front: 0,
1271-
behind: 0,
1272-
total: 0
1277+
behind: 0
12731278
};
12741279
this.offset = 0;
12751280
this.direction = 'STATIONARY';
@@ -1436,7 +1441,6 @@
14361441
eventFn(scroller, 'touchmove', this.preventDefault);
14371442
eventFn(scroller, 'keydown', this.preventDefaultForKeyDown);
14381443
}
1439-
// ========================================= Properties =========================================
14401444
}, {
14411445
key: "preventDefault",
14421446
value: function preventDefault(e) {
@@ -1581,16 +1585,8 @@
15811585
this.range.end = this.getEndByStart(start);
15821586
this.range.front = this.getFrontOffset();
15831587
this.range.behind = this.getBehindOffset();
1584-
this.range.total = this.getTotalOffset();
15851588
this.options.onUpdate(Object.assign({}, this.range));
15861589
}
1587-
}, {
1588-
key: "getTotalOffset",
1589-
value: function getTotalOffset() {
1590-
var offset = this.range.front + this.range.behind;
1591-
offset += this.getOffsetByRange(this.range.start, this.range.end + 1);
1592-
return offset;
1593-
}
15941590
}, {
15951591
key: "getFrontOffset",
15961592
value: function getFrontOffset() {
@@ -1846,7 +1842,7 @@
18461842
return;
18471843
}
18481844
var range = Object.assign({}, this.range);
1849-
if (newList.length > oldList.length && this.range.end === oldList.length - 1 && this._scrolledToBottom()) {
1845+
if (oldList.length > this.keeps && newList.length > oldList.length && this.range.end === oldList.length - 1 && this._scrolledToBottom()) {
18501846
range.start++;
18511847
}
18521848
(_a = this.virtualRef) === null || _a === void 0 ? void 0 : _a.updateRange(range);
@@ -1877,7 +1873,7 @@
18771873
var _a;
18781874
var rangeChanged = range.start !== _this4.range.start;
18791875
if (_this4.dragging && rangeChanged) {
1880-
_this4.sortableRef.reRendered = true;
1876+
_this4.sortableRef.rangeChanged = true;
18811877
}
18821878
_this4.range = range;
18831879
(_a = _this4.sortableRef) === null || _a === void 0 ? void 0 : _a.option('range', range);

dist/virtual-drag-list.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/.vuepress/components/group.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export default {
7373
padding: 16px;
7474
height: 50px;
7575
overflow: hidden;
76+
box-sizing: border-box;
7677
}
7778
7879
.item-title {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-virtual-draglist",
3-
"version": "2.9.6",
3+
"version": "2.9.7",
44
"description": "A virtual scrolling list component that can be sorted by dragging",
55
"main": "dist/virtual-drag-list.min.js",
66
"files": [

src/core

src/index.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { VirtualProps } from './props';
44
import {
55
Virtual,
66
Sortable,
7-
getDataKey,
8-
SortableAttrs,
9-
VirtualAttrs,
107
throttle,
8+
getDataKey,
119
isSameValue,
10+
VirtualAttrs,
11+
SortableAttrs,
1212
} from './core';
1313

1414
const VirtualList = Vue.component('virtual-list', {
@@ -208,6 +208,7 @@ const VirtualList = Vue.component('virtual-list', {
208208

209209
let range = { ...this.range };
210210
if (
211+
oldList.length > this.keeps &&
211212
newList.length > oldList.length &&
212213
this.range.end === oldList.length - 1 &&
213214
this._scrolledToBottom()
@@ -243,7 +244,7 @@ const VirtualList = Vue.component('virtual-list', {
243244
onUpdate: (range) => {
244245
const rangeChanged = range.start !== this.range.start;
245246
if (this.dragging && rangeChanged) {
246-
this.sortableRef.reRendered = true;
247+
this.sortableRef.rangeChanged = true;
247248
}
248249

249250
this.range = range;

src/props.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const VirtualProps = {
99
},
1010
scroller: {
1111
type: [Document, HTMLElement],
12+
default: undefined,
1213
},
1314
direction: {
1415
type: String,
@@ -20,6 +21,7 @@ export const VirtualProps = {
2021
},
2122
size: {
2223
type: Number,
24+
default: undefined,
2325
},
2426
keepOffset: {
2527
type: Boolean,
@@ -43,9 +45,11 @@ export const VirtualProps = {
4345
},
4446
handle: {
4547
type: [Function, String],
48+
default: undefined,
4649
},
4750
group: {
4851
type: [String, Object],
52+
default: undefined,
4953
},
5054
lockAxis: {
5155
type: String,
@@ -128,8 +132,10 @@ export const VirtualProps = {
128132
export const ItemProps = {
129133
dataKey: {
130134
type: [String, Number],
135+
default: undefined,
131136
},
132137
sizeKey: {
133138
type: String,
139+
default: undefined,
134140
},
135141
};

0 commit comments

Comments
 (0)