Add yet-another-react-lightbox package and update .gitignore to exclude node_modules
This commit is contained in:
123
frontend/node_modules/dnd-core/src/actions/dragDrop/beginDrag.ts
generated
vendored
123
frontend/node_modules/dnd-core/src/actions/dragDrop/beginDrag.ts
generated
vendored
@@ -1,123 +0,0 @@
|
||||
import { invariant } from '@react-dnd/invariant'
|
||||
|
||||
import type {
|
||||
Action,
|
||||
BeginDragOptions,
|
||||
BeginDragPayload,
|
||||
DragDropManager,
|
||||
DragDropMonitor,
|
||||
HandlerRegistry,
|
||||
Identifier,
|
||||
XYCoord,
|
||||
} from '../../interfaces.js'
|
||||
import { isObject } from '../../utils/js_utils.js'
|
||||
import { setClientOffset } from './local/setClientOffset.js'
|
||||
import { BEGIN_DRAG, INIT_COORDS } from './types.js'
|
||||
|
||||
const ResetCoordinatesAction = {
|
||||
type: INIT_COORDS,
|
||||
payload: {
|
||||
clientOffset: null,
|
||||
sourceClientOffset: null,
|
||||
},
|
||||
}
|
||||
|
||||
export function createBeginDrag(manager: DragDropManager) {
|
||||
return function beginDrag(
|
||||
sourceIds: Identifier[] = [],
|
||||
options: BeginDragOptions = {
|
||||
publishSource: true,
|
||||
},
|
||||
): Action<BeginDragPayload> | undefined {
|
||||
const {
|
||||
publishSource = true,
|
||||
clientOffset,
|
||||
getSourceClientOffset,
|
||||
}: BeginDragOptions = 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: XYCoord | null = 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: Identifier[],
|
||||
monitor: DragDropMonitor,
|
||||
registry: HandlerRegistry,
|
||||
) {
|
||||
invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.')
|
||||
sourceIds.forEach(function (sourceId) {
|
||||
invariant(
|
||||
registry.getSource(sourceId),
|
||||
'Expected sourceIds to be registered.',
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset: any) {
|
||||
invariant(
|
||||
typeof getSourceClientOffset === 'function',
|
||||
'When clientOffset is provided, getSourceClientOffset must be a function.',
|
||||
)
|
||||
}
|
||||
|
||||
function verifyItemIsObject(item: any) {
|
||||
invariant(isObject(item), 'Item must be an object.')
|
||||
}
|
||||
|
||||
function getDraggableSource(sourceIds: Identifier[], monitor: DragDropMonitor) {
|
||||
let sourceId = null
|
||||
for (let i = sourceIds.length - 1; i >= 0; i--) {
|
||||
if (monitor.canDragSource(sourceIds[i])) {
|
||||
sourceId = sourceIds[i]
|
||||
break
|
||||
}
|
||||
}
|
||||
return sourceId
|
||||
}
|
||||
74
frontend/node_modules/dnd-core/src/actions/dragDrop/drop.ts
generated
vendored
74
frontend/node_modules/dnd-core/src/actions/dragDrop/drop.ts
generated
vendored
@@ -1,74 +0,0 @@
|
||||
import { invariant } from '@react-dnd/invariant'
|
||||
|
||||
import type {
|
||||
Action,
|
||||
DragDropManager,
|
||||
DragDropMonitor,
|
||||
DropPayload,
|
||||
HandlerRegistry,
|
||||
Identifier,
|
||||
} from '../../interfaces.js'
|
||||
import { isObject } from '../../utils/js_utils.js'
|
||||
import { DROP } from './types.js'
|
||||
|
||||
export function createDrop(manager: DragDropManager) {
|
||||
return function drop(options = {}): void {
|
||||
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: Action<DropPayload> = {
|
||||
type: DROP,
|
||||
payload: {
|
||||
dropResult: {
|
||||
...options,
|
||||
...dropResult,
|
||||
},
|
||||
},
|
||||
}
|
||||
manager.dispatch(action)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function verifyInvariants(monitor: DragDropMonitor) {
|
||||
invariant(monitor.isDragging(), 'Cannot call drop while not dragging.')
|
||||
invariant(
|
||||
!monitor.didDrop(),
|
||||
'Cannot call drop twice during one drag operation.',
|
||||
)
|
||||
}
|
||||
|
||||
function determineDropResult(
|
||||
targetId: Identifier,
|
||||
index: number,
|
||||
registry: HandlerRegistry,
|
||||
monitor: DragDropMonitor,
|
||||
) {
|
||||
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: any) {
|
||||
invariant(
|
||||
typeof dropResult === 'undefined' || isObject(dropResult),
|
||||
'Drop result must either be an object or undefined.',
|
||||
)
|
||||
}
|
||||
|
||||
function getDroppableTargets(monitor: DragDropMonitor) {
|
||||
const targetIds = monitor
|
||||
.getTargetIds()
|
||||
.filter(monitor.canDropOnTarget, monitor)
|
||||
targetIds.reverse()
|
||||
return targetIds
|
||||
}
|
||||
28
frontend/node_modules/dnd-core/src/actions/dragDrop/endDrag.ts
generated
vendored
28
frontend/node_modules/dnd-core/src/actions/dragDrop/endDrag.ts
generated
vendored
@@ -1,28 +0,0 @@
|
||||
import { invariant } from '@react-dnd/invariant'
|
||||
|
||||
import type {
|
||||
DragDropManager,
|
||||
DragDropMonitor,
|
||||
SentinelAction,
|
||||
} from '../../interfaces.js'
|
||||
import { END_DRAG } from './types.js'
|
||||
|
||||
export function createEndDrag(manager: DragDropManager) {
|
||||
return function endDrag(): SentinelAction {
|
||||
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: DragDropMonitor) {
|
||||
invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.')
|
||||
}
|
||||
89
frontend/node_modules/dnd-core/src/actions/dragDrop/hover.ts
generated
vendored
89
frontend/node_modules/dnd-core/src/actions/dragDrop/hover.ts
generated
vendored
@@ -1,89 +0,0 @@
|
||||
import { invariant } from '@react-dnd/invariant'
|
||||
|
||||
import type {
|
||||
Action,
|
||||
DragDropManager,
|
||||
DragDropMonitor,
|
||||
HandlerRegistry,
|
||||
HoverOptions,
|
||||
HoverPayload,
|
||||
Identifier,
|
||||
} from '../../interfaces.js'
|
||||
import { matchesType } from '../../utils/matchesType.js'
|
||||
import { HOVER } from './types.js'
|
||||
|
||||
export function createHover(manager: DragDropManager) {
|
||||
return function hover(
|
||||
targetIdsArg: string[],
|
||||
{ clientOffset }: HoverOptions = {},
|
||||
): Action<HoverPayload> {
|
||||
verifyTargetIdsIsArray(targetIdsArg)
|
||||
const targetIds = targetIdsArg.slice(0)
|
||||
const monitor = manager.getMonitor()
|
||||
const registry = manager.getRegistry()
|
||||
const draggedItemType = monitor.getItemType()
|
||||
removeNonMatchingTargetIds(targetIds, registry, draggedItemType)
|
||||
checkInvariants(targetIds, monitor, registry)
|
||||
hoverAllTargets(targetIds, monitor, registry)
|
||||
|
||||
return {
|
||||
type: HOVER,
|
||||
payload: {
|
||||
targetIds,
|
||||
clientOffset: clientOffset || null,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function verifyTargetIdsIsArray(targetIdsArg: string[]) {
|
||||
invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.')
|
||||
}
|
||||
|
||||
function checkInvariants(
|
||||
targetIds: string[],
|
||||
monitor: DragDropMonitor,
|
||||
registry: HandlerRegistry,
|
||||
) {
|
||||
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] as string
|
||||
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: string[],
|
||||
registry: HandlerRegistry,
|
||||
draggedItemType: Identifier | null,
|
||||
) {
|
||||
// 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] as string
|
||||
const targetType = registry.getTargetType(targetId)
|
||||
if (!matchesType(targetType, draggedItemType)) {
|
||||
targetIds.splice(i, 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function hoverAllTargets(
|
||||
targetIds: string[],
|
||||
monitor: DragDropMonitor,
|
||||
registry: HandlerRegistry,
|
||||
) {
|
||||
// Finally call hover on all matching targets.
|
||||
targetIds.forEach(function (targetId) {
|
||||
const target = registry.getTarget(targetId)
|
||||
target.hover(monitor, targetId)
|
||||
})
|
||||
}
|
||||
20
frontend/node_modules/dnd-core/src/actions/dragDrop/index.ts
generated
vendored
20
frontend/node_modules/dnd-core/src/actions/dragDrop/index.ts
generated
vendored
@@ -1,20 +0,0 @@
|
||||
import type { DragDropActions, DragDropManager } from '../../interfaces.js'
|
||||
import { createBeginDrag } from './beginDrag.js'
|
||||
import { createDrop } from './drop.js'
|
||||
import { createEndDrag } from './endDrag.js'
|
||||
import { createHover } from './hover.js'
|
||||
import { createPublishDragSource } from './publishDragSource.js'
|
||||
|
||||
export * from './types.js'
|
||||
|
||||
export function createDragDropActions(
|
||||
manager: DragDropManager,
|
||||
): DragDropActions {
|
||||
return {
|
||||
beginDrag: createBeginDrag(manager),
|
||||
publishDragSource: createPublishDragSource(manager),
|
||||
hover: createHover(manager),
|
||||
drop: createDrop(manager),
|
||||
endDrag: createEndDrag(manager),
|
||||
}
|
||||
}
|
||||
17
frontend/node_modules/dnd-core/src/actions/dragDrop/local/setClientOffset.ts
generated
vendored
17
frontend/node_modules/dnd-core/src/actions/dragDrop/local/setClientOffset.ts
generated
vendored
@@ -1,17 +0,0 @@
|
||||
import type { AnyAction } from 'redux'
|
||||
|
||||
import type { XYCoord } from '../../../interfaces.js'
|
||||
import { INIT_COORDS } from '../types.js'
|
||||
|
||||
export function setClientOffset(
|
||||
clientOffset: XYCoord | null | undefined,
|
||||
sourceClientOffset?: XYCoord | null | undefined,
|
||||
): AnyAction {
|
||||
return {
|
||||
type: INIT_COORDS,
|
||||
payload: {
|
||||
sourceClientOffset: sourceClientOffset || null,
|
||||
clientOffset: clientOffset || null,
|
||||
},
|
||||
}
|
||||
}
|
||||
12
frontend/node_modules/dnd-core/src/actions/dragDrop/publishDragSource.ts
generated
vendored
12
frontend/node_modules/dnd-core/src/actions/dragDrop/publishDragSource.ts
generated
vendored
@@ -1,12 +0,0 @@
|
||||
import type { DragDropManager, SentinelAction } from '../../interfaces.js'
|
||||
import { PUBLISH_DRAG_SOURCE } from './types.js'
|
||||
|
||||
export function createPublishDragSource(manager: DragDropManager) {
|
||||
return function publishDragSource(): SentinelAction | undefined {
|
||||
const monitor = manager.getMonitor()
|
||||
if (monitor.isDragging()) {
|
||||
return { type: PUBLISH_DRAG_SOURCE }
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
6
frontend/node_modules/dnd-core/src/actions/dragDrop/types.ts
generated
vendored
6
frontend/node_modules/dnd-core/src/actions/dragDrop/types.ts
generated
vendored
@@ -1,6 +0,0 @@
|
||||
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'
|
||||
42
frontend/node_modules/dnd-core/src/actions/registry.ts
generated
vendored
42
frontend/node_modules/dnd-core/src/actions/registry.ts
generated
vendored
@@ -1,42 +0,0 @@
|
||||
import type { Action, SourceIdPayload, TargetIdPayload } from '../interfaces.js'
|
||||
|
||||
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: string): Action<SourceIdPayload> {
|
||||
return {
|
||||
type: ADD_SOURCE,
|
||||
payload: {
|
||||
sourceId,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function addTarget(targetId: string): Action<TargetIdPayload> {
|
||||
return {
|
||||
type: ADD_TARGET,
|
||||
payload: {
|
||||
targetId,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function removeSource(sourceId: string): Action<SourceIdPayload> {
|
||||
return {
|
||||
type: REMOVE_SOURCE,
|
||||
payload: {
|
||||
sourceId,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function removeTarget(targetId: string): Action<TargetIdPayload> {
|
||||
return {
|
||||
type: REMOVE_TARGET,
|
||||
payload: {
|
||||
targetId,
|
||||
},
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user