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

@bibliotype/collab

v26.10.25-rc.1

Published

协同校勘:IR ⇄ Y.Doc 映射、会话与 Provider 抽象 - bibliotype 协同包

Readme

@bibliotype/collab

协同校勘:IR ⇄ Y.Doc 映射、协同会话(CollabSession)与 Provider 抽象。 自带内存网络实现(InMemoryNetwork / InMemoryProvider),用于单元测试与单进程多端演示; 生产环境实现 CollabProvider 接口对接真实网络(如 WebSocket)。

安装

pnpm add @bibliotype/collab @bibliotype/core yjs

快速上手

import { CollabSession, InMemoryNetwork, InMemoryProvider } from '@bibliotype/collab';

/* 内存网络:同进程多端互联(两个会话即可模拟双人协同) */
const network = new InMemoryNetwork();
const sessionA = new CollabSession({
  user: { name: '钱大昕' },
  provider: new InMemoryProvider(network),
});
const sessionB = new CollabSession({
  user: { name: '戴震' },
  provider: new InMemoryProvider(network),
});

sessionA.loadDocument(document);   // 写入 Y.Doc(在线时同步给 B)

const off = sessionB.onDocumentChange((doc) => {
  console.log('B 收到最新快照:', doc.metadata.title);
});

const snapshot = sessionB.snapshot();   // 导出当前 IR(可交给 Reader / 编辑器)

/* 生命周期 */
sessionA.disconnect();                  // 断开网络(保留本地文档)
sessionA.connect();                     // 重新连接(幂等)
sessionA.updateUser({ name: '竹汀' });  // 更新本地用户
off();
sessionA.destroy();                     // 断开 + 清空订阅 + 销毁 Y.Doc
sessionB.destroy();

API 概览

| 分组 | 导出 | | --- | --- | | IR ⇄ Y.Doc 映射 | YDOC_KEYS、ORIGIN_DOCUMENT_MAPPER、writeDocument(ydoc, doc)、readDocument(ydoc) | | Provider | CollabProvider(name / status / bind / connect / disconnect / onStatusChange / destroy)、PROVIDER_STATUS、InMemoryNetwork、InMemoryProvider(network) | | 会话 | CollabSession(loadDocument / snapshot / onDocumentChange / connect / disconnect / updateUser / destroy / currentUser) | | 用户 | CollabUser { name, color }、DEFAULT_USER_COLORS、createDefaultUser()、resolveUser(partial) |

CollabSessionOptions:user?(缺省生成默认身份)、provider?(缺省为本地离线文档)、 autoConnect?(默认 true)。

设计要点

  • 延迟绑定:Provider 先创建、后由 CollabSession 注入 Y.Doc,会话是文档的唯一所有者;
  • 环回抑制:远端来源的更新不再回播,避免广播环路;
  • 统一订阅:本地与远端变更经同一 ydoc.on('update') 通道回调最新快照;
  • 更新以增量事务写入(ORIGIN_DOCUMENT_MAPPER 标记来源),为协同编辑器绑定预留。

相关