Documents
Open, switch, observe, export, and close documents in a workspace.
Open a document#
Pass a File, Blob, or ArrayBuffer in any supported format via initialDocuments or editor.documents.open():
const doc = await editor.documents.open(
{ id: "exhibit-a", title: "Exhibit A", source: file },
{ activate: true },
);open() resolves to a ReviseDocumentHandle once parsed. Newly opened documents become active by default; pass { activate: false } to load in the background.
Document IDs are host-owned and must be stable and unique within an editor instance. Do not reuse an ID for different content.
Per-document options#
Per-document inputs override editor-wide props:
await editor.documents.open({
id: "exhibit-a",
source: file,
format: "markdown", // inferred from filename or MIME type if omitted
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 }]close() discards unsaved edits; export first if persistence is needed.
Observe the document list#
useEffect(
() =>
editor.documents.subscribe((state) => {
setTabs(state.documents);
setActiveId(state.activeDocumentId);
}),
[editor],
);Each entry reports status: "opening" | "ready" | "error" and an optional error message.
Controlled or uncontrolled#
By default, ReviseEditor manages the active document (defaultActiveDocumentId sets the initial value). To control it externally, pass activeDocumentId and onActiveDocumentChange:
<ReviseEditor
activeDocumentId={activeId}
onActiveDocumentChange={setActiveId}
initialDocuments={docs}
/>Export#
const blob = await editor.tools.exportDocx(); // active document
const other = await editor.tools.exportDocx("exhibit-a"); // specific documentRead content#
const doc = editor.getDocument(); // active document
const doc2 = editor.getDocument("exhibit-a");onChange(documentId, document) fires on every user, toolbar, or agent edit.
onChange runs on every keystroke. Debounce saves, and use
editor.getStatistics() (no layout pass) rather than walking the full
document tree on every event.