Skip to content

Commit 4684991

Browse files
committed
1.14.0
1 parent 101b92e commit 4684991

7 files changed

+11374
-2707
lines changed

Sortable.js

Lines changed: 114 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**!
2-
* Sortable 1.13.0
2+
* Sortable 1.14.0
33
* @author RubaXa <[email protected]>
44
* @author owenm <[email protected]>
55
* @license MIT
@@ -8,9 +8,49 @@
88
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
99
typeof define === 'function' && define.amd ? define(factory) :
1010
(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+
}
1250

1351
function _typeof(obj) {
52+
"@babel/helpers - typeof";
53+
1454
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
1555
_typeof = function (obj) {
1656
return typeof obj;
@@ -57,25 +97,6 @@
5797
return _extends.apply(this, arguments);
5898
}
5999

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-
79100
function _objectWithoutPropertiesLoose(source, excluded) {
80101
if (source == null) return {};
81102
var target = {};
@@ -113,32 +134,43 @@
113134
}
114135

115136
function _toConsumableArray(arr) {
116-
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
137+
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
117138
}
118139

119140
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);
125142
}
126143

127144
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;
129163
}
130164

131165
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.");
133167
}
134168

135-
var version = "1.13.0";
169+
var version = "1.14.0";
136170

137171
function userAgent(pattern) {
138172
if (typeof window !== 'undefined' && window.navigator) {
139-
return !!
140-
/*@__PURE__*/
141-
navigator.userAgent.match(pattern);
173+
return !! /*@__PURE__*/navigator.userAgent.match(pattern);
142174
}
143175
}
144176

@@ -419,13 +451,13 @@
419451
*/
420452

421453

422-
function getChild(el, childNum, options) {
454+
function getChild(el, childNum, options, includeDragEl) {
423455
var currentChild = 0,
424456
i = 0,
425457
children = el.children;
426458

427459
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)) {
429461
if (currentChild === childNum) {
430462
return children[i];
431463
}
@@ -643,7 +675,7 @@
643675
rect: getRect(child)
644676
});
645677

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
647679

648680

649681
if (child.thisAnimationDuration) {
@@ -813,15 +845,15 @@
813845
if (!sortable[plugin.pluginName]) return; // Fire global events if it exists in this sortable
814846

815847
if (sortable[plugin.pluginName][eventNameGlobal]) {
816-
sortable[plugin.pluginName][eventNameGlobal](_objectSpread({
848+
sortable[plugin.pluginName][eventNameGlobal](_objectSpread2({
817849
sortable: sortable
818850
}, evt));
819851
} // Only fire plugin event if plugin is enabled in this sortable,
820852
// and plugin has event defined
821853

822854

823855
if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) {
824-
sortable[plugin.pluginName][eventName](_objectSpread({
856+
sortable[plugin.pluginName][eventName](_objectSpread2({
825857
sortable: sortable
826858
}, evt));
827859
}
@@ -913,7 +945,7 @@
913945
evt.originalEvent = originalEvent;
914946
evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
915947

916-
var allEventProperties = _objectSpread({}, extraEventProperties, PluginManager.getEventProperties(name, sortable));
948+
var allEventProperties = _objectSpread2(_objectSpread2({}, extraEventProperties), PluginManager.getEventProperties(name, sortable));
917949

918950
for (var option in allEventProperties) {
919951
evt[option] = allEventProperties[option];
@@ -928,12 +960,14 @@
928960
}
929961
}
930962

963+
var _excluded = ["evt"];
964+
931965
var pluginEvent = function pluginEvent(eventName, sortable) {
932966
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
933967
originalEvent = _ref.evt,
934-
data = _objectWithoutProperties(_ref, ["evt"]);
968+
data = _objectWithoutProperties(_ref, _excluded);
935969

936-
PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread({
970+
PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread2({
937971
dragEl: dragEl,
938972
parentEl: parentEl,
939973
ghostEl: ghostEl,
@@ -969,7 +1003,7 @@
9691003
};
9701004

9711005
function _dispatchEvent(info) {
972-
dispatchEvent(_objectSpread({
1006+
dispatchEvent(_objectSpread2({
9731007
putSortable: putSortable,
9741008
cloneEl: cloneEl,
9751009
targetEl: dragEl,
@@ -1078,13 +1112,13 @@
10781112
_detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
10791113
var ret;
10801114
sortables.some(function (sortable) {
1081-
if (lastChild(sortable)) return;
1115+
var threshold = sortable[expando].options.emptyInsertThreshold;
1116+
if (!threshold || lastChild(sortable)) return;
10821117
var rect = getRect(sortable),
1083-
threshold = sortable[expando].options.emptyInsertThreshold,
10841118
insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold,
10851119
insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold;
10861120

1087-
if (threshold && insideHorizontally && insideVertically) {
1121+
if (insideHorizontally && insideVertically) {
10881122
return ret = sortable;
10891123
}
10901124
});
@@ -1835,7 +1869,7 @@
18351869
if (_silent) return;
18361870

18371871
function dragOverEvent(name, extra) {
1838-
pluginEvent(name, _this, _objectSpread({
1872+
pluginEvent(name, _this, _objectSpread2({
18391873
evt: evt,
18401874
isOwner: isOwner,
18411875
axis: vertical ? 'vertical' : 'horizontal',
@@ -1952,7 +1986,7 @@
19521986

19531987
ignoreNextClick = false;
19541988

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
19561990
: putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) {
19571991
vertical = this._getDirection(evt, target) === 'vertical';
19581992
dragRect = getRect(dragEl);
@@ -1982,10 +2016,11 @@
19822016
var elLastChild = lastChild(el, options.draggable);
19832017

19842018
if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
2019+
// Insert to end of list
19852020
// If already at end of list: Do not insert
19862021
if (elLastChild === dragEl) {
19872022
return completed(false);
1988-
} // assign target only if condition is true
2023+
} // if there is a last element, it is the target
19892024

19902025

19912026
if (elLastChild && el === evt.target) {
@@ -2001,6 +2036,25 @@
20012036
el.appendChild(dragEl);
20022037
parentEl = el; // actualization
20032038

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+
20042058
changed();
20052059
return completed(true);
20062060
}
@@ -2514,6 +2568,12 @@
25142568
_silent = false;
25152569
}
25162570

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+
25172577
function _ghostIsLast(evt, vertical, sortable) {
25182578
var rect = getRect(lastChild(sortable.el, sortable.options.draggable));
25192579
var spacer = 10;
@@ -2674,7 +2734,7 @@
26742734
throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin));
26752735
}
26762736

2677-
if (plugin.utils) Sortable.utils = _objectSpread({}, Sortable.utils, plugin.utils);
2737+
if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils);
26782738
PluginManager.mount(plugin);
26792739
});
26802740
};
@@ -2705,6 +2765,7 @@
27052765
function AutoScroll() {
27062766
this.defaults = {
27072767
scroll: true,
2768+
forceAutoScrollFallback: false,
27082769
scrollSensitivity: 30,
27092770
scrollSpeed: 10,
27102771
bubbleScroll: true
@@ -2772,7 +2833,7 @@
27722833
// MACOS Safari does not have autoscroll,
27732834
// Firefox and Chrome are good
27742835

2775-
if (fallback || Edge || IE11OrLess || Safari) {
2836+
if (fallback || this.options.forceAutoScrollFallback || Edge || IE11OrLess || Safari) {
27762837
autoScroll(evt, this.options, elem, fallback); // Listener for pointer element change
27772838

27782839
var ogElemScroller = getParentAutoScrollElement(elem, true);
@@ -3472,7 +3533,8 @@
34723533

34733534

34743535
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+
34763538
if ((parentEl[expando].options.sort || parentEl !== rootEl) && multiDragElements.length > 1) {
34773539
var dragRect = getRect(dragEl$1),
34783540
multiDragIndex = index(dragEl$1, ':not(.' + this.options.selectedClass + ')');
@@ -3718,4 +3780,4 @@
37183780

37193781
return Sortable;
37203782

3721-
}));
3783+
})));

Sortable.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)