react-dnd-touch-backend
Advanced tools
Comparing version 14.1.0 to 14.1.1
@@ -5,3 +5,3 @@ (function (global, factory) { | ||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactDnDTouchBackend = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
})(this, (function (exports) { 'use strict'; | ||
@@ -150,2 +150,20 @@ /** | ||
var supportsPassive = function () { | ||
// simular to jQuery's test | ||
var supported = false; | ||
try { | ||
addEventListener('test', function () {// do nothing | ||
}, Object.defineProperty({}, 'passive', { | ||
get: function get() { | ||
supported = true; | ||
return true; | ||
} | ||
})); | ||
} catch (e) {// do nothing | ||
} | ||
return supported; | ||
}(); | ||
function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -669,3 +687,6 @@ | ||
value: function addEventListener(subject, event, handler, capture) { | ||
var options = capture; | ||
var options = supportsPassive ? { | ||
capture: capture, | ||
passive: false | ||
} : capture; | ||
this.listenerTypes.forEach(function (listenerType) { | ||
@@ -682,3 +703,6 @@ var evt = eventNames[listenerType][event]; | ||
value: function removeEventListener(subject, event, handler, capture) { | ||
var options = capture; | ||
var options = supportsPassive ? { | ||
capture: capture, | ||
passive: false | ||
} : capture; | ||
this.listenerTypes.forEach(function (listenerType) { | ||
@@ -854,2 +878,2 @@ var evt = eventNames[listenerType][event]; | ||
}))); | ||
})); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactDnDTouchBackend={})}(this,(function(e){"use strict";var t;e.ListenerType=void 0,(t=e.ListenerType||(e.ListenerType={})).mouse="mouse",t.touch="touch",t.keyboard="keyboard";function o(e){return void 0===e.button||0===e.button}function n(e){return!!e.targetTouches}function r(e,t){return n(e)?function(e,t){return 1===e.targetTouches.length?r(e.targetTouches[0]):t&&1===e.touches.length&&e.touches[0].target===t.target?r(e.touches[0]):void 0}(e,t):{x:e.clientX,y:e.clientY}}function i(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function s(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var a,u=function(){function e(t,o){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),s(this,"args",void 0),s(this,"context",void 0),this.args=t,this.context=o}var t,o;return t=e,(o=[{key:"delay",get:function(){var e;return null!==(e=this.args.delay)&&void 0!==e?e:0}},{key:"scrollAngleRanges",get:function(){return this.args.scrollAngleRanges}},{key:"getDropTargetElementsAtPoint",get:function(){return this.args.getDropTargetElementsAtPoint}},{key:"ignoreContextMenu",get:function(){var e;return null!==(e=this.args.ignoreContextMenu)&&void 0!==e&&e}},{key:"enableHoverOutsideTarget",get:function(){var e;return null!==(e=this.args.enableHoverOutsideTarget)&&void 0!==e&&e}},{key:"enableKeyboardEvents",get:function(){var e;return null!==(e=this.args.enableKeyboardEvents)&&void 0!==e&&e}},{key:"enableMouseEvents",get:function(){var e;return null!==(e=this.args.enableMouseEvents)&&void 0!==e&&e}},{key:"enableTouchEvents",get:function(){var e;return null===(e=this.args.enableTouchEvents)||void 0===e||e}},{key:"touchSlop",get:function(){return this.args.touchSlop||0}},{key:"delayTouchStart",get:function(){var e,t,o,n;return null!==(e=null!==(t=null===(o=this.args)||void 0===o?void 0:o.delayTouchStart)&&void 0!==t?t:null===(n=this.args)||void 0===n?void 0:n.delay)&&void 0!==e?e:0}},{key:"delayMouseStart",get:function(){var e,t,o,n;return null!==(e=null!==(t=null===(o=this.args)||void 0===o?void 0:o.delayMouseStart)&&void 0!==t?t:null===(n=this.args)||void 0===n?void 0:n.delay)&&void 0!==e?e:0}},{key:"window",get:function(){return this.context&&this.context.window?this.context.window:"undefined"!=typeof window?window:void 0}},{key:"document",get:function(){var e;return null!==(e=this.context)&&void 0!==e&&e.document?this.context.document:this.window?this.window.document:void 0}},{key:"rootElement",get:function(){var e;return(null===(e=this.args)||void 0===e?void 0:e.rootElement)||this.document}}])&&i(t.prototype,o),e}();function d(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function l(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var c=(l(a={},e.ListenerType.mouse,{start:"mousedown",move:"mousemove",end:"mouseup",contextmenu:"contextmenu"}),l(a,e.ListenerType.touch,{start:"touchstart",move:"touchmove",end:"touchend"}),l(a,e.ListenerType.keyboard,{keydown:"keydown"}),a),v=function(){function t(i,s,a){var d=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),l(this,"options",void 0),l(this,"actions",void 0),l(this,"monitor",void 0),l(this,"sourceNodes",void 0),l(this,"sourcePreviewNodes",void 0),l(this,"sourcePreviewNodeOptions",void 0),l(this,"targetNodes",void 0),l(this,"_mouseClientOffset",void 0),l(this,"_isScrolling",void 0),l(this,"listenerTypes",void 0),l(this,"moveStartSourceIds",void 0),l(this,"waitingForDelay",void 0),l(this,"timeout",void 0),l(this,"dragOverTargetIds",void 0),l(this,"draggedSourceNode",void 0),l(this,"draggedSourceNodeRemovalObserver",void 0),l(this,"lastTargetTouchFallback",void 0),l(this,"getSourceClientOffset",(function(e){var t=d.sourceNodes.get(e);return t&&function(e){var t=1===e.nodeType?e:e.parentElement;if(t){var o=t.getBoundingClientRect(),n=o.top;return{x:o.left,y:n}}}(t)})),l(this,"handleTopMoveStartCapture",(function(e){o(e)&&(d.moveStartSourceIds=[])})),l(this,"handleMoveStart",(function(e){Array.isArray(d.moveStartSourceIds)&&d.moveStartSourceIds.unshift(e)})),l(this,"handleTopMoveStart",(function(e){if(o(e)){var t=r(e);t&&(n(e)&&(d.lastTargetTouchFallback=e.targetTouches[0]),d._mouseClientOffset=t),d.waitingForDelay=!1}})),l(this,"handleTopMoveStartDelay",(function(e){if(o(e)){var t=e.type===c.touch.start?d.options.delayTouchStart:d.options.delayMouseStart;d.timeout=setTimeout(d.handleTopMoveStart.bind(d,e),t),d.waitingForDelay=!0}})),l(this,"handleTopMoveCapture",(function(){d.dragOverTargetIds=[]})),l(this,"handleMove",(function(e,t){d.dragOverTargetIds&&d.dragOverTargetIds.unshift(t)})),l(this,"handleTopMove",(function(e){if(d.timeout&&clearTimeout(d.timeout),d.document&&!d.waitingForDelay){var t,o,n,i,s=d.moveStartSourceIds,a=d.dragOverTargetIds,u=d.options.enableHoverOutsideTarget,l=r(e,d.lastTargetTouchFallback);if(l)if(d._isScrolling||!d.monitor.isDragging()&&function(e,t,o,n,r){if(!r)return!1;for(var i=180*Math.atan2(n-t,o-e)/Math.PI+180,s=0;s<r.length;++s)if((null==r[s].start||i>=r[s].start)&&(null==r[s].end||i<=r[s].end))return!0;return!1}(d._mouseClientOffset.x||0,d._mouseClientOffset.y||0,l.x,l.y,d.options.scrollAngleRanges))d._isScrolling=!0;else if(!d.monitor.isDragging()&&d._mouseClientOffset.hasOwnProperty("x")&&s&&(t=d._mouseClientOffset.x||0,o=d._mouseClientOffset.y||0,n=l.x,i=l.y,Math.sqrt(Math.pow(Math.abs(n-t),2)+Math.pow(Math.abs(i-o),2))>(d.options.touchSlop?d.options.touchSlop:0))&&(d.moveStartSourceIds=void 0,d.actions.beginDrag(s,{clientOffset:d._mouseClientOffset,getSourceClientOffset:d.getSourceClientOffset,publishSource:!1})),d.monitor.isDragging()){var c=d.sourceNodes.get(d.monitor.getSourceId());d.installSourceNodeRemovalObserver(c),d.actions.publishDragSource(),e.cancelable&&e.preventDefault();var v=(a||[]).map((function(e){return d.targetNodes.get(e)})).filter((function(e){return!!e})),h=d.options.getDropTargetElementsAtPoint?d.options.getDropTargetElementsAtPoint(l.x,l.y,v):d.document.elementsFromPoint(l.x,l.y),g=[];for(var f in h)if(h.hasOwnProperty(f)){var p=h[f];for(g.push(p);p;)(p=p.parentElement)&&-1===g.indexOf(p)&&g.push(p)}var m=g.filter((function(e){return v.indexOf(e)>-1})).map((function(e){return d._getDropTargetId(e)})).filter((function(e){return!!e})).filter((function(e,t,o){return o.indexOf(e)===t}));if(u)for(var y in d.targetNodes){var b=d.targetNodes.get(y);if(c&&b&&b.contains(c)&&-1===m.indexOf(y)){m.unshift(y);break}}m.reverse(),d.actions.hover(m,{clientOffset:l})}}})),l(this,"_getDropTargetId",(function(e){for(var t=d.targetNodes.keys(),o=t.next();!1===o.done;){var n=o.value;if(e===d.targetNodes.get(n))return n;o=t.next()}})),l(this,"handleTopMoveEndCapture",(function(e){d._isScrolling=!1,d.lastTargetTouchFallback=void 0,function(e){return void 0===e.buttons||0==(1&e.buttons)}(e)&&(d.monitor.isDragging()&&!d.monitor.didDrop()?(e.cancelable&&e.preventDefault(),d._mouseClientOffset={},d.uninstallSourceNodeRemovalObserver(),d.actions.drop(),d.actions.endDrag()):d.moveStartSourceIds=void 0)})),l(this,"handleCancelOnEscape",(function(e){"Escape"===e.key&&d.monitor.isDragging()&&(d._mouseClientOffset={},d.uninstallSourceNodeRemovalObserver(),d.actions.endDrag())})),this.options=new u(a,s),this.actions=i.getActions(),this.monitor=i.getMonitor(),this.sourceNodes=new Map,this.sourcePreviewNodes=new Map,this.sourcePreviewNodeOptions=new Map,this.targetNodes=new Map,this.listenerTypes=[],this._mouseClientOffset={},this._isScrolling=!1,this.options.enableMouseEvents&&this.listenerTypes.push(e.ListenerType.mouse),this.options.enableTouchEvents&&this.listenerTypes.push(e.ListenerType.touch),this.options.enableKeyboardEvents&&this.listenerTypes.push(e.ListenerType.keyboard)}var i,s;return i=t,(s=[{key:"profile",value:function(){var e;return{sourceNodes:this.sourceNodes.size,sourcePreviewNodes:this.sourcePreviewNodes.size,sourcePreviewNodeOptions:this.sourcePreviewNodeOptions.size,targetNodes:this.targetNodes.size,dragOverTargetIds:(null===(e=this.dragOverTargetIds)||void 0===e?void 0:e.length)||0}}},{key:"document",get:function(){return this.options.document}},{key:"setup",value:function(){var e=this.options.rootElement;e&&(function(e,t){for(var o=arguments.length,n=new Array(o>2?o-2:0),r=2;r<o;r++)n[r-2]=arguments[r];if(!e){var i;if(void 0===t)i=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=0;(i=new Error(t.replace(/%s/g,(function(){return n[s++]})))).name="Invariant Violation"}throw i.framesToPop=1,i}}(!t.isSetUp,"Cannot have two Touch backends at the same time."),t.isSetUp=!0,this.addEventListener(e,"start",this.getTopMoveStartHandler()),this.addEventListener(e,"start",this.handleTopMoveStartCapture,!0),this.addEventListener(e,"move",this.handleTopMove),this.addEventListener(e,"move",this.handleTopMoveCapture,!0),this.addEventListener(e,"end",this.handleTopMoveEndCapture,!0),this.options.enableMouseEvents&&!this.options.ignoreContextMenu&&this.addEventListener(e,"contextmenu",this.handleTopMoveEndCapture),this.options.enableKeyboardEvents&&this.addEventListener(e,"keydown",this.handleCancelOnEscape,!0))}},{key:"teardown",value:function(){var e=this.options.rootElement;e&&(t.isSetUp=!1,this._mouseClientOffset={},this.removeEventListener(e,"start",this.handleTopMoveStartCapture,!0),this.removeEventListener(e,"start",this.handleTopMoveStart),this.removeEventListener(e,"move",this.handleTopMoveCapture,!0),this.removeEventListener(e,"move",this.handleTopMove),this.removeEventListener(e,"end",this.handleTopMoveEndCapture,!0),this.options.enableMouseEvents&&!this.options.ignoreContextMenu&&this.removeEventListener(e,"contextmenu",this.handleTopMoveEndCapture),this.options.enableKeyboardEvents&&this.removeEventListener(e,"keydown",this.handleCancelOnEscape,!0),this.uninstallSourceNodeRemovalObserver())}},{key:"addEventListener",value:function(e,t,o,n){var r=n;this.listenerTypes.forEach((function(n){var i=c[n][t];i&&e.addEventListener(i,o,r)}))}},{key:"removeEventListener",value:function(e,t,o,n){var r=n;this.listenerTypes.forEach((function(n){var i=c[n][t];i&&e.removeEventListener(i,o,r)}))}},{key:"connectDragSource",value:function(e,t){var o=this,n=this.handleMoveStart.bind(this,e);return this.sourceNodes.set(e,t),this.addEventListener(t,"start",n),function(){o.sourceNodes.delete(e),o.removeEventListener(t,"start",n)}}},{key:"connectDragPreview",value:function(e,t,o){var n=this;return this.sourcePreviewNodeOptions.set(e,o),this.sourcePreviewNodes.set(e,t),function(){n.sourcePreviewNodes.delete(e),n.sourcePreviewNodeOptions.delete(e)}}},{key:"connectDropTarget",value:function(e,t){var o=this,n=this.options.rootElement;if(!this.document||!n)return function(){};var r=function(r){if(o.document&&n&&o.monitor.isDragging()){var i;switch(r.type){case c.mouse.move:i={x:r.clientX,y:r.clientY};break;case c.touch.move:i={x:r.touches[0].clientX,y:r.touches[0].clientY}}var s=null!=i?o.document.elementFromPoint(i.x,i.y):void 0,a=s&&t.contains(s);return s===t||a?o.handleMove(r,e):void 0}};return this.addEventListener(this.document.body,"move",r),this.targetNodes.set(e,t),function(){o.document&&(o.targetNodes.delete(e),o.removeEventListener(o.document.body,"move",r))}}},{key:"getTopMoveStartHandler",value:function(){return this.options.delayTouchStart||this.options.delayMouseStart?this.handleTopMoveStartDelay:this.handleTopMoveStart}},{key:"installSourceNodeRemovalObserver",value:function(e){var t=this;this.uninstallSourceNodeRemovalObserver(),this.draggedSourceNode=e,this.draggedSourceNodeRemovalObserver=new MutationObserver((function(){e&&!e.parentElement&&(t.resurrectSourceNode(),t.uninstallSourceNodeRemovalObserver())})),e&&e.parentElement&&this.draggedSourceNodeRemovalObserver.observe(e.parentElement,{childList:!0})}},{key:"resurrectSourceNode",value:function(){this.document&&this.draggedSourceNode&&(this.draggedSourceNode.style.display="none",this.draggedSourceNode.removeAttribute("data-reactid"),this.document.body.appendChild(this.draggedSourceNode))}},{key:"uninstallSourceNodeRemovalObserver",value:function(){this.draggedSourceNodeRemovalObserver&&this.draggedSourceNodeRemovalObserver.disconnect(),this.draggedSourceNodeRemovalObserver=void 0,this.draggedSourceNode=void 0}}])&&d(i.prototype,s),t}();l(v,"isSetUp",void 0),e.TouchBackend=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new v(e,t,o)},e.TouchBackendImpl=v,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactDnDTouchBackend={})}(this,(function(e){"use strict";var t;e.ListenerType=void 0,(t=e.ListenerType||(e.ListenerType={})).mouse="mouse",t.touch="touch",t.keyboard="keyboard";function o(e){return void 0===e.button||0===e.button}function n(e){return!!e.targetTouches}function r(e,t){return n(e)?function(e,t){return 1===e.targetTouches.length?r(e.targetTouches[0]):t&&1===e.touches.length&&e.touches[0].target===t.target?r(e.touches[0]):void 0}(e,t):{x:e.clientX,y:e.clientY}}var i=function(){var e=!1;try{addEventListener("test",(function(){}),Object.defineProperty({},"passive",{get:function(){return e=!0,!0}}))}catch(e){}return e}();function s(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function a(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var u,d=function(){function e(t,o){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),a(this,"args",void 0),a(this,"context",void 0),this.args=t,this.context=o}var t,o;return t=e,(o=[{key:"delay",get:function(){var e;return null!==(e=this.args.delay)&&void 0!==e?e:0}},{key:"scrollAngleRanges",get:function(){return this.args.scrollAngleRanges}},{key:"getDropTargetElementsAtPoint",get:function(){return this.args.getDropTargetElementsAtPoint}},{key:"ignoreContextMenu",get:function(){var e;return null!==(e=this.args.ignoreContextMenu)&&void 0!==e&&e}},{key:"enableHoverOutsideTarget",get:function(){var e;return null!==(e=this.args.enableHoverOutsideTarget)&&void 0!==e&&e}},{key:"enableKeyboardEvents",get:function(){var e;return null!==(e=this.args.enableKeyboardEvents)&&void 0!==e&&e}},{key:"enableMouseEvents",get:function(){var e;return null!==(e=this.args.enableMouseEvents)&&void 0!==e&&e}},{key:"enableTouchEvents",get:function(){var e;return null===(e=this.args.enableTouchEvents)||void 0===e||e}},{key:"touchSlop",get:function(){return this.args.touchSlop||0}},{key:"delayTouchStart",get:function(){var e,t,o,n;return null!==(e=null!==(t=null===(o=this.args)||void 0===o?void 0:o.delayTouchStart)&&void 0!==t?t:null===(n=this.args)||void 0===n?void 0:n.delay)&&void 0!==e?e:0}},{key:"delayMouseStart",get:function(){var e,t,o,n;return null!==(e=null!==(t=null===(o=this.args)||void 0===o?void 0:o.delayMouseStart)&&void 0!==t?t:null===(n=this.args)||void 0===n?void 0:n.delay)&&void 0!==e?e:0}},{key:"window",get:function(){return this.context&&this.context.window?this.context.window:"undefined"!=typeof window?window:void 0}},{key:"document",get:function(){var e;return null!==(e=this.context)&&void 0!==e&&e.document?this.context.document:this.window?this.window.document:void 0}},{key:"rootElement",get:function(){var e;return(null===(e=this.args)||void 0===e?void 0:e.rootElement)||this.document}}])&&s(t.prototype,o),e}();function l(e,t){for(var o=0;o<t.length;o++){var n=t[o];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function c(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var v=(c(u={},e.ListenerType.mouse,{start:"mousedown",move:"mousemove",end:"mouseup",contextmenu:"contextmenu"}),c(u,e.ListenerType.touch,{start:"touchstart",move:"touchmove",end:"touchend"}),c(u,e.ListenerType.keyboard,{keydown:"keydown"}),u),h=function(){function t(i,s,a){var u=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),c(this,"options",void 0),c(this,"actions",void 0),c(this,"monitor",void 0),c(this,"sourceNodes",void 0),c(this,"sourcePreviewNodes",void 0),c(this,"sourcePreviewNodeOptions",void 0),c(this,"targetNodes",void 0),c(this,"_mouseClientOffset",void 0),c(this,"_isScrolling",void 0),c(this,"listenerTypes",void 0),c(this,"moveStartSourceIds",void 0),c(this,"waitingForDelay",void 0),c(this,"timeout",void 0),c(this,"dragOverTargetIds",void 0),c(this,"draggedSourceNode",void 0),c(this,"draggedSourceNodeRemovalObserver",void 0),c(this,"lastTargetTouchFallback",void 0),c(this,"getSourceClientOffset",(function(e){var t=u.sourceNodes.get(e);return t&&function(e){var t=1===e.nodeType?e:e.parentElement;if(t){var o=t.getBoundingClientRect(),n=o.top;return{x:o.left,y:n}}}(t)})),c(this,"handleTopMoveStartCapture",(function(e){o(e)&&(u.moveStartSourceIds=[])})),c(this,"handleMoveStart",(function(e){Array.isArray(u.moveStartSourceIds)&&u.moveStartSourceIds.unshift(e)})),c(this,"handleTopMoveStart",(function(e){if(o(e)){var t=r(e);t&&(n(e)&&(u.lastTargetTouchFallback=e.targetTouches[0]),u._mouseClientOffset=t),u.waitingForDelay=!1}})),c(this,"handleTopMoveStartDelay",(function(e){if(o(e)){var t=e.type===v.touch.start?u.options.delayTouchStart:u.options.delayMouseStart;u.timeout=setTimeout(u.handleTopMoveStart.bind(u,e),t),u.waitingForDelay=!0}})),c(this,"handleTopMoveCapture",(function(){u.dragOverTargetIds=[]})),c(this,"handleMove",(function(e,t){u.dragOverTargetIds&&u.dragOverTargetIds.unshift(t)})),c(this,"handleTopMove",(function(e){if(u.timeout&&clearTimeout(u.timeout),u.document&&!u.waitingForDelay){var t,o,n,i,s=u.moveStartSourceIds,a=u.dragOverTargetIds,d=u.options.enableHoverOutsideTarget,l=r(e,u.lastTargetTouchFallback);if(l)if(u._isScrolling||!u.monitor.isDragging()&&function(e,t,o,n,r){if(!r)return!1;for(var i=180*Math.atan2(n-t,o-e)/Math.PI+180,s=0;s<r.length;++s)if((null==r[s].start||i>=r[s].start)&&(null==r[s].end||i<=r[s].end))return!0;return!1}(u._mouseClientOffset.x||0,u._mouseClientOffset.y||0,l.x,l.y,u.options.scrollAngleRanges))u._isScrolling=!0;else if(!u.monitor.isDragging()&&u._mouseClientOffset.hasOwnProperty("x")&&s&&(t=u._mouseClientOffset.x||0,o=u._mouseClientOffset.y||0,n=l.x,i=l.y,Math.sqrt(Math.pow(Math.abs(n-t),2)+Math.pow(Math.abs(i-o),2))>(u.options.touchSlop?u.options.touchSlop:0))&&(u.moveStartSourceIds=void 0,u.actions.beginDrag(s,{clientOffset:u._mouseClientOffset,getSourceClientOffset:u.getSourceClientOffset,publishSource:!1})),u.monitor.isDragging()){var c=u.sourceNodes.get(u.monitor.getSourceId());u.installSourceNodeRemovalObserver(c),u.actions.publishDragSource(),e.cancelable&&e.preventDefault();var v=(a||[]).map((function(e){return u.targetNodes.get(e)})).filter((function(e){return!!e})),h=u.options.getDropTargetElementsAtPoint?u.options.getDropTargetElementsAtPoint(l.x,l.y,v):u.document.elementsFromPoint(l.x,l.y),f=[];for(var g in h)if(h.hasOwnProperty(g)){var p=h[g];for(f.push(p);p;)(p=p.parentElement)&&-1===f.indexOf(p)&&f.push(p)}var m=f.filter((function(e){return v.indexOf(e)>-1})).map((function(e){return u._getDropTargetId(e)})).filter((function(e){return!!e})).filter((function(e,t,o){return o.indexOf(e)===t}));if(d)for(var y in u.targetNodes){var b=u.targetNodes.get(y);if(c&&b&&b.contains(c)&&-1===m.indexOf(y)){m.unshift(y);break}}m.reverse(),u.actions.hover(m,{clientOffset:l})}}})),c(this,"_getDropTargetId",(function(e){for(var t=u.targetNodes.keys(),o=t.next();!1===o.done;){var n=o.value;if(e===u.targetNodes.get(n))return n;o=t.next()}})),c(this,"handleTopMoveEndCapture",(function(e){u._isScrolling=!1,u.lastTargetTouchFallback=void 0,function(e){return void 0===e.buttons||0==(1&e.buttons)}(e)&&(u.monitor.isDragging()&&!u.monitor.didDrop()?(e.cancelable&&e.preventDefault(),u._mouseClientOffset={},u.uninstallSourceNodeRemovalObserver(),u.actions.drop(),u.actions.endDrag()):u.moveStartSourceIds=void 0)})),c(this,"handleCancelOnEscape",(function(e){"Escape"===e.key&&u.monitor.isDragging()&&(u._mouseClientOffset={},u.uninstallSourceNodeRemovalObserver(),u.actions.endDrag())})),this.options=new d(a,s),this.actions=i.getActions(),this.monitor=i.getMonitor(),this.sourceNodes=new Map,this.sourcePreviewNodes=new Map,this.sourcePreviewNodeOptions=new Map,this.targetNodes=new Map,this.listenerTypes=[],this._mouseClientOffset={},this._isScrolling=!1,this.options.enableMouseEvents&&this.listenerTypes.push(e.ListenerType.mouse),this.options.enableTouchEvents&&this.listenerTypes.push(e.ListenerType.touch),this.options.enableKeyboardEvents&&this.listenerTypes.push(e.ListenerType.keyboard)}var s,a;return s=t,(a=[{key:"profile",value:function(){var e;return{sourceNodes:this.sourceNodes.size,sourcePreviewNodes:this.sourcePreviewNodes.size,sourcePreviewNodeOptions:this.sourcePreviewNodeOptions.size,targetNodes:this.targetNodes.size,dragOverTargetIds:(null===(e=this.dragOverTargetIds)||void 0===e?void 0:e.length)||0}}},{key:"document",get:function(){return this.options.document}},{key:"setup",value:function(){var e=this.options.rootElement;e&&(function(e,t){for(var o=arguments.length,n=new Array(o>2?o-2:0),r=2;r<o;r++)n[r-2]=arguments[r];if(!e){var i;if(void 0===t)i=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=0;(i=new Error(t.replace(/%s/g,(function(){return n[s++]})))).name="Invariant Violation"}throw i.framesToPop=1,i}}(!t.isSetUp,"Cannot have two Touch backends at the same time."),t.isSetUp=!0,this.addEventListener(e,"start",this.getTopMoveStartHandler()),this.addEventListener(e,"start",this.handleTopMoveStartCapture,!0),this.addEventListener(e,"move",this.handleTopMove),this.addEventListener(e,"move",this.handleTopMoveCapture,!0),this.addEventListener(e,"end",this.handleTopMoveEndCapture,!0),this.options.enableMouseEvents&&!this.options.ignoreContextMenu&&this.addEventListener(e,"contextmenu",this.handleTopMoveEndCapture),this.options.enableKeyboardEvents&&this.addEventListener(e,"keydown",this.handleCancelOnEscape,!0))}},{key:"teardown",value:function(){var e=this.options.rootElement;e&&(t.isSetUp=!1,this._mouseClientOffset={},this.removeEventListener(e,"start",this.handleTopMoveStartCapture,!0),this.removeEventListener(e,"start",this.handleTopMoveStart),this.removeEventListener(e,"move",this.handleTopMoveCapture,!0),this.removeEventListener(e,"move",this.handleTopMove),this.removeEventListener(e,"end",this.handleTopMoveEndCapture,!0),this.options.enableMouseEvents&&!this.options.ignoreContextMenu&&this.removeEventListener(e,"contextmenu",this.handleTopMoveEndCapture),this.options.enableKeyboardEvents&&this.removeEventListener(e,"keydown",this.handleCancelOnEscape,!0),this.uninstallSourceNodeRemovalObserver())}},{key:"addEventListener",value:function(e,t,o,n){var r=i?{capture:n,passive:!1}:n;this.listenerTypes.forEach((function(n){var i=v[n][t];i&&e.addEventListener(i,o,r)}))}},{key:"removeEventListener",value:function(e,t,o,n){var r=i?{capture:n,passive:!1}:n;this.listenerTypes.forEach((function(n){var i=v[n][t];i&&e.removeEventListener(i,o,r)}))}},{key:"connectDragSource",value:function(e,t){var o=this,n=this.handleMoveStart.bind(this,e);return this.sourceNodes.set(e,t),this.addEventListener(t,"start",n),function(){o.sourceNodes.delete(e),o.removeEventListener(t,"start",n)}}},{key:"connectDragPreview",value:function(e,t,o){var n=this;return this.sourcePreviewNodeOptions.set(e,o),this.sourcePreviewNodes.set(e,t),function(){n.sourcePreviewNodes.delete(e),n.sourcePreviewNodeOptions.delete(e)}}},{key:"connectDropTarget",value:function(e,t){var o=this,n=this.options.rootElement;if(!this.document||!n)return function(){};var r=function(r){if(o.document&&n&&o.monitor.isDragging()){var i;switch(r.type){case v.mouse.move:i={x:r.clientX,y:r.clientY};break;case v.touch.move:i={x:r.touches[0].clientX,y:r.touches[0].clientY}}var s=null!=i?o.document.elementFromPoint(i.x,i.y):void 0,a=s&&t.contains(s);return s===t||a?o.handleMove(r,e):void 0}};return this.addEventListener(this.document.body,"move",r),this.targetNodes.set(e,t),function(){o.document&&(o.targetNodes.delete(e),o.removeEventListener(o.document.body,"move",r))}}},{key:"getTopMoveStartHandler",value:function(){return this.options.delayTouchStart||this.options.delayMouseStart?this.handleTopMoveStartDelay:this.handleTopMoveStart}},{key:"installSourceNodeRemovalObserver",value:function(e){var t=this;this.uninstallSourceNodeRemovalObserver(),this.draggedSourceNode=e,this.draggedSourceNodeRemovalObserver=new MutationObserver((function(){e&&!e.parentElement&&(t.resurrectSourceNode(),t.uninstallSourceNodeRemovalObserver())})),e&&e.parentElement&&this.draggedSourceNodeRemovalObserver.observe(e.parentElement,{childList:!0})}},{key:"resurrectSourceNode",value:function(){this.document&&this.draggedSourceNode&&(this.draggedSourceNode.style.display="none",this.draggedSourceNode.removeAttribute("data-reactid"),this.document.body.appendChild(this.draggedSourceNode))}},{key:"uninstallSourceNodeRemovalObserver",value:function(){this.draggedSourceNodeRemovalObserver&&this.draggedSourceNodeRemovalObserver.disconnect(),this.draggedSourceNodeRemovalObserver=void 0,this.draggedSourceNode=void 0}}])&&l(s.prototype,a),t}();c(h,"isSetUp",void 0),e.TouchBackend=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new h(e,t,o)},e.TouchBackendImpl=h,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "react-dnd-touch-backend", | ||
"version": "14.1.0", | ||
"version": "14.1.1", | ||
"description": "Touch backend for react-dnd", | ||
@@ -26,3 +26,3 @@ "main": "dist/cjs/index.js", | ||
"@react-dnd/invariant": "^2.0.0", | ||
"dnd-core": "14.0.0" | ||
"dnd-core": "14.0.1" | ||
}, | ||
@@ -29,0 +29,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
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
137896
3039
+ Addeddnd-core@14.0.1(transitive)
- Removeddnd-core@14.0.0(transitive)
Updateddnd-core@14.0.1