@reductoai/docx-editor gives you a Word-like editor in one call: toolbar, ruler, pages, review margin, find, context menu, dialogs, icons and styles.
Before you mount the editor, add the license proxy to your backend. The examples below assume it is at
/reducto. A browser editor without a proxy opens no document.Vanilla JS
React
dynamic(() => import("./Editor"), { ssr: false }).
document opens again when the object changes, so keep it stable between renders (state or useMemo).
useObservable(model, pick) re-renders only when a picked field changes. Always pass a selector for a component that stays mounted: the model changes on every caret move.
Svelte 5
UsemountDocxEditor from a Svelte 5 component. The bundle has its own Svelte runtime, so it works with any Svelte version:
Options
Layout engine
The editor lays out pages in@reductoai/docx/engine.wasm, a file in the @reductoai/docx package. Vite, webpack and Next.js copy it into your build with a hashed name, as they do for an image, so you set nothing.
Set wasmUrl only with another bundler (esbuild, for example), or when you serve the file from another place. Copy node_modules/@reductoai/docx/wasm/engine.wasm to your site and give its URL:
- If the engine does not load, the editor shows
no layout enginein place of the document, andmodel.errorholds the text with the URL that failed. - The browser downloads the engine (about 2 MB compressed) once. Serve it with
content-type: application/wasm, so the browser compiles it while it downloads. - Use it with
worker. On the page thread it works too, but it starts more slowly. - If the engine fails while it opens or lays out the document (a WebAssembly trap, which Safari 18.0 sometimes hits), the editor starts a fresh engine and lays out the current document again once, in the same Session.
- A worker that you write yourself over
serveEditorHostfinds the engine the same way. See Your own worker. - A page with a Content-Security-Policy must allow WebAssembly: add
'wasm-unsafe-eval'toscript-src. Without it the engine does not start and the error names the directive. - The engine and the package come from one release. Do not mix an
engine.wasmfrom one version with the editor of another.
Save and export
downloadDocx(model) and downloadPdf(model) wrap these in a file download.
Replace regions
Eight regions take a slot. Leave a slot out to keep the built-in, passnull to remove the region, or pass a function to put your own markup there.
toolbar={<MyToolbar model={model} />}, inspector={null}.
To change a built-in region, replace it with your own. The format bar is the exception: toolbarItems changes it (see below). If you replace most regions, use the headless model.
Everything a toolbar needs is on the model: model.format, toggleBold(), toggleItalic(), setAlignment(), toggleList(), undo(), redo(), setSuggesting(), model.find, model.review, and formatCommands(model) for the full command list. Build your own skin shows a complete toolbar, menu bar and context menu.
Change the format bar
You can keep the built-in format bar and remove or add controls.hide takes section names and control names. add puts your own control at the end of a section. If you do not give a section, your control gets a section of its own after the built-in sections:
On the docs site, this example runs live. Change hide, and the bar under the code changes.
TOOLBAR_SECTIONS has the same list. When the bar is too narrow, your controls fold into the More tools menu with the built-in controls. A control of your own goes under its label there (default “More”).
To change the bar after mount, assign a new object to model.toolbarItems. For example, hide the insert section for a reviewer.
A hidden control only goes off the bar. Its keys and its command palette row still work. To stop all edits, set readOnly.
In React, toolbarItems is a prop, and an addition takes a node in place of a slot:
reviewer changes the bar at once. Read the model in an added node through useObservable(model, select), so the node renders only when the field it reads changes. With hide: ["insert"], the built-in insert controls go away, but your Signature button stays.
Theme
Every colour, radius, shadow and font is a CSS custom property. Override them on:root or on the mount element:
@reductoai/docx-editor/tokens.css lists every token.
The stylesheet styles only the editor. Its reset, font, text selection colour and scrollbars apply under the reductoai class. The editor puts this class on its mount root and on the menus and dialogs it shows over the page. Your page keeps its own styles, also after the editor unmounts. On a page that shows only the editor, add the class to <html> and import page.css for the page margin and background:
data-theme="dark" on <html> and repaint the pages with Word’s dark-page colours:
Track changes and comments
model.setSuggesting(true)tracks the user’s edits (Word’s Track Changes).model.reviewdrives the review margin:accept(scope),reject(scope),reply(id, text),resolve(id, true),remove(id). A scope is"all","selection",{ id }or{ ids }.
Lock the editing mode
By default, the user picks Editing or Suggesting in the mode menu, with ⌘⇧E (Ctrl+Shift+E), or with the command palette. A document that has Word’s Track Changes setting on opens in Suggesting mode. Setsuggesting to take this choice away:
"off" or "on":
- The mode menu keeps Accept all, Reject all, Show resolved comments and Change user name. It does not show the Editing and Suggesting choice.
- ⌘⇧E does nothing, and the command palette does not show Track changes.
- Each document opens in the locked mode, whatever its own setting is.
- Tracked changes that are already in the document still show, and the user can accept or reject them.
model.suggestingPolicy. model.setSuggesting() cannot override the lock. To remove the mode menu too, add toolbarItems: { hide: ["mode"] }.
Display for Review
Word’s Display for Review sets how tracked changes show. Pick it when you open the document. The first layout then uses it:model.setMarkup(markup):
The user can type, track changes, accept and reject in every view except Original. A reopen with
keepView keeps the current view.
Set the author
Each tracked change and comment carries an author name. The default is"Reducto". Set the name of your signed-in user before or after a document opens:
model.revisionAuthor reads the current name.
An editor connected to a document server uses the token’s name (else the name in server) until you set one.
The user can also set the name: Change user name… in the editing mode menu or the command palette. The editor does not save this name. To keep it across visits, store it yourself:
Read-only view
SetreadOnly: true when you mount the editor (in React, the readOnly prop), or set model.readOnly = true later, to make a reader’s view:
- The caret moves, text selects, and Find and Copy work. Every edit is dropped.
- The toolbar, the inspector and the selection strip go away. The context menu has only Copy, Find and the navigation pane.
- A plain click on a link follows it, and the pointer shows a hand over links. A drag that starts on a link selects text.
- The pages get a transparent text layer, so a screen reader can read them.
model.locked is different. It drops commands while another writer (for example, an agent turn) owns the session. The chrome stays.
Screen readers
The pages are canvas, so the editor speaks through a polite live region (role="status") next to its input:
- When the caret lands on a new line, the screen reader reads the line. An empty line reads “blank”.
- An arrow key, Home or End along the same line reads the characters the caret crosses. A typed key is not read again, because the screen reader echoes it.
- A selection reads its text (up to 200 characters) and “selected”.
- A tracked deletion on the line reads as “deleted: … end deleted”. In All Markup, an insertion reads as “inserted: … end inserted”.
Links
links hooks every hyperlink. An href is a URL, or #name for a bookmark.
onClickruns on every click on a link and on every Open link (from the link strip or the context menu).followistruewhen the editor would open the link: Cmd+click (Ctrl+click on Windows), a click in a read-only view, or Open link. Returntrueand the editor does not open it.- A plain click while editing puts the caret in the link.
onClickthen getsfollow: false, so you can show a preview while the user edits. onHovergets the link under the pointer and the box of its text on that line, in client pixels. It getsnullwhen the pointer leaves the link. The box is measured when the pointer moves. If the pages scroll under a still pointer, the box is out of date.
links prop. Change it at any time with model.links = { ... }.