@convergencelabs/monaco-collab-ext

中文文档
0.4.0发布于 2022/09/20MITTypeScriptCommonJS近 30 天下载 5276

Collaborative Extensions for the Monaco Editor

原始使用文档
文档目录7 节
  1. Monaco Collaborative Extensions
  2. Installation
  3. Demo
  4. Usage
  5. RemoteCursorManager
  6. RemoteSelectionManager
  7. EditorContentManager

Monaco Collaborative Extensions

Build Status

Enhances the Monaco Editor by adding the ability to render cues about what remote users are doing in the system.

demo graphic

Installation

Install package with NPM and add it to your development dependencies:

npm install --save-dev @convergencelabs/monaco-collab-ext

Demo

Go here to see a live demo of multiple cursors, multiple selections, and remote scrollbars (Visit on multiple browsers, or even better, point a friend to it too). This uses Convergence to handle the synchronization of data and user actions.

Usage

RemoteCursorManager

The RemoteCursorManager allows you to easily render the cursors of other users working in the same document. The cursor position can be represented as either a single linear index or as a 2-dimensional position in the form of {lineNumber: 0, column: 10}.

const editor = monaco.editor.create(document.getElementById("editor"), {
  value: "function helloWorld = () => { console.log('hello world!')",
  theme: "vs-dark'",
  language: 'javascript'
});

const remoteCursorManager = new MonacoCollabExt.RemoteCursorManager({
  editor: editor,
  tooltips: true,
  tooltipDuration: 2
});

const cursor = remoteCursorManager.addCursor("jDoe", "blue", "John Doe");

// Set the position of the cursor.
cursor.setOffset(4);

// Hide the cursor
cursor.hide();

// Show the cursor
cursor.show();

// Remove the cursor.
cursor.dispose();

RemoteSelectionManager

The RemoteSelectionManager allows you to easily render the selection of other users working in the same document.

const editor = monaco.editor.create(document.getElementById("editor"), {
  value: "function helloWorld = () => { console.log('hello world!')",
  theme: "vs-dark'",
  language: 'javascript'
});

const remoteSelectionManager = new MonacoCollabExt.RemoteSelectionManager({editor: editor});

const selection = remoteSelectionManager.addSelection("jDoe", "blue");

// Set the range of the selection using zero-based offsets.
selection.setOffsets(45, 55);

// Hide the selection
selection.hide();

// Show the selection
selection.show();

// Remove the selection.
selection.dispose();

EditorContentManager

The EditorContentManager simplifies dealing with local and remote changes to the editor.

const editor = monaco.editor.create(document.getElementById("editor"), {
  value: "function helloWorld = () => { console.log('hello world!')",
  theme: "vs-dark'",
  language: 'javascript'
});

const contentManager = new MonacoCollabExt.EditorContentManager({
  editor: editor,
  onInsert(index, text) {
    console.log("Insert", index, text);
  },
  onReplace(index, length, text) {
    console.log("Replace", index, length, text);
  },
  onDelete(index, length) {
    console.log("Delete", index, length);
  }
});

// Insert text into the editor at offset 5.
contentManager.insert(5, "some text");

// Replace the text in the editor at range 5 - 10.
contentManager.replace(5, 10, "some text");

// Delete the text in the editor at range 5 - 10.
contentManager.delete(5, 10);

// Release resources when done
contentManager.dispose();

版本与发布记录

@convergencelabs/monaco-collab-ext 共发布 7 个版本,首次发布于 2019/03/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.4.0latest2022/09/204 年前
0.3.22021/04/095 年前
0.3.12020/11/096 年前
0.3.02020/03/066 年前
0.2.02020/01/086 年前
0.1.12019/03/137 年前

关于 @convergencelabs/monaco-collab-ext 的常见问题

@convergencelabs/monaco-collab-ext 是什么?

Collaborative Extensions for the Monaco Editor

如何安装 @convergencelabs/monaco-collab-ext?

在项目目录运行 npm install @convergencelabs/monaco-collab-ext,或使用 pnpm add / yarn add / bun add。

@convergencelabs/monaco-collab-ext 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@convergencelabs/monaco-collab-ext 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@convergencelabs/monaco-collab-ext 可以商用吗?

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

@convergencelabs/monaco-collab-ext 的下载量有多少?

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

@convergencelabs/monaco-collab-ext 还在维护吗?

最新版本 0.4.0 发布于 2022/09/20(4 年前);至今共发布 7 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/03/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。