| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   memo, | 
					
						
							| 
									
										
										
										
											2024-08-23 13:14:17 +08:00
										 |  |  |   useEffect, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   useRef, | 
					
						
							|  |  |  | } from 'react' | 
					
						
							|  |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							|  |  |  | import { useClickAway } from 'ahooks' | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  | import Divider from '../base/divider' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import ShortcutsName from './shortcuts-name' | 
					
						
							|  |  |  | import { useStore } from './store' | 
					
						
							|  |  |  | import { | 
					
						
							| 
									
										
										
										
											2024-06-25 15:46:12 +08:00
										 |  |  |   useDSL, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   useNodesInteractions, | 
					
						
							|  |  |  |   usePanelInteractions, | 
					
						
							|  |  |  |   useWorkflowStartRun, | 
					
						
							|  |  |  | } from './hooks' | 
					
						
							|  |  |  | import AddBlock from './operator/add-block' | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  | import { useOperator } from './operator/hooks' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const PanelContextmenu = () => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const ref = useRef(null) | 
					
						
							|  |  |  |   const panelMenu = useStore(s => s.panelMenu) | 
					
						
							|  |  |  |   const clipboardElements = useStore(s => s.clipboardElements) | 
					
						
							| 
									
										
										
										
											2024-06-25 15:46:12 +08:00
										 |  |  |   const setShowImportDSLModal = useStore(s => s.setShowImportDSLModal) | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   const { handleNodesPaste } = useNodesInteractions() | 
					
						
							| 
									
										
										
										
											2024-08-23 13:14:17 +08:00
										 |  |  |   const { handlePaneContextmenuCancel, handleNodeContextmenuCancel } = usePanelInteractions() | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   const { handleStartWorkflowRun } = useWorkflowStartRun() | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |   const { handleAddNote } = useOperator() | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |   const { exportCheck } = useDSL() | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-23 13:14:17 +08:00
										 |  |  |   useEffect(() => { | 
					
						
							|  |  |  |     if (panelMenu) | 
					
						
							|  |  |  |       handleNodeContextmenuCancel() | 
					
						
							|  |  |  |   }, [panelMenu, handleNodeContextmenuCancel]) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   useClickAway(() => { | 
					
						
							|  |  |  |     handlePaneContextmenuCancel() | 
					
						
							|  |  |  |   }, ref) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   const renderTrigger = () => { | 
					
						
							|  |  |  |     return ( | 
					
						
							|  |  |  |       <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |         className='flex h-8 cursor-pointer items-center justify-between rounded-lg px-3 text-sm text-text-secondary hover:bg-state-base-hover' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       > | 
					
						
							|  |  |  |         {t('workflow.common.addBlock')} | 
					
						
							|  |  |  |       </div> | 
					
						
							|  |  |  |     ) | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   if (!panelMenu) | 
					
						
							|  |  |  |     return null | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return ( | 
					
						
							|  |  |  |     <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       className='absolute z-[9] w-[200px] rounded-lg border-[0.5px] border-components-panel-border bg-components-panel-bg-blur shadow-lg' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       style={{ | 
					
						
							|  |  |  |         left: panelMenu.left, | 
					
						
							|  |  |  |         top: panelMenu.top, | 
					
						
							|  |  |  |       }} | 
					
						
							|  |  |  |       ref={ref} | 
					
						
							|  |  |  |     > | 
					
						
							|  |  |  |       <div className='p-1'> | 
					
						
							|  |  |  |         <AddBlock | 
					
						
							|  |  |  |           renderTrigger={renderTrigger} | 
					
						
							|  |  |  |           offset={{ | 
					
						
							|  |  |  |             mainAxis: -36, | 
					
						
							|  |  |  |             crossAxis: -4, | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |         /> | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |         <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           className='flex h-8 cursor-pointer items-center justify-between rounded-lg px-3 text-sm text-text-secondary hover:bg-state-base-hover' | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |           onClick={(e) => { | 
					
						
							|  |  |  |             e.stopPropagation() | 
					
						
							|  |  |  |             handleAddNote() | 
					
						
							|  |  |  |             handlePaneContextmenuCancel() | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           {t('workflow.nodes.note.addNote')} | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           className='flex h-8 cursor-pointer items-center justify-between rounded-lg px-3 text-sm text-text-secondary hover:bg-state-base-hover' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |           onClick={() => { | 
					
						
							|  |  |  |             handleStartWorkflowRun() | 
					
						
							|  |  |  |             handlePaneContextmenuCancel() | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           {t('workflow.common.run')} | 
					
						
							|  |  |  |           <ShortcutsName keys={['alt', 'r']} /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  |       <Divider className='m-0' /> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       <div className='p-1'> | 
					
						
							|  |  |  |         <div | 
					
						
							|  |  |  |           className={cn( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             'flex h-8 cursor-pointer items-center justify-between rounded-lg px-3 text-sm text-text-secondary', | 
					
						
							|  |  |  |             !clipboardElements.length ? 'cursor-not-allowed opacity-50' : 'hover:bg-state-base-hover', | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |           )} | 
					
						
							|  |  |  |           onClick={() => { | 
					
						
							|  |  |  |             if (clipboardElements.length) { | 
					
						
							|  |  |  |               handleNodesPaste() | 
					
						
							|  |  |  |               handlePaneContextmenuCancel() | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |           }} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           {t('workflow.common.pasteHere')} | 
					
						
							|  |  |  |           <ShortcutsName keys={['ctrl', 'v']} /> | 
					
						
							|  |  |  |         </div> | 
					
						
							|  |  |  |       </div> | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  |       <Divider className='m-0' /> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       <div className='p-1'> | 
					
						
							|  |  |  |         <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           className='flex h-8 cursor-pointer items-center justify-between rounded-lg px-3 text-sm text-text-secondary hover:bg-state-base-hover' | 
					
						
							| 
									
										
										
										
											2024-07-22 15:29:39 +08:00
										 |  |  |           onClick={() => exportCheck()} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         > | 
					
						
							|  |  |  |           {t('app.export')} | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2024-06-25 15:46:12 +08:00
										 |  |  |         <div | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           className='flex h-8 cursor-pointer items-center justify-between rounded-lg px-3 text-sm text-text-secondary hover:bg-state-base-hover' | 
					
						
							| 
									
										
										
										
											2024-06-25 15:46:12 +08:00
										 |  |  |           onClick={() => setShowImportDSLModal(true)} | 
					
						
							|  |  |  |         > | 
					
						
							|  |  |  |           {t('workflow.common.importDSL')} | 
					
						
							|  |  |  |         </div> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       </div> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default memo(PanelContextmenu) |