Skip to content

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 layers of the browser script, from Filament's fields down to Laravel.The layers of the browser script, from Filament's fields down to Laravel.
  1. The page says it is collaborative. The InteractsWithCollaboration trait 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.
  2. 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 input event. Filament's RichEditor is TipTap (ProseMirror) inside an Alpine component, so its adapter takes the editor from Alpine with getEditor(). Selects, toggles, dates, repeaters, uploads, and the Markdown and code editors have adapters too, through the same FilamentCollaboration.adapter() that other editors use.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
One keystroke, from Alice's field to Bob's, through Laravel.One keystroke, from Alice's field to Bob's, through Laravel.

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.

YjsThis package
What it isA mature, widely used JavaScript libraryA small engine written for this package, in both PHP and JavaScript
Who orders the editsNobody: copies merge in any order, even peer to peerLaravel: 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 HocuspocusYes: PHP reads and changes the draft itself, so it checks every operation before anybody else sees it
Server to runA separate Node WebSocket serverYour Laravel app, over HTTP polling or Laravel Reverb
Permissions per fieldHard: the whole document goes to every clientBuilt in: fields a person cannot see never reach their browser
Saving to the modelYour own code turns the document back into form dataBuilt in: Save publishes the draft through Filament's save
Editor bindingsMany ready-made onesAdapters for Filament's fields, and examples for TinyMCE, CKEditor, Quill and Trix
Data formatCompact binary, highly optimisedJSON, easy to read and debug; old history is compacted once a draft is saved and nobody is editing
MaturityYears of production useNew, 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.

Which parts of the package need Filament, Livewire or Laravel.Which parts of the package need Filament, Livewire or Laravel.
  • The merge engine needs nothing. resources/js/crdt imports no library and no browser API, so it runs in any browser or in Node, and src/Crdt is 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() and canView(), and saving goes through Filament's EditRecord.

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.

Released under the MIT License.