add new collaboration cursor plugin
This commit is contained in:
@@ -8,6 +8,9 @@ import Document from '@tiptap/extension-document'
|
|||||||
import Paragraph from '@tiptap/extension-paragraph'
|
import Paragraph from '@tiptap/extension-paragraph'
|
||||||
import Text from '@tiptap/extension-text'
|
import Text from '@tiptap/extension-text'
|
||||||
import Collaboration from '@tiptap/extension-collaboration'
|
import Collaboration from '@tiptap/extension-collaboration'
|
||||||
|
import CollaborationCursor from '@tiptap/extension-collaboration-cursor'
|
||||||
|
import * as Y from 'yjs'
|
||||||
|
import { WebrtcProvider } from 'y-webrtc'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -16,11 +19,18 @@ export default {
|
|||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
ydoc: null,
|
||||||
|
provider: null,
|
||||||
|
type: null,
|
||||||
editor: null,
|
editor: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
|
this.ydoc = new Y.Doc()
|
||||||
|
this.provider = new WebrtcProvider('example', this.ydoc)
|
||||||
|
this.type = this.ydoc.getXmlFragment('prosemirror')
|
||||||
|
|
||||||
this.editor = new Editor({
|
this.editor = new Editor({
|
||||||
// TODO: This is added by every new user.
|
// TODO: This is added by every new user.
|
||||||
// content: `
|
// content: `
|
||||||
@@ -31,6 +41,11 @@ export default {
|
|||||||
Paragraph(),
|
Paragraph(),
|
||||||
Text(),
|
Text(),
|
||||||
Collaboration({
|
Collaboration({
|
||||||
|
provider: this.provider,
|
||||||
|
type: this.type,
|
||||||
|
}),
|
||||||
|
CollaborationCursor({
|
||||||
|
provider: this.provider,
|
||||||
name: 'Other User',
|
name: 'Other User',
|
||||||
color: '#d6336c',
|
color: '#d6336c',
|
||||||
}),
|
}),
|
||||||
@@ -40,6 +55,7 @@ export default {
|
|||||||
|
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
this.editor.destroy()
|
this.editor.destroy()
|
||||||
|
this.provider.destroy()
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
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 { Extension } from '@tiptap/core'
|
||||||
import * as Y from 'yjs'
|
|
||||||
import {
|
import {
|
||||||
redo, undo, yCursorPlugin, ySyncPlugin, yUndoPlugin,
|
redo, undo, ySyncPlugin, yUndoPlugin,
|
||||||
} from 'y-prosemirror'
|
} from 'y-prosemirror'
|
||||||
import { WebrtcProvider } from 'y-webrtc'
|
|
||||||
import { keymap } from 'prosemirror-keymap'
|
import { keymap } from 'prosemirror-keymap'
|
||||||
|
|
||||||
export interface CollaborationOptions {
|
export interface CollaborationOptions {
|
||||||
name: string,
|
provider: any,
|
||||||
color: string,
|
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>()
|
export default new Extension<CollaborationOptions>()
|
||||||
.name('collaboration')
|
.name('collaboration')
|
||||||
.defaults({
|
.defaults({
|
||||||
name: 'Someone',
|
|
||||||
color: '#cccccc',
|
|
||||||
provider: null,
|
provider: null,
|
||||||
type: null,
|
type: null,
|
||||||
})
|
})
|
||||||
.plugins(({ options }) => [
|
.plugins(({ options }) => [
|
||||||
// Collaboration
|
ySyncPlugin(options.type),
|
||||||
ySyncPlugin(type),
|
|
||||||
yUndoPlugin(),
|
yUndoPlugin(),
|
||||||
keymap({
|
keymap({
|
||||||
'Mod-z': undo,
|
'Mod-z': undo,
|
||||||
'Mod-y': redo,
|
'Mod-y': redo,
|
||||||
'Mod-Shift-z': redo,
|
'Mod-Shift-z': redo,
|
||||||
}),
|
}),
|
||||||
|
|
||||||
// CollaborationCursor
|
|
||||||
yCursorPlugin((() => {
|
|
||||||
provider.awareness.setLocalStateField('user', { name: options.name, color: options.color })
|
|
||||||
|
|
||||||
return provider.awareness
|
|
||||||
})()),
|
|
||||||
])
|
])
|
||||||
.create()
|
.create()
|
||||||
|
|||||||
Reference in New Issue
Block a user