Skip to content

Commit

Permalink
fix: render error when list change
Browse files Browse the repository at this point in the history
  • Loading branch information
mfuu committed Dec 25, 2024
1 parent 1a16a34 commit 5b40b7f
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Root component:
<template slot="item" slot-scope="{ record, index, dataKey }">
<div>
<span class="handle">{{ record.id }}</span>
{{ record.text }}
<p>{{ record.text }}</p>
</div>
</template>
<template slot="header">
Expand Down
44 changes: 20 additions & 24 deletions dist/virtual-drag-list.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* vue-virtual-drag-list v2.9.6
* vue-virtual-drag-list v2.9.7
* open source under the MIT license
* https://github.com/mfuu/vue-virtual-drag-list#readme
*/
Expand Down Expand Up @@ -79,7 +79,8 @@
required: true
},
scroller: {
type: [Document, HTMLElement]
type: [Document, HTMLElement],
"default": undefined
},
direction: {
type: String,
Expand All @@ -90,7 +91,8 @@
"default": 30
},
size: {
type: Number
type: Number,
"default": undefined
},
keepOffset: {
type: Boolean,
Expand All @@ -113,10 +115,12 @@
"default": true
},
handle: {
type: [Function, String]
type: [Function, String],
"default": undefined
},
group: {
type: [String, Object]
type: [String, Object],
"default": undefined
},
lockAxis: {
type: String,
Expand Down Expand Up @@ -206,10 +210,12 @@
};
var ItemProps = {
dataKey: {
type: [String, Number]
type: [String, Number],
"default": undefined
},
sizeKey: {
type: String
type: String,
"default": undefined
}
};

Expand Down Expand Up @@ -1069,14 +1075,14 @@
_classCallCheck(this, Sortable);
this.el = el;
this.options = options;
this.reRendered = false;
this.rangeChanged = false;
this.installSortable();
}
return _createClass(Sortable, [{
key: "destroy",
value: function destroy() {
this.sortable.destroy();
this.reRendered = false;
this.rangeChanged = false;
}
}, {
key: "option",
Expand Down Expand Up @@ -1169,13 +1175,13 @@
this.handleDropEvent(event, params, index);
}
this.dispatchEvent('onDrop', params);
if (event.from === this.el && this.reRendered) {
if (event.from === this.el && this.rangeChanged) {
(_b = Dnd.dragged) === null || _b === void 0 ? void 0 : _b.remove();
}
if (event.from !== event.to) {
(_c = Dnd.clone) === null || _c === void 0 ? void 0 : _c.remove();
}
this.reRendered = false;
this.rangeChanged = false;
}
}, {
key: "handleDropEvent",
Expand Down Expand Up @@ -1268,8 +1274,7 @@
start: 0,
end: 0,
front: 0,
behind: 0,
total: 0
behind: 0
};
this.offset = 0;
this.direction = 'STATIONARY';
Expand Down Expand Up @@ -1436,7 +1441,6 @@
eventFn(scroller, 'touchmove', this.preventDefault);
eventFn(scroller, 'keydown', this.preventDefaultForKeyDown);
}
// ========================================= Properties =========================================
}, {
key: "preventDefault",
value: function preventDefault(e) {
Expand Down Expand Up @@ -1581,16 +1585,8 @@
this.range.end = this.getEndByStart(start);
this.range.front = this.getFrontOffset();
this.range.behind = this.getBehindOffset();
this.range.total = this.getTotalOffset();
this.options.onUpdate(Object.assign({}, this.range));
}
}, {
key: "getTotalOffset",
value: function getTotalOffset() {
var offset = this.range.front + this.range.behind;
offset += this.getOffsetByRange(this.range.start, this.range.end + 1);
return offset;
}
}, {
key: "getFrontOffset",
value: function getFrontOffset() {
Expand Down Expand Up @@ -1846,7 +1842,7 @@
return;
}
var range = Object.assign({}, this.range);
if (newList.length > oldList.length && this.range.end === oldList.length - 1 && this._scrolledToBottom()) {
if (oldList.length > this.keeps && newList.length > oldList.length && this.range.end === oldList.length - 1 && this._scrolledToBottom()) {
range.start++;
}
(_a = this.virtualRef) === null || _a === void 0 ? void 0 : _a.updateRange(range);
Expand Down Expand Up @@ -1877,7 +1873,7 @@
var _a;
var rangeChanged = range.start !== _this4.range.start;
if (_this4.dragging && rangeChanged) {
_this4.sortableRef.reRendered = true;
_this4.sortableRef.rangeChanged = true;
}
_this4.range = range;
(_a = _this4.sortableRef) === null || _a === void 0 ? void 0 : _a.option('range', range);
Expand Down
6 changes: 3 additions & 3 deletions dist/virtual-drag-list.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/.vuepress/components/group.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export default {
padding: 16px;
height: 50px;
overflow: hidden;
box-sizing: border-box;
}
.item-title {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-virtual-draglist",
"version": "2.9.6",
"version": "2.9.7",
"description": "A virtual scrolling list component that can be sorted by dragging",
"main": "dist/virtual-drag-list.min.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/core
Submodule core updated 3 files
+5 −5 README.md
+5 −5 Sortable.ts
+1 −12 Virtual.ts
9 changes: 5 additions & 4 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { VirtualProps } from './props';
import {
Virtual,
Sortable,
getDataKey,
SortableAttrs,
VirtualAttrs,
throttle,
getDataKey,
isSameValue,
VirtualAttrs,
SortableAttrs,
} from './core';

const VirtualList = Vue.component('virtual-list', {
Expand Down Expand Up @@ -208,6 +208,7 @@ const VirtualList = Vue.component('virtual-list', {

let range = { ...this.range };
if (
oldList.length > this.keeps &&
newList.length > oldList.length &&
this.range.end === oldList.length - 1 &&
this._scrolledToBottom()
Expand Down Expand Up @@ -243,7 +244,7 @@ const VirtualList = Vue.component('virtual-list', {
onUpdate: (range) => {
const rangeChanged = range.start !== this.range.start;
if (this.dragging && rangeChanged) {
this.sortableRef.reRendered = true;
this.sortableRef.rangeChanged = true;
}

this.range = range;
Expand Down
6 changes: 6 additions & 0 deletions src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const VirtualProps = {
},
scroller: {
type: [Document, HTMLElement],
default: undefined,
},
direction: {
type: String,
Expand All @@ -20,6 +21,7 @@ export const VirtualProps = {
},
size: {
type: Number,
default: undefined,
},
keepOffset: {
type: Boolean,
Expand All @@ -43,9 +45,11 @@ export const VirtualProps = {
},
handle: {
type: [Function, String],
default: undefined,
},
group: {
type: [String, Object],
default: undefined,
},
lockAxis: {
type: String,
Expand Down Expand Up @@ -128,8 +132,10 @@ export const VirtualProps = {
export const ItemProps = {
dataKey: {
type: [String, Number],
default: undefined,
},
sizeKey: {
type: String,
default: undefined,
},
};

0 comments on commit 5b40b7f

Please sign in to comment.