@gravity-ui/graph
Version:
Modern graph editor component
45 lines (44 loc) • 1.7 kB
TypeScript
import { Graph } from "../../graph";
/**
* KeyboardService
* This is an internal service that manages keyboard state for the graph.
*
* It is used to detect keyboard state changes and to provide a reactive signal with the current keyboard state.
*
* @example
* ```typescript
* const keyboardService = new KeyboardService(graph);
* keyboardService.$keyboardState.subscribe((state) => {
* console.log("is shift key pressed", state.shiftKey);
* console.log("is meta key pressed", state.metaKey);
* console.log("is ctrl key pressed", state.ctrlKey);
* console.log("is alt key pressed", state.altKey);
* });
* ```
* @internal
*/
export declare class KeyboardService {
private graph;
protected $keyboardState: import("@preact/signals-core").Signal<{
shiftKey: boolean;
metaKey: boolean;
ctrlKey: boolean;
altKey: boolean;
}>;
protected lastEvent: KeyboardEvent | null;
protected unsubscribes: (() => void)[];
constructor(graph: Graph);
isShiftPressed(): boolean;
isMetaPressed(): boolean;
isCtrlPressed(): boolean;
isAltPressed(): boolean;
protected keybordEvents: EventTarget;
protected startListening(): void;
onPress(key: string, cb: (event: CustomEvent<KeyboardEvent>) => void, options?: AddEventListenerOptions): () => void;
onRelease(key: string, cb: (event: CustomEvent<KeyboardEvent>) => void, options?: AddEventListenerOptions): () => void;
protected stopListening(): void;
protected hasChanged(event: KeyboardEvent): boolean;
protected notifyKeyCode(event: KeyboardEvent): void;
protected handleKeyDown: (event: KeyboardEvent) => void;
protected cleanup(): void;
}