Skip to content
2 min

Examples

Run Collaboration SDK examples by capability and open each example's guide, Server entry point, and Web entry point.

All examples live in univer-collaboration-examples. They use the same minimal web/main.ts + server/main.ts shape and run independently. Complete Quick Start first, then choose another example based on your integration task.

ExampleMain conceptCommand
Quick StartCore collaboration pathpnpm example:quick-start
Database AdapterPersistence boundarypnpm example:database-adapter
PermissionsIdentity and authorizationpnpm example:permissions
HistoryDerived version historypnpm example:history
CommentsIndependent commentspnpm example:comments
WorktreeIsolated editing and mergepnpm example:worktree
ExchangeOffice file exchangepnpm example:exchange

Quick Start

Compose Collaboration Client, Transport, Endpoint, Service, and Memory Adapter. Use two browsers to verify HTTP loading, WebSocket Sessions, Room, ACK, and broadcast for the same Sheet.

Bash
pnpm example:quick-start

Open http://127.0.0.1:3010/?unit=quick-start-sheet&type=2.

Database Adapter

Compare custom Memory, PostgreSQL, and built-in SQLite Adapters. The implementations demonstrate transactions, revision CAS, batch atomicity, and the customData transaction boundary.

Bash
pnpm example:database-adapter

Open http://127.0.0.1:3010/?unit=database-adapter-sheet&type=2.

Permissions

Create trusted identity from a cookie and protect Unit HTTP reads, realtime JOIN, and changeset submission separately. The page switches between a teaching editor and read-only viewer.

Bash
pnpm example:permissions

Open http://127.0.0.1:3010.

History

Add History Service, a separate Adapter, History Endpoint, and the browser history entry outside Core. Unit creation and changeset commit Events build History as a reconstructable derived index.

Bash
pnpm example:history

Open http://127.0.0.1:3010/?unit=history-sheet&type=2, edit the Sheet, and select History at the top of the page.

Comments

Add Thread Comment Service, a separate Adapter, Comment Endpoint, and the frontend comment entry. The Comment Endpoint reuses the main collaboration Endpoint's Sessions and Unit Rooms.

Bash
pnpm example:comments

Open http://127.0.0.1:3010/?unit=comments-sheet&type=2, select a cell, and use the comment entry.

Worktree

Demonstrate the complete isolated draft, Ready, Reopen, and per-Unit Merge lifecycle. Switch between trunk and draft to see how Agent changes remain isolated before merge.

Bash
pnpm example:worktree

Open http://127.0.0.1:3010/?unit=worktree-sheet&type=2&worktree=demo-worktree.

Exchange

Compose @univerjs-pro/exchange-node with Collaboration Service for server-side Sheet import and export, task polling, snapshot import, and confirmed-revision export.

Bash
pnpm example:exchange

Open http://127.0.0.1:3010/?unit=exchange-sheet&type=2. Import through File → Open (File) and export through File → Save As.