dnd-multi-backend
Advanced tools
Comparing version 5.1.0-rc01 to 5.1.1
@@ -24,223 +24,183 @@ "use strict"; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
var _default = function _default(manager, context, sourceOptions) { | ||
var _this = this; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
_classCallCheck(this, _default); | ||
var _default = /*#__PURE__*/function () { | ||
function _default(manager, context, sourceOptions) { | ||
var _this = this; | ||
this.setup = function () { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
_classCallCheck(this, _default); | ||
if (_this.constructor.isSetUp) { | ||
throw new Error('Cannot have two MultiBackends at the same time.'); | ||
} | ||
this.setup = function () { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
_this.constructor.isSetUp = true; | ||
if (_this.constructor.isSetUp) { | ||
throw new Error('Cannot have two MultiBackends at the same time.'); | ||
} | ||
_this.addEventListeners(window); | ||
_this.constructor.isSetUp = true; | ||
_this.backends[_this.current].instance.setup(); | ||
}; | ||
_this.addEventListeners(window); | ||
this.teardown = function () { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
_this.backends[_this.current].instance.setup(); | ||
}; | ||
_this.constructor.isSetUp = false; | ||
this.teardown = function () { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
_this.removeEventListeners(window); | ||
_this.constructor.isSetUp = false; | ||
_this.backends[_this.current].instance.teardown(); | ||
}; | ||
_this.removeEventListeners(window); | ||
this.connectDragSource = function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this.backends[_this.current].instance.teardown(); | ||
}; | ||
return _this.connectBackend('connectDragSource', args); | ||
}; | ||
this.connectDragSource = function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
this.connectDragPreview = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return _this.connectBackend('connectDragSource', args); | ||
}; | ||
return _this.connectBackend('connectDragPreview', args); | ||
}; | ||
this.connectDragPreview = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
this.connectDropTarget = function () { | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
return _this.connectBackend('connectDragPreview', args); | ||
}; | ||
return _this.connectBackend('connectDropTarget', args); | ||
}; | ||
this.connectDropTarget = function () { | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
this.previewEnabled = function () { | ||
return _this.backends[_this.current].preview; | ||
}; | ||
this.addEventListeners = function (target) { | ||
_this.backends.forEach(function (backend) { | ||
if (backend.transition) { | ||
target.addEventListener(backend.transition.event, _this.backendSwitcher, true); | ||
} | ||
}); | ||
}; | ||
return _this.connectBackend('connectDropTarget', args); | ||
}; | ||
this.removeEventListeners = function (target) { | ||
_this.backends.forEach(function (backend) { | ||
if (backend.transition) { | ||
target.removeEventListener(backend.transition.event, _this.backendSwitcher, true); | ||
} | ||
}); | ||
}; | ||
this.previewEnabled = function () { | ||
return _this.backends[_this.current].preview; | ||
}; | ||
this.backendSwitcher = function (event) { | ||
var oldBackend = _this.current; | ||
var i = 0; | ||
this.addEventListeners = function (target) { | ||
_this.backendsList.forEach(function (backend) { | ||
if (backend.transition) { | ||
target.addEventListener(backend.transition.event, _this.backendSwitcher, true); | ||
} | ||
}); | ||
}; | ||
_this.backends.some(function (backend) { | ||
if (i !== _this.current && backend.transition && backend.transition.check(event)) { | ||
_this.current = i; | ||
return true; | ||
} | ||
this.removeEventListeners = function (target) { | ||
_this.backendsList.forEach(function (backend) { | ||
if (backend.transition) { | ||
target.removeEventListener(backend.transition.event, _this.backendSwitcher, true); | ||
} | ||
}); | ||
}; | ||
i += 1; | ||
return false; | ||
}); | ||
this.backendSwitcher = function (event) { | ||
var oldBackend = _this.current; | ||
if (_this.current !== oldBackend) { | ||
_this.backends[oldBackend].instance.teardown(); | ||
_this.backendsList.some(function (backend) { | ||
if (backend.id !== _this.current && backend.transition && backend.transition.check(event)) { | ||
_this.current = backend.id; | ||
return true; | ||
} | ||
return false; | ||
Object.keys(_this.nodes).forEach(function (id) { | ||
var node = _this.nodes[id]; | ||
node.handler(); | ||
node.handler = _this.callBackend(node.func, node.args); | ||
}); | ||
if (_this.current !== oldBackend) { | ||
_this.backends[oldBackend].instance.teardown(); | ||
_this.previews.backendChanged(_this); | ||
Object.keys(_this.nodes).forEach(function (id) { | ||
var node = _this.nodes[id]; | ||
node.handler(); | ||
node.handler = _this.callBackend(node.func, node.args); | ||
}); | ||
var newBackend = _this.backends[_this.current]; | ||
newBackend.instance.setup(); | ||
_this.previews.backendChanged(_this); | ||
if (newBackend.skipDispatchOnTransition) { | ||
return; | ||
} | ||
var newBackend = _this.backends[_this.current]; | ||
newBackend.instance.setup(); | ||
var newEvent = null; | ||
if (newBackend.skipDispatchOnTransition) { | ||
return; | ||
} | ||
var newEvent = null; | ||
try { | ||
newEvent = new event.constructor(event.type, event); | ||
} catch (_e) { | ||
newEvent = document.createEvent('Event'); | ||
newEvent.initEvent(event.type, event.bubbles, event.cancelable); | ||
} | ||
event.target.dispatchEvent(newEvent); | ||
try { | ||
newEvent = new event.constructor(event.type, event); | ||
} catch (_e) { | ||
newEvent = document.createEvent('Event'); | ||
newEvent.initEvent(event.type, event.bubbles, event.cancelable); | ||
} | ||
}; | ||
this.callBackend = function (func, args) { | ||
var _this$backends$_this$; | ||
event.target.dispatchEvent(newEvent); | ||
} | ||
}; | ||
return (_this$backends$_this$ = _this.backends[_this.current].instance)[func].apply(_this$backends$_this$, _toConsumableArray(args)); | ||
}; | ||
this.callBackend = function (func, args) { | ||
var _this$backends$_this$; | ||
this.connectBackend = function (func, args) { | ||
var nodeId = "".concat(func, "_").concat(args[0]); | ||
return (_this$backends$_this$ = _this.backends[_this.current].instance)[func].apply(_this$backends$_this$, _toConsumableArray(args)); | ||
}; | ||
var handler = _this.callBackend(func, args); | ||
this.connectBackend = function (func, args) { | ||
var nodeId = "".concat(func, "_").concat(args[0]); | ||
_this.nodes[nodeId] = { | ||
func: func, | ||
args: args, | ||
handler: handler | ||
}; | ||
return function () { | ||
var _this$nodes$nodeId; | ||
var handler = _this.callBackend(func, args); | ||
var r = (_this$nodes$nodeId = _this.nodes[nodeId]).handler.apply(_this$nodes$nodeId, arguments); | ||
delete _this.nodes[nodeId]; | ||
return r; | ||
}; | ||
_this.nodes[nodeId] = { | ||
func: func, | ||
args: args, | ||
handler: handler | ||
}; | ||
return function () { | ||
var _this$nodes$nodeId; | ||
var options = Object.assign({ | ||
backends: [] | ||
}, sourceOptions || {}); | ||
var r = (_this$nodes$nodeId = _this.nodes[nodeId]).handler.apply(_this$nodes$nodeId, arguments); | ||
if (options.backends.length < 1) { | ||
throw new Error("You must specify at least one Backend, if you are coming from 2.x.x (or don't understand this error)\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-2xx"); | ||
} | ||
delete _this.nodes[nodeId]; | ||
return r; | ||
}; | ||
}; | ||
this.current = null; | ||
this.previews = new _PreviewList.PreviewList(); | ||
this.backends = {}; | ||
this.backendsList = []; | ||
options.backends.forEach(function (backend) { | ||
var backendRecord = _this.createBackend(manager, context, backend); | ||
var options = Object.assign({ | ||
backends: [] | ||
}, sourceOptions || {}); | ||
if (_this.current === null) { | ||
_this.current = backendRecord.id; | ||
} | ||
_this.backends[backendRecord.id] = backendRecord; | ||
_this.backendsList.push(backendRecord); | ||
}); | ||
this.nodes = {}; | ||
if (options.backends.length < 1) { | ||
throw new Error("You must specify at least one Backend, if you are coming from 2.x.x (or don't understand this error)\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-2xx"); | ||
} | ||
_createClass(_default, [{ | ||
key: "createBackend", | ||
value: function createBackend(manager, context, backend) { | ||
if (!backend.backend) { | ||
throw new Error("You must specify a 'backend' property in your Backend entry: ".concat(backend)); | ||
} | ||
this.current = 0; | ||
this.previews = new _PreviewList.PreviewList(); | ||
this.backends = []; | ||
options.backends.forEach(function (backend) { | ||
if (!backend.backend) { | ||
throw new Error("You must specify a 'backend' property in your Backend entry: ".concat(backend)); | ||
} | ||
var transition = backend.transition; | ||
var transition = backend.transition; | ||
if (transition && !transition._isMBTransition) { | ||
throw new Error("You must specify a valid 'transition' property (either undefined or the return of 'createTransition') in your Backend entry: ".concat(backend)); | ||
} | ||
if (transition && !transition._isMBTransition) { | ||
throw new Error("You must specify a valid 'transition' property (either undefined or the return of 'createTransition') in your Backend entry: ".concat(backend)); | ||
} | ||
var instance = backend.backend(manager, context, backend.options); | ||
var id = backend.id; // Try to infer an `id` if one doesn't exist | ||
_this.backends.push({ | ||
instance: backend.backend(manager, context, backend.options), | ||
preview: backend.preview || false, | ||
transition: transition, | ||
skipDispatchOnTransition: Boolean(backend.skipDispatchOnTransition) | ||
}); | ||
}); | ||
this.nodes = {}; | ||
} // DnD Backend API | ||
; | ||
if (!backend.id && instance && instance.constructor) { | ||
id = instance.constructor.name; | ||
console.warn( // eslint-disable-line no-console | ||
"Deprecation notice: You are using a pipeline which doesn't include backends' 'id'.\n This might be unsupported in the future, please specify 'id' explicitely for every backend."); | ||
} | ||
if (!id) { | ||
throw new Error("You must specify an 'id' property in your Backend entry: ".concat(Object.stringify(backend), "\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-5xx")); | ||
} | ||
if (this.backends[id]) { | ||
throw new Error("You must specify a unique 'id' property in your Backend entry:\n ".concat(Object.stringify(backend), " (conflicts with: ").concat(Object.stringify(this.backends[id]), ")")); | ||
} | ||
return { | ||
id: backend.id, | ||
instance: instance, | ||
preview: backend.preview || false, | ||
transition: transition, | ||
skipDispatchOnTransition: Boolean(backend.skipDispatchOnTransition) | ||
}; | ||
} // DnD Backend API | ||
}]); | ||
return _default; | ||
}(); | ||
exports.default = _default; |
@@ -15,225 +15,185 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
import { PreviewList } from './PreviewList'; | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var _default = function _default(manager, context, sourceOptions) { | ||
var _this = this; | ||
import { PreviewList } from './PreviewList'; | ||
_classCallCheck(this, _default); | ||
var _default = /*#__PURE__*/function () { | ||
function _default(manager, context, sourceOptions) { | ||
var _this = this; | ||
this.setup = function () { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
_classCallCheck(this, _default); | ||
if (_this.constructor.isSetUp) { | ||
throw new Error('Cannot have two MultiBackends at the same time.'); | ||
} | ||
this.setup = function () { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
_this.constructor.isSetUp = true; | ||
if (_this.constructor.isSetUp) { | ||
throw new Error('Cannot have two MultiBackends at the same time.'); | ||
} | ||
_this.addEventListeners(window); | ||
_this.constructor.isSetUp = true; | ||
_this.backends[_this.current].instance.setup(); | ||
}; | ||
_this.addEventListeners(window); | ||
this.teardown = function () { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
_this.backends[_this.current].instance.setup(); | ||
}; | ||
_this.constructor.isSetUp = false; | ||
this.teardown = function () { | ||
if (typeof window === 'undefined') { | ||
return; | ||
} | ||
_this.removeEventListeners(window); | ||
_this.constructor.isSetUp = false; | ||
_this.backends[_this.current].instance.teardown(); | ||
}; | ||
_this.removeEventListeners(window); | ||
this.connectDragSource = function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this.backends[_this.current].instance.teardown(); | ||
}; | ||
return _this.connectBackend('connectDragSource', args); | ||
}; | ||
this.connectDragSource = function () { | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
this.connectDragPreview = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
return _this.connectBackend('connectDragSource', args); | ||
}; | ||
return _this.connectBackend('connectDragPreview', args); | ||
}; | ||
this.connectDragPreview = function () { | ||
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { | ||
args[_key2] = arguments[_key2]; | ||
} | ||
this.connectDropTarget = function () { | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
} | ||
return _this.connectBackend('connectDragPreview', args); | ||
}; | ||
return _this.connectBackend('connectDropTarget', args); | ||
}; | ||
this.connectDropTarget = function () { | ||
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) { | ||
args[_key3] = arguments[_key3]; | ||
this.previewEnabled = function () { | ||
return _this.backends[_this.current].preview; | ||
}; | ||
this.addEventListeners = function (target) { | ||
_this.backends.forEach(function (backend) { | ||
if (backend.transition) { | ||
target.addEventListener(backend.transition.event, _this.backendSwitcher, true); | ||
} | ||
}); | ||
}; | ||
return _this.connectBackend('connectDropTarget', args); | ||
}; | ||
this.removeEventListeners = function (target) { | ||
_this.backends.forEach(function (backend) { | ||
if (backend.transition) { | ||
target.removeEventListener(backend.transition.event, _this.backendSwitcher, true); | ||
} | ||
}); | ||
}; | ||
this.previewEnabled = function () { | ||
return _this.backends[_this.current].preview; | ||
}; | ||
this.backendSwitcher = function (event) { | ||
var oldBackend = _this.current; | ||
var i = 0; | ||
this.addEventListeners = function (target) { | ||
_this.backendsList.forEach(function (backend) { | ||
if (backend.transition) { | ||
target.addEventListener(backend.transition.event, _this.backendSwitcher, true); | ||
} | ||
}); | ||
}; | ||
_this.backends.some(function (backend) { | ||
if (i !== _this.current && backend.transition && backend.transition.check(event)) { | ||
_this.current = i; | ||
return true; | ||
} | ||
this.removeEventListeners = function (target) { | ||
_this.backendsList.forEach(function (backend) { | ||
if (backend.transition) { | ||
target.removeEventListener(backend.transition.event, _this.backendSwitcher, true); | ||
} | ||
}); | ||
}; | ||
i += 1; | ||
return false; | ||
}); | ||
this.backendSwitcher = function (event) { | ||
var oldBackend = _this.current; | ||
if (_this.current !== oldBackend) { | ||
_this.backends[oldBackend].instance.teardown(); | ||
_this.backendsList.some(function (backend) { | ||
if (backend.id !== _this.current && backend.transition && backend.transition.check(event)) { | ||
_this.current = backend.id; | ||
return true; | ||
} | ||
return false; | ||
Object.keys(_this.nodes).forEach(function (id) { | ||
var node = _this.nodes[id]; | ||
node.handler(); | ||
node.handler = _this.callBackend(node.func, node.args); | ||
}); | ||
if (_this.current !== oldBackend) { | ||
_this.backends[oldBackend].instance.teardown(); | ||
_this.previews.backendChanged(_this); | ||
Object.keys(_this.nodes).forEach(function (id) { | ||
var node = _this.nodes[id]; | ||
node.handler(); | ||
node.handler = _this.callBackend(node.func, node.args); | ||
}); | ||
var newBackend = _this.backends[_this.current]; | ||
newBackend.instance.setup(); | ||
_this.previews.backendChanged(_this); | ||
if (newBackend.skipDispatchOnTransition) { | ||
return; | ||
} | ||
var newBackend = _this.backends[_this.current]; | ||
newBackend.instance.setup(); | ||
var newEvent = null; | ||
if (newBackend.skipDispatchOnTransition) { | ||
return; | ||
} | ||
var newEvent = null; | ||
try { | ||
newEvent = new event.constructor(event.type, event); | ||
} catch (_e) { | ||
newEvent = document.createEvent('Event'); | ||
newEvent.initEvent(event.type, event.bubbles, event.cancelable); | ||
} | ||
event.target.dispatchEvent(newEvent); | ||
try { | ||
newEvent = new event.constructor(event.type, event); | ||
} catch (_e) { | ||
newEvent = document.createEvent('Event'); | ||
newEvent.initEvent(event.type, event.bubbles, event.cancelable); | ||
} | ||
}; | ||
this.callBackend = function (func, args) { | ||
var _this$backends$_this$; | ||
event.target.dispatchEvent(newEvent); | ||
} | ||
}; | ||
return (_this$backends$_this$ = _this.backends[_this.current].instance)[func].apply(_this$backends$_this$, _toConsumableArray(args)); | ||
}; | ||
this.callBackend = function (func, args) { | ||
var _this$backends$_this$; | ||
this.connectBackend = function (func, args) { | ||
var nodeId = "".concat(func, "_").concat(args[0]); | ||
return (_this$backends$_this$ = _this.backends[_this.current].instance)[func].apply(_this$backends$_this$, _toConsumableArray(args)); | ||
}; | ||
var handler = _this.callBackend(func, args); | ||
this.connectBackend = function (func, args) { | ||
var nodeId = "".concat(func, "_").concat(args[0]); | ||
_this.nodes[nodeId] = { | ||
func: func, | ||
args: args, | ||
handler: handler | ||
}; | ||
return function () { | ||
var _this$nodes$nodeId; | ||
var handler = _this.callBackend(func, args); | ||
var r = (_this$nodes$nodeId = _this.nodes[nodeId]).handler.apply(_this$nodes$nodeId, arguments); | ||
delete _this.nodes[nodeId]; | ||
return r; | ||
}; | ||
_this.nodes[nodeId] = { | ||
func: func, | ||
args: args, | ||
handler: handler | ||
}; | ||
return function () { | ||
var _this$nodes$nodeId; | ||
var options = Object.assign({ | ||
backends: [] | ||
}, sourceOptions || {}); | ||
var r = (_this$nodes$nodeId = _this.nodes[nodeId]).handler.apply(_this$nodes$nodeId, arguments); | ||
if (options.backends.length < 1) { | ||
throw new Error("You must specify at least one Backend, if you are coming from 2.x.x (or don't understand this error)\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-2xx"); | ||
} | ||
delete _this.nodes[nodeId]; | ||
return r; | ||
}; | ||
}; | ||
this.current = null; | ||
this.previews = new PreviewList(); | ||
this.backends = {}; | ||
this.backendsList = []; | ||
options.backends.forEach(function (backend) { | ||
var backendRecord = _this.createBackend(manager, context, backend); | ||
var options = Object.assign({ | ||
backends: [] | ||
}, sourceOptions || {}); | ||
if (_this.current === null) { | ||
_this.current = backendRecord.id; | ||
} | ||
_this.backends[backendRecord.id] = backendRecord; | ||
_this.backendsList.push(backendRecord); | ||
}); | ||
this.nodes = {}; | ||
if (options.backends.length < 1) { | ||
throw new Error("You must specify at least one Backend, if you are coming from 2.x.x (or don't understand this error)\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-2xx"); | ||
} | ||
_createClass(_default, [{ | ||
key: "createBackend", | ||
value: function createBackend(manager, context, backend) { | ||
if (!backend.backend) { | ||
throw new Error("You must specify a 'backend' property in your Backend entry: ".concat(backend)); | ||
} | ||
this.current = 0; | ||
this.previews = new PreviewList(); | ||
this.backends = []; | ||
options.backends.forEach(function (backend) { | ||
if (!backend.backend) { | ||
throw new Error("You must specify a 'backend' property in your Backend entry: ".concat(backend)); | ||
} | ||
var transition = backend.transition; | ||
var transition = backend.transition; | ||
if (transition && !transition._isMBTransition) { | ||
throw new Error("You must specify a valid 'transition' property (either undefined or the return of 'createTransition') in your Backend entry: ".concat(backend)); | ||
} | ||
if (transition && !transition._isMBTransition) { | ||
throw new Error("You must specify a valid 'transition' property (either undefined or the return of 'createTransition') in your Backend entry: ".concat(backend)); | ||
} | ||
var instance = backend.backend(manager, context, backend.options); | ||
var id = backend.id; // Try to infer an `id` if one doesn't exist | ||
_this.backends.push({ | ||
instance: backend.backend(manager, context, backend.options), | ||
preview: backend.preview || false, | ||
transition: transition, | ||
skipDispatchOnTransition: Boolean(backend.skipDispatchOnTransition) | ||
}); | ||
}); | ||
this.nodes = {}; | ||
} // DnD Backend API | ||
; | ||
if (!backend.id && instance && instance.constructor) { | ||
id = instance.constructor.name; | ||
console.warn( // eslint-disable-line no-console | ||
"Deprecation notice: You are using a pipeline which doesn't include backends' 'id'.\n This might be unsupported in the future, please specify 'id' explicitely for every backend."); | ||
} | ||
if (!id) { | ||
throw new Error("You must specify an 'id' property in your Backend entry: ".concat(Object.stringify(backend), "\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-5xx")); | ||
} | ||
if (this.backends[id]) { | ||
throw new Error("You must specify a unique 'id' property in your Backend entry:\n ".concat(Object.stringify(backend), " (conflicts with: ").concat(Object.stringify(this.backends[id]), ")")); | ||
} | ||
return { | ||
id: backend.id, | ||
instance: instance, | ||
preview: backend.preview || false, | ||
transition: transition, | ||
skipDispatchOnTransition: Boolean(backend.skipDispatchOnTransition) | ||
}; | ||
} // DnD Backend API | ||
}]); | ||
return _default; | ||
}(); | ||
export { _default as default }; |
@@ -1,1 +0,1 @@ | ||
!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["dnd-multi-backend"]=e():n["dnd-multi-backend"]=e()}(window,(function(){return function(n){var e={};function t(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return n[r].call(i.exports,i,i.exports,t),i.l=!0,i.exports}return t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:r})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var i in n)t.d(r,i,function(e){return n[e]}.bind(null,i));return r},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=17)}({17:function(n,e,t){"use strict";t.r(e),t.d(e,"HTML5DragTransition",(function(){return o})),t.d(e,"TouchTransition",(function(){return i})),t.d(e,"MouseTransition",(function(){return c})),t.d(e,"createTransition",(function(){return r})),t.d(e,"PreviewList",(function(){return s})),t.d(e,"MultiBackend",(function(){return p}));var r=function(n,e){return{_isMBTransition:!0,event:n,check:e}},i=r("touchstart",(function(n){return null!=n.touches})),o=r("dragstart",(function(n){return!!n.type&&(-1!==n.type.indexOf("drag")||-1!==n.type.indexOf("drop"))})),c=r("mousedown",(function(n){return!!n.type&&(-1===n.type.indexOf("touch")&&-1!==n.type.indexOf("mouse"))}));function a(n){if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(n=function(n,e){if(!n)return;if("string"==typeof n)return u(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);"Object"===t&&n.constructor&&(t=n.constructor.name);if("Map"===t||"Set"===t)return Array.from(n);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return u(n,e)}(n))){var e=0,t=function(){};return{s:t,n:function(){return e>=n.length?{done:!0}:{done:!1,value:n[e++]}},e:function(n){throw n},f:t}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,i,o=!0,c=!1;return{s:function(){r=n[Symbol.iterator]()},n:function(){var n=r.next();return o=n.done,n},e:function(n){c=!0,i=n},f:function(){try{o||null==r.return||r.return()}finally{if(c)throw i}}}}function u(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}var s=function n(){var e=this;!function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),this.register=function(n){e.previews.push(n)},this.unregister=function(n){for(var t;-1!==(t=e.previews.indexOf(n));)e.previews.splice(t,1)},this.backendChanged=function(n){var t,r=a(e.previews);try{for(r.s();!(t=r.n()).done;){t.value.backendChanged(n)}}catch(n){r.e(n)}finally{r.f()}},this.previews=[]};function d(n){return function(n){if(Array.isArray(n))return f(n)}(n)||function(n){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(n))return Array.from(n)}(n)||function(n,e){if(!n)return;if("string"==typeof n)return f(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);"Object"===t&&n.constructor&&(t=n.constructor.name);if("Map"===t||"Set"===t)return Array.from(n);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return f(n,e)}(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function f(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}function l(n,e){for(var t=0;t<e.length;t++){var r=e[t];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(n,r.key,r)}}var p=function(){function n(e,t,r){var i=this;!function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),this.setup=function(){if("undefined"!=typeof window){if(i.constructor.isSetUp)throw new Error("Cannot have two MultiBackends at the same time.");i.constructor.isSetUp=!0,i.addEventListeners(window),i.backends[i.current].instance.setup()}},this.teardown=function(){"undefined"!=typeof window&&(i.constructor.isSetUp=!1,i.removeEventListeners(window),i.backends[i.current].instance.teardown())},this.connectDragSource=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return i.connectBackend("connectDragSource",e)},this.connectDragPreview=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return i.connectBackend("connectDragPreview",e)},this.connectDropTarget=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return i.connectBackend("connectDropTarget",e)},this.previewEnabled=function(){return i.backends[i.current].preview},this.addEventListeners=function(n){i.backendsList.forEach((function(e){e.transition&&n.addEventListener(e.transition.event,i.backendSwitcher,!0)}))},this.removeEventListeners=function(n){i.backendsList.forEach((function(e){e.transition&&n.removeEventListener(e.transition.event,i.backendSwitcher,!0)}))},this.backendSwitcher=function(n){var e=i.current;if(i.backendsList.some((function(e){return!(e.id===i.current||!e.transition||!e.transition.check(n))&&(i.current=e.id,!0)})),i.current!==e){i.backends[e].instance.teardown(),Object.keys(i.nodes).forEach((function(n){var e=i.nodes[n];e.handler(),e.handler=i.callBackend(e.func,e.args)})),i.previews.backendChanged(i);var t=i.backends[i.current];if(t.instance.setup(),t.skipDispatchOnTransition)return;var r=null;try{r=new n.constructor(n.type,n)}catch(e){(r=document.createEvent("Event")).initEvent(n.type,n.bubbles,n.cancelable)}n.target.dispatchEvent(r)}},this.callBackend=function(n,e){var t;return(t=i.backends[i.current].instance)[n].apply(t,d(e))},this.connectBackend=function(n,e){var t="".concat(n,"_").concat(e[0]),r=i.callBackend(n,e);return i.nodes[t]={func:n,args:e,handler:r},function(){var n,e=(n=i.nodes[t]).handler.apply(n,arguments);return delete i.nodes[t],e}};var o=Object.assign({backends:[]},r||{});if(o.backends.length<1)throw new Error("You must specify at least one Backend, if you are coming from 2.x.x (or don't understand this error)\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-2xx");this.current=null,this.previews=new s,this.backends={},this.backendsList=[],o.backends.forEach((function(n){var r=i.createBackend(e,t,n);null===i.current&&(i.current=r.id),i.backends[r.id]=r,i.backendsList.push(r)})),this.nodes={}}var e,t,r;return e=n,(t=[{key:"createBackend",value:function(n,e,t){if(!t.backend)throw new Error("You must specify a 'backend' property in your Backend entry: ".concat(t));var r=t.transition;if(r&&!r._isMBTransition)throw new Error("You must specify a valid 'transition' property (either undefined or the return of 'createTransition') in your Backend entry: ".concat(t));var i=t.backend(n,e,t.options),o=t.id;if(!t.id&&i&&i.constructor&&(o=i.constructor.name,console.warn("Deprecation notice: You are using a pipeline which doesn't include backends' 'id'.\n This might be unsupported in the future, please specify 'id' explicitely for every backend.")),!o)throw new Error("You must specify an 'id' property in your Backend entry: ".concat(Object.stringify(t),"\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-5xx"));if(this.backends[o])throw new Error("You must specify a unique 'id' property in your Backend entry:\n ".concat(Object.stringify(t)," (conflicts with: ").concat(Object.stringify(this.backends[o]),")"));return{id:t.id,instance:i,preview:t.preview||!1,transition:r,skipDispatchOnTransition:Boolean(t.skipDispatchOnTransition)}}}])&&l(e.prototype,t),r&&l(e,r),n}();e.default=function(n,e,t){return new p(n,e,t)}}})})); | ||
!function(n,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports["dnd-multi-backend"]=e():n["dnd-multi-backend"]=e()}(window,(function(){return function(n){var e={};function t(r){if(e[r])return e[r].exports;var o=e[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}return t.m=n,t.c=e,t.d=function(n,e,r){t.o(n,e)||Object.defineProperty(n,e,{enumerable:!0,get:r})},t.r=function(n){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(n,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(n,"__esModule",{value:!0})},t.t=function(n,e){if(1&e&&(n=t(n)),8&e)return n;if(4&e&&"object"==typeof n&&n&&n.__esModule)return n;var r=Object.create(null);if(t.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:n}),2&e&&"string"!=typeof n)for(var o in n)t.d(r,o,function(e){return n[e]}.bind(null,o));return r},t.n=function(n){var e=n&&n.__esModule?function(){return n.default}:function(){return n};return t.d(e,"a",e),e},t.o=function(n,e){return Object.prototype.hasOwnProperty.call(n,e)},t.p="",t(t.s=17)}({17:function(n,e,t){"use strict";t.r(e),t.d(e,"HTML5DragTransition",(function(){return i})),t.d(e,"TouchTransition",(function(){return o})),t.d(e,"MouseTransition",(function(){return a})),t.d(e,"createTransition",(function(){return r})),t.d(e,"PreviewList",(function(){return s})),t.d(e,"MultiBackend",(function(){return l}));var r=function(n,e){return{_isMBTransition:!0,event:n,check:e}},o=r("touchstart",(function(n){return null!=n.touches})),i=r("dragstart",(function(n){return!!n.type&&(-1!==n.type.indexOf("drag")||-1!==n.type.indexOf("drop"))})),a=r("mousedown",(function(n){return!!n.type&&(-1===n.type.indexOf("touch")&&-1!==n.type.indexOf("mouse"))}));function c(n){if("undefined"==typeof Symbol||null==n[Symbol.iterator]){if(Array.isArray(n)||(n=function(n,e){if(!n)return;if("string"==typeof n)return u(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);"Object"===t&&n.constructor&&(t=n.constructor.name);if("Map"===t||"Set"===t)return Array.from(n);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return u(n,e)}(n))){var e=0,t=function(){};return{s:t,n:function(){return e>=n.length?{done:!0}:{done:!1,value:n[e++]}},e:function(n){throw n},f:t}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,o,i=!0,a=!1;return{s:function(){r=n[Symbol.iterator]()},n:function(){var n=r.next();return i=n.done,n},e:function(n){a=!0,o=n},f:function(){try{i||null==r.return||r.return()}finally{if(a)throw o}}}}function u(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}var s=function n(){var e=this;!function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),this.register=function(n){e.previews.push(n)},this.unregister=function(n){for(var t;-1!==(t=e.previews.indexOf(n));)e.previews.splice(t,1)},this.backendChanged=function(n){var t,r=c(e.previews);try{for(r.s();!(t=r.n()).done;){t.value.backendChanged(n)}}catch(n){r.e(n)}finally{r.f()}},this.previews=[]};function f(n){return function(n){if(Array.isArray(n))return d(n)}(n)||function(n){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(n))return Array.from(n)}(n)||function(n,e){if(!n)return;if("string"==typeof n)return d(n,e);var t=Object.prototype.toString.call(n).slice(8,-1);"Object"===t&&n.constructor&&(t=n.constructor.name);if("Map"===t||"Set"===t)return Array.from(n);if("Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t))return d(n,e)}(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function d(n,e){(null==e||e>n.length)&&(e=n.length);for(var t=0,r=new Array(e);t<e;t++)r[t]=n[t];return r}var l=function n(e,t,r){var o=this;!function(n,e){if(!(n instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),this.setup=function(){if("undefined"!=typeof window){if(o.constructor.isSetUp)throw new Error("Cannot have two MultiBackends at the same time.");o.constructor.isSetUp=!0,o.addEventListeners(window),o.backends[o.current].instance.setup()}},this.teardown=function(){"undefined"!=typeof window&&(o.constructor.isSetUp=!1,o.removeEventListeners(window),o.backends[o.current].instance.teardown())},this.connectDragSource=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return o.connectBackend("connectDragSource",e)},this.connectDragPreview=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return o.connectBackend("connectDragPreview",e)},this.connectDropTarget=function(){for(var n=arguments.length,e=new Array(n),t=0;t<n;t++)e[t]=arguments[t];return o.connectBackend("connectDropTarget",e)},this.previewEnabled=function(){return o.backends[o.current].preview},this.addEventListeners=function(n){o.backends.forEach((function(e){e.transition&&n.addEventListener(e.transition.event,o.backendSwitcher,!0)}))},this.removeEventListeners=function(n){o.backends.forEach((function(e){e.transition&&n.removeEventListener(e.transition.event,o.backendSwitcher,!0)}))},this.backendSwitcher=function(n){var e=o.current,t=0;if(o.backends.some((function(e){return t!==o.current&&e.transition&&e.transition.check(n)?(o.current=t,!0):(t+=1,!1)})),o.current!==e){o.backends[e].instance.teardown(),Object.keys(o.nodes).forEach((function(n){var e=o.nodes[n];e.handler(),e.handler=o.callBackend(e.func,e.args)})),o.previews.backendChanged(o);var r=o.backends[o.current];if(r.instance.setup(),r.skipDispatchOnTransition)return;var i=null;try{i=new n.constructor(n.type,n)}catch(e){(i=document.createEvent("Event")).initEvent(n.type,n.bubbles,n.cancelable)}n.target.dispatchEvent(i)}},this.callBackend=function(n,e){var t;return(t=o.backends[o.current].instance)[n].apply(t,f(e))},this.connectBackend=function(n,e){var t="".concat(n,"_").concat(e[0]),r=o.callBackend(n,e);return o.nodes[t]={func:n,args:e,handler:r},function(){var n,e=(n=o.nodes[t]).handler.apply(n,arguments);return delete o.nodes[t],e}};var i=Object.assign({backends:[]},r||{});if(i.backends.length<1)throw new Error("You must specify at least one Backend, if you are coming from 2.x.x (or don't understand this error)\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-2xx");this.current=0,this.previews=new s,this.backends=[],i.backends.forEach((function(n){if(!n.backend)throw new Error("You must specify a 'backend' property in your Backend entry: ".concat(n));var r=n.transition;if(r&&!r._isMBTransition)throw new Error("You must specify a valid 'transition' property (either undefined or the return of 'createTransition') in your Backend entry: ".concat(n));o.backends.push({instance:n.backend(e,t,n.options),preview:n.preview||!1,transition:r,skipDispatchOnTransition:Boolean(n.skipDispatchOnTransition)})})),this.nodes={}};e.default=function(n,e,t){return new l(n,e,t)}}})})); |
{ | ||
"name": "dnd-multi-backend", | ||
"version": "5.1.0-rc01", | ||
"version": "5.1.1", | ||
"description": "Multi Backend system compatible with DnD Core / React DnD", | ||
@@ -5,0 +5,0 @@ "author": "Louis Brunner <louis.brunner.fr@gmail.com> (https://github.com/LouisBrunner)", |
@@ -8,4 +8,2 @@ # DnD Multi Backend [![NPM Version][npm-image]][npm-url] [![dependencies Status][deps-image]][deps-url] [![devDependencies Status][deps-dev-image]][deps-dev-url] | ||
See the [migration section](#migrating) for instructions when switching from `5.0.x`. | ||
## Installation | ||
@@ -62,3 +60,2 @@ | ||
{ | ||
id: 'html5', | ||
backend: HTML5Backend, | ||
@@ -68,3 +65,2 @@ transition: MouseTransition, | ||
{ | ||
id: 'touch', | ||
backend: TouchBackend, | ||
@@ -121,8 +117,2 @@ preview: true, | ||
## Migrating | ||
### Migrating from 5.0.x | ||
Starting with `5.1.0`, every backend in a pipeline will now need a new property called `id` and the library will warn if it isn't specified. The `MultiBackend` will try to guess it if possible, but that might fail and you will need to define them explicitly. | ||
## License | ||
@@ -129,0 +119,0 @@ |
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
33188
485
1
126