sortablejs 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,10 +1,50 @@
1
1
  /**!
2
- * Sortable 1.13.0
2
+ * Sortable 1.14.0
3
3
  * @author RubaXa <trash@rubaxa.org>
4
4
  * @author owenm <owen23355@gmail.com>
5
5
  * @license MIT
6
6
  */
7
+ function ownKeys(object, enumerableOnly) {
8
+ var keys = Object.keys(object);
9
+
10
+ if (Object.getOwnPropertySymbols) {
11
+ var symbols = Object.getOwnPropertySymbols(object);
12
+
13
+ if (enumerableOnly) {
14
+ symbols = symbols.filter(function (sym) {
15
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
16
+ });
17
+ }
18
+
19
+ keys.push.apply(keys, symbols);
20
+ }
21
+
22
+ return keys;
23
+ }
24
+
25
+ function _objectSpread2(target) {
26
+ for (var i = 1; i < arguments.length; i++) {
27
+ var source = arguments[i] != null ? arguments[i] : {};
28
+
29
+ if (i % 2) {
30
+ ownKeys(Object(source), true).forEach(function (key) {
31
+ _defineProperty(target, key, source[key]);
32
+ });
33
+ } else if (Object.getOwnPropertyDescriptors) {
34
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
35
+ } else {
36
+ ownKeys(Object(source)).forEach(function (key) {
37
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
38
+ });
39
+ }
40
+ }
41
+
42
+ return target;
43
+ }
44
+
7
45
  function _typeof(obj) {
46
+ "@babel/helpers - typeof";
47
+
8
48
  if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
9
49
  _typeof = function (obj) {
10
50
  return typeof obj;
@@ -51,25 +91,6 @@ function _extends() {
51
91
  return _extends.apply(this, arguments);
52
92
  }
53
93
 
54
- function _objectSpread(target) {
55
- for (var i = 1; i < arguments.length; i++) {
56
- var source = arguments[i] != null ? arguments[i] : {};
57
- var ownKeys = Object.keys(source);
58
-
59
- if (typeof Object.getOwnPropertySymbols === 'function') {
60
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
61
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
62
- }));
63
- }
64
-
65
- ownKeys.forEach(function (key) {
66
- _defineProperty(target, key, source[key]);
67
- });
68
- }
69
-
70
- return target;
71
- }
72
-
73
94
  function _objectWithoutPropertiesLoose(source, excluded) {
74
95
  if (source == null) return {};
75
96
  var target = {};
@@ -107,32 +128,43 @@ function _objectWithoutProperties(source, excluded) {
107
128
  }
108
129
 
109
130
  function _toConsumableArray(arr) {
110
- return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
131
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
111
132
  }
112
133
 
113
134
  function _arrayWithoutHoles(arr) {
114
- if (Array.isArray(arr)) {
115
- for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
116
-
117
- return arr2;
118
- }
135
+ if (Array.isArray(arr)) return _arrayLikeToArray(arr);
119
136
  }
120
137
 
121
138
  function _iterableToArray(iter) {
122
- if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
139
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
140
+ }
141
+
142
+ function _unsupportedIterableToArray(o, minLen) {
143
+ if (!o) return;
144
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
145
+ var n = Object.prototype.toString.call(o).slice(8, -1);
146
+ if (n === "Object" && o.constructor) n = o.constructor.name;
147
+ if (n === "Map" || n === "Set") return Array.from(o);
148
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
149
+ }
150
+
151
+ function _arrayLikeToArray(arr, len) {
152
+ if (len == null || len > arr.length) len = arr.length;
153
+
154
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
155
+
156
+ return arr2;
123
157
  }
124
158
 
125
159
  function _nonIterableSpread() {
126
- throw new TypeError("Invalid attempt to spread non-iterable instance");
160
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
127
161
  }
128
162
 
129
- var version = "1.13.0";
163
+ var version = "1.14.0";
130
164
 
131
165
  function userAgent(pattern) {
132
166
  if (typeof window !== 'undefined' && window.navigator) {
133
- return !!
134
- /*@__PURE__*/
135
- navigator.userAgent.match(pattern);
167
+ return !! /*@__PURE__*/navigator.userAgent.match(pattern);
136
168
  }
137
169
  }
138
170
 
@@ -413,13 +445,13 @@ function isScrolledPast(el, elSide, parentSide) {
413
445
  */
414
446
 
415
447
 
416
- function getChild(el, childNum, options) {
448
+ function getChild(el, childNum, options, includeDragEl) {
417
449
  var currentChild = 0,
418
450
  i = 0,
419
451
  children = el.children;
420
452
 
421
453
  while (i < children.length) {
422
- if (children[i].style.display !== 'none' && children[i] !== Sortable.ghost && children[i] !== Sortable.dragged && closest(children[i], options.draggable, el, false)) {
454
+ if (children[i].style.display !== 'none' && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false)) {
423
455
  if (currentChild === childNum) {
424
456
  return children[i];
425
457
  }
@@ -637,7 +669,7 @@ function AnimationStateManager() {
637
669
  rect: getRect(child)
638
670
  });
639
671
 
640
- var fromRect = _objectSpread({}, animationStates[animationStates.length - 1].rect); // If animating: compensate for current animation
672
+ var fromRect = _objectSpread2({}, animationStates[animationStates.length - 1].rect); // If animating: compensate for current animation
641
673
 
642
674
 
643
675
  if (child.thisAnimationDuration) {
@@ -807,7 +839,7 @@ var PluginManager = {
807
839
  if (!sortable[plugin.pluginName]) return; // Fire global events if it exists in this sortable
808
840
 
809
841
  if (sortable[plugin.pluginName][eventNameGlobal]) {
810
- sortable[plugin.pluginName][eventNameGlobal](_objectSpread({
842
+ sortable[plugin.pluginName][eventNameGlobal](_objectSpread2({
811
843
  sortable: sortable
812
844
  }, evt));
813
845
  } // Only fire plugin event if plugin is enabled in this sortable,
@@ -815,7 +847,7 @@ var PluginManager = {
815
847
 
816
848
 
817
849
  if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) {
818
- sortable[plugin.pluginName][eventName](_objectSpread({
850
+ sortable[plugin.pluginName][eventName](_objectSpread2({
819
851
  sortable: sortable
820
852
  }, evt));
821
853
  }
@@ -907,7 +939,7 @@ function dispatchEvent(_ref) {
907
939
  evt.originalEvent = originalEvent;
908
940
  evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
909
941
 
910
- var allEventProperties = _objectSpread({}, extraEventProperties, PluginManager.getEventProperties(name, sortable));
942
+ var allEventProperties = _objectSpread2(_objectSpread2({}, extraEventProperties), PluginManager.getEventProperties(name, sortable));
911
943
 
912
944
  for (var option in allEventProperties) {
913
945
  evt[option] = allEventProperties[option];
@@ -922,12 +954,14 @@ function dispatchEvent(_ref) {
922
954
  }
923
955
  }
924
956
 
957
+ var _excluded = ["evt"];
958
+
925
959
  var pluginEvent = function pluginEvent(eventName, sortable) {
926
960
  var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
927
961
  originalEvent = _ref.evt,
928
- data = _objectWithoutProperties(_ref, ["evt"]);
962
+ data = _objectWithoutProperties(_ref, _excluded);
929
963
 
930
- PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread({
964
+ PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread2({
931
965
  dragEl: dragEl,
932
966
  parentEl: parentEl,
933
967
  ghostEl: ghostEl,
@@ -963,7 +997,7 @@ var pluginEvent = function pluginEvent(eventName, sortable) {
963
997
  };
964
998
 
965
999
  function _dispatchEvent(info) {
966
- dispatchEvent(_objectSpread({
1000
+ dispatchEvent(_objectSpread2({
967
1001
  putSortable: putSortable,
968
1002
  cloneEl: cloneEl,
969
1003
  targetEl: dragEl,
@@ -1072,13 +1106,13 @@ supportDraggable = documentExists && !ChromeForAndroid && !IOS && 'draggable' in
1072
1106
  _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
1073
1107
  var ret;
1074
1108
  sortables.some(function (sortable) {
1075
- if (lastChild(sortable)) return;
1109
+ var threshold = sortable[expando].options.emptyInsertThreshold;
1110
+ if (!threshold || lastChild(sortable)) return;
1076
1111
  var rect = getRect(sortable),
1077
- threshold = sortable[expando].options.emptyInsertThreshold,
1078
1112
  insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold,
1079
1113
  insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold;
1080
1114
 
1081
- if (threshold && insideHorizontally && insideVertically) {
1115
+ if (insideHorizontally && insideVertically) {
1082
1116
  return ret = sortable;
1083
1117
  }
1084
1118
  });
@@ -1829,7 +1863,7 @@ Sortable.prototype =
1829
1863
  if (_silent) return;
1830
1864
 
1831
1865
  function dragOverEvent(name, extra) {
1832
- pluginEvent(name, _this, _objectSpread({
1866
+ pluginEvent(name, _this, _objectSpread2({
1833
1867
  evt: evt,
1834
1868
  isOwner: isOwner,
1835
1869
  axis: vertical ? 'vertical' : 'horizontal',
@@ -1946,7 +1980,7 @@ Sortable.prototype =
1946
1980
 
1947
1981
  ignoreNextClick = false;
1948
1982
 
1949
- if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list
1983
+ if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list
1950
1984
  : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) {
1951
1985
  vertical = this._getDirection(evt, target) === 'vertical';
1952
1986
  dragRect = getRect(dragEl);
@@ -1976,10 +2010,11 @@ Sortable.prototype =
1976
2010
  var elLastChild = lastChild(el, options.draggable);
1977
2011
 
1978
2012
  if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
2013
+ // Insert to end of list
1979
2014
  // If already at end of list: Do not insert
1980
2015
  if (elLastChild === dragEl) {
1981
2016
  return completed(false);
1982
- } // assign target only if condition is true
2017
+ } // if there is a last element, it is the target
1983
2018
 
1984
2019
 
1985
2020
  if (elLastChild && el === evt.target) {
@@ -1995,6 +2030,25 @@ Sortable.prototype =
1995
2030
  el.appendChild(dragEl);
1996
2031
  parentEl = el; // actualization
1997
2032
 
2033
+ changed();
2034
+ return completed(true);
2035
+ }
2036
+ } else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
2037
+ // Insert to start of list
2038
+ var firstChild = getChild(el, 0, options, true);
2039
+
2040
+ if (firstChild === dragEl) {
2041
+ return completed(false);
2042
+ }
2043
+
2044
+ target = firstChild;
2045
+ targetRect = getRect(target);
2046
+
2047
+ if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, false) !== false) {
2048
+ capture();
2049
+ el.insertBefore(dragEl, firstChild);
2050
+ parentEl = el; // actualization
2051
+
1998
2052
  changed();
1999
2053
  return completed(true);
2000
2054
  }
@@ -2508,6 +2562,12 @@ function _unsilent() {
2508
2562
  _silent = false;
2509
2563
  }
2510
2564
 
2565
+ function _ghostIsFirst(evt, vertical, sortable) {
2566
+ var rect = getRect(getChild(sortable.el, 0, sortable.options, true));
2567
+ var spacer = 10;
2568
+ 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;
2569
+ }
2570
+
2511
2571
  function _ghostIsLast(evt, vertical, sortable) {
2512
2572
  var rect = getRect(lastChild(sortable.el, sortable.options.draggable));
2513
2573
  var spacer = 10;
@@ -2668,7 +2728,7 @@ Sortable.mount = function () {
2668
2728
  throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin));
2669
2729
  }
2670
2730
 
2671
- if (plugin.utils) Sortable.utils = _objectSpread({}, Sortable.utils, plugin.utils);
2731
+ if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils);
2672
2732
  PluginManager.mount(plugin);
2673
2733
  });
2674
2734
  };
@@ -2699,6 +2759,7 @@ function AutoScrollPlugin() {
2699
2759
  function AutoScroll() {
2700
2760
  this.defaults = {
2701
2761
  scroll: true,
2762
+ forceAutoScrollFallback: false,
2702
2763
  scrollSensitivity: 30,
2703
2764
  scrollSpeed: 10,
2704
2765
  bubbleScroll: true
@@ -2766,7 +2827,7 @@ function AutoScrollPlugin() {
2766
2827
  // MACOS Safari does not have autoscroll,
2767
2828
  // Firefox and Chrome are good
2768
2829
 
2769
- if (fallback || Edge || IE11OrLess || Safari) {
2830
+ if (fallback || this.options.forceAutoScrollFallback || Edge || IE11OrLess || Safari) {
2770
2831
  autoScroll(evt, this.options, elem, fallback); // Listener for pointer element change
2771
2832
 
2772
2833
  var ogElemScroller = getParentAutoScrollElement(elem, true);
@@ -3466,7 +3527,8 @@ function MultiDragPlugin() {
3466
3527
 
3467
3528
 
3468
3529
  if (dragStarted && this.isMultiDrag) {
3469
- // Do not "unfold" after around dragEl if reverted
3530
+ folding = false; // Do not "unfold" after around dragEl if reverted
3531
+
3470
3532
  if ((parentEl[expando].options.sort || parentEl !== rootEl) && multiDragElements.length > 1) {
3471
3533
  var dragRect = getRect(dragEl$1),
3472
3534
  multiDragIndex = index(dragEl$1, ':not(.' + this.options.selectedClass + ')');
@@ -3588,9 +3650,9 @@ function MultiDragPlugin() {
3588
3650
  // Static methods & properties
3589
3651
  pluginName: 'multiDrag',
3590
3652
  utils: {
3591
- /**
3592
- * Selects the provided multi-drag item
3593
- * @param {HTMLElement} el The element to be selected
3653
+ /**
3654
+ * Selects the provided multi-drag item
3655
+ * @param {HTMLElement} el The element to be selected
3594
3656
  */
3595
3657
  select: function select(el) {
3596
3658
  var sortable = el.parentNode[expando];
@@ -3606,9 +3668,9 @@ function MultiDragPlugin() {
3606
3668
  multiDragElements.push(el);
3607
3669
  },
3608
3670
 
3609
- /**
3610
- * Deselects the provided multi-drag item
3611
- * @param {HTMLElement} el The element to be deselected
3671
+ /**
3672
+ * Deselects the provided multi-drag item
3673
+ * @param {HTMLElement} el The element to be deselected
3612
3674
  */
3613
3675
  deselect: function deselect(el) {
3614
3676
  var sortable = el.parentNode[expando],
@@ -3678,10 +3740,10 @@ function insertMultiDragElements(clonesInserted, rootEl) {
3678
3740
  }
3679
3741
  });
3680
3742
  }
3681
- /**
3682
- * Insert multi-drag clones
3683
- * @param {[Boolean]} elementsInserted Whether the multi-drag elements are inserted
3684
- * @param {HTMLElement} rootEl
3743
+ /**
3744
+ * Insert multi-drag clones
3745
+ * @param {[Boolean]} elementsInserted Whether the multi-drag elements are inserted
3746
+ * @param {HTMLElement} rootEl
3685
3747
  */
3686
3748
 
3687
3749