UNPKG

@edorivai/react-smooth-dnd

Version:
2 lines (1 loc) 5.86 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react"),require("prop-types"),require("smooth-dnd")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","smooth-dnd"],t):t((e=e||self).ReactSmoothDnD={},e.React,e.PropTypes,e.SmoothDnD)}(this,function(t,r,e,o){"use strict";var i="default"in r?r.default:r;function a(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function s(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function c(e,t,n){t&&s(e.prototype,t),n&&s(e,n),Object.defineProperty(e,"prototype",{writable:!1})}function p(e,t,n){t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n}function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n,r=arguments[t];for(n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e}).apply(this,arguments)}function u(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}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&f(e,t)}function l(e){return(l=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function f(e,t){return(f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e})(e,t)}function h(e,t){if(null==e)return{};var n,r=function(e,t){if(null==e)return{};for(var n,r={},o=Object.keys(e),i=0;i<o.length;i++)n=o[i],0<=t.indexOf(n)||(r[n]=e[n]);return r}(e,t);if(Object.getOwnPropertySymbols)for(var o=Object.getOwnPropertySymbols(e),i=0;i<o.length;i++)n=o[i],0<=t.indexOf(n)||Object.prototype.propertyIsEnumerable.call(e,n)&&(r[n]=e[n]);return r}function d(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function y(n){var r=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(e){return!1}}();return function(){var e,t=l(n),t=(e=r?(e=l(this).constructor,Reflect.construct(t,arguments,e)):t.apply(this,arguments),this);if(e&&("object"==typeof e||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return d(t)}}e=e&&e.hasOwnProperty("default")?e.default:e;var b=["render","children","style"],g=(o.smoothDnD.dropHandler=o.dropHandlers.reactDropHandler().handler,o.smoothDnD.wrapChild=!1,function(){u(n,r.Component);var t=y(n);function n(e){return a(this,n),p(d(e=t.call(this,e)),"prevContainer",void 0),p(d(e),"container",null),p(d(e),"containerRef",i.createRef()),e.getContainerOptions=e.getContainerOptions.bind(d(e)),e.getContainer=e.getContainer.bind(d(e)),e.isObjectTypePropsChanged=e.isObjectTypePropsChanged.bind(d(e)),e.prevContainer=null,e}return c(n,[{key:"componentDidMount",value:function(){this.prevContainer=this.getContainer(),this.container=o.smoothDnD(this.getContainer(),this.getContainerOptions())}},{key:"componentWillUnmount",value:function(){this.container.dispose(),this.container=null}},{key:"componentDidUpdate",value:function(e){this.getContainer()&&(this.prevContainer&&this.prevContainer!==this.getContainer()?(this.container.dispose(),this.container=o.smoothDnD(this.getContainer(),this.getContainerOptions()),this.prevContainer=this.getContainer()):this.isObjectTypePropsChanged(e)&&this.container.setOptions(this.getContainerOptions()))}},{key:"isObjectTypePropsChanged",value:function(e){var t,n=this.props,r=(n.render,n.children,n.style,h(n,b));for(t in r){var o=t;if(r.hasOwnProperty(o)){var i=r[o];if("function"!=typeof i&&i!==e[o])return!0}}return!1}},{key:"render",value:function(){return this.props.render?this.props.render(this.containerRef):i.createElement("div",{style:this.props.style,ref:this.containerRef},this.props.children)}},{key:"getContainer",value:function(){return this.containerRef.current}},{key:"getContainerOptions",value:function(){var r=this;return Object.keys(this.props).reduce(function(e,t){var n=t,t=r.props[n];return e[n]="function"==typeof t?function(){var e;return(e=r.props)[n].apply(e,arguments)}:t,e},{})}}]),n}()),v=(p(g,"propTypes",{behaviour:e.oneOf(["move","copy","drop-zone","contain"]),groupName:e.string,orientation:e.oneOf(["horizontal","vertical"]),style:e.object,dragHandleSelector:e.string,nonDragAreaSelector:e.string,dragBeginDelay:e.number,animationDuration:e.number,autoScrollEnabled:e.bool,lockAxis:e.string,dragClass:e.string,dropClass:e.string,onDragStart:e.func,onDragEnd:e.func,onDrop:e.func,getChildPayload:e.func,shouldAnimateDrop:e.func,shouldAcceptDrop:e.func,onDragEnter:e.func,onDragLeave:e.func,render:e.func,getGhostParent:e.func,removeOnDropOut:e.bool,dropPlaceholder:e.oneOfType([e.shape({className:e.string,animationDuration:e.number,showOnTop:e.bool}),e.bool])}),p(g,"defaultProps",{behaviour:"move",orientation:"vertical"}),o.constants.wrapperClass),O=function(){u(t,r.Component);var e=y(t);function t(){return a(this,t),e.apply(this,arguments)}return c(t,[{key:"render",value:function(){var e;return this.props.render?i.cloneElement(this.props.render(),{className:v}):(e="".concat(this.props.className?this.props.className+" ":""),i.createElement("div",n({},this.props,{className:"".concat(e).concat(v)}),this.props.children))}}]),t}();p(O,"propsTypes",{render:e.func,className:e.string}),Object.keys(o).forEach(function(e){t[e]=o[e]}),t.Container=g,t.Draggable=O,Object.defineProperty(t,"__esModule",{value:!0})});