Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { memo, useEffect, useMemo, useRef } from 'react'
  2. import { MiniMap } from 'reactflow'
  3. import UndoRedo from '../header/undo-redo'
  4. import ZoomInOut from './zoom-in-out'
  5. import VariableTrigger from '../variable-inspect/trigger'
  6. import VariableInspectPanel from '../variable-inspect'
  7. import { useStore } from '../store'
  8. export type OperatorProps = {
  9. handleUndo: () => void
  10. handleRedo: () => void
  11. }
  12. const Operator = ({ handleUndo, handleRedo }: OperatorProps) => {
  13. const bottomPanelRef = useRef<HTMLDivElement>(null)
  14. const workflowCanvasWidth = useStore(s => s.workflowCanvasWidth)
  15. const rightPanelWidth = useStore(s => s.rightPanelWidth)
  16. const setBottomPanelWidth = useStore(s => s.setBottomPanelWidth)
  17. const setBottomPanelHeight = useStore(s => s.setBottomPanelHeight)
  18. const bottomPanelWidth = useMemo(() => {
  19. if (!workflowCanvasWidth || !rightPanelWidth)
  20. return 'auto'
  21. return Math.max((workflowCanvasWidth - rightPanelWidth), 400)
  22. }, [workflowCanvasWidth, rightPanelWidth])
  23. // update bottom panel height
  24. useEffect(() => {
  25. if (bottomPanelRef.current) {
  26. const resizeContainerObserver = new ResizeObserver((entries) => {
  27. for (const entry of entries) {
  28. const { inlineSize, blockSize } = entry.borderBoxSize[0]
  29. setBottomPanelWidth(inlineSize)
  30. setBottomPanelHeight(blockSize)
  31. }
  32. })
  33. resizeContainerObserver.observe(bottomPanelRef.current)
  34. return () => {
  35. resizeContainerObserver.disconnect()
  36. }
  37. }
  38. }, [setBottomPanelHeight, setBottomPanelWidth])
  39. return (
  40. <div
  41. ref={bottomPanelRef}
  42. className='absolute bottom-0 left-0 right-0 z-10 px-1'
  43. style={
  44. {
  45. width: bottomPanelWidth,
  46. }
  47. }
  48. >
  49. <div className='flex justify-between px-1 pb-2'>
  50. <div className='flex items-center gap-2'>
  51. <UndoRedo handleUndo={handleUndo} handleRedo={handleRedo} />
  52. </div>
  53. <VariableTrigger />
  54. <div className='relative'>
  55. <MiniMap
  56. pannable
  57. zoomable
  58. style={{
  59. width: 102,
  60. height: 72,
  61. }}
  62. maskColor='var(--color-workflow-minimap-bg)'
  63. className='!absolute !bottom-10 z-[9] !m-0 !h-[73px] !w-[103px] !rounded-lg !border-[0.5px]
  64. !border-divider-subtle !bg-background-default-subtle !shadow-md !shadow-shadow-shadow-5'
  65. />
  66. <ZoomInOut />
  67. </div>
  68. </div>
  69. <VariableInspectPanel />
  70. </div>
  71. )
  72. }
  73. export default memo(Operator)