This commit is contained in:
101
node_modules/dnd-core/dist/esm/classes/DragDropManagerImpl.js
generated
vendored
Normal file
101
node_modules/dnd-core/dist/esm/classes/DragDropManagerImpl.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
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; }
|
||||
|
||||
import { createDragDropActions } from '../actions/dragDrop';
|
||||
export var DragDropManagerImpl = /*#__PURE__*/function () {
|
||||
function DragDropManagerImpl(store, monitor) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, DragDropManagerImpl);
|
||||
|
||||
_defineProperty(this, "store", void 0);
|
||||
|
||||
_defineProperty(this, "monitor", void 0);
|
||||
|
||||
_defineProperty(this, "backend", void 0);
|
||||
|
||||
_defineProperty(this, "isSetUp", false);
|
||||
|
||||
_defineProperty(this, "handleRefCountChange", function () {
|
||||
var shouldSetUp = _this.store.getState().refCount > 0;
|
||||
|
||||
if (_this.backend) {
|
||||
if (shouldSetUp && !_this.isSetUp) {
|
||||
_this.backend.setup();
|
||||
|
||||
_this.isSetUp = true;
|
||||
} else if (!shouldSetUp && _this.isSetUp) {
|
||||
_this.backend.teardown();
|
||||
|
||||
_this.isSetUp = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.store = store;
|
||||
this.monitor = monitor;
|
||||
store.subscribe(this.handleRefCountChange);
|
||||
}
|
||||
|
||||
_createClass(DragDropManagerImpl, [{
|
||||
key: "receiveBackend",
|
||||
value: function receiveBackend(backend) {
|
||||
this.backend = backend;
|
||||
}
|
||||
}, {
|
||||
key: "getMonitor",
|
||||
value: function getMonitor() {
|
||||
return this.monitor;
|
||||
}
|
||||
}, {
|
||||
key: "getBackend",
|
||||
value: function getBackend() {
|
||||
return this.backend;
|
||||
}
|
||||
}, {
|
||||
key: "getRegistry",
|
||||
value: function getRegistry() {
|
||||
return this.monitor.registry;
|
||||
}
|
||||
}, {
|
||||
key: "getActions",
|
||||
value: function getActions() {
|
||||
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
|
||||
var manager = this;
|
||||
var dispatch = this.store.dispatch;
|
||||
|
||||
function bindActionCreator(actionCreator) {
|
||||
return function () {
|
||||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
args[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
var action = actionCreator.apply(manager, args);
|
||||
|
||||
if (typeof action !== 'undefined') {
|
||||
dispatch(action);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var actions = createDragDropActions(this);
|
||||
return Object.keys(actions).reduce(function (boundActions, key) {
|
||||
var action = actions[key];
|
||||
boundActions[key] = bindActionCreator(action);
|
||||
return boundActions;
|
||||
}, {});
|
||||
}
|
||||
}, {
|
||||
key: "dispatch",
|
||||
value: function dispatch(action) {
|
||||
this.store.dispatch(action);
|
||||
}
|
||||
}]);
|
||||
|
||||
return DragDropManagerImpl;
|
||||
}();
|
||||
243
node_modules/dnd-core/dist/esm/classes/DragDropMonitorImpl.js
generated
vendored
Normal file
243
node_modules/dnd-core/dist/esm/classes/DragDropMonitorImpl.js
generated
vendored
Normal file
@@ -0,0 +1,243 @@
|
||||
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; }
|
||||
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { matchesType } from '../utils/matchesType';
|
||||
import { getSourceClientOffset as _getSourceClientOffset, getDifferenceFromInitialOffset as _getDifferenceFromInitialOffset } from '../utils/coords';
|
||||
import { areDirty } from '../utils/dirtiness';
|
||||
export var DragDropMonitorImpl = /*#__PURE__*/function () {
|
||||
function DragDropMonitorImpl(store, registry) {
|
||||
_classCallCheck(this, DragDropMonitorImpl);
|
||||
|
||||
_defineProperty(this, "store", void 0);
|
||||
|
||||
_defineProperty(this, "registry", void 0);
|
||||
|
||||
this.store = store;
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
_createClass(DragDropMonitorImpl, [{
|
||||
key: "subscribeToStateChange",
|
||||
value: function subscribeToStateChange(listener) {
|
||||
var _this = this;
|
||||
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
||||
handlerIds: undefined
|
||||
};
|
||||
var handlerIds = options.handlerIds;
|
||||
invariant(typeof listener === 'function', 'listener must be a function.');
|
||||
invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.');
|
||||
var prevStateId = this.store.getState().stateId;
|
||||
|
||||
var handleChange = function handleChange() {
|
||||
var state = _this.store.getState();
|
||||
|
||||
var currentStateId = state.stateId;
|
||||
|
||||
try {
|
||||
var canSkipListener = currentStateId === prevStateId || currentStateId === prevStateId + 1 && !areDirty(state.dirtyHandlerIds, handlerIds);
|
||||
|
||||
if (!canSkipListener) {
|
||||
listener();
|
||||
}
|
||||
} finally {
|
||||
prevStateId = currentStateId;
|
||||
}
|
||||
};
|
||||
|
||||
return this.store.subscribe(handleChange);
|
||||
}
|
||||
}, {
|
||||
key: "subscribeToOffsetChange",
|
||||
value: function subscribeToOffsetChange(listener) {
|
||||
var _this2 = this;
|
||||
|
||||
invariant(typeof listener === 'function', 'listener must be a function.');
|
||||
var previousState = this.store.getState().dragOffset;
|
||||
|
||||
var handleChange = function handleChange() {
|
||||
var nextState = _this2.store.getState().dragOffset;
|
||||
|
||||
if (nextState === previousState) {
|
||||
return;
|
||||
}
|
||||
|
||||
previousState = nextState;
|
||||
listener();
|
||||
};
|
||||
|
||||
return this.store.subscribe(handleChange);
|
||||
}
|
||||
}, {
|
||||
key: "canDragSource",
|
||||
value: function canDragSource(sourceId) {
|
||||
if (!sourceId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var source = this.registry.getSource(sourceId);
|
||||
invariant(source, "Expected to find a valid source. sourceId=".concat(sourceId));
|
||||
|
||||
if (this.isDragging()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return source.canDrag(this, sourceId);
|
||||
}
|
||||
}, {
|
||||
key: "canDropOnTarget",
|
||||
value: function canDropOnTarget(targetId) {
|
||||
// undefined on initial render
|
||||
if (!targetId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var target = this.registry.getTarget(targetId);
|
||||
invariant(target, "Expected to find a valid target. targetId=".concat(targetId));
|
||||
|
||||
if (!this.isDragging() || this.didDrop()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var targetType = this.registry.getTargetType(targetId);
|
||||
var draggedItemType = this.getItemType();
|
||||
return matchesType(targetType, draggedItemType) && target.canDrop(this, targetId);
|
||||
}
|
||||
}, {
|
||||
key: "isDragging",
|
||||
value: function isDragging() {
|
||||
return Boolean(this.getItemType());
|
||||
}
|
||||
}, {
|
||||
key: "isDraggingSource",
|
||||
value: function isDraggingSource(sourceId) {
|
||||
// undefined on initial render
|
||||
if (!sourceId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var source = this.registry.getSource(sourceId, true);
|
||||
invariant(source, "Expected to find a valid source. sourceId=".concat(sourceId));
|
||||
|
||||
if (!this.isDragging() || !this.isSourcePublic()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var sourceType = this.registry.getSourceType(sourceId);
|
||||
var draggedItemType = this.getItemType();
|
||||
|
||||
if (sourceType !== draggedItemType) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return source.isDragging(this, sourceId);
|
||||
}
|
||||
}, {
|
||||
key: "isOverTarget",
|
||||
value: function isOverTarget(targetId) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
|
||||
shallow: false
|
||||
};
|
||||
|
||||
// undefined on initial render
|
||||
if (!targetId) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var shallow = options.shallow;
|
||||
|
||||
if (!this.isDragging()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var targetType = this.registry.getTargetType(targetId);
|
||||
var draggedItemType = this.getItemType();
|
||||
|
||||
if (draggedItemType && !matchesType(targetType, draggedItemType)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var targetIds = this.getTargetIds();
|
||||
|
||||
if (!targetIds.length) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var index = targetIds.indexOf(targetId);
|
||||
|
||||
if (shallow) {
|
||||
return index === targetIds.length - 1;
|
||||
} else {
|
||||
return index > -1;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "getItemType",
|
||||
value: function getItemType() {
|
||||
return this.store.getState().dragOperation.itemType;
|
||||
}
|
||||
}, {
|
||||
key: "getItem",
|
||||
value: function getItem() {
|
||||
return this.store.getState().dragOperation.item;
|
||||
}
|
||||
}, {
|
||||
key: "getSourceId",
|
||||
value: function getSourceId() {
|
||||
return this.store.getState().dragOperation.sourceId;
|
||||
}
|
||||
}, {
|
||||
key: "getTargetIds",
|
||||
value: function getTargetIds() {
|
||||
return this.store.getState().dragOperation.targetIds;
|
||||
}
|
||||
}, {
|
||||
key: "getDropResult",
|
||||
value: function getDropResult() {
|
||||
return this.store.getState().dragOperation.dropResult;
|
||||
}
|
||||
}, {
|
||||
key: "didDrop",
|
||||
value: function didDrop() {
|
||||
return this.store.getState().dragOperation.didDrop;
|
||||
}
|
||||
}, {
|
||||
key: "isSourcePublic",
|
||||
value: function isSourcePublic() {
|
||||
return Boolean(this.store.getState().dragOperation.isSourcePublic);
|
||||
}
|
||||
}, {
|
||||
key: "getInitialClientOffset",
|
||||
value: function getInitialClientOffset() {
|
||||
return this.store.getState().dragOffset.initialClientOffset;
|
||||
}
|
||||
}, {
|
||||
key: "getInitialSourceClientOffset",
|
||||
value: function getInitialSourceClientOffset() {
|
||||
return this.store.getState().dragOffset.initialSourceClientOffset;
|
||||
}
|
||||
}, {
|
||||
key: "getClientOffset",
|
||||
value: function getClientOffset() {
|
||||
return this.store.getState().dragOffset.clientOffset;
|
||||
}
|
||||
}, {
|
||||
key: "getSourceClientOffset",
|
||||
value: function getSourceClientOffset() {
|
||||
return _getSourceClientOffset(this.store.getState().dragOffset);
|
||||
}
|
||||
}, {
|
||||
key: "getDifferenceFromInitialOffset",
|
||||
value: function getDifferenceFromInitialOffset() {
|
||||
return _getDifferenceFromInitialOffset(this.store.getState().dragOffset);
|
||||
}
|
||||
}]);
|
||||
|
||||
return DragDropMonitorImpl;
|
||||
}();
|
||||
210
node_modules/dnd-core/dist/esm/classes/HandlerRegistryImpl.js
generated
vendored
Normal file
210
node_modules/dnd-core/dist/esm/classes/HandlerRegistryImpl.js
generated
vendored
Normal file
@@ -0,0 +1,210 @@
|
||||
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; }
|
||||
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
||||
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
||||
|
||||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
||||
|
||||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
||||
|
||||
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { addSource as _addSource, addTarget as _addTarget, removeSource as _removeSource, removeTarget as _removeTarget } from '../actions/registry';
|
||||
import { getNextUniqueId } from '../utils/getNextUniqueId';
|
||||
import { HandlerRole } from '../interfaces';
|
||||
import { validateSourceContract, validateTargetContract, validateType } from '../contracts';
|
||||
import { asap } from '@react-dnd/asap';
|
||||
|
||||
function getNextHandlerId(role) {
|
||||
var id = getNextUniqueId().toString();
|
||||
|
||||
switch (role) {
|
||||
case HandlerRole.SOURCE:
|
||||
return "S".concat(id);
|
||||
|
||||
case HandlerRole.TARGET:
|
||||
return "T".concat(id);
|
||||
|
||||
default:
|
||||
throw new Error("Unknown Handler Role: ".concat(role));
|
||||
}
|
||||
}
|
||||
|
||||
function parseRoleFromHandlerId(handlerId) {
|
||||
switch (handlerId[0]) {
|
||||
case 'S':
|
||||
return HandlerRole.SOURCE;
|
||||
|
||||
case 'T':
|
||||
return HandlerRole.TARGET;
|
||||
|
||||
default:
|
||||
invariant(false, "Cannot parse handler ID: ".concat(handlerId));
|
||||
}
|
||||
}
|
||||
|
||||
function mapContainsValue(map, searchValue) {
|
||||
var entries = map.entries();
|
||||
var isDone = false;
|
||||
|
||||
do {
|
||||
var _entries$next = entries.next(),
|
||||
done = _entries$next.done,
|
||||
_entries$next$value = _slicedToArray(_entries$next.value, 2),
|
||||
value = _entries$next$value[1];
|
||||
|
||||
if (value === searchValue) {
|
||||
return true;
|
||||
}
|
||||
|
||||
isDone = !!done;
|
||||
} while (!isDone);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export var HandlerRegistryImpl = /*#__PURE__*/function () {
|
||||
function HandlerRegistryImpl(store) {
|
||||
_classCallCheck(this, HandlerRegistryImpl);
|
||||
|
||||
_defineProperty(this, "types", new Map());
|
||||
|
||||
_defineProperty(this, "dragSources", new Map());
|
||||
|
||||
_defineProperty(this, "dropTargets", new Map());
|
||||
|
||||
_defineProperty(this, "pinnedSourceId", null);
|
||||
|
||||
_defineProperty(this, "pinnedSource", null);
|
||||
|
||||
_defineProperty(this, "store", void 0);
|
||||
|
||||
this.store = store;
|
||||
}
|
||||
|
||||
_createClass(HandlerRegistryImpl, [{
|
||||
key: "addSource",
|
||||
value: function addSource(type, source) {
|
||||
validateType(type);
|
||||
validateSourceContract(source);
|
||||
var sourceId = this.addHandler(HandlerRole.SOURCE, type, source);
|
||||
this.store.dispatch(_addSource(sourceId));
|
||||
return sourceId;
|
||||
}
|
||||
}, {
|
||||
key: "addTarget",
|
||||
value: function addTarget(type, target) {
|
||||
validateType(type, true);
|
||||
validateTargetContract(target);
|
||||
var targetId = this.addHandler(HandlerRole.TARGET, type, target);
|
||||
this.store.dispatch(_addTarget(targetId));
|
||||
return targetId;
|
||||
}
|
||||
}, {
|
||||
key: "containsHandler",
|
||||
value: function containsHandler(handler) {
|
||||
return mapContainsValue(this.dragSources, handler) || mapContainsValue(this.dropTargets, handler);
|
||||
}
|
||||
}, {
|
||||
key: "getSource",
|
||||
value: function getSource(sourceId) {
|
||||
var includePinned = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
||||
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
|
||||
var isPinned = includePinned && sourceId === this.pinnedSourceId;
|
||||
var source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId);
|
||||
return source;
|
||||
}
|
||||
}, {
|
||||
key: "getTarget",
|
||||
value: function getTarget(targetId) {
|
||||
invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
|
||||
return this.dropTargets.get(targetId);
|
||||
}
|
||||
}, {
|
||||
key: "getSourceType",
|
||||
value: function getSourceType(sourceId) {
|
||||
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
|
||||
return this.types.get(sourceId);
|
||||
}
|
||||
}, {
|
||||
key: "getTargetType",
|
||||
value: function getTargetType(targetId) {
|
||||
invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
|
||||
return this.types.get(targetId);
|
||||
}
|
||||
}, {
|
||||
key: "isSourceId",
|
||||
value: function isSourceId(handlerId) {
|
||||
var role = parseRoleFromHandlerId(handlerId);
|
||||
return role === HandlerRole.SOURCE;
|
||||
}
|
||||
}, {
|
||||
key: "isTargetId",
|
||||
value: function isTargetId(handlerId) {
|
||||
var role = parseRoleFromHandlerId(handlerId);
|
||||
return role === HandlerRole.TARGET;
|
||||
}
|
||||
}, {
|
||||
key: "removeSource",
|
||||
value: function removeSource(sourceId) {
|
||||
var _this = this;
|
||||
|
||||
invariant(this.getSource(sourceId), 'Expected an existing source.');
|
||||
this.store.dispatch(_removeSource(sourceId));
|
||||
asap(function () {
|
||||
_this.dragSources.delete(sourceId);
|
||||
|
||||
_this.types.delete(sourceId);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "removeTarget",
|
||||
value: function removeTarget(targetId) {
|
||||
invariant(this.getTarget(targetId), 'Expected an existing target.');
|
||||
this.store.dispatch(_removeTarget(targetId));
|
||||
this.dropTargets.delete(targetId);
|
||||
this.types.delete(targetId);
|
||||
}
|
||||
}, {
|
||||
key: "pinSource",
|
||||
value: function pinSource(sourceId) {
|
||||
var source = this.getSource(sourceId);
|
||||
invariant(source, 'Expected an existing source.');
|
||||
this.pinnedSourceId = sourceId;
|
||||
this.pinnedSource = source;
|
||||
}
|
||||
}, {
|
||||
key: "unpinSource",
|
||||
value: function unpinSource() {
|
||||
invariant(this.pinnedSource, 'No source is pinned at the time.');
|
||||
this.pinnedSourceId = null;
|
||||
this.pinnedSource = null;
|
||||
}
|
||||
}, {
|
||||
key: "addHandler",
|
||||
value: function addHandler(role, type, handler) {
|
||||
var id = getNextHandlerId(role);
|
||||
this.types.set(id, type);
|
||||
|
||||
if (role === HandlerRole.SOURCE) {
|
||||
this.dragSources.set(id, handler);
|
||||
} else if (role === HandlerRole.TARGET) {
|
||||
this.dropTargets.set(id, handler);
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
}]);
|
||||
|
||||
return HandlerRegistryImpl;
|
||||
}();
|
||||
Reference in New Issue
Block a user