|
1 | 1 | /*! |
2 | | - * vue-virtual-drag-list v2.9.5 |
| 2 | + * vue-virtual-drag-list v2.9.6 |
3 | 3 | * open source under the MIT license |
4 | 4 | * https://github.com/mfuu/vue-virtual-drag-list#readme |
5 | 5 | */ |
|
1015 | 1015 | var sortableDnd_minExports = sortableDnd_min.exports; |
1016 | 1016 | var Dnd = /*@__PURE__*/getDefaultExportFromCjs(sortableDnd_minExports); |
1017 | 1017 |
|
| 1018 | + function throttle(fn, wait) { |
| 1019 | + var timer; |
| 1020 | + var result = function result() { |
| 1021 | + var _this = this; |
| 1022 | + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
| 1023 | + args[_key] = arguments[_key]; |
| 1024 | + } |
| 1025 | + if (timer) return; |
| 1026 | + if (wait <= 0) { |
| 1027 | + fn.apply(this, args); |
| 1028 | + } else { |
| 1029 | + timer = setTimeout(function () { |
| 1030 | + timer = null; |
| 1031 | + fn.apply(_this, args); |
| 1032 | + }, wait); |
| 1033 | + } |
| 1034 | + }; |
| 1035 | + result['cancel'] = function () { |
| 1036 | + if (timer) { |
| 1037 | + clearTimeout(timer); |
| 1038 | + timer = null; |
| 1039 | + } |
| 1040 | + }; |
| 1041 | + return result; |
| 1042 | + } |
| 1043 | + function debounce(fn, wait) { |
| 1044 | + var throttled = throttle(fn, wait); |
| 1045 | + var result = function result() { |
| 1046 | + throttled['cancel'](); |
| 1047 | + throttled.apply(this, arguments); |
| 1048 | + }; |
| 1049 | + result['cancel'] = function () { |
| 1050 | + throttled['cancel'](); |
| 1051 | + }; |
| 1052 | + return result; |
| 1053 | + } |
| 1054 | + function isSameValue(a, b) { |
| 1055 | + return a == b; |
| 1056 | + } |
| 1057 | + function getDataKey(item, dataKey) { |
| 1058 | + return (!Array.isArray(dataKey) ? dataKey.replace(/\[/g, '.').replace(/\]/g, '.').split('.') : dataKey).reduce(function (o, k) { |
| 1059 | + return (o || {})[k]; |
| 1060 | + }, item); |
| 1061 | + } |
| 1062 | + function elementIsDocumentOrWindow(element) { |
| 1063 | + return element instanceof Document && element.nodeType === 9 || element instanceof Window; |
| 1064 | + } |
| 1065 | + |
1018 | 1066 | var SortableAttrs = ['delay', 'group', 'handle', 'lockAxis', 'disabled', 'sortable', 'draggable', 'animation', 'autoScroll', 'ghostClass', 'ghostStyle', 'chosenClass', 'scrollSpeed', 'fallbackOnBody', 'scrollThreshold', 'delayOnTouchOnly', 'placeholderClass']; |
1019 | 1067 | var Sortable = /*#__PURE__*/function () { |
1020 | 1068 | function Sortable(el, options) { |
|
1081 | 1129 | }, { |
1082 | 1130 | key: "onDrag", |
1083 | 1131 | value: function onDrag(event) { |
1084 | | - var key = event.node.getAttribute('data-key'); |
1085 | | - var index = this.getIndex(key); |
| 1132 | + var dataKey = event.node.getAttribute('data-key'); |
| 1133 | + var index = this.getIndex(dataKey); |
1086 | 1134 | var item = this.options.list[index]; |
| 1135 | + var key = this.options.uniqueKeys[index]; |
1087 | 1136 | // store the dragged item |
1088 | 1137 | this.sortable.option('store', { |
1089 | 1138 | item: item, |
|
1172 | 1221 | }, { |
1173 | 1222 | key: "getIndex", |
1174 | 1223 | value: function getIndex(key) { |
1175 | | - return this.options.uniqueKeys.indexOf(key); |
| 1224 | + if (key === null || key === undefined) { |
| 1225 | + return -1; |
| 1226 | + } |
| 1227 | + var uniqueKeys = this.options.uniqueKeys; |
| 1228 | + for (var i = 0, len = uniqueKeys.length; i < len; i++) { |
| 1229 | + if (isSameValue(uniqueKeys[i], key)) { |
| 1230 | + return i; |
| 1231 | + } |
| 1232 | + } |
| 1233 | + return -1; |
1176 | 1234 | } |
1177 | 1235 | }, { |
1178 | 1236 | key: "dispatchEvent", |
|
1183 | 1241 | }]); |
1184 | 1242 | }(); |
1185 | 1243 |
|
1186 | | - function throttle(fn, wait) { |
1187 | | - var timer; |
1188 | | - var result = function result() { |
1189 | | - var _this = this; |
1190 | | - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
1191 | | - args[_key] = arguments[_key]; |
1192 | | - } |
1193 | | - if (timer) return; |
1194 | | - if (wait <= 0) { |
1195 | | - fn.apply(this, args); |
1196 | | - } else { |
1197 | | - timer = setTimeout(function () { |
1198 | | - timer = null; |
1199 | | - fn.apply(_this, args); |
1200 | | - }, wait); |
1201 | | - } |
1202 | | - }; |
1203 | | - result['cancel'] = function () { |
1204 | | - if (timer) { |
1205 | | - clearTimeout(timer); |
1206 | | - timer = null; |
1207 | | - } |
1208 | | - }; |
1209 | | - return result; |
1210 | | - } |
1211 | | - function debounce(fn, wait) { |
1212 | | - var throttled = throttle(fn, wait); |
1213 | | - var result = function result() { |
1214 | | - throttled['cancel'](); |
1215 | | - throttled.apply(this, arguments); |
1216 | | - }; |
1217 | | - result['cancel'] = function () { |
1218 | | - throttled['cancel'](); |
1219 | | - }; |
1220 | | - return result; |
1221 | | - } |
1222 | | - function getDataKey(item, dataKey) { |
1223 | | - return (!Array.isArray(dataKey) ? dataKey.replace(/\[/g, '.').replace(/\]/g, '.').split('.') : dataKey).reduce(function (o, k) { |
1224 | | - return (o || {})[k]; |
1225 | | - }, item); |
1226 | | - } |
1227 | | - function elementIsDocumentOrWindow(element) { |
1228 | | - return element instanceof Document && element.nodeType === 9 || element instanceof Window; |
1229 | | - } |
1230 | | - |
1231 | 1244 | var VirtualAttrs = ['size', 'keeps', 'scroller', 'direction', 'debounceTime', 'throttleTime']; |
1232 | 1245 | var Virtual = /*#__PURE__*/function () { |
1233 | 1246 | function Virtual(options) { |
|
1255 | 1268 | start: 0, |
1256 | 1269 | end: 0, |
1257 | 1270 | front: 0, |
1258 | | - behind: 0 |
| 1271 | + behind: 0, |
| 1272 | + total: 0 |
1259 | 1273 | }; |
1260 | 1274 | this.offset = 0; |
1261 | 1275 | this.direction = 'STATIONARY'; |
|
1319 | 1333 | if (index >= this.options.uniqueKeys.length - 1) { |
1320 | 1334 | this.scrollToBottom(); |
1321 | 1335 | } else { |
1322 | | - var indexOffset = this.getOffsetByIndex(index); |
| 1336 | + var indexOffset = this.getOffsetByRange(0, index); |
1323 | 1337 | var startOffset = this.getScrollStartOffset(); |
1324 | 1338 | this.scrollToOffset(indexOffset + startOffset); |
1325 | 1339 | } |
|
1447 | 1461 | value: function updateScrollElement() { |
1448 | 1462 | var scroller = this.options.scroller; |
1449 | 1463 | if (elementIsDocumentOrWindow(scroller)) { |
1450 | | - this.scrollEl = document.scrollingElement || document.documentElement || document.body; |
| 1464 | + var scrollEl = document.scrollingElement || document.documentElement || document.body; |
| 1465 | + this.scrollEl = scrollEl; |
1451 | 1466 | } else { |
1452 | 1467 | this.scrollEl = scroller; |
1453 | 1468 | } |
|
1534 | 1549 | var middleOffset = 0; |
1535 | 1550 | while (low <= high) { |
1536 | 1551 | middle = low + Math.floor((high - low) / 2); |
1537 | | - middleOffset = this.getOffsetByIndex(middle); |
| 1552 | + middleOffset = this.getOffsetByRange(0, middle); |
1538 | 1553 | if (middleOffset === offset) { |
1539 | 1554 | return middle; |
1540 | 1555 | } else if (middleOffset < offset) { |
|
1566 | 1581 | this.range.end = this.getEndByStart(start); |
1567 | 1582 | this.range.front = this.getFrontOffset(); |
1568 | 1583 | this.range.behind = this.getBehindOffset(); |
| 1584 | + this.range.total = this.getTotalOffset(); |
1569 | 1585 | this.options.onUpdate(Object.assign({}, this.range)); |
1570 | 1586 | } |
| 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 | + } |
1571 | 1594 | }, { |
1572 | 1595 | key: "getFrontOffset", |
1573 | 1596 | value: function getFrontOffset() { |
1574 | 1597 | if (this.isFixed()) { |
1575 | 1598 | return this.fixedSize * this.range.start; |
1576 | 1599 | } else { |
1577 | | - return this.getOffsetByIndex(this.range.start); |
| 1600 | + return this.getOffsetByRange(0, this.range.start); |
1578 | 1601 | } |
1579 | 1602 | } |
1580 | 1603 | }, { |
|
1588 | 1611 | return (last - end) * this.getItemSize(); |
1589 | 1612 | } |
1590 | 1613 | }, { |
1591 | | - key: "getOffsetByIndex", |
1592 | | - value: function getOffsetByIndex(index) { |
1593 | | - if (!index) { |
| 1614 | + key: "getOffsetByRange", |
| 1615 | + value: function getOffsetByRange(start, end) { |
| 1616 | + if (start >= end) { |
1594 | 1617 | return 0; |
1595 | 1618 | } |
1596 | 1619 | var offset = 0; |
1597 | | - for (var i = 0; i < index; i++) { |
| 1620 | + for (var i = start; i < end; i++) { |
1598 | 1621 | var size = this.sizes.get(this.options.uniqueKeys[i]); |
1599 | 1622 | offset = offset + (typeof size === 'number' ? size : this.getItemSize()); |
1600 | 1623 | } |
|
1629 | 1652 | } |
1630 | 1653 | var offset = 0; |
1631 | 1654 | if (scroller && wrapper) { |
1632 | | - var sizeKey = this.isHorizontal() ? 'left' : 'top'; |
| 1655 | + var offsetKey = this.isHorizontal() ? 'left' : 'top'; |
1633 | 1656 | var rect = elementIsDocumentOrWindow(scroller) ? Dnd.utils.getRect(wrapper) : Dnd.utils.getRect(wrapper, true, scroller); |
1634 | | - offset = this.offset + rect[sizeKey]; |
| 1657 | + offset = this.offset + rect[offsetKey]; |
1635 | 1658 | } |
1636 | 1659 | return offset; |
1637 | 1660 | } |
|
1652 | 1675 | front: 0, |
1653 | 1676 | behind: 0 |
1654 | 1677 | }, |
1655 | | - choosen: '', |
| 1678 | + chosenKey: '', |
1656 | 1679 | dragging: false, |
1657 | 1680 | lastList: [], |
1658 | 1681 | lastLength: null, |
|
1869 | 1892 | list: this.dataSource, |
1870 | 1893 | uniqueKeys: this.uniqueKeys, |
1871 | 1894 | onChoose: function onChoose(event) { |
1872 | | - _this5.choosen = event.node.getAttribute('data-key'); |
| 1895 | + _this5.chosenKey = event.node.getAttribute('data-key'); |
1873 | 1896 | }, |
1874 | 1897 | onUnChoose: function onUnChoose() { |
1875 | | - _this5.choosen = ''; |
| 1898 | + _this5.chosenKey = ''; |
1876 | 1899 | }, |
1877 | 1900 | onDrag: function onDrag(event) { |
1878 | 1901 | _this5.dragging = true; |
|
1901 | 1924 | this.$emit('bottom'); |
1902 | 1925 | }, 50), |
1903 | 1926 | _onItemResized: function _onItemResized(key, size) { |
1904 | | - if (key === this.choosen) { |
| 1927 | + if (isSameValue(key, this.chosenKey)) { |
1905 | 1928 | return; |
1906 | 1929 | } |
1907 | 1930 | var sizes = this.virtualRef.sizes.size; |
|
1936 | 1959 | var record = this.dataSource[index]; |
1937 | 1960 | if (record) { |
1938 | 1961 | var dataKey = getDataKey(record, this.dataKey); |
1939 | | - var itemStyle = this.dragging && dataKey == this.choosen && { |
| 1962 | + var isChosen = isSameValue(dataKey, this.chosenKey); |
| 1963 | + var itemStyle = this.dragging && isChosen && { |
1940 | 1964 | display: 'none' |
1941 | 1965 | }; |
1942 | 1966 | renders.push(this.$scopedSlots.item ? h(Item, { |
|
0 commit comments