# 편집 기록

- Human documentation: [https://docs.univer.ai/ko-KR/guides/sheets/features/edit-history](https://docs.univer.ai/ko-KR/guides/sheets/features/edit-history)

- Agent Markdown: [https://docs.univer.ai/ko-KR/guides/sheets/features/edit-history.md](https://docs.univer.ai/ko-KR/guides/sheets/features/edit-history.md)

- Requested language: `ko-KR`

- Content language: `ko-KR`

- Documentation version: `1.0.4`

- Source: [sheets/features/edit-history.ko-KR.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/sheets/features/edit-history.ko-KR.mdx)

---

#### Package metadata

```json
{
  "mobile": true,
  "preset": [
    {
      "client": "@univerjs/preset-sheets-collaboration",
      "locale": "@univerjs/preset-sheets-collaboration/locales/ko-KR",
      "style": "@univerjs/preset-sheets-collaboration/lib/index.css"
    }
  ],
  "plugins": [
    {
      "client": "@univerjs-pro/edit-history",
      "facade": "@univerjs-pro/edit-history/facade"
    },
    {
      "client": "@univerjs-pro/edit-history-ui",
      "locale": "@univerjs-pro/edit-history-ui/locale/ko-KR",
      "style": "@univerjs-pro/edit-history-ui/lib/index.css"
    },
    {
      "client": "@univerjs-pro/sheets-history"
    },
    {
      "client": "@univerjs-pro/sheets-history-ui",
      "locale": "@univerjs-pro/sheets-history-ui/locale/ko-KR",
      "style": "@univerjs-pro/sheets-history-ui/lib/index.css"
    }
  ],
  "license": true,
  "server": true
}
```

이전 버전을 열어 변경 내용을 비교하고, 권한이 있으면 복원할 수 있습니다. 기록을 영구 저장하려면 Server SDK로 기록 서비스를 통합해야 합니다. 현재 편집 세션의 실행 취소와 다시 실행에는 기록 서비스가 필요하지 않습니다.

## 협업 및 기록 서비스 준비

[협업 통합](https://docs.univer.ai/ko-KR/server/collaboration/browser-integration.md)과 [라이선스 설정](https://docs.univer.ai/ko-KR/server/license.md)을 완료한 뒤, [확장 모듈](https://docs.univer.ai/ko-KR/server/collaboration/extensions.md)과 [History 예제](https://docs.univer.ai/ko-KR/server/collaboration/examples.md#history)에 따라 기록 저장소와 권한을 연결합니다. 기본 협업만으로 기록이 활성화되지는 않습니다.

## 기록 플러그인 등록

기존 Sheets 및 협업 설정에 추가합니다. 협업 preset이 이미 등록한 플러그인은 다시 등록하지 말고 기존 설정을 변경하세요. Sheets 기록 UI에는 `UniverCollaborationClientUIPlugin`도 필요합니다.

#### npm

```bash
npm install @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/sheets-history @univerjs-pro/sheets-history-ui
```

#### pnpm

```bash
pnpm add @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/sheets-history @univerjs-pro/sheets-history-ui
```

#### yarn

```bash
yarn add @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/sheets-history @univerjs-pro/sheets-history-ui
```

#### bun

```bash
bun add @univerjs-pro/edit-history @univerjs-pro/edit-history-ui @univerjs-pro/sheets-history @univerjs-pro/sheets-history-ui
```

```ts
import { UniverEditHistoryPlugin } from '@univerjs-pro/edit-history'
import EditHistoryLocale from '@univerjs-pro/edit-history-ui/locale/en-US'
import { UniverSheetsHistoryPlugin } from '@univerjs-pro/sheets-history'
import { UniverSheetsHistoryUIPlugin } from '@univerjs-pro/sheets-history-ui'
import HistoryLocale from '@univerjs-pro/sheets-history-ui/locale/en-US'
import { LocaleType, mergeLocales } from '@univerjs/core'

import '@univerjs-pro/edit-history-ui/lib/index.css'
import '@univerjs-pro/sheets-history-ui/lib/index.css'

const historyServerUrl = '/api/history'

univerAPI.loadLocales(LocaleType.EN_US, mergeLocales(EditHistoryLocale, HistoryLocale))
univer.registerPlugin(UniverEditHistoryPlugin, { historyServerUrl })
univer.registerPlugin(UniverSheetsHistoryPlugin)
univer.registerPlugin(UniverSheetsHistoryUIPlugin, {
  univerContainerId: 'app',
  historyServerUrl,
})
```

`/api/history`를 애플리케이션 기록 서비스의 접두 경로로 바꾸고 두 `historyServerUrl` 값을 일치시키세요. `univerContainerId`에는 편집기 컨테이너의 DOM ID를 지정합니다. 언어 리소스는 편집기 언어와 일치해야 합니다.

## 모바일 지원

먼저 [모바일 에디터](https://docs.univer.ai/ko-KR/guides/sheets/getting-started/installation.md#mobile-support)를 구성하세요. 이 페이지의 플러그인 모드 초기화 코드에서 아래 데스크톱 등록을 같은 패키지의 모바일 버전으로 바꾸고 **문서를 열기 전에** 완료하세요. 모델 플러그인, 스타일, 언어 파일과 Facade 가져오기는 유지하며 두 버전을 동시에 등록하지 마세요.

| 패키지                               | 데스크톱 등록                       | 모바일 등록                              |
| --------------------------------- | ----------------------------- | ----------------------------------- |
| `@univerjs-pro/sheets-history-ui` | `UniverSheetsHistoryUIPlugin` | `UniverSheetsHistoryMobileUIPlugin` |

## 버전 확인 및 복원

셀, 수식 또는 서식을 편집한 다음 협업 확인을 기다리고 편집기 메뉴에서 기록을 엽니다. 버전 목록과 차이를 확인하고 서비스를 재시작해도 기록이 유지되는지 검사하세요. 복원은 공유 문서를 변경하므로 서버에서 복원 권한을 검증하고 다른 협업 세션에도 변경이 전달되는지 확인해야 합니다.

## 스냅샷 비교

검토 화면을 만들거나 AI Agent에 변경 정보를 제공하려면 `compareUnitData()`를 사용하세요. `prepareUnitComparison()`으로 한 번 계산한 결과를 반복 조회할 수도 있습니다. 제품의 History 플러그인을 등록하고 Facade 진입점을 가져온 뒤, 같은 문서의 완전한 두 스냅샷을 `beforeSnapshot`과 `afterSnapshot`으로 전달합니다. 읽기 전용 비교에는 기록 서비스가 필요하지 않으며 내용을 복원하거나 병합하지 않습니다.

```ts
import { UnitComparisonDetailLevel, UnitComparisonFidelity } from '@univerjs-pro/edit-history'
import { UniverInstanceType } from '@univerjs/core'

import '@univerjs-pro/edit-history/facade'

const comparison = univerAPI.prepareUnitComparison({
  comparisonId: 'review-1',
  unitId: beforeSnapshot.id,
  type: UniverInstanceType.UNIVER_SHEET,
  fidelity: UnitComparisonFidelity.SNAPSHOT,
  leftData: beforeSnapshot,
  rightData: afterSnapshot,
})
const overview = comparison.query({ detail: UnitComparisonDetailLevel.SUMMARY })
const scope = overview.scopes[0]
const page = comparison.query({ scope, offset: 0, limit: 100 })
console.log(page.items, page.page.hasMore, page.diagnostics)
```

`scopes`에서 사용 가능한 뷰를 찾고 선택한 범위를 `query()`에 전달하면 다시 계산하지 않고 결과를 필터링할 수 있습니다. 기본값은 100개이며 페이지당 최대 1,000개입니다. `page.hasMore`와 `offset`으로 다음 항목을 가져오세요. `summary`는 필터와 관계없이 전체 비교를 나타냅니다. `diagnostics.readiness`와 `diagnostics.codes`를 확인해 정확도가 저하된 결과를 완전한 비교로 취급하지 마세요. 편집기가 없는 Node.js 또는 CLI에서는 [헤드리스 비교 API](https://docs.univer.ai/ko-KR/reference/packages/plugins/univerjs-pro/edit-history.md#headless-comparison)를 사용하세요.
