Comments
Register the comment plugins after the product editor and the license are set up. Load the shared and product UI styles and locale resources. The product plugin owns its comment resources, so a snapshot can be restored only after that plugin is registered.
pnpm add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-uinpm install @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-uiyarn add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-uibun add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-uiimport { UniverSlidesThreadCommentPlugin } from '@univerjs-pro/slides-thread-comment'import { UniverSlidesThreadCommentUIPlugin } from '@univerjs-pro/slides-thread-comment-ui'import ProductLocale from '@univerjs-pro/slides-thread-comment-ui/locale/en-US'import { LocaleType, mergeLocales } from '@univerjs/core'import SharedLocale from '@univerjs/thread-comment-ui/locale/en-US'import '@univerjs/thread-comment-ui/lib/index.css'import '@univerjs-pro/slides-thread-comment-ui/lib/index.css'univerAPI.loadLocales(LocaleType.EN_US, mergeLocales(SharedLocale, ProductLocale))univer.registerPlugin(UniverSlidesThreadCommentPlugin)univer.registerPlugin(UniverSlidesThreadCommentUIPlugin)Mobile support
Configure the mobile editor first. In the plugin-mode setup described on this page, replace the desktop registrations 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-pro/slides-thread-comment-ui | UniverSlidesThreadCommentUIPlugin | UniverSlidesThreadCommentMobileUIPlugin |
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 the threads it already knows about through the configured data source, but it does not discover every thread on the server.
import '@univerjs/thread-comment/facade'import '@univerjs-pro/slides-thread-comment/facade'const element = univerAPI.getActivePresentation()?.getSlideByIndex(0)?.getElements()[0]if (element) { await element.createCommentAsync('Please review this element.') console.log(await element.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 their own server permissions; document editing permission does not cover them.
How is this guide?