import { Syringe } from 'mana-syringe'; import type { Disposable, DisposableCollection } from '../common/disposable'; import type { Graph as X6Graph } from '@antv/x6'; import type { IGraphConfig } from '../xflow-main/graph/config'; import type { NsModel, RxModel } from '../common/rx-model'; import type { IModelService } from '../model-service'; import type { IHooks } from '../command-contributions/interface'; import type { IRuntimeHook } from '@antv/xflow-hook/es/interface'; import type { NsGraph } from '../interface'; /** * A command is a unique identifier of a function * which can be executed by a user via a keyboard shortcut, * a menu action or directly. */ export interface IGraphCommand { /** * A unique identifier of this command. */ id: string; /** * A label of this command. */ label?: string; /** * An icon class of this command. */ iconName?: string; /** * A category of this command. */ category?: string; } /** Command 状态 */ export interface ICommandState { /** * cmd是否可以执行 */ isEnabled: boolean; /** * cmd是否可见 */ isVisible: boolean; } /** * IGraphCommandService * 声明执行Command的接口 */ export declare const IGraphCommandService: unique symbol; export interface IGraphCommandService { /** event:可以监听CommandService的变化 */ watchChange: NsModel.IWatch; /** 撤销命令 */ undoCommand: () => Promise; /** 重做命令 */ redoCommand: () => Promise; /** 是否可重做 */ isRedoable: boolean; /** 是否可撤销 */ isUndoable: boolean; /** 执行原子命令:会在undo stack中push cmd */ executeCommand: (commandId: string, args: Args, hooks?: IRuntimeHook) => Promise | undefined>; /** 用pipeline执行命令 */ executeCommandPipeline: (cmdOptions: IGraphPipelineCommand[]) => Promise; /** 执行撤销命令:不会在undo stack中push新的command记录 */ executeUndoCommand: (commandId: string, args: Args, hooks?: IRuntimeHook) => Promise | undefined>; /** 注册Command */ registerCommand: (command: IGraphCommand, factory: ICommandFactory) => Disposable; /** 注册Command */ setGlobal: (key: string, value: any) => void; /** 注册Command */ getGlobal: (key: string) => void; } /** * Command factory * 负责创建Command实例 */ export interface ICommandFactory { /** * 生成一个command */ createCommand: (commandId: string, args: Args, hooks: IRuntimeHook) => ICommandHandler; /** * 创建cmd state */ createCmdState?: (IContextService: IModelService) => Promise>; /** * cmd是否可用的state */ cmdState?: RxModel; } /** * Command Handler 的 Token */ export declare const ICommandHandler: Syringe.DefinedToken; /** * Command Handler * 负责Command的执行逻辑 */ export interface ICommandHandler { /** * 执行cmd返回的disposables * * Reject if a command cannot be executed. */ execute: () => Promise; /** * 执行 undo */ undo: () => Promise; /** * 执行 redo */ redo: () => Promise; /** * isUndoable */ isUndoable: () => boolean; /** * 获取执行cmd的context */ contextProvider: () => IContext; } /** Command Context Provider 的 Symbol 提供执行需要的各种api */ export declare const ICommandContextProvider: unique symbol; /** * Command Context Provider: 返回Command执行需要的IContext */ export interface ICommandContextProvider { (): IContext; } /** * Command Context: 提供Command执行需要的各种api */ export interface IContext { /** 执行undo */ undo: () => Promise; /** 添加undo */ addUndo: (disposable: Disposable) => Disposable; /** 是否可以undo */ isUndoable: () => boolean; /** 获取参数 */ getArgs: () => { args: Args; hooks: IRuntimeHook; }; /** 设置参数 */ setArgs: (args: Args, hooks: IRuntimeHook) => { args: Args; hooks: IRuntimeHook; }; /** 获取结果 */ getResult: () => Result; /** 设置结果 */ setResult: (result: Result) => Result; /** 获取hooks */ getHooks: () => Hooks; /** 获取Graph */ getX6Graph: () => Promise; /** 获取GraphMeta */ getGraphMeta: () => Promise; /** 获取Graph配置 */ getGraphConfig: () => Promise; /** 获取Command */ getCommands: () => IGraphCommandService; /** 获取ModelService */ getModelService: () => IModelService; /** 获取Disposables */ getDisposables: () => DisposableCollection; /** 设置command间的共享变量 */ setGlobal: (key: string, value: T) => void; /** 获取共享变量 */ getGlobal: (key: string) => T; } /** * IGraphCommandFactory * Command工厂方法 */ export declare const IGraphCommandFactory: unique symbol; export interface IGraphCommandFactory { (cmdId: string, cmdArgs: Args, hooks?: IRuntimeHook): ICommandHandler; } /** * Command注册扩展的Symbol */ export declare const IGraphCommandContribution: Syringe.DefinedToken; /** * Command的扩展类型 */ export interface IGraphCommandContribution { /** * Register commands and handlers. */ registerGraphCommands: (commands: IGraphCommandService) => void; } /** 执行command需要的参数 */ export interface ICommandConfig { /** command id */ commandId?: string; /** command 参数 */ args: Args; /** command hook */ hooks?: IRuntimeHook; } /** 执行command参数的基类 */ export interface IArgsBase { commandService?: IGraphCommandService; modelService?: IModelService; } /** Pipeline命令参数 */ export interface IGraphPipelineCommand { commandId: string; getCommandOption: (ctx: IContext) => Promise>; } /** 执行command需要的参数 */ export interface IGenericCmdOptions { (item: T, modelService: IModelService, cmd: IGraphCommandService): Promise>; } /** Command 注册函数 */ export interface ICommandRegisterFunction { (registry: Pick): void; }