@delove/reaflow
Version:
Node-based Visualizations for React
75 lines (74 loc) • 1.9 kB
TypeScript
import React from 'react';
import { EdgeData, NodeData } from '../types';
export type HotkeyTypes = 'selectAll' | 'deselect' | 'delete';
export interface SelectionProps {
/**
* Current selections.
*
* Contains both nodes and edges ids.
*/
selections?: string[];
/**
* Node datas.
*/
nodes?: NodeData[];
/**
* Edge datas.
*/
edges?: EdgeData[];
/**
* Disabled or not.
*/
disabled?: boolean;
/**
* Hotkey types
*/
hotkeys?: HotkeyTypes[];
/**
* On selection change.
*/
onSelection?: (newSelectedIds: string[]) => void;
/**
* On data change.
*/
onDataChange?: (nodes: NodeData[], edges: EdgeData[]) => void;
}
export interface SelectionResult {
/**
* Selections id array (of nodes and edges).
*/
selections: string[];
/**
* Clear selections method.
*/
clearSelections: (value?: string[]) => void;
/**
* A selection method.
*/
addSelection: (value: string) => void;
/**
* Remove selection method.
*/
removeSelection: (value: string) => void;
/**
* Toggle existing selection on/off method.
*/
toggleSelection: (value: string) => void;
/**
* Set internal selections.
*/
setSelections: (value: string[]) => void;
/**
* On click event pass through.
*/
onClick?: (event: React.MouseEvent<SVGGElement, MouseEvent>, data: any) => void;
/**
* On canvas click event pass through.
*/
onCanvasClick?: (event?: React.MouseEvent<SVGGElement, MouseEvent>) => void;
/**
* On keydown event pass through.
*/
onKeyDown?: (event: React.KeyboardEvent<SVGGElement>) => void;
}
export declare const useSelection: ({ selections, nodes, edges, hotkeys, disabled, onSelection, onDataChange }: SelectionProps) => SelectionResult;