control.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import type { MouseEvent } from 'react'
  2. import {
  3. memo,
  4. } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import {
  7. RiCursorLine,
  8. RiFunctionAddLine,
  9. RiHand,
  10. RiStickyNoteAddLine,
  11. } from '@remixicon/react'
  12. import {
  13. useNodesReadOnly,
  14. useWorkflowMoveMode,
  15. useWorkflowOrganize,
  16. } from '../hooks'
  17. import {
  18. ControlMode,
  19. } from '../types'
  20. import { useStore } from '../store'
  21. import AddBlock from './add-block'
  22. import TipPopup from './tip-popup'
  23. import { useOperator } from './hooks'
  24. import cn from '@/utils/classnames'
  25. const Control = () => {
  26. const { t } = useTranslation()
  27. const controlMode = useStore(s => s.controlMode)
  28. const { handleModePointer, handleModeHand } = useWorkflowMoveMode()
  29. const { handleLayout } = useWorkflowOrganize()
  30. const { handleAddNote } = useOperator()
  31. const {
  32. nodesReadOnly,
  33. getNodesReadOnly,
  34. } = useNodesReadOnly()
  35. const addNote = (e: MouseEvent<HTMLDivElement>) => {
  36. if (getNodesReadOnly())
  37. return
  38. e.stopPropagation()
  39. handleAddNote()
  40. }
  41. return (
  42. <div className='flex items-center p-0.5 rounded-lg border-[0.5px] border-gray-100 bg-white shadow-lg text-gray-500'>
  43. <AddBlock />
  44. <TipPopup title={t('workflow.nodes.note.addNote')}>
  45. <div
  46. className={cn(
  47. 'flex items-center justify-center ml-[1px] w-8 h-8 rounded-lg hover:bg-black/5 hover:text-gray-700 cursor-pointer',
  48. `${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
  49. )}
  50. onClick={addNote}
  51. >
  52. <RiStickyNoteAddLine className='w-4 h-4' />
  53. </div>
  54. </TipPopup>
  55. <div className='mx-[3px] w-[1px] h-3.5 bg-gray-200'></div>
  56. <TipPopup title={t('workflow.common.pointerMode')} shortcuts={['v']}>
  57. <div
  58. className={cn(
  59. 'flex items-center justify-center mr-[1px] w-8 h-8 rounded-lg cursor-pointer',
  60. controlMode === ControlMode.Pointer ? 'bg-primary-50 text-primary-600' : 'hover:bg-black/5 hover:text-gray-700',
  61. `${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
  62. )}
  63. onClick={handleModePointer}
  64. >
  65. <RiCursorLine className='w-4 h-4' />
  66. </div>
  67. </TipPopup>
  68. <TipPopup title={t('workflow.common.handMode')} shortcuts={['h']}>
  69. <div
  70. className={cn(
  71. 'flex items-center justify-center w-8 h-8 rounded-lg cursor-pointer',
  72. controlMode === ControlMode.Hand ? 'bg-primary-50 text-primary-600' : 'hover:bg-black/5 hover:text-gray-700',
  73. `${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
  74. )}
  75. onClick={handleModeHand}
  76. >
  77. <RiHand className='w-4 h-4' />
  78. </div>
  79. </TipPopup>
  80. <div className='mx-[3px] w-[1px] h-3.5 bg-gray-200'></div>
  81. <TipPopup title={t('workflow.panel.organizeBlocks')} shortcuts={['ctrl', 'o']}>
  82. <div
  83. className={cn(
  84. 'flex items-center justify-center w-8 h-8 rounded-lg hover:bg-black/5 hover:text-gray-700 cursor-pointer',
  85. `${nodesReadOnly && '!cursor-not-allowed opacity-50'}`,
  86. )}
  87. onClick={handleLayout}
  88. >
  89. <RiFunctionAddLine className='w-4 h-4' />
  90. </div>
  91. </TipPopup>
  92. </div>
  93. )
  94. }
  95. export default memo(Control)