@embedpdf/plugin-history

中文文档
3.2.0发布于 2026/11/12Apache-2.0TypeScriptESM + CJS近 30 天下载 171.6万

Undo and redo per open document, built on the document's change queue: every change the viewer's plugins stage is a step, undone by reference while still pending.

原始使用文档
文档目录4 节
  1. Setup
  2. Undo and redo
  3. When the engine answers
  4. For plugin authors

@embedpdf/plugin-history

Undo and redo for EmbedPDF, one history per open document, of what you change through the viewer: moving, restyling, deleting or typing into annotations, and every other change a plugin makes.

An action shows undone at once, even while it is still on its way to the engine. The engine undoes a change by reference: it keeps a record of what each change did, so the history keeps no copy of the document, and a part someone else changed since is left alone.

Setup

import { annotationPlugin } from '@embedpdf/react/annotation';
import { historyPlugin } from '@embedpdf/react/history';

const plugins = [
  // ...stage, interaction, selection...
  annotationPlugin(),
  historyPlugin(), // { limit: 100 } steps by default
];

No dependencies: it records the changes every plugin stages on the document's change queue.

Undo and redo

import { useHistory, useHistoryState } from '@embedpdf/react/history';

const history = useHistory();
const { canUndo, canRedo, undoLabel } = useHistoryState();

<button disabled={!canUndo} onClick={() => history.undo()}>
  Undo
</button>;
  • A step is one action: moving three annotations is one step, and so are the pauses of one typing session in one text box.
  • Labels are data: undoLabel is { key: 'annotation.move', count: 3 }, for your own translation ("Undo move of 3 annotations").
  • The selection follows: after an undo, what was selected before the action is selected again, as far as it still shows.

When the engine answers

What happensThe history
An undo or redo appliedonUndone({ label, redo, skipped }); skipped counts the parts someone changed since, which were left alone
The engine refused an actionThe action leaves the history; an undo of it already on its way says nothing
The engine refused an undo or redoonUndoFailed({ reason: 'refused', error }), and the step goes back: it can be tried again
It can't be undone any moreonUndoFailed({ reason: 'unavailable' }), and the step goes, with everything before it
A redaction, flattening, signing or form repairBoth stacks clear: nothing before it can be undone
A new version of the documentBoth stacks clear
Someone else changes the documentNothing: their changes aren't in your history, and the engine leaves alone what they changed since

For plugin authors

The history records what a plugin stages with ctx.changes. Give each change an undo (what undoing it looks like), so an undo is drawn before the engine answers; history: false keeps a change out; holds that make up one step pass one merge key. The rules are in docs/conventions/state-and-sync.md.

版本与发布记录

@embedpdf/plugin-history 共发布 92 个版本,首次发布于 2025/07/07;过去 12 个月发布了 49 个版本。

版本发布日期距今
3.2.0latest2026/11/121 天前
3.1.02026/11/094 天前
3.0.02026/11/076 天前
3.0.0-next.23next2026/11/076 天前
3.0.0-next.222026/11/049 天前
3.0.0-next.212026/11/0310 天前

关于 @embedpdf/plugin-history 的常见问题

@embedpdf/plugin-history 是什么?

Undo and redo per open document, built on the document's change queue: every change the viewer's plugins stage is a step, undone by reference while still pending.

如何安装 @embedpdf/plugin-history?

在项目目录运行 npm install @embedpdf/plugin-history,或使用 pnpm add / yarn add / bun add。

@embedpdf/plugin-history 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@embedpdf/plugin-history 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@embedpdf/plugin-history 可以商用吗?

@embedpdf/plugin-history 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@embedpdf/plugin-history 的下载量有多少?

根据 npm 官方下载统计,@embedpdf/plugin-history 在 2026/10/14 – 2026/11/12 这 30 天内被下载 1,716,129 次,日均约 57,204 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@embedpdf/plugin-history 还在维护吗?

最新版本 3.2.0 发布于 2026/11/12(1 天前);至今共发布 92 个版本,其中过去 12 个月发布了 49 个;首次发布于 2025/07/07。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。