qtsd-fork
Version:
Do not use this please
2 lines • 6.22 kB
JavaScript
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ReactDnDMouseMoveBackend=t():e.ReactDnDMouseMoveBackend=t()}(this,function(){return function(e){function t(o){if(n[o])return n[o].exports;var r=n[o]={exports:{},id:o,loaded:!1};return e[o].call(r.exports,r,r.exports,t),r.loaded=!0,r.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";function o(e){return e&&e.__esModule?e:{default:e}}Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),i=o(r),s=function(e){return new i.default(e)};t.default=s},function(e,t){"use strict";function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e){return{x:e.clientX,y:e.clientY}}function r(e){var t=e.nodeType===a?e:e.parentElement;if(!t)return null;var n=t.getBoundingClientRect(),o=n.top,r=n.left;return{x:r,y:o}}function i(e){return"which"in e?3===e.which:"button"in e&&2===e.button}Object.defineProperty(t,"__esModule",{value:!0});var s=function(){function e(e,t){var n=[],o=!0,r=!1,i=void 0;try{for(var s,u=e[Symbol.iterator]();!(o=(s=u.next()).done)&&(n.push(s.value),!t||n.length!==t);o=!0);}catch(e){r=!0,i=e}finally{try{!o&&u.return&&u.return()}finally{if(r)throw i}}return n}return function(t,n){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return e(t,n);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),u=function(){function e(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)}}return function(t,n,o){return n&&e(t.prototype,n),o&&e(t,o),t}}(),a=1,d=function(){function e(t){n(this,e),this.actions=t.getActions(),this.monitor=t.getMonitor(),this.registry=t.getRegistry(),this.sourceNodes={},this.sourceNodesOptions={},this.sourcePreviewNodes={},this.sourcePreviewNodesOptions={},this.targetNodes={},this.targetNodeOptions={},this.mouseClientOffset={},this.getSourceClientOffset=this.getSourceClientOffset.bind(this),this.handleWindowMoveStart=this.handleWindowMoveStart.bind(this),this.handleWindowMoveStartCapture=this.handleWindowMoveStartCapture.bind(this),this.handleWindowMoveCapture=this.handleWindowMoveCapture.bind(this),this.handleWindowMoveEndCapture=this.handleWindowMoveEndCapture.bind(this)}return u(e,[{key:"setup",value:function(){if("undefined"!=typeof window){if(this.constructor.isSetUp)throw new Error("Cannot have two DnD Mouse backend at the same time");this.constructor.isSetUp=!0,window.addEventListener("mousedown",this.handleWindowMoveStartCapture,!0),window.addEventListener("mousedown",this.handleWindowMoveStart),window.addEventListener("mousemove",this.handleWindowMoveCapture,!0),window.addEventListener("mouseup",this.handleWindowMoveEndCapture,!0)}}},{key:"getSourceClientOffset",value:function(e){return r(this.sourceNodes[e])}},{key:"teardown",value:function(){"undefined"!=typeof window&&(this.constructor.isSetUp=!1,this.mouseClientOffset={},window.removeEventListener("mousedown",this.handleWindowMoveStartCapture,!0),window.removeEventListener("mousedown",this.handleWindowMoveStart),window.removeEventListener("mousemove",this.handleWindowMoveCapture,!0),window.removeEventListener("mouseup",this.handleWindowMoveEndCapture,!0))}},{key:"connectDragSource",value:function(e,t){var n=this;this.sourceNodes[e]=t;var o=this.handleMoveStart.bind(this,e);return t.addEventListener("mousedown",o),function(){delete n.sourceNodes[e],t.removeEventListener("mousedown",o)}}},{key:"connectDragPreview",value:function(e,t,n){var o=this;return this.sourcePreviewNodesOptions[e]=n,this.sourcePreviewNodes[e]=t,function(){delete o.sourcePreviewNodes[e],delete o.sourcePreviewNodesOptions[e]}}},{key:"connectDropTarget",value:function(e,t){var n=this;return this.targetNodes[e]=t,function(){delete n.targetNodes[e]}}},{key:"handleWindowMoveStartCapture",value:function(){this.moveStartSourceIds=[]}},{key:"handleMoveStart",value:function(e,t){i(t)||this.moveStartSourceIds.unshift(e)}},{key:"handleWindowMoveStart",value:function(e){var t=o(e);t&&(this.mouseClientOffset=t)}},{key:"handleWindowMoveCapture",value:function(e){var t=this.moveStartSourceIds,n=o(e);if(n&&(this.monitor.isDragging()||!this.mouseClientOffset.hasOwnProperty("x")||!t||this.mouseClientOffset.x===n.x&&this.mouseClientOffset.y===n.y||(this.moveStartSourceIds=null,this.actions.beginDrag(t,{clientOffset:this.mouseClientOffset,getSourceClientOffset:this.getSourceClientOffset,publishSource:!1})),this.monitor.isDragging())){var r=this.sourceNodes[this.monitor.getSourceId()];this.installSourceNodeRemovalObserver(r),this.actions.publishDragSource(),e.preventDefault();var i=Object.entries(this.targetNodes).filter(function(t){var n=s(t,2),o=n[1];return o.contains(e.target)}).sort(function(e,t){var n=s(e,2),o=n[1],r=s(t,2),i=r[1];return o.contains(i)?-1:1}).map(function(e){var t=s(e,1),n=t[0];return n});this.actions.hover(i,{clientOffset:n})}}},{key:"handleWindowMoveEndCapture",value:function(e){return!this.monitor.isDragging()||this.monitor.didDrop()?void(this.moveStartSourceIds=null):(e.preventDefault(),this.mouseClientOffset={},this.uninstallSourceNodeRemovalObserver(),this.actions.drop(),void this.actions.endDrag())}},{key:"installSourceNodeRemovalObserver",value:function(e){var t=this;this.uninstallSourceNodeRemovalObserver(),this.draggedSourceNode=e,this.draggedSourceNodeRemovalObserver=new window.MutationObserver(function(){e.parentElement||(t.resurrectSourceNode(),t.uninstallSourceNodeRemovalObserver())}),e&&e.parentElement&&this.draggedSourceNodeRemovalObserver.observe(e.parentElement,{childList:!0})}},{key:"resurrectSourceNode",value:function(){this.draggedSourceNode.style.display="none",this.draggedSourceNode.removeAttribute("data-reactid"),document.body.appendChild(this.draggedSourceNode)}},{key:"uninstallSourceNodeRemovalObserver",value:function(){this.draggedSourceNodeRemovalObserver&&this.draggedSourceNodeRemovalObserver.disconnect(),this.draggedSourceNodeRemovalObserver=null,this.draggedSourceNode=null}}]),e}();t.default=d}])});
//# sourceMappingURL=ReactDnDMouseMoveBackend.min.js.map