Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

yjs

БесплатноБез исполняемых скриптовНе проверен

Yjs is a high-performance CRDT (Conflict-free Replicated Data Type) framework for building collaborative applications: shared types whose concurrent edits…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Yjs — CRDT Framework for Collaborative Editing

Overview

Yjs is a CRDT framework for collaborative applications. Data lives in shared types (Y.Text, Y.Map, Y.Array, Y.XmlFragment) inside a Y.Doc; every client edits its own copy and the copies converge without a central authority deciding conflicts. Providers move the updates around: y-websocket through a server, y-webrtc peer to peer, y-indexeddb to the browser's disk for offline work.

Instructions

Install

npm install yjs                    # core library (13.x)
npm install y-websocket            # WebSocket client provider (3.x)
npm install y-indexeddb            # browser offline persistence
npm install y-webrtc               # peer-to-peer sync, needs a signaling server
# Server (it left the y-websocket package in v3)
npm install @y/[email protected] ws
npm install y-mongodb-provider     # MongoDB persistence (community package); y-leveldb for LevelDB
# Tiptap 3 editor binding
npm install @tiptap/react @tiptap/starter-kit @tiptap/extension-collaboration @tiptap/extension-collaboration-caret @tiptap/y-tiptap

The current @y/websocket-server (0.1.5) depends on the Yjs 14 pre-release. Loaded next to Yjs 13 it prints "Yjs was already imported" and persistence code fails, so stay on 0.1.1, the last release with a Yjs 13 peer dependency, while the app uses Yjs 13.

Document and Shared Types

Create collaborative data structures that merge automatically:

// src/collaboration/document.ts — Set up a collaborative document with shared types
import * as Y from "yjs";

// A Y.Doc is the top-level container; every connected client holds a copy
const doc = new Y.Doc();
// Y.Text — collaborative text (rich text via yText.format and deltas)
const yText = doc.getText("document-content");
yText.insert(0, "Hello, ");
yText.insert(7, "world!"); // "Hello, world!" — concurrent inserts are both kept

// Y.Map — collaborative key-value store
const yMap = doc.getMap("settings");
yMap.set("theme", "dark");
// Different keys set concurrently: both applied. Same key: one write wins on every client.

// Y.Array — collaborative ordered list
const yArray = doc.getArray("tasks");
yArray.push([{ id: "1", title: "Design mockup", done: false }]);

// Y.XmlFragment — XML tree used by editor bindings (Tiptap, ProseMirror)
const yXml = doc.getXmlFragment("rich-content");
// Shared types nest: a map inside a map
const project = new Y.Map();
project.set("status", "active");
yMap.set("project", project);

// Group changes into one update; the second argument is the transaction origin
doc.transact(() => {
  yMap.set("fontSize", 14);
  yMap.set("lineHeight", 1.5);
}, "settings-form");

// React to changes
yMap.observe((event) => console.log("keys changed:", [...event.keysChanged]));
// Undo/redo for one user: undoManager.undo() reverts only local edits to yText
const undoManager = new Y.UndoManager(yText);

WebSocket Provider

Connect clients through a WebSocket server for real-time sync:

// src/collaboration/provider.ts — WebSocket-based real-time sync
import * as Y from "yjs";
import { WebsocketProvider } from "y-websocket";

const doc = new Y.Doc();
// All clients that join the same room on the same server sync automatically
const provider = new WebsocketProvider("ws://localhost:1234", "handbook-onboarding", doc, {
  params: { token: sessionToken }, // your app's session token, sent as ?token=... on every (re)connect
});

// Awareness — presence data (cursors, selections, user info); never persisted
const awareness = provider.awareness;
awareness.setLocalStateField("user", { name: "Alice", color: "#ff5733" });
awareness.on("change", () => {
  awareness.getStates().forEach((state, clientId) => {
    if (clientId !== doc.clientID) console.log(`${state.user?.name} is here`);
  });
});

provider.on("status", ({ status }) => console.log(status)); // "connecting" | "connected" | "disconnected"
provider.on("sync", (isSynced: boolean) => isSynced && console.log("Synced with server"));
// Fired when the server closed the connection with a 4400–4499 code: no more reconnects
provider.on("closed", ({ code, reason }) => console.log(`Rejected: ${code} ${reason}`));

Node.js 22 and later have a global WebSocket; on older versions pass WebSocketPolyfill: require("ws") in the options.

Server-Side Setup

For development, HOST=localhost PORT=1234 npx y-websocket (from @y/websocket-server) starts an in-memory server; with 0.1.1 and y-leveldb installed, YPERSISTENCE=./yjs-data makes it persist to LevelDB. For a database of your choice, write the server yourself:

// server/yjs-server.mjs — WebSocket server with MongoDB persistence
import http from "node:http";
import { WebSocketServer } from "ws";
import * as Y from "yjs";
import { setupWSConnection, setPersistence } from "@y/websocket-server/utils";
import { MongodbPersistence } from "y-mongodb-provider";

const mdb = new MongodbPersist
Полный SKILL.md на GitHub

Установить yjs в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл yjs?

Yjs is a high-performance CRDT (Conflict-free Replicated Data Type) framework for building collaborative applications: shared types whose concurrent edits merge automatically. Use when a user asks to add real-time collaborative editing, shared cursors and presence, offline-first sync, or peer-to-peer collaboration to an app, to run or secure a y-websocket server, to persist Yjs documents, or to make a Tiptap or ProseMirror editor collaborative.

Как установить скилл yjs?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл yjs запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить yjs с