# コメント

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

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

- Requested language: `ja-JP`

- Content language: `ja-JP`

- Documentation version: `1.1.0`

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

---

#### Package metadata

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

コメント機能を使うと、ドキュメント内にコメントや返信を追加でき、チーム内のコミュニケーションやコラボレーションを円滑にします。

## プラグインモード

### インストール

#### npm

```bash
npm install @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs/docs-thread-comment @univerjs/docs-thread-comment-ui
```

#### pnpm

```bash
pnpm add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs/docs-thread-comment @univerjs/docs-thread-comment-ui
```

#### yarn

```bash
yarn add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs/docs-thread-comment @univerjs/docs-thread-comment-ui
```

#### bun

```bash
bun add @univerjs/thread-comment @univerjs/thread-comment-ui @univerjs/docs-thread-comment @univerjs/docs-thread-comment-ui
```

### 使い方

```typescript
import { LocaleType, mergeLocales, Univer } from '@univerjs/core'
import { UniverDocsThreadCommentPlugin } from '@univerjs/docs-thread-comment' // [!code ++]
import { UniverDocsThreadCommentUIPlugin } from '@univerjs/docs-thread-comment-ui' // [!code ++]
import { UniverThreadCommentPlugin } from '@univerjs/thread-comment' // [!code ++]
import { UniverThreadCommentUIPlugin } from '@univerjs/thread-comment-ui' // [!code ++]
import DocsCommentLocale from '@univerjs/docs-thread-comment-ui/locale/ja-JP'
import ThreadCommentUIJaJP from '@univerjs/thread-comment-ui/locale/ja-JP' // [!code ++]

import '@univerjs/docs-thread-comment/facade' // [!code ++]
import '@univerjs/docs-thread-comment-ui/lib/index.css'
import '@univerjs/thread-comment-ui/lib/index.css' // [!code ++]

const univer = new Univer({
  locale: LocaleType.JA_JP,
  locales: {
    [LocaleType.JA_JP]: mergeLocales(
      ThreadCommentUIJaJP,
      DocsCommentLocale, // [!code ++]
    ),
  },
})

univer.registerPlugin(UniverThreadCommentPlugin) // [!code ++]
univer.registerPlugin(UniverThreadCommentUIPlugin) // [!code ++]
univer.registerPlugin(UniverDocsThreadCommentPlugin) // [!code ++]
univer.registerPlugin(UniverDocsThreadCommentUIPlugin) // [!code ++]
```

#### 共同編集機能と併用する場合

[共同編集](https://docs.univer.ai/ja-JP/guides/docs/features/collaboration.md) 機能を使う場合は、次のように設定します。

#### npm

```bash
npm install @univerjs-pro/thread-comment-datasource
```

#### pnpm

```bash
pnpm add @univerjs-pro/thread-comment-datasource
```

#### yarn

```bash
yarn add @univerjs-pro/thread-comment-datasource
```

#### bun

```bash
bun add @univerjs-pro/thread-comment-datasource
```

```typescript
import { UniverThreadCommentDataSourcePlugin } from '@univerjs-pro/thread-comment-datasource' // [!code ++]

univer.registerPlugin(UniverThreadCommentDataSourcePlugin) // [!code ++]
```

## モバイル対応

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

| パッケージ                              | デスクトップの登録                         | モバイルの登録                                 |
| ---------------------------------- | --------------------------------- | --------------------------------------- |
| `@univerjs/docs-thread-comment-ui` | `UniverDocsThreadCommentUIPlugin` | `UniverDocsThreadCommentMobileUIPlugin` |
| `@univerjs/thread-comment-ui`      | `UniverThreadCommentUIPlugin`     | `UniverThreadCommentMobileUIPlugin`     |

## プリセットモード

### インストール

#### npm

```bash
npm install @univerjs/preset-docs-thread-comment
```

#### pnpm

```bash
pnpm add @univerjs/preset-docs-thread-comment
```

#### yarn

```bash
yarn add @univerjs/preset-docs-thread-comment
```

#### bun

```bash
bun add @univerjs/preset-docs-thread-comment
```

### 使い方

```typescript
import { UniverDocsCorePreset } from '@univerjs/preset-docs-core'
import UniverPresetDocsCoreJaJP from '@univerjs/preset-docs-core/locales/ja-JP'
import { UniverDocsThreadCommentPreset } from '@univerjs/preset-docs-thread-comment' // [!code ++]
import UniverPresetDocsThreadCommentJaJP from '@univerjs/preset-docs-thread-comment/locales/ja-JP' // [!code ++]
import { createUniver, LocaleType, mergeLocales } from '@univerjs/presets'

import '@univerjs/preset-docs-core/lib/index.css'
import '@univerjs/preset-docs-thread-comment/lib/index.css' // [!code ++]

const { univerAPI } = createUniver({
  locale: LocaleType.JA_JP,
  locales: {
    [LocaleType.JA_JP]: mergeLocales(
      UniverPresetDocsCoreJaJP,
      UniverPresetDocsThreadCommentJaJP, // [!code ++]
    ),
  },
  presets: [
    UniverDocsCorePreset(),
    UniverDocsThreadCommentPreset(), // [!code ++]
  ],
})
```

## コメント Facade

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

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

```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` を使います。アプリからこれらのルートを公開してください。サーバーは文書の編集権限とは別に、コメントの読み書きを認可する必要があります。
