Image Pipeline Playground
feat(frontend/workflow): persist and export connector bend waypoints
Mohammad Rajaei7fe234b915d6
diff --git a/frontend/src/store/graphStore.ts b/frontend/src/store/graphStore.tsindex 36a60f5..7697c1e 100644--- a/frontend/src/store/graphStore.ts+++ b/frontend/src/store/graphStore.ts@@ -468,13 +468,23 @@ export const useGraphStore = create<GraphState>((set, get) => ({params: node.data.params,position: node.position,})),- edges: edges.map((edge) => ({- id: edge.id,- source: edge.source,- source_port: edge.sourceHandle ?? 'image',- target: edge.target,- target_port: edge.targetHandle ?? 'image',- })),+ edges: edges.map((edge) => {+ const waypoints = (+ edge.data as { waypoints?: { x: number; y: number }[] } | undefined+ )?.waypoints+ const cleaned =+ Array.isArray(waypoints) && waypoints.length > 0+ ? waypoints.map((point) => ({ x: point.x, y: point.y }))+ : undefined+ return {+ id: edge.id,+ source: edge.source,+ source_port: edge.sourceHandle ?? 'image',+ target: edge.target,+ target_port: edge.targetHandle ?? 'image',+ ...(cleaned ? { waypoints: cleaned } : {}),+ }+ }),}},@@ -531,7 +541,11 @@ export const useGraphStore = create<GraphState>((set, get) => ({zIndex: 1000,reconnectable: true,selectable: true,- data: { waypoints: [] },+ data: {+ waypoints: Array.isArray(edge.waypoints)+ ? edge.waypoints.map((point) => ({ x: point.x, y: point.y }))+ : [],+ },}))syncNodeCounter(nodes.map((node) => node.id))diff --git a/frontend/src/workflow/io.ts b/frontend/src/workflow/io.tsindex e278a6a..8463708 100644--- a/frontend/src/workflow/io.ts+++ b/frontend/src/workflow/io.ts@@ -1,5 +1,10 @@/** Versioned workflow JSON for export / load. */+export interface WorkflowWaypoint {+ x: number+ y: number+}+export interface WorkflowGraphPayload {nodes: Array<{id: string@@ -13,6 +18,8 @@ export interface WorkflowGraphPayload {source_port: stringtarget: stringtarget_port: string+ /** Optional bend anchors for reshaped connectors. */+ waypoints?: WorkflowWaypoint[]}>}@@ -32,6 +39,18 @@ function isGraphPayload(value: unknown): value is WorkflowGraphPayload {return Array.isArray(value.nodes) && Array.isArray(value.edges)}+function normalizeWaypoints(value: unknown): WorkflowWaypoint[] | undefined {+ if (!Array.isArray(value) || value.length === 0) return undefined+ const points = value+ .filter(isRecord)+ .map((point) => ({+ x: Number(point.x ?? 0),+ y: Number(point.y ?? 0),+ }))+ .filter((point) => Number.isFinite(point.x) && Number.isFinite(point.y))+ return points.length > 0 ? points : undefined+}+function normalizeGraph(graph: WorkflowGraphPayload): WorkflowGraphPayload {return {nodes: graph.nodes.map((node) => {@@ -50,12 +69,14 @@ function normalizeGraph(graph: WorkflowGraphPayload): WorkflowGraphPayload {}),edges: graph.edges.map((edge) => {const record = edge as unknown as Record<string, unknown>+ const waypoints = normalizeWaypoints(record.waypoints)return {id: String(record.id ?? ''),source: String(record.source ?? ''),source_port: String(record.source_port ?? 'image'),target: String(record.target ?? ''),target_port: String(record.target_port ?? 'image'),+ ...(waypoints ? { waypoints } : {}),}}),}