Adapters
Adapters for other editors
New to adapters? Make your own component live builds two from scratch, a text composer with carets and a star rating, with tests.
A third-party editor, such as a TinyMCE or CKEditor field, keeps its content in its own JavaScript object. An adapter is a short script that tells this package how to read and write that editor and where its caret is. The package does the rest: merging, carets, presence, saving, permissions.
Filament's own fields use the same API. Text inputs and textareas (filament-text-input), pickers (filament-value), the rich editor (filament-rich-editor), repeaters and builders (filament-repeater), uploads (filament-file-upload), and the Markdown and code editors are all adapters registered with FilamentCollaboration.adapter(), in resources/js/adapters/filament.js. Every field goes through this one API. An adapter you write gets exactly what they get, and they are the best examples to copy.
1. Say which fields use it, in PHP. A package does this once, in its service provider's boot():
use SolutionForest\FilamentCollaboration\CollaborationPlugin;
use SolutionForest\FilamentCollaboration\Enums\FieldKind;
use SolutionForest\FilamentCollaboration\Fields\Types\AdapterType;
CollaborationPlugin::registerFieldTypes(
AdapterType::make([TinyEditor::class], adapter: 'tinymce', kind: FieldKind::RichText),
);An app can also name the adapter on one field: TinyEditor::make('body')->collaborative(adapter: 'tinymce', as: FieldKind::RichText).
| Kind | Adapter format | Merges |
|---|---|---|
FieldKind::Text | text: a string | by character |
FieldKind::RichText | html: an HTML string | by character, block and mark; see HTML editors |
FieldKind::RichText | rich: a ProseMirror / TipTap JSON document | the same, for editors built on ProseMirror; FilamentCollaboration.prosemirror has the helpers Filament's rich editor uses |
FieldKind::Value | value: any JSON | the latest change wins |
FieldKind::Items | items: items by key, each an object of sub-fields, as a repeater keeps them | adding, removing and moving merge; text sub-fields by character, with carets; other sub-fields the latest change. Positions carry the item and sub-field: { item, path, anchor, head } |
2. Register the adapter, in JavaScript loaded on the panel, with FilamentCollaboration.adapter(), as you would register an Alpine component with Alpine.data():
FilamentCollaboration.adapter('my-editor', {
format: 'text',
attach({ element, changed, moved }) {
const editor = MyEditor.instanceIn(element) // however your editor is found
if (!editor) return null // not ready yet: asked again shortly
editor.on('change', changed)
editor.on('selectionchange', moved)
return {
read: () => editor.getText(),
write: (text) => editor.setText(text), // better: change only what differs; see minimalChange()
selection: () => editor.getSelection(), // { anchor, head }, UTF-16 offsets into read()
setSelection: ({ anchor, head }) => editor.select(anchor, head),
caretRect: (offset) => editor.coordsAt(offset), // a DOMRect, for other people's carets
isFocused: () => editor.hasFocus(),
destroy: () => editor.off('change', changed),
}
},
})FilamentCollaboration is defined in the panel's <head>, before any script, so your script may load before or after the package's: an adapter registered early waits until the package starts. adapter() returns FilamentCollaboration, so several can be chained. Before 0.3.0 it was called registerAdapter(), which still works.
attach() may also return false to say the editor cannot be live in this browser; the field then merges on save. The CodeMirror 6 adapter does this in Safari, where a change arriving mid-keystroke can lose that keystroke.
Only read and write are required; without the selection methods, edits still merge but carets are not kept or shown. The other capabilities Filament's own adapters use are open to yours:
undo() / redo() (on the context) | call them on Ctrl+Z instead of the editor's own undo: only this person's typing is undone, never a colleague's (text format) |
recover(error, details) (on the context) | the editor threw on a change: the draft is shown again, the error reported; repeated failures make the field merge on save |
geometry({ anchor, head }) (on the handle) | a caret and a whole selection to draw, instead of caretRect() |
isDirty() (on the handle) | false when nothing changed since the last read(), for editors where reading is costly |
If the adapter is missing, or throws, the field simply merges on save as before.
The demo's packages/ folder has working adapters for TinyMCE, CKEditor 5, Quill and Trix:

HTML editors
TinyMCE, CKEditor, Quill, Trix and most WYSIWYG editors hold HTML. Merging HTML by character could break its tags, so an adapter with format: 'html' hands over HTML, and the package turns it into the same document the built-in rich editor shares: paragraphs, headings, bold, italic, underline, strike, code, links, lists, quotes, tables, images and line breaks. Those merge by character, block and mark, with carets; anything else in the HTML is kept as its text. On save, the field gets HTML back.
Carets are positions in that document. FilamentCollaboration.html maps them to and from the editor's DOM, so an HTML adapter is mostly glue:
FilamentCollaboration.adapter('tinymce', {
format: 'html',
attach({ element, changed, moved }) {
const editor = element.querySelector('.my-tinymce')?.editor // however you keep it
if (!editor?.initialized) return null
const html = FilamentCollaboration.html
const body = () => editor.getBody()
editor.on('input change undo redo', changed)
editor.on('SelectionChange', moved)
return {
read: () => editor.getContent(),
write: (value) => editor.setContent(value),
selection: () => html.selectionIn(body(), editor.getDoc().getSelection()),
setSelection: (positions) => editor.selection.setRng(html.select(body(), positions)),
caretRect: (position) => html.caretRectAt(body(), position),
isFocused: () => editor.hasFocus(),
}
},
})Register its PHP side with FieldKind::RichText. Keep the editor object off Alpine's reactive data (for example on the element): editors such as CKEditor and Quill break behind its proxy.
Working examples are in demo/packages/: a TinyMCE, a CKEditor 5, a Quill and a Trix field, each a small Filament package with its adapter in resources/js/editor.js and its registration in the service provider. The demo's article form uses all four, and the browser tests type in each from two browsers at once. Rebuild them with npm run build:editors in demo/. TinyMCE and CKEditor 5 are GPL-licensed when used without a commercial licence key.
Your own presence storage. Presence is stored in the database by default. Bind your own implementation of Contracts\PresenceRepository, for example on Redis, in a service provider.