feat: [US-027] - Connect nodes with edges
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
718180fd35
commit
7270d72fa4
|
|
@ -14,6 +14,7 @@ import ReactFlow, {
|
||||||
Node,
|
Node,
|
||||||
Edge,
|
Edge,
|
||||||
NodeTypes,
|
NodeTypes,
|
||||||
|
MarkerType,
|
||||||
} from 'reactflow'
|
} from 'reactflow'
|
||||||
import { nanoid } from 'nanoid'
|
import { nanoid } from 'nanoid'
|
||||||
import 'reactflow/dist/style.css'
|
import 'reactflow/dist/style.css'
|
||||||
|
|
@ -47,6 +48,10 @@ function toReactFlowEdges(edges: FlowchartEdge[]): Edge[] {
|
||||||
target: edge.target,
|
target: edge.target,
|
||||||
targetHandle: edge.targetHandle,
|
targetHandle: edge.targetHandle,
|
||||||
data: edge.data,
|
data: edge.data,
|
||||||
|
type: 'smoothstep',
|
||||||
|
markerEnd: {
|
||||||
|
type: MarkerType.ArrowClosed,
|
||||||
|
},
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +77,21 @@ function FlowchartEditorInner({ initialData }: FlowchartEditorProps) {
|
||||||
)
|
)
|
||||||
|
|
||||||
const onConnect = useCallback(
|
const onConnect = useCallback(
|
||||||
(params: Connection) => setEdges((eds) => addEdge(params, eds)),
|
(params: Connection) => {
|
||||||
|
if (!params.source || !params.target) return
|
||||||
|
const newEdge: Edge = {
|
||||||
|
id: nanoid(),
|
||||||
|
source: params.source,
|
||||||
|
target: params.target,
|
||||||
|
sourceHandle: params.sourceHandle,
|
||||||
|
targetHandle: params.targetHandle,
|
||||||
|
type: 'smoothstep',
|
||||||
|
markerEnd: {
|
||||||
|
type: MarkerType.ArrowClosed,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
setEdges((eds) => addEdge(newEdge, eds))
|
||||||
|
},
|
||||||
[setEdges]
|
[setEdges]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue