add basic yjs extension with baked in web rtc support (wip)
This commit is contained in:
27
packages/extension-yjs/index.ts
Normal file
27
packages/extension-yjs/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Extension } from '@tiptap/core'
|
||||
import { keymap } from 'prosemirror-keymap'
|
||||
import {
|
||||
redo, undo, yCursorPlugin, ySyncPlugin, yUndoPlugin,
|
||||
} from 'y-prosemirror'
|
||||
import { WebrtcProvider } from 'y-webrtc'
|
||||
import * as Y from 'yjs'
|
||||
|
||||
const ydoc = new Y.Doc()
|
||||
const provider = new WebrtcProvider('tiptap', ydoc)
|
||||
const type = ydoc.getXmlFragment('prosemirror')
|
||||
|
||||
export default new Extension()
|
||||
.name('yjs')
|
||||
.plugins(() => {
|
||||
return [
|
||||
ySyncPlugin(type),
|
||||
yCursorPlugin(provider.awareness),
|
||||
yUndoPlugin(),
|
||||
keymap({
|
||||
'Mod-z': undo,
|
||||
'Mod-y': redo,
|
||||
'Mod-Shift-z': redo,
|
||||
}),
|
||||
]
|
||||
})
|
||||
.create()
|
||||
Reference in New Issue
Block a user