add Commands interface

This commit is contained in:
Philipp Kühn
2021-02-10 09:59:35 +01:00
parent 0ed368e9f4
commit 290ff76e37
100 changed files with 695 additions and 487 deletions

View File

@@ -1,4 +1,4 @@
import { Extension, Command } from '@tiptap/core'
import { Extension, Command, AnyObject } from '@tiptap/core'
import { yCursorPlugin } from 'y-prosemirror'
export interface CollaborationCursorOptions {
@@ -8,6 +8,12 @@ export interface CollaborationCursorOptions {
onUpdate: (users: { clientId: string, [key: string]: any }[]) => null,
}
declare module '@tiptap/core' {
interface Commands {
user: (attributes: AnyObject) => Command,
}
}
const awarenessStatesToArray = (states: Map<number, { [key: string]: any }>) => {
return Array.from(states.entries()).map(([key, value]) => {
return {
@@ -47,7 +53,7 @@ export const CollaborationCursor = Extension.create({
/**
* Update details of the current user
*/
user: (attributes: { [key: string]: any }): Command => () => {
user: attributes => () => {
this.options.user = attributes
this.options.provider.awareness.setLocalStateField('user', this.options.user)
@@ -87,9 +93,3 @@ export const CollaborationCursor = Extension.create({
]
},
})
declare module '@tiptap/core' {
interface AllExtensions {
CollaborationCursor: typeof CollaborationCursor,
}
}