Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dnd-core

Package Overview
Dependencies
Maintainers
1
Versions
93
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dnd-core - npm Package Compare versions

Comparing version 0.4.3 to 0.5.0

.istanbul.yml

238

dist-modules/__tests__/DragDropManager-test.js

@@ -48,3 +48,3 @@ "use strict";

registry.removeSource(sourceHandle);
expect(registry.getSource(sourceHandle)).to.equal(null);
expect(registry.getSource(sourceHandle)).to.equal(undefined);
expect(function () {

@@ -61,3 +61,3 @@ return registry.removeSource(sourceHandle);

registry.removeTarget(targetHandle);
expect(registry.getTarget(targetHandle)).to.equal(null);
expect(registry.getTarget(targetHandle)).to.equal(undefined);
expect(function () {

@@ -74,3 +74,3 @@ return registry.removeTarget(targetHandle);

registry.removeTarget(targetHandle);
expect(registry.getTarget(targetHandle)).to.equal(null);
expect(registry.getTarget(targetHandle)).to.equal(undefined);
expect(function () {

@@ -137,2 +137,29 @@ return registry.removeTarget(targetHandle);

it("throws on adding the same source twice", function () {
var source = new NormalSource();
var sourceHandle = registry.addSource(Types.FOO, source);
expect(function () {
return registry.addSource(Types.FOO, source);
}).to.throwError();
expect(function () {
return registry.addSource(Types.BAR, source);
}).to.throwError();
});
it("throws on adding the same target twice", function () {
var target = new NormalTarget();
var targetHandle = registry.addTarget(Types.FOO, target);
expect(function () {
return registry.addTarget(Types.FOO, target);
}).to.throwError();
expect(function () {
return registry.addTarget(Types.BAR, target);
}).to.throwError();
expect(function () {
return registry.addTarget([Types.FOO, Types.BAR], target);
}).to.throwError();
});
it("calls setup() and teardown() on backend", function () {

@@ -208,2 +235,24 @@ expect(backend.isActive).to.equal(undefined);

it("throws in beginDrag() if it is called with an invalid handle", function () {
var source = new NormalSource();
var sourceHandle = registry.addSource(Types.FOO, source);
var target = new NormalTarget();
var targetHandle = registry.addTarget(Types.FOO, target);
expect(function () {
return backend.simulateBeginDrag(null);
}).to.throwError();
expect(function () {
return backend.simulateBeginDrag("yo");
}).to.throwError();
expect(function () {
return backend.simulateBeginDrag(targetHandle);
}).to.throwError();
registry.removeSource(sourceHandle);
expect(function () {
return backend.simulateBeginDrag(sourceHandle);
}).to.throwError();
});
it("lets beginDrag() be called again in a next operation", function () {

@@ -232,3 +281,3 @@ var source = new NormalSource();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
backend.simulateDrop();

@@ -247,3 +296,3 @@ backend.simulateEndDrag();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
backend.simulateDrop();

@@ -269,3 +318,3 @@ backend.simulateEndDrag();

registry.removeSource(sourceHandle);
expect(registry.getSource(sourceHandle)).to.equal(null);
expect(registry.getSource(sourceHandle)).to.equal(undefined);

@@ -303,6 +352,6 @@ backend.simulateEndDrag();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
backend.simulateLeave(targetBHandle);
backend.simulateLeave(targetAHandle);
backend.simulateHover([targetAHandle]);
backend.simulateHover([targetAHandle, targetBHandle]);
backend.simulateHover([targetAHandle]);
backend.simulateHover([]);
backend.simulateDrop();

@@ -322,3 +371,3 @@ backend.simulateEndDrag();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
backend.simulateDrop();

@@ -335,3 +384,3 @@ expect(target.didCallDrop).to.equal(false);

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
backend.simulateDrop();

@@ -354,3 +403,3 @@ expect(target.didCallDrop).to.equal(false);

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
expect(function () {

@@ -373,5 +422,3 @@ return backend.simulateDrop();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
backend.simulateEnter(targetCHandle);
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle]);
backend.simulateDrop();

@@ -396,5 +443,3 @@ backend.simulateEndDrag();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
backend.simulateEnter(targetCHandle);
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle]);
backend.simulateDrop();

@@ -419,5 +464,3 @@ backend.simulateEndDrag();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
backend.simulateEnter(targetCHandle);
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle]);
backend.simulateDrop();

@@ -456,9 +499,3 @@ backend.simulateEndDrag();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
backend.simulateEnter(targetCHandle);
backend.simulateEnter(targetDHandle);
backend.simulateEnter(targetEHandle);
backend.simulateEnter(targetFHandle);
backend.simulateEnter(targetGHandle);
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle, targetDHandle, targetEHandle, targetFHandle, targetGHandle]);
backend.simulateDrop();

@@ -501,9 +538,3 @@ backend.simulateEndDrag();

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
backend.simulateEnter(targetCHandle);
backend.simulateEnter(targetDHandle);
backend.simulateEnter(targetEHandle);
backend.simulateEnter(targetFHandle);
backend.simulateEnter(targetGHandle);
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle, targetDHandle, targetEHandle, targetFHandle, targetGHandle]);
backend.simulateDrop();

@@ -520,45 +551,154 @@ backend.simulateEndDrag();

});
it("excludes removed targets when dispatching drop", 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.FOO, targetB);
var targetC = new NormalTarget();
var targetCHandle = registry.addTarget(Types.FOO, targetC);
backend.simulateBeginDrag(sourceHandle);
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle]);
registry.removeTarget(targetBHandle);
backend.simulateDrop();
backend.simulateEndDrag();
expect(targetA.didCallDrop).to.equal(true);
expect(targetB.didCallDrop).to.equal(false);
expect(targetC.didCallDrop).to.equal(true);
});
});
});
describe("enter() and leave()", function () {
it("throws in enter() if it is called outside a drag operation", function () {
describe("hover()", function () {
it("lets hover() be called any time", function () {
var source = new NormalSource();
var sourceHandle = registry.addSource(Types.FOO, source);
var target = new NormalTarget();
var targetHandle = registry.addTarget(Types.BAR, target);
expect(function () {
return backend.simulateEnter(targetHandle);
return backend.simulateHover([targetHandle]);
}).to.not.throwError();
backend.simulateBeginDrag(sourceHandle);
expect(function () {
return backend.simulateHover([targetHandle]);
}).to.not.throwError();
backend.simulateDrop();
expect(function () {
return backend.simulateHover([targetHandle]);
}).to.not.throwError();
backend.simulateEndDrag();
expect(function () {
return backend.simulateHover([targetHandle]);
}).to.not.throwError();
backend.simulateBeginDrag(sourceHandle);
expect(function () {
return backend.simulateHover([targetHandle]);
}).to.not.throwError();
});
it("throws in hover() if it contains the same target twice", function () {
var source = new NormalSource();
var sourceHandle = registry.addSource(Types.FOO, source);
var targetA = new NormalTarget();
var targetAHandle = registry.addTarget(Types.BAR, targetA);
var targetB = new NormalTarget();
var targetBHandle = registry.addTarget(Types.BAR, targetB);
backend.simulateBeginDrag(sourceHandle);
expect(function () {
return backend.simulateHover([targetAHandle, targetBHandle, targetAHandle]);
}).to.throwError();
});
it("throws in enter() if it is already in an entered target", function () {
var target = new NormalTarget();
it("throws in hover() if it is called with a non-array", function () {
var source = new NormalSource();
var sourceHandle = registry.addSource(Types.FOO, source);
var target = new NormalTarget();
var targetHandle = registry.addTarget(Types.BAR, target);
backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetHandle);
expect(function () {
return backend.simulateEnter(targetHandle);
return backend.simulateHover(null);
}).to.throwError();
expect(function () {
return backend.simulateHover("yo");
}).to.throwError();
expect(function () {
return backend.simulateHover(targetHandle);
}).to.throwError();
});
it("throws in leave() if it is called outside a drag operation", function () {
it("throws in hover() if it contains an invalid drop target", function () {
var source = new NormalSource();
var sourceHandle = registry.addSource(Types.FOO, source);
var target = new NormalTarget();
var targetHandle = registry.addTarget(Types.BAR, target);
backend.simulateBeginDrag(sourceHandle);
expect(function () {
return backend.simulateLeave(targetHandle);
return backend.simulateHover([targetHandle, null]);
}).to.throwError();
expect(function () {
return backend.simulateHover([targetHandle, "yo"]);
}).to.throwError();
expect(function () {
return backend.simulateHover([targetHandle, sourceHandle]);
}).to.throwError();
});
it("throws in leave() if it is not entered", function () {
var target = new NormalTarget();
it("throws in hover() if it contains a removed drop target", function () {
var source = new NormalSource();
var sourceHandle = registry.addSource(Types.FOO, source);
var targetHandle = registry.addTarget(Types.BAR, target);
var targetA = new NormalTarget();
var targetAHandle = registry.addTarget(Types.BAR, targetA);
var targetB = new NormalTarget();
var targetBHandle = registry.addTarget(Types.FOO, targetB);
backend.simulateBeginDrag(sourceHandle);
expect(function () {
return backend.simulateLeave(targetHandle);
return backend.simulateHover([targetAHandle, targetBHandle]);
}).to.not.throwError();
backend.simulateHover([targetAHandle, targetBHandle]);
registry.removeTarget(targetAHandle);
expect(function () {
return backend.simulateHover([targetBHandle, targetAHandle]);
}).to.throwError();
expect(function () {
return backend.simulateHover([targetAHandle, targetBHandle]);
}).to.throwError();
expect(function () {
return backend.simulateHover([targetBHandle]);
}).to.not.throwError();
backend.simulateHover([targetBHandle]);
registry.removeTarget(targetBHandle);
expect(function () {
return backend.simulateHover([targetBHandle, targetAHandle]);
}).to.throwError();
expect(function () {
return backend.simulateHover([targetBHandle]);
}).to.throwError();
expect(function () {
return backend.simulateHover([targetAHandle]);
}).to.throwError();
targetAHandle = registry.addTarget(Types.FOO, targetA);
expect(function () {
return backend.simulateHover([targetAHandle]);
}).to.not.throwError();
backend.simulateHover([targetAHandle]);
targetBHandle = registry.addTarget(Types.BAR, targetB);
expect(function () {
return backend.simulateHover([targetAHandle, targetBHandle]);
}).to.not.throwError();
});

@@ -565,0 +705,0 @@ });

@@ -84,3 +84,3 @@ "use strict";

backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
backend.simulateDrop();

@@ -128,3 +128,3 @@ expect(monitor.canDrag(sourceAHandle)).to.equal(false);

backend.simulateEnter(targetAHandle);
backend.simulateHover([targetAHandle]);
backend.simulateDrop();

@@ -166,3 +166,3 @@ expect(monitor.canDrop(targetAHandle)).to.equal(false);

backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
backend.simulateDrop();

@@ -201,3 +201,3 @@ expect(monitor.isDragging()).to.equal(true);

backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
backend.simulateDrop();

@@ -235,3 +235,3 @@ expect(monitor.getItem().a).to.equal(123);

backend.simulateEnter(targetAHandle);
backend.simulateHover([targetAHandle]);
backend.simulateDrop();

@@ -249,3 +249,3 @@ expect(monitor.didDrop()).to.equal(true);

backend.simulateEnter(targetBHandle);
backend.simulateHover([targetBHandle]);
backend.simulateDrop();

@@ -283,3 +283,3 @@ expect(monitor.didDrop()).to.equal(true);

backend.simulateEnter(targetAHandle);
backend.simulateHover([targetAHandle]);
backend.simulateDrop();

@@ -303,3 +303,3 @@ expect(monitor.canDrop(targetAHandle)).to.equal(false);

describe("target handle tracking", function () {
it("treats removing an entered drop target midflight as calling leave() on it", function () {
it("treats removing a hovered drop target as unhovering it", function () {
var source = new NormalSource();

@@ -311,3 +311,3 @@ var sourceHandle = registry.addSource(Types.FOO, source);

backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
expect(monitor.getTargetHandles().length).to.be(1);

@@ -323,5 +323,3 @@ expect(monitor.isOver(targetHandle)).to.equal(true);

it("leaves nested drop zones when parent leaves", function () {
var source = new NormalSource();
var sourceHandle = registry.addSource(Types.FOO, source);
it("keeps track of target handles", function () {
var targetA = new NormalTarget();

@@ -333,22 +331,30 @@ var targetAHandle = registry.addTarget(Types.FOO, targetA);

var targetCHandle = registry.addTarget(Types.BAR, targetC);
var targetD = new NormalTarget();
var targetDHandle = registry.addTarget(Types.FOO, targetD);
var handles = undefined;
backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
var handles = monitor.getTargetHandles();
expect(handles.length).to.be(0);
backend.simulateHover([targetAHandle]);
handles = monitor.getTargetHandles();
expect(handles.length).to.be(2);
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(handles[1]).to.equal(targetBHandle);
expect(monitor.isOver(targetBHandle)).to.equal(true);
expect(monitor.isOver(targetBHandle, 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.simulateEnter(targetCHandle);
backend.simulateEnter(targetDHandle);
backend.simulateHover([targetAHandle, targetBHandle, targetCHandle]);
handles = monitor.getTargetHandles();
expect(handles.length).to.be(4);
expect(handles.length).to.be(3);
expect(handles[0]).to.equal(targetAHandle);

@@ -362,16 +368,30 @@ expect(monitor.isOver(targetAHandle)).to.equal(true);

expect(monitor.isOver(targetCHandle)).to.equal(true);
expect(monitor.isOver(targetCHandle, true)).to.equal(true);
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(true);
expect(monitor.isOver(targetCHandle, true)).to.equal(false);
expect(handles[3]).to.equal(targetDHandle);
expect(monitor.isOver(targetDHandle)).to.equal(true);
expect(monitor.isOver(targetDHandle, true)).to.equal(true);
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.simulateLeave(targetBHandle);
backend.simulateHover([targetBHandle]);
handles = monitor.getTargetHandles();
expect(handles[0]).to.equal(targetAHandle);
expect(handles[0]).to.equal(targetBHandle);
expect(handles.length).to.be(1);
expect(monitor.isOver(targetAHandle)).to.equal(true);
expect(monitor.isOver(targetAHandle, true)).to.equal(true);
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);
});
it("reset target handles on drop", function () {
it("does not reset target handles on drop() and endDrag()", function () {
var source = new NormalSource();

@@ -383,69 +403,37 @@ var sourceHandle = registry.addSource(Types.FOO, source);

var targetBHandle = registry.addTarget(Types.FOO, targetB);
var handles = undefined;
handles = monitor.getTargetHandles();
expect(handles.length).to.be(0);
expect(monitor.getTargetHandles().length).to.be(0);
backend.simulateHover([targetAHandle, targetBHandle]);
expect(monitor.getTargetHandles().length).to.be(2);
backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
handles = monitor.getTargetHandles();
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(true);
expect(handles.length).to.be(2);
expect(monitor.getTargetHandles().length).to.be(2);
backend.simulateDrop();
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.getTargetHandles().length).to.be(2);
backend.simulateEndDrag();
handles = monitor.getTargetHandles();
expect(handles.length).to.be(0);
expect(monitor.getTargetHandles().length).to.be(2);
backend.simulateHover([targetAHandle]);
expect(monitor.getTargetHandles().length).to.be(1);
backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
handles = monitor.getTargetHandles();
expect(handles[0]).to.equal(targetAHandle);
expect(monitor.isOver(targetAHandle)).to.equal(true);
expect(monitor.isOver(targetAHandle, true)).to.equal(true);
expect(handles.length).to.be(1);
expect(monitor.getTargetHandles().length).to.be(1);
});
it("reset target handles on endDrag", function () {
it("does not let array mutation to corrupt internal state", 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.FOO, targetB);
var handles = undefined;
var target = new NormalTarget();
var targetHandle = registry.addTarget(Types.FOO, target);
var handles = [targetHandle];
handles = monitor.getTargetHandles();
expect(handles.length).to.be(0);
backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
backend.simulateEnter(targetBHandle);
handles = monitor.getTargetHandles();
expect(handles[0]).to.equal(targetAHandle);
expect(handles[1]).to.equal(targetBHandle);
expect(handles.length).to.be(2);
backend.simulateHover(handles);
expect(monitor.getTargetHandles().length).to.be(1);
backend.simulateEndDrag();
handles = monitor.getTargetHandles();
expect(handles.length).to.be(0);
backend.simulateBeginDrag(sourceHandle);
backend.simulateEnter(targetAHandle);
handles = monitor.getTargetHandles();
expect(handles[0]).to.equal(targetAHandle);
expect(handles.length).to.be(1);
handles.push(targetHandle);
expect(monitor.getTargetHandles().length).to.be(1);
});

@@ -463,3 +451,3 @@ });

var sourceD = new NumberSource(4, false);
var sourceDHandle = registry.addSource(Types.FOO, sourceC);
var sourceDHandle = registry.addSource(Types.FOO, sourceD);
var target = new NormalTarget();

@@ -489,3 +477,3 @@ var targetHandle = registry.addTarget(Types.FOO, target);

registry.removeSource(sourceDHandle);
backend.simulateEnter(targetHandle);
backend.simulateHover([targetHandle]);
backend.simulateDrop();

@@ -492,0 +480,0 @@ expect(monitor.isDragging(sourceAHandle)).to.equal(false);

@@ -13,2 +13,4 @@ "use strict";

var isArray = _interopRequire(require("lodash/lang/isArray"));
var isObject = _interopRequire(require("lodash/lang/isObject"));

@@ -44,22 +46,15 @@

DragDropActions.prototype.enter = function enter(targetHandle) {
var monitor = this.manager.getMonitor();
invariant(monitor.isDragging(), "Cannot call enter while not dragging.");
DragDropActions.prototype.hover = function hover(targetHandles) {
invariant(isArray(targetHandles), "Target handles must be an array.");
targetHandles = targetHandles.slice(0);
var targetHandles = monitor.getTargetHandles();
invariant(targetHandles.indexOf(targetHandle) === -1, "Cannot enter the same target twice.");
var registry = this.manager.getRegistry();
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.");
}
return { targetHandle: targetHandle };
return { targetHandles: targetHandles };
};
DragDropActions.prototype.leave = function leave(targetHandle) {
var monitor = this.manager.getMonitor();
invariant(monitor.isDragging(), "Cannot call leave while not dragging.");
var targetHandles = monitor.getTargetHandles();
invariant(targetHandles.indexOf(targetHandle) !== -1, "Cannot leave a target that was not entered.");
return { targetHandle: targetHandle };
};
DragDropActions.prototype.drop = function drop() {

@@ -66,0 +61,0 @@ var _this = this;

@@ -25,10 +25,6 @@ "use strict";

TestBackend.prototype.simulateEnter = function simulateEnter(targetHandle) {
this.actions.enter(targetHandle);
TestBackend.prototype.simulateHover = function simulateHover(targetHandles) {
this.actions.hover(targetHandles);
};
TestBackend.prototype.simulateLeave = function simulateLeave(targetHandle) {
this.actions.leave(targetHandle);
};
TestBackend.prototype.simulateDrop = function simulateDrop() {

@@ -35,0 +31,0 @@ this.actions.drop();

"use strict";
var _interopRequire = function (obj) { return obj && obj.__esModule ? obj["default"] : obj; };
var _inherits = function (subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) subClass.__proto__ = superClass; };

@@ -9,2 +11,4 @@

var without = _interopRequire(require("lodash/array/without"));
var DragOperationStore = (function (_Store) {

@@ -20,4 +24,3 @@ function DragOperationStore(flux) {

this.register(dragDropActionIds.beginDrag, this.handleBeginDrag);
this.register(dragDropActionIds.enter, this.handleEnter);
this.register(dragDropActionIds.leave, this.handleLeave);
this.register(dragDropActionIds.hover, this.handleHover);
this.register(dragDropActionIds.endDrag, this.handleEndDrag);

@@ -48,3 +51,2 @@ this.register(dragDropActionIds.drop, this.handleDrop);

sourceHandle: sourceHandle,
targetHandles: [],
dropResult: false,

@@ -55,27 +57,16 @@ didDrop: false

DragOperationStore.prototype.handleEnter = function handleEnter(_ref) {
var targetHandle = _ref.targetHandle;
var targetHandles = this.state.targetHandles;
DragOperationStore.prototype.handleHover = function handleHover(_ref) {
var targetHandles = _ref.targetHandles;
this.setState({
targetHandles: targetHandles.concat([targetHandle])
});
this.setState({ targetHandles: targetHandles });
};
DragOperationStore.prototype.handleLeave = function handleLeave(_ref) {
DragOperationStore.prototype.handleRemoveTarget = function handleRemoveTarget(_ref) {
var targetHandle = _ref.targetHandle;
var targetHandles = this.state.targetHandles;
var index = targetHandles.indexOf(targetHandle);
this.setState({
targetHandles: targetHandles.slice(0, index)
});
};
DragOperationStore.prototype.handleRemoveTarget = function handleRemoveTarget(_ref) {
var targetHandle = _ref.targetHandle;
if (this.getTargetHandles().indexOf(targetHandle) > -1) {
this.handleLeave({ targetHandle: targetHandle });
if (targetHandles.indexOf(targetHandle) > -1) {
this.setState({
targetHandles: without(targetHandles, targetHandle)
});
}

@@ -89,4 +80,3 @@ };

dropResult: dropResult,
didDrop: true,
targetHandles: []
didDrop: true
});

@@ -100,3 +90,2 @@ };

sourceHandle: null,
targetHandles: [],
dropResult: null,

@@ -120,3 +109,3 @@ didDrop: false

DragOperationStore.prototype.getTargetHandles = function getTargetHandles() {
return this.state.targetHandles;
return this.state.targetHandles.slice(0);
};

@@ -123,0 +112,0 @@

@@ -85,3 +85,3 @@ "use strict";

invariant(typeof type === "string" || typeof type === "symbol", allowArray ? "Type can only be a string, a symbol, or an array of them." : "Type can only be a string or a symbol.");
invariant(typeof type === "string", allowArray ? "Type can only be a string or an array of them." : "Type can only be a string.");
}

@@ -126,6 +126,16 @@

invariant(!this.containsHandler(handler), "Cannot add the same handler instance twice.");
this.handlers[handle] = handler;
return handle;
};
HandlerRegistry.prototype.containsHandler = function containsHandler(handler) {
var _this = this;
return Object.keys(this.handlers).some(function (key) {
return _this.handlers[key] === handler;
});
};
HandlerRegistry.prototype.getSource = function getSource(sourceHandle, includePinned) {

@@ -169,3 +179,3 @@ validateSourceHandle(sourceHandle);

this.handlers[sourceHandle] = null;
delete this.handlers[sourceHandle];
this.actions.removeSource(sourceHandle);

@@ -178,3 +188,3 @@ };

this.handlers[targetHandle] = null;
delete this.handlers[targetHandle];
this.actions.removeTarget(targetHandle);

@@ -181,0 +191,0 @@ };

{
"name": "dnd-core",
"version": "0.4.3",
"version": "0.5.0",
"description": "Drag and drop sans the GUI",

@@ -8,3 +8,4 @@ "main": "dist-modules/index.js",

"build": "./scripts/build",
"test": "./scripts/test-cov",
"test": "./scripts/test",
"test-cov": "./scripts/test-cov",
"prepublish": "npm run build"

@@ -11,0 +12,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc