import clsx from 'clsx'; import { MiniButton } from '@/components/Control'; import { IconGraphCollapse, IconGraphCore, IconGraphExpand, IconGraphInputs, IconGraphInverse, IconGraphMaximize, IconGraphOutputs, IconPredecessor, IconReset } from '@/components/Icons'; import { CProps } from '@/components/props'; import { Graph } from '@/models/Graph'; interface ToolbarGraphSelectionProps extends CProps.Styling { value: number[]; onChange: (newSelection: number[]) => void; graph: Graph; isCore: (item: number) => boolean; isOwned?: (item: number) => boolean; emptySelection?: boolean; } export function ToolbarGraphSelection({ className, graph, value: selected, isCore, isOwned, onChange, emptySelection, ...restProps }: ToolbarGraphSelectionProps) { function handleSelectCore() { const core = [...graph.nodes.keys()].filter(isCore); onChange([...core, ...graph.expandInputs(core)]); } function handleSelectOwned() { if (isOwned) onChange([...graph.nodes.keys()].filter(isOwned)); } return (
} onClick={() => onChange([])} disabled={emptySelection} /> } onClick={() => onChange([...selected, ...graph.expandAllInputs(selected)])} disabled={emptySelection} /> } onClick={() => onChange([...selected, ...graph.expandAllOutputs(selected)])} disabled={emptySelection} /> } onClick={() => onChange(graph.maximizePart(selected))} disabled={emptySelection} /> } onClick={() => onChange([...selected, ...graph.expandInputs(selected)])} disabled={emptySelection} /> } onClick={() => onChange([...selected, ...graph.expandOutputs(selected)])} disabled={emptySelection} /> } onClick={() => onChange([...graph.nodes.keys()].filter(item => !selected.includes(item)))} /> } onClick={handleSelectCore} /> {isOwned ? ( } onClick={handleSelectOwned} /> ) : null}
); }