import React, { useContext } from 'react'
import { Handle, Position } from '@xyflow/react'
import { ArrowDownLeft, ArrowUpRight } from 'lucide-react'
import { FlowUIContext } from '@/lib/graph/flowContext'
import { cn } from '@/lib/utils'
type NodeHandleProps = {
id: string
/** Pass when this handle is a connection target so valid highlight can show as soon as connection starts */
nodeId?: string
}
export function InputHandle({ id, nodeId }: NodeHandleProps) {
const ctx = useContext(FlowUIContext)
const connectionFrom = ctx?.connectionFrom ?? null
const isValidConnection = ctx?.isValidConnection
const isConnecting = Boolean(nodeId && connectionFrom && connectionFrom.nodeId !== nodeId)
const isValidTarget =
isConnecting &&
isValidConnection?.({
source: connectionFrom!.nodeId,
sourceHandle: connectionFrom!.sourceHandle ?? null,
target: nodeId!,
targetHandle: id,
})
return (
)
}
export function OutputHandle({ id }: NodeHandleProps) {
return (
)
}