Comparing version 3.0.1 to 3.0.2
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,6 +14,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const invariant_1 = __importDefault(require("invariant")); | ||
const isArray_1 = __importDefault(require("lodash/isArray")); | ||
const isObject_1 = __importDefault(require("lodash/isObject")); | ||
const matchesType_1 = __importDefault(require("../utils/matchesType")); | ||
var invariant_1 = __importDefault(require("invariant")); | ||
var isArray_1 = __importDefault(require("lodash/isArray")); | ||
var isObject_1 = __importDefault(require("lodash/isObject")); | ||
var matchesType_1 = __importDefault(require("../utils/matchesType")); | ||
exports.BEGIN_DRAG = 'dnd-core/BEGIN_DRAG'; | ||
@@ -18,13 +26,16 @@ exports.PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE'; | ||
return { | ||
beginDrag(sourceIds = [], { publishSource, clientOffset, getSourceClientOffset, } = { | ||
publishSource: true, | ||
}) { | ||
const monitor = manager.getMonitor(); | ||
const registry = manager.getRegistry(); | ||
beginDrag: function (sourceIds, _a) { | ||
if (sourceIds === void 0) { sourceIds = []; } | ||
var _b = _a === void 0 ? { | ||
publishSource: true, | ||
} : _a, publishSource = _b.publishSource, clientOffset = _b.clientOffset, getSourceClientOffset = _b.getSourceClientOffset; | ||
var monitor = manager.getMonitor(); | ||
var registry = manager.getRegistry(); | ||
invariant_1.default(!monitor.isDragging(), 'Cannot call beginDrag while dragging.'); | ||
for (const s of sourceIds) { | ||
for (var _i = 0, sourceIds_1 = sourceIds; _i < sourceIds_1.length; _i++) { | ||
var s = sourceIds_1[_i]; | ||
invariant_1.default(registry.getSource(s), 'Expected sourceIds to be registered.'); | ||
} | ||
let sourceId = null; | ||
for (let i = sourceIds.length - 1; i >= 0; i--) { | ||
var sourceId = null; | ||
for (var i = sourceIds.length - 1; i >= 0; i--) { | ||
if (monitor.canDragSource(sourceIds[i])) { | ||
@@ -38,3 +49,3 @@ sourceId = sourceIds[i]; | ||
} | ||
let sourceClientOffset = null; | ||
var sourceClientOffset = null; | ||
if (clientOffset) { | ||
@@ -44,13 +55,13 @@ invariant_1.default(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.'); | ||
} | ||
const source = registry.getSource(sourceId); | ||
const item = source.beginDrag(monitor, sourceId); | ||
var source = registry.getSource(sourceId); | ||
var item = source.beginDrag(monitor, sourceId); | ||
invariant_1.default(isObject_1.default(item), 'Item must be an object.'); | ||
registry.pinSource(sourceId); | ||
const itemType = registry.getSourceType(sourceId); | ||
var itemType = registry.getSourceType(sourceId); | ||
return { | ||
type: exports.BEGIN_DRAG, | ||
payload: { | ||
itemType, | ||
item, | ||
sourceId, | ||
itemType: itemType, | ||
item: item, | ||
sourceId: sourceId, | ||
clientOffset: clientOffset || null, | ||
@@ -62,4 +73,4 @@ sourceClientOffset: sourceClientOffset || null, | ||
}, | ||
publishDragSource() { | ||
const monitor = manager.getMonitor(); | ||
publishDragSource: function () { | ||
var monitor = manager.getMonitor(); | ||
if (!monitor.isDragging()) { | ||
@@ -70,23 +81,24 @@ return; | ||
}, | ||
hover(targetIdsArg, { clientOffset } = {}) { | ||
hover: function (targetIdsArg, _a) { | ||
var clientOffset = (_a === void 0 ? {} : _a).clientOffset; | ||
invariant_1.default(isArray_1.default(targetIdsArg), 'Expected targetIds to be an array.'); | ||
const targetIds = targetIdsArg.slice(0); | ||
const monitor = manager.getMonitor(); | ||
const registry = manager.getRegistry(); | ||
var targetIds = targetIdsArg.slice(0); | ||
var monitor = manager.getMonitor(); | ||
var registry = manager.getRegistry(); | ||
invariant_1.default(monitor.isDragging(), 'Cannot call hover while not dragging.'); | ||
invariant_1.default(!monitor.didDrop(), 'Cannot call hover after drop.'); | ||
// First check invariants. | ||
for (let i = 0; i < targetIds.length; i++) { | ||
const targetId = targetIds[i]; | ||
for (var i = 0; i < targetIds.length; i++) { | ||
var targetId = targetIds[i]; | ||
invariant_1.default(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.'); | ||
const target = registry.getTarget(targetId); | ||
var target = registry.getTarget(targetId); | ||
invariant_1.default(target, 'Expected targetIds to be registered.'); | ||
} | ||
const draggedItemType = monitor.getItemType(); | ||
var draggedItemType = monitor.getItemType(); | ||
// 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); | ||
for (var i = targetIds.length - 1; i >= 0; i--) { | ||
var targetId = targetIds[i]; | ||
var targetType = registry.getTargetType(targetId); | ||
if (!matchesType_1.default(targetType, draggedItemType)) { | ||
@@ -97,4 +109,5 @@ targetIds.splice(i, 1); | ||
// Finally call hover on all matching targets. | ||
for (const targetId of targetIds) { | ||
const target = registry.getTarget(targetId); | ||
for (var _i = 0, targetIds_1 = targetIds; _i < targetIds_1.length; _i++) { | ||
var targetId = targetIds_1[_i]; | ||
var target = registry.getTarget(targetId); | ||
target.hover(monitor, targetId); | ||
@@ -105,3 +118,3 @@ } | ||
payload: { | ||
targetIds, | ||
targetIds: targetIds, | ||
clientOffset: clientOffset || null, | ||
@@ -111,8 +124,9 @@ }, | ||
}, | ||
drop(options = {}) { | ||
const monitor = manager.getMonitor(); | ||
const registry = manager.getRegistry(); | ||
drop: function (options) { | ||
if (options === void 0) { options = {}; } | ||
var monitor = manager.getMonitor(); | ||
var registry = manager.getRegistry(); | ||
invariant_1.default(monitor.isDragging(), 'Cannot call drop while not dragging.'); | ||
invariant_1.default(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.'); | ||
const targetIds = monitor | ||
var targetIds = monitor | ||
.getTargetIds() | ||
@@ -122,5 +136,5 @@ .filter(monitor.canDropOnTarget, monitor); | ||
// Multiple actions are dispatched here, which is why this doesn't return an action | ||
targetIds.forEach((targetId, index) => { | ||
const target = registry.getTarget(targetId); | ||
let dropResult = target.drop(monitor, targetId); | ||
targetIds.forEach(function (targetId, index) { | ||
var target = registry.getTarget(targetId); | ||
var dropResult = target.drop(monitor, targetId); | ||
invariant_1.default(typeof dropResult === 'undefined' || isObject_1.default(dropResult), 'Drop result must either be an object or undefined.'); | ||
@@ -130,6 +144,6 @@ if (typeof dropResult === 'undefined') { | ||
} | ||
const action = { | ||
var action = { | ||
type: exports.DROP, | ||
payload: { | ||
dropResult: Object.assign({}, options, dropResult), | ||
dropResult: __assign({}, options, dropResult), | ||
}, | ||
@@ -140,8 +154,8 @@ }; | ||
}, | ||
endDrag() { | ||
const monitor = manager.getMonitor(); | ||
const registry = manager.getRegistry(); | ||
endDrag: function () { | ||
var monitor = manager.getMonitor(); | ||
var registry = manager.getRegistry(); | ||
invariant_1.default(monitor.isDragging(), 'Cannot call endDrag while not dragging.'); | ||
const sourceId = monitor.getSourceId(); | ||
const source = registry.getSource(sourceId, true); | ||
var sourceId = monitor.getSourceId(); | ||
var source = registry.getSource(sourceId, true); | ||
source.endDrag(monitor, sourceId); | ||
@@ -148,0 +162,0 @@ registry.unpinSource(); |
@@ -11,3 +11,3 @@ "use strict"; | ||
payload: { | ||
sourceId, | ||
sourceId: sourceId, | ||
}, | ||
@@ -21,3 +21,3 @@ }; | ||
payload: { | ||
targetId, | ||
targetId: targetId, | ||
}, | ||
@@ -31,3 +31,3 @@ }; | ||
payload: { | ||
sourceId, | ||
sourceId: sourceId, | ||
}, | ||
@@ -41,3 +41,3 @@ }; | ||
payload: { | ||
targetId, | ||
targetId: targetId, | ||
}, | ||
@@ -44,0 +44,0 @@ }; |
@@ -6,4 +6,4 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const invariant_1 = __importDefault(require("invariant")); | ||
const isArray_1 = __importDefault(require("lodash/isArray")); | ||
var invariant_1 = __importDefault(require("invariant")); | ||
var isArray_1 = __importDefault(require("lodash/isArray")); | ||
function validateSourceContract(source) { | ||
@@ -23,3 +23,3 @@ invariant_1.default(typeof source.canDrag === 'function', 'Expected canDrag to be a function.'); | ||
if (allowArray && isArray_1.default(type)) { | ||
type.forEach(t => validateType(t, false)); | ||
type.forEach(function (t) { return validateType(t, false); }); | ||
return; | ||
@@ -26,0 +26,0 @@ } |
@@ -6,12 +6,13 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const redux_1 = require("redux"); | ||
const reducers_1 = __importDefault(require("./reducers")); | ||
const dragDrop_1 = __importDefault(require("./actions/dragDrop")); | ||
const DragDropMonitorImpl_1 = __importDefault(require("./DragDropMonitorImpl")); | ||
const HandlerRegistryImpl_1 = __importDefault(require("./HandlerRegistryImpl")); | ||
class DragDropManagerImpl { | ||
constructor(createBackend, context = {}) { | ||
var redux_1 = require("redux"); | ||
var reducers_1 = __importDefault(require("./reducers")); | ||
var dragDrop_1 = __importDefault(require("./actions/dragDrop")); | ||
var DragDropMonitorImpl_1 = __importDefault(require("./DragDropMonitorImpl")); | ||
var HandlerRegistryImpl_1 = __importDefault(require("./HandlerRegistryImpl")); | ||
var DragDropManagerImpl = /** @class */ (function () { | ||
function DragDropManagerImpl(createBackend, context) { | ||
if (context === void 0) { context = {}; } | ||
this.context = context; | ||
this.isSetUp = false; | ||
const store = redux_1.createStore(reducers_1.default); | ||
var store = redux_1.createStore(reducers_1.default); | ||
this.store = store; | ||
@@ -22,20 +23,24 @@ this.monitor = new DragDropMonitorImpl_1.default(store, new HandlerRegistryImpl_1.default(store)); | ||
} | ||
getContext() { | ||
DragDropManagerImpl.prototype.getContext = function () { | ||
return this.context; | ||
} | ||
getMonitor() { | ||
}; | ||
DragDropManagerImpl.prototype.getMonitor = function () { | ||
return this.monitor; | ||
} | ||
getBackend() { | ||
}; | ||
DragDropManagerImpl.prototype.getBackend = function () { | ||
return this.backend; | ||
} | ||
getRegistry() { | ||
}; | ||
DragDropManagerImpl.prototype.getRegistry = function () { | ||
return this.monitor.registry; | ||
} | ||
getActions() { | ||
const manager = this; | ||
const { dispatch } = this.store; | ||
}; | ||
DragDropManagerImpl.prototype.getActions = function () { | ||
var manager = this; | ||
var dispatch = this.store.dispatch; | ||
function bindActionCreator(actionCreator) { | ||
return (...args) => { | ||
const action = actionCreator.apply(manager, args); | ||
return function () { | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var action = actionCreator.apply(manager, args); | ||
if (typeof action !== 'undefined') { | ||
@@ -46,14 +51,14 @@ dispatch(action); | ||
} | ||
const actions = dragDrop_1.default(this); | ||
return Object.keys(actions).reduce((boundActions, key) => { | ||
const action = actions[key]; | ||
var actions = dragDrop_1.default(this); | ||
return Object.keys(actions).reduce(function (boundActions, key) { | ||
var action = actions[key]; | ||
boundActions[key] = bindActionCreator(action); // eslint-disable-line no-param-reassign | ||
return boundActions; | ||
}, {}); | ||
} | ||
dispatch(action) { | ||
}; | ||
DragDropManagerImpl.prototype.dispatch = function (action) { | ||
this.store.dispatch(action); | ||
} | ||
handleRefCountChange() { | ||
const shouldSetUp = this.store.getState().refCount > 0; | ||
}; | ||
DragDropManagerImpl.prototype.handleRefCountChange = function () { | ||
var shouldSetUp = this.store.getState().refCount > 0; | ||
if (shouldSetUp && !this.isSetUp) { | ||
@@ -67,5 +72,6 @@ this.backend.setup(); | ||
} | ||
} | ||
} | ||
}; | ||
return DragDropManagerImpl; | ||
}()); | ||
exports.default = DragDropManagerImpl; | ||
//# sourceMappingURL=DragDropManagerImpl.js.map |
@@ -6,22 +6,24 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const invariant_1 = __importDefault(require("invariant")); | ||
const isArray_1 = __importDefault(require("lodash/isArray")); | ||
const matchesType_1 = __importDefault(require("./utils/matchesType")); | ||
const coords_1 = require("./utils/coords"); | ||
const dirtiness_1 = require("./utils/dirtiness"); | ||
class DragDropMonitorImpl { | ||
constructor(store, registry) { | ||
var invariant_1 = __importDefault(require("invariant")); | ||
var isArray_1 = __importDefault(require("lodash/isArray")); | ||
var matchesType_1 = __importDefault(require("./utils/matchesType")); | ||
var coords_1 = require("./utils/coords"); | ||
var dirtiness_1 = require("./utils/dirtiness"); | ||
var DragDropMonitorImpl = /** @class */ (function () { | ||
function DragDropMonitorImpl(store, registry) { | ||
this.store = store; | ||
this.registry = registry; | ||
} | ||
subscribeToStateChange(listener, options = { handlerIds: undefined }) { | ||
const { handlerIds } = options; | ||
DragDropMonitorImpl.prototype.subscribeToStateChange = function (listener, options) { | ||
var _this = this; | ||
if (options === void 0) { options = { handlerIds: undefined }; } | ||
var handlerIds = options.handlerIds; | ||
invariant_1.default(typeof listener === 'function', 'listener must be a function.'); | ||
invariant_1.default(typeof handlerIds === 'undefined' || isArray_1.default(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; | ||
var prevStateId = this.store.getState().stateId; | ||
var handleChange = function () { | ||
var state = _this.store.getState(); | ||
var currentStateId = state.stateId; | ||
try { | ||
const canSkipListener = currentStateId === prevStateId || | ||
var canSkipListener = currentStateId === prevStateId || | ||
(currentStateId === prevStateId + 1 && | ||
@@ -38,8 +40,9 @@ !dirtiness_1.areDirty(state.dirtyHandlerIds, handlerIds)); | ||
return this.store.subscribe(handleChange); | ||
} | ||
subscribeToOffsetChange(listener) { | ||
}; | ||
DragDropMonitorImpl.prototype.subscribeToOffsetChange = function (listener) { | ||
var _this = this; | ||
invariant_1.default(typeof listener === 'function', 'listener must be a function.'); | ||
let previousState = this.store.getState().dragOffset; | ||
const handleChange = () => { | ||
const nextState = this.store.getState().dragOffset; | ||
var previousState = this.store.getState().dragOffset; | ||
var handleChange = function () { | ||
var nextState = _this.store.getState().dragOffset; | ||
if (nextState === previousState) { | ||
@@ -52,5 +55,5 @@ return; | ||
return this.store.subscribe(handleChange); | ||
} | ||
canDragSource(sourceId) { | ||
const source = this.registry.getSource(sourceId); | ||
}; | ||
DragDropMonitorImpl.prototype.canDragSource = function (sourceId) { | ||
var source = this.registry.getSource(sourceId); | ||
invariant_1.default(source, 'Expected to find a valid source.'); | ||
@@ -61,5 +64,5 @@ if (this.isDragging()) { | ||
return source.canDrag(this, sourceId); | ||
} | ||
canDropOnTarget(targetId) { | ||
const target = this.registry.getTarget(targetId); | ||
}; | ||
DragDropMonitorImpl.prototype.canDropOnTarget = function (targetId) { | ||
var target = this.registry.getTarget(targetId); | ||
invariant_1.default(target, 'Expected to find a valid target.'); | ||
@@ -69,11 +72,11 @@ if (!this.isDragging() || this.didDrop()) { | ||
} | ||
const targetType = this.registry.getTargetType(targetId); | ||
const draggedItemType = this.getItemType(); | ||
var targetType = this.registry.getTargetType(targetId); | ||
var draggedItemType = this.getItemType(); | ||
return (matchesType_1.default(targetType, draggedItemType) && target.canDrop(this, targetId)); | ||
} | ||
isDragging() { | ||
}; | ||
DragDropMonitorImpl.prototype.isDragging = function () { | ||
return Boolean(this.getItemType()); | ||
} | ||
isDraggingSource(sourceId) { | ||
const source = this.registry.getSource(sourceId, true); | ||
}; | ||
DragDropMonitorImpl.prototype.isDraggingSource = function (sourceId) { | ||
var source = this.registry.getSource(sourceId, true); | ||
invariant_1.default(source, 'Expected to find a valid source.'); | ||
@@ -83,4 +86,4 @@ if (!this.isDragging() || !this.isSourcePublic()) { | ||
} | ||
const sourceType = this.registry.getSourceType(sourceId); | ||
const draggedItemType = this.getItemType(); | ||
var sourceType = this.registry.getSourceType(sourceId); | ||
var draggedItemType = this.getItemType(); | ||
if (sourceType !== draggedItemType) { | ||
@@ -90,18 +93,19 @@ return false; | ||
return source.isDragging(this, sourceId); | ||
} | ||
isOverTarget(targetId, options = { shallow: false }) { | ||
const { shallow } = options; | ||
}; | ||
DragDropMonitorImpl.prototype.isOverTarget = function (targetId, options) { | ||
if (options === void 0) { options = { shallow: false }; } | ||
var shallow = options.shallow; | ||
if (!this.isDragging()) { | ||
return false; | ||
} | ||
const targetType = this.registry.getTargetType(targetId); | ||
const draggedItemType = this.getItemType(); | ||
var targetType = this.registry.getTargetType(targetId); | ||
var draggedItemType = this.getItemType(); | ||
if (draggedItemType && !matchesType_1.default(targetType, draggedItemType)) { | ||
return false; | ||
} | ||
const targetIds = this.getTargetIds(); | ||
var targetIds = this.getTargetIds(); | ||
if (!targetIds.length) { | ||
return false; | ||
} | ||
const index = targetIds.indexOf(targetId); | ||
var index = targetIds.indexOf(targetId); | ||
if (shallow) { | ||
@@ -113,41 +117,42 @@ return index === targetIds.length - 1; | ||
} | ||
} | ||
getItemType() { | ||
}; | ||
DragDropMonitorImpl.prototype.getItemType = function () { | ||
return this.store.getState().dragOperation.itemType; | ||
} | ||
getItem() { | ||
}; | ||
DragDropMonitorImpl.prototype.getItem = function () { | ||
return this.store.getState().dragOperation.item; | ||
} | ||
getSourceId() { | ||
}; | ||
DragDropMonitorImpl.prototype.getSourceId = function () { | ||
return this.store.getState().dragOperation.sourceId; | ||
} | ||
getTargetIds() { | ||
}; | ||
DragDropMonitorImpl.prototype.getTargetIds = function () { | ||
return this.store.getState().dragOperation.targetIds; | ||
} | ||
getDropResult() { | ||
}; | ||
DragDropMonitorImpl.prototype.getDropResult = function () { | ||
return this.store.getState().dragOperation.dropResult; | ||
} | ||
didDrop() { | ||
}; | ||
DragDropMonitorImpl.prototype.didDrop = function () { | ||
return this.store.getState().dragOperation.didDrop; | ||
} | ||
isSourcePublic() { | ||
}; | ||
DragDropMonitorImpl.prototype.isSourcePublic = function () { | ||
return this.store.getState().dragOperation.isSourcePublic; | ||
} | ||
getInitialClientOffset() { | ||
}; | ||
DragDropMonitorImpl.prototype.getInitialClientOffset = function () { | ||
return this.store.getState().dragOffset.initialClientOffset; | ||
} | ||
getInitialSourceClientOffset() { | ||
}; | ||
DragDropMonitorImpl.prototype.getInitialSourceClientOffset = function () { | ||
return this.store.getState().dragOffset.initialSourceClientOffset; | ||
} | ||
getClientOffset() { | ||
}; | ||
DragDropMonitorImpl.prototype.getClientOffset = function () { | ||
return this.store.getState().dragOffset.clientOffset; | ||
} | ||
getSourceClientOffset() { | ||
}; | ||
DragDropMonitorImpl.prototype.getSourceClientOffset = function () { | ||
return coords_1.getSourceClientOffset(this.store.getState().dragOffset); | ||
} | ||
getDifferenceFromInitialOffset() { | ||
}; | ||
DragDropMonitorImpl.prototype.getDifferenceFromInitialOffset = function () { | ||
return coords_1.getDifferenceFromInitialOffset(this.store.getState().dragOffset); | ||
} | ||
} | ||
}; | ||
return DragDropMonitorImpl; | ||
}()); | ||
exports.default = DragDropMonitorImpl; | ||
//# sourceMappingURL=DragDropMonitorImpl.js.map |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const DragDropManagerImpl_1 = __importDefault(require("./DragDropManagerImpl")); | ||
var DragDropManagerImpl_1 = __importDefault(require("./DragDropManagerImpl")); | ||
function createDragDropManager(backend, context) { | ||
@@ -9,0 +9,0 @@ return new DragDropManagerImpl_1.default(backend, context); |
@@ -6,17 +6,17 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const invariant_1 = __importDefault(require("invariant")); | ||
const asap = require('asap'); | ||
const registry_1 = require("./actions/registry"); | ||
const getNextUniqueId_1 = __importDefault(require("./utils/getNextUniqueId")); | ||
const interfaces_1 = require("./interfaces"); | ||
const contracts_1 = require("./contracts"); | ||
var invariant_1 = __importDefault(require("invariant")); | ||
var asap = require('asap'); | ||
var registry_1 = require("./actions/registry"); | ||
var getNextUniqueId_1 = __importDefault(require("./utils/getNextUniqueId")); | ||
var interfaces_1 = require("./interfaces"); | ||
var contracts_1 = require("./contracts"); | ||
function getNextHandlerId(role) { | ||
const id = getNextUniqueId_1.default().toString(); | ||
var id = getNextUniqueId_1.default().toString(); | ||
switch (role) { | ||
case interfaces_1.HandlerRole.SOURCE: | ||
return `S${id}`; | ||
return "S" + id; | ||
case interfaces_1.HandlerRole.TARGET: | ||
return `T${id}`; | ||
return "T" + id; | ||
default: | ||
throw new Error(`Unknown Handler Role: ${role}`); | ||
throw new Error("Unknown Handler Role: " + role); | ||
} | ||
@@ -31,7 +31,7 @@ } | ||
default: | ||
invariant_1.default(false, `Cannot parse handler ID: ${handlerId}`); | ||
invariant_1.default(false, "Cannot parse handler ID: " + handlerId); | ||
} | ||
} | ||
class HandlerRegistryImpl { | ||
constructor(store) { | ||
var HandlerRegistryImpl = /** @class */ (function () { | ||
function HandlerRegistryImpl(store) { | ||
this.store = store; | ||
@@ -44,75 +44,79 @@ this.types = {}; | ||
} | ||
addSource(type, source) { | ||
HandlerRegistryImpl.prototype.addSource = function (type, source) { | ||
contracts_1.validateType(type); | ||
contracts_1.validateSourceContract(source); | ||
const sourceId = this.addHandler(interfaces_1.HandlerRole.SOURCE, type, source); | ||
var sourceId = this.addHandler(interfaces_1.HandlerRole.SOURCE, type, source); | ||
this.store.dispatch(registry_1.addSource(sourceId)); | ||
return sourceId; | ||
} | ||
addTarget(type, target) { | ||
}; | ||
HandlerRegistryImpl.prototype.addTarget = function (type, target) { | ||
contracts_1.validateType(type, true); | ||
contracts_1.validateTargetContract(target); | ||
const targetId = this.addHandler(interfaces_1.HandlerRole.TARGET, type, target); | ||
var targetId = this.addHandler(interfaces_1.HandlerRole.TARGET, type, target); | ||
this.store.dispatch(registry_1.addTarget(targetId)); | ||
return targetId; | ||
} | ||
containsHandler(handler) { | ||
return (Object.keys(this.dragSources).some(key => this.dragSources[key] === handler) || | ||
Object.keys(this.dropTargets).some(key => this.dropTargets[key] === handler)); | ||
} | ||
getSource(sourceId, includePinned = false) { | ||
}; | ||
HandlerRegistryImpl.prototype.containsHandler = function (handler) { | ||
var _this = this; | ||
return (Object.keys(this.dragSources).some(function (key) { return _this.dragSources[key] === handler; }) || | ||
Object.keys(this.dropTargets).some(function (key) { return _this.dropTargets[key] === handler; })); | ||
}; | ||
HandlerRegistryImpl.prototype.getSource = function (sourceId, includePinned) { | ||
if (includePinned === void 0) { includePinned = false; } | ||
invariant_1.default(this.isSourceId(sourceId), 'Expected a valid source ID.'); | ||
const isPinned = includePinned && sourceId === this.pinnedSourceId; | ||
const source = isPinned ? this.pinnedSource : this.dragSources[sourceId]; | ||
var isPinned = includePinned && sourceId === this.pinnedSourceId; | ||
var source = isPinned ? this.pinnedSource : this.dragSources[sourceId]; | ||
return source; | ||
} | ||
getTarget(targetId) { | ||
}; | ||
HandlerRegistryImpl.prototype.getTarget = function (targetId) { | ||
invariant_1.default(this.isTargetId(targetId), 'Expected a valid target ID.'); | ||
return this.dropTargets[targetId]; | ||
} | ||
getSourceType(sourceId) { | ||
}; | ||
HandlerRegistryImpl.prototype.getSourceType = function (sourceId) { | ||
invariant_1.default(this.isSourceId(sourceId), 'Expected a valid source ID.'); | ||
return this.types[sourceId]; | ||
} | ||
getTargetType(targetId) { | ||
}; | ||
HandlerRegistryImpl.prototype.getTargetType = function (targetId) { | ||
invariant_1.default(this.isTargetId(targetId), 'Expected a valid target ID.'); | ||
return this.types[targetId]; | ||
} | ||
isSourceId(handlerId) { | ||
const role = parseRoleFromHandlerId(handlerId); | ||
}; | ||
HandlerRegistryImpl.prototype.isSourceId = function (handlerId) { | ||
var role = parseRoleFromHandlerId(handlerId); | ||
return role === interfaces_1.HandlerRole.SOURCE; | ||
} | ||
isTargetId(handlerId) { | ||
const role = parseRoleFromHandlerId(handlerId); | ||
}; | ||
HandlerRegistryImpl.prototype.isTargetId = function (handlerId) { | ||
var role = parseRoleFromHandlerId(handlerId); | ||
return role === interfaces_1.HandlerRole.TARGET; | ||
} | ||
removeSource(sourceId) { | ||
}; | ||
HandlerRegistryImpl.prototype.removeSource = function (sourceId) { | ||
var _this = this; | ||
invariant_1.default(this.getSource(sourceId), 'Expected an existing source.'); | ||
this.store.dispatch(registry_1.removeSource(sourceId)); | ||
asap(() => { | ||
delete this.dragSources[sourceId]; | ||
delete this.types[sourceId]; | ||
asap(function () { | ||
delete _this.dragSources[sourceId]; | ||
delete _this.types[sourceId]; | ||
}); | ||
} | ||
removeTarget(targetId) { | ||
}; | ||
HandlerRegistryImpl.prototype.removeTarget = function (targetId) { | ||
var _this = this; | ||
invariant_1.default(this.getTarget(targetId), 'Expected an existing target.'); | ||
this.store.dispatch(registry_1.removeTarget(targetId)); | ||
asap(() => { | ||
delete this.dropTargets[targetId]; | ||
delete this.types[targetId]; | ||
asap(function () { | ||
delete _this.dropTargets[targetId]; | ||
delete _this.types[targetId]; | ||
}); | ||
} | ||
pinSource(sourceId) { | ||
const source = this.getSource(sourceId); | ||
}; | ||
HandlerRegistryImpl.prototype.pinSource = function (sourceId) { | ||
var source = this.getSource(sourceId); | ||
invariant_1.default(source, 'Expected an existing source.'); | ||
this.pinnedSourceId = sourceId; | ||
this.pinnedSource = source; | ||
} | ||
unpinSource() { | ||
}; | ||
HandlerRegistryImpl.prototype.unpinSource = function () { | ||
invariant_1.default(this.pinnedSource, 'No source is pinned at the time.'); | ||
this.pinnedSourceId = null; | ||
this.pinnedSource = null; | ||
} | ||
addHandler(role, type, handler) { | ||
const id = getNextHandlerId(role); | ||
}; | ||
HandlerRegistryImpl.prototype.addHandler = function (role, type, handler) { | ||
var id = getNextHandlerId(role); | ||
this.types[id] = type; | ||
@@ -126,5 +130,6 @@ if (role === interfaces_1.HandlerRole.SOURCE) { | ||
return id; | ||
} | ||
} | ||
}; | ||
return HandlerRegistryImpl; | ||
}()); | ||
exports.default = HandlerRegistryImpl; | ||
//# sourceMappingURL=HandlerRegistryImpl.js.map |
@@ -6,8 +6,9 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const xor_1 = __importDefault(require("lodash/xor")); | ||
const dragDrop_1 = require("../actions/dragDrop"); | ||
const registry_1 = require("../actions/registry"); | ||
const equality_1 = require("../utils/equality"); | ||
const dirtiness_1 = require("../utils/dirtiness"); | ||
function dirtyHandlerIds(state = dirtiness_1.NONE, action) { | ||
var xor_1 = __importDefault(require("lodash/xor")); | ||
var dragDrop_1 = require("../actions/dragDrop"); | ||
var registry_1 = require("../actions/registry"); | ||
var equality_1 = require("../utils/equality"); | ||
var dirtiness_1 = require("../utils/dirtiness"); | ||
function dirtyHandlerIds(state, action) { | ||
if (state === void 0) { state = dirtiness_1.NONE; } | ||
switch (action.type) { | ||
@@ -28,5 +29,5 @@ case dragDrop_1.HOVER: | ||
} | ||
const { targetIds = [], prevTargetIds = [] } = action.payload; | ||
const result = xor_1.default(targetIds, prevTargetIds); | ||
const didChange = result.length > 0 || !equality_1.areArraysEqual(targetIds, prevTargetIds); | ||
var _a = action.payload, _b = _a.targetIds, targetIds = _b === void 0 ? [] : _b, _c = _a.prevTargetIds, prevTargetIds = _c === void 0 ? [] : _c; | ||
var result = xor_1.default(targetIds, prevTargetIds); | ||
var didChange = result.length > 0 || !equality_1.areArraysEqual(targetIds, prevTargetIds); | ||
if (!didChange) { | ||
@@ -37,4 +38,4 @@ return dirtiness_1.NONE; | ||
// to the result | ||
const prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1]; | ||
const innermostTargetId = targetIds[targetIds.length - 1]; | ||
var prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1]; | ||
var innermostTargetId = targetIds[targetIds.length - 1]; | ||
if (prevInnermostTargetId !== innermostTargetId) { | ||
@@ -41,0 +42,0 @@ if (prevInnermostTargetId) { |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const dragDrop_1 = require("../actions/dragDrop"); | ||
const equality_1 = require("../utils/equality"); | ||
const initialState = { | ||
var dragDrop_1 = require("../actions/dragDrop"); | ||
var equality_1 = require("../utils/equality"); | ||
var initialState = { | ||
initialSourceClientOffset: null, | ||
@@ -10,4 +18,5 @@ initialClientOffset: null, | ||
}; | ||
function dragOffset(state = initialState, action) { | ||
const { payload } = action; | ||
function dragOffset(state, action) { | ||
if (state === void 0) { state = initialState; } | ||
var payload = action.payload; | ||
switch (action.type) { | ||
@@ -24,3 +33,3 @@ case dragDrop_1.BEGIN_DRAG: | ||
} | ||
return Object.assign({}, state, { clientOffset: payload.clientOffset }); | ||
return __assign({}, state, { clientOffset: payload.clientOffset }); | ||
case dragDrop_1.END_DRAG: | ||
@@ -27,0 +36,0 @@ case dragDrop_1.DROP: |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,6 +14,6 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const without_1 = __importDefault(require("lodash/without")); | ||
const dragDrop_1 = require("../actions/dragDrop"); | ||
const registry_1 = require("../actions/registry"); | ||
const initialState = { | ||
var without_1 = __importDefault(require("lodash/without")); | ||
var dragDrop_1 = require("../actions/dragDrop"); | ||
var registry_1 = require("../actions/registry"); | ||
var initialState = { | ||
itemType: null, | ||
@@ -19,11 +27,12 @@ item: null, | ||
}; | ||
function dragOperation(state = initialState, action) { | ||
const { payload } = action; | ||
function dragOperation(state, action) { | ||
if (state === void 0) { state = initialState; } | ||
var payload = action.payload; | ||
switch (action.type) { | ||
case dragDrop_1.BEGIN_DRAG: | ||
return Object.assign({}, state, { itemType: payload.itemType, item: payload.item, sourceId: payload.sourceId, isSourcePublic: payload.isSourcePublic, dropResult: null, didDrop: false }); | ||
return __assign({}, state, { itemType: payload.itemType, item: payload.item, sourceId: payload.sourceId, isSourcePublic: payload.isSourcePublic, dropResult: null, didDrop: false }); | ||
case dragDrop_1.PUBLISH_DRAG_SOURCE: | ||
return Object.assign({}, state, { isSourcePublic: true }); | ||
return __assign({}, state, { isSourcePublic: true }); | ||
case dragDrop_1.HOVER: | ||
return Object.assign({}, state, { targetIds: payload.targetIds }); | ||
return __assign({}, state, { targetIds: payload.targetIds }); | ||
case registry_1.REMOVE_TARGET: | ||
@@ -33,7 +42,7 @@ if (state.targetIds.indexOf(payload.targetId) === -1) { | ||
} | ||
return Object.assign({}, state, { targetIds: without_1.default(state.targetIds, payload.targetId) }); | ||
return __assign({}, state, { targetIds: without_1.default(state.targetIds, payload.targetId) }); | ||
case dragDrop_1.DROP: | ||
return Object.assign({}, state, { dropResult: payload.dropResult, didDrop: true, targetIds: [] }); | ||
return __assign({}, state, { dropResult: payload.dropResult, didDrop: true, targetIds: [] }); | ||
case dragDrop_1.END_DRAG: | ||
return Object.assign({}, state, { itemType: null, item: null, sourceId: null, dropResult: null, didDrop: false, isSourcePublic: null, targetIds: [] }); | ||
return __assign({}, state, { itemType: null, item: null, sourceId: null, dropResult: null, didDrop: false, isSourcePublic: null, targetIds: [] }); | ||
default: | ||
@@ -40,0 +49,0 @@ return state; |
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -6,13 +14,14 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const get_1 = __importDefault(require("lodash/get")); | ||
const dragOffset_1 = __importDefault(require("./dragOffset")); | ||
const dragOperation_1 = __importDefault(require("./dragOperation")); | ||
const refCount_1 = __importDefault(require("./refCount")); | ||
const dirtyHandlerIds_1 = __importDefault(require("./dirtyHandlerIds")); | ||
const stateId_1 = __importDefault(require("./stateId")); | ||
function reduce(state = {}, action) { | ||
var get_1 = __importDefault(require("lodash/get")); | ||
var dragOffset_1 = __importDefault(require("./dragOffset")); | ||
var dragOperation_1 = __importDefault(require("./dragOperation")); | ||
var refCount_1 = __importDefault(require("./refCount")); | ||
var dirtyHandlerIds_1 = __importDefault(require("./dirtyHandlerIds")); | ||
var stateId_1 = __importDefault(require("./stateId")); | ||
function reduce(state, action) { | ||
if (state === void 0) { state = {}; } | ||
return { | ||
dirtyHandlerIds: dirtyHandlerIds_1.default(state.dirtyHandlerIds, { | ||
type: action.type, | ||
payload: Object.assign({}, action.payload, { prevTargetIds: get_1.default(state, 'dragOperation.targetIds', []) }), | ||
payload: __assign({}, action.payload, { prevTargetIds: get_1.default(state, 'dragOperation.targetIds', []) }), | ||
}), | ||
@@ -19,0 +28,0 @@ dragOffset: dragOffset_1.default(state.dragOffset, action), |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const registry_1 = require("../actions/registry"); | ||
function refCount(state = 0, action) { | ||
var registry_1 = require("../actions/registry"); | ||
function refCount(state, action) { | ||
if (state === void 0) { state = 0; } | ||
switch (action.type) { | ||
@@ -6,0 +7,0 @@ case registry_1.ADD_SOURCE: |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function stateId(state = 0) { | ||
function stateId(state) { | ||
if (state === void 0) { state = 0; } | ||
return state + 1; | ||
@@ -5,0 +6,0 @@ } |
@@ -36,3 +36,3 @@ "use strict"; | ||
function getSourceClientOffset(state) { | ||
const { clientOffset, initialClientOffset, initialSourceClientOffset } = state; | ||
var clientOffset = state.clientOffset, initialClientOffset = state.initialClientOffset, initialSourceClientOffset = state.initialSourceClientOffset; | ||
if (!clientOffset || !initialClientOffset || !initialSourceClientOffset) { | ||
@@ -50,3 +50,3 @@ return null; | ||
function getDifferenceFromInitialOffset(state) { | ||
const { clientOffset, initialClientOffset } = state; | ||
var clientOffset = state.clientOffset, initialClientOffset = state.initialClientOffset; | ||
if (!clientOffset || !initialClientOffset) { | ||
@@ -53,0 +53,0 @@ return null; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const intersection_1 = __importDefault(require("lodash/intersection")); | ||
var intersection_1 = __importDefault(require("lodash/intersection")); | ||
exports.NONE = []; | ||
@@ -9,0 +9,0 @@ exports.ALL = []; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.strictEquality = (a, b) => a === b; | ||
exports.strictEquality = function (a, b) { return a === b; }; | ||
/** | ||
@@ -26,7 +26,8 @@ * Determine if two cartesian coordinate offsets are equal | ||
*/ | ||
function areArraysEqual(a, b, isEqual = exports.strictEquality) { | ||
function areArraysEqual(a, b, isEqual) { | ||
if (isEqual === void 0) { isEqual = exports.strictEquality; } | ||
if (a.length !== b.length) { | ||
return false; | ||
} | ||
for (let i = 0; i < a.length; ++i) { | ||
for (var i = 0; i < a.length; ++i) { | ||
if (!isEqual(a[i], b[i])) { | ||
@@ -33,0 +34,0 @@ return false; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
let nextUniqueId = 0; | ||
var nextUniqueId = 0; | ||
function getNextUniqueId() { | ||
@@ -5,0 +5,0 @@ return nextUniqueId++; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const isArray_1 = __importDefault(require("lodash/isArray")); | ||
var isArray_1 = __importDefault(require("lodash/isArray")); | ||
function matchesType(targetType, draggedItemType) { | ||
@@ -13,3 +13,3 @@ if (draggedItemType === null) { | ||
return isArray_1.default(targetType) | ||
? targetType.some(t => t === draggedItemType) | ||
? targetType.some(function (t) { return t === draggedItemType; }) | ||
: targetType === draggedItemType; | ||
@@ -16,0 +16,0 @@ } |
{ | ||
"name": "dnd-core", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Drag and drop sans the GUI", | ||
@@ -5,0 +5,0 @@ "license": "BSD-3-Clause", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
205767
4596
0