node-contextmenu.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import {
  2. memo,
  3. useRef,
  4. } from 'react'
  5. import { useClickAway } from 'ahooks'
  6. import { useNodes } from 'reactflow'
  7. import PanelOperatorPopup from './nodes/_base/components/panel-operator/panel-operator-popup'
  8. import type { Node } from './types'
  9. import { useStore } from './store'
  10. import { usePanelInteractions } from './hooks'
  11. const PanelContextmenu = () => {
  12. const ref = useRef(null)
  13. const nodes = useNodes()
  14. const { handleNodeContextmenuCancel } = usePanelInteractions()
  15. const nodeMenu = useStore(s => s.nodeMenu)
  16. const currentNode = nodes.find(node => node.id === nodeMenu?.nodeId) as Node
  17. useClickAway(() => {
  18. handleNodeContextmenuCancel()
  19. }, ref)
  20. if (!nodeMenu || !currentNode)
  21. return null
  22. return (
  23. <div
  24. className='absolute z-[9]'
  25. style={{
  26. left: nodeMenu.left,
  27. top: nodeMenu.top,
  28. }}
  29. ref={ref}
  30. >
  31. <PanelOperatorPopup
  32. id={currentNode.id}
  33. data={currentNode.data}
  34. onClosePopup={() => handleNodeContextmenuCancel()}
  35. showHelpLink
  36. />
  37. </div>
  38. )
  39. }
  40. export default memo(PanelContextmenu)