import * as _flowgram_ai_utils from '@flowgram.ai/utils'; import { Disposable, Event, Emitter } from '@flowgram.ai/utils'; import { ContainerModule } from 'inversify'; /** * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates * SPDX-License-Identifier: MIT */ declare const CommandService: unique symbol; /** * command service 执行接口 */ interface CommandService extends Disposable { /** * command 事件执行前触发事件 */ readonly onWillExecuteCommand: Event; /** * command 事件执行完成后触发 */ readonly onDidExecuteCommand: Event; /** * 执行 command */ executeCommand(command: string, ...args: any[]): Promise; } interface Command { /** * id,唯一 key */ id: string; /** * 展示用 label */ label?: string; /** * 在一些明确的场景下,部分只展示简短的 label 即可 */ shortLabel?: string; /** * 展示用 command icon */ icon?: string | React.ReactNode | ((props: any) => React.ReactNode); /** * 暂不使用 */ category?: string; } declare namespace Command { enum Default { ZOOM_IN = "ZOOM_IN", ZOOM_OUT = "ZOOM_OUT", DELETE = "DELETE", COPY = "COPY", PASTE = "PASTE", UNDO = "UNDO", REDO = "REDO", VIEW_CLOSE_ALL_WIDGET = "view.closeAllWidget", VIEW_CLOSE_CURRENT_WIDGET = "view.closeCurrentWidget", VIEW_REOPEN_LAST_WIDGET = "view.reopenLastWidget", VIEW_CLOSE_OTHER_WIDGET = "view.closeOtherWidget", VIEW_CLOSE_BOTTOM_PANEL = "view.closeBottomPannel", VIEW_OPEN_NEXT_TAB = "view.openNextTab", VIEW_OEPN_LAST_TAB = "view.openLastTab", VIEW_FULL_SCREEN = "view.fullScreen", VIEW_SAVING_WIDGET_CLOSE_CONFIRM = "view.savingWidgetCloseConfirm", VIEW_SHORTCUTS = "view.shortcuts", VIEW_PREFERENCES = "view.preferences", VIEW_LOG = "view.log", VIEW_PROBLEMS = "view.problems" } /** * 判断是否是 command */ function is(arg: Command | any): arg is Command; } interface CommandHandler { /** * handler 执行函数 */ execute(...args: any[]): any; /** * 该 handler 是否可以执行 */ isEnabled?(...args: any[]): boolean; /** * 预留 contextMenu 用,该 handler 是否可见 */ isVisible?(...args: any[]): boolean; /** * 预留 contextMenu 用,该 handler 是否可以触发 */ isToggled?(...args: any[]): boolean; } interface CommandEvent { /** * commandId */ commandId: string; /** * 参数 */ args: any[]; } declare const CommandContribution: unique symbol; interface CommandContribution { /** * 注册 command */ registerCommands(commands: CommandService): void; } /** * 当前正在运行的 command */ interface CommandExecuting { /** * commandid */ id: string; /** * 参数 */ args: any[]; /** * 正在进行的 promise */ promise?: Promise; } declare namespace CommandExecuting { /** * 获取正在运行的 command 单个实例 */ function findSimple(arrs: Set, newCmd: CommandExecuting): CommandExecuting | undefined; } declare const CommandRegistryFactory = "CommandRegistryFactory"; declare class CommandRegistry implements CommandService { protected readonly _handlers: { [id: string]: CommandHandler[]; }; protected readonly _commands: { [id: string]: Command; }; protected readonly _commandExecutings: Set; protected readonly toUnregisterCommands: Map; protected readonly onDidExecuteCommandEmitter: Emitter; readonly onDidExecuteCommand: _flowgram_ai_utils.Event; protected readonly onWillExecuteCommandEmitter: Emitter; readonly onWillExecuteCommand: _flowgram_ai_utils.Event; protected readonly contributions: CommandContribution[]; init(): void; /** * 当前所有 command */ get commands(): Command[]; /** * 当前所有 commandid */ get commandIds(): string[]; /** * registerCommand */ registerCommand(id: string, handler?: CommandHandler): Disposable; registerCommand(command: Command, handler?: CommandHandler): Disposable; /** * unregisterCommand */ unregisterCommand(command: Command): void; unregisterCommand(id: string): void; /** * 注册 handler */ registerHandler(commandId: string, handler: CommandHandler): Disposable; /** * 预留 contextMenu 用,该 handler 是否可见 */ isVisible(command: string, ...args: any[]): boolean; /** * command 是否可用 */ isEnabled(command: string, ...args: any[]): boolean; /** * 预留 contextMenu 用,该 handler 是否可以触发 */ isToggled(command: string, ...args: any[]): boolean; /** * 执行 command,会先判断是否可以执行,不会重复执行 */ executeCommand(commandId: string, ...args: any[]): Promise; getVisibleHandler(commandId: string, ...args: any[]): CommandHandler | undefined; getActiveHandler(commandId: string, ...args: any[]): CommandHandler | undefined; /** * 获取 command 对应的所有 handler */ getAllHandlers(commandId: string): CommandHandler[]; getToggledHandler(commandId: string, ...args: any[]): CommandHandler | undefined; /** * 获取 command */ getCommand(id: string): Command | undefined; protected doRegisterCommand(command: Command): Disposable; /** * 更新 command */ updateCommand(id: string, command: Partial>): void; dispose(): void; } /** * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates * SPDX-License-Identifier: MIT */ declare const CommandContainerModule: ContainerModule; export { Command, CommandContainerModule, CommandContribution, type CommandHandler, CommandRegistry, CommandRegistryFactory, CommandService };