@pantograph/sortable 2.0.0 → 2.1.1

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