"use client"; /** * Workflow v3 edge: LLM judgement, variable expression, or deterministic default. */ import { BaseEdge, EdgeLabelRenderer, getBezierPath, type EdgeProps, useReactFlow, } from "@xyflow/react"; import { Pencil, Trash2 } from "lucide-react"; import { useContext, useState } from "react"; import { cn } from "@/lib/utils"; import { EdgeActionContext } from "./context"; export function ConditionEdge({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data, selected, }: EdgeProps) { const actions = useContext(EdgeActionContext); const { setEdges } = useReactFlow(); const [hovered, setHovered] = useState(false); // 点击标签:只选中这条边(露出编辑/删除按钮),不直接进入编辑。 const selectThisEdge = () => setEdges((eds) => eds.map((e) => ({ ...e, selected: e.id === id }))); const [path, labelX, labelY] = getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, curvature: 0.28, }); const mode = (data?.mode as string) || "always"; const label = ( (data?.label as string) || (mode === "llm" ? (data?.condition as string) : "") || (mode === "llm" ? "大模型判断" : mode === "expression" ? "表达式" : "默认路径") ).toString().trim(); const expanded = hovered || selected; return ( <> setHovered(true)} onMouseLeave={() => setHovered(false)} > {label || "+ 条件"} {expanded && ( actions.edit(id)} > )} {expanded && ( actions.remove(id)} > )} > ); } export const edgeTypes = { condition: ConditionEdge };