You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.8 KiB

"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; }
var isCallingCanDrop = false;
var DropTargetMonitorImpl =
/*#__PURE__*/
function () {
function DropTargetMonitorImpl(manager) {
_classCallCheck(this, DropTargetMonitorImpl);
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;