This commit is contained in:
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))));
|
||||
}
|
||||
Reference in New Issue
Block a user