Comparing version 0.5.5 to 0.6.0
@@ -628,2 +628,56 @@ "use strict"; | ||
it("does not call hover() outside drag operation", function () { | ||
var source = new NormalSource(); | ||
var sourceHandle = registry.addSource(Types.FOO, source); | ||
var target = new NormalTarget(); | ||
var targetHandle = registry.addTarget(Types.FOO, target); | ||
backend.simulateHover([targetHandle]); | ||
expect(target.didCallHover).to.equal(false); | ||
backend.simulateBeginDrag(sourceHandle); | ||
backend.simulateHover([targetHandle]); | ||
expect(target.didCallHover).to.equal(true); | ||
target.didCallHover = false; | ||
backend.simulateHover([targetHandle]); | ||
expect(target.didCallHover).to.equal(true); | ||
target.didCallHover = false; | ||
backend.simulateEndDrag(); | ||
backend.simulateHover([targetHandle]); | ||
expect(target.didCallHover).to.equal(false); | ||
}); | ||
it("excludes targets of different type when dispatching hover", function () { | ||
var source = new NormalSource(); | ||
var sourceHandle = registry.addSource(Types.FOO, source); | ||
var targetA = new NormalTarget(); | ||
var targetAHandle = registry.addTarget(Types.FOO, targetA); | ||
var targetB = new NormalTarget(); | ||
var targetBHandle = registry.addTarget(Types.BAR, targetB); | ||
var targetC = new NormalTarget(); | ||
var targetCHandle = registry.addTarget(Types.FOO, targetC); | ||
backend.simulateBeginDrag(sourceHandle); | ||
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle]); | ||
expect(targetA.didCallHover).to.equal(true); | ||
expect(targetB.didCallHover).to.equal(false); | ||
expect(targetC.didCallHover).to.equal(true); | ||
}); | ||
it("includes non-droppable targets when dispatching hover", function () { | ||
var source = new NormalSource(); | ||
var sourceHandle = registry.addSource(Types.FOO, source); | ||
var targetA = new TargetWithNoDropResult(); | ||
var targetAHandle = registry.addTarget(Types.FOO, targetA); | ||
var targetB = new TargetWithNoDropResult(); | ||
var targetBHandle = registry.addTarget(Types.FOO, targetB); | ||
backend.simulateBeginDrag(sourceHandle); | ||
backend.simulateHover([targetAHandle, targetBHandle]); | ||
expect(targetA.didCallHover).to.equal(true); | ||
expect(targetB.didCallHover).to.equal(true); | ||
}); | ||
it("throws in hover() if it contains the same target twice", function () { | ||
@@ -630,0 +684,0 @@ var source = new NormalSource(); |
@@ -58,2 +58,47 @@ "use strict"; | ||
}); | ||
it("does not raise change event if hover targets have not changed", function () { | ||
var source = new NormalSource(); | ||
var sourceHandle = registry.addSource(Types.FOO, source); | ||
var targetA = new NormalTarget({ a: 123 }); | ||
var targetAHandle = registry.addTarget(Types.FOO, targetA); | ||
var targetB = new TargetWithNoDropResult(); | ||
var targetBHandle = registry.addTarget(Types.FOO, targetB); | ||
var raisedChange = false; | ||
function setRaisedChange() { | ||
raisedChange = true; | ||
} | ||
monitor.addChangeListener(setRaisedChange); | ||
backend.simulateBeginDrag(sourceHandle); | ||
expect(raisedChange).to.equal(true); | ||
raisedChange = false; | ||
backend.simulateHover([targetAHandle]); | ||
expect(raisedChange).to.equal(true); | ||
raisedChange = false; | ||
backend.simulateHover([targetBHandle]); | ||
expect(raisedChange).to.equal(true); | ||
raisedChange = false; | ||
backend.simulateHover([targetBHandle]); | ||
expect(raisedChange).to.equal(false); | ||
backend.simulateHover([targetBHandle, targetAHandle]); | ||
expect(raisedChange).to.equal(true); | ||
raisedChange = false; | ||
backend.simulateHover([targetBHandle, targetAHandle]); | ||
expect(raisedChange).to.equal(false); | ||
backend.simulateHover([targetAHandle, targetBHandle]); | ||
expect(raisedChange).to.equal(true); | ||
raisedChange = false; | ||
backend.simulateHover([targetAHandle, targetBHandle]); | ||
expect(raisedChange).to.equal(false); | ||
}); | ||
}); | ||
@@ -371,3 +416,3 @@ | ||
var targetC = new NormalTarget(); | ||
var targetCHandle = registry.addTarget(Types.BAR, targetC); | ||
var targetCHandle = registry.addTarget(Types.FOO, targetC); | ||
@@ -458,2 +503,96 @@ var handles = monitor.getTargetHandles(); | ||
it("counts non-droppable targets, but skips targets of another type", function () { | ||
var source = new NormalSource(); | ||
var sourceHandle = registry.addSource(Types.FOO, source); | ||
var targetA = new NormalTarget(); | ||
var targetAHandle = registry.addTarget(Types.FOO, targetA); | ||
var targetB = new NonDroppableTarget(); | ||
var targetBHandle = registry.addTarget(Types.FOO, targetB); | ||
var targetC = new NormalTarget(); | ||
var targetCHandle = registry.addTarget(Types.BAR, targetC); | ||
var handles = monitor.getTargetHandles(); | ||
expect(handles.length).to.be(0); | ||
backend.simulateHover([targetAHandle]); | ||
handles = monitor.getTargetHandles(); | ||
expect(handles.length).to.be(1); | ||
expect(handles[0]).to.equal(targetAHandle); | ||
expect(monitor.isOver(targetAHandle)).to.equal(false); | ||
expect(monitor.isOver(targetAHandle, true)).to.equal(false); | ||
expect(monitor.isOver(targetBHandle)).to.equal(false); | ||
expect(monitor.isOver(targetBHandle, true)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle, true)).to.equal(false); | ||
backend.simulateBeginDrag(sourceHandle); | ||
handles = monitor.getTargetHandles(); | ||
expect(handles.length).to.be(1); | ||
expect(handles[0]).to.equal(targetAHandle); | ||
expect(monitor.isOver(targetAHandle)).to.equal(true); | ||
expect(monitor.isOver(targetAHandle, true)).to.equal(true); | ||
expect(monitor.isOver(targetBHandle)).to.equal(false); | ||
expect(monitor.isOver(targetBHandle, true)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle, true)).to.equal(false); | ||
backend.simulateHover([]); | ||
handles = monitor.getTargetHandles(); | ||
expect(handles.length).to.be(0); | ||
expect(monitor.isOver(targetAHandle)).to.equal(false); | ||
expect(monitor.isOver(targetAHandle, true)).to.equal(false); | ||
expect(monitor.isOver(targetBHandle)).to.equal(false); | ||
expect(monitor.isOver(targetBHandle, true)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle, true)).to.equal(false); | ||
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle]); | ||
handles = monitor.getTargetHandles(); | ||
expect(handles.length).to.be(3); | ||
expect(handles[0]).to.equal(targetAHandle); | ||
expect(monitor.isOver(targetAHandle)).to.equal(true); | ||
expect(monitor.isOver(targetAHandle, true)).to.equal(false); | ||
expect(handles[1]).to.equal(targetBHandle); | ||
expect(monitor.isOver(targetBHandle)).to.equal(true); | ||
expect(monitor.isOver(targetBHandle, true)).to.equal(false); | ||
expect(handles[2]).to.equal(targetCHandle); | ||
expect(monitor.isOver(targetCHandle)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle, true)).to.equal(false); | ||
backend.simulateHover([targetCHandle, targetBHandle, targetAHandle]); | ||
handles = monitor.getTargetHandles(); | ||
expect(handles.length).to.be(3); | ||
expect(handles[0]).to.equal(targetCHandle); | ||
expect(monitor.isOver(targetCHandle)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle, true)).to.equal(false); | ||
expect(handles[1]).to.equal(targetBHandle); | ||
expect(monitor.isOver(targetBHandle)).to.equal(true); | ||
expect(monitor.isOver(targetBHandle, true)).to.equal(false); | ||
expect(handles[2]).to.equal(targetAHandle); | ||
expect(monitor.isOver(targetAHandle)).to.equal(true); | ||
expect(monitor.isOver(targetAHandle, true)).to.equal(true); | ||
backend.simulateHover([targetBHandle]); | ||
backend.simulateDrop(); | ||
handles = monitor.getTargetHandles(); | ||
expect(handles[0]).to.equal(targetBHandle); | ||
expect(handles.length).to.be(1); | ||
expect(monitor.isOver(targetAHandle)).to.equal(false); | ||
expect(monitor.isOver(targetAHandle, true)).to.equal(false); | ||
expect(monitor.isOver(targetBHandle)).to.equal(true); | ||
expect(monitor.isOver(targetBHandle, true)).to.equal(true); | ||
expect(monitor.isOver(targetCHandle)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle, true)).to.equal(false); | ||
backend.simulateEndDrag(); | ||
expect(handles[0]).to.equal(targetBHandle); | ||
expect(handles.length).to.be(1); | ||
expect(monitor.isOver(targetAHandle)).to.equal(false); | ||
expect(monitor.isOver(targetAHandle, true)).to.equal(false); | ||
expect(monitor.isOver(targetBHandle)).to.equal(false); | ||
expect(monitor.isOver(targetBHandle, true)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle)).to.equal(false); | ||
expect(monitor.isOver(targetCHandle, true)).to.equal(false); | ||
}); | ||
it("does not reset target handles on drop() and endDrag()", function () { | ||
@@ -488,3 +627,3 @@ var source = new NormalSource(); | ||
it("does not let array mutation to corrupt internal state", function () { | ||
it("does not let array mutation corrupt internal state", function () { | ||
var source = new NormalSource(); | ||
@@ -491,0 +630,0 @@ var sourceHandle = registry.addSource(Types.FOO, source); |
@@ -14,2 +14,3 @@ "use strict"; | ||
this.didCallDrop = false; | ||
this.didCallHover = false; | ||
this.dropResult = dropResult || { foo: "bar" }; | ||
@@ -20,2 +21,6 @@ } | ||
NormalTarget.prototype.hover = function hover() { | ||
this.didCallHover = true; | ||
}; | ||
NormalTarget.prototype.drop = function drop() { | ||
@@ -34,2 +39,3 @@ this.didCallDrop = true; | ||
this.didCallDrop = false; | ||
this.didCallHover = false; | ||
} | ||
@@ -43,2 +49,6 @@ | ||
NonDroppableTarget.prototype.hover = function hover() { | ||
this.didCallHover = true; | ||
}; | ||
NonDroppableTarget.prototype.drop = function drop() { | ||
@@ -56,2 +66,3 @@ this.didCallDrop = true; | ||
this.didCallDrop = false; | ||
this.didCallHover = false; | ||
} | ||
@@ -61,2 +72,6 @@ | ||
TargetWithNoDropResult.prototype.hover = function hover() { | ||
this.didCallHover = true; | ||
}; | ||
TargetWithNoDropResult.prototype.drop = function drop() { | ||
@@ -93,2 +108,3 @@ this.didCallDrop = true; | ||
this.didCallDrop = false; | ||
this.didCallHover = false; | ||
} | ||
@@ -98,2 +114,6 @@ | ||
TransformResultTarget.prototype.hover = function hover() { | ||
this.didCallHover = true; | ||
}; | ||
TransformResultTarget.prototype.drop = function drop(monitor) { | ||
@@ -100,0 +120,0 @@ this.didCallDrop = true; |
@@ -60,8 +60,34 @@ "use strict"; | ||
var monitor = this.manager.getMonitor(); | ||
var registry = this.manager.getRegistry(); | ||
var draggedItemType = monitor.getItemType(); | ||
var prevTargetHandles = monitor.getTargetHandles(); | ||
var didChange = false; | ||
if (prevTargetHandles.length !== targetHandles.length) { | ||
didChange = true; | ||
} | ||
for (var i = 0; i < targetHandles.length; i++) { | ||
invariant(targetHandles.lastIndexOf(targetHandles[i]) === i, "Target handles should be unique in the passed array."); | ||
invariant(registry.getTarget(targetHandles[i]), "All hovered target handles must be registered."); | ||
var targetHandle = targetHandles[i]; | ||
invariant(targetHandles.lastIndexOf(targetHandle) === i, "Target handles should be unique in the passed array."); | ||
var target = registry.getTarget(targetHandle); | ||
invariant(target, "All hovered target handles must be registered."); | ||
var targetType = registry.getTargetType(targetHandle); | ||
if (targetType === draggedItemType) { | ||
target.hover(monitor, targetHandle); | ||
} | ||
if (!didChange && targetHandle !== prevTargetHandles[i]) { | ||
didChange = true; | ||
} | ||
} | ||
if (!didChange) { | ||
return; | ||
} | ||
return { targetHandles: targetHandles }; | ||
@@ -68,0 +94,0 @@ }; |
@@ -29,8 +29,8 @@ "use strict"; | ||
DragDropMonitor.prototype.addChangeListener = function addChangeListener(listener, context) { | ||
this.dragOperationStore.addListener("change", listener, context); | ||
DragDropMonitor.prototype.addChangeListener = function addChangeListener(listener) { | ||
this.dragOperationStore.addListener("change", listener); | ||
}; | ||
DragDropMonitor.prototype.removeChangeListener = function removeChangeListener(listener, context) { | ||
this.dragOperationStore.removeListener("change", listener, context); | ||
DragDropMonitor.prototype.removeChangeListener = function removeChangeListener(listener) { | ||
this.dragOperationStore.removeListener("change", listener); | ||
}; | ||
@@ -93,2 +93,8 @@ | ||
var targetType = this.registry.getTargetType(targetHandle); | ||
var draggedItemType = this.getItemType(); | ||
if (draggedItemType !== targetType) { | ||
return false; | ||
} | ||
var targetHandles = this.getTargetHandles(); | ||
@@ -95,0 +101,0 @@ if (!targetHandles.length) { |
@@ -14,2 +14,4 @@ "use strict"; | ||
DropTarget.prototype.hover = function hover() {}; | ||
DropTarget.prototype.drop = function drop() {}; | ||
@@ -16,0 +18,0 @@ |
@@ -60,2 +60,4 @@ "use strict"; | ||
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."); | ||
@@ -62,0 +64,0 @@ } |
{ | ||
"name": "dnd-core", | ||
"version": "0.5.5", | ||
"version": "0.6.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
225997
2501