feat(workspace): integrate persisted canvas, element editing and session renewal

This commit is contained in:
2026-11-06 12:50:43 +08:00
parent 45e78f2e43
commit 373582906d
36 changed files with 1028 additions and 193 deletions
+27
View File
@@ -0,0 +1,27 @@
"use client";
import { BaseEdge, useInternalNode, type ConnectionLineComponentProps, type EdgeProps, type InternalNode } from "@xyflow/react";
import type { CanvasNode } from "@/lib/canvas";
import { connectorBezier, nodeConnector, type ConnectorSide } from "@/lib/canvas-geometry";
function connector(node: InternalNode<CanvasNode>, handle: string | null | undefined, fallback: ConnectorSide) {
const side = handle === "top" || handle === "right" || handle === "bottom" || handle === "left" ? handle : fallback;
return nodeConnector({ ...node, position: node.internals.positionAbsolute }, side);
}
export function CanvasEdge(props: EdgeProps) {
const source = useInternalNode<CanvasNode>(props.source);
const target = useInternalNode<CanvasNode>(props.target);
if (!source || !target) return null;
const from = connector(source, props.sourceHandleId, "right");
const to = connector(target, props.targetHandleId, "left");
return <BaseEdge id={props.id} path={connectorBezier(from, to)} style={{ ...props.style, strokeLinecap: "round" }} markerStart={props.markerStart} markerEnd={props.markerEnd} interactionWidth={props.interactionWidth} />;
}
export function CanvasConnectionLine(props: ConnectionLineComponentProps<CanvasNode>) {
const from = connector(props.fromNode, props.fromHandle.id, "right");
const to = props.toNode && props.toHandle
? connector(props.toNode, props.toHandle.id, "left")
: { point: { x: props.toX, y: props.toY }, normal: { x: -from.normal.x, y: -from.normal.y } };
return <path fill="none" className="react-flow__connection-path" d={connectorBezier(from, to)} style={{ stroke: "#aa968b", strokeWidth: 1.5, ...props.connectionLineStyle, strokeLinecap: "round" }} />;
}