Skip to content

Make your own component live ​

Native HTML inputs (<input>, <textarea>, <select>, checkboxes, radios) and TipTap work out of the box. When your app uses its own components — a UI library like shadcn/ui or Flux, a custom star rating or tag picker, a composer with a character counter, or a third-party editor like CodeMirror or Quill — you can connect them to the same shared draft in a few lines.

Before you start: pick the right pattern ​

What your component isField kindHow to connect it
A wrapper around a native <input>, <textarea>, or <select> (shadcn/ui, Blade <x-input>, Vue wrapper)FieldKind::Text or FieldKind::ValueForward the binding attributes/props to the underlying input — no extra JS
A custom picker or choice widget (star rating, colour picker, tag selector, date picker)FieldKind::ValueShare whole values with onChange(value) (React) or room.change(field, value) (Vue / Livewire)
A custom text widget with <input> or <textarea> (post composer with character count, mention box)FieldKind::TextSpread form.field() / v-collaborate / data-collaborate onto the inner <textarea>
A custom TipTap editor (your own toolbar and extensions)FieldKind::RichTextAdd the Collaborative extension from @solutionforest/laravel-collaboration/tiptap
Any third-party text or code editor (CodeMirror, Quill, Ace, Monaco)FieldKind::TextBind directly to room.bind() and room.change()

1. Wrapping your own UI input components ​

If your app already has styled input components, you do not need a custom binding — forward the collaborative attributes to the native element inside.

Any Blade component that forwards $attributes (including wire:model) already works automatically. If your component renders an <input> or <textarea> without a direct wire:model on the element itself, add data-collaborate="field_name":

blade
{{-- resources/views/components/form/input.blade.php --}}
@props(['label', 'field'])

<label class="block">
    <span class="flex items-center gap-2 text-sm font-medium">
        {{ $label }}
        <x-collaboration::field-people :field="$field" />
    </span>

    <input
        {{ $attributes->merge(['class' => 'mt-1 w-full rounded-lg border px-3 py-2']) }}
        wire:model="{{ $field }}"
    >
</label>

Use it inside any Livewire component with WithCollaboration:

blade
<x-form.input label="Title" field="title" />

2. Build a live picker: Star Rating (latest value wins) ​

A star rating is a row of buttons with no native <input>. Declare the column as FieldKind::Value on the model (an integer cast already makes it a value):

php
protected array $collaborative = [
    'title',
    'rating' => FieldKind::Value,
];

Use wire:ignore so Livewire does not replace the widget while people click, and connect to the room with Collaboration.whenReady():

blade
<div
    wire:ignore
    x-data="{
        value: @js($rating ?? 0),
        room: null,
        init() {
            Collaboration.whenReady(this.$el, (room) => {
                this.room = room
                room.bind('rating', {
                    render: () => {
                        this.value = room.value('rating') ?? 0
                        $wire.$set('rating', this.value, false)
                    },
                    reveal: () => this.$el.scrollIntoView({ block: 'center', behavior: 'smooth' }),
                })
                if (room.isReady) this.value = room.value('rating') ?? this.value
            })
        },
        pick(star) {
            this.value = star
            $wire.$set('rating', star, false)
            this.room?.change('rating', star)
        },
    }"
    @focusin="room?.focus('rating')"
    @focusout="room?.blur('rating')"
    class="flex items-center gap-1"
>
    @for ($star = 1; $star <= 5; $star++)
        <button
            type="button"
            @click="pick({{ $star }})"
            :class="value >= {{ $star }} ? 'text-amber-500' : 'text-slate-300'"
        >★</button>
    @endfor
</div>

3. Build a live text widget: Post Composer with character counter ​

A post composer adds a live character counter around a <textarea>. Because the inner element is a <textarea>, the package's built-in text binding handles character-by-character merging, remote carets, IME composition, and per-user Ctrl+Z undo automatically.

Declare 'social_post' as text on the model:

php
protected array $collaborative = [
    'social_post', // FieldKind::Text by default
];

Put data-collaborate="social_post" on the <textarea> so the Livewire script attaches bindTextField() to it, and listen for input to keep Alpine's counter in sync:

blade
<div
    x-data="{ count: @js(mb_strlen($social_post ?? '')), limit: 280 }"
    class="space-y-1"
>
    <div class="flex items-center justify-between text-sm">
        <span class="font-medium">Social post <x-collaboration::field-people field="social_post" /></span>
        <span :class="count > limit ? 'text-red-600' : 'text-slate-500'" x-text="`${limit - count} left`"></span>
    </div>

    <textarea
        wire:model="social_post"
        data-collaborate="social_post"
        rows="3"
        class="w-full rounded border px-3 py-2"
        @input="count = $event.target.value.length"
    ></textarea>
</div>

4. Custom TipTap toolbar or third-party editors ​

TipTap with your own toolbar and extensions ​

When you want your own formatting toolbar, slash commands, or extra TipTap extensions, build TipTap yourself and add the Collaborative extension from @solutionforest/laravel-collaboration/tiptap:

In your Vite bundle, mount TipTap inside an Alpine component with wire:ignore and wait for the room with Collaboration.whenReady():

js
import { Editor } from '@tiptap/core'
import StarterKit from '@tiptap/starter-kit'
import { Collaborative } from '@solutionforest/laravel-collaboration/tiptap'

export function richEditor(field) {
    return {
        // Keep the Editor instance off Alpine's reactive object so Alpine does not proxy it.
        init() {
            Collaboration.whenReady(this.$el, (room) => {
                this.$el._editor = new Editor({
                    element: this.$refs.surface,
                    extensions: [StarterKit, Collaborative.configure({ room, field })],
                    content: this.$wire.get(field) ?? '',
                    onUpdate: ({ editor }) => this.$wire.$set(field, editor.getJSON(), false),
                })
            })
        },
        toggleBold() {
            this.$el._editor?.chain().focus().toggleBold().run()
        },
        destroy() {
            this.$el._editor?.destroy()
        },
    }
}

Connecting any other editor (CodeMirror, Quill, Ace, plain JS) ​

For an editor that manages its own DOM and selection, use room.bind() directly. The room calls capture() before applying colleagues' edits and render() immediately after so you can preserve the user's cursor:

js
import { Room } from '@solutionforest/laravel-collaboration'

function bindCustomEditor(room, field, editor) {
    let saved = null
    let applying = false

    const render = () => {
        const next = room.value(field) ?? ''

        if (editor.getValue() !== next) {
            applying = true
            editor.setValue(next)
            applying = false
        }

        // Restore the user's caret using stable CRDT character IDs.
        if (saved && editor.hasFocus()) {
            const anchor = room.indexOf(field, saved.anchor) ?? 0
            const head = room.indexOf(field, saved.head) ?? 0
            editor.setSelection(anchor, head)
        }

        saved = null
    }

    const unbind = room.bind(field, {
        get isBusy() {
            return editor.isComposing() // pause remote updates during IME input
        },
        capture() {
            if (!editor.hasFocus()) return
            const { anchor, head } = editor.getSelection()
            saved = { anchor: room.idAt(field, anchor), head: room.idAt(field, head) }
        },
        render,
        cursor: () => (editor.hasFocus() ? editor.getSelection() : null),
        reveal: () => editor.dom.scrollIntoView({ block: 'center', behavior: 'smooth' }),
    })

    const offChange = editor.onChange(() => {
        if (applying) return
        room.change(field, editor.getValue(), editor.getSelection().head)
    })
    const offSelection = editor.onSelectionChange(() => room.cursorMoved())
    const offFocus = editor.onFocus(() => room.focus(field))
    const offBlur = editor.onBlur(() => room.blur(field))
    const offPeople = room.on('people', () => editor.drawCarets(room.carets(field)))

    if (room.isReady) render()

    return () => {
        offChange()
        offSelection()
        offFocus()
        offBlur()
        offPeople()
        unbind()
    }
}

Custom component API reference ​

APIWhat it does
room.bind(field, { capture, render, cursor, isBusy, reveal })Registers a custom field binding; returns an unbind() function
room.change(field, value, caret?)Records a local edit into the CRDT and queues it for sync
room.value(field)Reads the current shared value of a field
room.focus(field) / room.blur(field)Announces which field this user is in (drives <FieldPeople> and locks)
room.cursorMoved()Schedules a quick sync after a caret/selection move
room.idAt(field, index) / room.indexOf(field, id)Converts caret offsets to/from stable character IDs that survive remote edits
room.carets(field)Returns other users' selections in this field: { person, anchor, head }[]
room.peopleIn(field)Returns active colleagues currently in field
room.lockedBy(field)Returns the colleague holding a ->lock() field, or null
room.on(event, fn)Subscribes to ready, change, people, status, saved, expired, deleted
bindTextField(room, field, el, { onValueChange })Binds any <input> or <textarea> with carets, IME handling, and per-user undo
bindValueField(room, field, elOrList, { onValueChange })Binds any <select>, checkbox, checkbox group, or radio group
lockWhileEditing(room, field, el)Applies read-only lock behaviour and banner when ->lock() is set in PHP
window.Collaboration.whenReady(el, (room) => ...)Livewire helper: hands you the enclosing Livewire component's Room once ready

Checklist before shipping a custom component ​

  • [ ] Livewire: Add wire:ignore on widgets that manage their own DOM, and never store a third-party editor instance directly on Alpine reactive data (this.editor = ...).
  • [ ] React: Never turn a live text field into a controlled value={...} input; let {...form.field()} pass defaultValue.
  • [ ] Focus & blur: Call room.focus(field) and room.blur(field) so <FieldPeople> and ->lock() know when someone is in the field.
  • [ ] IME safety: Return isBusy: true while composing CJK/IME text so remote edits wait until composition ends.
  • [ ] Cleanup: Call the unbind() function returned by room.bind() (and remove listeners) when the component unmounts.
  • [ ] Test with two browsers: Open the same record in a normal window and a private window, edit simultaneously, and verify that saving preserves both edits.

Released under the MIT License.