Add yet-another-react-lightbox package and update .gitignore to exclude node_modules
This commit is contained in:
142
frontend/node_modules/react-dnd/src/internals/DragSourceMonitorImpl.ts
generated
vendored
142
frontend/node_modules/react-dnd/src/internals/DragSourceMonitorImpl.ts
generated
vendored
@@ -1,142 +0,0 @@
|
||||
import { invariant } from '@react-dnd/invariant'
|
||||
import type {
|
||||
DragDropManager,
|
||||
DragDropMonitor,
|
||||
Identifier,
|
||||
Listener,
|
||||
Unsubscribe,
|
||||
XYCoord,
|
||||
} from 'dnd-core'
|
||||
|
||||
import type { DragSourceMonitor } from '../types/index.js'
|
||||
|
||||
let isCallingCanDrag = false
|
||||
let isCallingIsDragging = false
|
||||
|
||||
export class DragSourceMonitorImpl implements DragSourceMonitor {
|
||||
private internalMonitor: DragDropMonitor
|
||||
private sourceId: Identifier | null = null
|
||||
|
||||
public constructor(manager: DragDropManager) {
|
||||
this.internalMonitor = manager.getMonitor()
|
||||
}
|
||||
|
||||
public receiveHandlerId(sourceId: Identifier | null): void {
|
||||
this.sourceId = sourceId
|
||||
}
|
||||
|
||||
public getHandlerId(): Identifier | null {
|
||||
return this.sourceId
|
||||
}
|
||||
|
||||
public canDrag(): boolean {
|
||||
invariant(
|
||||
!isCallingCanDrag,
|
||||
'You may not call monitor.canDrag() inside your canDrag() implementation. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor',
|
||||
)
|
||||
|
||||
try {
|
||||
isCallingCanDrag = true
|
||||
return this.internalMonitor.canDragSource(this.sourceId as Identifier)
|
||||
} finally {
|
||||
isCallingCanDrag = false
|
||||
}
|
||||
}
|
||||
|
||||
public isDragging(): boolean {
|
||||
if (!this.sourceId) {
|
||||
return false
|
||||
}
|
||||
invariant(
|
||||
!isCallingIsDragging,
|
||||
'You may not call monitor.isDragging() inside your isDragging() implementation. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor',
|
||||
)
|
||||
|
||||
try {
|
||||
isCallingIsDragging = true
|
||||
return this.internalMonitor.isDraggingSource(this.sourceId)
|
||||
} finally {
|
||||
isCallingIsDragging = false
|
||||
}
|
||||
}
|
||||
|
||||
public subscribeToStateChange(
|
||||
listener: Listener,
|
||||
options?: { handlerIds?: Identifier[] },
|
||||
): Unsubscribe {
|
||||
return this.internalMonitor.subscribeToStateChange(listener, options)
|
||||
}
|
||||
|
||||
public isDraggingSource(sourceId: Identifier): boolean {
|
||||
return this.internalMonitor.isDraggingSource(sourceId)
|
||||
}
|
||||
|
||||
public isOverTarget(
|
||||
targetId: Identifier,
|
||||
options?: { shallow: boolean },
|
||||
): boolean {
|
||||
return this.internalMonitor.isOverTarget(targetId, options)
|
||||
}
|
||||
|
||||
public getTargetIds(): Identifier[] {
|
||||
return this.internalMonitor.getTargetIds()
|
||||
}
|
||||
|
||||
public isSourcePublic(): boolean | null {
|
||||
return this.internalMonitor.isSourcePublic()
|
||||
}
|
||||
|
||||
public getSourceId(): Identifier | null {
|
||||
return this.internalMonitor.getSourceId()
|
||||
}
|
||||
|
||||
public subscribeToOffsetChange(listener: Listener): Unsubscribe {
|
||||
return this.internalMonitor.subscribeToOffsetChange(listener)
|
||||
}
|
||||
|
||||
public canDragSource(sourceId: Identifier): boolean {
|
||||
return this.internalMonitor.canDragSource(sourceId)
|
||||
}
|
||||
|
||||
public canDropOnTarget(targetId: Identifier): boolean {
|
||||
return this.internalMonitor.canDropOnTarget(targetId)
|
||||
}
|
||||
|
||||
public getItemType(): Identifier | null {
|
||||
return this.internalMonitor.getItemType()
|
||||
}
|
||||
|
||||
public getItem(): any {
|
||||
return this.internalMonitor.getItem()
|
||||
}
|
||||
|
||||
public getDropResult(): any {
|
||||
return this.internalMonitor.getDropResult()
|
||||
}
|
||||
|
||||
public didDrop(): boolean {
|
||||
return this.internalMonitor.didDrop()
|
||||
}
|
||||
|
||||
public getInitialClientOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getInitialClientOffset()
|
||||
}
|
||||
|
||||
public getInitialSourceClientOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getInitialSourceClientOffset()
|
||||
}
|
||||
|
||||
public getSourceClientOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getSourceClientOffset()
|
||||
}
|
||||
|
||||
public getClientOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getClientOffset()
|
||||
}
|
||||
|
||||
public getDifferenceFromInitialOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getDifferenceFromInitialOffset()
|
||||
}
|
||||
}
|
||||
101
frontend/node_modules/react-dnd/src/internals/DropTargetMonitorImpl.ts
generated
vendored
101
frontend/node_modules/react-dnd/src/internals/DropTargetMonitorImpl.ts
generated
vendored
@@ -1,101 +0,0 @@
|
||||
import { invariant } from '@react-dnd/invariant'
|
||||
import type {
|
||||
DragDropManager,
|
||||
DragDropMonitor,
|
||||
Identifier,
|
||||
Listener,
|
||||
Unsubscribe,
|
||||
XYCoord,
|
||||
} from 'dnd-core'
|
||||
|
||||
import type { DropTargetMonitor } from '../types/index.js'
|
||||
|
||||
let isCallingCanDrop = false
|
||||
|
||||
export class DropTargetMonitorImpl implements DropTargetMonitor {
|
||||
private internalMonitor: DragDropMonitor
|
||||
private targetId: Identifier | null = null
|
||||
|
||||
public constructor(manager: DragDropManager) {
|
||||
this.internalMonitor = manager.getMonitor()
|
||||
}
|
||||
|
||||
public receiveHandlerId(targetId: Identifier | null): void {
|
||||
this.targetId = targetId
|
||||
}
|
||||
|
||||
public getHandlerId(): Identifier | null {
|
||||
return this.targetId
|
||||
}
|
||||
|
||||
public subscribeToStateChange(
|
||||
listener: Listener,
|
||||
options?: { handlerIds?: Identifier[] },
|
||||
): Unsubscribe {
|
||||
return this.internalMonitor.subscribeToStateChange(listener, options)
|
||||
}
|
||||
|
||||
public canDrop(): boolean {
|
||||
// Cut out early if the target id has not been set. This should prevent errors
|
||||
// where the user has an older version of dnd-core like in
|
||||
// https://github.com/react-dnd/react-dnd/issues/1310
|
||||
if (!this.targetId) {
|
||||
return false
|
||||
}
|
||||
invariant(
|
||||
!isCallingCanDrop,
|
||||
'You may not call monitor.canDrop() inside your canDrop() implementation. ' +
|
||||
'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target-monitor',
|
||||
)
|
||||
|
||||
try {
|
||||
isCallingCanDrop = true
|
||||
return this.internalMonitor.canDropOnTarget(this.targetId)
|
||||
} finally {
|
||||
isCallingCanDrop = false
|
||||
}
|
||||
}
|
||||
|
||||
public isOver(options?: { shallow?: boolean }): boolean {
|
||||
if (!this.targetId) {
|
||||
return false
|
||||
}
|
||||
return this.internalMonitor.isOverTarget(this.targetId, options)
|
||||
}
|
||||
|
||||
public getItemType(): Identifier | null {
|
||||
return this.internalMonitor.getItemType()
|
||||
}
|
||||
|
||||
public getItem(): any {
|
||||
return this.internalMonitor.getItem()
|
||||
}
|
||||
|
||||
public getDropResult(): any {
|
||||
return this.internalMonitor.getDropResult()
|
||||
}
|
||||
|
||||
public didDrop(): boolean {
|
||||
return this.internalMonitor.didDrop()
|
||||
}
|
||||
|
||||
public getInitialClientOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getInitialClientOffset()
|
||||
}
|
||||
|
||||
public getInitialSourceClientOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getInitialSourceClientOffset()
|
||||
}
|
||||
|
||||
public getSourceClientOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getSourceClientOffset()
|
||||
}
|
||||
|
||||
public getClientOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getClientOffset()
|
||||
}
|
||||
|
||||
public getDifferenceFromInitialOffset(): XYCoord | null {
|
||||
return this.internalMonitor.getDifferenceFromInitialOffset()
|
||||
}
|
||||
}
|
||||
231
frontend/node_modules/react-dnd/src/internals/SourceConnector.ts
generated
vendored
231
frontend/node_modules/react-dnd/src/internals/SourceConnector.ts
generated
vendored
@@ -1,231 +0,0 @@
|
||||
import { shallowEqual } from '@react-dnd/shallowequal'
|
||||
import type { Backend, Identifier, Unsubscribe } from 'dnd-core'
|
||||
import type { ReactElement, Ref, RefObject } from 'react'
|
||||
|
||||
import type { DragPreviewOptions, DragSourceOptions } from '../types/index.js'
|
||||
import { isRef } from './isRef.js'
|
||||
import { wrapConnectorHooks } from './wrapConnectorHooks.js'
|
||||
|
||||
export interface Connector {
|
||||
hooks: any
|
||||
connectTarget: any
|
||||
receiveHandlerId(handlerId: Identifier | null): void
|
||||
reconnect(): void
|
||||
}
|
||||
|
||||
export class SourceConnector implements Connector {
|
||||
public hooks = wrapConnectorHooks({
|
||||
dragSource: (
|
||||
node: Element | ReactElement | Ref<any>,
|
||||
options?: DragSourceOptions,
|
||||
) => {
|
||||
this.clearDragSource()
|
||||
this.dragSourceOptions = options || null
|
||||
if (isRef(node)) {
|
||||
this.dragSourceRef = node as RefObject<any>
|
||||
} else {
|
||||
this.dragSourceNode = node
|
||||
}
|
||||
this.reconnectDragSource()
|
||||
},
|
||||
dragPreview: (node: any, options?: DragPreviewOptions) => {
|
||||
this.clearDragPreview()
|
||||
this.dragPreviewOptions = options || null
|
||||
if (isRef(node)) {
|
||||
this.dragPreviewRef = node
|
||||
} else {
|
||||
this.dragPreviewNode = node
|
||||
}
|
||||
this.reconnectDragPreview()
|
||||
},
|
||||
})
|
||||
private handlerId: Identifier | null = null
|
||||
|
||||
// The drop target may either be attached via ref or connect function
|
||||
private dragSourceRef: RefObject<any> | null = null
|
||||
private dragSourceNode: any
|
||||
private dragSourceOptionsInternal: DragSourceOptions | null = null
|
||||
private dragSourceUnsubscribe: Unsubscribe | undefined
|
||||
|
||||
// The drag preview may either be attached via ref or connect function
|
||||
private dragPreviewRef: RefObject<any> | null = null
|
||||
private dragPreviewNode: any
|
||||
private dragPreviewOptionsInternal: DragPreviewOptions | null = null
|
||||
private dragPreviewUnsubscribe: Unsubscribe | undefined
|
||||
|
||||
private lastConnectedHandlerId: Identifier | null = null
|
||||
private lastConnectedDragSource: any = null
|
||||
private lastConnectedDragSourceOptions: any = null
|
||||
private lastConnectedDragPreview: any = null
|
||||
private lastConnectedDragPreviewOptions: any = null
|
||||
|
||||
private readonly backend: Backend
|
||||
|
||||
public constructor(backend: Backend) {
|
||||
this.backend = backend
|
||||
}
|
||||
|
||||
public receiveHandlerId(newHandlerId: Identifier | null): void {
|
||||
if (this.handlerId === newHandlerId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.handlerId = newHandlerId
|
||||
this.reconnect()
|
||||
}
|
||||
|
||||
public get connectTarget(): any {
|
||||
return this.dragSource
|
||||
}
|
||||
|
||||
public get dragSourceOptions(): DragSourceOptions | null {
|
||||
return this.dragSourceOptionsInternal
|
||||
}
|
||||
public set dragSourceOptions(options: DragSourceOptions | null) {
|
||||
this.dragSourceOptionsInternal = options
|
||||
}
|
||||
|
||||
public get dragPreviewOptions(): DragPreviewOptions | null {
|
||||
return this.dragPreviewOptionsInternal
|
||||
}
|
||||
|
||||
public set dragPreviewOptions(options: DragPreviewOptions | null) {
|
||||
this.dragPreviewOptionsInternal = options
|
||||
}
|
||||
|
||||
public reconnect(): void {
|
||||
const didChange = this.reconnectDragSource()
|
||||
this.reconnectDragPreview(didChange)
|
||||
}
|
||||
|
||||
private reconnectDragSource(): boolean {
|
||||
const dragSource = this.dragSource
|
||||
// if nothing has changed then don't resubscribe
|
||||
const didChange =
|
||||
this.didHandlerIdChange() ||
|
||||
this.didConnectedDragSourceChange() ||
|
||||
this.didDragSourceOptionsChange()
|
||||
|
||||
if (didChange) {
|
||||
this.disconnectDragSource()
|
||||
}
|
||||
|
||||
if (!this.handlerId) {
|
||||
return didChange
|
||||
}
|
||||
if (!dragSource) {
|
||||
this.lastConnectedDragSource = dragSource
|
||||
return didChange
|
||||
}
|
||||
|
||||
if (didChange) {
|
||||
this.lastConnectedHandlerId = this.handlerId
|
||||
this.lastConnectedDragSource = dragSource
|
||||
this.lastConnectedDragSourceOptions = this.dragSourceOptions
|
||||
this.dragSourceUnsubscribe = this.backend.connectDragSource(
|
||||
this.handlerId,
|
||||
dragSource,
|
||||
this.dragSourceOptions,
|
||||
)
|
||||
}
|
||||
return didChange
|
||||
}
|
||||
|
||||
private reconnectDragPreview(forceDidChange = false): void {
|
||||
const dragPreview = this.dragPreview
|
||||
// if nothing has changed then don't resubscribe
|
||||
const didChange =
|
||||
forceDidChange ||
|
||||
this.didHandlerIdChange() ||
|
||||
this.didConnectedDragPreviewChange() ||
|
||||
this.didDragPreviewOptionsChange()
|
||||
|
||||
if (didChange) {
|
||||
this.disconnectDragPreview()
|
||||
}
|
||||
|
||||
if (!this.handlerId) {
|
||||
return
|
||||
}
|
||||
if (!dragPreview) {
|
||||
this.lastConnectedDragPreview = dragPreview
|
||||
return
|
||||
}
|
||||
|
||||
if (didChange) {
|
||||
this.lastConnectedHandlerId = this.handlerId
|
||||
this.lastConnectedDragPreview = dragPreview
|
||||
this.lastConnectedDragPreviewOptions = this.dragPreviewOptions
|
||||
this.dragPreviewUnsubscribe = this.backend.connectDragPreview(
|
||||
this.handlerId,
|
||||
dragPreview,
|
||||
this.dragPreviewOptions,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private didHandlerIdChange(): boolean {
|
||||
return this.lastConnectedHandlerId !== this.handlerId
|
||||
}
|
||||
|
||||
private didConnectedDragSourceChange(): boolean {
|
||||
return this.lastConnectedDragSource !== this.dragSource
|
||||
}
|
||||
|
||||
private didConnectedDragPreviewChange(): boolean {
|
||||
return this.lastConnectedDragPreview !== this.dragPreview
|
||||
}
|
||||
|
||||
private didDragSourceOptionsChange(): boolean {
|
||||
return !shallowEqual(
|
||||
this.lastConnectedDragSourceOptions,
|
||||
this.dragSourceOptions,
|
||||
)
|
||||
}
|
||||
|
||||
private didDragPreviewOptionsChange(): boolean {
|
||||
return !shallowEqual(
|
||||
this.lastConnectedDragPreviewOptions,
|
||||
this.dragPreviewOptions,
|
||||
)
|
||||
}
|
||||
|
||||
public disconnectDragSource() {
|
||||
if (this.dragSourceUnsubscribe) {
|
||||
this.dragSourceUnsubscribe()
|
||||
this.dragSourceUnsubscribe = undefined
|
||||
}
|
||||
}
|
||||
|
||||
public disconnectDragPreview() {
|
||||
if (this.dragPreviewUnsubscribe) {
|
||||
this.dragPreviewUnsubscribe()
|
||||
this.dragPreviewUnsubscribe = undefined
|
||||
this.dragPreviewNode = null
|
||||
this.dragPreviewRef = null
|
||||
}
|
||||
}
|
||||
|
||||
private get dragSource() {
|
||||
return (
|
||||
this.dragSourceNode || (this.dragSourceRef && this.dragSourceRef.current)
|
||||
)
|
||||
}
|
||||
|
||||
private get dragPreview() {
|
||||
return (
|
||||
this.dragPreviewNode ||
|
||||
(this.dragPreviewRef && this.dragPreviewRef.current)
|
||||
)
|
||||
}
|
||||
|
||||
private clearDragSource() {
|
||||
this.dragSourceNode = null
|
||||
this.dragSourceRef = null
|
||||
}
|
||||
|
||||
private clearDragPreview() {
|
||||
this.dragPreviewNode = null
|
||||
this.dragPreviewRef = null
|
||||
}
|
||||
}
|
||||
125
frontend/node_modules/react-dnd/src/internals/TargetConnector.ts
generated
vendored
125
frontend/node_modules/react-dnd/src/internals/TargetConnector.ts
generated
vendored
@@ -1,125 +0,0 @@
|
||||
import { shallowEqual } from '@react-dnd/shallowequal'
|
||||
import type { Backend, Identifier, Unsubscribe } from 'dnd-core'
|
||||
import type { RefObject } from 'react'
|
||||
|
||||
import type { DropTargetOptions } from '../types/index.js'
|
||||
import { isRef } from './isRef.js'
|
||||
import type { Connector } from './SourceConnector.js'
|
||||
import { wrapConnectorHooks } from './wrapConnectorHooks.js'
|
||||
|
||||
export class TargetConnector implements Connector {
|
||||
public hooks = wrapConnectorHooks({
|
||||
dropTarget: (node: any, options: DropTargetOptions) => {
|
||||
this.clearDropTarget()
|
||||
this.dropTargetOptions = options
|
||||
if (isRef(node)) {
|
||||
this.dropTargetRef = node
|
||||
} else {
|
||||
this.dropTargetNode = node
|
||||
}
|
||||
this.reconnect()
|
||||
},
|
||||
})
|
||||
|
||||
private handlerId: Identifier | null = null
|
||||
// The drop target may either be attached via ref or connect function
|
||||
private dropTargetRef: RefObject<any> | null = null
|
||||
private dropTargetNode: any
|
||||
private dropTargetOptionsInternal: DropTargetOptions | null = null
|
||||
private unsubscribeDropTarget: Unsubscribe | undefined
|
||||
|
||||
private lastConnectedHandlerId: Identifier | null = null
|
||||
private lastConnectedDropTarget: any = null
|
||||
private lastConnectedDropTargetOptions: DropTargetOptions | null = null
|
||||
private readonly backend: Backend
|
||||
|
||||
public constructor(backend: Backend) {
|
||||
this.backend = backend
|
||||
}
|
||||
|
||||
public get connectTarget(): any {
|
||||
return this.dropTarget
|
||||
}
|
||||
|
||||
public reconnect(): void {
|
||||
// if nothing has changed then don't resubscribe
|
||||
const didChange =
|
||||
this.didHandlerIdChange() ||
|
||||
this.didDropTargetChange() ||
|
||||
this.didOptionsChange()
|
||||
|
||||
if (didChange) {
|
||||
this.disconnectDropTarget()
|
||||
}
|
||||
|
||||
const dropTarget = this.dropTarget
|
||||
if (!this.handlerId) {
|
||||
return
|
||||
}
|
||||
if (!dropTarget) {
|
||||
this.lastConnectedDropTarget = dropTarget
|
||||
return
|
||||
}
|
||||
|
||||
if (didChange) {
|
||||
this.lastConnectedHandlerId = this.handlerId
|
||||
this.lastConnectedDropTarget = dropTarget
|
||||
this.lastConnectedDropTargetOptions = this.dropTargetOptions
|
||||
|
||||
this.unsubscribeDropTarget = this.backend.connectDropTarget(
|
||||
this.handlerId,
|
||||
dropTarget,
|
||||
this.dropTargetOptions,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
public receiveHandlerId(newHandlerId: Identifier | null): void {
|
||||
if (newHandlerId === this.handlerId) {
|
||||
return
|
||||
}
|
||||
|
||||
this.handlerId = newHandlerId
|
||||
this.reconnect()
|
||||
}
|
||||
|
||||
public get dropTargetOptions(): DropTargetOptions {
|
||||
return this.dropTargetOptionsInternal
|
||||
}
|
||||
public set dropTargetOptions(options: DropTargetOptions) {
|
||||
this.dropTargetOptionsInternal = options
|
||||
}
|
||||
|
||||
private didHandlerIdChange(): boolean {
|
||||
return this.lastConnectedHandlerId !== this.handlerId
|
||||
}
|
||||
|
||||
private didDropTargetChange(): boolean {
|
||||
return this.lastConnectedDropTarget !== this.dropTarget
|
||||
}
|
||||
|
||||
private didOptionsChange(): boolean {
|
||||
return !shallowEqual(
|
||||
this.lastConnectedDropTargetOptions,
|
||||
this.dropTargetOptions,
|
||||
)
|
||||
}
|
||||
|
||||
public disconnectDropTarget() {
|
||||
if (this.unsubscribeDropTarget) {
|
||||
this.unsubscribeDropTarget()
|
||||
this.unsubscribeDropTarget = undefined
|
||||
}
|
||||
}
|
||||
|
||||
private get dropTarget() {
|
||||
return (
|
||||
this.dropTargetNode || (this.dropTargetRef && this.dropTargetRef.current)
|
||||
)
|
||||
}
|
||||
|
||||
private clearDropTarget() {
|
||||
this.dropTargetRef = null
|
||||
this.dropTargetNode = null
|
||||
}
|
||||
}
|
||||
5
frontend/node_modules/react-dnd/src/internals/index.ts
generated
vendored
5
frontend/node_modules/react-dnd/src/internals/index.ts
generated
vendored
@@ -1,5 +0,0 @@
|
||||
export * from './DragSourceMonitorImpl.js'
|
||||
export * from './DropTargetMonitorImpl.js'
|
||||
export * from './registration.js'
|
||||
export * from './SourceConnector.js'
|
||||
export * from './TargetConnector.js'
|
||||
12
frontend/node_modules/react-dnd/src/internals/isRef.ts
generated
vendored
12
frontend/node_modules/react-dnd/src/internals/isRef.ts
generated
vendored
@@ -1,12 +0,0 @@
|
||||
export interface Ref<T> {
|
||||
current: T
|
||||
}
|
||||
|
||||
export function isRef(obj: unknown): boolean {
|
||||
return (
|
||||
// eslint-disable-next-line no-prototype-builtins
|
||||
obj !== null &&
|
||||
typeof obj === 'object' &&
|
||||
Object.prototype.hasOwnProperty.call(obj, 'current')
|
||||
)
|
||||
}
|
||||
31
frontend/node_modules/react-dnd/src/internals/registration.ts
generated
vendored
31
frontend/node_modules/react-dnd/src/internals/registration.ts
generated
vendored
@@ -1,31 +0,0 @@
|
||||
import type {
|
||||
DragDropManager,
|
||||
DragSource,
|
||||
DropTarget,
|
||||
Identifier,
|
||||
SourceType,
|
||||
TargetType,
|
||||
Unsubscribe,
|
||||
} from 'dnd-core'
|
||||
|
||||
export function registerTarget(
|
||||
type: TargetType,
|
||||
target: DropTarget,
|
||||
manager: DragDropManager,
|
||||
): [Identifier, Unsubscribe] {
|
||||
const registry = manager.getRegistry()
|
||||
const targetId = registry.addTarget(type, target)
|
||||
|
||||
return [targetId, () => registry.removeTarget(targetId)]
|
||||
}
|
||||
|
||||
export function registerSource(
|
||||
type: SourceType,
|
||||
source: DragSource,
|
||||
manager: DragDropManager,
|
||||
): [Identifier, Unsubscribe] {
|
||||
const registry = manager.getRegistry()
|
||||
const sourceId = registry.addSource(type, source)
|
||||
|
||||
return [sourceId, () => registry.removeSource(sourceId)]
|
||||
}
|
||||
93
frontend/node_modules/react-dnd/src/internals/wrapConnectorHooks.ts
generated
vendored
93
frontend/node_modules/react-dnd/src/internals/wrapConnectorHooks.ts
generated
vendored
@@ -1,93 +0,0 @@
|
||||
import { invariant } from '@react-dnd/invariant'
|
||||
import type { ReactElement } from 'react'
|
||||
import { cloneElement, isValidElement } from 'react'
|
||||
|
||||
function throwIfCompositeComponentElement(element: ReactElement<any>) {
|
||||
// Custom components can no longer be wrapped directly in React DnD 2.0
|
||||
// so that we don't need to depend on findDOMNode() from react-dom.
|
||||
if (typeof element.type === 'string') {
|
||||
return
|
||||
}
|
||||
|
||||
const displayName =
|
||||
(element.type as any).displayName || element.type.name || 'the component'
|
||||
|
||||
throw new Error(
|
||||
'Only native element nodes can now be passed to React DnD connectors.' +
|
||||
`You can either wrap ${displayName} into a <div>, or turn it into a ` +
|
||||
'drag source or a drop target itself.',
|
||||
)
|
||||
}
|
||||
|
||||
function wrapHookToRecognizeElement(hook: (node: any, options: any) => void) {
|
||||
return (elementOrNode = null, options = null) => {
|
||||
// When passed a node, call the hook straight away.
|
||||
if (!isValidElement(elementOrNode)) {
|
||||
const node = elementOrNode
|
||||
hook(node, options)
|
||||
// return the node so it can be chained (e.g. when within callback refs
|
||||
// <div ref={node => connectDragSource(connectDropTarget(node))}/>
|
||||
return node
|
||||
}
|
||||
|
||||
// If passed a ReactElement, clone it and attach this function as a ref.
|
||||
// This helps us achieve a neat API where user doesn't even know that refs
|
||||
// are being used under the hood.
|
||||
const element: ReactElement | null = elementOrNode
|
||||
throwIfCompositeComponentElement(element as any)
|
||||
|
||||
// When no options are passed, use the hook directly
|
||||
const ref = options ? (node: Element) => hook(node, options) : hook
|
||||
return cloneWithRef(element, ref)
|
||||
}
|
||||
}
|
||||
|
||||
export function wrapConnectorHooks(hooks: any) {
|
||||
const wrappedHooks: any = {}
|
||||
|
||||
Object.keys(hooks).forEach((key) => {
|
||||
const hook = hooks[key]
|
||||
|
||||
// ref objects should be passed straight through without wrapping
|
||||
if (key.endsWith('Ref')) {
|
||||
wrappedHooks[key] = hooks[key]
|
||||
} else {
|
||||
const wrappedHook = wrapHookToRecognizeElement(hook)
|
||||
wrappedHooks[key] = () => wrappedHook
|
||||
}
|
||||
})
|
||||
|
||||
return wrappedHooks
|
||||
}
|
||||
|
||||
function setRef(ref: any, node: any) {
|
||||
if (typeof ref === 'function') {
|
||||
ref(node)
|
||||
} else {
|
||||
ref.current = node
|
||||
}
|
||||
}
|
||||
|
||||
function cloneWithRef(element: any, newRef: any): ReactElement<any> {
|
||||
const previousRef = element.ref
|
||||
invariant(
|
||||
typeof previousRef !== 'string',
|
||||
'Cannot connect React DnD to an element with an existing string ref. ' +
|
||||
'Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. ' +
|
||||
'Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs',
|
||||
)
|
||||
|
||||
if (!previousRef) {
|
||||
// When there is no ref on the element, use the new ref directly
|
||||
return cloneElement(element, {
|
||||
ref: newRef,
|
||||
})
|
||||
} else {
|
||||
return cloneElement(element, {
|
||||
ref: (node: any) => {
|
||||
setRef(previousRef, node)
|
||||
setRef(newRef, node)
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user