How it works with Filament
You do not need this page to use the package. It explains, in plain words, how the browser script works with Filament, why the package has its own merge engine instead of Yjs, and which parts would work without Filament.
The browser script and Filament
The package does not replace Filament's fields. Its script, collaboration.js, runs beside them and listens.
- The page says it is collaborative. The
InteractsWithCollaborationtrait renders a small hidden element through a Filament render hook. It carries an encrypted token, the sync URL and the list of live fields. The script, registered as a normal Filament asset, finds the element and attaches to the page's Livewire component. - Each field gets an adapter. An adapter knows how to read and write one kind of field. A text input is read from the browser's
inputevent. Filament'sRichEditoris TipTap (ProseMirror) inside an Alpine component, so its adapter takes the editor from Alpine withgetEditor(). Selects, toggles, dates, repeaters, uploads, and the Markdown and code editors have adapters too, through the sameFilamentCollaboration.adapter()that other editors use. - Your typing becomes small operations. The adapter compares the field with the shared draft, and only what changed becomes operations, such as "insert ing after this character". They are applied to your copy at once.
- Typing goes to the package's own endpoint, not through Livewire. Every 0.4 seconds, or at once with Reverb, the browser sends its operations to
{panel}/_collaboration/sync. Laravel checks the user and the policy again, validates every operation, stores it in the shared draft and answers with what this browser is missing. - Colleagues' changes go into the field, and into Livewire. The adapter writes them into the field with your caret kept in place, and the script tells Livewire the new value with
queueUpdate, so the form state is right without a Livewire request per keystroke. - Save is still Filament's Save. The trait's
save()takes a lock, takes the shared draft with everybody's typing, merges the fields that cannot be live, then calls Filament's own save. Validation, hooks and notifications run as usual.
Why not Yjs
Both Yjs and this package's engine are CRDTs: a way to merge edits made at the same time so that every copy ends up the same. The package started on Yjs and replaced it with its own engine.
| Yjs | This package | |
|---|---|---|
| What it is | A mature, widely used JavaScript library | A small engine written for this package, in both PHP and JavaScript |
| Who orders the edits | Nobody: copies merge in any order, even peer to peer | Laravel: each edit is applied under a database row lock |
| Can Laravel read the document? | Not easily: Yjs has its own binary format, with no mature PHP version, so it usually needs a Node server such as y-websocket or Hocuspocus | Yes: PHP reads and changes the draft itself, so it checks every operation before anybody else sees it |
| Server to run | A separate Node WebSocket server | Your Laravel app, over HTTP polling or Laravel Reverb |
| Permissions per field | Hard: the whole document goes to every client | Built in: fields a person cannot see never reach their browser |
| Saving to the model | Your own code turns the document back into form data | Built in: Save publishes the draft through Filament's save |
| Editor bindings | Many ready-made ones | Adapters for Filament's fields, and examples for TinyMCE, CKEditor, Quill and Trix |
| Data format | Compact binary, highly optimised | JSON, easy to read and debug; old history is compacted once a draft is saved and nobody is editing |
| Maturity | Years of production use | New, tested with sessions replayed in PHP and JavaScript, 2,000 random four-person sessions that must converge, and chaos and load tests |
Yjs suits apps where browsers sync directly, or through a Node server that never needs to understand the content. A Filament form needs the server to understand it: to check permissions per field, validate HTML and save through Filament. An engine that also runs in PHP keeps Laravel in charge, with no Node server to run. The price is that it is younger than Yjs and does less: only what forms need, which is text, rich text, picked values and lists. Architecture explains how it works.
Without Filament
Not as it ships: the package is a Filament plugin. Some of its parts do not depend on Filament at all, though.
- The merge engine needs nothing.
resources/js/crdtimports no library and no browser API, so it runs in any browser or in Node, andsrc/Crdtis plain PHP. - The room and the adapter API need Livewire and Alpine. They start only when both are on the page, read and write the form through the Livewire component, and save through it.
- The server side needs Filament. The sync endpoint is a panel route, the token is issued by a Filament page, access is checked with the resource's
canEdit()andcanView(), and saving goes through Filament'sEditRecord.
Using it with plain Livewire, Inertia or another framework would mean a new server endpoint and a new way to read and save the form. The merge engine and the adapters could be reused as they are.