import { TooltipContent, TooltipNode, TooltipTrigger, } from '@/components/xyflow/tooltip-node'; import { cn } from '@/lib/utils'; import { Position } from '@xyflow/react'; import { Copy, Play, Trash2 } from 'lucide-react'; import { HTMLAttributes, MouseEventHandler, PropsWithChildren, useCallback, } from 'react'; import { Operator } from '../../constant'; import { useDuplicateNode } from '../../hooks'; import useGraphStore from '../../store'; function IconWrapper({ children, className, ...props }: HTMLAttributes) { return (
{children}
); } type ToolBarProps = { selected?: boolean | undefined; label: string; id: string; showRun?: boolean; showCopy?: boolean; } & PropsWithChildren; export function ToolBar({ selected, children, label, id, showRun = true, showCopy = true, }: ToolBarProps) { const deleteNodeById = useGraphStore((store) => store.deleteNodeById); const deleteIterationNodeById = useGraphStore( (store) => store.deleteIterationNodeById, ); const deleteNode: MouseEventHandler = useCallback( (e) => { e.stopPropagation(); if (label === Operator.Iteration) { deleteIterationNodeById(id); } else { deleteNodeById(id); } }, [deleteIterationNodeById, deleteNodeById, id, label], ); const duplicateNode = useDuplicateNode(); const handleDuplicate: MouseEventHandler = useCallback( (e) => { e.stopPropagation(); duplicateNode(id, label); }, [duplicateNode, id, label], ); return ( {children}
{showRun && ( )} {showCopy && ( )}
); }