This commit is contained in:
68
node_modules/react-dnd/lib/internals/DropTargetMonitorImpl.js
generated
vendored
Normal file
68
node_modules/react-dnd/lib/internals/DropTargetMonitorImpl.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
let isCallingCanDrop = false;
|
||||
export class DropTargetMonitorImpl {
|
||||
internalMonitor;
|
||||
targetId = null;
|
||||
constructor(manager) {
|
||||
this.internalMonitor = manager.getMonitor();
|
||||
}
|
||||
receiveHandlerId(targetId) {
|
||||
this.targetId = targetId;
|
||||
}
|
||||
getHandlerId() {
|
||||
return this.targetId;
|
||||
}
|
||||
subscribeToStateChange(listener, options) {
|
||||
return this.internalMonitor.subscribeToStateChange(listener, options);
|
||||
}
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
isOver(options) {
|
||||
if (!this.targetId) {
|
||||
return false;
|
||||
}
|
||||
return this.internalMonitor.isOverTarget(this.targetId, options);
|
||||
}
|
||||
getItemType() {
|
||||
return this.internalMonitor.getItemType();
|
||||
}
|
||||
getItem() {
|
||||
return this.internalMonitor.getItem();
|
||||
}
|
||||
getDropResult() {
|
||||
return this.internalMonitor.getDropResult();
|
||||
}
|
||||
didDrop() {
|
||||
return this.internalMonitor.didDrop();
|
||||
}
|
||||
getInitialClientOffset() {
|
||||
return this.internalMonitor.getInitialClientOffset();
|
||||
}
|
||||
getInitialSourceClientOffset() {
|
||||
return this.internalMonitor.getInitialSourceClientOffset();
|
||||
}
|
||||
getSourceClientOffset() {
|
||||
return this.internalMonitor.getSourceClientOffset();
|
||||
}
|
||||
getClientOffset() {
|
||||
return this.internalMonitor.getClientOffset();
|
||||
}
|
||||
getDifferenceFromInitialOffset() {
|
||||
return this.internalMonitor.getDifferenceFromInitialOffset();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user