Live collaboration with Yjs over ActionCable

All editors now work on a server document at the same time instead of
taking turns behind an edit lock.

- The document's content is a sequence of Yjs updates (document_updates);
  DocumentChannel stores and relays them immediately, checks access on
  subscribe and again whenever links or memberships change.
- app/frontend/collab/: the store stays position-based; a binding maps it
  to a Yjs form with stable row/column ids, so a row inserted by one
  person doesn't misplace what another is typing. Remote changes are
  applied only after pending local ones went into Yjs.
- Per-person undo (Y.UndoManager), presence via awareness: the others'
  selections as coloured boxes with names, avatars in the toolbar.
- Existing JSON documents convert on first open, deterministically, so
  two people opening one at once end up with the same Yjs state.
- Editors compact the stored updates after 200 and keep a JSON snapshot
  current for export and duplicating. Edit lock and polling are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
wkh
2026-09-28 20:41:02 +02:00
co-authored by Claude Opus 5.5
parent e14bada114
commit 7fce972fdc
27 changed files with 1685 additions and 413 deletions
+6 -4
View File
@@ -621,17 +621,19 @@ wie jede andere Änderung verteilt. Viewer können keine Makros starten.
---
## Umsetzungsstand (Branch `with-server`, 2026-09-28)
## Umsetzungsstand (Branch `with-server`, 2026-09-29)
Umgesetzt sind Phasen 1–3 in angepasster Form; Live-Sync (Phase 4) fehlt noch.
Umgesetzt sind Phasen 1–4 in angepasster Form, einschließlich Live-Bearbeitung mit Yjs.
| Thema | Umsetzung | Abweichung vom Konzept |
| --- | --- | --- |
| Anonym | Dokumente bleiben lokal in IndexedDB (`/?doc=<id>`) | kein Gast-Konto auf dem Server |
| Konto | Magic Link + 6-stelliger Code, Konto entsteht bei der ersten Anmeldung | – |
| Übernahme | nach der ersten Anmeldung Rückfrage, welche lokalen Dokumente hochgeladen werden; hochgeladene werden lokal entfernt | statt automatischer Übernahme |
| Server-Dokumente | JSON-Inhalt mit Versionsnummer, `/d/<id>`; mit Konto werden neue Dokumente auf dem Server angelegt | Inhalt noch nicht als Yjs-Stand |
| Gleichzeitiges Bearbeiten | Sperre pro Browser-Tab (90 s ohne Heartbeat), andere sehen „Nur Lesen“ und folgen per Abfrage alle 10 s | Übergang bis Phase 4 |
| Server-Dokumente | Inhalt = Yjs-Updates (`document_updates`), `documents.content` als JSON-Snapshot (Export, Duplizieren, erste Umwandlung); `/d/<id>` | – |
| Gleichzeitiges Bearbeiten | live über ActionCable (`DocumentChannel`), ~150 ms; feste Zeilen-/Spalten-IDs; Undo pro Person (`Y.UndoManager`); Auswahl der anderen als farbiger Rahmen | Store bleibt positionsbasiert, eine Binding-Schicht übersetzt (`app/frontend/collab/`) |
| Erste Umwandlung | JSON → Yjs deterministisch im Browser (feste Client-ID, IDs `r0…`/`c0…`), gleichzeitige Umwandlungen verschmelzen | statt serverseitig |
| Zusammenfassen | ab 200 Updates schickt ein Editor den Gesamtstand, der Server ersetzt die gelisteten Updates | clientseitig, kein `y-rb` nötig |
| Teilen per Link | ohne Konto nutzbar; Token im Browser gespeichert (localStorage), nach Anmeldung dem Konto zugeordnet | Link-Token im Klartext gespeichert, damit der Besitzer den Link erneut kopieren kann |
| Einladungen | Mail mit Link (7 Tage gültig), meldet gleichzeitig an | – |
| Sessions | signierte Session-ID im Cookie (Rails-8-Standard) | statt Token-Digest |