This commit is contained in:
12
node_modules/react-dnd/lib/core/DndContext.d.ts
generated
vendored
Normal file
12
node_modules/react-dnd/lib/core/DndContext.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/// <reference types="react" />
|
||||
import { DragDropManager } from 'dnd-core';
|
||||
/**
|
||||
* The React context type
|
||||
*/
|
||||
export interface DndContextType {
|
||||
dragDropManager: DragDropManager | undefined;
|
||||
}
|
||||
/**
|
||||
* Create the React Context
|
||||
*/
|
||||
export declare const DndContext: import("react").Context<DndContextType>;
|
||||
7
node_modules/react-dnd/lib/core/DndContext.js
generated
vendored
Normal file
7
node_modules/react-dnd/lib/core/DndContext.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { createContext } from 'react';
|
||||
/**
|
||||
* Create the React Context
|
||||
*/
|
||||
export const DndContext = createContext({
|
||||
dragDropManager: undefined,
|
||||
});
|
||||
16
node_modules/react-dnd/lib/core/DndProvider.d.ts
generated
vendored
Normal file
16
node_modules/react-dnd/lib/core/DndProvider.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import { FC, ReactNode } from 'react';
|
||||
import { BackendFactory, DragDropManager } from 'dnd-core';
|
||||
export declare type DndProviderProps<BackendContext, BackendOptions> = {
|
||||
children?: ReactNode;
|
||||
manager: DragDropManager;
|
||||
} | {
|
||||
backend: BackendFactory;
|
||||
children?: ReactNode;
|
||||
context?: BackendContext;
|
||||
options?: BackendOptions;
|
||||
debugMode?: boolean;
|
||||
};
|
||||
/**
|
||||
* A React component that provides the React-DnD context
|
||||
*/
|
||||
export declare const DndProvider: FC<DndProviderProps<unknown, unknown>>;
|
||||
50
node_modules/react-dnd/lib/core/DndProvider.js
generated
vendored
Normal file
50
node_modules/react-dnd/lib/core/DndProvider.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { useEffect, memo } from 'react';
|
||||
import { createDragDropManager, } from 'dnd-core';
|
||||
import { DndContext } from './DndContext';
|
||||
let refCount = 0;
|
||||
const INSTANCE_SYM = Symbol.for('__REACT_DND_CONTEXT_INSTANCE__');
|
||||
/**
|
||||
* A React component that provides the React-DnD context
|
||||
*/
|
||||
export const DndProvider = memo(function DndProvider({ children, ...props }) {
|
||||
const [manager, isGlobalInstance] = getDndContextValue(props); // memoized from props
|
||||
/**
|
||||
* If the global context was used to store the DND context
|
||||
* then where theres no more references to it we should
|
||||
* clean it up to avoid memory leaks
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (isGlobalInstance) {
|
||||
const context = getGlobalContext();
|
||||
++refCount;
|
||||
return () => {
|
||||
if (--refCount === 0) {
|
||||
context[INSTANCE_SYM] = null;
|
||||
}
|
||||
};
|
||||
}
|
||||
}, []);
|
||||
return _jsx(DndContext.Provider, Object.assign({ value: manager }, { children: children }), void 0);
|
||||
});
|
||||
function getDndContextValue(props) {
|
||||
if ('manager' in props) {
|
||||
const manager = { dragDropManager: props.manager };
|
||||
return [manager, false];
|
||||
}
|
||||
const manager = createSingletonDndContext(props.backend, props.context, props.options, props.debugMode);
|
||||
const isGlobalInstance = !props.context;
|
||||
return [manager, isGlobalInstance];
|
||||
}
|
||||
function createSingletonDndContext(backend, context = getGlobalContext(), options, debugMode) {
|
||||
const ctx = context;
|
||||
if (!ctx[INSTANCE_SYM]) {
|
||||
ctx[INSTANCE_SYM] = {
|
||||
dragDropManager: createDragDropManager(backend, context, options, debugMode),
|
||||
};
|
||||
}
|
||||
return ctx[INSTANCE_SYM];
|
||||
}
|
||||
function getGlobalContext() {
|
||||
return typeof global !== 'undefined' ? global : window;
|
||||
}
|
||||
10
node_modules/react-dnd/lib/core/DragPreviewImage.d.ts
generated
vendored
Normal file
10
node_modules/react-dnd/lib/core/DragPreviewImage.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { FC } from 'react';
|
||||
import { ConnectDragPreview } from '../types';
|
||||
export interface DragPreviewImageProps {
|
||||
connect: ConnectDragPreview;
|
||||
src: string;
|
||||
}
|
||||
/**
|
||||
* A utility for rendering a drag preview image
|
||||
*/
|
||||
export declare const DragPreviewImage: FC<DragPreviewImageProps>;
|
||||
23
node_modules/react-dnd/lib/core/DragPreviewImage.js
generated
vendored
Normal file
23
node_modules/react-dnd/lib/core/DragPreviewImage.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useEffect, memo } from 'react';
|
||||
/**
|
||||
* A utility for rendering a drag preview image
|
||||
*/
|
||||
export const DragPreviewImage = memo(function DragPreviewImage({ connect, src }) {
|
||||
useEffect(() => {
|
||||
if (typeof Image === 'undefined')
|
||||
return;
|
||||
let connected = false;
|
||||
const img = new Image();
|
||||
img.src = src;
|
||||
img.onload = () => {
|
||||
connect(img);
|
||||
connected = true;
|
||||
};
|
||||
return () => {
|
||||
if (connected) {
|
||||
connect(null);
|
||||
}
|
||||
};
|
||||
});
|
||||
return null;
|
||||
});
|
||||
3
node_modules/react-dnd/lib/core/index.d.ts
generated
vendored
Normal file
3
node_modules/react-dnd/lib/core/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './DndContext';
|
||||
export * from './DndProvider';
|
||||
export * from './DragPreviewImage';
|
||||
3
node_modules/react-dnd/lib/core/index.js
generated
vendored
Normal file
3
node_modules/react-dnd/lib/core/index.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './DndContext';
|
||||
export * from './DndProvider';
|
||||
export * from './DragPreviewImage';
|
||||
6
node_modules/react-dnd/lib/decorators/DragLayer.d.ts
generated
vendored
Normal file
6
node_modules/react-dnd/lib/decorators/DragLayer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { DragLayerCollector, DndComponentEnhancer, DndOptions } from './types';
|
||||
/**
|
||||
* @param collect The props collector function
|
||||
* @param options The DnD options
|
||||
*/
|
||||
export declare function DragLayer<RequiredProps, CollectedProps = any>(collect: DragLayerCollector<RequiredProps, CollectedProps>, options?: DndOptions<RequiredProps>): DndComponentEnhancer<CollectedProps>;
|
||||
96
node_modules/react-dnd/lib/decorators/DragLayer.js
generated
vendored
Normal file
96
node_modules/react-dnd/lib/decorators/DragLayer.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { createRef, Component, } from 'react';
|
||||
import { shallowEqual } from '@react-dnd/shallowequal';
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import hoistStatics from 'hoist-non-react-statics';
|
||||
import { DndContext } from '../core';
|
||||
import { isRefable, checkDecoratorArguments, isPlainObject } from './utils';
|
||||
/**
|
||||
* @param collect The props collector function
|
||||
* @param options The DnD options
|
||||
*/
|
||||
export function DragLayer(collect, options = {}) {
|
||||
checkDecoratorArguments('DragLayer', 'collect[, options]', collect, options);
|
||||
invariant(typeof collect === 'function', 'Expected "collect" provided as the first argument to DragLayer to be a function that collects props to inject into the component. ', 'Instead, received %s. Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-layer', collect);
|
||||
invariant(isPlainObject(options), 'Expected "options" provided as the second argument to DragLayer to be a plain object when specified. ' +
|
||||
'Instead, received %s. Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-layer', options);
|
||||
return function decorateLayer(DecoratedComponent) {
|
||||
const Decorated = DecoratedComponent;
|
||||
const { arePropsEqual = shallowEqual } = options;
|
||||
const displayName = Decorated.displayName || Decorated.name || 'Component';
|
||||
class DragLayerContainer extends Component {
|
||||
static displayName = `DragLayer(${displayName})`;
|
||||
static DecoratedComponent = DecoratedComponent;
|
||||
manager;
|
||||
isCurrentlyMounted = false;
|
||||
unsubscribeFromOffsetChange;
|
||||
unsubscribeFromStateChange;
|
||||
ref = createRef();
|
||||
getDecoratedComponentInstance() {
|
||||
invariant(this.ref.current, 'In order to access an instance of the decorated component, it must either be a class component or use React.forwardRef()');
|
||||
return this.ref.current;
|
||||
}
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
return (!arePropsEqual(nextProps, this.props) ||
|
||||
!shallowEqual(nextState, this.state));
|
||||
}
|
||||
componentDidMount() {
|
||||
this.isCurrentlyMounted = true;
|
||||
this.handleChange();
|
||||
}
|
||||
componentWillUnmount() {
|
||||
this.isCurrentlyMounted = false;
|
||||
if (this.unsubscribeFromOffsetChange) {
|
||||
this.unsubscribeFromOffsetChange();
|
||||
this.unsubscribeFromOffsetChange = undefined;
|
||||
}
|
||||
if (this.unsubscribeFromStateChange) {
|
||||
this.unsubscribeFromStateChange();
|
||||
this.unsubscribeFromStateChange = undefined;
|
||||
}
|
||||
}
|
||||
render() {
|
||||
return (_jsx(DndContext.Consumer, { children: ({ dragDropManager }) => {
|
||||
if (dragDropManager === undefined) {
|
||||
return null;
|
||||
}
|
||||
this.receiveDragDropManager(dragDropManager);
|
||||
// Let componentDidMount fire to initialize the collected state
|
||||
if (!this.isCurrentlyMounted) {
|
||||
return null;
|
||||
}
|
||||
return (_jsx(Decorated, Object.assign({}, this.props, this.state, { ref: isRefable(Decorated) ? this.ref : null }), void 0));
|
||||
} }, void 0));
|
||||
}
|
||||
receiveDragDropManager(dragDropManager) {
|
||||
if (this.manager !== undefined) {
|
||||
return;
|
||||
}
|
||||
this.manager = dragDropManager;
|
||||
invariant(typeof dragDropManager === 'object', 'Could not find the drag and drop manager in the context of %s. ' +
|
||||
'Make sure to render a DndProvider component in your top-level component. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/troubleshooting#could-not-find-the-drag-and-drop-manager-in-the-context', displayName, displayName);
|
||||
const monitor = this.manager.getMonitor();
|
||||
this.unsubscribeFromOffsetChange = monitor.subscribeToOffsetChange(this.handleChange);
|
||||
this.unsubscribeFromStateChange = monitor.subscribeToStateChange(this.handleChange);
|
||||
}
|
||||
handleChange = () => {
|
||||
if (!this.isCurrentlyMounted) {
|
||||
return;
|
||||
}
|
||||
const nextState = this.getCurrentState();
|
||||
if (!shallowEqual(nextState, this.state)) {
|
||||
this.setState(nextState);
|
||||
}
|
||||
};
|
||||
getCurrentState() {
|
||||
if (!this.manager) {
|
||||
return {};
|
||||
}
|
||||
const monitor = this.manager.getMonitor();
|
||||
return collect(monitor, this.props);
|
||||
}
|
||||
}
|
||||
return hoistStatics(DragLayerContainer, DecoratedComponent);
|
||||
};
|
||||
}
|
||||
10
node_modules/react-dnd/lib/decorators/DragSource.d.ts
generated
vendored
Normal file
10
node_modules/react-dnd/lib/decorators/DragSource.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { SourceType } from 'dnd-core';
|
||||
import { DndOptions, DndComponentEnhancer, DragSourceSpec, DragSourceCollector } from './types';
|
||||
/**
|
||||
* Decorates a component as a dragsource
|
||||
* @param type The dragsource type
|
||||
* @param spec The drag source specification
|
||||
* @param collect The props collector function
|
||||
* @param options DnD options
|
||||
*/
|
||||
export declare function DragSource<RequiredProps, CollectedProps = any, DragObject = any, DropResult = any>(type: SourceType | ((props: RequiredProps) => SourceType), spec: DragSourceSpec<RequiredProps, DragObject, DropResult>, collect: DragSourceCollector<CollectedProps, RequiredProps>, options?: DndOptions<RequiredProps>): DndComponentEnhancer<CollectedProps>;
|
||||
48
node_modules/react-dnd/lib/decorators/DragSource.js
generated
vendored
Normal file
48
node_modules/react-dnd/lib/decorators/DragSource.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { registerSource, DragSourceMonitorImpl, SourceConnector, } from '../internals';
|
||||
import { checkDecoratorArguments, isPlainObject, isValidType } from './utils';
|
||||
import { decorateHandler } from './decorateHandler';
|
||||
import { createSourceFactory } from './createSourceFactory';
|
||||
/**
|
||||
* Decorates a component as a dragsource
|
||||
* @param type The dragsource type
|
||||
* @param spec The drag source specification
|
||||
* @param collect The props collector function
|
||||
* @param options DnD options
|
||||
*/
|
||||
export function DragSource(type, spec, collect, options = {}) {
|
||||
checkDecoratorArguments('DragSource', 'type, spec, collect[, options]', type, spec, collect, options);
|
||||
let getType = type;
|
||||
if (typeof type !== 'function') {
|
||||
invariant(isValidType(type), 'Expected "type" provided as the first argument to DragSource to be ' +
|
||||
'a string, or a function that returns a string given the current props. ' +
|
||||
'Instead, received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source', type);
|
||||
getType = () => type;
|
||||
}
|
||||
invariant(isPlainObject(spec), 'Expected "spec" provided as the second argument to DragSource to be ' +
|
||||
'a plain object. Instead, received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source', spec);
|
||||
const createSource = createSourceFactory(spec);
|
||||
invariant(typeof collect === 'function', 'Expected "collect" provided as the third argument to DragSource to be ' +
|
||||
'a function that returns a plain object of props to inject. ' +
|
||||
'Instead, received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source', collect);
|
||||
invariant(isPlainObject(options), 'Expected "options" provided as the fourth argument to DragSource to be ' +
|
||||
'a plain object when specified. ' +
|
||||
'Instead, received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source', collect);
|
||||
return function decorateSource(DecoratedComponent) {
|
||||
return decorateHandler({
|
||||
containerDisplayName: 'DragSource',
|
||||
createHandler: createSource,
|
||||
registerHandler: registerSource,
|
||||
createConnector: (backend) => new SourceConnector(backend),
|
||||
createMonitor: (manager) => new DragSourceMonitorImpl(manager),
|
||||
DecoratedComponent,
|
||||
getType,
|
||||
collect,
|
||||
options,
|
||||
});
|
||||
};
|
||||
}
|
||||
9
node_modules/react-dnd/lib/decorators/DropTarget.d.ts
generated
vendored
Normal file
9
node_modules/react-dnd/lib/decorators/DropTarget.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { TargetType } from 'dnd-core';
|
||||
import { DndOptions, DropTargetSpec, DropTargetCollector, DndComponentEnhancer } from './types';
|
||||
/**
|
||||
* @param type The accepted target type
|
||||
* @param spec The DropTarget specification
|
||||
* @param collect The props collector function
|
||||
* @param options Options
|
||||
*/
|
||||
export declare function DropTarget<RequiredProps, CollectedProps = any, DragObject = any, DropResult = any>(type: TargetType | ((props: RequiredProps) => TargetType), spec: DropTargetSpec<RequiredProps, DragObject, DropResult>, collect: DropTargetCollector<CollectedProps, RequiredProps>, options?: DndOptions<RequiredProps>): DndComponentEnhancer<CollectedProps>;
|
||||
48
node_modules/react-dnd/lib/decorators/DropTarget.js
generated
vendored
Normal file
48
node_modules/react-dnd/lib/decorators/DropTarget.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { TargetConnector, DropTargetMonitorImpl, registerTarget, } from '../internals';
|
||||
import { isPlainObject, isValidType } from './utils';
|
||||
import { checkDecoratorArguments } from './utils';
|
||||
import { decorateHandler } from './decorateHandler';
|
||||
import { createTargetFactory } from './createTargetFactory';
|
||||
/**
|
||||
* @param type The accepted target type
|
||||
* @param spec The DropTarget specification
|
||||
* @param collect The props collector function
|
||||
* @param options Options
|
||||
*/
|
||||
export function DropTarget(type, spec, collect, options = {}) {
|
||||
checkDecoratorArguments('DropTarget', 'type, spec, collect[, options]', type, spec, collect, options);
|
||||
let getType = type;
|
||||
if (typeof type !== 'function') {
|
||||
invariant(isValidType(type, true), 'Expected "type" provided as the first argument to DropTarget to be ' +
|
||||
'a string, an array of strings, or a function that returns either given ' +
|
||||
'the current props. Instead, received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target', type);
|
||||
getType = () => type;
|
||||
}
|
||||
invariant(isPlainObject(spec), 'Expected "spec" provided as the second argument to DropTarget to be ' +
|
||||
'a plain object. Instead, received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target', spec);
|
||||
const createTarget = createTargetFactory(spec);
|
||||
invariant(typeof collect === 'function', 'Expected "collect" provided as the third argument to DropTarget to be ' +
|
||||
'a function that returns a plain object of props to inject. ' +
|
||||
'Instead, received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target', collect);
|
||||
invariant(isPlainObject(options), 'Expected "options" provided as the fourth argument to DropTarget to be ' +
|
||||
'a plain object when specified. ' +
|
||||
'Instead, received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target', collect);
|
||||
return function decorateTarget(DecoratedComponent) {
|
||||
return decorateHandler({
|
||||
containerDisplayName: 'DropTarget',
|
||||
createHandler: createTarget,
|
||||
registerHandler: registerTarget,
|
||||
createMonitor: (manager) => new DropTargetMonitorImpl(manager),
|
||||
createConnector: (backend) => new TargetConnector(backend),
|
||||
DecoratedComponent,
|
||||
getType,
|
||||
collect,
|
||||
options,
|
||||
});
|
||||
};
|
||||
}
|
||||
8
node_modules/react-dnd/lib/decorators/createSourceFactory.d.ts
generated
vendored
Normal file
8
node_modules/react-dnd/lib/decorators/createSourceFactory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { RefObject } from 'react';
|
||||
import { DragSource } from 'dnd-core';
|
||||
import { DragSourceMonitor } from '../types';
|
||||
import { DragSourceSpec } from './types';
|
||||
export interface Source extends DragSource {
|
||||
receiveProps(props: any): void;
|
||||
}
|
||||
export declare function createSourceFactory<Props, DragObject, DropResult>(spec: DragSourceSpec<Props, DragObject, DropResult>): (monitor: DragSourceMonitor<DragObject, DropResult>, ref: RefObject<any>) => Source;
|
||||
76
node_modules/react-dnd/lib/decorators/createSourceFactory.js
generated
vendored
Normal file
76
node_modules/react-dnd/lib/decorators/createSourceFactory.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { isPlainObject, getDecoratedComponent } from './utils';
|
||||
const ALLOWED_SPEC_METHODS = ['canDrag', 'beginDrag', 'isDragging', 'endDrag'];
|
||||
const REQUIRED_SPEC_METHODS = ['beginDrag'];
|
||||
class SourceImpl {
|
||||
props = null;
|
||||
spec;
|
||||
monitor;
|
||||
ref;
|
||||
constructor(spec, monitor, ref) {
|
||||
this.spec = spec;
|
||||
this.monitor = monitor;
|
||||
this.ref = ref;
|
||||
}
|
||||
receiveProps(props) {
|
||||
this.props = props;
|
||||
}
|
||||
canDrag() {
|
||||
if (!this.props) {
|
||||
return false;
|
||||
}
|
||||
if (!this.spec.canDrag) {
|
||||
return true;
|
||||
}
|
||||
return this.spec.canDrag(this.props, this.monitor);
|
||||
}
|
||||
isDragging(globalMonitor, sourceId) {
|
||||
if (!this.props) {
|
||||
return false;
|
||||
}
|
||||
if (!this.spec.isDragging) {
|
||||
return sourceId === globalMonitor.getSourceId();
|
||||
}
|
||||
return this.spec.isDragging(this.props, this.monitor);
|
||||
}
|
||||
beginDrag = () => {
|
||||
if (!this.props) {
|
||||
return;
|
||||
}
|
||||
const item = this.spec.beginDrag(this.props, this.monitor, this.ref.current);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
invariant(isPlainObject(item), 'beginDrag() must return a plain object that represents the dragged item. ' +
|
||||
'Instead received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source', item);
|
||||
}
|
||||
return item;
|
||||
};
|
||||
endDrag() {
|
||||
if (!this.props) {
|
||||
return;
|
||||
}
|
||||
if (!this.spec.endDrag) {
|
||||
return;
|
||||
}
|
||||
this.spec.endDrag(this.props, this.monitor, getDecoratedComponent(this.ref));
|
||||
}
|
||||
}
|
||||
export function createSourceFactory(spec) {
|
||||
Object.keys(spec).forEach((key) => {
|
||||
invariant(ALLOWED_SPEC_METHODS.indexOf(key) > -1, 'Expected the drag source specification to only have ' +
|
||||
'some of the following keys: %s. ' +
|
||||
'Instead received a specification with an unexpected "%s" key. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source', ALLOWED_SPEC_METHODS.join(', '), key);
|
||||
invariant(typeof spec[key] === 'function', 'Expected %s in the drag source specification to be a function. ' +
|
||||
'Instead received a specification with %s: %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source', key, key, spec[key]);
|
||||
});
|
||||
REQUIRED_SPEC_METHODS.forEach((key) => {
|
||||
invariant(typeof spec[key] === 'function', 'Expected %s in the drag source specification to be a function. ' +
|
||||
'Instead received a specification with %s: %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source', key, key, spec[key]);
|
||||
});
|
||||
return function createSource(monitor, ref) {
|
||||
return new SourceImpl(spec, monitor, ref);
|
||||
};
|
||||
}
|
||||
9
node_modules/react-dnd/lib/decorators/createTargetFactory.d.ts
generated
vendored
Normal file
9
node_modules/react-dnd/lib/decorators/createTargetFactory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { RefObject } from 'react';
|
||||
import { DropTarget } from 'dnd-core';
|
||||
import { DropTargetMonitor } from '../types';
|
||||
import { DropTargetSpec } from './types';
|
||||
export interface Target extends DropTarget {
|
||||
receiveProps(props: any): void;
|
||||
receiveMonitor(monitor: any): void;
|
||||
}
|
||||
export declare function createTargetFactory<Props, DragObject, DropResult>(spec: DropTargetSpec<Props, DragObject, DropResult>): (monitor: DropTargetMonitor<DragObject, DropResult>, ref: RefObject<any>) => Target;
|
||||
58
node_modules/react-dnd/lib/decorators/createTargetFactory.js
generated
vendored
Normal file
58
node_modules/react-dnd/lib/decorators/createTargetFactory.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { isPlainObject, getDecoratedComponent } from './utils';
|
||||
const ALLOWED_SPEC_METHODS = ['canDrop', 'hover', 'drop'];
|
||||
class TargetImpl {
|
||||
props = null;
|
||||
spec;
|
||||
monitor;
|
||||
ref;
|
||||
constructor(spec, monitor, ref) {
|
||||
this.spec = spec;
|
||||
this.monitor = monitor;
|
||||
this.ref = ref;
|
||||
}
|
||||
receiveProps(props) {
|
||||
this.props = props;
|
||||
}
|
||||
receiveMonitor(monitor) {
|
||||
this.monitor = monitor;
|
||||
}
|
||||
canDrop() {
|
||||
if (!this.spec.canDrop) {
|
||||
return true;
|
||||
}
|
||||
return this.spec.canDrop(this.props, this.monitor);
|
||||
}
|
||||
hover() {
|
||||
if (!this.spec.hover || !this.props) {
|
||||
return;
|
||||
}
|
||||
this.spec.hover(this.props, this.monitor, getDecoratedComponent(this.ref));
|
||||
}
|
||||
drop() {
|
||||
if (!this.spec.drop) {
|
||||
return undefined;
|
||||
}
|
||||
const dropResult = this.spec.drop(this.props, this.monitor, this.ref.current);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
invariant(typeof dropResult === 'undefined' || isPlainObject(dropResult), 'drop() must either return undefined, or an object that represents the drop result. ' +
|
||||
'Instead received %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target', dropResult);
|
||||
}
|
||||
return dropResult;
|
||||
}
|
||||
}
|
||||
export function createTargetFactory(spec) {
|
||||
Object.keys(spec).forEach((key) => {
|
||||
invariant(ALLOWED_SPEC_METHODS.indexOf(key) > -1, 'Expected the drop target specification to only have ' +
|
||||
'some of the following keys: %s. ' +
|
||||
'Instead received a specification with an unexpected "%s" key. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target', ALLOWED_SPEC_METHODS.join(', '), key);
|
||||
invariant(typeof spec[key] === 'function', 'Expected %s in the drop target specification to be a function. ' +
|
||||
'Instead received a specification with %s: %s. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target', key, key, spec[key]);
|
||||
});
|
||||
return function createTarget(monitor, ref) {
|
||||
return new TargetImpl(spec, monitor, ref);
|
||||
};
|
||||
}
|
||||
23
node_modules/react-dnd/lib/decorators/decorateHandler.d.ts
generated
vendored
Normal file
23
node_modules/react-dnd/lib/decorators/decorateHandler.d.ts
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
import { RefObject } from 'react';
|
||||
import { DragDropManager, Identifier } from 'dnd-core';
|
||||
import { DndComponent } from './types';
|
||||
export interface DecorateHandlerArgs<Props, ItemIdType> {
|
||||
DecoratedComponent: any;
|
||||
createMonitor: (manager: DragDropManager) => HandlerReceiver;
|
||||
createHandler: (monitor: HandlerReceiver, ref: RefObject<any>) => Handler<Props>;
|
||||
createConnector: any;
|
||||
registerHandler: any;
|
||||
containerDisplayName: string;
|
||||
getType: (props: Props) => ItemIdType;
|
||||
collect: any;
|
||||
options: any;
|
||||
}
|
||||
interface HandlerReceiver {
|
||||
receiveHandlerId: (handlerId: Identifier | null) => void;
|
||||
}
|
||||
interface Handler<Props> {
|
||||
ref: RefObject<any>;
|
||||
receiveProps(props: Props): void;
|
||||
}
|
||||
export declare function decorateHandler<Props, CollectedProps, ItemIdType>({ DecoratedComponent, createHandler, createMonitor, createConnector, registerHandler, containerDisplayName, getType, collect, options, }: DecorateHandlerArgs<Props, ItemIdType>): DndComponent<Props>;
|
||||
export {};
|
||||
132
node_modules/react-dnd/lib/decorators/decorateHandler.js
generated
vendored
Normal file
132
node_modules/react-dnd/lib/decorators/decorateHandler.js
generated
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
import { jsx as _jsx } from "react/jsx-runtime";
|
||||
import { createRef, Component } from 'react';
|
||||
import { shallowEqual } from '@react-dnd/shallowequal';
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { DndContext } from '../core';
|
||||
import { isPlainObject } from './utils';
|
||||
import { Disposable, CompositeDisposable, SerialDisposable, } from './disposables';
|
||||
import { isRefable } from './utils';
|
||||
import hoistStatics from 'hoist-non-react-statics';
|
||||
export function decorateHandler({ DecoratedComponent, createHandler, createMonitor, createConnector, registerHandler, containerDisplayName, getType, collect, options, }) {
|
||||
const { arePropsEqual = shallowEqual } = options;
|
||||
const Decorated = DecoratedComponent;
|
||||
const displayName = DecoratedComponent.displayName || DecoratedComponent.name || 'Component';
|
||||
class DragDropContainer extends Component {
|
||||
static DecoratedComponent = DecoratedComponent;
|
||||
static displayName = `${containerDisplayName}(${displayName})`;
|
||||
decoratedRef = createRef();
|
||||
handlerId;
|
||||
manager;
|
||||
handlerMonitor;
|
||||
handlerConnector;
|
||||
handler;
|
||||
disposable;
|
||||
currentType;
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.disposable = new SerialDisposable();
|
||||
this.receiveProps(props);
|
||||
this.dispose();
|
||||
}
|
||||
getHandlerId() {
|
||||
return this.handlerId;
|
||||
}
|
||||
getDecoratedComponentInstance() {
|
||||
invariant(this.decoratedRef.current, 'In order to access an instance of the decorated component, it must either be a class component or use React.forwardRef()');
|
||||
return this.decoratedRef.current;
|
||||
}
|
||||
shouldComponentUpdate(nextProps, nextState) {
|
||||
return (!arePropsEqual(nextProps, this.props) ||
|
||||
!shallowEqual(nextState, this.state));
|
||||
}
|
||||
componentDidMount() {
|
||||
this.disposable = new SerialDisposable();
|
||||
this.currentType = undefined;
|
||||
this.receiveProps(this.props);
|
||||
this.handleChange();
|
||||
}
|
||||
componentDidUpdate(prevProps) {
|
||||
if (!arePropsEqual(this.props, prevProps)) {
|
||||
this.receiveProps(this.props);
|
||||
this.handleChange();
|
||||
}
|
||||
}
|
||||
componentWillUnmount() {
|
||||
this.dispose();
|
||||
}
|
||||
receiveProps(props) {
|
||||
if (!this.handler) {
|
||||
return;
|
||||
}
|
||||
this.handler.receiveProps(props);
|
||||
this.receiveType(getType(props));
|
||||
}
|
||||
receiveType(type) {
|
||||
if (!this.handlerMonitor || !this.manager || !this.handlerConnector) {
|
||||
return;
|
||||
}
|
||||
if (type === this.currentType) {
|
||||
return;
|
||||
}
|
||||
this.currentType = type;
|
||||
const [handlerId, unregister] = registerHandler(type, this.handler, this.manager);
|
||||
this.handlerId = handlerId;
|
||||
this.handlerMonitor.receiveHandlerId(handlerId);
|
||||
this.handlerConnector.receiveHandlerId(handlerId);
|
||||
const globalMonitor = this.manager.getMonitor();
|
||||
const unsubscribe = globalMonitor.subscribeToStateChange(this.handleChange, { handlerIds: [handlerId] });
|
||||
this.disposable.setDisposable(new CompositeDisposable(new Disposable(unsubscribe), new Disposable(unregister)));
|
||||
}
|
||||
handleChange = () => {
|
||||
const nextState = this.getCurrentState();
|
||||
if (!shallowEqual(nextState, this.state)) {
|
||||
this.setState(nextState);
|
||||
}
|
||||
};
|
||||
dispose() {
|
||||
this.disposable.dispose();
|
||||
if (this.handlerConnector) {
|
||||
this.handlerConnector.receiveHandlerId(null);
|
||||
}
|
||||
}
|
||||
getCurrentState() {
|
||||
if (!this.handlerConnector) {
|
||||
return {};
|
||||
}
|
||||
const nextState = collect(this.handlerConnector.hooks, this.handlerMonitor, this.props);
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
invariant(isPlainObject(nextState), 'Expected `collect` specified as the second argument to ' +
|
||||
'%s for %s to return a plain object of props to inject. ' +
|
||||
'Instead, received %s.', containerDisplayName, displayName, nextState);
|
||||
}
|
||||
return nextState;
|
||||
}
|
||||
render() {
|
||||
return (_jsx(DndContext.Consumer, { children: ({ dragDropManager }) => {
|
||||
this.receiveDragDropManager(dragDropManager);
|
||||
if (typeof requestAnimationFrame !== 'undefined') {
|
||||
requestAnimationFrame(() => this.handlerConnector?.reconnect());
|
||||
}
|
||||
return (_jsx(Decorated, Object.assign({}, this.props, this.getCurrentState(), {
|
||||
// NOTE: if Decorated is a Function Component, decoratedRef will not be populated unless it's a refforwarding component.
|
||||
ref: isRefable(Decorated) ? this.decoratedRef : null }), void 0));
|
||||
} }, void 0));
|
||||
}
|
||||
receiveDragDropManager(dragDropManager) {
|
||||
if (this.manager !== undefined) {
|
||||
return;
|
||||
}
|
||||
invariant(dragDropManager !== undefined, 'Could not find the drag and drop manager in the context of %s. ' +
|
||||
'Make sure to render a DndProvider component in your top-level component. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/troubleshooting#could-not-find-the-drag-and-drop-manager-in-the-context', displayName, displayName);
|
||||
if (dragDropManager === undefined) {
|
||||
return;
|
||||
}
|
||||
this.manager = dragDropManager;
|
||||
this.handlerMonitor = createMonitor(dragDropManager);
|
||||
this.handlerConnector = createConnector(dragDropManager.getBackend());
|
||||
this.handler = createHandler(this.handlerMonitor, this.decoratedRef);
|
||||
}
|
||||
}
|
||||
return hoistStatics(DragDropContainer, DecoratedComponent);
|
||||
}
|
||||
79
node_modules/react-dnd/lib/decorators/disposables.d.ts
generated
vendored
Normal file
79
node_modules/react-dnd/lib/decorators/disposables.d.ts
generated
vendored
Normal file
@@ -0,0 +1,79 @@
|
||||
import { noop } from './utils';
|
||||
/**
|
||||
* Provides a set of static methods for creating Disposables.
|
||||
* @param {Function} action Action to run during the first call to dispose.
|
||||
* The action is guaranteed to be run at most once.
|
||||
*/
|
||||
export declare class Disposable {
|
||||
/**
|
||||
* Gets the disposable that does nothing when disposed.
|
||||
*/
|
||||
static empty: {
|
||||
dispose: typeof noop;
|
||||
};
|
||||
/**
|
||||
* Validates whether the given object is a disposable
|
||||
* @param {Object} Object to test whether it has a dispose method
|
||||
* @returns {Boolean} true if a disposable object, else false.
|
||||
*/
|
||||
static isDisposable(d: any): boolean;
|
||||
static _fixup(result: any): any;
|
||||
/**
|
||||
* Creates a disposable object that invokes the specified action when disposed.
|
||||
* @param {Function} dispose Action to run during the first call to dispose.
|
||||
* The action is guaranteed to be run at most once.
|
||||
* @return {Disposable} The disposable object that runs the given action upon disposal.
|
||||
*/
|
||||
static create(action: any): Disposable;
|
||||
private isDisposed;
|
||||
private action;
|
||||
constructor(action: any);
|
||||
/** Performs the task of cleaning up resources. */
|
||||
dispose(): void;
|
||||
}
|
||||
/**
|
||||
* Represents a group of disposable resources that are disposed together.
|
||||
* @constructor
|
||||
*/
|
||||
export declare class CompositeDisposable {
|
||||
private isDisposed;
|
||||
private disposables;
|
||||
constructor(...disposables: Disposable[]);
|
||||
/**
|
||||
* Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
|
||||
* @param {Any} item Disposable to add.
|
||||
*/
|
||||
add(item: Disposable): void;
|
||||
/**
|
||||
* Removes and disposes the first occurrence of a disposable from the CompositeDisposable.
|
||||
* @param {Any} item Disposable to remove.
|
||||
* @returns {Boolean} true if found; false otherwise.
|
||||
*/
|
||||
remove(item: Disposable): boolean;
|
||||
/**
|
||||
* Disposes all disposables in the group and removes them from the group but
|
||||
* does not dispose the CompositeDisposable.
|
||||
*/
|
||||
clear(): void;
|
||||
/**
|
||||
* Disposes all disposables in the group and removes them from the group.
|
||||
*/
|
||||
dispose(): void;
|
||||
}
|
||||
/**
|
||||
* Represents a disposable resource whose underlying disposable resource can
|
||||
* be replaced by another disposable resource, causing automatic disposal of
|
||||
* the previous underlying disposable resource.
|
||||
*/
|
||||
export declare class SerialDisposable {
|
||||
private isDisposed;
|
||||
private current;
|
||||
/**
|
||||
* Gets the underlying disposable.
|
||||
* @returns {Any} the underlying disposable.
|
||||
*/
|
||||
getDisposable(): Disposable | undefined;
|
||||
setDisposable(value: Disposable): void;
|
||||
/** Performs the task of cleaning up resources. */
|
||||
dispose(): void;
|
||||
}
|
||||
158
node_modules/react-dnd/lib/decorators/disposables.js
generated
vendored
Normal file
158
node_modules/react-dnd/lib/decorators/disposables.js
generated
vendored
Normal file
@@ -0,0 +1,158 @@
|
||||
import { isFunction, noop } from './utils';
|
||||
/**
|
||||
* Provides a set of static methods for creating Disposables.
|
||||
* @param {Function} action Action to run during the first call to dispose.
|
||||
* The action is guaranteed to be run at most once.
|
||||
*/
|
||||
export class Disposable {
|
||||
/**
|
||||
* Gets the disposable that does nothing when disposed.
|
||||
*/
|
||||
static empty = { dispose: noop };
|
||||
/**
|
||||
* Validates whether the given object is a disposable
|
||||
* @param {Object} Object to test whether it has a dispose method
|
||||
* @returns {Boolean} true if a disposable object, else false.
|
||||
*/
|
||||
static isDisposable(d) {
|
||||
return Boolean(d && isFunction(d.dispose));
|
||||
}
|
||||
static _fixup(result) {
|
||||
return Disposable.isDisposable(result) ? result : Disposable.empty;
|
||||
}
|
||||
/**
|
||||
* Creates a disposable object that invokes the specified action when disposed.
|
||||
* @param {Function} dispose Action to run during the first call to dispose.
|
||||
* The action is guaranteed to be run at most once.
|
||||
* @return {Disposable} The disposable object that runs the given action upon disposal.
|
||||
*/
|
||||
static create(action) {
|
||||
return new Disposable(action);
|
||||
}
|
||||
isDisposed = false;
|
||||
action;
|
||||
constructor(action) {
|
||||
this.action = isFunction(action) ? action : noop;
|
||||
}
|
||||
/** Performs the task of cleaning up resources. */
|
||||
dispose() {
|
||||
if (!this.isDisposed) {
|
||||
this.action();
|
||||
this.isDisposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Represents a group of disposable resources that are disposed together.
|
||||
* @constructor
|
||||
*/
|
||||
export class CompositeDisposable {
|
||||
isDisposed = false;
|
||||
disposables;
|
||||
constructor(...disposables) {
|
||||
this.disposables = disposables;
|
||||
}
|
||||
/**
|
||||
* Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
|
||||
* @param {Any} item Disposable to add.
|
||||
*/
|
||||
add(item) {
|
||||
if (this.isDisposed) {
|
||||
item.dispose();
|
||||
}
|
||||
else {
|
||||
this.disposables.push(item);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Removes and disposes the first occurrence of a disposable from the CompositeDisposable.
|
||||
* @param {Any} item Disposable to remove.
|
||||
* @returns {Boolean} true if found; false otherwise.
|
||||
*/
|
||||
remove(item) {
|
||||
let shouldDispose = false;
|
||||
if (!this.isDisposed) {
|
||||
const idx = this.disposables.indexOf(item);
|
||||
if (idx !== -1) {
|
||||
shouldDispose = true;
|
||||
this.disposables.splice(idx, 1);
|
||||
item.dispose();
|
||||
}
|
||||
}
|
||||
return shouldDispose;
|
||||
}
|
||||
/**
|
||||
* Disposes all disposables in the group and removes them from the group but
|
||||
* does not dispose the CompositeDisposable.
|
||||
*/
|
||||
clear() {
|
||||
if (!this.isDisposed) {
|
||||
const len = this.disposables.length;
|
||||
const currentDisposables = new Array(len);
|
||||
for (let i = 0; i < len; i++) {
|
||||
currentDisposables[i] = this.disposables[i];
|
||||
}
|
||||
this.disposables = [];
|
||||
for (let i = 0; i < len; i++) {
|
||||
currentDisposables[i].dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Disposes all disposables in the group and removes them from the group.
|
||||
*/
|
||||
dispose() {
|
||||
if (!this.isDisposed) {
|
||||
this.isDisposed = true;
|
||||
const len = this.disposables.length;
|
||||
const currentDisposables = new Array(len);
|
||||
for (let i = 0; i < len; i++) {
|
||||
currentDisposables[i] = this.disposables[i];
|
||||
}
|
||||
this.disposables = [];
|
||||
for (let i = 0; i < len; i++) {
|
||||
currentDisposables[i].dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Represents a disposable resource whose underlying disposable resource can
|
||||
* be replaced by another disposable resource, causing automatic disposal of
|
||||
* the previous underlying disposable resource.
|
||||
*/
|
||||
export class SerialDisposable {
|
||||
isDisposed = false;
|
||||
current;
|
||||
/**
|
||||
* Gets the underlying disposable.
|
||||
* @returns {Any} the underlying disposable.
|
||||
*/
|
||||
getDisposable() {
|
||||
return this.current;
|
||||
}
|
||||
setDisposable(value) {
|
||||
const shouldDispose = this.isDisposed;
|
||||
if (!shouldDispose) {
|
||||
const old = this.current;
|
||||
this.current = value;
|
||||
if (old) {
|
||||
old.dispose();
|
||||
}
|
||||
}
|
||||
if (shouldDispose && value) {
|
||||
value.dispose();
|
||||
}
|
||||
}
|
||||
/** Performs the task of cleaning up resources. */
|
||||
dispose() {
|
||||
if (!this.isDisposed) {
|
||||
this.isDisposed = true;
|
||||
const old = this.current;
|
||||
this.current = undefined;
|
||||
if (old) {
|
||||
old.dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
4
node_modules/react-dnd/lib/decorators/index.d.ts
generated
vendored
Normal file
4
node_modules/react-dnd/lib/decorators/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './DragSource';
|
||||
export * from './DropTarget';
|
||||
export * from './DragLayer';
|
||||
export * from './types';
|
||||
4
node_modules/react-dnd/lib/decorators/index.js
generated
vendored
Normal file
4
node_modules/react-dnd/lib/decorators/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './DragSource';
|
||||
export * from './DropTarget';
|
||||
export * from './DragLayer';
|
||||
export * from './types';
|
||||
161
node_modules/react-dnd/lib/decorators/types.d.ts
generated
vendored
Normal file
161
node_modules/react-dnd/lib/decorators/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,161 @@
|
||||
import { Component, ComponentType, ComponentClass } from 'react';
|
||||
import { Identifier } from 'dnd-core';
|
||||
import { DropTargetMonitor, DragSourceMonitor, DragLayerMonitor, ConnectDragPreview, ConnectDropTarget, ConnectDragSource } from '../types';
|
||||
import { NonReactStatics } from 'hoist-non-react-statics';
|
||||
/**
|
||||
* Options for the Drag Sources, Drop Targets, and Drag Layers decorators
|
||||
*/
|
||||
export interface DndOptions<Props> {
|
||||
arePropsEqual?: (first: Props, second: Props) => boolean;
|
||||
}
|
||||
/**
|
||||
* A DnD interactive component
|
||||
*/
|
||||
export interface DndComponent<Props> extends Component<Props> {
|
||||
getDecoratedComponentInstance(): Component<Props> | null;
|
||||
getHandlerId(): Identifier;
|
||||
}
|
||||
/**
|
||||
* Interface for the DropTarget specification object
|
||||
*/
|
||||
export interface DropTargetSpec<Props, DragObject = any, DropResult = any> {
|
||||
/**
|
||||
* Optional.
|
||||
* Called when a compatible item is dropped on the target. You may either return undefined, or a plain object.
|
||||
* If you return an object, it is going to become the drop result and will be available to the drag source in its
|
||||
* endDrag method as monitor.getDropResult(). This is useful in case you want to perform different actions
|
||||
* depending on which target received the drop. If you have nested drop targets, you can test whether a nested
|
||||
* target has already handled drop by checking monitor.didDrop() and monitor.getDropResult(). Both this method and
|
||||
* the source's endDrag method are good places to fire Flux actions. This method will not be called if canDrop()
|
||||
* is defined and returns false.
|
||||
*/
|
||||
drop?: (props: Props, monitor: DropTargetMonitor<DragObject, DropResult>, component: any) => DropResult | undefined;
|
||||
/**
|
||||
* Optional.
|
||||
* Called when an item is hovered over the component. You can check monitor.isOver({ shallow: true }) to test whether
|
||||
* the hover happens over just the current target, or over a nested one. Unlike drop(), this method will be called even
|
||||
* if canDrop() is defined and returns false. You can check monitor.canDrop() to test whether this is the case.
|
||||
*/
|
||||
hover?: (props: Props, monitor: DropTargetMonitor<DragObject, DropResult>, component: any) => void;
|
||||
/**
|
||||
* Optional. Use it to specify whether the drop target is able to accept the item. If you want to always allow it, just
|
||||
* omit this method. Specifying it is handy if you'd like to disable dropping based on some predicate over props or
|
||||
* monitor.getItem(). Note: You may not call monitor.canDrop() inside this method.
|
||||
*/
|
||||
canDrop?: (props: Props, monitor: DropTargetMonitor<DragObject, DropResult>) => boolean;
|
||||
}
|
||||
export interface DragSourceSpec<Props, DragObject = any, DropResult = any> {
|
||||
/**
|
||||
* Required.
|
||||
* When the dragging starts, beginDrag is called. You must return a plain JavaScript object describing the
|
||||
* data being dragged. What you return is the only information available to the drop targets about the drag
|
||||
* source so it's important to pick the minimal data they need to know. You may be tempted to put a reference
|
||||
* to the component into it, but you should try very hard to avoid doing this because it couples the drag
|
||||
* sources and drop targets. It's a good idea to return something like { id: props.id } from this method.
|
||||
*/
|
||||
beginDrag: (props: Props, monitor: DragSourceMonitor<DragObject, DropResult>, component: any) => DragObject;
|
||||
/**
|
||||
* Optional.
|
||||
* When the dragging stops, endDrag is called. For every beginDrag call, a corresponding endDrag call is guaranteed.
|
||||
* You may call monitor.didDrop() to check whether or not the drop was handled by a compatible drop target. If it was handled,
|
||||
* and the drop target specified a drop result by returning a plain object from its drop() method, it will be available as
|
||||
* monitor.getDropResult(). This method is a good place to fire a Flux action. Note: If the component is unmounted while dragging,
|
||||
* component parameter is set to be null.
|
||||
*/
|
||||
endDrag?: (props: Props, monitor: DragSourceMonitor<DragObject, DropResult>, component: any) => void;
|
||||
/**
|
||||
* Optional.
|
||||
* Use it to specify whether the dragging is currently allowed. If you want to always allow it, just omit this method.
|
||||
* Specifying it is handy if you'd like to disable dragging based on some predicate over props. Note: You may not call
|
||||
* monitor.canDrag() inside this method.
|
||||
*/
|
||||
canDrag?: (props: Props, monitor: DragSourceMonitor<DragObject, DropResult>) => boolean;
|
||||
/**
|
||||
* Optional.
|
||||
* By default, only the drag source that initiated the drag operation is considered to be dragging. You can
|
||||
* override this behavior by defining a custom isDragging method. It might return something like props.id === monitor.getItem().id.
|
||||
* Do this if the original component may be unmounted during the dragging and later “resurrected” with a different parent.
|
||||
* For example, when moving a card across the lists in a Kanban board, you want it to retain the dragged appearance—even though
|
||||
* technically, the component gets unmounted and a different one gets mounted every time you move it to another list.
|
||||
*
|
||||
* Note: You may not call monitor.isDragging() inside this method.
|
||||
*/
|
||||
isDragging?: (props: Props, monitor: DragSourceMonitor<DragObject, DropResult>) => boolean;
|
||||
}
|
||||
/**
|
||||
* DragSourceConnector is an object passed to a collecting function of the DragSource.
|
||||
* Its methods return functions that let you assign the roles to your component's DOM nodes.
|
||||
*/
|
||||
export interface DragSourceConnector {
|
||||
/**
|
||||
* Returns a function that must be used inside the component to assign the drag source role to a node. By
|
||||
* returning { connectDragSource: connect.dragSource() } from your collecting function, you can mark any React
|
||||
* element as the draggable node. To do that, replace any element with this.props.connectDragSource(element) inside
|
||||
* the render function.
|
||||
*/
|
||||
dragSource(): ConnectDragSource;
|
||||
/**
|
||||
* Optional. Returns a function that may be used inside the component to assign the drag preview role to a node. By
|
||||
* returning { connectDragPreview: connect.dragPreview() } from your collecting function, you can mark any React element
|
||||
* as the drag preview node. To do that, replace any element with this.props.connectDragPreview(element) inside the render
|
||||
* function. The drag preview is the node that will be screenshotted by the HTML5 backend when the drag begins. For example,
|
||||
* if you want to make something draggable by a small custom handle, you can mark this handle as the dragSource(), but also
|
||||
* mark an outer, larger component node as the dragPreview(). Thus the larger drag preview appears on the screenshot, but
|
||||
* only the smaller drag source is actually draggable. Another possible customization is passing an Image instance to dragPreview
|
||||
* from a lifecycle method like componentDidMount. This lets you use the actual images for drag previews. (Note that IE does not
|
||||
* support this customization). See the example code below for the different usage examples.
|
||||
*/
|
||||
dragPreview(): ConnectDragPreview;
|
||||
}
|
||||
/**
|
||||
* DropTargetConnector is an object passed to a collecting function of the DropTarget. Its only method dropTarget() returns a function
|
||||
* that lets you assign the drop target role to one of your component's DOM nodes.
|
||||
*/
|
||||
export interface DropTargetConnector {
|
||||
/**
|
||||
* Returns a function that must be used inside the component to assign the drop target role to a node.
|
||||
* By returning { connectDropTarget: connect.dropTarget() } from your collecting function, you can mark any React element
|
||||
* as the droppable node. To do that, replace any element with this.props.connectDropTarget(element) inside the render function.
|
||||
*/
|
||||
dropTarget(): ConnectDropTarget;
|
||||
}
|
||||
export declare type DragSourceCollector<CollectedProps, TargetProps> = (connect: DragSourceConnector, monitor: DragSourceMonitor, props: TargetProps) => CollectedProps;
|
||||
export declare type DropTargetCollector<CollectedProps, TargetProps> = (connect: DropTargetConnector, monitor: DropTargetMonitor, props: TargetProps) => CollectedProps;
|
||||
export declare type DragLayerCollector<TargetProps, CollectedProps> = (monitor: DragLayerMonitor, props: TargetProps) => CollectedProps;
|
||||
export declare type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
|
||||
/**
|
||||
* A property P will be present if:
|
||||
* - it is present in DecorationTargetProps
|
||||
*
|
||||
* Its value will be dependent on the following conditions
|
||||
* - if property P is present in InjectedProps and its definition extends the definition
|
||||
* in DecorationTargetProps, then its definition will be that of DecorationTargetProps[P]
|
||||
* - if property P is not present in InjectedProps then its definition will be that of
|
||||
* DecorationTargetProps[P]
|
||||
* - if property P is present in InjectedProps but does not extend the
|
||||
* DecorationTargetProps[P] definition, its definition will be that of InjectedProps[P]
|
||||
*/
|
||||
export declare type Matching<InjectedProps, DecorationTargetProps> = {
|
||||
[P in keyof DecorationTargetProps]: P extends keyof InjectedProps ? InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : InjectedProps[P] : DecorationTargetProps[P];
|
||||
};
|
||||
/**
|
||||
* a property P will be present if :
|
||||
* - it is present in both DecorationTargetProps and InjectedProps
|
||||
* - InjectedProps[P] can satisfy DecorationTargetProps[P]
|
||||
* ie: decorated component can accept more types than decorator is injecting
|
||||
*
|
||||
* For decoration, inject props or ownProps are all optionally
|
||||
* required by the decorated (right hand side) component.
|
||||
* But any property required by the decorated component must be satisfied by the injected property.
|
||||
*/
|
||||
export declare type Shared<InjectedProps, DecorationTargetProps> = {
|
||||
[P in Extract<keyof InjectedProps, keyof DecorationTargetProps>]?: InjectedProps[P] extends DecorationTargetProps[P] ? DecorationTargetProps[P] : never;
|
||||
};
|
||||
/**
|
||||
* Gets the props interface of a component using inference
|
||||
*/
|
||||
export declare type GetProps<C> = C extends ComponentType<infer P> ? P : never;
|
||||
export declare type DndComponentEnhancer<CollectedProps> = <C extends ComponentType<Matching<CollectedProps, GetProps<C>>>>(component: C) => DndComponentClass<C, Omit<GetProps<C>, keyof Shared<CollectedProps, GetProps<C>>>>;
|
||||
export declare type DndComponentClass<C extends ComponentType<any>, P> = ComponentClass<JSX.LibraryManagedAttributes<C, P>> & NonReactStatics<C> & {
|
||||
DecoratedComponent: C;
|
||||
};
|
||||
1
node_modules/react-dnd/lib/decorators/types.js
generated
vendored
Normal file
1
node_modules/react-dnd/lib/decorators/types.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
10
node_modules/react-dnd/lib/decorators/utils.d.ts
generated
vendored
Normal file
10
node_modules/react-dnd/lib/decorators/utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { RefObject } from 'react';
|
||||
export declare function getDecoratedComponent(instanceRef: RefObject<any>): any;
|
||||
export declare function isClassComponent(Component: unknown): boolean;
|
||||
export declare function isRefForwardingComponent(C: unknown): boolean;
|
||||
export declare function isRefable(C: unknown): boolean;
|
||||
export declare function checkDecoratorArguments(functionName: string, signature: string, ...args: any[]): void;
|
||||
export declare function isFunction(input: unknown): boolean;
|
||||
export declare function noop(): void;
|
||||
export declare function isPlainObject(input: unknown): boolean;
|
||||
export declare function isValidType(type: unknown, allowArray?: boolean): boolean;
|
||||
68
node_modules/react-dnd/lib/decorators/utils.js
generated
vendored
Normal file
68
node_modules/react-dnd/lib/decorators/utils.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
export function getDecoratedComponent(instanceRef) {
|
||||
const currentRef = instanceRef.current;
|
||||
if (currentRef == null) {
|
||||
return null;
|
||||
}
|
||||
else if (currentRef.decoratedRef) {
|
||||
// go through the private field in decorateHandler to avoid the invariant hit
|
||||
return currentRef.decoratedRef.current;
|
||||
}
|
||||
else {
|
||||
return currentRef;
|
||||
}
|
||||
}
|
||||
export function isClassComponent(Component) {
|
||||
return (Component &&
|
||||
Component.prototype &&
|
||||
typeof Component.prototype.render === 'function');
|
||||
}
|
||||
export function isRefForwardingComponent(C) {
|
||||
const item = C;
|
||||
return item?.$$typeof?.toString() === 'Symbol(react.forward_ref)';
|
||||
}
|
||||
export function isRefable(C) {
|
||||
return isClassComponent(C) || isRefForwardingComponent(C);
|
||||
}
|
||||
export function checkDecoratorArguments(functionName, signature, ...args) {
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
if (arg && arg.prototype && arg.prototype.render) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('You seem to be applying the arguments in the wrong order. ' +
|
||||
`It should be ${functionName}(${signature})(Component), not the other way around. ` +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/troubleshooting#you-seem-to-be-applying-the-arguments-in-the-wrong-order');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export function isFunction(input) {
|
||||
return typeof input === 'function';
|
||||
}
|
||||
export function noop() {
|
||||
// noop
|
||||
}
|
||||
function isObjectLike(input) {
|
||||
return typeof input === 'object' && input !== null;
|
||||
}
|
||||
export function isPlainObject(input) {
|
||||
if (!isObjectLike(input)) {
|
||||
return false;
|
||||
}
|
||||
if (Object.getPrototypeOf(input) === null) {
|
||||
return true;
|
||||
}
|
||||
let proto = input;
|
||||
while (Object.getPrototypeOf(proto) !== null) {
|
||||
proto = Object.getPrototypeOf(proto);
|
||||
}
|
||||
return Object.getPrototypeOf(input) === proto;
|
||||
}
|
||||
export function isValidType(type, allowArray) {
|
||||
return (typeof type === 'string' ||
|
||||
typeof type === 'symbol' ||
|
||||
(!!allowArray &&
|
||||
Array.isArray(type) &&
|
||||
type.every((t) => isValidType(t, false))));
|
||||
}
|
||||
5
node_modules/react-dnd/lib/hooks/index.d.ts
generated
vendored
Normal file
5
node_modules/react-dnd/lib/hooks/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './useDrag';
|
||||
export * from './useDrop';
|
||||
export * from './useDragLayer';
|
||||
export * from './useDragDropManager';
|
||||
export * from './types';
|
||||
5
node_modules/react-dnd/lib/hooks/index.js
generated
vendored
Normal file
5
node_modules/react-dnd/lib/hooks/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './useDrag';
|
||||
export * from './useDrop';
|
||||
export * from './useDragLayer';
|
||||
export * from './useDragDropManager';
|
||||
export * from './types';
|
||||
108
node_modules/react-dnd/lib/hooks/types.d.ts
generated
vendored
Normal file
108
node_modules/react-dnd/lib/hooks/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
import { TargetType, SourceType } from 'dnd-core';
|
||||
import { DropTargetMonitor, DragSourceMonitor, DragSourceOptions, DragPreviewOptions, DropTargetOptions } from '../types';
|
||||
export declare type FactoryOrInstance<T> = T | (() => T);
|
||||
export declare type DragObjectFactory<T> = (monitor: DragSourceMonitor<T>) => T | null;
|
||||
export interface DragSourceHookSpec<DragObject, DropResult, CollectedProps> {
|
||||
/**
|
||||
* The type of item being dragged. This is required when using the function form of spec.item.
|
||||
* If spec.item is a static object, the type may either be defined on that object as `item.type`, or it may
|
||||
* be defined here.
|
||||
*/
|
||||
type: SourceType;
|
||||
/**
|
||||
* This property generates or defines a plain javascript item describing
|
||||
* the data being dragged. This is the only information available to the
|
||||
* drop targets about the drag source so it's important to pick the minimal
|
||||
* data they need to know.
|
||||
*
|
||||
* You may be tempted to put a reference to the component or complex object here,
|
||||
* but you should try very hard to avoid doing this because it couples the
|
||||
* drag sources and drop targets. It's a good idea to use something like
|
||||
* { id: props.id }
|
||||
*
|
||||
* If a function-form is used, it is invoked when the drag begins and returns a draggable item.
|
||||
* If the function returns null, the drag is canceled
|
||||
*
|
||||
*/
|
||||
item?: DragObject | DragObjectFactory<DragObject>;
|
||||
/**
|
||||
* The drag source options
|
||||
*/
|
||||
options?: DragSourceOptions;
|
||||
/**
|
||||
* DragPreview options
|
||||
*/
|
||||
previewOptions?: DragPreviewOptions;
|
||||
/**
|
||||
* Optional.
|
||||
* When the dragging stops, endDrag is called. For every beginDrag call, a corresponding endDrag call is guaranteed.
|
||||
* You may call monitor.didDrop() to check whether or not the drop was handled by a compatible drop target. If it was handled,
|
||||
* and the drop target specified a drop result by returning a plain object from its drop() method, it will be available as
|
||||
* monitor.getDropResult(). This method is a good place to fire a Flux action. Note: If the component is unmounted while dragging,
|
||||
* component parameter is set to be null.
|
||||
*/
|
||||
end?: (draggedItem: DragObject, monitor: DragSourceMonitor<DragObject, DropResult>) => void;
|
||||
/**
|
||||
* Optional.
|
||||
* Use it to specify whether the dragging is currently allowed. If you want to always allow it, just omit this method.
|
||||
* Specifying it is handy if you'd like to disable dragging based on some predicate over props. Note: You may not call
|
||||
* monitor.canDrag() inside this method.
|
||||
*/
|
||||
canDrag?: boolean | ((monitor: DragSourceMonitor<DragObject, DropResult>) => boolean);
|
||||
/**
|
||||
* Optional.
|
||||
* By default, only the drag source that initiated the drag operation is considered to be dragging. You can
|
||||
* override this behavior by defining a custom isDragging method. It might return something like props.id === monitor.getItem().id.
|
||||
* Do this if the original component may be unmounted during the dragging and later “resurrected” with a different parent.
|
||||
* For example, when moving a card across the lists in a Kanban board, you want it to retain the dragged appearance—even though
|
||||
* technically, the component gets unmounted and a different one gets mounted every time you move it to another list.
|
||||
*
|
||||
* Note: You may not call monitor.isDragging() inside this method.
|
||||
*/
|
||||
isDragging?: (monitor: DragSourceMonitor<DragObject, DropResult>) => boolean;
|
||||
/**
|
||||
* A function to collect rendering properties
|
||||
*/
|
||||
collect?: (monitor: DragSourceMonitor<DragObject, DropResult>) => CollectedProps;
|
||||
}
|
||||
/**
|
||||
* Interface for the DropTarget specification object
|
||||
*/
|
||||
export interface DropTargetHookSpec<DragObject, DropResult, CollectedProps> {
|
||||
/**
|
||||
* The kinds of dragItems this dropTarget accepts
|
||||
*/
|
||||
accept: TargetType;
|
||||
/**
|
||||
* The drop target options
|
||||
*/
|
||||
options?: DropTargetOptions;
|
||||
/**
|
||||
* Optional.
|
||||
* Called when a compatible item is dropped on the target. You may either return undefined, or a plain object.
|
||||
* If you return an object, it is going to become the drop result and will be available to the drag source in its
|
||||
* endDrag method as monitor.getDropResult(). This is useful in case you want to perform different actions
|
||||
* depending on which target received the drop. If you have nested drop targets, you can test whether a nested
|
||||
* target has already handled drop by checking monitor.didDrop() and monitor.getDropResult(). Both this method and
|
||||
* the source's endDrag method are good places to fire Flux actions. This method will not be called if canDrop()
|
||||
* is defined and returns false.
|
||||
*/
|
||||
drop?: (item: DragObject, monitor: DropTargetMonitor) => DropResult | undefined;
|
||||
/**
|
||||
* Optional.
|
||||
* Called when an item is hovered over the component. You can check monitor.isOver({ shallow: true }) to test whether
|
||||
* the hover happens over just the current target, or over a nested one. Unlike drop(), this method will be called even
|
||||
* if canDrop() is defined and returns false. You can check monitor.canDrop() to test whether this is the case.
|
||||
*/
|
||||
hover?: (item: DragObject, monitor: DropTargetMonitor) => void;
|
||||
/**
|
||||
* Optional. Use it to specify whether the drop target is able to accept the item. If you want to always allow it, just
|
||||
* omit this method. Specifying it is handy if you'd like to disable dropping based on some predicate over props or
|
||||
* monitor.getItem(). Note: You may not call monitor.canDrop() inside this method.
|
||||
*/
|
||||
canDrop?: (item: DragObject, monitor: DropTargetMonitor) => boolean;
|
||||
/**
|
||||
* A function to collect rendering properties
|
||||
*/
|
||||
collect?: (monitor: DropTargetMonitor) => CollectedProps;
|
||||
}
|
||||
1
node_modules/react-dnd/lib/hooks/types.js
generated
vendored
Normal file
1
node_modules/react-dnd/lib/hooks/types.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export {};
|
||||
3
node_modules/react-dnd/lib/hooks/useCollectedProps.d.ts
generated
vendored
Normal file
3
node_modules/react-dnd/lib/hooks/useCollectedProps.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Connector } from '../internals';
|
||||
import { HandlerManager, MonitorEventEmitter } from '../types';
|
||||
export declare function useCollectedProps<Collected, Monitor extends HandlerManager>(collector: ((monitor: Monitor) => Collected) | undefined, monitor: Monitor & MonitorEventEmitter, connector: Connector): Collected;
|
||||
4
node_modules/react-dnd/lib/hooks/useCollectedProps.js
generated
vendored
Normal file
4
node_modules/react-dnd/lib/hooks/useCollectedProps.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { useMonitorOutput } from './useMonitorOutput';
|
||||
export function useCollectedProps(collector, monitor, connector) {
|
||||
return useMonitorOutput(monitor, collector || (() => ({})), () => connector.reconnect());
|
||||
}
|
||||
7
node_modules/react-dnd/lib/hooks/useCollector.d.ts
generated
vendored
Normal file
7
node_modules/react-dnd/lib/hooks/useCollector.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
/**
|
||||
*
|
||||
* @param monitor The monitor to collect state from
|
||||
* @param collect The collecting function
|
||||
* @param onUpdate A method to invoke when updates occur
|
||||
*/
|
||||
export declare function useCollector<T, S>(monitor: T, collect: (monitor: T) => S, onUpdate?: () => void): [S, () => void];
|
||||
28
node_modules/react-dnd/lib/hooks/useCollector.js
generated
vendored
Normal file
28
node_modules/react-dnd/lib/hooks/useCollector.js
generated
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
import equal from 'fast-deep-equal';
|
||||
import { useState, useCallback } from 'react';
|
||||
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
||||
/**
|
||||
*
|
||||
* @param monitor The monitor to collect state from
|
||||
* @param collect The collecting function
|
||||
* @param onUpdate A method to invoke when updates occur
|
||||
*/
|
||||
export function useCollector(monitor, collect, onUpdate) {
|
||||
const [collected, setCollected] = useState(() => collect(monitor));
|
||||
const updateCollected = useCallback(() => {
|
||||
const nextValue = collect(monitor);
|
||||
// This needs to be a deep-equality check because some monitor-collected values
|
||||
// include XYCoord objects that may be equivalent, but do not have instance equality.
|
||||
if (!equal(collected, nextValue)) {
|
||||
setCollected(nextValue);
|
||||
if (onUpdate) {
|
||||
onUpdate();
|
||||
}
|
||||
}
|
||||
}, [collected, monitor, onUpdate]);
|
||||
// update the collected properties after react renders.
|
||||
// Note that the "Dustbin Stress Test" fails if this is not
|
||||
// done when the component updates
|
||||
useIsomorphicLayoutEffect(updateCollected);
|
||||
return [collected, updateCollected];
|
||||
}
|
||||
14
node_modules/react-dnd/lib/hooks/useDrag/DragSourceImpl.d.ts
generated
vendored
Normal file
14
node_modules/react-dnd/lib/hooks/useDrag/DragSourceImpl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { DragDropMonitor, DragSource, Identifier } from 'dnd-core';
|
||||
import { Connector } from '../../internals';
|
||||
import { DragSourceMonitor } from '../../types';
|
||||
import { DragSourceHookSpec } from '../types';
|
||||
export declare class DragSourceImpl<O, R, P> implements DragSource {
|
||||
spec: DragSourceHookSpec<O, R, P>;
|
||||
private monitor;
|
||||
private connector;
|
||||
constructor(spec: DragSourceHookSpec<O, R, P>, monitor: DragSourceMonitor<O, R>, connector: Connector);
|
||||
beginDrag(): NonNullable<O> | null;
|
||||
canDrag(): boolean;
|
||||
isDragging(globalMonitor: DragDropMonitor, target: Identifier): boolean;
|
||||
endDrag(): void;
|
||||
}
|
||||
56
node_modules/react-dnd/lib/hooks/useDrag/DragSourceImpl.js
generated
vendored
Normal file
56
node_modules/react-dnd/lib/hooks/useDrag/DragSourceImpl.js
generated
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
export class DragSourceImpl {
|
||||
spec;
|
||||
monitor;
|
||||
connector;
|
||||
constructor(spec, monitor, connector) {
|
||||
this.spec = spec;
|
||||
this.monitor = monitor;
|
||||
this.connector = connector;
|
||||
}
|
||||
beginDrag() {
|
||||
const spec = this.spec;
|
||||
const monitor = this.monitor;
|
||||
let result = null;
|
||||
if (typeof spec.item === 'object') {
|
||||
result = spec.item;
|
||||
}
|
||||
else if (typeof spec.item === 'function') {
|
||||
result = spec.item(monitor);
|
||||
}
|
||||
else {
|
||||
result = {};
|
||||
}
|
||||
return result ?? null;
|
||||
}
|
||||
canDrag() {
|
||||
const spec = this.spec;
|
||||
const monitor = this.monitor;
|
||||
if (typeof spec.canDrag === 'boolean') {
|
||||
return spec.canDrag;
|
||||
}
|
||||
else if (typeof spec.canDrag === 'function') {
|
||||
return spec.canDrag(monitor);
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
isDragging(globalMonitor, target) {
|
||||
const spec = this.spec;
|
||||
const monitor = this.monitor;
|
||||
const { isDragging } = spec;
|
||||
return isDragging
|
||||
? isDragging(monitor)
|
||||
: target === globalMonitor.getSourceId();
|
||||
}
|
||||
endDrag() {
|
||||
const spec = this.spec;
|
||||
const monitor = this.monitor;
|
||||
const connector = this.connector;
|
||||
const { end } = spec;
|
||||
if (end) {
|
||||
end(monitor.getItem(), monitor);
|
||||
}
|
||||
connector.reconnect();
|
||||
}
|
||||
}
|
||||
3
node_modules/react-dnd/lib/hooks/useDrag/connectors.d.ts
generated
vendored
Normal file
3
node_modules/react-dnd/lib/hooks/useDrag/connectors.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { SourceConnector } from '../../internals';
|
||||
export declare function useConnectDragSource(connector: SourceConnector): any;
|
||||
export declare function useConnectDragPreview(connector: SourceConnector): any;
|
||||
7
node_modules/react-dnd/lib/hooks/useDrag/connectors.js
generated
vendored
Normal file
7
node_modules/react-dnd/lib/hooks/useDrag/connectors.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { useMemo } from 'react';
|
||||
export function useConnectDragSource(connector) {
|
||||
return useMemo(() => connector.hooks.dragSource(), [connector]);
|
||||
}
|
||||
export function useConnectDragPreview(connector) {
|
||||
return useMemo(() => connector.hooks.dragPreview(), [connector]);
|
||||
}
|
||||
1
node_modules/react-dnd/lib/hooks/useDrag/index.d.ts
generated
vendored
Normal file
1
node_modules/react-dnd/lib/hooks/useDrag/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './useDrag';
|
||||
1
node_modules/react-dnd/lib/hooks/useDrag/index.js
generated
vendored
Normal file
1
node_modules/react-dnd/lib/hooks/useDrag/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './useDrag';
|
||||
8
node_modules/react-dnd/lib/hooks/useDrag/useDrag.d.ts
generated
vendored
Normal file
8
node_modules/react-dnd/lib/hooks/useDrag/useDrag.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { ConnectDragSource, ConnectDragPreview } from '../../types';
|
||||
import { DragSourceHookSpec, FactoryOrInstance } from '../types';
|
||||
/**
|
||||
* useDragSource hook
|
||||
* @param sourceSpec The drag source specification (object or function, function preferred)
|
||||
* @param deps The memoization deps array to use when evaluating spec changes
|
||||
*/
|
||||
export declare function useDrag<DragObject, DropResult, CollectedProps>(specArg: FactoryOrInstance<DragSourceHookSpec<DragObject, DropResult, CollectedProps>>, deps?: unknown[]): [CollectedProps, ConnectDragSource, ConnectDragPreview];
|
||||
24
node_modules/react-dnd/lib/hooks/useDrag/useDrag.js
generated
vendored
Normal file
24
node_modules/react-dnd/lib/hooks/useDrag/useDrag.js
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useRegisteredDragSource } from './useRegisteredDragSource';
|
||||
import { useOptionalFactory } from '../useOptionalFactory';
|
||||
import { useDragSourceMonitor } from './useDragSourceMonitor';
|
||||
import { useDragSourceConnector } from './useDragSourceConnector';
|
||||
import { useCollectedProps } from '../useCollectedProps';
|
||||
import { useConnectDragPreview, useConnectDragSource } from './connectors';
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
/**
|
||||
* useDragSource hook
|
||||
* @param sourceSpec The drag source specification (object or function, function preferred)
|
||||
* @param deps The memoization deps array to use when evaluating spec changes
|
||||
*/
|
||||
export function useDrag(specArg, deps) {
|
||||
const spec = useOptionalFactory(specArg, deps);
|
||||
invariant(!spec.begin, `useDrag::spec.begin was deprecated in v14. Replace spec.begin() with spec.item(). (see more here - https://react-dnd.github.io/react-dnd/docs/api/use-drag)`);
|
||||
const monitor = useDragSourceMonitor();
|
||||
const connector = useDragSourceConnector(spec.options, spec.previewOptions);
|
||||
useRegisteredDragSource(spec, monitor, connector);
|
||||
return [
|
||||
useCollectedProps(spec.collect, monitor, connector),
|
||||
useConnectDragSource(connector),
|
||||
useConnectDragPreview(connector),
|
||||
];
|
||||
}
|
||||
5
node_modules/react-dnd/lib/hooks/useDrag/useDragSource.d.ts
generated
vendored
Normal file
5
node_modules/react-dnd/lib/hooks/useDrag/useDragSource.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { Connector } from '../../internals';
|
||||
import { DragSourceMonitor } from '../../types';
|
||||
import { DragSourceHookSpec } from '../types';
|
||||
import { DragSourceImpl } from './DragSourceImpl';
|
||||
export declare function useDragSource<O, R, P>(spec: DragSourceHookSpec<O, R, P>, monitor: DragSourceMonitor<O, R>, connector: Connector): DragSourceImpl<O, R, P>;
|
||||
9
node_modules/react-dnd/lib/hooks/useDrag/useDragSource.js
generated
vendored
Normal file
9
node_modules/react-dnd/lib/hooks/useDrag/useDragSource.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { DragSourceImpl } from './DragSourceImpl';
|
||||
export function useDragSource(spec, monitor, connector) {
|
||||
const handler = useMemo(() => new DragSourceImpl(spec, monitor, connector), [monitor, connector]);
|
||||
useEffect(() => {
|
||||
handler.spec = spec;
|
||||
}, [spec]);
|
||||
return handler;
|
||||
}
|
||||
3
node_modules/react-dnd/lib/hooks/useDrag/useDragSourceConnector.d.ts
generated
vendored
Normal file
3
node_modules/react-dnd/lib/hooks/useDrag/useDragSourceConnector.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { SourceConnector } from '../../internals';
|
||||
import { DragPreviewOptions, DragSourceOptions } from '../../types';
|
||||
export declare function useDragSourceConnector(dragSourceOptions: DragSourceOptions | undefined, dragPreviewOptions: DragPreviewOptions | undefined): SourceConnector;
|
||||
19
node_modules/react-dnd/lib/hooks/useDrag/useDragSourceConnector.js
generated
vendored
Normal file
19
node_modules/react-dnd/lib/hooks/useDrag/useDragSourceConnector.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { useMemo } from 'react';
|
||||
import { SourceConnector } from '../../internals';
|
||||
import { useDragDropManager } from '../useDragDropManager';
|
||||
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect';
|
||||
export function useDragSourceConnector(dragSourceOptions, dragPreviewOptions) {
|
||||
const manager = useDragDropManager();
|
||||
const connector = useMemo(() => new SourceConnector(manager.getBackend()), [manager]);
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
connector.dragSourceOptions = dragSourceOptions || null;
|
||||
connector.reconnect();
|
||||
return () => connector.disconnectDragSource();
|
||||
}, [connector, dragSourceOptions]);
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
connector.dragPreviewOptions = dragPreviewOptions || null;
|
||||
connector.reconnect();
|
||||
return () => connector.disconnectDragPreview();
|
||||
}, [connector, dragPreviewOptions]);
|
||||
return connector;
|
||||
}
|
||||
2
node_modules/react-dnd/lib/hooks/useDrag/useDragSourceMonitor.d.ts
generated
vendored
Normal file
2
node_modules/react-dnd/lib/hooks/useDrag/useDragSourceMonitor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { DragSourceMonitor } from '../../types';
|
||||
export declare function useDragSourceMonitor<O, R>(): DragSourceMonitor<O, R>;
|
||||
7
node_modules/react-dnd/lib/hooks/useDrag/useDragSourceMonitor.js
generated
vendored
Normal file
7
node_modules/react-dnd/lib/hooks/useDrag/useDragSourceMonitor.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { useMemo } from 'react';
|
||||
import { DragSourceMonitorImpl } from '../../internals';
|
||||
import { useDragDropManager } from '../useDragDropManager';
|
||||
export function useDragSourceMonitor() {
|
||||
const manager = useDragDropManager();
|
||||
return useMemo(() => new DragSourceMonitorImpl(manager), [manager]);
|
||||
}
|
||||
3
node_modules/react-dnd/lib/hooks/useDrag/useDragType.d.ts
generated
vendored
Normal file
3
node_modules/react-dnd/lib/hooks/useDrag/useDragType.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Identifier } from 'dnd-core';
|
||||
import { DragSourceHookSpec } from '../types';
|
||||
export declare function useDragType(spec: DragSourceHookSpec<any, any, any>): Identifier;
|
||||
9
node_modules/react-dnd/lib/hooks/useDrag/useDragType.js
generated
vendored
Normal file
9
node_modules/react-dnd/lib/hooks/useDrag/useDragType.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { useMemo } from 'react';
|
||||
export function useDragType(spec) {
|
||||
return useMemo(() => {
|
||||
const result = spec.type;
|
||||
invariant(result != null, 'spec.type must be defined');
|
||||
return result;
|
||||
}, [spec]);
|
||||
}
|
||||
4
node_modules/react-dnd/lib/hooks/useDrag/useRegisteredDragSource.d.ts
generated
vendored
Normal file
4
node_modules/react-dnd/lib/hooks/useDrag/useRegisteredDragSource.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { DragSourceMonitor } from '../../types';
|
||||
import { SourceConnector } from '../../internals';
|
||||
import { DragSourceHookSpec } from '../types';
|
||||
export declare function useRegisteredDragSource<O, R, P>(spec: DragSourceHookSpec<O, R, P>, monitor: DragSourceMonitor<O, R>, connector: SourceConnector): void;
|
||||
18
node_modules/react-dnd/lib/hooks/useDrag/useRegisteredDragSource.js
generated
vendored
Normal file
18
node_modules/react-dnd/lib/hooks/useDrag/useRegisteredDragSource.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { registerSource } from '../../internals';
|
||||
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect';
|
||||
import { useDragSource } from './useDragSource';
|
||||
import { useDragDropManager } from '../useDragDropManager';
|
||||
import { useDragType } from './useDragType';
|
||||
export function useRegisteredDragSource(spec, monitor, connector) {
|
||||
const manager = useDragDropManager();
|
||||
const handler = useDragSource(spec, monitor, connector);
|
||||
const itemType = useDragType(spec);
|
||||
useIsomorphicLayoutEffect(function registerDragSource() {
|
||||
if (itemType != null) {
|
||||
const [handlerId, unregister] = registerSource(itemType, handler, manager);
|
||||
monitor.receiveHandlerId(handlerId);
|
||||
connector.receiveHandlerId(handlerId);
|
||||
return unregister;
|
||||
}
|
||||
}, [manager, monitor, connector, handler, itemType]);
|
||||
}
|
||||
5
node_modules/react-dnd/lib/hooks/useDragDropManager.d.ts
generated
vendored
Normal file
5
node_modules/react-dnd/lib/hooks/useDragDropManager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { DragDropManager } from 'dnd-core';
|
||||
/**
|
||||
* A hook to retrieve the DragDropManager from Context
|
||||
*/
|
||||
export declare function useDragDropManager(): DragDropManager;
|
||||
11
node_modules/react-dnd/lib/hooks/useDragDropManager.js
generated
vendored
Normal file
11
node_modules/react-dnd/lib/hooks/useDragDropManager.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { useContext } from 'react';
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { DndContext } from '../core';
|
||||
/**
|
||||
* A hook to retrieve the DragDropManager from Context
|
||||
*/
|
||||
export function useDragDropManager() {
|
||||
const { dragDropManager } = useContext(DndContext);
|
||||
invariant(dragDropManager != null, 'Expected drag drop context');
|
||||
return dragDropManager;
|
||||
}
|
||||
6
node_modules/react-dnd/lib/hooks/useDragLayer.d.ts
generated
vendored
Normal file
6
node_modules/react-dnd/lib/hooks/useDragLayer.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
import { DragLayerMonitor } from 'react-dnd';
|
||||
/**
|
||||
* useDragLayer Hook
|
||||
* @param collector The property collector
|
||||
*/
|
||||
export declare function useDragLayer<CollectedProps>(collect: (monitor: DragLayerMonitor) => CollectedProps): CollectedProps;
|
||||
15
node_modules/react-dnd/lib/hooks/useDragLayer.js
generated
vendored
Normal file
15
node_modules/react-dnd/lib/hooks/useDragLayer.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useDragDropManager } from './useDragDropManager';
|
||||
import { useCollector } from './useCollector';
|
||||
/**
|
||||
* useDragLayer Hook
|
||||
* @param collector The property collector
|
||||
*/
|
||||
export function useDragLayer(collect) {
|
||||
const dragDropManager = useDragDropManager();
|
||||
const monitor = dragDropManager.getMonitor();
|
||||
const [collected, updateCollected] = useCollector(monitor, collect);
|
||||
useEffect(() => monitor.subscribeToOffsetChange(updateCollected));
|
||||
useEffect(() => monitor.subscribeToStateChange(updateCollected));
|
||||
return collected;
|
||||
}
|
||||
11
node_modules/react-dnd/lib/hooks/useDrop/DropTargetImpl.d.ts
generated
vendored
Normal file
11
node_modules/react-dnd/lib/hooks/useDrop/DropTargetImpl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
import { DropTarget } from 'dnd-core';
|
||||
import { DropTargetMonitor } from '../../types';
|
||||
import { DropTargetHookSpec } from '../types';
|
||||
export declare class DropTargetImpl<O, R, P> implements DropTarget {
|
||||
spec: DropTargetHookSpec<O, R, P>;
|
||||
private monitor;
|
||||
constructor(spec: DropTargetHookSpec<O, R, P>, monitor: DropTargetMonitor<O, R>);
|
||||
canDrop(): boolean;
|
||||
hover(): void;
|
||||
drop(): R | undefined;
|
||||
}
|
||||
27
node_modules/react-dnd/lib/hooks/useDrop/DropTargetImpl.js
generated
vendored
Normal file
27
node_modules/react-dnd/lib/hooks/useDrop/DropTargetImpl.js
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
export class DropTargetImpl {
|
||||
spec;
|
||||
monitor;
|
||||
constructor(spec, monitor) {
|
||||
this.spec = spec;
|
||||
this.monitor = monitor;
|
||||
}
|
||||
canDrop() {
|
||||
const spec = this.spec;
|
||||
const monitor = this.monitor;
|
||||
return spec.canDrop ? spec.canDrop(monitor.getItem(), monitor) : true;
|
||||
}
|
||||
hover() {
|
||||
const spec = this.spec;
|
||||
const monitor = this.monitor;
|
||||
if (spec.hover) {
|
||||
spec.hover(monitor.getItem(), monitor);
|
||||
}
|
||||
}
|
||||
drop() {
|
||||
const spec = this.spec;
|
||||
const monitor = this.monitor;
|
||||
if (spec.drop) {
|
||||
return spec.drop(monitor.getItem(), monitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
2
node_modules/react-dnd/lib/hooks/useDrop/connectors.d.ts
generated
vendored
Normal file
2
node_modules/react-dnd/lib/hooks/useDrop/connectors.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { TargetConnector } from '../../internals';
|
||||
export declare function useConnectDropTarget(connector: TargetConnector): any;
|
||||
4
node_modules/react-dnd/lib/hooks/useDrop/connectors.js
generated
vendored
Normal file
4
node_modules/react-dnd/lib/hooks/useDrop/connectors.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { useMemo } from 'react';
|
||||
export function useConnectDropTarget(connector) {
|
||||
return useMemo(() => connector.hooks.dropTarget(), [connector]);
|
||||
}
|
||||
1
node_modules/react-dnd/lib/hooks/useDrop/index.d.ts
generated
vendored
Normal file
1
node_modules/react-dnd/lib/hooks/useDrop/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './useDrop';
|
||||
1
node_modules/react-dnd/lib/hooks/useDrop/index.js
generated
vendored
Normal file
1
node_modules/react-dnd/lib/hooks/useDrop/index.js
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export * from './useDrop';
|
||||
8
node_modules/react-dnd/lib/hooks/useDrop/useAccept.d.ts
generated
vendored
Normal file
8
node_modules/react-dnd/lib/hooks/useDrop/useAccept.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { Identifier } from 'dnd-core';
|
||||
import { DropTargetHookSpec } from '../types';
|
||||
/**
|
||||
* 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 declare function useAccept<O, R, P>(spec: DropTargetHookSpec<O, R, P>): Identifier[];
|
||||
14
node_modules/react-dnd/lib/hooks/useDrop/useAccept.js
generated
vendored
Normal file
14
node_modules/react-dnd/lib/hooks/useDrop/useAccept.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
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) {
|
||||
const { accept } = spec;
|
||||
return useMemo(() => {
|
||||
invariant(spec.accept != null, 'accept must be defined');
|
||||
return Array.isArray(accept) ? accept : [accept];
|
||||
}, [accept]);
|
||||
}
|
||||
8
node_modules/react-dnd/lib/hooks/useDrop/useDrop.d.ts
generated
vendored
Normal file
8
node_modules/react-dnd/lib/hooks/useDrop/useDrop.d.ts
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
import { ConnectDropTarget } from '../../types';
|
||||
import { DropTargetHookSpec, FactoryOrInstance } from '../types';
|
||||
/**
|
||||
* 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 declare function useDrop<DragObject, DropResult, CollectedProps>(specArg: FactoryOrInstance<DropTargetHookSpec<DragObject, DropResult, CollectedProps>>, deps?: unknown[]): [CollectedProps, ConnectDropTarget];
|
||||
21
node_modules/react-dnd/lib/hooks/useDrop/useDrop.js
generated
vendored
Normal file
21
node_modules/react-dnd/lib/hooks/useDrop/useDrop.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
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) {
|
||||
const spec = useOptionalFactory(specArg, deps);
|
||||
const monitor = useDropTargetMonitor();
|
||||
const connector = useDropTargetConnector(spec.options);
|
||||
useRegisteredDropTarget(spec, monitor, connector);
|
||||
return [
|
||||
useCollectedProps(spec.collect, monitor, connector),
|
||||
useConnectDropTarget(connector),
|
||||
];
|
||||
}
|
||||
4
node_modules/react-dnd/lib/hooks/useDrop/useDropTarget.d.ts
generated
vendored
Normal file
4
node_modules/react-dnd/lib/hooks/useDrop/useDropTarget.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { DropTargetMonitor } from '../../types';
|
||||
import { DropTargetHookSpec } from '../types';
|
||||
import { DropTargetImpl } from './DropTargetImpl';
|
||||
export declare function useDropTarget<O, R, P>(spec: DropTargetHookSpec<O, R, P>, monitor: DropTargetMonitor<O, R>): DropTargetImpl<O, R, P>;
|
||||
9
node_modules/react-dnd/lib/hooks/useDrop/useDropTarget.js
generated
vendored
Normal file
9
node_modules/react-dnd/lib/hooks/useDrop/useDropTarget.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { useEffect, useMemo } from 'react';
|
||||
import { DropTargetImpl } from './DropTargetImpl';
|
||||
export function useDropTarget(spec, monitor) {
|
||||
const dropTarget = useMemo(() => new DropTargetImpl(spec, monitor), [monitor]);
|
||||
useEffect(() => {
|
||||
dropTarget.spec = spec;
|
||||
}, [spec]);
|
||||
return dropTarget;
|
||||
}
|
||||
3
node_modules/react-dnd/lib/hooks/useDrop/useDropTargetConnector.d.ts
generated
vendored
Normal file
3
node_modules/react-dnd/lib/hooks/useDrop/useDropTargetConnector.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { TargetConnector } from '../../internals';
|
||||
import { DropTargetOptions } from '../../types';
|
||||
export declare function useDropTargetConnector(options: DropTargetOptions): TargetConnector;
|
||||
14
node_modules/react-dnd/lib/hooks/useDrop/useDropTargetConnector.js
generated
vendored
Normal file
14
node_modules/react-dnd/lib/hooks/useDrop/useDropTargetConnector.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { useMemo } from 'react';
|
||||
import { TargetConnector } from '../../internals';
|
||||
import { useDragDropManager } from '../useDragDropManager';
|
||||
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect';
|
||||
export function useDropTargetConnector(options) {
|
||||
const manager = useDragDropManager();
|
||||
const connector = useMemo(() => new TargetConnector(manager.getBackend()), [manager]);
|
||||
useIsomorphicLayoutEffect(() => {
|
||||
connector.dropTargetOptions = options || null;
|
||||
connector.reconnect();
|
||||
return () => connector.disconnectDropTarget();
|
||||
}, [options]);
|
||||
return connector;
|
||||
}
|
||||
2
node_modules/react-dnd/lib/hooks/useDrop/useDropTargetMonitor.d.ts
generated
vendored
Normal file
2
node_modules/react-dnd/lib/hooks/useDrop/useDropTargetMonitor.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { DropTargetMonitor } from '../../types';
|
||||
export declare function useDropTargetMonitor<O, R>(): DropTargetMonitor<O, R>;
|
||||
7
node_modules/react-dnd/lib/hooks/useDrop/useDropTargetMonitor.js
generated
vendored
Normal file
7
node_modules/react-dnd/lib/hooks/useDrop/useDropTargetMonitor.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { useMemo } from 'react';
|
||||
import { DropTargetMonitorImpl } from '../../internals';
|
||||
import { useDragDropManager } from '../useDragDropManager';
|
||||
export function useDropTargetMonitor() {
|
||||
const manager = useDragDropManager();
|
||||
return useMemo(() => new DropTargetMonitorImpl(manager), [manager]);
|
||||
}
|
||||
4
node_modules/react-dnd/lib/hooks/useDrop/useRegisteredDropTarget.d.ts
generated
vendored
Normal file
4
node_modules/react-dnd/lib/hooks/useDrop/useRegisteredDropTarget.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { TargetConnector } from '../../internals';
|
||||
import { DropTargetMonitor } from '../../types';
|
||||
import { DropTargetHookSpec } from '../types';
|
||||
export declare function useRegisteredDropTarget<O, R, P>(spec: DropTargetHookSpec<O, R, P>, monitor: DropTargetMonitor<O, R>, connector: TargetConnector): void;
|
||||
22
node_modules/react-dnd/lib/hooks/useDrop/useRegisteredDropTarget.js
generated
vendored
Normal file
22
node_modules/react-dnd/lib/hooks/useDrop/useRegisteredDropTarget.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
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) {
|
||||
const manager = useDragDropManager();
|
||||
const dropTarget = useDropTarget(spec, monitor);
|
||||
const accept = useAccept(spec);
|
||||
useIsomorphicLayoutEffect(function registerDropTarget() {
|
||||
const [handlerId, unregister] = registerTarget(accept, dropTarget, manager);
|
||||
monitor.receiveHandlerId(handlerId);
|
||||
connector.receiveHandlerId(handlerId);
|
||||
return unregister;
|
||||
}, [
|
||||
manager,
|
||||
monitor,
|
||||
dropTarget,
|
||||
connector,
|
||||
accept.map((a) => a.toString()).join('|'),
|
||||
]);
|
||||
}
|
||||
2
node_modules/react-dnd/lib/hooks/useIsomorphicLayoutEffect.d.ts
generated
vendored
Normal file
2
node_modules/react-dnd/lib/hooks/useIsomorphicLayoutEffect.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { useEffect } from 'react';
|
||||
export declare const useIsomorphicLayoutEffect: typeof useEffect;
|
||||
3
node_modules/react-dnd/lib/hooks/useIsomorphicLayoutEffect.js
generated
vendored
Normal file
3
node_modules/react-dnd/lib/hooks/useIsomorphicLayoutEffect.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { useLayoutEffect, useEffect } from 'react';
|
||||
// suppress the useLayoutEffect warning on server side.
|
||||
export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
||||
2
node_modules/react-dnd/lib/hooks/useMonitorOutput.d.ts
generated
vendored
Normal file
2
node_modules/react-dnd/lib/hooks/useMonitorOutput.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { HandlerManager, MonitorEventEmitter } from '../types';
|
||||
export declare function useMonitorOutput<Monitor extends HandlerManager, Collected>(monitor: Monitor & MonitorEventEmitter, collect: (monitor: Monitor) => Collected, onCollect?: () => void): Collected;
|
||||
15
node_modules/react-dnd/lib/hooks/useMonitorOutput.js
generated
vendored
Normal file
15
node_modules/react-dnd/lib/hooks/useMonitorOutput.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
|
||||
import { useCollector } from './useCollector';
|
||||
export function useMonitorOutput(monitor, collect, onCollect) {
|
||||
const [collected, updateCollected] = useCollector(monitor, collect, onCollect);
|
||||
useIsomorphicLayoutEffect(function subscribeToMonitorStateChange() {
|
||||
const handlerId = monitor.getHandlerId();
|
||||
if (handlerId == null) {
|
||||
return;
|
||||
}
|
||||
return monitor.subscribeToStateChange(updateCollected, {
|
||||
handlerIds: [handlerId],
|
||||
});
|
||||
}, [monitor, updateCollected]);
|
||||
return collected;
|
||||
}
|
||||
2
node_modules/react-dnd/lib/hooks/useOptionalFactory.d.ts
generated
vendored
Normal file
2
node_modules/react-dnd/lib/hooks/useOptionalFactory.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { FactoryOrInstance } from './types';
|
||||
export declare function useOptionalFactory<T>(arg: FactoryOrInstance<T>, deps?: unknown[]): T;
|
||||
10
node_modules/react-dnd/lib/hooks/useOptionalFactory.js
generated
vendored
Normal file
10
node_modules/react-dnd/lib/hooks/useOptionalFactory.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { useMemo } from 'react';
|
||||
export function useOptionalFactory(arg, deps) {
|
||||
const memoDeps = [...(deps || [])];
|
||||
if (deps == null && typeof arg !== 'function') {
|
||||
memoDeps.push(arg);
|
||||
}
|
||||
return useMemo(() => {
|
||||
return typeof arg === 'function' ? arg() : arg;
|
||||
}, memoDeps);
|
||||
}
|
||||
4
node_modules/react-dnd/lib/index.d.ts
generated
vendored
Normal file
4
node_modules/react-dnd/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './types';
|
||||
export * from './core';
|
||||
export * from './decorators';
|
||||
export * from './hooks';
|
||||
4
node_modules/react-dnd/lib/index.js
generated
vendored
Normal file
4
node_modules/react-dnd/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export * from './types';
|
||||
export * from './core';
|
||||
export * from './decorators';
|
||||
export * from './hooks';
|
||||
33
node_modules/react-dnd/lib/internals/DragSourceMonitorImpl.d.ts
generated
vendored
Normal file
33
node_modules/react-dnd/lib/internals/DragSourceMonitorImpl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
import { DragDropManager, Unsubscribe, Listener, Identifier, XYCoord } from 'dnd-core';
|
||||
import { DragSourceMonitor } from '../types';
|
||||
export declare class DragSourceMonitorImpl implements DragSourceMonitor {
|
||||
private internalMonitor;
|
||||
private sourceId;
|
||||
constructor(manager: DragDropManager);
|
||||
receiveHandlerId(sourceId: Identifier | null): void;
|
||||
getHandlerId(): Identifier | null;
|
||||
canDrag(): boolean;
|
||||
isDragging(): boolean;
|
||||
subscribeToStateChange(listener: Listener, options?: {
|
||||
handlerIds: Identifier[] | undefined;
|
||||
}): Unsubscribe;
|
||||
isDraggingSource(sourceId: Identifier): boolean;
|
||||
isOverTarget(targetId: Identifier, options?: {
|
||||
shallow: boolean;
|
||||
}): boolean;
|
||||
getTargetIds(): Identifier[];
|
||||
isSourcePublic(): boolean | null;
|
||||
getSourceId(): Identifier | null;
|
||||
subscribeToOffsetChange(listener: Listener): Unsubscribe;
|
||||
canDragSource(sourceId: Identifier): boolean;
|
||||
canDropOnTarget(targetId: Identifier): boolean;
|
||||
getItemType(): Identifier | null;
|
||||
getItem(): any;
|
||||
getDropResult(): any;
|
||||
didDrop(): boolean;
|
||||
getInitialClientOffset(): XYCoord | null;
|
||||
getInitialSourceClientOffset(): XYCoord | null;
|
||||
getSourceClientOffset(): XYCoord | null;
|
||||
getClientOffset(): XYCoord | null;
|
||||
getDifferenceFromInitialOffset(): XYCoord | null;
|
||||
}
|
||||
95
node_modules/react-dnd/lib/internals/DragSourceMonitorImpl.js
generated
vendored
Normal file
95
node_modules/react-dnd/lib/internals/DragSourceMonitorImpl.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
let isCallingCanDrag = false;
|
||||
let isCallingIsDragging = false;
|
||||
export class DragSourceMonitorImpl {
|
||||
internalMonitor;
|
||||
sourceId = null;
|
||||
constructor(manager) {
|
||||
this.internalMonitor = manager.getMonitor();
|
||||
}
|
||||
receiveHandlerId(sourceId) {
|
||||
this.sourceId = sourceId;
|
||||
}
|
||||
getHandlerId() {
|
||||
return this.sourceId;
|
||||
}
|
||||
canDrag() {
|
||||
invariant(!isCallingCanDrag, 'You may not call monitor.canDrag() inside your canDrag() implementation. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
|
||||
try {
|
||||
isCallingCanDrag = true;
|
||||
return this.internalMonitor.canDragSource(this.sourceId);
|
||||
}
|
||||
finally {
|
||||
isCallingCanDrag = false;
|
||||
}
|
||||
}
|
||||
isDragging() {
|
||||
if (!this.sourceId) {
|
||||
return false;
|
||||
}
|
||||
invariant(!isCallingIsDragging, 'You may not call monitor.isDragging() inside your isDragging() implementation. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
|
||||
try {
|
||||
isCallingIsDragging = true;
|
||||
return this.internalMonitor.isDraggingSource(this.sourceId);
|
||||
}
|
||||
finally {
|
||||
isCallingIsDragging = false;
|
||||
}
|
||||
}
|
||||
subscribeToStateChange(listener, options) {
|
||||
return this.internalMonitor.subscribeToStateChange(listener, options);
|
||||
}
|
||||
isDraggingSource(sourceId) {
|
||||
return this.internalMonitor.isDraggingSource(sourceId);
|
||||
}
|
||||
isOverTarget(targetId, options) {
|
||||
return this.internalMonitor.isOverTarget(targetId, options);
|
||||
}
|
||||
getTargetIds() {
|
||||
return this.internalMonitor.getTargetIds();
|
||||
}
|
||||
isSourcePublic() {
|
||||
return this.internalMonitor.isSourcePublic();
|
||||
}
|
||||
getSourceId() {
|
||||
return this.internalMonitor.getSourceId();
|
||||
}
|
||||
subscribeToOffsetChange(listener) {
|
||||
return this.internalMonitor.subscribeToOffsetChange(listener);
|
||||
}
|
||||
canDragSource(sourceId) {
|
||||
return this.internalMonitor.canDragSource(sourceId);
|
||||
}
|
||||
canDropOnTarget(targetId) {
|
||||
return this.internalMonitor.canDropOnTarget(targetId);
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
25
node_modules/react-dnd/lib/internals/DropTargetMonitorImpl.d.ts
generated
vendored
Normal file
25
node_modules/react-dnd/lib/internals/DropTargetMonitorImpl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { DragDropManager, Unsubscribe, Listener, Identifier, XYCoord } from 'dnd-core';
|
||||
import { DropTargetMonitor } from '../types';
|
||||
export declare class DropTargetMonitorImpl implements DropTargetMonitor {
|
||||
private internalMonitor;
|
||||
private targetId;
|
||||
constructor(manager: DragDropManager);
|
||||
receiveHandlerId(targetId: Identifier | null): void;
|
||||
getHandlerId(): Identifier | null;
|
||||
subscribeToStateChange(listener: Listener, options?: {
|
||||
handlerIds: Identifier[] | undefined;
|
||||
}): Unsubscribe;
|
||||
canDrop(): boolean;
|
||||
isOver(options?: {
|
||||
shallow?: boolean;
|
||||
}): boolean;
|
||||
getItemType(): Identifier | null;
|
||||
getItem(): any;
|
||||
getDropResult(): any;
|
||||
didDrop(): boolean;
|
||||
getInitialClientOffset(): XYCoord | null;
|
||||
getInitialSourceClientOffset(): XYCoord | null;
|
||||
getSourceClientOffset(): XYCoord | null;
|
||||
getClientOffset(): XYCoord | null;
|
||||
getDifferenceFromInitialOffset(): XYCoord | null;
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
47
node_modules/react-dnd/lib/internals/SourceConnector.d.ts
generated
vendored
Normal file
47
node_modules/react-dnd/lib/internals/SourceConnector.d.ts
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
import { Backend, Identifier } from 'dnd-core';
|
||||
import { DragSourceOptions, DragPreviewOptions } from '../types';
|
||||
export interface Connector {
|
||||
hooks: any;
|
||||
connectTarget: any;
|
||||
receiveHandlerId(handlerId: Identifier | null): void;
|
||||
reconnect(): void;
|
||||
}
|
||||
export declare class SourceConnector implements Connector {
|
||||
hooks: any;
|
||||
private handlerId;
|
||||
private dragSourceRef;
|
||||
private dragSourceNode;
|
||||
private dragSourceOptionsInternal;
|
||||
private dragSourceUnsubscribe;
|
||||
private dragPreviewRef;
|
||||
private dragPreviewNode;
|
||||
private dragPreviewOptionsInternal;
|
||||
private dragPreviewUnsubscribe;
|
||||
private lastConnectedHandlerId;
|
||||
private lastConnectedDragSource;
|
||||
private lastConnectedDragSourceOptions;
|
||||
private lastConnectedDragPreview;
|
||||
private lastConnectedDragPreviewOptions;
|
||||
private readonly backend;
|
||||
constructor(backend: Backend);
|
||||
receiveHandlerId(newHandlerId: Identifier | null): void;
|
||||
get connectTarget(): any;
|
||||
get dragSourceOptions(): DragSourceOptions | null;
|
||||
set dragSourceOptions(options: DragSourceOptions | null);
|
||||
get dragPreviewOptions(): DragPreviewOptions | null;
|
||||
set dragPreviewOptions(options: DragPreviewOptions | null);
|
||||
reconnect(): void;
|
||||
private reconnectDragSource;
|
||||
private reconnectDragPreview;
|
||||
private didHandlerIdChange;
|
||||
private didConnectedDragSourceChange;
|
||||
private didConnectedDragPreviewChange;
|
||||
private didDragSourceOptionsChange;
|
||||
private didDragPreviewOptionsChange;
|
||||
disconnectDragSource(): void;
|
||||
disconnectDragPreview(): void;
|
||||
private get dragSource();
|
||||
private get dragPreview();
|
||||
private clearDragSource;
|
||||
private clearDragPreview;
|
||||
}
|
||||
165
node_modules/react-dnd/lib/internals/SourceConnector.js
generated
vendored
Normal file
165
node_modules/react-dnd/lib/internals/SourceConnector.js
generated
vendored
Normal file
@@ -0,0 +1,165 @@
|
||||
import { wrapConnectorHooks } from './wrapConnectorHooks';
|
||||
import { isRef } from './isRef';
|
||||
import { shallowEqual } from '@react-dnd/shallowequal';
|
||||
export class SourceConnector {
|
||||
hooks = wrapConnectorHooks({
|
||||
dragSource: (node, options) => {
|
||||
this.clearDragSource();
|
||||
this.dragSourceOptions = options || null;
|
||||
if (isRef(node)) {
|
||||
this.dragSourceRef = node;
|
||||
}
|
||||
else {
|
||||
this.dragSourceNode = node;
|
||||
}
|
||||
this.reconnectDragSource();
|
||||
},
|
||||
dragPreview: (node, options) => {
|
||||
this.clearDragPreview();
|
||||
this.dragPreviewOptions = options || null;
|
||||
if (isRef(node)) {
|
||||
this.dragPreviewRef = node;
|
||||
}
|
||||
else {
|
||||
this.dragPreviewNode = node;
|
||||
}
|
||||
this.reconnectDragPreview();
|
||||
},
|
||||
});
|
||||
handlerId = null;
|
||||
// The drop target may either be attached via ref or connect function
|
||||
dragSourceRef = null;
|
||||
dragSourceNode;
|
||||
dragSourceOptionsInternal = null;
|
||||
dragSourceUnsubscribe;
|
||||
// The drag preview may either be attached via ref or connect function
|
||||
dragPreviewRef = null;
|
||||
dragPreviewNode;
|
||||
dragPreviewOptionsInternal = null;
|
||||
dragPreviewUnsubscribe;
|
||||
lastConnectedHandlerId = null;
|
||||
lastConnectedDragSource = null;
|
||||
lastConnectedDragSourceOptions = null;
|
||||
lastConnectedDragPreview = null;
|
||||
lastConnectedDragPreviewOptions = null;
|
||||
backend;
|
||||
constructor(backend) {
|
||||
this.backend = backend;
|
||||
}
|
||||
receiveHandlerId(newHandlerId) {
|
||||
if (this.handlerId === newHandlerId) {
|
||||
return;
|
||||
}
|
||||
this.handlerId = newHandlerId;
|
||||
this.reconnect();
|
||||
}
|
||||
get connectTarget() {
|
||||
return this.dragSource;
|
||||
}
|
||||
get dragSourceOptions() {
|
||||
return this.dragSourceOptionsInternal;
|
||||
}
|
||||
set dragSourceOptions(options) {
|
||||
this.dragSourceOptionsInternal = options;
|
||||
}
|
||||
get dragPreviewOptions() {
|
||||
return this.dragPreviewOptionsInternal;
|
||||
}
|
||||
set dragPreviewOptions(options) {
|
||||
this.dragPreviewOptionsInternal = options;
|
||||
}
|
||||
reconnect() {
|
||||
this.reconnectDragSource();
|
||||
this.reconnectDragPreview();
|
||||
}
|
||||
reconnectDragSource() {
|
||||
const dragSource = this.dragSource;
|
||||
// if nothing has changed then don't resubscribe
|
||||
const didChange = this.didHandlerIdChange() ||
|
||||
this.didConnectedDragSourceChange() ||
|
||||
this.didDragSourceOptionsChange();
|
||||
if (didChange) {
|
||||
this.disconnectDragSource();
|
||||
}
|
||||
if (!this.handlerId) {
|
||||
return;
|
||||
}
|
||||
if (!dragSource) {
|
||||
this.lastConnectedDragSource = dragSource;
|
||||
return;
|
||||
}
|
||||
if (didChange) {
|
||||
this.lastConnectedHandlerId = this.handlerId;
|
||||
this.lastConnectedDragSource = dragSource;
|
||||
this.lastConnectedDragSourceOptions = this.dragSourceOptions;
|
||||
this.dragSourceUnsubscribe = this.backend.connectDragSource(this.handlerId, dragSource, this.dragSourceOptions);
|
||||
}
|
||||
}
|
||||
reconnectDragPreview() {
|
||||
const dragPreview = this.dragPreview;
|
||||
// if nothing has changed then don't resubscribe
|
||||
const didChange = this.didHandlerIdChange() ||
|
||||
this.didConnectedDragPreviewChange() ||
|
||||
this.didDragPreviewOptionsChange();
|
||||
if (didChange) {
|
||||
this.disconnectDragPreview();
|
||||
}
|
||||
if (!this.handlerId) {
|
||||
return;
|
||||
}
|
||||
if (!dragPreview) {
|
||||
this.lastConnectedDragPreview = dragPreview;
|
||||
return;
|
||||
}
|
||||
if (didChange) {
|
||||
this.lastConnectedHandlerId = this.handlerId;
|
||||
this.lastConnectedDragPreview = dragPreview;
|
||||
this.lastConnectedDragPreviewOptions = this.dragPreviewOptions;
|
||||
this.dragPreviewUnsubscribe = this.backend.connectDragPreview(this.handlerId, dragPreview, this.dragPreviewOptions);
|
||||
}
|
||||
}
|
||||
didHandlerIdChange() {
|
||||
return this.lastConnectedHandlerId !== this.handlerId;
|
||||
}
|
||||
didConnectedDragSourceChange() {
|
||||
return this.lastConnectedDragSource !== this.dragSource;
|
||||
}
|
||||
didConnectedDragPreviewChange() {
|
||||
return this.lastConnectedDragPreview !== this.dragPreview;
|
||||
}
|
||||
didDragSourceOptionsChange() {
|
||||
return !shallowEqual(this.lastConnectedDragSourceOptions, this.dragSourceOptions);
|
||||
}
|
||||
didDragPreviewOptionsChange() {
|
||||
return !shallowEqual(this.lastConnectedDragPreviewOptions, this.dragPreviewOptions);
|
||||
}
|
||||
disconnectDragSource() {
|
||||
if (this.dragSourceUnsubscribe) {
|
||||
this.dragSourceUnsubscribe();
|
||||
this.dragSourceUnsubscribe = undefined;
|
||||
}
|
||||
}
|
||||
disconnectDragPreview() {
|
||||
if (this.dragPreviewUnsubscribe) {
|
||||
this.dragPreviewUnsubscribe();
|
||||
this.dragPreviewUnsubscribe = undefined;
|
||||
this.dragPreviewNode = null;
|
||||
this.dragPreviewRef = null;
|
||||
}
|
||||
}
|
||||
get dragSource() {
|
||||
return (this.dragSourceNode || (this.dragSourceRef && this.dragSourceRef.current));
|
||||
}
|
||||
get dragPreview() {
|
||||
return (this.dragPreviewNode ||
|
||||
(this.dragPreviewRef && this.dragPreviewRef.current));
|
||||
}
|
||||
clearDragSource() {
|
||||
this.dragSourceNode = null;
|
||||
this.dragSourceRef = null;
|
||||
}
|
||||
clearDragPreview() {
|
||||
this.dragPreviewNode = null;
|
||||
this.dragPreviewRef = null;
|
||||
}
|
||||
}
|
||||
27
node_modules/react-dnd/lib/internals/TargetConnector.d.ts
generated
vendored
Normal file
27
node_modules/react-dnd/lib/internals/TargetConnector.d.ts
generated
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Backend, Identifier } from 'dnd-core';
|
||||
import { Connector } from './SourceConnector';
|
||||
import { DropTargetOptions } from '../types';
|
||||
export declare class TargetConnector implements Connector {
|
||||
hooks: any;
|
||||
private handlerId;
|
||||
private dropTargetRef;
|
||||
private dropTargetNode;
|
||||
private dropTargetOptionsInternal;
|
||||
private unsubscribeDropTarget;
|
||||
private lastConnectedHandlerId;
|
||||
private lastConnectedDropTarget;
|
||||
private lastConnectedDropTargetOptions;
|
||||
private readonly backend;
|
||||
constructor(backend: Backend);
|
||||
get connectTarget(): any;
|
||||
reconnect(): void;
|
||||
receiveHandlerId(newHandlerId: Identifier | null): void;
|
||||
get dropTargetOptions(): DropTargetOptions;
|
||||
set dropTargetOptions(options: DropTargetOptions);
|
||||
private didHandlerIdChange;
|
||||
private didDropTargetChange;
|
||||
private didOptionsChange;
|
||||
disconnectDropTarget(): void;
|
||||
private get dropTarget();
|
||||
private clearDropTarget;
|
||||
}
|
||||
92
node_modules/react-dnd/lib/internals/TargetConnector.js
generated
vendored
Normal file
92
node_modules/react-dnd/lib/internals/TargetConnector.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
import { shallowEqual } from '@react-dnd/shallowequal';
|
||||
import { wrapConnectorHooks } from './wrapConnectorHooks';
|
||||
import { isRef } from './isRef';
|
||||
export class TargetConnector {
|
||||
hooks = wrapConnectorHooks({
|
||||
dropTarget: (node, options) => {
|
||||
this.clearDropTarget();
|
||||
this.dropTargetOptions = options;
|
||||
if (isRef(node)) {
|
||||
this.dropTargetRef = node;
|
||||
}
|
||||
else {
|
||||
this.dropTargetNode = node;
|
||||
}
|
||||
this.reconnect();
|
||||
},
|
||||
});
|
||||
handlerId = null;
|
||||
// The drop target may either be attached via ref or connect function
|
||||
dropTargetRef = null;
|
||||
dropTargetNode;
|
||||
dropTargetOptionsInternal = null;
|
||||
unsubscribeDropTarget;
|
||||
lastConnectedHandlerId = null;
|
||||
lastConnectedDropTarget = null;
|
||||
lastConnectedDropTargetOptions = null;
|
||||
backend;
|
||||
constructor(backend) {
|
||||
this.backend = backend;
|
||||
}
|
||||
get connectTarget() {
|
||||
return this.dropTarget;
|
||||
}
|
||||
reconnect() {
|
||||
// if nothing has changed then don't resubscribe
|
||||
const didChange = this.didHandlerIdChange() ||
|
||||
this.didDropTargetChange() ||
|
||||
this.didOptionsChange();
|
||||
if (didChange) {
|
||||
this.disconnectDropTarget();
|
||||
}
|
||||
const dropTarget = this.dropTarget;
|
||||
if (!this.handlerId) {
|
||||
return;
|
||||
}
|
||||
if (!dropTarget) {
|
||||
this.lastConnectedDropTarget = dropTarget;
|
||||
return;
|
||||
}
|
||||
if (didChange) {
|
||||
this.lastConnectedHandlerId = this.handlerId;
|
||||
this.lastConnectedDropTarget = dropTarget;
|
||||
this.lastConnectedDropTargetOptions = this.dropTargetOptions;
|
||||
this.unsubscribeDropTarget = this.backend.connectDropTarget(this.handlerId, dropTarget, this.dropTargetOptions);
|
||||
}
|
||||
}
|
||||
receiveHandlerId(newHandlerId) {
|
||||
if (newHandlerId === this.handlerId) {
|
||||
return;
|
||||
}
|
||||
this.handlerId = newHandlerId;
|
||||
this.reconnect();
|
||||
}
|
||||
get dropTargetOptions() {
|
||||
return this.dropTargetOptionsInternal;
|
||||
}
|
||||
set dropTargetOptions(options) {
|
||||
this.dropTargetOptionsInternal = options;
|
||||
}
|
||||
didHandlerIdChange() {
|
||||
return this.lastConnectedHandlerId !== this.handlerId;
|
||||
}
|
||||
didDropTargetChange() {
|
||||
return this.lastConnectedDropTarget !== this.dropTarget;
|
||||
}
|
||||
didOptionsChange() {
|
||||
return !shallowEqual(this.lastConnectedDropTargetOptions, this.dropTargetOptions);
|
||||
}
|
||||
disconnectDropTarget() {
|
||||
if (this.unsubscribeDropTarget) {
|
||||
this.unsubscribeDropTarget();
|
||||
this.unsubscribeDropTarget = undefined;
|
||||
}
|
||||
}
|
||||
get dropTarget() {
|
||||
return (this.dropTargetNode || (this.dropTargetRef && this.dropTargetRef.current));
|
||||
}
|
||||
clearDropTarget() {
|
||||
this.dropTargetRef = null;
|
||||
this.dropTargetNode = null;
|
||||
}
|
||||
}
|
||||
5
node_modules/react-dnd/lib/internals/index.d.ts
generated
vendored
Normal file
5
node_modules/react-dnd/lib/internals/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './DragSourceMonitorImpl';
|
||||
export * from './DropTargetMonitorImpl';
|
||||
export * from './SourceConnector';
|
||||
export * from './TargetConnector';
|
||||
export * from './registration';
|
||||
5
node_modules/react-dnd/lib/internals/index.js
generated
vendored
Normal file
5
node_modules/react-dnd/lib/internals/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export * from './DragSourceMonitorImpl';
|
||||
export * from './DropTargetMonitorImpl';
|
||||
export * from './SourceConnector';
|
||||
export * from './TargetConnector';
|
||||
export * from './registration';
|
||||
4
node_modules/react-dnd/lib/internals/isRef.d.ts
generated
vendored
Normal file
4
node_modules/react-dnd/lib/internals/isRef.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface Ref<T> {
|
||||
current: T;
|
||||
}
|
||||
export declare function isRef(obj: unknown): boolean;
|
||||
7
node_modules/react-dnd/lib/internals/isRef.js
generated
vendored
Normal file
7
node_modules/react-dnd/lib/internals/isRef.js
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
export function isRef(obj) {
|
||||
return (
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
obj !== null &&
|
||||
typeof obj === 'object' &&
|
||||
Object.prototype.hasOwnProperty.call(obj, 'current'));
|
||||
}
|
||||
3
node_modules/react-dnd/lib/internals/registration.d.ts
generated
vendored
Normal file
3
node_modules/react-dnd/lib/internals/registration.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { DragDropManager, DropTarget, Unsubscribe, Identifier, TargetType, SourceType, DragSource } from 'dnd-core';
|
||||
export declare function registerTarget(type: TargetType, target: DropTarget, manager: DragDropManager): [Identifier, Unsubscribe];
|
||||
export declare function registerSource(type: SourceType, source: DragSource, manager: DragDropManager): [Identifier, Unsubscribe];
|
||||
10
node_modules/react-dnd/lib/internals/registration.js
generated
vendored
Normal file
10
node_modules/react-dnd/lib/internals/registration.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
export function registerTarget(type, target, manager) {
|
||||
const registry = manager.getRegistry();
|
||||
const targetId = registry.addTarget(type, target);
|
||||
return [targetId, () => registry.removeTarget(targetId)];
|
||||
}
|
||||
export function registerSource(type, source, manager) {
|
||||
const registry = manager.getRegistry();
|
||||
const sourceId = registry.addSource(type, source);
|
||||
return [sourceId, () => registry.removeSource(sourceId)];
|
||||
}
|
||||
1
node_modules/react-dnd/lib/internals/wrapConnectorHooks.d.ts
generated
vendored
Normal file
1
node_modules/react-dnd/lib/internals/wrapConnectorHooks.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function wrapConnectorHooks(hooks: any): any;
|
||||
76
node_modules/react-dnd/lib/internals/wrapConnectorHooks.js
generated
vendored
Normal file
76
node_modules/react-dnd/lib/internals/wrapConnectorHooks.js
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { cloneElement, isValidElement } from 'react';
|
||||
function throwIfCompositeComponentElement(element) {
|
||||
// Custom components can no longer be wrapped directly in React DnD 2.0
|
||||
// so that we don't need to depend on findDOMNode() from react-dom.
|
||||
if (typeof element.type === 'string') {
|
||||
return;
|
||||
}
|
||||
const displayName = element.type.displayName || element.type.name || 'the component';
|
||||
throw new Error('Only native element nodes can now be passed to React DnD connectors.' +
|
||||
`You can either wrap ${displayName} into a <div>, or turn it into a ` +
|
||||
'drag source or a drop target itself.');
|
||||
}
|
||||
function wrapHookToRecognizeElement(hook) {
|
||||
return (elementOrNode = null, options = null) => {
|
||||
// When passed a node, call the hook straight away.
|
||||
if (!isValidElement(elementOrNode)) {
|
||||
const node = elementOrNode;
|
||||
hook(node, options);
|
||||
// return the node so it can be chained (e.g. when within callback refs
|
||||
// <div ref={node => connectDragSource(connectDropTarget(node))}/>
|
||||
return node;
|
||||
}
|
||||
// If passed a ReactElement, clone it and attach this function as a ref.
|
||||
// This helps us achieve a neat API where user doesn't even know that refs
|
||||
// are being used under the hood.
|
||||
const element = elementOrNode;
|
||||
throwIfCompositeComponentElement(element);
|
||||
// When no options are passed, use the hook directly
|
||||
const ref = options ? (node) => hook(node, options) : hook;
|
||||
return cloneWithRef(element, ref);
|
||||
};
|
||||
}
|
||||
export function wrapConnectorHooks(hooks) {
|
||||
const wrappedHooks = {};
|
||||
Object.keys(hooks).forEach((key) => {
|
||||
const hook = hooks[key];
|
||||
// ref objects should be passed straight through without wrapping
|
||||
if (key.endsWith('Ref')) {
|
||||
wrappedHooks[key] = hooks[key];
|
||||
}
|
||||
else {
|
||||
const wrappedHook = wrapHookToRecognizeElement(hook);
|
||||
wrappedHooks[key] = () => wrappedHook;
|
||||
}
|
||||
});
|
||||
return wrappedHooks;
|
||||
}
|
||||
function setRef(ref, node) {
|
||||
if (typeof ref === 'function') {
|
||||
ref(node);
|
||||
}
|
||||
else {
|
||||
ref.current = node;
|
||||
}
|
||||
}
|
||||
function cloneWithRef(element, newRef) {
|
||||
const previousRef = element.ref;
|
||||
invariant(typeof previousRef !== 'string', 'Cannot connect React DnD to an element with an existing string ref. ' +
|
||||
'Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. ' +
|
||||
'Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs');
|
||||
if (!previousRef) {
|
||||
// When there is no ref on the element, use the new ref directly
|
||||
return cloneElement(element, {
|
||||
ref: newRef,
|
||||
});
|
||||
}
|
||||
else {
|
||||
return cloneElement(element, {
|
||||
ref: (node) => {
|
||||
setRef(previousRef, node);
|
||||
setRef(newRef, node);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user