评论
在品类编辑器和许可证配置之后注册评论插件,并加载通用及品类 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-CN'import { LocaleType, mergeLocales } from '@univerjs/core'import SharedLocale from '@univerjs/thread-comment-ui/locale/zh-CN'import '@univerjs/thread-comment-ui/lib/index.css'import '@univerjs-pro/slides-thread-comment-ui/lib/index.css'univerAPI.loadLocales(LocaleType.ZH_CN, mergeLocales(SharedLocale, ProductLocale))univer.registerPlugin(UniverSlidesThreadCommentPlugin)univer.registerPlugin(UniverSlidesThreadCommentUIPlugin)评论 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,请通过应用暴露这些路由。服务端需要独立验证评论读写权限,不能仅依赖文档编辑权限。
你觉得这篇文档如何?