node.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import type { FC } from 'react'
  2. import {
  3. memo,
  4. useEffect,
  5. } from 'react'
  6. import {
  7. Background,
  8. useNodesInitialized,
  9. useViewport,
  10. } from 'reactflow'
  11. import { useNodeIterationInteractions } from './use-interactions'
  12. import type { IterationNodeType } from './types'
  13. import AddBlock from './add-block'
  14. import cn from '@/utils/classnames'
  15. import type { NodeProps } from '@/app/components/workflow/types'
  16. const Node: FC<NodeProps<IterationNodeType>> = ({
  17. id,
  18. data,
  19. }) => {
  20. const { zoom } = useViewport()
  21. const nodesInitialized = useNodesInitialized()
  22. const { handleNodeIterationRerender } = useNodeIterationInteractions()
  23. useEffect(() => {
  24. if (nodesInitialized)
  25. handleNodeIterationRerender(id)
  26. }, [nodesInitialized, id, handleNodeIterationRerender])
  27. return (
  28. <div className={cn(
  29. 'relative min-w-[258px] min-h-[118px] w-full h-full rounded-2xl bg-[#F0F2F7]/90',
  30. )}>
  31. <Background
  32. id={`iteration-background-${id}`}
  33. className='rounded-2xl !z-0'
  34. gap={[14 / zoom, 14 / zoom]}
  35. size={2 / zoom}
  36. color='#E4E5E7'
  37. />
  38. <AddBlock
  39. iterationNodeId={id}
  40. iterationNodeData={data}
  41. />
  42. </div>
  43. )
  44. }
  45. export default memo(Node)