add new collaboration cursor plugin

This commit is contained in:
Hans Pagel
2020-09-26 11:03:17 +02:00
parent 90f127b8a6
commit 6190380e75
4 changed files with 69 additions and 22 deletions

View File

@@ -1,45 +1,27 @@
import { Extension } from '@tiptap/core'
import * as Y from 'yjs'
import {
redo, undo, yCursorPlugin, ySyncPlugin, yUndoPlugin,
redo, undo, ySyncPlugin, yUndoPlugin,
} from 'y-prosemirror'
import { WebrtcProvider } from 'y-webrtc'
import { keymap } from 'prosemirror-keymap'
export interface CollaborationOptions {
name: string,
color: string,
provider?: any,
type?: any,
provider: any,
type: any,
}
const ydoc = new Y.Doc()
const provider = new WebrtcProvider('example', ydoc)
const type = ydoc.getXmlFragment('prosemirror')
export default new Extension<CollaborationOptions>()
.name('collaboration')
.defaults({
name: 'Someone',
color: '#cccccc',
provider: null,
type: null,
})
.plugins(({ options }) => [
// Collaboration
ySyncPlugin(type),
ySyncPlugin(options.type),
yUndoPlugin(),
keymap({
'Mod-z': undo,
'Mod-y': redo,
'Mod-Shift-z': redo,
}),
// CollaborationCursor
yCursorPlugin((() => {
provider.awareness.setLocalStateField('user', { name: options.name, color: options.color })
return provider.awareness
})()),
])
.create()