You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
4.8 KiB

4 months ago
import type { RuntimeContext } from '../runtime/types';
import type { IPointerEvent, State } from '../types';
import type { ShortcutKey } from '../utils/shortcut';
import type { BaseBehaviorOptions } from './base-behavior';
import { BaseBehavior } from './base-behavior';
/**
* <zh/>
*
* <en/> Click element behavior options
*/
export interface ClickSelectOptions extends BaseBehaviorOptions {
/**
* <zh/>
*
* <en/> Whether to enable animation
* @defaultValue true
*/
animation?: boolean;
/**
* <zh/>
*
* <en/> Whether to enable the function of clicking the element
* @defaultValue true
* @remarks
* <zh/>
*
* <en/> Whether to enable can be dynamically controlled by functions, such as only when nodes are selected.
*
* ```json
* { enable: event => event.targetType === 'node'}
* ```
*/
enable?: boolean | ((event: IPointerEvent) => boolean);
/**
* <zh/>
*
* <en/> Whether to allow multiple selection
* @defaultValue false
*/
multiple?: boolean;
/**
* <zh/>
*
* <en/> Press this shortcut key to apply multiple selection with mouse click
* @defaultValue ['shift']
*/
trigger?: ShortcutKey;
/**
* <zh/>
*
* <en/> The state to be applied when an element is selected
* @defaultValue 'selected'
*/
state?: State;
/**
* <zh/> n n degree degree 1
*
* <en/> The state to be applied to the neighboring elements within n degrees when an element is selected. The value of n is controlled by the degree property, for instance, a degree of 1 indicates direct neighbors
* @defaultValue 'selected'
*/
neighborState?: State;
/**
* <zh/>
*
* <en/> The state to be applied to all unselected elements when some elements are selected, excluding the selected element and its affected neighbors
*/
unselectedState?: State;
/**
* <zh/>
*
* <en/> The degree to determine the scope of influence
* @defaultValue 0
* @remarks
* <zh/> `0` `1`
*
* <zh/> `0` `1`
*
* <en/> For nodes, `0` means only the current node is selected, `1` means the current node and its directly adjacent nodes and edges are selected, etc.
*
* <en/> For edges, `0 `means only the current edge is selected,`1` means the current edge and its directly adjacent nodes are selected, etc.
*/
degree?: number | ((event: IPointerEvent) => number);
/**
* <zh/>
*
* <en/> Callback when the element is clicked
* @param event - <zh/> | <en/> click event
*/
onClick?: (event: IPointerEvent) => void;
}
/**
* <zh/>
*
* <en/> Click Element
* @remarks
* <zh/> degree `1`
*
* <en/> When the mouse clicks on an element, you can activate the state of the element, such as selecting nodes or edges. When the degree is 1, clicking on a node will highlight the current node and its directly adjacent nodes and edges.
*/
export declare class ClickSelect extends BaseBehavior<ClickSelectOptions> {
private shortcut;
static defaultOptions: Partial<ClickSelectOptions>;
constructor(context: RuntimeContext, options: ClickSelectOptions);
private bindEvents;
private onClickSelect;
private onClickCanvas;
private get isMultipleSelect();
private getNeighborIds;
private updateState;
private getDataStates;
/**
* <zh/>
*
* <en/> Get the states that need to be cleared
* @param complete - <zh/> | <en/> Whether to return all states
* @returns - <zh/> | <en/> States that need to be cleared
*/
private getClearStates;
private clearState;
private validate;
private unbindEvents;
destroy(): void;
}