Blame view

天文台pc/tianwentai-ui/node_modules/react-dnd/src/hooks/useDrop/useDropTargetConnector.ts 706 Bytes
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  import { useMemo } from 'react'
  
  import { TargetConnector } from '../../internals/index.js'
  import type { DropTargetOptions } from '../../types/index.js'
  import { useDragDropManager } from '../useDragDropManager.js'
  import { useIsomorphicLayoutEffect } from '../useIsomorphicLayoutEffect.js'
  
  export function useDropTargetConnector(
  	options: DropTargetOptions,
  ): TargetConnector {
  	const manager = useDragDropManager()
  	const connector = useMemo(
  		() => new TargetConnector(manager.getBackend()),
  		[manager],
  	)
  	useIsomorphicLayoutEffect(() => {
  		connector.dropTargetOptions = options || null
  		connector.reconnect()
  		return () => connector.disconnectDropTarget()
  	}, [options])
  	return connector
  }