HistoryPlugin(撤销/重做)
HistoryPlugin 为 ListTable 提供撤销/重做能力:它会把用户操作转换为可回放的事务(transaction),从而实现 undo/redo。
安装
npm install @visactor/vtable-plugins
基础用法(VTable)
import { ListTable } from '@visactor/vtable'; import { HistoryPlugin } from '@visactor/vtable-plugins'; const table = new ListTable(container, { records, columns, plugins: [ new HistoryPlugin({ maxHistory: 100, enableCompression: false }) ] }); const history = table.pluginManager.getPlugin('history-plugin') as HistoryPlugin; history.undo(); history.redo();
快捷键
- Ctrl/Cmd + Z:撤销
- Ctrl/Cmd + Shift + Z 或 Ctrl/Cmd + Y:重做
配置项
export interface HistoryPluginOptions {
id?: string;
maxHistory?: number;
enableCompression?: boolean;
onTransactionPushed?: (args: { tx: HistoryTransaction; sheetKey?: string; table?: ListTable }) => void;
}
id:插件 id(默认history-plugin)maxHistory:最大历史条数enableCompression:是否把连续编辑合并到上一条事务onTransactionPushed:新事务入栈回调(用于 和上层历史管理器联动)
在 VTable-Sheet 中使用
VTable-Sheet 内部会使用 HistoryPlugin 采集表格层操作,并汇总到工作簿级别历史栈。你可以:
- 通过
VTablePluginModules覆盖HistoryPlugin配置 - 通过
VTablePluginModules: [{ module: HistoryPlugin, disabled: true }]禁用内置历史采集
import { VTableSheet } from '@visactor/vtable-sheet'; import { HistoryPlugin } from '@visactor/vtable-plugins'; const sheet = new VTableSheet(container, { VTablePluginModules: [ { module: HistoryPlugin, moduleOptions: { maxHistory: 200, enableCompression: false } } ], sheets: [/* ... */] });