mirror of
https://github.com/langgenius/dify.git
synced 2026-05-02 16:38:04 +08:00
- Extract useFileOperations hook to hooks/use-file-operations.ts - Move tree utilities to utils/tree-utils.ts - Move file utilities to utils/file-utils.ts (renamed from utils.ts) - Remove unnecessary JSDoc comments throughout components - Simplify type.ts to only contain local type definitions - Clean up store/index.ts by removing verbose comments
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
'use client'
|
|
|
|
import type { FC } from 'react'
|
|
import type { TreeApi } from 'react-arborist'
|
|
import type { TreeNodeData } from './type'
|
|
import { useClickAway } from 'ahooks'
|
|
import * as React from 'react'
|
|
import { useCallback, useRef } from 'react'
|
|
import FileOperationsMenu from './file-operations-menu'
|
|
import { useSkillEditorStore, useSkillEditorStoreApi } from './store'
|
|
|
|
type FileTreeContextMenuProps = {
|
|
treeRef: React.RefObject<TreeApi<TreeNodeData> | null>
|
|
}
|
|
|
|
const FileTreeContextMenu: FC<FileTreeContextMenuProps> = ({ treeRef }) => {
|
|
const ref = useRef<HTMLDivElement>(null)
|
|
const contextMenu = useSkillEditorStore(s => s.contextMenu)
|
|
const storeApi = useSkillEditorStoreApi()
|
|
|
|
const handleClose = useCallback(() => {
|
|
storeApi.getState().setContextMenu(null)
|
|
}, [storeApi])
|
|
|
|
useClickAway(() => {
|
|
handleClose()
|
|
}, ref)
|
|
|
|
if (!contextMenu)
|
|
return null
|
|
|
|
return (
|
|
<div
|
|
ref={ref}
|
|
className="fixed z-[100]"
|
|
style={{
|
|
top: contextMenu.top,
|
|
left: contextMenu.left,
|
|
}}
|
|
>
|
|
<FileOperationsMenu
|
|
nodeId={contextMenu.nodeId}
|
|
onClose={handleClose}
|
|
treeRef={treeRef}
|
|
/>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default React.memo(FileTreeContextMenu)
|