Comparing version 0.8.0 to 0.9.0
@@ -127,29 +127,2 @@ 'use strict'; | ||
it('throws on adding the same source twice', function () { | ||
var source = new _NormalSource$NonDraggableSource$BadItemSource.NormalSource(); | ||
registry.addSource(_Types2['default'].FOO, source); | ||
_expect2['default'](function () { | ||
return registry.addSource(_Types2['default'].FOO, source); | ||
}).to.throwError(); | ||
_expect2['default'](function () { | ||
return registry.addSource(_Types2['default'].BAR, source); | ||
}).to.throwError(); | ||
}); | ||
it('throws on adding the same target twice', function () { | ||
var target = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult$BadResultTarget$TransformResultTarget.NormalTarget(); | ||
registry.addTarget(_Types2['default'].FOO, target); | ||
_expect2['default'](function () { | ||
return registry.addTarget(_Types2['default'].FOO, target); | ||
}).to.throwError(); | ||
_expect2['default'](function () { | ||
return registry.addTarget(_Types2['default'].BAR, target); | ||
}).to.throwError(); | ||
_expect2['default'](function () { | ||
return registry.addTarget([_Types2['default'].FOO, _Types2['default'].BAR], target); | ||
}).to.throwError(); | ||
}); | ||
it('calls setup() and teardown() on backend', function () { | ||
@@ -156,0 +129,0 @@ _expect2['default'](backend.didCallSetup).to.equal(undefined); |
@@ -32,14 +32,254 @@ 'use strict'; | ||
describe('change event', function () { | ||
it('raises change event on beginDrag()', function (done) { | ||
describe('change subscription', function () { | ||
it('throws on bad listener', function () { | ||
_expect2['default'](function () { | ||
return monitor.subscribe(function () {}); | ||
}).to.not.throwError(); | ||
_expect2['default'](function () { | ||
return monitor.subscribe(); | ||
}).to.throwError(); | ||
_expect2['default'](function () { | ||
return monitor.subscribe(42); | ||
}).to.throwError(); | ||
_expect2['default'](function () { | ||
return monitor.subscribe('hi'); | ||
}).to.throwError(); | ||
_expect2['default'](function () { | ||
return monitor.subscribe({}); | ||
}).to.throwError(); | ||
}); | ||
it('throws on bad handlerIds', function () { | ||
_expect2['default'](function () { | ||
return monitor.subscribe(function () {}, []); | ||
}).to.not.throwError(); | ||
_expect2['default'](function () { | ||
return monitor.subscribe(function () {}, ['hi']); | ||
}).to.not.throwError(); | ||
_expect2['default'](function () { | ||
return monitor.subscribe(function () {}, {}); | ||
}).to.throwError(); | ||
_expect2['default'](function () { | ||
return monitor.subscribe(function () {}, function () {}); | ||
}).to.throwError(); | ||
_expect2['default'](function () { | ||
return monitor.subscribe(function () {}, 'hi'); | ||
}).to.throwError(); | ||
}); | ||
it('allows to unsubscribe', function () { | ||
var source = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceId = registry.addSource(_Types2['default'].FOO, source); | ||
monitor.addChangeListener(done); | ||
var raisedChange = false; | ||
var unsubscribe = monitor.subscribe(function () { | ||
raisedChange = true; | ||
}); | ||
unsubscribe(); | ||
_expect2['default'](unsubscribe).to.not.throwError(); | ||
backend.simulateBeginDrag([sourceId]); | ||
_expect2['default'](raisedChange).to.equal(false); | ||
}); | ||
it('raises change event on endDrag()', function (done) { | ||
it('raises global change event on beginDrag()', function (done) { | ||
var source = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceId = registry.addSource(_Types2['default'].FOO, source); | ||
monitor.subscribe(done); | ||
backend.simulateBeginDrag([sourceId]); | ||
}); | ||
it('raises local change event on sources and targets in beginDrag()', function () { | ||
var sourceA = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceAId = registry.addSource(_Types2['default'].FOO, sourceA); | ||
var sourceB = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceBId = registry.addSource(_Types2['default'].FOO, sourceB); | ||
var targetA = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetAId = registry.addTarget(_Types2['default'].FOO, targetA); | ||
var raisedChangeForSourceA = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceA = true; | ||
}, [sourceAId]); | ||
var raisedChangeForSourceB = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceB = true; | ||
}, [sourceBId]); | ||
var raisedChangeForSourceAAndB = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceAAndB = true; | ||
}, [sourceAId, sourceBId]); | ||
var raisedChangeForTargetA = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForTargetA = true; | ||
}, [targetAId]); | ||
backend.simulateBeginDrag([sourceAId]); | ||
_expect2['default'](raisedChangeForSourceA).to.equal(true); | ||
_expect2['default'](raisedChangeForSourceB).to.equal(true); | ||
_expect2['default'](raisedChangeForSourceAAndB).to.equal(true); | ||
_expect2['default'](raisedChangeForTargetA).to.equal(true); | ||
}); | ||
it('raises local change event on sources and targets in endDrag()', function () { | ||
var sourceA = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceAId = registry.addSource(_Types2['default'].FOO, sourceA); | ||
var sourceB = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceBId = registry.addSource(_Types2['default'].FOO, sourceB); | ||
var targetA = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetAId = registry.addTarget(_Types2['default'].FOO, targetA); | ||
backend.simulateBeginDrag([sourceAId]); | ||
var raisedChangeForSourceA = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceA = true; | ||
}, [sourceAId]); | ||
var raisedChangeForSourceB = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceB = true; | ||
}, [sourceBId]); | ||
var raisedChangeForSourceAAndB = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceAAndB = true; | ||
}, [sourceAId, sourceBId]); | ||
var raisedChangeForTargetA = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForTargetA = true; | ||
}, [targetAId]); | ||
backend.simulateEndDrag(); | ||
_expect2['default'](raisedChangeForSourceA).to.equal(true); | ||
_expect2['default'](raisedChangeForSourceB).to.equal(true); | ||
_expect2['default'](raisedChangeForSourceAAndB).to.equal(true); | ||
_expect2['default'](raisedChangeForTargetA).to.equal(true); | ||
}); | ||
it('raises local change event on sources and targets in drop()', function () { | ||
var sourceA = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceAId = registry.addSource(_Types2['default'].FOO, sourceA); | ||
var sourceB = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceBId = registry.addSource(_Types2['default'].FOO, sourceB); | ||
var targetA = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetAId = registry.addTarget(_Types2['default'].FOO, targetA); | ||
backend.simulateBeginDrag([sourceAId]); | ||
backend.simulateHover([targetAId]); | ||
var raisedChangeForSourceA = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceA = true; | ||
}, [sourceAId]); | ||
var raisedChangeForSourceB = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceB = true; | ||
}, [sourceBId]); | ||
var raisedChangeForSourceAAndB = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceAAndB = true; | ||
}, [sourceAId, sourceBId]); | ||
var raisedChangeForTargetA = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForTargetA = true; | ||
}, [targetAId]); | ||
backend.simulateDrop(); | ||
_expect2['default'](raisedChangeForSourceA).to.equal(true); | ||
_expect2['default'](raisedChangeForSourceB).to.equal(true); | ||
_expect2['default'](raisedChangeForSourceAAndB).to.equal(true); | ||
_expect2['default'](raisedChangeForTargetA).to.equal(true); | ||
}); | ||
it('raises local change event only on previous and next targets in hover()', function () { | ||
var sourceA = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceAId = registry.addSource(_Types2['default'].FOO, sourceA); | ||
var sourceB = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceBId = registry.addSource(_Types2['default'].FOO, sourceB); | ||
var targetA = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetAId = registry.addTarget(_Types2['default'].FOO, targetA); | ||
var targetB = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetBId = registry.addTarget(_Types2['default'].FOO, targetB); | ||
var targetC = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetCId = registry.addTarget(_Types2['default'].FOO, targetC); | ||
var targetD = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetDId = registry.addTarget(_Types2['default'].FOO, targetD); | ||
var targetE = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetEId = registry.addTarget(_Types2['default'].FOO, targetE); | ||
backend.simulateBeginDrag([sourceAId]); | ||
backend.simulateHover([targetAId, targetBId]); | ||
var raisedChangeForSourceA = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceA = true; | ||
}, [sourceAId]); | ||
var raisedChangeForSourceB = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceB = true; | ||
}, [sourceBId]); | ||
var raisedChangeForTargetA = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForTargetA = true; | ||
}, [targetAId]); | ||
var raisedChangeForTargetB = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForTargetB = true; | ||
}, [targetBId]); | ||
var raisedChangeForTargetC = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForTargetC = true; | ||
}, [targetCId]); | ||
var raisedChangeForTargetD = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForTargetD = true; | ||
}, [targetDId]); | ||
var raisedChangeForTargetE = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForTargetE = true; | ||
}, [targetEId]); | ||
var raisedChangeForSourceBAndTargetC = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceBAndTargetC = true; | ||
}, [sourceBId, targetCId]); | ||
var raisedChangeForSourceBAndTargetE = false; | ||
monitor.subscribe(function () { | ||
raisedChangeForSourceBAndTargetE = true; | ||
}, [sourceBId, targetEId]); | ||
backend.simulateHover([targetDId, targetEId]); | ||
_expect2['default'](raisedChangeForSourceA).to.equal(false); | ||
_expect2['default'](raisedChangeForSourceB).to.equal(false); | ||
_expect2['default'](raisedChangeForTargetA).to.equal(true); | ||
_expect2['default'](raisedChangeForTargetB).to.equal(true); | ||
_expect2['default'](raisedChangeForTargetC).to.equal(false); | ||
_expect2['default'](raisedChangeForTargetD).to.equal(true); | ||
_expect2['default'](raisedChangeForTargetE).to.equal(true); | ||
_expect2['default'](raisedChangeForSourceBAndTargetC).to.equal(false); | ||
_expect2['default'](raisedChangeForSourceBAndTargetE).to.equal(true); | ||
}); | ||
it('raises global change event on endDrag()', function (done) { | ||
var source = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceId = registry.addSource(_Types2['default'].FOO, source); | ||
var target = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
@@ -49,9 +289,22 @@ registry.addTarget(_Types2['default'].FOO, target); | ||
backend.simulateBeginDrag([sourceId]); | ||
monitor.addChangeListener(done); | ||
monitor.subscribe(done); | ||
backend.simulateEndDrag(); | ||
}); | ||
it('does not raise change event if hover targets have not changed', function () { | ||
it('raises global change event on drop()', function (done) { | ||
var source = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceId = registry.addSource(_Types2['default'].FOO, source); | ||
var target = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget(); | ||
var targetId = registry.addTarget(_Types2['default'].FOO, target); | ||
backend.simulateBeginDrag([sourceId]); | ||
backend.simulateHover([targetId]); | ||
monitor.subscribe(done); | ||
backend.simulateDrop(); | ||
}); | ||
it('does not raise global change event if hover targets have not changed', function () { | ||
var source = new _NormalSource$NonDraggableSource$NumberSource.NormalSource(); | ||
var sourceId = registry.addSource(_Types2['default'].FOO, source); | ||
var targetA = new _NormalTarget$NonDroppableTarget$TargetWithNoDropResult.NormalTarget({ a: 123 }); | ||
@@ -63,8 +316,6 @@ var targetAId = registry.addTarget(_Types2['default'].FOO, targetA); | ||
var raisedChange = false; | ||
function setRaisedChange() { | ||
monitor.subscribe(function () { | ||
raisedChange = true; | ||
} | ||
}); | ||
monitor.addChangeListener(setRaisedChange); | ||
backend.simulateBeginDrag([sourceId]); | ||
@@ -71,0 +322,0 @@ _expect2['default'](raisedChange).to.equal(true); |
@@ -17,2 +17,10 @@ 'use strict'; | ||
var _intersection = require('lodash/array/intersection'); | ||
var _intersection2 = _interopRequireWildcard(_intersection); | ||
var _isArray = require('lodash/lang/isArray'); | ||
var _isArray2 = _interopRequireWildcard(_isArray); | ||
var DragDropMonitor = (function () { | ||
@@ -26,8 +34,23 @@ function DragDropMonitor(flux, registry) { | ||
DragDropMonitor.prototype.addChangeListener = function addChangeListener(listener) { | ||
this.dragOperationStore.addListener('change', listener); | ||
}; | ||
DragDropMonitor.prototype.subscribe = function subscribe(listener, handlerIds) { | ||
_invariant2['default'](handlerIds == null || _isArray2['default'](handlerIds), 'handlerIds, if passed, must be an array of strings.'); | ||
_invariant2['default'](typeof listener === 'function', 'listener must be a function.'); | ||
DragDropMonitor.prototype.removeChangeListener = function removeChangeListener(listener) { | ||
this.dragOperationStore.removeListener('change', listener); | ||
var dragOperationStore = this.dragOperationStore; | ||
var handleChange = listener; | ||
if (_isArray2['default'](handlerIds)) { | ||
handleChange = function () { | ||
if (dragOperationStore.areDirty(handlerIds)) { | ||
listener(); | ||
} | ||
}; | ||
} | ||
dragOperationStore.addListener('change', handleChange); | ||
return function dispose() { | ||
dragOperationStore.removeListener('change', handleChange); | ||
}; | ||
}; | ||
@@ -34,0 +57,0 @@ |
@@ -17,2 +17,8 @@ 'use strict'; | ||
var _intersection = require('lodash/array/intersection'); | ||
var _intersection2 = _interopRequireWildcard(_intersection); | ||
var ALL_DIRTY_WILDCARD = { __all__: true }; | ||
var DragOperationStore = (function (_Store) { | ||
@@ -34,2 +40,3 @@ function DragOperationStore(flux) { | ||
this.dirtyHandlerIds = []; | ||
this.state = { | ||
@@ -48,2 +55,9 @@ itemType: null, | ||
DragOperationStore.prototype.setState = function setState(nextState) { | ||
var dirtyHandlerIds = arguments[1] === undefined ? ALL_DIRTY_WILDCARD : arguments[1]; | ||
this.dirtyHandlerIds = dirtyHandlerIds; | ||
_Store.prototype.setState.call(this, nextState); | ||
}; | ||
DragOperationStore.prototype.handleBeginDrag = function handleBeginDrag(_ref) { | ||
@@ -72,3 +86,4 @@ var itemType = _ref.itemType; | ||
this.setState({ targetIds: targetIds }); | ||
var dirtyHandlerIds = targetIds.concat(this.state.targetIds); | ||
this.setState({ targetIds: targetIds }, dirtyHandlerIds); | ||
}; | ||
@@ -80,7 +95,9 @@ | ||
if (targetIds.indexOf(targetId) > -1) { | ||
this.setState({ | ||
targetIds: _without2['default'](targetIds, targetId) | ||
}); | ||
if (targetIds.indexOf(targetId) === -1) { | ||
return; | ||
} | ||
this.setState({ | ||
targetIds: _without2['default'](targetIds, targetId) | ||
}, []); | ||
}; | ||
@@ -140,2 +157,10 @@ | ||
DragOperationStore.prototype.areDirty = function areDirty(handlerIds) { | ||
if (this.dirtyHandlerIds === ALL_DIRTY_WILDCARD) { | ||
return true; | ||
} | ||
return _intersection2['default'](handlerIds, this.dirtyHandlerIds).length > 0; | ||
}; | ||
return DragOperationStore; | ||
@@ -142,0 +167,0 @@ })(_Store2.Store); |
@@ -108,6 +108,2 @@ 'use strict'; | ||
HandlerRegistry.prototype.addHandler = function addHandler(role, type, handler) { | ||
if (process.env.NODE_ENV !== 'production') { | ||
_invariant2['default'](!this.containsHandler(handler), 'Cannot add the same handler instance twice.'); | ||
} | ||
var id = getNextHandlerId(role); | ||
@@ -114,0 +110,0 @@ this.types[id] = type; |
{ | ||
"name": "dnd-core", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"description": "Drag and drop sans the GUI", | ||
@@ -5,0 +5,0 @@ "main": "dist-modules/index.js", |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
261347
46
2908
0