planning
All checks were successful
Publish To Prod / deploy_and_publish (push) Successful in 35s

This commit is contained in:
2024-10-14 09:15:30 +02:00
parent bcba00a730
commit 6e64e138e2
21059 changed files with 2317811 additions and 1 deletions

View File

@@ -0,0 +1,2 @@
import { Action, DragDropManager, BeginDragPayload, BeginDragOptions, Identifier } from '../../interfaces';
export declare function createBeginDrag(manager: DragDropManager): (sourceIds?: Identifier[], options?: BeginDragOptions) => Action<BeginDragPayload> | undefined;

View 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
View 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
View 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;
}

View 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
View 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.');
}

View 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
View 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);
});
}

View 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
View 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),
};
}

View 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;

View 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,
},
};
}

View File

@@ -0,0 +1,2 @@
import { DragDropManager, SentinelAction } from '../../interfaces';
export declare function createPublishDragSource(manager: DragDropManager): () => SentinelAction | undefined;

View 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 };
}
};
}

View 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
View 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
View 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
View 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,
},
};
}