import { Handle, NodeResizeControl, type Position, useReactFlow } from "@xyflow/react"; import type React from "react"; import { ErrorBoundary } from "react-error-boundary"; // @ts-ignore import AlertTriangle from "~icons/tabler/alert-triangle-filled.jsx"; // @ts-ignore import ChevronDownRight from "~icons/tabler/chevron-down-right.jsx"; // @ts-ignore import Dots from "~icons/tabler/dots.jsx"; // @ts-ignore import Help from "~icons/tabler/question-mark.jsx"; // @ts-ignore import Skull from "~icons/tabler/skull.jsx"; import Tooltip from "../../Tooltip"; import { COLORS } from "../../common.ts"; interface LynxKiteNodeProps { id: string; width: number; height: number; nodeStyle: any; data: any; children: any; parentId?: string; } function getHandles(inputs: any[], outputs: any[]) { const handles: { position: "top" | "bottom" | "left" | "right"; name: string; index: number; offsetPercentage: number; showLabel: boolean; type: "source" | "target"; }[] = []; for (const e of inputs) { handles.push({ ...e, type: "target" }); } for (const e of outputs) { handles.push({ ...e, type: "source" }); } const counts = { top: 0, bottom: 0, left: 0, right: 0 }; for (const e of handles) { e.index = counts[e.position]; counts[e.position]++; } const simpleHorizontal = counts.top === 0 && counts.bottom === 0 && counts.left <= 1 && counts.right <= 1; const simpleVertical = counts.left === 0 && counts.right === 0 && counts.top <= 1 && counts.bottom <= 1; for (const e of handles) { e.offsetPercentage = (100 * (e.index + 1)) / (counts[e.position] + 1); e.showLabel = !simpleHorizontal && !simpleVertical; } return handles; } function LynxKiteNodeComponent(props: LynxKiteNodeProps) { const reactFlow = useReactFlow(); const data = props.data; const expanded = !data.collapsed; const handles = getHandles(data.meta?.value?.inputs || [], data.meta?.value?.outputs || []); function titleClicked() { reactFlow.updateNodeData(props.id, { collapsed: expanded }); } const handleOffsetDirection = { top: "left", bottom: "left", left: "top", right: "top", }; const titleStyle: { backgroundColor?: string } = {}; if (data.meta?.value?.color) { titleStyle.backgroundColor = COLORS[data.meta.value.color] || data.meta.value.color; } return (