import { HistoryEvent } from '../../constants/events/history'; import type { RuntimeContext } from '../../runtime/types'; import { Loosen } from '../../types'; import type { Command } from '../../types/history'; import type { BasePluginOptions } from '../base-plugin'; import { BasePlugin } from '../base-plugin'; /** * 历史记录配置项 * * History options */ export interface HistoryOptions extends BasePluginOptions { /** * 最多记录该数据长度的历史记录 * * The maximum number of history records * @defaultValue 0(不做限制) */ stackSize?: number; /** * 当一个命令被添加到 Undo/Redo 队列前被调用,如果该方法返回 false,那么这个命令将不会被添加到队列中。revert 为 true 时表示撤销操作,为 false 时表示重做操作 * * Called before a command is added to the Undo/Redo queue. If this method returns false, the command will not be added to the queue. revert is true for undo operations and false for redo operations */ beforeAddCommand?: (cmd: Command, revert: boolean) => boolean | void; /** * 当一个命令被添加到 Undo/Redo 队列后被调用。revert 为 true 时表示撤销操作,为 false 时表示重做操作 * * Called after a command is added to the Undo/Redo queue. revert is true for undo operations and false for redo operations */ afterAddCommand?: (cmd: Command, revert: boolean) => void; /** * 执行命令时的回调函数 * * Callback function when executing a command */ executeCommand?: (cmd: Command) => void; } /** * 历史记录 * * History * @remarks * 历史记录用于记录图的数据变化,支持撤销和重做等操作。 * * History is used to record data changes in the graph and supports operations such as undo and redo. */ export declare class History extends BasePlugin { static defaultOptions: Partial; private emitter; private batchChanges; private batchAnimation; undoStack: Command[]; redoStack: Command[]; private freezed; constructor(context: RuntimeContext, options: HistoryOptions); /** * 是否可以执行撤销操作 * * Whether undo can be done * @returns 是否可以执行撤销操作 | Whether undo can be done */ canUndo(): boolean; /** * 是否可以执行重做操作 * * Whether redo can be done * @returns 是否可以执行重做操作 | Whether redo can be done */ canRedo(): boolean; /** * 执行撤销 * * Execute undo * @returns 返回当前实例 | Return the current instance */ undo(): this | undefined; /** * 执行重做 * * Execute redo * @returns 返回当前实例 | Return the current instance */ redo(): this; /** * 执行撤销且不计入历史记录 * * Execute undo and do not record in history * @returns 返回当前实例 | Return the current instance */ undoAndCancel(): this; private executeCommand; private addCommand; private initBatchCommand; private undoStackPush; /** * 清空历史记录 * * Clear history */ clear(): void; private notify; /** * 监听历史记录事件 * * Listen to history events * @param event - 事件名称 | Event name * @param handler - 事件处理函数 | Event handler */ on(event: Loosen, handler: (e: { cmd?: Command | null; }) => void): void; /** * 销毁 * * Destroy * @internal */ destroy(): void; }