Reference status
This page predates the current package split. Use the current package guides for checked installation, public imports, and onboarding examples. The detailed examples below have not all been revalidated.
@barocss/collaboration-yjs
@barocss/collaboration-yjs connects DataStore to Yjs (Y.Doc + provider) for CRDT-based realtime sync.
Components
YjsAdapter(extendsBaseAdapter)Y.DocandY.Map(default:ydoc.getMap('barocss-document'))- Provider:
y-websocketor custom
Quick Start
import { DataStore } from '@barocss/datastore';
import { YjsAdapter } from '@barocss/collaboration-yjs';
import * as Y from 'yjs';
import { WebsocketProvider } from 'y-websocket';
const ydoc = new Y.Doc();
const ymap = ydoc.getMap('barocss-document');
const provider = new WebsocketProvider('ws://localhost:1234', 'room-id', ydoc);
const adapter = new YjsAdapter({
ydoc,
ymap,
config: {
clientId: 'user-1',
user: { id: 'user-1', name: 'User 1', color: '#ff0000' },
debug: true,
},
});
const dataStore = new DataStore();
await adapter.connect(dataStore);
Adapter Options
ydoc: Y.Doc(required)ymap?: Y.Map<any>(optional, defaultydoc.getMap('barocss-document'))config?: AdapterConfig(see base collaboration)
Flow
Notes & Tips
- Use
provider.on('status')/provider.on('sync')for connection state. - Presence/awareness: use
y-protocols/awarenesswith the sameY.Doc. - Custom sync: you can skip
y-websocketand wire your own transport; just supplyydocand manage updates.
Troubleshooting
- Not syncing: check provider connection and
ymapname consistency. - Circular updates: adapter guards apply; ensure remote updates are identified by Yjs origin.
- State load: verify
ymapcontains initial document; callgetDocumentState()if needed.
@barocss/collaboration-yjs
Yjs adapter for Barocss Editor collaboration.
Purpose
Integrates Barocss Editor with Yjs CRDT library for real-time collaborative editing.
Key Exports
YjsAdapter- Yjs collaboration adapter
Basic Usage
import { Editor } from '@barocss/editor-core';
import { YjsAdapter } from '@barocss/collaboration-yjs';
import * as Y from 'yjs';
// Create Yjs document
const ydoc = new Y.Doc();
// Create adapter
const adapter = new YjsAdapter({
dataStore: editor.dataStore,
ydoc: ydoc
});
// Connect to Yjs provider (e.g., y-websocket)
const provider = new WebsocketProvider('ws://localhost:1234', 'room-name', ydoc);
Yjs Integration
The adapter:
- Converts Barocss operations to Yjs updates
- Converts Yjs updates to Barocss operations
- Handles Yjs document synchronization
- Manages conflict resolution
Related
- Collaboration - Base collaboration system
- Yjs Documentation - Yjs library documentation