This commit is contained in:
2
node_modules/dnd-core/lib/actions/dragDrop/beginDrag.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/actions/dragDrop/beginDrag.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Action, DragDropManager, BeginDragPayload, BeginDragOptions, Identifier } from '../../interfaces';
|
||||
export declare function createBeginDrag(manager: DragDropManager): (sourceIds?: Identifier[], options?: BeginDragOptions) => Action<BeginDragPayload> | undefined;
|
||||
82
node_modules/dnd-core/lib/actions/dragDrop/beginDrag.js
generated
vendored
Normal file
82
node_modules/dnd-core/lib/actions/dragDrop/beginDrag.js
generated
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { setClientOffset } from './local/setClientOffset';
|
||||
import { isObject } from '../../utils/js_utils';
|
||||
import { BEGIN_DRAG, INIT_COORDS } from './types';
|
||||
const ResetCoordinatesAction = {
|
||||
type: INIT_COORDS,
|
||||
payload: {
|
||||
clientOffset: null,
|
||||
sourceClientOffset: null,
|
||||
},
|
||||
};
|
||||
export function createBeginDrag(manager) {
|
||||
return function beginDrag(sourceIds = [], options = {
|
||||
publishSource: true,
|
||||
}) {
|
||||
const { publishSource = true, clientOffset, getSourceClientOffset, } = options;
|
||||
const monitor = manager.getMonitor();
|
||||
const registry = manager.getRegistry();
|
||||
// Initialize the coordinates using the client offset
|
||||
manager.dispatch(setClientOffset(clientOffset));
|
||||
verifyInvariants(sourceIds, monitor, registry);
|
||||
// Get the draggable source
|
||||
const sourceId = getDraggableSource(sourceIds, monitor);
|
||||
if (sourceId === null) {
|
||||
manager.dispatch(ResetCoordinatesAction);
|
||||
return;
|
||||
}
|
||||
// Get the source client offset
|
||||
let sourceClientOffset = null;
|
||||
if (clientOffset) {
|
||||
if (!getSourceClientOffset) {
|
||||
throw new Error('getSourceClientOffset must be defined');
|
||||
}
|
||||
verifyGetSourceClientOffsetIsFunction(getSourceClientOffset);
|
||||
sourceClientOffset = getSourceClientOffset(sourceId);
|
||||
}
|
||||
// Initialize the full coordinates
|
||||
manager.dispatch(setClientOffset(clientOffset, sourceClientOffset));
|
||||
const source = registry.getSource(sourceId);
|
||||
const item = source.beginDrag(monitor, sourceId);
|
||||
// If source.beginDrag returns null, this is an indicator to cancel the drag
|
||||
if (item == null) {
|
||||
return undefined;
|
||||
}
|
||||
verifyItemIsObject(item);
|
||||
registry.pinSource(sourceId);
|
||||
const itemType = registry.getSourceType(sourceId);
|
||||
return {
|
||||
type: BEGIN_DRAG,
|
||||
payload: {
|
||||
itemType,
|
||||
item,
|
||||
sourceId,
|
||||
clientOffset: clientOffset || null,
|
||||
sourceClientOffset: sourceClientOffset || null,
|
||||
isSourcePublic: !!publishSource,
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
function verifyInvariants(sourceIds, monitor, registry) {
|
||||
invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.');
|
||||
sourceIds.forEach(function (sourceId) {
|
||||
invariant(registry.getSource(sourceId), 'Expected sourceIds to be registered.');
|
||||
});
|
||||
}
|
||||
function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) {
|
||||
invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.');
|
||||
}
|
||||
function verifyItemIsObject(item) {
|
||||
invariant(isObject(item), 'Item must be an object.');
|
||||
}
|
||||
function getDraggableSource(sourceIds, monitor) {
|
||||
let sourceId = null;
|
||||
for (let i = sourceIds.length - 1; i >= 0; i--) {
|
||||
if (monitor.canDragSource(sourceIds[i])) {
|
||||
sourceId = sourceIds[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return sourceId;
|
||||
}
|
||||
2
node_modules/dnd-core/lib/actions/dragDrop/drop.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/actions/dragDrop/drop.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { DragDropManager } from '../../interfaces';
|
||||
export declare function createDrop(manager: DragDropManager): (options?: {}) => void;
|
||||
48
node_modules/dnd-core/lib/actions/dragDrop/drop.js
generated
vendored
Normal file
48
node_modules/dnd-core/lib/actions/dragDrop/drop.js
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { DROP } from './types';
|
||||
import { isObject } from '../../utils/js_utils';
|
||||
export function createDrop(manager) {
|
||||
return function drop(options = {}) {
|
||||
const monitor = manager.getMonitor();
|
||||
const registry = manager.getRegistry();
|
||||
verifyInvariants(monitor);
|
||||
const targetIds = getDroppableTargets(monitor);
|
||||
// Multiple actions are dispatched here, which is why this doesn't return an action
|
||||
targetIds.forEach((targetId, index) => {
|
||||
const dropResult = determineDropResult(targetId, index, registry, monitor);
|
||||
const action = {
|
||||
type: DROP,
|
||||
payload: {
|
||||
dropResult: {
|
||||
...options,
|
||||
...dropResult,
|
||||
},
|
||||
},
|
||||
};
|
||||
manager.dispatch(action);
|
||||
});
|
||||
};
|
||||
}
|
||||
function verifyInvariants(monitor) {
|
||||
invariant(monitor.isDragging(), 'Cannot call drop while not dragging.');
|
||||
invariant(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.');
|
||||
}
|
||||
function determineDropResult(targetId, index, registry, monitor) {
|
||||
const target = registry.getTarget(targetId);
|
||||
let dropResult = target ? target.drop(monitor, targetId) : undefined;
|
||||
verifyDropResultType(dropResult);
|
||||
if (typeof dropResult === 'undefined') {
|
||||
dropResult = index === 0 ? {} : monitor.getDropResult();
|
||||
}
|
||||
return dropResult;
|
||||
}
|
||||
function verifyDropResultType(dropResult) {
|
||||
invariant(typeof dropResult === 'undefined' || isObject(dropResult), 'Drop result must either be an object or undefined.');
|
||||
}
|
||||
function getDroppableTargets(monitor) {
|
||||
const targetIds = monitor
|
||||
.getTargetIds()
|
||||
.filter(monitor.canDropOnTarget, monitor);
|
||||
targetIds.reverse();
|
||||
return targetIds;
|
||||
}
|
||||
2
node_modules/dnd-core/lib/actions/dragDrop/endDrag.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/actions/dragDrop/endDrag.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { DragDropManager, SentinelAction } from '../../interfaces';
|
||||
export declare function createEndDrag(manager: DragDropManager): () => SentinelAction;
|
||||
19
node_modules/dnd-core/lib/actions/dragDrop/endDrag.js
generated
vendored
Normal file
19
node_modules/dnd-core/lib/actions/dragDrop/endDrag.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { END_DRAG } from './types';
|
||||
export function createEndDrag(manager) {
|
||||
return function endDrag() {
|
||||
const monitor = manager.getMonitor();
|
||||
const registry = manager.getRegistry();
|
||||
verifyIsDragging(monitor);
|
||||
const sourceId = monitor.getSourceId();
|
||||
if (sourceId != null) {
|
||||
const source = registry.getSource(sourceId, true);
|
||||
source.endDrag(monitor, sourceId);
|
||||
registry.unpinSource();
|
||||
}
|
||||
return { type: END_DRAG };
|
||||
};
|
||||
}
|
||||
function verifyIsDragging(monitor) {
|
||||
invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.');
|
||||
}
|
||||
2
node_modules/dnd-core/lib/actions/dragDrop/hover.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/actions/dragDrop/hover.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Action, DragDropManager, HoverPayload, HoverOptions } from '../../interfaces';
|
||||
export declare function createHover(manager: DragDropManager): (targetIdsArg: string[], { clientOffset }?: HoverOptions) => Action<HoverPayload>;
|
||||
54
node_modules/dnd-core/lib/actions/dragDrop/hover.js
generated
vendored
Normal file
54
node_modules/dnd-core/lib/actions/dragDrop/hover.js
generated
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { matchesType } from '../../utils/matchesType';
|
||||
import { HOVER } from './types';
|
||||
export function createHover(manager) {
|
||||
return function hover(targetIdsArg, { clientOffset } = {}) {
|
||||
verifyTargetIdsIsArray(targetIdsArg);
|
||||
const targetIds = targetIdsArg.slice(0);
|
||||
const monitor = manager.getMonitor();
|
||||
const registry = manager.getRegistry();
|
||||
checkInvariants(targetIds, monitor, registry);
|
||||
const draggedItemType = monitor.getItemType();
|
||||
removeNonMatchingTargetIds(targetIds, registry, draggedItemType);
|
||||
hoverAllTargets(targetIds, monitor, registry);
|
||||
return {
|
||||
type: HOVER,
|
||||
payload: {
|
||||
targetIds,
|
||||
clientOffset: clientOffset || null,
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
function verifyTargetIdsIsArray(targetIdsArg) {
|
||||
invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.');
|
||||
}
|
||||
function checkInvariants(targetIds, monitor, registry) {
|
||||
invariant(monitor.isDragging(), 'Cannot call hover while not dragging.');
|
||||
invariant(!monitor.didDrop(), 'Cannot call hover after drop.');
|
||||
for (let i = 0; i < targetIds.length; i++) {
|
||||
const targetId = targetIds[i];
|
||||
invariant(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.');
|
||||
const target = registry.getTarget(targetId);
|
||||
invariant(target, 'Expected targetIds to be registered.');
|
||||
}
|
||||
}
|
||||
function removeNonMatchingTargetIds(targetIds, registry, draggedItemType) {
|
||||
// Remove those targetIds that don't match the targetType. This
|
||||
// fixes shallow isOver which would only be non-shallow because of
|
||||
// non-matching targets.
|
||||
for (let i = targetIds.length - 1; i >= 0; i--) {
|
||||
const targetId = targetIds[i];
|
||||
const targetType = registry.getTargetType(targetId);
|
||||
if (!matchesType(targetType, draggedItemType)) {
|
||||
targetIds.splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
function hoverAllTargets(targetIds, monitor, registry) {
|
||||
// Finally call hover on all matching targets.
|
||||
targetIds.forEach(function (targetId) {
|
||||
const target = registry.getTarget(targetId);
|
||||
target.hover(monitor, targetId);
|
||||
});
|
||||
}
|
||||
3
node_modules/dnd-core/lib/actions/dragDrop/index.d.ts
generated
vendored
Normal file
3
node_modules/dnd-core/lib/actions/dragDrop/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { DragDropManager, DragDropActions } from '../../interfaces';
|
||||
export * from './types';
|
||||
export declare function createDragDropActions(manager: DragDropManager): DragDropActions;
|
||||
15
node_modules/dnd-core/lib/actions/dragDrop/index.js
generated
vendored
Normal file
15
node_modules/dnd-core/lib/actions/dragDrop/index.js
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { createBeginDrag } from './beginDrag';
|
||||
import { createPublishDragSource } from './publishDragSource';
|
||||
import { createHover } from './hover';
|
||||
import { createDrop } from './drop';
|
||||
import { createEndDrag } from './endDrag';
|
||||
export * from './types';
|
||||
export function createDragDropActions(manager) {
|
||||
return {
|
||||
beginDrag: createBeginDrag(manager),
|
||||
publishDragSource: createPublishDragSource(manager),
|
||||
hover: createHover(manager),
|
||||
drop: createDrop(manager),
|
||||
endDrag: createEndDrag(manager),
|
||||
};
|
||||
}
|
||||
3
node_modules/dnd-core/lib/actions/dragDrop/local/setClientOffset.d.ts
generated
vendored
Normal file
3
node_modules/dnd-core/lib/actions/dragDrop/local/setClientOffset.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { XYCoord } from '../../../interfaces';
|
||||
import { AnyAction } from 'redux';
|
||||
export declare function setClientOffset(clientOffset: XYCoord | null | undefined, sourceClientOffset?: XYCoord | null | undefined): AnyAction;
|
||||
10
node_modules/dnd-core/lib/actions/dragDrop/local/setClientOffset.js
generated
vendored
Normal file
10
node_modules/dnd-core/lib/actions/dragDrop/local/setClientOffset.js
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { INIT_COORDS } from '../types';
|
||||
export function setClientOffset(clientOffset, sourceClientOffset) {
|
||||
return {
|
||||
type: INIT_COORDS,
|
||||
payload: {
|
||||
sourceClientOffset: sourceClientOffset || null,
|
||||
clientOffset: clientOffset || null,
|
||||
},
|
||||
};
|
||||
}
|
||||
2
node_modules/dnd-core/lib/actions/dragDrop/publishDragSource.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/actions/dragDrop/publishDragSource.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { DragDropManager, SentinelAction } from '../../interfaces';
|
||||
export declare function createPublishDragSource(manager: DragDropManager): () => SentinelAction | undefined;
|
||||
9
node_modules/dnd-core/lib/actions/dragDrop/publishDragSource.js
generated
vendored
Normal file
9
node_modules/dnd-core/lib/actions/dragDrop/publishDragSource.js
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { PUBLISH_DRAG_SOURCE } from './types';
|
||||
export function createPublishDragSource(manager) {
|
||||
return function publishDragSource() {
|
||||
const monitor = manager.getMonitor();
|
||||
if (monitor.isDragging()) {
|
||||
return { type: PUBLISH_DRAG_SOURCE };
|
||||
}
|
||||
};
|
||||
}
|
||||
6
node_modules/dnd-core/lib/actions/dragDrop/types.d.ts
generated
vendored
Normal file
6
node_modules/dnd-core/lib/actions/dragDrop/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export declare const INIT_COORDS = "dnd-core/INIT_COORDS";
|
||||
export declare const BEGIN_DRAG = "dnd-core/BEGIN_DRAG";
|
||||
export declare const PUBLISH_DRAG_SOURCE = "dnd-core/PUBLISH_DRAG_SOURCE";
|
||||
export declare const HOVER = "dnd-core/HOVER";
|
||||
export declare const DROP = "dnd-core/DROP";
|
||||
export declare const END_DRAG = "dnd-core/END_DRAG";
|
||||
6
node_modules/dnd-core/lib/actions/dragDrop/types.js
generated
vendored
Normal file
6
node_modules/dnd-core/lib/actions/dragDrop/types.js
generated
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
export const INIT_COORDS = 'dnd-core/INIT_COORDS';
|
||||
export const BEGIN_DRAG = 'dnd-core/BEGIN_DRAG';
|
||||
export const PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE';
|
||||
export const HOVER = 'dnd-core/HOVER';
|
||||
export const DROP = 'dnd-core/DROP';
|
||||
export const END_DRAG = 'dnd-core/END_DRAG';
|
||||
9
node_modules/dnd-core/lib/actions/registry.d.ts
generated
vendored
Normal file
9
node_modules/dnd-core/lib/actions/registry.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Action, SourceIdPayload, TargetIdPayload } from '../interfaces';
|
||||
export declare const ADD_SOURCE = "dnd-core/ADD_SOURCE";
|
||||
export declare const ADD_TARGET = "dnd-core/ADD_TARGET";
|
||||
export declare const REMOVE_SOURCE = "dnd-core/REMOVE_SOURCE";
|
||||
export declare const REMOVE_TARGET = "dnd-core/REMOVE_TARGET";
|
||||
export declare function addSource(sourceId: string): Action<SourceIdPayload>;
|
||||
export declare function addTarget(targetId: string): Action<TargetIdPayload>;
|
||||
export declare function removeSource(sourceId: string): Action<SourceIdPayload>;
|
||||
export declare function removeTarget(targetId: string): Action<TargetIdPayload>;
|
||||
36
node_modules/dnd-core/lib/actions/registry.js
generated
vendored
Normal file
36
node_modules/dnd-core/lib/actions/registry.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
export const ADD_SOURCE = 'dnd-core/ADD_SOURCE';
|
||||
export const ADD_TARGET = 'dnd-core/ADD_TARGET';
|
||||
export const REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE';
|
||||
export const REMOVE_TARGET = 'dnd-core/REMOVE_TARGET';
|
||||
export function addSource(sourceId) {
|
||||
return {
|
||||
type: ADD_SOURCE,
|
||||
payload: {
|
||||
sourceId,
|
||||
},
|
||||
};
|
||||
}
|
||||
export function addTarget(targetId) {
|
||||
return {
|
||||
type: ADD_TARGET,
|
||||
payload: {
|
||||
targetId,
|
||||
},
|
||||
};
|
||||
}
|
||||
export function removeSource(sourceId) {
|
||||
return {
|
||||
type: REMOVE_SOURCE,
|
||||
payload: {
|
||||
sourceId,
|
||||
},
|
||||
};
|
||||
}
|
||||
export function removeTarget(targetId) {
|
||||
return {
|
||||
type: REMOVE_TARGET,
|
||||
payload: {
|
||||
targetId,
|
||||
},
|
||||
};
|
||||
}
|
||||
17
node_modules/dnd-core/lib/classes/DragDropManagerImpl.d.ts
generated
vendored
Normal file
17
node_modules/dnd-core/lib/classes/DragDropManagerImpl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
import { Store, Action } from 'redux';
|
||||
import { Backend, DragDropActions, DragDropMonitor, DragDropManager, HandlerRegistry } from '../interfaces';
|
||||
import { State } from '../reducers';
|
||||
export declare class DragDropManagerImpl implements DragDropManager {
|
||||
private store;
|
||||
private monitor;
|
||||
private backend;
|
||||
private isSetUp;
|
||||
constructor(store: Store<State>, monitor: DragDropMonitor);
|
||||
receiveBackend(backend: Backend): void;
|
||||
getMonitor(): DragDropMonitor;
|
||||
getBackend(): Backend;
|
||||
getRegistry(): HandlerRegistry;
|
||||
getActions(): DragDropActions;
|
||||
dispatch(action: Action<any>): void;
|
||||
private handleRefCountChange;
|
||||
}
|
||||
59
node_modules/dnd-core/lib/classes/DragDropManagerImpl.js
generated
vendored
Normal file
59
node_modules/dnd-core/lib/classes/DragDropManagerImpl.js
generated
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
import { createDragDropActions } from '../actions/dragDrop';
|
||||
export class DragDropManagerImpl {
|
||||
store;
|
||||
monitor;
|
||||
backend;
|
||||
isSetUp = false;
|
||||
constructor(store, monitor) {
|
||||
this.store = store;
|
||||
this.monitor = monitor;
|
||||
store.subscribe(this.handleRefCountChange);
|
||||
}
|
||||
receiveBackend(backend) {
|
||||
this.backend = backend;
|
||||
}
|
||||
getMonitor() {
|
||||
return this.monitor;
|
||||
}
|
||||
getBackend() {
|
||||
return this.backend;
|
||||
}
|
||||
getRegistry() {
|
||||
return this.monitor.registry;
|
||||
}
|
||||
getActions() {
|
||||
/* eslint-disable-next-line @typescript-eslint/no-this-alias */
|
||||
const manager = this;
|
||||
const { dispatch } = this.store;
|
||||
function bindActionCreator(actionCreator) {
|
||||
return (...args) => {
|
||||
const action = actionCreator.apply(manager, args);
|
||||
if (typeof action !== 'undefined') {
|
||||
dispatch(action);
|
||||
}
|
||||
};
|
||||
}
|
||||
const actions = createDragDropActions(this);
|
||||
return Object.keys(actions).reduce((boundActions, key) => {
|
||||
const action = actions[key];
|
||||
boundActions[key] = bindActionCreator(action);
|
||||
return boundActions;
|
||||
}, {});
|
||||
}
|
||||
dispatch(action) {
|
||||
this.store.dispatch(action);
|
||||
}
|
||||
handleRefCountChange = () => {
|
||||
const shouldSetUp = this.store.getState().refCount > 0;
|
||||
if (this.backend) {
|
||||
if (shouldSetUp && !this.isSetUp) {
|
||||
this.backend.setup();
|
||||
this.isSetUp = true;
|
||||
}
|
||||
else if (!shouldSetUp && this.isSetUp) {
|
||||
this.backend.teardown();
|
||||
this.isSetUp = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
31
node_modules/dnd-core/lib/classes/DragDropMonitorImpl.d.ts
generated
vendored
Normal file
31
node_modules/dnd-core/lib/classes/DragDropMonitorImpl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Store } from 'redux';
|
||||
import { State } from '../reducers';
|
||||
import { DragDropMonitor, Listener, Unsubscribe, XYCoord, HandlerRegistry, Identifier } from '../interfaces';
|
||||
export declare class DragDropMonitorImpl implements DragDropMonitor {
|
||||
private store;
|
||||
readonly registry: HandlerRegistry;
|
||||
constructor(store: Store<State>, registry: HandlerRegistry);
|
||||
subscribeToStateChange(listener: Listener, options?: {
|
||||
handlerIds: string[] | undefined;
|
||||
}): Unsubscribe;
|
||||
subscribeToOffsetChange(listener: Listener): Unsubscribe;
|
||||
canDragSource(sourceId: string | undefined): boolean;
|
||||
canDropOnTarget(targetId: string | undefined): boolean;
|
||||
isDragging(): boolean;
|
||||
isDraggingSource(sourceId: string | undefined): boolean;
|
||||
isOverTarget(targetId: string | undefined, options?: {
|
||||
shallow: boolean;
|
||||
}): boolean;
|
||||
getItemType(): Identifier;
|
||||
getItem(): any;
|
||||
getSourceId(): string | null;
|
||||
getTargetIds(): string[];
|
||||
getDropResult(): any;
|
||||
didDrop(): boolean;
|
||||
isSourcePublic(): boolean;
|
||||
getInitialClientOffset(): XYCoord | null;
|
||||
getInitialSourceClientOffset(): XYCoord | null;
|
||||
getClientOffset(): XYCoord | null;
|
||||
getSourceClientOffset(): XYCoord | null;
|
||||
getDifferenceFromInitialOffset(): XYCoord | null;
|
||||
}
|
||||
154
node_modules/dnd-core/lib/classes/DragDropMonitorImpl.js
generated
vendored
Normal file
154
node_modules/dnd-core/lib/classes/DragDropMonitorImpl.js
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { matchesType } from '../utils/matchesType';
|
||||
import { getSourceClientOffset, getDifferenceFromInitialOffset, } from '../utils/coords';
|
||||
import { areDirty } from '../utils/dirtiness';
|
||||
export class DragDropMonitorImpl {
|
||||
store;
|
||||
registry;
|
||||
constructor(store, registry) {
|
||||
this.store = store;
|
||||
this.registry = registry;
|
||||
}
|
||||
subscribeToStateChange(listener, options = { handlerIds: undefined }) {
|
||||
const { handlerIds } = options;
|
||||
invariant(typeof listener === 'function', 'listener must be a function.');
|
||||
invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.');
|
||||
let prevStateId = this.store.getState().stateId;
|
||||
const handleChange = () => {
|
||||
const state = this.store.getState();
|
||||
const currentStateId = state.stateId;
|
||||
try {
|
||||
const canSkipListener = currentStateId === prevStateId ||
|
||||
(currentStateId === prevStateId + 1 &&
|
||||
!areDirty(state.dirtyHandlerIds, handlerIds));
|
||||
if (!canSkipListener) {
|
||||
listener();
|
||||
}
|
||||
}
|
||||
finally {
|
||||
prevStateId = currentStateId;
|
||||
}
|
||||
};
|
||||
return this.store.subscribe(handleChange);
|
||||
}
|
||||
subscribeToOffsetChange(listener) {
|
||||
invariant(typeof listener === 'function', 'listener must be a function.');
|
||||
let previousState = this.store.getState().dragOffset;
|
||||
const handleChange = () => {
|
||||
const nextState = this.store.getState().dragOffset;
|
||||
if (nextState === previousState) {
|
||||
return;
|
||||
}
|
||||
previousState = nextState;
|
||||
listener();
|
||||
};
|
||||
return this.store.subscribe(handleChange);
|
||||
}
|
||||
canDragSource(sourceId) {
|
||||
if (!sourceId) {
|
||||
return false;
|
||||
}
|
||||
const source = this.registry.getSource(sourceId);
|
||||
invariant(source, `Expected to find a valid source. sourceId=${sourceId}`);
|
||||
if (this.isDragging()) {
|
||||
return false;
|
||||
}
|
||||
return source.canDrag(this, sourceId);
|
||||
}
|
||||
canDropOnTarget(targetId) {
|
||||
// undefined on initial render
|
||||
if (!targetId) {
|
||||
return false;
|
||||
}
|
||||
const target = this.registry.getTarget(targetId);
|
||||
invariant(target, `Expected to find a valid target. targetId=${targetId}`);
|
||||
if (!this.isDragging() || this.didDrop()) {
|
||||
return false;
|
||||
}
|
||||
const targetType = this.registry.getTargetType(targetId);
|
||||
const draggedItemType = this.getItemType();
|
||||
return (matchesType(targetType, draggedItemType) && target.canDrop(this, targetId));
|
||||
}
|
||||
isDragging() {
|
||||
return Boolean(this.getItemType());
|
||||
}
|
||||
isDraggingSource(sourceId) {
|
||||
// undefined on initial render
|
||||
if (!sourceId) {
|
||||
return false;
|
||||
}
|
||||
const source = this.registry.getSource(sourceId, true);
|
||||
invariant(source, `Expected to find a valid source. sourceId=${sourceId}`);
|
||||
if (!this.isDragging() || !this.isSourcePublic()) {
|
||||
return false;
|
||||
}
|
||||
const sourceType = this.registry.getSourceType(sourceId);
|
||||
const draggedItemType = this.getItemType();
|
||||
if (sourceType !== draggedItemType) {
|
||||
return false;
|
||||
}
|
||||
return source.isDragging(this, sourceId);
|
||||
}
|
||||
isOverTarget(targetId, options = { shallow: false }) {
|
||||
// undefined on initial render
|
||||
if (!targetId) {
|
||||
return false;
|
||||
}
|
||||
const { shallow } = options;
|
||||
if (!this.isDragging()) {
|
||||
return false;
|
||||
}
|
||||
const targetType = this.registry.getTargetType(targetId);
|
||||
const draggedItemType = this.getItemType();
|
||||
if (draggedItemType && !matchesType(targetType, draggedItemType)) {
|
||||
return false;
|
||||
}
|
||||
const targetIds = this.getTargetIds();
|
||||
if (!targetIds.length) {
|
||||
return false;
|
||||
}
|
||||
const index = targetIds.indexOf(targetId);
|
||||
if (shallow) {
|
||||
return index === targetIds.length - 1;
|
||||
}
|
||||
else {
|
||||
return index > -1;
|
||||
}
|
||||
}
|
||||
getItemType() {
|
||||
return this.store.getState().dragOperation.itemType;
|
||||
}
|
||||
getItem() {
|
||||
return this.store.getState().dragOperation.item;
|
||||
}
|
||||
getSourceId() {
|
||||
return this.store.getState().dragOperation.sourceId;
|
||||
}
|
||||
getTargetIds() {
|
||||
return this.store.getState().dragOperation.targetIds;
|
||||
}
|
||||
getDropResult() {
|
||||
return this.store.getState().dragOperation.dropResult;
|
||||
}
|
||||
didDrop() {
|
||||
return this.store.getState().dragOperation.didDrop;
|
||||
}
|
||||
isSourcePublic() {
|
||||
return Boolean(this.store.getState().dragOperation.isSourcePublic);
|
||||
}
|
||||
getInitialClientOffset() {
|
||||
return this.store.getState().dragOffset.initialClientOffset;
|
||||
}
|
||||
getInitialSourceClientOffset() {
|
||||
return this.store.getState().dragOffset.initialSourceClientOffset;
|
||||
}
|
||||
getClientOffset() {
|
||||
return this.store.getState().dragOffset.clientOffset;
|
||||
}
|
||||
getSourceClientOffset() {
|
||||
return getSourceClientOffset(this.store.getState().dragOffset);
|
||||
}
|
||||
getDifferenceFromInitialOffset() {
|
||||
return getDifferenceFromInitialOffset(this.store.getState().dragOffset);
|
||||
}
|
||||
}
|
||||
26
node_modules/dnd-core/lib/classes/HandlerRegistryImpl.d.ts
generated
vendored
Normal file
26
node_modules/dnd-core/lib/classes/HandlerRegistryImpl.d.ts
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
import { Store } from 'redux';
|
||||
import { State } from '../reducers';
|
||||
import { DragSource, DropTarget, SourceType, TargetType, Identifier, HandlerRegistry } from '../interfaces';
|
||||
export declare class HandlerRegistryImpl implements HandlerRegistry {
|
||||
private types;
|
||||
private dragSources;
|
||||
private dropTargets;
|
||||
private pinnedSourceId;
|
||||
private pinnedSource;
|
||||
private store;
|
||||
constructor(store: Store<State>);
|
||||
addSource(type: SourceType, source: DragSource): string;
|
||||
addTarget(type: TargetType, target: DropTarget): string;
|
||||
containsHandler(handler: DragSource | DropTarget): boolean;
|
||||
getSource(sourceId: string, includePinned?: boolean): DragSource;
|
||||
getTarget(targetId: string): DropTarget;
|
||||
getSourceType(sourceId: string): Identifier;
|
||||
getTargetType(targetId: string): Identifier | Identifier[];
|
||||
isSourceId(handlerId: string): boolean;
|
||||
isTargetId(handlerId: string): boolean;
|
||||
removeSource(sourceId: string): void;
|
||||
removeTarget(targetId: string): void;
|
||||
pinSource(sourceId: string): void;
|
||||
unpinSource(): void;
|
||||
private addHandler;
|
||||
}
|
||||
130
node_modules/dnd-core/lib/classes/HandlerRegistryImpl.js
generated
vendored
Normal file
130
node_modules/dnd-core/lib/classes/HandlerRegistryImpl.js
generated
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
import { addSource, addTarget, removeSource, removeTarget, } from '../actions/registry';
|
||||
import { getNextUniqueId } from '../utils/getNextUniqueId';
|
||||
import { HandlerRole, } from '../interfaces';
|
||||
import { validateSourceContract, validateTargetContract, validateType, } from '../contracts';
|
||||
import { asap } from '@react-dnd/asap';
|
||||
function getNextHandlerId(role) {
|
||||
const id = getNextUniqueId().toString();
|
||||
switch (role) {
|
||||
case HandlerRole.SOURCE:
|
||||
return `S${id}`;
|
||||
case HandlerRole.TARGET:
|
||||
return `T${id}`;
|
||||
default:
|
||||
throw new Error(`Unknown Handler Role: ${role}`);
|
||||
}
|
||||
}
|
||||
function parseRoleFromHandlerId(handlerId) {
|
||||
switch (handlerId[0]) {
|
||||
case 'S':
|
||||
return HandlerRole.SOURCE;
|
||||
case 'T':
|
||||
return HandlerRole.TARGET;
|
||||
default:
|
||||
invariant(false, `Cannot parse handler ID: ${handlerId}`);
|
||||
}
|
||||
}
|
||||
function mapContainsValue(map, searchValue) {
|
||||
const entries = map.entries();
|
||||
let isDone = false;
|
||||
do {
|
||||
const { done, value: [, value], } = entries.next();
|
||||
if (value === searchValue) {
|
||||
return true;
|
||||
}
|
||||
isDone = !!done;
|
||||
} while (!isDone);
|
||||
return false;
|
||||
}
|
||||
export class HandlerRegistryImpl {
|
||||
types = new Map();
|
||||
dragSources = new Map();
|
||||
dropTargets = new Map();
|
||||
pinnedSourceId = null;
|
||||
pinnedSource = null;
|
||||
store;
|
||||
constructor(store) {
|
||||
this.store = store;
|
||||
}
|
||||
addSource(type, source) {
|
||||
validateType(type);
|
||||
validateSourceContract(source);
|
||||
const sourceId = this.addHandler(HandlerRole.SOURCE, type, source);
|
||||
this.store.dispatch(addSource(sourceId));
|
||||
return sourceId;
|
||||
}
|
||||
addTarget(type, target) {
|
||||
validateType(type, true);
|
||||
validateTargetContract(target);
|
||||
const targetId = this.addHandler(HandlerRole.TARGET, type, target);
|
||||
this.store.dispatch(addTarget(targetId));
|
||||
return targetId;
|
||||
}
|
||||
containsHandler(handler) {
|
||||
return (mapContainsValue(this.dragSources, handler) ||
|
||||
mapContainsValue(this.dropTargets, handler));
|
||||
}
|
||||
getSource(sourceId, includePinned = false) {
|
||||
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
|
||||
const isPinned = includePinned && sourceId === this.pinnedSourceId;
|
||||
const source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId);
|
||||
return source;
|
||||
}
|
||||
getTarget(targetId) {
|
||||
invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
|
||||
return this.dropTargets.get(targetId);
|
||||
}
|
||||
getSourceType(sourceId) {
|
||||
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
|
||||
return this.types.get(sourceId);
|
||||
}
|
||||
getTargetType(targetId) {
|
||||
invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
|
||||
return this.types.get(targetId);
|
||||
}
|
||||
isSourceId(handlerId) {
|
||||
const role = parseRoleFromHandlerId(handlerId);
|
||||
return role === HandlerRole.SOURCE;
|
||||
}
|
||||
isTargetId(handlerId) {
|
||||
const role = parseRoleFromHandlerId(handlerId);
|
||||
return role === HandlerRole.TARGET;
|
||||
}
|
||||
removeSource(sourceId) {
|
||||
invariant(this.getSource(sourceId), 'Expected an existing source.');
|
||||
this.store.dispatch(removeSource(sourceId));
|
||||
asap(() => {
|
||||
this.dragSources.delete(sourceId);
|
||||
this.types.delete(sourceId);
|
||||
});
|
||||
}
|
||||
removeTarget(targetId) {
|
||||
invariant(this.getTarget(targetId), 'Expected an existing target.');
|
||||
this.store.dispatch(removeTarget(targetId));
|
||||
this.dropTargets.delete(targetId);
|
||||
this.types.delete(targetId);
|
||||
}
|
||||
pinSource(sourceId) {
|
||||
const source = this.getSource(sourceId);
|
||||
invariant(source, 'Expected an existing source.');
|
||||
this.pinnedSourceId = sourceId;
|
||||
this.pinnedSource = source;
|
||||
}
|
||||
unpinSource() {
|
||||
invariant(this.pinnedSource, 'No source is pinned at the time.');
|
||||
this.pinnedSourceId = null;
|
||||
this.pinnedSource = null;
|
||||
}
|
||||
addHandler(role, type, handler) {
|
||||
const id = getNextHandlerId(role);
|
||||
this.types.set(id, type);
|
||||
if (role === HandlerRole.SOURCE) {
|
||||
this.dragSources.set(id, handler);
|
||||
}
|
||||
else if (role === HandlerRole.TARGET) {
|
||||
this.dropTargets.set(id, handler);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
}
|
||||
4
node_modules/dnd-core/lib/contracts.d.ts
generated
vendored
Normal file
4
node_modules/dnd-core/lib/contracts.d.ts
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { DragSource, DropTarget, Identifier } from './interfaces';
|
||||
export declare function validateSourceContract(source: DragSource): void;
|
||||
export declare function validateTargetContract(target: DropTarget): void;
|
||||
export declare function validateType(type: Identifier | Identifier[], allowArray?: boolean): void;
|
||||
20
node_modules/dnd-core/lib/contracts.js
generated
vendored
Normal file
20
node_modules/dnd-core/lib/contracts.js
generated
vendored
Normal file
@@ -0,0 +1,20 @@
|
||||
import { invariant } from '@react-dnd/invariant';
|
||||
export function validateSourceContract(source) {
|
||||
invariant(typeof source.canDrag === 'function', 'Expected canDrag to be a function.');
|
||||
invariant(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.');
|
||||
invariant(typeof source.endDrag === 'function', 'Expected endDrag to be a function.');
|
||||
}
|
||||
export function validateTargetContract(target) {
|
||||
invariant(typeof target.canDrop === 'function', 'Expected canDrop to be a function.');
|
||||
invariant(typeof target.hover === 'function', 'Expected hover to be a function.');
|
||||
invariant(typeof target.drop === 'function', 'Expected beginDrag to be a function.');
|
||||
}
|
||||
export function validateType(type, allowArray) {
|
||||
if (allowArray && Array.isArray(type)) {
|
||||
type.forEach((t) => validateType(t, false));
|
||||
return;
|
||||
}
|
||||
invariant(typeof type === 'string' || typeof type === 'symbol', allowArray
|
||||
? 'Type can only be a string, a symbol, or an array of either.'
|
||||
: 'Type can only be a string or a symbol.');
|
||||
}
|
||||
2
node_modules/dnd-core/lib/createDragDropManager.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/createDragDropManager.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { DragDropManager, BackendFactory } from './interfaces';
|
||||
export declare function createDragDropManager(backendFactory: BackendFactory, globalContext?: unknown, backendOptions?: unknown, debugMode?: boolean): DragDropManager;
|
||||
25
node_modules/dnd-core/lib/createDragDropManager.js
generated
vendored
Normal file
25
node_modules/dnd-core/lib/createDragDropManager.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
import { DragDropManagerImpl } from './classes/DragDropManagerImpl';
|
||||
import { createStore } from 'redux';
|
||||
import { reduce } from './reducers';
|
||||
import { DragDropMonitorImpl } from './classes/DragDropMonitorImpl';
|
||||
import { HandlerRegistryImpl } from './classes/HandlerRegistryImpl';
|
||||
export function createDragDropManager(backendFactory, globalContext = undefined, backendOptions = {}, debugMode = false) {
|
||||
const store = makeStoreInstance(debugMode);
|
||||
const monitor = new DragDropMonitorImpl(store, new HandlerRegistryImpl(store));
|
||||
const manager = new DragDropManagerImpl(store, monitor);
|
||||
const backend = backendFactory(manager, globalContext, backendOptions);
|
||||
manager.receiveBackend(backend);
|
||||
return manager;
|
||||
}
|
||||
function makeStoreInstance(debugMode) {
|
||||
// TODO: if we ever make a react-native version of this,
|
||||
// we'll need to consider how to pull off dev-tooling
|
||||
const reduxDevTools = typeof window !== 'undefined' &&
|
||||
window.__REDUX_DEVTOOLS_EXTENSION__;
|
||||
return createStore(reduce, debugMode &&
|
||||
reduxDevTools &&
|
||||
reduxDevTools({
|
||||
name: 'dnd-core',
|
||||
instanceId: 'dnd-core',
|
||||
}));
|
||||
}
|
||||
2
node_modules/dnd-core/lib/index.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './interfaces';
|
||||
export * from './createDragDropManager';
|
||||
2
node_modules/dnd-core/lib/index.js
generated
vendored
Normal file
2
node_modules/dnd-core/lib/index.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export * from './interfaces';
|
||||
export * from './createDragDropManager';
|
||||
170
node_modules/dnd-core/lib/interfaces.d.ts
generated
vendored
Normal file
170
node_modules/dnd-core/lib/interfaces.d.ts
generated
vendored
Normal file
@@ -0,0 +1,170 @@
|
||||
export declare type Identifier = string | symbol;
|
||||
export declare type SourceType = Identifier;
|
||||
export declare type TargetType = Identifier | Identifier[];
|
||||
export declare type Unsubscribe = () => void;
|
||||
export declare type Listener = () => void;
|
||||
export interface XYCoord {
|
||||
x: number;
|
||||
y: number;
|
||||
}
|
||||
export declare enum HandlerRole {
|
||||
SOURCE = "SOURCE",
|
||||
TARGET = "TARGET"
|
||||
}
|
||||
export interface Backend {
|
||||
setup(): void;
|
||||
teardown(): void;
|
||||
connectDragSource(sourceId: any, node?: any, options?: any): Unsubscribe;
|
||||
connectDragPreview(sourceId: any, node?: any, options?: any): Unsubscribe;
|
||||
connectDropTarget(targetId: any, node?: any, options?: any): Unsubscribe;
|
||||
profile(): Record<string, number>;
|
||||
}
|
||||
export interface DragDropMonitor {
|
||||
subscribeToStateChange(listener: Listener, options?: {
|
||||
handlerIds: Identifier[] | undefined;
|
||||
}): Unsubscribe;
|
||||
subscribeToOffsetChange(listener: Listener): Unsubscribe;
|
||||
canDragSource(sourceId: Identifier | undefined): boolean;
|
||||
canDropOnTarget(targetId: Identifier | undefined): boolean;
|
||||
/**
|
||||
* Returns true if a drag operation is in progress, and either the owner initiated the drag, or its isDragging()
|
||||
* is defined and returns true.
|
||||
*/
|
||||
isDragging(): boolean;
|
||||
isDraggingSource(sourceId: Identifier | undefined): boolean;
|
||||
isOverTarget(targetId: Identifier | undefined, options?: {
|
||||
shallow?: boolean;
|
||||
}): boolean;
|
||||
/**
|
||||
* Returns a string or a symbol identifying the type of the current dragged item. Returns null if no item is being dragged.
|
||||
*/
|
||||
getItemType(): Identifier | null;
|
||||
/**
|
||||
* Returns a plain object representing the currently dragged item. Every drag source must specify it by returning an object
|
||||
* from its beginDrag() method. Returns null if no item is being dragged.
|
||||
*/
|
||||
getItem(): any;
|
||||
getSourceId(): Identifier | null;
|
||||
getTargetIds(): Identifier[];
|
||||
/**
|
||||
* Returns a plain object representing the last recorded drop result. The drop targets may optionally specify it by returning an
|
||||
* object from their drop() methods. When a chain of drop() is dispatched for the nested targets, bottom up, any parent that
|
||||
* explicitly returns its own result from drop() overrides the child drop result previously set by the child. Returns null if
|
||||
* called outside endDrag().
|
||||
*/
|
||||
getDropResult(): any;
|
||||
/**
|
||||
* Returns true if some drop target has handled the drop event, false otherwise. Even if a target did not return a drop result,
|
||||
* didDrop() returns true. Use it inside endDrag() to test whether any drop target has handled the drop. Returns false if called
|
||||
* outside endDrag().
|
||||
*/
|
||||
didDrop(): boolean;
|
||||
isSourcePublic(): boolean | null;
|
||||
/**
|
||||
* Returns the { x, y } client offset of the pointer at the time when the current drag operation has started.
|
||||
* Returns null if no item is being dragged.
|
||||
*/
|
||||
getInitialClientOffset(): XYCoord | null;
|
||||
/**
|
||||
* Returns the { x, y } client offset of the drag source component's root DOM node at the time when the current drag
|
||||
* operation has started. Returns null if no item is being dragged.
|
||||
*/
|
||||
getInitialSourceClientOffset(): XYCoord | null;
|
||||
/**
|
||||
* Returns the last recorded { x, y } client offset of the pointer while a drag operation is in progress.
|
||||
* Returns null if no item is being dragged.
|
||||
*/
|
||||
getClientOffset(): XYCoord | null;
|
||||
/**
|
||||
* Returns the projected { x, y } client offset of the drag source component's root DOM node, based on its position at the time
|
||||
* when the current drag operation has started, and the movement difference. Returns null if no item is being dragged.
|
||||
*/
|
||||
getSourceClientOffset(): XYCoord | null;
|
||||
/**
|
||||
* Returns the { x, y } difference between the last recorded client offset of the pointer and the client offset when the current
|
||||
* drag operation has started. Returns null if no item is being dragged.
|
||||
*/
|
||||
getDifferenceFromInitialOffset(): XYCoord | null;
|
||||
}
|
||||
export interface HandlerRegistry {
|
||||
addSource(type: SourceType, source: DragSource): Identifier;
|
||||
addTarget(type: TargetType, target: DropTarget): Identifier;
|
||||
containsHandler(handler: DragSource | DropTarget): boolean;
|
||||
getSource(sourceId: Identifier, includePinned?: boolean): DragSource;
|
||||
getSourceType(sourceId: Identifier): SourceType;
|
||||
getTargetType(targetId: Identifier): TargetType;
|
||||
getTarget(targetId: Identifier): DropTarget;
|
||||
isSourceId(handlerId: Identifier): boolean;
|
||||
isTargetId(handlerId: Identifier): boolean;
|
||||
removeSource(sourceId: Identifier): void;
|
||||
removeTarget(targetId: Identifier): void;
|
||||
pinSource(sourceId: Identifier): void;
|
||||
unpinSource(): void;
|
||||
}
|
||||
export interface Action<Payload> {
|
||||
type: Identifier;
|
||||
payload: Payload;
|
||||
}
|
||||
export interface SentinelAction {
|
||||
type: Identifier;
|
||||
}
|
||||
export declare type ActionCreator<Payload> = (args: any[]) => Action<Payload>;
|
||||
export interface BeginDragOptions {
|
||||
publishSource?: boolean;
|
||||
clientOffset?: XYCoord;
|
||||
getSourceClientOffset?: (sourceId: Identifier) => XYCoord;
|
||||
}
|
||||
export interface InitCoordsPayload {
|
||||
clientOffset: XYCoord | null;
|
||||
sourceClientOffset: XYCoord | null;
|
||||
}
|
||||
export interface BeginDragPayload {
|
||||
itemType: Identifier;
|
||||
item: any;
|
||||
sourceId: Identifier;
|
||||
clientOffset: XYCoord | null;
|
||||
sourceClientOffset: XYCoord | null;
|
||||
isSourcePublic: boolean;
|
||||
}
|
||||
export interface HoverPayload {
|
||||
targetIds: Identifier[];
|
||||
clientOffset: XYCoord | null;
|
||||
}
|
||||
export interface HoverOptions {
|
||||
clientOffset?: XYCoord;
|
||||
}
|
||||
export interface DropPayload {
|
||||
dropResult: any;
|
||||
}
|
||||
export interface TargetIdPayload {
|
||||
targetId: Identifier;
|
||||
}
|
||||
export interface SourceIdPayload {
|
||||
sourceId: Identifier;
|
||||
}
|
||||
export interface DragDropActions {
|
||||
beginDrag(sourceIds?: Identifier[], options?: any): Action<BeginDragPayload> | undefined;
|
||||
publishDragSource(): SentinelAction | undefined;
|
||||
hover(targetIds: Identifier[], options?: any): Action<HoverPayload>;
|
||||
drop(options?: any): void;
|
||||
endDrag(): SentinelAction;
|
||||
}
|
||||
export interface DragDropManager {
|
||||
getMonitor(): DragDropMonitor;
|
||||
getBackend(): Backend;
|
||||
getRegistry(): HandlerRegistry;
|
||||
getActions(): DragDropActions;
|
||||
dispatch(action: any): void;
|
||||
}
|
||||
export declare type BackendFactory = (manager: DragDropManager, globalContext?: any, configuration?: any) => Backend;
|
||||
export interface DragSource {
|
||||
beginDrag(monitor: DragDropMonitor, targetId: Identifier): void;
|
||||
endDrag(monitor: DragDropMonitor, targetId: Identifier): void;
|
||||
canDrag(monitor: DragDropMonitor, targetId: Identifier): boolean;
|
||||
isDragging(monitor: DragDropMonitor, targetId: Identifier): boolean;
|
||||
}
|
||||
export interface DropTarget {
|
||||
canDrop(monitor: DragDropMonitor, targetId: Identifier): boolean;
|
||||
hover(monitor: DragDropMonitor, targetId: Identifier): void;
|
||||
drop(monitor: DragDropMonitor, targetId: Identifier): any;
|
||||
}
|
||||
5
node_modules/dnd-core/lib/interfaces.js
generated
vendored
Normal file
5
node_modules/dnd-core/lib/interfaces.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
export var HandlerRole;
|
||||
(function (HandlerRole) {
|
||||
HandlerRole["SOURCE"] = "SOURCE";
|
||||
HandlerRole["TARGET"] = "TARGET";
|
||||
})(HandlerRole || (HandlerRole = {}));
|
||||
7
node_modules/dnd-core/lib/reducers/dirtyHandlerIds.d.ts
generated
vendored
Normal file
7
node_modules/dnd-core/lib/reducers/dirtyHandlerIds.d.ts
generated
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Action } from '../interfaces';
|
||||
export declare type State = string[];
|
||||
export interface DirtyHandlerIdPayload {
|
||||
targetIds: string[];
|
||||
prevTargetIds: string[];
|
||||
}
|
||||
export declare function reduce(_state: State | undefined, action: Action<DirtyHandlerIdPayload>): State;
|
||||
43
node_modules/dnd-core/lib/reducers/dirtyHandlerIds.js
generated
vendored
Normal file
43
node_modules/dnd-core/lib/reducers/dirtyHandlerIds.js
generated
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP, } from '../actions/dragDrop';
|
||||
import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET, } from '../actions/registry';
|
||||
import { areArraysEqual } from '../utils/equality';
|
||||
import { NONE, ALL } from '../utils/dirtiness';
|
||||
import { xor } from '../utils/js_utils';
|
||||
export function reduce(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
_state = NONE, action) {
|
||||
switch (action.type) {
|
||||
case HOVER:
|
||||
break;
|
||||
case ADD_SOURCE:
|
||||
case ADD_TARGET:
|
||||
case REMOVE_TARGET:
|
||||
case REMOVE_SOURCE:
|
||||
return NONE;
|
||||
case BEGIN_DRAG:
|
||||
case PUBLISH_DRAG_SOURCE:
|
||||
case END_DRAG:
|
||||
case DROP:
|
||||
default:
|
||||
return ALL;
|
||||
}
|
||||
const { targetIds = [], prevTargetIds = [] } = action.payload;
|
||||
const result = xor(targetIds, prevTargetIds);
|
||||
const didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds);
|
||||
if (!didChange) {
|
||||
return NONE;
|
||||
}
|
||||
// Check the target ids at the innermost position. If they are valid, add them
|
||||
// to the result
|
||||
const prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1];
|
||||
const innermostTargetId = targetIds[targetIds.length - 1];
|
||||
if (prevInnermostTargetId !== innermostTargetId) {
|
||||
if (prevInnermostTargetId) {
|
||||
result.push(prevInnermostTargetId);
|
||||
}
|
||||
if (innermostTargetId) {
|
||||
result.push(innermostTargetId);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
10
node_modules/dnd-core/lib/reducers/dragOffset.d.ts
generated
vendored
Normal file
10
node_modules/dnd-core/lib/reducers/dragOffset.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import { XYCoord, Action } from '../interfaces';
|
||||
export interface State {
|
||||
initialSourceClientOffset: XYCoord | null;
|
||||
initialClientOffset: XYCoord | null;
|
||||
clientOffset: XYCoord | null;
|
||||
}
|
||||
export declare function reduce(state: State | undefined, action: Action<{
|
||||
sourceClientOffset: XYCoord;
|
||||
clientOffset: XYCoord;
|
||||
}>): State;
|
||||
32
node_modules/dnd-core/lib/reducers/dragOffset.js
generated
vendored
Normal file
32
node_modules/dnd-core/lib/reducers/dragOffset.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import { INIT_COORDS, BEGIN_DRAG, HOVER, END_DRAG, DROP, } from '../actions/dragDrop';
|
||||
import { areCoordsEqual } from '../utils/equality';
|
||||
const initialState = {
|
||||
initialSourceClientOffset: null,
|
||||
initialClientOffset: null,
|
||||
clientOffset: null,
|
||||
};
|
||||
export function reduce(state = initialState, action) {
|
||||
const { payload } = action;
|
||||
switch (action.type) {
|
||||
case INIT_COORDS:
|
||||
case BEGIN_DRAG:
|
||||
return {
|
||||
initialSourceClientOffset: payload.sourceClientOffset,
|
||||
initialClientOffset: payload.clientOffset,
|
||||
clientOffset: payload.clientOffset,
|
||||
};
|
||||
case HOVER:
|
||||
if (areCoordsEqual(state.clientOffset, payload.clientOffset)) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
clientOffset: payload.clientOffset,
|
||||
};
|
||||
case END_DRAG:
|
||||
case DROP:
|
||||
return initialState;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
19
node_modules/dnd-core/lib/reducers/dragOperation.d.ts
generated
vendored
Normal file
19
node_modules/dnd-core/lib/reducers/dragOperation.d.ts
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import { Identifier, Action } from '../interfaces';
|
||||
export interface State {
|
||||
itemType: Identifier | Identifier[] | null;
|
||||
item: any;
|
||||
sourceId: string | null;
|
||||
targetIds: string[];
|
||||
dropResult: any;
|
||||
didDrop: boolean;
|
||||
isSourcePublic: boolean | null;
|
||||
}
|
||||
export declare function reduce(state: State | undefined, action: Action<{
|
||||
itemType: Identifier | Identifier[];
|
||||
item: any;
|
||||
sourceId: string;
|
||||
targetId: string;
|
||||
targetIds: string[];
|
||||
isSourcePublic: boolean;
|
||||
dropResult: any;
|
||||
}>): State;
|
||||
65
node_modules/dnd-core/lib/reducers/dragOperation.js
generated
vendored
Normal file
65
node_modules/dnd-core/lib/reducers/dragOperation.js
generated
vendored
Normal file
@@ -0,0 +1,65 @@
|
||||
import { BEGIN_DRAG, PUBLISH_DRAG_SOURCE, HOVER, END_DRAG, DROP, } from '../actions/dragDrop';
|
||||
import { REMOVE_TARGET } from '../actions/registry';
|
||||
import { without } from '../utils/js_utils';
|
||||
const initialState = {
|
||||
itemType: null,
|
||||
item: null,
|
||||
sourceId: null,
|
||||
targetIds: [],
|
||||
dropResult: null,
|
||||
didDrop: false,
|
||||
isSourcePublic: null,
|
||||
};
|
||||
export function reduce(state = initialState, action) {
|
||||
const { payload } = action;
|
||||
switch (action.type) {
|
||||
case BEGIN_DRAG:
|
||||
return {
|
||||
...state,
|
||||
itemType: payload.itemType,
|
||||
item: payload.item,
|
||||
sourceId: payload.sourceId,
|
||||
isSourcePublic: payload.isSourcePublic,
|
||||
dropResult: null,
|
||||
didDrop: false,
|
||||
};
|
||||
case PUBLISH_DRAG_SOURCE:
|
||||
return {
|
||||
...state,
|
||||
isSourcePublic: true,
|
||||
};
|
||||
case HOVER:
|
||||
return {
|
||||
...state,
|
||||
targetIds: payload.targetIds,
|
||||
};
|
||||
case REMOVE_TARGET:
|
||||
if (state.targetIds.indexOf(payload.targetId) === -1) {
|
||||
return state;
|
||||
}
|
||||
return {
|
||||
...state,
|
||||
targetIds: without(state.targetIds, payload.targetId),
|
||||
};
|
||||
case DROP:
|
||||
return {
|
||||
...state,
|
||||
dropResult: payload.dropResult,
|
||||
didDrop: true,
|
||||
targetIds: [],
|
||||
};
|
||||
case END_DRAG:
|
||||
return {
|
||||
...state,
|
||||
itemType: null,
|
||||
item: null,
|
||||
sourceId: null,
|
||||
dropResult: null,
|
||||
didDrop: false,
|
||||
isSourcePublic: null,
|
||||
targetIds: [],
|
||||
};
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
14
node_modules/dnd-core/lib/reducers/index.d.ts
generated
vendored
Normal file
14
node_modules/dnd-core/lib/reducers/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import { State as DragOffsetState } from './dragOffset';
|
||||
import { State as DragOperationState } from './dragOperation';
|
||||
import { State as RefCountState } from './refCount';
|
||||
import { State as DirtyHandlerIdsState } from './dirtyHandlerIds';
|
||||
import { State as StateIdState } from './stateId';
|
||||
import { Action } from '../interfaces';
|
||||
export interface State {
|
||||
dirtyHandlerIds: DirtyHandlerIdsState;
|
||||
dragOffset: DragOffsetState;
|
||||
refCount: RefCountState;
|
||||
dragOperation: DragOperationState;
|
||||
stateId: StateIdState;
|
||||
}
|
||||
export declare function reduce(state: State | undefined, action: Action<any>): State;
|
||||
21
node_modules/dnd-core/lib/reducers/index.js
generated
vendored
Normal file
21
node_modules/dnd-core/lib/reducers/index.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { reduce as dragOffset } from './dragOffset';
|
||||
import { reduce as dragOperation, } from './dragOperation';
|
||||
import { reduce as refCount } from './refCount';
|
||||
import { reduce as dirtyHandlerIds, } from './dirtyHandlerIds';
|
||||
import { reduce as stateId } from './stateId';
|
||||
import { get } from '../utils/js_utils';
|
||||
export function reduce(state = {}, action) {
|
||||
return {
|
||||
dirtyHandlerIds: dirtyHandlerIds(state.dirtyHandlerIds, {
|
||||
type: action.type,
|
||||
payload: {
|
||||
...action.payload,
|
||||
prevTargetIds: get(state, 'dragOperation.targetIds', []),
|
||||
},
|
||||
}),
|
||||
dragOffset: dragOffset(state.dragOffset, action),
|
||||
refCount: refCount(state.refCount, action),
|
||||
dragOperation: dragOperation(state.dragOperation, action),
|
||||
stateId: stateId(state.stateId),
|
||||
};
|
||||
}
|
||||
3
node_modules/dnd-core/lib/reducers/refCount.d.ts
generated
vendored
Normal file
3
node_modules/dnd-core/lib/reducers/refCount.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Action } from '../interfaces';
|
||||
export declare type State = number;
|
||||
export declare function reduce(state: number | undefined, action: Action<any>): State;
|
||||
13
node_modules/dnd-core/lib/reducers/refCount.js
generated
vendored
Normal file
13
node_modules/dnd-core/lib/reducers/refCount.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import { ADD_SOURCE, ADD_TARGET, REMOVE_SOURCE, REMOVE_TARGET, } from '../actions/registry';
|
||||
export function reduce(state = 0, action) {
|
||||
switch (action.type) {
|
||||
case ADD_SOURCE:
|
||||
case ADD_TARGET:
|
||||
return state + 1;
|
||||
case REMOVE_SOURCE:
|
||||
case REMOVE_TARGET:
|
||||
return state - 1;
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
||||
2
node_modules/dnd-core/lib/reducers/stateId.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/reducers/stateId.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export declare type State = number;
|
||||
export declare function reduce(state?: State): State;
|
||||
3
node_modules/dnd-core/lib/reducers/stateId.js
generated
vendored
Normal file
3
node_modules/dnd-core/lib/reducers/stateId.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
export function reduce(state = 0) {
|
||||
return state + 1;
|
||||
}
|
||||
29
node_modules/dnd-core/lib/utils/coords.d.ts
generated
vendored
Normal file
29
node_modules/dnd-core/lib/utils/coords.d.ts
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
import { State } from '../reducers/dragOffset';
|
||||
import { XYCoord } from '..';
|
||||
/**
|
||||
* Coordinate addition
|
||||
* @param a The first coordinate
|
||||
* @param b The second coordinate
|
||||
*/
|
||||
export declare function add(a: XYCoord, b: XYCoord): XYCoord;
|
||||
/**
|
||||
* Coordinate subtraction
|
||||
* @param a The first coordinate
|
||||
* @param b The second coordinate
|
||||
*/
|
||||
export declare function subtract(a: XYCoord, b: XYCoord): XYCoord;
|
||||
/**
|
||||
* Returns the cartesian distance of the drag source component's position, based on its position
|
||||
* at the time when the current drag operation has started, and the movement difference.
|
||||
*
|
||||
* Returns null if no item is being dragged.
|
||||
*
|
||||
* @param state The offset state to compute from
|
||||
*/
|
||||
export declare function getSourceClientOffset(state: State): XYCoord | null;
|
||||
/**
|
||||
* Determines the x,y offset between the client offset and the initial client offset
|
||||
*
|
||||
* @param state The offset state to compute from
|
||||
*/
|
||||
export declare function getDifferenceFromInitialOffset(state: State): XYCoord | null;
|
||||
49
node_modules/dnd-core/lib/utils/coords.js
generated
vendored
Normal file
49
node_modules/dnd-core/lib/utils/coords.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Coordinate addition
|
||||
* @param a The first coordinate
|
||||
* @param b The second coordinate
|
||||
*/
|
||||
export function add(a, b) {
|
||||
return {
|
||||
x: a.x + b.x,
|
||||
y: a.y + b.y,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Coordinate subtraction
|
||||
* @param a The first coordinate
|
||||
* @param b The second coordinate
|
||||
*/
|
||||
export function subtract(a, b) {
|
||||
return {
|
||||
x: a.x - b.x,
|
||||
y: a.y - b.y,
|
||||
};
|
||||
}
|
||||
/**
|
||||
* Returns the cartesian distance of the drag source component's position, based on its position
|
||||
* at the time when the current drag operation has started, and the movement difference.
|
||||
*
|
||||
* Returns null if no item is being dragged.
|
||||
*
|
||||
* @param state The offset state to compute from
|
||||
*/
|
||||
export function getSourceClientOffset(state) {
|
||||
const { clientOffset, initialClientOffset, initialSourceClientOffset } = state;
|
||||
if (!clientOffset || !initialClientOffset || !initialSourceClientOffset) {
|
||||
return null;
|
||||
}
|
||||
return subtract(add(clientOffset, initialSourceClientOffset), initialClientOffset);
|
||||
}
|
||||
/**
|
||||
* Determines the x,y offset between the client offset and the initial client offset
|
||||
*
|
||||
* @param state The offset state to compute from
|
||||
*/
|
||||
export function getDifferenceFromInitialOffset(state) {
|
||||
const { clientOffset, initialClientOffset } = state;
|
||||
if (!clientOffset || !initialClientOffset) {
|
||||
return null;
|
||||
}
|
||||
return subtract(clientOffset, initialClientOffset);
|
||||
}
|
||||
9
node_modules/dnd-core/lib/utils/dirtiness.d.ts
generated
vendored
Normal file
9
node_modules/dnd-core/lib/utils/dirtiness.d.ts
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
export declare const NONE: string[];
|
||||
export declare const ALL: string[];
|
||||
/**
|
||||
* Determines if the given handler IDs are dirty or not.
|
||||
*
|
||||
* @param dirtyIds The set of dirty handler ids
|
||||
* @param handlerIds The set of handler ids to check
|
||||
*/
|
||||
export declare function areDirty(dirtyIds: string[], handlerIds: string[] | undefined): boolean;
|
||||
21
node_modules/dnd-core/lib/utils/dirtiness.js
generated
vendored
Normal file
21
node_modules/dnd-core/lib/utils/dirtiness.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { intersection } from './js_utils';
|
||||
export const NONE = [];
|
||||
export const ALL = [];
|
||||
NONE.__IS_NONE__ = true;
|
||||
ALL.__IS_ALL__ = true;
|
||||
/**
|
||||
* Determines if the given handler IDs are dirty or not.
|
||||
*
|
||||
* @param dirtyIds The set of dirty handler ids
|
||||
* @param handlerIds The set of handler ids to check
|
||||
*/
|
||||
export function areDirty(dirtyIds, handlerIds) {
|
||||
if (dirtyIds === NONE) {
|
||||
return false;
|
||||
}
|
||||
if (dirtyIds === ALL || typeof handlerIds === 'undefined') {
|
||||
return true;
|
||||
}
|
||||
const commonIds = intersection(handlerIds, dirtyIds);
|
||||
return commonIds.length > 0;
|
||||
}
|
||||
15
node_modules/dnd-core/lib/utils/equality.d.ts
generated
vendored
Normal file
15
node_modules/dnd-core/lib/utils/equality.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
import { XYCoord } from '../interfaces';
|
||||
export declare type EqualityCheck<T> = (a: T, b: T) => boolean;
|
||||
export declare const strictEquality: <T>(a: T, b: T) => boolean;
|
||||
/**
|
||||
* Determine if two cartesian coordinate offsets are equal
|
||||
* @param offsetA
|
||||
* @param offsetB
|
||||
*/
|
||||
export declare function areCoordsEqual(offsetA: XYCoord | null | undefined, offsetB: XYCoord | null | undefined): boolean;
|
||||
/**
|
||||
* Determines if two arrays of items are equal
|
||||
* @param a The first array of items
|
||||
* @param b The second array of items
|
||||
*/
|
||||
export declare function areArraysEqual<T>(a: T[], b: T[], isEqual?: EqualityCheck<T>): boolean;
|
||||
33
node_modules/dnd-core/lib/utils/equality.js
generated
vendored
Normal file
33
node_modules/dnd-core/lib/utils/equality.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
export const strictEquality = (a, b) => a === b;
|
||||
/**
|
||||
* Determine if two cartesian coordinate offsets are equal
|
||||
* @param offsetA
|
||||
* @param offsetB
|
||||
*/
|
||||
export function areCoordsEqual(offsetA, offsetB) {
|
||||
if (!offsetA && !offsetB) {
|
||||
return true;
|
||||
}
|
||||
else if (!offsetA || !offsetB) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return offsetA.x === offsetB.x && offsetA.y === offsetB.y;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Determines if two arrays of items are equal
|
||||
* @param a The first array of items
|
||||
* @param b The second array of items
|
||||
*/
|
||||
export function areArraysEqual(a, b, isEqual = strictEquality) {
|
||||
if (a.length !== b.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < a.length; ++i) {
|
||||
if (!isEqual(a[i], b[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
1
node_modules/dnd-core/lib/utils/getNextUniqueId.d.ts
generated
vendored
Normal file
1
node_modules/dnd-core/lib/utils/getNextUniqueId.d.ts
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
export declare function getNextUniqueId(): number;
|
||||
4
node_modules/dnd-core/lib/utils/getNextUniqueId.js
generated
vendored
Normal file
4
node_modules/dnd-core/lib/utils/getNextUniqueId.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
let nextUniqueId = 0;
|
||||
export function getNextUniqueId() {
|
||||
return nextUniqueId++;
|
||||
}
|
||||
33
node_modules/dnd-core/lib/utils/js_utils.d.ts
generated
vendored
Normal file
33
node_modules/dnd-core/lib/utils/js_utils.d.ts
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* drop-in replacement for _.get
|
||||
* @param obj
|
||||
* @param path
|
||||
* @param defaultValue
|
||||
*/
|
||||
export declare function get<T>(obj: any, path: string, defaultValue: T): T;
|
||||
/**
|
||||
* drop-in replacement for _.without
|
||||
*/
|
||||
export declare function without<T>(items: T[], item: T): T[];
|
||||
/**
|
||||
* drop-in replacement for _.isString
|
||||
* @param input
|
||||
*/
|
||||
export declare function isString(input: any): boolean;
|
||||
/**
|
||||
* drop-in replacement for _.isString
|
||||
* @param input
|
||||
*/
|
||||
export declare function isObject(input: any): boolean;
|
||||
/**
|
||||
* repalcement for _.xor
|
||||
* @param itemsA
|
||||
* @param itemsB
|
||||
*/
|
||||
export declare function xor<T extends string | number>(itemsA: T[], itemsB: T[]): T[];
|
||||
/**
|
||||
* replacement for _.intersection
|
||||
* @param itemsA
|
||||
* @param itemsB
|
||||
*/
|
||||
export declare function intersection<T>(itemsA: T[], itemsB: T[]): T[];
|
||||
60
node_modules/dnd-core/lib/utils/js_utils.js
generated
vendored
Normal file
60
node_modules/dnd-core/lib/utils/js_utils.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
// cheap lodash replacements
|
||||
/**
|
||||
* drop-in replacement for _.get
|
||||
* @param obj
|
||||
* @param path
|
||||
* @param defaultValue
|
||||
*/
|
||||
export function get(obj, path, defaultValue) {
|
||||
return path
|
||||
.split('.')
|
||||
.reduce((a, c) => (a && a[c] ? a[c] : defaultValue || null), obj);
|
||||
}
|
||||
/**
|
||||
* drop-in replacement for _.without
|
||||
*/
|
||||
export function without(items, item) {
|
||||
return items.filter((i) => i !== item);
|
||||
}
|
||||
/**
|
||||
* drop-in replacement for _.isString
|
||||
* @param input
|
||||
*/
|
||||
export function isString(input) {
|
||||
return typeof input === 'string';
|
||||
}
|
||||
/**
|
||||
* drop-in replacement for _.isString
|
||||
* @param input
|
||||
*/
|
||||
export function isObject(input) {
|
||||
return typeof input === 'object';
|
||||
}
|
||||
/**
|
||||
* repalcement for _.xor
|
||||
* @param itemsA
|
||||
* @param itemsB
|
||||
*/
|
||||
export function xor(itemsA, itemsB) {
|
||||
const map = new Map();
|
||||
const insertItem = (item) => {
|
||||
map.set(item, map.has(item) ? map.get(item) + 1 : 1);
|
||||
};
|
||||
itemsA.forEach(insertItem);
|
||||
itemsB.forEach(insertItem);
|
||||
const result = [];
|
||||
map.forEach((count, key) => {
|
||||
if (count === 1) {
|
||||
result.push(key);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
/**
|
||||
* replacement for _.intersection
|
||||
* @param itemsA
|
||||
* @param itemsB
|
||||
*/
|
||||
export function intersection(itemsA, itemsB) {
|
||||
return itemsA.filter((t) => itemsB.indexOf(t) > -1);
|
||||
}
|
||||
2
node_modules/dnd-core/lib/utils/matchesType.d.ts
generated
vendored
Normal file
2
node_modules/dnd-core/lib/utils/matchesType.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { Identifier } from '../interfaces';
|
||||
export declare function matchesType(targetType: Identifier | Identifier[] | null, draggedItemType: Identifier | null): boolean;
|
||||
8
node_modules/dnd-core/lib/utils/matchesType.js
generated
vendored
Normal file
8
node_modules/dnd-core/lib/utils/matchesType.js
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
export function matchesType(targetType, draggedItemType) {
|
||||
if (draggedItemType === null) {
|
||||
return targetType === null;
|
||||
}
|
||||
return Array.isArray(targetType)
|
||||
? targetType.some((t) => t === draggedItemType)
|
||||
: targetType === draggedItemType;
|
||||
}
|
||||
Reference in New Issue
Block a user