Features
Comments
Let writers comment on a selection, reply, resolve threads and keep the comments when saving as Word, with the thread data stored next to the HTML.
Writers select some text, add a comment and discuss it in a panel next to the text. Other people reply, and a thread is marked resolved when it is done. On phones the panel opens as a sheet from the bottom of the screen.
Comments are part of the one-script build. With npm you add the extension and the panel yourself.
Using comments
- Select text and press the comment button above the selection, or press Ctrl+Alt+M (⌘+⌥+M on a Mac).
- The comments tool on the toolbar opens the panel. The number on it counts open threads.
- In the panel you can reply, edit or delete your own comments, resolve a thread and open it again.
- Placing the cursor in commented text highlights its thread.
- Comments can overlap and can stretch across paragraphs.
- In a read-only editor the toolbar keeps only the comments tool, so readers can open the panel and read the threads.
One-script build
Add a hidden field for the thread data and point the textarea at it with data-threads. data-user-id and data-user-name name the person who is writing:
<form method="post">
<textarea name="body" data-editor data-threads="body-threads"
data-user-id="42" data-user-name="Ayşe Yılmaz">…</textarea>
<input type="hidden" name="threads" id="body-threads" value="[]">
</form>
- The panel loads from
viveeditor.review.iife.jsthe first time it is needed. Like the other add-ons, it is checked against asha384fingerprint. - Every change is written to the hidden field as JSON, so the form sends the HTML and the threads together.
- Without both user attributes the panel is read-only.
- If the field holds broken JSON, the editor starts with no threads. Resetting the form brings back the threads the page loaded with.
- If the add-on cannot load, the editor keeps working without the panel.
With npm
- Install the packages:
npm install @viveeditor/ext-comments @viveeditor/ui @viveeditor/core. - Add
Commentsto the extensions and import its stylesheet. - Create a thread store and add
commentsPanel()to thepluginsofcreateUI.
import { Editor } from '@viveeditor/core'
import { basicExtensions } from '@viveeditor/ext-basic'
import { Comments } from '@viveeditor/ext-comments'
import { createThreadStore } from '@viveeditor/ext-comments/threads'
import { createUI } from '@viveeditor/ui'
import { commentsPanel } from '@viveeditor/ui/review'
import '@viveeditor/ext-comments/style.css'
const threads = createThreadStore(savedThreads)
const editor = await Editor.create(document.querySelector('#editor'), {
extensions: [...basicExtensions, Comments],
content: savedHtml,
})
createUI(editor, {
plugins: [commentsPanel({ threads, user: { id: '42', name: 'Ayşe Yılmaz' } })],
})
threads.subscribe(() => save({ html: editor.getHTML(), threads: threads.toJSON() }))
usercan also be a function, for apps where the signed-in person changes.nullmakes the panel read-only.threads.load(value)replaces every thread, for example after loading another document.threads.apply(action)changes threads from your own code and returnsfalsefor an action it refuses.
What is stored
The HTML marks the commented text:
<p>The <span data-vive-comment="V1StGXR8_Z5jdHi6B-myT">launch date</span> is fixed.</p>
The threads are a JSON list kept next to the HTML:
[{
"id": "V1StGXR8_Z5jdHi6B-myT",
"resolved": false,
"comments": [{
"id": "q2Hk9…",
"author": { "id": "42", "name": "Ayşe Yılmaz" },
"body": "Is this confirmed?",
"created": "2026-11-23T10:00:00.000Z"
}]
}]
Comment bodies are plain text, up to 5,000 characters. A document holds up to 1,000 threads with up to 200 comments each. Ids are 1 to 64 letters, digits, - or _. Thread data that breaks these rules is dropped when it is loaded.
Copying commented text and pasting it elsewhere does not copy the comment. Saving as Markdown writes the text without comments.
On the server
- The server sanitizer removes comment anchors by default. Use
comments: 'keep'when you clean HTML that will be edited again, and the default when you publish. - Clean the thread JSON too:
cleanThreadsfrom@viveeditor/ext-comments/threadsin Node,Viveeditor\Sanitizer\Threads::clean()orThreads::cleanJson()in PHP. Both apply the same rules.Threads::cleanJson()throws aSanitizeException(INVALID_JSON) for JSON it cannot read instead of saving an empty list, so a broken request never wipes the stored comments. - In Laravel, the editor component takes the threads and the user, and the
ViveThreadscast stores clean JSON. See Laravel.
Who may change comments
Only editing and deleting another person’s comment is blocked in the panel, and only in the browser. Anyone who can save the document can send any thread data, including comments under other names. Decide on your server who may save a document. If authors must be trusted, merge the incoming threads into the stored ones with reconcileThreads (Node) or Threads::reconcile() (PHP) when saving.
import { reconcileThreads } from '@viveeditor/ext-comments/threads'
const threads = reconcileThreads(storedThreads, request.body.threads, {
user: { id: session.userId, name: session.userName },
moderator: session.isModerator,
})
use Viveeditor\Sanitizer\Threads;
$threads = Threads::reconcile($storedThreads, $request->input('threads', '[]'), [
'user' => ['id' => $user->id, 'name' => $user->name],
'moderator' => $user->isModerator(),
]);
Both clean the two lists first and apply the same rules:
-
A new comment gets the saving person as
authorand the server time ascreated, whatever the browser sent. -
An existing comment keeps its stored
authorandcreated. A changed text is accepted only from its author or a moderator and gets the server time asedited; otherwise the stored text stays. -
A comment missing from the incoming list is deleted only when its author or a moderator saves; otherwise it comes back. A thread that disappears keeps the comments of other people.
-
Anyone who may save can resolve or reopen a thread.
-
The result follows the order of the incoming list, with threads that came back at the end. Stored threads count first toward the 1,000-thread limit.
-
nowsets the time used for new and edited comments (default: the current time). A missing or invalid user throws. -
Use an id that means nothing outside your app for
author.id, never an e-mail address: everyone who can open the document receives the threads. -
Store threads per document. A thread id is unique only inside its own document.
-
Thread JSON larger than 2 MB is refused by the PHP cleaner, so limit the field size in your validation as well.
-
Show published HTML through the sanitizer’s default, or
@viveHtmlin Laravel, so readers do not see which text was commented on.
Word files
With the File menu and the comments panel together:
- Save as Word writes each thread as a Word comment, with its replies and the resolved state. Threads whose text was deleted are left out.
- Open a Word file and its comments arrive in the panel with their authors, dates, replies and resolved state, and a small Word badge next to the author so they are not mistaken for people on your site. The threads already in the panel stay.
Without the comments panel, opening a Word file leaves its comments out. With npm, exportDocx(editor, { threads }) and the threads field of importDocx do the same.
Related pages
Frequently asked questions
Are the comments stored inside the HTML?
Only the place each comment refers to is stored in the HTML, as a span with the comment id. The comment text, authors and replies are stored separately as JSON.
Can a writer change someone else's comment?
The panel lets people edit and delete only their own comments, but that is a rule in the browser. Anyone who can save the document can send different thread data, so decide on your server who may save it, and merge what they send with `reconcileThreads` or `Threads::reconcile()`.
Do readers see the comments on the published page?
No. The server sanitizer removes comment anchors by default, so published pages show plain text.