Skip to content

Image Pipeline Playground

feat(frontend/canvas): enable reconnectable edges and dark canvas

Mohammad Rajaei26583ed1f548
diff --git a/frontend/src/features/canvas/PipelineCanvas.tsx b/frontend/src/features/canvas/PipelineCanvas.tsx
index dc23285..2def80a 100644
--- a/frontend/src/features/canvas/PipelineCanvas.tsx
+++ b/frontend/src/features/canvas/PipelineCanvas.tsx
@@ -4,6 +4,8 @@ import {
Controls,
MiniMap,
ReactFlow,
+ type Connection,
+ type Edge,
type NodeTypes,
} from '@xyflow/react'
import '@xyflow/react/dist/style.css'
@@ -18,6 +20,7 @@ export function PipelineCanvas() {
const onNodesChange = useGraphStore((s) => s.onNodesChange)
const onEdgesChange = useGraphStore((s) => s.onEdgesChange)
const onConnect = useGraphStore((s) => s.onConnect)
+ const onReconnect = useGraphStore((s) => s.onReconnect)
const selectNode = useGraphStore((s) => s.selectNode)
const addNodeFromType = useGraphStore((s) => s.addNodeFromType)
@@ -39,22 +42,51 @@ export function PipelineCanvas() {
[addNodeFromType],
)
+ const isValidConnection = useCallback((connection: Connection | Edge) => {
+ if (!connection.source || !connection.target) return false
+ return connection.source !== connection.target
+ }, [])
+
return (
- <Box sx={{ width: '100%', height: '100%' }} onDragOver={(e) => e.preventDefault()} onDrop={onDrop}>
+ <Box
+ sx={{ width: '100%', height: '100%', bgcolor: '#0c0c0c' }}
+ onDragOver={(e) => e.preventDefault()}
+ onDrop={onDrop}
+ >
<ReactFlow
nodes={nodes}
edges={edges}
onNodesChange={onNodesChange}
onEdgesChange={onEdgesChange}
onConnect={onConnect}
+ onReconnect={onReconnect}
+ isValidConnection={isValidConnection}
nodeTypes={nodeTypes}
onNodeClick={(_, node) => selectNode(node.id)}
onPaneClick={() => selectNode(null)}
+ deleteKeyCode={['Backspace', 'Delete']}
+ multiSelectionKeyCode="Shift"
+ nodesConnectable
+ nodesDraggable
+ elementsSelectable
+ edgesReconnectable
fitView
+ colorMode="dark"
+ defaultEdgeOptions={{
+ style: { stroke: 'rgba(255,255,255,0.45)', strokeWidth: 2.5 },
+ type: 'smoothstep',
+ reconnectable: true,
+ selectable: true,
+ }}
>
- <MiniMap />
+ <MiniMap
+ pannable
+ zoomable
+ style={{ background: '#1a1a1a' }}
+ maskColor="rgba(0,0,0,0.55)"
+ />
<Controls />
- <Background gap={16} />
+ <Background gap={20} color="rgba(255,255,255,0.05)" />
</ReactFlow>
</Box>
)