@pantograph/sortable 1.15.6 → 2.1.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,7 +1,6 @@
1
1
  /**!
2
2
  * Sortable 1.15.6
3
- * @author RubaXa <trash@rubaxa.org>
4
- * @author owenm <owen23355@gmail.com>
3
+ * @author Sedmedgh <sedmedgh@gmail.com>
5
4
  * @license MIT
6
5
  */
7
6
  function _arrayLikeToArray(r, a) {
@@ -9,9 +8,6 @@ function _arrayLikeToArray(r, a) {
9
8
  for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
10
9
  return n;
11
10
  }
12
- function _arrayWithoutHoles(r) {
13
- if (Array.isArray(r)) return _arrayLikeToArray(r);
14
- }
15
11
  function _classCallCheck(a, n) {
16
12
  if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
17
13
  }
@@ -91,12 +87,6 @@ function _extends() {
91
87
  return n;
92
88
  }, _extends.apply(null, arguments);
93
89
  }
94
- function _iterableToArray(r) {
95
- if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r);
96
- }
97
- function _nonIterableSpread() {
98
- throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
99
- }
100
90
  function ownKeys(e, r) {
101
91
  var t = Object.keys(e);
102
92
  if (Object.getOwnPropertySymbols) {
@@ -138,9 +128,6 @@ function _objectWithoutPropertiesLoose(r, e) {
138
128
  }
139
129
  return t;
140
130
  }
141
- function _toConsumableArray(r) {
142
- return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread();
143
- }
144
131
  function _toPrimitive(t, r) {
145
132
  if ("object" != typeof t || !t) return t;
146
133
  var e = t[Symbol.toPrimitive];
@@ -217,11 +204,13 @@ function matches(/**HTMLElement*/el, /**String*/selector) {
217
204
  function getParentOrHost(el) {
218
205
  return el.host && el !== document && el.host.nodeType && el.host !== el ? el.host : el.parentNode;
219
206
  }
220
- function closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx, includeCTX, /**HTMLElement*/ignoreEl) {
207
+ function closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx, includeCTX, /**HTMLElement[]*/ignoreEls) {
221
208
  if (el) {
222
209
  ctx = ctx || document;
223
210
  do {
224
- if (el !== ignoreEl && (selector != null && (selector[0] === '>' ? el.parentNode === ctx && matches(el, selector) : matches(el, selector)) || includeCTX && el === ctx)) {
211
+ if (!(ignoreEls !== null && ignoreEls !== void 0 && ignoreEls.some(function (ignoreEl) {
212
+ return ignoreEl === el;
213
+ })) && (selector != null && (selector[0] === '>' ? el.parentNode === ctx && matches(el, selector) : matches(el, selector)) || includeCTX && el === ctx)) {
225
214
  return el;
226
215
  }
227
216
  if (el === ctx) break;
@@ -299,14 +288,14 @@ function getWindowScrollingElement() {
299
288
  }
300
289
  }
301
290
 
302
- /**
303
- * Returns the "bounding client rect" of given element
304
- * @param {HTMLElement} el The element whose boundingClientRect is wanted
305
- * @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container
306
- * @param {[Boolean]} relativeToNonStaticParent Whether the rect should be relative to the relative parent of (including) the contaienr
307
- * @param {[Boolean]} undoScale Whether the container's scale() should be undone
308
- * @param {[HTMLElement]} container The parent the element will be placed in
309
- * @return {Object} The boundingClientRect of el, with specified adjustments
291
+ /**
292
+ * Returns the "bounding client rect" of given element
293
+ * @param {HTMLElement} el The element whose boundingClientRect is wanted
294
+ * @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container
295
+ * @param {[Boolean]} relativeToNonStaticParent Whether the rect should be relative to the relative parent of (including) the contaienr
296
+ * @param {[Boolean]} undoScale Whether the container's scale() should be undone
297
+ * @param {[HTMLElement]} container The parent the element will be placed in
298
+ * @return {Object} The boundingClientRect of el, with specified adjustments
310
299
  */
311
300
  function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) {
312
301
  if (!el.getBoundingClientRect && el !== window) return;
@@ -373,12 +362,12 @@ function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoS
373
362
  };
374
363
  }
375
364
 
376
- /**
377
- * Checks if a side of an element is scrolled past a side of its parents
378
- * @param {HTMLElement} el The element who's side being scrolled out of view is in question
379
- * @param {String} elSide Side of the element in question ('top', 'left', 'right', 'bottom')
380
- * @param {String} parentSide Side of the parent in question ('top', 'left', 'right', 'bottom')
381
- * @return {HTMLElement} The parent scroll element that the el's side is scrolled past, or null if there is no such element
365
+ /**
366
+ * Checks if a side of an element is scrolled past a side of its parents
367
+ * @param {HTMLElement} el The element who's side being scrolled out of view is in question
368
+ * @param {String} elSide Side of the element in question ('top', 'left', 'right', 'bottom')
369
+ * @param {String} parentSide Side of the parent in question ('top', 'left', 'right', 'bottom')
370
+ * @return {HTMLElement} The parent scroll element that the el's side is scrolled past, or null if there is no such element
382
371
  */
383
372
  function isScrolledPast(el, elSide, parentSide) {
384
373
  var parent = getParentAutoScrollElement(el, true),
@@ -400,22 +389,24 @@ function isScrolledPast(el, elSide, parentSide) {
400
389
  return false;
401
390
  }
402
391
 
403
- /**
404
- * Gets nth child of el, ignoring hidden children, sortable's elements (does not ignore clone if it's visible)
405
- * and non-draggable elements
406
- * @param {HTMLElement} el The parent element
407
- * @param {Number} childNum The index of the child
408
- * @param {Object} options Parent Sortable's options
409
- * @param {boolean} includeDragEl include dragging item
410
- * @param {HTMLElement} ignoreEl exclude item
411
- * @return {HTMLElement} The child at index childNum, or null if not found
392
+ /**
393
+ * Gets nth child of el, ignoring hidden children, sortable's elements (does not ignore clone if it's visible)
394
+ * and non-draggable elements
395
+ * @param {HTMLElement} el The parent element
396
+ * @param {Number} childNum The index of the child
397
+ * @param {Object} options Parent Sortable's options
398
+ * @param {boolean} includeDragEl include dragging item
399
+ * @param {HTMLElement[]} ignoreEls exclude item
400
+ * @return {HTMLElement} The child at index childNum, or null if not found
412
401
  */
413
- function getChild(el, childNum, options, includeDragEl, ignoreEl) {
402
+ function getChild(el, childNum, options, includeDragEl, ignoreEls) {
414
403
  var currentChild = 0,
415
404
  i = 0,
416
405
  children = el.children;
417
406
  while (i < children.length) {
418
- if (children[i] !== ignoreEl && children[i].style.display !== 'none' && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false)) {
407
+ if (!(ignoreEls !== null && ignoreEls !== void 0 && ignoreEls.some(function (ignoreEl) {
408
+ return ignoreEl === children[i];
409
+ })) && children[i].style.display !== 'none' && children[i] !== Sortable.ghost && (includeDragEl || children[i] !== Sortable.dragged) && closest(children[i], options.draggable, el, false, ignoreEls)) {
419
410
  if (currentChild === childNum) {
420
411
  return children[i];
421
412
  }
@@ -426,11 +417,11 @@ function getChild(el, childNum, options, includeDragEl, ignoreEl) {
426
417
  return null;
427
418
  }
428
419
 
429
- /**
430
- * Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
431
- * @param {HTMLElement} el Parent element
432
- * @param {selector} selector Any other elements that should be ignored
433
- * @return {HTMLElement} The last child, ignoring ghostEl
420
+ /**
421
+ * Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
422
+ * @param {HTMLElement} el Parent element
423
+ * @param {selector} selector Any other elements that should be ignored
424
+ * @return {HTMLElement} The last child, ignoring ghostEl
434
425
  */
435
426
  function lastChild(el, selector) {
436
427
  var last = el.lastElementChild;
@@ -440,15 +431,15 @@ function lastChild(el, selector) {
440
431
  return last || null;
441
432
  }
442
433
 
443
- /**
444
- * Returns the index of an element within its parent for a selected set of
445
- * elements
446
- * @param {HTMLElement} el
447
- * @param {selector} selector
448
- * @param {HTMLElement} ignoreEl
449
- * @return {number}
434
+ /**
435
+ * Returns the index of an element within its parent for a selected set of
436
+ * elements
437
+ * @param {HTMLElement} el
438
+ * @param {selector} selector
439
+ * @param {HTMLElement[]} ignoreEls
440
+ * @return {number}
450
441
  */
451
- function index(el, selector, ignoreEl) {
442
+ function index(el, selector, ignoreEls) {
452
443
  var index = 0;
453
444
  if (!el || !el.parentNode) {
454
445
  return -1;
@@ -456,18 +447,20 @@ function index(el, selector, ignoreEl) {
456
447
 
457
448
  /* jshint boss:true */
458
449
  while (el = el.previousElementSibling) {
459
- if (el.nodeName.toUpperCase() !== 'TEMPLATE' && el !== Sortable.clone && (!selector || matches(el, selector)) && el !== ignoreEl) {
450
+ if (el.nodeName.toUpperCase() !== 'TEMPLATE' && el !== Sortable.clone && (!selector || matches(el, selector)) && !(ignoreEls !== null && ignoreEls !== void 0 && ignoreEls.some(function (ignoreEl) {
451
+ return ignoreEl === el;
452
+ }))) {
460
453
  index++;
461
454
  }
462
455
  }
463
456
  return index;
464
457
  }
465
458
 
466
- /**
467
- * Returns the scroll offset of the given element, added with all the scroll offsets of parent elements.
468
- * The value is returned in real pixels.
469
- * @param {HTMLElement} el
470
- * @return {Array} Offsets in the format of [left, top]
459
+ /**
460
+ * Returns the scroll offset of the given element, added with all the scroll offsets of parent elements.
461
+ * The value is returned in real pixels.
462
+ * @param {HTMLElement} el
463
+ * @return {Array} Offsets in the format of [left, top]
471
464
  */
472
465
  function getRelativeScrollOffset(el) {
473
466
  var offsetLeft = 0,
@@ -485,11 +478,11 @@ function getRelativeScrollOffset(el) {
485
478
  return [offsetLeft, offsetTop];
486
479
  }
487
480
 
488
- /**
489
- * Returns the index of the object within the given array
490
- * @param {Array} arr Array that may or may not hold the object
491
- * @param {Object} obj An object that has a key-value pair unique to and identical to a key-value pair in the object you want to find
492
- * @return {Number} The index of the object in the array, or -1
481
+ /**
482
+ * Returns the index of the object within the given array
483
+ * @param {Array} arr Array that may or may not hold the object
484
+ * @param {Object} obj An object that has a key-value pair unique to and identical to a key-value pair in the object you want to find
485
+ * @return {Number} The index of the object in the array, or -1
493
486
  */
494
487
  function indexOfObject(arr, obj) {
495
488
  for (var i in arr) {
@@ -568,25 +561,11 @@ function clone(el) {
568
561
  return el.cloneNode(true);
569
562
  }
570
563
  }
571
- function setRect(el, rect) {
572
- css(el, 'position', 'absolute');
573
- css(el, 'top', rect.top);
574
- css(el, 'left', rect.left);
575
- css(el, 'width', rect.width);
576
- css(el, 'height', rect.height);
577
- }
578
- function unsetRect(el) {
579
- css(el, 'position', '');
580
- css(el, 'top', '');
581
- css(el, 'left', '');
582
- css(el, 'width', '');
583
- css(el, 'height', '');
584
- }
585
- function getChildContainingRectFromElement(container, options, ghostEl, ignoreEl) {
564
+ function getChildContainingRectFromElement(container, options, ghostEl, ignoreEls) {
586
565
  var rect = {};
587
566
  Array.from(container.children).forEach(function (child) {
588
567
  var _rect$left, _rect$top, _rect$right, _rect$bottom;
589
- if (!closest(child, options.draggable, container, false, ignoreEl) || child.animated || child === ghostEl) return;
568
+ if (!closest(child, options.draggable, container, false, ignoreEls) || child.animated || child === ghostEl) return;
590
569
  var childRect = getRect(child);
591
570
  rect.left = Math.min((_rect$left = rect.left) !== null && _rect$left !== void 0 ? _rect$left : Infinity, childRect.left);
592
571
  rect.top = Math.min((_rect$top = rect.top) !== null && _rect$top !== void 0 ? _rect$top : Infinity, childRect.top);
@@ -750,12 +729,9 @@ var PluginManager = {
750
729
  plugin[option] = defaults[option];
751
730
  }
752
731
  }
753
- plugins.forEach(function (p) {
754
- if (p.pluginName === plugin.pluginName) {
755
- throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
756
- }
757
- });
758
- plugins.push(plugin);
732
+ if (!plugins.some(function (p) {
733
+ return p.pluginName === plugin.pluginName;
734
+ })) plugins.push(plugin);
759
735
  },
760
736
  pluginEvent: function pluginEvent(eventName, sortable, evt) {
761
737
  var _this = this;
@@ -825,7 +801,7 @@ var PluginManager = {
825
801
  }
826
802
  };
827
803
 
828
- function dispatchEvent(_ref) {
804
+ function getEvent(_ref) {
829
805
  var sortable = _ref.sortable,
830
806
  rootEl = _ref.rootEl,
831
807
  name = _ref.name,
@@ -842,9 +818,7 @@ function dispatchEvent(_ref) {
842
818
  extraEventProperties = _ref.extraEventProperties;
843
819
  sortable = sortable || rootEl && rootEl[expando];
844
820
  if (!sortable) return;
845
- var evt,
846
- options = sortable.options,
847
- onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
821
+ var evt;
848
822
  // Support for new CustomEvent feature
849
823
  if (window.CustomEvent && !IE11OrLess && !Edge) {
850
824
  evt = new CustomEvent(name, {
@@ -869,6 +843,43 @@ function dispatchEvent(_ref) {
869
843
  for (var option in allEventProperties) {
870
844
  evt[option] = allEventProperties[option];
871
845
  }
846
+ return evt;
847
+ }
848
+ function dispatchEvent(_ref2) {
849
+ var sortable = _ref2.sortable,
850
+ rootEl = _ref2.rootEl,
851
+ name = _ref2.name,
852
+ targetEl = _ref2.targetEl,
853
+ cloneEl = _ref2.cloneEl,
854
+ toEl = _ref2.toEl,
855
+ fromEl = _ref2.fromEl,
856
+ oldIndex = _ref2.oldIndex,
857
+ newIndex = _ref2.newIndex,
858
+ oldDraggableIndex = _ref2.oldDraggableIndex,
859
+ newDraggableIndex = _ref2.newDraggableIndex,
860
+ originalEvent = _ref2.originalEvent,
861
+ putSortable = _ref2.putSortable,
862
+ extraEventProperties = _ref2.extraEventProperties;
863
+ sortable = sortable || rootEl && rootEl[expando];
864
+ if (!sortable) return;
865
+ var options = sortable.options,
866
+ onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
867
+ var evt = getEvent({
868
+ sortable: sortable,
869
+ rootEl: rootEl,
870
+ name: name,
871
+ targetEl: targetEl,
872
+ cloneEl: cloneEl,
873
+ toEl: toEl,
874
+ fromEl: fromEl,
875
+ oldIndex: oldIndex,
876
+ newIndex: newIndex,
877
+ oldDraggableIndex: oldDraggableIndex,
878
+ newDraggableIndex: newDraggableIndex,
879
+ originalEvent: originalEvent,
880
+ putSortable: putSortable,
881
+ extraEventProperties: extraEventProperties
882
+ });
872
883
  if (rootEl) {
873
884
  rootEl.dispatchEvent(evt);
874
885
  }
@@ -930,6 +941,18 @@ function _dispatchEvent(info) {
930
941
  newDraggableIndex: newDraggableIndex
931
942
  }, info));
932
943
  }
944
+ function _getEvent(info) {
945
+ return getEvent(_objectSpread2({
946
+ putSortable: putSortable,
947
+ cloneEl: cloneEl,
948
+ targetEl: originalDragEl || dragEl,
949
+ rootEl: rootEl,
950
+ oldIndex: oldIndex,
951
+ oldDraggableIndex: oldDraggableIndex,
952
+ newIndex: newIndex,
953
+ newDraggableIndex: newDraggableIndex
954
+ }, info));
955
+ }
933
956
  var dragEl,
934
957
  originalDragEl,
935
958
  originalDragElDisplay,
@@ -965,7 +988,6 @@ var dragEl,
965
988
  ghostRelativeParent,
966
989
  ghostRelativeParentInitialScroll = [],
967
990
  // (left, top)
968
-
969
991
  _silent = false,
970
992
  savedInputChecked = [];
971
993
 
@@ -988,8 +1010,8 @@ var documentExists = typeof document !== 'undefined',
988
1010
  _detectDirection = function _detectDirection(el, options) {
989
1011
  var elCSS = css(el),
990
1012
  elWidth = parseInt(elCSS.width) - parseInt(elCSS.paddingLeft) - parseInt(elCSS.paddingRight) - parseInt(elCSS.borderLeftWidth) - parseInt(elCSS.borderRightWidth),
991
- child1 = getChild(el, 0, options, false, originalDragEl),
992
- child2 = getChild(el, 1, options, false, originalDragEl),
1013
+ child1 = getChild(el, 0, options, false, [originalDragEl]),
1014
+ child2 = getChild(el, 1, options, false, [originalDragEl]),
993
1015
  firstChildCSS = child1 && css(child1),
994
1016
  secondChildCSS = child2 && css(child2),
995
1017
  firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + getRect(child1).width,
@@ -1015,11 +1037,11 @@ var documentExists = typeof document !== 'undefined',
1015
1037
  targetOppLength = vertical ? targetRect.width : targetRect.height;
1016
1038
  return dragElS1Opp === targetS1Opp || dragElS2Opp === targetS2Opp || dragElS1Opp + dragElOppLength / 2 === targetS1Opp + targetOppLength / 2;
1017
1039
  },
1018
- /**
1019
- * Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
1020
- * @param {Number} x X position
1021
- * @param {Number} y Y position
1022
- * @return {HTMLElement} Element of the first found nearest Sortable
1040
+ /**
1041
+ * Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
1042
+ * @param {Number} x X position
1043
+ * @param {Number} y Y position
1044
+ * @return {HTMLElement} Element of the first found nearest Sortable
1023
1045
  */
1024
1046
  _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
1025
1047
  var ret;
@@ -1116,1013 +1138,1040 @@ var _checkOutsideTargetEl = function _checkOutsideTargetEl(evt) {
1116
1138
  }
1117
1139
  };
1118
1140
 
1119
- /**
1120
- * @class Sortable
1121
- * @param {HTMLElement} el
1122
- * @param {Object} [options]
1123
- */
1124
- function Sortable(el, options) {
1125
- if (!(el && el.nodeType && el.nodeType === 1)) {
1126
- throw "Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(el));
1127
- }
1128
- this.el = el; // root element
1129
- this.options = options = _extends({}, options);
1130
-
1131
- // Export instance
1132
- el[expando] = this;
1133
- var defaults = {
1134
- group: null,
1135
- sort: true,
1136
- disabled: false,
1137
- store: null,
1138
- handle: null,
1139
- draggable: /^[uo]l$/i.test(el.nodeName) ? '>li' : '>*',
1140
- swapThreshold: 1,
1141
- // percentage; 0 <= x <= 1
1142
- invertSwap: false,
1143
- // invert always
1144
- invertedSwapThreshold: null,
1145
- // will be set to same as swapThreshold if default
1146
- removeCloneOnHide: true,
1147
- direction: function direction() {
1148
- return _detectDirection(el, this.options);
1149
- },
1150
- ghostClass: 'sortable-ghost',
1151
- chosenClass: 'sortable-chosen',
1152
- dragClass: 'sortable-drag',
1153
- ignore: 'a, img',
1154
- filter: null,
1155
- preventOnFilter: true,
1156
- getGhostFallback: undefined,
1157
- getPlaceholder: undefined,
1158
- getPlaceholderOnMove: undefined,
1159
- tree: false,
1160
- treeItemLevelAttr: 'data-level',
1161
- treeIndentThreshold: 10,
1162
- animation: 0,
1163
- easing: null,
1164
- setData: function setData(dataTransfer, dragEl) {
1165
- dataTransfer.setData('Text', dragEl.textContent);
1166
- },
1167
- dropBubble: false,
1168
- dragoverBubble: false,
1169
- dataIdAttr: 'data-id',
1170
- delay: 0,
1171
- delayOnTouchOnly: false,
1172
- touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
1173
- forceFallback: false,
1174
- fallbackClass: 'sortable-fallback',
1175
- fallbackOnBody: false,
1176
- fallbackTolerance: 0,
1177
- fallbackOffset: {
1178
- x: 0,
1179
- y: 0
1180
- },
1181
- // Disabled on Safari: #1571; Enabled on Safari IOS: #2244
1182
- supportPointer: Sortable.supportPointer !== false && 'PointerEvent' in window && (!Safari || IOS),
1183
- emptyInsertThreshold: 5
1184
- };
1185
- PluginManager.initializePlugins(this, el, defaults);
1186
-
1187
- // Set default options
1188
- for (var name in defaults) {
1189
- !(name in options) && (options[name] = defaults[name]);
1190
- }
1191
- _prepareGroup(options);
1192
-
1193
- // Bind all private methods
1194
- for (var fn in this) {
1195
- if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
1196
- this[fn] = this[fn].bind(this);
1141
+ // Replace the function Sortable and Sortable.prototype with a class
1142
+ var Sortable = /*#__PURE__*/function () {
1143
+ function Sortable(el, options) {
1144
+ _classCallCheck(this, Sortable);
1145
+ _defineProperty(this, "_ignoreWhileAnimating", null);
1146
+ if (!(el && el.nodeType && el.nodeType === 1)) {
1147
+ throw "Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(el));
1148
+ }
1149
+ this.el = el; // root element
1150
+ this.options = options = _extends({}, options);
1151
+ el[expando] = this;
1152
+ var defaults = {
1153
+ group: null,
1154
+ sort: true,
1155
+ disabled: false,
1156
+ store: null,
1157
+ handle: null,
1158
+ draggable: /^[uo]l$/i.test(el.nodeName) ? '>li' : '>*',
1159
+ swapThreshold: 1,
1160
+ // percentage; 0 <= x <= 1
1161
+ invertSwap: false,
1162
+ // invert always
1163
+ invertedSwapThreshold: null,
1164
+ // will be set to same as swapThreshold if default
1165
+ removeCloneOnHide: true,
1166
+ direction: function direction() {
1167
+ return _detectDirection(el, this.options);
1168
+ },
1169
+ ghostClass: 'sortable-ghost',
1170
+ chosenClass: 'sortable-chosen',
1171
+ dragClass: 'sortable-drag',
1172
+ ignore: 'a, img',
1173
+ filter: null,
1174
+ preventOnFilter: true,
1175
+ getGhostFallback: undefined,
1176
+ getPlaceholder: undefined,
1177
+ getPlaceholderOnMove: undefined,
1178
+ tree: false,
1179
+ treeItemLevelAttr: 'data-level',
1180
+ treeIndentThreshold: 10,
1181
+ animation: 0,
1182
+ easing: null,
1183
+ setData: function setData(dataTransfer, dragEl) {
1184
+ dataTransfer.setData('Text', dragEl.textContent);
1185
+ },
1186
+ dropBubble: false,
1187
+ dragoverBubble: false,
1188
+ dataIdAttr: 'data-id',
1189
+ delay: 0,
1190
+ delayOnTouchOnly: false,
1191
+ touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
1192
+ forceFallback: false,
1193
+ fallbackClass: 'sortable-fallback',
1194
+ fallbackOnBody: false,
1195
+ fallbackTolerance: 0,
1196
+ fallbackOffset: {
1197
+ x: 0,
1198
+ y: 0
1199
+ },
1200
+ // Disabled on Safari: #1571; Enabled on Safari IOS: #2244
1201
+ supportPointer: Sortable.supportPointer !== false && 'PointerEvent' in window && (!Safari || IOS),
1202
+ emptyInsertThreshold: 5
1203
+ };
1204
+ PluginManager.initializePlugins(this, el, defaults);
1205
+ for (var name in defaults) {
1206
+ !(name in options) && (options[name] = defaults[name]);
1197
1207
  }
1198
- }
1199
-
1200
- // Setup drag mode
1201
- this.nativeDraggable = options.forceFallback ? false : supportDraggable;
1202
- if (this.nativeDraggable) {
1203
- // Touch start threshold cannot be greater than the native dragstart threshold
1204
- this.options.touchStartThreshold = 1;
1205
- }
1206
-
1207
- // Bind events
1208
- if (options.supportPointer) {
1209
- on(el, 'pointerdown', this._onTapStart);
1210
- } else {
1211
- on(el, 'mousedown', this._onTapStart);
1212
- on(el, 'touchstart', this._onTapStart);
1213
- }
1214
- if (this.nativeDraggable) {
1215
- on(el, 'dragover', this);
1216
- on(el, 'dragenter', this);
1217
- }
1218
- sortables.push(this.el);
1219
-
1220
- // Restore sorting
1221
- options.store && options.store.get && this.sort(options.store.get(this) || []);
1222
-
1223
- // Add animation state manager
1224
- _extends(this, AnimationStateManager());
1225
- }
1226
- Sortable.prototype = /** @lends Sortable.prototype */{
1227
- constructor: Sortable,
1228
- _isOutsideThisEl: function _isOutsideThisEl(target) {
1229
- if (!this.el.contains(target) && target !== this.el) {
1230
- lastTarget = null;
1208
+ _prepareGroup(options);
1209
+ var _iterator = _createForOfIteratorHelper(Object.getOwnPropertyNames(Object.getPrototypeOf(this))),
1210
+ _step;
1211
+ try {
1212
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1213
+ var fn = _step.value;
1214
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
1215
+ this[fn] = this[fn].bind(this);
1216
+ }
1217
+ }
1218
+ } catch (err) {
1219
+ _iterator.e(err);
1220
+ } finally {
1221
+ _iterator.f();
1231
1222
  }
1232
- },
1233
- _getDirection: function _getDirection(evt, target) {
1234
- return typeof this.options.direction === 'function' ? this.options.direction.call(this, evt, target, originalDragEl || dragEl) : this.options.direction;
1235
- },
1236
- _onTapStart: function _onTapStart(/** Event|TouchEvent */evt) {
1237
- if (!evt.cancelable) return;
1238
- var _this = this,
1239
- el = this.el,
1240
- options = this.options,
1241
- preventOnFilter = options.preventOnFilter,
1242
- type = evt.type,
1243
- touch = evt.touches && evt.touches[0] || evt.pointerType && evt.pointerType === 'touch' && evt,
1244
- target = (touch || evt).target,
1245
- originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0] || evt.composedPath && evt.composedPath()[0]) || target,
1246
- filter = options.filter;
1247
- _saveInputCheckedState(el);
1248
-
1249
- // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
1250
- if (dragEl) {
1251
- return;
1223
+ this.nativeDraggable = options.forceFallback ? false : supportDraggable;
1224
+ if (this.nativeDraggable) {
1225
+ this.options.touchStartThreshold = 1;
1252
1226
  }
1253
- if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
1254
- return; // only left button and enabled
1227
+ if (options.supportPointer) {
1228
+ on(el, 'pointerdown', this._onTapStart);
1229
+ } else {
1230
+ on(el, 'mousedown', this._onTapStart);
1231
+ on(el, 'touchstart', this._onTapStart);
1255
1232
  }
1256
-
1257
- // cancel dnd if original target is content editable
1258
- if (originalTarget.isContentEditable) {
1259
- return;
1233
+ if (this.nativeDraggable) {
1234
+ on(el, 'dragover', this);
1235
+ on(el, 'dragenter', this);
1260
1236
  }
1237
+ sortables.push(this.el);
1238
+ options.store && options.store.get && this.sort(options.store.get(this) || []);
1239
+ _extends(this, AnimationStateManager());
1240
+ }
1261
1241
 
1262
- // Safari ignores further event handling after mousedown
1263
- if (!this.nativeDraggable && Safari && target && target.tagName.toUpperCase() === 'SELECT') {
1264
- return;
1265
- }
1266
- target = closest(target, options.draggable, el, false, originalDragEl);
1267
- if (target && target.animated) {
1268
- return;
1242
+ // All prototype methods go here as class methods (remove prototype)
1243
+ return _createClass(Sortable, [{
1244
+ key: "_isOutsideThisEl",
1245
+ value: function _isOutsideThisEl(target) {
1246
+ if (!this.el.contains(target) && target !== this.el) {
1247
+ lastTarget = null;
1248
+ }
1269
1249
  }
1270
- if (lastDownEl === target) {
1271
- // Ignoring duplicate `down`
1272
- return;
1250
+ }, {
1251
+ key: "_getDirection",
1252
+ value: function _getDirection(evt, target) {
1253
+ return typeof this.options.direction === 'function' ? this.options.direction.call(this, evt, target, originalDragEl || dragEl) : this.options.direction;
1273
1254
  }
1255
+ }, {
1256
+ key: "_onTapStart",
1257
+ value: function _onTapStart(/** Event|TouchEvent */evt) {
1258
+ if (!evt.cancelable) return;
1259
+ var _this = this,
1260
+ el = this.el,
1261
+ options = this.options,
1262
+ preventOnFilter = options.preventOnFilter,
1263
+ type = evt.type,
1264
+ touch = evt.touches && evt.touches[0] || evt.pointerType && evt.pointerType === 'touch' && evt,
1265
+ target = (touch || evt).target,
1266
+ originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0] || evt.composedPath && evt.composedPath()[0]) || target,
1267
+ filter = options.filter;
1268
+ _saveInputCheckedState(el);
1269
+
1270
+ // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
1271
+ if (dragEl) {
1272
+ return;
1273
+ }
1274
+ if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
1275
+ return; // only left button and enabled
1276
+ }
1274
1277
 
1275
- // Get the index of the dragged element within its parent
1276
- oldIndex = index(target, undefined, originalDragEl);
1277
- oldDraggableIndex = index(target, options.draggable, originalDragEl);
1278
+ // cancel dnd if original target is content editable
1279
+ if (originalTarget.isContentEditable) {
1280
+ return;
1281
+ }
1278
1282
 
1279
- // Check filter
1280
- if (typeof filter === 'function') {
1281
- if (filter.call(this, evt, target, this)) {
1282
- _dispatchEvent({
1283
- sortable: _this,
1284
- rootEl: originalTarget,
1285
- name: 'filter',
1286
- targetEl: target,
1287
- toEl: el,
1288
- fromEl: el
1289
- });
1290
- pluginEvent('filter', _this, {
1291
- evt: evt
1292
- });
1293
- preventOnFilter && evt.preventDefault();
1294
- return; // cancel dnd
1283
+ // Safari ignores further event handling after mousedown
1284
+ if (!this.nativeDraggable && Safari && target && target.tagName.toUpperCase() === 'SELECT') {
1285
+ return;
1295
1286
  }
1296
- } else if (filter) {
1297
- filter = filter.split(',').some(function (criteria) {
1298
- criteria = closest(originalTarget, criteria.trim(), el, false, originalDragEl);
1299
- if (criteria) {
1287
+ target = closest(target, options.draggable, el, false, [originalDragEl]);
1288
+ if (target && target.animated) {
1289
+ return;
1290
+ }
1291
+ if (lastDownEl === target) {
1292
+ // Ignoring duplicate `down`
1293
+ return;
1294
+ }
1295
+
1296
+ // Get the index of the dragged element within its parent
1297
+ oldIndex = index(target, undefined, [originalDragEl]);
1298
+ oldDraggableIndex = index(target, options.draggable, [originalDragEl]);
1299
+
1300
+ // Check filter
1301
+ if (typeof filter === 'function') {
1302
+ if (filter.call(this, evt, target, this)) {
1300
1303
  _dispatchEvent({
1301
1304
  sortable: _this,
1302
- rootEl: criteria,
1305
+ rootEl: originalTarget,
1303
1306
  name: 'filter',
1304
1307
  targetEl: target,
1305
- fromEl: el,
1306
- toEl: el
1308
+ toEl: el,
1309
+ fromEl: el
1307
1310
  });
1308
1311
  pluginEvent('filter', _this, {
1309
1312
  evt: evt
1310
1313
  });
1311
- return true;
1314
+ preventOnFilter && evt.preventDefault();
1315
+ return; // cancel dnd
1316
+ }
1317
+ } else if (filter) {
1318
+ filter = filter.split(',').some(function (criteria) {
1319
+ criteria = closest(originalTarget, criteria.trim(), el, false, [originalDragEl]);
1320
+ if (criteria) {
1321
+ _dispatchEvent({
1322
+ sortable: _this,
1323
+ rootEl: criteria,
1324
+ name: 'filter',
1325
+ targetEl: target,
1326
+ fromEl: el,
1327
+ toEl: el
1328
+ });
1329
+ pluginEvent('filter', _this, {
1330
+ evt: evt
1331
+ });
1332
+ return true;
1333
+ }
1334
+ });
1335
+ if (filter) {
1336
+ preventOnFilter && evt.preventDefault();
1337
+ return; // cancel dnd
1312
1338
  }
1313
- });
1314
- if (filter) {
1315
- preventOnFilter && evt.preventDefault();
1316
- return; // cancel dnd
1317
1339
  }
1340
+ if (options.handle && !closest(originalTarget, options.handle, el, false, [originalDragEl])) {
1341
+ return;
1342
+ }
1343
+
1344
+ // Prepare `dragstart`
1345
+ this._prepareDragStart(evt, touch, target);
1318
1346
  }
1319
- if (options.handle && !closest(originalTarget, options.handle, el, false, originalDragEl)) {
1320
- return;
1321
- }
1347
+ }, {
1348
+ key: "_prepareDragStart",
1349
+ value: function _prepareDragStart(/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
1350
+ var _this = this,
1351
+ el = _this.el,
1352
+ options = _this.options,
1353
+ ownerDocument = el.ownerDocument,
1354
+ dragStartFn;
1355
+ if (target && !dragEl && target.parentNode === el) {
1356
+ var dragRect = getRect(target);
1357
+ rootEl = el;
1358
+ dragEl = target;
1359
+ parentEl = dragEl.parentNode;
1360
+ nextEl = dragEl.nextSibling;
1361
+ lastDownEl = target;
1362
+ activeGroup = options.group;
1363
+ Sortable.dragged = dragEl;
1364
+ tapEvt = {
1365
+ target: dragEl,
1366
+ clientX: (touch || evt).clientX,
1367
+ clientY: (touch || evt).clientY
1368
+ };
1369
+ tapDistanceLeft = tapEvt.clientX - dragRect.left;
1370
+ tapDistanceTop = tapEvt.clientY - dragRect.top;
1371
+ this._lastX = (touch || evt).clientX;
1372
+ this._lastY = (touch || evt).clientY;
1373
+ dragEl.style['will-change'] = 'all';
1374
+ dragStartFn = function dragStartFn() {
1375
+ pluginEvent('delayEnded', _this, {
1376
+ evt: evt
1377
+ });
1378
+ if (Sortable.eventCanceled) {
1379
+ _this._onDrop();
1380
+ return;
1381
+ }
1382
+ // Delayed drag has been triggered
1383
+ // we can re-enable the events: touchmove/mousemove
1384
+ _this._disableDelayedDragEvents();
1385
+ if (!FireFox && _this.nativeDraggable) {
1386
+ dragEl.draggable = true;
1387
+ }
1322
1388
 
1323
- // Prepare `dragstart`
1324
- this._prepareDragStart(evt, touch, target);
1325
- },
1326
- _prepareDragStart: function _prepareDragStart(/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
1327
- var _this = this,
1328
- el = _this.el,
1329
- options = _this.options,
1330
- ownerDocument = el.ownerDocument,
1331
- dragStartFn;
1332
- if (target && !dragEl && target.parentNode === el) {
1333
- var dragRect = getRect(target);
1334
- rootEl = el;
1335
- dragEl = target;
1336
- parentEl = dragEl.parentNode;
1337
- nextEl = dragEl.nextSibling;
1338
- lastDownEl = target;
1339
- activeGroup = options.group;
1340
- Sortable.dragged = dragEl;
1341
- tapEvt = {
1342
- target: dragEl,
1343
- clientX: (touch || evt).clientX,
1344
- clientY: (touch || evt).clientY
1345
- };
1346
- tapDistanceLeft = tapEvt.clientX - dragRect.left;
1347
- tapDistanceTop = tapEvt.clientY - dragRect.top;
1348
- this._lastX = (touch || evt).clientX;
1349
- this._lastY = (touch || evt).clientY;
1350
- dragEl.style['will-change'] = 'all';
1351
- dragStartFn = function dragStartFn() {
1352
- pluginEvent('delayEnded', _this, {
1353
- evt: evt
1389
+ // Bind the events: dragstart/dragend
1390
+ _this._triggerDragStart(evt, touch);
1391
+
1392
+ // Drag start event
1393
+ _dispatchEvent({
1394
+ sortable: _this,
1395
+ name: 'choose',
1396
+ originalEvent: evt
1397
+ });
1398
+
1399
+ // Chosen item
1400
+ toggleClass(dragEl, options.chosenClass, true);
1401
+ };
1402
+
1403
+ // Disable "draggable"
1404
+ options.ignore.split(',').forEach(function (criteria) {
1405
+ find(dragEl, criteria.trim(), _disableDraggable);
1354
1406
  });
1355
- if (Sortable.eventCanceled) {
1356
- _this._onDrop();
1357
- return;
1407
+ on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
1408
+ on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
1409
+ on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
1410
+ if (options.supportPointer) {
1411
+ on(ownerDocument, 'pointerup', _this._onDrop);
1412
+ // Native D&D triggers pointercancel
1413
+ !this.nativeDraggable && on(ownerDocument, 'pointercancel', _this._onDrop);
1414
+ } else {
1415
+ on(ownerDocument, 'mouseup', _this._onDrop);
1416
+ on(ownerDocument, 'touchend', _this._onDrop);
1417
+ on(ownerDocument, 'touchcancel', _this._onDrop);
1358
1418
  }
1359
- // Delayed drag has been triggered
1360
- // we can re-enable the events: touchmove/mousemove
1361
- _this._disableDelayedDragEvents();
1362
- if (!FireFox && _this.nativeDraggable) {
1419
+
1420
+ // Make dragEl draggable (must be before delay for FireFox)
1421
+ if (FireFox && this.nativeDraggable) {
1422
+ this.options.touchStartThreshold = 4;
1363
1423
  dragEl.draggable = true;
1364
1424
  }
1365
-
1366
- // Bind the events: dragstart/dragend
1367
- _this._triggerDragStart(evt, touch);
1368
-
1369
- // Drag start event
1370
- _dispatchEvent({
1371
- sortable: _this,
1372
- name: 'choose',
1373
- originalEvent: evt
1425
+ pluginEvent('delayStart', this, {
1426
+ evt: evt
1374
1427
  });
1375
1428
 
1376
- // Chosen item
1377
- toggleClass(dragEl, options.chosenClass, true);
1378
- };
1379
-
1380
- // Disable "draggable"
1381
- options.ignore.split(',').forEach(function (criteria) {
1382
- find(dragEl, criteria.trim(), _disableDraggable);
1383
- });
1384
- on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
1385
- on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
1386
- on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
1387
- if (options.supportPointer) {
1388
- on(ownerDocument, 'pointerup', _this._onDrop);
1389
- // Native D&D triggers pointercancel
1390
- !this.nativeDraggable && on(ownerDocument, 'pointercancel', _this._onDrop);
1391
- } else {
1392
- on(ownerDocument, 'mouseup', _this._onDrop);
1393
- on(ownerDocument, 'touchend', _this._onDrop);
1394
- on(ownerDocument, 'touchcancel', _this._onDrop);
1429
+ // Delay is impossible for native DnD in Edge or IE
1430
+ if (options.delay && (!options.delayOnTouchOnly || touch) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
1431
+ if (Sortable.eventCanceled) {
1432
+ this._onDrop();
1433
+ return;
1434
+ }
1435
+ // If the user moves the pointer or let go the click or touch
1436
+ // before the delay has been reached:
1437
+ // disable the delayed drag
1438
+ if (options.supportPointer) {
1439
+ on(ownerDocument, 'pointerup', _this._disableDelayedDrag);
1440
+ on(ownerDocument, 'pointercancel', _this._disableDelayedDrag);
1441
+ } else {
1442
+ on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
1443
+ on(ownerDocument, 'touchend', _this._disableDelayedDrag);
1444
+ on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
1445
+ }
1446
+ on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
1447
+ on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
1448
+ options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
1449
+ _this._dragStartTimer = setTimeout(dragStartFn, options.delay);
1450
+ } else {
1451
+ dragStartFn();
1452
+ }
1395
1453
  }
1396
-
1397
- // Make dragEl draggable (must be before delay for FireFox)
1398
- if (FireFox && this.nativeDraggable) {
1399
- this.options.touchStartThreshold = 4;
1400
- dragEl.draggable = true;
1454
+ }
1455
+ }, {
1456
+ key: "_delayedDragTouchMoveHandler",
1457
+ value: function _delayedDragTouchMoveHandler(/** TouchEvent|PointerEvent **/e) {
1458
+ var touch = e.touches ? e.touches[0] : e;
1459
+ if (Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) >= Math.floor(this.options.touchStartThreshold / (this.nativeDraggable && window.devicePixelRatio || 1))) {
1460
+ this._disableDelayedDrag();
1401
1461
  }
1402
- pluginEvent('delayStart', this, {
1403
- evt: evt
1404
- });
1405
-
1406
- // Delay is impossible for native DnD in Edge or IE
1407
- if (options.delay && (!options.delayOnTouchOnly || touch) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
1408
- if (Sortable.eventCanceled) {
1409
- this._onDrop();
1410
- return;
1411
- }
1412
- // If the user moves the pointer or let go the click or touch
1413
- // before the delay has been reached:
1414
- // disable the delayed drag
1415
- if (options.supportPointer) {
1416
- on(ownerDocument, 'pointerup', _this._disableDelayedDrag);
1417
- on(ownerDocument, 'pointercancel', _this._disableDelayedDrag);
1462
+ }
1463
+ }, {
1464
+ key: "_disableDelayedDrag",
1465
+ value: function _disableDelayedDrag() {
1466
+ dragEl && _disableDraggable(dragEl);
1467
+ clearTimeout(this._dragStartTimer);
1468
+ this._disableDelayedDragEvents();
1469
+ }
1470
+ }, {
1471
+ key: "_disableDelayedDragEvents",
1472
+ value: function _disableDelayedDragEvents() {
1473
+ var ownerDocument = this.el.ownerDocument;
1474
+ off(ownerDocument, 'mouseup', this._disableDelayedDrag);
1475
+ off(ownerDocument, 'touchend', this._disableDelayedDrag);
1476
+ off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
1477
+ off(ownerDocument, 'pointerup', this._disableDelayedDrag);
1478
+ off(ownerDocument, 'pointercancel', this._disableDelayedDrag);
1479
+ off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
1480
+ off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
1481
+ off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
1482
+ }
1483
+ }, {
1484
+ key: "_triggerDragStart",
1485
+ value: function _triggerDragStart(/** Event */evt, /** Touch */touch) {
1486
+ touch = touch || evt.pointerType == 'touch' && evt;
1487
+ if (!this.nativeDraggable || touch) {
1488
+ if (this.options.supportPointer) {
1489
+ on(document, 'pointermove', this._onTouchMove);
1490
+ } else if (touch) {
1491
+ on(document, 'touchmove', this._onTouchMove);
1418
1492
  } else {
1419
- on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
1420
- on(ownerDocument, 'touchend', _this._disableDelayedDrag);
1421
- on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
1493
+ on(document, 'mousemove', this._onTouchMove);
1422
1494
  }
1423
- on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
1424
- on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
1425
- options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
1426
- _this._dragStartTimer = setTimeout(dragStartFn, options.delay);
1427
1495
  } else {
1428
- dragStartFn();
1496
+ on(dragEl, 'dragend', this);
1497
+ on(rootEl, 'dragstart', this._onDragStart);
1429
1498
  }
1499
+ try {
1500
+ if (document.selection) {
1501
+ _nextTick(function () {
1502
+ document.selection.empty();
1503
+ });
1504
+ } else {
1505
+ window.getSelection().removeAllRanges();
1506
+ }
1507
+ } catch (err) {}
1430
1508
  }
1431
- },
1432
- _delayedDragTouchMoveHandler: function _delayedDragTouchMoveHandler(/** TouchEvent|PointerEvent **/e) {
1433
- var touch = e.touches ? e.touches[0] : e;
1434
- if (Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) >= Math.floor(this.options.touchStartThreshold / (this.nativeDraggable && window.devicePixelRatio || 1))) {
1435
- this._disableDelayedDrag();
1436
- }
1437
- },
1438
- _disableDelayedDrag: function _disableDelayedDrag() {
1439
- dragEl && _disableDraggable(dragEl);
1440
- clearTimeout(this._dragStartTimer);
1441
- this._disableDelayedDragEvents();
1442
- },
1443
- _disableDelayedDragEvents: function _disableDelayedDragEvents() {
1444
- var ownerDocument = this.el.ownerDocument;
1445
- off(ownerDocument, 'mouseup', this._disableDelayedDrag);
1446
- off(ownerDocument, 'touchend', this._disableDelayedDrag);
1447
- off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
1448
- off(ownerDocument, 'pointerup', this._disableDelayedDrag);
1449
- off(ownerDocument, 'pointercancel', this._disableDelayedDrag);
1450
- off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
1451
- off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
1452
- off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
1453
- },
1454
- _triggerDragStart: function _triggerDragStart(/** Event */evt, /** Touch */touch) {
1455
- touch = touch || evt.pointerType == 'touch' && evt;
1456
- if (!this.nativeDraggable || touch) {
1457
- if (this.options.supportPointer) {
1458
- on(document, 'pointermove', this._onTouchMove);
1459
- } else if (touch) {
1460
- on(document, 'touchmove', this._onTouchMove);
1461
- } else {
1462
- on(document, 'mousemove', this._onTouchMove);
1509
+ }, {
1510
+ key: "_getPlaceholder",
1511
+ value: function _getPlaceholder(evt) {
1512
+ if (typeof this.options.getPlaceholder === 'function') {
1513
+ var placeholder = this.options.getPlaceholder(_getEvent({
1514
+ sortable: this,
1515
+ name: 'getPlaceholder',
1516
+ originalEvent: evt
1517
+ }));
1518
+ if (placeholder) {
1519
+ originalDragEl = dragEl;
1520
+ originalDragElDisplay = dragEl.style.display;
1521
+ dragEl = placeholder;
1522
+ }
1523
+ if (dragEl && originalDragEl) {
1524
+ originalDragEl.after(dragEl);
1525
+ css(originalDragEl, 'display', 'none');
1526
+ css(originalDragEl, 'transform', '');
1527
+ toggleClass(originalDragEl, this.options.dragClass, false);
1528
+ toggleClass(originalDragEl, this.options.ghostClass, false);
1529
+ toggleClass(originalDragEl, this.options.chosenClass, false);
1530
+ }
1531
+ pluginEvent('getPlaceholder', this);
1463
1532
  }
1464
- } else {
1465
- on(dragEl, 'dragend', this);
1466
- on(rootEl, 'dragstart', this._onDragStart);
1467
1533
  }
1468
- try {
1469
- if (document.selection) {
1470
- _nextTick(function () {
1471
- document.selection.empty();
1472
- });
1473
- } else {
1474
- window.getSelection().removeAllRanges();
1534
+ }, {
1535
+ key: "_removeClonedSelectedItem",
1536
+ value: function _removeClonedSelectedItem() {
1537
+ if (typeof this.options.getPlaceholder === 'function' || typeof this.options.getPlaceholderOnMove === 'function') {
1538
+ if (dragEl && originalDragEl) {
1539
+ css(originalDragEl, 'display', originalDragElDisplay || '');
1540
+ dragEl.remove();
1541
+ }
1475
1542
  }
1476
- } catch (err) {}
1477
- },
1478
- _getPlaceholder: function _getPlaceholder() {
1479
- if (typeof this.options.getPlaceholder === 'function') {
1480
- originalDragEl = dragEl;
1481
- originalDragElDisplay = dragEl.style.display;
1482
- dragEl = this.options.getPlaceholder(dragEl);
1483
- if (dragEl && originalDragEl) {
1484
- originalDragEl.after(dragEl);
1485
- css(originalDragEl, 'display', 'none');
1486
- css(originalDragEl, 'transform', '');
1487
- toggleClass(originalDragEl, this.options.dragClass, false);
1488
- toggleClass(originalDragEl, this.options.ghostClass, false);
1489
- toggleClass(originalDragEl, this.options.chosenClass, false);
1490
- }
1491
- pluginEvent('getPlaceholder', this);
1492
1543
  }
1493
- },
1494
- _removeClonedSelectedItem: function _removeClonedSelectedItem() {
1495
- if (typeof this.options.getPlaceholder === 'function' || typeof this.options.getPlaceholderOnMove === 'function') {
1496
- if (dragEl && originalDragEl) {
1497
- css(originalDragEl, 'display', originalDragElDisplay || '');
1544
+ }, {
1545
+ key: "_replacePlaceholder",
1546
+ value: function _replacePlaceholder(newDragEl) {
1547
+ var parent = dragEl.parentNode;
1548
+ if (parent) {
1549
+ parent.replaceChild(newDragEl, dragEl);
1550
+ } else {
1498
1551
  dragEl.remove();
1499
1552
  }
1553
+ dragEl = newDragEl;
1500
1554
  }
1501
- },
1502
- _replacePlaceholder: function _replacePlaceholder(newDragEl) {
1503
- var parent = dragEl.parentNode;
1504
- if (parent) {
1505
- parent.replaceChild(newDragEl, dragEl);
1506
- } else {
1507
- dragEl.remove();
1508
- }
1509
- dragEl = newDragEl;
1510
- },
1511
- _getPlaceholderOnMove: function _getPlaceholderOnMove(el, dragRect, target, targetRect, evt, after) {
1512
- if (typeof this.options.getPlaceholderOnMove === 'function') {
1513
- var newPlaceholder = this.options.getPlaceholderOnMove(getMoveEvent(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, after));
1514
- if (newPlaceholder) {
1515
- this._replacePlaceholder(newPlaceholder);
1555
+ }, {
1556
+ key: "_getPlaceholderOnMove",
1557
+ value: function _getPlaceholderOnMove(el, dragRect, target, targetRect, evt, after) {
1558
+ if (typeof this.options.getPlaceholderOnMove === 'function') {
1559
+ var newPlaceholder = this.options.getPlaceholderOnMove(getMoveEvent(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, after));
1560
+ if (newPlaceholder) {
1561
+ this._replacePlaceholder(newPlaceholder);
1562
+ }
1516
1563
  }
1517
1564
  }
1518
- },
1519
- _dragStarted: function _dragStarted(fallback, evt) {
1520
- awaitingDragStarted = false;
1521
- if (rootEl && dragEl) {
1522
- this._getPlaceholder();
1523
- pluginEvent('dragStarted', this, {
1524
- evt: evt
1525
- });
1526
- if (this.nativeDraggable) {
1527
- on(document, 'dragover', _checkOutsideTargetEl);
1528
- }
1529
- var options = this.options;
1565
+ }, {
1566
+ key: "_dragStarted",
1567
+ value: function _dragStarted(fallback, evt) {
1568
+ awaitingDragStarted = false;
1569
+ if (rootEl && dragEl) {
1570
+ this._getPlaceholder(evt);
1571
+ pluginEvent('dragStarted', this, {
1572
+ evt: evt
1573
+ });
1574
+ if (this.nativeDraggable) {
1575
+ on(document, 'dragover', _checkOutsideTargetEl);
1576
+ }
1577
+ var options = this.options;
1530
1578
 
1531
- // Apply effect
1532
- !fallback && toggleClass(dragEl, options.dragClass, false);
1533
- toggleClass(dragEl, options.ghostClass, true);
1534
- Sortable.active = this;
1535
- fallback && this._appendGhost();
1579
+ // Apply effect
1580
+ !fallback && toggleClass(dragEl, options.dragClass, false);
1581
+ toggleClass(dragEl, options.ghostClass, true);
1582
+ Sortable.active = this;
1583
+ fallback && this._appendGhost();
1536
1584
 
1537
- // Drag start event
1538
- _dispatchEvent({
1539
- sortable: this,
1540
- name: 'start',
1541
- originalEvent: evt
1542
- });
1543
- } else {
1544
- this._nulling();
1585
+ // Drag start event
1586
+ _dispatchEvent({
1587
+ sortable: this,
1588
+ name: 'start',
1589
+ originalEvent: evt
1590
+ });
1591
+ } else {
1592
+ this._nulling();
1593
+ }
1545
1594
  }
1546
- },
1547
- _emulateDragOver: function _emulateDragOver() {
1548
- if (touchEvt) {
1549
- this._lastX = touchEvt.clientX;
1550
- this._lastY = touchEvt.clientY;
1551
- _hideGhostForTarget();
1552
- var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1553
- var parent = target;
1554
- while (target && target.shadowRoot) {
1555
- target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1556
- if (target === parent) break;
1557
- parent = target;
1558
- }
1559
- dragEl.parentNode[expando]._isOutsideThisEl(target);
1560
- if (parent) {
1561
- do {
1562
- if (parent[expando]) {
1563
- var inserted = void 0;
1564
- inserted = parent[expando]._onDragOver({
1565
- clientX: touchEvt.clientX,
1566
- clientY: touchEvt.clientY,
1567
- target: target,
1568
- rootEl: parent
1569
- });
1570
- if (inserted && !this.options.dragoverBubble) {
1571
- break;
1595
+ }, {
1596
+ key: "_emulateDragOver",
1597
+ value: function _emulateDragOver() {
1598
+ if (touchEvt) {
1599
+ this._lastX = touchEvt.clientX;
1600
+ this._lastY = touchEvt.clientY;
1601
+ _hideGhostForTarget();
1602
+ var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1603
+ var parent = target;
1604
+ while (target && target.shadowRoot) {
1605
+ target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1606
+ if (target === parent) break;
1607
+ parent = target;
1608
+ }
1609
+ dragEl.parentNode[expando]._isOutsideThisEl(target);
1610
+ if (parent) {
1611
+ do {
1612
+ if (parent[expando]) {
1613
+ var inserted = void 0;
1614
+ inserted = parent[expando]._onDragOver({
1615
+ clientX: touchEvt.clientX,
1616
+ clientY: touchEvt.clientY,
1617
+ target: target,
1618
+ rootEl: parent
1619
+ });
1620
+ if (inserted && !this.options.dragoverBubble) {
1621
+ break;
1622
+ }
1572
1623
  }
1573
- }
1574
- target = parent; // store last element
1624
+ target = parent; // store last element
1625
+ } while ((/* jshint boss:true */
1626
+ parent = getParentOrHost(parent)));
1575
1627
  }
1576
- /* jshint boss:true */ while (parent = getParentOrHost(parent));
1628
+ _unhideGhostForTarget();
1577
1629
  }
1578
- _unhideGhostForTarget();
1579
1630
  }
1580
- },
1581
- _onTouchMove: function _onTouchMove(/**TouchEvent*/evt) {
1582
- if (tapEvt) {
1583
- var options = this.options,
1584
- fallbackTolerance = options.fallbackTolerance,
1585
- fallbackOffset = options.fallbackOffset,
1586
- touch = evt.touches ? evt.touches[0] : evt,
1587
- ghostMatrix = ghostEl && matrix(ghostEl, true),
1588
- scaleX = ghostEl && ghostMatrix && ghostMatrix.a,
1589
- scaleY = ghostEl && ghostMatrix && ghostMatrix.d,
1590
- relativeScrollOffset = PositionGhostAbsolutely && ghostRelativeParent && getRelativeScrollOffset(ghostRelativeParent),
1591
- dx = (touch.clientX - tapEvt.clientX + fallbackOffset.x) / (scaleX || 1) + (relativeScrollOffset ? relativeScrollOffset[0] - ghostRelativeParentInitialScroll[0] : 0) / (scaleX || 1),
1592
- dy = (touch.clientY - tapEvt.clientY + fallbackOffset.y) / (scaleY || 1) + (relativeScrollOffset ? relativeScrollOffset[1] - ghostRelativeParentInitialScroll[1] : 0) / (scaleY || 1);
1593
-
1594
- // only set the status to dragging, when we are actually dragging
1595
- if (!Sortable.active && !awaitingDragStarted) {
1596
- if (fallbackTolerance && Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) < fallbackTolerance) {
1597
- return;
1631
+ }, {
1632
+ key: "_onTouchMove",
1633
+ value: function _onTouchMove(/**TouchEvent*/evt) {
1634
+ if (tapEvt) {
1635
+ var options = this.options,
1636
+ fallbackTolerance = options.fallbackTolerance,
1637
+ fallbackOffset = options.fallbackOffset,
1638
+ touch = evt.touches ? evt.touches[0] : evt,
1639
+ ghostMatrix = ghostEl && matrix(ghostEl, true),
1640
+ scaleX = ghostEl && ghostMatrix && ghostMatrix.a,
1641
+ scaleY = ghostEl && ghostMatrix && ghostMatrix.d,
1642
+ relativeScrollOffset = PositionGhostAbsolutely && ghostRelativeParent && getRelativeScrollOffset(ghostRelativeParent),
1643
+ dx = (touch.clientX - tapEvt.clientX + fallbackOffset.x) / (scaleX || 1) + (relativeScrollOffset ? relativeScrollOffset[0] - ghostRelativeParentInitialScroll[0] : 0) / (scaleX || 1),
1644
+ dy = (touch.clientY - tapEvt.clientY + fallbackOffset.y) / (scaleY || 1) + (relativeScrollOffset ? relativeScrollOffset[1] - ghostRelativeParentInitialScroll[1] : 0) / (scaleY || 1);
1645
+
1646
+ // only set the status to dragging, when we are actually dragging
1647
+ if (!Sortable.active && !awaitingDragStarted) {
1648
+ if (fallbackTolerance && Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) < fallbackTolerance) {
1649
+ return;
1650
+ }
1651
+ this._onDragStart(evt, true);
1598
1652
  }
1599
- this._onDragStart(evt, true);
1600
- }
1601
- if (ghostEl) {
1602
- if (ghostMatrix) {
1603
- ghostMatrix.e += dx - (lastDx || 0);
1604
- ghostMatrix.f += dy - (lastDy || 0);
1605
- } else {
1606
- ghostMatrix = {
1607
- a: 1,
1608
- b: 0,
1609
- c: 0,
1610
- d: 1,
1611
- e: dx,
1612
- f: dy
1613
- };
1653
+ if (ghostEl) {
1654
+ if (ghostMatrix) {
1655
+ ghostMatrix.e += dx - (lastDx || 0);
1656
+ ghostMatrix.f += dy - (lastDy || 0);
1657
+ } else {
1658
+ ghostMatrix = {
1659
+ a: 1,
1660
+ b: 0,
1661
+ c: 0,
1662
+ d: 1,
1663
+ e: dx,
1664
+ f: dy
1665
+ };
1666
+ }
1667
+ var cssMatrix = "matrix(".concat(ghostMatrix.a, ",").concat(ghostMatrix.b, ",").concat(ghostMatrix.c, ",").concat(ghostMatrix.d, ",").concat(ghostMatrix.e, ",").concat(ghostMatrix.f, ")");
1668
+ css(ghostEl, 'webkitTransform', cssMatrix);
1669
+ css(ghostEl, 'mozTransform', cssMatrix);
1670
+ css(ghostEl, 'msTransform', cssMatrix);
1671
+ css(ghostEl, 'transform', cssMatrix);
1672
+ lastDx = dx;
1673
+ lastDy = dy;
1674
+ touchEvt = touch;
1614
1675
  }
1615
- var cssMatrix = "matrix(".concat(ghostMatrix.a, ",").concat(ghostMatrix.b, ",").concat(ghostMatrix.c, ",").concat(ghostMatrix.d, ",").concat(ghostMatrix.e, ",").concat(ghostMatrix.f, ")");
1616
- css(ghostEl, 'webkitTransform', cssMatrix);
1617
- css(ghostEl, 'mozTransform', cssMatrix);
1618
- css(ghostEl, 'msTransform', cssMatrix);
1619
- css(ghostEl, 'transform', cssMatrix);
1620
- lastDx = dx;
1621
- lastDy = dy;
1622
- touchEvt = touch;
1676
+ evt.cancelable && evt.preventDefault();
1623
1677
  }
1624
- evt.cancelable && evt.preventDefault();
1625
1678
  }
1626
- },
1627
- _appendGhost: function _appendGhost() {
1628
- // Bug if using scale(): https://stackoverflow.com/questions/2637058
1629
- // Not being adjusted for
1630
- if (!ghostEl) {
1631
- var container = this.options.fallbackOnBody ? document.body : rootEl,
1632
- rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container),
1633
- options = this.options;
1634
-
1635
- // Position absolutely
1636
- if (PositionGhostAbsolutely) {
1637
- // Get relatively positioned parent
1638
- ghostRelativeParent = container;
1639
- while (css(ghostRelativeParent, 'position') === 'static' && css(ghostRelativeParent, 'transform') === 'none' && ghostRelativeParent !== document) {
1640
- ghostRelativeParent = ghostRelativeParent.parentNode;
1641
- }
1642
- if (ghostRelativeParent !== document.body && ghostRelativeParent !== document.documentElement) {
1643
- if (ghostRelativeParent === document) ghostRelativeParent = getWindowScrollingElement();
1644
- rect.top += ghostRelativeParent.scrollTop;
1645
- rect.left += ghostRelativeParent.scrollLeft;
1646
- } else {
1647
- ghostRelativeParent = getWindowScrollingElement();
1679
+ }, {
1680
+ key: "_appendGhost",
1681
+ value: function _appendGhost() {
1682
+ // Bug if using scale(): https://stackoverflow.com/questions/2637058
1683
+ // Not being adjusted for
1684
+ if (!ghostEl) {
1685
+ var container = this.options.fallbackOnBody ? document.body : rootEl,
1686
+ rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container),
1687
+ options = this.options;
1688
+
1689
+ // Position absolutely
1690
+ if (PositionGhostAbsolutely) {
1691
+ // Get relatively positioned parent
1692
+ ghostRelativeParent = container;
1693
+ while (css(ghostRelativeParent, 'position') === 'static' && css(ghostRelativeParent, 'transform') === 'none' && ghostRelativeParent !== document) {
1694
+ ghostRelativeParent = ghostRelativeParent.parentNode;
1695
+ }
1696
+ if (ghostRelativeParent !== document.body && ghostRelativeParent !== document.documentElement) {
1697
+ if (ghostRelativeParent === document) ghostRelativeParent = getWindowScrollingElement();
1698
+ rect.top += ghostRelativeParent.scrollTop;
1699
+ rect.left += ghostRelativeParent.scrollLeft;
1700
+ } else {
1701
+ ghostRelativeParent = getWindowScrollingElement();
1702
+ }
1703
+ ghostRelativeParentInitialScroll = getRelativeScrollOffset(ghostRelativeParent);
1648
1704
  }
1649
- ghostRelativeParentInitialScroll = getRelativeScrollOffset(ghostRelativeParent);
1650
- }
1651
- ghostEl = this.options.getGhostFallback && typeof this.options.getGhostFallback === 'function' ? this.options.getGhostFallback(dragEl) : dragEl.cloneNode(true);
1652
- toggleClass(ghostEl, options.ghostClass, false);
1653
- toggleClass(ghostEl, options.fallbackClass, true);
1654
- toggleClass(ghostEl, options.dragClass, true);
1655
- css(ghostEl, 'transition', '');
1656
- css(ghostEl, 'transform', '');
1657
- css(ghostEl, 'box-sizing', 'border-box');
1658
- css(ghostEl, 'margin', 0);
1659
- css(ghostEl, 'top', rect.top);
1660
- css(ghostEl, 'left', rect.left);
1661
- css(ghostEl, 'width', rect.width);
1662
- css(ghostEl, 'height', rect.height);
1663
- css(ghostEl, 'opacity', '0.8');
1664
- css(ghostEl, 'position', PositionGhostAbsolutely ? 'absolute' : 'fixed');
1665
- css(ghostEl, 'zIndex', '100000');
1666
- css(ghostEl, 'pointerEvents', 'none');
1667
- Sortable.ghost = ghostEl;
1668
- container.appendChild(ghostEl);
1669
-
1670
- // Set transform-origin
1671
- css(ghostEl, 'transform-origin', tapDistanceLeft / parseInt(ghostEl.style.width) * 100 + '% ' + tapDistanceTop / parseInt(ghostEl.style.height) * 100 + '%');
1705
+ ghostEl = this.options.getGhostFallback && typeof this.options.getGhostFallback === 'function' ? this.options.getGhostFallback(_getEvent({
1706
+ sortable: this,
1707
+ name: 'getGhostFallback'
1708
+ })) : dragEl.cloneNode(true);
1709
+ toggleClass(ghostEl, options.ghostClass, false);
1710
+ toggleClass(ghostEl, options.fallbackClass, true);
1711
+ toggleClass(ghostEl, options.dragClass, true);
1712
+ css(ghostEl, 'transition', '');
1713
+ css(ghostEl, 'transform', '');
1714
+ css(ghostEl, 'box-sizing', 'border-box');
1715
+ css(ghostEl, 'margin', 0);
1716
+ css(ghostEl, 'top', rect.top);
1717
+ css(ghostEl, 'left', rect.left);
1718
+ css(ghostEl, 'width', rect.width);
1719
+ css(ghostEl, 'height', rect.height);
1720
+ css(ghostEl, 'opacity', '0.8');
1721
+ css(ghostEl, 'position', PositionGhostAbsolutely ? 'absolute' : 'fixed');
1722
+ css(ghostEl, 'zIndex', '100000');
1723
+ css(ghostEl, 'pointerEvents', 'none');
1724
+ Sortable.ghost = ghostEl;
1725
+ container.appendChild(ghostEl);
1726
+
1727
+ // Set transform-origin
1728
+ css(ghostEl, 'transform-origin', tapDistanceLeft / parseInt(ghostEl.style.width) * 100 + '% ' + tapDistanceTop / parseInt(ghostEl.style.height) * 100 + '%');
1729
+ }
1672
1730
  }
1673
- },
1674
- _onDragStart: function _onDragStart(/**Event*/evt, /**boolean*/fallback) {
1675
- var _this = this;
1676
- var dataTransfer = evt.dataTransfer;
1677
- var options = _this.options;
1678
- pluginEvent('dragStart', this, {
1679
- evt: evt
1680
- });
1681
- if (Sortable.eventCanceled) {
1682
- this._onDrop();
1683
- return;
1684
- }
1685
- pluginEvent('setupClone', this);
1686
- if (!Sortable.eventCanceled) {
1687
- cloneEl = clone(dragEl);
1688
- cloneEl.removeAttribute("id");
1689
- cloneEl.draggable = false;
1690
- cloneEl.style['will-change'] = '';
1691
- this._hideClone();
1692
- toggleClass(cloneEl, this.options.chosenClass, false);
1693
- Sortable.clone = cloneEl;
1694
- }
1695
-
1696
- // #1143: IFrame support workaround
1697
- _this.cloneId = _nextTick(function () {
1698
- pluginEvent('clone', _this);
1699
- if (Sortable.eventCanceled) return;
1700
- if (!_this.options.removeCloneOnHide) {
1701
- rootEl.insertBefore(cloneEl, dragEl);
1702
- }
1703
- _this._hideClone();
1704
- _dispatchEvent({
1705
- sortable: _this,
1706
- name: 'clone'
1731
+ }, {
1732
+ key: "_onDragStart",
1733
+ value: function _onDragStart(/**Event*/evt, /**boolean*/fallback) {
1734
+ var _this = this;
1735
+ var dataTransfer = evt.dataTransfer;
1736
+ var options = _this.options;
1737
+ pluginEvent('dragStart', this, {
1738
+ evt: evt
1707
1739
  });
1708
- });
1709
- !fallback && toggleClass(dragEl, options.dragClass, true);
1710
-
1711
- // Set proper drop events
1712
- if (fallback) {
1713
- ignoreNextClick = true;
1714
- _this._loopId = setInterval(_this._emulateDragOver, 50);
1715
- } else {
1716
- // Undo what was set in _prepareDragStart before drag started
1717
- off(document, 'mouseup', _this._onDrop);
1718
- off(document, 'touchend', _this._onDrop);
1719
- off(document, 'touchcancel', _this._onDrop);
1720
- if (dataTransfer) {
1721
- dataTransfer.effectAllowed = 'move';
1722
- options.setData && options.setData.call(_this, dataTransfer, dragEl);
1723
- }
1724
- on(document, 'drop', _this);
1725
-
1726
- // #1276 fix:
1727
- css(dragEl, 'transform', 'translateZ(0)');
1728
- }
1729
- awaitingDragStarted = true;
1730
- _this._dragStartId = _nextTick(_this._dragStarted.bind(_this, fallback, evt));
1731
- on(document, 'selectstart', _this);
1732
- moved = true;
1733
- window.getSelection().removeAllRanges();
1734
- if (Safari) {
1735
- css(document.body, 'user-select', 'none');
1736
- }
1737
- },
1738
- // Returns true - if no further action is needed (either inserted or another condition)
1739
- _onDragOver: function _onDragOver(/**Event*/evt) {
1740
- var el = this.el,
1741
- target = evt.target,
1742
- dragRect,
1743
- targetRect,
1744
- revert,
1745
- options = this.options,
1746
- group = options.group,
1747
- activeSortable = Sortable.active,
1748
- isOwner = activeGroup === group,
1749
- canSort = options.sort,
1750
- fromSortable = putSortable || activeSortable,
1751
- vertical,
1752
- _this = this,
1753
- completedFired = false;
1754
- if (_silent) return;
1755
- function dragOverEvent(name, extra) {
1756
- pluginEvent(name, _this, _objectSpread2({
1757
- evt: evt,
1758
- isOwner: isOwner,
1759
- axis: vertical ? 'vertical' : 'horizontal',
1760
- revert: revert,
1761
- dragRect: dragRect,
1762
- targetRect: targetRect,
1763
- canSort: canSort,
1764
- fromSortable: fromSortable,
1765
- target: target,
1766
- completed: completed,
1767
- onMove: function onMove(target, after) {
1768
- return _onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, getRect(target), evt, after);
1769
- },
1770
- changed: changed
1771
- }, extra));
1772
- }
1773
-
1774
- // Capture animation state
1775
- function capture() {
1776
- dragOverEvent('dragOverAnimationCapture');
1777
- _this.captureAnimationState();
1778
- if (_this !== fromSortable) {
1779
- fromSortable.captureAnimationState();
1740
+ if (Sortable.eventCanceled) {
1741
+ this._onDrop();
1742
+ return;
1743
+ }
1744
+ pluginEvent('setupClone', this);
1745
+ if (!Sortable.eventCanceled) {
1746
+ cloneEl = clone(dragEl);
1747
+ cloneEl.removeAttribute('id');
1748
+ cloneEl.draggable = false;
1749
+ cloneEl.style['will-change'] = '';
1750
+ this._hideClone();
1751
+ toggleClass(cloneEl, this.options.chosenClass, false);
1752
+ Sortable.clone = cloneEl;
1780
1753
  }
1781
- }
1782
-
1783
- // Return invocation when dragEl is inserted (or completed)
1784
- function completed(insertion) {
1785
- dragOverEvent('dragOverCompleted', {
1786
- insertion: insertion
1787
- });
1788
- if (insertion) {
1789
- // Clones must be hidden before folding animation to capture dragRectAbsolute properly
1790
- if (isOwner) {
1791
- activeSortable._hideClone();
1792
- } else {
1793
- activeSortable._showClone(_this);
1794
- }
1795
- if (_this !== fromSortable) {
1796
- // Set ghost class to new sortable's ghost class
1797
- toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
1798
- toggleClass(dragEl, options.ghostClass, true);
1799
- }
1800
- if (putSortable !== _this && _this !== Sortable.active) {
1801
- putSortable = _this;
1802
- } else if (_this === Sortable.active && putSortable) {
1803
- putSortable = null;
1804
- }
1805
1754
 
1806
- // Animation
1807
- if (fromSortable === _this) {
1808
- _this._ignoreWhileAnimating = target;
1755
+ // #1143: IFrame support workaround
1756
+ _this.cloneId = _nextTick(function () {
1757
+ pluginEvent('clone', _this);
1758
+ if (Sortable.eventCanceled) return;
1759
+ if (!_this.options.removeCloneOnHide) {
1760
+ rootEl.insertBefore(cloneEl, dragEl);
1809
1761
  }
1810
- _this.animateAll(function () {
1811
- dragOverEvent('dragOverAnimationComplete');
1812
- _this._ignoreWhileAnimating = null;
1762
+ _this._hideClone();
1763
+ _dispatchEvent({
1764
+ sortable: _this,
1765
+ name: 'clone'
1813
1766
  });
1814
- if (_this !== fromSortable) {
1815
- fromSortable.animateAll();
1816
- fromSortable._ignoreWhileAnimating = null;
1767
+ });
1768
+ !fallback && toggleClass(dragEl, options.dragClass, true);
1769
+
1770
+ // Set proper drop events
1771
+ if (fallback) {
1772
+ ignoreNextClick = true;
1773
+ _this._loopId = setInterval(_this._emulateDragOver, 50);
1774
+ } else {
1775
+ // Undo what was set in _prepareDragStart before drag started
1776
+ off(document, 'mouseup', _this._onDrop);
1777
+ off(document, 'touchend', _this._onDrop);
1778
+ off(document, 'touchcancel', _this._onDrop);
1779
+ if (dataTransfer) {
1780
+ dataTransfer.effectAllowed = 'move';
1781
+ options.setData && options.setData.call(_this, dataTransfer, dragEl);
1817
1782
  }
1818
- }
1783
+ on(document, 'drop', _this);
1819
1784
 
1820
- // Null lastTarget if it is not inside a previously swapped element
1821
- if (target === dragEl && !dragEl.animated || target === el && !target.animated) {
1822
- lastTarget = null;
1785
+ // #1276 fix:
1786
+ css(dragEl, 'transform', 'translateZ(0)');
1823
1787
  }
1824
-
1825
- // no bubbling and not fallback
1826
- if (!options.dragoverBubble && !evt.rootEl && target !== document) {
1827
- dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
1828
-
1829
- // Do not detect for empty insert if already inserted
1830
- !insertion && nearestEmptyInsertDetectEvent(evt);
1788
+ awaitingDragStarted = true;
1789
+ _this._dragStartId = _nextTick(_this._dragStarted.bind(_this, fallback, evt));
1790
+ on(document, 'selectstart', _this);
1791
+ moved = true;
1792
+ window.getSelection().removeAllRanges();
1793
+ if (Safari) {
1794
+ css(document.body, 'user-select', 'none');
1831
1795
  }
1832
- !options.dragoverBubble && evt.stopPropagation && evt.stopPropagation();
1833
- return completedFired = true;
1834
1796
  }
1835
1797
 
1836
- // Call when dragEl has been inserted
1837
- function changed() {
1838
- newIndex = index(dragEl, undefined, originalDragEl);
1839
- newDraggableIndex = index(dragEl, options.draggable, originalDragEl);
1840
- _dispatchEvent({
1841
- sortable: _this,
1842
- name: 'change',
1843
- toEl: el,
1844
- newIndex: newIndex,
1845
- newDraggableIndex: newDraggableIndex,
1846
- originalEvent: evt
1847
- });
1848
- }
1849
- if (evt.preventDefault !== void 0) {
1850
- evt.cancelable && evt.preventDefault();
1851
- }
1852
- target = closest(target, options.draggable, el, true, originalDragEl);
1853
- dragOverEvent('dragOver');
1854
- if (Sortable.eventCanceled) return completedFired;
1855
- if (dragEl.contains(evt.target) || target.animated && target.animatingX && target.animatingY || _this._ignoreWhileAnimating === target) {
1856
- return completed(false);
1857
- }
1858
- ignoreNextClick = false;
1859
- if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list
1860
- : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, originalDragEl || dragEl, evt)) && group.checkPut(this, activeSortable, originalDragEl || dragEl, evt))) {
1861
- vertical = this._getDirection(evt, target) === 'vertical';
1862
- dragRect = getRect(dragEl);
1863
- dragOverEvent('dragOverValid');
1864
- if (Sortable.eventCanceled) return completedFired;
1865
- if (revert) {
1866
- parentEl = rootEl; // actualization
1867
- capture();
1868
- this._hideClone();
1869
- dragOverEvent('revert');
1870
- if (!Sortable.eventCanceled) {
1871
- if (nextEl) {
1872
- rootEl.insertBefore(dragEl, nextEl);
1873
- } else {
1874
- rootEl.appendChild(dragEl);
1875
- }
1798
+ // Returns true - if no further action is needed (either inserted or another condition)
1799
+ }, {
1800
+ key: "_onDragOver",
1801
+ value: function _onDragOver(/**Event*/evt) {
1802
+ var el = this.el,
1803
+ target = evt.target,
1804
+ dragRect,
1805
+ targetRect,
1806
+ revert,
1807
+ options = this.options,
1808
+ group = options.group,
1809
+ activeSortable = Sortable.active,
1810
+ isOwner = activeGroup === group,
1811
+ canSort = options.sort,
1812
+ fromSortable = putSortable || activeSortable,
1813
+ vertical,
1814
+ _this = this,
1815
+ completedFired = false;
1816
+ if (_silent) return;
1817
+ function dragOverEvent(name, extra) {
1818
+ pluginEvent(name, _this, _objectSpread2({
1819
+ evt: evt,
1820
+ isOwner: isOwner,
1821
+ axis: vertical ? 'vertical' : 'horizontal',
1822
+ revert: revert,
1823
+ dragRect: dragRect,
1824
+ targetRect: targetRect,
1825
+ canSort: canSort,
1826
+ fromSortable: fromSortable,
1827
+ target: target,
1828
+ completed: completed,
1829
+ onMove: function onMove(target, after) {
1830
+ return _onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, getRect(target), evt, after);
1831
+ },
1832
+ changed: changed
1833
+ }, extra));
1834
+ }
1835
+
1836
+ // Capture animation state
1837
+ function capture() {
1838
+ dragOverEvent('dragOverAnimationCapture');
1839
+ _this.captureAnimationState();
1840
+ if (_this !== fromSortable) {
1841
+ fromSortable.captureAnimationState();
1876
1842
  }
1877
- return completed(true);
1878
1843
  }
1879
- var elLastChild = lastChild(el, options.draggable);
1880
- if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
1881
- // Insert to end of list
1882
1844
 
1883
- // If already at end of list: Do not insert
1884
- if (elLastChild === dragEl) {
1885
- return completed(false);
1845
+ // Return invocation when dragEl is inserted (or completed)
1846
+ function completed(insertion) {
1847
+ dragOverEvent('dragOverCompleted', {
1848
+ insertion: insertion
1849
+ });
1850
+ if (insertion) {
1851
+ // Clones must be hidden before folding animation to capture dragRectAbsolute properly
1852
+ if (isOwner) {
1853
+ activeSortable._hideClone();
1854
+ } else {
1855
+ activeSortable._showClone(_this);
1856
+ }
1857
+ if (_this !== fromSortable) {
1858
+ // Set ghost class to new sortable's ghost class
1859
+ toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
1860
+ toggleClass(dragEl, options.ghostClass, true);
1861
+ }
1862
+ if (putSortable !== _this && _this !== Sortable.active) {
1863
+ putSortable = _this;
1864
+ } else if (_this === Sortable.active && putSortable) {
1865
+ putSortable = null;
1866
+ }
1867
+
1868
+ // Animation
1869
+ if (fromSortable === _this) {
1870
+ _this._ignoreWhileAnimating = target;
1871
+ }
1872
+ _this.animateAll(function () {
1873
+ dragOverEvent('dragOverAnimationComplete');
1874
+ _this._ignoreWhileAnimating = null;
1875
+ });
1876
+ if (_this !== fromSortable) {
1877
+ fromSortable.animateAll();
1878
+ fromSortable._ignoreWhileAnimating = null;
1879
+ }
1886
1880
  }
1887
1881
 
1888
- // if there is a last element, it is the target
1889
- if (elLastChild && el === evt.target) {
1890
- target = elLastChild;
1882
+ // Null lastTarget if it is not inside a previously swapped element
1883
+ if (target === dragEl && !dragEl.animated || target === el && !target.animated) {
1884
+ lastTarget = null;
1891
1885
  }
1892
- if (target) {
1893
- targetRect = getRect(target);
1886
+
1887
+ // no bubbling and not fallback
1888
+ if (!options.dragoverBubble && !evt.rootEl && target !== document) {
1889
+ dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
1890
+
1891
+ // Do not detect for empty insert if already inserted
1892
+ !insertion && nearestEmptyInsertDetectEvent(evt);
1894
1893
  }
1895
- if (_onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
1894
+ !options.dragoverBubble && evt.stopPropagation && evt.stopPropagation();
1895
+ return completedFired = true;
1896
+ }
1897
+
1898
+ // Call when dragEl has been inserted
1899
+ function changed() {
1900
+ newIndex = index(dragEl, undefined, [originalDragEl]);
1901
+ newDraggableIndex = index(dragEl, options.draggable, [originalDragEl]);
1902
+ _dispatchEvent({
1903
+ sortable: _this,
1904
+ name: 'change',
1905
+ toEl: el,
1906
+ newIndex: newIndex,
1907
+ newDraggableIndex: newDraggableIndex,
1908
+ originalEvent: evt
1909
+ });
1910
+ }
1911
+ if (evt.preventDefault !== void 0) {
1912
+ evt.cancelable && evt.preventDefault();
1913
+ }
1914
+ target = closest(target, options.draggable, el, true, [originalDragEl]);
1915
+ dragOverEvent('dragOver');
1916
+ if (Sortable.eventCanceled) return completedFired;
1917
+ if (dragEl.contains(evt.target) || target.animated && target.animatingX && target.animatingY || _this._ignoreWhileAnimating === target) {
1918
+ return completed(false);
1919
+ }
1920
+ ignoreNextClick = false;
1921
+ if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = parentEl !== rootEl) // Reverting item into the original list
1922
+ : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, originalDragEl || dragEl, evt)) && group.checkPut(this, activeSortable, originalDragEl || dragEl, evt))) {
1923
+ vertical = this._getDirection(evt, target) === 'vertical';
1924
+ dragRect = getRect(dragEl);
1925
+ dragOverEvent('dragOverValid');
1926
+ if (Sortable.eventCanceled) return completedFired;
1927
+ if (revert) {
1928
+ parentEl = rootEl; // actualization
1896
1929
  capture();
1897
- this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, Boolean(target));
1898
- if (elLastChild && elLastChild.nextSibling) {
1899
- // the last draggable element is not the last node
1900
- el.insertBefore(dragEl, elLastChild.nextSibling);
1901
- } else {
1902
- el.appendChild(dragEl);
1930
+ this._hideClone();
1931
+ dragOverEvent('revert');
1932
+ if (!Sortable.eventCanceled) {
1933
+ if (nextEl) {
1934
+ rootEl.insertBefore(dragEl, nextEl);
1935
+ } else {
1936
+ rootEl.appendChild(dragEl);
1937
+ }
1903
1938
  }
1904
- parentEl = el; // actualization
1905
-
1906
- changed();
1907
1939
  return completed(true);
1908
1940
  }
1909
- } else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
1910
- // Insert to start of list
1911
- var firstChild = getChild(el, 0, options, true, originalDragEl);
1912
- if (firstChild === dragEl) {
1913
- return completed(false);
1914
- }
1915
- target = firstChild;
1916
- targetRect = getRect(target);
1917
- if (_onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, false) !== false) {
1918
- this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, false);
1919
- capture();
1920
- el.insertBefore(dragEl, firstChild);
1921
- parentEl = el; // actualization
1941
+ var elLastChild = lastChild(el, options.draggable);
1942
+ if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
1943
+ // Insert to end of list
1922
1944
 
1923
- changed();
1924
- return completed(true);
1925
- }
1926
- } else if (target.parentNode === el) {
1927
- targetRect = getRect(target);
1928
- var direction = 0,
1929
- targetBeforeFirstSwap,
1930
- differentLevel = dragEl.parentNode !== el,
1931
- differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target.animated && target.toRect || targetRect, vertical),
1932
- side1 = vertical ? 'top' : 'left',
1933
- scrolledPastTop = isScrolledPast(target, 'top', 'top') || isScrolledPast(dragEl, 'top', 'top'),
1934
- scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
1935
- if (lastTarget !== target) {
1936
- targetBeforeFirstSwap = targetRect[side1];
1937
- pastFirstInvertThresh = false;
1938
- isCircumstantialInvert = !differentRowCol && options.invertSwap || differentLevel;
1939
- }
1940
- direction = _getSwapDirection(evt, target, targetRect, vertical, differentRowCol ? 1 : options.swapThreshold, options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold, isCircumstantialInvert, lastTarget === target);
1941
- var sibling;
1942
- if (direction !== 0) {
1943
- // Check if target is beside dragEl in respective direction (ignoring hidden elements)
1944
- var dragIndex = index(dragEl, undefined, originalDragEl);
1945
- do {
1946
- dragIndex -= direction;
1947
- sibling = parentEl.children[dragIndex];
1948
- } while (sibling && (css(sibling, 'display') === 'none' || sibling === ghostEl));
1949
- }
1950
- // If dragEl is already beside target: Do not insert
1951
- if (direction === 0 || sibling === target) {
1952
- return completed(false);
1953
- }
1954
- lastTarget = target;
1955
- lastDirection = direction;
1956
- var after = false;
1957
- after = direction === 1;
1958
- var moveVector = _onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, after);
1959
- if (moveVector !== false) {
1960
- if (moveVector === 1 || moveVector === -1) {
1961
- after = moveVector === 1;
1945
+ // If already at end of list: Do not insert
1946
+ if (elLastChild === dragEl) {
1947
+ return completed(false);
1962
1948
  }
1963
- _silent = true;
1964
- setTimeout(_unsilent, 30);
1965
- capture();
1966
- this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, after);
1967
- var nextSibling = target.nextElementSibling;
1968
- if (after && !nextSibling) {
1969
- el.appendChild(dragEl);
1970
- } else {
1971
- target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
1949
+
1950
+ // if there is a last element, it is the target
1951
+ if (elLastChild && el === evt.target) {
1952
+ target = elLastChild;
1972
1953
  }
1954
+ if (target) {
1955
+ targetRect = getRect(target);
1956
+ }
1957
+ if (_onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
1958
+ capture();
1959
+ this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, Boolean(target));
1960
+ if (elLastChild && elLastChild.nextSibling) {
1961
+ // the last draggable element is not the last node
1962
+ el.insertBefore(dragEl, elLastChild.nextSibling);
1963
+ } else {
1964
+ el.appendChild(dragEl);
1965
+ }
1966
+ parentEl = el; // actualization
1973
1967
 
1974
- // Undo chrome's scroll adjustment (has no effect on other browsers)
1975
- if (scrolledPastTop) {
1976
- scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
1968
+ changed();
1969
+ return completed(true);
1977
1970
  }
1978
- parentEl = dragEl.parentNode; // actualization
1971
+ } else if (elLastChild && _ghostIsFirst(evt, vertical, this)) {
1972
+ // Insert to start of list
1973
+ var firstChild = getChild(el, 0, options, true, [originalDragEl]);
1974
+ if (firstChild === dragEl) {
1975
+ return completed(false);
1976
+ }
1977
+ target = firstChild;
1978
+ targetRect = getRect(target);
1979
+ if (_onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, false) !== false) {
1980
+ this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, false);
1981
+ capture();
1982
+ el.insertBefore(dragEl, firstChild);
1983
+ parentEl = el; // actualization
1984
+
1985
+ changed();
1986
+ return completed(true);
1987
+ }
1988
+ } else if (target.parentNode === el) {
1989
+ targetRect = getRect(target);
1990
+ var direction = 0,
1991
+ targetBeforeFirstSwap,
1992
+ differentLevel = dragEl.parentNode !== el,
1993
+ differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target.animated && target.toRect || targetRect, vertical),
1994
+ side1 = vertical ? 'top' : 'left',
1995
+ scrolledPastTop = isScrolledPast(target, 'top', 'top') || isScrolledPast(dragEl, 'top', 'top'),
1996
+ scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
1997
+ if (lastTarget !== target) {
1998
+ targetBeforeFirstSwap = targetRect[side1];
1999
+ pastFirstInvertThresh = false;
2000
+ isCircumstantialInvert = !differentRowCol && options.invertSwap || differentLevel;
2001
+ }
2002
+ direction = _getSwapDirection(evt, target, targetRect, vertical, differentRowCol ? 1 : options.swapThreshold, options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold, isCircumstantialInvert, lastTarget === target);
2003
+ var sibling;
2004
+ if (direction !== 0) {
2005
+ // Check if target is beside dragEl in respective direction (ignoring hidden elements)
2006
+ var dragIndex = index(dragEl, undefined, [originalDragEl]);
2007
+ do {
2008
+ dragIndex -= direction;
2009
+ sibling = parentEl.children[dragIndex];
2010
+ } while (sibling && (css(sibling, 'display') === 'none' || sibling === ghostEl));
2011
+ }
2012
+ // If dragEl is already beside target: Do not insert
2013
+ if (direction === 0 || sibling === target) {
2014
+ return completed(false);
2015
+ }
2016
+ lastTarget = target;
2017
+ lastDirection = direction;
2018
+ var after = false;
2019
+ after = direction === 1;
2020
+ var moveVector = _onMove(rootEl, el, originalDragEl || dragEl, dragRect, target, targetRect, evt, after);
2021
+ if (moveVector !== false) {
2022
+ if (moveVector === 1 || moveVector === -1) {
2023
+ after = moveVector === 1;
2024
+ }
2025
+ _silent = true;
2026
+ setTimeout(_unsilent, 30);
2027
+ capture();
2028
+ this._getPlaceholderOnMove(el, dragRect, target, targetRect, evt, after);
2029
+ var nextSibling = target.nextElementSibling;
2030
+ if (after && !nextSibling) {
2031
+ el.appendChild(dragEl);
2032
+ } else {
2033
+ target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
2034
+ }
1979
2035
 
1980
- // must be done before animation
1981
- if (targetBeforeFirstSwap !== undefined && !isCircumstantialInvert) {
1982
- targetMoveDistance = Math.abs(targetBeforeFirstSwap - getRect(target)[side1]);
2036
+ // Undo chrome's scroll adjustment (has no effect on other browsers)
2037
+ if (scrolledPastTop) {
2038
+ scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
2039
+ }
2040
+ parentEl = dragEl.parentNode; // actualization
2041
+
2042
+ // must be done before animation
2043
+ if (targetBeforeFirstSwap !== undefined && !isCircumstantialInvert) {
2044
+ targetMoveDistance = Math.abs(targetBeforeFirstSwap - getRect(target)[side1]);
2045
+ }
2046
+ changed();
2047
+ return completed(true);
1983
2048
  }
1984
- changed();
1985
- return completed(true);
2049
+ }
2050
+ if (el.contains(dragEl)) {
2051
+ return completed(false);
1986
2052
  }
1987
2053
  }
1988
- if (el.contains(dragEl)) {
1989
- return completed(false);
1990
- }
1991
- }
1992
- return false;
1993
- },
1994
- _ignoreWhileAnimating: null,
1995
- _offMoveEvents: function _offMoveEvents() {
1996
- off(document, 'mousemove', this._onTouchMove);
1997
- off(document, 'touchmove', this._onTouchMove);
1998
- off(document, 'pointermove', this._onTouchMove);
1999
- off(document, 'dragover', nearestEmptyInsertDetectEvent);
2000
- off(document, 'mousemove', nearestEmptyInsertDetectEvent);
2001
- off(document, 'touchmove', nearestEmptyInsertDetectEvent);
2002
- },
2003
- _offUpEvents: function _offUpEvents() {
2004
- var ownerDocument = this.el.ownerDocument;
2005
- off(ownerDocument, 'mouseup', this._onDrop);
2006
- off(ownerDocument, 'touchend', this._onDrop);
2007
- off(ownerDocument, 'pointerup', this._onDrop);
2008
- off(ownerDocument, 'pointercancel', this._onDrop);
2009
- off(ownerDocument, 'touchcancel', this._onDrop);
2010
- off(document, 'selectstart', this);
2011
- },
2012
- _onDrop: function _onDrop(/**Event*/evt) {
2013
- var el = this.el,
2014
- options = this.options;
2015
-
2016
- // Get the index of the dragged element within its parent
2017
- newIndex = index(dragEl, undefined, originalDragEl);
2018
- newDraggableIndex = index(dragEl, options.draggable, originalDragEl);
2019
- pluginEvent('drop', this, {
2020
- evt: evt
2021
- });
2022
- parentEl = dragEl && dragEl.parentNode;
2023
-
2024
- // Get again after plugin event
2025
- newIndex = index(dragEl, undefined, originalDragEl);
2026
- newDraggableIndex = index(dragEl, options.draggable, originalDragEl);
2027
- if (Sortable.eventCanceled) {
2028
- this._nulling();
2029
- return;
2054
+ return false;
2030
2055
  }
2031
- awaitingDragStarted = false;
2032
- isCircumstantialInvert = false;
2033
- pastFirstInvertThresh = false;
2034
- clearInterval(this._loopId);
2035
- clearTimeout(this._dragStartTimer);
2036
- _cancelNextTick(this.cloneId);
2037
- _cancelNextTick(this._dragStartId);
2038
-
2039
- // Unbind events
2040
- if (this.nativeDraggable) {
2041
- off(document, 'drop', this);
2042
- off(el, 'dragstart', this._onDragStart);
2056
+ }, {
2057
+ key: "_offMoveEvents",
2058
+ value: function _offMoveEvents() {
2059
+ off(document, 'mousemove', this._onTouchMove);
2060
+ off(document, 'touchmove', this._onTouchMove);
2061
+ off(document, 'pointermove', this._onTouchMove);
2062
+ off(document, 'dragover', nearestEmptyInsertDetectEvent);
2063
+ off(document, 'mousemove', nearestEmptyInsertDetectEvent);
2064
+ off(document, 'touchmove', nearestEmptyInsertDetectEvent);
2043
2065
  }
2044
- this._offMoveEvents();
2045
- this._offUpEvents();
2046
- if (Safari) {
2047
- css(document.body, 'user-select', '');
2066
+ }, {
2067
+ key: "_offUpEvents",
2068
+ value: function _offUpEvents() {
2069
+ var ownerDocument = this.el.ownerDocument;
2070
+ off(ownerDocument, 'mouseup', this._onDrop);
2071
+ off(ownerDocument, 'touchend', this._onDrop);
2072
+ off(ownerDocument, 'pointerup', this._onDrop);
2073
+ off(ownerDocument, 'pointercancel', this._onDrop);
2074
+ off(ownerDocument, 'touchcancel', this._onDrop);
2075
+ off(document, 'selectstart', this);
2048
2076
  }
2049
- css(dragEl, 'transform', '');
2050
- if (evt) {
2051
- if (moved) {
2052
- evt.cancelable && evt.preventDefault();
2053
- !options.dropBubble && evt.stopPropagation();
2077
+ }, {
2078
+ key: "_onDrop",
2079
+ value: function _onDrop(/**Event*/evt) {
2080
+ var el = this.el,
2081
+ options = this.options;
2082
+
2083
+ // Get the index of the dragged element within its parent
2084
+ newIndex = index(dragEl, undefined, [originalDragEl]);
2085
+ newDraggableIndex = index(dragEl, options.draggable, [originalDragEl]);
2086
+ pluginEvent('drop', this, {
2087
+ evt: evt
2088
+ });
2089
+ parentEl = dragEl && dragEl.parentNode;
2090
+
2091
+ // Get again after plugin event
2092
+ newIndex = index(dragEl, undefined, [originalDragEl]);
2093
+ newDraggableIndex = index(dragEl, options.draggable, [originalDragEl]);
2094
+ if (Sortable.eventCanceled) {
2095
+ this._nulling();
2096
+ return;
2054
2097
  }
2055
- ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
2056
- if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
2057
- // Remove clone(s)
2058
- cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
2098
+ awaitingDragStarted = false;
2099
+ isCircumstantialInvert = false;
2100
+ pastFirstInvertThresh = false;
2101
+ clearInterval(this._loopId);
2102
+ clearTimeout(this._dragStartTimer);
2103
+ _cancelNextTick(this.cloneId);
2104
+ _cancelNextTick(this._dragStartId);
2105
+
2106
+ // Unbind events
2107
+ if (this.nativeDraggable) {
2108
+ off(document, 'drop', this);
2109
+ off(el, 'dragstart', this._onDragStart);
2059
2110
  }
2060
- if (dragEl) {
2061
- if (this.nativeDraggable) {
2062
- off(dragEl, 'dragend', this);
2111
+ this._offMoveEvents();
2112
+ this._offUpEvents();
2113
+ if (Safari) {
2114
+ css(document.body, 'user-select', '');
2115
+ }
2116
+ css(dragEl, 'transform', '');
2117
+ if (evt) {
2118
+ if (moved) {
2119
+ evt.cancelable && evt.preventDefault();
2120
+ !options.dropBubble && evt.stopPropagation();
2063
2121
  }
2064
- _disableDraggable(dragEl);
2065
- dragEl.style['will-change'] = '';
2066
-
2067
- // Remove classes
2068
- // ghostClass is added in dragStarted
2069
- if (moved && !awaitingDragStarted) {
2070
- toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : this.options.ghostClass, false);
2122
+ ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
2123
+ if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
2124
+ // Remove clone(s)
2125
+ cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
2071
2126
  }
2072
- toggleClass(dragEl, this.options.chosenClass, false);
2073
-
2074
- // Drag stop event
2075
- _dispatchEvent({
2076
- sortable: this,
2077
- name: 'unchoose',
2078
- toEl: parentEl,
2079
- newIndex: null,
2080
- newDraggableIndex: null,
2081
- originalEvent: evt
2082
- });
2083
- if (rootEl !== parentEl) {
2084
- if (newIndex >= 0) {
2085
- // Add event
2086
- _dispatchEvent({
2087
- rootEl: parentEl,
2088
- name: 'add',
2089
- toEl: parentEl,
2090
- fromEl: rootEl,
2091
- originalEvent: evt
2092
- });
2093
-
2094
- // Remove event
2095
- _dispatchEvent({
2096
- sortable: this,
2097
- name: 'remove',
2098
- toEl: parentEl,
2099
- originalEvent: evt
2100
- });
2127
+ if (dragEl) {
2128
+ if (this.nativeDraggable) {
2129
+ off(dragEl, 'dragend', this);
2130
+ }
2131
+ _disableDraggable(dragEl);
2132
+ dragEl.style['will-change'] = '';
2101
2133
 
2102
- // drag from one list and drop into another
2103
- _dispatchEvent({
2104
- rootEl: parentEl,
2105
- name: 'sort',
2106
- toEl: parentEl,
2107
- fromEl: rootEl,
2108
- originalEvent: evt
2109
- });
2110
- _dispatchEvent({
2111
- sortable: this,
2112
- name: 'sort',
2113
- toEl: parentEl,
2114
- originalEvent: evt
2115
- });
2134
+ // Remove classes
2135
+ // ghostClass is added in dragStarted
2136
+ if (moved && !awaitingDragStarted) {
2137
+ toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : this.options.ghostClass, false);
2116
2138
  }
2117
- putSortable && putSortable.save();
2118
- } else {
2119
- if (newIndex !== oldIndex) {
2139
+ toggleClass(dragEl, this.options.chosenClass, false);
2140
+
2141
+ // Drag stop event
2142
+ _dispatchEvent({
2143
+ sortable: this,
2144
+ name: 'unchoose',
2145
+ toEl: parentEl,
2146
+ newIndex: null,
2147
+ newDraggableIndex: null,
2148
+ originalEvent: evt
2149
+ });
2150
+ if (rootEl !== parentEl) {
2120
2151
  if (newIndex >= 0) {
2121
- // drag & drop within the same list
2152
+ // Add event
2153
+ _dispatchEvent({
2154
+ rootEl: parentEl,
2155
+ name: 'add',
2156
+ toEl: parentEl,
2157
+ fromEl: rootEl,
2158
+ originalEvent: evt
2159
+ });
2160
+
2161
+ // Remove event
2122
2162
  _dispatchEvent({
2123
2163
  sortable: this,
2124
- name: 'update',
2164
+ name: 'remove',
2165
+ toEl: parentEl,
2166
+ originalEvent: evt
2167
+ });
2168
+
2169
+ // drag from one list and drop into another
2170
+ _dispatchEvent({
2171
+ rootEl: parentEl,
2172
+ name: 'sort',
2125
2173
  toEl: parentEl,
2174
+ fromEl: rootEl,
2126
2175
  originalEvent: evt
2127
2176
  });
2128
2177
  _dispatchEvent({
@@ -2132,198 +2181,289 @@ Sortable.prototype = /** @lends Sortable.prototype */{
2132
2181
  originalEvent: evt
2133
2182
  });
2134
2183
  }
2184
+ putSortable && putSortable.save();
2185
+ } else {
2186
+ if (newIndex !== oldIndex) {
2187
+ if (newIndex >= 0) {
2188
+ // drag & drop within the same list
2189
+ _dispatchEvent({
2190
+ sortable: this,
2191
+ name: 'update',
2192
+ toEl: parentEl,
2193
+ originalEvent: evt
2194
+ });
2195
+ _dispatchEvent({
2196
+ sortable: this,
2197
+ name: 'sort',
2198
+ toEl: parentEl,
2199
+ originalEvent: evt
2200
+ });
2201
+ }
2202
+ }
2135
2203
  }
2136
- }
2137
- if (Sortable.active) {
2138
- /* jshint eqnull:true */
2139
- if (newIndex == null || newIndex === -1) {
2140
- newIndex = oldIndex;
2141
- newDraggableIndex = oldDraggableIndex;
2142
- }
2143
- _dispatchEvent({
2144
- sortable: this,
2145
- name: 'end',
2146
- toEl: parentEl,
2147
- originalEvent: evt
2148
- });
2204
+ if (Sortable.active) {
2205
+ /* jshint eqnull:true */
2206
+ if (newIndex == null || newIndex === -1) {
2207
+ newIndex = oldIndex;
2208
+ newDraggableIndex = oldDraggableIndex;
2209
+ }
2210
+ _dispatchEvent({
2211
+ sortable: this,
2212
+ name: 'end',
2213
+ toEl: parentEl,
2214
+ originalEvent: evt
2215
+ });
2149
2216
 
2150
- // Save sorting
2151
- this.save();
2217
+ // Save sorting
2218
+ this.save();
2219
+ }
2152
2220
  }
2153
2221
  }
2222
+ this._nulling();
2154
2223
  }
2155
- this._nulling();
2156
- },
2157
- _nulling: function _nulling() {
2158
- pluginEvent('nulling', this);
2159
- this._removeClonedSelectedItem();
2160
- rootEl = dragEl = originalDragEl = originalDragElDisplay = parentEl = ghostEl = nextEl = cloneEl = lastDownEl = cloneHidden = tapEvt = touchEvt = moved = newIndex = newDraggableIndex = oldIndex = oldDraggableIndex = lastTarget = lastDirection = putSortable = activeGroup = Sortable.dragged = Sortable.ghost = Sortable.clone = Sortable.active = null;
2161
- var el = this.el;
2162
- savedInputChecked.forEach(function (checkEl) {
2163
- if (el.contains(checkEl)) {
2164
- checkEl.checked = true;
2165
- }
2166
- });
2167
- savedInputChecked.length = lastDx = lastDy = 0;
2168
- },
2169
- handleEvent: function handleEvent(/**Event*/evt) {
2170
- switch (evt.type) {
2171
- case 'drop':
2172
- case 'dragend':
2173
- this._onDrop(evt);
2174
- break;
2175
- case 'dragenter':
2176
- case 'dragover':
2177
- if (dragEl) {
2178
- this._onDragOver(evt);
2179
- _globalDragOver(evt);
2224
+ }, {
2225
+ key: "_nulling",
2226
+ value: function _nulling() {
2227
+ pluginEvent('nulling', this);
2228
+ this._removeClonedSelectedItem();
2229
+ rootEl = dragEl = originalDragEl = originalDragElDisplay = parentEl = ghostEl = nextEl = cloneEl = lastDownEl = cloneHidden = tapEvt = touchEvt = moved = newIndex = newDraggableIndex = oldIndex = oldDraggableIndex = lastTarget = lastDirection = putSortable = activeGroup = Sortable.dragged = Sortable.ghost = Sortable.clone = Sortable.active = null;
2230
+ var el = this.el;
2231
+ savedInputChecked.forEach(function (checkEl) {
2232
+ if (el.contains(checkEl)) {
2233
+ checkEl.checked = true;
2180
2234
  }
2181
- break;
2182
- case 'selectstart':
2183
- evt.preventDefault();
2184
- break;
2235
+ });
2236
+ savedInputChecked.length = lastDx = lastDy = 0;
2185
2237
  }
2186
- },
2187
- /**
2188
- * Serializes the item into an array of string.
2189
- * @returns {String[]}
2190
- */
2191
- toArray: function toArray() {
2192
- var order = [],
2193
- el,
2194
- children = this.el.children,
2195
- i = 0,
2196
- n = children.length,
2197
- options = this.options;
2198
- for (; i < n; i++) {
2199
- el = children[i];
2200
- if (closest(el, options.draggable, this.el, false, originalDragEl)) {
2201
- order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
2238
+ }, {
2239
+ key: "handleEvent",
2240
+ value: function handleEvent(/**Event*/evt) {
2241
+ switch (evt.type) {
2242
+ case 'drop':
2243
+ case 'dragend':
2244
+ this._onDrop(evt);
2245
+ break;
2246
+ case 'dragenter':
2247
+ case 'dragover':
2248
+ if (dragEl) {
2249
+ this._onDragOver(evt);
2250
+ _globalDragOver(evt);
2251
+ }
2252
+ break;
2253
+ case 'selectstart':
2254
+ evt.preventDefault();
2255
+ break;
2202
2256
  }
2203
2257
  }
2204
- return order;
2205
- },
2206
- /**
2207
- * Sorts the elements according to the array.
2208
- * @param {String[]} order order of the items
2209
- */
2210
- sort: function sort(order, useAnimation) {
2211
- var items = {},
2212
- rootEl = this.el;
2213
- this.toArray().forEach(function (id, i) {
2214
- var el = rootEl.children[i];
2215
- if (closest(el, this.options.draggable, rootEl, false, originalDragEl)) {
2216
- items[id] = el;
2217
- }
2218
- }, this);
2219
- useAnimation && this.captureAnimationState();
2220
- order.forEach(function (id) {
2221
- if (items[id]) {
2222
- rootEl.removeChild(items[id]);
2223
- rootEl.appendChild(items[id]);
2258
+
2259
+ /**
2260
+ * Serializes the item into an array of string.
2261
+ * @returns {String[]}
2262
+ */
2263
+ }, {
2264
+ key: "toArray",
2265
+ value: function toArray() {
2266
+ var order = [],
2267
+ el,
2268
+ children = this.el.children,
2269
+ i = 0,
2270
+ n = children.length,
2271
+ options = this.options;
2272
+ for (; i < n; i++) {
2273
+ el = children[i];
2274
+ if (closest(el, options.draggable, this.el, false, [originalDragEl])) {
2275
+ order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
2276
+ }
2224
2277
  }
2225
- });
2226
- useAnimation && this.animateAll();
2227
- },
2228
- /**
2229
- * Save the current sorting
2230
- */
2231
- save: function save() {
2232
- var store = this.options.store;
2233
- store && store.set && store.set(this);
2234
- },
2235
- /**
2236
- * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
2237
- * @param {HTMLElement} el
2238
- * @param {String} [selector] default: `options.draggable`
2239
- * @returns {HTMLElement|null}
2240
- */
2241
- closest: function closest$1(el, selector) {
2242
- return closest(el, selector || this.options.draggable, this.el, false, originalDragEl);
2243
- },
2244
- /**
2245
- * Set/get option
2246
- * @param {string} name
2247
- * @param {*} [value]
2248
- * @returns {*}
2249
- */
2250
- option: function option(name, value) {
2251
- var options = this.options;
2252
- if (value === void 0) {
2253
- return options[name];
2254
- } else {
2255
- var modifiedValue = PluginManager.modifyOption(this, name, value);
2256
- if (typeof modifiedValue !== 'undefined') {
2257
- options[name] = modifiedValue;
2278
+ return order;
2279
+ }
2280
+
2281
+ /**
2282
+ * Sorts the elements according to the array.
2283
+ * @param {String[]} order order of the items
2284
+ */
2285
+ }, {
2286
+ key: "sort",
2287
+ value: function sort(order, useAnimation) {
2288
+ var items = {},
2289
+ rootEl = this.el;
2290
+ this.toArray().forEach(function (id, i) {
2291
+ var el = rootEl.children[i];
2292
+ if (closest(el, this.options.draggable, rootEl, false, [originalDragEl])) {
2293
+ items[id] = el;
2294
+ }
2295
+ }, this);
2296
+ useAnimation && this.captureAnimationState();
2297
+ order.forEach(function (id) {
2298
+ if (items[id]) {
2299
+ rootEl.removeChild(items[id]);
2300
+ rootEl.appendChild(items[id]);
2301
+ }
2302
+ });
2303
+ useAnimation && this.animateAll();
2304
+ }
2305
+
2306
+ /**
2307
+ * Save the current sorting
2308
+ */
2309
+ }, {
2310
+ key: "save",
2311
+ value: function save() {
2312
+ var store = this.options.store;
2313
+ store && store.set && store.set(this);
2314
+ }
2315
+
2316
+ /**
2317
+ * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
2318
+ * @param {HTMLElement} el
2319
+ * @param {String} [selector] default: `options.draggable`
2320
+ * @returns {HTMLElement|null}
2321
+ */
2322
+ }, {
2323
+ key: "closest",
2324
+ value: function closest$1(el, selector) {
2325
+ return closest(el, selector || this.options.draggable, this.el, false, [originalDragEl]);
2326
+ }
2327
+
2328
+ /**
2329
+ * Set/get option
2330
+ * @param {string} name
2331
+ * @param {*} [value]
2332
+ * @returns {*}
2333
+ */
2334
+ }, {
2335
+ key: "option",
2336
+ value: function option(name, value) {
2337
+ var options = this.options;
2338
+ if (value === void 0) {
2339
+ return options[name];
2258
2340
  } else {
2259
- options[name] = value;
2260
- }
2261
- if (name === 'group') {
2262
- _prepareGroup(options);
2341
+ var modifiedValue = PluginManager.modifyOption(this, name, value);
2342
+ if (typeof modifiedValue !== 'undefined') {
2343
+ options[name] = modifiedValue;
2344
+ } else {
2345
+ options[name] = value;
2346
+ }
2347
+ if (name === 'group') {
2348
+ _prepareGroup(options);
2349
+ }
2263
2350
  }
2264
2351
  }
2265
- },
2266
- /**
2267
- * Destroy
2268
- */
2269
- destroy: function destroy() {
2270
- pluginEvent('destroy', this);
2271
- var el = this.el;
2272
- el[expando] = null;
2273
- off(el, 'mousedown', this._onTapStart);
2274
- off(el, 'touchstart', this._onTapStart);
2275
- off(el, 'pointerdown', this._onTapStart);
2276
- if (this.nativeDraggable) {
2277
- off(el, 'dragover', this);
2278
- off(el, 'dragenter', this);
2352
+
2353
+ /**
2354
+ * Destroy
2355
+ */
2356
+ }, {
2357
+ key: "destroy",
2358
+ value: function destroy() {
2359
+ pluginEvent('destroy', this);
2360
+ var el = this.el;
2361
+ el[expando] = null;
2362
+ off(el, 'mousedown', this._onTapStart);
2363
+ off(el, 'touchstart', this._onTapStart);
2364
+ off(el, 'pointerdown', this._onTapStart);
2365
+ if (this.nativeDraggable) {
2366
+ off(el, 'dragover', this);
2367
+ off(el, 'dragenter', this);
2368
+ }
2369
+ // Remove draggable attributes
2370
+ Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {
2371
+ el.removeAttribute('draggable');
2372
+ });
2373
+ this._onDrop();
2374
+ this._disableDelayedDragEvents();
2375
+ sortables.splice(sortables.indexOf(this.el), 1);
2376
+ this.el = el = null;
2279
2377
  }
2280
- // Remove draggable attributes
2281
- Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {
2282
- el.removeAttribute('draggable');
2283
- });
2284
- this._onDrop();
2285
- this._disableDelayedDragEvents();
2286
- sortables.splice(sortables.indexOf(this.el), 1);
2287
- this.el = el = null;
2288
- },
2289
- _hideClone: function _hideClone() {
2290
- if (!cloneHidden) {
2291
- pluginEvent('hideClone', this);
2292
- if (Sortable.eventCanceled) return;
2293
- css(cloneEl, 'display', 'none');
2294
- if (this.options.removeCloneOnHide && cloneEl.parentNode) {
2295
- cloneEl.parentNode.removeChild(cloneEl);
2378
+ }, {
2379
+ key: "_hideClone",
2380
+ value: function _hideClone() {
2381
+ if (!cloneHidden) {
2382
+ pluginEvent('hideClone', this);
2383
+ if (Sortable.eventCanceled) return;
2384
+ css(cloneEl, 'display', 'none');
2385
+ if (this.options.removeCloneOnHide && cloneEl.parentNode) {
2386
+ cloneEl.parentNode.removeChild(cloneEl);
2387
+ }
2388
+ cloneHidden = true;
2296
2389
  }
2297
- cloneHidden = true;
2298
2390
  }
2299
- },
2300
- _showClone: function _showClone(putSortable) {
2301
- if (putSortable.lastPutMode !== 'clone') {
2302
- this._hideClone();
2303
- return;
2304
- }
2305
- if (cloneHidden) {
2306
- pluginEvent('showClone', this);
2307
- if (Sortable.eventCanceled) return;
2308
-
2309
- // show clone at dragEl or original position
2310
- if (typeof this.options.getPlaceholder !== 'function' && typeof this.options.getPlaceholderOnMove !== 'function') {
2311
- if (dragEl.parentNode == rootEl && !this.options.group.revertClone) {
2312
- rootEl.insertBefore(cloneEl, dragEl);
2313
- } else if (nextEl) {
2314
- rootEl.insertBefore(cloneEl, nextEl);
2315
- } else {
2316
- rootEl.appendChild(cloneEl);
2391
+ }, {
2392
+ key: "_showClone",
2393
+ value: function _showClone(putSortable) {
2394
+ if (putSortable.lastPutMode !== 'clone') {
2395
+ this._hideClone();
2396
+ return;
2397
+ }
2398
+ if (cloneHidden) {
2399
+ pluginEvent('showClone', this);
2400
+ if (Sortable.eventCanceled) return;
2401
+
2402
+ // show clone at dragEl or original position
2403
+ if (typeof this.options.getPlaceholder !== 'function' && typeof this.options.getPlaceholderOnMove !== 'function') {
2404
+ if (dragEl.parentNode == rootEl && !this.options.group.revertClone) {
2405
+ rootEl.insertBefore(cloneEl, dragEl);
2406
+ } else if (nextEl) {
2407
+ rootEl.insertBefore(cloneEl, nextEl);
2408
+ } else {
2409
+ rootEl.appendChild(cloneEl);
2410
+ }
2411
+ }
2412
+ if (this.options.group.revertClone) {
2413
+ this.animate(dragEl, cloneEl);
2317
2414
  }
2415
+ css(cloneEl, 'display', '');
2416
+ cloneHidden = false;
2318
2417
  }
2319
- if (this.options.group.revertClone) {
2320
- this.animate(dragEl, cloneEl);
2418
+ }
2419
+ }], [{
2420
+ key: "get",
2421
+ value: function get(element) {
2422
+ return element[expando];
2423
+ }
2424
+ }, {
2425
+ key: "mount",
2426
+ value: function mount() {
2427
+ for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
2428
+ plugins[_key] = arguments[_key];
2321
2429
  }
2322
- css(cloneEl, 'display', '');
2323
- cloneHidden = false;
2430
+ if (plugins[0].constructor === Array) plugins = plugins[0];
2431
+ plugins.forEach(function (plugin) {
2432
+ if (!plugin.prototype || !plugin.prototype.constructor) {
2433
+ throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin));
2434
+ }
2435
+ if (plugin.utils) Sortable.utils = _objectSpread2(_objectSpread2({}, Sortable.utils), plugin.utils);
2436
+ PluginManager.mount(plugin);
2437
+ });
2324
2438
  }
2325
- }
2326
- };
2439
+ }, {
2440
+ key: "create",
2441
+ value: function create(el, options) {
2442
+ return new Sortable(el, options);
2443
+ }
2444
+ }]);
2445
+ }();
2446
+ _defineProperty(Sortable, "utils", {
2447
+ on: on,
2448
+ off: off,
2449
+ css: css,
2450
+ find: find,
2451
+ is: function is(el, selector) {
2452
+ return !!closest(el, selector, el, false, [originalDragEl]);
2453
+ },
2454
+ extend: extend,
2455
+ throttle: throttle,
2456
+ closest: closest,
2457
+ toggleClass: toggleClass,
2458
+ clone: clone,
2459
+ index: index,
2460
+ nextTick: _nextTick,
2461
+ cancelNextTick: _cancelNextTick,
2462
+ detectDirection: _detectDirection,
2463
+ getChild: getChild,
2464
+ expando: expando
2465
+ });
2466
+ _defineProperty(Sortable, "version", version);
2327
2467
  function _globalDragOver(/**Event*/evt) {
2328
2468
  if (evt.dataTransfer) {
2329
2469
  evt.dataTransfer.dropEffect = 'move';
@@ -2350,6 +2490,15 @@ var getMoveEvent = function getMoveEvent(fromEl, toEl, dragEl, dragRect, targetE
2350
2490
  evt.relatedRect = targetRect || getRect(toEl);
2351
2491
  evt.willInsertAfter = willInsertAfter;
2352
2492
  evt.originalEvent = originalEvent;
2493
+
2494
+ // Add plugin properties
2495
+ var sortable = fromEl[expando];
2496
+ if (sortable) {
2497
+ var allEventProperties = _objectSpread2({}, PluginManager.getEventProperties('move', sortable));
2498
+ for (var option in allEventProperties) {
2499
+ evt[option] = allEventProperties[option];
2500
+ }
2501
+ }
2353
2502
  return evt;
2354
2503
  };
2355
2504
  function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvent, willInsertAfter) {
@@ -2370,14 +2519,14 @@ function _unsilent() {
2370
2519
  _silent = false;
2371
2520
  }
2372
2521
  function _ghostIsFirst(evt, vertical, sortable) {
2373
- var firstElRect = getRect(getChild(sortable.el, 0, sortable.options, true, originalDragEl));
2374
- var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl, originalDragEl);
2522
+ var firstElRect = getRect(getChild(sortable.el, 0, sortable.options, true, [originalDragEl]));
2523
+ var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl, [originalDragEl]);
2375
2524
  var spacer = 10;
2376
2525
  return vertical ? evt.clientX < childContainingRect.left - spacer || evt.clientY < firstElRect.top && evt.clientX < firstElRect.right : evt.clientY < childContainingRect.top - spacer || evt.clientY < firstElRect.bottom && evt.clientX < firstElRect.left;
2377
2526
  }
2378
2527
  function _ghostIsLast(evt, vertical, sortable) {
2379
2528
  var lastElRect = getRect(lastChild(sortable.el, sortable.options.draggable));
2380
- var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl, originalDragEl);
2529
+ var childContainingRect = getChildContainingRectFromElement(sortable.el, sortable.options, ghostEl, [originalDragEl]);
2381
2530
  var spacer = 10;
2382
2531
  return vertical ? evt.clientX > childContainingRect.right + spacer || evt.clientY > lastElRect.bottom && evt.clientX > lastElRect.left : evt.clientY > childContainingRect.bottom + spacer || evt.clientX > lastElRect.right && evt.clientY > lastElRect.top;
2383
2532
  }
@@ -2422,25 +2571,25 @@ function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, inv
2422
2571
  return 0;
2423
2572
  }
2424
2573
 
2425
- /**
2426
- * Gets the direction dragEl must be swapped relative to target in order to make it
2427
- * seem that dragEl has been "inserted" into that element's position
2428
- * @param {HTMLElement} target The target whose position dragEl is being inserted at
2429
- * @return {Number} Direction dragEl must be swapped
2574
+ /**
2575
+ * Gets the direction dragEl must be swapped relative to target in order to make it
2576
+ * seem that dragEl has been "inserted" into that element's position
2577
+ * @param {HTMLElement} target The target whose position dragEl is being inserted at
2578
+ * @return {Number} Direction dragEl must be swapped
2430
2579
  */
2431
2580
  function _getInsertDirection(target) {
2432
- if (index(dragEl, undefined, originalDragEl) < index(target, undefined, originalDragEl)) {
2581
+ if (index(dragEl, undefined, [originalDragEl]) < index(target, undefined, [originalDragEl])) {
2433
2582
  return 1;
2434
2583
  } else {
2435
2584
  return -1;
2436
2585
  }
2437
2586
  }
2438
2587
 
2439
- /**
2440
- * Generate id
2441
- * @param {HTMLElement} el
2442
- * @returns {String}
2443
- * @private
2588
+ /**
2589
+ * Generate id
2590
+ * @param {HTMLElement} el
2591
+ * @returns {String}
2592
+ * @private
2444
2593
  */
2445
2594
  function _generateId(el) {
2446
2595
  var str = el.tagName + el.className + el.src + el.href + el.textContent,
@@ -2483,7 +2632,7 @@ Sortable.utils = {
2483
2632
  css: css,
2484
2633
  find: find,
2485
2634
  is: function is(el, selector) {
2486
- return !!closest(el, selector, el, false, originalDragEl);
2635
+ return !!closest(el, selector, el, false, [originalDragEl]);
2487
2636
  },
2488
2637
  extend: extend,
2489
2638
  throttle: throttle,
@@ -2498,22 +2647,22 @@ Sortable.utils = {
2498
2647
  expando: expando
2499
2648
  };
2500
2649
 
2501
- /**
2502
- * Get the Sortable instance of an element
2503
- * @param {HTMLElement} element The element
2504
- * @return {Sortable|undefined} The instance of Sortable
2650
+ /**
2651
+ * Get the Sortable instance of an element
2652
+ * @param {HTMLElement} element The element
2653
+ * @return {Sortable|undefined} The instance of Sortable
2505
2654
  */
2506
2655
  Sortable.get = function (element) {
2507
2656
  return element[expando];
2508
2657
  };
2509
2658
 
2510
- /**
2511
- * Mount a plugin to Sortable
2512
- * @param {...SortablePlugin|SortablePlugin[]} plugins Plugins being mounted
2659
+ /**
2660
+ * Mount a plugin to Sortable
2661
+ * @param {...SortablePlugin|SortablePlugin[]} plugins Plugins being mounted
2513
2662
  */
2514
2663
  Sortable.mount = function () {
2515
- for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
2516
- plugins[_key] = arguments[_key];
2664
+ for (var _len2 = arguments.length, plugins = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
2665
+ plugins[_key2] = arguments[_key2];
2517
2666
  }
2518
2667
  if (plugins[0].constructor === Array) plugins = plugins[0];
2519
2668
  plugins.forEach(function (plugin) {
@@ -2525,10 +2674,10 @@ Sortable.mount = function () {
2525
2674
  });
2526
2675
  };
2527
2676
 
2528
- /**
2529
- * Create sortable instance
2530
- * @param {HTMLElement} el
2531
- * @param {Object} [options]
2677
+ /**
2678
+ * Create sortable instance
2679
+ * @param {HTMLElement} el
2680
+ * @param {Object} [options]
2532
2681
  */
2533
2682
  Sortable.create = function (el, options) {
2534
2683
  return new Sortable(el, options);
@@ -2754,97 +2903,163 @@ var autoScroll = throttle(function (evt, options, rootEl, isFallback) {
2754
2903
  }, 30);
2755
2904
 
2756
2905
  var originalDragEl$1;
2757
- var drop = function drop(_ref) {
2758
- var originalEvent = _ref.originalEvent,
2759
- putSortable = _ref.putSortable,
2760
- dragEl = _ref.dragEl,
2761
- activeSortable = _ref.activeSortable,
2762
- dispatchSortableEvent = _ref.dispatchSortableEvent,
2763
- hideGhostForTarget = _ref.hideGhostForTarget,
2764
- unhideGhostForTarget = _ref.unhideGhostForTarget;
2765
- if (!originalEvent) return;
2766
- var toSortable = putSortable || activeSortable;
2767
- hideGhostForTarget();
2768
- var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
2769
- var target = document.elementFromPoint(touch.clientX, touch.clientY);
2770
- unhideGhostForTarget();
2771
- if (toSortable && !toSortable.el.contains(target)) {
2772
- dispatchSortableEvent('spill');
2773
- this.onSpill({
2774
- dragEl: dragEl,
2775
- putSortable: putSortable
2776
- });
2906
+ var RevertOnSpill = /*#__PURE__*/function () {
2907
+ function RevertOnSpill(sortable) {
2908
+ _classCallCheck(this, RevertOnSpill);
2909
+ _defineProperty(this, "startIndex", null);
2910
+ this.sortable = sortable;
2911
+ this.options = sortable.options;
2777
2912
  }
2778
- };
2779
- function Revert() {}
2780
- Revert.prototype = {
2781
- startIndex: null,
2782
- dragStart: function dragStart(_ref2) {
2783
- var oldDraggableIndex = _ref2.oldDraggableIndex;
2784
- this.startIndex = oldDraggableIndex;
2785
- },
2786
- getPlaceholder: function getPlaceholder(_ref3) {
2787
- var originalDrag = _ref3.originalDragEl;
2788
- originalDragEl$1 = originalDrag;
2789
- },
2790
- onSpill: function onSpill(_ref4) {
2791
- var dragEl = _ref4.dragEl,
2792
- putSortable = _ref4.putSortable;
2793
- this.sortable.captureAnimationState();
2794
- if (putSortable) {
2795
- putSortable.captureAnimationState();
2796
- }
2797
- var nextSibling = getChild(this.sortable.el, this.startIndex, this.options, originalDragEl$1);
2798
- if (nextSibling) {
2799
- this.sortable.el.insertBefore(dragEl, nextSibling);
2800
- } else {
2801
- this.sortable.el.appendChild(dragEl);
2913
+ return _createClass(RevertOnSpill, [{
2914
+ key: "dragStart",
2915
+ value: function dragStart(_ref) {
2916
+ var oldDraggableIndex = _ref.oldDraggableIndex;
2917
+ this.startIndex = oldDraggableIndex;
2802
2918
  }
2803
- this.sortable.animateAll();
2804
- if (putSortable) {
2805
- putSortable.animateAll();
2919
+ }, {
2920
+ key: "getPlaceholder",
2921
+ value: function getPlaceholder(_ref2) {
2922
+ var originalDrag = _ref2.originalDragEl;
2923
+ originalDragEl$1 = originalDrag;
2806
2924
  }
2807
- },
2808
- drop: drop
2809
- };
2810
- _extends(Revert, {
2811
- pluginName: 'revertOnSpill'
2812
- });
2813
- function Remove() {}
2814
- Remove.prototype = {
2815
- onSpill: function onSpill(_ref5) {
2816
- var dragEl = _ref5.dragEl,
2817
- putSortable = _ref5.putSortable;
2818
- var parentSortable = putSortable || this.sortable;
2819
- parentSortable.captureAnimationState();
2820
- dragEl.parentNode && dragEl.parentNode.removeChild(dragEl);
2821
- parentSortable.animateAll();
2822
- },
2823
- drop: drop
2824
- };
2825
- _extends(Remove, {
2826
- pluginName: 'removeOnSpill'
2827
- });
2925
+ }, {
2926
+ key: "onSpill",
2927
+ value: function onSpill(_ref3) {
2928
+ var dragEl = _ref3.dragEl,
2929
+ putSortable = _ref3.putSortable;
2930
+ this.sortable.captureAnimationState();
2931
+ if (putSortable) {
2932
+ putSortable.captureAnimationState();
2933
+ }
2934
+ var nextSibling = getChild(this.sortable.el, this.startIndex, this.options, [originalDragEl$1]);
2935
+ if (nextSibling) {
2936
+ this.sortable.el.insertBefore(dragEl, nextSibling);
2937
+ } else {
2938
+ this.sortable.el.appendChild(dragEl);
2939
+ }
2940
+ this.sortable.animateAll();
2941
+ if (putSortable) {
2942
+ putSortable.animateAll();
2943
+ }
2944
+ }
2945
+ }, {
2946
+ key: "drop",
2947
+ value: function drop(_ref4) {
2948
+ var originalEvent = _ref4.originalEvent,
2949
+ putSortable = _ref4.putSortable,
2950
+ dragEl = _ref4.dragEl,
2951
+ activeSortable = _ref4.activeSortable,
2952
+ dispatchSortableEvent = _ref4.dispatchSortableEvent,
2953
+ hideGhostForTarget = _ref4.hideGhostForTarget,
2954
+ unhideGhostForTarget = _ref4.unhideGhostForTarget;
2955
+ if (!originalEvent) return;
2956
+ var toSortable = putSortable || activeSortable;
2957
+ hideGhostForTarget();
2958
+ var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
2959
+ var target = document.elementFromPoint(touch.clientX, touch.clientY);
2960
+ unhideGhostForTarget();
2961
+ if (toSortable && !toSortable.el.contains(target)) {
2962
+ dispatchSortableEvent('spill');
2963
+ this.onSpill({
2964
+ dragEl: dragEl,
2965
+ putSortable: putSortable
2966
+ });
2967
+ }
2968
+ }
2969
+ }]);
2970
+ }();
2971
+ _defineProperty(RevertOnSpill, "pluginName", 'revertOnSpill');
2972
+ var RemoveOnSpill = /*#__PURE__*/function () {
2973
+ function RemoveOnSpill(sortable) {
2974
+ _classCallCheck(this, RemoveOnSpill);
2975
+ this.sortable = sortable;
2976
+ this.options = sortable.options;
2977
+ }
2978
+ return _createClass(RemoveOnSpill, [{
2979
+ key: "onSpill",
2980
+ value: function onSpill(_ref5) {
2981
+ var dragEl = _ref5.dragEl,
2982
+ putSortable = _ref5.putSortable;
2983
+ var parentSortable = putSortable || this.sortable;
2984
+ parentSortable.captureAnimationState();
2985
+ dragEl.parentNode && dragEl.parentNode.removeChild(dragEl);
2986
+ parentSortable.animateAll();
2987
+ }
2988
+ }, {
2989
+ key: "drop",
2990
+ value: function drop(_ref6) {
2991
+ var originalEvent = _ref6.originalEvent,
2992
+ putSortable = _ref6.putSortable,
2993
+ dragEl = _ref6.dragEl,
2994
+ activeSortable = _ref6.activeSortable,
2995
+ dispatchSortableEvent = _ref6.dispatchSortableEvent,
2996
+ hideGhostForTarget = _ref6.hideGhostForTarget,
2997
+ unhideGhostForTarget = _ref6.unhideGhostForTarget;
2998
+ if (!originalEvent) return;
2999
+ var toSortable = putSortable || activeSortable;
3000
+ hideGhostForTarget();
3001
+ var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
3002
+ var target = document.elementFromPoint(touch.clientX, touch.clientY);
3003
+ unhideGhostForTarget();
3004
+ if (toSortable && !toSortable.el.contains(target)) {
3005
+ dispatchSortableEvent('spill');
3006
+ this.onSpill({
3007
+ dragEl: dragEl,
3008
+ putSortable: putSortable
3009
+ });
3010
+ }
3011
+ }
3012
+ }]);
3013
+ }();
3014
+ _defineProperty(RemoveOnSpill, "pluginName", 'removeOnSpill');
2828
3015
 
2829
- var lastSwapEl;
2830
- function SwapPlugin() {
2831
- function Swap() {
3016
+ var _excluded$1 = ["activeSortable", "putSortable", "dragEl"];
3017
+ var lastSwapEl, originalDragEl$2, newIndex$1;
3018
+ var Swap = /*#__PURE__*/function () {
3019
+ function Swap(sortable) {
3020
+ _classCallCheck(this, Swap);
3021
+ this.sortable = sortable;
3022
+ this.options = sortable.options;
2832
3023
  this.defaults = {
2833
3024
  swapClass: 'sortable-swap-highlight'
2834
3025
  };
3026
+ // Bind all private methods
3027
+ var _iterator = _createForOfIteratorHelper(Object.getOwnPropertyNames(Object.getPrototypeOf(this))),
3028
+ _step;
3029
+ try {
3030
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
3031
+ var fn = _step.value;
3032
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
3033
+ this[fn] = this[fn].bind(this);
3034
+ }
3035
+ }
3036
+ } catch (err) {
3037
+ _iterator.e(err);
3038
+ } finally {
3039
+ _iterator.f();
3040
+ }
2835
3041
  }
2836
- Swap.prototype = {
2837
- dragStart: function dragStart(_ref) {
3042
+ return _createClass(Swap, [{
3043
+ key: "dragStart",
3044
+ value: function dragStart(_ref) {
2838
3045
  var dragEl = _ref.dragEl;
2839
- lastSwapEl = dragEl;
2840
- },
2841
- dragOverValid: function dragOverValid(_ref2) {
2842
- var completed = _ref2.completed,
2843
- target = _ref2.target,
2844
- onMove = _ref2.onMove,
2845
- activeSortable = _ref2.activeSortable,
2846
- changed = _ref2.changed,
2847
- cancel = _ref2.cancel;
3046
+ this.setLastSwapEl(dragEl);
3047
+ }
3048
+ }, {
3049
+ key: "getPlaceholder",
3050
+ value: function getPlaceholder(_ref2) {
3051
+ var originalDrag = _ref2.originalDragEl;
3052
+ originalDragEl$2 = originalDrag;
3053
+ }
3054
+ }, {
3055
+ key: "dragOverValid",
3056
+ value: function dragOverValid(_ref3) {
3057
+ var completed = _ref3.completed,
3058
+ target = _ref3.target,
3059
+ onMove = _ref3.onMove,
3060
+ activeSortable = _ref3.activeSortable,
3061
+ changed = _ref3.changed,
3062
+ cancel = _ref3.cancel;
2848
3063
  if (!activeSortable.options.swap) return;
2849
3064
  var el = this.sortable.el,
2850
3065
  options = this.options;
@@ -2852,9 +3067,9 @@ function SwapPlugin() {
2852
3067
  var prevSwapEl = lastSwapEl;
2853
3068
  if (onMove(target) !== false) {
2854
3069
  toggleClass(target, options.swapClass, true);
2855
- lastSwapEl = target;
3070
+ this.setLastSwapEl(target);
2856
3071
  } else {
2857
- lastSwapEl = null;
3072
+ this.setLastSwapEl(null);
2858
3073
  }
2859
3074
  if (prevSwapEl && prevSwapEl !== lastSwapEl) {
2860
3075
  toggleClass(prevSwapEl, options.swapClass, false);
@@ -2863,11 +3078,48 @@ function SwapPlugin() {
2863
3078
  changed();
2864
3079
  completed(true);
2865
3080
  cancel();
2866
- },
2867
- drop: function drop(_ref3) {
2868
- var activeSortable = _ref3.activeSortable,
2869
- putSortable = _ref3.putSortable,
2870
- dragEl = _ref3.dragEl;
3081
+ }
3082
+ }, {
3083
+ key: "setLastSwapEl",
3084
+ value: function setLastSwapEl(node) {
3085
+ lastSwapEl = node;
3086
+ var parent = node === null || node === void 0 ? void 0 : node.parentNode;
3087
+ var _index = -1;
3088
+ if (parent && node && typeof this.options.getPlaceholder === 'function') {
3089
+ _index = index(node, this.options.draggable, [originalDragEl$2]);
3090
+ }
3091
+ if (_index > -1) {
3092
+ newIndex$1 = _index;
3093
+ } else {
3094
+ newIndex$1 = undefined;
3095
+ }
3096
+ }
3097
+ }, {
3098
+ key: "swapNodes",
3099
+ value: function swapNodes(n1, n2, activeSortable, putSortable) {
3100
+ var _putSortable$options;
3101
+ if (typeof activeSortable.options.getPlaceholder !== 'function' && typeof (putSortable === null || putSortable === void 0 || (_putSortable$options = putSortable.options) === null || _putSortable$options === void 0 ? void 0 : _putSortable$options.getPlaceholder) !== 'function') {
3102
+ var p1 = n1.parentNode,
3103
+ p2 = n2.parentNode,
3104
+ i1,
3105
+ i2;
3106
+ if (!p1 || !p2 || p1.isEqualNode(n2) || p2.isEqualNode(n1)) return;
3107
+ i1 = index(n1, this.options.draggable, [originalDragEl$2]);
3108
+ i2 = index(n2, this.options.draggable, [originalDragEl$2]);
3109
+ if (p1.isEqualNode(p2) && i1 < i2) {
3110
+ i2++;
3111
+ }
3112
+ p1.insertBefore(n2, p1.children[i1]);
3113
+ p2.insertBefore(n1, p2.children[i2]);
3114
+ }
3115
+ }
3116
+ }, {
3117
+ key: "drop",
3118
+ value: function drop(_ref4) {
3119
+ var activeSortable = _ref4.activeSortable,
3120
+ putSortable = _ref4.putSortable,
3121
+ dragEl = _ref4.dragEl,
3122
+ data = _objectWithoutProperties(_ref4, _excluded$1);
2871
3123
  var toSortable = putSortable || this.sortable;
2872
3124
  var options = this.options;
2873
3125
  lastSwapEl && toggleClass(lastSwapEl, options.swapClass, false);
@@ -2875,633 +3127,35 @@ function SwapPlugin() {
2875
3127
  if (dragEl !== lastSwapEl) {
2876
3128
  toSortable.captureAnimationState();
2877
3129
  if (toSortable !== activeSortable) activeSortable.captureAnimationState();
2878
- swapNodes(dragEl, lastSwapEl);
3130
+ this.swapNodes(dragEl, lastSwapEl, activeSortable, putSortable);
2879
3131
  toSortable.animateAll();
2880
3132
  if (toSortable !== activeSortable) activeSortable.animateAll();
2881
3133
  }
2882
3134
  }
2883
- },
2884
- nulling: function nulling() {
2885
- lastSwapEl = null;
2886
- }
2887
- };
2888
- return _extends(Swap, {
2889
- pluginName: 'swap',
2890
- eventProperties: function eventProperties() {
2891
- return {
2892
- swapItem: lastSwapEl
2893
- };
2894
- }
2895
- });
2896
- }
2897
- function swapNodes(n1, n2) {
2898
- var p1 = n1.parentNode,
2899
- p2 = n2.parentNode,
2900
- i1,
2901
- i2;
2902
- if (!p1 || !p2 || p1.isEqualNode(n2) || p2.isEqualNode(n1)) return;
2903
- i1 = index(n1);
2904
- i2 = index(n2);
2905
- if (p1.isEqualNode(p2) && i1 < i2) {
2906
- i2++;
2907
- }
2908
- p1.insertBefore(n2, p1.children[i1]);
2909
- p2.insertBefore(n1, p2.children[i2]);
2910
- }
2911
-
2912
- var multiDragElements = [],
2913
- multiDragClones = [],
2914
- lastMultiDragSelect,
2915
- // for selection with modifier key down (SHIFT)
2916
- multiDragSortable,
2917
- initialFolding = false,
2918
- // Initial multi-drag fold when drag started
2919
- folding = false,
2920
- // Folding any other time
2921
- dragStarted = false,
2922
- dragEl$1,
2923
- originalDragEl$2,
2924
- clonesFromRect,
2925
- clonesHidden;
2926
- function MultiDragPlugin() {
2927
- function MultiDrag(sortable) {
2928
- // Bind all private methods
2929
- for (var fn in this) {
2930
- if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
2931
- this[fn] = this[fn].bind(this);
2932
- }
2933
- }
2934
- if (!sortable.options.avoidImplicitDeselect) {
2935
- if (sortable.options.supportPointer) {
2936
- on(document, 'pointerup', this._deselectMultiDrag);
2937
- } else {
2938
- on(document, 'mouseup', this._deselectMultiDrag);
2939
- on(document, 'touchend', this._deselectMultiDrag);
2940
- }
2941
3135
  }
2942
- on(document, 'keydown', this._checkKeyDown);
2943
- on(document, 'keyup', this._checkKeyUp);
2944
- this.defaults = {
2945
- selectedClass: 'sortable-selected',
2946
- multiDragKey: null,
2947
- avoidImplicitDeselect: false,
2948
- setData: function setData(dataTransfer, dragEl) {
2949
- var data = '';
2950
- if (multiDragElements.length && multiDragSortable === sortable) {
2951
- multiDragElements.forEach(function (multiDragElement, i) {
2952
- data += (!i ? '' : ', ') + multiDragElement.textContent;
2953
- });
2954
- } else {
2955
- data = dragEl.textContent;
2956
- }
2957
- dataTransfer.setData('Text', data);
2958
- }
2959
- };
2960
- }
2961
- MultiDrag.prototype = {
2962
- multiDragKeyDown: false,
2963
- isMultiDrag: false,
2964
- delayStartGlobal: function delayStartGlobal(_ref) {
2965
- var dragged = _ref.dragEl;
2966
- dragEl$1 = dragged;
2967
- },
2968
- delayEnded: function delayEnded() {
2969
- this.isMultiDrag = ~multiDragElements.indexOf(dragEl$1);
2970
- },
2971
- setupClone: function setupClone(_ref2) {
2972
- var sortable = _ref2.sortable,
2973
- cancel = _ref2.cancel;
2974
- if (!this.isMultiDrag) return;
2975
- for (var i = 0; i < multiDragElements.length; i++) {
2976
- multiDragClones.push(clone(multiDragElements[i]));
2977
- multiDragClones[i].sortableIndex = multiDragElements[i].sortableIndex;
2978
- multiDragClones[i].draggable = false;
2979
- multiDragClones[i].style['will-change'] = '';
2980
- toggleClass(multiDragClones[i], this.options.selectedClass, false);
2981
- multiDragElements[i] === dragEl$1 && toggleClass(multiDragClones[i], this.options.chosenClass, false);
2982
- }
2983
- sortable._hideClone();
2984
- cancel();
2985
- },
2986
- clone: function clone(_ref3) {
2987
- var sortable = _ref3.sortable,
2988
- rootEl = _ref3.rootEl,
2989
- dispatchSortableEvent = _ref3.dispatchSortableEvent,
2990
- cancel = _ref3.cancel;
2991
- if (!this.isMultiDrag) return;
2992
- if (!this.options.removeCloneOnHide) {
2993
- if (multiDragElements.length && multiDragSortable === sortable) {
2994
- insertMultiDragClones(true, rootEl);
2995
- dispatchSortableEvent('clone');
2996
- cancel();
2997
- }
2998
- }
2999
- },
3000
- showClone: function showClone(_ref4) {
3001
- var cloneNowShown = _ref4.cloneNowShown,
3002
- rootEl = _ref4.rootEl,
3003
- cancel = _ref4.cancel;
3004
- if (!this.isMultiDrag) return;
3005
- insertMultiDragClones(false, rootEl);
3006
- multiDragClones.forEach(function (clone) {
3007
- css(clone, 'display', '');
3008
- });
3009
- cloneNowShown();
3010
- clonesHidden = false;
3011
- cancel();
3012
- },
3013
- hideClone: function hideClone(_ref5) {
3014
- var _this = this;
3015
- var sortable = _ref5.sortable,
3016
- cloneNowHidden = _ref5.cloneNowHidden,
3017
- cancel = _ref5.cancel;
3018
- if (!this.isMultiDrag) return;
3019
- multiDragClones.forEach(function (clone) {
3020
- css(clone, 'display', 'none');
3021
- if (_this.options.removeCloneOnHide && clone.parentNode) {
3022
- clone.parentNode.removeChild(clone);
3023
- }
3024
- });
3025
- cloneNowHidden();
3026
- clonesHidden = true;
3027
- cancel();
3028
- },
3029
- dragStartGlobal: function dragStartGlobal(_ref6) {
3030
- var sortable = _ref6.sortable;
3031
- if (!this.isMultiDrag && multiDragSortable) {
3032
- multiDragSortable.multiDrag._deselectMultiDrag();
3033
- }
3034
- multiDragElements.forEach(function (multiDragElement) {
3035
- multiDragElement.sortableIndex = index(multiDragElement);
3036
- });
3037
-
3038
- // Sort multi-drag elements
3039
- multiDragElements = multiDragElements.sort(function (a, b) {
3040
- return a.sortableIndex - b.sortableIndex;
3041
- });
3042
- dragStarted = true;
3043
- },
3044
- getPlaceholder: function getPlaceholder(_ref7) {
3045
- var originalDrag = _ref7.originalDragEl;
3046
- originalDragEl$2 = originalDrag;
3047
- },
3048
- dragStarted: function dragStarted(_ref8) {
3049
- var _this2 = this;
3050
- var sortable = _ref8.sortable;
3051
- if (!this.isMultiDrag) return;
3052
- if (this.options.sort) {
3053
- // Capture rects,
3054
- // hide multi drag elements (by positioning them absolute),
3055
- // set multi drag elements rects to dragRect,
3056
- // show multi drag elements,
3057
- // animate to rects,
3058
- // unset rects & remove from DOM
3059
-
3060
- sortable.captureAnimationState();
3061
- if (this.options.animation) {
3062
- multiDragElements.forEach(function (multiDragElement) {
3063
- if (multiDragElement === dragEl$1) return;
3064
- css(multiDragElement, 'position', 'absolute');
3065
- });
3066
- var dragRect = getRect(dragEl$1, false, true, true);
3067
- multiDragElements.forEach(function (multiDragElement) {
3068
- if (multiDragElement === dragEl$1) return;
3069
- setRect(multiDragElement, dragRect);
3070
- });
3071
- folding = true;
3072
- initialFolding = true;
3073
- }
3074
- }
3075
- sortable.animateAll(function () {
3076
- folding = false;
3077
- initialFolding = false;
3078
- if (_this2.options.animation) {
3079
- multiDragElements.forEach(function (multiDragElement) {
3080
- unsetRect(multiDragElement);
3081
- });
3082
- }
3083
-
3084
- // Remove all auxiliary multidrag items from el, if sorting enabled
3085
- if (_this2.options.sort) {
3086
- removeMultiDragElements();
3087
- }
3088
- });
3089
- },
3090
- dragOver: function dragOver(_ref9) {
3091
- var target = _ref9.target,
3092
- completed = _ref9.completed,
3093
- cancel = _ref9.cancel;
3094
- if (folding && ~multiDragElements.indexOf(target)) {
3095
- completed(false);
3096
- cancel();
3097
- }
3098
- },
3099
- revert: function revert(_ref0) {
3100
- var fromSortable = _ref0.fromSortable,
3101
- rootEl = _ref0.rootEl,
3102
- sortable = _ref0.sortable,
3103
- dragRect = _ref0.dragRect;
3104
- if (multiDragElements.length > 1) {
3105
- // Setup unfold animation
3106
- multiDragElements.forEach(function (multiDragElement) {
3107
- sortable.addAnimationState({
3108
- target: multiDragElement,
3109
- rect: folding ? getRect(multiDragElement) : dragRect
3110
- });
3111
- unsetRect(multiDragElement);
3112
- multiDragElement.fromRect = dragRect;
3113
- fromSortable.removeAnimationState(multiDragElement);
3114
- });
3115
- folding = false;
3116
- insertMultiDragElements(!this.options.removeCloneOnHide, rootEl);
3117
- }
3118
- },
3119
- dragOverCompleted: function dragOverCompleted(_ref1) {
3120
- var sortable = _ref1.sortable,
3121
- isOwner = _ref1.isOwner,
3122
- insertion = _ref1.insertion,
3123
- activeSortable = _ref1.activeSortable,
3124
- parentEl = _ref1.parentEl,
3125
- putSortable = _ref1.putSortable;
3126
- var options = this.options;
3127
- if (insertion) {
3128
- // Clones must be hidden before folding animation to capture dragRectAbsolute properly
3129
- if (isOwner) {
3130
- activeSortable._hideClone();
3131
- }
3132
- initialFolding = false;
3133
- // If leaving sort:false root, or already folding - Fold to new location
3134
- if (options.animation && multiDragElements.length > 1 && (folding || !isOwner && !activeSortable.options.sort && !putSortable)) {
3135
- // Fold: Set all multi drag elements's rects to dragEl's rect when multi-drag elements are invisible
3136
- var dragRectAbsolute = getRect(dragEl$1, false, true, true);
3137
- multiDragElements.forEach(function (multiDragElement) {
3138
- if (multiDragElement === dragEl$1) return;
3139
- setRect(multiDragElement, dragRectAbsolute);
3140
-
3141
- // Move element(s) to end of parentEl so that it does not interfere with multi-drag clones insertion if they are inserted
3142
- // while folding, and so that we can capture them again because old sortable will no longer be fromSortable
3143
- parentEl.appendChild(multiDragElement);
3144
- });
3145
- folding = true;
3146
- }
3147
-
3148
- // Clones must be shown (and check to remove multi drags) after folding when interfering multiDragElements are moved out
3149
- if (!isOwner) {
3150
- // Only remove if not folding (folding will remove them anyways)
3151
- if (!folding) {
3152
- removeMultiDragElements();
3153
- }
3154
- if (multiDragElements.length > 1) {
3155
- var clonesHiddenBefore = clonesHidden;
3156
- activeSortable._showClone(sortable);
3157
-
3158
- // Unfold animation for clones if showing from hidden
3159
- if (activeSortable.options.animation && !clonesHidden && clonesHiddenBefore) {
3160
- multiDragClones.forEach(function (clone) {
3161
- activeSortable.addAnimationState({
3162
- target: clone,
3163
- rect: clonesFromRect
3164
- });
3165
- clone.fromRect = clonesFromRect;
3166
- clone.thisAnimationDuration = null;
3167
- });
3168
- }
3169
- } else {
3170
- activeSortable._showClone(sortable);
3171
- }
3172
- }
3173
- }
3174
- },
3175
- dragOverAnimationCapture: function dragOverAnimationCapture(_ref10) {
3176
- var dragRect = _ref10.dragRect,
3177
- isOwner = _ref10.isOwner,
3178
- activeSortable = _ref10.activeSortable;
3179
- multiDragElements.forEach(function (multiDragElement) {
3180
- multiDragElement.thisAnimationDuration = null;
3181
- });
3182
- if (activeSortable.options.animation && !isOwner && activeSortable.multiDrag.isMultiDrag) {
3183
- clonesFromRect = _extends({}, dragRect);
3184
- var dragMatrix = matrix(dragEl$1, true);
3185
- clonesFromRect.top -= dragMatrix.f;
3186
- clonesFromRect.left -= dragMatrix.e;
3187
- }
3188
- },
3189
- dragOverAnimationComplete: function dragOverAnimationComplete() {
3190
- if (folding) {
3191
- folding = false;
3192
- removeMultiDragElements();
3193
- }
3194
- },
3195
- drop: function drop(_ref11) {
3196
- var evt = _ref11.originalEvent,
3197
- rootEl = _ref11.rootEl,
3198
- parentEl = _ref11.parentEl,
3199
- sortable = _ref11.sortable,
3200
- dispatchSortableEvent = _ref11.dispatchSortableEvent,
3201
- oldIndex = _ref11.oldIndex,
3202
- putSortable = _ref11.putSortable;
3203
- var toSortable = putSortable || this.sortable;
3204
- if (!evt) return;
3205
- var options = this.options,
3206
- children = parentEl.children;
3207
-
3208
- // Multi-drag selection
3209
- if (!dragStarted) {
3210
- if (options.multiDragKey && !this.multiDragKeyDown) {
3211
- this._deselectMultiDrag();
3212
- }
3213
- toggleClass(dragEl$1, options.selectedClass, !~multiDragElements.indexOf(dragEl$1));
3214
- if (!~multiDragElements.indexOf(dragEl$1)) {
3215
- multiDragElements.push(dragEl$1);
3216
- dispatchEvent({
3217
- sortable: sortable,
3218
- rootEl: rootEl,
3219
- name: 'select',
3220
- targetEl: dragEl$1,
3221
- originalEvent: evt
3222
- });
3223
-
3224
- // Modifier activated, select from last to dragEl
3225
- if (evt.shiftKey && lastMultiDragSelect && sortable.el.contains(lastMultiDragSelect)) {
3226
- var lastIndex = index(lastMultiDragSelect),
3227
- currentIndex = index(dragEl$1);
3228
- if (~lastIndex && ~currentIndex && lastIndex !== currentIndex) {
3229
- // Must include lastMultiDragSelect (select it), in case modified selection from no selection
3230
- // (but previous selection existed)
3231
- var n, i;
3232
- if (currentIndex > lastIndex) {
3233
- i = lastIndex;
3234
- n = currentIndex;
3235
- } else {
3236
- i = currentIndex;
3237
- n = lastIndex + 1;
3238
- }
3239
- var filter = options.filter;
3240
- for (; i < n; i++) {
3241
- if (~multiDragElements.indexOf(children[i])) continue;
3242
- // Check if element is draggable
3243
- if (!closest(children[i], options.draggable, parentEl, false, originalDragEl$2)) continue;
3244
- // Check if element is filtered
3245
- var filtered = filter && (typeof filter === 'function' ? filter.call(sortable, evt, children[i], sortable) : filter.split(',').some(function (criteria) {
3246
- return closest(children[i], criteria.trim(), parentEl, false, originalDragEl$2);
3247
- }));
3248
- if (filtered) continue;
3249
- toggleClass(children[i], options.selectedClass, true);
3250
- multiDragElements.push(children[i]);
3251
- dispatchEvent({
3252
- sortable: sortable,
3253
- rootEl: rootEl,
3254
- name: 'select',
3255
- targetEl: children[i],
3256
- originalEvent: evt
3257
- });
3258
- }
3259
- }
3260
- } else {
3261
- lastMultiDragSelect = dragEl$1;
3262
- }
3263
- multiDragSortable = toSortable;
3264
- } else {
3265
- multiDragElements.splice(multiDragElements.indexOf(dragEl$1), 1);
3266
- lastMultiDragSelect = null;
3267
- dispatchEvent({
3268
- sortable: sortable,
3269
- rootEl: rootEl,
3270
- name: 'deselect',
3271
- targetEl: dragEl$1,
3272
- originalEvent: evt
3273
- });
3274
- }
3275
- }
3276
-
3277
- // Multi-drag drop
3278
- if (dragStarted && this.isMultiDrag) {
3279
- folding = false;
3280
- // Do not "unfold" after around dragEl if reverted
3281
- if ((parentEl[expando].options.sort || parentEl !== rootEl) && multiDragElements.length > 1) {
3282
- var dragRect = getRect(dragEl$1),
3283
- multiDragIndex = index(dragEl$1, ':not(.' + this.options.selectedClass + ')');
3284
- if (!initialFolding && options.animation) dragEl$1.thisAnimationDuration = null;
3285
- toSortable.captureAnimationState();
3286
- if (!initialFolding) {
3287
- if (options.animation) {
3288
- dragEl$1.fromRect = dragRect;
3289
- multiDragElements.forEach(function (multiDragElement) {
3290
- multiDragElement.thisAnimationDuration = null;
3291
- if (multiDragElement !== dragEl$1) {
3292
- var rect = folding ? getRect(multiDragElement) : dragRect;
3293
- multiDragElement.fromRect = rect;
3294
-
3295
- // Prepare unfold animation
3296
- toSortable.addAnimationState({
3297
- target: multiDragElement,
3298
- rect: rect
3299
- });
3300
- }
3301
- });
3302
- }
3303
-
3304
- // Multi drag elements are not necessarily removed from the DOM on drop, so to reinsert
3305
- // properly they must all be removed
3306
- removeMultiDragElements();
3307
- multiDragElements.forEach(function (multiDragElement) {
3308
- if (children[multiDragIndex]) {
3309
- parentEl.insertBefore(multiDragElement, children[multiDragIndex]);
3310
- } else {
3311
- parentEl.appendChild(multiDragElement);
3312
- }
3313
- multiDragIndex++;
3314
- });
3315
-
3316
- // If initial folding is done, the elements may have changed position because they are now
3317
- // unfolding around dragEl, even though dragEl may not have his index changed, so update event
3318
- // must be fired here as Sortable will not.
3319
- if (oldIndex === index(dragEl$1)) {
3320
- var update = false;
3321
- multiDragElements.forEach(function (multiDragElement) {
3322
- if (multiDragElement.sortableIndex !== index(multiDragElement)) {
3323
- update = true;
3324
- return;
3325
- }
3326
- });
3327
- if (update) {
3328
- dispatchSortableEvent('update');
3329
- dispatchSortableEvent('sort');
3330
- }
3331
- }
3332
- }
3333
-
3334
- // Must be done after capturing individual rects (scroll bar)
3335
- multiDragElements.forEach(function (multiDragElement) {
3336
- unsetRect(multiDragElement);
3337
- });
3338
- toSortable.animateAll();
3339
- }
3340
- multiDragSortable = toSortable;
3341
- }
3342
-
3343
- // Remove clones if necessary
3344
- if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
3345
- multiDragClones.forEach(function (clone) {
3346
- clone.parentNode && clone.parentNode.removeChild(clone);
3347
- });
3348
- }
3349
- },
3350
- nullingGlobal: function nullingGlobal() {
3351
- this.isMultiDrag = dragStarted = false;
3352
- multiDragClones.length = 0;
3353
- },
3354
- destroyGlobal: function destroyGlobal() {
3355
- this._deselectMultiDrag();
3356
- off(document, 'pointerup', this._deselectMultiDrag);
3357
- off(document, 'mouseup', this._deselectMultiDrag);
3358
- off(document, 'touchend', this._deselectMultiDrag);
3359
- off(document, 'keydown', this._checkKeyDown);
3360
- off(document, 'keyup', this._checkKeyUp);
3361
- },
3362
- _deselectMultiDrag: function _deselectMultiDrag(evt) {
3363
- if (typeof dragStarted !== "undefined" && dragStarted) return;
3364
-
3365
- // Only deselect if selection is in this sortable
3366
- if (multiDragSortable !== this.sortable) return;
3367
-
3368
- // Only deselect if target is not item in this sortable
3369
- if (evt && closest(evt.target, this.options.draggable, this.sortable.el, false, originalDragEl$2)) return;
3370
-
3371
- // Only deselect if left click
3372
- if (evt && evt.button !== 0) return;
3373
- while (multiDragElements.length) {
3374
- var el = multiDragElements[0];
3375
- toggleClass(el, this.options.selectedClass, false);
3376
- multiDragElements.shift();
3377
- dispatchEvent({
3378
- sortable: this.sortable,
3379
- rootEl: this.sortable.el,
3380
- name: 'deselect',
3381
- targetEl: el,
3382
- originalEvent: evt
3383
- });
3384
- }
3385
- },
3386
- _checkKeyDown: function _checkKeyDown(evt) {
3387
- if (evt.key === this.options.multiDragKey) {
3388
- this.multiDragKeyDown = true;
3389
- }
3390
- },
3391
- _checkKeyUp: function _checkKeyUp(evt) {
3392
- if (evt.key === this.options.multiDragKey) {
3393
- this.multiDragKeyDown = false;
3394
- }
3136
+ }, {
3137
+ key: "nulling",
3138
+ value: function nulling() {
3139
+ this.setLastSwapEl(null);
3140
+ originalDragEl$2 = null;
3395
3141
  }
3396
- };
3397
- return _extends(MultiDrag, {
3398
- // Static methods & properties
3399
- pluginName: 'multiDrag',
3400
- utils: {
3401
- /**
3402
- * Selects the provided multi-drag item
3403
- * @param {HTMLElement} el The element to be selected
3404
- */
3405
- select: function select(el) {
3406
- var sortable = el.parentNode[expando];
3407
- if (!sortable || !sortable.options.multiDrag || ~multiDragElements.indexOf(el)) return;
3408
- if (multiDragSortable && multiDragSortable !== sortable) {
3409
- multiDragSortable.multiDrag._deselectMultiDrag();
3410
- multiDragSortable = sortable;
3411
- }
3412
- toggleClass(el, sortable.options.selectedClass, true);
3413
- multiDragElements.push(el);
3414
- },
3415
- /**
3416
- * Deselects the provided multi-drag item
3417
- * @param {HTMLElement} el The element to be deselected
3418
- */
3419
- deselect: function deselect(el) {
3420
- var sortable = el.parentNode[expando],
3421
- index = multiDragElements.indexOf(el);
3422
- if (!sortable || !sortable.options.multiDrag || !~index) return;
3423
- toggleClass(el, sortable.options.selectedClass, false);
3424
- multiDragElements.splice(index, 1);
3425
- }
3426
- },
3427
- eventProperties: function eventProperties() {
3428
- var _this3 = this;
3429
- var oldIndicies = [],
3430
- newIndicies = [];
3431
- multiDragElements.forEach(function (multiDragElement) {
3432
- oldIndicies.push({
3433
- multiDragElement: multiDragElement,
3434
- index: multiDragElement.sortableIndex
3435
- });
3436
-
3437
- // multiDragElements will already be sorted if folding
3438
- var newIndex;
3439
- if (folding && multiDragElement !== dragEl$1) {
3440
- newIndex = -1;
3441
- } else if (folding) {
3442
- newIndex = index(multiDragElement, ':not(.' + _this3.options.selectedClass + ')');
3443
- } else {
3444
- newIndex = index(multiDragElement);
3445
- }
3446
- newIndicies.push({
3447
- multiDragElement: multiDragElement,
3448
- index: newIndex
3449
- });
3450
- });
3451
- return {
3452
- items: _toConsumableArray(multiDragElements),
3453
- clones: [].concat(multiDragClones),
3454
- oldIndicies: oldIndicies,
3455
- newIndicies: newIndicies
3142
+ }], [{
3143
+ key: "eventProperties",
3144
+ value: function eventProperties() {
3145
+ var obj = {
3146
+ swapItem: lastSwapEl
3456
3147
  };
3457
- },
3458
- optionListeners: {
3459
- multiDragKey: function multiDragKey(key) {
3460
- key = key.toLowerCase();
3461
- if (key === 'ctrl') {
3462
- key = 'Control';
3463
- } else if (key.length > 1) {
3464
- key = key.charAt(0).toUpperCase() + key.substr(1);
3465
- }
3466
- return key;
3148
+ if (newIndex$1 !== undefined) {
3149
+ obj.newIndex = newIndex$1;
3467
3150
  }
3151
+ return obj;
3468
3152
  }
3469
- });
3470
- }
3471
- function insertMultiDragElements(clonesInserted, rootEl) {
3472
- multiDragElements.forEach(function (multiDragElement, i) {
3473
- var target = rootEl.children[multiDragElement.sortableIndex + (clonesInserted ? Number(i) : 0)];
3474
- if (target) {
3475
- rootEl.insertBefore(multiDragElement, target);
3476
- } else {
3477
- rootEl.appendChild(multiDragElement);
3478
- }
3479
- });
3480
- }
3481
-
3482
- /**
3483
- * Insert multi-drag clones
3484
- * @param {[Boolean]} elementsInserted Whether the multi-drag elements are inserted
3485
- * @param {HTMLElement} rootEl
3486
- */
3487
- function insertMultiDragClones(elementsInserted, rootEl) {
3488
- multiDragClones.forEach(function (clone, i) {
3489
- var target = rootEl.children[clone.sortableIndex + (elementsInserted ? Number(i) : 0)];
3490
- if (target) {
3491
- rootEl.insertBefore(clone, target);
3492
- } else {
3493
- rootEl.appendChild(clone);
3494
- }
3495
- });
3496
- }
3497
- function removeMultiDragElements() {
3498
- multiDragElements.forEach(function (multiDragElement) {
3499
- if (multiDragElement === dragEl$1) return;
3500
- multiDragElement.parentNode && multiDragElement.parentNode.removeChild(multiDragElement);
3501
- });
3502
- }
3153
+ }]);
3154
+ }();
3155
+ _defineProperty(Swap, "pluginName", 'swap');
3503
3156
 
3504
- var dragParent;
3157
+ var _excluded$2 = ["axis", "originalEvent", "dragEl", "originalDragEl", "sortable", "fromSortable", "onMove", "ghostEl", "changed"];
3158
+ var draggedTreeItemParent, draggedTreeItemLevel, draggedTreeItemBefore, draggedTreeItemAfter;
3505
3159
  var TreePlugin = /*#__PURE__*/function () {
3506
3160
  function TreePlugin(sortable) {
3507
3161
  _classCallCheck(this, TreePlugin);
@@ -3509,7 +3163,6 @@ var TreePlugin = /*#__PURE__*/function () {
3509
3163
  this.options = sortable.options;
3510
3164
  this.startX = 0;
3511
3165
  this.startLevel = 1;
3512
- this.currentLevel = 1;
3513
3166
  this.beforeElement = null;
3514
3167
  }
3515
3168
  return _createClass(TreePlugin, [{
@@ -3519,12 +3172,42 @@ var TreePlugin = /*#__PURE__*/function () {
3519
3172
  }
3520
3173
  }, {
3521
3174
  key: "dragStarted",
3522
- value: function dragStarted(evt) {
3175
+ value: function dragStarted(_ref) {
3176
+ var originalEvent = _ref.originalEvent,
3177
+ dragEl = _ref.dragEl,
3178
+ originalDragEl = _ref.originalDragEl,
3179
+ sortable = _ref.sortable;
3523
3180
  if (!this.options.tree) return;
3524
- this.startX = evt.originalEvent.clientX;
3525
- this.startLevel = getLevel(evt.originalDragEl || evt.dragEl, this.options);
3526
- this.currentLevel = this.startLevel;
3527
- }
3181
+ this.startX = originalEvent.clientX;
3182
+ this.startLevel = getLevel(originalDragEl || dragEl, this.options);
3183
+ draggedTreeItemLevel = this.startLevel;
3184
+ this._getDraggedTreeItemParent(dragEl, originalDragEl, sortable);
3185
+ }
3186
+
3187
+ // dragOverValid({ completed, target, onMove, activeSortable, changed, cancel }) {
3188
+ // if (!this.options.tree) return;
3189
+ //
3190
+ // // Check if onMove function exists and call it
3191
+ // if (onMove && typeof onMove === 'function') {
3192
+ // const moveResult = onMove(target);
3193
+ //
3194
+ // // If onMove returns false, cancel the move
3195
+ // if (moveResult === false) {
3196
+ // cancel();
3197
+ // return;
3198
+ // }
3199
+ //
3200
+ // // If onMove returns a number (1 or -1), it indicates direction
3201
+ // if (moveResult === 1 || moveResult === -1) {
3202
+ // // Handle direction-based movement if needed
3203
+ // // For tree structure, we might want to adjust level based on direction
3204
+ // }
3205
+ // }
3206
+ //
3207
+ // // Continue with normal tree logic
3208
+ // changed();
3209
+ // completed(true);
3210
+ // }
3528
3211
  }, {
3529
3212
  key: "_findPrevSibling",
3530
3213
  value: function _findPrevSibling(el, originalDragEl) {
@@ -3532,7 +3215,7 @@ var TreePlugin = /*#__PURE__*/function () {
3532
3215
  var prev = el.previousElementSibling;
3533
3216
  var levelAttr = this.options.treeItemLevelAttr || 'data-level';
3534
3217
  while (prev) {
3535
- var match = closest(prev, this.options.draggable, this.sortable.el, false, originalDragEl);
3218
+ var match = closest(prev, this.options.draggable, this.sortable.el, false, [originalDragEl]);
3536
3219
  if (match) {
3537
3220
  if (typeof level === 'number' && match.getAttribute(levelAttr) === level.toString() || level === undefined) return match;
3538
3221
  }
@@ -3545,29 +3228,50 @@ var TreePlugin = /*#__PURE__*/function () {
3545
3228
  value: function _findNextSibling(el, originalDragEl) {
3546
3229
  var next = el.nextElementSibling;
3547
3230
  while (next) {
3548
- var match = closest(next, this.options.draggable, this.sortable.el, false, originalDragEl);
3231
+ var match = closest(next, this.options.draggable, this.sortable.el, false, [originalDragEl]);
3549
3232
  if (match) return match;
3550
3233
  next = next.nextElementSibling;
3551
3234
  }
3552
3235
  return null;
3553
3236
  }
3237
+ }, {
3238
+ key: "_getDraggedTreeItemParent",
3239
+ value: function _getDraggedTreeItemParent(dragEl, originalDragEl, sortable) {
3240
+ var _this$_findPrevSiblin;
3241
+ draggedTreeItemParent = (_this$_findPrevSiblin = this._findPrevSibling(dragEl, originalDragEl, draggedTreeItemLevel - 1)) !== null && _this$_findPrevSiblin !== void 0 ? _this$_findPrevSiblin : sortable.el;
3242
+ }
3554
3243
  }, {
3555
3244
  key: "dragOver",
3556
- value: function dragOver(evt) {
3557
- if (!this.options.tree || evt.axis === 'vertical') return;
3558
- var deltaX = evt.originalEvent.clientX - this.startX;
3245
+ value: function dragOver(_ref2) {
3246
+ var axis = _ref2.axis,
3247
+ originalEvent = _ref2.originalEvent,
3248
+ dragEl = _ref2.dragEl,
3249
+ originalDragEl = _ref2.originalDragEl,
3250
+ sortable = _ref2.sortable,
3251
+ fromSortable = _ref2.fromSortable,
3252
+ onMove = _ref2.onMove,
3253
+ ghostEl = _ref2.ghostEl,
3254
+ changed = _ref2.changed,
3255
+ other = _objectWithoutProperties(_ref2, _excluded$2);
3256
+ if (!this.options.tree || axis === 'vertical') return;
3257
+ var deltaX = originalEvent.clientX - this.startX;
3559
3258
  var indent = this.options.treeIndentThreshold || 10;
3560
3259
  var levelAttr = this.options.treeItemLevelAttr || 'data-level';
3561
- var before = this._findPrevSibling(evt.dragEl, evt.originalDragEl);
3562
- var after = this._findNextSibling(evt.dragEl, evt.originalDragEl);
3563
- var beforeLevel = before ? getLevel(before, this.options) : 1;
3564
- var afterLevel = after ? getLevel(after, this.options) : 1;
3260
+ draggedTreeItemBefore = this._findPrevSibling(dragEl, originalDragEl);
3261
+ draggedTreeItemAfter = this._findNextSibling(dragEl, originalDragEl);
3262
+ var beforeLevel = draggedTreeItemBefore ? getLevel(draggedTreeItemBefore, this.options) : 1;
3263
+ var afterLevel = draggedTreeItemAfter ? getLevel(draggedTreeItemAfter, this.options) : 1;
3264
+ if (draggedTreeItemBefore) draggedTreeItemBefore.level = beforeLevel;
3265
+ if (draggedTreeItemAfter) draggedTreeItemAfter.level = afterLevel;
3565
3266
  var minLevel = 1;
3566
3267
  var maxLevel = 1;
3567
- if (before && after) {
3568
- minLevel = Math.min(beforeLevel + 1, afterLevel, beforeLevel);
3268
+ if (draggedTreeItemBefore && draggedTreeItemAfter) {
3269
+ minLevel = Math.min(beforeLevel + 1, afterLevel);
3270
+ if (beforeLevel >= afterLevel) {
3271
+ minLevel = Math.min(minLevel, beforeLevel);
3272
+ }
3569
3273
  maxLevel = Math.max(beforeLevel + 1, afterLevel);
3570
- } else if (!after) {
3274
+ } else if (!draggedTreeItemAfter) {
3571
3275
  minLevel = 1;
3572
3276
  maxLevel = beforeLevel + 1;
3573
3277
  } else {
@@ -3575,51 +3279,65 @@ var TreePlugin = /*#__PURE__*/function () {
3575
3279
  }
3576
3280
  var levelChange = Math.floor(deltaX / indent);
3577
3281
  var newLevel = Math.max(minLevel, Math.min(maxLevel, this.startLevel + levelChange));
3578
- if (newLevel !== this.currentLevel || this.beforeElement !== before) {
3579
- var _evt$dragEl, _evt$dragEl$setAttrib, _evt$ghostEl, _evt$ghostEl$setAttri;
3580
- this.beforeElement = before;
3581
- this.currentLevel = newLevel;
3582
- if (evt.originalDragEl) {
3583
- evt.originalDragEl.setAttribute("sortable-".concat(levelAttr), this.currentLevel);
3584
- }
3585
- (_evt$dragEl = evt.dragEl) === null || _evt$dragEl === void 0 || (_evt$dragEl$setAttrib = _evt$dragEl.setAttribute) === null || _evt$dragEl$setAttrib === void 0 || _evt$dragEl$setAttrib.call(_evt$dragEl, "sortable-".concat(levelAttr), this.currentLevel);
3586
- (_evt$ghostEl = evt.ghostEl) === null || _evt$ghostEl === void 0 || (_evt$ghostEl$setAttri = _evt$ghostEl.setAttribute) === null || _evt$ghostEl$setAttri === void 0 || _evt$ghostEl$setAttri.call(_evt$ghostEl, "sortable-".concat(levelAttr), this.currentLevel);
3282
+ if (newLevel !== draggedTreeItemLevel || this.beforeElement !== draggedTreeItemBefore || sortable !== fromSortable) {
3587
3283
  this.removeDragPrent();
3588
- if (newLevel > 1) {
3589
- dragParent = this._findPrevSibling(evt.dragEl, evt.originalDragEl, newLevel - 1);
3590
- if (dragParent) dragParent.setAttribute('sortable-data-parent', 'true');
3591
- }
3592
- var target = before || after || this.sortable.el;
3284
+ this.beforeElement = draggedTreeItemBefore;
3285
+ draggedTreeItemLevel = newLevel;
3286
+ this._getDraggedTreeItemParent(dragEl, originalDragEl, sortable);
3287
+ var target = draggedTreeItemBefore || draggedTreeItemAfter || this.sortable.el;
3593
3288
  var targetRect = getRect(target);
3594
- this.sortable._getPlaceholderOnMove(this.sortable.el, getRect(evt.dragEl), target, targetRect, evt, Boolean(before));
3289
+ var moveResult = onMove(target, Boolean(draggedTreeItemBefore));
3290
+ if (moveResult !== false) {
3291
+ var _dragEl$setAttribute, _ghostEl$setAttribute;
3292
+ if (originalDragEl && !(typeof this.options.getPlaceholder === 'function' || typeof this.options.getPlaceholderOnMove === 'function')) {
3293
+ originalDragEl.setAttribute(levelAttr, draggedTreeItemLevel);
3294
+ }
3295
+ dragEl === null || dragEl === void 0 || (_dragEl$setAttribute = dragEl.setAttribute) === null || _dragEl$setAttribute === void 0 || _dragEl$setAttribute.call(dragEl, levelAttr, draggedTreeItemLevel);
3296
+ ghostEl === null || ghostEl === void 0 || (_ghostEl$setAttribute = ghostEl.setAttribute) === null || _ghostEl$setAttribute === void 0 || _ghostEl$setAttribute.call(ghostEl, levelAttr, draggedTreeItemLevel);
3297
+ if (newLevel > 1 && draggedTreeItemParent) draggedTreeItemParent.setAttribute('data-drag-parent', 'true');
3298
+ this.sortable._getPlaceholderOnMove(this.sortable.el, getRect(dragEl), target, targetRect, originalEvent, Boolean(draggedTreeItemBefore));
3299
+ changed();
3300
+ }
3595
3301
  }
3596
3302
  }
3597
3303
  }, {
3598
3304
  key: "drop",
3599
3305
  value: function drop(evt) {
3600
- var _evt$dragEl2, _evt$dragEl2$setAttri, _evt$ghostEl2, _evt$ghostEl2$setAttr;
3601
3306
  if (!this.options.tree) return;
3602
- var levelAttr = this.options.treeItemLevelAttr || 'data-level';
3603
- if (evt.originalDragEl) {
3604
- evt.originalDragEl.setAttribute("sortable-".concat(levelAttr), this.currentLevel);
3605
- }
3606
- (_evt$dragEl2 = evt.dragEl) === null || _evt$dragEl2 === void 0 || (_evt$dragEl2$setAttri = _evt$dragEl2.setAttribute) === null || _evt$dragEl2$setAttri === void 0 || _evt$dragEl2$setAttri.call(_evt$dragEl2, "sortable-".concat(levelAttr), this.currentLevel);
3607
- (_evt$ghostEl2 = evt.ghostEl) === null || _evt$ghostEl2 === void 0 || (_evt$ghostEl2$setAttr = _evt$ghostEl2.setAttribute) === null || _evt$ghostEl2$setAttr === void 0 || _evt$ghostEl2$setAttr.call(_evt$ghostEl2, "sortable-".concat(levelAttr), this.currentLevel);
3608
3307
  }
3609
3308
  }, {
3610
3309
  key: "removeDragPrent",
3611
3310
  value: function removeDragPrent() {
3612
- if (dragParent) {
3613
- dragParent.removeAttribute('sortable-data-parent');
3311
+ if (draggedTreeItemParent) {
3312
+ draggedTreeItemParent.removeAttribute('data-drag-parent');
3614
3313
  }
3615
- dragParent = null;
3314
+ draggedTreeItemParent = null;
3616
3315
  }
3617
3316
  }, {
3618
3317
  key: "nulling",
3619
3318
  value: function nulling() {
3620
3319
  this.removeDragPrent();
3621
3320
  this.startX = 0;
3622
- this.startLevel = this.currentLevel = 1;
3321
+ this.startLevel = 1;
3322
+ draggedTreeItemLevel = draggedTreeItemBefore = draggedTreeItemAfter = undefined;
3323
+ }
3324
+ }], [{
3325
+ key: "eventProperties",
3326
+ value: function eventProperties() {
3327
+ var obj = {};
3328
+ if (draggedTreeItemParent !== undefined) {
3329
+ obj.draggedTreeItemParent = draggedTreeItemParent;
3330
+ }
3331
+ if (draggedTreeItemLevel !== undefined) {
3332
+ obj.draggedTreeItemLevel = draggedTreeItemLevel;
3333
+ }
3334
+ if (draggedTreeItemBefore !== undefined) {
3335
+ obj.draggedTreeItemBefore = draggedTreeItemBefore;
3336
+ }
3337
+ if (draggedTreeItemAfter !== undefined) {
3338
+ obj.draggedTreeItemAfter = draggedTreeItemAfter;
3339
+ }
3340
+ return obj;
3623
3341
  }
3624
3342
  }]);
3625
3343
  }();
@@ -3631,7 +3349,7 @@ function getLevel(el, options) {
3631
3349
 
3632
3350
  Sortable.mount(TreePlugin);
3633
3351
  Sortable.mount(AutoScroll);
3634
- Sortable.mount(Remove, Revert);
3352
+ Sortable.mount(RemoveOnSpill, RevertOnSpill);
3635
3353
 
3636
3354
  export default Sortable;
3637
- export { MultiDragPlugin as MultiDrag, Sortable, SwapPlugin as Swap };
3355
+ export { Sortable, Swap };