UNPKG

@inweb/viewer-core

Version:

3D CAD and BIM data Viewer core

99 lines (98 loc) 3.1 kB
import { IViewer } from "../viewer/IViewer"; /** * Defines the command executer service interface. */ export interface ICommandService { /** * Executes the command denoted by the given command ID. * * @param id - ID of the command to execute. * @param args - Parameters passed to the command handler function. * @returns Returns the result of the command handler function. Returns `undefined` when the command * doesn't exists. */ executeCommand(id: string, ...args: any[]): any; } /** * Defines the command handler function. */ export interface ICommandHandler { /** * @param viewer - Viewer instance that executes the command. * @param args - Parameters passed to the command handler function. */ (viewer: any, ...args: any[]): any; } /** * Defines the command to execute by the {@link Viewer}. */ export interface ICommand { /** * Command ID. */ id: string; /** * Handler function. */ handler: ICommandHandler; /** * The `this` context used when invoking the handler function. */ thisArg?: any; /** * Command description. */ description?: ICommandDescription; } /** * Defines the command description. */ export interface ICommandDescription { /** * Command description string. */ readonly description: string; } /** * Defines the viewer commands registry interface. */ export interface ICommandsRegistry { /** * Binds a command ID to a handler function. Registering a command with an existing ID twice overrides * the existing handler. * * @param id - Unique ID for the command. * @param handler - Command handler function. * @param description - Command description. * @param thisArg - The `this` context used when invoking the handler function. */ registerCommand(id: string, handler: ICommandHandler, description?: ICommandDescription, thisArg?: any): void; /** * Registers an alias for a command. * * @param id - Unique ID for the command. * @param alias - Command alias string. */ registerCommandAlias(id: string, alias: string): void; /** * Returns a list of registered commands. */ getCommands(): Map<string, ICommand>; /** * Returns the specified command or `undefined` when the command doesn't exists. * * @param id - Command ID. */ getCommand(id: string): ICommand | undefined; /** * Executes the command denoted by the given command. If the command is not found, tries to set active * dragger with the specified name. * * @param id - Command ID or dragger name. * @param viewer - Viewer instance that wants to execute the command. * @param args - Parameters passed to the command handler function. * @returns Returns the result of the command handler function or new active dragger instance. Returns * `undefined` if neither the command nor the dragger exists. */ executeCommand(id: string, viewer: IViewer, ...args: any[]): any; }