-
Notifications
You must be signed in to change notification settings - Fork 374
Expand file tree
/
Copy pathNodePort.tsx
More file actions
64 lines (58 loc) · 1.55 KB
/
NodePort.tsx
File metadata and controls
64 lines (58 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { useNodeConnections, useUpdateNodeInternals } from '@xyflow/react'
import React from 'react'
import { cn } from '@/utils'
import { type NodeId, type PortId } from '../utils'
import { NodeHandles } from './NodeHandles'
export const NodePort = React.memo(function NodePort<
TPortId extends string = PortId,
TNodeID extends string = NodeId,
>({
id,
nodeId,
className,
children,
}: {
id: TPortId
nodeId: TNodeID
className?: string
children: React.ReactNode
}) {
const updateNodeInternals = useUpdateNodeInternals()
const sources = useNodeConnections({
id: nodeId,
handleType: 'source',
handleId: id,
})
const targets = useNodeConnections({
id: nodeId,
handleType: 'target',
handleId: id,
})
const leftId = targets.length > 0 ? id : undefined
const rightId = sources.length > 0 ? id : undefined
React.useEffect(() => {
if (leftId || rightId) {
updateNodeInternals(nodeId)
}
}, [updateNodeInternals, nodeId, leftId, rightId])
return (
<NodeHandles
data-component="NodePort"
leftIcon={
<span className="flex-shrink-0 p-1.5 rounded-full bg-lineage-node-port-handle-target"></span>
}
rightIcon={
<span className="flex-shrink-0 p-1.5 rounded-full bg-lineage-node-port-handle-source"></span>
}
leftId={leftId}
rightId={rightId}
className={cn(
'relative overflow-visible group bg-lineage-node-port-background h-auto',
className,
)}
handleClassName="absolute"
>
{children}
</NodeHandles>
)
})