bc518174
王天杨
提交两个项目文件
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import { useMemo } from 'react'
import { SourceConnector } from '../../internals/index.js'
import type {
DragPreviewOptions,
DragSourceOptions,
} from '../../types/index.js'
import { useDragDropManager } from '../useDragDropManager.js'
import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect.js'
export function useDragSourceConnector(
dragSourceOptions: DragSourceOptions | undefined,
dragPreviewOptions: DragPreviewOptions | undefined,
): SourceConnector {
const manager = useDragDropManager()
const connector = useMemo(
() => new SourceConnector(manager.getBackend()),
[manager],
)
useIsomorphicLayoutEffect(() => {
connector.dragSourceOptions = dragSourceOptions || null
connector.reconnect()
return () => connector.disconnectDragSource()
}, [connector, dragSourceOptions])
useIsomorphicLayoutEffect(() => {
connector.dragPreviewOptions = dragPreviewOptions || null
connector.reconnect()
return () => connector.disconnectDragPreview()
}, [connector, dragPreviewOptions])
return connector
}
|