You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.tsx 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. <UndoRedo handleUndo={handleUndo} handleRedo={handleRedo} />
  51. <VariableTrigger />
  52. <div className='relative'>
  53. <MiniMap
  54. pannable
  55. zoomable
  56. style={{
  57. width: 102,
  58. height: 72,
  59. }}
  60. maskColor='var(--color-workflow-minimap-bg)'
  61. className='!absolute !bottom-10 z-[9] !m-0 !h-[73px] !w-[103px] !rounded-lg !border-[0.5px]
  62. !border-divider-subtle !bg-background-default-subtle !shadow-md !shadow-shadow-shadow-5'
  63. />
  64. <ZoomInOut />
  65. </div>
  66. </div>
  67. <VariableInspectPanel />
  68. </div>
  69. )
  70. }
  71. export default memo(Operator)