add new collaboration cursor plugin
This commit is contained in:
27
packages/extension-collaboration-cursor/index.ts
Normal file
27
packages/extension-collaboration-cursor/index.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Extension } from '@tiptap/core'
|
||||
import { yCursorPlugin } from 'y-prosemirror'
|
||||
|
||||
export interface CollaborationCursorOptions {
|
||||
name: string,
|
||||
color: string,
|
||||
provider: any,
|
||||
}
|
||||
|
||||
export default new Extension<CollaborationCursorOptions>()
|
||||
.name('collaboration_cursor')
|
||||
.defaults({
|
||||
provider: null,
|
||||
name: 'Someone',
|
||||
color: '#cccccc',
|
||||
})
|
||||
.plugins(({ options }) => [
|
||||
yCursorPlugin((() => {
|
||||
options.provider.awareness.setLocalStateField('user', {
|
||||
name: options.name,
|
||||
color: options.color,
|
||||
})
|
||||
|
||||
return options.provider.awareness
|
||||
})()),
|
||||
])
|
||||
.create()
|
||||
22
packages/extension-collaboration-cursor/package.json
Normal file
22
packages/extension-collaboration-cursor/package.json
Normal file
@@ -0,0 +1,22 @@
|
||||
{
|
||||
"name": "@tiptap/extension-collaboration-cursor",
|
||||
"version": "1.0.0",
|
||||
"source": "index.ts",
|
||||
"main": "dist/tiptap-extension-collaboration-cursor.js",
|
||||
"umd:main": "dist/tiptap-extension-collaboration-cursor.umd.js",
|
||||
"module": "dist/tiptap-extension-collaboration-cursor.mjs",
|
||||
"unpkg": "dist/tiptap-extension-collaboration-cursor.js",
|
||||
"jsdelivr": "dist/tiptap-extension-collaboration-cursor.js",
|
||||
"files": [
|
||||
"src",
|
||||
"dist"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@tiptap/core": "2.x"
|
||||
},
|
||||
"dependencies": {
|
||||
"y-prosemirror": "^0.3.7",
|
||||
"y-webrtc": "^10.1.6",
|
||||
"yjs": "^13.3.2"
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user