planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

View File

@@ -0,0 +1,165 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DragSourceMonitorImpl = void 0;
var _invariant = require("@react-dnd/invariant");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var isCallingCanDrag = false;
var isCallingIsDragging = false;
var DragSourceMonitorImpl = /*#__PURE__*/function () {
function DragSourceMonitorImpl(manager) {
_classCallCheck(this, DragSourceMonitorImpl);
_defineProperty(this, "internalMonitor", void 0);
_defineProperty(this, "sourceId", null);
this.internalMonitor = manager.getMonitor();
}
_createClass(DragSourceMonitorImpl, [{
key: "receiveHandlerId",
value: function receiveHandlerId(sourceId) {
this.sourceId = sourceId;
}
}, {
key: "getHandlerId",
value: function getHandlerId() {
return this.sourceId;
}
}, {
key: "canDrag",
value: function canDrag() {
(0, _invariant.invariant)(!isCallingCanDrag, 'You may not call monitor.canDrag() inside your canDrag() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
try {
isCallingCanDrag = true;
return this.internalMonitor.canDragSource(this.sourceId);
} finally {
isCallingCanDrag = false;
}
}
}, {
key: "isDragging",
value: function isDragging() {
if (!this.sourceId) {
return false;
}
(0, _invariant.invariant)(!isCallingIsDragging, 'You may not call monitor.isDragging() inside your isDragging() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
try {
isCallingIsDragging = true;
return this.internalMonitor.isDraggingSource(this.sourceId);
} finally {
isCallingIsDragging = false;
}
}
}, {
key: "subscribeToStateChange",
value: function subscribeToStateChange(listener, options) {
return this.internalMonitor.subscribeToStateChange(listener, options);
}
}, {
key: "isDraggingSource",
value: function isDraggingSource(sourceId) {
return this.internalMonitor.isDraggingSource(sourceId);
}
}, {
key: "isOverTarget",
value: function isOverTarget(targetId, options) {
return this.internalMonitor.isOverTarget(targetId, options);
}
}, {
key: "getTargetIds",
value: function getTargetIds() {
return this.internalMonitor.getTargetIds();
}
}, {
key: "isSourcePublic",
value: function isSourcePublic() {
return this.internalMonitor.isSourcePublic();
}
}, {
key: "getSourceId",
value: function getSourceId() {
return this.internalMonitor.getSourceId();
}
}, {
key: "subscribeToOffsetChange",
value: function subscribeToOffsetChange(listener) {
return this.internalMonitor.subscribeToOffsetChange(listener);
}
}, {
key: "canDragSource",
value: function canDragSource(sourceId) {
return this.internalMonitor.canDragSource(sourceId);
}
}, {
key: "canDropOnTarget",
value: function canDropOnTarget(targetId) {
return this.internalMonitor.canDropOnTarget(targetId);
}
}, {
key: "getItemType",
value: function getItemType() {
return this.internalMonitor.getItemType();
}
}, {
key: "getItem",
value: function getItem() {
return this.internalMonitor.getItem();
}
}, {
key: "getDropResult",
value: function getDropResult() {
return this.internalMonitor.getDropResult();
}
}, {
key: "didDrop",
value: function didDrop() {
return this.internalMonitor.didDrop();
}
}, {
key: "getInitialClientOffset",
value: function getInitialClientOffset() {
return this.internalMonitor.getInitialClientOffset();
}
}, {
key: "getInitialSourceClientOffset",
value: function getInitialSourceClientOffset() {
return this.internalMonitor.getInitialSourceClientOffset();
}
}, {
key: "getSourceClientOffset",
value: function getSourceClientOffset() {
return this.internalMonitor.getSourceClientOffset();
}
}, {
key: "getClientOffset",
value: function getClientOffset() {
return this.internalMonitor.getClientOffset();
}
}, {
key: "getDifferenceFromInitialOffset",
value: function getDifferenceFromInitialOffset() {
return this.internalMonitor.getDifferenceFromInitialOffset();
}
}]);
return DragSourceMonitorImpl;
}();
exports.DragSourceMonitorImpl = DragSourceMonitorImpl;

View File

@@ -0,0 +1,124 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.DropTargetMonitorImpl = void 0;
var _invariant = require("@react-dnd/invariant");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var isCallingCanDrop = false;
var DropTargetMonitorImpl = /*#__PURE__*/function () {
function DropTargetMonitorImpl(manager) {
_classCallCheck(this, DropTargetMonitorImpl);
_defineProperty(this, "internalMonitor", void 0);
_defineProperty(this, "targetId", null);
this.internalMonitor = manager.getMonitor();
}
_createClass(DropTargetMonitorImpl, [{
key: "receiveHandlerId",
value: function receiveHandlerId(targetId) {
this.targetId = targetId;
}
}, {
key: "getHandlerId",
value: function getHandlerId() {
return this.targetId;
}
}, {
key: "subscribeToStateChange",
value: function subscribeToStateChange(listener, options) {
return this.internalMonitor.subscribeToStateChange(listener, options);
}
}, {
key: "canDrop",
value: function canDrop() {
// Cut out early if the target id has not been set. This should prevent errors
// where the user has an older version of dnd-core like in
// https://github.com/react-dnd/react-dnd/issues/1310
if (!this.targetId) {
return false;
}
(0, _invariant.invariant)(!isCallingCanDrop, 'You may not call monitor.canDrop() inside your canDrop() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target-monitor');
try {
isCallingCanDrop = true;
return this.internalMonitor.canDropOnTarget(this.targetId);
} finally {
isCallingCanDrop = false;
}
}
}, {
key: "isOver",
value: function isOver(options) {
if (!this.targetId) {
return false;
}
return this.internalMonitor.isOverTarget(this.targetId, options);
}
}, {
key: "getItemType",
value: function getItemType() {
return this.internalMonitor.getItemType();
}
}, {
key: "getItem",
value: function getItem() {
return this.internalMonitor.getItem();
}
}, {
key: "getDropResult",
value: function getDropResult() {
return this.internalMonitor.getDropResult();
}
}, {
key: "didDrop",
value: function didDrop() {
return this.internalMonitor.didDrop();
}
}, {
key: "getInitialClientOffset",
value: function getInitialClientOffset() {
return this.internalMonitor.getInitialClientOffset();
}
}, {
key: "getInitialSourceClientOffset",
value: function getInitialSourceClientOffset() {
return this.internalMonitor.getInitialSourceClientOffset();
}
}, {
key: "getSourceClientOffset",
value: function getSourceClientOffset() {
return this.internalMonitor.getSourceClientOffset();
}
}, {
key: "getClientOffset",
value: function getClientOffset() {
return this.internalMonitor.getClientOffset();
}
}, {
key: "getDifferenceFromInitialOffset",
value: function getDifferenceFromInitialOffset() {
return this.internalMonitor.getDifferenceFromInitialOffset();
}
}]);
return DropTargetMonitorImpl;
}();
exports.DropTargetMonitorImpl = DropTargetMonitorImpl;

View File

@@ -0,0 +1,253 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SourceConnector = void 0;
var _wrapConnectorHooks = require("./wrapConnectorHooks");
var _isRef = require("./isRef");
var _shallowequal = require("@react-dnd/shallowequal");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var SourceConnector = /*#__PURE__*/function () {
// The drop target may either be attached via ref or connect function
// The drag preview may either be attached via ref or connect function
function SourceConnector(backend) {
var _this = this;
_classCallCheck(this, SourceConnector);
_defineProperty(this, "hooks", (0, _wrapConnectorHooks.wrapConnectorHooks)({
dragSource: function dragSource(node, options) {
_this.clearDragSource();
_this.dragSourceOptions = options || null;
if ((0, _isRef.isRef)(node)) {
_this.dragSourceRef = node;
} else {
_this.dragSourceNode = node;
}
_this.reconnectDragSource();
},
dragPreview: function dragPreview(node, options) {
_this.clearDragPreview();
_this.dragPreviewOptions = options || null;
if ((0, _isRef.isRef)(node)) {
_this.dragPreviewRef = node;
} else {
_this.dragPreviewNode = node;
}
_this.reconnectDragPreview();
}
}));
_defineProperty(this, "handlerId", null);
_defineProperty(this, "dragSourceRef", null);
_defineProperty(this, "dragSourceNode", void 0);
_defineProperty(this, "dragSourceOptionsInternal", null);
_defineProperty(this, "dragSourceUnsubscribe", void 0);
_defineProperty(this, "dragPreviewRef", null);
_defineProperty(this, "dragPreviewNode", void 0);
_defineProperty(this, "dragPreviewOptionsInternal", null);
_defineProperty(this, "dragPreviewUnsubscribe", void 0);
_defineProperty(this, "lastConnectedHandlerId", null);
_defineProperty(this, "lastConnectedDragSource", null);
_defineProperty(this, "lastConnectedDragSourceOptions", null);
_defineProperty(this, "lastConnectedDragPreview", null);
_defineProperty(this, "lastConnectedDragPreviewOptions", null);
_defineProperty(this, "backend", void 0);
this.backend = backend;
}
_createClass(SourceConnector, [{
key: "receiveHandlerId",
value: function receiveHandlerId(newHandlerId) {
if (this.handlerId === newHandlerId) {
return;
}
this.handlerId = newHandlerId;
this.reconnect();
}
}, {
key: "connectTarget",
get: function get() {
return this.dragSource;
}
}, {
key: "dragSourceOptions",
get: function get() {
return this.dragSourceOptionsInternal;
},
set: function set(options) {
this.dragSourceOptionsInternal = options;
}
}, {
key: "dragPreviewOptions",
get: function get() {
return this.dragPreviewOptionsInternal;
},
set: function set(options) {
this.dragPreviewOptionsInternal = options;
}
}, {
key: "reconnect",
value: function reconnect() {
this.reconnectDragSource();
this.reconnectDragPreview();
}
}, {
key: "reconnectDragSource",
value: function reconnectDragSource() {
var dragSource = this.dragSource; // if nothing has changed then don't resubscribe
var didChange = this.didHandlerIdChange() || this.didConnectedDragSourceChange() || this.didDragSourceOptionsChange();
if (didChange) {
this.disconnectDragSource();
}
if (!this.handlerId) {
return;
}
if (!dragSource) {
this.lastConnectedDragSource = dragSource;
return;
}
if (didChange) {
this.lastConnectedHandlerId = this.handlerId;
this.lastConnectedDragSource = dragSource;
this.lastConnectedDragSourceOptions = this.dragSourceOptions;
this.dragSourceUnsubscribe = this.backend.connectDragSource(this.handlerId, dragSource, this.dragSourceOptions);
}
}
}, {
key: "reconnectDragPreview",
value: function reconnectDragPreview() {
var dragPreview = this.dragPreview; // if nothing has changed then don't resubscribe
var didChange = this.didHandlerIdChange() || this.didConnectedDragPreviewChange() || this.didDragPreviewOptionsChange();
if (didChange) {
this.disconnectDragPreview();
}
if (!this.handlerId) {
return;
}
if (!dragPreview) {
this.lastConnectedDragPreview = dragPreview;
return;
}
if (didChange) {
this.lastConnectedHandlerId = this.handlerId;
this.lastConnectedDragPreview = dragPreview;
this.lastConnectedDragPreviewOptions = this.dragPreviewOptions;
this.dragPreviewUnsubscribe = this.backend.connectDragPreview(this.handlerId, dragPreview, this.dragPreviewOptions);
}
}
}, {
key: "didHandlerIdChange",
value: function didHandlerIdChange() {
return this.lastConnectedHandlerId !== this.handlerId;
}
}, {
key: "didConnectedDragSourceChange",
value: function didConnectedDragSourceChange() {
return this.lastConnectedDragSource !== this.dragSource;
}
}, {
key: "didConnectedDragPreviewChange",
value: function didConnectedDragPreviewChange() {
return this.lastConnectedDragPreview !== this.dragPreview;
}
}, {
key: "didDragSourceOptionsChange",
value: function didDragSourceOptionsChange() {
return !(0, _shallowequal.shallowEqual)(this.lastConnectedDragSourceOptions, this.dragSourceOptions);
}
}, {
key: "didDragPreviewOptionsChange",
value: function didDragPreviewOptionsChange() {
return !(0, _shallowequal.shallowEqual)(this.lastConnectedDragPreviewOptions, this.dragPreviewOptions);
}
}, {
key: "disconnectDragSource",
value: function disconnectDragSource() {
if (this.dragSourceUnsubscribe) {
this.dragSourceUnsubscribe();
this.dragSourceUnsubscribe = undefined;
}
}
}, {
key: "disconnectDragPreview",
value: function disconnectDragPreview() {
if (this.dragPreviewUnsubscribe) {
this.dragPreviewUnsubscribe();
this.dragPreviewUnsubscribe = undefined;
this.dragPreviewNode = null;
this.dragPreviewRef = null;
}
}
}, {
key: "dragSource",
get: function get() {
return this.dragSourceNode || this.dragSourceRef && this.dragSourceRef.current;
}
}, {
key: "dragPreview",
get: function get() {
return this.dragPreviewNode || this.dragPreviewRef && this.dragPreviewRef.current;
}
}, {
key: "clearDragSource",
value: function clearDragSource() {
this.dragSourceNode = null;
this.dragSourceRef = null;
}
}, {
key: "clearDragPreview",
value: function clearDragPreview() {
this.dragPreviewNode = null;
this.dragPreviewRef = null;
}
}]);
return SourceConnector;
}();
exports.SourceConnector = SourceConnector;

View File

@@ -0,0 +1,156 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TargetConnector = void 0;
var _shallowequal = require("@react-dnd/shallowequal");
var _wrapConnectorHooks = require("./wrapConnectorHooks");
var _isRef = require("./isRef");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
var TargetConnector = /*#__PURE__*/function () {
// The drop target may either be attached via ref or connect function
function TargetConnector(backend) {
var _this = this;
_classCallCheck(this, TargetConnector);
_defineProperty(this, "hooks", (0, _wrapConnectorHooks.wrapConnectorHooks)({
dropTarget: function dropTarget(node, options) {
_this.clearDropTarget();
_this.dropTargetOptions = options;
if ((0, _isRef.isRef)(node)) {
_this.dropTargetRef = node;
} else {
_this.dropTargetNode = node;
}
_this.reconnect();
}
}));
_defineProperty(this, "handlerId", null);
_defineProperty(this, "dropTargetRef", null);
_defineProperty(this, "dropTargetNode", void 0);
_defineProperty(this, "dropTargetOptionsInternal", null);
_defineProperty(this, "unsubscribeDropTarget", void 0);
_defineProperty(this, "lastConnectedHandlerId", null);
_defineProperty(this, "lastConnectedDropTarget", null);
_defineProperty(this, "lastConnectedDropTargetOptions", null);
_defineProperty(this, "backend", void 0);
this.backend = backend;
}
_createClass(TargetConnector, [{
key: "connectTarget",
get: function get() {
return this.dropTarget;
}
}, {
key: "reconnect",
value: function reconnect() {
// if nothing has changed then don't resubscribe
var didChange = this.didHandlerIdChange() || this.didDropTargetChange() || this.didOptionsChange();
if (didChange) {
this.disconnectDropTarget();
}
var dropTarget = this.dropTarget;
if (!this.handlerId) {
return;
}
if (!dropTarget) {
this.lastConnectedDropTarget = dropTarget;
return;
}
if (didChange) {
this.lastConnectedHandlerId = this.handlerId;
this.lastConnectedDropTarget = dropTarget;
this.lastConnectedDropTargetOptions = this.dropTargetOptions;
this.unsubscribeDropTarget = this.backend.connectDropTarget(this.handlerId, dropTarget, this.dropTargetOptions);
}
}
}, {
key: "receiveHandlerId",
value: function receiveHandlerId(newHandlerId) {
if (newHandlerId === this.handlerId) {
return;
}
this.handlerId = newHandlerId;
this.reconnect();
}
}, {
key: "dropTargetOptions",
get: function get() {
return this.dropTargetOptionsInternal;
},
set: function set(options) {
this.dropTargetOptionsInternal = options;
}
}, {
key: "didHandlerIdChange",
value: function didHandlerIdChange() {
return this.lastConnectedHandlerId !== this.handlerId;
}
}, {
key: "didDropTargetChange",
value: function didDropTargetChange() {
return this.lastConnectedDropTarget !== this.dropTarget;
}
}, {
key: "didOptionsChange",
value: function didOptionsChange() {
return !(0, _shallowequal.shallowEqual)(this.lastConnectedDropTargetOptions, this.dropTargetOptions);
}
}, {
key: "disconnectDropTarget",
value: function disconnectDropTarget() {
if (this.unsubscribeDropTarget) {
this.unsubscribeDropTarget();
this.unsubscribeDropTarget = undefined;
}
}
}, {
key: "dropTarget",
get: function get() {
return this.dropTargetNode || this.dropTargetRef && this.dropTargetRef.current;
}
}, {
key: "clearDropTarget",
value: function clearDropTarget() {
this.dropTargetRef = null;
this.dropTargetNode = null;
}
}]);
return TargetConnector;
}();
exports.TargetConnector = TargetConnector;

70
node_modules/react-dnd/dist/cjs/internals/index.js generated vendored Normal file
View File

@@ -0,0 +1,70 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _DragSourceMonitorImpl = require("./DragSourceMonitorImpl");
Object.keys(_DragSourceMonitorImpl).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _DragSourceMonitorImpl[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _DragSourceMonitorImpl[key];
}
});
});
var _DropTargetMonitorImpl = require("./DropTargetMonitorImpl");
Object.keys(_DropTargetMonitorImpl).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _DropTargetMonitorImpl[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _DropTargetMonitorImpl[key];
}
});
});
var _SourceConnector = require("./SourceConnector");
Object.keys(_SourceConnector).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _SourceConnector[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _SourceConnector[key];
}
});
});
var _TargetConnector = require("./TargetConnector");
Object.keys(_TargetConnector).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _TargetConnector[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _TargetConnector[key];
}
});
});
var _registration = require("./registration");
Object.keys(_registration).forEach(function (key) {
if (key === "default" || key === "__esModule") return;
if (key in exports && exports[key] === _registration[key]) return;
Object.defineProperty(exports, key, {
enumerable: true,
get: function get() {
return _registration[key];
}
});
});

14
node_modules/react-dnd/dist/cjs/internals/isRef.js generated vendored Normal file
View File

@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isRef = isRef;
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function isRef(obj) {
return (// eslint-disable-next-line no-prototype-builtins
obj !== null && _typeof(obj) === 'object' && Object.prototype.hasOwnProperty.call(obj, 'current')
);
}

View File

@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.registerTarget = registerTarget;
exports.registerSource = registerSource;
function registerTarget(type, target, manager) {
var registry = manager.getRegistry();
var targetId = registry.addTarget(type, target);
return [targetId, function () {
return registry.removeTarget(targetId);
}];
}
function registerSource(type, source, manager) {
var registry = manager.getRegistry();
var sourceId = registry.addSource(type, source);
return [sourceId, function () {
return registry.removeSource(sourceId);
}];
}

View File

@@ -0,0 +1,93 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.wrapConnectorHooks = wrapConnectorHooks;
var _invariant = require("@react-dnd/invariant");
var _react = require("react");
function throwIfCompositeComponentElement(element) {
// Custom components can no longer be wrapped directly in React DnD 2.0
// so that we don't need to depend on findDOMNode() from react-dom.
if (typeof element.type === 'string') {
return;
}
var displayName = element.type.displayName || element.type.name || 'the component';
throw new Error('Only native element nodes can now be passed to React DnD connectors.' + "You can either wrap ".concat(displayName, " into a <div>, or turn it into a ") + 'drag source or a drop target itself.');
}
function wrapHookToRecognizeElement(hook) {
return function () {
var elementOrNode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
// When passed a node, call the hook straight away.
if (!(0, _react.isValidElement)(elementOrNode)) {
var node = elementOrNode;
hook(node, options); // return the node so it can be chained (e.g. when within callback refs
// <div ref={node => connectDragSource(connectDropTarget(node))}/>
return node;
} // If passed a ReactElement, clone it and attach this function as a ref.
// This helps us achieve a neat API where user doesn't even know that refs
// are being used under the hood.
var element = elementOrNode;
throwIfCompositeComponentElement(element); // When no options are passed, use the hook directly
var ref = options ? function (node) {
return hook(node, options);
} : hook;
return cloneWithRef(element, ref);
};
}
function wrapConnectorHooks(hooks) {
var wrappedHooks = {};
Object.keys(hooks).forEach(function (key) {
var hook = hooks[key]; // ref objects should be passed straight through without wrapping
if (key.endsWith('Ref')) {
wrappedHooks[key] = hooks[key];
} else {
var wrappedHook = wrapHookToRecognizeElement(hook);
wrappedHooks[key] = function () {
return wrappedHook;
};
}
});
return wrappedHooks;
}
function setRef(ref, node) {
if (typeof ref === 'function') {
ref(node);
} else {
ref.current = node;
}
}
function cloneWithRef(element, newRef) {
var previousRef = element.ref;
(0, _invariant.invariant)(typeof previousRef !== 'string', 'Cannot connect React DnD to an element with an existing string ref. ' + 'Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. ' + 'Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs');
if (!previousRef) {
// When there is no ref on the element, use the new ref directly
return (0, _react.cloneElement)(element, {
ref: newRef
});
} else {
return (0, _react.cloneElement)(element, {
ref: function ref(node) {
setRef(previousRef, node);
setRef(newRef, node);
}
});
}
}