評論
在品類編輯器及授權設定之後註冊評論外掛,並載入通用及品類 UI 的樣式與語言資源。評論資源由品類外掛管理,還原快照前必須先註冊該外掛。
Shell
pnpm add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-uiShell
npm install @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-uiShell
yarn add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-uiShell
bun add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-uiTypeScript
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-ui | UniverSlidesThreadCommentUIPlugin | UniverSlidesThreadCommentMobileUIPlugin |
評論 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,請由應用程式提供這些路由。服務端須獨立驗證評論讀寫權限,不能僅依賴文件編輯權限。
你覺得這篇文檔如何?