Skip to content
Snippets Groups Projects
Commit 8029ca69 authored by Giannis Kopanas's avatar Giannis Kopanas
Browse files

feat(services): yjs add cursor color per user

parent 69eb74a0
No related branches found
No related tags found
1 merge request!515Comments title feature
/* eslint-disable no-console */
import { Service } from 'wax-prosemirror-core'; import { Service } from 'wax-prosemirror-core';
import { yCursorPlugin, ySyncPlugin, yUndoPlugin } from 'y-prosemirror'; import { yCursorPlugin, ySyncPlugin, yUndoPlugin } from 'y-prosemirror';
import { WebsocketProvider } from 'y-websocket'; import { WebsocketProvider } from 'y-websocket';
...@@ -7,10 +8,22 @@ import './yjs.css'; ...@@ -7,10 +8,22 @@ import './yjs.css';
class YjsService extends Service { class YjsService extends Service {
name = 'YjsService'; name = 'YjsService';
boot() { boot() {
const { connectionUrl, docIdentifier } = this.config; const {
const ydoc = new Y.Doc(); connectionUrl,
// const provider = new WebsocketProvider('wss://demos.yjs.dev', 'prosemirror-demo', ydoc) docIdentifier,
const provider = new WebsocketProvider(connectionUrl, docIdentifier, ydoc); cursorBuilder,
provider: configProvider,
ydoc: configYdoc,
} = this.config;
let provider = configProvider ? configProvider() : null;
let ydoc = configYdoc ? configYdoc() : null;
if (!configProvider || !configYdoc) {
ydoc = new Y.Doc();
provider = new WebsocketProvider(connectionUrl, docIdentifier, ydoc);
}
provider.on('sync', args => { provider.on('sync', args => {
console.log({ sync: args }); console.log({ sync: args });
}); });
...@@ -23,9 +36,23 @@ class YjsService extends Service { ...@@ -23,9 +36,23 @@ class YjsService extends Service {
provider.on('connection-error', args => { provider.on('connection-error', args => {
console.log({ connectioError: args }); console.log({ connectioError: args });
}); });
const type = ydoc.getXmlFragment('prosemirror'); const type = ydoc.getXmlFragment('prosemirror');
this.app.PmPlugins.add('ySyncPlugin', ySyncPlugin(type)); this.app.PmPlugins.add('ySyncPlugin', ySyncPlugin(type));
this.app.PmPlugins.add('yCursorPlugin', yCursorPlugin(provider.awareness));
if (cursorBuilder) {
this.app.PmPlugins.add(
'yCursorPlugin',
yCursorPlugin(provider.awareness, { cursorBuilder }),
);
} else {
this.app.PmPlugins.add(
'yCursorPlugin',
yCursorPlugin(provider.awareness),
);
}
this.app.PmPlugins.add('yUndoPlugin', yUndoPlugin()); this.app.PmPlugins.add('yUndoPlugin', yUndoPlugin());
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment