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,51 @@
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; }
export var DropTargetImpl = /*#__PURE__*/function () {
function DropTargetImpl(spec, monitor) {
_classCallCheck(this, DropTargetImpl);
_defineProperty(this, "spec", void 0);
_defineProperty(this, "monitor", void 0);
this.spec = spec;
this.monitor = monitor;
}
_createClass(DropTargetImpl, [{
key: "canDrop",
value: function canDrop() {
var spec = this.spec;
var monitor = this.monitor;
return spec.canDrop ? spec.canDrop(monitor.getItem(), monitor) : true;
}
}, {
key: "hover",
value: function hover() {
var spec = this.spec;
var monitor = this.monitor;
if (spec.hover) {
spec.hover(monitor.getItem(), monitor);
}
}
}, {
key: "drop",
value: function drop() {
var spec = this.spec;
var monitor = this.monitor;
if (spec.drop) {
return spec.drop(monitor.getItem(), monitor);
}
}
}]);
return DropTargetImpl;
}();

View File

@@ -0,0 +1,6 @@
import { useMemo } from 'react';
export function useConnectDropTarget(connector) {
return useMemo(function () {
return connector.hooks.dropTarget();
}, [connector]);
}

View File

@@ -0,0 +1 @@
export * from './useDrop';

View File

@@ -0,0 +1,15 @@
import { invariant } from '@react-dnd/invariant';
import { useMemo } from 'react';
/**
* Internal utility hook to get an array-version of spec.accept.
* The main utility here is that we aren't creating a new array on every render if a non-array spec.accept is passed in.
* @param spec
*/
export function useAccept(spec) {
var accept = spec.accept;
return useMemo(function () {
invariant(spec.accept != null, 'accept must be defined');
return Array.isArray(accept) ? accept : [accept];
}, [accept]);
}

View File

@@ -0,0 +1,19 @@
import { useRegisteredDropTarget } from './useRegisteredDropTarget';
import { useOptionalFactory } from '../useOptionalFactory';
import { useDropTargetMonitor } from './useDropTargetMonitor';
import { useDropTargetConnector } from './useDropTargetConnector';
import { useCollectedProps } from '../useCollectedProps';
import { useConnectDropTarget } from './connectors';
/**
* useDropTarget Hook
* @param spec The drop target specification (object or function, function preferred)
* @param deps The memoization deps array to use when evaluating spec changes
*/
export function useDrop(specArg, deps) {
var spec = useOptionalFactory(specArg, deps);
var monitor = useDropTargetMonitor();
var connector = useDropTargetConnector(spec.options);
useRegisteredDropTarget(spec, monitor, connector);
return [useCollectedProps(spec.collect, monitor, connector), useConnectDropTarget(connector)];
}

View File

@@ -0,0 +1,11 @@
import { useEffect, useMemo } from 'react';
import { DropTargetImpl } from './DropTargetImpl';
export function useDropTarget(spec, monitor) {
var dropTarget = useMemo(function () {
return new DropTargetImpl(spec, monitor);
}, [monitor]);
useEffect(function () {
dropTarget.spec = spec;
}, [spec]);
return dropTarget;
}

View File

@@ -0,0 +1,18 @@
import { useMemo } from 'react';
import { TargetConnector } from '../../internals';
import { useDragDropManager } from '../useDragDropManager';
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect';
export function useDropTargetConnector(options) {
var manager = useDragDropManager();
var connector = useMemo(function () {
return new TargetConnector(manager.getBackend());
}, [manager]);
useIsomorphicLayoutEffect(function () {
connector.dropTargetOptions = options || null;
connector.reconnect();
return function () {
return connector.disconnectDropTarget();
};
}, [options]);
return connector;
}

View File

@@ -0,0 +1,9 @@
import { useMemo } from 'react';
import { DropTargetMonitorImpl } from '../../internals';
import { useDragDropManager } from '../useDragDropManager';
export function useDropTargetMonitor() {
var manager = useDragDropManager();
return useMemo(function () {
return new DropTargetMonitorImpl(manager);
}, [manager]);
}

View File

@@ -0,0 +1,34 @@
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 { registerTarget } from '../../internals';
import { useDragDropManager } from '../useDragDropManager';
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect';
import { useAccept } from './useAccept';
import { useDropTarget } from './useDropTarget';
export function useRegisteredDropTarget(spec, monitor, connector) {
var manager = useDragDropManager();
var dropTarget = useDropTarget(spec, monitor);
var accept = useAccept(spec);
useIsomorphicLayoutEffect(function registerDropTarget() {
var _registerTarget = registerTarget(accept, dropTarget, manager),
_registerTarget2 = _slicedToArray(_registerTarget, 2),
handlerId = _registerTarget2[0],
unregister = _registerTarget2[1];
monitor.receiveHandlerId(handlerId);
connector.receiveHandlerId(handlerId);
return unregister;
}, [manager, monitor, dropTarget, connector, accept.map(function (a) {
return a.toString();
}).join('|')]);
}