|
1 | 1 | /*!
|
2 |
| - * vue-virtual-draglist v3.3.1 |
| 2 | + * vue-virtual-draglist v3.3.2 |
3 | 3 | * open source under the MIT license
|
4 | 4 | * https://github.com/mfuu/vue3-virtual-drag-list#readme
|
5 | 5 | */
|
|
876 | 876 | })(sortableDnd_min);
|
877 | 877 | var Dnd = sortableDnd_min.exports;
|
878 | 878 |
|
879 |
| - var SortableAttrs = ['delay', 'group', 'handle', 'lockAxis', 'disabled', 'sortable', 'draggable', 'animation', 'autoScroll', 'ghostClass', 'ghostStyle', 'chosenClass', 'fallbackOnBody', 'scrollThreshold', 'delayOnTouchOnly']; |
| 879 | + var SortableAttrs = ['delay', 'group', 'handle', 'lockAxis', 'disabled', 'sortable', 'draggable', 'animation', 'autoScroll', 'ghostClass', 'ghostStyle', 'chosenClass', 'scrollSpeed', 'fallbackOnBody', 'scrollThreshold', 'delayOnTouchOnly']; |
880 | 880 | function Sortable(el, options) {
|
881 | 881 | this.el = el;
|
882 | 882 | this.options = options;
|
|
911 | 911 | },
|
912 | 912 | onDrop: function onDrop(event) {
|
913 | 913 | return _this.onDrop(event);
|
914 |
| - }, |
915 |
| - onAdd: function onAdd(event) { |
916 |
| - return _this.onAdd(event); |
917 |
| - }, |
918 |
| - onRemove: function onRemove(event) { |
919 |
| - return _this.onRemove(event); |
920 | 914 | }
|
921 | 915 | }));
|
922 | 916 | },
|
923 |
| - onAdd: function onAdd(event) { |
924 |
| - var _Dnd$get$option = Dnd.get(event.from).option('store'), |
925 |
| - item = _Dnd$get$option.item, |
926 |
| - key = _Dnd$get$option.key; |
927 |
| - |
928 |
| - // store the dragged item |
929 |
| - this.sortable.option('store', { |
930 |
| - item: item, |
931 |
| - key: key |
932 |
| - }); |
933 |
| - this.dispatchEvent('onAdd', { |
934 |
| - item: item, |
935 |
| - key: key, |
936 |
| - event: event |
937 |
| - }); |
938 |
| - }, |
939 |
| - onRemove: function onRemove(event) { |
940 |
| - var _Dnd$get$option2 = Dnd.get(event.from).option('store'), |
941 |
| - item = _Dnd$get$option2.item, |
942 |
| - key = _Dnd$get$option2.key; |
943 |
| - this.dispatchEvent('onRemove', { |
944 |
| - item: item, |
945 |
| - key: key, |
946 |
| - event: event |
947 |
| - }); |
948 |
| - }, |
949 | 917 | onDrag: function onDrag(event) {
|
950 | 918 | var key = event.node.getAttribute('data-key');
|
951 | 919 | var index = this.getIndex(key);
|
|
965 | 933 | });
|
966 | 934 | },
|
967 | 935 | onDrop: function onDrop(event) {
|
968 |
| - var _Dnd$get$option3 = Dnd.get(event.from).option('store'), |
969 |
| - item = _Dnd$get$option3.item, |
970 |
| - key = _Dnd$get$option3.key, |
971 |
| - index = _Dnd$get$option3.index; |
| 936 | + var _Dnd$get$option = Dnd.get(event.from).option('store'), |
| 937 | + item = _Dnd$get$option.item, |
| 938 | + key = _Dnd$get$option.key, |
| 939 | + index = _Dnd$get$option.index; |
972 | 940 | var list = this.options.list;
|
973 | 941 | var params = {
|
974 | 942 | key: key,
|
|
981 | 949 | newIndex: index
|
982 | 950 | };
|
983 | 951 | if (!(event.from === event.to && event.node === event.target)) {
|
984 |
| - this.getDropParams(params, event, item, key, index, list); |
| 952 | + this.handleDropEvent(params, event, item, key, index, list); |
985 | 953 | }
|
986 | 954 | this.dispatchEvent('onDrop', params);
|
987 | 955 | if (event.from === this.el && this.reRendered) {
|
|
994 | 962 | }
|
995 | 963 | this.reRendered = false;
|
996 | 964 | },
|
997 |
| - getDropParams: function getDropParams(params, event, item, key, index, list) { |
| 965 | + handleDropEvent: function handleDropEvent(params, event, item, key, index, list) { |
998 | 966 | var targetKey = event.target.getAttribute('data-key');
|
999 | 967 | var newIndex = -1;
|
1000 | 968 | var oldIndex = index;
|
|
1141 | 1109 | this.calcType = CACLTYPE.INIT;
|
1142 | 1110 | this.calcSize = {
|
1143 | 1111 | average: 0,
|
1144 |
| - total: 0, |
1145 | 1112 | fixed: 0
|
1146 | 1113 | };
|
1147 | 1114 | this.scrollDirection = '';
|
|
1227 | 1194 | this.handleUpdate(start, this.getEndByStart(start));
|
1228 | 1195 | },
|
1229 | 1196 | onItemResized: function onItemResized(key, size) {
|
| 1197 | + if (this.sizes.get(key) === size) { |
| 1198 | + return; |
| 1199 | + } |
1230 | 1200 | this.sizes.set(key, size);
|
1231 | 1201 | if (this.calcType === CACLTYPE.INIT) {
|
1232 | 1202 | this.calcType = CACLTYPE.FIXED;
|
1233 | 1203 | this.calcSize.fixed = size;
|
1234 | 1204 | } else if (this.isFixed() && this.calcSize.fixed !== size) {
|
1235 | 1205 | this.calcType = CACLTYPE.DYNAMIC;
|
1236 |
| - this.calcSize.fixed = undefined; |
| 1206 | + this.calcSize.fixed = 0; |
1237 | 1207 | }
|
1238 |
| - // In the case of non-fixed heights, the average height and the total height are calculated |
1239 |
| - if (this.calcType !== CACLTYPE.FIXED) { |
1240 |
| - this.calcSize.total = _toConsumableArray(this.sizes.values()).reduce(function (t, i) { |
1241 |
| - return t + i; |
1242 |
| - }, 0); |
1243 |
| - this.calcSize.average = Math.round(this.calcSize.total / this.sizes.size); |
| 1208 | + |
| 1209 | + // calculate the average size only once |
| 1210 | + if (this.calcType === CACLTYPE.DYNAMIC && !this.calcSize.average) { |
| 1211 | + var critical = Math.min(this.options.keeps, this.options.uniqueKeys.length); |
| 1212 | + if (this.sizes.size === critical) { |
| 1213 | + var total = _toConsumableArray(this.sizes.values()).reduce(function (t, i) { |
| 1214 | + return t + i; |
| 1215 | + }, 0); |
| 1216 | + this.calcSize.average = Math.round(total / this.sizes.size); |
| 1217 | + } |
1244 | 1218 | }
|
1245 | 1219 | },
|
1246 | 1220 | addScrollEventListener: function addScrollEventListener() {
|
|
1331 | 1305 | },
|
1332 | 1306 | handleScrollFront: function handleScrollFront() {
|
1333 | 1307 | var scrolls = this.getScrollItems();
|
1334 |
| - if (scrolls > this.range.start) { |
| 1308 | + if (scrolls >= this.range.start) { |
1335 | 1309 | return;
|
1336 | 1310 | }
|
1337 | 1311 | var start = Math.max(scrolls - this.options.buffer, 0);
|
1338 | 1312 | this.checkIfUpdate(start, this.getEndByStart(start));
|
1339 | 1313 | },
|
1340 | 1314 | handleScrollBehind: function handleScrollBehind() {
|
1341 | 1315 | var scrolls = this.getScrollItems();
|
1342 |
| - if (scrolls < this.range.start + this.options.buffer) { |
| 1316 | + if (scrolls <= this.range.start + this.options.buffer) { |
1343 | 1317 | return;
|
1344 | 1318 | }
|
1345 | 1319 | this.checkIfUpdate(scrolls, this.getEndByStart(scrolls));
|
|
1431 | 1405 | wrapper = _this$options3.wrapper,
|
1432 | 1406 | scroller = _this$options3.scroller,
|
1433 | 1407 | direction = _this$options3.direction;
|
| 1408 | + if (scroller === wrapper) { |
| 1409 | + return 0; |
| 1410 | + } |
1434 | 1411 | if (scroller && wrapper) {
|
1435 | 1412 | var rect = scroller instanceof Window ? Dnd.utils.getRect(wrapper) : Dnd.utils.getRect(wrapper, true, scroller);
|
1436 | 1413 | offset = this.offset + rect[rectDir[direction]];
|
|
1503 | 1480 | type: Boolean,
|
1504 | 1481 | "default": true
|
1505 | 1482 | },
|
| 1483 | + scrollSpeed: { |
| 1484 | + type: Object, |
| 1485 | + "default": function _default() { |
| 1486 | + return { |
| 1487 | + x: 10, |
| 1488 | + y: 10 |
| 1489 | + }; |
| 1490 | + } |
| 1491 | + }, |
1506 | 1492 | scrollThreshold: {
|
1507 | 1493 | type: Number,
|
1508 | 1494 | "default": 55
|
|
0 commit comments