MCPcopy Create free account
hub / github.com/pacexy/flow / DropZoneInner

Function DropZoneInner

apps/reader/src/components/base/DropZone.tsx:33–123  ·  view source on GitHub ↗
({
  children,
  className,
  onDrop,
  split = false,
})

Source from the content-addressed store, hash-verified

31}
32
33const DropZoneInner: React.FC<DropZoneProps> = ({
34 children,
35 className,
36 onDrop,
37 split = false,
38}) => {
39 const { dragover, setDragEvent } = useDndContext()
40 const [position, setPosition] = useState<Position>()
41 // console.log(dragover, position)
42
43 useEffect(() => {
44 if (!dragover) setPosition(undefined)
45 }, [dragover])
46
47 const handleDragover = useCallback(
48 (e: DragEvent<HTMLDivElement>) => {
49 e.stopPropagation()
50 e.preventDefault()
51
52 setPosition(() => {
53 if (!split) return 'universe'
54
55 const rect = (e.target as HTMLDivElement).getBoundingClientRect()
56 if (!rect.width || !rect.height) return
57
58 const offsetLeft = (e.clientX - rect.left) / rect.width
59 const offsetTop = (e.clientY - rect.top) / rect.height
60 const offsetRight = 1 - offsetLeft
61 const offsetBottom = 1 - offsetTop
62 const threshold = 0.15
63
64 // TODO: add `offsetTop` and `offsetBottom`
65 const minOffset = Math.min(offsetLeft, offsetRight)
66
67 if (minOffset > threshold) return 'universe'
68 if (minOffset === offsetLeft) return 'left'
69 if (minOffset === offsetRight) return 'right'
70 if (minOffset === offsetTop) return 'top'
71 if (minOffset === offsetBottom) return 'bottom'
72 })
73 },
74 [split],
75 )
76
77 return (
78 <div
79 className={clsx('relative', className)}
80 // https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications#selecting_files_using_drag_and_drop
81 onDragEnter={(e) => {
82 console.log('drag enter', e.dataTransfer.types)
83 if (dragover) return
84
85 setDragEvent(e)
86 e.stopPropagation()
87 e.preventDefault()
88 }}
89 >
90 {children}

Callers

nothing calls this directly

Calls 1

useDndContextFunction · 0.85

Tested by

no test coverage detected