Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

3.5 KB
Raw Blame

@univerjs/thread-comment

npm version license downloads

@univerjs/thread-comment provides shared thread comment models, commands, and services that product-specific comment packages build on.

Package Overview

Package UMD global CSS Locales Facade entry Worker entry
@univerjs/thread-comment UniverThreadComment No No Yes No

Installation

pnpm add @univerjs/thread-comment
# or
npm install @univerjs/thread-comment

Usage

Start with the integration setup for your document type, including its required plugins, styles, and locale resources. The snippet below assumes that setup is complete.

import { UniverThreadCommentPlugin } from '@univerjs/thread-comment';
import '@univerjs/thread-comment/facade';

univer.registerPlugin(UniverThreadCommentPlugin);

const openComments = univerAPI.getComments({
  authorIds: ['review-agent'],
  anchorKinds: [univerAPI.Enum.ThreadCommentAnchorKind.SLIDE_ELEMENT],
  resolved: false,
});

All commentable targets use stable IDs and a shared query vocabulary:

Product target Product Facade ThreadCommentAnchorKind
Sheet cell FRange.addCommentAsync() SHEET_CELL
Sheet image, chart, or Shape element createCommentAsync() SHEET_DRAWING
Document text range FDocumentTextRange.createCommentAsync() DOC_TEXT_RANGE
Document image, chart, or Shape element createCommentAsync() DOC_DRAWING
Slide Shape, text, image, chart, table, or group FPageElement.createCommentAsync() or FSlide.createElementCommentAsync() SLIDE_ELEMENT
Slide free position FSlide.createPositionCommentAsync() SLIDE_POSITION
Board Shape, text, image, chart, table, connector, mind map, or ink FBoard.createElementCommentAsync() BOARD_ELEMENT
Board free position FBoard.createPositionCommentAsync() BOARD_POSITION
Base record in Grid, Kanban, Gallery, Calendar, or Gantt FBaseTableRecord.createCommentAsync() BASE_RECORD

Product Facades create and locate anchored threads. Use the shared Facade for thread lifecycle operations:

const record = univerAPI.getActiveBase()?.getTables()[0]?.getRecords()[0];
const [thread] = record ? await record.listCommentsAsync() : [];
if (thread) {
  await univerAPI.replyCommentAsync({
    unitId: thread.unitId,
    subUnitId: thread.subUnitId,
    threadId: thread.threadId,
    content: 'Verified.',
    id: 'review-record-1-reply',
  });
  await univerAPI.resolveCommentAsync({
    unitId: thread.unitId,
    subUnitId: thread.subUnitId,
    commentId: thread.root.id,
  });
}

personId defaults to the current identity in UserManagerService. Agent and human identities intentionally share that user-management boundary.

Integration Notes

Product-specific packages such as @univerjs/sheets-thread-comment and @univerjs/docs-thread-comment-ui build on this shared layer.

Resources