add command to update username and color, add UI to show other users

This commit is contained in:
Hans Pagel
2020-09-26 17:35:07 +02:00
parent 0597936ab8
commit 79113aa394
3 changed files with 124 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
import { Extension } from '@tiptap/core'
import { Extension, Command } from '@tiptap/core'
import { yCursorPlugin } from 'y-prosemirror'
export interface CollaborationCursorOptions {
@@ -8,8 +8,26 @@ export interface CollaborationCursorOptions {
render (user: { name: string, color: string }): HTMLElement,
}
export type UserCommand = (attributes: {
name: string,
color: string,
}) => Command
declare module '@tiptap/core/src/Editor' {
interface Commands {
user: UserCommand,
}
}
export default new Extension<CollaborationCursorOptions>()
.name('collaboration_cursor')
.commands(({ options }) => ({
user: attributes => () => {
options.provider.awareness.setLocalStateField('user', attributes)
return true
},
}))
.defaults({
provider: null,
name: 'Someone',