sortable-dnd
Advanced tools
Comparing version 0.6.6 to 0.6.7
/*! | ||
* sortable-dnd v0.6.6 | ||
* sortable-dnd v0.6.7 | ||
* open source under the MIT license | ||
@@ -686,5 +686,4 @@ * https://github.com/mfuu/sortable-dnd#readme | ||
var sortables = []; | ||
var fromEl, dragEl, dropEl, nextEl, cloneEl, ghostEl, parentEl, dragEvent, moveEvent, lastDropEl, listenerNode, lastHoverArea, dragStartTimer, useSelectHandle; | ||
var to, from, pullMode, oldIndex, newIndex, fromIndex, targetNode; | ||
var _prepareGroup = function _prepareGroup(options) { | ||
var to, from, fromEl, dragEl, dropEl, nextEl, cloneEl, ghostEl, targetEl, parentEl, pullMode, oldIndex, newIndex, fromIndex, dragEvent, moveEvent, lastDropEl, cloneEvent, cloneTarget, listenerNode, lastHoverArea, dragStartTimer, useSelectHandle; | ||
function _prepareGroup(options) { | ||
var group = {}; | ||
@@ -705,3 +704,3 @@ var originalGroup = options.group; | ||
options.group = group; | ||
}; | ||
} | ||
@@ -734,3 +733,3 @@ /** | ||
* @param {HTMLElement} el container | ||
* @param {Object} options | ||
* @param {Object} options sortable options | ||
*/ | ||
@@ -746,12 +745,13 @@ function Sortable(el, options) { | ||
store: null, | ||
group: '', | ||
handle: null, | ||
sortable: true, | ||
disabled: false, | ||
group: '', | ||
multiple: false, | ||
lockAxis: '', | ||
direction: '', | ||
animation: 150, | ||
draggable: null, | ||
handle: null, | ||
multiple: false, | ||
selectHandle: null, | ||
customGhost: null, | ||
direction: '', | ||
autoScroll: true, | ||
@@ -818,3 +818,3 @@ scrollThreshold: 55, | ||
dragEvent = { | ||
original: event, | ||
origin: event, | ||
clientX: (touch || event).clientX, | ||
@@ -880,6 +880,13 @@ clientY: (touch || event).clientY | ||
from = this.el; | ||
targetEl = dragEl; | ||
oldIndex = i; | ||
newIndex = i; | ||
fromIndex = i; | ||
targetNode = dragEl; | ||
cloneEvent = { | ||
to: this.el, | ||
target: dragEl, | ||
newIndex: i, | ||
relative: 0 | ||
}; | ||
cloneTarget = dragEl; | ||
fromEl = this.el; | ||
@@ -920,3 +927,3 @@ cloneEl = dragEl.cloneNode(true); | ||
name: 'onDrag', | ||
params: this._getParams(dragEvent.original) | ||
params: this._getParams(dragEvent.origin) | ||
}); | ||
@@ -930,4 +937,4 @@ css(dragEl, 'display', 'none'); | ||
if (typeof customGhost === 'function') { | ||
var selectedElements = this.multiplayer.selectedElements; | ||
return customGhost(selectedElements.length ? selectedElements : [dragEl]); | ||
var selects = this.multiplayer.selectedElements; | ||
return customGhost(selects.length ? selects : [dragEl]); | ||
} | ||
@@ -985,3 +992,3 @@ return this.multiplayer.getGhostElement() || dragEl; | ||
moveEvent = { | ||
original: event, | ||
origin: event, | ||
clientX: clientX, | ||
@@ -1015,3 +1022,3 @@ clientY: clientY | ||
direction = _this$options3.direction; | ||
return direction ? typeof direction === 'function' ? direction.call(moveEvent.original, dragEl, this) : direction : detectDirection(parentEl, draggable); | ||
return direction ? typeof direction === 'function' ? direction.call(moveEvent.origin, dragEl, this) : direction : detectDirection(parentEl, draggable); | ||
}, | ||
@@ -1056,3 +1063,3 @@ _allowSwap: function _allowSwap() { | ||
_onMove: function _onMove( /** TouchEvent|MouseEvent */event, target) { | ||
if (!this._allowPut()) return; | ||
if (!this.options.sortable || !this._allowPut()) return; | ||
dispatchEvent({ | ||
@@ -1089,3 +1096,3 @@ sortable: this, | ||
oldIndex = index(cloneEl); | ||
targetNode = target; | ||
targetEl = target; | ||
parentEl = dropEl ? dropEl.parentNode : this.el; | ||
@@ -1097,2 +1104,5 @@ from[expando].animator.collect(cloneEl.parentNode); | ||
if (cloneTo) { | ||
cloneEvent.target = cloneTarget; | ||
cloneEvent.newIndex = oldIndex; | ||
cloneEvent.relative = cloneTarget === dragEl ? 0 : sort(cloneEl, cloneTarget); | ||
css(dragEl, 'display', ''); | ||
@@ -1118,2 +1128,5 @@ fromEl[expando].multiplayer.toggleVisible(true); | ||
if (cloneTo && fromEl[expando].options.group.revertDrag) { | ||
cloneEvent.target = dragEl; | ||
cloneEvent.newIndex = fromIndex; | ||
cloneEvent.relative = 0; | ||
dispatchEvent({ | ||
@@ -1138,2 +1151,3 @@ sortable: fromEl[expando], | ||
if (cloneBack && dropEl !== dragEl) { | ||
cloneTarget = dropEl; | ||
dispatchEvent({ | ||
@@ -1160,5 +1174,8 @@ sortable: this, | ||
_onChange: function _onChange(event) { | ||
oldIndex = index(cloneEl); | ||
parentEl = dropEl.parentNode; | ||
oldIndex = index(cloneEl); | ||
targetNode = dropEl; | ||
targetEl = dropEl; | ||
if (this.el === fromEl) { | ||
cloneTarget = dropEl; | ||
} | ||
this.animator.collect(parentEl); | ||
@@ -1187,4 +1204,4 @@ parentEl.insertBefore(cloneEl, nextEl); | ||
oldIndex = fromIndex; | ||
if (targetNode === cloneEl) { | ||
targetNode = dragEl; | ||
if (targetEl === cloneEl) { | ||
targetEl = dragEl; | ||
} | ||
@@ -1203,9 +1220,5 @@ this.multiplayer.toggleClass(false); | ||
if (multiple && (selectHandle && useSelectHandle || !selectHandle && !fromEl)) { | ||
var evt = event.changedTouches ? event.changedTouches[0] : event, | ||
dx = evt.clientX - dragEvent.clientX, | ||
dy = evt.clientY - dragEvent.clientY, | ||
dd = Math.sqrt(dx * dx + dy * dy); | ||
var evt = event.changedTouches ? event.changedTouches[0] : event; | ||
// check whether the event is a click event | ||
dd >= 0 && dd <= 1 && this.multiplayer.onSelect(event, dragEl, this); | ||
!_positionChanged(evt) && this.multiplayer.onSelect(event, dragEl, this); | ||
} | ||
@@ -1237,3 +1250,3 @@ if (ghostEl && ghostEl.parentNode) { | ||
name: 'onDrop', | ||
params: params | ||
params: pullMode === 'clone' ? _extends({}, params, cloneEvent) : params | ||
}); | ||
@@ -1255,3 +1268,3 @@ } | ||
evt.clone = cloneEl; | ||
evt.target = targetNode; | ||
evt.target = targetEl; | ||
evt.oldIndex = oldIndex; | ||
@@ -1262,7 +1275,7 @@ evt.newIndex = newIndex; | ||
_extends(evt, params); | ||
evt.relative = evt.target === dragEl ? 0 : sort(evt.target, cloneEl); | ||
evt.relative = targetEl === dragEl ? 0 : sort(cloneEl, targetEl); | ||
return evt; | ||
}, | ||
_nulling: function _nulling() { | ||
to = from = fromEl = dragEl = dropEl = nextEl = cloneEl = ghostEl = parentEl = pullMode = oldIndex = newIndex = fromIndex = dragEvent = moveEvent = targetNode = lastDropEl = listenerNode = lastHoverArea = dragStartTimer = useSelectHandle = Sortable.clone = Sortable.ghost = Sortable.active = Sortable.dragged = null; | ||
to = from = fromEl = dragEl = dropEl = nextEl = cloneEl = ghostEl = targetEl = parentEl = pullMode = oldIndex = newIndex = fromIndex = dragEvent = moveEvent = lastDropEl = cloneEvent = cloneTarget = listenerNode = lastHoverArea = dragStartTimer = useSelectHandle = Sortable.clone = Sortable.ghost = Sortable.active = Sortable.dragged = null; | ||
}, | ||
@@ -1269,0 +1282,0 @@ // ========================================= Public Methods ========================================= |
/*! | ||
* sortable-dnd v0.6.6 | ||
* sortable-dnd v0.6.7 | ||
* open source under the MIT license | ||
* https://github.com/mfuu/sortable-dnd#readme | ||
*/ | ||
!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 t(e){return t="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(e)}function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},e.apply(this,arguments)}var n={capture:!1,passive:!1},o=/\s+/g;function i(t){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(t)}var r=i(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),s=i(/Edge/i),a=i(/safari/i)&&!i(/chrome/i)&&!i(/android/i),l=function(){var t=!1;return document.addEventListener("checkIfSupportPassive",null,{get passive(){return t=!0,!0}}),t}(),c=function(){if("undefined"==typeof window||"undefined"==typeof document)return{};var t=window.getComputedStyle(document.documentElement,"")||["-moz-hidden-iframe"],e=(Array.prototype.slice.call(t).join("").match(/-(moz|webkit|ms)-/)||""===t.OLink&&["","o"])[1];return{dom:"WebKit|Moz|MS|O".match(new RegExp("("+e+")","i"))[1],lowercase:e,css:"-"+e+"-",js:e[0].toUpperCase()+e.substr(1)}}();function h(t,e){t.style["".concat(c.css,"transition-duration")]=e?"".concat(e,"ms"):""}function u(t,e){t.style["".concat(c.css,"transform")]=e?"".concat(e):""}function d(t,e,o){window.addEventListener?t.addEventListener(e,o,!(!l&&r)&&n):window.attachEvent?t.attachEvent("on"+e,o):t["on"+e]=o}function p(t,e,o){window.removeEventListener?t.removeEventListener(e,o,!(!l&&r)&&n):window.detachEvent?t.detachEvent("on"+e,o):t["on"+e]=null}function m(){return document.scrollingElement||document.documentElement}function f(t,e,n){if(t.getBoundingClientRect||t===window){var o,i,r,s,a,l,c;if(t!==window&&t.parentNode&&t!==m()?(i=(o=t.getBoundingClientRect()).top,r=o.left,s=o.bottom,a=o.right,l=o.height,c=o.width):(i=0,r=0,s=window.innerHeight,a=window.innerWidth,l=window.innerHeight,c=window.innerWidth),e&&t!==window){n=n||t.parentNode;do{if(n&&n.getBoundingClientRect){var h=n.getBoundingClientRect();i-=h.top+parseInt(E(n,"border-top-width")),r-=h.left+parseInt(E(n,"border-left-width")),s=i+o.height,a=r+o.width;break}}while(n=n.parentNode)}return{top:i,left:r,bottom:s,right:a,width:c,height:l}}}function g(t,e,n,o){if(!t)return null;if(n&&!e){var i=Array.prototype.slice.call(n.children),r=i.indexOf(t);if(r>-1)return i[r];for(var s=0;s<i.length;s++)if(v(t,i[s]))return i[s]}n=n||document;do{if(null!=e&&(">"===e[0]?t.parentNode===n&&x(t,e):x(t,e))||o&&t===n)return t;if(t===n)break}while(t=t.parentNode);return null}function v(t,e){if(!t||!e)return!1;if(e.compareDocumentPosition)return!!(16&e.compareDocumentPosition(t));if(e.contains&&1===t.nodeType)return e.contains(t)&&e!==t;for(;t=t.parentNode;)if(t===e)return!0;return!1}function y(t,e){for(var n=t.lastElementChild;n&&(n===ot.ghost||"none"===E(n,"display")||e&&!x(n,e));)n=n.previousElementSibling;return n||null}function w(t,e){if(!t||!t.parentNode)return-1;for(var n=0;t=t.previousElementSibling;)"TEMPLATE"===t.nodeName.toUpperCase()||e&&!x(t,e)||"none"===E(t,"display")||n++;return n}function b(t,e,n,o){for(var i=0,r=0,s=t.children;i<s.length;){if(s[i]!==ot.ghost&&"none"!==E(s[i],"display")&&g(s[i],n,t,!1)&&(o||s[i]!==ot.dragged)){if(r===e)return s[i];r++}i++}return null}function _(t,e){var n=E(t),o=parseInt(n.width)-parseInt(n.paddingLeft)-parseInt(n.paddingRight)-parseInt(n.borderLeftWidth)-parseInt(n.borderRightWidth),i=b(t,0,e),a=b(t,1,e),l=i&&E(i),c=a&&E(a),h=l&&parseInt(l.marginLeft)+parseInt(l.marginRight)+f(i).width,u=c&&parseInt(c.marginLeft)+parseInt(c.marginRight)+f(a).width,d=s||r?"cssFloat":"float";if("flex"===n.display)return"column"===n.flexDirection||"column-reverse"===n.flexDirection?"vertical":"horizontal";if("grid"===n.display)return n.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(i&&l.float&&"none"!==l.float){var p="left"===l.float?"left":"right";return!a||"both"!==c.clear&&c.clear!==p?"horizontal":"vertical"}return i&&("block"===l.display||"flex"===l.display||"table"===l.display||"grid"===l.display||h>=o&&"none"===n[d]||a&&"none"===n[d]&&h+u>o)?"vertical":"horizontal"}function S(t,e,n){if(t&&e)if(t.classList)t.classList[n?"add":"remove"](e);else{var i=(" "+t.className+" ").replace(o," ").replace(" "+e+" "," ");t.className=(i+(n?" "+e:"")).replace(o," ")}}function x(t,e){if(e){if(">"===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!1}return!1}}function E(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];e in o||-1!==e.indexOf("webkit")||(e="-webkit-"+e),o[e]=n+("string"==typeof n?"":"px")}}function D(t,e){var n,o,i=(o=e,(n=t).compareDocumentPosition?n.compareDocumentPosition(o):n.contains?(n!=o&&n.contains(o)&&16)+(n!=o&&o.contains(n)&&8)+(n.sourceIndex>=0&&o.sourceIndex>=0?(n.sourceIndex<o.sourceIndex&&4)+(n.sourceIndex>o.sourceIndex&&2):1):0);return 2===i?1:4===i?-1:0}function C(t){void 0!==t.preventDefault&&t.cancelable&&t.preventDefault()}function M(t){var n=t.sortable,o=t.name,i=t.params,r=n.options[o];"function"==typeof r&&r(e({},i))}var T,N,I="Sortable"+Date.now();function P(t){this.options=t,this.autoScrollAnimationFrame=null}function O(t){this.options=t,this.animations=[]}function A(t){this.options=t||{},this.selectedElements=[]}window.requestAnimationFrame||(window.requestAnimationFrame=function(t){return setTimeout(t,17)}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)}),P.prototype={destroy:function(){this.autoScrollAnimationFrame&&(cancelAnimationFrame(this.autoScrollAnimationFrame),this.autoScrollAnimationFrame=null)},update:function(t,e,n){var o=this;cancelAnimationFrame(this.autoScrollAnimationFrame),this.autoScrollAnimationFrame=requestAnimationFrame((function(){e&&n&&o.autoScroll(t,n),o.update(t,e,n)}))},autoScroll:function(t,e){if(t&&void 0!==e.clientX&&void 0!==e.clientY){var n=f(t);if(n){var o=e.clientX,i=e.clientY,r=n.top,s=n.right,a=n.bottom,l=n.left,c=n.height,h=n.width;if(!(i<r||o>s||i>a||o<l)){var u=this.options,d=u.scrollThreshold,p=u.scrollSpeed,m=t.scrollTop,g=t.scrollLeft,v=t.scrollHeight,y=m>0&&i>=r&&i<=r+d,w=g+h<t.scrollWidth&&o<=s&&o>=s-d,b=m+c<v&&i<=a&&i>=a-d,_=0,S=0;g>0&&o>=l&&o<=l+d&&(_=Math.floor(Math.max(-1,(o-l)/d-1)*p.x)),w&&(_=Math.ceil(Math.min(1,(o-s)/d+1)*p.x)),y&&(S=Math.floor(Math.max(-1,(i-r)/d-1)*p.y)),b&&(S=Math.ceil(Math.min(1,(i-a)/d+1)*p.y)),t.scrollTop+=S,t.scrollLeft+=_}}}}},O.prototype={collect:function(t){if(t){for(var e=f(t),n=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,o=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,i=Math.min(e.right,n),r=Math.min(e.bottom,o),s=Array.prototype.slice.call(t.children),a=[],l=0;l<=s.length;l++){var c=s[l];if(c&&c!==ot.ghost&&"none"!==E(c,"display")){var h=f(c);if(!(h.bottom<0||h.right<0)){if(h.top-h.height>r||h.left-h.width>i)break;a.push({node:c,rect:h})}}}this.animations.push(a)}},animate:function(){for(var t=this.animations.pop(),e=0,n=t.length;e<n;e++){var o=t[e],i=o.node,r=o.rect;this._excute(i,r)}},_excute:function(t,e){var n=e.left,o=e.top,i=f(t);if(i.top!==o||i.left!==n){var r=o-i.top,s=n-i.left;h(t),u(t,"translate3d(".concat(s,"px, ").concat(r,"px, 0)")),t.offsetWidth,h(t,this.options.animation),u(t,"translate3d(0px, 0px, 0px)"),clearTimeout(t.animated),t.animated=setTimeout((function(){h(t),u(t,""),t.animated=null}),this.options.animation)}}},A.prototype={destroy:function(){T=N=null},active:function(){return!!T},setParams:function(t){t.nodes=T||[],t.clones=N||[]},select:function(t){S(t,this.options.selectedClass,!0),this.selectedElements.push(t),this.selectedElements.sort((function(t,e){return D(t,e)}))},deselect:function(t){var e=this.selectedElements.indexOf(t);e>-1&&(S(t,this.options.selectedClass,!1),this.selectedElements.splice(e,1))},getGhostElement:function(){if(!T)return null;var t=document.createElement("div");return this.selectedElements.forEach((function(e,n){var o=e.cloneNode(!0),i=0===n?1:.5;o.style="position: absolute;left: 0;top: 0;bottom: 0;right: 0;opacity: ".concat(i,";z-index: ").concat(n,";"),t.appendChild(o)})),t},toggleSelected:function(t,e){var n=this;e?t.forEach((function(t){return n.selectedElements.push(t)})):this.selectedElements=this.selectedElements.filter((function(e){return t.indexOf(e)<0}))},toggleClass:function(t){if(T)for(var e=0;e<T.length;e++)S(T[e],this.options.chosenClass,t)},toggleVisible:function(t){if(T)if(t){var e=T.indexOf(ot.dragged);this._viewElements(T,e,ot.dragged)}else this._hideElements(T)},onChoose:function(){!this.options.multiple||!this.selectedElements.length||this.selectedElements.indexOf(ot.dragged)<0||(this.selectedElements.sort((function(t,e){return D(t,e)})),T=this.selectedElements,this.toggleClass(!0))},onDrag:function(t){T&&(t.animator.collect(ot.dragged.parentNode),this._hideElements(T),t.animator.animate(),this.toggleClass(!1))},onDrop:function(t,e,n){if(T){var o=ot.dragged,i=ot.clone,r=T.indexOf(o);e[I].animator.collect(i.parentNode),t!==e&&"clone"===n?(E(i,"display","none"),N=T.map((function(t){return t.cloneNode(!0)})),this._viewElements(N,r,i),this._viewElements(T,r,o)):this._viewElements(T,r,i),e[I].animator.animate(),t!==e&&(e[I].multiplayer.toggleSelected(N||T,!0),"clone"!==n&&t[I].multiplayer.toggleSelected(T,!1))}},onSelect:function(t,e,n){var o=this.selectedElements.indexOf(e);S(e,this.options.selectedClass,o<0);var i={from:n.el,event:t,node:e,index:w(e)};o<0?(this.selectedElements.push(e),M({sortable:n,name:"onSelect",params:i})):(this.selectedElements.splice(o,1),M({sortable:n,name:"onDeselect",params:i})),this.selectedElements.sort((function(t,e){return D(t,e)}))},_viewElements:function(t,e,n){for(var o=0;o<t.length;o++)if(E(t[o],"display",""),o<e)n.parentNode.insertBefore(t[o],n);else{var i=o>0?t[o-1]:n;n.parentNode.insertBefore(t[o],i.nextSibling)}},_hideElements:function(t){for(var e=0;e<t.length;e++)t[e]!=ot.dragged&&E(t[e],"display","none")}};var H,X,Y,L,W,k,R,B,F,z,j,G,V,q,U,K,Z,J,Q,$,tt,et=[],nt=function(e){var n={},o=e.group;o&&"object"==t(o)||(o={name:o,pull:!0,put:!0,revertDrag:!0}),n.name=o.name,n.pull=o.pull,n.put=o.put,n.revertDrag=o.revertDrag,e.group=n};function ot(t,n){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable-dnd: `el` must be an HTMLElement, not ".concat({}.toString.call(t));t[I]=this,this.el=t,this.options=n=e({},n);var o={store:null,disabled:!1,group:"",lockAxis:"",animation:150,draggable:null,handle:null,multiple:!1,selectHandle:null,customGhost:null,direction:"",autoScroll:!0,scrollThreshold:55,scrollSpeed:{x:10,y:10},delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,ghostClass:"",ghostStyle:{},chosenClass:"",selectedClass:"",swapOnDrop:!0,fallbackOnBody:!1,supportTouch:"ontouchstart"in window,emptyInsertThreshold:-5};for(var i in o)!(i in this.options)&&(this.options[i]=o[i]);for(var r in nt(n),this)"_"===r.charAt(0)&&"function"==typeof this[r]&&(this[r]=this[r].bind(this));d(t,this.options.supportTouch?"touchstart":"mousedown",this._onDrag),et.push(t),this.autoScroller=new P(this.options),this.multiplayer=new A(this.options),this.animator=new O(this.options)}return ot.prototype={constructor:ot,_onDrag:function(t){var e=this;if(!X&&!this.options.disabled&&this.options.group.pull&&(!/mousedown|pointerdown/.test(t.type)||0===t.button)){var n=t.touches&&t.touches[0],o=(n||t).target;if(!a||!o||"SELECT"!==o.tagName.toUpperCase()){var i=g(o,this.options.draggable,this.el);if(i&&!i.animated){B={original:t,clientX:(n||t).clientX,clientY:(n||t).clientY},X=i,d(j=n?X:document,"mouseup",this._onDrop),d(j,"touchend",this._onDrop),d(j,"touchcancel",this._onDrop);var l=this.options,c=l.handle,h=l.selectHandle;if("function"==typeof h&&h(t)||"string"==typeof h&&x(o,h))q=!0;else if(("function"!=typeof c||c(t))&&("string"!=typeof c||x(o,c))){var u=this.options,p=u.delay,m=u.delayOnTouchOnly;!p||m&&!n||s||r?this._onStart(n,t):(d(this.el.ownerDocument,"touchmove",this._delayMoveHandler),d(this.el.ownerDocument,"mousemove",this._delayMoveHandler),d(this.el.ownerDocument,"mouseup",this._cancelStart),d(this.el.ownerDocument,"touchend",this._cancelStart),d(this.el.ownerDocument,"touchcancel",this._cancelStart),V=setTimeout((function(){return e._onStart(n,t)}),p)),d(document,"selectstart",C),a&&E(document.body,"user-select","none")}}}}},_delayMoveHandler:function(t){var e=t.touches?t.touches[0]:t;Math.max(Math.abs(e.clientX-B.clientX),Math.abs(e.clientY-B.clientY))>=Math.floor(this.options.touchStartThreshold/(window.devicePixelRatio||1))&&this._cancelStart()},_cancelStart:function(){clearTimeout(V),p(this.el.ownerDocument,"touchmove",this._delayMoveHandler),p(this.el.ownerDocument,"mousemove",this._delayMoveHandler),p(this.el.ownerDocument,"mouseup",this._cancelStart),p(this.el.ownerDocument,"touchend",this._cancelStart),p(this.el.ownerDocument,"touchcancel",this._cancelStart),p(document,"selectstart",C),a&&E(document.body,"user-select","")},_onStart:function(t,e){var n=w(X);U=this.el,K=this.el,J=n,Q=n,$=n,tt=X,H=this.el,W=X.cloneNode(!0),R=X.parentNode,Z=this.options.group.pull,ot.clone=W,ot.active=this,ot.dragged=X,S(X,this.options.chosenClass,!0),this.multiplayer.onChoose(),M({sortable:this,name:"onChoose",params:this._getParams(e)}),d(j,t?"touchmove":"mousemove",this._nearestSortable);try{document.selection?setTimeout((function(){return document.selection.empty()}),0):window.getSelection().removeAllRanges()}catch(t){}},_onStarted:function(){S(W,this.options.chosenClass,!0),this._appendGhost(),this.multiplayer.onDrag(this),M({sortable:this,name:"onDrag",params:this._getParams(B.original)}),E(X,"display","none"),S(X,this.options.chosenClass,!1),X.parentNode.insertBefore(W,X)},_getGhostElement:function(){var t=this.options.customGhost;if("function"==typeof t){var e=this.multiplayer.selectedElements;return t(e.length?e:[X])}return this.multiplayer.getGhostElement()||X},_appendGhost:function(){if(!k){var t=this.options.fallbackOnBody?document.body:this.el,n=this._getGhostElement();S(k=n.cloneNode(!0),this.options.ghostClass,!0);var o,i=f(X),r=e({position:"fixed",top:i.top,left:i.left,width:i.width,height:i.height,minWidth:i.width,minHeight:i.height,opacity:"0.8",overflow:"hidden","z-index":"100000","box-sizing":"border-box","pointer-events":"none"},this.options.ghostStyle);for(var s in r)E(k,s,r[s]);o="none",k.style["".concat(c.css,"transition")]=o?"none"===o?"none":"".concat(o):"",u(k,"translate3d(0px, 0px, 0px)"),ot.ghost=k,t.appendChild(k);var a=(B.clientX-i.left)/parseInt(k.style.width)*100,l=(B.clientY-i.top)/parseInt(k.style.height)*100;E(k,"transform-origin","".concat(a,"% ").concat(l,"%")),E(k,"transform","translateZ(0)"),E(k,"will-change","transform")}},_nearestSortable:function(t){C(t);var e=t.touches&&t.touches[0]||t;if(X&&function(t){var e=F||B;return!(void 0!==t.clientX&&void 0!==t.clientY&&Math.abs(t.clientX-e.clientX)<=0&&Math.abs(t.clientY-e.clientY)<=0)}(e)){!F&&this._onStarted();var n=this.options.lockAxis,o="x"===n?B.clientX:e.clientX,i="y"===n?B.clientY:e.clientY,r=document.elementFromPoint(o,i),s=o-B.clientX,a=i-B.clientY;if(F={original:t,clientX:o,clientY:i},u(k,"translate3d(".concat(s,"px, ").concat(a,"px, 0)")),this.options.autoScroll){var l=function(t,e){if(!t||!t.getBoundingClientRect)return m();var n=t,o=!1;do{if(n.clientWidth<n.scrollWidth||n.clientHeight<n.scrollHeight){var i=E(n);if(n.clientWidth<n.scrollWidth&&("auto"==i.overflowX||"scroll"==i.overflowX)||n.clientHeight<n.scrollHeight&&("auto"==i.overflowY||"scroll"==i.overflowY)){if(!n.getBoundingClientRect||n===document.body)return m();if(o||e)return n;o=!0}}}while(n=n.parentNode);return m()}(r,!0);this.autoScroller.update(l,B,F)}var c,h,d,p=(c=o,h=i,et.some((function(t){var e=t[I].options.emptyInsertThreshold;if(null!=e){var n=f(t),o=c>=n.left-e&&c<=n.right+e,i=h>=n.top-e&&h<=n.bottom+e;return o&&i?d=t:void 0}})),d);p&&p[I]._onMove(t,r)}},_allowPut:function(){if(H===this.el)return!0;if(this.options.group.put){var t=this.options.group,e=t.name,n=t.put,o=H[I].options.group;return n.join&&n.indexOf(o.name)>-1||o.name&&e&&o.name===e}return!1},_getDirection:function(){var t=this.options,e=t.draggable,n=t.direction;return n?"function"==typeof n?n.call(F.original,X,this):n:_(R,e)},_allowSwap:function(){var t=f(Y),e="vertical"===this._getDirection(),n=e?"top":"left",o=e?"bottom":"right",i=Y[e?"offsetHeight":"offsetWidth"],r=e?F.clientY:F.clientX,s=r>=t[n]&&r<t[o]-i/2?-1:1,a=b(R,0,this.options.draggable),l=y(R),c=f(a),h=f(l);if(Y===R||v(R,Y))return W===a&&r<c[n]?(L=Y,!0):W===l&&r>h[o]&&(L=Y.nextSibling,!0);var u=D(W,Y);return L=u<0?Y.nextSibling:Y,z!==Y?(G=s,!0):G!==s&&(G=s,s<0?u>0:u<0)},_onMove:function(t,e){if(this._allowPut()){if(M({sortable:this,name:"onMove",params:this._getParams(t)}),this.el!==K&&(e===this.el||!y(this.el)))return Y=z=null,void this._onInsert(t);(Y=g(e,this.options.draggable,this.el))&&!Y.animated&&this._allowSwap()&&(Y!==W&&L!==W?(this.el!==K?this._onInsert(t):Y!==X&&this._onChange(t),z=Y):z=Y)}},_onInsert:function(t){var e=Y||W,n="clone"===Z&&this.el!==H&&K===H,o="clone"===Z&&this.el===H&&K!==H;U=this.el,J=w(W),tt=e,R=Y?Y.parentNode:this.el,K[I].animator.collect(W.parentNode),this.animator.collect(R),n&&(E(X,"display",""),H[I].multiplayer.toggleVisible(!0),H[I].options.group.revertDrag||K.insertBefore(X,W)),o&&(J=w(X),E(X,"display","none"),this.multiplayer.toggleVisible(!1)),Y?R.insertBefore(W,G<0?Y:Y.nextSibling):R.appendChild(W),Q=w(W),n&&H[I].options.group.revertDrag&&M({sortable:H[I],name:"onChange",params:this._getParams(t,{to:H,target:X,newIndex:$,revertDrag:!0})}),n||M({sortable:K[I],name:"onRemove",params:this._getParams(t)}),o&&Y!==X&&M({sortable:this,name:"onChange",params:this._getParams(t,{from:H,backToOrigin:!0})}),o||M({sortable:this,name:"onAdd",params:this._getParams(t)}),K[I].animator.animate(),this.animator.animate(),K=this.el},_onChange:function(t){R=Y.parentNode,J=w(W),tt=Y,this.animator.collect(R),R.insertBefore(W,L),Q=w(W),M({sortable:this,name:"onChange",params:this._getParams(t)}),this.animator.animate(),K=this.el},_onDrop:function(t){C(t),this._cancelStart(),p(j,"touchmove",this._nearestSortable),p(j,"mousemove",this._nearestSortable),p(j,"mouseup",this._onDrop),p(j,"touchend",this._onDrop),p(j,"touchcancel",this._onDrop),S(X,this.options.chosenClass,!1),H&&(K=H,J=$,tt===W&&(tt=X),this.multiplayer.toggleClass(!1),M({sortable:this,name:"onUnchoose",params:this._getParams(t)}),F&&this._onEnd(t));var e=this.options,n=e.multiple,o=e.selectHandle;if(n&&(o&&q||!o&&!H)){var i=t.changedTouches?t.changedTouches[0]:t,r=i.clientX-B.clientX,s=i.clientY-B.clientY,a=Math.sqrt(r*r+s*s);a>=0&&a<=1&&this.multiplayer.onSelect(t,X,this)}k&&k.parentNode&&k.parentNode.removeChild(k),this.multiplayer.destroy(),this.autoScroller.destroy(),this._nulling()},_onEnd:function(t){var e=this._getParams(t);this.multiplayer.onDrop(K,U,Z);var n=this.options.swapOnDrop;"clone"===Z&&K!==U||!("function"==typeof n?n(e):n)||R.insertBefore(X,W),"clone"!==Z||K===U||this.multiplayer.active()?W&&W.parentNode&&W.parentNode.removeChild(W):S(W,this.options.chosenClass,!1),E(X,"display",""),K!==U&&M({sortable:K[I],name:"onDrop",params:e}),M({sortable:U[I],name:"onDrop",params:e})},_getParams:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o={};return o.event=t,o.to=U,o.from=K,o.node=X,o.clone=W,o.target=tt,o.oldIndex=J,o.newIndex=Q,o.pullMode=Z,this.multiplayer.setParams(o),e(o,n),o.relative=o.target===X?0:D(o.target,W),o},_nulling:function(){U=K=H=X=Y=L=W=k=R=Z=J=Q=$=B=F=tt=z=j=G=V=q=ot.clone=ot.ghost=ot.active=ot.dragged=null},destroy:function(){this._cancelStart(),this._nulling(),p(this.el,"touchstart",this._onDrag),p(this.el,"mousedown",this._onDrag),et.splice(et.indexOf(this.el),1),this.el[I]=this.animator=this.multiplayer=this.autoScroller=null},option:function(t,e){if(void 0===e)return this.options[t];this.options[t]=e,this.animator.options[t]=e,this.multiplayer.options[t]=e,this.autoScroller.options[t]=e,"group"===t&&nt(this.options)},select:function(t){this.multiplayer.select(t)},deselect:function(t){this.multiplayer.deselect(t)},getSelectedElements:function(){return this.multiplayer.selectedElements}},ot.utils={on:d,off:p,css:E,index:w,closest:g,getRect:f,toggleClass:S,detectDirection:_},ot.get=function(t){return t[I]},ot.create=function(t,e){return new ot(t,e)},ot})); | ||
!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 t(e){return t="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(e)}function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},e.apply(this,arguments)}var n={capture:!1,passive:!1},o=/\s+/g;function i(t){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(t)}var r=i(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),s=i(/Edge/i),a=i(/safari/i)&&!i(/chrome/i)&&!i(/android/i),l=function(){var t=!1;return document.addEventListener("checkIfSupportPassive",null,{get passive(){return t=!0,!0}}),t}(),c=function(){if("undefined"==typeof window||"undefined"==typeof document)return{};var t=window.getComputedStyle(document.documentElement,"")||["-moz-hidden-iframe"],e=(Array.prototype.slice.call(t).join("").match(/-(moz|webkit|ms)-/)||""===t.OLink&&["","o"])[1];return{dom:"WebKit|Moz|MS|O".match(new RegExp("("+e+")","i"))[1],lowercase:e,css:"-"+e+"-",js:e[0].toUpperCase()+e.substr(1)}}();function h(t,e){t.style["".concat(c.css,"transition-duration")]=e?"".concat(e,"ms"):""}function u(t,e){t.style["".concat(c.css,"transform")]=e?"".concat(e):""}function d(t,e,o){window.addEventListener?t.addEventListener(e,o,!(!l&&r)&&n):window.attachEvent?t.attachEvent("on"+e,o):t["on"+e]=o}function p(t,e,o){window.removeEventListener?t.removeEventListener(e,o,!(!l&&r)&&n):window.detachEvent?t.detachEvent("on"+e,o):t["on"+e]=null}function m(){return document.scrollingElement||document.documentElement}function f(t,e,n){if(t.getBoundingClientRect||t===window){var o,i,r,s,a,l,c;if(t!==window&&t.parentNode&&t!==m()?(i=(o=t.getBoundingClientRect()).top,r=o.left,s=o.bottom,a=o.right,l=o.height,c=o.width):(i=0,r=0,s=window.innerHeight,a=window.innerWidth,l=window.innerHeight,c=window.innerWidth),e&&t!==window){n=n||t.parentNode;do{if(n&&n.getBoundingClientRect){var h=n.getBoundingClientRect();i-=h.top+parseInt(E(n,"border-top-width")),r-=h.left+parseInt(E(n,"border-left-width")),s=i+o.height,a=r+o.width;break}}while(n=n.parentNode)}return{top:i,left:r,bottom:s,right:a,width:c,height:l}}}function g(t,e,n,o){if(!t)return null;if(n&&!e){var i=Array.prototype.slice.call(n.children),r=i.indexOf(t);if(r>-1)return i[r];for(var s=0;s<i.length;s++)if(v(t,i[s]))return i[s]}n=n||document;do{if(null!=e&&(">"===e[0]?t.parentNode===n&&x(t,e):x(t,e))||o&&t===n)return t;if(t===n)break}while(t=t.parentNode);return null}function v(t,e){if(!t||!e)return!1;if(e.compareDocumentPosition)return!!(16&e.compareDocumentPosition(t));if(e.contains&&1===t.nodeType)return e.contains(t)&&e!==t;for(;t=t.parentNode;)if(t===e)return!0;return!1}function y(t,e){for(var n=t.lastElementChild;n&&(n===st.ghost||"none"===E(n,"display")||e&&!x(n,e));)n=n.previousElementSibling;return n||null}function w(t,e){if(!t||!t.parentNode)return-1;for(var n=0;t=t.previousElementSibling;)"TEMPLATE"===t.nodeName.toUpperCase()||e&&!x(t,e)||"none"===E(t,"display")||n++;return n}function b(t,e,n,o){for(var i=0,r=0,s=t.children;i<s.length;){if(s[i]!==st.ghost&&"none"!==E(s[i],"display")&&g(s[i],n,t,!1)&&(o||s[i]!==st.dragged)){if(r===e)return s[i];r++}i++}return null}function _(t,e){var n=E(t),o=parseInt(n.width)-parseInt(n.paddingLeft)-parseInt(n.paddingRight)-parseInt(n.borderLeftWidth)-parseInt(n.borderRightWidth),i=b(t,0,e),a=b(t,1,e),l=i&&E(i),c=a&&E(a),h=l&&parseInt(l.marginLeft)+parseInt(l.marginRight)+f(i).width,u=c&&parseInt(c.marginLeft)+parseInt(c.marginRight)+f(a).width,d=s||r?"cssFloat":"float";if("flex"===n.display)return"column"===n.flexDirection||"column-reverse"===n.flexDirection?"vertical":"horizontal";if("grid"===n.display)return n.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(i&&l.float&&"none"!==l.float){var p="left"===l.float?"left":"right";return!a||"both"!==c.clear&&c.clear!==p?"horizontal":"vertical"}return i&&("block"===l.display||"flex"===l.display||"table"===l.display||"grid"===l.display||h>=o&&"none"===n[d]||a&&"none"===n[d]&&h+u>o)?"vertical":"horizontal"}function S(t,e,n){if(t&&e)if(t.classList)t.classList[n?"add":"remove"](e);else{var i=(" "+t.className+" ").replace(o," ").replace(" "+e+" "," ");t.className=(i+(n?" "+e:"")).replace(o," ")}}function x(t,e){if(e){if(">"===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!1}return!1}}function E(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];e in o||-1!==e.indexOf("webkit")||(e="-webkit-"+e),o[e]=n+("string"==typeof n?"":"px")}}function D(t,e){var n,o,i=(o=e,(n=t).compareDocumentPosition?n.compareDocumentPosition(o):n.contains?(n!=o&&n.contains(o)&&16)+(n!=o&&o.contains(n)&&8)+(n.sourceIndex>=0&&o.sourceIndex>=0?(n.sourceIndex<o.sourceIndex&&4)+(n.sourceIndex>o.sourceIndex&&2):1):0);return 2===i?1:4===i?-1:0}function C(t){void 0!==t.preventDefault&&t.cancelable&&t.preventDefault()}function I(t){var n=t.sortable,o=t.name,i=t.params,r=n.options[o];"function"==typeof r&&r(e({},i))}var M,T,N="Sortable"+Date.now();function P(t){this.options=t,this.autoScrollAnimationFrame=null}function O(t){this.options=t,this.animations=[]}function A(t){this.options=t||{},this.selectedElements=[]}window.requestAnimationFrame||(window.requestAnimationFrame=function(t){return setTimeout(t,17)}),window.cancelAnimationFrame||(window.cancelAnimationFrame=function(t){clearTimeout(t)}),P.prototype={destroy:function(){this.autoScrollAnimationFrame&&(cancelAnimationFrame(this.autoScrollAnimationFrame),this.autoScrollAnimationFrame=null)},update:function(t,e,n){var o=this;cancelAnimationFrame(this.autoScrollAnimationFrame),this.autoScrollAnimationFrame=requestAnimationFrame((function(){e&&n&&o.autoScroll(t,n),o.update(t,e,n)}))},autoScroll:function(t,e){if(t&&void 0!==e.clientX&&void 0!==e.clientY){var n=f(t);if(n){var o=e.clientX,i=e.clientY,r=n.top,s=n.right,a=n.bottom,l=n.left,c=n.height,h=n.width;if(!(i<r||o>s||i>a||o<l)){var u=this.options,d=u.scrollThreshold,p=u.scrollSpeed,m=t.scrollTop,g=t.scrollLeft,v=t.scrollHeight,y=m>0&&i>=r&&i<=r+d,w=g+h<t.scrollWidth&&o<=s&&o>=s-d,b=m+c<v&&i<=a&&i>=a-d,_=0,S=0;g>0&&o>=l&&o<=l+d&&(_=Math.floor(Math.max(-1,(o-l)/d-1)*p.x)),w&&(_=Math.ceil(Math.min(1,(o-s)/d+1)*p.x)),y&&(S=Math.floor(Math.max(-1,(i-r)/d-1)*p.y)),b&&(S=Math.ceil(Math.min(1,(i-a)/d+1)*p.y)),t.scrollTop+=S,t.scrollLeft+=_}}}}},O.prototype={collect:function(t){if(t){for(var e=f(t),n=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,o=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,i=Math.min(e.right,n),r=Math.min(e.bottom,o),s=Array.prototype.slice.call(t.children),a=[],l=0;l<=s.length;l++){var c=s[l];if(c&&c!==st.ghost&&"none"!==E(c,"display")){var h=f(c);if(!(h.bottom<0||h.right<0)){if(h.top-h.height>r||h.left-h.width>i)break;a.push({node:c,rect:h})}}}this.animations.push(a)}},animate:function(){for(var t=this.animations.pop(),e=0,n=t.length;e<n;e++){var o=t[e],i=o.node,r=o.rect;this._excute(i,r)}},_excute:function(t,e){var n=e.left,o=e.top,i=f(t);if(i.top!==o||i.left!==n){var r=o-i.top,s=n-i.left;h(t),u(t,"translate3d(".concat(s,"px, ").concat(r,"px, 0)")),t.offsetWidth,h(t,this.options.animation),u(t,"translate3d(0px, 0px, 0px)"),clearTimeout(t.animated),t.animated=setTimeout((function(){h(t),u(t,""),t.animated=null}),this.options.animation)}}},A.prototype={destroy:function(){M=T=null},active:function(){return!!M},setParams:function(t){t.nodes=M||[],t.clones=T||[]},select:function(t){S(t,this.options.selectedClass,!0),this.selectedElements.push(t),this.selectedElements.sort((function(t,e){return D(t,e)}))},deselect:function(t){var e=this.selectedElements.indexOf(t);e>-1&&(S(t,this.options.selectedClass,!1),this.selectedElements.splice(e,1))},getGhostElement:function(){if(!M)return null;var t=document.createElement("div");return this.selectedElements.forEach((function(e,n){var o=e.cloneNode(!0),i=0===n?1:.5;o.style="position: absolute;left: 0;top: 0;bottom: 0;right: 0;opacity: ".concat(i,";z-index: ").concat(n,";"),t.appendChild(o)})),t},toggleSelected:function(t,e){var n=this;e?t.forEach((function(t){return n.selectedElements.push(t)})):this.selectedElements=this.selectedElements.filter((function(e){return t.indexOf(e)<0}))},toggleClass:function(t){if(M)for(var e=0;e<M.length;e++)S(M[e],this.options.chosenClass,t)},toggleVisible:function(t){if(M)if(t){var e=M.indexOf(st.dragged);this._viewElements(M,e,st.dragged)}else this._hideElements(M)},onChoose:function(){!this.options.multiple||!this.selectedElements.length||this.selectedElements.indexOf(st.dragged)<0||(this.selectedElements.sort((function(t,e){return D(t,e)})),M=this.selectedElements,this.toggleClass(!0))},onDrag:function(t){M&&(t.animator.collect(st.dragged.parentNode),this._hideElements(M),t.animator.animate(),this.toggleClass(!1))},onDrop:function(t,e,n){if(M){var o=st.dragged,i=st.clone,r=M.indexOf(o);e[N].animator.collect(i.parentNode),t!==e&&"clone"===n?(E(i,"display","none"),T=M.map((function(t){return t.cloneNode(!0)})),this._viewElements(T,r,i),this._viewElements(M,r,o)):this._viewElements(M,r,i),e[N].animator.animate(),t!==e&&(e[N].multiplayer.toggleSelected(T||M,!0),"clone"!==n&&t[N].multiplayer.toggleSelected(M,!1))}},onSelect:function(t,e,n){var o=this.selectedElements.indexOf(e);S(e,this.options.selectedClass,o<0);var i={from:n.el,event:t,node:e,index:w(e)};o<0?(this.selectedElements.push(e),I({sortable:n,name:"onSelect",params:i})):(this.selectedElements.splice(o,1),I({sortable:n,name:"onDeselect",params:i})),this.selectedElements.sort((function(t,e){return D(t,e)}))},_viewElements:function(t,e,n){for(var o=0;o<t.length;o++)if(E(t[o],"display",""),o<e)n.parentNode.insertBefore(t[o],n);else{var i=o>0?t[o-1]:n;n.parentNode.insertBefore(t[o],i.nextSibling)}},_hideElements:function(t){for(var e=0;e<t.length;e++)t[e]!=st.dragged&&E(t[e],"display","none")}};var H,L,W,X,Y,k,R,B,F,z,j,G,V,U,q,K,Z,J,Q,$,tt,et,nt,ot=[];function it(e){var n={},o=e.group;o&&"object"==t(o)||(o={name:o,pull:!0,put:!0,revertDrag:!0}),n.name=o.name,n.pull=o.pull,n.put=o.put,n.revertDrag=o.revertDrag,e.group=n}function rt(t){var e=K||q;return!(void 0!==t.clientX&&void 0!==t.clientY&&Math.abs(t.clientX-e.clientX)<=0&&Math.abs(t.clientY-e.clientY)<=0)}function st(t,n){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable-dnd: `el` must be an HTMLElement, not ".concat({}.toString.call(t));t[N]=this,this.el=t,this.options=n=e({},n);var o={store:null,group:"",handle:null,sortable:!0,disabled:!1,multiple:!1,lockAxis:"",direction:"",animation:150,draggable:null,selectHandle:null,customGhost:null,autoScroll:!0,scrollThreshold:55,scrollSpeed:{x:10,y:10},delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,ghostClass:"",ghostStyle:{},chosenClass:"",selectedClass:"",swapOnDrop:!0,fallbackOnBody:!1,supportTouch:"ontouchstart"in window,emptyInsertThreshold:-5};for(var i in o)!(i in this.options)&&(this.options[i]=o[i]);for(var r in it(n),this)"_"===r.charAt(0)&&"function"==typeof this[r]&&(this[r]=this[r].bind(this));d(t,this.options.supportTouch?"touchstart":"mousedown",this._onDrag),ot.push(t),this.autoScroller=new P(this.options),this.multiplayer=new A(this.options),this.animator=new O(this.options)}return st.prototype={constructor:st,_onDrag:function(t){var e=this;if(!X&&!this.options.disabled&&this.options.group.pull&&(!/mousedown|pointerdown/.test(t.type)||0===t.button)){var n=t.touches&&t.touches[0],o=(n||t).target;if(!a||!o||"SELECT"!==o.tagName.toUpperCase()){var i=g(o,this.options.draggable,this.el);if(i&&!i.animated){q={origin:t,clientX:(n||t).clientX,clientY:(n||t).clientY},X=i,d($=n?X:document,"mouseup",this._onDrop),d($,"touchend",this._onDrop),d($,"touchcancel",this._onDrop);var l=this.options,c=l.handle,h=l.selectHandle;if("function"==typeof h&&h(t)||"string"==typeof h&&x(o,h))nt=!0;else if(("function"!=typeof c||c(t))&&("string"!=typeof c||x(o,c))){var u=this.options,p=u.delay,m=u.delayOnTouchOnly;!p||m&&!n||s||r?this._onStart(n,t):(d(this.el.ownerDocument,"touchmove",this._delayMoveHandler),d(this.el.ownerDocument,"mousemove",this._delayMoveHandler),d(this.el.ownerDocument,"mouseup",this._cancelStart),d(this.el.ownerDocument,"touchend",this._cancelStart),d(this.el.ownerDocument,"touchcancel",this._cancelStart),et=setTimeout((function(){return e._onStart(n,t)}),p)),d(document,"selectstart",C),a&&E(document.body,"user-select","none")}}}}},_delayMoveHandler:function(t){var e=t.touches?t.touches[0]:t;Math.max(Math.abs(e.clientX-q.clientX),Math.abs(e.clientY-q.clientY))>=Math.floor(this.options.touchStartThreshold/(window.devicePixelRatio||1))&&this._cancelStart()},_cancelStart:function(){clearTimeout(et),p(this.el.ownerDocument,"touchmove",this._delayMoveHandler),p(this.el.ownerDocument,"mousemove",this._delayMoveHandler),p(this.el.ownerDocument,"mouseup",this._cancelStart),p(this.el.ownerDocument,"touchend",this._cancelStart),p(this.el.ownerDocument,"touchcancel",this._cancelStart),p(document,"selectstart",C),a&&E(document.body,"user-select","")},_onStart:function(t,e){var n=w(X);H=this.el,L=this.el,F=X,G=n,V=n,U=n,J={to:this.el,target:X,newIndex:n,relative:0},Q=X,W=this.el,R=X.cloneNode(!0),z=X.parentNode,j=this.options.group.pull,st.clone=R,st.active=this,st.dragged=X,S(X,this.options.chosenClass,!0),this.multiplayer.onChoose(),I({sortable:this,name:"onChoose",params:this._getParams(e)}),d($,t?"touchmove":"mousemove",this._nearestSortable);try{document.selection?setTimeout((function(){return document.selection.empty()}),0):window.getSelection().removeAllRanges()}catch(t){}},_onStarted:function(){S(R,this.options.chosenClass,!0),this._appendGhost(),this.multiplayer.onDrag(this),I({sortable:this,name:"onDrag",params:this._getParams(q.origin)}),E(X,"display","none"),S(X,this.options.chosenClass,!1),X.parentNode.insertBefore(R,X)},_getGhostElement:function(){var t=this.options.customGhost;if("function"==typeof t){var e=this.multiplayer.selectedElements;return t(e.length?e:[X])}return this.multiplayer.getGhostElement()||X},_appendGhost:function(){if(!B){var t=this.options.fallbackOnBody?document.body:this.el,n=this._getGhostElement();S(B=n.cloneNode(!0),this.options.ghostClass,!0);var o,i=f(X),r=e({position:"fixed",top:i.top,left:i.left,width:i.width,height:i.height,minWidth:i.width,minHeight:i.height,opacity:"0.8",overflow:"hidden","z-index":"100000","box-sizing":"border-box","pointer-events":"none"},this.options.ghostStyle);for(var s in r)E(B,s,r[s]);o="none",B.style["".concat(c.css,"transition")]=o?"none"===o?"none":"".concat(o):"",u(B,"translate3d(0px, 0px, 0px)"),st.ghost=B,t.appendChild(B);var a=(q.clientX-i.left)/parseInt(B.style.width)*100,l=(q.clientY-i.top)/parseInt(B.style.height)*100;E(B,"transform-origin","".concat(a,"% ").concat(l,"%")),E(B,"transform","translateZ(0)"),E(B,"will-change","transform")}},_nearestSortable:function(t){C(t);var e=t.touches&&t.touches[0]||t;if(X&&rt(e)){!K&&this._onStarted();var n=this.options.lockAxis,o="x"===n?q.clientX:e.clientX,i="y"===n?q.clientY:e.clientY,r=document.elementFromPoint(o,i),s=o-q.clientX,a=i-q.clientY;if(K={origin:t,clientX:o,clientY:i},u(B,"translate3d(".concat(s,"px, ").concat(a,"px, 0)")),this.options.autoScroll){var l=function(t,e){if(!t||!t.getBoundingClientRect)return m();var n=t,o=!1;do{if(n.clientWidth<n.scrollWidth||n.clientHeight<n.scrollHeight){var i=E(n);if(n.clientWidth<n.scrollWidth&&("auto"==i.overflowX||"scroll"==i.overflowX)||n.clientHeight<n.scrollHeight&&("auto"==i.overflowY||"scroll"==i.overflowY)){if(!n.getBoundingClientRect||n===document.body)return m();if(o||e)return n;o=!0}}}while(n=n.parentNode);return m()}(r,!0);this.autoScroller.update(l,q,K)}var c,h,d,p=(c=o,h=i,ot.some((function(t){var e=t[N].options.emptyInsertThreshold;if(null!=e){var n=f(t),o=c>=n.left-e&&c<=n.right+e,i=h>=n.top-e&&h<=n.bottom+e;return o&&i?d=t:void 0}})),d);p&&p[N]._onMove(t,r)}},_allowPut:function(){if(W===this.el)return!0;if(this.options.group.put){var t=this.options.group,e=t.name,n=t.put,o=W[N].options.group;return n.join&&n.indexOf(o.name)>-1||o.name&&e&&o.name===e}return!1},_getDirection:function(){var t=this.options,e=t.draggable,n=t.direction;return n?"function"==typeof n?n.call(K.origin,X,this):n:_(z,e)},_allowSwap:function(){var t=f(Y),e="vertical"===this._getDirection(),n=e?"top":"left",o=e?"bottom":"right",i=Y[e?"offsetHeight":"offsetWidth"],r=e?K.clientY:K.clientX,s=r>=t[n]&&r<t[o]-i/2?-1:1,a=b(z,0,this.options.draggable),l=y(z),c=f(a),h=f(l);if(Y===z||v(z,Y))return R===a&&r<c[n]?(k=Y,!0):R===l&&r>h[o]&&(k=Y.nextSibling,!0);var u=D(R,Y);return k=u<0?Y.nextSibling:Y,Z!==Y?(tt=s,!0):tt!==s&&(tt=s,s<0?u>0:u<0)},_onMove:function(t,e){if(this.options.sortable&&this._allowPut()){if(I({sortable:this,name:"onMove",params:this._getParams(t)}),this.el!==L&&(e===this.el||!y(this.el)))return Y=Z=null,void this._onInsert(t);(Y=g(e,this.options.draggable,this.el))&&!Y.animated&&this._allowSwap()&&(Y!==R&&k!==R?(this.el!==L?this._onInsert(t):Y!==X&&this._onChange(t),Z=Y):Z=Y)}},_onInsert:function(t){var e=Y||R,n="clone"===j&&this.el!==W&&L===W,o="clone"===j&&this.el===W&&L!==W;H=this.el,G=w(R),F=e,z=Y?Y.parentNode:this.el,L[N].animator.collect(R.parentNode),this.animator.collect(z),n&&(J.target=Q,J.newIndex=G,J.relative=Q===X?0:D(R,Q),E(X,"display",""),W[N].multiplayer.toggleVisible(!0),W[N].options.group.revertDrag||L.insertBefore(X,R)),o&&(G=w(X),E(X,"display","none"),this.multiplayer.toggleVisible(!1)),Y?z.insertBefore(R,tt<0?Y:Y.nextSibling):z.appendChild(R),V=w(R),n&&W[N].options.group.revertDrag&&(J.target=X,J.newIndex=U,J.relative=0,I({sortable:W[N],name:"onChange",params:this._getParams(t,{to:W,target:X,newIndex:U,revertDrag:!0})})),n||I({sortable:L[N],name:"onRemove",params:this._getParams(t)}),o&&Y!==X&&(Q=Y,I({sortable:this,name:"onChange",params:this._getParams(t,{from:W,backToOrigin:!0})})),o||I({sortable:this,name:"onAdd",params:this._getParams(t)}),L[N].animator.animate(),this.animator.animate(),L=this.el},_onChange:function(t){G=w(R),z=Y.parentNode,F=Y,this.el===W&&(Q=Y),this.animator.collect(z),z.insertBefore(R,k),V=w(R),I({sortable:this,name:"onChange",params:this._getParams(t)}),this.animator.animate(),L=this.el},_onDrop:function(t){C(t),this._cancelStart(),p($,"touchmove",this._nearestSortable),p($,"mousemove",this._nearestSortable),p($,"mouseup",this._onDrop),p($,"touchend",this._onDrop),p($,"touchcancel",this._onDrop),S(X,this.options.chosenClass,!1),W&&(L=W,G=U,F===R&&(F=X),this.multiplayer.toggleClass(!1),I({sortable:this,name:"onUnchoose",params:this._getParams(t)}),K&&this._onEnd(t));var e=this.options,n=e.multiple,o=e.selectHandle;n&&(o&&nt||!o&&!W)&&(!rt(t.changedTouches?t.changedTouches[0]:t)&&this.multiplayer.onSelect(t,X,this));B&&B.parentNode&&B.parentNode.removeChild(B),this.multiplayer.destroy(),this.autoScroller.destroy(),this._nulling()},_onEnd:function(t){var n=this._getParams(t);this.multiplayer.onDrop(L,H,j);var o=this.options.swapOnDrop;"clone"===j&&L!==H||!("function"==typeof o?o(n):o)||z.insertBefore(X,R),"clone"!==j||L===H||this.multiplayer.active()?R&&R.parentNode&&R.parentNode.removeChild(R):S(R,this.options.chosenClass,!1),E(X,"display",""),L!==H&&I({sortable:L[N],name:"onDrop",params:"clone"===j?e({},n,J):n}),I({sortable:H[N],name:"onDrop",params:n})},_getParams:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o={};return o.event=t,o.to=H,o.from=L,o.node=X,o.clone=R,o.target=F,o.oldIndex=G,o.newIndex=V,o.pullMode=j,this.multiplayer.setParams(o),e(o,n),o.relative=F===X?0:D(R,F),o},_nulling:function(){H=L=W=X=Y=k=R=B=F=z=j=G=V=U=q=K=Z=J=Q=$=tt=et=nt=st.clone=st.ghost=st.active=st.dragged=null},destroy:function(){this._cancelStart(),this._nulling(),p(this.el,"touchstart",this._onDrag),p(this.el,"mousedown",this._onDrag),ot.splice(ot.indexOf(this.el),1),this.el[N]=this.animator=this.multiplayer=this.autoScroller=null},option:function(t,e){if(void 0===e)return this.options[t];this.options[t]=e,this.animator.options[t]=e,this.multiplayer.options[t]=e,this.autoScroller.options[t]=e,"group"===t&&it(this.options)},select:function(t){this.multiplayer.select(t)},deselect:function(t){this.multiplayer.deselect(t)},getSelectedElements:function(){return this.multiplayer.selectedElements}},st.utils={on:d,off:p,css:E,index:w,closest:g,getRect:f,toggleClass:S,detectDirection:_},st.get=function(t){return t[N]},st.create=function(t,e){return new st(t,e)},st})); |
{ | ||
"name": "sortable-dnd", | ||
"version": "0.6.6", | ||
"version": "0.6.7", | ||
"description": "JS library for drag-and-drop lists, supports sortable and draggable", | ||
@@ -5,0 +5,0 @@ "main": "dist/sortable-dnd.min.js", |
@@ -70,3 +70,3 @@ export type Direction = 'vertical' | 'horizontal'; | ||
/** | ||
* List of currently placed drag element. | ||
* List of currently placed drag element. Or the start list(from) in `pull: 'clone'`. | ||
*/ | ||
@@ -121,11 +121,11 @@ to: HTMLElement; | ||
/** | ||
* Position of the drop element relative to the drag element after swap is complete. | ||
* Position of the drag element relative to the drop element(target) after swap is complete. | ||
* @example | ||
* 0: <div>dragEl, dropEl</div> // The position of dropEl is the same as dragEl. | ||
* | ||
* 1: <div>dragEl</div> // dropEl comes after dragEl. | ||
* <div>dropEl</div> | ||
* 1: <div>dropEl</div> // dragEl comes after dropEl. | ||
* <div>dragEl</div> | ||
* | ||
* -1: <div>dropEl</div> // dropEl comes before dragEl. | ||
* <div>dragEl</div> | ||
* -1: <div>dragEl</div> // dragEl comes before dropEl. | ||
* <div>dropEl</div> | ||
*/ | ||
@@ -135,3 +135,3 @@ relative: 0 | 1 | -1; | ||
/** | ||
* Revert draged element to initial position after moving to a another list if `pull: 'clone'` & `revertDrag: true`. | ||
* Revert draged element to initial position after moving to a another list in `pull: 'clone'` & `revertDrag: true`. | ||
*/ | ||
@@ -141,3 +141,3 @@ revertDrag?: boolean; | ||
/** | ||
* Dragged element go back to the original list if `pull: 'clone'`. | ||
* Dragged element go back to the original list in `pull: 'clone'`. | ||
*/ | ||
@@ -159,2 +159,8 @@ backToOrigin?: boolean; | ||
/** | ||
* Allow Sorting by Dragging. | ||
* @defaults `true` | ||
*/ | ||
sortable?: boolean; | ||
/** | ||
* Specifies which items inside the element should be draggable. | ||
@@ -161,0 +167,0 @@ * @example |
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
1795
92050