sortable-dnd
Advanced tools
Comparing version 0.3.4 to 0.3.5
/*! | ||
* sortable-dnd v0.3.4 | ||
* sortable-dnd v0.3.5 | ||
* open source under the MIT license | ||
@@ -665,2 +665,7 @@ * https://github.com/mfuu/sortable-dnd#readme | ||
if (start < 0) { | ||
start = end; | ||
end = Math.min(children.length - 1, 100); | ||
} | ||
children.slice(start, end + 1).forEach(function (child) { | ||
@@ -792,3 +797,5 @@ animationState.push({ | ||
originalGroup = { | ||
name: originalGroup | ||
name: originalGroup, | ||
pull: true, | ||
put: true | ||
}; | ||
@@ -817,4 +824,3 @@ } | ||
if (nearest) { | ||
if (evt.dataTransfer) evt.dataTransfer.dropEffect = 'move'; // Create imitation event | ||
// Create imitation event | ||
var event = {}; | ||
@@ -873,2 +879,10 @@ | ||
}; | ||
var _globalDragOver = function _globalDragOver(evt) { | ||
if (evt.dataTransfer) { | ||
evt.dataTransfer.dropEffect = 'move'; | ||
} | ||
evt.cancelable && evt.preventDefault(); | ||
}; | ||
/** | ||
@@ -1124,7 +1138,6 @@ * @class Sortable | ||
_triggerEvent: function _triggerEvent(evt) { | ||
if (activeGroup.name !== this.options.group.name) return; | ||
rootEl = evt.rootEl; | ||
if (this.nativeDraggable) { | ||
on(this.el, 'dragover', this._onDragOver); | ||
on(this.el, 'dragover', _globalDragOver); | ||
on(this.el, 'dragend', this._onDrop); | ||
@@ -1162,3 +1175,3 @@ | ||
if (this.options.group.put || fromGroup === this.el) this._onChange(target, e, evt); // auto scroll | ||
if (this._allowPut()) this._onChange(target, e, evt); // auto scroll | ||
@@ -1179,4 +1192,6 @@ clearTimeout(this.autoScrollTimer); | ||
if (evt.dataTransfer) evt.dataTransfer.dropEffect = 'move'; // truly started | ||
var allowPut = this._allowPut(); | ||
if (evt.dataTransfer) evt.dataTransfer.dropEffect = allowPut ? 'move' : 'none'; // truly started | ||
this._onStarted(evt, evt); | ||
@@ -1192,5 +1207,15 @@ | ||
if (this.options.group.put || fromGroup === this.el) this._onChange(evt.target, evt, evt); | ||
if (allowPut) this._onChange(evt.target, evt, evt); | ||
} | ||
}, | ||
_allowPut: function _allowPut() { | ||
if (fromGroup === this.el) { | ||
return true; | ||
} else if (!this.options.group.put) { | ||
return false; | ||
} else { | ||
var name = this.options.group.name; | ||
return activeGroup.name && name && activeGroup.name === name; | ||
} | ||
}, | ||
// -------------------------------- real started ---------------------------------- | ||
@@ -1269,6 +1294,8 @@ _onStarted: function _onStarted(e, | ||
if (!lastChild(this.el)) { | ||
if (!lastChild(rootEl) || target === rootEl && differ.from.group !== rootEl) { | ||
differ.from.sortable._captureAnimationState(dragEl, dragEl); | ||
differ.to = { | ||
sortable: this, | ||
group: this.el, | ||
group: rootEl, | ||
node: dragEl, | ||
@@ -1290,5 +1317,8 @@ rect: getRect(dragEl), | ||
this.el.appendChild(dragEl); | ||
rootEl.appendChild(dragEl); | ||
differ.from.sortable._rangeAnimate(); | ||
differ.from.sortable = this; | ||
differ.from.group = this.el; | ||
differ.from.group = rootEl; | ||
} else { | ||
@@ -1304,3 +1334,3 @@ var _getElement2 = getElement(rootEl, target), | ||
sortable: this, | ||
group: this.el, | ||
group: rootEl, | ||
node: dropEl, | ||
@@ -1321,3 +1351,5 @@ rect: rect, | ||
if (differ.from.group !== differ.to.group) { | ||
// onRemove callback | ||
differ.from.sortable._captureAnimationState(dragEl, dropEl); // onRemove callback | ||
differ.from.sortable._dispatchEvent('onRemove', _objectSpread2(_objectSpread2({}, differ), {}, { | ||
@@ -1334,5 +1366,5 @@ event: e, | ||
this.el.insertBefore(dragEl, dropEl); | ||
differ.from.sortable = this; | ||
differ.from.group = this.el; | ||
rootEl.insertBefore(dragEl, dropEl); | ||
differ.from.sortable._rangeAnimate(); | ||
} else { | ||
@@ -1349,11 +1381,11 @@ // onChange callback | ||
if (_offset.top < offset.top || _offset.left < offset.left) { | ||
this.el.insertBefore(dragEl, dropEl.nextSibling); | ||
rootEl.insertBefore(dragEl, dropEl.nextSibling); | ||
} else { | ||
this.el.insertBefore(dragEl, dropEl); | ||
rootEl.insertBefore(dragEl, dropEl); | ||
} | ||
differ.from.sortable = this; | ||
differ.from.group = this.el; | ||
} | ||
differ.from.sortable = this; | ||
differ.from.group = rootEl; | ||
this._rangeAnimate(); | ||
@@ -1428,3 +1460,3 @@ } | ||
off(this.el, 'dragstart', this._onDragStart); | ||
off(this.el, 'dragover', this._onDragOver); | ||
off(this.el, 'dragover', _globalDragOver); | ||
off(this.el, 'dragend', this._onDrop); | ||
@@ -1431,0 +1463,0 @@ } |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Sortable=e()}(this,function(){"use strict";function e(e,t){var o,n=Object.keys(e);return Object.getOwnPropertySymbols&&(o=Object.getOwnPropertySymbols(e),t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)),n}function c(n){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?e(Object(r),!0).forEach(function(t){var e,o;e=n,o=r[t=t],t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(r,t))})}return n}function s(t){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function r(t,e,o){return e&&n(t.prototype,e),o&&n(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t}function B(t){return function(t){if(Array.isArray(t))return i(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return i(t,e);var o=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(o="Object"===o&&t.constructor?t.constructor.name:o)||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?i(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var o=0,n=new Array(e);o<e;o++)n[o]=t[o];return n}function t(t){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(t)}var a,l=t(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),I=t(/Edge/i),u=t(/safari/i)&&!t(/chrome/i)&&!t(/android/i),R=t(/iP(ad|od|hone)/i),W=t(/chrome/i)&&t(/android/i),X={capture:!1,passive:!1},Y=/\s+/g,h=["-webkit-transition","-moz-transition","-ms-transition","-o-transition","transition"],H=["-webkit-transform","-moz-transform","-ms-transform","-o-transform","transform"],F=(a=!1,document.addEventListener("checkIfSupportPassive",null,{get passive(){return a=!0}}),a);function f(e,o){o?"none"===o?h.forEach(function(t){return E(e,t,"none")}):h.forEach(function(t){return E(e,t,"".concat(t.split("transition")[0],"transform ").concat(o))}):h.forEach(function(t){return E(e,t,"")})}function d(e,o){o?H.forEach(function(t){return E(e,t,"".concat(t.split("transform")[0]).concat(o))}):H.forEach(function(t){return E(e,t,"")})}function p(t){var e=t.touches&&t.touches[0]||t.pointerType&&"touch"===t.pointerType&&t,t=e||t;return{touch:e,e:t,target:e?document.elementFromPoint(t.clientX,t.clientY):t.target}}function g(t,e,o){window.addEventListener?t.addEventListener(e,o,!(!F&&l)&&X):window.attachEvent&&t.attachEvent("on"+e,o)}function m(t,e,o){window.removeEventListener?t.removeEventListener(e,o,!(!F&&l)&&X):window.detachEvent&&t.detachEvent("on"+e,o)}function v(t){for(var e={top:0,left:0,height:0,width:0},o=(e.height=t.offsetHeight,e.width=t.offsetWidth,e.top=t.offsetTop,e.left=t.offsetLeft,t.offsetParent);null!==o;)e.top+=o.offsetTop,e.left+=o.offsetLeft,o=o.offsetParent;return e}function b(){var t=document.scrollingElement;return!t||t.contains(document.body)?document:t}function w(t,e){if(t.getBoundingClientRect||t===window){var o,n={top:0,left:0,bottom:0,right:0,height:0,width:0};if(t!==window&&t.parentNode&&t!==b()){if(o=t.getBoundingClientRect(),n.top=o.top,n.left=o.left,n.bottom=o.bottom,n.right=o.right,n.height=o.height,n.width=o.width,e&&t.parentNode!==t.ownerDocument.body)for(var r,i=t.parentNode;i&&i.getBoundingClientRect&&i!==t.ownerDocument.body;){if((r=i.getBoundingClientRect()).height<n.height)return n.top=r.top,n.left=r.left,n.bottom=r.bottom,n.right=r.right,n.height=r.height,n.width=r.width,n;i=i.parentNode}}else n.top=0,n.left=0,n.bottom=window.innerHeight,n.right=window.innerWidth,n.height=window.innerHeight,n.width=window.innerWidth;return n}}function y(t,e,o){var n=B(Array.from(t.children)),t=n.indexOf(e);if(-1<t)return o?n[t]:{index:t,el:n[t],rect:w(n[t]),offset:v(n[t])};for(var r=0;r<n.length;r++)if(function(t,e){var o;if(t&&e)for(o=t.parentNode;o;){if(e===o)return 1;o=o.parentNode}return}(e,n[r]))return o?n[r]:{index:r,el:n[r],rect:w(n[r]),offset:v(n[r])};return o?null:{index:-1,el:null,rect:{},offset:{}}}function D(t,e,o){var n;t&&e&&(t.classList?t.classList[o?"add":"remove"](e):(n=(" "+t.className+" ").replace(Y," ").replace(" "+e+" "," "),t.className=(n+(o?" "+e:"")).replace(Y," ")))}function q(t,e){if(e&&(">"===e[0]&&(e=e.substring(1)),t))try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch(t){return}}function E(t,e,o){var n=t&&t.style;if(n){if(void 0===o)return document.defaultView&&document.defaultView.getComputedStyle?o=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(o=t.currentStyle),void 0===e?o:o[e];n[e=e in n||-1!==e.indexOf("webkit")?e:"-webkit-"+e]=o+("string"==typeof o?"":"px")}}function z(o,n,r){var i=null;return function(){var t=this,e=arguments;i&&clearTimeout(i),r&&!i&&o.apply(t,e),i=setTimeout(function(){o.apply(t,e)},n)}}function V(o,n){var r=null;return function(){var t=this,e=arguments;r=r||setTimeout(function(){r=null,o.apply(t,e)},n)}}var _="Sortable"+Date.now();function G(){var r=[];return{_captureAnimationState:function(t,e){var o=B(Array.from(this.el.children)),e=(t=t,e=e,t=(n=o).indexOf(t),n=n.indexOf(e),t<n?{start:t,end:n}:{start:n,end:t}),n=e.start,t=e.end;r.length=0,o.slice(n,t+1).forEach(function(t){r.push({target:t,rect:w(t)})})},_rangeAnimate:function(){var o=this;r.forEach(function(t){var e=t.target,t=t.rect;o._animate(e,t,o.options.animation)})},_animate:function(t,e){var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:150,n=w(t),r=e.left-n.left,e=e.top-n.top;f(t,"none"),d(t,"translate3d(".concat(r,"px, ").concat(e,"px, 0)")),t.offsetWidth,f(t,"".concat(o,"ms")),d(t,"translate3d(0px, 0px, 0px)"),clearTimeout(t.animated),t.animated=setTimeout(function(){f(t,""),d(t,""),t.animated=null},o)}}}function S(t){if(x){var e=t=t.touches?t.touches[0]:t,o=e.clientX,e=e.clientY,n=U(o,e);if(n){t.dataTransfer&&(t.dataTransfer.dropEffect="move");var r,i={};for(r in t)i[r]=t[r];i.target=document.elementFromPoint(o,e),i.rootEl=n,i.preventDefault=void 0,i.stopPropagation=void 0,n[_]._triggerEvent(i)}}}function U(r,i){var a;return K.some(function(t){var e,o,n=t[_].options.emptyInsertThreshold;if(n)return o=w(t,!0),e=r>=o.left-n&&r<=o.right+n,o=i>=o.top-n&&i<=o.bottom+n,e&&o?a=t:void 0}),a}var T,x,O,P,C,M,Z=r(function t(){o(this,t),this.sortableDown=void 0,this.sortableMove=void 0,this.animationEnd=void 0}),$=function(){function t(){o(this,t),this.from={sortable:null,group:null,node:null,rect:{},offset:{}},this.to={sortable:null,group:null,node:null,rect:{},offset:{}}}return r(t,[{key:"destroy",value:function(){this.from={sortable:null,group:null,node:null,rect:{},offset:{}},this.to={sortable:null,group:null,node:null,rect:{},offset:{}}}}]),t}(),J="undefined"!=typeof document&&!W&&!R&&"draggable"in document.createElement("div"),K=[],A=new Z,j=new $,k={x:0,y:0},N={x:0,y:0};function L(t,e){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));(t[_]=this).el=t,this.scrollEl=function(t,e){if(!t||!t.getBoundingClientRect)return b();var o=t,n=!1;do{if(o.clientWidth<o.scrollWidth||o.clientHeight<o.scrollHeight){var r=E(o);if(o.clientWidth<o.scrollWidth&&("auto"==r.overflowX||"scroll"==r.overflowX)||o.clientHeight<o.scrollHeight&&("auto"==r.overflowY||"scroll"==r.overflowY)){if(!o.getBoundingClientRect||o===document.body)return b();if(n||e)return o;n=!0}}}while(o=o.parentNode);return b()}(t,!0),this.options=e=Object.assign({},e),this.ownerDocument=t.ownerDocument;var o,n,r={group:"",animation:150,draggable:void 0,onDrag:void 0,onMove:void 0,onDrop:void 0,onChange:void 0,autoScroll:!0,scrollStep:5,scrollThreshold:15,delay:0,delayOnTouchOnly:!1,disabled:!1,ghostClass:"",ghostStyle:{},chosenClass:"",fallbackOnBody:!1,forceFallback:!1,stopPropagation:!1,supportPointer:"PointerEvent"in window&&!u,supportTouch:"ontouchstart"in window,emptyInsertThreshold:5};for(o in r)o in this.options||(this.options[o]=r[o]);for(n in this.nativeDraggable=!this.options.forceFallback&&J,this.dragStartTimer=null,this.autoScrollTimer=null,a={},(i=(e=e).group)&&"object"==s(i)||(i={name:i}),a.name=i.name,a.pull=i.pull,a.put=i.put,e.group=a,this)"_"===n.charAt(0)&&"function"==typeof this[n]&&(this[n]=this[n].bind(this));var i=this.options,e=i.supportPointer,a=i.supportTouch;g(t,e?"pointerdown":a?"touchstart":"mousedown",this._onDrag),K.push(t),Object.assign(this,G(),(window.requestAnimationFrame||(window.requestAnimationFrame=function(t){return setTimeout(t,17)}),{_autoScroll:V(function(t,e){var o,n,r,i,a,s,l,c,u,h,f,d,p,g,m;t.scrollEl&&e.sortableDown&&e.sortableMove&&(o=(n=e.sortableMove).clientX,n=n.clientY,void 0!==o&&void 0!==n&&t.scrollEl!==t.ownerDocument&&(r=(g=t.scrollEl).scrollTop,i=g.scrollLeft,a=g.scrollHeight,g=g.scrollWidth,s=(p=w(t.scrollEl)).top,f=p.right,l=p.bottom,d=p.left,c=p.height,p=p.width,u=(h=t.options).scrollStep,h=h.scrollThreshold,d=0<i&&d<=o&&o<=d+h,p=i+p<g&&o<=f&&f-h<=o,g=r+c<a&&n<=l&&l-h<=n,m={x:i,y:r},(f=0<r&&s<=n&&n<=s+h)?(m.x=d?i-u:p?i+u:i,m.y=r-u):g?(m.x=d?i-u:p?i+u:i,m.y=r+u):d?(m.x=i-u,m.y=r):p&&(m.x=i+u,m.y=r),(f||d||p||g)&&requestAnimationFrame(function(){t.scrollEl.scrollTo(m.x,m.y),t._autoScroll(t,e)})))},10)}))}return(L.prototype={constructor:L,destroy:function(){this.el[_]=null,m(this.el,"pointerdown",this._onDrag),m(this.el,"touchstart",this._onDrag),m(this.el,"mousedown",this._onDrag),this._clearState(),Array.prototype.forEach.call(this.el.querySelectorAll("[draggable]"),function(t){t.removeAttribute("draggable")})},_onDrag:function(t){var e=this;if(!x&&!this.options.disabled&&!1!==this.options.group.pull){if(/mousedown|pointerdown/.test(t.type)&&0!==t.button)return!0;var t=p(t),o=t.touch,n=t.e,t=t.target;if(!this.nativeDraggable&&u&&t&&"SELECT"===t.tagName.toUpperCase())return!0;if(t===this.el)return!0;var r=this.options.draggable;if("function"==typeof r){var i=r(n);if(!i)return!0;!function(e){var t=document.createElement("div");try{return t.appendChild(e.cloneNode(!0)),1==e.nodeType}catch(t){return e==window||e==document}}(i)||(x=i)}else if("string"==typeof r){if(!q(t,r))return!0}else if(r)throw new Error('draggable expected "function" or "string" but received "'.concat(s(r),'"'));if(!(x=x||y(this.el,t,!0))||x.animated)return!0;o&&(x.style["touch-action"]="none"),C=this.el;i=y(this.el,x),r=i.rect,t=i.offset,i=(j.from={sortable:this,group:this.el,node:x,rect:r,offset:t},k={x:n.clientX-r.left,y:n.clientY-r.top},A.sortableDown=n,g(this.ownerDocument,"dragover",S),this.options.supportPointer?g(this.ownerDocument,"pointermove",S):g(this.ownerDocument,o?"touchmove":"mousemove",S),g(this.ownerDocument,"pointerup",this._onDrop),g(this.ownerDocument,"touchend",this._onDrop),g(this.ownerDocument,"mouseup",this._onDrop),this.options),t=i.delay,r=i.delayOnTouchOnly;!t||r&&!o||this.nativeDraggable&&(I||l)?this._onStart(n,o):(clearTimeout(this.dragStartTimer),this.dragStartTimer=setTimeout(function(){return e._onStart(n,o)},t))}},_onStart:function(t,e){T=this.el,M=this.options.group,!this.nativeDraggable||e?(this.options.supportPointer?g(this.ownerDocument,"pointermove",this._onMove):g(this.ownerDocument,e?"touchmove":"mousemove",this._onMove),g(this.ownerDocument,"pointercancel",this._onDrop),g(this.ownerDocument,"touchcancel",this._onDrop)):(x.draggable=!0,g(this.el,"dragstart",this._onDragStart));try{document.selection?setTimeout(function(){document.selection.empty()},0):window.getSelection().removeAllRanges()}catch(t){}},_onDragStart:function(t){t=t.dataTransfer;t&&(t.setData("text",""),t.setDragImage(P,k.x,k.y),t.effectAllowed="move")},_triggerEvent:function(t){M.name===this.options.group.name&&(T=t.rootEl,this.nativeDraggable?(g(this.el,"dragover",this._onDragOver),g(this.el,"dragend",this._onDrop),this._onDragOver(t)):this._onMove(t))},_onMove:function(t){var e,o,n=this;A.sortableDown&&x&&(this._preventEvent(t),e=(o=p(t)).e,o=o.target,this._onStarted(e,t),t.rootEl&&(this._dispatchEvent("onMove",c(c({},j),{},{ghostEl:P,event:e,originalEvent:t})),!this.options.group.put&&C!==this.el||this._onChange(o,e,t),clearTimeout(this.autoScrollTimer),this.options.autoScroll&&(this.autoScrollTimer=setTimeout(function(){return n._autoScroll(n,A)},0))))},_onDragOver:function(t){var e,o,n,r;A.sortableDown&&x&&(this._preventEvent(t),t.dataTransfer&&(t.dataTransfer.dropEffect="move"),this._onStarted(t,t),!t.rootEl||(o=(e=t).clientX,e=e.clientY,n=o-N.x,r=e-N.y,N.x=o,N.y=e,void 0!==o&&Math.abs(n)<=0&&void 0!==e&&Math.abs(r)<=0)||(this._dispatchEvent("onMove",c(c({},j),{},{ghostEl:P,event:t,originalEvent:t})),!this.options.group.put&&C!==this.el||this._onChange(t.target,t,t)))},_onStarted:function(t,e){var o;A.sortableMove||(this._dispatchEvent("onDrag",c(c({},j),{},{event:t,originalEvent:e})),this._appendGhost(),D(x,this.options.chosenClass,!0),x.style["will-change"]="transform",this.nativeDraggable&&this._unbindDropEvents(),u&&E(document.body,"user-select","none")),A.sortableMove=t,this.nativeDraggable||(o=(e=A.sortableDown).clientX,e=e.clientY,f(P,"none"),d(P,"translate3d(".concat(t.clientX-o,"px, ").concat(t.clientY-e,"px, 0)")))},_appendGhost:function(){if(!P){var t,e=this.options,o=e.fallbackOnBody,n=e.ghostClass,e=e.ghostStyle,r=void 0===e?{}:e,e=o?document.body:this.el,o=j.from.rect;for(t in D(P=x.cloneNode(!0),n,!0),E(P,"box-sizing","border-box"),E(P,"margin",0),E(P,"top",o.top),E(P,"left",o.left),E(P,"width",o.width),E(P,"height",o.height),E(P,"opacity","0.8"),E(P,"position","fixed"),E(P,"zIndex","100000"),E(P,"pointerEvents","none"),r)E(P,t,r[t]);this.nativeDraggable&&E(P,"top","-999px"),f(P,"none"),d(P,"translate3d(0px, 0px, 0px)"),e.appendChild(P);n=k.x/parseInt(P.style.width)*100,o=k.y/parseInt(P.style.height)*100;E(P,"transform-origin","".concat(n,"% ").concat(o,"%")),E(P,"transform","translateZ(0)"),L.ghost=P}},_onChange:z(function(t,e,o){var n,r,i,a,s,l;x&&(!function(t,e){for(var o=t.lastElementChild;o&&(o===L.ghost||"none"===E(o,"display")||e&&!q(o,e));)o=o.previousElementSibling;return o}(this.el)?(j.to={sortable:this,group:this.el,node:x,rect:w(x),offset:v(x)},j.from.sortable._dispatchEvent("onRemove",c(c({},j),{},{event:e,originalEvent:o})),this._dispatchEvent("onAdd",c(c({},j),{},{event:e,originalEvent:o})),this.el.appendChild(x),j.from.sortable=this,j.from.group=this.el):(n=(t=y(T,t)).el,s=t.rect,t=t.offset,n&&!n.animated&&n!==x&&(O=n,j.to={sortable:this,group:this.el,node:O,rect:s,offset:t},n=e.clientX,r=e.clientY,l=s.left,i=s.right,a=s.top,s=s.bottom,l<n&&n<i&&a<r&&r<s&&(this._captureAnimationState(x,O),j.from.group!==j.to.group?(j.from.sortable._dispatchEvent("onRemove",c(c({},j),{},{event:e,originalEvent:o})),this._dispatchEvent("onAdd",c(c({},j),{},{event:e,originalEvent:o})),this.el.insertBefore(x,O)):(this._dispatchEvent("onChange",c(c({},j),{},{event:e,originalEvent:o})),(l=v(x)).top<t.top||l.left<t.left?this.el.insertBefore(x,O.nextSibling):this.el.insertBefore(x,O)),j.from.sortable=this,j.from.group=this.el,this._rangeAnimate()))))},3),_onDrop:function(t){var e,o;this._unbindDragEvents(),this._unbindMoveEvents(),this._unbindDropEvents(),this._preventEvent(t),this.dragStartTimer&&clearTimeout(this.dragStartTimer),x&&(e=p(t).touch,D(x,this.options.chosenClass,!1),this.nativeDraggable&&(x.draggable=!1),e&&(x.style["touch-action"]=""),x.style["will-change"]="",A.sortableDown&&A.sortableMove&&(j.to.offset=v(x),j.to.rect=w(x),e=j.from.offset,o=j.to.offset,e=e.top!==o.top||e.left!==o.left,this._dispatchEvent("onDrop",c(c({},j),{},{changed:e,event:t,originalEvent:t})))),u&&E(document.body,"user-select",""),this._clearState()},_preventEvent:function(t){void 0!==t.preventDefault&&t.cancelable&&t.preventDefault(),this.options.stopPropagation&&t.stopPropagation&&t.stopPropagation()},_dispatchEvent:function(t,e){t=this.options[t];"function"==typeof t&&t(e)},_clearState:function(){P&&P.parentNode&&P.parentNode.removeChild(P),x=O=P=C=M=L.ghostEl=null,k=N={x:0,y:0},A=new Z,j.destroy()},_unbindDragEvents:function(){this.nativeDraggable&&(m(this.el,"dragstart",this._onDragStart),m(this.el,"dragover",this._onDragOver),m(this.el,"dragend",this._onDrop))},_unbindMoveEvents:function(){m(this.ownerDocument,"pointermove",this._onMove),m(this.ownerDocument,"touchmove",this._onMove),m(this.ownerDocument,"mousemove",this._onMove),m(this.ownerDocument,"pointermove",S),m(this.ownerDocument,"touchmove",S),m(this.ownerDocument,"mousemove",S),m(this.ownerDocument,"dragover",S)},_unbindDropEvents:function(){m(this.ownerDocument,"pointerup",this._onDrop),m(this.ownerDocument,"pointercancel",this._onDrop),m(this.ownerDocument,"touchend",this._onDrop),m(this.ownerDocument,"touchcancel",this._onDrop),m(this.ownerDocument,"mouseup",this._onDrop)}}).utils={getRect:w,getOffset:v,debounce:z,throttle:V},L}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Sortable=e()}(this,function(){"use strict";function e(e,t){var o,n=Object.keys(e);return Object.getOwnPropertySymbols&&(o=Object.getOwnPropertySymbols(e),t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)),n}function c(n){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?e(Object(r),!0).forEach(function(t){var e,o;e=n,o=r[t=t],t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(r)):e(Object(r)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(r,t))})}return n}function s(t){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(t,e){for(var o=0;o<e.length;o++){var n=e[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function r(t,e,o){return e&&n(t.prototype,e),o&&n(t,o),Object.defineProperty(t,"prototype",{writable:!1}),t}function B(t){return function(t){if(Array.isArray(t))return i(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(t){if("string"==typeof t)return i(t,e);var o=Object.prototype.toString.call(t).slice(8,-1);return"Map"===(o="Object"===o&&t.constructor?t.constructor.name:o)||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?i(t,e):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var o=0,n=new Array(e);o<e;o++)n[o]=t[o];return n}function t(t){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(t)}var a,l=t(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),I=t(/Edge/i),u=t(/safari/i)&&!t(/chrome/i)&&!t(/android/i),R=t(/iP(ad|od|hone)/i),W=t(/chrome/i)&&t(/android/i),X={capture:!1,passive:!1},Y=/\s+/g,h=["-webkit-transition","-moz-transition","-ms-transition","-o-transition","transition"],H=["-webkit-transform","-moz-transform","-ms-transform","-o-transform","transform"],F=(a=!1,document.addEventListener("checkIfSupportPassive",null,{get passive(){return a=!0}}),a);function f(e,o){o?"none"===o?h.forEach(function(t){return _(e,t,"none")}):h.forEach(function(t){return _(e,t,"".concat(t.split("transition")[0],"transform ").concat(o))}):h.forEach(function(t){return _(e,t,"")})}function d(e,o){o?H.forEach(function(t){return _(e,t,"".concat(t.split("transform")[0]).concat(o))}):H.forEach(function(t){return _(e,t,"")})}function p(t){var e=t.touches&&t.touches[0]||t.pointerType&&"touch"===t.pointerType&&t,t=e||t;return{touch:e,e:t,target:e?document.elementFromPoint(t.clientX,t.clientY):t.target}}function m(t,e,o){window.addEventListener?t.addEventListener(e,o,!(!F&&l)&&X):window.attachEvent&&t.attachEvent("on"+e,o)}function g(t,e,o){window.removeEventListener?t.removeEventListener(e,o,!(!F&&l)&&X):window.detachEvent&&t.detachEvent("on"+e,o)}function v(t){for(var e={top:0,left:0,height:0,width:0},o=(e.height=t.offsetHeight,e.width=t.offsetWidth,e.top=t.offsetTop,e.left=t.offsetLeft,t.offsetParent);null!==o;)e.top+=o.offsetTop,e.left+=o.offsetLeft,o=o.offsetParent;return e}function b(){var t=document.scrollingElement;return!t||t.contains(document.body)?document:t}function w(t,e){if(t.getBoundingClientRect||t===window){var o,n={top:0,left:0,bottom:0,right:0,height:0,width:0};if(t!==window&&t.parentNode&&t!==b()){if(o=t.getBoundingClientRect(),n.top=o.top,n.left=o.left,n.bottom=o.bottom,n.right=o.right,n.height=o.height,n.width=o.width,e&&t.parentNode!==t.ownerDocument.body)for(var r,i=t.parentNode;i&&i.getBoundingClientRect&&i!==t.ownerDocument.body;){if((r=i.getBoundingClientRect()).height<n.height)return n.top=r.top,n.left=r.left,n.bottom=r.bottom,n.right=r.right,n.height=r.height,n.width=r.width,n;i=i.parentNode}}else n.top=0,n.left=0,n.bottom=window.innerHeight,n.right=window.innerWidth,n.height=window.innerHeight,n.width=window.innerWidth;return n}}function y(t,e,o){var n=B(Array.from(t.children)),t=n.indexOf(e);if(-1<t)return o?n[t]:{index:t,el:n[t],rect:w(n[t]),offset:v(n[t])};for(var r=0;r<n.length;r++)if(function(t,e){var o;if(t&&e)for(o=t.parentNode;o;){if(e===o)return 1;o=o.parentNode}return}(e,n[r]))return o?n[r]:{index:r,el:n[r],rect:w(n[r]),offset:v(n[r])};return o?null:{index:-1,el:null,rect:{},offset:{}}}function D(t,e,o){var n;t&&e&&(t.classList?t.classList[o?"add":"remove"](e):(n=(" "+t.className+" ").replace(Y," ").replace(" "+e+" "," "),t.className=(n+(o?" "+e:"")).replace(Y," ")))}function q(t,e){if(e&&(">"===e[0]&&(e=e.substring(1)),t))try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch(t){return}}function _(t,e,o){var n=t&&t.style;if(n){if(void 0===o)return document.defaultView&&document.defaultView.getComputedStyle?o=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(o=t.currentStyle),void 0===e?o:o[e];n[e=e in n||-1!==e.indexOf("webkit")?e:"-webkit-"+e]=o+("string"==typeof o?"":"px")}}function z(o,n,r){var i=null;return function(){var t=this,e=arguments;i&&clearTimeout(i),r&&!i&&o.apply(t,e),i=setTimeout(function(){o.apply(t,e)},n)}}function V(o,n){var r=null;return function(){var t=this,e=arguments;r=r||setTimeout(function(){r=null,o.apply(t,e)},n)}}var E="Sortable"+Date.now();function G(){var r=[];return{_captureAnimationState:function(t,e){var o=B(Array.from(this.el.children)),e=(t=t,e=e,t=(n=o).indexOf(t),n=n.indexOf(e),t<n?{start:t,end:n}:{start:n,end:t}),n=e.start,t=e.end;n<(r.length=0)&&(n=t,t=Math.min(o.length-1,100)),o.slice(n,t+1).forEach(function(t){r.push({target:t,rect:w(t)})})},_rangeAnimate:function(){var o=this;r.forEach(function(t){var e=t.target,t=t.rect;o._animate(e,t,o.options.animation)})},_animate:function(t,e){var o=2<arguments.length&&void 0!==arguments[2]?arguments[2]:150,n=w(t),r=e.left-n.left,e=e.top-n.top;f(t,"none"),d(t,"translate3d(".concat(r,"px, ").concat(e,"px, 0)")),t.offsetWidth,f(t,"".concat(o,"ms")),d(t,"translate3d(0px, 0px, 0px)"),clearTimeout(t.animated),t.animated=setTimeout(function(){f(t,""),d(t,""),t.animated=null},o)}}}function S(t){if(x){var e=t=t.touches?t.touches[0]:t,o=e.clientX,e=e.clientY,n=U(o,e);if(n){var r,i={};for(r in t)i[r]=t[r];i.target=document.elementFromPoint(o,e),i.rootEl=n,i.preventDefault=void 0,i.stopPropagation=void 0,n[E]._triggerEvent(i)}}}function U(r,i){var a;return Q.some(function(t){var e,o,n=t[E].options.emptyInsertThreshold;if(n)return o=w(t,!0),e=r>=o.left-n&&r<=o.right+n,o=i>=o.top-n&&i<=o.bottom+n,e&&o?a=t:void 0}),a}function Z(t){t.dataTransfer&&(t.dataTransfer.dropEffect="move"),t.cancelable&&t.preventDefault()}var T,x,O,P,A,C,$=r(function t(){o(this,t),this.sortableDown=void 0,this.sortableMove=void 0,this.animationEnd=void 0}),J=function(){function t(){o(this,t),this.from={sortable:null,group:null,node:null,rect:{},offset:{}},this.to={sortable:null,group:null,node:null,rect:{},offset:{}}}return r(t,[{key:"destroy",value:function(){this.from={sortable:null,group:null,node:null,rect:{},offset:{}},this.to={sortable:null,group:null,node:null,rect:{},offset:{}}}}]),t}(),K="undefined"!=typeof document&&!W&&!R&&"draggable"in document.createElement("div"),Q=[],M=new $,j=new J,k={x:0,y:0},N={x:0,y:0};function L(t,e){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(t));(t[E]=this).el=t,this.scrollEl=function(t,e){if(!t||!t.getBoundingClientRect)return b();var o=t,n=!1;do{if(o.clientWidth<o.scrollWidth||o.clientHeight<o.scrollHeight){var r=_(o);if(o.clientWidth<o.scrollWidth&&("auto"==r.overflowX||"scroll"==r.overflowX)||o.clientHeight<o.scrollHeight&&("auto"==r.overflowY||"scroll"==r.overflowY)){if(!o.getBoundingClientRect||o===document.body)return b();if(n||e)return o;n=!0}}}while(o=o.parentNode);return b()}(t,!0),this.options=e=Object.assign({},e),this.ownerDocument=t.ownerDocument;var o,n,r={group:"",animation:150,draggable:void 0,onDrag:void 0,onMove:void 0,onDrop:void 0,onChange:void 0,autoScroll:!0,scrollStep:5,scrollThreshold:15,delay:0,delayOnTouchOnly:!1,disabled:!1,ghostClass:"",ghostStyle:{},chosenClass:"",fallbackOnBody:!1,forceFallback:!1,stopPropagation:!1,supportPointer:"PointerEvent"in window&&!u,supportTouch:"ontouchstart"in window,emptyInsertThreshold:5};for(o in r)o in this.options||(this.options[o]=r[o]);for(n in this.nativeDraggable=!this.options.forceFallback&&K,this.dragStartTimer=null,this.autoScrollTimer=null,a={},(i=(e=e).group)&&"object"==s(i)||(i={name:i,pull:!0,put:!0}),a.name=i.name,a.pull=i.pull,a.put=i.put,e.group=a,this)"_"===n.charAt(0)&&"function"==typeof this[n]&&(this[n]=this[n].bind(this));var i=this.options,e=i.supportPointer,a=i.supportTouch;m(t,e?"pointerdown":a?"touchstart":"mousedown",this._onDrag),Q.push(t),Object.assign(this,G(),(window.requestAnimationFrame||(window.requestAnimationFrame=function(t){return setTimeout(t,17)}),{_autoScroll:V(function(t,e){var o,n,r,i,a,s,l,c,u,h,f,d,p,m,g;t.scrollEl&&e.sortableDown&&e.sortableMove&&(o=(n=e.sortableMove).clientX,n=n.clientY,void 0!==o&&void 0!==n&&t.scrollEl!==t.ownerDocument&&(r=(m=t.scrollEl).scrollTop,i=m.scrollLeft,a=m.scrollHeight,m=m.scrollWidth,s=(p=w(t.scrollEl)).top,f=p.right,l=p.bottom,d=p.left,c=p.height,p=p.width,u=(h=t.options).scrollStep,h=h.scrollThreshold,d=0<i&&d<=o&&o<=d+h,p=i+p<m&&o<=f&&f-h<=o,m=r+c<a&&n<=l&&l-h<=n,g={x:i,y:r},(f=0<r&&s<=n&&n<=s+h)?(g.x=d?i-u:p?i+u:i,g.y=r-u):m?(g.x=d?i-u:p?i+u:i,g.y=r+u):d?(g.x=i-u,g.y=r):p&&(g.x=i+u,g.y=r),(f||d||p||m)&&requestAnimationFrame(function(){t.scrollEl.scrollTo(g.x,g.y),t._autoScroll(t,e)})))},10)}))}return(L.prototype={constructor:L,destroy:function(){this.el[E]=null,g(this.el,"pointerdown",this._onDrag),g(this.el,"touchstart",this._onDrag),g(this.el,"mousedown",this._onDrag),this._clearState(),Array.prototype.forEach.call(this.el.querySelectorAll("[draggable]"),function(t){t.removeAttribute("draggable")})},_onDrag:function(t){var e=this;if(!x&&!this.options.disabled&&!1!==this.options.group.pull){if(/mousedown|pointerdown/.test(t.type)&&0!==t.button)return!0;var t=p(t),o=t.touch,n=t.e,t=t.target;if(!this.nativeDraggable&&u&&t&&"SELECT"===t.tagName.toUpperCase())return!0;if(t===this.el)return!0;var r=this.options.draggable;if("function"==typeof r){var i=r(n);if(!i)return!0;!function(e){var t=document.createElement("div");try{return t.appendChild(e.cloneNode(!0)),1==e.nodeType}catch(t){return e==window||e==document}}(i)||(x=i)}else if("string"==typeof r){if(!q(t,r))return!0}else if(r)throw new Error('draggable expected "function" or "string" but received "'.concat(s(r),'"'));if(!(x=x||y(this.el,t,!0))||x.animated)return!0;o&&(x.style["touch-action"]="none"),A=this.el;i=y(this.el,x),r=i.rect,t=i.offset,i=(j.from={sortable:this,group:this.el,node:x,rect:r,offset:t},k={x:n.clientX-r.left,y:n.clientY-r.top},M.sortableDown=n,m(this.ownerDocument,"dragover",S),this.options.supportPointer?m(this.ownerDocument,"pointermove",S):m(this.ownerDocument,o?"touchmove":"mousemove",S),m(this.ownerDocument,"pointerup",this._onDrop),m(this.ownerDocument,"touchend",this._onDrop),m(this.ownerDocument,"mouseup",this._onDrop),this.options),t=i.delay,r=i.delayOnTouchOnly;!t||r&&!o||this.nativeDraggable&&(I||l)?this._onStart(n,o):(clearTimeout(this.dragStartTimer),this.dragStartTimer=setTimeout(function(){return e._onStart(n,o)},t))}},_onStart:function(t,e){T=this.el,C=this.options.group,!this.nativeDraggable||e?(this.options.supportPointer?m(this.ownerDocument,"pointermove",this._onMove):m(this.ownerDocument,e?"touchmove":"mousemove",this._onMove),m(this.ownerDocument,"pointercancel",this._onDrop),m(this.ownerDocument,"touchcancel",this._onDrop)):(x.draggable=!0,m(this.el,"dragstart",this._onDragStart));try{document.selection?setTimeout(function(){document.selection.empty()},0):window.getSelection().removeAllRanges()}catch(t){}},_onDragStart:function(t){t=t.dataTransfer;t&&(t.setData("text",""),t.setDragImage(P,k.x,k.y),t.effectAllowed="move")},_triggerEvent:function(t){T=t.rootEl,this.nativeDraggable?(m(this.el,"dragover",Z),m(this.el,"dragend",this._onDrop),this._onDragOver(t)):this._onMove(t)},_onMove:function(t){var e,o,n=this;M.sortableDown&&x&&(this._preventEvent(t),e=(o=p(t)).e,o=o.target,this._onStarted(e,t),t.rootEl&&(this._dispatchEvent("onMove",c(c({},j),{},{ghostEl:P,event:e,originalEvent:t})),this._allowPut()&&this._onChange(o,e,t),clearTimeout(this.autoScrollTimer),this.options.autoScroll&&(this.autoScrollTimer=setTimeout(function(){return n._autoScroll(n,M)},0))))},_onDragOver:function(t){var e,o,n,r,i;M.sortableDown&&x&&(this._preventEvent(t),e=this._allowPut(),t.dataTransfer&&(t.dataTransfer.dropEffect=e?"move":"none"),this._onStarted(t,t),!t.rootEl||(n=(o=t).clientX,o=o.clientY,r=n-N.x,i=o-N.y,N.x=n,N.y=o,void 0!==n&&Math.abs(r)<=0&&void 0!==o&&Math.abs(i)<=0)||(this._dispatchEvent("onMove",c(c({},j),{},{ghostEl:P,event:t,originalEvent:t})),e&&this._onChange(t.target,t,t)))},_allowPut:function(){var t;return A===this.el||!!this.options.group.put&&(t=this.options.group.name,C.name&&t&&C.name===t)},_onStarted:function(t,e){var o;M.sortableMove||(this._dispatchEvent("onDrag",c(c({},j),{},{event:t,originalEvent:e})),this._appendGhost(),D(x,this.options.chosenClass,!0),x.style["will-change"]="transform",this.nativeDraggable&&this._unbindDropEvents(),u&&_(document.body,"user-select","none")),M.sortableMove=t,this.nativeDraggable||(o=(e=M.sortableDown).clientX,e=e.clientY,f(P,"none"),d(P,"translate3d(".concat(t.clientX-o,"px, ").concat(t.clientY-e,"px, 0)")))},_appendGhost:function(){if(!P){var t,e=this.options,o=e.fallbackOnBody,n=e.ghostClass,e=e.ghostStyle,r=void 0===e?{}:e,e=o?document.body:this.el,o=j.from.rect;for(t in D(P=x.cloneNode(!0),n,!0),_(P,"box-sizing","border-box"),_(P,"margin",0),_(P,"top",o.top),_(P,"left",o.left),_(P,"width",o.width),_(P,"height",o.height),_(P,"opacity","0.8"),_(P,"position","fixed"),_(P,"zIndex","100000"),_(P,"pointerEvents","none"),r)_(P,t,r[t]);this.nativeDraggable&&_(P,"top","-999px"),f(P,"none"),d(P,"translate3d(0px, 0px, 0px)"),e.appendChild(P);n=k.x/parseInt(P.style.width)*100,o=k.y/parseInt(P.style.height)*100;_(P,"transform-origin","".concat(n,"% ").concat(o,"%")),_(P,"transform","translateZ(0)"),L.ghost=P}},_onChange:z(function(t,e,o){var n,r,i,a,s,l;x&&(!function(t,e){for(var o=t.lastElementChild;o&&(o===L.ghost||"none"===_(o,"display")||e&&!q(o,e));)o=o.previousElementSibling;return o}(T)||t===T&&j.from.group!==T?(j.from.sortable._captureAnimationState(x,x),j.to={sortable:this,group:T,node:x,rect:w(x),offset:v(x)},j.from.sortable._dispatchEvent("onRemove",c(c({},j),{},{event:e,originalEvent:o})),this._dispatchEvent("onAdd",c(c({},j),{},{event:e,originalEvent:o})),T.appendChild(x),j.from.sortable._rangeAnimate(),j.from.sortable=this,j.from.group=T):(n=(t=y(T,t)).el,s=t.rect,t=t.offset,n&&!n.animated&&n!==x&&(O=n,j.to={sortable:this,group:T,node:O,rect:s,offset:t},n=e.clientX,r=e.clientY,l=s.left,i=s.right,a=s.top,s=s.bottom,l<n&&n<i&&a<r&&r<s&&(this._captureAnimationState(x,O),j.from.group!==j.to.group?(j.from.sortable._captureAnimationState(x,O),j.from.sortable._dispatchEvent("onRemove",c(c({},j),{},{event:e,originalEvent:o})),this._dispatchEvent("onAdd",c(c({},j),{},{event:e,originalEvent:o})),T.insertBefore(x,O),j.from.sortable._rangeAnimate()):(this._dispatchEvent("onChange",c(c({},j),{},{event:e,originalEvent:o})),(l=v(x)).top<t.top||l.left<t.left?T.insertBefore(x,O.nextSibling):T.insertBefore(x,O)),j.from.sortable=this,j.from.group=T,this._rangeAnimate()))))},3),_onDrop:function(t){var e,o;this._unbindDragEvents(),this._unbindMoveEvents(),this._unbindDropEvents(),this._preventEvent(t),this.dragStartTimer&&clearTimeout(this.dragStartTimer),x&&(e=p(t).touch,D(x,this.options.chosenClass,!1),this.nativeDraggable&&(x.draggable=!1),e&&(x.style["touch-action"]=""),x.style["will-change"]="",M.sortableDown&&M.sortableMove&&(j.to.offset=v(x),j.to.rect=w(x),e=j.from.offset,o=j.to.offset,e=e.top!==o.top||e.left!==o.left,this._dispatchEvent("onDrop",c(c({},j),{},{changed:e,event:t,originalEvent:t})))),u&&_(document.body,"user-select",""),this._clearState()},_preventEvent:function(t){void 0!==t.preventDefault&&t.cancelable&&t.preventDefault(),this.options.stopPropagation&&t.stopPropagation&&t.stopPropagation()},_dispatchEvent:function(t,e){t=this.options[t];"function"==typeof t&&t(e)},_clearState:function(){P&&P.parentNode&&P.parentNode.removeChild(P),x=O=P=A=C=L.ghostEl=null,k=N={x:0,y:0},M=new $,j.destroy()},_unbindDragEvents:function(){this.nativeDraggable&&(g(this.el,"dragstart",this._onDragStart),g(this.el,"dragover",Z),g(this.el,"dragend",this._onDrop))},_unbindMoveEvents:function(){g(this.ownerDocument,"pointermove",this._onMove),g(this.ownerDocument,"touchmove",this._onMove),g(this.ownerDocument,"mousemove",this._onMove),g(this.ownerDocument,"pointermove",S),g(this.ownerDocument,"touchmove",S),g(this.ownerDocument,"mousemove",S),g(this.ownerDocument,"dragover",S)},_unbindDropEvents:function(){g(this.ownerDocument,"pointerup",this._onDrop),g(this.ownerDocument,"pointercancel",this._onDrop),g(this.ownerDocument,"touchend",this._onDrop),g(this.ownerDocument,"touchcancel",this._onDrop),g(this.ownerDocument,"mouseup",this._onDrop)}}).utils={getRect:w,getOffset:v,debounce:z,throttle:V},L}); |
{ | ||
"name": "sortable-dnd", | ||
"version": "0.3.4", | ||
"version": "0.3.5", | ||
"description": "JS library for drag-and-drop lists, supports sortable and draggable", | ||
@@ -5,0 +5,0 @@ "main": "dist/sortable.js", |
@@ -17,6 +17,11 @@ import { getRect, setTransition, setTransform } from './utils.js' | ||
const children = [...Array.from(this.el.children)] | ||
const { start, end } = getRange(children, dragEl, dropEl) | ||
let { start, end } = getRange(children, dragEl, dropEl) | ||
animationState.length = 0 // reset | ||
if (start < 0) { | ||
start = end | ||
end = Math.min(children.length - 1, 100) | ||
} | ||
children.slice(start, end + 1).forEach(child => { | ||
@@ -23,0 +28,0 @@ animationState.push({ |
@@ -74,3 +74,3 @@ import { | ||
if (!originalGroup || typeof originalGroup != 'object') { | ||
originalGroup = { name: originalGroup } | ||
originalGroup = { name: originalGroup, pull: true, put: true } | ||
} | ||
@@ -95,3 +95,2 @@ | ||
if (nearest) { | ||
if (evt.dataTransfer) evt.dataTransfer.dropEffect = 'move' | ||
// Create imitation event | ||
@@ -149,2 +148,9 @@ let event = {} | ||
const _globalDragOver = function(evt) { | ||
if (evt.dataTransfer) { | ||
evt.dataTransfer.dropEffect = 'move' | ||
} | ||
evt.cancelable && evt.preventDefault() | ||
} | ||
/** | ||
@@ -368,8 +374,6 @@ * @class Sortable | ||
_triggerEvent(evt) { | ||
if (activeGroup.name !== this.options.group.name) return | ||
rootEl = evt.rootEl | ||
if (this.nativeDraggable) { | ||
on(this.el, 'dragover', this._onDragOver) | ||
on(this.el, 'dragover', _globalDragOver) | ||
on(this.el, 'dragend', this._onDrop) | ||
@@ -394,3 +398,3 @@ this._onDragOver(evt) | ||
// check if element will exchange | ||
if (this.options.group.put || fromGroup === this.el) this._onChange(target, e, evt) | ||
if (this._allowPut()) this._onChange(target, e, evt) | ||
// auto scroll | ||
@@ -408,3 +412,5 @@ clearTimeout(this.autoScrollTimer) | ||
if (evt.dataTransfer) evt.dataTransfer.dropEffect = 'move' | ||
const allowPut = this._allowPut() | ||
if (evt.dataTransfer) evt.dataTransfer.dropEffect = allowPut ? 'move' : 'none' | ||
// truly started | ||
@@ -417,6 +423,17 @@ this._onStarted(evt, evt) | ||
if (this.options.group.put || fromGroup === this.el) this._onChange(evt.target, evt, evt) | ||
if (allowPut) this._onChange(evt.target, evt, evt) | ||
} | ||
}, | ||
_allowPut: function() { | ||
if (fromGroup === this.el) { | ||
return true | ||
} else if (!this.options.group.put) { | ||
return false | ||
} else { | ||
const { name } = this.options.group | ||
return activeGroup.name && name && activeGroup.name === name | ||
} | ||
}, | ||
// -------------------------------- real started ---------------------------------- | ||
@@ -493,4 +510,6 @@ _onStarted: function(e, /** originalEvent */evt) { | ||
if (!dragEl) return | ||
if (!lastChild(this.el)) { | ||
differ.to = { sortable: this, group: this.el, node: dragEl, rect: getRect(dragEl), offset: getOffset(dragEl) } | ||
if (!lastChild(rootEl) || (target === rootEl && differ.from.group !== rootEl)) { | ||
differ.from.sortable._captureAnimationState(dragEl, dragEl) | ||
differ.to = { sortable: this, group: rootEl, node: dragEl, rect: getRect(dragEl), offset: getOffset(dragEl) } | ||
// onRemove callback | ||
@@ -501,6 +520,7 @@ differ.from.sortable._dispatchEvent('onRemove', { ...differ, event: e, originalEvent: evt }) | ||
this.el.appendChild(dragEl) | ||
rootEl.appendChild(dragEl) | ||
differ.from.sortable._rangeAnimate() | ||
differ.from.sortable = this | ||
differ.from.group = this.el | ||
differ.from.group = rootEl | ||
} else { | ||
@@ -511,3 +531,3 @@ const { el, rect, offset } = getElement(rootEl, target) | ||
dropEl = el | ||
differ.to = { sortable: this, group: this.el, node: dropEl, rect, offset } | ||
differ.to = { sortable: this, group: rootEl, node: dropEl, rect, offset } | ||
@@ -522,2 +542,3 @@ const { clientX, clientY } = e | ||
if (differ.from.group !== differ.to.group) { | ||
differ.from.sortable._captureAnimationState(dragEl, dropEl) | ||
// onRemove callback | ||
@@ -528,6 +549,4 @@ differ.from.sortable._dispatchEvent('onRemove', { ...differ, event: e, originalEvent: evt }) | ||
this.el.insertBefore(dragEl, dropEl) | ||
differ.from.sortable = this | ||
differ.from.group = this.el | ||
rootEl.insertBefore(dragEl, dropEl) | ||
differ.from.sortable._rangeAnimate() | ||
} else { | ||
@@ -540,11 +559,10 @@ // onChange callback | ||
if (_offset.top < offset.top || _offset.left < offset.left) { | ||
this.el.insertBefore(dragEl, dropEl.nextSibling) | ||
rootEl.insertBefore(dragEl, dropEl.nextSibling) | ||
} else { | ||
this.el.insertBefore(dragEl, dropEl) | ||
rootEl.insertBefore(dragEl, dropEl) | ||
} | ||
differ.from.sortable = this | ||
differ.from.group = this.el | ||
} | ||
differ.from.sortable = this | ||
differ.from.group = rootEl | ||
this._rangeAnimate() | ||
@@ -617,3 +635,3 @@ } | ||
off(this.el, 'dragstart', this._onDragStart) | ||
off(this.el, 'dragover', this._onDragOver) | ||
off(this.el, 'dragover', _globalDragOver) | ||
off(this.el, 'dragend', this._onDrop) | ||
@@ -620,0 +638,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
111223
2359