UNPKG

@atrubchik/vue-slicksort

Version:

Set of mixins to turn any list into a sortable, touch-friendly, animated list

3 lines (2 loc) 21.9 kB
(function(p,m){typeof exports=="object"&&typeof module!="undefined"?m(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],m):(p=typeof globalThis!="undefined"?globalThis:p||self,m(p.VueSlicksort={},p.vue))})(this,function(p,m){"use strict";const O=m.defineComponent({inject:["manager"],props:{index:{type:Number,required:!0},disabled:{type:Boolean,default:!1}},data(){return{}},watch:{index(t){this.$el&&this.$el.sortableInfo&&(this.$el.sortableInfo.index=t)},disabled(t){t?this.removeDraggable():this.setDraggable(this.index)}},mounted(){const{disabled:t,index:e}=this.$props;t||this.setDraggable(e)},beforeUnmount(){this.disabled||this.removeDraggable()},methods:{setDraggable(t){const e=this.$el;e.sortableInfo={index:t,manager:this.manager},this.ref={node:e},this.manager.add(this.ref)},removeDraggable(){this.manager.remove(this.ref)}}});class A{constructor(){this.refs=[],this.active=null}add(e){this.refs||(this.refs=[]),this.refs.push(e)}remove(e){const i=this.getIndex(e);i!==-1&&this.refs.splice(i,1)}isActive(){return!!this.active}getActive(){return this.refs.find(({node:e})=>{var i,n;return((i=e==null?void 0:e.sortableInfo)==null?void 0:i.index)==((n=this==null?void 0:this.active)==null?void 0:n.index)})||null}getIndex(e){return this.refs.indexOf(e)}getRefs(){return this.refs}getOrderedRefs(){return this.refs.sort((e,i)=>e.node.sortableInfo.index-i.node.sortableInfo.index)}}const b=t=>t.touches!=null;function I(t,e){return!!t&&Object.prototype.hasOwnProperty.call(t,e)}function E(t,e,i){const n=t.slice(0);if(i>=n.length){let s=i-n.length;for(;s--+1;)n.push(void 0)}return n.splice(i,0,n.splice(e,1)[0]),n}function F(t,e){const i=t.slice(0);return e>=i.length||i.splice(e,1),i}function K(t,e,i){const n=t.slice(0);return e===n.length?n.push(i):n.splice(e,0,i),n}const y={start:["touchstart","mousedown"],move:["touchmove","mousemove"],end:["touchend","mouseup"],cancel:["touchcancel","keyup"]};function _(t,e){for(;t;){if(e(t))return t;t=t.parentNode}}function $(t,e,i){return i<t?t:i>e?e:i}function S(t){return t.substr(-2)==="px"?parseFloat(t):0}function N(t){const e=window.getComputedStyle(t);return{top:S(e.marginTop),right:S(e.marginRight),bottom:S(e.marginBottom),left:S(e.marginLeft)}}function w(t,e="page"){const i=`${e}X`,n=`${e}Y`;return{x:b(t)?t.touches[0][i]:t[i],y:b(t)?t.touches[0][n]:t[n]}}function L(t){const e=[t];for(;t;t=t.offsetParent)e.unshift(t);return e}function X(t,e){const i=L(t),n=L(e);if(i[0]!=n[0])throw"No common ancestor!";for(let s=0;s<i.length;s++)if(i[s]!=n[s])return i[s-1]}function v(t,e,i={top:0,left:0}){if(t){const n={top:i.top+t.offsetTop,left:i.left+t.offsetLeft};return t.offsetParent!==e.offsetParent?v(t.offsetParent,e,n):n}return{top:0,left:0}}function M(t){const e=t.querySelectorAll("input, textarea, select"),i=t.cloneNode(!0);return[...i.querySelectorAll("input, textarea, select")].forEach((s,r)=>{s.type!=="file"&&e[r]&&(s.value=e[r].value)}),i}function Y(t,e,i){if(typeof t=="string"&&(t=+t),Array.isArray(t)||(t=[t,t]),t.length!==2)throw new Error(`lockOffset prop of SortableContainer should be a single value or an array of exactly two values. Given ${t}`);const[n,s]=t;return[P(n,e,i),P(s,e,i)]}function P(t,e,i){let n=t,s=t,r="px";if(typeof t=="string"){const o=/^[+-]?\d*(?:\.\d*)?(px|%)$/.exec(t);if(o===null)throw new Error(`lockOffset value should be a number or a string of a number followed by "px" or "%". Given ${t}`);n=s=parseFloat(t),r=o[1]}if(!isFinite(n)||!isFinite(s))throw new Error(`lockOffset value should be a finite. Given ${t}`);return r==="%"&&(n=n*e/100,s=s*i/100),{x:n,y:s}}function q(t,e,i,n){const s=t-i,r=e-n;return Math.sqrt(s*s+r*r)}function j(t){return{x:t.left+t.width/2,y:t.top+t.height/2}}function R(t=[]){for(let e=0,i=t.length;e<i;e++){const n=t[e],s=n.node;if(!s)return;n.edgeOffset=null,T(s)}}function T(t,e="",i=""){!t||(t.style.transform=e,t.style.transitionDuration=i)}function B(t,e,i){const n=Math.max(e,i);return Math.min(e,i)<=t&&t<=n}function H({x:t,y:e},{top:i,left:n,width:s,height:r}){const o=B(t,n,n+s),h=B(e,i,i+r);return o&&h}const C=setTimeout,k=m.defineComponent({inject:["SlicksortHub"],provide(){return{manager:this.manager}},props:{list:{type:Array,required:!0},axis:{type:String,default:"y"},distance:{type:Number,default:0},pressDelay:{type:Number,default:0},pressThreshold:{type:Number,default:5},useDragHandle:{type:Boolean,default:!1},useWindowAsScrollContainer:{type:Boolean,default:!1},hideSortableGhost:{type:Boolean,default:!0},lockToContainerEdges:{type:Boolean,default:!1},lockOffset:{type:[String,Number,Array],default:"50%"},transitionDuration:{type:Number,default:300},appendTo:{type:String,default:"body"},draggedSettlingDuration:{type:Number,default:null},group:{type:String,default:""},accept:{type:[Boolean,Array,Function],default:null},insert:{type:Function,default:()=>!0},cancelKey:{type:String,default:"Escape"},block:{type:Array,default:()=>[]},lockAxis:{type:String,default:""},helperClass:{type:String,default:""},contentWindow:{type:Object,default:null},shouldCancelStart:{type:Function,default:t=>["input","textarea","select","option","button"].indexOf(t.target.tagName.toLowerCase())!==-1},getHelperDimensions:{type:Function,default:({node:t})=>({width:t.offsetWidth,height:t.offsetHeight})}},emits:["sort-start","sort-move","sort-end","sort-cancel","sort-insert","sort-remove","sort-failed-to-insert","update:list"],data(){let t=!1;return this.group&&this.SlicksortHub&&(t=!0),{sorting:!1,hub:t?this.SlicksortHub:null,manager:new A}},mounted(){this.hub&&(this.id=this.hub.getId()),this.container=this.$el,this.document=this.container.ownerDocument||document,this._window=this.contentWindow||window,this.scrollContainer=this.useWindowAsScrollContainer?{scrollLeft:0,scrollTop:0}:this.container,this.events={start:this.handleStart,move:this.handleMove,end:this.handleEnd};for(const t in this.events)I(this.events,t)&&y[t].forEach(e=>this.container.addEventListener(e,this.events[t]));this.hub&&this.hub.addContainer(this)},beforeUnmount(){for(const t in this.events)I(this.events,t)&&y[t].forEach(e=>this.container.removeEventListener(e,this.events[t]));this.hub&&this.hub.removeContainer(this),this.dragendTimer&&clearTimeout(this.dragendTimer),this.cancelTimer&&clearTimeout(this.cancelTimer),this.pressTimer&&clearTimeout(this.pressTimer),this.autoscrollInterval&&clearInterval(this.autoscrollInterval)},methods:{handleStart(t){const{distance:e,shouldCancelStart:i}=this.$props;if(!b(t)&&t.button===2||i(t))return!1;this._touched=!0,this._pos=w(t);const n=t.target,s=_(n,r=>r.sortableInfo!=null);if(s&&s.sortableInfo&&this.nodeIsChild(s)&&!this.sorting){const{useDragHandle:r}=this.$props,{index:o}=s.sortableInfo;if(r&&!_(n,h=>h.sortableHandle!=null))return;this.manager.active={index:o},n.tagName.toLowerCase()==="a"&&t.preventDefault(),e||(this.pressDelay===0?this.handlePress(t):this.pressTimer=C(()=>this.handlePress(t),this.pressDelay))}},nodeIsChild(t){return t.sortableInfo.manager===this.manager},handleFailedToInsert(){const t=this.getPayload();this.$emit("sort-failed-to-insert",t)},handleMove(t){const{distance:e,pressThreshold:i}=this.$props;if(!this.sorting&&this._touched){const n=w(t);this._delta={x:this._pos.x-n.x,y:this._pos.y-n.y};const s=Math.abs(this._delta.x)+Math.abs(this._delta.y);!e&&(!i||i&&s>=i)?(this.cancelTimer&&clearTimeout(this.cancelTimer),this.cancelTimer=C(this.cancel,0)):e&&s>=e&&this.manager.isActive()&&this.handlePress(t)}},handleEnd(){if(!this._touched)return;const{distance:t}=this.$props;this._touched=!1,t||this.cancel()},cancel(){this.sorting||(this.pressTimer&&clearTimeout(this.pressTimer),this.manager.active=null,this.hub&&this.hub.cancel())},handleSortCancel(t){(b(t)||t.key===this.cancelKey)&&(this.newIndex=this.index,this.canceling=!0,this.translate={x:0,y:0},this.animateNodes(),this.handleSortEnd(t))},handlePress(t){t.stopPropagation();const e=this.manager.getActive();if(e){const{getHelperDimensions:i,helperClass:n,hideSortableGhost:s,appendTo:r}=this.$props,{node:o}=e,{index:h}=o.sortableInfo,a=N(o),l=this.container.getBoundingClientRect(),u=i({index:h,node:o});this.node=o,this.margin=a,this.width=u.width,this.height=u.height,this.marginOffset={x:this.margin.left+this.margin.right,y:Math.max(this.margin.top,this.margin.bottom)},this.boundingClientRect=o.getBoundingClientRect(),this.containerBoundingRect=l,this.index=h,this.newIndex=h;const g=M(o);this.helper=this.document.querySelector(r).appendChild(g),this.helper.style.position="fixed",this.helper.style.top=`${this.boundingClientRect.top-a.top}px`,this.helper.style.left=`${this.boundingClientRect.left-a.left}px`,this.helper.style.width=`${this.width}px`,this.helper.style.height=`${this.height}px`,this.helper.style.boxSizing="border-box",this.helper.style.pointerEvents="none",s&&(this.sortableGhost=o,o.style.visibility="hidden",o.style.opacity="0"),this.hub&&(this.hub.sortStart(this),this.hub.helper=this.helper,this.hub.ghost=this.sortableGhost),this.intializeOffsets(t,this.boundingClientRect),this.offsetEdge=v(o,this.container),n&&this.helper.classList.add(...n.split(" ")),this.listenerNode=b(t)?o:this._window,y.move.forEach(d=>this.listenerNode.addEventListener(d,this.handleSortMove)),y.end.forEach(d=>this.listenerNode.addEventListener(d,this.handleSortEnd)),y.cancel.forEach(d=>this.listenerNode.addEventListener(d,this.handleSortCancel)),this.sorting=!0,this.$emit("sort-start",{event:t,node:o,index:h})}},handleSortMove(t){if(t.preventDefault(),this.updatePosition(t),this.hub){const e=this.list[this.index];this.hub.handleSortMove(t,e)}(!this.hub||this.hub.isDest(this))&&(this.animateNodes(),this.autoscroll()),this.$emit("sort-move",{event:t})},getPayload(){return this.list[this.index]},handleDropOut(){const t=this.list[this.index],e=F(this.list,this.index);return this.$emit("sort-remove",{oldIndex:this.index}),this.$emit("update:list",e),t},handleDropIn(t){const e=K(this.list,this.newIndex,t);this.$emit("sort-insert",{newIndex:this.newIndex,value:t}),this.$emit("update:list",e),this.handleDragEnd()},handleDragOut(){this.autoscrollInterval&&(clearInterval(this.autoscrollInterval),this.autoscrollInterval=null),this.hub.isSource(this)?(this.translate={x:1e4,y:1e4},this.animateNodes()):(this.manager.getRefs().forEach(t=>{t.node.style.transform=""}),this.dragendTimer=C(this.handleDragEnd,this.transitionDuration||0))},handleDragEnd(){this.autoscrollInterval&&(clearInterval(this.autoscrollInterval),this.autoscrollInterval=null),R(this.manager.getRefs()),this.sortableGhost&&(this.sortableGhost.remove(),this.sortableGhost=null),this.dragendTimer&&(clearTimeout(this.dragendTimer),this.dragendTimer=null),this.manager.active=null,this._touched=!1,this.sorting=!1},intializeOffsets(t,e){const{useWindowAsScrollContainer:i,containerBoundingRect:n,_window:s}=this;this.marginOffset={x:this.margin.left+this.margin.right,y:Math.max(this.margin.top,this.margin.bottom)},this._axis={x:this.axis.indexOf("x")>=0,y:this.axis.indexOf("y")>=0},this.initialOffset=w(t),this.initialScroll={top:this.scrollContainer.scrollTop,left:this.scrollContainer.scrollLeft},this.initialWindowScroll={top:window.pageYOffset,left:window.pageXOffset},this.translate={x:0,y:0},this.minTranslate={},this.maxTranslate={},this._axis.x&&(this.minTranslate.x=(i?0:n.left)-e.left-this.width/2,this.maxTranslate.x=(i?s.innerWidth:n.left+n.width)-e.left-this.width/2),this._axis.y&&(this.minTranslate.y=(i?0:n.top)-e.top-this.height/2,this.maxTranslate.y=(i?s.innerHeight:n.top+n.height)-e.top-this.height/2)},handleDragIn(t,e,i){if(this.hub.isSource(this))return;this.dragendTimer&&(this.handleDragEnd(),clearTimeout(this.dragendTimer),this.dragendTimer=null);const n=this.manager.getRefs();this.index=n.length,this.manager.active={index:this.index};const s=this.container.getBoundingClientRect(),r=i.getBoundingClientRect();this.containerBoundingRect=s,this.sortableGhost=M(e),this.container.appendChild(this.sortableGhost);const o=this.sortableGhost.getBoundingClientRect();this.boundingClientRect=o,this.margin=N(this.sortableGhost),this.width=o.width,this.height=o.height,this.offsetEdge=v(this.sortableGhost,this.container),this.intializeOffsets(t,o),this.initialOffset.x+=o.x-r.x,this.initialOffset.y+=o.y-r.y,this.sorting=!0},handleSortEnd(t){var e,i;const n=this.getPayload();this.hub&&!((i=(e=this.hub)==null?void 0:e.getDest())==null?void 0:i.insert(n))&&!this.canceling&&(this.newIndex=this.index,this.canceling=!0,this.translate={x:0,y:0},this.animateNodes(),this.handleSortEnd(t),this.handleFailedToInsert()),this.listenerNode&&(y.move.forEach(o=>this.listenerNode.removeEventListener(o,this.handleSortMove)),y.end.forEach(o=>this.listenerNode.removeEventListener(o,this.handleSortEnd)),y.cancel.forEach(o=>this.listenerNode.removeEventListener(o,this.handleSortCancel)));const s=this.manager.getRefs();this.helper&&this.helperClass&&this.helper.classList.remove(...this.helperClass.split(" ")),this.autoscrollInterval&&clearInterval(this.autoscrollInterval),this.autoscrollInterval=null;const r=()=>{this.helper&&(this.helper.remove(),this.helper=null),this.hideSortableGhost&&this.sortableGhost&&(this.sortableGhost.style.visibility="",this.sortableGhost.style.opacity=""),R(s),this.hub&&!this.hub.isDest(this)?this.canceling?this.hub.cancel():this.hub.handleSortEnd(t):this.canceling?this.$emit("sort-cancel",{event:t}):(this.$emit("sort-end",{event:t,oldIndex:this.index,newIndex:this.newIndex}),this.$emit("update:list",E(this.list,this.index,this.newIndex))),this.manager.active=null,this._touched=!1,this.canceling=!1,this.sorting=!1};this.transitionDuration||this.draggedSettlingDuration?this.transitionHelperIntoPlace(s,r):r()},transitionHelperIntoPlace(t,e){if(this.draggedSettlingDuration===0||t.length===0||!this.helper)return Promise.resolve();const i=t[this.index].node;let n=0,s=0;const r={top:window.pageYOffset-this.initialWindowScroll.top,left:window.pageXOffset-this.initialWindowScroll.left};if(this.hub&&!this.hub.isDest(this)&&!this.canceling){const l=this.hub.getDest();if(!l)return;const u=l.newIndex,g=l.manager.getOrderedRefs(),d=u<g.length?g[u].node:l.sortableGhost,c=X(i,d),f=v(i,c),x=v(d,c);n=x.left-f.left-r.left,s=x.top-f.top-r.top}else{const l=t[this.newIndex].node,u={left:this.scrollContainer.scrollLeft-this.initialScroll.left+r.left,top:this.scrollContainer.scrollTop-this.initialScroll.top+r.top};n=-u.left,this.translate&&this.translate.x>0?n+=l.offsetLeft+l.offsetWidth-(i.offsetLeft+i.offsetWidth):n+=l.offsetLeft-i.offsetLeft,s=-u.top,this.translate&&this.translate.y>0?s+=l.offsetTop+l.offsetHeight-(i.offsetTop+i.offsetHeight):s+=l.offsetTop-i.offsetTop}const o=this.draggedSettlingDuration!==null?this.draggedSettlingDuration:this.transitionDuration;T(this.helper,`translate3d(${n}px,${s}px, 0)`,`${o}ms`);const h=l=>{(!l||l.propertyName==="transform")&&(clearTimeout(a),T(this.helper),e())},a=setTimeout(h,o+10);this.helper.addEventListener("transitionend",h)},updatePosition(t){const{lockAxis:e,lockToContainerEdges:i}=this.$props,n=w(t),s={x:n.x-this.initialOffset.x,y:n.y-this.initialOffset.y};if(s.y-=window.pageYOffset-this.initialWindowScroll.top,s.x-=window.pageXOffset-this.initialWindowScroll.left,this.translate=s,i){const[r,o]=Y(this.lockOffset,this.height,this.width),h={x:this.width/2-r.x,y:this.height/2-r.y},a={x:this.width/2-o.x,y:this.height/2-o.y};this.minTranslate.x&&this.maxTranslate.x&&(s.x=$(this.minTranslate.x+h.x,this.maxTranslate.x-a.x,s.x)),this.minTranslate.y&&this.maxTranslate.y&&(s.y=$(this.minTranslate.y+h.y,this.maxTranslate.y-a.y,s.y))}e==="x"?s.y=0:e==="y"&&(s.x=0),this.helper&&(this.helper.style.transform=`translate3d(${s.x}px,${s.y}px, 0)`)},animateNodes(){const{transitionDuration:t,hideSortableGhost:e}=this.$props,i=this.manager.getOrderedRefs(),n={left:this.scrollContainer.scrollLeft-this.initialScroll.left,top:this.scrollContainer.scrollTop-this.initialScroll.top},s={left:this.offsetEdge.left+this.translate.x+n.left,top:this.offsetEdge.top+this.translate.y+n.top},r={top:window.pageYOffset-this.initialWindowScroll.top,left:window.pageXOffset-this.initialWindowScroll.left};this.newIndex=null;for(let o=0,h=i.length;o<h;o++){const{node:a}=i[o],l=a.sortableInfo.index,u=a.offsetWidth,g=a.offsetHeight,d={width:this.width>u?u/2:this.width/2,height:this.height>g?g/2:this.height/2},c={x:0,y:0};let{edgeOffset:f}=i[o];f||(i[o].edgeOffset=f=v(a,this.container));const x=o<i.length-1&&i[o+1],D=o>0&&i[o-1];if(x&&!x.edgeOffset&&(x.edgeOffset=v(x.node,this.container)),l===this.index){e&&(this.sortableGhost=a,a.style.visibility="hidden",a.style.opacity="0");continue}t&&(a.style.transitionDuration=`${t}ms`),this._axis.x?this._axis.y?l<this.index&&(s.left+r.left-d.width<=f.left&&s.top+r.top<=f.top+d.height||s.top+r.top+d.height<=f.top)?(c.x=this.width+this.marginOffset.x,f.left+c.x>this.containerBoundingRect.width-d.width&&x&&(c.x=x.edgeOffset.left-f.left,c.y=x.edgeOffset.top-f.top),this.newIndex===null&&(this.newIndex=l)):l>this.index&&(s.left+r.left+d.width>=f.left&&s.top+r.top+d.height>=f.top||s.top+r.top+d.height>=f.top+g)&&(c.x=-(this.width+this.marginOffset.x),f.left+c.x<this.containerBoundingRect.left+d.width&&D&&(c.x=D.edgeOffset.left-f.left,c.y=D.edgeOffset.top-f.top),this.newIndex=l):l>this.index&&s.left+r.left+d.width>=f.left?(c.x=-(this.width+this.marginOffset.x),this.newIndex=l):l<this.index&&s.left+r.left<=f.left+d.width&&(c.x=this.width+this.marginOffset.x,this.newIndex==null&&(this.newIndex=l)):this._axis.y&&(l>this.index&&s.top+r.top+d.height>=f.top?(c.y=-(this.height+this.marginOffset.y),this.newIndex=l):l<this.index&&s.top+r.top<=f.top+d.height&&(c.y=this.height+this.marginOffset.y,this.newIndex==null&&(this.newIndex=l))),a.style.transform=`translate3d(${c.x}px,${c.y}px,0)`}this.newIndex==null&&(this.newIndex=this.index)},autoscroll(){const t=this.translate,e={x:0,y:0},i={x:1,y:1},n={x:10,y:10};t.y>=this.maxTranslate.y-this.height/2?(e.y=1,i.y=n.y*Math.abs((this.maxTranslate.y-this.height/2-t.y)/this.height)):t.x>=this.maxTranslate.x-this.width/2?(e.x=1,i.x=n.x*Math.abs((this.maxTranslate.x-this.width/2-t.x)/this.width)):t.y<=this.minTranslate.y+this.height/2?(e.y=-1,i.y=n.y*Math.abs((t.y-this.height/2-this.minTranslate.y)/this.height)):t.x<=this.minTranslate.x+this.width/2&&(e.x=-1,i.x=n.x*Math.abs((t.x-this.width/2-this.minTranslate.x)/this.width)),this.autoscrollInterval&&(clearInterval(this.autoscrollInterval),this.autoscrollInterval=null),(e.x!==0||e.y!==0)&&(this.autoscrollInterval=window.setInterval(()=>{const s={left:1*i.x*e.x,top:1*i.y*e.y};this.useWindowAsScrollContainer?this._window.scrollBy(s.left,s.top):(this.scrollContainer.scrollTop+=s.top,this.scrollContainer.scrollLeft+=s.left),this.translate.x+=s.left,this.translate.y+=s.top,this.animateNodes()},5))}}}),G={beforeMount(t){t.sortableHandle=!0}},W=m.defineComponent({name:"SlickItem",mixins:[O],props:{tag:{type:String,default:"div"}},render(){var t,e;return m.h(this.tag,(e=(t=this.$slots).default)==null?void 0:e.call(t))}}),z=m.defineComponent({name:"SlickList",mixins:[k],props:{tag:{type:String,default:"div"},itemKey:{type:[String,Function],default:"id"}},render(){var t,e;return this.$slots.item?m.h(this.tag,this.list.map((i,n)=>{let s;if(i!=null){if(typeof this.itemKey=="function")s=this.itemKey(i);else if(typeof i=="object"&&I(i,this.itemKey)&&typeof i[this.itemKey]=="string")s=i[this.itemKey];else if(typeof i=="string")s=i;else throw new Error("Cannot find key for item, use the item-key prop and pass a function or string");return m.h(W,{key:s,index:n},{default:()=>{var r,o;return(o=(r=this.$slots).item)==null?void 0:o.call(r,{item:i,index:n})}})}})):m.h(this.tag,(e=(t=this.$slots).default)==null?void 0:e.call(t))}}),V=m.defineComponent({props:{tag:{type:String,default:"span"}},mounted(){this.$el.sortableHandle=!0},render(){var t,e;return m.h(this.tag,(e=(t=this.$slots).default)==null?void 0:e.call(t))}});let U=1;function J(t,e,i){return e.id===t.id?!0:t.block&&t.block.includes(e.group)?!1:typeof t.accept=="function"?t.accept({dest:t,source:e,payload:i}):typeof t.accept=="boolean"?t.accept:!!(t.accept&&t.accept.includes(e.group)||t.group===e.group)}function Q({x:t,y:e},i,n){if(H({x:t,y:e},n.container.getBoundingClientRect()))return n;let s=null,r=Infinity;for(let o=0;o<i.length;o++){const h=i[o],a=h.container.getBoundingClientRect();if(H({x:t,y:e},a))return h;const u=j(a),g=q(t,e,u.x,u.y);g<r&&(s=h,r=g)}return s}class Z{constructor(){this.helper=null,this.ghost=null,this.refs=[],this.source=null,this.dest=null}getId(){return""+U++}isSource({id:e}){var i;return((i=this.source)==null?void 0:i.id)===e}getSource(){return this.source}isDest({id:e}){var i;return((i=this.dest)==null?void 0:i.id)===e}getDest(){return this.dest}addContainer(e){this.refs.push(e)}removeContainer(e){this.refs=this.refs.filter(i=>i.id!==e.id)}sortStart(e){this.source=e,this.dest=e}handleSortMove(e,i){var n,s,r,o;const h=this.dest,a=this.source;if(!h||!a)return;const l=this.refs,u=w(e,"client"),g=Q(u,l,h)||h;h.id!==g.id&&J(g,a,i)&&(this.dest=g,h.handleDragOut(),g.handleDragIn(e,this.ghost,this.helper)),h.id!==((n=this.source)==null?void 0:n.id)&&((s=this.dest)==null||s.updatePosition(e),(r=this.dest)==null||r.animateNodes(),(o=this.dest)==null||o.autoscroll())}handleSortEnd(){var e,i,n,s;if(((e=this.source)==null?void 0:e.id)===((i=this.dest)==null?void 0:i.id))return;const r=(n=this.source)==null?void 0:n.handleDropOut();(s=this.dest)==null||s.handleDropIn(r),this.reset()}reset(){this.source=null,this.dest=null,this.helper=null,this.ghost=null}cancel(){var e;(e=this.dest)==null||e.handleDragEnd(),this.reset()}}const tt={install(t){t.directive("drag-handle",G),t.provide("SlicksortHub",new Z)}};p.ContainerMixin=k,p.DragHandle=V,p.ElementMixin=O,p.HandleDirective=G,p.SlickItem=W,p.SlickList=z,p.arrayMove=E,p.plugin=tt,Object.defineProperty(p,"__esModule",{value:!0})}); //# sourceMappingURL=vue-slicksort.min.js.map