react-dnd
Version:
Drag and Drop for React
68 lines • 2.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var wrapConnectorHooks_1 = __importDefault(require("./wrapConnectorHooks"));
var shallowequal_1 = __importDefault(require("shallowequal"));
function createSourceConnector(backend) {
var currentHandlerId;
var currentDragSourceNode;
var currentDragSourceOptions;
var disconnectCurrentDragSource;
var currentDragPreviewNode;
var currentDragPreviewOptions;
var disconnectCurrentDragPreview;
function reconnectDragSource() {
if (disconnectCurrentDragSource) {
disconnectCurrentDragSource();
disconnectCurrentDragSource = undefined;
}
if (currentHandlerId && currentDragSourceNode) {
disconnectCurrentDragSource = backend.connectDragSource(currentHandlerId, currentDragSourceNode, currentDragSourceOptions);
}
}
function reconnectDragPreview() {
if (disconnectCurrentDragPreview) {
disconnectCurrentDragPreview();
disconnectCurrentDragPreview = undefined;
}
if (currentHandlerId && currentDragPreviewNode) {
disconnectCurrentDragPreview = backend.connectDragPreview(currentHandlerId, currentDragPreviewNode, currentDragPreviewOptions);
}
}
function receiveHandlerId(handlerId) {
if (handlerId === currentHandlerId) {
return;
}
currentHandlerId = handlerId;
reconnectDragSource();
reconnectDragPreview();
}
var hooks = wrapConnectorHooks_1.default({
dragSource: function connectDragSource(node, options) {
if (node === currentDragSourceNode &&
shallowequal_1.default(options, currentDragSourceOptions)) {
return;
}
currentDragSourceNode = node;
currentDragSourceOptions = options;
reconnectDragSource();
},
dragPreview: function connectDragPreview(node, options) {
if (node === currentDragPreviewNode &&
shallowequal_1.default(options, currentDragPreviewOptions)) {
return;
}
currentDragPreviewNode = node;
currentDragPreviewOptions = options;
reconnectDragPreview();
},
});
return {
receiveHandlerId: receiveHandlerId,
hooks: hooks,
};
}
exports.default = createSourceConnector;
//# sourceMappingURL=createSourceConnector.js.map