Commentaires
Les utilisateurs peuvent ajouter des commentaires et des réponses dans un document, de sorte que les membres de l'équipe peuvent discuter du contenu en place.
Mode plugin
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-uiUtilisation
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)Utilisation avec la fonctionnalité de collaboration
Si l'application utilise Collaboration, enregistrez également le plugin source de données :
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)Prise en charge mobile
Configurez d'abord le éditeur mobile. Dans la configuration en mode plugin de cette page, remplacez les enregistrements de bureau énumérés ci-dessous par les exportations mobiles des mêmes paquets, et faites le remplacement avant d'ouvrir un document . Gardez les modèles plugins, styles, locaux et importations Facade, et ne enregistrez pas les deux variantes.
| Paquet | Inscription de bureau | Inscription mobile |
|---|---|---|
@univerjs/docs-thread-comment-ui | UniverDocsThreadCommentUIPlugin | UniverDocsThreadCommentMobileUIPlugin |
@univerjs/thread-comment-ui | UniverThreadCommentUIPlugin | UniverThreadCommentMobileUIPlugin |
Mode preset
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-commentUtilisation
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(), ],})Facade des commentaires
Importez le commentaire partagé Facade et le produit Facade avant d'appeler ces méthodes. Les helpers de produit créent des ancres stables, et l'API partagée gère les réponses, les mises à jour, la résolution et la suppression. getComments() lit l'état local. listCommentsAsync() synchronise les threads déjà connus à travers la source de données configurée; il ne découvre pas tous les thread sur le serveur.
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.', })}Discussions partagées
Les discussions partagées exigent que le service de commentaires et le point d'arrivée soient connectés par Server SDK. Après la collaboration et la configuration de la licence, enregistrez UniverThreadCommentDataSourcePlugin depuis @univerjs-pro/thread-comment-datasource . La source de données fournie appelle /universer-api/comment/unit/{unitId}/... et /universer-api/user/list, de sorte que l'application doit exposer ces routes.
Commentaires sur les images et graphiques
Configurez d'abord les plugins de dessin ou de graphique de l'hôte, puis ajoutez l'intégration correspondante ci-dessous et son entrée Facade avant d'ouvrir l'unité. Le mode plugin et le mode préréglé exigent tous deux que ces intégrations soient enregistrées explicitement. Ils n'ajoutent ni styles ni localisations.
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)Une fois qu'une unité est ouverte, des commentaires peuvent être ajoutés aux images et aux graphiques qui existent déjà dans cette unité. getComments() retourne les threads chargés localement, et listCommentsAsync() synchronise les thread qu'il connaît avant de les renvoyer.
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
Que pensez-vous de ce guide ?