import { useClickAway } from 'ahooks' import { memo, useEffect, useRef, } from 'react' import { useTranslation } from 'react-i18next' import { cn } from '@/utils/classnames' import Divider from '../base/divider' import { useDSL, useNodesInteractions, usePanelInteractions, useWorkflowStartRun, } from './hooks' import AddBlock from './operator/add-block' import { useOperator } from './operator/hooks' import ShortcutsName from './shortcuts-name' import { useStore } from './store' 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('common.addBlock', { ns: 'workflow' })}
) } if (!panelMenu) return null return (
{ e.stopPropagation() handleAddNote() handlePaneContextmenuCancel() }} > {t('nodes.note.addNote', { ns: 'workflow' })}
{ handleStartWorkflowRun() handlePaneContextmenuCancel() }} > {t('common.run', { ns: 'workflow' })}
{ if (clipboardElements.length) { handleNodesPaste() handlePaneContextmenuCancel() } }} > {t('common.pasteHere', { ns: 'workflow' })}
exportCheck?.()} > {t('export', { ns: 'app' })}
setShowImportDSLModal(true)} > {t('common.importDSL', { ns: 'workflow' })}
) } export default memo(PanelContextmenu)