import { memo, useEffect, useRef, } from 'react' import { useTranslation } from 'react-i18next' import { useClickAway } from 'ahooks' import ShortcutsName from './shortcuts-name' import { useStore } from './store' import { useDSL, useNodesInteractions, usePanelInteractions, useWorkflowStartRun, } from './hooks' import AddBlock from './operator/add-block' import { useOperator } from './operator/hooks' import cn from '@/utils/classnames' const PanelContextmenu = () => { const { t } = useTranslation() const ref = useRef(null) const panelMenu = useStore(s => s.panelMenu) const clipboardElements = useStore(s => s.clipboardElements) const setShowImportDSLModal = useStore(s => s.setShowImportDSLModal) const { handleNodesPaste } = useNodesInteractions() const { handlePaneContextmenuCancel, handleNodeContextmenuCancel } = usePanelInteractions() const { handleStartWorkflowRun } = useWorkflowStartRun() const { handleAddNote } = useOperator() const { exportCheck } = useDSL() useEffect(() => { if (panelMenu) handleNodeContextmenuCancel() }, [panelMenu, handleNodeContextmenuCancel]) useClickAway(() => { handlePaneContextmenuCancel() }, ref) const renderTrigger = () => { return (
{t('workflow.common.addBlock')}
) } if (!panelMenu) return null return (
{ e.stopPropagation() handleAddNote() handlePaneContextmenuCancel() }} > {t('workflow.nodes.note.addNote')}
{ handleStartWorkflowRun() handlePaneContextmenuCancel() }} > {t('workflow.common.run')}
{ if (clipboardElements.length) { handleNodesPaste() handlePaneContextmenuCancel() } }} > {t('workflow.common.pasteHere')}
exportCheck()} > {t('app.export')}
setShowImportDSLModal(true)} > {t('workflow.common.importDSL')}
) } export default memo(PanelContextmenu)