Documents
Opening, switching, and closing documents in a multi-document workspace.
Open a document#
A document is a File, Blob, or ArrayBuffer in any of the supported
formats. Pass documents in initialDocuments, or
open them at runtime:
const doc = await editor.documents.open(
{ id: "exhibit-a", title: "Exhibit A", source: file },
{ activate: true },
);open() resolves to a ReviseDocumentHandle when the document is parsed and
ready. A new document becomes active by default. Pass { activate: false } to
open it in the background.
You assign document IDs. Each must be stable and unique within one editor
instance. Callbacks, tool routing, and forDocument() use them. Do not reuse
an ID for different content.
Per-document options#
Any editor-wide option can be overridden per document:
await editor.documents.open({
id: "exhibit-a",
source: file,
format: "markdown", // optional; inferred from the filename or MIME type
title: "Exhibit A",
documentMode: "suggesting",
readOnly: false,
zoom: "fit-width",
defaultCommentsOpen: false,
agent: { model: "claude-opus-5-5" },
});Switch and close#
editor.documents.activate("exhibit-a");
editor.documents.close("exhibit-a");
editor.documents.getActiveId(); // "contract-1"
editor.documents.list(); // [{ id, title, status, active, error }]Closing a document does not save it. Export it first if you need the file.
Observe the document list#
useEffect(
() =>
editor.documents.subscribe((state) => {
setTabs(state.documents);
setActiveId(state.activeDocumentId);
}),
[editor],
);Each entry has a status of "opening", "ready", or "error", and an
error string when parsing failed. Use them to render tabs with loading and
error states.
Controlled or uncontrolled#
By default, the component tracks the active document. To control it from your
own state, pass activeDocumentId and handle onActiveDocumentChange:
<ReviseEditor
activeDocumentId={activeId}
onActiveDocumentChange={setActiveId}
initialDocuments={docs}
/>defaultActiveDocumentId sets the initial active document without controlling it.
Export#
const blob = await editor.tools.exportDocx(); // active document
const other = await editor.tools.exportDocx("exhibit-a"); // a specific oneRead content#
Read the document tree for your own logic, such as word counts, validation, or autosave:
const doc = editor.getDocument(); // active
const doc2 = editor.getDocument("exhibit-a");onChange(documentId, document) fires on every edit from the user, your
toolbar, or an agent.
onChange fires on every keystroke. Debounce before saving. Use
measure_document or a cheap check instead of walking the whole tree on
every call.