| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  | import type { MouseEvent } from 'react' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   memo, | 
					
						
							|  |  |  | } from 'react' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import { useTranslation } from 'react-i18next' | 
					
						
							| 
									
										
										
										
											2024-06-20 11:05:08 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   RiCursorLine, | 
					
						
							|  |  |  |   RiFunctionAddLine, | 
					
						
							|  |  |  |   RiHand, | 
					
						
							|  |  |  |   RiStickyNoteAddLine, | 
					
						
							|  |  |  | } from '@remixicon/react' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   useNodesReadOnly, | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  |   useWorkflowMoveMode, | 
					
						
							|  |  |  |   useWorkflowOrganize, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | } from '../hooks' | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  | import { | 
					
						
							|  |  |  |   ControlMode, | 
					
						
							|  |  |  | } from '../types' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import { useStore } from '../store' | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  | import Divider from '../../base/divider' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | import AddBlock from './add-block' | 
					
						
							|  |  |  | import TipPopup from './tip-popup' | 
					
						
							| 
									
										
										
										
											2025-04-14 11:18:18 +08:00
										 |  |  | import ExportImage from './export-image' | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  | import { useOperator } from './hooks' | 
					
						
							| 
									
										
										
										
											2024-07-09 15:05:40 +08:00
										 |  |  | import cn from '@/utils/classnames' | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const Control = () => { | 
					
						
							|  |  |  |   const { t } = useTranslation() | 
					
						
							|  |  |  |   const controlMode = useStore(s => s.controlMode) | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  |   const { handleModePointer, handleModeHand } = useWorkflowMoveMode() | 
					
						
							|  |  |  |   const { handleLayout } = useWorkflowOrganize() | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |   const { handleAddNote } = useOperator() | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   const { | 
					
						
							|  |  |  |     nodesReadOnly, | 
					
						
							|  |  |  |     getNodesReadOnly, | 
					
						
							|  |  |  |   } = useNodesReadOnly() | 
					
						
							| 
									
										
										
										
											2024-07-30 16:18:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |   const addNote = (e: MouseEvent<HTMLDivElement>) => { | 
					
						
							|  |  |  |     if (getNodesReadOnly()) | 
					
						
							|  |  |  |       return | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     e.stopPropagation() | 
					
						
							|  |  |  |     handleAddNote() | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |   return ( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |     <div className='flex items-center rounded-lg border-[0.5px] border-components-actionbar-border bg-components-actionbar-bg p-0.5 text-text-tertiary shadow-lg'> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |       <AddBlock /> | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |       <TipPopup title={t('workflow.nodes.note.addNote')}> | 
					
						
							|  |  |  |         <div | 
					
						
							|  |  |  |           className={cn( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             'ml-[1px] flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg hover:bg-state-base-hover hover:text-text-secondary', | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  |             `${nodesReadOnly && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled'}`, | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |           )} | 
					
						
							|  |  |  |           onClick={addNote} | 
					
						
							|  |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <RiStickyNoteAddLine className='h-4 w-4' /> | 
					
						
							| 
									
										
										
										
											2024-06-14 17:08:11 +08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       </TipPopup> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <Divider type='vertical' className='mx-0.5 h-3.5' /> | 
					
						
							| 
									
										
										
										
											2024-07-30 16:18:58 +08:00
										 |  |  |       <TipPopup title={t('workflow.common.pointerMode')} shortcuts={['v']}> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         <div | 
					
						
							|  |  |  |           className={cn( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             'mr-[1px] flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg', | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  |             controlMode === ControlMode.Pointer ? 'bg-state-accent-active text-text-accent' : 'hover:bg-state-base-hover hover:text-text-secondary', | 
					
						
							|  |  |  |             `${nodesReadOnly && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled'}`, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |           )} | 
					
						
							| 
									
										
										
										
											2024-05-17 11:42:03 +08:00
										 |  |  |           onClick={handleModePointer} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <RiCursorLine className='h-4 w-4' /> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       </TipPopup> | 
					
						
							| 
									
										
										
										
											2024-07-30 16:18:58 +08:00
										 |  |  |       <TipPopup title={t('workflow.common.handMode')} shortcuts={['h']}> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         <div | 
					
						
							|  |  |  |           className={cn( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             'flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg', | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  |             controlMode === ControlMode.Hand ? 'bg-state-accent-active text-text-accent' : 'hover:bg-state-base-hover hover:text-text-secondary', | 
					
						
							|  |  |  |             `${nodesReadOnly && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled'}`, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |           )} | 
					
						
							| 
									
										
										
										
											2024-05-17 11:42:03 +08:00
										 |  |  |           onClick={handleModeHand} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <RiHand className='h-4 w-4' /> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       </TipPopup> | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |       <Divider type='vertical' className='mx-0.5 h-3.5' /> | 
					
						
							| 
									
										
										
										
											2025-04-14 11:18:18 +08:00
										 |  |  |       <ExportImage /> | 
					
						
							| 
									
										
										
										
											2024-07-30 16:18:58 +08:00
										 |  |  |       <TipPopup title={t('workflow.panel.organizeBlocks')} shortcuts={['ctrl', 'o']}> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         <div | 
					
						
							|  |  |  |           className={cn( | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |             'flex h-8 w-8 cursor-pointer items-center justify-center rounded-lg hover:bg-state-base-hover hover:text-text-secondary', | 
					
						
							| 
									
										
										
										
											2024-12-17 12:20:49 +08:00
										 |  |  |             `${nodesReadOnly && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled'}`, | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |           )} | 
					
						
							| 
									
										
										
										
											2024-08-19 18:11:11 +08:00
										 |  |  |           onClick={handleLayout} | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         > | 
					
						
							| 
									
										
										
										
											2025-03-21 17:41:03 +08:00
										 |  |  |           <RiFunctionAddLine className='h-4 w-4' /> | 
					
						
							| 
									
										
										
										
											2024-05-09 17:18:51 +08:00
										 |  |  |         </div> | 
					
						
							|  |  |  |       </TipPopup> | 
					
						
							|  |  |  |     </div> | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | export default memo(Control) |