UNPKG

@maxgraph/core

Version:

maxGraph is a fully client side JavaScript diagramming library that uses SVG and HTML for rendering.

136 lines (135 loc) 4.45 kB
import Point from '../geometry/Point.js'; import InternalMouseEvent from '../event/InternalMouseEvent.js'; import type { AbstractGraph } from '../AbstractGraph.js'; import type { GraphPlugin, MouseListenerSet } from '../../types.js'; import EventSource from '../event/EventSource.js'; /** * Event handler that selects rectangular regions. * * **IMPORTANT**: This is not built-into `maxGraph` i.e. this plugin is not in the `maxGraph` default plugins, see {@link getDefaultPlugins}. * * To enable rubberband selection in a graph, use the following code. * * ```javascript * const plugins = [ * ...getDefaultPlugins(), // or any other plugins you want * RubberBandHandler, * ]; * * // Creates the graph with the custom plugins * const graph = new Graph(container, undefined, plugins); * ``` * * **IMPORTANT**: the RubberBandHandler requires CSS styles in order to work properly. * See the CSS rules in the `css/common.css` file provided within the npm package. They relate to the `.mxRubberband` class. * * @category Plugin */ declare class RubberBandHandler implements GraphPlugin, MouseListenerSet { static pluginId: string; constructor(graph: AbstractGraph); forceRubberbandHandler: Function; panHandler: Function; gestureHandler: Function; graph: AbstractGraph; first: Point | null; destroyed: boolean; dragHandler: ((evt: MouseEvent) => void) | null; dropHandler: ((evt: MouseEvent) => void) | null; x: number; y: number; width: number; height: number; /** * Specifies the default opacity to be used for the rubberband div. * Valid values are between `0` and `100`. * @default 20 */ defaultOpacity: number; /** * Specifies if events are handled. * @default true */ enabled: boolean; /** * Holds the DIV element which is currently visible. */ div: HTMLElement | null; /** * Holds the DIV element which is used to display the rubberband. */ sharedDiv: HTMLElement | null; /** * Holds the value of the x argument in the last call to {@link update}. */ currentX: number; /** * Holds the value of the y argument in the last call to {@link update}. */ currentY: number; /** * Optional fade out effect. * @default false */ fadeOut: boolean; /** * Creates the rubberband selection shape. */ isEnabled(): boolean; /** * Enables or disables event handling. This implementation updates{@link enabled}. */ setEnabled(enabled: boolean): void; /** * Returns true if the given {@link MouseEvent} should start rubberband selection. * This implementation returns true if the alt key is pressed. */ isForceRubberbandEvent(me: InternalMouseEvent): boolean; /** * Handles the event by initiating a rubberband selection. * By consuming the event all subsequent events of the gesture are redirected to this handler. */ mouseDown(_sender: EventSource, me: InternalMouseEvent): void; /** * Creates the rubberband selection shape. */ start(x: number, y: number): void; /** * Handles the event by updating the rubberband selection. */ mouseMove(_sender: EventSource, me: InternalMouseEvent): void; /** * Creates the rubberband selection shape. */ createShape(): HTMLElement; /** * Returns true if this handler is active. */ isActive(sender?: EventSource, me?: InternalMouseEvent): boolean | null; /** * Handles the event by selecting the region of the rubberband using {@link AbstractGraph.selectRegion}. */ mouseUp(_sender: EventSource, me: InternalMouseEvent): void; /** * Resets the state of this handler and selects the current region for the given event. */ execute(evt: MouseEvent): void; /** * Resets the state of the rubberband selection. */ reset(): void; /** * Sets <currentX> and <currentY> and calls {@link repaint}. */ update(x: number, y: number): void; /** * Computes the bounding box and updates the style of the `div`. */ repaint(): void; /** * Destroys the handler and all its resources and DOM nodes. * This does normally not need to be called, it is called automatically when the window unloads. */ onDestroy(): void; } export default RubberBandHandler;