Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-dnd-touch-backend

Package Overview
Dependencies
Maintainers
3
Versions
71
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-dnd-touch-backend - npm Package Compare versions

Comparing version 11.1.0 to 11.1.1

30

dist/cjs/TouchBackendImpl.js

@@ -196,9 +196,3 @@ "use strict";

.map(function (node) {
for (var targetId in _this.targetNodes) {
if (node === _this.targetNodes.get(targetId)) {
return targetId;
}
}
return undefined;
return _this._getDropTargetId(node);
}) // Filter off possible null rows

@@ -229,3 +223,25 @@ .filter(function (node) {

};
/**
*
* visible for testing
*/
this._getDropTargetId = function (node) {
var keys = _this.targetNodes.keys();
var next = keys.next();
var targetId = next.value;
while (next.done === false) {
if (node === _this.targetNodes.get(targetId)) {
return targetId;
} else {
next = keys.next();
}
}
return undefined;
};
this.handleTopMoveEndCapture = function (e) {

@@ -232,0 +248,0 @@ _this._isScrolling = false;

@@ -181,9 +181,3 @@ var _eventNames;

.map(function (node) {
for (var targetId in _this.targetNodes) {
if (node === _this.targetNodes.get(targetId)) {
return targetId;
}
}
return undefined;
return _this._getDropTargetId(node);
}) // Filter off possible null rows

@@ -214,3 +208,25 @@ .filter(function (node) {

};
/**
*
* visible for testing
*/
this._getDropTargetId = function (node) {
var keys = _this.targetNodes.keys();
var next = keys.next();
var targetId = next.value;
while (next.done === false) {
if (node === _this.targetNodes.get(targetId)) {
return targetId;
} else {
next = keys.next();
}
}
return undefined;
};
this.handleTopMoveEndCapture = function (e) {

@@ -217,0 +233,0 @@ _this._isScrolling = false;

@@ -375,9 +375,3 @@ (function (global, factory) {

.map(function (node) {
for (var targetId in _this.targetNodes) {
if (node === _this.targetNodes.get(targetId)) {
return targetId;
}
}
return undefined;
return _this._getDropTargetId(node);
}) // Filter off possible null rows

@@ -408,3 +402,25 @@ .filter(function (node) {

};
/**
*
* visible for testing
*/
this._getDropTargetId = function (node) {
var keys = _this.targetNodes.keys();
var next = keys.next();
var targetId = next.value;
while (next.done === false) {
if (node === _this.targetNodes.get(targetId)) {
return targetId;
} else {
next = keys.next();
}
}
return undefined;
};
this.handleTopMoveEndCapture = function (e) {

@@ -411,0 +427,0 @@ _this._isScrolling = false;

@@ -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=e||self).ReactDnDTouchBackend={})}(this,(function(e){"use strict";var t;!function(e){e.mouse="mouse",e.touch="touch",e.keyboard="keyboard"}(t||(t={}));var n=1,o=0;function i(e){return void 0===e.button||e.button===o}function r(e){return!!e.targetTouches}function s(e,t){return r(e)?function(e,t){return 1===e.targetTouches.length?s(e.targetTouches[0]):t&&1===e.touches.length&&e.touches[0].target===t.target?s(e.touches[0]):void 0}(e,t):{x:e.clientX,y:e.clientY}}function a(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 u,d=function(){function e(t,n){var o=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.enableTouchEvents=!0,this.enableMouseEvents=!1,this.enableKeyboardEvents=!1,this.ignoreContextMenu=!1,this.enableHoverOutsideTarget=!1,this.touchSlop=0,this.scrollAngleRanges=void 0,this.context=n,this.delayTouchStart=t.delayTouchStart||t.delay||0,this.delayMouseStart=t.delayMouseStart||t.delay||0,Object.keys(t).forEach((function(e){null!=t[e]&&(o[e]=t[e])}))}var t,n,o;return t=e,(n=[{key:"window",get:function(){return this.context&&this.context.window?this.context.window:"undefined"!=typeof window?window:void 0}},{key:"document",get:function(){if(this.window)return this.window.document}}])&&a(t.prototype,n),o&&a(t,o),e}();function c(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)}}function h(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l=(h(u={},t.mouse,{start:"mousedown",move:"mousemove",end:"mouseup",contextmenu:"contextmenu"}),h(u,t.touch,{start:"touchstart",move:"touchmove",end:"touchend"}),h(u,t.keyboard,{keydown:"keydown"}),u),v=function(){function e(o,a,u){var c=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.getSourceClientOffset=function(e){var t=c.sourceNodes.get(e);return t&&function(e){var t=1===e.nodeType?e:e.parentElement;if(t){var n=t.getBoundingClientRect(),o=n.top;return{x:n.left,y:o}}}(t)},this.handleTopMoveStartCapture=function(e){i(e)&&(c.moveStartSourceIds=[])},this.handleMoveStart=function(e){Array.isArray(c.moveStartSourceIds)&&c.moveStartSourceIds.unshift(e)},this.handleTopMoveStart=function(e){if(i(e)){var t=s(e);t&&(r(e)&&(c.lastTargetTouchFallback=e.targetTouches[0]),c._mouseClientOffset=t),c.waitingForDelay=!1}},this.handleTopMoveStartDelay=function(e){if(i(e)){var t=e.type===l.touch.start?c.options.delayTouchStart:c.options.delayMouseStart;c.timeout=setTimeout(c.handleTopMoveStart.bind(c,e),t),c.waitingForDelay=!0}},this.handleTopMoveCapture=function(){c.dragOverTargetIds=[]},this.handleMove=function(e,t){c.dragOverTargetIds&&c.dragOverTargetIds.unshift(t)},this.handleTopMove=function(e){if(c.timeout&&clearTimeout(c.timeout),c.document&&!c.waitingForDelay){var t,n,o,i,r=c.moveStartSourceIds,a=c.dragOverTargetIds,u=c.options.enableHoverOutsideTarget,d=s(e,c.lastTargetTouchFallback);if(d)if(c._isScrolling||!c.monitor.isDragging()&&function(e,t,n,o,i){if(!i)return!1;for(var r=180*Math.atan2(o-t,n-e)/Math.PI+180,s=0;s<i.length;++s)if((null==i[s].start||r>=i[s].start)&&(null==i[s].end||r<=i[s].end))return!0;return!1}(c._mouseClientOffset.x||0,c._mouseClientOffset.y||0,d.x,d.y,c.options.scrollAngleRanges))c._isScrolling=!0;else if(!c.monitor.isDragging()&&c._mouseClientOffset.hasOwnProperty("x")&&r&&(t=c._mouseClientOffset.x||0,n=c._mouseClientOffset.y||0,o=d.x,i=d.y,Math.sqrt(Math.pow(Math.abs(o-t),2)+Math.pow(Math.abs(i-n),2))>(c.options.touchSlop?c.options.touchSlop:0))&&(c.moveStartSourceIds=void 0,c.actions.beginDrag(r,{clientOffset:c._mouseClientOffset,getSourceClientOffset:c.getSourceClientOffset,publishSource:!1})),c.monitor.isDragging()){var h=c.sourceNodes.get(c.monitor.getSourceId());c.installSourceNodeRemovalObserver(h),c.actions.publishDragSource(),e.cancelable&&e.preventDefault();var l=(a||[]).map((function(e){return c.targetNodes.get(e)})).filter((function(e){return!!e})),v=c.options.getDropTargetElementsAtPoint?c.options.getDropTargetElementsAtPoint(d.x,d.y,l):c.document.elementsFromPoint(d.x,d.y),f=[];for(var p in v)if(v.hasOwnProperty(p)){var g=v[p];for(f.push(g);g;)(g=g.parentElement)&&-1===f.indexOf(g)&&f.push(g)}var m=f.filter((function(e){return l.indexOf(e)>-1})).map((function(e){for(var t in c.targetNodes)if(e===c.targetNodes.get(t))return t})).filter((function(e){return!!e})).filter((function(e,t,n){return n.indexOf(e)===t}));if(u)for(var w in c.targetNodes){var y=c.targetNodes.get(w);if(h&&y&&y.contains(h)&&-1===m.indexOf(w)){m.unshift(w);break}}m.reverse(),c.actions.hover(m,{clientOffset:d})}}},this.handleTopMoveEndCapture=function(e){c._isScrolling=!1,c.lastTargetTouchFallback=void 0,function(e){return void 0===e.buttons||0==(e.buttons&n)}(e)&&(c.monitor.isDragging()&&!c.monitor.didDrop()?(e.cancelable&&e.preventDefault(),c._mouseClientOffset={},c.uninstallSourceNodeRemovalObserver(),c.actions.drop(),c.actions.endDrag()):c.moveStartSourceIds=void 0)},this.handleCancelOnEscape=function(e){"Escape"===e.key&&c.monitor.isDragging()&&(c._mouseClientOffset={},c.uninstallSourceNodeRemovalObserver(),c.actions.endDrag())},this.options=new d(u,a),this.actions=o.getActions(),this.monitor=o.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(t.mouse),this.options.enableTouchEvents&&this.listenerTypes.push(t.touch),this.options.enableKeyboardEvents&&this.listenerTypes.push(t.keyboard)}var o,a,u;return o=e,(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:"setup",value:function(){this.window&&(function(e,t){for(var n=arguments.length,o=new Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];if(!e){var r;if(void 0===t)r=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=0;(r=new Error(t.replace(/%s/g,(function(){return o[s++]})))).name="Invariant Violation"}throw r.framesToPop=1,r}}(!e.isSetUp,"Cannot have two Touch backends at the same time."),e.isSetUp=!0,this.addEventListener(this.window,"start",this.getTopMoveStartHandler()),this.addEventListener(this.window,"start",this.handleTopMoveStartCapture,!0),this.addEventListener(this.window,"move",this.handleTopMove),this.addEventListener(this.window,"move",this.handleTopMoveCapture,!0),this.addEventListener(this.window,"end",this.handleTopMoveEndCapture,!0),this.options.enableMouseEvents&&!this.options.ignoreContextMenu&&this.addEventListener(this.window,"contextmenu",this.handleTopMoveEndCapture),this.options.enableKeyboardEvents&&this.addEventListener(this.window,"keydown",this.handleCancelOnEscape,!0))}},{key:"teardown",value:function(){this.window&&(e.isSetUp=!1,this._mouseClientOffset={},this.removeEventListener(this.window,"start",this.handleTopMoveStartCapture,!0),this.removeEventListener(this.window,"start",this.handleTopMoveStart),this.removeEventListener(this.window,"move",this.handleTopMoveCapture,!0),this.removeEventListener(this.window,"move",this.handleTopMove),this.removeEventListener(this.window,"end",this.handleTopMoveEndCapture,!0),this.options.enableMouseEvents&&!this.options.ignoreContextMenu&&this.removeEventListener(this.window,"contextmenu",this.handleTopMoveEndCapture),this.options.enableKeyboardEvents&&this.removeEventListener(this.window,"keydown",this.handleCancelOnEscape,!0),this.uninstallSourceNodeRemovalObserver())}},{key:"addEventListener",value:function(e,t,n,o){var i=o;this.listenerTypes.forEach((function(o){var r=l[o][t];r&&e.addEventListener(r,n,i)}))}},{key:"removeEventListener",value:function(e,t,n,o){var i=o;this.listenerTypes.forEach((function(o){var r=l[o][t];r&&e.removeEventListener(r,n,i)}))}},{key:"connectDragSource",value:function(e,t){var n=this,o=this.handleMoveStart.bind(this,e);return this.sourceNodes.set(e,t),this.addEventListener(t,"start",o),function(){n.sourceNodes.delete(e),n.removeEventListener(t,"start",o)}}},{key:"connectDragPreview",value:function(e,t,n){var o=this;return this.sourcePreviewNodeOptions.set(e,n),this.sourcePreviewNodes.set(e,t),function(){o.sourcePreviewNodes.delete(e),o.sourcePreviewNodeOptions.delete(e)}}},{key:"connectDropTarget",value:function(e,t){var n=this;if(!this.document)return function(){};var o=function(o){if(n.document&&n.monitor.isDragging()){var i;switch(o.type){case l.mouse.move:i={x:o.clientX,y:o.clientY};break;case l.touch.move:i={x:o.touches[0].clientX,y:o.touches[0].clientY}}var r=null!=i?n.document.elementFromPoint(i.x,i.y):void 0,s=r&&t.contains(r);return r===t||s?n.handleMove(o,e):void 0}};return this.addEventListener(this.document.body,"move",o),this.targetNodes.set(e,t),function(){n.document&&(n.targetNodes.delete(e),n.removeEventListener(n.document.body,"move",o))}}},{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}},{key:"window",get:function(){return this.options.window}},{key:"document",get:function(){if(this.window)return this.window.document}}])&&c(o.prototype,a),u&&c(o,u),e}();e.TouchBackend=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new v(e,t,n)},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=e||self).ReactDnDTouchBackend={})}(this,(function(e){"use strict";var t;!function(e){e.mouse="mouse",e.touch="touch",e.keyboard="keyboard"}(t||(t={}));var n=1,o=0;function i(e){return void 0===e.button||e.button===o}function r(e){return!!e.targetTouches}function s(e,t){return r(e)?function(e,t){return 1===e.targetTouches.length?s(e.targetTouches[0]):t&&1===e.touches.length&&e.touches[0].target===t.target?s(e.touches[0]):void 0}(e,t):{x:e.clientX,y:e.clientY}}function a(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 u,d=function(){function e(t,n){var o=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.enableTouchEvents=!0,this.enableMouseEvents=!1,this.enableKeyboardEvents=!1,this.ignoreContextMenu=!1,this.enableHoverOutsideTarget=!1,this.touchSlop=0,this.scrollAngleRanges=void 0,this.context=n,this.delayTouchStart=t.delayTouchStart||t.delay||0,this.delayMouseStart=t.delayMouseStart||t.delay||0,Object.keys(t).forEach((function(e){null!=t[e]&&(o[e]=t[e])}))}var t,n,o;return t=e,(n=[{key:"window",get:function(){return this.context&&this.context.window?this.context.window:"undefined"!=typeof window?window:void 0}},{key:"document",get:function(){if(this.window)return this.window.document}}])&&a(t.prototype,n),o&&a(t,o),e}();function c(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)}}function h(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var l=(h(u={},t.mouse,{start:"mousedown",move:"mousemove",end:"mouseup",contextmenu:"contextmenu"}),h(u,t.touch,{start:"touchstart",move:"touchmove",end:"touchend"}),h(u,t.keyboard,{keydown:"keydown"}),u),v=function(){function e(o,a,u){var c=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.getSourceClientOffset=function(e){var t=c.sourceNodes.get(e);return t&&function(e){var t=1===e.nodeType?e:e.parentElement;if(t){var n=t.getBoundingClientRect(),o=n.top;return{x:n.left,y:o}}}(t)},this.handleTopMoveStartCapture=function(e){i(e)&&(c.moveStartSourceIds=[])},this.handleMoveStart=function(e){Array.isArray(c.moveStartSourceIds)&&c.moveStartSourceIds.unshift(e)},this.handleTopMoveStart=function(e){if(i(e)){var t=s(e);t&&(r(e)&&(c.lastTargetTouchFallback=e.targetTouches[0]),c._mouseClientOffset=t),c.waitingForDelay=!1}},this.handleTopMoveStartDelay=function(e){if(i(e)){var t=e.type===l.touch.start?c.options.delayTouchStart:c.options.delayMouseStart;c.timeout=setTimeout(c.handleTopMoveStart.bind(c,e),t),c.waitingForDelay=!0}},this.handleTopMoveCapture=function(){c.dragOverTargetIds=[]},this.handleMove=function(e,t){c.dragOverTargetIds&&c.dragOverTargetIds.unshift(t)},this.handleTopMove=function(e){if(c.timeout&&clearTimeout(c.timeout),c.document&&!c.waitingForDelay){var t,n,o,i,r=c.moveStartSourceIds,a=c.dragOverTargetIds,u=c.options.enableHoverOutsideTarget,d=s(e,c.lastTargetTouchFallback);if(d)if(c._isScrolling||!c.monitor.isDragging()&&function(e,t,n,o,i){if(!i)return!1;for(var r=180*Math.atan2(o-t,n-e)/Math.PI+180,s=0;s<i.length;++s)if((null==i[s].start||r>=i[s].start)&&(null==i[s].end||r<=i[s].end))return!0;return!1}(c._mouseClientOffset.x||0,c._mouseClientOffset.y||0,d.x,d.y,c.options.scrollAngleRanges))c._isScrolling=!0;else if(!c.monitor.isDragging()&&c._mouseClientOffset.hasOwnProperty("x")&&r&&(t=c._mouseClientOffset.x||0,n=c._mouseClientOffset.y||0,o=d.x,i=d.y,Math.sqrt(Math.pow(Math.abs(o-t),2)+Math.pow(Math.abs(i-n),2))>(c.options.touchSlop?c.options.touchSlop:0))&&(c.moveStartSourceIds=void 0,c.actions.beginDrag(r,{clientOffset:c._mouseClientOffset,getSourceClientOffset:c.getSourceClientOffset,publishSource:!1})),c.monitor.isDragging()){var h=c.sourceNodes.get(c.monitor.getSourceId());c.installSourceNodeRemovalObserver(h),c.actions.publishDragSource(),e.cancelable&&e.preventDefault();var l=(a||[]).map((function(e){return c.targetNodes.get(e)})).filter((function(e){return!!e})),v=c.options.getDropTargetElementsAtPoint?c.options.getDropTargetElementsAtPoint(d.x,d.y,l):c.document.elementsFromPoint(d.x,d.y),f=[];for(var p in v)if(v.hasOwnProperty(p)){var g=v[p];for(f.push(g);g;)(g=g.parentElement)&&-1===f.indexOf(g)&&f.push(g)}var m=f.filter((function(e){return l.indexOf(e)>-1})).map((function(e){return c._getDropTargetId(e)})).filter((function(e){return!!e})).filter((function(e,t,n){return n.indexOf(e)===t}));if(u)for(var w in c.targetNodes){var y=c.targetNodes.get(w);if(h&&y&&y.contains(h)&&-1===m.indexOf(w)){m.unshift(w);break}}m.reverse(),c.actions.hover(m,{clientOffset:d})}}},this._getDropTargetId=function(e){for(var t=c.targetNodes.keys(),n=t.next(),o=n.value;!1===n.done;){if(e===c.targetNodes.get(o))return o;n=t.next()}},this.handleTopMoveEndCapture=function(e){c._isScrolling=!1,c.lastTargetTouchFallback=void 0,function(e){return void 0===e.buttons||0==(e.buttons&n)}(e)&&(c.monitor.isDragging()&&!c.monitor.didDrop()?(e.cancelable&&e.preventDefault(),c._mouseClientOffset={},c.uninstallSourceNodeRemovalObserver(),c.actions.drop(),c.actions.endDrag()):c.moveStartSourceIds=void 0)},this.handleCancelOnEscape=function(e){"Escape"===e.key&&c.monitor.isDragging()&&(c._mouseClientOffset={},c.uninstallSourceNodeRemovalObserver(),c.actions.endDrag())},this.options=new d(u,a),this.actions=o.getActions(),this.monitor=o.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(t.mouse),this.options.enableTouchEvents&&this.listenerTypes.push(t.touch),this.options.enableKeyboardEvents&&this.listenerTypes.push(t.keyboard)}var o,a,u;return o=e,(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:"setup",value:function(){this.window&&(function(e,t){for(var n=arguments.length,o=new Array(n>2?n-2:0),i=2;i<n;i++)o[i-2]=arguments[i];if(!e){var r;if(void 0===t)r=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var s=0;(r=new Error(t.replace(/%s/g,(function(){return o[s++]})))).name="Invariant Violation"}throw r.framesToPop=1,r}}(!e.isSetUp,"Cannot have two Touch backends at the same time."),e.isSetUp=!0,this.addEventListener(this.window,"start",this.getTopMoveStartHandler()),this.addEventListener(this.window,"start",this.handleTopMoveStartCapture,!0),this.addEventListener(this.window,"move",this.handleTopMove),this.addEventListener(this.window,"move",this.handleTopMoveCapture,!0),this.addEventListener(this.window,"end",this.handleTopMoveEndCapture,!0),this.options.enableMouseEvents&&!this.options.ignoreContextMenu&&this.addEventListener(this.window,"contextmenu",this.handleTopMoveEndCapture),this.options.enableKeyboardEvents&&this.addEventListener(this.window,"keydown",this.handleCancelOnEscape,!0))}},{key:"teardown",value:function(){this.window&&(e.isSetUp=!1,this._mouseClientOffset={},this.removeEventListener(this.window,"start",this.handleTopMoveStartCapture,!0),this.removeEventListener(this.window,"start",this.handleTopMoveStart),this.removeEventListener(this.window,"move",this.handleTopMoveCapture,!0),this.removeEventListener(this.window,"move",this.handleTopMove),this.removeEventListener(this.window,"end",this.handleTopMoveEndCapture,!0),this.options.enableMouseEvents&&!this.options.ignoreContextMenu&&this.removeEventListener(this.window,"contextmenu",this.handleTopMoveEndCapture),this.options.enableKeyboardEvents&&this.removeEventListener(this.window,"keydown",this.handleCancelOnEscape,!0),this.uninstallSourceNodeRemovalObserver())}},{key:"addEventListener",value:function(e,t,n,o){var i=o;this.listenerTypes.forEach((function(o){var r=l[o][t];r&&e.addEventListener(r,n,i)}))}},{key:"removeEventListener",value:function(e,t,n,o){var i=o;this.listenerTypes.forEach((function(o){var r=l[o][t];r&&e.removeEventListener(r,n,i)}))}},{key:"connectDragSource",value:function(e,t){var n=this,o=this.handleMoveStart.bind(this,e);return this.sourceNodes.set(e,t),this.addEventListener(t,"start",o),function(){n.sourceNodes.delete(e),n.removeEventListener(t,"start",o)}}},{key:"connectDragPreview",value:function(e,t,n){var o=this;return this.sourcePreviewNodeOptions.set(e,n),this.sourcePreviewNodes.set(e,t),function(){o.sourcePreviewNodes.delete(e),o.sourcePreviewNodeOptions.delete(e)}}},{key:"connectDropTarget",value:function(e,t){var n=this;if(!this.document)return function(){};var o=function(o){if(n.document&&n.monitor.isDragging()){var i;switch(o.type){case l.mouse.move:i={x:o.clientX,y:o.clientY};break;case l.touch.move:i={x:o.touches[0].clientX,y:o.touches[0].clientY}}var r=null!=i?n.document.elementFromPoint(i.x,i.y):void 0,s=r&&t.contains(r);return r===t||s?n.handleMove(o,e):void 0}};return this.addEventListener(this.document.body,"move",o),this.targetNodes.set(e,t),function(){n.document&&(n.targetNodes.delete(e),n.removeEventListener(n.document.body,"move",o))}}},{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}},{key:"window",get:function(){return this.options.window}},{key:"document",get:function(){if(this.window)return this.window.document}}])&&c(o.prototype,a),u&&c(o,u),e}();e.TouchBackend=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new v(e,t,n)},e.TouchBackendImpl=v,Object.defineProperty(e,"__esModule",{value:!0})}));

@@ -1,2 +0,2 @@

import { Backend, DragDropManager, Unsubscribe } from 'dnd-core';
import { Backend, Identifier, DragDropManager, Unsubscribe } from 'dnd-core';
import { TouchBackendOptions, TouchBackendContext } from './interfaces';

@@ -8,6 +8,6 @@ export declare class TouchBackendImpl implements Backend {

private static isSetUp;
private sourceNodes;
private sourcePreviewNodes;
private sourcePreviewNodeOptions;
private targetNodes;
sourceNodes: Map<Identifier, HTMLElement>;
sourcePreviewNodes: Map<string, HTMLElement>;
sourcePreviewNodeOptions: Map<string, any>;
targetNodes: Map<string, HTMLElement>;
private _mouseClientOffset;

@@ -46,2 +46,7 @@ private _isScrolling;

handleTopMove: (e: TouchEvent | MouseEvent) => void;
/**
*
* visible for testing
*/
_getDropTargetId: (node: Element) => Identifier | undefined;
handleTopMoveEndCapture: (e: Event) => void;

@@ -48,0 +53,0 @@ handleCancelOnEscape: (e: KeyboardEvent) => void;

@@ -148,10 +148,3 @@ import { invariant } from '@react-dnd/invariant';

// Map back the nodes elements to targetIds
.map((node) => {
for (const targetId in this.targetNodes) {
if (node === this.targetNodes.get(targetId)) {
return targetId;
}
}
return undefined;
})
.map((node) => this._getDropTargetId(node))
// Filter off possible null rows

@@ -179,2 +172,20 @@ .filter((node) => !!node)

};
/**
*
* visible for testing
*/
this._getDropTargetId = (node) => {
const keys = this.targetNodes.keys();
let next = keys.next();
const targetId = next.value;
while (next.done === false) {
if (node === this.targetNodes.get(targetId)) {
return targetId;
}
else {
next = keys.next();
}
}
return undefined;
};
this.handleTopMoveEndCapture = (e) => {

@@ -181,0 +192,0 @@ this._isScrolling = false;

{
"name": "react-dnd-touch-backend",
"version": "11.1.0",
"version": "11.1.1",
"description": "Touch backend for react-dnd",

@@ -22,5 +22,5 @@ "main": "./dist/cjs/index.js",

"@react-dnd/invariant": "^2.0.0",
"dnd-core": "^11.1.0"
"dnd-core": "^11.1.1"
},
"gitHead": "b74700a81953a107656c2e0a565f2437255fe15e"
"gitHead": "e036601cafda176b793655b0aee317ed40733a40"
}
import { TouchBackend } from '../index'
import { DragDropManager } from 'dnd-core'
import { TouchBackendImpl } from '../TouchBackendImpl'

@@ -19,2 +20,11 @@ describe('TouchBackend', () => {

})
it('can determine target ids', () => {
const mockNode = {} as HTMLElement
const backend = TouchBackend(mockManager(), {}, {}) as TouchBackendImpl
backend.targetNodes.set('abc', mockNode)
expect(backend._getDropTargetId(mockNode)).toEqual('abc')
expect(backend._getDropTargetId({} as Element)).toEqual(undefined)
})
})

@@ -21,0 +31,0 @@

@@ -53,6 +53,6 @@ import { invariant } from '@react-dnd/invariant'

private static isSetUp: boolean
private sourceNodes: Map<Identifier, HTMLElement>
private sourcePreviewNodes: Map<string, HTMLElement>
private sourcePreviewNodeOptions: Map<string, any>
private targetNodes: Map<string, HTMLElement>
public sourceNodes: Map<Identifier, HTMLElement>
public sourcePreviewNodes: Map<string, HTMLElement>
public sourcePreviewNodeOptions: Map<string, any>
public targetNodes: Map<string, HTMLElement>
private _mouseClientOffset: Partial<XYCoord>

@@ -531,10 +531,3 @@ private _isScrolling: boolean

// Map back the nodes elements to targetIds
.map((node) => {
for (const targetId in this.targetNodes) {
if (node === this.targetNodes.get(targetId)) {
return targetId
}
}
return undefined
})
.map((node) => this._getDropTargetId(node))
// Filter off possible null rows

@@ -568,2 +561,20 @@ .filter((node) => !!node)

/**
*
* visible for testing
*/
public _getDropTargetId = (node: Element): Identifier | undefined => {
const keys = this.targetNodes.keys()
let next = keys.next()
const targetId = next.value
while (next.done === false) {
if (node === this.targetNodes.get(targetId)) {
return targetId
} else {
next = keys.next()
}
}
return undefined
}
public handleTopMoveEndCapture = (e: Event): void => {

@@ -570,0 +581,0 @@ this._isScrolling = false

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc