# コメント

- Human documentation: [https://docs.univer.ai/ja-JP/guides/slides/features/comments](https://docs.univer.ai/ja-JP/guides/slides/features/comments)

- Agent Markdown: [https://docs.univer.ai/ja-JP/guides/slides/features/comments.md](https://docs.univer.ai/ja-JP/guides/slides/features/comments.md)

- Requested language: `ja-JP`

- Content language: `ja-JP`

- Documentation version: `1.2.0`

- Source: [slides/features/comments.ja-JP.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/slides/features/comments.ja-JP.mdx)

---

#### Package metadata

```json
{
  "mobile": true,
  "preset": [],
  "plugins": [
    {
      "client": "@univerjs/thread-comment",
      "facade": "@univerjs/thread-comment/facade"
    },
    {
      "client": "@univerjs/thread-comment-ui",
      "locale": "@univerjs/thread-comment-ui/locale/ja-JP",
      "style": "@univerjs/thread-comment-ui/lib/index.css"
    },
    {
      "client": "@univerjs-pro/slides-thread-comment",
      "facade": "@univerjs-pro/slides-thread-comment/facade"
    },
    {
      "client": "@univerjs-pro/slides-thread-comment-ui",
      "locale": "@univerjs-pro/slides-thread-comment-ui/locale/ja-JP",
      "style": "@univerjs-pro/slides-thread-comment-ui/lib/index.css"
    }
  ],
  "license": true,
  "server": "optional"
}
```

製品エディターとライセンスの設定後にコメントプラグインを登録し、共通 UI と製品 UI のスタイル・言語リソースを読み込みます。コメントリソースは製品プラグインが管理するため、スナップショットの復元前に登録してください。

#### npm

```bash
npm install @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-ui
```

#### pnpm

```bash
pnpm add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-ui
```

#### yarn

```bash
yarn add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-ui
```

#### bun

```bash
bun add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs-pro/slides-thread-comment @univerjs-pro/slides-thread-comment-ui
```

```ts
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/ja-JP'
import { LocaleType, mergeLocales } from '@univerjs/core'
import SharedLocale from '@univerjs/thread-comment-ui/locale/ja-JP'

import '@univerjs/thread-comment-ui/lib/index.css'
import '@univerjs-pro/slides-thread-comment-ui/lib/index.css'

univerAPI.loadLocales(LocaleType.JA_JP, mergeLocales(SharedLocale, ProductLocale))
univer.registerPlugin(UniverSlidesThreadCommentPlugin)
univer.registerPlugin(UniverSlidesThreadCommentUIPlugin)
```

## モバイル対応

まず[モバイルエディター](https://docs.univer.ai/ja-JP/guides/slides/getting-started/installation.md#mobile-support)を設定します。このページのプラグインモードの初期化コードで、以下のデスクトップ登録を同じパッケージのモバイル版に置き換え、**文書を開く前に**完了してください。モデル、スタイル、言語ファイル、Facade は維持し、両方を同時に登録しないでください。

| パッケージ                                    | デスクトップの登録                           | モバイルの登録                                   |
| ---------------------------------------- | ----------------------------------- | ----------------------------------------- |
| `@univerjs-pro/slides-thread-comment-ui` | `UniverSlidesThreadCommentUIPlugin` | `UniverSlidesThreadCommentMobileUIPlugin` |

## コメント Facade

共通のコメント Facade と製品 Facade を両方インポートします。製品のメソッドは安定したアンカーを作成し、共通 API は返信・更新・解決・削除を扱います。`getComments()` はローカル状態を読み取ります。`listCommentsAsync()` は設定済みデータソースを通じて既知のスレッドを同期し、サーバー上の全スレッドを検索するものではありません。

```ts
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())
}
```

```ts
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](https://docs.univer.ai/ja-JP/server/collaboration/extensions.md) で Comment Service と Endpoint を統合し、共同編集とライセンスの設定後に `@univerjs-pro/thread-comment-datasource` の `UniverThreadCommentDataSourcePlugin` を登録します。付属のデータソースは `/universer-api/comment/unit/{unitId}/...` と `/universer-api/user/list` を使います。アプリからこれらのルートを公開してください。サーバーは文書の編集権限とは別に、コメントの読み書きを認可する必要があります。
