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

41 lines
654 B
TypeScript
Raw Normal View History

2020-11-16 06:25:25 +08:00
import { Extension } from '@tiptap/core'
import {
2020-11-25 16:50:54 +08:00
redo,
undo,
ySyncPlugin,
yUndoPlugin,
} from 'y-prosemirror'
2020-09-26 16:43:08 +08:00
export interface CollaborationOptions {
2020-09-26 17:03:17 +08:00
type: any,
}
2020-11-16 06:25:25 +08:00
const Collaboration = Extension.create({
2020-10-22 18:34:49 +08:00
defaultOptions: <CollaborationOptions>{
2020-09-26 16:43:08 +08:00
type: null,
2020-10-22 18:34:49 +08:00
},
addProseMirrorPlugins() {
return [
ySyncPlugin(this.options.type),
yUndoPlugin(),
]
},
addKeyboardShortcuts() {
2020-09-26 17:28:48 +08:00
return {
'Mod-z': undo,
'Mod-y': redo,
'Mod-Shift-z': redo,
2020-09-26 17:28:48 +08:00
}
2020-10-22 18:34:49 +08:00
},
})
2020-10-23 04:40:40 +08:00
export default Collaboration
2020-11-11 04:18:22 +08:00
declare module '@tiptap/core' {
2020-10-23 04:40:40 +08:00
interface AllExtensions {
Collaboration: typeof Collaboration,
}
}