Files
dify/web/app/components/workflow/skill/hooks/use-root-file-drop.ts
yyh 9f444f1f6a refactor(skill): split file operations hook and extract TreeNodeIcon component
Split use-file-operations.ts (248 lines) into smaller focused hooks:
- use-create-operations.ts for file/folder creation and upload
- use-modify-operations.ts for rename and delete operations
- use-file-operations.ts now serves as orchestrator maintaining backward compatibility

Extract TreeNodeIcon component from tree-node.tsx for cleaner separation of concerns.

Add brief comments to drag hooks explaining their purpose and relationships.
2026-01-19 19:13:09 +08:00

56 lines
1.6 KiB
TypeScript

'use client'
// Root-level file drop handler with drag counter to handle nested DOM events
import { useCallback, useRef } from 'react'
import { isFileDrag } from '../utils/drag-utils'
import { useFileDrop } from './use-file-drop'
type UseRootFileDropReturn = {
handleRootDragEnter: (e: React.DragEvent) => void
handleRootDragOver: (e: React.DragEvent) => void
handleRootDragLeave: (e: React.DragEvent) => void
handleRootDrop: (e: React.DragEvent) => void
resetRootDragCounter: () => void
}
export function useRootFileDrop(): UseRootFileDropReturn {
const { handleDragOver, handleDragLeave, handleDrop } = useFileDrop()
const dragCounterRef = useRef(0)
const handleRootDragEnter = useCallback((e: React.DragEvent) => {
if (!isFileDrag(e))
return
dragCounterRef.current += 1
}, [])
const handleRootDragOver = useCallback((e: React.DragEvent) => {
handleDragOver(e, { folderId: null, isFolder: false })
}, [handleDragOver])
const handleRootDragLeave = useCallback((e: React.DragEvent) => {
if (!isFileDrag(e))
return
dragCounterRef.current = Math.max(dragCounterRef.current - 1, 0)
if (dragCounterRef.current === 0)
handleDragLeave(e)
}, [handleDragLeave])
const handleRootDrop = useCallback((e: React.DragEvent) => {
dragCounterRef.current = 0
handleDrop(e, null)
}, [handleDrop])
const resetRootDragCounter = useCallback(() => {
dragCounterRef.current = 0
}, [])
return {
handleRootDragEnter,
handleRootDragOver,
handleRootDragLeave,
handleRootDrop,
resetRootDragCounter,
}
}