webxdc yjs provider
  • TypeScript 96.1%
  • JavaScript 3.9%
Find a file
faassen c25a0e9163 Merge pull request 'api-tweaks: make autosaveInterval optional and split on()' (#10) from api-tweaks into main
Reviewed-on: #10
Reviewed-by: hpk <hpk@noreply.codeberg.org>
Reviewed-by: ndh <ndh@noreply.codeberg.org>
2026-06-26 16:43:19 +02:00
doc Revert "removed screenshots, published 1.0.5" 2023-09-29 17:24:44 +02:00
src remove: on() API. 2026-06-26 12:53:07 +02:00
tests remove: on() API. 2026-06-26 12:53:07 +02:00
.gitignore some more metadata 2023-09-29 11:26:33 +02:00
.prettierignore tooling: prettier 2026-06-24 19:04:51 +02:00
CHANGELOG.md remove: on() API. 2026-06-26 12:53:07 +02:00
eslint.config.js types: it now typechecks and we can make it strict. 2026-06-25 21:10:40 +02:00
LICENSE packaging: add in a missing LICENSE file. 2026-06-23 19:03:33 +02:00
package.json types: it now typechecks and we can make it strict. 2026-06-25 21:10:40 +02:00
pnpm-lock.yaml types: it now typechecks and we can make it strict. 2026-06-25 21:10:40 +02:00
pnpm-workspace.yaml comments: fix typo 2026-06-26 16:41:15 +02:00
README.md tooling: mechanical shift to typescript 2026-06-25 14:26:44 +02:00
tsconfig.build.json types: it now typechecks and we can make it strict. 2026-06-25 21:10:40 +02:00
tsconfig.json types: it now typechecks and we can make it strict. 2026-06-25 21:10:40 +02:00
vitest.config.ts types: it now typechecks and we can make it strict. 2026-06-25 21:10:40 +02:00

y-webxdc

Webxdc provider for Yjs

The WebxdcProvider turns apps using yjs into production-ready webxdc apps. Webxdc apps can be shared in a chat with messengers like Delta Chat and Cheogram, sharing all application state with chat members via yjs.

WebxdcProvider supports:

  • immediate receiving of yjs changes from chat peers

  • autosaving: saving yjs changes periodically to chat peers

  • manual saving: call provider.syncToChatPeers() for causing immediate saving (it's fine to mix manual and autosaving).

  • setting of document, summary and chat-message info which is the metadata shown in a chat (see below screenshots).

  • reliably saving any pending yjs changes when the app window closes, on all webxdc-supporting platforms.

  • resending entire state to force consistency over unreliable messanger delivery (resendAllUpdates).

Setup

Install

npm i y-webxdc

Client code

import * as Y from "yjs";
import { WebxdcProvider } from "y-webxdc";

// provided by messengers or webxdc-dev tool
// see https://docs.webxdc.org/spec.html
const webxdc = window.webxdc;

const ydoc = new Y.Doc();
const yarray = ydoc.get("array", Y.Array);
const provider = new WebxdcProvider({
  webxdc,
  ydoc,
  autosaveInterval: 10 * 1000,
  getEditInfo: () => {
    const document = "webxdc yjs provider";
    const summary = `Last edit: ${webxdc.selfName}`;
    const startinfo = `${webxdc.selfName} editing ${document}`;
    return { document, summary, startinfo };
  },
  resendAllUpdates: false,
});

See the following example for the meaning of document, summary and startinfo as returned by the getEditInfo callback passed into the provider.

Example

The webxdc editor uses y-webxdc to implement a collaborative editor.

Editor running Delta Chat desktop

Showing edit information in chat

Development

This project is written in TypeScript and uses pnpm. Install dependencies with:

pnpm install

Test

Run the test suite (vitest):

pnpm test

Build

Compile src/ to dist/ (JavaScript plus type declarations):

pnpm build

Type check

Check types without emitting any output:

pnpm typecheck

Code Style

Linting with eslint and formatting with prettier:

pnpm lint
pnpm lint:fix
pnpm format

pnpm lint:fix applies eslint fixes; pnpm format reformats with prettier.

Check everything

pnpm check runs the formatting check, the type checker, the linter and the tests together:

pnpm check