評論

插件信息

評論外掛應在品類編輯器和許可證配置完成後註冊,同時載入通用和品類 UI 的樣式與語言資源。評論資源由對應的品類外掛管理,因此恢復快照前必須先註冊該外掛。

Shell
pnpm add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-ui
TypeScript
import { 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/zh-TW'import { LocaleType, mergeLocales } from '@univerjs/core'import SharedLocale from '@univerjs/thread-comment-ui/locale/zh-TW'import '@univerjs/thread-comment-ui/lib/index.css'import '@univerjs-pro/slides-thread-comment-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_TW, mergeLocales(SharedLocale, ProductLocale))univer.registerPlugin(UniverSlidesThreadCommentPlugin)univer.registerPlugin(UniverSlidesThreadCommentUIPlugin)

行動裝置支援

請先配置行動版編輯器。在本頁介紹的外掛模式初始化程式碼中,將下面列出的桌面版註冊替換為同一套件匯出的行動版外掛,並且必須在開啟文件前完成替換。模型外掛、樣式、語言套件和 Facade 匯入均需保留,不要同時註冊兩個版本。

套件桌面版註冊行動版註冊
@univerjs-pro/slides-thread-comment-uiUniverSlidesThreadCommentUIPluginUniverSlidesThreadCommentMobileUIPlugin

評論 Facade

呼叫這些方法之前,需要同時匯入通用評論 Facade 和品類 Facade。品類方法負責建立穩定的錨點,通用 API 負責回覆、修改、解決和刪除。getComments() 讀取本地狀態;listCommentsAsync() 會透過已配置的資料來源同步已知的執行緒,但不會發現伺服器端的全部執行緒。

TypeScript
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())}
TypeScript
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.',  })}

共享討論

共享討論需要先透過 Server SDK 接入 Comment Service 和 Endpoint,然後在協同與許可證配置完成後,註冊 @univerjs-pro/thread-comment-datasource 中的 UniverThreadCommentDataSourcePlugin。內建資料來源會請求 /universer-api/comment/unit/{unitId}/... 和 /universer-api/user/list,這兩個路由需要由應用對外提供。評論的讀取和寫入需要單獨的伺服器端權限,文件編輯權限無法覆蓋。

你覺得這篇文檔如何?

© 2026 DreamNum Co., Ltd.