Use tracked changes and editor modes
Before you start, install Nutrient Document Authoring SDK and load it in your app. If you haven’t set it up, refer to the getting started guide.
Nutrient Document Authoring SDK supports tracked changes for review workflows. Authorized users create tracked revisions, inspect tracked changes, and accept or reject them in the editor.
The example code omits error handling. Add error handling before you use this code in production.
Understand the editor modes
Nutrient Document Authoring SDK supports three editor modes:
edit— Changes apply directly, while existing tracked changes remain visible.review— New edits are recorded as tracked revisions, while tracked changes remain visible.view— Editing is disabled, while tracked changes remain visible.
Use editor.getEditorMode() to inspect the current mode:
const mode = editor.getEditorMode();console.log(mode);Switch modes at runtime
Use editor.setEditorMode(mode) to move between editing states:
editor.setEditorMode('edit');editor.setEditorMode('review');editor.setEditorMode('view');Use separate modes when your application needs separate drafting, review, and read-only steps.
Create tracked changes in review mode
When the editor is in review mode, supported edits are recorded as tracked changes instead of applying directly:
editor.setAuthor('Jane Reviewer');editor.setEditorMode('review');After switching to review mode, supported editor changes are recorded as revisions for the current author.
Set the author used for tracked changes
Use editor.setAuthor(name) to control the author name used for new tracked changes, comments, and replies:
editor.setAuthor('Legal Team');Read the current author with editor.getAuthor():
const author = editor.getAuthor();console.log(author);Clear the author name to use the default anonymous label:
editor.setAuthor('');Review and resolve tracked changes in the UI
Review tracked changes directly in the editor UI. Revisions can show inserted content, deleted content, and supported formatting or document property changes.
Users with permission can inspect each revision and accept or reject it in the editor.
Choose a review task
Refer to these guides to control review in your application:
- Refer to the control review permissions guide to restrict editor operations and assign participant roles.
- Refer to the manage tracked changes programmatically guide to query, accept, reject, and withdraw revisions in transactions.
- Refer to the observe review events guide to distinguish editor attempts from committed document changes.
Use tracked changes with Document Authoring AI
Document Authoring AI uses the same editor modes as the rest of the editor. Your app decides how AI write operations apply:
- In
editmode, AI writes can apply immediately. - In
reviewmode, AI writes can use tracked changes. Authorized users can accept or reject them. - In
viewmode, AI writes are blocked. Read-only AI tools can still inspect the document.
Set the editor author before you run AI writes in review mode. This attributes tracked changes to the right user or team. For AI-specific policy and writeMode: "track_changes" examples, refer to the review and approval in Document Authoring AI guide.
Use review transactions together with programmatic editing
Use review transactions to create tracked revisions from code with DocAuthDocument.transaction(). Supported changes are recorded as revisions for the supplied author. Changes that tracked-change markup can’t represent apply directly and don’t create revisions.
const currentDoc = editor.currentDocument();
await currentDoc.transaction( async ({ draft }) => { const paragraph = draft.body().content().addParagraph(); paragraph.asTextView().setText('This change is authored in review mode.');
return true; }, { review: { author: 'Nutrient Docs', }, },);For revision queries and decisions, refer to the manage tracked changes programmatically guide. For the transaction model, refer to the programmatic editing guide.
Learn more
Use these references for related review and editing workflows:
- Document Authoring API reference
- Refer to the comments guide to use comments in review workflows.
- Refer to the review permissions guide to control review permissions.
- Refer to the programmatic tracked changes guide to manage tracked changes.
- Refer to the review events guide to observe review events.
- Refer to the programmatic editing guide to run document transactions.
- Refer to the review and approval in Document Authoring AI guide to review AI writes.