dnd-core
Advanced tools
Comparing version 9.3.1 to 9.3.2
@@ -26,4 +26,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; } | ||
function makeStoreInstance(debugMode) { | ||
@@ -49,11 +47,5 @@ // TODO: if we ever make a react-native version of this, | ||
_defineProperty(this, "store", void 0); | ||
this.isSetUp = false; | ||
_defineProperty(this, "monitor", void 0); | ||
_defineProperty(this, "backend", void 0); | ||
_defineProperty(this, "isSetUp", false); | ||
_defineProperty(this, "handleRefCountChange", function () { | ||
this.handleRefCountChange = function () { | ||
var shouldSetUp = _this.store.getState().refCount > 0; | ||
@@ -72,3 +64,3 @@ | ||
} | ||
}); | ||
}; | ||
@@ -75,0 +67,0 @@ var store = makeStoreInstance(debugMode); |
@@ -24,4 +24,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 DragDropMonitorImpl = | ||
@@ -33,6 +31,2 @@ /*#__PURE__*/ | ||
_defineProperty(this, "store", void 0); | ||
_defineProperty(this, "registry", void 0); | ||
this.store = store; | ||
@@ -39,0 +33,0 @@ this.registry = registry; |
@@ -28,4 +28,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; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
@@ -93,14 +91,7 @@ | ||
_defineProperty(this, "types", new Map()); | ||
_defineProperty(this, "dragSources", new Map()); | ||
_defineProperty(this, "dropTargets", new Map()); | ||
_defineProperty(this, "pinnedSourceId", null); | ||
_defineProperty(this, "pinnedSource", null); | ||
_defineProperty(this, "store", void 0); | ||
this.types = new Map(); | ||
this.dragSources = new Map(); | ||
this.dropTargets = new Map(); | ||
this.pinnedSourceId = null; | ||
this.pinnedSource = null; | ||
this.store = store; | ||
@@ -107,0 +98,0 @@ } |
@@ -13,4 +13,3 @@ "use strict"; | ||
exports.NONE = NONE; | ||
var ALL = [] // Add these flags for debug | ||
; | ||
var ALL = []; | ||
exports.ALL = ALL; | ||
@@ -17,0 +16,0 @@ NONE.__IS_NONE__ = true; |
@@ -5,107 +5,72 @@ import invariant from 'invariant'; | ||
import { BEGIN_DRAG, INIT_COORDS } from './types'; | ||
var ResetCoordinatesAction = { | ||
type: INIT_COORDS, | ||
payload: { | ||
clientOffset: null, | ||
sourceClientOffset: null | ||
} | ||
const ResetCoordinatesAction = { | ||
type: INIT_COORDS, | ||
payload: { | ||
clientOffset: null, | ||
sourceClientOffset: null, | ||
}, | ||
}; | ||
export default 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 | ||
return function beginDrag(sourceIds = [], options = { | ||
publishSource: true, | ||
}) { | ||
const { publishSource = true, clientOffset, getSourceClientOffset, } = options; | ||
const monitor = manager.getMonitor(); | ||
const registry = manager.getRegistry(); | ||
// Initialize the coordinates using the client offset | ||
manager.dispatch(setClientOffset(clientOffset)); | ||
verifyInvariants(sourceIds, monitor, registry); | ||
// Get the draggable source | ||
const sourceId = getDraggableSource(sourceIds, monitor); | ||
if (sourceId === null) { | ||
manager.dispatch(ResetCoordinatesAction); | ||
return; | ||
} | ||
// Get the source client offset | ||
let sourceClientOffset = null; | ||
if (clientOffset) { | ||
verifyGetSourceClientOffsetIsFunction(getSourceClientOffset); | ||
sourceClientOffset = getSourceClientOffset(sourceId); | ||
} | ||
// Initialize the full coordinates | ||
manager.dispatch(setClientOffset(clientOffset, sourceClientOffset)); | ||
const source = registry.getSource(sourceId); | ||
const item = source.beginDrag(monitor, sourceId); | ||
verifyItemIsObject(item); | ||
registry.pinSource(sourceId); | ||
const itemType = registry.getSourceType(sourceId); | ||
return { | ||
type: BEGIN_DRAG, | ||
payload: { | ||
itemType, | ||
item, | ||
sourceId, | ||
clientOffset: clientOffset || null, | ||
sourceClientOffset: sourceClientOffset || null, | ||
isSourcePublic: !!publishSource, | ||
}, | ||
}; | ||
}; | ||
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) { | ||
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); | ||
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.'); | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = sourceIds[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var s = _step.value; | ||
invariant(registry.getSource(s), 'Expected sourceIds to be registered.'); | ||
invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.'); | ||
for (const s of sourceIds) { | ||
invariant(registry.getSource(s), 'Expected sourceIds to be registered.'); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) { | ||
invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.'); | ||
invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.'); | ||
} | ||
function verifyItemIsObject(item) { | ||
invariant(isObject(item), 'Item must be an object.'); | ||
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; | ||
let sourceId = null; | ||
for (let i = sourceIds.length - 1; i >= 0; i--) { | ||
if (monitor.canDragSource(sourceIds[i])) { | ||
sourceId = sourceIds[i]; | ||
break; | ||
} | ||
} | ||
} | ||
return sourceId; | ||
} | ||
return sourceId; | ||
} |
@@ -1,7 +0,1 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { keys.push.apply(keys, Object.getOwnPropertySymbols(object)); } if (enumerableOnly) keys = keys.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(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 'invariant'; | ||
@@ -11,47 +5,45 @@ import { DROP } from './types'; | ||
export default 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({}, options, {}, dropResult) | ||
} | ||
}; | ||
manager.dispatch(action); | ||
}); | ||
}; | ||
return function drop(options = {}) { | ||
const monitor = manager.getMonitor(); | ||
const registry = manager.getRegistry(); | ||
verifyInvariants(monitor); | ||
const targetIds = getDroppableTargets(monitor); | ||
// Multiple actions are dispatched here, which is why this doesn't return an action | ||
targetIds.forEach((targetId, index) => { | ||
const dropResult = determineDropResult(targetId, index, registry, monitor); | ||
const action = { | ||
type: DROP, | ||
payload: { | ||
dropResult: { | ||
...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.'); | ||
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; | ||
const target = registry.getTarget(targetId); | ||
let 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.'); | ||
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; | ||
} | ||
const targetIds = monitor | ||
.getTargetIds() | ||
.filter(monitor.canDropOnTarget, monitor); | ||
targetIds.reverse(); | ||
return targetIds; | ||
} |
import invariant from 'invariant'; | ||
import { END_DRAG } from './types'; | ||
export default function createEndDrag(manager) { | ||
return function endDrag() { | ||
var monitor = manager.getMonitor(); | ||
var registry = manager.getRegistry(); | ||
verifyIsDragging(monitor); | ||
var sourceId = monitor.getSourceId(); | ||
var source = registry.getSource(sourceId, true); | ||
source.endDrag(monitor, sourceId); | ||
registry.unpinSource(); | ||
return { | ||
type: END_DRAG | ||
return function endDrag() { | ||
const monitor = manager.getMonitor(); | ||
const registry = manager.getRegistry(); | ||
verifyIsDragging(monitor); | ||
const sourceId = monitor.getSourceId(); | ||
const 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.'); | ||
} | ||
invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.'); | ||
} |
@@ -5,80 +5,51 @@ import invariant from 'invariant'; | ||
export default 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 | ||
} | ||
return function hover(targetIdsArg, { clientOffset } = {}) { | ||
verifyTargetIdsIsArray(targetIdsArg); | ||
const targetIds = targetIdsArg.slice(0); | ||
const monitor = manager.getMonitor(); | ||
const registry = manager.getRegistry(); | ||
checkInvariants(targetIds, monitor, registry); | ||
const draggedItemType = monitor.getItemType(); | ||
removeNonMatchingTargetIds(targetIds, registry, draggedItemType); | ||
hoverAllTargets(targetIds, monitor, registry); | ||
return { | ||
type: HOVER, | ||
payload: { | ||
targetIds, | ||
clientOffset: clientOffset || null, | ||
}, | ||
}; | ||
}; | ||
}; | ||
} | ||
function verifyTargetIdsIsArray(targetIdsArg) { | ||
invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.'); | ||
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.'); | ||
} | ||
invariant(monitor.isDragging(), 'Cannot call hover while not dragging.'); | ||
invariant(!monitor.didDrop(), 'Cannot call hover after drop.'); | ||
for (let i = 0; i < targetIds.length; i++) { | ||
const targetId = targetIds[i]; | ||
invariant(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.'); | ||
const 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); | ||
// 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 (let i = targetIds.length - 1; i >= 0; i--) { | ||
const targetId = targetIds[i]; | ||
const targetType = registry.getTargetType(targetId); | ||
if (!matchesType(targetType, draggedItemType)) { | ||
targetIds.splice(i, 1); | ||
} | ||
} | ||
} | ||
} | ||
function hoverAllTargets(targetIds, monitor, registry) { | ||
// Finally call hover on all matching targets. | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = targetIds[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var targetId = _step.value; | ||
var target = registry.getTarget(targetId); | ||
target.hover(monitor, targetId); | ||
// Finally call hover on all matching targets. | ||
for (const targetId of targetIds) { | ||
const target = registry.getTarget(targetId); | ||
target.hover(monitor, targetId); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
_iterator.return(); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
} | ||
} | ||
} |
@@ -8,9 +8,9 @@ import createBeginDrag from './beginDrag'; | ||
export default function createDragDropActions(manager) { | ||
return { | ||
beginDrag: createBeginDrag(manager), | ||
publishDragSource: createPublishDragSource(manager), | ||
hover: createHover(manager), | ||
drop: createDrop(manager), | ||
endDrag: createEndDrag(manager) | ||
}; | ||
} | ||
return { | ||
beginDrag: createBeginDrag(manager), | ||
publishDragSource: createPublishDragSource(manager), | ||
hover: createHover(manager), | ||
drop: createDrop(manager), | ||
endDrag: createEndDrag(manager), | ||
}; | ||
} |
import { INIT_COORDS } from '../types'; | ||
export function setClientOffset(clientOffset, sourceClientOffset) { | ||
return { | ||
type: INIT_COORDS, | ||
payload: { | ||
sourceClientOffset: sourceClientOffset || null, | ||
clientOffset: clientOffset || null | ||
} | ||
}; | ||
} | ||
return { | ||
type: INIT_COORDS, | ||
payload: { | ||
sourceClientOffset: sourceClientOffset || null, | ||
clientOffset: clientOffset || null, | ||
}, | ||
}; | ||
} |
import { PUBLISH_DRAG_SOURCE } from './types'; | ||
export default function createPublishDragSource(manager) { | ||
return function publishDragSource() { | ||
var monitor = manager.getMonitor(); | ||
if (monitor.isDragging()) { | ||
return { | ||
type: PUBLISH_DRAG_SOURCE | ||
}; | ||
} | ||
}; | ||
} | ||
return function publishDragSource() { | ||
const monitor = manager.getMonitor(); | ||
if (monitor.isDragging()) { | ||
return { type: PUBLISH_DRAG_SOURCE }; | ||
} | ||
}; | ||
} |
@@ -1,6 +0,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'; | ||
export const INIT_COORDS = 'dnd-core/INIT_COORDS'; | ||
export const BEGIN_DRAG = 'dnd-core/BEGIN_DRAG'; | ||
export const PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE'; | ||
export const HOVER = 'dnd-core/HOVER'; | ||
export const DROP = 'dnd-core/DROP'; | ||
export const END_DRAG = 'dnd-core/END_DRAG'; |
@@ -1,36 +0,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 const ADD_SOURCE = 'dnd-core/ADD_SOURCE'; | ||
export const ADD_TARGET = 'dnd-core/ADD_TARGET'; | ||
export const REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE'; | ||
export const REMOVE_TARGET = 'dnd-core/REMOVE_TARGET'; | ||
export function addSource(sourceId) { | ||
return { | ||
type: ADD_SOURCE, | ||
payload: { | ||
sourceId: sourceId | ||
} | ||
}; | ||
return { | ||
type: ADD_SOURCE, | ||
payload: { | ||
sourceId, | ||
}, | ||
}; | ||
} | ||
export function addTarget(targetId) { | ||
return { | ||
type: ADD_TARGET, | ||
payload: { | ||
targetId: targetId | ||
} | ||
}; | ||
return { | ||
type: ADD_TARGET, | ||
payload: { | ||
targetId, | ||
}, | ||
}; | ||
} | ||
export function removeSource(sourceId) { | ||
return { | ||
type: REMOVE_SOURCE, | ||
payload: { | ||
sourceId: sourceId | ||
} | ||
}; | ||
return { | ||
type: REMOVE_SOURCE, | ||
payload: { | ||
sourceId, | ||
}, | ||
}; | ||
} | ||
export function removeTarget(targetId) { | ||
return { | ||
type: REMOVE_TARGET, | ||
payload: { | ||
targetId: targetId | ||
} | ||
}; | ||
} | ||
return { | ||
type: REMOVE_TARGET, | ||
payload: { | ||
targetId, | ||
}, | ||
}; | ||
} |
@@ -1,23 +0,20 @@ | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
import invariant from 'invariant'; | ||
export function validateSourceContract(source) { | ||
invariant(typeof source.canDrag === 'function', 'Expected canDrag to be a function.'); | ||
invariant(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.'); | ||
invariant(typeof source.endDrag === 'function', 'Expected endDrag to be a function.'); | ||
invariant(typeof source.canDrag === 'function', 'Expected canDrag to be a function.'); | ||
invariant(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.'); | ||
invariant(typeof source.endDrag === 'function', 'Expected endDrag to be a function.'); | ||
} | ||
export function validateTargetContract(target) { | ||
invariant(typeof target.canDrop === 'function', 'Expected canDrop to be a function.'); | ||
invariant(typeof target.hover === 'function', 'Expected hover to be a function.'); | ||
invariant(typeof target.drop === 'function', 'Expected beginDrag to be a function.'); | ||
invariant(typeof target.canDrop === 'function', 'Expected canDrop to be a function.'); | ||
invariant(typeof target.hover === 'function', 'Expected hover to be a function.'); | ||
invariant(typeof target.drop === 'function', 'Expected beginDrag to be a function.'); | ||
} | ||
export function validateType(type, allowArray) { | ||
if (allowArray && Array.isArray(type)) { | ||
type.forEach(function (t) { | ||
return validateType(t, false); | ||
}); | ||
return; | ||
} | ||
invariant(typeof type === 'string' || _typeof(type) === 'symbol', allowArray ? 'Type can only be a string, a symbol, or an array of either.' : 'Type can only be a string or a symbol.'); | ||
} | ||
if (allowArray && Array.isArray(type)) { | ||
type.forEach(t => validateType(t, false)); | ||
return; | ||
} | ||
invariant(typeof type === 'string' || typeof type === 'symbol', allowArray | ||
? 'Type can only be a string, a symbol, or an array of either.' | ||
: 'Type can only be a string or a symbol.'); | ||
} |
@@ -1,9 +0,1 @@ | ||
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 { createStore } from 'redux'; | ||
@@ -14,110 +6,68 @@ import reducer from './reducers'; | ||
import HandlerRegistryImpl from './HandlerRegistryImpl'; | ||
function makeStoreInstance(debugMode) { | ||
// TODO: if we ever make a react-native version of this, | ||
// we'll need to consider how to pull off dev-tooling | ||
var reduxDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__; | ||
return createStore(reducer, debugMode && reduxDevTools && reduxDevTools({ | ||
name: 'dnd-core', | ||
instanceId: 'dnd-core' | ||
})); | ||
// TODO: if we ever make a react-native version of this, | ||
// we'll need to consider how to pull off dev-tooling | ||
const reduxDevTools = typeof window !== 'undefined' && | ||
window.__REDUX_DEVTOOLS_EXTENSION__; | ||
return createStore(reducer, debugMode && | ||
reduxDevTools && | ||
reduxDevTools({ | ||
name: 'dnd-core', | ||
instanceId: 'dnd-core', | ||
})); | ||
} | ||
var DragDropManagerImpl = | ||
/*#__PURE__*/ | ||
function () { | ||
function DragDropManagerImpl() { | ||
var _this = this; | ||
var debugMode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false; | ||
_classCallCheck(this, DragDropManagerImpl); | ||
_defineProperty(this, "store", void 0); | ||
_defineProperty(this, "monitor", void 0); | ||
_defineProperty(this, "backend", void 0); | ||
_defineProperty(this, "isSetUp", false); | ||
_defineProperty(this, "handleRefCountChange", function () { | ||
var shouldSetUp = _this.store.getState().refCount > 0; | ||
if (_this.backend) { | ||
if (shouldSetUp && !_this.isSetUp) { | ||
_this.backend.setup(); | ||
_this.isSetUp = true; | ||
} else if (!shouldSetUp && _this.isSetUp) { | ||
_this.backend.teardown(); | ||
_this.isSetUp = false; | ||
} | ||
} | ||
}); | ||
var store = makeStoreInstance(debugMode); | ||
this.store = store; | ||
this.monitor = new DragDropMonitorImpl(store, new HandlerRegistryImpl(store)); | ||
store.subscribe(this.handleRefCountChange); | ||
} | ||
_createClass(DragDropManagerImpl, [{ | ||
key: "receiveBackend", | ||
value: function receiveBackend(backend) { | ||
this.backend = backend; | ||
export default class DragDropManagerImpl { | ||
constructor(debugMode = false) { | ||
this.isSetUp = false; | ||
this.handleRefCountChange = () => { | ||
const shouldSetUp = this.store.getState().refCount > 0; | ||
if (this.backend) { | ||
if (shouldSetUp && !this.isSetUp) { | ||
this.backend.setup(); | ||
this.isSetUp = true; | ||
} | ||
else if (!shouldSetUp && this.isSetUp) { | ||
this.backend.teardown(); | ||
this.isSetUp = false; | ||
} | ||
} | ||
}; | ||
const store = makeStoreInstance(debugMode); | ||
this.store = store; | ||
this.monitor = new DragDropMonitorImpl(store, new HandlerRegistryImpl(store)); | ||
store.subscribe(this.handleRefCountChange); | ||
} | ||
}, { | ||
key: "getMonitor", | ||
value: function getMonitor() { | ||
return this.monitor; | ||
receiveBackend(backend) { | ||
this.backend = backend; | ||
} | ||
}, { | ||
key: "getBackend", | ||
value: function getBackend() { | ||
return this.backend; | ||
getMonitor() { | ||
return this.monitor; | ||
} | ||
}, { | ||
key: "getRegistry", | ||
value: function getRegistry() { | ||
return this.monitor.registry; | ||
getBackend() { | ||
return this.backend; | ||
} | ||
}, { | ||
key: "getActions", | ||
value: function getActions() { | ||
var manager = this; | ||
var dispatch = this.store.dispatch; | ||
function bindActionCreator(actionCreator) { | ||
return function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var action = actionCreator.apply(manager, args); | ||
if (typeof action !== 'undefined') { | ||
dispatch(action); | ||
} | ||
}; | ||
} | ||
var actions = dragDropActions(this); | ||
return Object.keys(actions).reduce(function (boundActions, key) { | ||
var action = actions[key]; | ||
boundActions[key] = bindActionCreator(action); | ||
return boundActions; | ||
}, {}); | ||
getRegistry() { | ||
return this.monitor.registry; | ||
} | ||
}, { | ||
key: "dispatch", | ||
value: function dispatch(action) { | ||
this.store.dispatch(action); | ||
getActions() { | ||
const manager = this; | ||
const { dispatch } = this.store; | ||
function bindActionCreator(actionCreator) { | ||
return (...args) => { | ||
const action = actionCreator.apply(manager, args); | ||
if (typeof action !== 'undefined') { | ||
dispatch(action); | ||
} | ||
}; | ||
} | ||
const actions = dragDropActions(this); | ||
return Object.keys(actions).reduce((boundActions, key) => { | ||
const action = actions[key]; | ||
boundActions[key] = bindActionCreator(action); | ||
return boundActions; | ||
}, {}); | ||
} | ||
}]); | ||
return DragDropManagerImpl; | ||
}(); | ||
export { DragDropManagerImpl as default }; | ||
dispatch(action) { | ||
this.store.dispatch(action); | ||
} | ||
} |
@@ -1,248 +0,152 @@ | ||
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'; | ||
import matchesType from './utils/matchesType'; | ||
import { getSourceClientOffset as _getSourceClientOffset, getDifferenceFromInitialOffset as _getDifferenceFromInitialOffset } from './utils/coords'; | ||
import { getSourceClientOffset, getDifferenceFromInitialOffset, } from './utils/coords'; | ||
import { areDirty } from './utils/dirtiness'; | ||
var DragDropMonitorImpl = | ||
/*#__PURE__*/ | ||
function () { | ||
function DragDropMonitorImpl(store, registry) { | ||
_classCallCheck(this, DragDropMonitorImpl); | ||
_defineProperty(this, "store", void 0); | ||
_defineProperty(this, "registry", void 0); | ||
this.store = store; | ||
this.registry = registry; | ||
} | ||
_createClass(DragDropMonitorImpl, [{ | ||
key: "subscribeToStateChange", | ||
value: function subscribeToStateChange(listener) { | ||
var _this = this; | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
handlerIds: undefined | ||
}; | ||
var handlerIds = options.handlerIds; | ||
invariant(typeof listener === 'function', 'listener must be a function.'); | ||
invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.'); | ||
var prevStateId = this.store.getState().stateId; | ||
var handleChange = function handleChange() { | ||
var state = _this.store.getState(); | ||
var currentStateId = state.stateId; | ||
try { | ||
var canSkipListener = currentStateId === prevStateId || currentStateId === prevStateId + 1 && !areDirty(state.dirtyHandlerIds, handlerIds); | ||
if (!canSkipListener) { | ||
export default class DragDropMonitorImpl { | ||
constructor(store, registry) { | ||
this.store = store; | ||
this.registry = registry; | ||
} | ||
subscribeToStateChange(listener, options = { handlerIds: undefined }) { | ||
const { handlerIds } = options; | ||
invariant(typeof listener === 'function', 'listener must be a function.'); | ||
invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.'); | ||
let prevStateId = this.store.getState().stateId; | ||
const handleChange = () => { | ||
const state = this.store.getState(); | ||
const currentStateId = state.stateId; | ||
try { | ||
const canSkipListener = currentStateId === prevStateId || | ||
(currentStateId === prevStateId + 1 && | ||
!areDirty(state.dirtyHandlerIds, handlerIds)); | ||
if (!canSkipListener) { | ||
listener(); | ||
} | ||
} | ||
finally { | ||
prevStateId = currentStateId; | ||
} | ||
}; | ||
return this.store.subscribe(handleChange); | ||
} | ||
subscribeToOffsetChange(listener) { | ||
invariant(typeof listener === 'function', 'listener must be a function.'); | ||
let previousState = this.store.getState().dragOffset; | ||
const handleChange = () => { | ||
const nextState = this.store.getState().dragOffset; | ||
if (nextState === previousState) { | ||
return; | ||
} | ||
previousState = nextState; | ||
listener(); | ||
} | ||
} finally { | ||
prevStateId = currentStateId; | ||
}; | ||
return this.store.subscribe(handleChange); | ||
} | ||
canDragSource(sourceId) { | ||
if (!sourceId) { | ||
return false; | ||
} | ||
}; | ||
return this.store.subscribe(handleChange); | ||
const source = this.registry.getSource(sourceId); | ||
invariant(source, 'Expected to find a valid source.'); | ||
if (this.isDragging()) { | ||
return false; | ||
} | ||
return source.canDrag(this, sourceId); | ||
} | ||
}, { | ||
key: "subscribeToOffsetChange", | ||
value: function subscribeToOffsetChange(listener) { | ||
var _this2 = this; | ||
invariant(typeof listener === 'function', 'listener must be a function.'); | ||
var previousState = this.store.getState().dragOffset; | ||
var handleChange = function handleChange() { | ||
var nextState = _this2.store.getState().dragOffset; | ||
if (nextState === previousState) { | ||
return; | ||
canDropOnTarget(targetId) { | ||
// undefined on initial render | ||
if (!targetId) { | ||
return false; | ||
} | ||
previousState = nextState; | ||
listener(); | ||
}; | ||
return this.store.subscribe(handleChange); | ||
const target = this.registry.getTarget(targetId); | ||
invariant(target, 'Expected to find a valid target.'); | ||
if (!this.isDragging() || this.didDrop()) { | ||
return false; | ||
} | ||
const targetType = this.registry.getTargetType(targetId); | ||
const draggedItemType = this.getItemType(); | ||
return (matchesType(targetType, draggedItemType) && target.canDrop(this, targetId)); | ||
} | ||
}, { | ||
key: "canDragSource", | ||
value: function canDragSource(sourceId) { | ||
if (!sourceId) { | ||
return false; | ||
} | ||
var source = this.registry.getSource(sourceId); | ||
invariant(source, 'Expected to find a valid source.'); | ||
if (this.isDragging()) { | ||
return false; | ||
} | ||
return source.canDrag(this, sourceId); | ||
isDragging() { | ||
return Boolean(this.getItemType()); | ||
} | ||
}, { | ||
key: "canDropOnTarget", | ||
value: function canDropOnTarget(targetId) { | ||
// undefined on initial render | ||
if (!targetId) { | ||
return false; | ||
} | ||
var target = this.registry.getTarget(targetId); | ||
invariant(target, 'Expected to find a valid target.'); | ||
if (!this.isDragging() || this.didDrop()) { | ||
return false; | ||
} | ||
var targetType = this.registry.getTargetType(targetId); | ||
var draggedItemType = this.getItemType(); | ||
return matchesType(targetType, draggedItemType) && target.canDrop(this, targetId); | ||
isDraggingSource(sourceId) { | ||
// undefined on initial render | ||
if (!sourceId) { | ||
return false; | ||
} | ||
const source = this.registry.getSource(sourceId, true); | ||
invariant(source, 'Expected to find a valid source.'); | ||
if (!this.isDragging() || !this.isSourcePublic()) { | ||
return false; | ||
} | ||
const sourceType = this.registry.getSourceType(sourceId); | ||
const draggedItemType = this.getItemType(); | ||
if (sourceType !== draggedItemType) { | ||
return false; | ||
} | ||
return source.isDragging(this, sourceId); | ||
} | ||
}, { | ||
key: "isDragging", | ||
value: function isDragging() { | ||
return Boolean(this.getItemType()); | ||
isOverTarget(targetId, options = { shallow: false }) { | ||
// undefined on initial render | ||
if (!targetId) { | ||
return false; | ||
} | ||
const { shallow } = options; | ||
if (!this.isDragging()) { | ||
return false; | ||
} | ||
const targetType = this.registry.getTargetType(targetId); | ||
const draggedItemType = this.getItemType(); | ||
if (draggedItemType && !matchesType(targetType, draggedItemType)) { | ||
return false; | ||
} | ||
const targetIds = this.getTargetIds(); | ||
if (!targetIds.length) { | ||
return false; | ||
} | ||
const index = targetIds.indexOf(targetId); | ||
if (shallow) { | ||
return index === targetIds.length - 1; | ||
} | ||
else { | ||
return index > -1; | ||
} | ||
} | ||
}, { | ||
key: "isDraggingSource", | ||
value: function isDraggingSource(sourceId) { | ||
// undefined on initial render | ||
if (!sourceId) { | ||
return false; | ||
} | ||
var source = this.registry.getSource(sourceId, true); | ||
invariant(source, 'Expected to find a valid source.'); | ||
if (!this.isDragging() || !this.isSourcePublic()) { | ||
return false; | ||
} | ||
var sourceType = this.registry.getSourceType(sourceId); | ||
var draggedItemType = this.getItemType(); | ||
if (sourceType !== draggedItemType) { | ||
return false; | ||
} | ||
return source.isDragging(this, sourceId); | ||
getItemType() { | ||
return this.store.getState().dragOperation.itemType; | ||
} | ||
}, { | ||
key: "isOverTarget", | ||
value: function isOverTarget(targetId) { | ||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : { | ||
shallow: false | ||
}; | ||
// undefined on initial render | ||
if (!targetId) { | ||
return false; | ||
} | ||
var shallow = options.shallow; | ||
if (!this.isDragging()) { | ||
return false; | ||
} | ||
var targetType = this.registry.getTargetType(targetId); | ||
var draggedItemType = this.getItemType(); | ||
if (draggedItemType && !matchesType(targetType, draggedItemType)) { | ||
return false; | ||
} | ||
var targetIds = this.getTargetIds(); | ||
if (!targetIds.length) { | ||
return false; | ||
} | ||
var index = targetIds.indexOf(targetId); | ||
if (shallow) { | ||
return index === targetIds.length - 1; | ||
} else { | ||
return index > -1; | ||
} | ||
getItem() { | ||
return this.store.getState().dragOperation.item; | ||
} | ||
}, { | ||
key: "getItemType", | ||
value: function getItemType() { | ||
return this.store.getState().dragOperation.itemType; | ||
getSourceId() { | ||
return this.store.getState().dragOperation.sourceId; | ||
} | ||
}, { | ||
key: "getItem", | ||
value: function getItem() { | ||
return this.store.getState().dragOperation.item; | ||
getTargetIds() { | ||
return this.store.getState().dragOperation.targetIds; | ||
} | ||
}, { | ||
key: "getSourceId", | ||
value: function getSourceId() { | ||
return this.store.getState().dragOperation.sourceId; | ||
getDropResult() { | ||
return this.store.getState().dragOperation.dropResult; | ||
} | ||
}, { | ||
key: "getTargetIds", | ||
value: function getTargetIds() { | ||
return this.store.getState().dragOperation.targetIds; | ||
didDrop() { | ||
return this.store.getState().dragOperation.didDrop; | ||
} | ||
}, { | ||
key: "getDropResult", | ||
value: function getDropResult() { | ||
return this.store.getState().dragOperation.dropResult; | ||
isSourcePublic() { | ||
return this.store.getState().dragOperation.isSourcePublic; | ||
} | ||
}, { | ||
key: "didDrop", | ||
value: function didDrop() { | ||
return this.store.getState().dragOperation.didDrop; | ||
getInitialClientOffset() { | ||
return this.store.getState().dragOffset.initialClientOffset; | ||
} | ||
}, { | ||
key: "isSourcePublic", | ||
value: function isSourcePublic() { | ||
return this.store.getState().dragOperation.isSourcePublic; | ||
getInitialSourceClientOffset() { | ||
return this.store.getState().dragOffset.initialSourceClientOffset; | ||
} | ||
}, { | ||
key: "getInitialClientOffset", | ||
value: function getInitialClientOffset() { | ||
return this.store.getState().dragOffset.initialClientOffset; | ||
getClientOffset() { | ||
return this.store.getState().dragOffset.clientOffset; | ||
} | ||
}, { | ||
key: "getInitialSourceClientOffset", | ||
value: function getInitialSourceClientOffset() { | ||
return this.store.getState().dragOffset.initialSourceClientOffset; | ||
getSourceClientOffset() { | ||
return getSourceClientOffset(this.store.getState().dragOffset); | ||
} | ||
}, { | ||
key: "getClientOffset", | ||
value: function getClientOffset() { | ||
return this.store.getState().dragOffset.clientOffset; | ||
getDifferenceFromInitialOffset() { | ||
return getDifferenceFromInitialOffset(this.store.getState().dragOffset); | ||
} | ||
}, { | ||
key: "getSourceClientOffset", | ||
value: function getSourceClientOffset() { | ||
return _getSourceClientOffset(this.store.getState().dragOffset); | ||
} | ||
}, { | ||
key: "getDifferenceFromInitialOffset", | ||
value: function getDifferenceFromInitialOffset() { | ||
return _getDifferenceFromInitialOffset(this.store.getState().dragOffset); | ||
} | ||
}]); | ||
return DragDropMonitorImpl; | ||
}(); | ||
export { DragDropMonitorImpl as default }; | ||
} |
import DragDropManagerImpl from './DragDropManagerImpl'; | ||
export function createDragDropManager(backendFactory, globalContext, backendOptions, debugMode) { | ||
var manager = new DragDropManagerImpl(debugMode); | ||
var backend = backendFactory(manager, globalContext, backendOptions); | ||
manager.receiveBackend(backend); | ||
return manager; | ||
} | ||
const manager = new DragDropManagerImpl(debugMode); | ||
const backend = backendFactory(manager, globalContext, backendOptions); | ||
manager.receiveBackend(backend); | ||
return manager; | ||
} |
@@ -1,210 +0,129 @@ | ||
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; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
import asap from 'asap'; | ||
import invariant from 'invariant'; | ||
import { addSource as _addSource, addTarget as _addTarget, removeSource as _removeSource, removeTarget as _removeTarget } from './actions/registry'; | ||
import { addSource, addTarget, removeSource, removeTarget, } from './actions/registry'; | ||
import getNextUniqueId from './utils/getNextUniqueId'; | ||
import { HandlerRole } from './interfaces'; | ||
import { validateSourceContract, validateTargetContract, validateType } from './contracts'; | ||
import { HandlerRole, } from './interfaces'; | ||
import { validateSourceContract, validateTargetContract, validateType, } from './contracts'; | ||
function getNextHandlerId(role) { | ||
var id = getNextUniqueId().toString(); | ||
switch (role) { | ||
case HandlerRole.SOURCE: | ||
return "S".concat(id); | ||
case HandlerRole.TARGET: | ||
return "T".concat(id); | ||
default: | ||
throw new Error("Unknown Handler Role: ".concat(role)); | ||
} | ||
const id = getNextUniqueId().toString(); | ||
switch (role) { | ||
case HandlerRole.SOURCE: | ||
return `S${id}`; | ||
case HandlerRole.TARGET: | ||
return `T${id}`; | ||
default: | ||
throw new Error(`Unknown Handler Role: ${role}`); | ||
} | ||
} | ||
function parseRoleFromHandlerId(handlerId) { | ||
switch (handlerId[0]) { | ||
case 'S': | ||
return HandlerRole.SOURCE; | ||
case 'T': | ||
return HandlerRole.TARGET; | ||
default: | ||
invariant(false, "Cannot parse handler ID: ".concat(handlerId)); | ||
} | ||
switch (handlerId[0]) { | ||
case 'S': | ||
return HandlerRole.SOURCE; | ||
case 'T': | ||
return HandlerRole.TARGET; | ||
default: | ||
invariant(false, `Cannot parse handler ID: ${handlerId}`); | ||
} | ||
} | ||
function mapContainsValue(map, searchValue) { | ||
var entries = map.entries(); | ||
var isDone = false; | ||
do { | ||
var _entries$next = entries.next(), | ||
done = _entries$next.done, | ||
_entries$next$value = _slicedToArray(_entries$next.value, 2), | ||
value = _entries$next$value[1]; | ||
if (value === searchValue) { | ||
return true; | ||
} | ||
isDone = done; | ||
} while (!isDone); | ||
return false; | ||
const entries = map.entries(); | ||
let isDone = false; | ||
do { | ||
const { done, value: [, value], } = entries.next(); | ||
if (value === searchValue) { | ||
return true; | ||
} | ||
isDone = done; | ||
} while (!isDone); | ||
return false; | ||
} | ||
var HandlerRegistryImpl = | ||
/*#__PURE__*/ | ||
function () { | ||
function HandlerRegistryImpl(store) { | ||
_classCallCheck(this, HandlerRegistryImpl); | ||
_defineProperty(this, "types", new Map()); | ||
_defineProperty(this, "dragSources", new Map()); | ||
_defineProperty(this, "dropTargets", new Map()); | ||
_defineProperty(this, "pinnedSourceId", null); | ||
_defineProperty(this, "pinnedSource", null); | ||
_defineProperty(this, "store", void 0); | ||
this.store = store; | ||
} | ||
_createClass(HandlerRegistryImpl, [{ | ||
key: "addSource", | ||
value: function addSource(type, source) { | ||
validateType(type); | ||
validateSourceContract(source); | ||
var sourceId = this.addHandler(HandlerRole.SOURCE, type, source); | ||
this.store.dispatch(_addSource(sourceId)); | ||
return sourceId; | ||
export default class HandlerRegistryImpl { | ||
constructor(store) { | ||
this.types = new Map(); | ||
this.dragSources = new Map(); | ||
this.dropTargets = new Map(); | ||
this.pinnedSourceId = null; | ||
this.pinnedSource = null; | ||
this.store = store; | ||
} | ||
}, { | ||
key: "addTarget", | ||
value: function addTarget(type, target) { | ||
validateType(type, true); | ||
validateTargetContract(target); | ||
var targetId = this.addHandler(HandlerRole.TARGET, type, target); | ||
this.store.dispatch(_addTarget(targetId)); | ||
return targetId; | ||
addSource(type, source) { | ||
validateType(type); | ||
validateSourceContract(source); | ||
const sourceId = this.addHandler(HandlerRole.SOURCE, type, source); | ||
this.store.dispatch(addSource(sourceId)); | ||
return sourceId; | ||
} | ||
}, { | ||
key: "containsHandler", | ||
value: function containsHandler(handler) { | ||
return mapContainsValue(this.dragSources, handler) || mapContainsValue(this.dropTargets, handler); | ||
addTarget(type, target) { | ||
validateType(type, true); | ||
validateTargetContract(target); | ||
const targetId = this.addHandler(HandlerRole.TARGET, type, target); | ||
this.store.dispatch(addTarget(targetId)); | ||
return targetId; | ||
} | ||
}, { | ||
key: "getSource", | ||
value: function getSource(sourceId) { | ||
var includePinned = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; | ||
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.'); | ||
var isPinned = includePinned && sourceId === this.pinnedSourceId; | ||
var source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId); | ||
return source; | ||
containsHandler(handler) { | ||
return (mapContainsValue(this.dragSources, handler) || | ||
mapContainsValue(this.dropTargets, handler)); | ||
} | ||
}, { | ||
key: "getTarget", | ||
value: function getTarget(targetId) { | ||
invariant(this.isTargetId(targetId), 'Expected a valid target ID.'); | ||
return this.dropTargets.get(targetId); | ||
getSource(sourceId, includePinned = false) { | ||
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.'); | ||
const isPinned = includePinned && sourceId === this.pinnedSourceId; | ||
const source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId); | ||
return source; | ||
} | ||
}, { | ||
key: "getSourceType", | ||
value: function getSourceType(sourceId) { | ||
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.'); | ||
return this.types.get(sourceId); | ||
getTarget(targetId) { | ||
invariant(this.isTargetId(targetId), 'Expected a valid target ID.'); | ||
return this.dropTargets.get(targetId); | ||
} | ||
}, { | ||
key: "getTargetType", | ||
value: function getTargetType(targetId) { | ||
invariant(this.isTargetId(targetId), 'Expected a valid target ID.'); | ||
return this.types.get(targetId); | ||
getSourceType(sourceId) { | ||
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.'); | ||
return this.types.get(sourceId); | ||
} | ||
}, { | ||
key: "isSourceId", | ||
value: function isSourceId(handlerId) { | ||
var role = parseRoleFromHandlerId(handlerId); | ||
return role === HandlerRole.SOURCE; | ||
getTargetType(targetId) { | ||
invariant(this.isTargetId(targetId), 'Expected a valid target ID.'); | ||
return this.types.get(targetId); | ||
} | ||
}, { | ||
key: "isTargetId", | ||
value: function isTargetId(handlerId) { | ||
var role = parseRoleFromHandlerId(handlerId); | ||
return role === HandlerRole.TARGET; | ||
isSourceId(handlerId) { | ||
const role = parseRoleFromHandlerId(handlerId); | ||
return role === HandlerRole.SOURCE; | ||
} | ||
}, { | ||
key: "removeSource", | ||
value: function removeSource(sourceId) { | ||
var _this = this; | ||
invariant(this.getSource(sourceId), 'Expected an existing source.'); | ||
this.store.dispatch(_removeSource(sourceId)); | ||
asap(function () { | ||
_this.dragSources.delete(sourceId); | ||
_this.types.delete(sourceId); | ||
}); | ||
isTargetId(handlerId) { | ||
const role = parseRoleFromHandlerId(handlerId); | ||
return role === HandlerRole.TARGET; | ||
} | ||
}, { | ||
key: "removeTarget", | ||
value: function removeTarget(targetId) { | ||
invariant(this.getTarget(targetId), 'Expected an existing target.'); | ||
this.store.dispatch(_removeTarget(targetId)); | ||
this.dropTargets.delete(targetId); | ||
this.types.delete(targetId); | ||
removeSource(sourceId) { | ||
invariant(this.getSource(sourceId), 'Expected an existing source.'); | ||
this.store.dispatch(removeSource(sourceId)); | ||
asap(() => { | ||
this.dragSources.delete(sourceId); | ||
this.types.delete(sourceId); | ||
}); | ||
} | ||
}, { | ||
key: "pinSource", | ||
value: function pinSource(sourceId) { | ||
var source = this.getSource(sourceId); | ||
invariant(source, 'Expected an existing source.'); | ||
this.pinnedSourceId = sourceId; | ||
this.pinnedSource = source; | ||
removeTarget(targetId) { | ||
invariant(this.getTarget(targetId), 'Expected an existing target.'); | ||
this.store.dispatch(removeTarget(targetId)); | ||
this.dropTargets.delete(targetId); | ||
this.types.delete(targetId); | ||
} | ||
}, { | ||
key: "unpinSource", | ||
value: function unpinSource() { | ||
invariant(this.pinnedSource, 'No source is pinned at the time.'); | ||
this.pinnedSourceId = null; | ||
this.pinnedSource = null; | ||
pinSource(sourceId) { | ||
const source = this.getSource(sourceId); | ||
invariant(source, 'Expected an existing source.'); | ||
this.pinnedSourceId = sourceId; | ||
this.pinnedSource = source; | ||
} | ||
}, { | ||
key: "addHandler", | ||
value: function addHandler(role, type, handler) { | ||
var id = getNextHandlerId(role); | ||
this.types.set(id, type); | ||
if (role === HandlerRole.SOURCE) { | ||
this.dragSources.set(id, handler); | ||
} else if (role === HandlerRole.TARGET) { | ||
this.dropTargets.set(id, handler); | ||
} | ||
return id; | ||
unpinSource() { | ||
invariant(this.pinnedSource, 'No source is pinned at the time.'); | ||
this.pinnedSourceId = null; | ||
this.pinnedSource = null; | ||
} | ||
}]); | ||
return HandlerRegistryImpl; | ||
}(); | ||
export { HandlerRegistryImpl as default }; | ||
addHandler(role, type, handler) { | ||
const id = getNextHandlerId(role); | ||
this.types.set(id, type); | ||
if (role === HandlerRole.SOURCE) { | ||
this.dragSources.set(id, handler); | ||
} | ||
else if (role === HandlerRole.TARGET) { | ||
this.dropTargets.set(id, handler); | ||
} | ||
return id; | ||
} | ||
} |
export * from './interfaces'; | ||
export * from './factories'; | ||
export * from './factories'; |
export var HandlerRole; | ||
(function (HandlerRole) { | ||
HandlerRole["SOURCE"] = "SOURCE"; | ||
HandlerRole["TARGET"] = "TARGET"; | ||
})(HandlerRole || (HandlerRole = {})); | ||
HandlerRole["SOURCE"] = "SOURCE"; | ||
HandlerRole["TARGET"] = "TARGET"; | ||
})(HandlerRole || (HandlerRole = {})); |
@@ -1,56 +0,41 @@ | ||
import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP } from '../actions/dragDrop'; | ||
import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET } from '../actions/registry'; | ||
import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP, } from '../actions/dragDrop'; | ||
import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET, } from '../actions/registry'; | ||
import { areArraysEqual } from '../utils/equality'; | ||
import { NONE, ALL } from '../utils/dirtiness'; | ||
import { xor } from '../utils/js_utils'; | ||
export default function dirtyHandlerIds() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : NONE; | ||
var action = arguments.length > 1 ? arguments[1] : undefined; | ||
switch (action.type) { | ||
case HOVER: | ||
break; | ||
case ADD_SOURCE: | ||
case ADD_TARGET: | ||
case REMOVE_TARGET: | ||
case REMOVE_SOURCE: | ||
return NONE; | ||
case BEGIN_DRAG: | ||
case PUBLISH_DRAG_SOURCE: | ||
case END_DRAG: | ||
case DROP: | ||
default: | ||
return ALL; | ||
} | ||
var _action$payload = action.payload, | ||
_action$payload$targe = _action$payload.targetIds, | ||
targetIds = _action$payload$targe === void 0 ? [] : _action$payload$targe, | ||
_action$payload$prevT = _action$payload.prevTargetIds, | ||
prevTargetIds = _action$payload$prevT === void 0 ? [] : _action$payload$prevT; | ||
var result = xor(targetIds, prevTargetIds); | ||
var didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds); | ||
if (!didChange) { | ||
return NONE; | ||
} // Check the target ids at the innermost position. If they are valid, add them | ||
// to the result | ||
var prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1]; | ||
var innermostTargetId = targetIds[targetIds.length - 1]; | ||
if (prevInnermostTargetId !== innermostTargetId) { | ||
if (prevInnermostTargetId) { | ||
result.push(prevInnermostTargetId); | ||
export default function dirtyHandlerIds(state = NONE, action) { | ||
switch (action.type) { | ||
case HOVER: | ||
break; | ||
case ADD_SOURCE: | ||
case ADD_TARGET: | ||
case REMOVE_TARGET: | ||
case REMOVE_SOURCE: | ||
return NONE; | ||
case BEGIN_DRAG: | ||
case PUBLISH_DRAG_SOURCE: | ||
case END_DRAG: | ||
case DROP: | ||
default: | ||
return ALL; | ||
} | ||
if (innermostTargetId) { | ||
result.push(innermostTargetId); | ||
const { targetIds = [], prevTargetIds = [] } = action.payload; | ||
const result = xor(targetIds, prevTargetIds); | ||
const didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds); | ||
if (!didChange) { | ||
return NONE; | ||
} | ||
} | ||
return result; | ||
} | ||
// Check the target ids at the innermost position. If they are valid, add them | ||
// to the result | ||
const prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1]; | ||
const innermostTargetId = targetIds[targetIds.length - 1]; | ||
if (prevInnermostTargetId !== innermostTargetId) { | ||
if (prevInnermostTargetId) { | ||
result.push(prevInnermostTargetId); | ||
} | ||
if (innermostTargetId) { | ||
result.push(innermostTargetId); | ||
} | ||
} | ||
return result; | ||
} |
@@ -1,44 +0,32 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { keys.push.apply(keys, Object.getOwnPropertySymbols(object)); } if (enumerableOnly) keys = keys.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(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 { INIT_COORDS, BEGIN_DRAG, HOVER, END_DRAG, DROP } from '../actions/dragDrop'; | ||
import { INIT_COORDS, BEGIN_DRAG, HOVER, END_DRAG, DROP, } from '../actions/dragDrop'; | ||
import { areCoordsEqual } from '../utils/equality'; | ||
var initialState = { | ||
initialSourceClientOffset: null, | ||
initialClientOffset: null, | ||
clientOffset: null | ||
const initialState = { | ||
initialSourceClientOffset: null, | ||
initialClientOffset: null, | ||
clientOffset: null, | ||
}; | ||
export default function dragOffset() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; | ||
var action = arguments.length > 1 ? arguments[1] : undefined; | ||
var payload = action.payload; | ||
switch (action.type) { | ||
case INIT_COORDS: | ||
case BEGIN_DRAG: | ||
return { | ||
initialSourceClientOffset: payload.sourceClientOffset, | ||
initialClientOffset: payload.clientOffset, | ||
clientOffset: payload.clientOffset | ||
}; | ||
case HOVER: | ||
if (areCoordsEqual(state.clientOffset, payload.clientOffset)) { | ||
return state; | ||
} | ||
return _objectSpread({}, state, { | ||
clientOffset: payload.clientOffset | ||
}); | ||
case END_DRAG: | ||
case DROP: | ||
return initialState; | ||
default: | ||
return state; | ||
} | ||
} | ||
export default function dragOffset(state = initialState, action) { | ||
const { payload } = action; | ||
switch (action.type) { | ||
case INIT_COORDS: | ||
case BEGIN_DRAG: | ||
return { | ||
initialSourceClientOffset: payload.sourceClientOffset, | ||
initialClientOffset: payload.clientOffset, | ||
clientOffset: payload.clientOffset, | ||
}; | ||
case HOVER: | ||
if (areCoordsEqual(state.clientOffset, payload.clientOffset)) { | ||
return state; | ||
} | ||
return { | ||
...state, | ||
clientOffset: payload.clientOffset, | ||
}; | ||
case END_DRAG: | ||
case DROP: | ||
return initialState; | ||
default: | ||
return state; | ||
} | ||
} |
@@ -1,75 +0,65 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { keys.push.apply(keys, Object.getOwnPropertySymbols(object)); } if (enumerableOnly) keys = keys.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(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 { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP } from '../actions/dragDrop'; | ||
import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP, } from '../actions/dragDrop'; | ||
import { REMOVE_TARGET } from '../actions/registry'; | ||
import { without } from '../utils/js_utils'; | ||
var initialState = { | ||
itemType: null, | ||
item: null, | ||
sourceId: null, | ||
targetIds: [], | ||
dropResult: null, | ||
didDrop: false, | ||
isSourcePublic: null | ||
const initialState = { | ||
itemType: null, | ||
item: null, | ||
sourceId: null, | ||
targetIds: [], | ||
dropResult: null, | ||
didDrop: false, | ||
isSourcePublic: null, | ||
}; | ||
export default function dragOperation() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : initialState; | ||
var action = arguments.length > 1 ? arguments[1] : undefined; | ||
var payload = action.payload; | ||
switch (action.type) { | ||
case BEGIN_DRAG: | ||
return _objectSpread({}, state, { | ||
itemType: payload.itemType, | ||
item: payload.item, | ||
sourceId: payload.sourceId, | ||
isSourcePublic: payload.isSourcePublic, | ||
dropResult: null, | ||
didDrop: false | ||
}); | ||
case PUBLISH_DRAG_SOURCE: | ||
return _objectSpread({}, state, { | ||
isSourcePublic: true | ||
}); | ||
case HOVER: | ||
return _objectSpread({}, state, { | ||
targetIds: payload.targetIds | ||
}); | ||
case REMOVE_TARGET: | ||
if (state.targetIds.indexOf(payload.targetId) === -1) { | ||
return state; | ||
} | ||
return _objectSpread({}, state, { | ||
targetIds: without(state.targetIds, payload.targetId) | ||
}); | ||
case DROP: | ||
return _objectSpread({}, state, { | ||
dropResult: payload.dropResult, | ||
didDrop: true, | ||
targetIds: [] | ||
}); | ||
case END_DRAG: | ||
return _objectSpread({}, state, { | ||
itemType: null, | ||
item: null, | ||
sourceId: null, | ||
dropResult: null, | ||
didDrop: false, | ||
isSourcePublic: null, | ||
targetIds: [] | ||
}); | ||
default: | ||
return state; | ||
} | ||
} | ||
export default function dragOperation(state = initialState, action) { | ||
const { payload } = action; | ||
switch (action.type) { | ||
case BEGIN_DRAG: | ||
return { | ||
...state, | ||
itemType: payload.itemType, | ||
item: payload.item, | ||
sourceId: payload.sourceId, | ||
isSourcePublic: payload.isSourcePublic, | ||
dropResult: null, | ||
didDrop: false, | ||
}; | ||
case PUBLISH_DRAG_SOURCE: | ||
return { | ||
...state, | ||
isSourcePublic: true, | ||
}; | ||
case HOVER: | ||
return { | ||
...state, | ||
targetIds: payload.targetIds, | ||
}; | ||
case REMOVE_TARGET: | ||
if (state.targetIds.indexOf(payload.targetId) === -1) { | ||
return state; | ||
} | ||
return { | ||
...state, | ||
targetIds: without(state.targetIds, payload.targetId), | ||
}; | ||
case DROP: | ||
return { | ||
...state, | ||
dropResult: payload.dropResult, | ||
didDrop: true, | ||
targetIds: [], | ||
}; | ||
case END_DRAG: | ||
return { | ||
...state, | ||
itemType: null, | ||
item: null, | ||
sourceId: null, | ||
dropResult: null, | ||
didDrop: false, | ||
isSourcePublic: null, | ||
targetIds: [], | ||
}; | ||
default: | ||
return state; | ||
} | ||
} |
@@ -1,7 +0,1 @@ | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { keys.push.apply(keys, Object.getOwnPropertySymbols(object)); } if (enumerableOnly) keys = keys.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(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 dragOffset from './dragOffset'; | ||
@@ -13,17 +7,16 @@ import dragOperation from './dragOperation'; | ||
import { get } from '../utils/js_utils'; | ||
export default function reduce() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var action = arguments.length > 1 ? arguments[1] : undefined; | ||
return { | ||
dirtyHandlerIds: dirtyHandlerIds(state.dirtyHandlerIds, { | ||
type: action.type, | ||
payload: _objectSpread({}, action.payload, { | ||
prevTargetIds: get(state, 'dragOperation.targetIds', []) | ||
}) | ||
}), | ||
dragOffset: dragOffset(state.dragOffset, action), | ||
refCount: refCount(state.refCount, action), | ||
dragOperation: dragOperation(state.dragOperation, action), | ||
stateId: stateId(state.stateId) | ||
}; | ||
} | ||
export default function reduce(state = {}, action) { | ||
return { | ||
dirtyHandlerIds: dirtyHandlerIds(state.dirtyHandlerIds, { | ||
type: action.type, | ||
payload: { | ||
...action.payload, | ||
prevTargetIds: get(state, 'dragOperation.targetIds', []), | ||
}, | ||
}), | ||
dragOffset: dragOffset(state.dragOffset, action), | ||
refCount: refCount(state.refCount, action), | ||
dragOperation: dragOperation(state.dragOperation, action), | ||
stateId: stateId(state.stateId), | ||
}; | ||
} |
@@ -1,18 +0,13 @@ | ||
import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET } from '../actions/registry'; | ||
export default function refCount() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
var action = arguments.length > 1 ? arguments[1] : undefined; | ||
switch (action.type) { | ||
case ADD_SOURCE: | ||
case ADD_TARGET: | ||
return state + 1; | ||
case REMOVE_SOURCE: | ||
case REMOVE_TARGET: | ||
return state - 1; | ||
default: | ||
return state; | ||
} | ||
} | ||
import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET, } from '../actions/registry'; | ||
export default function refCount(state = 0, action) { | ||
switch (action.type) { | ||
case ADD_SOURCE: | ||
case ADD_TARGET: | ||
return state + 1; | ||
case REMOVE_SOURCE: | ||
case REMOVE_TARGET: | ||
return state - 1; | ||
default: | ||
return state; | ||
} | ||
} |
@@ -1,4 +0,3 @@ | ||
export default function stateId() { | ||
var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; | ||
return state + 1; | ||
} | ||
export default function stateId(state = 0) { | ||
return state + 1; | ||
} |
@@ -7,6 +7,6 @@ /** | ||
export function add(a, b) { | ||
return { | ||
x: a.x + b.x, | ||
y: a.y + b.y | ||
}; | ||
return { | ||
x: a.x + b.x, | ||
y: a.y + b.y, | ||
}; | ||
} | ||
@@ -18,8 +18,7 @@ /** | ||
*/ | ||
export function subtract(a, b) { | ||
return { | ||
x: a.x - b.x, | ||
y: a.y - b.y | ||
}; | ||
return { | ||
x: a.x - b.x, | ||
y: a.y - b.y, | ||
}; | ||
} | ||
@@ -34,13 +33,8 @@ /** | ||
*/ | ||
export function getSourceClientOffset(state) { | ||
var clientOffset = state.clientOffset, | ||
initialClientOffset = state.initialClientOffset, | ||
initialSourceClientOffset = state.initialSourceClientOffset; | ||
if (!clientOffset || !initialClientOffset || !initialSourceClientOffset) { | ||
return null; | ||
} | ||
return subtract(add(clientOffset, initialSourceClientOffset), initialClientOffset); | ||
const { clientOffset, initialClientOffset, initialSourceClientOffset } = state; | ||
if (!clientOffset || !initialClientOffset || !initialSourceClientOffset) { | ||
return null; | ||
} | ||
return subtract(add(clientOffset, initialSourceClientOffset), initialClientOffset); | ||
} | ||
@@ -52,12 +46,8 @@ /** | ||
*/ | ||
export function getDifferenceFromInitialOffset(state) { | ||
var clientOffset = state.clientOffset, | ||
initialClientOffset = state.initialClientOffset; | ||
if (!clientOffset || !initialClientOffset) { | ||
return null; | ||
} | ||
return subtract(clientOffset, initialClientOffset); | ||
} | ||
const { clientOffset, initialClientOffset } = state; | ||
if (!clientOffset || !initialClientOffset) { | ||
return null; | ||
} | ||
return subtract(clientOffset, initialClientOffset); | ||
} |
import { intersection } from './js_utils'; | ||
export var NONE = []; | ||
export var ALL = [] // Add these flags for debug | ||
; | ||
export const NONE = []; | ||
export const ALL = []; | ||
NONE.__IS_NONE__ = true; | ||
@@ -13,14 +12,11 @@ ALL.__IS_ALL__ = true; | ||
*/ | ||
export function areDirty(dirtyIds, handlerIds) { | ||
if (dirtyIds === NONE) { | ||
return false; | ||
} | ||
if (dirtyIds === ALL || typeof handlerIds === 'undefined') { | ||
return true; | ||
} | ||
var commonIds = intersection(handlerIds, dirtyIds); | ||
return commonIds.length > 0; | ||
} | ||
if (dirtyIds === NONE) { | ||
return false; | ||
} | ||
if (dirtyIds === ALL || typeof handlerIds === 'undefined') { | ||
return true; | ||
} | ||
const commonIds = intersection(handlerIds, dirtyIds); | ||
return commonIds.length > 0; | ||
} |
@@ -1,4 +0,2 @@ | ||
export var strictEquality = function strictEquality(a, b) { | ||
return a === b; | ||
}; | ||
export const strictEquality = (a, b) => a === b; | ||
/** | ||
@@ -9,11 +7,12 @@ * Determine if two cartesian coordinate offsets are equal | ||
*/ | ||
export function areCoordsEqual(offsetA, offsetB) { | ||
if (!offsetA && !offsetB) { | ||
return true; | ||
} else if (!offsetA || !offsetB) { | ||
return false; | ||
} else { | ||
return offsetA.x === offsetB.x && offsetA.y === offsetB.y; | ||
} | ||
if (!offsetA && !offsetB) { | ||
return true; | ||
} | ||
else if (!offsetA || !offsetB) { | ||
return false; | ||
} | ||
else { | ||
return offsetA.x === offsetB.x && offsetA.y === offsetB.y; | ||
} | ||
} | ||
@@ -25,17 +24,12 @@ /** | ||
*/ | ||
export function areArraysEqual(a, b) { | ||
var isEqual = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : strictEquality; | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
for (var i = 0; i < a.length; ++i) { | ||
if (!isEqual(a[i], b[i])) { | ||
return false; | ||
export function areArraysEqual(a, b, isEqual = strictEquality) { | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
for (let i = 0; i < a.length; ++i) { | ||
if (!isEqual(a[i], b[i])) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
@@ -1,4 +0,4 @@ | ||
var nextUniqueId = 0; | ||
let nextUniqueId = 0; | ||
export default function getNextUniqueId() { | ||
return nextUniqueId++; | ||
} | ||
return nextUniqueId++; | ||
} |
@@ -1,5 +0,2 @@ | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
// cheap lodash replacements | ||
/** | ||
@@ -12,5 +9,5 @@ * drop-in replacement for _.get | ||
export function get(obj, path, defaultValue) { | ||
return path.split('.').reduce(function (a, c) { | ||
return a && a[c] ? a[c] : defaultValue || null; | ||
}, obj); | ||
return path | ||
.split('.') | ||
.reduce((a, c) => (a && a[c] ? a[c] : defaultValue || null), obj); | ||
} | ||
@@ -20,7 +17,4 @@ /** | ||
*/ | ||
export function without(items, item) { | ||
return items.filter(function (i) { | ||
return i !== item; | ||
}); | ||
return items.filter(i => i !== item); | ||
} | ||
@@ -31,5 +25,4 @@ /** | ||
*/ | ||
export function isString(input) { | ||
return typeof input === 'string'; | ||
return typeof input === 'string'; | ||
} | ||
@@ -40,5 +33,4 @@ /** | ||
*/ | ||
export function isObject(input) { | ||
return _typeof(input) === 'object'; | ||
return typeof input === 'object'; | ||
} | ||
@@ -50,19 +42,14 @@ /** | ||
*/ | ||
export function xor(itemsA, itemsB) { | ||
var map = new Map(); | ||
var insertItem = function insertItem(item) { | ||
return map.set(item, map.has(item) ? map.get(item) + 1 : 1); | ||
}; | ||
itemsA.forEach(insertItem); | ||
itemsB.forEach(insertItem); | ||
var result = []; | ||
map.forEach(function (count, key) { | ||
if (count === 1) { | ||
result.push(key); | ||
} | ||
}); | ||
return result; | ||
const map = new Map(); | ||
const insertItem = (item) => map.set(item, map.has(item) ? map.get(item) + 1 : 1); | ||
itemsA.forEach(insertItem); | ||
itemsB.forEach(insertItem); | ||
const result = []; | ||
map.forEach((count, key) => { | ||
if (count === 1) { | ||
result.push(key); | ||
} | ||
}); | ||
return result; | ||
} | ||
@@ -74,7 +61,4 @@ /** | ||
*/ | ||
export function intersection(itemsA, itemsB) { | ||
return itemsA.filter(function (t) { | ||
return itemsB.indexOf(t) > -1; | ||
}); | ||
} | ||
return itemsA.filter(t => itemsB.indexOf(t) > -1); | ||
} |
export default function matchesType(targetType, draggedItemType) { | ||
if (draggedItemType === null) { | ||
return targetType === null; | ||
} | ||
return Array.isArray(targetType) ? targetType.some(function (t) { | ||
return t === draggedItemType; | ||
}) : targetType === draggedItemType; | ||
} | ||
if (draggedItemType === null) { | ||
return targetType === null; | ||
} | ||
return Array.isArray(targetType) | ||
? targetType.some(t => t === draggedItemType) | ||
: targetType === draggedItemType; | ||
} |
{ | ||
"name": "dnd-core", | ||
"version": "9.3.1", | ||
"version": "9.3.2", | ||
"description": "Drag and drop sans the GUI", | ||
"license": "MIT", | ||
"main": "./lib/index.js", | ||
"module": "./lib/index.js", | ||
"main": "./dist/esm/index.js", | ||
"module": "./dist/esm/index.js", | ||
"type": "module", | ||
@@ -25,4 +25,3 @@ "types": "./lib/index.d.ts", | ||
"redux": "^4.0.1" | ||
}, | ||
"gitHead": "0493eaa356cd25de1d1ba753e3f43c051e2076b2" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
339208
116
4011