您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

index.tsx 1.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import {
  2. memo,
  3. useMemo,
  4. } from 'react'
  5. import type { NodeProps } from 'reactflow'
  6. import type { Node } from '../types'
  7. import { CUSTOM_NODE } from '../constants'
  8. import {
  9. NodeComponentMap,
  10. PanelComponentMap,
  11. } from './constants'
  12. import BaseNode from './_base/node'
  13. import BasePanel from './_base/components/workflow-panel'
  14. const CustomNode = (props: NodeProps) => {
  15. const nodeData = props.data
  16. const NodeComponent = useMemo(() => NodeComponentMap[nodeData.type], [nodeData.type])
  17. return (
  18. <>
  19. <BaseNode
  20. id={props.id}
  21. data={props.data}
  22. >
  23. <NodeComponent />
  24. </BaseNode>
  25. </>
  26. )
  27. }
  28. CustomNode.displayName = 'CustomNode'
  29. export type PanelProps = {
  30. type: Node['type']
  31. id: Node['id']
  32. data: Node['data']
  33. }
  34. export const Panel = memo((props: PanelProps) => {
  35. const nodeClass = props.type
  36. const nodeData = props.data
  37. const PanelComponent = useMemo(() => {
  38. if (nodeClass === CUSTOM_NODE)
  39. return PanelComponentMap[nodeData.type]
  40. return () => null
  41. }, [nodeClass, nodeData.type])
  42. if (nodeClass === CUSTOM_NODE) {
  43. return (
  44. <BasePanel
  45. key={props.id}
  46. id={props.id}
  47. data={props.data}
  48. >
  49. <PanelComponent />
  50. </BasePanel>
  51. )
  52. }
  53. return null
  54. })
  55. Panel.displayName = 'Panel'
  56. export default memo(CustomNode)