react-dnd-touch-backend
Advanced tools
Comparing version 10.0.2 to 11.0.0
@@ -6,14 +6,26 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
var _exportNames = { | ||
TouchBackend: true | ||
}; | ||
exports.TouchBackend = void 0; | ||
var _TouchBackend = _interopRequireDefault(require("./TouchBackend")); | ||
var _TouchBackendImpl = require("./TouchBackendImpl"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
Object.keys(_TouchBackendImpl).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _TouchBackendImpl[key]; | ||
} | ||
}); | ||
}); | ||
var createBackend = function createBackend(manager, context) { | ||
var TouchBackend = function createBackend(manager) { | ||
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return new _TouchBackend.default(manager, context, options); | ||
return new _TouchBackendImpl.TouchBackendImpl(manager, context, options); | ||
}; | ||
var _default = createBackend; | ||
exports.default = _default; | ||
exports.TouchBackend = TouchBackend; |
@@ -14,5 +14,3 @@ "use strict"; | ||
var OptionsReader = | ||
/*#__PURE__*/ | ||
function () { | ||
var OptionsReader = /*#__PURE__*/function () { | ||
function OptionsReader(incoming, context) { | ||
@@ -19,0 +17,0 @@ var _this = this; |
@@ -6,3 +6,3 @@ "use strict"; | ||
}); | ||
exports.default = void 0; | ||
exports.supportsPassive = void 0; | ||
@@ -27,3 +27,2 @@ var supportsPassive = function () { | ||
var _default = supportsPassive; | ||
exports.default = _default; | ||
exports.supportsPassive = supportsPassive; |
@@ -1,8 +0,7 @@ | ||
import TouchBackend from './TouchBackend'; | ||
var createBackend = function createBackend(manager, context) { | ||
import { TouchBackendImpl } from './TouchBackendImpl'; | ||
export * from './TouchBackendImpl'; | ||
export var TouchBackend = function createBackend(manager) { | ||
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return new TouchBackend(manager, context, options); | ||
}; | ||
export default createBackend; | ||
return new TouchBackendImpl(manager, context, options); | ||
}; |
@@ -7,5 +7,3 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
export var OptionsReader = | ||
/*#__PURE__*/ | ||
function () { | ||
export var OptionsReader = /*#__PURE__*/function () { | ||
function OptionsReader(incoming, context) { | ||
@@ -12,0 +10,0 @@ var _this = this; |
@@ -1,2 +0,2 @@ | ||
var supportsPassive = function () { | ||
export var supportsPassive = function () { | ||
// simular to jQuery's test | ||
@@ -17,4 +17,2 @@ var supported = false; | ||
return supported; | ||
}(); | ||
export default supportsPassive; | ||
}(); |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.ReactDnDTouchBackend = factory()); | ||
}(this, (function () { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.ReactDnDTouchBackend = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -22,3 +22,3 @@ /** | ||
if ("development" !== 'production') { | ||
{ | ||
if (format === undefined) { | ||
@@ -150,20 +150,2 @@ throw new Error('invariant requires an error message argument'); | ||
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(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
@@ -175,5 +157,3 @@ | ||
var OptionsReader = | ||
/*#__PURE__*/ | ||
function () { | ||
var OptionsReader = /*#__PURE__*/function () { | ||
function OptionsReader(incoming, context) { | ||
@@ -247,13 +227,12 @@ var _this = this; | ||
}), _eventNames); | ||
var TouchBackend = | ||
/*#__PURE__*/ | ||
function () { | ||
function TouchBackend(manager, context, options) { | ||
var TouchBackendImpl = /*#__PURE__*/function () { | ||
function TouchBackendImpl(manager, context, options) { | ||
var _this = this; | ||
_classCallCheck$1(this, TouchBackend); | ||
_classCallCheck$1(this, TouchBackendImpl); | ||
this.getSourceClientOffset = function (sourceId) { | ||
return getNodeClientOffset(_this.sourceNodes[sourceId]); | ||
var element = _this.sourceNodes.get(sourceId); | ||
return element && getNodeClientOffset(element); | ||
}; | ||
@@ -313,3 +292,3 @@ | ||
this.handleMove = function (_, targetId) { | ||
this.handleMove = function (_evt, targetId) { | ||
if (_this.dragOverTargetIds) { | ||
@@ -360,3 +339,3 @@ _this.dragOverTargetIds.unshift(targetId); | ||
var sourceNode = _this.sourceNodes[_this.monitor.getSourceId()]; | ||
var sourceNode = _this.sourceNodes.get(_this.monitor.getSourceId()); | ||
@@ -367,6 +346,8 @@ _this.installSourceNodeRemovalObserver(sourceNode); | ||
e.preventDefault(); // Get the node elements of the hovered DropTargets | ||
if (e.cancelable) e.preventDefault(); // Get the node elements of the hovered DropTargets | ||
var dragOverTargetNodes = (dragOverTargetIds || []).map(function (key) { | ||
return _this.targetNodes[key]; | ||
return _this.targetNodes.get(key); | ||
}).filter(function (e) { | ||
return !!e; | ||
}); // Get the a ordered list of nodes that are touched by | ||
@@ -390,3 +371,3 @@ | ||
if (elementsAtPointExtended.indexOf(currentNode) === -1) { | ||
if (currentNode && elementsAtPointExtended.indexOf(currentNode) === -1) { | ||
elementsAtPointExtended.push(currentNode); | ||
@@ -403,3 +384,3 @@ } | ||
for (var targetId in _this.targetNodes) { | ||
if (node === _this.targetNodes[targetId]) { | ||
if (node === _this.targetNodes.get(targetId)) { | ||
return targetId; | ||
@@ -419,3 +400,5 @@ } | ||
for (var targetId in _this.targetNodes) { | ||
if (_this.targetNodes[targetId] && _this.targetNodes[targetId].contains(sourceNode) && orderedDragOverTargetIds.indexOf(targetId) === -1) { | ||
var targetNode = _this.targetNodes.get(targetId); | ||
if (sourceNode && targetNode && targetNode.contains(sourceNode) && orderedDragOverTargetIds.indexOf(targetId) === -1) { | ||
orderedDragOverTargetIds.unshift(targetId); | ||
@@ -448,3 +431,3 @@ break; | ||
e.preventDefault(); | ||
if (e.cancelable) e.preventDefault(); | ||
_this._mouseClientOffset = {}; | ||
@@ -472,6 +455,6 @@ | ||
this.monitor = manager.getMonitor(); | ||
this.sourceNodes = {}; | ||
this.sourcePreviewNodes = {}; | ||
this.sourcePreviewNodeOptions = {}; | ||
this.targetNodes = {}; | ||
this.sourceNodes = new Map(); | ||
this.sourcePreviewNodes = new Map(); | ||
this.sourcePreviewNodeOptions = new Map(); | ||
this.targetNodes = new Map(); | ||
this.listenerTypes = []; | ||
@@ -492,6 +475,23 @@ this._mouseClientOffset = {}; | ||
} | ||
} // public for test | ||
} | ||
/** | ||
* Generate profiling statistics for the HTML5Backend. | ||
*/ | ||
_createClass$1(TouchBackend, [{ | ||
_createClass$1(TouchBackendImpl, [{ | ||
key: "profile", | ||
value: function profile() { | ||
var _this$dragOverTargetI; | ||
return { | ||
sourceNodes: this.sourceNodes.size, | ||
sourcePreviewNodes: this.sourcePreviewNodes.size, | ||
sourcePreviewNodeOptions: this.sourcePreviewNodeOptions.size, | ||
targetNodes: this.targetNodes.size, | ||
dragOverTargetIds: ((_this$dragOverTargetI = this.dragOverTargetIds) === null || _this$dragOverTargetI === void 0 ? void 0 : _this$dragOverTargetI.length) || 0 | ||
}; | ||
} // public for test | ||
}, { | ||
key: "setup", | ||
@@ -503,4 +503,4 @@ value: function setup() { | ||
invariant(!TouchBackend.isSetUp, 'Cannot have two Touch backends at the same time.'); | ||
TouchBackend.isSetUp = true; | ||
invariant(!TouchBackendImpl.isSetUp, 'Cannot have two Touch backends at the same time.'); | ||
TouchBackendImpl.isSetUp = true; | ||
this.addEventListener(this.window, 'start', this.getTopMoveStartHandler()); | ||
@@ -527,3 +527,3 @@ this.addEventListener(this.window, 'start', this.handleTopMoveStartCapture, true); | ||
TouchBackend.isSetUp = false; | ||
TouchBackendImpl.isSetUp = false; | ||
this._mouseClientOffset = {}; | ||
@@ -549,6 +549,3 @@ this.removeEventListener(this.window, 'start', this.handleTopMoveStartCapture, true); | ||
value: function addEventListener(subject, event, handler, capture) { | ||
var options = supportsPassive ? { | ||
capture: capture, | ||
passive: false | ||
} : capture; | ||
var options = capture; | ||
this.listenerTypes.forEach(function (listenerType) { | ||
@@ -565,6 +562,3 @@ var evt = eventNames[listenerType][event]; | ||
value: function removeEventListener(subject, event, handler, capture) { | ||
var options = supportsPassive ? { | ||
capture: capture, | ||
passive: false | ||
} : capture; | ||
var options = capture; | ||
this.listenerTypes.forEach(function (listenerType) { | ||
@@ -584,6 +578,6 @@ var evt = eventNames[listenerType][event]; | ||
var handleMoveStart = this.handleMoveStart.bind(this, sourceId); | ||
this.sourceNodes[sourceId] = node; | ||
this.sourceNodes.set(sourceId, node); | ||
this.addEventListener(node, 'start', handleMoveStart); | ||
return function () { | ||
delete _this2.sourceNodes[sourceId]; | ||
_this2.sourceNodes.delete(sourceId); | ||
@@ -598,7 +592,8 @@ _this2.removeEventListener(node, 'start', handleMoveStart); | ||
this.sourcePreviewNodeOptions[sourceId] = options; | ||
this.sourcePreviewNodes[sourceId] = node; | ||
this.sourcePreviewNodeOptions.set(sourceId, options); | ||
this.sourcePreviewNodes.set(sourceId, node); | ||
return function () { | ||
delete _this3.sourcePreviewNodes[sourceId]; | ||
delete _this3.sourcePreviewNodeOptions[sourceId]; | ||
_this3.sourcePreviewNodes.delete(sourceId); | ||
_this3.sourcePreviewNodeOptions.delete(sourceId); | ||
}; | ||
@@ -613,3 +608,3 @@ } | ||
return function () { | ||
return null; | ||
/* noop */ | ||
}; | ||
@@ -662,6 +657,6 @@ } | ||
this.addEventListener(this.document.body, 'move', handleMove); | ||
this.targetNodes[targetId] = node; | ||
this.targetNodes.set(targetId, node); | ||
return function () { | ||
if (_this4.document) { | ||
delete _this4.targetNodes[targetId]; | ||
_this4.targetNodes.delete(targetId); | ||
@@ -740,12 +735,16 @@ _this4.removeEventListener(_this4.document.body, 'move', handleMove); | ||
return TouchBackend; | ||
return TouchBackendImpl; | ||
}(); | ||
var createBackend = function createBackend(manager, context) { | ||
var TouchBackend = function createBackend(manager) { | ||
var context = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return new TouchBackend(manager, context, options); | ||
return new TouchBackendImpl(manager, context, options); | ||
}; | ||
return createBackend; | ||
exports.TouchBackend = TouchBackend; | ||
exports.TouchBackendImpl = TouchBackendImpl; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).ReactDnDTouchBackend=t()}(this,(function(){"use strict";var e;!function(e){e.mouse="mouse",e.touch="touch",e.keyboard="keyboard"}(e||(e={}));var t={Left:1,Right:2,Center:4},n={Left:0,Center:1,Right:2};function o(e){return void 0===e.button||e.button===n.Left}function r(e){return!!e.targetTouches}var i=1;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}}var a=function(){var e=!1;try{addEventListener("test",(function(){}),Object.defineProperty({},"passive",{get:function(){return e=!0,!0}}))}catch(e){}return e}();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 d,c=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}}])&&u(t.prototype,n),o&&u(t,o),e}();function h(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 l(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var v=(l(d={},e.mouse,{start:"mousedown",move:"mousemove",end:"mouseup",contextmenu:"contextmenu"}),l(d,e.touch,{start:"touchstart",move:"touchmove",end:"touchend"}),l(d,e.keyboard,{keydown:"keydown"}),d),f=function(){function n(a,u,d){var h=this;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),this.getSourceClientOffset=function(e){return function(e){var t=e.nodeType===i?e:e.parentElement;if(t){var n=t.getBoundingClientRect(),o=n.top;return{x:n.left,y:o}}}(h.sourceNodes[e])},this.handleTopMoveStartCapture=function(e){o(e)&&(h.moveStartSourceIds=[])},this.handleMoveStart=function(e){Array.isArray(h.moveStartSourceIds)&&h.moveStartSourceIds.unshift(e)},this.handleTopMoveStart=function(e){if(o(e)){var t=s(e);t&&(r(e)&&(h.lastTargetTouchFallback=e.targetTouches[0]),h._mouseClientOffset=t),h.waitingForDelay=!1}},this.handleTopMoveStartDelay=function(e){if(o(e)){var t=e.type===v.touch.start?h.options.delayTouchStart:h.options.delayMouseStart;h.timeout=setTimeout(h.handleTopMoveStart.bind(h,e),t),h.waitingForDelay=!0}},this.handleTopMoveCapture=function(){h.dragOverTargetIds=[]},this.handleMove=function(e,t){h.dragOverTargetIds&&h.dragOverTargetIds.unshift(t)},this.handleTopMove=function(e){if(h.timeout&&clearTimeout(h.timeout),h.document&&!h.waitingForDelay){var t,n,o,r,i=h.moveStartSourceIds,a=h.dragOverTargetIds,u=h.options.enableHoverOutsideTarget,d=s(e,h.lastTargetTouchFallback);if(d)if(h._isScrolling||!h.monitor.isDragging()&&function(e,t,n,o,r){if(!r)return!1;for(var i=180*Math.atan2(o-t,n-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}(h._mouseClientOffset.x||0,h._mouseClientOffset.y||0,d.x,d.y,h.options.scrollAngleRanges))h._isScrolling=!0;else if(!h.monitor.isDragging()&&h._mouseClientOffset.hasOwnProperty("x")&&i&&(t=h._mouseClientOffset.x||0,n=h._mouseClientOffset.y||0,o=d.x,r=d.y,Math.sqrt(Math.pow(Math.abs(o-t),2)+Math.pow(Math.abs(r-n),2))>(h.options.touchSlop?h.options.touchSlop:0))&&(h.moveStartSourceIds=void 0,h.actions.beginDrag(i,{clientOffset:h._mouseClientOffset,getSourceClientOffset:h.getSourceClientOffset,publishSource:!1})),h.monitor.isDragging()){var c=h.sourceNodes[h.monitor.getSourceId()];h.installSourceNodeRemovalObserver(c),h.actions.publishDragSource(),e.preventDefault();var l=(a||[]).map((function(e){return h.targetNodes[e]})),v=h.options.getDropTargetElementsAtPoint?h.options.getDropTargetElementsAtPoint(d.x,d.y,l):h.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 h.targetNodes)if(e===h.targetNodes[t])return t})).filter((function(e){return!!e})).filter((function(e,t,n){return n.indexOf(e)===t}));if(u)for(var w in h.targetNodes)if(h.targetNodes[w]&&h.targetNodes[w].contains(c)&&-1===m.indexOf(w)){m.unshift(w);break}m.reverse(),h.actions.hover(m,{clientOffset:d})}}},this.handleTopMoveEndCapture=function(e){h._isScrolling=!1,h.lastTargetTouchFallback=void 0,function(e){return void 0===e.buttons||0==(e.buttons&t.Left)}(e)&&(h.monitor.isDragging()&&!h.monitor.didDrop()?(e.preventDefault(),h._mouseClientOffset={},h.uninstallSourceNodeRemovalObserver(),h.actions.drop(),h.actions.endDrag()):h.moveStartSourceIds=void 0)},this.handleCancelOnEscape=function(e){"Escape"===e.key&&h.monitor.isDragging()&&(h._mouseClientOffset={},h.uninstallSourceNodeRemovalObserver(),h.actions.endDrag())},this.options=new c(d,u),this.actions=a.getActions(),this.monitor=a.getMonitor(),this.sourceNodes={},this.sourcePreviewNodes={},this.sourcePreviewNodeOptions={},this.targetNodes={},this.listenerTypes=[],this._mouseClientOffset={},this._isScrolling=!1,this.options.enableMouseEvents&&this.listenerTypes.push(e.mouse),this.options.enableTouchEvents&&this.listenerTypes.push(e.touch),this.options.enableKeyboardEvents&&this.listenerTypes.push(e.keyboard)}var u,d,l;return u=n,(d=[{key:"setup",value:function(){this.window&&(function(e,t){for(var n=arguments.length,o=new Array(n>2?n-2:0),r=2;r<n;r++)o[r-2]=arguments[r];if("production"!=="production"&&void 0===t)throw new Error("invariant requires an error message argument");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 o[s++]})))).name="Invariant Violation"}throw i.framesToPop=1,i}}(!n.isSetUp,"Cannot have two Touch backends at the same time."),n.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&&(n.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 r=a?{capture:o,passive:!1}:o;this.listenerTypes.forEach((function(o){var i=v[o][t];i&&e.addEventListener(i,n,r)}))}},{key:"removeEventListener",value:function(e,t,n,o){var r=a?{capture:o,passive:!1}:o;this.listenerTypes.forEach((function(o){var i=v[o][t];i&&e.removeEventListener(i,n,r)}))}},{key:"connectDragSource",value:function(e,t){var n=this,o=this.handleMoveStart.bind(this,e);return this.sourceNodes[e]=t,this.addEventListener(t,"start",o),function(){delete n.sourceNodes[e],n.removeEventListener(t,"start",o)}}},{key:"connectDragPreview",value:function(e,t,n){var o=this;return this.sourcePreviewNodeOptions[e]=n,this.sourcePreviewNodes[e]=t,function(){delete o.sourcePreviewNodes[e],delete o.sourcePreviewNodeOptions[e]}}},{key:"connectDropTarget",value:function(e,t){var n=this;if(!this.document)return function(){return null};var o=function(o){if(n.document&&n.monitor.isDragging()){var r;switch(o.type){case v.mouse.move:r={x:o.clientX,y:o.clientY};break;case v.touch.move:r={x:o.touches[0].clientX,y:o.touches[0].clientY}}var i=null!=r?n.document.elementFromPoint(r.x,r.y):void 0,s=i&&t.contains(i);return i===t||s?n.handleMove(o,e):void 0}};return this.addEventListener(this.document.body,"move",o),this.targetNodes[e]=t,function(){n.document&&(delete n.targetNodes[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}}])&&h(u.prototype,d),l&&h(u,l),n}();return function(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return new f(e,t,n)}})); | ||
!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})})); |
import { BackendFactory } from 'dnd-core'; | ||
declare const createBackend: BackendFactory; | ||
export default createBackend; | ||
export * from './TouchBackendImpl'; | ||
export declare const TouchBackend: BackendFactory; |
@@ -1,3 +0,5 @@ | ||
import TouchBackend from './TouchBackend'; | ||
const createBackend = (manager, context, options = {}) => new TouchBackend(manager, context, options); | ||
export default createBackend; | ||
import { TouchBackendImpl } from './TouchBackendImpl'; | ||
export * from './TouchBackendImpl'; | ||
export const TouchBackend = function createBackend(manager, context = {}, options = {}) { | ||
return new TouchBackendImpl(manager, context, options); | ||
}; |
@@ -19,3 +19,3 @@ export interface EventName { | ||
scrollAngleRanges?: AngleRange[]; | ||
getDropTargetElementsAtPoint?: Function; | ||
getDropTargetElementsAtPoint?: (x: number, y: number, dropTargets: HTMLElement[]) => HTMLElement[]; | ||
} | ||
@@ -31,1 +31,4 @@ export interface AngleRange { | ||
} | ||
export interface TouchBackendContext { | ||
window?: Window; | ||
} |
@@ -1,2 +0,2 @@ | ||
import { TouchBackendOptions, AngleRange } from './interfaces'; | ||
import { TouchBackendOptions, AngleRange, TouchBackendContext } from './interfaces'; | ||
export declare class OptionsReader implements TouchBackendOptions { | ||
@@ -12,7 +12,7 @@ enableTouchEvents: boolean; | ||
delayMouseStart: number; | ||
getDropTargetElementsAtPoint?: Function; | ||
getDropTargetElementsAtPoint?: (x: number, y: number, elements: HTMLElement[]) => HTMLElement[]; | ||
private context; | ||
constructor(incoming: TouchBackendOptions, context?: any); | ||
get window(): any; | ||
get document(): any; | ||
constructor(incoming: TouchBackendOptions, context: TouchBackendContext); | ||
get window(): Window | undefined; | ||
get document(): Document | undefined; | ||
} |
@@ -13,3 +13,3 @@ export class OptionsReader { | ||
this.delayMouseStart = incoming.delayMouseStart || incoming.delay || 0; | ||
Object.keys(incoming).forEach(key => { | ||
Object.keys(incoming).forEach((key) => { | ||
if (incoming[key] != null) { | ||
@@ -16,0 +16,0 @@ ; |
import { XYCoord } from 'dnd-core'; | ||
export declare function getNodeClientOffset(node: any): XYCoord | undefined; | ||
export declare function getNodeClientOffset(node: Element): XYCoord | undefined; | ||
export declare function getEventClientTouchOffset(e: TouchEvent, lastTargetTouchFallback?: Touch): XYCoord | undefined; | ||
export declare function getEventClientOffset(e: TouchEvent | Touch | MouseEvent, lastTargetTouchFallback?: Touch): XYCoord | undefined; |
@@ -5,3 +5,3 @@ /** | ||
*/ | ||
export declare function eventShouldStartDrag(e: any): boolean; | ||
export declare function eventShouldStartDrag(e: MouseEvent): boolean; | ||
/** | ||
@@ -13,3 +13,3 @@ * Only touch events and mouse events where the left mouse button is no longer held should end a drag. | ||
*/ | ||
export declare function eventShouldEndDrag(e: any): boolean; | ||
export declare function eventShouldEndDrag(e: MouseEvent): boolean; | ||
export declare function isTouchEvent(e: Touch | TouchEvent | MouseEvent): e is TouchEvent; |
@@ -1,2 +0,1 @@ | ||
declare const supportsPassive: boolean; | ||
export default supportsPassive; | ||
export declare const supportsPassive: boolean; |
@@ -1,2 +0,2 @@ | ||
const supportsPassive = (() => { | ||
export const supportsPassive = (() => { | ||
// simular to jQuery's test | ||
@@ -19,2 +19,1 @@ let supported = false; | ||
})(); | ||
export default supportsPassive; |
{ | ||
"name": "react-dnd-touch-backend", | ||
"version": "10.0.2", | ||
"version": "11.0.0", | ||
"description": "Touch backend for react-dnd", | ||
@@ -22,5 +22,5 @@ "main": "./dist/cjs/index.js", | ||
"@react-dnd/invariant": "^2.0.0", | ||
"dnd-core": "^10.0.2" | ||
"dnd-core": "^11.0.0" | ||
}, | ||
"gitHead": "5d16ab043eb83d49c5b6964ce276d0a6c15210d5" | ||
"gitHead": "418cb25315323efd6c0b9e23ccc28c5607d86edb" | ||
} |
import path from 'path' | ||
import resolve from 'rollup-plugin-node-resolve' | ||
import commonjs from 'rollup-plugin-commonjs' | ||
import resolve from '@rollup/plugin-node-resolve' | ||
import commonjs from '@rollup/plugin-commonjs' | ||
import replace from '@rollup/plugin-replace' | ||
import { terser } from 'rollup-plugin-terser' | ||
import replace from '@rollup/plugin-replace' | ||
export default { | ||
input: path.resolve(__dirname, 'dist/esm/index.js'), | ||
output: [ | ||
{ | ||
name: 'ReactDnDTouchBackend', | ||
file: path.resolve(__dirname, 'dist/umd/ReactDnDTouchBackend.js'), | ||
format: 'umd', | ||
globals: { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'react-dnd': 'ReactDnD', | ||
const input = path.resolve(__dirname, 'dist/esm/index.js') | ||
function replaceNodeEnv(env) { | ||
return replace({ | ||
values: { 'process.env.NODE_ENV': JSON.stringify(env) }, | ||
delimiters: ['', ''], | ||
}) | ||
} | ||
const commonPlugins = [resolve({ browser: true }), commonjs()] | ||
const external = ['react', 'react-dom', 'react-dnd'] | ||
const globals = { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'react-dnd': 'ReactDnD', | ||
} | ||
export default [ | ||
{ | ||
input, | ||
external, | ||
plugins: [...commonPlugins, replaceNodeEnv('development')], | ||
output: [ | ||
{ | ||
name: 'ReactDnDTouchBackend', | ||
file: path.resolve(__dirname, 'dist/umd/ReactDnDTouchBackend.js'), | ||
format: 'umd', | ||
globals, | ||
}, | ||
plugins: [ | ||
replace({ | ||
values: { 'process.env.NODE_ENV': JSON.stringify('development') }, | ||
delimiters: ['', ''], | ||
}), | ||
], | ||
}, | ||
{ | ||
name: 'ReactDnDTouchBackend', | ||
file: path.resolve(__dirname, 'dist/umd/ReactDnDTouchBackend.min.js'), | ||
format: 'umd', | ||
globals: { | ||
react: 'React', | ||
'react-dom': 'ReactDOM', | ||
'react-dnd': 'ReactDnD', | ||
], | ||
}, | ||
{ | ||
input, | ||
external, | ||
plugins: [...commonPlugins, replaceNodeEnv('production'), terser()], | ||
output: [ | ||
{ | ||
name: 'ReactDnDTouchBackend', | ||
file: path.resolve(__dirname, 'dist/umd/ReactDnDTouchBackend.min.js'), | ||
format: 'umd', | ||
globals, | ||
}, | ||
plugins: [ | ||
terser(), | ||
replace({ | ||
values: { 'process.env.NODE_ENV': JSON.stringify('production') }, | ||
delimiters: ['', ''], | ||
}), | ||
], | ||
}, | ||
], | ||
external: ['react', 'react-dom', 'react-dnd'], | ||
plugins: [resolve({ browser: true }), commonjs()], | ||
} | ||
], | ||
}, | ||
] |
import { DragDropManager, BackendFactory } from 'dnd-core' | ||
import { TouchBackendOptions } from './interfaces' | ||
import TouchBackend from './TouchBackend' | ||
import { TouchBackendOptions, TouchBackendContext } from './interfaces' | ||
import { TouchBackendImpl } from './TouchBackendImpl' | ||
export * from './TouchBackendImpl' | ||
const createBackend: BackendFactory = ( | ||
export const TouchBackend: BackendFactory = function createBackend( | ||
manager: DragDropManager, | ||
context: any, | ||
context: TouchBackendContext = {}, | ||
options: TouchBackendOptions = {}, | ||
) => new TouchBackend(manager, context, options) | ||
export default createBackend | ||
): TouchBackendImpl { | ||
return new TouchBackendImpl(manager, context, options) | ||
} |
@@ -20,3 +20,7 @@ export interface EventName { | ||
scrollAngleRanges?: AngleRange[] | ||
getDropTargetElementsAtPoint?: Function | ||
getDropTargetElementsAtPoint?: ( | ||
x: number, | ||
y: number, | ||
dropTargets: HTMLElement[], | ||
) => HTMLElement[] | ||
} | ||
@@ -34,1 +38,5 @@ | ||
} | ||
export interface TouchBackendContext { | ||
window?: Window | ||
} |
@@ -1,2 +0,6 @@ | ||
import { TouchBackendOptions, AngleRange } from './interfaces' | ||
import { | ||
TouchBackendOptions, | ||
AngleRange, | ||
TouchBackendContext, | ||
} from './interfaces' | ||
@@ -13,6 +17,13 @@ export class OptionsReader implements TouchBackendOptions { | ||
public delayMouseStart: number | ||
public getDropTargetElementsAtPoint?: Function | ||
private context: any | ||
public getDropTargetElementsAtPoint?: ( | ||
x: number, | ||
y: number, | ||
elements: HTMLElement[], | ||
) => HTMLElement[] | ||
private context: TouchBackendContext | ||
public constructor(incoming: TouchBackendOptions, context?: any) { | ||
public constructor( | ||
incoming: TouchBackendOptions, | ||
context: TouchBackendContext, | ||
) { | ||
this.context = context | ||
@@ -22,3 +33,3 @@ this.delayTouchStart = incoming.delayTouchStart || incoming.delay || 0 | ||
Object.keys(incoming).forEach(key => { | ||
Object.keys(incoming).forEach((key) => { | ||
if ((incoming as any)[key] != null) { | ||
@@ -30,3 +41,3 @@ ;(this as any)[key] = (incoming as any)[key] | ||
public get window() { | ||
public get window(): Window | undefined { | ||
if (this.context && this.context.window) { | ||
@@ -40,3 +51,3 @@ return this.context.window | ||
public get document() { | ||
public get document(): Document | undefined { | ||
if (this.window) { | ||
@@ -43,0 +54,0 @@ return this.window.document |
import { AngleRange } from '../interfaces' | ||
export function distance(x1: number, y1: number, x2: number, y2: number) { | ||
export function distance( | ||
x1: number, | ||
y1: number, | ||
x2: number, | ||
y2: number, | ||
): number { | ||
return Math.sqrt( | ||
@@ -15,3 +20,3 @@ Math.pow(Math.abs(x2 - x1), 2) + Math.pow(Math.abs(y2 - y1), 2), | ||
angleRanges?: AngleRange[], | ||
) { | ||
): boolean { | ||
if (!angleRanges) { | ||
@@ -18,0 +23,0 @@ return false |
@@ -6,3 +6,3 @@ import { XYCoord } from 'dnd-core' | ||
export function getNodeClientOffset(node: any): XYCoord | undefined { | ||
export function getNodeClientOffset(node: Element): XYCoord | undefined { | ||
const el = node.nodeType === ELEMENT_NODE ? node : node.parentElement | ||
@@ -9,0 +9,0 @@ if (!el) { |
@@ -19,3 +19,3 @@ // Used for MouseEvent.buttons (note the s on the end). | ||
*/ | ||
export function eventShouldStartDrag(e: any) { | ||
export function eventShouldStartDrag(e: MouseEvent): boolean { | ||
// For touch events, button will be undefined. If e.button is defined, | ||
@@ -32,3 +32,3 @@ // then it should be MouseButton.Left. | ||
*/ | ||
export function eventShouldEndDrag(e: any) { | ||
export function eventShouldEndDrag(e: MouseEvent): boolean { | ||
// Touch events will have buttons be undefined, while mouse events will have e.buttons's left button | ||
@@ -35,0 +35,0 @@ // bit field unset if the left mouse button has been released |
@@ -1,2 +0,2 @@ | ||
const supportsPassive = (() => { | ||
export const supportsPassive = ((): boolean => { | ||
// simular to jQuery's test | ||
@@ -22,2 +22,1 @@ let supported = false | ||
})() | ||
export default supportsPassive |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
355084
49
3391
1
+ Addeddnd-core@11.1.3(transitive)
- Removeddnd-core@10.0.2(transitive)
Updateddnd-core@^11.0.0