@betteroffice/pptx-react

中文文档
0.5.1发布于 2026/10/27Apache-2.0TypeScriptES Module构建来源已验证近 30 天下载 9.7万

PowerPoint-faithful React PPTX editor and viewer: full OOXML fidelity, real-time human + AI agent collaboration.

原始使用文档
文档目录12 节
  1. Install
  2. Usage
  3. Key options
  4. Editor API
  5. Saving
  6. Toolbar
  7. Plugins
  8. Version-checked edit batches
  9. Review agent proposals
  10. Collaboration
  11. Browser integration
  12. Documentation

@betteroffice/pptx-react

React presentation editor with a slide canvas, slide strip, formatting toolbar, and keyboard editing. The engine runs in a Web Worker by default, with promise-returning reads and exports.

Install

bun add @betteroffice/pptx-react react react-dom

Peer dependencies: react and react-dom, version 18 or 19; the PPTX core is a package dependency.

Usage

import { PptxEditor } from '@betteroffice/pptx-react';

export function Presentation({ file, fontBytes }: {
  file: Uint8Array;
  fontBytes: Uint8Array;
}) {
  return (
    <div style={{ height: 720 }}>
      <PptxEditor file={file} fonts={[{ family: 'My Sans', bytes: fontBytes }]} />
    </div>
  );
}

fonts is required. Each entry is a family name and the bytes of a TTF or OTF file, for example fetched from your server or loaded with loadBundledFontBytes from @betteroffice/fonts.

Key options

The exported PptxAsyncEditorProps type describes the default editor props. All props below are optional except fonts.

proptypedescription
fileUint8Array | ArrayBufferPresentation bytes to open.
fontsReadonlyArray<PptxFontFace>Font families and bytes for text layout.
readOnlybooleanBlock user edits while retaining navigation and selection.
initialSlidenumberInitial slide, numbered from 1 and clamped to the deck.
fileNamestringDownload name; defaults to presentation.pptx.
classNamestringClass for the editor container.
styleCSSPropertiesInline styles for the editor container.
initialZoomnumberInitial zoom scale from 0.1 to 5; omitted, the slide fits the stage.
loadingIndicatorReactNodeShown while the presentation opens.
i18nPptxAsyncEditorProps['i18n']UI translations from @betteroffice/pptx-i18n.
onReady(api: PptxAsyncEditorApi) => void | (() => void)Receive the async API; optionally return cleanup.
onChange(snapshot: DeckSnapshot) => voidReceive deck snapshots after changes.
onDocumentChange(change: PptxDocumentChange) => voidReceive { version } after a committed edit, alongside onChange.
onError(error: Error) => voidReceive loading and editing errors.
onSave(bytes: Uint8Array) => voidReceive saved bytes; omitted, saving downloads the file.
downloadOnSavebooleanWhether saving also downloads a copy; defaults to true only without onSave.
onSaveRequest() => boolean | void | Promise<boolean | void>Intercept toolbar and keyboard saves; return true to continue.
toolbarReactNodeReplace built-in controls; null removes them.
showToolbarbooleanShow the toolbar region; defaults to true.
collaborationPptxAsyncCollaborationOptionsShared seed, replica callback, and presence options.
pluginsreadonly PptxPlugin[]Host-owned tools, panels, and overlays.
pluginGrantsReadonly<Record<string, PptxPluginGrant>>Permissions keyed by plugin ID.
onPluginError(error: PptxPluginError) => voidReceive isolated plugin failures.

PptxFontFace and DeckSnapshot are exported by @betteroffice/pptx; editor and plugin types are exported by @betteroffice/pptx-react. ReactNode is a React type.

Deprecated: legacySyncApi keeps the synchronous API on the in-thread engine and is removed in 0.6.0; omit it to use the default async editor. Also omit the deprecated experimentalWorkerOpen prop.

Editor API

onReady receives PptxAsyncEditorApi. Await save() to serialize the presentation (saveAsync() is a deprecated alias), and await handleAsync() for asynchronous document access, including snapshot(), exportStructured(), and exportMarkdown(). Reads and exports through that access object return promises; the API also has exportStructured() and exportMarkdown() directly. Work that cannot run against its input or target rejects with PptxCommandAdmissionError.

flushPendingInput() waits for accepted input. goToSlide(slide) and selectText(target) return promises; slide numbers are 1-based and text offsets use UTF-16. getPositionAtPoint(clientX, clientY) asynchronously returns a hit on the current slide or null outside slide content.

Finish pointer gestures before workflows that flush input. Keep the API tied to the mounted presentation; replacing or closing the document invalidates its access.

Saving

The toolbar and Ctrl/Cmd+S invoke onSaveRequest before serialization. Its result is awaited: true continues saving, while false or void handles or cancels the request. If saving continues, onSave receives the bytes, and the editor downloads the file using fileName when downloadOnSave is true (the default without onSave).

Calling save() directly returns bytes without invoking those save callbacks.

Toolbar

The toolbar composition API is experimental. api.commands is shared by the built-in controls and host toolbar parts. Replace controls with toolbar, or hide the region with showToolbar={false}. See Compose the PPTX toolbar for composition, external controls, command state, and overflow.

Deprecated: prop-based EditorToolbar and Toolbar usage is replaced by command-mode controls; use EditorToolbar with mode="commands".

Plugins

definePptxPlugin defines tools installed through plugins, with permissions supplied by pluginGrants. This plugin API is experimental and may change in minor releases. See Host PPTX editor plugins for panels, overlays, lifecycle, permissions, and error handling.

Version-checked edit batches

readContent, findText, validateEdits, and applyEdits on the editor API return promises and run after pending input. See Edit PPTX in version-checked batches for requests, atomicity, and typed refusals.

Review agent proposals

Use the access returned by handleAsync() to call propose, then await refreshProposals(). Pending proposals appear on the canvas with text differences, shape bounds, and speaker-note diffs. The review controls preview, accept, or reject a group; acceptance creates one undo step.

Escape or Edit slide exits review mode. Saving, PNG export, and presentation mode use committed content. Pending proposals stay in the session; accepted edits are saved and synchronized.

Collaboration

Pass collaboration to co-edit a deck; onReplica receives an async replica or null on cleanup. Set roomId when switching rooms and seed peers from the same update. Omit clientId to generate one for each opened session. See the collaboration guide for transport setup.

Browser integration

Mount the editor in the browser with a container of explicit height. Frameworks that render on the server should load the editor client-side with server rendering disabled. See hosting for worker, chunk and CSP needs.

Documentation

版本与发布记录

@betteroffice/pptx-react 共发布 9 个版本,首次发布于 2026/07/20;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.1latest2026/10/2712 天前
0.5.02026/10/2613 天前
0.2.02026/09/291 个月前
0.1.12026/09/171 个月前
0.1.02026/09/161 个月前
0.0.42026/08/202 个月前

关于 @betteroffice/pptx-react 的常见问题

@betteroffice/pptx-react 是什么?

PowerPoint-faithful React PPTX editor and viewer: full OOXML fidelity, real-time human + AI agent collaboration.

如何安装 @betteroffice/pptx-react?

在项目目录运行 npm install @betteroffice/pptx-react,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@betteroffice/pptx-react 支持 TypeScript 吗?

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

@betteroffice/pptx-react 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@betteroffice/pptx-react 可以商用吗?

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

@betteroffice/pptx-react 的下载量有多少?

根据 npm 官方下载统计,@betteroffice/pptx-react 在 2026/10/08 – 2026/11/06 这 30 天内被下载 96,570 次,日均约 3,219 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@betteroffice/pptx-react 还在维护吗?

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