|
1 | 1 | /**! |
2 | | - * Sortable 1.13.0 |
| 2 | + * Sortable 1.14.0 |
3 | 3 | * @author RubaXa <[email protected]> |
4 | 4 | * @author owenm <[email protected]> |
5 | 5 | * @license MIT |
|
8 | 8 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : |
9 | 9 | typeof define === 'function' && define.amd ? define(factory) : |
10 | 10 | (global = global || self, global.Sortable = factory()); |
11 | | -}(this, function () { 'use strict'; |
| 11 | +}(this, (function () { 'use strict'; |
| 12 | + |
| 13 | + function ownKeys(object, enumerableOnly) { |
| 14 | + var keys = Object.keys(object); |
| 15 | + |
| 16 | + if (Object.getOwnPropertySymbols) { |
| 17 | + var symbols = Object.getOwnPropertySymbols(object); |
| 18 | + |
| 19 | + if (enumerableOnly) { |
| 20 | + symbols = symbols.filter(function (sym) { |
| 21 | + return Object.getOwnPropertyDescriptor(object, sym).enumerable; |
| 22 | + }); |
| 23 | + } |
| 24 | + |
| 25 | + keys.push.apply(keys, symbols); |
| 26 | + } |
| 27 | + |
| 28 | + return keys; |
| 29 | + } |
| 30 | + |
| 31 | + function _objectSpread2(target) { |
| 32 | + for (var i = 1; i < arguments.length; i++) { |
| 33 | + var source = arguments[i] != null ? arguments[i] : {}; |
| 34 | + |
| 35 | + if (i % 2) { |
| 36 | + ownKeys(Object(source), true).forEach(function (key) { |
| 37 | + _defineProperty(target, key, source[key]); |
| 38 | + }); |
| 39 | + } else if (Object.getOwnPropertyDescriptors) { |
| 40 | + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); |
| 41 | + } else { |
| 42 | + ownKeys(Object(source)).forEach(function (key) { |
| 43 | + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); |
| 44 | + }); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + return target; |
| 49 | + } |
12 | 50 |
|
13 | 51 | function _typeof(obj) { |
| 52 | + "@babel/helpers - typeof"; |
| 53 | + |
14 | 54 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { |
15 | 55 | _typeof = function (obj) { |
16 | 56 | return typeof obj; |
|
57 | 97 | return _extends.apply(this, arguments); |
58 | 98 | } |
59 | 99 |
|
60 | | - function _objectSpread(target) { |
61 | | - for (var i = 1; i < arguments.length; i++) { |
62 | | - var source = arguments[i] != null ? arguments[i] : {}; |
63 | | - var ownKeys = Object.keys(source); |
64 | | - |
65 | | - if (typeof Object.getOwnPropertySymbols === 'function') { |
66 | | - ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { |
67 | | - return Object.getOwnPropertyDescriptor(source, sym).enumerable; |
68 | | - })); |
69 | | - } |
70 | | - |
71 | | - ownKeys.forEach(function (key) { |
72 | | - _defineProperty(target, key, source[key]); |
73 | | - }); |
74 | | - } |
75 | | - |
76 | | - return target; |
77 | | - } |
78 | | - |
79 | 100 | function _objectWithoutPropertiesLoose(source, excluded) { |
80 | 101 | if (source == null) return {}; |
81 | 102 | var target = {}; |
|
113 | 134 | } |
114 | 135 |
|
115 | 136 | function _toConsumableArray(arr) { |
116 | | - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); |
| 137 | + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); |
117 | 138 | } |
118 | 139 |
|
119 | 140 | function _arrayWithoutHoles(arr) { |
120 | | - if (Array.isArray(arr)) { |
121 | | - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; |
122 | | - |
123 | | - return arr2; |
124 | | - } |
| 141 | + if (Array.isArray(arr)) return _arrayLikeToArray(arr); |
125 | 142 | } |
126 | 143 |
|
127 | 144 | function _iterableToArray(iter) { |
128 | | - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); |
| 145 | + if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); |
| 146 | + } |
| 147 | + |
| 148 | + function _unsupportedIterableToArray(o, minLen) { |
| 149 | + if (!o) return; |
| 150 | + if (typeof o === "string") return _arrayLikeToArray(o, minLen); |
| 151 | + var n = Object.prototype.toString.call(o).slice(8, -1); |
| 152 | + if (n === "Object" && o.constructor) n = o.constructor.name; |
| 153 | + if (n === "Map" || n === "Set") return Array.from(o); |
| 154 | + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); |
| 155 | + } |
| 156 | + |
| 157 | + function _arrayLikeToArray(arr, len) { |
| 158 | + if (len == null || len > arr.length) len = arr.length; |
| 159 | + |
| 160 | + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; |
| 161 | + |
| 162 | + return arr2; |
129 | 163 | } |
130 | 164 |
|
131 | 165 | function _nonIterableSpread() { |
132 | | - throw new TypeError("Invalid attempt to spread non-iterable instance"); |
| 166 | + throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
133 | 167 | } |
134 | 168 |
|
135 | | - var version = "1.13.0"; |
| 169 | + var version = "1.14.0"; |
136 | 170 |
|
137 | 171 | function userAgent(pattern) { |
138 | 172 | if (typeof window !== 'undefined' && window.navigator) { |
139 | | - return !! |
140 | | - /*@__PURE__*/ |
141 | | - navigator.userAgent.match(pattern); |
| 173 | + return !! /*@__PURE__*/navigator.userAgent.match(pattern); |
142 | 174 | } |
143 | 175 | } |
144 | 176 |
|
|
419 | 451 | */ |
420 | 452 |
|
421 | 453 |
|
422 | | - function getChild(el, childNum, options) { |
| 454 | + function getChild(el, childNum, options, includeDragEl) { |
423 | 455 | var currentChild = 0, |
424 | 456 | i = 0, |
425 | 457 | children = el.children; |
426 | 458 |
|
427 | 459 | while (i < children.length) { |
428 | | - if (children[i].style.display !== 'none' && children[i] !== Sortable.ghost && children[i] !== Sortable.dragged && closest(children[i], options.draggable, el, false)) { |
| 460 | + if (children[i].style.display !== 'none' && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false)) { |
429 | 461 | if (currentChild === childNum) { |
430 | 462 | return children[i]; |
431 | 463 | } |
|
643 | 675 | rect: getRect(child) |
644 | 676 | }); |
645 | 677 |
|
646 | | - var fromRect = _objectSpread({}, animationStates[animationStates.length - 1].rect); // If animating: compensate for current animation |
| 678 | + var fromRect = _objectSpread2({}, animationStates[animationStates.length - 1].rect); // If animating: compensate for current animation |
647 | 679 |
|
648 | 680 |
|
649 | 681 | if (child.thisAnimationDuration) { |
|
813 | 845 | if (!sortable[plugin.pluginName]) return; // Fire global events if it exists in this sortable |
814 | 846 |
|
815 | 847 | if (sortable[plugin.pluginName][eventNameGlobal]) { |
816 | | - sortable[plugin.pluginName][eventNameGlobal](_objectSpread({ |
| 848 | + sortable[plugin.pluginName][eventNameGlobal](_objectSpread2({ |
817 | 849 | sortable: sortable |
818 | 850 | }, evt)); |
819 | 851 | } // Only fire plugin event if plugin is enabled in this sortable, |
820 | 852 | // and plugin has event defined |
821 | 853 |
|
822 | 854 |
|
823 | 855 | if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) { |
824 | | - sortable[plugin.pluginName][eventName](_objectSpread({ |
| 856 | + sortable[plugin.pluginName][eventName](_objectSpread2({ |
825 | 857 | sortable: sortable |
826 | 858 | }, evt)); |
827 | 859 | } |
|
913 | 945 | evt.originalEvent = originalEvent; |
914 | 946 | evt.pullMode = putSortable ? putSortable.lastPutMode : undefined; |
915 | 947 |
|
916 | | - var allEventProperties = _objectSpread({}, extraEventProperties, PluginManager.getEventProperties(name, sortable)); |
| 948 | + var allEventProperties = _objectSpread2(_objectSpread2({}, extraEventProperties), PluginManager.getEventProperties(name, sortable)); |
917 | 949 |
|
918 | 950 | for (var option in allEventProperties) { |
919 | 951 | evt[option] = allEventProperties[option]; |
|
928 | 960 | } |
929 | 961 | } |
930 | 962 |
|
| 963 | + var _excluded = ["evt"]; |
| 964 | + |
931 | 965 | var pluginEvent = function pluginEvent(eventName, sortable) { |
932 | 966 | var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, |
933 | 967 | originalEvent = _ref.evt, |
934 | | - data = _objectWithoutProperties(_ref, ["evt"]); |
| 968 | + data = _objectWithoutProperties(_ref, _excluded); |
935 | 969 |
|
936 | | - PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread({ |
| 970 | + PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread2({ |
937 | 971 | dragEl: dragEl, |
938 | 972 | parentEl: parentEl, |
939 | 973 | ghostEl: ghostEl, |
|
969 | 1003 | }; |
970 | 1004 |
|
971 | 1005 | function _dispatchEvent(info) { |
972 | | - dispatchEvent(_objectSpread({ |
| 1006 | + dispatchEvent(_objectSpread2({ |
973 | 1007 | putSortable: putSortable, |
974 | 1008 | cloneEl: cloneEl, |
975 | 1009 | targetEl: dragEl, |
|
1078 | 1112 | _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) { |
1079 | 1113 | var ret; |
1080 | 1114 | sortables.some(function (sortable) { |
1081 | | - if (lastChild(sortable)) return; |
| 1115 | + var threshold = sortable[expando].options.emptyInsertThreshold; |
| 1116 | + if (!threshold || lastChild(sortable)) return; |
1082 | 1117 | var rect = getRect(sortable), |
1083 | | - threshold = sortable[expando].options.emptyInsertThreshold, |
1084 | 1118 | insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold, |
1085 | 1119 | insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold; |
1086 | 1120 |
|
1087 | | - if (threshold && insideHorizontally && insideVertically) { |
| 1121 | + if (insideHorizontally && insideVertically) { |
1088 | 1122 | return ret = sortable; |
1089 | 1123 | } |
1090 | 1124 | }); |
|
1835 | 1869 | if (_silent) return; |
1836 | 1870 |
|
1837 | 1871 | function dragOverEvent(name, extra) { |
1838 | | - pluginEvent(name, _this, _objectSpread({ |
| 1872 | + pluginEvent(name, _this, _objectSpread2({ |
1839 | 1873 | evt: evt, |
1840 | 1874 | isOwner: isOwner, |
1841 | 1875 | axis: vertical ? 'vertical' : 'horizontal', |
|
1952 | 1986 |
|
1953 | 1987 | ignoreNextClick = false; |
1954 | 1988 |
|
1955 | | - if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list |
| 1989 | + if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list |
1956 | 1990 | : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) { |
1957 | 1991 | vertical = this._getDirection(evt, target) === 'vertical'; |
1958 | 1992 | dragRect = getRect(dragEl); |
|
1982 | 2016 | var elLastChild = lastChild(el, options.draggable); |
1983 | 2017 |
|
1984 | 2018 | if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) { |
| 2019 | + // Insert to end of list |
1985 | 2020 | // If already at end of list: Do not insert |
1986 | 2021 | if (elLastChild === dragEl) { |
1987 | 2022 | return completed(false); |
1988 | | - } // assign target only if condition is true |
| 2023 | + } // if there is a last element, it is the target |
1989 | 2024 |
|
1990 | 2025 |
|
1991 | 2026 | if (elLastChild && el === evt.target) { |
|
2001 | 2036 | el.appendChild(dragEl); |
2002 | 2037 | parentEl = el; // actualization |
2003 | 2038 |
|
| 2039 | + changed(); |
| 2040 | + return completed(true); |
| 2041 | + } |
| 2042 | + } else if (elLastChild && _ghostIsFirst(evt, vertical, this)) { |
| 2043 | + // Insert to start of list |
| 2044 | + var firstChild = getChild(el, 0, options, true); |
| 2045 | + |
| 2046 | + if (firstChild === dragEl) { |
| 2047 | + return completed(false); |
| 2048 | + } |
| 2049 | + |
| 2050 | + target = firstChild; |
| 2051 | + targetRect = getRect(target); |
| 2052 | + |
| 2053 | + if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, false) !== false) { |
| 2054 | + capture(); |
| 2055 | + el.insertBefore(dragEl, firstChild); |
| 2056 | + parentEl = el; // actualization |
| 2057 | + |
2004 | 2058 | changed(); |
2005 | 2059 | return completed(true); |
2006 | 2060 | } |
|
2514 | 2568 | _silent = false; |
2515 | 2569 | } |
2516 | 2570 |
|
| 2571 | + function _ghostIsFirst(evt, vertical, sortable) { |
| 2572 | + var rect = getRect(getChild(sortable.el, 0, sortable.options, true)); |
| 2573 | + var spacer = 10; |
| 2574 | + return vertical ? evt.clientX < rect.left - spacer || evt.clientY < rect.top && evt.clientX < rect.right : evt.clientY < rect.top - spacer || evt.clientY < rect.bottom && evt.clientX < rect.left; |
| 2575 | + } |
| 2576 | + |
2517 | 2577 | function _ghostIsLast(evt, vertical, sortable) { |
2518 | 2578 | var rect = getRect(lastChild(sortable.el, sortable.options.draggable)); |
2519 | 2579 | var spacer = 10; |
|
2674 | 2734 | throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin)); |
2675 | 2735 | } |
2676 | 2736 |
|
2677 | | - if (plugin.utils) Sortable.utils = _objectSpread({}, Sortable.utils, plugin.utils); |
| 2737 | + if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils); |
2678 | 2738 | PluginManager.mount(plugin); |
2679 | 2739 | }); |
2680 | 2740 | }; |
|
2705 | 2765 | function AutoScroll() { |
2706 | 2766 | this.defaults = { |
2707 | 2767 | scroll: true, |
| 2768 | + forceAutoScrollFallback: false, |
2708 | 2769 | scrollSensitivity: 30, |
2709 | 2770 | scrollSpeed: 10, |
2710 | 2771 | bubbleScroll: true |
|
2772 | 2833 | // MACOS Safari does not have autoscroll, |
2773 | 2834 | // Firefox and Chrome are good |
2774 | 2835 |
|
2775 | | - if (fallback || Edge || IE11OrLess || Safari) { |
| 2836 | + if (fallback || this.options.forceAutoScrollFallback || Edge || IE11OrLess || Safari) { |
2776 | 2837 | autoScroll(evt, this.options, elem, fallback); // Listener for pointer element change |
2777 | 2838 |
|
2778 | 2839 | var ogElemScroller = getParentAutoScrollElement(elem, true); |
|
3472 | 3533 |
|
3473 | 3534 |
|
3474 | 3535 | if (dragStarted && this.isMultiDrag) { |
3475 | | - // Do not "unfold" after around dragEl if reverted |
| 3536 | + folding = false; // Do not "unfold" after around dragEl if reverted |
| 3537 | + |
3476 | 3538 | if ((parentEl[expando].options.sort || parentEl !== rootEl) && multiDragElements.length > 1) { |
3477 | 3539 | var dragRect = getRect(dragEl$1), |
3478 | 3540 | multiDragIndex = index(dragEl$1, ':not(.' + this.options.selectedClass + ')'); |
|
3718 | 3780 |
|
3719 | 3781 | return Sortable; |
3720 | 3782 |
|
3721 | | -})); |
| 3783 | +}))); |
0 commit comments