Collaborative Cursor and Selection support for sharedb-monaco.
(If you're using your own ShareDB Monaco implementation, sharedb-monaco-cursors will work even without sharedb-monaco installed)
Developed for the CodeCollab project.
Tested and works well with monaco-react.
Using NPM:
$ npm install sharedb-monaco-cursors
sharedb-monaco-cursors
relies on the ShareDB Presence API to work. Before using this library, ensure that this API is enabled on the server as it is disabled by default.
To enable the Presence API on the server:
let shareConfig = {
db,
presence: true // This line enables Presence
}
const share = new ShareDB(shareConfig);
Sample usage of this library in action
import ShareDBMonaco from "sharedb-monaco";
import ShareDBMonacoCursors from "sharedb-monaco-cursors";
import monaco from "monaco-editor";
// Get a monaco editor (ICodeEditor) instance
let editor = monaco.editor.create(document.getElementById("editor"), {
value: "print('Hello World!')",
language: "python"
});
// Initialise sharedb-monaco
let binding = new ShareDBMonaco(options);
let model = binding.add(editor, attachOptions);
// Initialise sharedb-monaco-cursors
let cursors = new ShareDBMonacoCursors(cursorOptions);
options
<Object>id
<string> ID of the ShareDB documentnamespace
<string> The namespace of document within ShareDB, to be equal to that on the servername
<string> Name of this user, to be displayed to other connected users.editors
<monaco.editor.ICodeEditor[]> Array ofICodeEditor
s to bind cursors to.viewOnly
<boolean> Should local cursor and selection events be listened and broadcasted. Default:false
colors
<string[]> Array of color codes to use for cursors. Defaults to['BurlyWood', 'lightseagreen', 'Violet', 'Red', 'forestgreen', 'DarkViolet', 'OrangeRed', 'navy', 'darkviolet', 'maroon']
uid
<string> Unique Identifier for each user's cursors. Important if you want to manage cursors across multipleShareDBMonacoCursors
instances and documents at the same time.
Toggles the view-only state of the cursors.
viewOnly
<boolean> Should this document ignore local cursor and selection events.
Add an editor to bind cursor and selection event listeners to
editor
<monaco.editor.ICodeEditor> The editor to bind listeners to
Remove an editor from listening and receiving cursor and selection events
id
<string> Id of theICodeEditor
instance fromICodeEditor.getId()
Closes all event listeners, removes all cursors and clean up. Will also unsubscribe and destroy the presence.