@automerge/automerge-codemirror

中文文档
0.2.0发布于 2025/07/21MITES Module近 30 天下载 2064

This plugin adds collaborative editing to codemirror using automerge-repo.

原始使用文档

Automerge + Codemirror

This plugin adds collaborative editing to codemirror using automerge-repo.

Example

import { Repo } from "@automerge/automerge-repo";
import { automergeSyncPlugin } from "@automerge/automerge-codemirror";
import { EditorView } from "@codemirror/view"
import { basicSetup } from "codemirror"

// Setup a repo and create a doc handle. In practice you'll probably get a
// DocHandle by loading it from a document URL
const repo = new Repo(..)
const doc = repo.create({text: ""})

// Setup the codemirror view
const container = document.createElement("div")
const view = new EditorView({
  doc: handle.doc().text,
  extensions: [
    basicSetup,
    automergeSyncPlugin({
      handle,
      path: ["text"],
    }),
  ],
  parent: container,
})

Automerge Repo 1.0 Compatibility

This codemirror plugin is intended for use with automerge-repo 2.0. That means that the interface it expects to be passed as the handle argument matches the signature of the DocHandle interface in automerge-repo 2.0. The main difference with automerge-repo 1.0 is that the automerge 1.0 DocHandle.doc method is asynchronous. If you can't upgrade to automerge-repo 2.0 then you can get around this by wrapping the 1.0 handle in an object which uses the 1.0 DocHandle.docSync method to implement the DocHandle.doc method. Like so:

import { type DocHandle } from "@automerge/automerge-codemirror"
import { type DocHandle as RepoHandle } from "@automerge/automerge-repo"

// Convert an automerge-repo 1.0 DocHandle to the interface this plugin expects
function makeHandle<T>(h: RepoHandle<T>): DocHandle<T> {
    return Object.assign({}, h, {
        doc: () => h.docSync(),
    })
}

版本与发布记录

@automerge/automerge-codemirror 共发布 13 个版本,首次发布于 2023/06/26;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.2.0latest2025/07/211.3 年前
0.1.02025/05/191.5 年前
0.0.122024/06/272 年前
0.0.112024/04/242 年前
0.0.102023/12/292 年前
0.0.92023/12/012 年前

关于 @automerge/automerge-codemirror 的常见问题

@automerge/automerge-codemirror 是什么?

This plugin adds collaborative editing to codemirror using automerge-repo.

如何安装 @automerge/automerge-codemirror?

在项目目录运行 npm install @automerge/automerge-codemirror,或使用 pnpm add / yarn add / bun add。

@automerge/automerge-codemirror 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/automerge__automerge-codemirror 是否存在。

@automerge/automerge-codemirror 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@automerge/automerge-codemirror 可以商用吗?

@automerge/automerge-codemirror 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@automerge/automerge-codemirror 的下载量有多少?

根据 npm 官方下载统计,@automerge/automerge-codemirror 在 2026/10/07 – 2026/11/05 这 30 天内被下载 2,064 次,日均约 69 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@automerge/automerge-codemirror 还在维护吗?

最新版本 0.2.0 发布于 2025/07/21(1.3 年前);至今共发布 13 个版本,其中过去 12 个月发布了 0 个;首次发布于 2023/06/26。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。