Comparing version 0.4.2 to 0.4.3
@@ -28,2 +28,4 @@ "use strict"; | ||
var isString = _interopRequire(require("lodash/lang/isString")); | ||
describe("DragDropManager", function () { | ||
@@ -151,2 +153,15 @@ var manager = undefined; | ||
}); | ||
it("returns string handles", 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, Types.BAR], targetB); | ||
expect(isString(sourceHandle)).to.equal(true); | ||
expect(isString(targetAHandle)).to.equal(true); | ||
expect(isString(targetBHandle)).to.equal(true); | ||
}); | ||
}); | ||
@@ -153,0 +168,0 @@ |
@@ -39,4 +39,3 @@ "use strict"; | ||
var itemType = sourceHandle.type; | ||
var itemType = registry.getSourceType(sourceHandle); | ||
return { itemType: itemType, item: item, sourceHandle: sourceHandle }; | ||
@@ -43,0 +42,0 @@ }; |
@@ -56,6 +56,4 @@ "use strict"; | ||
var targetType = targetHandle.type; | ||
var targetType = this.registry.getTargetType(targetHandle); | ||
var draggedItemType = this.getItemType(); | ||
return matchesType(targetType, draggedItemType) && target.canDrop(this, targetHandle); | ||
@@ -70,4 +68,3 @@ }; | ||
var sourceType = sourceHandle.type; | ||
var sourceType = this.registry.getSourceType(sourceHandle); | ||
var draggedItemType = this.getItemType(); | ||
@@ -74,0 +71,0 @@ if (sourceType !== draggedItemType) { |
@@ -5,2 +5,4 @@ "use strict"; | ||
var _slicedToArray = function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { var _arr = []; for (var _iterator = arr[Symbol.iterator](), _step; !(_step = _iterator.next()).done;) { _arr.push(_step.value); if (i && _arr.length === i) break; } return _arr; } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; | ||
var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; | ||
@@ -14,6 +16,2 @@ | ||
var getIn = _interopRequire(require("./getIn")); | ||
var setIn = _interopRequire(require("./setIn")); | ||
var getNextUniqueId = _interopRequire(require("./getNextUniqueId")); | ||
@@ -26,2 +24,31 @@ | ||
var HANDLE_SEPARATOR = "🐲"; | ||
var TYPE_SEPARATOR = "💧"; | ||
function parseHandle(handle) { | ||
var _handle$split = handle.split(HANDLE_SEPARATOR); | ||
var _handle$split2 = _slicedToArray(_handle$split, 3); | ||
var type = _handle$split2[0]; | ||
var role = _handle$split2[1]; | ||
var id = _handle$split2[2]; | ||
if (type.indexOf(TYPE_SEPARATOR) > -1) { | ||
type = type.split(TYPE_SEPARATOR); | ||
} | ||
return { type: type, role: role, id: id }; | ||
} | ||
function makeHandle(_ref) { | ||
var type = _ref.type; | ||
var role = _ref.role; | ||
var id = _ref.id; | ||
if (isArray(type)) { | ||
type = type.join(TYPE_SEPARATOR); | ||
} | ||
return [type, role, id].join(HANDLE_SEPARATOR); | ||
} | ||
function validateSourceContract(source) { | ||
@@ -38,7 +65,15 @@ invariant(typeof source.canDrag === "function", "Expected canDrag to be a function."); | ||
function validateSourceHandle(handle) { | ||
invariant(handle.role === HandlerRoles.SOURCE, "Expected to receive a source handle"); | ||
var _parseHandle = parseHandle(handle); | ||
var role = _parseHandle.role; | ||
invariant(role === HandlerRoles.SOURCE, "Expected to receive a source handle"); | ||
} | ||
function validateTargetHandle(handle) { | ||
invariant(handle.role === HandlerRoles.TARGET, "Expected to receive a target handle"); | ||
var _parseHandle = parseHandle(handle); | ||
var role = _parseHandle.role; | ||
invariant(role === HandlerRoles.TARGET, "Expected to receive a target handle"); | ||
} | ||
@@ -57,10 +92,2 @@ | ||
function makePath(_ref) { | ||
var role = _ref.role; | ||
var type = _ref.type; | ||
var id = _ref.id; | ||
return [role, type, id]; | ||
} | ||
var HandlerRegistry = (function () { | ||
@@ -101,6 +128,5 @@ function HandlerRegistry(actions) { | ||
var id = getNextUniqueId().toString(); | ||
var handle = { role: role, type: type, id: id }; | ||
var path = makePath(handle); | ||
var handle = makeHandle({ role: role, type: type, id: id }); | ||
setIn(this.handlers, path, handler); | ||
this.handlers[handle] = handler; | ||
return handle; | ||
@@ -112,5 +138,4 @@ }; | ||
var path = makePath(sourceHandle); | ||
var isPinned = includePinned && sourceHandle === this.pinnedSourceHandle; | ||
var source = isPinned ? this.pinnedSource : getIn(this.handlers, path); | ||
var source = isPinned ? this.pinnedSource : this.handlers[sourceHandle]; | ||
@@ -122,7 +147,25 @@ return source; | ||
validateTargetHandle(targetHandle); | ||
return this.handlers[targetHandle]; | ||
}; | ||
var path = makePath(targetHandle); | ||
return getIn(this.handlers, path); | ||
HandlerRegistry.prototype.getSourceType = function getSourceType(sourceHandle) { | ||
validateSourceHandle(sourceHandle); | ||
var _parseHandle = parseHandle(sourceHandle); | ||
var type = _parseHandle.type; | ||
return type; | ||
}; | ||
HandlerRegistry.prototype.getTargetType = function getTargetType(targetHandle) { | ||
validateTargetHandle(targetHandle); | ||
var _parseHandle = parseHandle(targetHandle); | ||
var type = _parseHandle.type; | ||
return type; | ||
}; | ||
HandlerRegistry.prototype.removeSource = function removeSource(sourceHandle) { | ||
@@ -132,4 +175,3 @@ validateSourceHandle(sourceHandle); | ||
var path = makePath(sourceHandle); | ||
setIn(this.handlers, path, null); | ||
this.handlers[sourceHandle] = null; | ||
this.actions.removeSource(sourceHandle); | ||
@@ -142,4 +184,3 @@ }; | ||
var path = makePath(targetHandle); | ||
setIn(this.handlers, path, null); | ||
this.handlers[targetHandle] = null; | ||
this.actions.removeTarget(targetHandle); | ||
@@ -146,0 +187,0 @@ }; |
{ | ||
"name": "dnd-core", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"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
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
2065
309161