react-sortable-hoc
Version:
Set of higher-order components to turn any list into a sortable, touch-friendly, animated list
2 lines (1 loc) • 27.4 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("react-dom"),require("prop-types")):"function"==typeof define&&define.amd?define(["exports","react","react-dom","prop-types"],t):t((e=e||self).SortableHOC={},e.React,e.ReactDOM,e.PropTypes)}(this,function(e,a,l,t){"use strict";function n(e,t){return e(t={exports:{}},t.exports),t.exports}t=t&&t.hasOwnProperty("default")?t.default:t;var s=n(function(e){function t(){return e.exports=t=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e},t.apply(this,arguments)}e.exports=t});var o=function(e){if(Array.isArray(e))return e};var r=function(e,t){var n=[],o=!0,r=!1,i=void 0;try{for(var a,l=e[Symbol.iterator]();!(o=(a=l.next()).done)&&(n.push(a.value),!t||n.length!==t);o=!0);}catch(e){r=!0,i=e}finally{try{o||null==l.return||l.return()}finally{if(r)throw i}}return n};var i=function(){throw new TypeError("Invalid attempt to destructure non-iterable instance")};var b=function(e,t){return o(e)||r(e,t)||i()};var c=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e};var D=function(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},o=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),o.forEach(function(e){c(t,e,n[e])})}return t};var d=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")};function u(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}var f=function(e,t,n){return t&&u(e.prototype,t),n&&u(e,n),e},h=n(function(t){function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function o(e){return"function"==typeof Symbol&&"symbol"===n(Symbol.iterator)?t.exports=o=function(e){return n(e)}:t.exports=o=function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":n(e)},o(e)}t.exports=o});var p=function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e};var y=function(e,t){return!t||"object"!==h(t)&&"function"!=typeof t?p(e):t},g=n(function(t){function n(e){return t.exports=n=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},n(e)}t.exports=n}),v=n(function(n){function o(e,t){return n.exports=o=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},o(e,t)}n.exports=o});var m=function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&v(e,t)},w=function(e,t,n,o,r,i,a,l){if(!e){var s;if(void 0===t)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var c=[n,o,r,i,a,l],d=0;(s=new Error(t.replace(/%s/g,function(){return c[d++]}))).name="Invariant Violation"}throw s.framesToPop=1,s}},x=function(){function e(){d(this,e),c(this,"refs",{})}return f(e,[{key:"add",value:function(e,t){this.refs[e]||(this.refs[e]=[]),this.refs[e].push(t)}},{key:"remove",value:function(e,t){var n=this.getIndex(e,t);-1!==n&&this.refs[e].splice(n,1)}},{key:"isActive",value:function(){return this.active}},{key:"getActive",value:function(){var t=this;return this.refs[this.active.collection].find(function(e){return e.node.sortableInfo.index==t.active.index})}},{key:"getIndex",value:function(e,t){return this.refs[e].indexOf(t)}},{key:"getOrderedRefs",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.active.collection;return this.refs[e].sort(S)}}]),e}();function S(e,t){return e.node.sortableInfo.index-t.node.sortableInfo.index}var O=function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}};var C=function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)};var T=function(){throw new TypeError("Invalid attempt to spread non-iterable instance")};var A=function(e){return O(e)||C(e)||T()};function I(n,o){return Object.keys(n).reduce(function(e,t){return-1===o.indexOf(t)&&(e[t]=n[t]),e},{})}var N={end:["touchend","touchcancel","mouseup"],move:["touchmove","mousemove"],start:["touchstart","mousedown"]},k=function(){if("undefined"==typeof window||"undefined"==typeof document)return"";var e=window.getComputedStyle(document.documentElement,"")||["-moz-hidden-iframe"],t=(Array.prototype.slice.call(e).join("").match(/-(moz|webkit|ms)-/)||""===e.OLink&&["","o"])[1];switch(t){case"ms":return"ms";default:return t&&t.length?t[0].toUpperCase()+t.substr(1):""}}();function M(t,n){Object.keys(n).forEach(function(e){t.style[e]=n[e]})}function E(e,t){e.style["".concat(k,"Transform")]=null==t?"":"translate3d(".concat(t.x,"px,").concat(t.y,"px,0)")}function W(e,t){e.style["".concat(k,"TransitionDuration")]=null==t?"":"".concat(t,"ms")}function P(e,t){for(;e;){if(t(e))return e;e=e.parentNode}return null}function R(e,t,n){return Math.max(e,Math.min(n,t))}function L(e){return"px"===e.substr(-2)?parseFloat(e):0}function j(e,t){var n=t.displayName||t.name;return n?"".concat(e,"(").concat(n,")"):e}function H(e,t){var n=e.getBoundingClientRect();return{top:n.top+t.top,left:n.left+t.left}}function K(e){return e.touches&&e.touches.length?{x:e.touches[0].pageX,y:e.touches[0].pageY}:e.changedTouches&&e.changedTouches.length?{x:e.changedTouches[0].pageX,y:e.changedTouches[0].pageY}:{x:e.pageX,y:e.pageY}}function G(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{left:0,top:0};if(e){var o={left:n.left+e.offsetLeft,top:n.top+e.offsetTop};return e.parentNode===t?o:G(e.parentNode,t,o)}}function _(e){var t=e.lockOffset,n=e.width,o=e.height,r=t,i=t,a="px";if("string"==typeof t){var l=/^[+-]?\d*(?:\.\d*)?(px|%)$/.exec(t);w(null!==l,'lockOffset value should be a number or a string of a number followed by "px" or "%". Given %s',t),r=parseFloat(t),i=parseFloat(t),a=l[1]}return w(isFinite(r)&&isFinite(i),"lockOffset value should be a finite. Given %s",t),"%"===a&&(r=r*n/100,i=i*o/100),{x:r,y:i}}function B(e){return e instanceof HTMLElement?(t=e,n=window.getComputedStyle(t),o=/(auto|scroll)/,["overflow","overflowX","overflowY"].find(function(e){return o.test(n[e])})?e:B(e.parentNode)):null;var t,n,o}var X=27,U=32,Y=37,F=38,V=39,q=40,z={Anchor:"A",Button:"BUTTON",Canvas:"CANVAS",Input:"INPUT",Option:"OPTION",Textarea:"TEXTAREA",Select:"SELECT"};function $(t){var e,n,o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{withRef:!1};return n=e=function(e){function i(){var e,t;d(this,i);for(var n=arguments.length,o=new Array(n),r=0;r<n;r++)o[r]=arguments[r];return t=y(this,(e=g(i)).call.apply(e,[this].concat(o))),c(p(p(t)),"wrappedInstance",a.createRef()),t}return m(i,e),f(i,[{key:"componentDidMount",value:function(){l.findDOMNode(this).sortableHandle=!0}},{key:"getWrappedInstance",value:function(){return w(o.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableHandle() call"),this.wrappedInstance.current}},{key:"render",value:function(){var e=o.withRef?this.wrappedInstance:null;return a.createElement(t,s({ref:e},this.props))}}]),i}(a.Component),c(e,"displayName",j("sortableHandle",t)),n}function J(e){return null!=e.sortableHandle}var Q=function(){function n(e,t){d(this,n),this.container=e,this.onScrollCallback=t}return f(n,[{key:"clear",value:function(){null!=this.interval&&(clearInterval(this.interval),this.interval=null)}},{key:"update",value:function(e){var t=this,n=e.translate,o=e.minTranslate,r=e.maxTranslate,i=e.width,a=e.height,l={x:0,y:0},s={x:1,y:1},c=10,d=10,u=this.container,f=u.scrollTop,h=u.scrollLeft,p=u.scrollHeight,y=u.scrollWidth,g=0===f,v=p-f-u.clientHeight==0,m=0===h,x=y-h-u.clientWidth==0;n.y>=r.y-a/2&&!v?(l.y=1,s.y=d*Math.abs((r.y-a/2-n.y)/a)):n.x>=r.x-i/2&&!x?(l.x=1,s.x=c*Math.abs((r.x-i/2-n.x)/i)):n.y<=o.y+a/2&&!g?(l.y=-1,s.y=d*Math.abs((n.y-a/2-o.y)/a)):n.x<=o.x+i/2&&!m&&(l.x=-1,s.x=c*Math.abs((n.x-i/2-o.x)/i)),this.interval&&(this.clear(),this.isAutoScrolling=!1),0===l.x&&0===l.y||(this.interval=setInterval(function(){t.isAutoScrolling=!0;var e={left:s.x*l.x,top:s.y*l.y};t.container.scrollTop+=e.top,t.container.scrollLeft+=e.left,t.onScrollCallback(e)},5))}}]),n}();var Z={axis:t.oneOf(["x","y","xy"]),contentWindow:t.any,disableAutoscroll:t.bool,distance:t.number,getContainer:t.func,getHelperDimensions:t.func,helperClass:t.string,helperContainer:t.oneOfType([t.func,"undefined"==typeof HTMLElement?t.any:t.instanceOf(HTMLElement)]),hideSortableGhost:t.bool,keyboardSortingTransitionDuration:t.number,lockAxis:t.string,lockOffset:t.oneOfType([t.number,t.string,t.arrayOf(t.oneOfType([t.number,t.string]))]),lockToContainerEdges:t.bool,onSortEnd:t.func,onSortMove:t.func,onSortOver:t.func,onSortStart:t.func,pressDelay:t.number,pressThreshold:t.number,keyCodes:t.shape({lift:t.arrayOf(t.number),drop:t.arrayOf(t.number),cancel:t.arrayOf(t.number),up:t.arrayOf(t.number),down:t.arrayOf(t.number)}),shouldCancelStart:t.func,transitionDuration:t.number,updateBeforeSortStart:t.func,useDragHandle:t.bool,useWindowAsScrollContainer:t.bool},ee={lift:[U],drop:[U],cancel:[X],up:[F,Y],down:[q,V]},te={axis:"y",disableAutoscroll:!1,distance:0,getHelperDimensions:function(e){var t=e.node;return{height:t.offsetHeight,width:t.offsetWidth}},hideSortableGhost:!0,lockOffset:"50%",lockToContainerEdges:!1,pressDelay:0,pressThreshold:5,keyCodes:ee,shouldCancelStart:function(e){return-1!==[z.Input,z.Textarea,z.Select,z.Option,z.Button].indexOf(e.target.tagName)||!!P(e.target,function(e){return"true"===e.contentEditable})},transitionDuration:300,useWindowAsScrollContainer:!1},ne=Object.keys(Z);var oe=a.createContext({manager:{}});function re(t){var e,n,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{withRef:!1};return n=e=function(e){function o(e){var R;d(this,o),R=y(this,g(o).call(this,e)),c(p(p(R)),"state",{}),c(p(p(R)),"handleStart",function(e){var t=R.props,n=t.distance,o=t.shouldCancelStart;if(2!==e.button&&!o(e)){R.touched=!0,R.position=K(e);var r,i=P(e.target,function(e){return null!=e.sortableInfo});if(i&&i.sortableInfo&&R.nodeIsChild(i)&&!R.state.sorting){var a=R.props.useDragHandle,l=i.sortableInfo,s=l.index,c=l.collection;if(l.disabled)return;if(a&&!P(e.target,J))return;R.manager.active={collection:c,index:s},(r=e).touches&&r.touches.length||r.changedTouches&&r.changedTouches.length||e.target.tagName!==z.Anchor||e.preventDefault(),n||(0===R.props.pressDelay?R.handlePress(e):R.pressTimer=setTimeout(function(){return R.handlePress(e)},R.props.pressDelay))}}}),c(p(p(R)),"nodeIsChild",function(e){return e.sortableInfo.manager===R.manager}),c(p(p(R)),"handleMove",function(e){var t=R.props,n=t.distance,o=t.pressThreshold;if(!R.state.sorting&&R.touched&&!R._awaitingUpdateBeforeSortStart){var r=K(e),i={x:R.position.x-r.x,y:R.position.y-r.y},a=Math.abs(i.x)+Math.abs(i.y);R.delta=i,n||o&&!(o<=a)?n&&n<=a&&R.manager.isActive()&&R.handlePress(e):(clearTimeout(R.cancelTimer),R.cancelTimer=setTimeout(R.cancel,0))}}),c(p(p(R)),"handleEnd",function(){R.touched=!1,R.cancel()}),c(p(p(R)),"cancel",function(){var e=R.props.distance;R.state.sorting||(e||clearTimeout(R.pressTimer),R.manager.active=null)}),c(p(p(R)),"handlePress",function(E){try{var r=R.manager.getActive(),e=function(){if(r){var e=function(){var e,t,n,o,r,i,a,l,s=T.sortableInfo.index,c=(e=T,{bottom:L((t=window.getComputedStyle(e)).marginBottom),left:L(t.marginLeft),right:L(t.marginRight),top:L(t.marginTop)}),d=(n=R.container,"grid"===(o=window.getComputedStyle(n)).display?{x:L(o.gridColumnGap),y:L(o.gridRowGap)}:{x:0,y:0}),u=R.scrollContainer.getBoundingClientRect(),f=b({index:s,node:T,collection:I});if(R.node=T,R.margin=c,R.gridGap=d,R.width=f.width,R.height=f.height,R.marginOffset={x:R.margin.left+R.margin.right+R.gridGap.x,y:Math.max(R.margin.top,R.margin.bottom,R.gridGap.y)},R.boundingClientRect=T.getBoundingClientRect(),R.containerBoundingRect=u,R.index=s,R.newIndex=s,R.axis={x:0<=x.indexOf("x"),y:0<=x.indexOf("y")},R.offsetEdge=G(T,R.container),R.initialOffset=K(k?D({},E,{pageX:R.boundingClientRect.left,pageY:R.boundingClientRect.top}):E),R.initialScroll={left:R.scrollContainer.scrollLeft,top:R.scrollContainer.scrollTop},R.initialWindowScroll={left:window.pageXOffset,top:window.pageYOffset},R.helper=R.helperContainer.appendChild((i="input, textarea, select, canvas, [contenteditable]",a=(r=T).querySelectorAll(i),l=r.cloneNode(!0),A(l.querySelectorAll(i)).forEach(function(e,t){"file"!==e.type&&(e.value=a[t].value),"radio"===e.type&&e.name&&(e.name="__sortableClone__".concat(e.name)),e.tagName===z.Canvas&&0<a[t].width&&0<a[t].height&&e.getContext("2d").drawImage(a[t],0,0)}),l)),M(R.helper,{boxSizing:"border-box",height:"".concat(R.height,"px"),left:"".concat(R.boundingClientRect.left-c.left,"px"),pointerEvents:"none",position:"fixed",top:"".concat(R.boundingClientRect.top-c.top,"px"),width:"".concat(R.width,"px")}),k&&R.helper.focus(),S&&M(R.sortableGhost=T,{opacity:0,visibility:"hidden"}),R.minTranslate={},R.maxTranslate={},k){var h=C?{top:0,left:0,width:R.contentWindow.innerWidth,height:R.contentWindow.innerHeight}:R.containerBoundingRect,p=h.top,y=h.left,g=h.width,v=p+h.height,m=y+g;R.axis.x&&(R.minTranslate.x=y-R.boundingClientRect.left,R.maxTranslate.x=m-(R.boundingClientRect.left+R.width)),R.axis.y&&(R.minTranslate.y=p-R.boundingClientRect.top,R.maxTranslate.y=v-(R.boundingClientRect.top+R.height))}else R.axis.x&&(R.minTranslate.x=(C?0:u.left)-R.boundingClientRect.left-R.width/2,R.maxTranslate.x=(C?R.contentWindow.innerWidth:u.left+u.width)-R.boundingClientRect.left-R.width/2),R.axis.y&&(R.minTranslate.y=(C?0:u.top)-R.boundingClientRect.top-R.height/2,R.maxTranslate.y=(C?R.contentWindow.innerHeight:u.top+u.height)-R.boundingClientRect.top-R.height/2);w&&w.split(" ").forEach(function(e){return R.helper.classList.add(e)}),R.listenerNode=E.touches?E.target:R.contentWindow,k?(R.listenerNode.addEventListener("wheel",R.handleKeyEnd,!0),R.listenerNode.addEventListener("mousedown",R.handleKeyEnd,!0),R.listenerNode.addEventListener("keydown",R.handleKeyDown)):(N.move.forEach(function(e){return R.listenerNode.addEventListener(e,R.handleSortMove,!1)}),N.end.forEach(function(e){return R.listenerNode.addEventListener(e,R.handleSortEnd,!1)})),R.setState({sorting:!0,sortingIndex:s}),O&&O({node:T,index:s,collection:I,isKeySorting:k,nodes:R.manager.getOrderedRefs(),helper:R.helper},E),k&&R.keyMove(0)},t=R.props,x=t.axis,b=t.getHelperDimensions,w=t.helperClass,S=t.hideSortableGhost,n=t.updateBeforeSortStart,O=t.onSortStart,C=t.useWindowAsScrollContainer,T=r.node,I=r.collection,k=R.manager.isKeySorting,o=function(){if("function"==typeof n){R._awaitingUpdateBeforeSortStart=!0;var e=function(e,t){try{var n=e()}catch(e){return t(!0,e)}return n&&n.then?n.then(t.bind(null,!1),t.bind(null,!0)):t(!1,value)}(function(){var e=T.sortableInfo.index;return Promise.resolve(n({collection:I,index:e,node:T,isKeySorting:k},E)).then(function(){})},function(e,t){if(R._awaitingUpdateBeforeSortStart=!1,e)throw t;return t});if(e&&e.then)return e.then(function(){})}}();return o&&o.then?o.then(e):e()}}();return Promise.resolve(e&&e.then?e.then(function(){}):void 0)}catch(e){return Promise.reject(e)}}),c(p(p(R)),"handleSortMove",function(e){var t=R.props.onSortMove;"function"==typeof e.preventDefault&&e.cancelable&&e.preventDefault(),R.updateHelperPosition(e),R.animateNodes(),R.autoscroll(),t&&t(e)}),c(p(p(R)),"handleSortEnd",function(e){var t=R.props,n=t.hideSortableGhost,o=t.onSortEnd,r=R.manager,i=r.active.collection,a=r.isKeySorting,l=R.manager.getOrderedRefs();R.listenerNode&&(a?(R.listenerNode.removeEventListener("wheel",R.handleKeyEnd,!0),R.listenerNode.removeEventListener("mousedown",R.handleKeyEnd,!0),R.listenerNode.removeEventListener("keydown",R.handleKeyDown)):(N.move.forEach(function(e){return R.listenerNode.removeEventListener(e,R.handleSortMove)}),N.end.forEach(function(e){return R.listenerNode.removeEventListener(e,R.handleSortEnd)}))),R.helper.parentNode.removeChild(R.helper),n&&R.sortableGhost&&M(R.sortableGhost,{opacity:"",visibility:""});for(var s=0,c=l.length;s<c;s++){var d=l[s],u=d.node;d.edgeOffset=null,E(u,d.boundingClientRect=null),W(u,null),d.translate=null}R.autoScroller.clear(),R.manager.active=null,R.manager.isKeySorting=!1,R.setState({sorting:!1,sortingIndex:null}),"function"==typeof o&&o({collection:i,newIndex:R.newIndex,oldIndex:R.index,isKeySorting:a,nodes:l},e),R.touched=!1}),c(p(p(R)),"autoscroll",function(){var e=R.props.disableAutoscroll,t=R.manager.isKeySorting;if(e)R.autoScroller.clear();else{if(t){var n=D({},R.translate),o=0,r=0;return R.axis.x&&(n.x=Math.min(R.maxTranslate.x,Math.max(R.minTranslate.x,R.translate.x)),o=R.translate.x-n.x),R.axis.y&&(n.y=Math.min(R.maxTranslate.y,Math.max(R.minTranslate.y,R.translate.y)),r=R.translate.y-n.y),R.translate=n,E(R.helper,R.translate),R.scrollContainer.scrollLeft+=o,void(R.scrollContainer.scrollTop+=r)}R.autoScroller.update({height:R.height,maxTranslate:R.maxTranslate,minTranslate:R.minTranslate,translate:R.translate,width:R.width})}}),c(p(p(R)),"onAutoScroll",function(e){R.translate.x+=e.left,R.translate.y+=e.top,R.animateNodes()}),c(p(p(R)),"handleKeyDown",function(e){var t=e.keyCode,n=R.props,o=n.shouldCancelStart,r=n.keyCodes,i=D({},ee,void 0===r?{}:r);R.manager.active&&!R.manager.isKeySorting||!(R.manager.active||i.lift.includes(t)&&!o(e)&&R.isValidSortingTarget(e))||(e.stopPropagation(),e.preventDefault(),i.lift.includes(t)&&!R.manager.active?R.keyLift(e):i.drop.includes(t)&&R.manager.active?R.keyDrop(e):i.cancel.includes(t)?(R.newIndex=R.manager.active.index,R.keyDrop(e)):i.up.includes(t)?R.keyMove(-1):i.down.includes(t)&&R.keyMove(1))}),c(p(p(R)),"keyLift",function(e){var t=e.target,n=P(t,function(e){return null!=e.sortableInfo}).sortableInfo,o=n.index,r=n.collection;R.initialFocusedNode=t,R.manager.isKeySorting=!0,R.manager.active={index:o,collection:r},R.handlePress(e)}),c(p(p(R)),"keyMove",function(e){var t=R.manager.getOrderedRefs(),n=t[t.length-1].node.sortableInfo.index,o=R.newIndex+e,r=R.newIndex;if(!(o<0||n<o)){R.prevIndex=r,R.newIndex=o;var i,a,l,s=(i=R.newIndex,a=R.prevIndex,l=R.index,i<l&&a<i?i-1:l<i&&i<a?i+1:i),c=t.find(function(e){return e.node.sortableInfo.index===s}),d=c.node,u=R.containerScrollDelta,f=c.boundingClientRect||H(d,u),h=c.translate||{x:0,y:0},p=f.top+h.y-u.top,y=f.left+h.x-u.left,g=r<o,v=g&&R.axis.x?d.offsetWidth-R.width:0,m=g&&R.axis.y?d.offsetHeight-R.height:0;R.handleSortMove({pageX:y+v,pageY:p+m,ignoreTransition:0===e})}}),c(p(p(R)),"keyDrop",function(e){R.handleSortEnd(e),R.initialFocusedNode&&R.initialFocusedNode.focus()}),c(p(p(R)),"handleKeyEnd",function(e){R.manager.active&&R.keyDrop(e)}),c(p(p(R)),"isValidSortingTarget",function(e){var t=R.props.useDragHandle,n=e.target,o=P(n,function(e){return null!=e.sortableInfo});return o&&o.sortableInfo&&!o.sortableInfo.disabled&&(t?J(n):n.sortableInfo)});var t,n=new x;return w(!((t=e).distance&&t.pressDelay),"Attempted to set both `pressDelay` and `distance` on SortableContainer, you may only use one or the other, not both at the same time."),R.manager=n,R.wrappedInstance=a.createRef(),R.sortableContextValue={manager:n},R.events={end:R.handleEnd,move:R.handleMove,start:R.handleStart},R}return m(o,e),f(o,[{key:"componentDidMount",value:function(){var n=this,o=this.props.useWindowAsScrollContainer,e=this.getContainer();Promise.resolve(e).then(function(e){n.container=e,n.document=n.container.ownerDocument||document;var t=n.props.contentWindow||n.document.defaultView||window;n.contentWindow="function"==typeof t?t():t,n.scrollContainer=o?n.document.scrollingElement||n.document.documentElement:B(n.container)||n.container,n.autoScroller=new Q(n.scrollContainer,n.onAutoScroll),Object.keys(n.events).forEach(function(t){return N[t].forEach(function(e){return n.container.addEventListener(e,n.events[t],!1)})}),n.container.addEventListener("keydown",n.handleKeyDown)})}},{key:"componentWillUnmount",value:function(){var n=this;this.helper&&this.helper.parentNode&&this.helper.parentNode.removeChild(this.helper),this.container&&(Object.keys(this.events).forEach(function(t){return N[t].forEach(function(e){return n.container.removeEventListener(e,n.events[t])})}),this.container.removeEventListener("keydown",this.handleKeyDown))}},{key:"updateHelperPosition",value:function(e){var t=this.props,n=t.lockAxis,o=t.lockOffset,r=t.lockToContainerEdges,i=t.transitionDuration,a=t.keyboardSortingTransitionDuration,l=void 0===a?i:a,s=this.manager.isKeySorting,c=e.ignoreTransition,d=K(e),u={x:d.x-this.initialOffset.x,y:d.y-this.initialOffset.y};if(u.y-=window.pageYOffset-this.initialWindowScroll.top,u.x-=window.pageXOffset-this.initialWindowScroll.left,this.translate=u,r){var f=function(e){var t=e.height,n=e.width,o=e.lockOffset,r=Array.isArray(o)?o:[o,o];w(2===r.length,"lockOffset prop of SortableContainer should be a single value or an array of exactly two values. Given %s",o);var i=b(r,2),a=i[0],l=i[1];return[_({height:t,lockOffset:a,width:n}),_({height:t,lockOffset:l,width:n})]}({height:this.height,lockOffset:o,width:this.width}),h=b(f,2),p=h[0],y=h[1],g=this.width/2-p.x,v=this.height/2-p.y,m=this.width/2-y.x,x=this.height/2-y.y;u.x=R(this.minTranslate.x+g,this.maxTranslate.x-m,u.x),u.y=R(this.minTranslate.y+v,this.maxTranslate.y-x,u.y)}"x"===n?u.y=0:"y"===n&&(u.x=0),s&&l&&!c&&W(this.helper,l),E(this.helper,u)}},{key:"animateNodes",value:function(){var e=this.props,t=e.transitionDuration,n=e.hideSortableGhost,o=e.onSortOver,r=this.containerScrollDelta,i=this.windowScrollDelta,a=this.manager.getOrderedRefs(),l=this.offsetEdge.left+this.translate.x+r.left,s=this.offsetEdge.top+this.translate.y+r.top,c=this.manager.isKeySorting,d=this.newIndex;this.newIndex=null;for(var u=0,f=a.length;u<f;u++){var h=a[u].node,p=h.sortableInfo.index,y=h.offsetWidth,g=h.offsetHeight,v=this.height>g?g/2:this.height/2,m=this.width>y?y/2:this.width/2,x=c&&p>this.index&&p<=d,b=c&&p<this.index&&d<=p,w={x:0,y:0},S=a[u].edgeOffset;S||(S=G(h,this.container),a[u].edgeOffset=S,c&&(a[u].boundingClientRect=H(h,r)));var O=u<a.length-1&&a[u+1],C=0<u&&a[u-1];O&&!O.edgeOffset&&(O.edgeOffset=G(O.node,this.container),c&&(O.boundingClientRect=H(O.node,r))),p!==this.index?(t&&W(h,t),this.axis.x?this.axis.y?b||p<this.index&&(l+i.left-m<=S.left&&s+i.top<=S.top+v||s+i.top+v<=S.top)?(w.x=this.width+this.marginOffset.x,S.left+w.x>this.containerBoundingRect.width-m&&O&&(w.x=O.edgeOffset.left-S.left,w.y=O.edgeOffset.top-S.top),null===this.newIndex&&(this.newIndex=p)):(x||p>this.index&&(l+i.left+m>=S.left&&s+i.top+v>=S.top||s+i.top+v>=S.top+g))&&(w.x=-(this.width+this.marginOffset.x),S.left+w.x<this.containerBoundingRect.left+m&&C&&(w.x=C.edgeOffset.left-S.left,w.y=C.edgeOffset.top-S.top),this.newIndex=p):x||p>this.index&&l+i.left+m>=S.left?(w.x=-(this.width+this.marginOffset.x),this.newIndex=p):(b||p<this.index&&l+i.left<=S.left+m)&&(w.x=this.width+this.marginOffset.x,null==this.newIndex&&(this.newIndex=p)):this.axis.y&&(x||p>this.index&&s+i.top+v>=S.top?(w.y=-(this.height+this.marginOffset.y),this.newIndex=p):(b||p<this.index&&s+i.top<=S.top+v)&&(w.y=this.height+this.marginOffset.y,null==this.newIndex&&(this.newIndex=p))),E(h,w),a[u].translate=w):n&&M(this.sortableGhost=h,{opacity:0,visibility:"hidden"})}null==this.newIndex&&(this.newIndex=this.index),c&&(this.newIndex=d);var T=c?this.prevIndex:d;o&&this.newIndex!==T&&o({collection:this.manager.active.collection,index:this.index,newIndex:this.newIndex,oldIndex:T,isKeySorting:c,nodes:a,helper:this.helper})}},{key:"getWrappedInstance",value:function(){return w(r.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableContainer() call"),this.wrappedInstance.current}},{key:"getContainer",value:function(){var e=this.props.getContainer;return"function"!=typeof e?l.findDOMNode(this):e(r.withRef?this.getWrappedInstance():void 0)}},{key:"render",value:function(){var e=r.withRef?this.wrappedInstance:null;return a.createElement(oe.Provider,{value:this.sortableContextValue},a.createElement(t,s({ref:e},I(this.props,ne))))}},{key:"helperContainer",get:function(){var e=this.props.helperContainer;return"function"==typeof e?e():this.props.helperContainer||this.document.body}},{key:"containerScrollDelta",get:function(){return this.props.useWindowAsScrollContainer?{left:0,top:0}:{left:this.scrollContainer.scrollLeft-this.initialScroll.left,top:this.scrollContainer.scrollTop-this.initialScroll.top}}},{key:"windowScrollDelta",get:function(){return{left:this.contentWindow.pageXOffset-this.initialWindowScroll.left,top:this.contentWindow.pageYOffset-this.initialWindowScroll.top}}}]),o}(a.Component),c(e,"displayName",j("sortableList",t)),c(e,"defaultProps",te),c(e,"propTypes",Z),n}var ie={index:t.number.isRequired,collection:t.oneOfType([t.number,t.string]),disabled:t.bool},ae=Object.keys(ie);function le(t){var e,n,o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{withRef:!1};return n=e=function(e){function i(){var e,t;d(this,i);for(var n=arguments.length,o=new Array(n),r=0;r<n;r++)o[r]=arguments[r];return t=y(this,(e=g(i)).call.apply(e,[this].concat(o))),c(p(p(t)),"wrappedInstance",a.createRef()),t}return m(i,e),f(i,[{key:"componentDidMount",value:function(){this.register()}},{key:"componentDidUpdate",value:function(e){this.node&&(e.index!==this.props.index&&(this.node.sortableInfo.index=this.props.index),e.disabled!==this.props.disabled&&(this.node.sortableInfo.disabled=this.props.disabled)),e.collection!==this.props.collection&&(this.unregister(e.collection),this.register())}},{key:"componentWillUnmount",value:function(){this.unregister()}},{key:"register",value:function(){var e=this.props,t=e.collection,n=e.disabled,o=e.index,r=l.findDOMNode(this);r.sortableInfo={collection:t,disabled:n,index:o,manager:this.context.manager},this.node=r,this.ref={node:r},this.context.manager.add(t,this.ref)}},{key:"unregister",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:this.props.collection;this.context.manager.remove(e,this.ref)}},{key:"getWrappedInstance",value:function(){return w(o.withRef,"To access the wrapped instance, you need to pass in {withRef: true} as the second argument of the SortableElement() call"),this.wrappedInstance.current}},{key:"render",value:function(){var e=o.withRef?this.wrappedInstance:null;return a.createElement(t,s({ref:e},I(this.props,ae)))}}]),i}(a.Component),c(e,"displayName",j("sortableElement",t)),c(e,"contextType",oe),c(e,"propTypes",ie),c(e,"defaultProps",{collection:0}),n}e.SortableContainer=re,e.sortableContainer=re,e.SortableElement=le,e.sortableElement=le,e.SortableHandle=$,e.sortableHandle=$,e.arrayMove=function(e,t,n){return(e=e.slice()).splice(n<0?e.length+n:n,0,e.splice(t,1)[0]),e},Object.defineProperty(e,"__esModule",{value:!0})});