react-dnd-touch-backend
Advanced tools
Comparing version 9.3.1 to 9.3.2
@@ -14,4 +14,2 @@ "use strict"; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
var OptionsReader = | ||
@@ -25,24 +23,9 @@ /*#__PURE__*/ | ||
_defineProperty(this, "enableTouchEvents", true); | ||
_defineProperty(this, "enableMouseEvents", false); | ||
_defineProperty(this, "enableKeyboardEvents", false); | ||
_defineProperty(this, "ignoreContextMenu", false); | ||
_defineProperty(this, "enableHoverOutsideTarget", false); | ||
_defineProperty(this, "touchSlop", 0); | ||
_defineProperty(this, "scrollAngleRanges", undefined); | ||
_defineProperty(this, "delayTouchStart", void 0); | ||
_defineProperty(this, "delayMouseStart", void 0); | ||
_defineProperty(this, "getDropTargetElementsAtPoint", void 0); | ||
_defineProperty(this, "context", void 0); | ||
this.enableTouchEvents = true; | ||
this.enableMouseEvents = false; | ||
this.enableKeyboardEvents = false; | ||
this.ignoreContextMenu = false; | ||
this.enableHoverOutsideTarget = false; | ||
this.touchSlop = 0; | ||
this.scrollAngleRanges = undefined; | ||
this.context = context; | ||
@@ -49,0 +32,0 @@ this.delayTouchStart = incoming.delayTouchStart || incoming.delay || 0; |
@@ -50,4 +50,2 @@ "use strict"; | ||
function () { | ||
// React-DnD Dependencies | ||
// Internal State | ||
function TouchBackend(manager, context, options) { | ||
@@ -58,39 +56,7 @@ var _this = this; | ||
_defineProperty(this, "options", void 0); | ||
_defineProperty(this, "actions", void 0); | ||
_defineProperty(this, "monitor", void 0); | ||
_defineProperty(this, "sourceNodes", void 0); | ||
_defineProperty(this, "sourcePreviewNodes", void 0); | ||
_defineProperty(this, "sourcePreviewNodeOptions", void 0); | ||
_defineProperty(this, "targetNodes", void 0); | ||
_defineProperty(this, "_mouseClientOffset", void 0); | ||
_defineProperty(this, "_isScrolling", void 0); | ||
_defineProperty(this, "listenerTypes", void 0); | ||
_defineProperty(this, "moveStartSourceIds", void 0); | ||
_defineProperty(this, "waitingForDelay", void 0); | ||
_defineProperty(this, "timeout", void 0); | ||
_defineProperty(this, "dragOverTargetIds", void 0); | ||
_defineProperty(this, "draggedSourceNode", void 0); | ||
_defineProperty(this, "draggedSourceNodeRemovalObserver", void 0); | ||
_defineProperty(this, "getSourceClientOffset", function (sourceId) { | ||
this.getSourceClientOffset = function (sourceId) { | ||
return (0, _offsets.getNodeClientOffset)(_this.sourceNodes[sourceId]); | ||
}); | ||
}; | ||
_defineProperty(this, "handleTopMoveStartCapture", function (e) { | ||
this.handleTopMoveStartCapture = function (e) { | ||
if (!(0, _predicates.eventShouldStartDrag)(e)) { | ||
@@ -101,5 +67,5 @@ return; | ||
_this.moveStartSourceIds = []; | ||
}); | ||
}; | ||
_defineProperty(this, "handleMoveStart", function (sourceId) { | ||
this.handleMoveStart = function (sourceId) { | ||
// Just because we received an event doesn't necessarily mean we need to collect drag sources. | ||
@@ -110,5 +76,5 @@ // We only collect start collecting drag sources on touch and left mouse events. | ||
} | ||
}); | ||
}; | ||
_defineProperty(this, "handleTopMoveStart", function (e) { | ||
this.handleTopMoveStart = function (e) { | ||
if (!(0, _predicates.eventShouldStartDrag)(e)) { | ||
@@ -129,5 +95,5 @@ return; | ||
_this.waitingForDelay = false; | ||
}); | ||
}; | ||
_defineProperty(this, "handleTopMoveStartDelay", function (e) { | ||
this.handleTopMoveStartDelay = function (e) { | ||
if (!(0, _predicates.eventShouldStartDrag)(e)) { | ||
@@ -140,15 +106,15 @@ return; | ||
_this.waitingForDelay = true; | ||
}); | ||
}; | ||
_defineProperty(this, "handleTopMoveCapture", function () { | ||
this.handleTopMoveCapture = function () { | ||
_this.dragOverTargetIds = []; | ||
}); | ||
}; | ||
_defineProperty(this, "handleMove", function (_, targetId) { | ||
this.handleMove = function (_, targetId) { | ||
if (_this.dragOverTargetIds) { | ||
_this.dragOverTargetIds.unshift(targetId); | ||
} | ||
}); | ||
}; | ||
_defineProperty(this, "handleTopMove", function (e) { | ||
this.handleTopMove = function (e) { | ||
if (_this.timeout) { | ||
@@ -261,5 +227,5 @@ clearTimeout(_this.timeout); | ||
}); | ||
}); | ||
}; | ||
_defineProperty(this, "handleTopMoveEndCapture", function (e) { | ||
this.handleTopMoveEndCapture = function (e) { | ||
_this._isScrolling = false; | ||
@@ -284,5 +250,5 @@ | ||
_this.actions.endDrag(); | ||
}); | ||
}; | ||
_defineProperty(this, "handleCancelOnEscape", function (e) { | ||
this.handleCancelOnEscape = function (e) { | ||
if (e.key === 'Escape' && _this.monitor.isDragging()) { | ||
@@ -295,3 +261,3 @@ _this._mouseClientOffset = {}; | ||
} | ||
}); | ||
}; | ||
@@ -562,4 +528,2 @@ this.options = new _OptionsReader.OptionsReader(options, context); | ||
exports.default = TouchBackend; | ||
_defineProperty(TouchBackend, "isSetUp", void 0); | ||
exports.default = TouchBackend; |
@@ -13,5 +13,5 @@ "use strict"; | ||
Right: 2, | ||
Center: 4 // Used for e.button (note the lack of an s on the end). | ||
Center: 4 | ||
}; // Used for e.button (note the lack of an s on the end). | ||
}; | ||
var MouseButton = { | ||
@@ -21,8 +21,7 @@ Left: 0, | ||
Right: 2 | ||
/** | ||
* Only touch events and mouse events where the left button is pressed should initiate a drag. | ||
* @param {MouseEvent | TouchEvent} e The event | ||
*/ | ||
}; | ||
/** | ||
* Only touch events and mouse events where the left button is pressed should initiate a drag. | ||
* @param {MouseEvent | TouchEvent} e The event | ||
*/ | ||
@@ -29,0 +28,0 @@ function eventShouldStartDrag(e) { |
import TouchBackend from './TouchBackend'; | ||
var createTouchBackendFactory = function createTouchBackendFactory(manager, context) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
return new TouchBackend(manager, context, options); | ||
}; | ||
export default createTouchBackendFactory; | ||
const createTouchBackendFactory = (manager, context, options = {}) => new TouchBackend(manager, context, options); | ||
export default createTouchBackendFactory; |
export var ListenerType; | ||
(function (ListenerType) { | ||
ListenerType["mouse"] = "mouse"; | ||
ListenerType["touch"] = "touch"; | ||
ListenerType["keyboard"] = "keyboard"; | ||
})(ListenerType || (ListenerType = {})); | ||
ListenerType["mouse"] = "mouse"; | ||
ListenerType["touch"] = "touch"; | ||
ListenerType["keyboard"] = "keyboard"; | ||
})(ListenerType || (ListenerType = {})); |
@@ -1,73 +0,35 @@ | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
export var OptionsReader = | ||
/*#__PURE__*/ | ||
function () { | ||
function OptionsReader(incoming, context) { | ||
var _this = this; | ||
_classCallCheck(this, OptionsReader); | ||
_defineProperty(this, "enableTouchEvents", true); | ||
_defineProperty(this, "enableMouseEvents", false); | ||
_defineProperty(this, "enableKeyboardEvents", false); | ||
_defineProperty(this, "ignoreContextMenu", false); | ||
_defineProperty(this, "enableHoverOutsideTarget", false); | ||
_defineProperty(this, "touchSlop", 0); | ||
_defineProperty(this, "scrollAngleRanges", undefined); | ||
_defineProperty(this, "delayTouchStart", void 0); | ||
_defineProperty(this, "delayMouseStart", void 0); | ||
_defineProperty(this, "getDropTargetElementsAtPoint", void 0); | ||
_defineProperty(this, "context", void 0); | ||
this.context = context; | ||
this.delayTouchStart = incoming.delayTouchStart || incoming.delay || 0; | ||
this.delayMouseStart = incoming.delayMouseStart || incoming.delay || 0; | ||
Object.keys(incoming).forEach(function (key) { | ||
if (incoming[key] != null) { | ||
; | ||
_this[key] = incoming[key]; | ||
} | ||
}); | ||
} | ||
_createClass(OptionsReader, [{ | ||
key: "window", | ||
get: function get() { | ||
if (this.context && this.context.window) { | ||
return this.context.window; | ||
} else if (typeof window !== 'undefined') { | ||
return window; | ||
} | ||
return undefined; | ||
export class OptionsReader { | ||
constructor(incoming, context) { | ||
this.enableTouchEvents = true; | ||
this.enableMouseEvents = false; | ||
this.enableKeyboardEvents = false; | ||
this.ignoreContextMenu = false; | ||
this.enableHoverOutsideTarget = false; | ||
this.touchSlop = 0; | ||
this.scrollAngleRanges = undefined; | ||
this.context = context; | ||
this.delayTouchStart = incoming.delayTouchStart || incoming.delay || 0; | ||
this.delayMouseStart = incoming.delayMouseStart || incoming.delay || 0; | ||
Object.keys(incoming).forEach(key => { | ||
if (incoming[key] != null) { | ||
; | ||
this[key] = incoming[key]; | ||
} | ||
}); | ||
} | ||
}, { | ||
key: "document", | ||
get: function get() { | ||
if (this.window) { | ||
return this.window.document; | ||
} | ||
return undefined; | ||
get window() { | ||
if (this.context && this.context.window) { | ||
return this.context.window; | ||
} | ||
else if (typeof window !== 'undefined') { | ||
return window; | ||
} | ||
return undefined; | ||
} | ||
}]); | ||
return OptionsReader; | ||
}(); | ||
get document() { | ||
if (this.window) { | ||
return this.window.document; | ||
} | ||
return undefined; | ||
} | ||
} |
@@ -1,11 +0,1 @@ | ||
var _eventNames; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
import invariant from 'invariant'; | ||
@@ -18,523 +8,376 @@ import { ListenerType } from './interfaces'; | ||
import { OptionsReader } from './OptionsReader'; | ||
var eventNames = (_eventNames = {}, _defineProperty(_eventNames, ListenerType.mouse, { | ||
start: 'mousedown', | ||
move: 'mousemove', | ||
end: 'mouseup', | ||
contextmenu: 'contextmenu' | ||
}), _defineProperty(_eventNames, ListenerType.touch, { | ||
start: 'touchstart', | ||
move: 'touchmove', | ||
end: 'touchend' | ||
}), _defineProperty(_eventNames, ListenerType.keyboard, { | ||
keydown: 'keydown' | ||
}), _eventNames); | ||
var TouchBackend = | ||
/*#__PURE__*/ | ||
function () { | ||
// React-DnD Dependencies | ||
// Internal State | ||
function TouchBackend(manager, context, options) { | ||
var _this = this; | ||
_classCallCheck(this, TouchBackend); | ||
_defineProperty(this, "options", void 0); | ||
_defineProperty(this, "actions", void 0); | ||
_defineProperty(this, "monitor", void 0); | ||
_defineProperty(this, "sourceNodes", void 0); | ||
_defineProperty(this, "sourcePreviewNodes", void 0); | ||
_defineProperty(this, "sourcePreviewNodeOptions", void 0); | ||
_defineProperty(this, "targetNodes", void 0); | ||
_defineProperty(this, "_mouseClientOffset", void 0); | ||
_defineProperty(this, "_isScrolling", void 0); | ||
_defineProperty(this, "listenerTypes", void 0); | ||
_defineProperty(this, "moveStartSourceIds", void 0); | ||
_defineProperty(this, "waitingForDelay", void 0); | ||
_defineProperty(this, "timeout", void 0); | ||
_defineProperty(this, "dragOverTargetIds", void 0); | ||
_defineProperty(this, "draggedSourceNode", void 0); | ||
_defineProperty(this, "draggedSourceNodeRemovalObserver", void 0); | ||
_defineProperty(this, "getSourceClientOffset", function (sourceId) { | ||
return getNodeClientOffset(_this.sourceNodes[sourceId]); | ||
}); | ||
_defineProperty(this, "handleTopMoveStartCapture", function (e) { | ||
if (!eventShouldStartDrag(e)) { | ||
return; | ||
} | ||
_this.moveStartSourceIds = []; | ||
}); | ||
_defineProperty(this, "handleMoveStart", function (sourceId) { | ||
// Just because we received an event doesn't necessarily mean we need to collect drag sources. | ||
// We only collect start collecting drag sources on touch and left mouse events. | ||
if (Array.isArray(_this.moveStartSourceIds)) { | ||
_this.moveStartSourceIds.unshift(sourceId); | ||
} | ||
}); | ||
_defineProperty(this, "handleTopMoveStart", function (e) { | ||
if (!eventShouldStartDrag(e)) { | ||
return; | ||
} // Don't prematurely preventDefault() here since it might: | ||
// 1. Mess up scrolling | ||
// 2. Mess up long tap (which brings up context menu) | ||
// 3. If there's an anchor link as a child, tap won't be triggered on link | ||
var clientOffset = getEventClientOffset(e); | ||
if (clientOffset) { | ||
_this._mouseClientOffset = clientOffset; | ||
} | ||
_this.waitingForDelay = false; | ||
}); | ||
_defineProperty(this, "handleTopMoveStartDelay", function (e) { | ||
if (!eventShouldStartDrag(e)) { | ||
return; | ||
} | ||
var delay = e.type === eventNames.touch.start ? _this.options.delayTouchStart : _this.options.delayMouseStart; | ||
_this.timeout = setTimeout(_this.handleTopMoveStart.bind(_this, e), delay); | ||
_this.waitingForDelay = true; | ||
}); | ||
_defineProperty(this, "handleTopMoveCapture", function () { | ||
_this.dragOverTargetIds = []; | ||
}); | ||
_defineProperty(this, "handleMove", function (_, targetId) { | ||
if (_this.dragOverTargetIds) { | ||
_this.dragOverTargetIds.unshift(targetId); | ||
} | ||
}); | ||
_defineProperty(this, "handleTopMove", function (e) { | ||
if (_this.timeout) { | ||
clearTimeout(_this.timeout); | ||
} | ||
if (!_this.document || _this.waitingForDelay) { | ||
return; | ||
} | ||
var moveStartSourceIds = _this.moveStartSourceIds, | ||
dragOverTargetIds = _this.dragOverTargetIds; | ||
var enableHoverOutsideTarget = _this.options.enableHoverOutsideTarget; | ||
var clientOffset = getEventClientOffset(e); | ||
if (!clientOffset) { | ||
return; | ||
} // If the touch move started as a scroll, or is is between the scroll angles | ||
if (_this._isScrolling || !_this.monitor.isDragging() && inAngleRanges(_this._mouseClientOffset.x || 0, _this._mouseClientOffset.y || 0, clientOffset.x, clientOffset.y, _this.options.scrollAngleRanges)) { | ||
_this._isScrolling = true; | ||
return; | ||
} // If we're not dragging and we've moved a little, that counts as a drag start | ||
if (!_this.monitor.isDragging() && // eslint-disable-next-line no-prototype-builtins | ||
_this._mouseClientOffset.hasOwnProperty('x') && moveStartSourceIds && distance(_this._mouseClientOffset.x || 0, _this._mouseClientOffset.y || 0, clientOffset.x, clientOffset.y) > (_this.options.touchSlop ? _this.options.touchSlop : 0)) { | ||
_this.moveStartSourceIds = undefined; | ||
_this.actions.beginDrag(moveStartSourceIds, { | ||
clientOffset: _this._mouseClientOffset, | ||
getSourceClientOffset: _this.getSourceClientOffset, | ||
publishSource: false | ||
}); | ||
} | ||
if (!_this.monitor.isDragging()) { | ||
return; | ||
} | ||
var sourceNode = _this.sourceNodes[_this.monitor.getSourceId()]; | ||
_this.installSourceNodeRemovalObserver(sourceNode); | ||
_this.actions.publishDragSource(); | ||
e.preventDefault(); // Get the node elements of the hovered DropTargets | ||
var dragOverTargetNodes = (dragOverTargetIds || []).map(function (key) { | ||
return _this.targetNodes[key]; | ||
}); // Get the a ordered list of nodes that are touched by | ||
var elementsAtPoint = _this.options.getDropTargetElementsAtPoint ? _this.options.getDropTargetElementsAtPoint(clientOffset.x, clientOffset.y, dragOverTargetNodes) : _this.document.elementsFromPoint(clientOffset.x, clientOffset.y); // Extend list with parents that are not receiving elementsFromPoint events (size 0 elements and svg groups) | ||
var elementsAtPointExtended = []; | ||
for (var nodeId in elementsAtPoint) { | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (!elementsAtPoint.hasOwnProperty(nodeId)) { | ||
continue; | ||
const eventNames = { | ||
[ListenerType.mouse]: { | ||
start: 'mousedown', | ||
move: 'mousemove', | ||
end: 'mouseup', | ||
contextmenu: 'contextmenu', | ||
}, | ||
[ListenerType.touch]: { | ||
start: 'touchstart', | ||
move: 'touchmove', | ||
end: 'touchend', | ||
}, | ||
[ListenerType.keyboard]: { | ||
keydown: 'keydown', | ||
}, | ||
}; | ||
export default class TouchBackend { | ||
constructor(manager, context, options) { | ||
this.getSourceClientOffset = (sourceId) => { | ||
return getNodeClientOffset(this.sourceNodes[sourceId]); | ||
}; | ||
this.handleTopMoveStartCapture = (e) => { | ||
if (!eventShouldStartDrag(e)) { | ||
return; | ||
} | ||
this.moveStartSourceIds = []; | ||
}; | ||
this.handleMoveStart = (sourceId) => { | ||
// Just because we received an event doesn't necessarily mean we need to collect drag sources. | ||
// We only collect start collecting drag sources on touch and left mouse events. | ||
if (Array.isArray(this.moveStartSourceIds)) { | ||
this.moveStartSourceIds.unshift(sourceId); | ||
} | ||
}; | ||
this.handleTopMoveStart = (e) => { | ||
if (!eventShouldStartDrag(e)) { | ||
return; | ||
} | ||
// Don't prematurely preventDefault() here since it might: | ||
// 1. Mess up scrolling | ||
// 2. Mess up long tap (which brings up context menu) | ||
// 3. If there's an anchor link as a child, tap won't be triggered on link | ||
const clientOffset = getEventClientOffset(e); | ||
if (clientOffset) { | ||
this._mouseClientOffset = clientOffset; | ||
} | ||
this.waitingForDelay = false; | ||
}; | ||
this.handleTopMoveStartDelay = (e) => { | ||
if (!eventShouldStartDrag(e)) { | ||
return; | ||
} | ||
const delay = e.type === eventNames.touch.start | ||
? this.options.delayTouchStart | ||
: this.options.delayMouseStart; | ||
this.timeout = setTimeout(this.handleTopMoveStart.bind(this, e), delay); | ||
this.waitingForDelay = true; | ||
}; | ||
this.handleTopMoveCapture = () => { | ||
this.dragOverTargetIds = []; | ||
}; | ||
this.handleMove = (_, targetId) => { | ||
if (this.dragOverTargetIds) { | ||
this.dragOverTargetIds.unshift(targetId); | ||
} | ||
}; | ||
this.handleTopMove = (e) => { | ||
if (this.timeout) { | ||
clearTimeout(this.timeout); | ||
} | ||
if (!this.document || this.waitingForDelay) { | ||
return; | ||
} | ||
const { moveStartSourceIds, dragOverTargetIds } = this; | ||
const enableHoverOutsideTarget = this.options.enableHoverOutsideTarget; | ||
const clientOffset = getEventClientOffset(e); | ||
if (!clientOffset) { | ||
return; | ||
} | ||
// If the touch move started as a scroll, or is is between the scroll angles | ||
if (this._isScrolling || | ||
(!this.monitor.isDragging() && | ||
inAngleRanges(this._mouseClientOffset.x || 0, this._mouseClientOffset.y || 0, clientOffset.x, clientOffset.y, this.options.scrollAngleRanges))) { | ||
this._isScrolling = true; | ||
return; | ||
} | ||
// If we're not dragging and we've moved a little, that counts as a drag start | ||
if (!this.monitor.isDragging() && | ||
// eslint-disable-next-line no-prototype-builtins | ||
this._mouseClientOffset.hasOwnProperty('x') && | ||
moveStartSourceIds && | ||
distance(this._mouseClientOffset.x || 0, this._mouseClientOffset.y || 0, clientOffset.x, clientOffset.y) > (this.options.touchSlop ? this.options.touchSlop : 0)) { | ||
this.moveStartSourceIds = undefined; | ||
this.actions.beginDrag(moveStartSourceIds, { | ||
clientOffset: this._mouseClientOffset, | ||
getSourceClientOffset: this.getSourceClientOffset, | ||
publishSource: false, | ||
}); | ||
} | ||
if (!this.monitor.isDragging()) { | ||
return; | ||
} | ||
const sourceNode = this.sourceNodes[this.monitor.getSourceId()]; | ||
this.installSourceNodeRemovalObserver(sourceNode); | ||
this.actions.publishDragSource(); | ||
e.preventDefault(); | ||
// Get the node elements of the hovered DropTargets | ||
const dragOverTargetNodes = (dragOverTargetIds || []).map(key => this.targetNodes[key]); | ||
// Get the a ordered list of nodes that are touched by | ||
let elementsAtPoint = this.options.getDropTargetElementsAtPoint | ||
? this.options.getDropTargetElementsAtPoint(clientOffset.x, clientOffset.y, dragOverTargetNodes) | ||
: this.document.elementsFromPoint(clientOffset.x, clientOffset.y); | ||
// Extend list with parents that are not receiving elementsFromPoint events (size 0 elements and svg groups) | ||
let elementsAtPointExtended = []; | ||
for (let nodeId in elementsAtPoint) { | ||
// eslint-disable-next-line no-prototype-builtins | ||
if (!elementsAtPoint.hasOwnProperty(nodeId)) { | ||
continue; | ||
} | ||
let currentNode = elementsAtPoint[nodeId]; | ||
elementsAtPointExtended.push(currentNode); | ||
while (currentNode) { | ||
currentNode = currentNode.parentElement; | ||
if (elementsAtPointExtended.indexOf(currentNode) === -1) { | ||
elementsAtPointExtended.push(currentNode); | ||
} | ||
} | ||
} | ||
let orderedDragOverTargetIds = elementsAtPointExtended | ||
// Filter off nodes that arent a hovered DropTargets nodes | ||
.filter(node => dragOverTargetNodes.indexOf(node) > -1) | ||
// Map back the nodes elements to targetIds | ||
.map(node => { | ||
for (let targetId in this.targetNodes) { | ||
if (node === this.targetNodes[targetId]) { | ||
return targetId; | ||
} | ||
} | ||
return undefined; | ||
}) | ||
// Filter off possible null rows | ||
.filter(node => !!node) | ||
.filter((id, index, ids) => ids.indexOf(id) === index); | ||
// Invoke hover for drop targets when source node is still over and pointer is outside | ||
if (enableHoverOutsideTarget) { | ||
for (let targetId in this.targetNodes) { | ||
if (this.targetNodes[targetId] && | ||
this.targetNodes[targetId].contains(sourceNode) && | ||
orderedDragOverTargetIds.indexOf(targetId) === -1) { | ||
orderedDragOverTargetIds.unshift(targetId); | ||
break; | ||
} | ||
} | ||
} | ||
// Reverse order because dnd-core reverse it before calling the DropTarget drop methods | ||
orderedDragOverTargetIds.reverse(); | ||
this.actions.hover(orderedDragOverTargetIds, { | ||
clientOffset: clientOffset, | ||
}); | ||
}; | ||
this.handleTopMoveEndCapture = (e) => { | ||
this._isScrolling = false; | ||
if (!eventShouldEndDrag(e)) { | ||
return; | ||
} | ||
if (!this.monitor.isDragging() || this.monitor.didDrop()) { | ||
this.moveStartSourceIds = undefined; | ||
return; | ||
} | ||
e.preventDefault(); | ||
this._mouseClientOffset = {}; | ||
this.uninstallSourceNodeRemovalObserver(); | ||
this.actions.drop(); | ||
this.actions.endDrag(); | ||
}; | ||
this.handleCancelOnEscape = (e) => { | ||
if (e.key === 'Escape' && this.monitor.isDragging()) { | ||
this._mouseClientOffset = {}; | ||
this.uninstallSourceNodeRemovalObserver(); | ||
this.actions.endDrag(); | ||
} | ||
}; | ||
this.options = new OptionsReader(options, context); | ||
this.actions = manager.getActions(); | ||
this.monitor = manager.getMonitor(); | ||
this.sourceNodes = {}; | ||
this.sourcePreviewNodes = {}; | ||
this.sourcePreviewNodeOptions = {}; | ||
this.targetNodes = {}; | ||
this.listenerTypes = []; | ||
this._mouseClientOffset = {}; | ||
this._isScrolling = false; | ||
if (this.options.enableMouseEvents) { | ||
this.listenerTypes.push(ListenerType.mouse); | ||
} | ||
var currentNode = elementsAtPoint[nodeId]; | ||
elementsAtPointExtended.push(currentNode); | ||
while (currentNode) { | ||
currentNode = currentNode.parentElement; | ||
if (elementsAtPointExtended.indexOf(currentNode) === -1) { | ||
elementsAtPointExtended.push(currentNode); | ||
} | ||
if (this.options.enableTouchEvents) { | ||
this.listenerTypes.push(ListenerType.touch); | ||
} | ||
} | ||
var orderedDragOverTargetIds = elementsAtPointExtended // Filter off nodes that arent a hovered DropTargets nodes | ||
.filter(function (node) { | ||
return dragOverTargetNodes.indexOf(node) > -1; | ||
}) // Map back the nodes elements to targetIds | ||
.map(function (node) { | ||
for (var targetId in _this.targetNodes) { | ||
if (node === _this.targetNodes[targetId]) { | ||
return targetId; | ||
} | ||
if (this.options.enableKeyboardEvents) { | ||
this.listenerTypes.push(ListenerType.keyboard); | ||
} | ||
return undefined; | ||
}) // Filter off possible null rows | ||
.filter(function (node) { | ||
return !!node; | ||
}).filter(function (id, index, ids) { | ||
return ids.indexOf(id) === index; | ||
}); // Invoke hover for drop targets when source node is still over and pointer is outside | ||
if (enableHoverOutsideTarget) { | ||
for (var targetId in _this.targetNodes) { | ||
if (_this.targetNodes[targetId] && _this.targetNodes[targetId].contains(sourceNode) && orderedDragOverTargetIds.indexOf(targetId) === -1) { | ||
orderedDragOverTargetIds.unshift(targetId); | ||
break; | ||
} | ||
} | ||
} // Reverse order because dnd-core reverse it before calling the DropTarget drop methods | ||
orderedDragOverTargetIds.reverse(); | ||
_this.actions.hover(orderedDragOverTargetIds, { | ||
clientOffset: clientOffset | ||
}); | ||
}); | ||
_defineProperty(this, "handleTopMoveEndCapture", function (e) { | ||
_this._isScrolling = false; | ||
if (!eventShouldEndDrag(e)) { | ||
return; | ||
} | ||
if (!_this.monitor.isDragging() || _this.monitor.didDrop()) { | ||
_this.moveStartSourceIds = undefined; | ||
return; | ||
} | ||
e.preventDefault(); | ||
_this._mouseClientOffset = {}; | ||
_this.uninstallSourceNodeRemovalObserver(); | ||
_this.actions.drop(); | ||
_this.actions.endDrag(); | ||
}); | ||
_defineProperty(this, "handleCancelOnEscape", function (e) { | ||
if (e.key === 'Escape' && _this.monitor.isDragging()) { | ||
_this._mouseClientOffset = {}; | ||
_this.uninstallSourceNodeRemovalObserver(); | ||
_this.actions.endDrag(); | ||
} | ||
}); | ||
this.options = new OptionsReader(options, context); | ||
this.actions = manager.getActions(); | ||
this.monitor = manager.getMonitor(); | ||
this.sourceNodes = {}; | ||
this.sourcePreviewNodes = {}; | ||
this.sourcePreviewNodeOptions = {}; | ||
this.targetNodes = {}; | ||
this.listenerTypes = []; | ||
this._mouseClientOffset = {}; | ||
this._isScrolling = false; | ||
if (this.options.enableMouseEvents) { | ||
this.listenerTypes.push(ListenerType.mouse); | ||
} | ||
if (this.options.enableTouchEvents) { | ||
this.listenerTypes.push(ListenerType.touch); | ||
// public for test | ||
get window() { | ||
return this.options.window; | ||
} | ||
if (this.options.enableKeyboardEvents) { | ||
this.listenerTypes.push(ListenerType.keyboard); | ||
// public for test | ||
get document() { | ||
if (this.window) { | ||
return this.window.document; | ||
} | ||
return undefined; | ||
} | ||
} // public for test | ||
_createClass(TouchBackend, [{ | ||
key: "setup", | ||
value: function setup() { | ||
if (!this.window) { | ||
return; | ||
} | ||
invariant(!TouchBackend.isSetUp, 'Cannot have two Touch backends at the same time.'); | ||
TouchBackend.isSetUp = true; | ||
this.addEventListener(this.window, 'start', this.getTopMoveStartHandler()); | ||
this.addEventListener(this.window, 'start', this.handleTopMoveStartCapture, true); | ||
this.addEventListener(this.window, 'move', this.handleTopMove); | ||
this.addEventListener(this.window, 'move', this.handleTopMoveCapture, true); | ||
this.addEventListener(this.window, 'end', this.handleTopMoveEndCapture, true); | ||
if (this.options.enableMouseEvents && !this.options.ignoreContextMenu) { | ||
this.addEventListener(this.window, 'contextmenu', this.handleTopMoveEndCapture); | ||
} | ||
if (this.options.enableKeyboardEvents) { | ||
this.addEventListener(this.window, 'keydown', this.handleCancelOnEscape, true); | ||
} | ||
} | ||
}, { | ||
key: "teardown", | ||
value: function teardown() { | ||
if (!this.window) { | ||
return; | ||
} | ||
TouchBackend.isSetUp = false; | ||
this._mouseClientOffset = {}; | ||
this.removeEventListener(this.window, 'start', this.handleTopMoveStartCapture, true); | ||
this.removeEventListener(this.window, 'start', this.handleTopMoveStart); | ||
this.removeEventListener(this.window, 'move', this.handleTopMoveCapture, true); | ||
this.removeEventListener(this.window, 'move', this.handleTopMove); | ||
this.removeEventListener(this.window, 'end', this.handleTopMoveEndCapture, true); | ||
if (this.options.enableMouseEvents && !this.options.ignoreContextMenu) { | ||
this.removeEventListener(this.window, 'contextmenu', this.handleTopMoveEndCapture); | ||
} | ||
if (this.options.enableKeyboardEvents) { | ||
this.removeEventListener(this.window, 'keydown', this.handleCancelOnEscape, true); | ||
} | ||
this.uninstallSourceNodeRemovalObserver(); | ||
} | ||
}, { | ||
key: "addEventListener", | ||
value: function addEventListener(subject, event, handler, capture) { | ||
var options = supportsPassive ? { | ||
capture: capture, | ||
passive: false | ||
} : capture; | ||
this.listenerTypes.forEach(function (listenerType) { | ||
var evt = eventNames[listenerType][event]; | ||
if (evt) { | ||
subject.addEventListener(evt, handler, options); | ||
setup() { | ||
if (!this.window) { | ||
return; | ||
} | ||
}); | ||
invariant(!TouchBackend.isSetUp, 'Cannot have two Touch backends at the same time.'); | ||
TouchBackend.isSetUp = true; | ||
this.addEventListener(this.window, 'start', this.getTopMoveStartHandler()); | ||
this.addEventListener(this.window, 'start', this.handleTopMoveStartCapture, true); | ||
this.addEventListener(this.window, 'move', this.handleTopMove); | ||
this.addEventListener(this.window, 'move', this.handleTopMoveCapture, true); | ||
this.addEventListener(this.window, 'end', this.handleTopMoveEndCapture, true); | ||
if (this.options.enableMouseEvents && !this.options.ignoreContextMenu) { | ||
this.addEventListener(this.window, 'contextmenu', this | ||
.handleTopMoveEndCapture); | ||
} | ||
if (this.options.enableKeyboardEvents) { | ||
this.addEventListener(this.window, 'keydown', this.handleCancelOnEscape, true); | ||
} | ||
} | ||
}, { | ||
key: "removeEventListener", | ||
value: function removeEventListener(subject, event, handler, capture) { | ||
var options = supportsPassive ? { | ||
capture: capture, | ||
passive: false | ||
} : capture; | ||
this.listenerTypes.forEach(function (listenerType) { | ||
var evt = eventNames[listenerType][event]; | ||
if (evt) { | ||
subject.removeEventListener(evt, handler, options); | ||
teardown() { | ||
if (!this.window) { | ||
return; | ||
} | ||
}); | ||
TouchBackend.isSetUp = false; | ||
this._mouseClientOffset = {}; | ||
this.removeEventListener(this.window, 'start', this.handleTopMoveStartCapture, true); | ||
this.removeEventListener(this.window, 'start', this | ||
.handleTopMoveStart); | ||
this.removeEventListener(this.window, 'move', this.handleTopMoveCapture, true); | ||
this.removeEventListener(this.window, 'move', this.handleTopMove); | ||
this.removeEventListener(this.window, 'end', this.handleTopMoveEndCapture, true); | ||
if (this.options.enableMouseEvents && !this.options.ignoreContextMenu) { | ||
this.removeEventListener(this.window, 'contextmenu', this | ||
.handleTopMoveEndCapture); | ||
} | ||
if (this.options.enableKeyboardEvents) { | ||
this.removeEventListener(this.window, 'keydown', this.handleCancelOnEscape, true); | ||
} | ||
this.uninstallSourceNodeRemovalObserver(); | ||
} | ||
}, { | ||
key: "connectDragSource", | ||
value: function connectDragSource(sourceId, node) { | ||
var _this2 = this; | ||
var handleMoveStart = this.handleMoveStart.bind(this, sourceId); | ||
this.sourceNodes[sourceId] = node; | ||
this.addEventListener(node, 'start', handleMoveStart); | ||
return function () { | ||
delete _this2.sourceNodes[sourceId]; | ||
_this2.removeEventListener(node, 'start', handleMoveStart); | ||
}; | ||
addEventListener(subject, event, handler, capture) { | ||
const options = supportsPassive ? { capture, passive: false } : capture; | ||
this.listenerTypes.forEach(function (listenerType) { | ||
const evt = eventNames[listenerType][event]; | ||
if (evt) { | ||
subject.addEventListener(evt, handler, options); | ||
} | ||
}); | ||
} | ||
}, { | ||
key: "connectDragPreview", | ||
value: function connectDragPreview(sourceId, node, options) { | ||
var _this3 = this; | ||
this.sourcePreviewNodeOptions[sourceId] = options; | ||
this.sourcePreviewNodes[sourceId] = node; | ||
return function () { | ||
delete _this3.sourcePreviewNodes[sourceId]; | ||
delete _this3.sourcePreviewNodeOptions[sourceId]; | ||
}; | ||
removeEventListener(subject, event, handler, capture) { | ||
const options = supportsPassive ? { capture, passive: false } : capture; | ||
this.listenerTypes.forEach(function (listenerType) { | ||
const evt = eventNames[listenerType][event]; | ||
if (evt) { | ||
subject.removeEventListener(evt, handler, options); | ||
} | ||
}); | ||
} | ||
}, { | ||
key: "connectDropTarget", | ||
value: function connectDropTarget(targetId, node) { | ||
var _this4 = this; | ||
if (!this.document) { | ||
return function () { | ||
return null; | ||
connectDragSource(sourceId, node) { | ||
const handleMoveStart = this.handleMoveStart.bind(this, sourceId); | ||
this.sourceNodes[sourceId] = node; | ||
this.addEventListener(node, 'start', handleMoveStart); | ||
return () => { | ||
delete this.sourceNodes[sourceId]; | ||
this.removeEventListener(node, 'start', handleMoveStart); | ||
}; | ||
} | ||
var handleMove = function handleMove(e) { | ||
if (!_this4.document || !_this4.monitor.isDragging()) { | ||
return; | ||
} | ||
connectDragPreview(sourceId, node, options) { | ||
this.sourcePreviewNodeOptions[sourceId] = options; | ||
this.sourcePreviewNodes[sourceId] = node; | ||
return () => { | ||
delete this.sourcePreviewNodes[sourceId]; | ||
delete this.sourcePreviewNodeOptions[sourceId]; | ||
}; | ||
} | ||
connectDropTarget(targetId, node) { | ||
if (!this.document) { | ||
return () => null; | ||
} | ||
var coords; | ||
const handleMove = (e) => { | ||
if (!this.document || !this.monitor.isDragging()) { | ||
return; | ||
} | ||
let coords; | ||
/** | ||
* Grab the coordinates for the current mouse/touch position | ||
*/ | ||
switch (e.type) { | ||
case eventNames.mouse.move: | ||
coords = { | ||
x: e.clientX, | ||
y: e.clientY, | ||
}; | ||
break; | ||
case eventNames.touch.move: | ||
coords = { | ||
x: e.touches[0].clientX, | ||
y: e.touches[0].clientY, | ||
}; | ||
break; | ||
} | ||
/** | ||
* Use the coordinates to grab the element the drag ended on. | ||
* If the element is the same as the target node (or any of it's children) then we have hit a drop target and can handle the move. | ||
*/ | ||
let droppedOn = coords != null | ||
? this.document.elementFromPoint(coords.x, coords.y) | ||
: undefined; | ||
let childMatch = droppedOn && node.contains(droppedOn); | ||
if (droppedOn === node || childMatch) { | ||
return this.handleMove(e, targetId); | ||
} | ||
}; | ||
/** | ||
* Grab the coordinates for the current mouse/touch position | ||
* Attaching the event listener to the body so that touchmove will work while dragging over multiple target elements. | ||
*/ | ||
switch (e.type) { | ||
case eventNames.mouse.move: | ||
coords = { | ||
x: e.clientX, | ||
y: e.clientY | ||
}; | ||
break; | ||
case eventNames.touch.move: | ||
coords = { | ||
x: e.touches[0].clientX, | ||
y: e.touches[0].clientY | ||
}; | ||
break; | ||
this.addEventListener(this.document.body, 'move', handleMove); | ||
this.targetNodes[targetId] = node; | ||
return () => { | ||
if (this.document) { | ||
delete this.targetNodes[targetId]; | ||
this.removeEventListener(this.document.body, 'move', handleMove); | ||
} | ||
}; | ||
} | ||
getTopMoveStartHandler() { | ||
if (!this.options.delayTouchStart && !this.options.delayMouseStart) { | ||
return this.handleTopMoveStart; | ||
} | ||
/** | ||
* Use the coordinates to grab the element the drag ended on. | ||
* If the element is the same as the target node (or any of it's children) then we have hit a drop target and can handle the move. | ||
*/ | ||
var droppedOn = coords != null ? _this4.document.elementFromPoint(coords.x, coords.y) : undefined; | ||
var childMatch = droppedOn && node.contains(droppedOn); | ||
if (droppedOn === node || childMatch) { | ||
return _this4.handleMove(e, targetId); | ||
return this.handleTopMoveStartDelay; | ||
} | ||
installSourceNodeRemovalObserver(node) { | ||
this.uninstallSourceNodeRemovalObserver(); | ||
this.draggedSourceNode = node; | ||
this.draggedSourceNodeRemovalObserver = new MutationObserver(() => { | ||
if (node && !node.parentElement) { | ||
this.resurrectSourceNode(); | ||
this.uninstallSourceNodeRemovalObserver(); | ||
} | ||
}); | ||
if (!node || !node.parentElement) { | ||
return; | ||
} | ||
}; | ||
/** | ||
* Attaching the event listener to the body so that touchmove will work while dragging over multiple target elements. | ||
*/ | ||
this.addEventListener(this.document.body, 'move', handleMove); | ||
this.targetNodes[targetId] = node; | ||
return function () { | ||
if (_this4.document) { | ||
delete _this4.targetNodes[targetId]; | ||
_this4.removeEventListener(_this4.document.body, 'move', handleMove); | ||
this.draggedSourceNodeRemovalObserver.observe(node.parentElement, { | ||
childList: true, | ||
}); | ||
} | ||
resurrectSourceNode() { | ||
if (this.document && this.draggedSourceNode) { | ||
this.draggedSourceNode.style.display = 'none'; | ||
this.draggedSourceNode.removeAttribute('data-reactid'); | ||
this.document.body.appendChild(this.draggedSourceNode); | ||
} | ||
}; | ||
} | ||
}, { | ||
key: "getTopMoveStartHandler", | ||
value: function getTopMoveStartHandler() { | ||
if (!this.options.delayTouchStart && !this.options.delayMouseStart) { | ||
return this.handleTopMoveStart; | ||
} | ||
return this.handleTopMoveStartDelay; | ||
} | ||
}, { | ||
key: "installSourceNodeRemovalObserver", | ||
value: function installSourceNodeRemovalObserver(node) { | ||
var _this5 = this; | ||
this.uninstallSourceNodeRemovalObserver(); | ||
this.draggedSourceNode = node; | ||
this.draggedSourceNodeRemovalObserver = new MutationObserver(function () { | ||
if (node && !node.parentElement) { | ||
_this5.resurrectSourceNode(); | ||
_this5.uninstallSourceNodeRemovalObserver(); | ||
uninstallSourceNodeRemovalObserver() { | ||
if (this.draggedSourceNodeRemovalObserver) { | ||
this.draggedSourceNodeRemovalObserver.disconnect(); | ||
} | ||
}); | ||
if (!node || !node.parentElement) { | ||
return; | ||
} | ||
this.draggedSourceNodeRemovalObserver.observe(node.parentElement, { | ||
childList: true | ||
}); | ||
this.draggedSourceNodeRemovalObserver = undefined; | ||
this.draggedSourceNode = undefined; | ||
} | ||
}, { | ||
key: "resurrectSourceNode", | ||
value: function resurrectSourceNode() { | ||
if (this.document && this.draggedSourceNode) { | ||
this.draggedSourceNode.style.display = 'none'; | ||
this.draggedSourceNode.removeAttribute('data-reactid'); | ||
this.document.body.appendChild(this.draggedSourceNode); | ||
} | ||
} | ||
}, { | ||
key: "uninstallSourceNodeRemovalObserver", | ||
value: function uninstallSourceNodeRemovalObserver() { | ||
if (this.draggedSourceNodeRemovalObserver) { | ||
this.draggedSourceNodeRemovalObserver.disconnect(); | ||
} | ||
this.draggedSourceNodeRemovalObserver = undefined; | ||
this.draggedSourceNode = undefined; | ||
} | ||
}, { | ||
key: "window", | ||
get: function get() { | ||
return this.options.window; | ||
} // public for test | ||
}, { | ||
key: "document", | ||
get: function get() { | ||
if (this.window) { | ||
return this.window.document; | ||
} | ||
return undefined; | ||
} | ||
}]); | ||
return TouchBackend; | ||
}(); | ||
_defineProperty(TouchBackend, "isSetUp", void 0); | ||
export { TouchBackend as default }; | ||
} |
export function distance(x1, y1, x2, y2) { | ||
return Math.sqrt(Math.pow(Math.abs(x2 - x1), 2) + Math.pow(Math.abs(y2 - y1), 2)); | ||
return Math.sqrt(Math.pow(Math.abs(x2 - x1), 2) + Math.pow(Math.abs(y2 - y1), 2)); | ||
} | ||
export function inAngleRanges(x1, y1, x2, y2, angleRanges) { | ||
if (!angleRanges) { | ||
if (!angleRanges) { | ||
return false; | ||
} | ||
const angle = (Math.atan2(y2 - y1, x2 - x1) * 180) / Math.PI + 180; | ||
for (let i = 0; i < angleRanges.length; ++i) { | ||
if ((angleRanges[i].start == null || angle >= angleRanges[i].start) && | ||
(angleRanges[i].end == null || angle <= angleRanges[i].end)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
var angle = Math.atan2(y2 - y1, x2 - x1) * 180 / Math.PI + 180; | ||
for (var i = 0; i < angleRanges.length; ++i) { | ||
if ((angleRanges[i].start == null || angle >= angleRanges[i].start) && (angleRanges[i].end == null || angle <= angleRanges[i].end)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
import { isTouchEvent } from './predicates'; | ||
var ELEMENT_NODE = 1; | ||
const ELEMENT_NODE = 1; | ||
export function getNodeClientOffset(node) { | ||
var el = node.nodeType === ELEMENT_NODE ? node : node.parentElement; | ||
if (!el) { | ||
return undefined; | ||
} | ||
var _el$getBoundingClient = el.getBoundingClientRect(), | ||
top = _el$getBoundingClient.top, | ||
left = _el$getBoundingClient.left; | ||
return { | ||
x: left, | ||
y: top | ||
}; | ||
const el = node.nodeType === ELEMENT_NODE ? node : node.parentElement; | ||
if (!el) { | ||
return undefined; | ||
} | ||
const { top, left } = el.getBoundingClientRect(); | ||
return { x: left, y: top }; | ||
} | ||
export function getEventClientTouchOffset(e) { | ||
if (e.targetTouches.length === 1) { | ||
return getEventClientOffset(e.targetTouches[0]); | ||
} | ||
if (e.targetTouches.length === 1) { | ||
return getEventClientOffset(e.targetTouches[0]); | ||
} | ||
} | ||
export function getEventClientOffset(e) { | ||
if (isTouchEvent(e)) { | ||
return getEventClientTouchOffset(e); | ||
} else { | ||
return { | ||
x: e.clientX, | ||
y: e.clientY | ||
}; | ||
} | ||
} | ||
if (isTouchEvent(e)) { | ||
return getEventClientTouchOffset(e); | ||
} | ||
else { | ||
return { | ||
x: e.clientX, | ||
y: e.clientY, | ||
}; | ||
} | ||
} |
// Used for MouseEvent.buttons (note the s on the end). | ||
var MouseButtons = { | ||
Left: 1, | ||
Right: 2, | ||
Center: 4 // Used for e.button (note the lack of an s on the end). | ||
const MouseButtons = { | ||
Left: 1, | ||
Right: 2, | ||
Center: 4, | ||
}; | ||
var MouseButton = { | ||
Left: 0, | ||
Center: 1, | ||
Right: 2 | ||
/** | ||
* Only touch events and mouse events where the left button is pressed should initiate a drag. | ||
* @param {MouseEvent | TouchEvent} e The event | ||
*/ | ||
// Used for e.button (note the lack of an s on the end). | ||
const MouseButton = { | ||
Left: 0, | ||
Center: 1, | ||
Right: 2, | ||
}; | ||
/** | ||
* Only touch events and mouse events where the left button is pressed should initiate a drag. | ||
* @param {MouseEvent | TouchEvent} e The event | ||
*/ | ||
export function eventShouldStartDrag(e) { | ||
// For touch events, button will be undefined. If e.button is defined, | ||
// then it should be MouseButton.Left. | ||
return e.button === undefined || e.button === MouseButton.Left; | ||
// For touch events, button will be undefined. If e.button is defined, | ||
// then it should be MouseButton.Left. | ||
return e.button === undefined || e.button === MouseButton.Left; | ||
} | ||
@@ -29,10 +28,9 @@ /** | ||
*/ | ||
export function eventShouldEndDrag(e) { | ||
// Touch events will have buttons be undefined, while mouse events will have e.buttons's left button | ||
// bit field unset if the left mouse button has been released | ||
return e.buttons === undefined || (e.buttons & MouseButtons.Left) === 0; | ||
// Touch events will have buttons be undefined, while mouse events will have e.buttons's left button | ||
// bit field unset if the left mouse button has been released | ||
return e.buttons === undefined || (e.buttons & MouseButtons.Left) === 0; | ||
} | ||
export function isTouchEvent(e) { | ||
return !!e.targetTouches; | ||
} | ||
return !!e.targetTouches; | ||
} |
@@ -1,18 +0,17 @@ | ||
var supportsPassive = function () { | ||
// simular to jQuery's test | ||
var supported = false; | ||
try { | ||
addEventListener('test', function () {}, Object.defineProperty({}, 'passive', { | ||
get: function get() { | ||
supported = true; | ||
return true; | ||
} | ||
})); | ||
} catch (e) {// do nothing | ||
} | ||
return supported; | ||
}(); | ||
export default supportsPassive; | ||
const supportsPassive = (() => { | ||
// simular to jQuery's test | ||
let supported = false; | ||
try { | ||
addEventListener('test', () => { }, Object.defineProperty({}, 'passive', { | ||
get() { | ||
supported = true; | ||
return true; | ||
}, | ||
})); | ||
} | ||
catch (e) { | ||
// do nothing | ||
} | ||
return supported; | ||
})(); | ||
export default supportsPassive; |
{ | ||
"name": "react-dnd-touch-backend", | ||
"version": "9.3.1", | ||
"version": "9.3.2", | ||
"description": "Touch backend for react-dnd", | ||
"type": "module", | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"main": "./dist/esm/index.js", | ||
"module": "./dist/esm/index.js", | ||
"types": "lib/index.d.ts", | ||
@@ -22,6 +22,5 @@ "license": "MIT", | ||
"@types/invariant": "^2.2.30", | ||
"dnd-core": "^9.3.1", | ||
"dnd-core": "^9.3.2", | ||
"invariant": "^2.2.4" | ||
}, | ||
"gitHead": "0493eaa356cd25de1d1ba753e3f43c051e2076b2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
255683
45
2499
Updateddnd-core@^9.3.2