|
1 | 1 | /*! |
2 | | - * vue-virtual-draglist v3.3.6 |
| 2 | + * vue-virtual-draglist v3.3.7 |
3 | 3 | * open source under the MIT license |
4 | 4 | * https://github.com/mfuu/vue3-virtual-drag-list#readme |
5 | 5 | */ |
|
857 | 857 | })(sortableDnd_min); |
858 | 858 | var Dnd = sortableDnd_min.exports; |
859 | 859 |
|
| 860 | + function throttle(fn, wait) { |
| 861 | + var timer; |
| 862 | + var result = function result() { |
| 863 | + var _this = this; |
| 864 | + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
| 865 | + args[_key] = arguments[_key]; |
| 866 | + } |
| 867 | + if (timer) return; |
| 868 | + if (wait <= 0) { |
| 869 | + fn.apply(this, args); |
| 870 | + } else { |
| 871 | + timer = setTimeout(function () { |
| 872 | + timer = null; |
| 873 | + fn.apply(_this, args); |
| 874 | + }, wait); |
| 875 | + } |
| 876 | + }; |
| 877 | + result['cancel'] = function () { |
| 878 | + if (timer) { |
| 879 | + clearTimeout(timer); |
| 880 | + timer = null; |
| 881 | + } |
| 882 | + }; |
| 883 | + return result; |
| 884 | + } |
| 885 | + function debounce(fn, wait) { |
| 886 | + var throttled = throttle(fn, wait); |
| 887 | + var result = function result() { |
| 888 | + throttled['cancel'](); |
| 889 | + throttled.apply(this, arguments); |
| 890 | + }; |
| 891 | + result['cancel'] = function () { |
| 892 | + throttled['cancel'](); |
| 893 | + }; |
| 894 | + return result; |
| 895 | + } |
| 896 | + function isSameValue(a, b) { |
| 897 | + return a == b; |
| 898 | + } |
| 899 | + function getDataKey(item, dataKey) { |
| 900 | + return (!Array.isArray(dataKey) ? dataKey.replace(/\[/g, '.').replace(/\]/g, '.').split('.') : dataKey).reduce(function (o, k) { |
| 901 | + return (o || {})[k]; |
| 902 | + }, item); |
| 903 | + } |
| 904 | + function elementIsDocumentOrWindow(element) { |
| 905 | + return element instanceof Document && element.nodeType === 9 || element instanceof Window; |
| 906 | + } |
| 907 | + |
860 | 908 | var SortableAttrs = ['delay', 'group', 'handle', 'lockAxis', 'disabled', 'sortable', 'draggable', 'animation', 'autoScroll', 'ghostClass', 'ghostStyle', 'chosenClass', 'scrollSpeed', 'fallbackOnBody', 'scrollThreshold', 'delayOnTouchOnly', 'placeholderClass']; |
861 | 909 | var Sortable = /*#__PURE__*/function () { |
862 | 910 | function Sortable(el, options) { |
|
923 | 971 | }, { |
924 | 972 | key: "onDrag", |
925 | 973 | value: function onDrag(event) { |
926 | | - var key = event.node.getAttribute('data-key'); |
927 | | - var index = this.getIndex(key); |
| 974 | + var dataKey = event.node.getAttribute('data-key'); |
| 975 | + var index = this.getIndex(dataKey); |
928 | 976 | var item = this.options.list[index]; |
| 977 | + var key = this.options.uniqueKeys[index]; |
929 | 978 | // store the dragged item |
930 | 979 | this.sortable.option('store', { |
931 | 980 | item: item, |
|
1014 | 1063 | }, { |
1015 | 1064 | key: "getIndex", |
1016 | 1065 | value: function getIndex(key) { |
1017 | | - return this.options.uniqueKeys.indexOf(key); |
| 1066 | + if (key === null || key === undefined) { |
| 1067 | + return -1; |
| 1068 | + } |
| 1069 | + var uniqueKeys = this.options.uniqueKeys; |
| 1070 | + for (var i = 0, len = uniqueKeys.length; i < len; i++) { |
| 1071 | + if (isSameValue(uniqueKeys[i], key)) { |
| 1072 | + return i; |
| 1073 | + } |
| 1074 | + } |
| 1075 | + return -1; |
1018 | 1076 | } |
1019 | 1077 | }, { |
1020 | 1078 | key: "dispatchEvent", |
|
1025 | 1083 | }]); |
1026 | 1084 | }(); |
1027 | 1085 |
|
1028 | | - function throttle(fn, wait) { |
1029 | | - var timer; |
1030 | | - var result = function result() { |
1031 | | - var _this = this; |
1032 | | - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { |
1033 | | - args[_key] = arguments[_key]; |
1034 | | - } |
1035 | | - if (timer) return; |
1036 | | - if (wait <= 0) { |
1037 | | - fn.apply(this, args); |
1038 | | - } else { |
1039 | | - timer = setTimeout(function () { |
1040 | | - timer = null; |
1041 | | - fn.apply(_this, args); |
1042 | | - }, wait); |
1043 | | - } |
1044 | | - }; |
1045 | | - result['cancel'] = function () { |
1046 | | - if (timer) { |
1047 | | - clearTimeout(timer); |
1048 | | - timer = null; |
1049 | | - } |
1050 | | - }; |
1051 | | - return result; |
1052 | | - } |
1053 | | - function debounce(fn, wait) { |
1054 | | - var throttled = throttle(fn, wait); |
1055 | | - var result = function result() { |
1056 | | - throttled['cancel'](); |
1057 | | - throttled.apply(this, arguments); |
1058 | | - }; |
1059 | | - result['cancel'] = function () { |
1060 | | - throttled['cancel'](); |
1061 | | - }; |
1062 | | - return result; |
1063 | | - } |
1064 | | - function getDataKey(item, dataKey) { |
1065 | | - return (!Array.isArray(dataKey) ? dataKey.replace(/\[/g, '.').replace(/\]/g, '.').split('.') : dataKey).reduce(function (o, k) { |
1066 | | - return (o || {})[k]; |
1067 | | - }, item); |
1068 | | - } |
1069 | | - function elementIsDocumentOrWindow(element) { |
1070 | | - return element instanceof Document && element.nodeType === 9 || element instanceof Window; |
1071 | | - } |
1072 | | - |
1073 | 1086 | var VirtualAttrs = ['size', 'keeps', 'scroller', 'direction', 'debounceTime', 'throttleTime']; |
1074 | 1087 | var Virtual = /*#__PURE__*/function () { |
1075 | 1088 | function Virtual(options) { |
|
1097 | 1110 | start: 0, |
1098 | 1111 | end: 0, |
1099 | 1112 | front: 0, |
1100 | | - behind: 0 |
| 1113 | + behind: 0, |
| 1114 | + total: 0 |
1101 | 1115 | }; |
1102 | 1116 | this.offset = 0; |
1103 | 1117 | this.direction = 'STATIONARY'; |
|
1161 | 1175 | if (index >= this.options.uniqueKeys.length - 1) { |
1162 | 1176 | this.scrollToBottom(); |
1163 | 1177 | } else { |
1164 | | - var indexOffset = this.getOffsetByIndex(index); |
| 1178 | + var indexOffset = this.getOffsetByRange(0, index); |
1165 | 1179 | var startOffset = this.getScrollStartOffset(); |
1166 | 1180 | this.scrollToOffset(indexOffset + startOffset); |
1167 | 1181 | } |
|
1289 | 1303 | value: function updateScrollElement() { |
1290 | 1304 | var scroller = this.options.scroller; |
1291 | 1305 | if (elementIsDocumentOrWindow(scroller)) { |
1292 | | - this.scrollEl = document.scrollingElement || document.documentElement || document.body; |
| 1306 | + var scrollEl = document.scrollingElement || document.documentElement || document.body; |
| 1307 | + this.scrollEl = scrollEl; |
1293 | 1308 | } else { |
1294 | 1309 | this.scrollEl = scroller; |
1295 | 1310 | } |
|
1376 | 1391 | var middleOffset = 0; |
1377 | 1392 | while (low <= high) { |
1378 | 1393 | middle = low + Math.floor((high - low) / 2); |
1379 | | - middleOffset = this.getOffsetByIndex(middle); |
| 1394 | + middleOffset = this.getOffsetByRange(0, middle); |
1380 | 1395 | if (middleOffset === offset) { |
1381 | 1396 | return middle; |
1382 | 1397 | } else if (middleOffset < offset) { |
|
1408 | 1423 | this.range.end = this.getEndByStart(start); |
1409 | 1424 | this.range.front = this.getFrontOffset(); |
1410 | 1425 | this.range.behind = this.getBehindOffset(); |
| 1426 | + this.range.total = this.getTotalOffset(); |
1411 | 1427 | this.options.onUpdate(Object.assign({}, this.range)); |
1412 | 1428 | } |
| 1429 | + }, { |
| 1430 | + key: "getTotalOffset", |
| 1431 | + value: function getTotalOffset() { |
| 1432 | + var offset = this.range.front + this.range.behind; |
| 1433 | + offset += this.getOffsetByRange(this.range.start, this.range.end + 1); |
| 1434 | + return offset; |
| 1435 | + } |
1413 | 1436 | }, { |
1414 | 1437 | key: "getFrontOffset", |
1415 | 1438 | value: function getFrontOffset() { |
1416 | 1439 | if (this.isFixed()) { |
1417 | 1440 | return this.fixedSize * this.range.start; |
1418 | 1441 | } else { |
1419 | | - return this.getOffsetByIndex(this.range.start); |
| 1442 | + return this.getOffsetByRange(0, this.range.start); |
1420 | 1443 | } |
1421 | 1444 | } |
1422 | 1445 | }, { |
|
1430 | 1453 | return (last - end) * this.getItemSize(); |
1431 | 1454 | } |
1432 | 1455 | }, { |
1433 | | - key: "getOffsetByIndex", |
1434 | | - value: function getOffsetByIndex(index) { |
1435 | | - if (!index) { |
| 1456 | + key: "getOffsetByRange", |
| 1457 | + value: function getOffsetByRange(start, end) { |
| 1458 | + if (start >= end) { |
1436 | 1459 | return 0; |
1437 | 1460 | } |
1438 | 1461 | var offset = 0; |
1439 | | - for (var i = 0; i < index; i++) { |
| 1462 | + for (var i = start; i < end; i++) { |
1440 | 1463 | var size = this.sizes.get(this.options.uniqueKeys[i]); |
1441 | 1464 | offset = offset + (typeof size === 'number' ? size : this.getItemSize()); |
1442 | 1465 | } |
|
1471 | 1494 | } |
1472 | 1495 | var offset = 0; |
1473 | 1496 | if (scroller && wrapper) { |
1474 | | - var sizeKey = this.isHorizontal() ? 'left' : 'top'; |
| 1497 | + var offsetKey = this.isHorizontal() ? 'left' : 'top'; |
1475 | 1498 | var rect = elementIsDocumentOrWindow(scroller) ? Dnd.utils.getRect(wrapper) : Dnd.utils.getRect(wrapper, true, scroller); |
1476 | | - offset = this.offset + rect[sizeKey]; |
| 1499 | + offset = this.offset + rect[offsetKey]; |
1477 | 1500 | } |
1478 | 1501 | return offset; |
1479 | 1502 | } |
|
1716 | 1739 | start: 0, |
1717 | 1740 | end: props.keeps - 1, |
1718 | 1741 | front: 0, |
1719 | | - behind: 0 |
| 1742 | + behind: 0, |
| 1743 | + total: 0 |
1720 | 1744 | }); |
1721 | 1745 | var horizontal = vue.computed(function () { |
1722 | 1746 | return props.direction !== 'vertical'; |
|
1840 | 1864 | }; |
1841 | 1865 | // ========================================== use virtual ========================================== |
1842 | 1866 | var virtual; |
1843 | | - var choosen = vue.ref(); |
1844 | 1867 | var dragging = vue.ref(false); |
| 1868 | + var chosenKey = vue.ref(''); |
1845 | 1869 | var virtualAttributes = vue.computed(function () { |
1846 | 1870 | return VirtualAttrs.reduce(function (res, key) { |
1847 | 1871 | res[key] = props[key]; |
|
1891 | 1915 | }; |
1892 | 1916 | var onItemResized = function onItemResized(size, key) { |
1893 | 1917 | // ignore changes for dragging element |
1894 | | - if (key === choosen.value) { |
| 1918 | + if (isSameValue(key, chosenKey.value)) { |
1895 | 1919 | return; |
1896 | 1920 | } |
1897 | 1921 | var sizes = virtual.sizes.size; |
|
1918 | 1942 | } |
1919 | 1943 | }); |
1920 | 1944 | var onChoose = function onChoose(event) { |
1921 | | - choosen.value = event.node.getAttribute('data-key'); |
| 1945 | + chosenKey.value = event.node.getAttribute('data-key'); |
1922 | 1946 | }; |
1923 | 1947 | var onUnchoose = function onUnchoose() { |
1924 | | - choosen.value = ''; |
| 1948 | + chosenKey.value = ''; |
1925 | 1949 | }; |
1926 | 1950 | var onDrag = function onDrag(event) { |
1927 | 1951 | dragging.value = true; |
|
1978 | 2002 | var record = listRef.value[index]; |
1979 | 2003 | if (record) { |
1980 | 2004 | var dataKey = getDataKey(record, props.dataKey); |
| 2005 | + var isChosen = isSameValue(dataKey, chosenKey.value); |
1981 | 2006 | renders.push(slots.item ? vue.h(Item, { |
1982 | 2007 | key: dataKey, |
1983 | 2008 | "class": props.itemClass, |
1984 | | - style: dragging.value && dataKey == choosen.value && { |
| 2009 | + style: dragging.value && isChosen && { |
1985 | 2010 | display: 'none' |
1986 | 2011 | }, |
1987 | 2012 | dataKey: dataKey, |
|
0 commit comments