control.tsx 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 Divider from '../../base/divider'
  22. import AddBlock from './add-block'
  23. import TipPopup from './tip-popup'
  24. import { useOperator } from './hooks'
  25. import cn from '@/utils/classnames'
  26. const Control = () => {
  27. const { t } = useTranslation()
  28. const controlMode = useStore(s => s.controlMode)
  29. const { handleModePointer, handleModeHand } = useWorkflowMoveMode()
  30. const { handleLayout } = useWorkflowOrganize()
  31. const { handleAddNote } = useOperator()
  32. const {
  33. nodesReadOnly,
  34. getNodesReadOnly,
  35. } = useNodesReadOnly()
  36. const addNote = (e: MouseEvent<HTMLDivElement>) => {
  37. if (getNodesReadOnly())
  38. return
  39. e.stopPropagation()
  40. handleAddNote()
  41. }
  42. return (
  43. <div className='flex items-center p-0.5 rounded-lg border-[0.5px] border-components-actionbar-border bg-components-actionbar-bg shadow-lg text-text-tertiary'>
  44. <AddBlock />
  45. <TipPopup title={t('workflow.nodes.note.addNote')}>
  46. <div
  47. className={cn(
  48. 'flex items-center justify-center ml-[1px] w-8 h-8 rounded-lg hover:bg-state-base-hover hover:text-text-secondary cursor-pointer',
  49. `${nodesReadOnly && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled'}`,
  50. )}
  51. onClick={addNote}
  52. >
  53. <RiStickyNoteAddLine className='w-4 h-4' />
  54. </div>
  55. </TipPopup>
  56. <Divider type='vertical' className='h-3.5 mx-0.5' />
  57. <TipPopup title={t('workflow.common.pointerMode')} shortcuts={['v']}>
  58. <div
  59. className={cn(
  60. 'flex items-center justify-center mr-[1px] w-8 h-8 rounded-lg cursor-pointer',
  61. controlMode === ControlMode.Pointer ? 'bg-state-accent-active text-text-accent' : 'hover:bg-state-base-hover hover:text-text-secondary',
  62. `${nodesReadOnly && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled'}`,
  63. )}
  64. onClick={handleModePointer}
  65. >
  66. <RiCursorLine className='w-4 h-4' />
  67. </div>
  68. </TipPopup>
  69. <TipPopup title={t('workflow.common.handMode')} shortcuts={['h']}>
  70. <div
  71. className={cn(
  72. 'flex items-center justify-center w-8 h-8 rounded-lg cursor-pointer',
  73. controlMode === ControlMode.Hand ? 'bg-state-accent-active text-text-accent' : 'hover:bg-state-base-hover hover:text-text-secondary',
  74. `${nodesReadOnly && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled'}`,
  75. )}
  76. onClick={handleModeHand}
  77. >
  78. <RiHand className='w-4 h-4' />
  79. </div>
  80. </TipPopup>
  81. <Divider type='vertical' className='h-3.5 mx-0.5' />
  82. <TipPopup title={t('workflow.panel.organizeBlocks')} shortcuts={['ctrl', 'o']}>
  83. <div
  84. className={cn(
  85. 'flex items-center justify-center w-8 h-8 rounded-lg hover:bg-state-base-hover hover:text-text-secondary cursor-pointer',
  86. `${nodesReadOnly && 'cursor-not-allowed text-text-disabled hover:bg-transparent hover:text-text-disabled'}`,
  87. )}
  88. onClick={handleLayout}
  89. >
  90. <RiFunctionAddLine className='w-4 h-4' />
  91. </div>
  92. </TipPopup>
  93. </div>
  94. )
  95. }
  96. export default memo(Control)