npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@llui/lexical-collab

v0.4.1

Published

Opt-in collaborative editing for the LLui ↔ Lexical binding — Yjs CRDT sync, scoped undo, and presence cursors over an injected provider

Readme

@llui/lexical-collab

Opt-in collaborative editing for the LLui ↔ Lexical binding. It composes @lexical/yjs's CRDT primitives — the same wiring the official React CollaborationPlugin performs — into a single options fragment you spread into lexicalForeign (or, more commonly, into the markdown editor's collab option).

The network provider is injected: bring your own y-websocket, y-webrtc, or @hocuspocus/provider. This package never opens a socket itself, so it stays transport-agnostic and ships zero CRDT bytes to non-collaborative bundles (it is a separate, opt-in package).

Why it can't be "just a plugin"

A collaborative session inverts the editor's source of truth: the shared Yjs document — not a markdown string — is canonical. That means the base seam's built-in pieces must be disabled and replaced, which a plain LexicalPlugin cannot do:

  • History@lexical/history's local undo stack would cross peers. Replaced by a Yjs UndoManager scoped to the local origin (your undo only reverts your edits).
  • Seed → seeding on every client duplicates content. Replaced by a sync-gated bootstrap: exactly one peer seeds, and only while the shared document is still empty.
  • Controlled value → a markdown signal pushing into a CRDT fights convergence. Mutually exclusive with collab.

So @llui/lexical exposes the seam options this package plugs into — most importantly externalUndo, which takes ownership of the undo stack AND forces the built-in @lexical/history stack off in one place, so the two can never both run and double-apply an undo — plus seedMode: 'deferred' for the sync-gated bootstrap.

You never set either yourself. yjsCollab(...) returns them pre-filled as collab.foreign, a fragment you spread into lexicalForeign; the handle exposes its registration only as externalUndo and has no register member at all. So wiring the binding and disabling local history are the same act, and the pairing that silently double-applies undo has no spelling.

Renaming your way around that doesn't work either: collab.externalUndo is an ExternalUndoOwner, a branded function type that lexicalForeign's register slot rejects at compile time. Plain registration functions are unaffected — @llui/lexical-loro's split register + externalUndo binding still type-checks unchanged.

Usage with the markdown editor (recommended)

import { mountApp } from '@llui/dom'
import { markdownEditor } from '@llui/markdown-editor'
import { yjsCollab } from '@llui/lexical-collab'
import { Doc } from 'yjs'
import { WebsocketProvider } from 'y-websocket'

const doc = new Doc()

mountApp(
  el,
  markdownEditor({
    defaultValue: '# Shared doc\n\nStart typing…', // becomes the bootstrap seed
    collab: (hooks) =>
      yjsCollab({
        id: 'room-42',
        doc,
        provider: new WebsocketProvider('wss://example.com', 'room-42', doc),
        user: { name: 'Ada', color: '#0a7' },
        shouldBootstrap: true, // exactly one peer should seed
        ...hooks, // seed + onStatus/onSync/onPeers → editor's state.collab
      }),
  }),
)

...hooks forwards the markdown seed (so the bootstrapping peer fills the empty shared doc from defaultValue via the editor's own transformers) and the status sinks (so connection / sync / peer-count flow into state.collab for your chrome).

Usage with the low-level seam

import { lexicalForeign } from '@llui/lexical'
import { yjsCollab } from '@llui/lexical-collab'

const collab = yjsCollab({ id, doc, provider, user, seed })

lexicalForeign({
  namespace: 'doc',
  serialize,
  deserialize,
  readonly,
  // Everything a CRDT session needs from the seam, in one spread: the binding
  // registration in the `externalUndo` slot (which force-disables the built-in
  // @lexical/history stack) plus `seedMode: 'deferred'` (the sync-gated
  // bootstrap replaces the boot-time seed). Nothing left to remember.
  ...collab.foreign,
})

When you yjsCollab(...) created the document (you passed neither doc nor a factory that made its own), call collab.destroy() after the lexicalForeign unmount tears the binding down — it destroy()s the internally-created YDoc and removes it from the docMap. A doc you supplied is yours to destroy.

Presence cursors

Remote carets render automatically when a user is set. @lexical/yjs inline-styles each caret in the peer's colour; this package ships styles/collab.css to position the overlay container:

import '@llui/lexical-collab/styles/collab.css'

Testing your integration

The in-memory networked provider used by this package's own tests connects N peers without a server — useful for asserting convergence in your app's tests. (See test/network.ts.)