Code Monkey home page Code Monkey logo

ace-collab-ext's Introduction

Ace Collaborative Extensions

example workflow

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

Installation

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

For versions >= 0.5.0 (current): npm install --save-dev @convergencelabs/ace-collab-ext

For versions <= 0.4.0 (previous): npm install --save-dev @convergence/ace-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

CSS

Be sure to include one of CSS files located in the css directory of the node modules:

  • css/ace-collab-ext.css
  • css/ace-collab-ext.min.css

How to do this will depend on how you are packaging and distributing your application. For example if you are bundling your css / sass / less you might be able to use an @import statement or you might require it. If you are hotlinking, you might need to at a <link> tag to your document.

If you forget to include the styles, its likely that the remote cursors / selections will either not show up, or they will not properly move.

Multi Cursor Manager

The multi cursor manager 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 {row: 0, column: 10}.

const editor = ace.edit("editor");
const curMgr = new AceCollabExt.AceMultiCursorManager(editor.getSession());

// Add a new remote cursor with an id of "uid1", and a color of orange.
curMgr.addCursor("uid1", "User 1", "orange", {row: 0, column: 10});

// Set cursor for "uid1" to index 10.
curMgr.setCursor("uid1", 10);

// Clear the remote cursor for "uid1" without removing it.
curMgr.clearCursor("uid1");

// Remove the remote cursor for "uid1".
curMgr.removeCursor("uid1");

Multi Selection Manager

The multi selection manager allows you to easily render the selection of other users working in the same document. Selection is represented by an array of AceRanges. A single range is common for normal selection, but multiple ranges are needed to support block selection.

const AceRange = ace.require("ace/range");

const editor = ace.edit("editor");
const selMgr = new AceCollabExt.AceMultiSelectionManager(editor.getSession());

// A two-line block selection
const initialRanges = [
  new AceRange(0, 0, 0, 10),
  new AceRange(1, 0, 1, 10),
];

// Add a new remote view indicator with an id of "uid1", and a color of orange.
selMgr.addSelection("uid1", "User 1", "orange", initialRanges);

// Set the selection to a new range.
selMgr.setSelection("uid1", new AceRange(10, 0, 11, 10));

// Nullify the selection without removing the marker.
selMgr.clearSelection("uid1");

// Remove the remote view indicator for "uid1".
selMgr.removeSelection("uid1");

Radar View

A radar view indicates where in a document another user is looking and allows you to easily go to the location in the document.

const editor = ace.edit("editor");
const radarView = new AceCollabExt.RadarView("radarView", editor);

// Add a new remote view indicator with an id of "uid1", and a color of orange.
radarView.addView("uid1", "user1", "orange", 0, 20, 0);

// Set the viewport range of the indicator to span rows 10 through 40.
radarView.setViewRows("uid1", 10, 40);

// Set the row location of the cursor to line 10.
radarView.setCursorRow("uid1", 10);

// Remove the remote view indicator for "uid1".
radarView.removeView("uid1");

ace-collab-ext's People

Contributors

alalonde avatar cgnonofr avatar mmacfadden avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ace-collab-ext's Issues

AceRadarView.ts:31 Uncaught TypeError: Cannot read properties of null (reading 'style')

I am getting this error when i use radar view

AceRadarView.ts:31 Uncaught TypeError: Cannot read properties of null (reading 'style')

const radarView = new AceCollabExt.AceRadarView(
          'radar-view',
          aceEditor.current.editor.getSession()
        );

        const initialIndices =
          AceCollabExt.AceViewportUtil.getVisibleIndexRange(
            aceEditor.current.editor.getSession()
          );
        const initialRows = AceCollabExt.AceViewportUtil.indicesToRows(
          aceEditor.current.editor.getSession(),
          initialIndices.start,
          initialIndices.end
        );
        radarView.addView(user.userId, user.name, user.color, initialRows, 0);

not able to install

currently am using angular 6 . when i try npm install --save-dev @convergencelabs/ace-collab-ext

"npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@convergencelabs%2face-collab-ext - Not found
npm ERR! 404
npm ERR! 404 '@convergencelabs/ace-collab-ext@latest' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

npm ERR! A complete log of this run can be found in:
"
please check

Integration with ng2-ace-editor npm package

i'm looking to integrate collaborative plugin (npm install --save-dev @convergencelabs/ace-collab-ext) with angular 6's ng2-ace-editor(version 3.9). Package successfully imported but ends with an error message when trying to call
const curMgr = new AceCollabExt.AceMultiCursorManager(this.editor._editor.session); curMgr.addCursor("uid1", "User 1", "orange", {row: 2, column: 2});
ng2-ace-editor is using brace for ace editor configuration. Is there any version mismatch? How can i rectify this. Could you please help me where i have gone wrong.

ng2-ace-editor is using brace for ace setup. how can i update this

AceMultiCursorManager and AceMultiSelectionManager should take EditSession instead of Edit

Currently the AceMultiCursorManager and AceMultiSelectionManager are currently constructed with the Ace Editor like so:

var editor = ace.edit("editor");
var curMgr = new AceCollabExt.AceMultiCursorManager(editor);
var selMgr = new AceCollabExt.AceMultiSelectionManager(editor);

This means that you have to created the editor first, which usually causes a render. Users may wish to initialize the edit session first and set up the cursors and selections before rendering. So these should take the edit session instead. Like so:

var editor = ace.edit("editor");
var curMgr = new AceCollabExt.AceMultiCursorManager(editor.getSession());
var selMgr = new AceCollabExt.AceMultiSelectionManager(editor.getSession());

[Example] What does `../dist/umd/ace-collab-ext.js` refer to? [SOLVED]

Hello! I was going through the example, and then looked into the index.html, file. There is this import, as shown below,

<script src="../dist/umd/ace-collab-ext.js" type="text/javascript" charset="utf-8"></script>

This is a relative import from the root from the repository, but I don't see a dist directory. In the same file, just above this, there is also this stylesheet import,

<link rel="stylesheet" href="../dist/css/ace-collab-ext.css"/>

This now maps to ../src/css/ace-collab-ext.css , but I was unable to resolve this as the same as with the first example. There is no umd directory. There is no ace-collab-ext.js under the ts directory as well.

Thanks!

Remote cursor position stuck at {0, 0}

The index is being transmitted to connected clients. The setup I have now is basically identical to the example. If you look at the "set" listener, both reference.sessionId() and reference.value() are correct. I followed the code and the index (reference.value()) gets converted to the {row,col} formatted properly. This makes it all the way to the addDynamicCursor. So I have no idea where it goes wrong.

I would like to add that I am using react-ace.

const cursorKey = "cursor";
let cursorReference = null;
let cursorManager = null;

const initSharedCursors = (textModel) => {
  cursorManager = new AceCollabExt.AceMultiCursorManager(editor.getSession());
  cursorReference = textModel.indexReference(cursorKey);

  const references = textModel.references({ key: cursorKey });
  references.forEach((ref) => {
    if (!ref.isLocal()) addCursor(ref);
  })

  setLocalCursor();
  cursorReference.share();
  
  editor.getSession().selection.on('changeCursor', () => setLocalCursor());
  
  textModel.on('reference', (e) => {
    if (e.reference.key() === cursorKey) addCursor(e.reference);
  });
}

const setLocalCursor = () => {
  const position = editor.getCursorPosition();
  const index = doc.positionToIndex(position);
  cursorReference.set(index);
}

const addCursor = (reference) => {
  const color = colorAssigner.getColorAsHex(reference.sessionId());
  const remoteCursorIndex = reference.value();
  
  cursorManager.addCursor(reference.sessionId(), reference.user().displayName, color, remoteCursorIndex);
  
  reference.on("cleared", () => cursorManager.clearCursor(reference.sessionId()));
  reference.on("disposed", () => cursorManager.removeCursor(reference.sessionId()));
  reference.on("set", () => {
    cursorManager.setCursor(reference.sessionId(), reference.value())
  });
}

undo behaviour

I've been playing with the Ace demo. I notice when collaborating if you press undo it undoes the other user's changes, which would be confusing when collaborating.

I also observed the following.
user 1: enter 'a', press undo. 'a' disappears as you would expect.
user 2: press undo. 'a' reappears.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.