|
| 1 | +# TipTap CRDT Demo |
| 2 | + |
| 3 | +> **[🚀 View Live Demo](https://sample-apps-tiptap-crdt-demo.vercel.app/)** |
| 4 | +
|
| 5 | + |
| 6 | +https://github.com/user-attachments/assets/ba757155-087d-4c1f-9d80-47b72d29ca9b |
| 7 | + |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +This demo showcases **real-time collaborative text editing** built using **TipTap** with **Velt's CRDT extension**. Multiple users can simultaneously edit content with automatic conflict resolution, ensuring a smooth collaborative writing experience. |
| 12 | + |
| 13 | +Velt's CRDT extension is based on Yjs. |
| 14 | + |
| 15 | +## Path |
| 16 | + |
| 17 | +``` |
| 18 | +apps/react/crdt/text-editors/tiptap/tiptap-crdt-demo/ |
| 19 | +``` |
| 20 | + |
| 21 | +## Package Name |
| 22 | + |
| 23 | +`@apps/react-crdt-text-editors-tiptap-tiptap-crdt-demo` |
| 24 | + |
| 25 | +## Features |
| 26 | + |
| 27 | +### Real-time Collaboration |
| 28 | +- **Live Co-editing**: Multiple users can simultaneously edit the document with Velt's CRDT synchronization |
| 29 | +- **Presence Awareness**: See who's currently viewing and editing the document |
| 30 | +- **Live Cursors**: See collaborators' cursor positions in real-time |
| 31 | +- **Notifications**: Stay updated on document activity |
| 32 | +- **Conflict Resolution**: Automatic CRDT-based conflict resolution for simultaneous edits |
| 33 | + |
| 34 | +### Editor Features |
| 35 | +- **Rich Text Editing**: Full-featured rich text editor powered by TipTap |
| 36 | +- **History**: Undo/redo functionality that respects collaborative changes |
| 37 | +- **Extensible**: Built on TipTap's powerful extension system |
| 38 | + |
| 39 | +## Directory Structure |
| 40 | + |
| 41 | +``` |
| 42 | +tiptap-crdt-demo/ |
| 43 | +├── app/ |
| 44 | +│ ├── api/ |
| 45 | +│ │ └── velt/ |
| 46 | +│ │ └── token/ |
| 47 | +│ │ └── route.ts # Velt JWT token generation endpoint |
| 48 | +│ ├── document/ |
| 49 | +│ │ ├── DocumentContext.tsx # Document context provider |
| 50 | +│ │ └── useCurrentDocument.ts # Document management hook |
| 51 | +│ ├── userAuth/ |
| 52 | +│ │ ├── AppUserContext.tsx # User authentication context |
| 53 | +│ │ ├── LoginPanel.tsx # User login panel component |
| 54 | +│ │ ├── useAppUser.ts # User authentication hook |
| 55 | +│ │ └── users.ts # Mock user data |
| 56 | +│ ├── layout.tsx # Root layout with Velt provider |
| 57 | +│ └── page.tsx # Main page |
| 58 | +├── components/ |
| 59 | +│ ├── header/ |
| 60 | +│ │ └── header.tsx # Header with Velt tools (presence, notifications) |
| 61 | +│ ├── sidebar/ |
| 62 | +│ │ └── sidebar.tsx # Left navigation sidebar |
| 63 | +│ ├── document/ |
| 64 | +│ │ ├── document-canvas.tsx # Main document wrapper |
| 65 | +│ │ └── TipTapComponent/ |
| 66 | +│ │ ├── TipTapComponent.tsx # Main TipTap editor with Velt CRDT |
| 67 | +│ │ ├── constants.ts # Editor configuration constants |
| 68 | +│ │ └── types.ts # TypeScript type definitions |
| 69 | +│ └── velt/ |
| 70 | +│ ├── ui-customization/ |
| 71 | +│ │ ├── VeltCustomization.tsx # Velt UI customization wrapper |
| 72 | +│ │ ├── VeltNotificationsToolWf.tsx # Custom notifications wireframe |
| 73 | +│ │ └── styles.css # Custom Velt styles |
| 74 | +│ ├── VeltCollaboration.tsx # Velt client setup and configuration |
| 75 | +│ ├── VeltInitializeDocument.tsx # Document initialization |
| 76 | +│ ├── VeltInitializeUser.tsx # User initialization |
| 77 | +│ └── VeltTools.tsx # Velt component exports |
| 78 | +├── hooks/ # Custom React hooks |
| 79 | +├── lib/ |
| 80 | +│ └── utils.ts # Utility functions |
| 81 | +├── public/ # Static assets |
| 82 | +├── styles/ |
| 83 | +│ └── globals.css # Global styles |
| 84 | +├── .npmrc # pnpm config to prevent Tailwind v4 hoisting |
| 85 | +├── next.config.js |
| 86 | +├── tailwind.config.js |
| 87 | +├── tsconfig.json |
| 88 | +├── components.json # shadcn/ui configuration |
| 89 | +└── package.json |
| 90 | +``` |
| 91 | + |
| 92 | +## Key Technologies |
| 93 | + |
| 94 | +- **Next.js 15** with React 19 |
| 95 | +- **TipTap 2.x** - Headless rich text editor |
| 96 | +- **@veltdev/tiptap-crdt** - Velt CRDT extension for TipTap |
| 97 | +- **@veltdev/react** - Velt collaboration components |
| 98 | +- **Yjs** - Underlying CRDT implementation |
| 99 | +- **Tailwind CSS v3.4** - Styling |
| 100 | +- **TypeScript** - Type safety |
| 101 | + |
| 102 | +## Getting Started |
| 103 | + |
| 104 | +### Install Dependencies |
| 105 | + |
| 106 | +From the monorepo root: |
| 107 | + |
| 108 | +```bash |
| 109 | +pnpm install |
| 110 | +``` |
| 111 | + |
| 112 | +### Run Development Server |
| 113 | + |
| 114 | +Navigate to the demo directory: |
| 115 | + |
| 116 | +```bash |
| 117 | +cd apps/react/crdt/text-editors/tiptap/tiptap-crdt-demo |
| 118 | +pnpm dev |
| 119 | +``` |
| 120 | + |
| 121 | +Or run from the root: |
| 122 | + |
| 123 | +```bash |
| 124 | +pnpm --filter @apps/react-crdt-text-editors-tiptap-tiptap-crdt-demo dev |
| 125 | +``` |
| 126 | + |
| 127 | +Open [http://localhost:3000](http://localhost:3000) in your browser. |
| 128 | + |
| 129 | +### Build for Production |
| 130 | + |
| 131 | +```bash |
| 132 | +pnpm --filter @apps/react-crdt-text-editors-tiptap-tiptap-crdt-demo build |
| 133 | +``` |
| 134 | + |
| 135 | +## Usage |
| 136 | + |
| 137 | +### Basic Editing |
| 138 | + |
| 139 | +1. **Type content**: Click into the editor and start writing |
| 140 | +2. **See collaborators**: View other users' cursors in real-time |
| 141 | +3. **Edit simultaneously**: Multiple users can type in different parts of the document |
| 142 | + |
| 143 | +### Collaborative Features |
| 144 | + |
| 145 | +1. **Join session**: Open the same document in multiple browsers |
| 146 | +2. **Switch users**: Use the login panel to switch between test users |
| 147 | +3. **See active users**: View avatars of online collaborators in the header |
| 148 | +4. **Live cursors**: See where other users are typing in real-time |
| 149 | +5. **Simultaneous edits**: Type in different parts of the document simultaneously |
| 150 | + |
| 151 | +### Collaboration Features |
| 152 | + |
| 153 | +- **See active users**: View avatars of online collaborators in the header |
| 154 | +- **Receive notifications**: Bell icon shows document activity |
| 155 | +- **Real-time updates**: All edits appear instantly for all users |
| 156 | + |
| 157 | +## Troubleshooting |
| 158 | + |
| 159 | +### PostCSS Errors |
| 160 | +If you see PostCSS/Tailwind errors, ensure: |
| 161 | +1. The `.npmrc` file exists in this directory |
| 162 | +2. You ran `pnpm install` from the monorepo root |
| 163 | +3. You're not accidentally using Tailwind v4 |
| 164 | + |
| 165 | +### Velt Not Loading |
| 166 | +If Velt features don't appear: |
| 167 | +1. Check that `NEXT_PUBLIC_VELT_API_KEY` is set in your environment |
| 168 | +2. Verify user initialization in browser console |
| 169 | +3. Ensure you're running the dev server on the correct port |
| 170 | + |
| 171 | +### CRDT Sync Issues |
| 172 | +If changes aren't syncing: |
| 173 | +1. Check browser console for WebSocket errors |
| 174 | +2. Verify the `editorId` is unique for your document |
| 175 | +3. Ensure multiple users are on the same document ID |
| 176 | +4. Test with two unique users on two different browser profiles (e.g., Chrome regular + Chrome incognito, or different browsers) |
| 177 | + |
| 178 | +### Editor Not Loading |
| 179 | +If the editor doesn't appear: |
| 180 | +1. Check that TipTap extensions are loaded correctly |
| 181 | +2. Verify collaboration config is available before editor initialization |
| 182 | +3. Ensure `isLoading` is false before rendering editor |
| 183 | +4. Check browser console for TipTap errors |
| 184 | + |
| 185 | +## About Velt SDK |
| 186 | + |
| 187 | +<a href="https://npmjs.org/package/@veltdev/react"> |
| 188 | + <img src="https://img.shields.io/npm/v/@veltdev/react?style=flat&label=npm&color=09f" alt="NPM" /> |
| 189 | +</a> |
| 190 | + |
| 191 | +With Velt SDK you can add powerful collaboration features to your product extremely fast. |
| 192 | + |
| 193 | +The SDK provides **fullstack components**: |
| 194 | +- UI and behavior are fully customizable to match your product's needs |
| 195 | +- Fully-managed on a scalable realtime backend |
| 196 | + |
| 197 | +**Features include:** |
| 198 | +- **Comments** like Figma, Frame.io, Google Docs, Sheets and more |
| 199 | +- **Recording** like Loom (audio, video, screen) |
| 200 | +- **Huddle** like Slack (audio, video, screensharing) |
| 201 | +- In-app and off-app **notifications** |
| 202 | +- **@mentions** and assignment |
| 203 | +- **Presence**, **Cursors**, **Live Selection** |
| 204 | +- **Live state sync** with Single Editor mode |
| 205 | +- **Multiplayer editing** with conflict resolution |
| 206 | +- **Follow mode** like Figma |
| 207 | +- ... and so much more |
| 208 | + |
| 209 | +### Resources |
| 210 | +- 📚 [Documentation](https://docs.velt.dev/get-started/overview) - Guides and API references |
| 211 | +- 🎨 [Use Cases](https://velt.dev/use-case) - See collaboration in action |
| 212 | +- 🎭 [Figma Template](https://www.figma.com/community/file/1402312407969730816/velt-collaboration-kit) - Visualize features for your product |
| 213 | +- 📝 [Release Notes](https://docs.velt.dev/release-notes/version-4/sdk-changelog) - Latest changes |
| 214 | +- 🔒 [Security](https://velt.dev/security) - SOC2 Type 2 & HIPAA compliant |
| 215 | +- 🐦 [X/Twitter](https://x.com/veltjs) - Updates and announcements |
| 216 | + |
| 217 | +## Important Configuration |
| 218 | + |
| 219 | +### .npmrc File |
| 220 | + |
| 221 | +This demo includes a `.npmrc` file that prevents pnpm from hoisting Tailwind CSS v4 from other workspace packages: |
| 222 | + |
| 223 | +``` |
| 224 | +public-hoist-pattern[]=* |
| 225 | +public-hoist-pattern[]=!@tailwindcss* |
| 226 | +``` |
| 227 | + |
| 228 | +**Why this matters**: |
| 229 | +- This demo uses Tailwind CSS v3.4.x with traditional PostCSS configuration |
| 230 | +- Other apps in the monorepo may use Tailwind CSS v4 |
| 231 | +- Without the `.npmrc`, pnpm would hoist v4 and cause PostCSS build errors |
| 232 | + |
| 233 | +**Do not delete the `.npmrc` file** - it ensures the correct Tailwind version is used. |
| 234 | + |
0 commit comments