Thread Comment
| Packages | @univerjs/thread-comment, @univerjs/docs-thread-comment, @univerjs/sheets-thread-comment, @univerjs-pro/bases-thread-comment, @univerjs-pro/boards-thread-comment, @univerjs-pro/slides-thread-comment, @univerjs-pro/shape-thread-comment |
|---|
A unified Facade for creating, querying, updating, resolving, and deleting thread comments across Univer products. The existing Sheets comment object and builder APIs remain documented below.
Cross-product API
import '@univerjs/thread-comment/facade'const [comment] = univerAPI.getComments({ resolved: false })if (comment) { await univerAPI.replyCommentAsync({ unitId: comment.unitId, subUnitId: comment.subUnitId, threadId: comment.threadId, content: 'Verified.', })}| Method | Purpose |
|---|---|
createCommentAsync | Create a root thread on a serialized product anchor |
replyCommentAsync | Reply to a loaded root thread |
updateCommentAsync | Update root or reply content and attachments |
deleteCommentAsync | Delete one comment or the complete thread tree |
resolveCommentAsync | Resolve or reopen a thread |
getComments | Filter locally loaded threads |
listCommentsAsync | Synchronize known threads, then apply the same filters |
Available anchor kinds are SHEET_CELL, SHEET_DRAWING, DOC_TEXT_RANGE, DOC_DRAWING, SLIDE_ELEMENT, SLIDE_POSITION, BOARD_ELEMENT, BOARD_POSITION, and BASE_RECORD through univerAPI.Enum.ThreadCommentAnchorKind.
Product Facade entries provide convenient methods on ranges, text ranges, elements, slides, boards, and Base records. Use the root methods when an application already owns the serialized anchor.
Legacy Sheets comment objects
@univerjs/sheets-thread-comment
| Method | Description |
|---|---|
build | Build the comment |
copy | Copy the comment |
create | Create a new FTheadCommentItem |
deleteAsync | Delete the comment and its replies |
getCommentData | Get the comment data |
getIsRoot | Whether the comment is a root comment |
getRange | Get the range of the comment |
getReplies | Get the replies of the comment |
getRichText | Get the rich text of the comment |
replyAsync | Reply to the comment |
resolveAsync | Resolve the comment |
setContent | Set the content of the comment |
setDateTime | Set the date time of the comment |
setId | Set the id of the comment |
setPersonId | Set the person id of the comment |
setThreadId | Set the thread id of the comment |
updateAsync | Update the comment content |
APIs
Lifecycle & Creation
build
Build the comment
Signature
build(): IThreadCommentReturns
IThreadComment— The comment
Examples
const richText = univerAPI.newRichText().insertText('hello univer');const comment = univerAPI.newTheadComment() .setContent(richText) .setPersonId('mock-user-id') .setDateTime(new Date('2025-02-21 14:22:22')) .setId('mock-comment-id') .setThreadId('mock-thread-id') .build();console.log(comment);@univerjs/sheets-thread-comment
create
Create a new FTheadCommentItem
Signature
static create(comment?: IThreadComment): FTheadCommentItemParameters
commentIThreadComment(optional) — No description
Returns
FTheadCommentItem— A new instance of FTheadCommentItem
Examples
const commentBuilder = univerAPI.newTheadComment();console.log(commentBuilder);@univerjs/sheets-thread-comment
Getters & Queries
getCommentData
Get the comment data
Signature
getCommentData(): IBaseCommentReturns
IBaseComment— The comment data
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const comments = fWorksheet.getComments();comments.forEach((comment) => { console.log(comment.getCommentData());});@univerjs/sheets-thread-comment
getIsRoot
Whether the comment is a root comment
Signature
getIsRoot(): booleanReturns
boolean— Whether the comment is a root comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const comments = fWorksheet.getComments();comments.forEach((comment) => { console.log(comment.getIsRoot());});@univerjs/sheets-thread-comment
getRange
Get the range of the comment
Signature
getRange(): FRange | nullReturns
FRange | null— The range of the comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const comments = fWorksheet.getComments();comments.forEach((comment) => { const range = comment.getRange(); if (range) { console.log(range.getA1Notation()); }});@univerjs/sheets-thread-comment
getReplies
Get the replies of the comment
Signature
getReplies(): FThreadComment[] | undefinedReturns
FThreadComment[]— the replies of the comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const comments = fWorksheet.getComments();comments.forEach((comment) => { if (comment.getIsRoot()) { const replies = comment.getReplies(); replies?.forEach((reply) => { console.log(reply.getCommentData()); }); }});@univerjs/sheets-thread-comment
getRichText
Get the rich text of the comment
Signature
getRichText(): RichTextValueReturns
RichTextValue— The rich text of the comment
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const comments = fWorksheet.getComments();comments.forEach((comment) => { console.log(comment.getRichText());});@univerjs/sheets-thread-comment
Setters & Modifiers
setContent
Set the content of the comment
Signature
setContent(content: IDocumentBody | RichTextValue): FTheadCommentBuilderParameters
contentIDocumentBody | RichTextValue— No description
Returns
FTheadCommentBuilder— The comment builder for chaining
Examples
// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer');const commentBuilder = univerAPI.newTheadComment() .setContent(richText);console.log(commentBuilder.content);// Add the comment to the cell A1const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const cell = fWorksheet.getRange('A1');const result = await cell.addCommentAsync(commentBuilder);console.log(result);@univerjs/sheets-thread-comment
setDateTime
Set the date time of the comment
Signature
setDateTime(date: Date): FTheadCommentBuilderParameters
dateDate— No description
Returns
FTheadCommentBuilder— The comment builder for chaining
Examples
// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer');const commentBuilder = univerAPI.newTheadComment() .setContent(richText) .setDateTime(new Date('2025-02-21 14:22:22'));console.log(commentBuilder.dateTime);// Add the comment to the cell A1const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const cell = fWorksheet.getRange('A1');const result = await cell.addCommentAsync(commentBuilder);console.log(result);@univerjs/sheets-thread-comment
setId
Set the id of the comment
Signature
setId(id: string): FTheadCommentBuilderParameters
idstring— No description
Returns
FTheadCommentBuilder— The comment builder for chaining
Examples
// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer');const commentBuilder = univerAPI.newTheadComment() .setContent(richText) .setId('mock-comment-id');console.log(commentBuilder.id);// Add the comment to the cell A1const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const cell = fWorksheet.getRange('A1');const result = await cell.addCommentAsync(commentBuilder);console.log(result);@univerjs/sheets-thread-comment
setPersonId
Set the person id of the comment
Signature
setPersonId(userId: string): FTheadCommentBuilderParameters
userIdstring— No description
Returns
FTheadCommentBuilder— The comment builder for chaining
Examples
// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer');const commentBuilder = univerAPI.newTheadComment() .setContent(richText) .setPersonId('mock-user-id');console.log(commentBuilder.personId);// Add the comment to the cell A1const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const cell = fWorksheet.getRange('A1');const result = await cell.addCommentAsync(commentBuilder);console.log(result);@univerjs/sheets-thread-comment
setThreadId
Set the thread id of the comment
Signature
setThreadId(threadId: string): FTheadCommentBuilderParameters
threadIdstring— No description
Returns
FTheadCommentBuilder— The comment builder
Examples
// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer');const commentBuilder = univerAPI.newTheadComment() .setContent(richText) .setThreadId('mock-thread-id');console.log(commentBuilder.threadId);// Add the comment to the cell A1const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const cell = fWorksheet.getRange('A1');const result = await cell.addCommentAsync(commentBuilder);console.log(result);@univerjs/sheets-thread-comment
updateAsync
Update the comment content
Signature
async updateAsync(content: IDocumentBody | RichTextValue): Promise<boolean>Parameters
contentIDocumentBody | RichTextValue— No description
Returns
Promise<boolean>— Whether the comment is updated successfully
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer');const commentBuilder = univerAPI.newTheadComment() .setContent(richText) .setId('mock-comment-id');const cell = fWorksheet.getRange('A1');await cell.addCommentAsync(commentBuilder);// Update the comment after 3 secondssetTimeout(async () => { const comment = fWorksheet.getCommentById('mock-comment-id'); const newRichText = univerAPI.newRichText().insertText('Hello Univer AI'); const result = await comment.updateAsync(newRichText); console.log(result);}, 3000);@univerjs/sheets-thread-comment
Actions & Operations
copy
Copy the comment
Signature
copy(): FTheadCommentBuilderReturns
FTheadCommentBuilder— The comment builder
Examples
const commentBuilder = univerAPI.newTheadComment();const newCommentBuilder = commentBuilder.copy();console.log(newCommentBuilder);@univerjs/sheets-thread-comment
deleteAsync
Delete the comment and its replies
Signature
deleteAsync(): Promise<boolean>Returns
Promise<boolean>— Whether the comment is deleted successfully
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();const comments = fWorksheet.getComments();// Delete the first commentconst result = await comments[0]?.deleteAsync();console.log(result);@univerjs/sheets-thread-comment
Miscellaneous
replyAsync
Reply to the comment
Signature
replyAsync(comment: FTheadCommentBuilder): Promise<boolean>Parameters
commentFTheadCommentBuilder— No description
Returns
Promise<boolean>— Whether the comment is replied successfully
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer');const commentBuilder = univerAPI.newTheadComment() .setContent(richText) .setId('mock-comment-id');const cell = fWorksheet.getRange('A1');await cell.addCommentAsync(commentBuilder);// Reply to the commentconst replyText = univerAPI.newRichText().insertText('Hello Univer AI');const reply = univerAPI.newTheadComment().setContent(replyText);const comment = fWorksheet.getCommentById('mock-comment-id');const result = await comment.replyAsync(reply);console.log(result);@univerjs/sheets-thread-comment
resolveAsync
Resolve the comment
Signature
resolveAsync(resolved?: boolean): Promise<boolean>Parameters
resolvedboolean(optional) — No description
Returns
Promise<boolean>— Set the comment to resolved or not operation result
Examples
const fWorkbook = univerAPI.getActiveWorkbook();const fWorksheet = fWorkbook.getActiveSheet();// Create a new commentconst richText = univerAPI.newRichText().insertText('hello univer');const commentBuilder = univerAPI.newTheadComment() .setContent(richText) .setId('mock-comment-id');const cell = fWorksheet.getRange('A1');await cell.addCommentAsync(commentBuilder);// Resolve the comment after 3 secondssetTimeout(async () => { const comment = fWorksheet.getCommentById('mock-comment-id'); const result = await comment.resolveAsync(true); console.log(result);}, 3000);@univerjs/sheets-thread-commentHow is this guide?