|
1 | 1 | /*!
|
2 |
| - * vue-virtual-draglist v3.3.0 |
| 2 | + * vue-virtual-draglist v3.3.1 |
3 | 3 | * open source under the MIT license
|
4 | 4 | * https://github.com/mfuu/vue3-virtual-drag-list#readme
|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | (function (global, factory) {
|
8 | 8 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('vue')) :
|
9 | 9 | typeof define === 'function' && define.amd ? define(['vue'], factory) :
|
10 |
| - (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VirtualDragList = factory(global.Vue)); |
| 10 | + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.VirtualList = factory(global.Vue)); |
11 | 11 | })(this, (function (vue) { 'use strict';
|
12 | 12 |
|
13 | 13 | function _iterableToArrayLimit(arr, i) {
|
|
1447 | 1447 | "default": '',
|
1448 | 1448 | required: true
|
1449 | 1449 | },
|
| 1450 | + tableMode: { |
| 1451 | + type: Boolean, |
| 1452 | + "default": false |
| 1453 | + }, |
1450 | 1454 | draggable: {
|
1451 | 1455 | type: String,
|
1452 | 1456 | "default": '.virtual-dnd-list-item'
|
1453 | 1457 | },
|
| 1458 | + itemClass: { |
| 1459 | + type: String, |
| 1460 | + "default": 'virtual-dnd-list-item' |
| 1461 | + }, |
1454 | 1462 | sortable: {
|
1455 | 1463 | type: Boolean,
|
1456 | 1464 | "default": true
|
|
1559 | 1567 | sizeKey: {
|
1560 | 1568 | type: String,
|
1561 | 1569 | "default": 'offsetHeight'
|
| 1570 | + }, |
| 1571 | + itemClass: { |
| 1572 | + type: String |
1562 | 1573 | }
|
1563 | 1574 | };
|
1564 | 1575 |
|
|
1582 | 1593 | }
|
1583 | 1594 | });
|
1584 | 1595 | };
|
1585 |
| - var Items = vue.defineComponent({ |
| 1596 | + var Item = vue.defineComponent({ |
1586 | 1597 | props: SlotsProps,
|
1587 | 1598 | emits: ['resize'],
|
1588 | 1599 | setup: function setup(props, _ref2) {
|
|
1610 | 1621 | observer = null;
|
1611 | 1622 | }
|
1612 | 1623 | };
|
1613 |
| - var mySlot = createSlot({ |
| 1624 | + var customSlot = createSlot({ |
1614 | 1625 | mounted: mounted,
|
1615 | 1626 | updated: updated,
|
1616 | 1627 | unmounted: unmounted
|
1617 | 1628 | });
|
1618 | 1629 | return function () {
|
1619 | 1630 | var _a;
|
1620 |
| - var dataKey = props.dataKey; |
| 1631 | + var dataKey = props.dataKey, |
| 1632 | + itemClass = props.itemClass; |
1621 | 1633 | var _ref3 = ((_a = slots["default"]) === null || _a === void 0 ? void 0 : _a.call(slots)) || [],
|
1622 | 1634 | _ref4 = _slicedToArray(_ref3, 1),
|
1623 | 1635 | defaultSlot = _ref4[0];
|
1624 |
| - return vue.h(mySlot, { |
| 1636 | + return vue.h(customSlot, { |
1625 | 1637 | key: dataKey,
|
| 1638 | + "class": itemClass, |
1626 | 1639 | vnode: defaultSlot,
|
1627 |
| - 'data-key': dataKey, |
1628 |
| - "class": 'virtual-dnd-list-item' |
| 1640 | + 'data-key': dataKey |
1629 | 1641 | }, {
|
1630 | 1642 | "default": function _default() {
|
1631 | 1643 | var _a;
|
|
1635 | 1647 | };
|
1636 | 1648 | }
|
1637 | 1649 | });
|
| 1650 | + |
1638 | 1651 | var getList = function getList(source) {
|
1639 | 1652 | return vue.isRef(source) ? source.value : source;
|
1640 | 1653 | };
|
1641 |
| - var VirtualDragList = vue.defineComponent({ |
| 1654 | + var VirtualList = vue.defineComponent({ |
1642 | 1655 | props: VirtualProps,
|
1643 |
| - emits: ['update:dataSource', 'update:modelValue', 'top', 'bottom', 'drag', 'drop', 'add', 'remove', 'rangeChange'], |
1644 |
| - setup: function setup(props, _ref5) { |
1645 |
| - var emit = _ref5.emit, |
1646 |
| - slots = _ref5.slots, |
1647 |
| - expose = _ref5.expose; |
| 1656 | + emits: ['update:dataSource', 'update:modelValue', 'top', 'bottom', 'drag', 'drop', 'rangeChange'], |
| 1657 | + setup: function setup(props, _ref) { |
| 1658 | + var emit = _ref.emit, |
| 1659 | + slots = _ref.slots, |
| 1660 | + expose = _ref.expose; |
1648 | 1661 | var rangeRef = vue.ref({
|
1649 | 1662 | start: 0,
|
1650 | 1663 | end: props.keeps - 1,
|
|
1656 | 1669 | var listRef = vue.ref([]);
|
1657 | 1670 | var dragging = vue.ref();
|
1658 | 1671 | var lastList = vue.ref([]);
|
1659 |
| - var isHorizontal = vue.computed(function () { |
| 1672 | + var horizontal = vue.computed(function () { |
1660 | 1673 | return props.direction !== 'vertical';
|
1661 | 1674 | });
|
1662 | 1675 | var virtualAttributes = vue.computed(function () {
|
|
1675 | 1688 | var sortable;
|
1676 | 1689 | var uniqueKeys = [];
|
1677 | 1690 | var lastLength = 0;
|
1678 |
| - // git item size by data-key |
1679 | 1691 | function getSize(key) {
|
1680 | 1692 | return virtual.getSize(key);
|
1681 | 1693 | }
|
1682 |
| - // Get the current scroll height |
1683 | 1694 | function getOffset() {
|
1684 | 1695 | return virtual.getOffset();
|
1685 | 1696 | }
|
1686 |
| - // Get client viewport size |
1687 | 1697 | function getClientSize() {
|
1688 | 1698 | return virtual.getClientSize();
|
1689 | 1699 | }
|
1690 |
| - // Get all scroll size |
1691 | 1700 | function getScrollSize() {
|
1692 | 1701 | return virtual.getScrollSize();
|
1693 | 1702 | }
|
|
1697 | 1706 | virtual.scrollToIndex(index);
|
1698 | 1707 | }
|
1699 | 1708 | }
|
1700 |
| - // Scroll to the specified offset |
1701 | 1709 | function scrollToOffset(offset) {
|
1702 | 1710 | virtual.scrollToOffset(offset);
|
1703 | 1711 | }
|
1704 |
| - // Scroll to the specified index position |
1705 | 1712 | function scrollToIndex(index) {
|
1706 | 1713 | virtual.scrollToIndex(index);
|
1707 | 1714 | }
|
1708 |
| - // Scroll to top of list |
1709 | 1715 | function scrollToTop() {
|
1710 | 1716 | scrollToOffset(0);
|
1711 | 1717 | }
|
1712 |
| - // Scroll to bottom of list |
1713 | 1718 | function scrollToBottom() {
|
1714 | 1719 | virtual.scrollToBottom();
|
1715 | 1720 | }
|
|
1747 | 1752 | }
|
1748 | 1753 | }
|
1749 | 1754 | });
|
1750 |
| - // init range |
1751 | 1755 | vue.onBeforeMount(function () {
|
1752 | 1756 | onUpdate();
|
1753 | 1757 | });
|
|
1760 | 1764 | virtual.removeScrollEventListener();
|
1761 | 1765 | });
|
1762 | 1766 | vue.onMounted(function () {
|
1763 |
| - initVirtual(); |
1764 |
| - initSortable(); |
| 1767 | + installVirtual(); |
| 1768 | + installSortable(); |
1765 | 1769 | });
|
1766 | 1770 | vue.onUnmounted(function () {
|
1767 | 1771 | sortable === null || sortable === void 0 ? void 0 : sortable.destroy();
|
|
1791 | 1795 | virtual === null || virtual === void 0 ? void 0 : virtual.option('uniqueKeys', uniqueKeys);
|
1792 | 1796 | sortable === null || sortable === void 0 ? void 0 : sortable.option('uniqueKeys', uniqueKeys);
|
1793 | 1797 | };
|
1794 |
| - var initVirtual = function initVirtual() { |
1795 |
| - virtual = new Virtual({ |
1796 |
| - size: props.size, |
1797 |
| - keeps: props.keeps, |
| 1798 | + var installVirtual = function installVirtual() { |
| 1799 | + virtual = new Virtual(Object.assign(Object.assign({}, virtualAttributes.value), { |
1798 | 1800 | buffer: Math.round(props.keeps / 3),
|
1799 | 1801 | wrapper: wrapRef.value,
|
1800 | 1802 | scroller: props.scroller || rootRef.value,
|
1801 |
| - direction: props.direction, |
1802 | 1803 | uniqueKeys: uniqueKeys,
|
1803 |
| - debounceTime: props.debounceTime, |
1804 |
| - throttleTime: props.throttleTime, |
1805 | 1804 | onScroll: function onScroll(event) {
|
1806 | 1805 | lastLength = 0;
|
1807 | 1806 | if (!!listRef.value.length && event.top) {
|
|
1818 | 1817 | rangeRef.value = range;
|
1819 | 1818 | rangeChanged && emit('rangeChange', range);
|
1820 | 1819 | }
|
1821 |
| - }); |
| 1820 | + })); |
1822 | 1821 | };
|
1823 |
| - var initSortable = function initSortable() { |
| 1822 | + var installSortable = function installSortable() { |
1824 | 1823 | sortable = new Sortable(rootRef.value, Object.assign(Object.assign({}, sortableAttributes.value), {
|
1825 | 1824 | list: listRef.value,
|
1826 | 1825 | uniqueKeys: uniqueKeys,
|
1827 |
| - onAdd: function onAdd(event) { |
1828 |
| - emit('add', event); |
1829 |
| - }, |
1830 |
| - onRemove: function onRemove(event) { |
1831 |
| - emit('remove', event); |
1832 |
| - }, |
1833 | 1826 | onDrag: function onDrag(event) {
|
1834 | 1827 | dragging.value = event.key;
|
1835 | 1828 | if (!props.sortable) {
|
|
1879 | 1872 | updateRange(listRef.value, listRef.value);
|
1880 | 1873 | }
|
1881 | 1874 | };
|
1882 |
| - var getItemStyle = function getItemStyle(dataKey) { |
1883 |
| - if (dataKey == dragging.value) { |
1884 |
| - return { |
1885 |
| - display: 'none' |
| 1875 | + var renderSpacer = function renderSpacer(offset) { |
| 1876 | + if (props.tableMode) { |
| 1877 | + var tdStyle = { |
| 1878 | + padding: 0, |
| 1879 | + margin: 0, |
| 1880 | + border: 0, |
| 1881 | + height: "".concat(offset, "px") |
1886 | 1882 | };
|
| 1883 | + return vue.h('tr', {}, [vue.h('td', { |
| 1884 | + style: tdStyle |
| 1885 | + })]); |
1887 | 1886 | }
|
1888 |
| - return {}; |
| 1887 | + return null; |
1889 | 1888 | };
|
1890 | 1889 | var renderItems = function renderItems() {
|
1891 | 1890 | var renders = [];
|
1892 | 1891 | var _rangeRef$value = rangeRef.value,
|
1893 | 1892 | start = _rangeRef$value.start,
|
1894 |
| - end = _rangeRef$value.end; |
1895 |
| - var sizeKey = props.direction === 'vertical' ? 'offsetHeight' : 'offsetWidth'; |
| 1893 | + end = _rangeRef$value.end, |
| 1894 | + front = _rangeRef$value.front, |
| 1895 | + behind = _rangeRef$value.behind; |
| 1896 | + var sizeKey = horizontal.value ? 'offsetWidth' : 'offsetHeight'; |
| 1897 | + renders.push(renderSpacer(front)); |
1896 | 1898 | var _loop = function _loop(index) {
|
1897 | 1899 | var record = listRef.value[index];
|
1898 | 1900 | if (record) {
|
1899 | 1901 | var dataKey = getDataKey(record, props.dataKey);
|
1900 |
| - renders.push(slots.item ? vue.h(Items, { |
| 1902 | + renders.push(slots.item ? vue.h(Item, { |
1901 | 1903 | key: dataKey,
|
1902 |
| - "class": 'virtual-dnd-list-item', |
1903 |
| - style: getItemStyle(dataKey), |
| 1904 | + "class": props.itemClass, |
| 1905 | + style: dataKey == dragging.value && { |
| 1906 | + display: 'none' |
| 1907 | + }, |
1904 | 1908 | dataKey: dataKey,
|
1905 | 1909 | sizeKey: sizeKey,
|
1906 | 1910 | onResize: onItemResized
|
|
1919 | 1923 | for (var index = start; index <= end; index++) {
|
1920 | 1924 | _loop(index);
|
1921 | 1925 | }
|
| 1926 | + renders.push(renderSpacer(behind)); |
1922 | 1927 | return renders;
|
1923 | 1928 | };
|
1924 | 1929 | return function () {
|
1925 | 1930 | var _rangeRef$value2 = rangeRef.value,
|
1926 | 1931 | front = _rangeRef$value2.front,
|
1927 | 1932 | behind = _rangeRef$value2.behind;
|
1928 |
| - var rootTag = props.rootTag, |
| 1933 | + var tableMode = props.tableMode, |
| 1934 | + rootTag = props.rootTag, |
1929 | 1935 | wrapTag = props.wrapTag,
|
1930 | 1936 | scroller = props.scroller,
|
1931 | 1937 | wrapClass = props.wrapClass,
|
1932 | 1938 | wrapStyle = props.wrapStyle;
|
1933 |
| - var padding = isHorizontal.value ? "0px ".concat(behind, "px 0px ").concat(front, "px") : "".concat(front, "px 0px ").concat(behind, "px"); |
1934 |
| - return vue.h(rootTag, { |
| 1939 | + var padding = horizontal.value ? "0 ".concat(behind, "px 0 ").concat(front, "px") : "".concat(front, "px 0 ").concat(behind, "px"); |
| 1940 | + var overflow = horizontal.value ? 'auto hidden' : 'hidden auto'; |
| 1941 | + var container = tableMode ? 'table' : rootTag; |
| 1942 | + var wrapper = tableMode ? 'tbody' : wrapTag; |
| 1943 | + return vue.h(container, { |
1935 | 1944 | ref: rootRef,
|
1936 |
| - style: !scroller && { |
1937 |
| - overflow: isHorizontal.value ? 'auto hidden' : 'hidden auto' |
| 1945 | + style: !scroller && !tableMode && { |
| 1946 | + overflow: overflow |
1938 | 1947 | }
|
1939 | 1948 | }, {
|
1940 | 1949 | "default": function _default() {
|
1941 | 1950 | var _a, _b;
|
1942 |
| - return [(_a = slots.header) === null || _a === void 0 ? void 0 : _a.call(slots), vue.h(wrapTag, { |
| 1951 | + return [(_a = slots.header) === null || _a === void 0 ? void 0 : _a.call(slots), vue.h(wrapper, { |
1943 | 1952 | ref: wrapRef,
|
1944 | 1953 | "class": wrapClass,
|
1945 | 1954 | style: Object.assign(Object.assign({}, wrapStyle), {
|
1946 |
| - padding: padding |
| 1955 | + padding: !tableMode && padding |
1947 | 1956 | })
|
1948 | 1957 | }, {
|
1949 | 1958 | "default": function _default() {
|
|
1956 | 1965 | }
|
1957 | 1966 | });
|
1958 | 1967 |
|
1959 |
| - return VirtualDragList; |
| 1968 | + return VirtualList; |
1960 | 1969 |
|
1961 | 1970 | }));
|
0 commit comments