Skip to Content
🎉 Univer 0.8.0 版本已发布。查看详情 →
GuidesUniver Sheets功能历史记录Pro

历史记录

Facade API可付费升级需要 Univer 服务端Univer on Node.jsPreset
--UniverSheetsCollaborationPreset

Univer 基于协同编辑提供了历史记录功能,因此在使用历史记录之前,需要先安装 协同编辑 功能

该功能包含以下插件包:

Presets 安装

按照 协同编辑功能 中的引导安装即可。

手动组合安装

npm install @univerjs-pro/edit-history-viewer @univerjs-pro/edit-history-loader
import { LocaleType, merge, Univer } from '@univerjs/core'; import { defaultTheme } from "@univerjs/design"; import { UniverEditHistoryLoaderPlugin } from '@univerjs-pro/edit-history-loader'; import EditHistoryViewerZhCN from '@univerjs-pro/edit-history-viewer/locale/zh-CN'; import '@univerjs-pro/edit-history-viewer/lib/index.css'; const univer = new Univer({ theme: defaultTheme, locale: LocaleType.ZH_CN, locales: { [LocaleType.ZH_CN]: merge( EditHistoryViewerZhCN ), }, }); univer.registerPlugin(UniverEditHistoryLoaderPlugin, { univerContainerId: 'Your-Univer-Container-Id', });

启动历史记录时,UniverEditHistoryLoaderPlugin 会加载一个新的 Univer 实例挂载指定 DOM 节点上。因此在注册时,需要提供合适的 DOM 节点 id(如原 Univer 实例的 Container),以达到历史记录面板覆盖原 Univer 面板的目的。若节点 id 未指定,则默认为 univer-container

Feature 适配

历史记录的 Univer 实例中只会默认加载官方的 Plugin。为业务需求开发的第三方 Feature Plugin 需要被注册到 HistoryLoaderService 后,才会被正确的显示在历史记录中。

对已经内置注册的官方 Plugin,也可以修改其配置。

在 HistoryLoaderService 中,你还可以获取或订阅历史记录的 Univer 实例,用于支持更多的拓展操作。

import { HistoryLoaderService } from '@univerjs-pro/edit-history-loader'; // Presets 引入: import { HistoryLoaderService } from '@univerjs/presets/preset-sheets-collaboration'; const disposable = univerAPI.addEvent(univerAPI.Event.LifeCycleChanged, ({ stage }) => { if (stage === univerAPI.Enum.LifecycleStages.Steady) { const injector = univer.__getInjector(); const historyLoaderService = injector.get(HistoryLoaderService); // 和 PluginService 的注册方式一致,历史记录的 Univer 实例在新建后会按照以下配置来注册对应 Plugin historyLoaderService.registerPlugin(YourPlugin, YourPluginConfig); // 配置官方已注册的 Plugin, 需设置 true 参数表示覆盖原配置 historyLoaderService.registerPlugin(ExamplePlugin, ExamplePluginConfig, true); // 如果加载了历史记录,则可以直接获取到历史记录的 Univer 实例 const historyUniver = historyLoaderService.historyUniver; } }); // 移除事件监听器,使用 `disposable.dispose()`

这个页面对您有帮助吗?
Last updated on