tiptap/packages/extension-collaboration-cursor/index.ts

28 lines
615 B
TypeScript
Raw Normal View History

2020-09-26 17:03:17 +08:00
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()