Blame view

天文台pc/tianwentai-ui/node_modules/react-dnd-html5-backend/src/NativeDragSources/index.ts 957 Bytes
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
32
33
34
35
36
  import { NativeDragSource } from './NativeDragSource.js'
  import { nativeTypesConfig } from './nativeTypesConfig.js'
  
  export function createNativeDragSource(
  	type: string,
  	dataTransfer?: DataTransfer,
  ): NativeDragSource {
  	const config = nativeTypesConfig[type]
  	if (!config) {
  		throw new Error(`native type ${type} has no configuration`)
  	}
  	const result = new NativeDragSource(config)
  	result.loadDataTransfer(dataTransfer)
  	return result
  }
  
  export function matchNativeItemType(
  	dataTransfer: DataTransfer | null,
  ): string | null {
  	if (!dataTransfer) {
  		return null
  	}
  
  	const dataTransferTypes = Array.prototype.slice.call(dataTransfer.types || [])
  	return (
  		Object.keys(nativeTypesConfig).filter((nativeItemType) => {
  			const typeConfig = nativeTypesConfig[nativeItemType]
  			if (!typeConfig?.matchesTypes) {
  				return false
  			}
  			return typeConfig.matchesTypes.some(
  				(t) => dataTransferTypes.indexOf(t) > -1,
  			)
  		})[0] || null
  	)
  }