Comments
Users can add comments and replies inside a document, so team members can discuss the content in place.
Plugin mode
Installation
pnpm add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs/docs-thread-comment @univerjs/docs-thread-comment-uinpm install @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs/docs-thread-comment @univerjs/docs-thread-comment-uiyarn add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs/docs-thread-comment @univerjs/docs-thread-comment-uibun add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs/docs-thread-comment @univerjs/docs-thread-comment-uiUsage
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'import { UniverDocsThreadCommentPlugin } from '@univerjs/docs-thread-comment'import { UniverDocsThreadCommentUIPlugin } from '@univerjs/docs-thread-comment-ui'import { UniverThreadCommentPlugin } from '@univerjs/thread-comment'import { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui'import DocsCommentLocale from '@univerjs/docs-thread-comment-ui/locale/en-US'import ThreadCommentUIEnUS from '@univerjs/thread-comment-ui/locale/en-US'import '@univerjs/docs-thread-comment/facade'import '@univerjs/docs-thread-comment-ui/lib/index.css'import '@univerjs/thread-comment-ui/lib/index.css'const univer = new Univer({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( ThreadCommentUIEnUS, DocsCommentLocale, ), },})univer.registerPlugin(UniverThreadCommentPlugin)univer.registerPlugin(UniverThreadCommentUIPlugin)univer.registerPlugin(UniverDocsThreadCommentPlugin)univer.registerPlugin(UniverDocsThreadCommentUIPlugin)Using with collaboration feature
If the application uses Collaboration, register the data source plugin as well:
pnpm add @univerjs-pro/thread-comment-datasourcenpm install @univerjs-pro/thread-comment-datasourceyarn add @univerjs-pro/thread-comment-datasourcebun add @univerjs-pro/thread-comment-datasourceimport { UniverThreadCommentDataSourcePlugin } from '@univerjs-pro/thread-comment-datasource'univer.registerPlugin(UniverThreadCommentDataSourcePlugin)Mobile support
Configure the mobile editor first. In the plugin-mode setup on this page, replace the desktop registrations listed below with the mobile exports from the same packages, and make the replacement before opening a document. Keep the model plugins, styles, locales, and Facade imports, and do not register both variants.
| Package | Desktop registration | Mobile registration |
|---|---|---|
@univerjs/docs-thread-comment-ui | UniverDocsThreadCommentUIPlugin | UniverDocsThreadCommentMobileUIPlugin |
@univerjs/thread-comment-ui | UniverThreadCommentUIPlugin | UniverThreadCommentMobileUIPlugin |
Preset mode
Installation
pnpm add @univerjs/preset-docs-thread-commentnpm install @univerjs/preset-docs-thread-commentyarn add @univerjs/preset-docs-thread-commentbun add @univerjs/preset-docs-thread-commentUsage
import { UniverDocsCorePreset } from '@univerjs/preset-docs-core'import UniverPresetDocsCoreEnUS from '@univerjs/preset-docs-core/locales/en-US'import { UniverDocsThreadCommentPreset } from '@univerjs/preset-docs-thread-comment'import UniverPresetDocsThreadCommentEnUS from '@univerjs/preset-docs-thread-comment/locales/en-US'import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'import '@univerjs/preset-docs-core/lib/index.css'import '@univerjs/preset-docs-thread-comment/lib/index.css'const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( UniverPresetDocsCoreEnUS, UniverPresetDocsThreadCommentEnUS, ), }, presets: [ UniverDocsCorePreset(), UniverDocsThreadCommentPreset(), ],})Comment Facade
Import the shared comment Facade and the product Facade before calling these methods. The product helpers create stable anchors, and the shared API handles replies, updates, resolution, and deletion. getComments() reads local state. listCommentsAsync() synchronizes threads that are already known through the configured data source; it does not discover every thread on the server.
import '@univerjs/thread-comment/facade'import '@univerjs/docs-thread-comment/facade'const range = univerAPI.getActiveDocument()?.getTextRange(0, 1)if (range) { await range.createCommentAsync('Please review this text.') console.log(await range.listCommentsAsync())}import '@univerjs/thread-comment/facade'const [thread] = univerAPI.getComments({ resolved: false })if (thread) { await univerAPI.replyCommentAsync({ unitId: thread.unitId, subUnitId: thread.subUnitId, threadId: thread.threadId, content: 'Reviewed.', })}Shared discussions
Shared discussions require the Comment Service and Endpoint to be connected through Server SDK. After collaboration and license setup, register UniverThreadCommentDataSourcePlugin from @univerjs-pro/thread-comment-datasource. The supplied data source calls /universer-api/comment/unit/{unitId}/... and /universer-api/user/list, so the application must expose those routes. Comment reads and writes require separate server permissions; document editing permission does not cover them.
Comments on images and charts
Configure the host drawing or chart plugins first, then add the matching integration below and its Facade entry before opening the Unit. Plugin mode and preset mode both require these integrations to be registered explicitly. They add no styles or locales.
pnpm add @univerjs-pro/docs-drawing-thread-comment @univerjs-pro/docs-chart-thread-commentnpm install @univerjs-pro/docs-drawing-thread-comment @univerjs-pro/docs-chart-thread-commentyarn add @univerjs-pro/docs-drawing-thread-comment @univerjs-pro/docs-chart-thread-commentbun add @univerjs-pro/docs-drawing-thread-comment @univerjs-pro/docs-chart-thread-commentimport { UniverDocsDrawingThreadCommentPlugin } from '@univerjs-pro/docs-drawing-thread-comment'import { UniverDocsChartThreadCommentPlugin } from '@univerjs-pro/docs-chart-thread-comment'import '@univerjs-pro/docs-drawing-thread-comment/facade'import '@univerjs-pro/docs-chart-thread-comment/facade'univer.registerPlugin(UniverDocsDrawingThreadCommentPlugin)univer.registerPlugin(UniverDocsChartThreadCommentPlugin)After a Unit is open, comments can be added to images and charts that already exist in it. getComments() returns the threads loaded locally, and listCommentsAsync() synchronizes the threads it knows about before returning them.
const host = univerAPI.getActiveDocument()const image = host?.getImages()[0]const chart = host?.getCharts()[0]await image?.createCommentAsync('Review this image.')await chart?.createCommentAsync('Verify the chart source.')@univerjs-pro/docs-drawing-thread-comment · @univerjs-pro/docs-chart-thread-comment
How is this guide?