refactor: restructure extensions

This commit is contained in:
Florian Wiech
2020-12-04 20:56:22 +01:00
parent e171f381a8
commit 11de3a287f
31 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
import { Extension, Command } from '@tiptap/core'
import {
redo,
undo,
ySyncPlugin,
yUndoPlugin,
} from 'y-prosemirror'
export interface CollaborationOptions {
provider: any,
}
const Collaboration = Extension.create({
name: 'collaboration',
defaultOptions: <CollaborationOptions>{
provider: null,
},
addCommands() {
return {
/**
* Undo recent changes
*/
undo: (): Command => ({ tr, state }) => {
tr.setMeta('preventDispatch', true)
return undo(state)
},
/**
* Reapply reverted changes
*/
redo: (): Command => ({ tr, state }) => {
tr.setMeta('preventDispatch', true)
return redo(state)
},
}
},
addKeyboardShortcuts() {
return {
'Mod-z': () => this.editor.commands.undo(),
'Mod-y': () => this.editor.commands.redo(),
'Shift-Mod-z': () => this.editor.commands.redo(),
}
},
addProseMirrorPlugins() {
return [
ySyncPlugin(
this.options.provider.doc.getXmlFragment('prosemirror'),
),
yUndoPlugin(),
]
},
onDestroy() {
this.options.provider?.destroy()
},
})
export default Collaboration
declare module '@tiptap/core' {
interface AllExtensions {
Collaboration: typeof Collaboration,
}
}