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';
|
||||
Reference in New Issue
Block a user