Comparing version 0.12.1 to 0.13.0
@@ -435,2 +435,16 @@ 'use strict'; | ||
it('throws in drop() if called twice', function () { | ||
var source = new _NormalSource$NonDraggableSource$BadItemSource.NormalSource(); | ||
var sourceId = registry.addSource(_Types2['default'].FOO, source); | ||
var target = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult$BadResultTarget$TransformResultTarget.NormalTarget(); | ||
var targetId = registry.addTarget(_Types2['default'].FOO, target); | ||
backend.simulateBeginDrag([sourceId]); | ||
backend.simulateHover([targetId]); | ||
backend.simulateDrop(); | ||
_expect2['default'](function () { | ||
return backend.simulateDrop(); | ||
}).to.throwError(); | ||
}); | ||
describe('nested drop targets', function () { | ||
@@ -596,16 +610,13 @@ it('uses child result if parents have no drop result', function () { | ||
describe('hover()', function () { | ||
it('lets hover() be called any time', function () { | ||
it('throws on hover after drop', function () { | ||
var source = new _NormalSource$NonDraggableSource$BadItemSource.NormalSource(); | ||
var sourceId = registry.addSource(_Types2['default'].FOO, source); | ||
var target = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult$BadResultTarget$TransformResultTarget.NormalTarget(); | ||
var targetId = registry.addTarget(_Types2['default'].BAR, target); | ||
var targetId = registry.addTarget(_Types2['default'].FOO, target); | ||
_expect2['default'](function () { | ||
return backend.simulateHover([targetId]); | ||
}).to.not.throwError(); | ||
}).to.throwError(); | ||
backend.simulateBeginDrag([sourceId]); | ||
_expect2['default'](function () { | ||
return backend.simulateHover([targetId]); | ||
}).to.not.throwError(); | ||
backend.simulateHover([targetId]); | ||
@@ -615,16 +626,6 @@ backend.simulateDrop(); | ||
return backend.simulateHover([targetId]); | ||
}).to.not.throwError(); | ||
backend.simulateEndDrag(); | ||
_expect2['default'](function () { | ||
return backend.simulateHover([targetId]); | ||
}).to.not.throwError(); | ||
backend.simulateBeginDrag([sourceId]); | ||
_expect2['default'](function () { | ||
return backend.simulateHover([targetId]); | ||
}).to.not.throwError(); | ||
}).to.throwError(); | ||
}); | ||
it('does not call hover() outside drag operation', function () { | ||
it('throws on hover outside dragging operation', function () { | ||
var source = new _NormalSource$NonDraggableSource$BadItemSource.NormalSource(); | ||
@@ -635,17 +636,12 @@ var sourceId = registry.addSource(_Types2['default'].FOO, source); | ||
backend.simulateHover([targetId]); | ||
_expect2['default'](target.didCallHover).to.equal(false); | ||
_expect2['default'](function () { | ||
return backend.simulateHover([targetId]); | ||
}).to.throwError(); | ||
backend.simulateBeginDrag([sourceId]); | ||
backend.simulateHover([targetId]); | ||
_expect2['default'](target.didCallHover).to.equal(true); | ||
target.didCallHover = false; | ||
backend.simulateHover([targetId]); | ||
_expect2['default'](target.didCallHover).to.equal(true); | ||
target.didCallHover = false; | ||
backend.simulateEndDrag(); | ||
backend.simulateHover([targetId]); | ||
_expect2['default'](target.didCallHover).to.equal(false); | ||
_expect2['default'](function () { | ||
return backend.simulateHover([targetId]); | ||
}).to.throwError(); | ||
}); | ||
@@ -652,0 +648,0 @@ |
@@ -44,2 +44,5 @@ 'use strict'; | ||
var publishSource = _ref$publishSource === undefined ? true : _ref$publishSource; | ||
var _ref$clientOffset = _ref.clientOffset; | ||
var clientOffset = _ref$clientOffset === undefined ? null : _ref$clientOffset; | ||
var getSourceClientOffset = _ref.getSourceClientOffset; | ||
@@ -67,2 +70,8 @@ _invariant2['default'](_isArray2['default'](sourceIds), 'Expected sourceIds to be an array.'); | ||
var sourceClientOffset = null; | ||
if (clientOffset) { | ||
_invariant2['default'](typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.'); | ||
sourceClientOffset = getSourceClientOffset(sourceId); | ||
} | ||
var source = registry.getSource(sourceId); | ||
@@ -75,3 +84,10 @@ var item = source.beginDrag(monitor, sourceId); | ||
var itemType = registry.getSourceType(sourceId); | ||
return { itemType: itemType, item: item, sourceId: sourceId, isSourcePublic: publishSource }; | ||
return { | ||
itemType: itemType, | ||
item: item, | ||
sourceId: sourceId, | ||
clientOffset: clientOffset, | ||
sourceClientOffset: sourceClientOffset, | ||
isSourcePublic: publishSource | ||
}; | ||
}; | ||
@@ -89,2 +105,7 @@ | ||
DragDropActions.prototype.hover = function hover(targetIds) { | ||
var _ref2 = arguments[1] === undefined ? {} : arguments[1]; | ||
var _ref2$clientOffset = _ref2.clientOffset; | ||
var clientOffset = _ref2$clientOffset === undefined ? null : _ref2$clientOffset; | ||
_invariant2['default'](_isArray2['default'](targetIds), 'Expected targetIds to be an array.'); | ||
@@ -95,11 +116,6 @@ targetIds = targetIds.slice(0); | ||
var registry = this.manager.getRegistry(); | ||
_invariant2['default'](monitor.isDragging(), 'Cannot call hover while not dragging.'); | ||
_invariant2['default'](!monitor.didDrop(), 'Cannot call hover after drop.'); | ||
var draggedItemType = monitor.getItemType(); | ||
var prevTargetIds = monitor.getTargetIds(); | ||
var didChange = false; | ||
if (prevTargetIds.length !== targetIds.length) { | ||
didChange = true; | ||
} | ||
for (var i = 0; i < targetIds.length; i++) { | ||
@@ -116,13 +132,5 @@ var targetId = targetIds[i]; | ||
} | ||
if (!didChange && targetId !== prevTargetIds[i]) { | ||
didChange = true; | ||
} | ||
} | ||
if (!didChange) { | ||
return; | ||
} | ||
return { targetIds: targetIds }; | ||
return { targetIds: targetIds, clientOffset: clientOffset }; | ||
}; | ||
@@ -136,2 +144,3 @@ | ||
_invariant2['default'](monitor.isDragging(), 'Cannot call drop while not dragging.'); | ||
_invariant2['default'](!monitor.didDrop(), 'Cannot call drop twice during one drag operation.'); | ||
@@ -138,0 +147,0 @@ var _getActionIds = this.getActionIds(); |
@@ -23,4 +23,4 @@ "use strict"; | ||
TestBackend.prototype.simulateBeginDrag = function simulateBeginDrag(sourceIds, publishSource) { | ||
this.actions.beginDrag(sourceIds, publishSource); | ||
TestBackend.prototype.simulateBeginDrag = function simulateBeginDrag(sourceIds, options) { | ||
this.actions.beginDrag(sourceIds, options); | ||
}; | ||
@@ -32,4 +32,4 @@ | ||
TestBackend.prototype.simulateHover = function simulateHover(targetIds) { | ||
this.actions.hover(targetIds); | ||
TestBackend.prototype.simulateHover = function simulateHover(targetIds, options) { | ||
this.actions.hover(targetIds, options); | ||
}; | ||
@@ -36,0 +36,0 @@ |
@@ -17,6 +17,2 @@ 'use strict'; | ||
var _intersection = require('lodash/array/intersection'); | ||
var _intersection2 = _interopRequireWildcard(_intersection); | ||
var _isArray = require('lodash/lang/isArray'); | ||
@@ -31,7 +27,12 @@ | ||
this.dragOperationStore = flux.dragOperationStore; | ||
this.dragOffsetStore = flux.dragOffsetStore; | ||
this.registry = registry; | ||
} | ||
DragDropMonitor.prototype.subscribe = function subscribe(listener, handlerIds) { | ||
_invariant2['default'](handlerIds == null || _isArray2['default'](handlerIds), 'handlerIds, if passed, must be an array of strings.'); | ||
DragDropMonitor.prototype.subscribeToStateChange = function subscribeToStateChange(listener) { | ||
var _ref = arguments[1] === undefined ? {} : arguments[1]; | ||
var _ref$handlerIds = _ref.handlerIds; | ||
var handlerIds = _ref$handlerIds === undefined ? null : _ref$handlerIds; | ||
_invariant2['default'](typeof listener === 'function', 'listener must be a function.'); | ||
@@ -42,4 +43,4 @@ | ||
var handleChange = listener; | ||
if (_isArray2['default'](handlerIds)) { | ||
if (handlerIds) { | ||
_invariant2['default'](_isArray2['default'](handlerIds), 'handlerIds, when specified, must be an array of strings.'); | ||
handleChange = function () { | ||
@@ -59,2 +60,14 @@ if (dragOperationStore.areDirty(handlerIds)) { | ||
DragDropMonitor.prototype.subscribeToOffsetChange = function subscribeToOffsetChange(listener) { | ||
_invariant2['default'](typeof listener === 'function', 'listener must be a function.'); | ||
var dragOffsetStore = this.dragOffsetStore; | ||
dragOffsetStore.addListener('change', listener); | ||
return function dispose() { | ||
dragOffsetStore.removeListener('change', listener); | ||
}; | ||
}; | ||
DragDropMonitor.prototype.canDragSource = function canDragSource(sourceId) { | ||
@@ -106,6 +119,6 @@ var source = this.registry.getSource(sourceId); | ||
DragDropMonitor.prototype.isOverTarget = function isOverTarget(targetId) { | ||
var _ref = arguments[1] === undefined ? {} : arguments[1]; | ||
var _ref2 = arguments[1] === undefined ? {} : arguments[1]; | ||
var _ref$shallow = _ref.shallow; | ||
var shallow = _ref$shallow === undefined ? false : _ref$shallow; | ||
var _ref2$shallow = _ref2.shallow; | ||
var shallow = _ref2$shallow === undefined ? false : _ref2$shallow; | ||
@@ -163,2 +176,18 @@ if (!this.isDragging()) { | ||
DragDropMonitor.prototype.getInitialClientOffset = function getInitialClientOffset() { | ||
return this.dragOffsetStore.getInitialClientOffset(); | ||
}; | ||
DragDropMonitor.prototype.getInitialSourceClientOffset = function getInitialSourceClientOffset() { | ||
return this.dragOffsetStore.getInitialSourceClientOffset(); | ||
}; | ||
DragDropMonitor.prototype.getClientOffset = function getClientOffset() { | ||
return this.dragOffsetStore.getClientOffset(); | ||
}; | ||
DragDropMonitor.prototype.getDifferenceFromInitialOffset = function getDifferenceFromInitialOffset() { | ||
return this.dragOffsetStore.getDifferenceFromInitialOffset(); | ||
}; | ||
return DragDropMonitor; | ||
@@ -165,0 +194,0 @@ })(); |
@@ -25,2 +25,6 @@ 'use strict'; | ||
var _DragOffsetStore = require('./stores/DragOffsetStore'); | ||
var _DragOffsetStore2 = _interopRequireWildcard(_DragOffsetStore); | ||
var _RefCountStore = require('./stores/RefCountStore'); | ||
@@ -44,2 +48,4 @@ | ||
this.dragOffsetStore = this.createStore('dragOffsetStore', _DragOffsetStore2['default'], this); | ||
this.refCountStore = this.createStore('refCountStore', _RefCountStore2['default'], this); | ||
@@ -46,0 +52,0 @@ } |
@@ -13,2 +13,6 @@ 'use strict'; | ||
var _xor = require('lodash/array/xor'); | ||
var _xor2 = _interopRequireWildcard(_xor); | ||
var _without = require('lodash/array/without'); | ||
@@ -78,3 +82,5 @@ | ||
DragOperationStore.prototype.handlePublishDragSource = function handlePublishDragSource() { | ||
this.setState({ isSourcePublic: true }); | ||
this.setState({ | ||
isSourcePublic: true | ||
}); | ||
}; | ||
@@ -84,5 +90,23 @@ | ||
var targetIds = _ref2.targetIds; | ||
var prevTargetIds = this.state.targetIds; | ||
var dirtyHandlerIds = targetIds.concat(this.state.targetIds); | ||
this.setState({ targetIds: targetIds }, dirtyHandlerIds); | ||
var dirtyHandlerIds = _xor2['default'](targetIds, prevTargetIds); | ||
var didChange = false; | ||
if (dirtyHandlerIds.length === 0) { | ||
for (var i = 0; i < targetIds.length; i++) { | ||
if (targetIds[i] !== prevTargetIds[i]) { | ||
didChange = true; | ||
break; | ||
} | ||
} | ||
} else { | ||
didChange = true; | ||
} | ||
if (didChange) { | ||
this.setState({ | ||
targetIds: targetIds | ||
}, dirtyHandlerIds); | ||
} | ||
}; | ||
@@ -108,3 +132,4 @@ | ||
dropResult: dropResult, | ||
didDrop: true | ||
didDrop: true, | ||
targetIds: [] | ||
}); | ||
@@ -120,3 +145,4 @@ }; | ||
didDrop: false, | ||
isSourcePublic: null | ||
isSourcePublic: null, | ||
targetIds: [] | ||
}); | ||
@@ -123,0 +149,0 @@ }; |
{ | ||
"name": "dnd-core", | ||
"version": "0.12.1", | ||
"version": "0.13.0", | ||
"description": "Drag and drop sans the GUI", | ||
@@ -5,0 +5,0 @@ "main": "dist-modules/index.js", |
Sorry, the diff of this file is too big to display
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
287380
48
3410