horacioh / slate-yjs

Yjs bindings for Slate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Slate Yjs

(Experimental) Yjs bindings for Slate.

Heavily inspired by slate-collaboritve

Installation

Via npm:

npm install slate-yjs

Via yarn:

yarn add slate-yjs

Why use Slate Yjs instead of slate-collaborative?

Performance. slate-collaborative works well for small documents but causes 20 seconds plus load times on larger documents which slate-yjs can load in a fraction of a second.

For a more in-depth comparison take a look at this benchmark.

Why CRDTs over OT?

The article "CRDTs are the future" from the creator of sharedb might be interesting for you.

API

YjsEditor

Adding a 2-way binding from the editor to a yjs document is as easy as:

import { withYjs } from 'slate-yjs';

const yjsEditor = withYjs(editor);

// The 2-way bound sync doc
console.log(yjsEditor.syncDoc);

WebsocketEditor

Slate Yjs comes with built in support for y-websocket:

import { WebsocketEditorOptions, withWebsocket } from 'slate-yjs';

const collabEditor = withWebsocket(yjsEditor, options);

// Connect editor
collabEditor.connect();

Options

{
  roomName: string // Room name
  endpoint: string // Websocket endpoint
  onConnect?: () => void // Connect callback
  onDisconnect?: () => void // Disconnect callback
  connect?: boolean // Whether to connect automatically (default false)
  awareness?: awarenessProtocol.Awareness // Awareness protocol to use
  WebSocketPolyfill?: typeof WebSocket // Websocket polyfill to use
  resyncInterval?: number // Request server state every `resyncInterval` milliseconds
}

Example project

Take a look at the example project here

Contribute

Please refer to each project's style and contribution guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!

About

Yjs bindings for Slate

License:MIT License


Languages

Language:TypeScript 98.7%Language:JavaScript 1.3%