MCPcopy
hub / github.com/react-dnd/react-dnd / SourceConnector

Class SourceConnector

packages/react-dnd/src/internals/SourceConnector.ts:16–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14}
15
16export class SourceConnector implements Connector {
17 public hooks = wrapConnectorHooks({
18 dragSource: (
19 node: Element | ReactElement | Ref<any>,
20 options?: DragSourceOptions,
21 ) => {
22 this.clearDragSource()
23 this.dragSourceOptions = options || null
24 if (isRef(node)) {
25 this.dragSourceRef = node as RefObject<any>
26 } else {
27 this.dragSourceNode = node
28 }
29 this.reconnectDragSource()
30 },
31 dragPreview: (node: any, options?: DragPreviewOptions) => {
32 this.clearDragPreview()
33 this.dragPreviewOptions = options || null
34 if (isRef(node)) {
35 this.dragPreviewRef = node
36 } else {
37 this.dragPreviewNode = node
38 }
39 this.reconnectDragPreview()
40 },
41 })
42 private handlerId: Identifier | null = null
43
44 // The drop target may either be attached via ref or connect function
45 private dragSourceRef: RefObject<any> | null = null
46 private dragSourceNode: any
47 private dragSourceOptionsInternal: DragSourceOptions | null = null
48 private dragSourceUnsubscribe: Unsubscribe | undefined
49
50 // The drag preview may either be attached via ref or connect function
51 private dragPreviewRef: RefObject<any> | null = null
52 private dragPreviewNode: any
53 private dragPreviewOptionsInternal: DragPreviewOptions | null = null
54 private dragPreviewUnsubscribe: Unsubscribe | undefined
55
56 private lastConnectedHandlerId: Identifier | null = null
57 private lastConnectedDragSource: any = null
58 private lastConnectedDragSourceOptions: any = null
59 private lastConnectedDragPreview: any = null
60 private lastConnectedDragPreviewOptions: any = null
61
62 private readonly backend: Backend
63
64 public constructor(backend: Backend) {
65 this.backend = backend
66 }
67
68 public receiveHandlerId(newHandlerId: Identifier | null): void {
69 if (this.handlerId === newHandlerId) {
70 return
71 }
72
73 this.handlerId = newHandlerId

Callers

nothing calls this directly

Calls 6

clearDragSourceMethod · 0.95
reconnectDragSourceMethod · 0.95
clearDragPreviewMethod · 0.95
reconnectDragPreviewMethod · 0.95
wrapConnectorHooksFunction · 0.85
isRefFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…