mirror of
https://github.com/langgenius/dify.git
synced 2026-06-07 07:52:50 +08:00
- Add Rename using react-arborist native inline editing (node.edit()) - Add Delete with Confirm modal and automatic tab cleanup - Add getAllDescendantFileIds utility for finding files to close on delete - Add i18n strings for rename/delete operations (en-US, zh-Hans)
57 lines
1.4 KiB
TypeScript
57 lines
1.4 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>
|
|
}
|
|
|
|
/**
|
|
* FileTreeContextMenu - Right-click context menu for file tree
|
|
*
|
|
* Renders at absolute position when contextMenu state is set.
|
|
* Uses useClickAway to close when clicking outside.
|
|
*/
|
|
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)
|