Skip to content

Commit 5ff9d3a

Browse files
committed
Merge branch 'main' of github.com:velt-js/sample-apps
2 parents 6fde718 + 25bfad8 commit 5ff9d3a

File tree

147 files changed

+19605
-6179
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+19605
-6179
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# CodeMirror CRDT Demo (Vanilla JavaScript)
2+
3+
Real-time collaborative code editing built with CodeMirror 6 and Velt CRDT extension.
4+
5+
## What Changed
6+
7+
This demo was converted from React/Next.js to **vanilla JavaScript** with Vite:
8+
9+
- **Removed**: React, Next.js, @veltdev/react, @veltdev/codemirror-crdt-react
10+
- **Added**: @veltdev/client, @veltdev/codemirror-crdt (non-React versions)
11+
- **Bundler**: Vite instead of Next.js
12+
- **UI**: Same layout and styling, implemented with vanilla JS DOM manipulation
13+
14+
## Features
15+
16+
- Real-time collaborative code editing
17+
- Live cursors and presence awareness
18+
- CRDT-based conflict resolution (Yjs)
19+
- Velt collaboration tools (presence, comments, notifications)
20+
21+
## Directory Structure
22+
23+
```
24+
codemirror-crdt-demo/
25+
├── src/
26+
│ ├── main.js # Entry point
27+
│ ├── lib/
28+
│ │ ├── user.js # User management
29+
│ │ ├── document.js # Document ID management
30+
│ │ └── velt.js # Velt client initialization
31+
│ ├── components/
32+
│ │ ├── sidebar.js # Left sidebar component
33+
│ │ ├── header.js # Header with Velt tools
34+
│ │ ├── document-canvas.js # Main layout
35+
│ │ └── codemirror.js # CodeMirror with CRDT
36+
│ └── styles/
37+
│ └── velt-customization.css # Velt theme variables
38+
├── styles/
39+
│ ├── globals.css # Global styles (Tailwind)
40+
│ └── codemirror.css # Editor styles
41+
├── public/ # Static assets
42+
├── index.html # HTML entry
43+
├── vite.config.js # Vite configuration
44+
├── tailwind.config.js # Tailwind configuration
45+
├── postcss.config.js # PostCSS configuration
46+
└── package.json
47+
```
48+
49+
## Getting Started
50+
51+
### Install Dependencies
52+
53+
```bash
54+
pnpm install
55+
```
56+
57+
### Run Development Server
58+
59+
```bash
60+
pnpm dev
61+
```
62+
63+
Open http://localhost:3000 in your browser.
64+
65+
### Build for Production
66+
67+
```bash
68+
pnpm build
69+
pnpm preview
70+
```
71+
72+
## Testing Collaboration
73+
74+
1. Open the demo in two browser tabs (or different browsers)
75+
2. Both tabs will automatically get unique users
76+
3. Edit code in one tab and see changes appear in the other
77+
4. Observe live cursors showing other users' positions
78+
79+
## Key Technologies
80+
81+
- **Vite** - Build tool
82+
- **CodeMirror 6** - Code editor
83+
- **@veltdev/client** - Velt SDK (vanilla JS)
84+
- **@veltdev/codemirror-crdt** - CRDT extension for CodeMirror
85+
- **y-codemirror.next** - Yjs binding for CodeMirror
86+
- **Tailwind CSS v3.4** - Styling
87+
88+
## Velt Integration
89+
90+
The demo uses these Velt features:
91+
92+
1. **@veltdev/client** for initialization:
93+
```js
94+
import { initVelt } from '@veltdev/client';
95+
const client = await initVelt('YOUR_API_KEY');
96+
await client.identify(user);
97+
await client.setDocument(documentId);
98+
```
99+
100+
2. **@veltdev/codemirror-crdt** for collaborative editing:
101+
```js
102+
import { createVeltCodeMirrorStore } from '@veltdev/codemirror-crdt';
103+
const store = await createVeltCodeMirrorStore({
104+
editorId: 'editor-1',
105+
veltClient: client,
106+
initialContent: '...',
107+
});
108+
```
109+
110+
3. **Velt web components** for collaboration UI:
111+
```html
112+
<velt-presence></velt-presence>
113+
<velt-comments></velt-comments>
114+
<velt-notifications-tool></velt-notifications-tool>
115+
```
116+
117+
## Troubleshooting
118+
119+
### Editor Not Loading
120+
- Check browser console for errors
121+
- Verify Velt client initialization succeeded
122+
- Ensure document ID is set before creating the editor
123+
124+
### Collaboration Not Working
125+
- Open in two different browser profiles (not just tabs)
126+
- Check that both sessions have the same document ID
127+
- Verify user authentication completed
128+
129+
### Styles Not Applied
130+
- Run `pnpm install` to ensure Tailwind is installed
131+
- Check that CSS files are imported in main.js
132+
133+
## Resources
134+
135+
- [Velt Documentation](https://docs.velt.dev)
136+
- [CodeMirror Documentation](https://codemirror.net/)
137+
- [Velt CodeMirror CRDT Guide](https://docs.velt.dev/realtime-collaboration/crdt/setup/codemirror)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
<title>CodeMirror CRDT Demo</title>
7+
<meta name="description" content="CodeMirror demo for CRDT collaborative editing" />
8+
<link rel="preconnect" href="https://fonts.googleapis.com" />
9+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
10+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Urbanist:wght@400;500;600;700&family=Poppins:wght@400;500;600;700&display=swap" rel="stylesheet" />
11+
</head>
12+
<body>
13+
<div id="app"></div>
14+
<script type="module" src="/src/main.js"></script>
15+
</body>
16+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"name": "@apps/vanilla-js-CRDT-text-editors-codemirror-codemirror-crdt-demo",
3+
"version": "0.1.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"dev": "vite",
8+
"build": "vite build",
9+
"preview": "vite preview",
10+
"serve": "vite preview"
11+
},
12+
"dependencies": {
13+
"@codemirror/lang-css": "^6",
14+
"@codemirror/lang-html": "^6",
15+
"@codemirror/lang-javascript": "^6",
16+
"@codemirror/state": "^6",
17+
"@codemirror/theme-one-dark": "^6",
18+
"@veltdev/client": "^4.6.10",
19+
"@veltdev/codemirror-crdt": "4.5.8",
20+
"@veltdev/types": "^4.6.10",
21+
"codemirror": "^6",
22+
"y-codemirror.next": "^0.3.5",
23+
"yjs": "^13.6.18"
24+
},
25+
"devDependencies": {
26+
"@types/node": "^22",
27+
"autoprefixer": "^10",
28+
"postcss": "^8",
29+
"tailwindcss": "^3.4.0",
30+
"typescript": "^5",
31+
"vite": "^5.4.0"
32+
}
33+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
plugins: {
3+
tailwindcss: {},
4+
autoprefixer: {},
5+
},
6+
}

apps/javascript/crdt/text-editors/codemirror/codemirror-crdt-demo/public/.gitkeep

Whitespace-only changes.
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)