This commit is contained in:
99
node_modules/dnd-core/dist/esm/actions/dragDrop/beginDrag.js
generated
vendored
Normal file
99
node_modules/dnd-core/dist/esm/actions/dragDrop/beginDrag.js
generated
vendored
Normal file
@@ -0,0 +1,99 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { setClientOffset } from './local/setClientOffset';
|
||||
import { isObject } from '../../utils/js_utils';
|
||||
import { BEGIN_DRAG, INIT_COORDS } from './types';
|
||||
var ResetCoordinatesAction = {
|
||||
type: INIT_COORDS,
|
||||
payload: {
|
||||
clientOffset: null,
|
||||
sourceClientOffset: null
|
||||
}
|
||||
};
|
||||
export function createBeginDrag(manager) {
|
||||
return function beginDrag() {
|
||||
var sourceIds = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
||||
publishSource: true
|
||||
};
|
||||
var _options$publishSourc = options.publishSource,
|
||||
publishSource = _options$publishSourc === void 0 ? true : _options$publishSourc,
|
||||
clientOffset = options.clientOffset,
|
||||
getSourceClientOffset = options.getSourceClientOffset;
|
||||
var monitor = manager.getMonitor();
|
||||
var registry = manager.getRegistry(); // Initialize the coordinates using the client offset
|
||||
|
||||
manager.dispatch(setClientOffset(clientOffset));
|
||||
verifyInvariants(sourceIds, monitor, registry); // Get the draggable source
|
||||
|
||||
var sourceId = getDraggableSource(sourceIds, monitor);
|
||||
|
||||
if (sourceId === null) {
|
||||
manager.dispatch(ResetCoordinatesAction);
|
||||
return;
|
||||
} // Get the source client offset
|
||||
|
||||
|
||||
var sourceClientOffset = null;
|
||||
|
||||
if (clientOffset) {
|
||||
if (!getSourceClientOffset) {
|
||||
throw new Error('getSourceClientOffset must be defined');
|
||||
}
|
||||
|
||||
verifyGetSourceClientOffsetIsFunction(getSourceClientOffset);
|
||||
sourceClientOffset = getSourceClientOffset(sourceId);
|
||||
} // Initialize the full coordinates
|
||||
|
||||
|
||||
manager.dispatch(setClientOffset(clientOffset, sourceClientOffset));
|
||||
var source = registry.getSource(sourceId);
|
||||
var item = source.beginDrag(monitor, sourceId); // If source.beginDrag returns null, this is an indicator to cancel the drag
|
||||
|
||||
if (item == null) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
verifyItemIsObject(item);
|
||||
registry.pinSource(sourceId);
|
||||
var itemType = registry.getSourceType(sourceId);
|
||||
return {
|
||||
type: BEGIN_DRAG,
|
||||
payload: {
|
||||
itemType: itemType,
|
||||
item: item,
|
||||
sourceId: sourceId,
|
||||
clientOffset: clientOffset || null,
|
||||
sourceClientOffset: sourceClientOffset || null,
|
||||
isSourcePublic: !!publishSource
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function verifyInvariants(sourceIds, monitor, registry) {
|
||||
invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.');
|
||||
sourceIds.forEach(function (sourceId) {
|
||||
invariant(registry.getSource(sourceId), 'Expected sourceIds to be registered.');
|
||||
});
|
||||
}
|
||||
|
||||
function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) {
|
||||
invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.');
|
||||
}
|
||||
|
||||
function verifyItemIsObject(item) {
|
||||
invariant(isObject(item), 'Item must be an object.');
|
||||
}
|
||||
|
||||
function getDraggableSource(sourceIds, monitor) {
|
||||
var sourceId = null;
|
||||
|
||||
for (var i = sourceIds.length - 1; i >= 0; i--) {
|
||||
if (monitor.canDragSource(sourceIds[i])) {
|
||||
sourceId = sourceIds[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return sourceId;
|
||||
}
|
||||
56
node_modules/dnd-core/dist/esm/actions/dragDrop/drop.js
generated
vendored
Normal file
56
node_modules/dnd-core/dist/esm/actions/dragDrop/drop.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
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 '@react-dnd/invariant';
|
||||
import { DROP } from './types';
|
||||
import { isObject } from '../../utils/js_utils';
|
||||
export function createDrop(manager) {
|
||||
return function drop() {
|
||||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
var monitor = manager.getMonitor();
|
||||
var registry = manager.getRegistry();
|
||||
verifyInvariants(monitor);
|
||||
var targetIds = getDroppableTargets(monitor); // Multiple actions are dispatched here, which is why this doesn't return an action
|
||||
|
||||
targetIds.forEach(function (targetId, index) {
|
||||
var dropResult = determineDropResult(targetId, index, registry, monitor);
|
||||
var action = {
|
||||
type: DROP,
|
||||
payload: {
|
||||
dropResult: _objectSpread(_objectSpread({}, options), dropResult)
|
||||
}
|
||||
};
|
||||
manager.dispatch(action);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function verifyInvariants(monitor) {
|
||||
invariant(monitor.isDragging(), 'Cannot call drop while not dragging.');
|
||||
invariant(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.');
|
||||
}
|
||||
|
||||
function determineDropResult(targetId, index, registry, monitor) {
|
||||
var target = registry.getTarget(targetId);
|
||||
var dropResult = target ? target.drop(monitor, targetId) : undefined;
|
||||
verifyDropResultType(dropResult);
|
||||
|
||||
if (typeof dropResult === 'undefined') {
|
||||
dropResult = index === 0 ? {} : monitor.getDropResult();
|
||||
}
|
||||
|
||||
return dropResult;
|
||||
}
|
||||
|
||||
function verifyDropResultType(dropResult) {
|
||||
invariant(typeof dropResult === 'undefined' || isObject(dropResult), 'Drop result must either be an object or undefined.');
|
||||
}
|
||||
|
||||
function getDroppableTargets(monitor) {
|
||||
var targetIds = monitor.getTargetIds().filter(monitor.canDropOnTarget, monitor);
|
||||
targetIds.reverse();
|
||||
return targetIds;
|
||||
}
|
||||
24
node_modules/dnd-core/dist/esm/actions/dragDrop/endDrag.js
generated
vendored
Normal file
24
node_modules/dnd-core/dist/esm/actions/dragDrop/endDrag.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { END_DRAG } from './types';
|
||||
export function createEndDrag(manager) {
|
||||
return function endDrag() {
|
||||
var monitor = manager.getMonitor();
|
||||
var registry = manager.getRegistry();
|
||||
verifyIsDragging(monitor);
|
||||
var sourceId = monitor.getSourceId();
|
||||
|
||||
if (sourceId != null) {
|
||||
var source = registry.getSource(sourceId, true);
|
||||
source.endDrag(monitor, sourceId);
|
||||
registry.unpinSource();
|
||||
}
|
||||
|
||||
return {
|
||||
type: END_DRAG
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function verifyIsDragging(monitor) {
|
||||
invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.');
|
||||
}
|
||||
63
node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js
generated
vendored
Normal file
63
node_modules/dnd-core/dist/esm/actions/dragDrop/hover.js
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { matchesType } from '../../utils/matchesType';
|
||||
import { HOVER } from './types';
|
||||
export function createHover(manager) {
|
||||
return function hover(targetIdsArg) {
|
||||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
||||
clientOffset = _ref.clientOffset;
|
||||
|
||||
verifyTargetIdsIsArray(targetIdsArg);
|
||||
var targetIds = targetIdsArg.slice(0);
|
||||
var monitor = manager.getMonitor();
|
||||
var registry = manager.getRegistry();
|
||||
checkInvariants(targetIds, monitor, registry);
|
||||
var draggedItemType = monitor.getItemType();
|
||||
removeNonMatchingTargetIds(targetIds, registry, draggedItemType);
|
||||
hoverAllTargets(targetIds, monitor, registry);
|
||||
return {
|
||||
type: HOVER,
|
||||
payload: {
|
||||
targetIds: targetIds,
|
||||
clientOffset: clientOffset || null
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
function verifyTargetIdsIsArray(targetIdsArg) {
|
||||
invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.');
|
||||
}
|
||||
|
||||
function checkInvariants(targetIds, monitor, registry) {
|
||||
invariant(monitor.isDragging(), 'Cannot call hover while not dragging.');
|
||||
invariant(!monitor.didDrop(), 'Cannot call hover after drop.');
|
||||
|
||||
for (var i = 0; i < targetIds.length; i++) {
|
||||
var targetId = targetIds[i];
|
||||
invariant(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.');
|
||||
var target = registry.getTarget(targetId);
|
||||
invariant(target, 'Expected targetIds to be registered.');
|
||||
}
|
||||
}
|
||||
|
||||
function removeNonMatchingTargetIds(targetIds, registry, draggedItemType) {
|
||||
// Remove those targetIds that don't match the targetType. This
|
||||
// fixes shallow isOver which would only be non-shallow because of
|
||||
// non-matching targets.
|
||||
for (var i = targetIds.length - 1; i >= 0; i--) {
|
||||
var targetId = targetIds[i];
|
||||
var targetType = registry.getTargetType(targetId);
|
||||
|
||||
if (!matchesType(targetType, draggedItemType)) {
|
||||
targetIds.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function hoverAllTargets(targetIds, monitor, registry) {
|
||||
// Finally call hover on all matching targets.
|
||||
targetIds.forEach(function (targetId) {
|
||||
var target = registry.getTarget(targetId);
|
||||
target.hover(monitor, targetId);
|
||||
});
|
||||
}
|
||||
15
node_modules/dnd-core/dist/esm/actions/dragDrop/index.js
generated
vendored
Normal file
15
node_modules/dnd-core/dist/esm/actions/dragDrop/index.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { createBeginDrag } from './beginDrag';
|
||||
import { createPublishDragSource } from './publishDragSource';
|
||||
import { createHover } from './hover';
|
||||
import { createDrop } from './drop';
|
||||
import { createEndDrag } from './endDrag';
|
||||
export * from './types';
|
||||
export function createDragDropActions(manager) {
|
||||
return {
|
||||
beginDrag: createBeginDrag(manager),
|
||||
publishDragSource: createPublishDragSource(manager),
|
||||
hover: createHover(manager),
|
||||
drop: createDrop(manager),
|
||||
endDrag: createEndDrag(manager)
|
||||
};
|
||||
}
|
||||
10
node_modules/dnd-core/dist/esm/actions/dragDrop/local/setClientOffset.js
generated
vendored
Normal file
10
node_modules/dnd-core/dist/esm/actions/dragDrop/local/setClientOffset.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { INIT_COORDS } from '../types';
|
||||
export function setClientOffset(clientOffset, sourceClientOffset) {
|
||||
return {
|
||||
type: INIT_COORDS,
|
||||
payload: {
|
||||
sourceClientOffset: sourceClientOffset || null,
|
||||
clientOffset: clientOffset || null
|
||||
}
|
||||
};
|
||||
}
|
||||
12
node_modules/dnd-core/dist/esm/actions/dragDrop/publishDragSource.js
generated
vendored
Normal file
12
node_modules/dnd-core/dist/esm/actions/dragDrop/publishDragSource.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import { PUBLISH_DRAG_SOURCE } from './types';
|
||||
export function createPublishDragSource(manager) {
|
||||
return function publishDragSource() {
|
||||
var monitor = manager.getMonitor();
|
||||
|
||||
if (monitor.isDragging()) {
|
||||
return {
|
||||
type: PUBLISH_DRAG_SOURCE
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
6
node_modules/dnd-core/dist/esm/actions/dragDrop/types.js
generated
vendored
Normal file
6
node_modules/dnd-core/dist/esm/actions/dragDrop/types.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export var INIT_COORDS = 'dnd-core/INIT_COORDS';
|
||||
export var BEGIN_DRAG = 'dnd-core/BEGIN_DRAG';
|
||||
export var PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE';
|
||||
export var HOVER = 'dnd-core/HOVER';
|
||||
export var DROP = 'dnd-core/DROP';
|
||||
export var END_DRAG = 'dnd-core/END_DRAG';
|
||||
36
node_modules/dnd-core/dist/esm/actions/registry.js
generated
vendored
Normal file
36
node_modules/dnd-core/dist/esm/actions/registry.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
export var ADD_SOURCE = 'dnd-core/ADD_SOURCE';
|
||||
export var ADD_TARGET = 'dnd-core/ADD_TARGET';
|
||||
export var REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE';
|
||||
export var REMOVE_TARGET = 'dnd-core/REMOVE_TARGET';
|
||||
export function addSource(sourceId) {
|
||||
return {
|
||||
type: ADD_SOURCE,
|
||||
payload: {
|
||||
sourceId: sourceId
|
||||
}
|
||||
};
|
||||
}
|
||||
export function addTarget(targetId) {
|
||||
return {
|
||||
type: ADD_TARGET,
|
||||
payload: {
|
||||
targetId: targetId
|
||||
}
|
||||
};
|
||||
}
|
||||
export function removeSource(sourceId) {
|
||||
return {
|
||||
type: REMOVE_SOURCE,
|
||||
payload: {
|
||||
sourceId: sourceId
|
||||
}
|
||||
};
|
||||
}
|
||||
export function removeTarget(targetId) {
|
||||
return {
|
||||
type: REMOVE_TARGET,
|
||||
payload: {
|
||||
targetId: targetId
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user