2020-03-06 18:02:35 +08:00
|
|
|
import Editor, { Extension } from '@tiptap/core'
|
|
|
|
import {
|
|
|
|
history,
|
|
|
|
undo,
|
|
|
|
redo,
|
|
|
|
undoDepth,
|
|
|
|
redoDepth,
|
|
|
|
} from 'prosemirror-history'
|
|
|
|
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
|
|
interface Editor {
|
|
|
|
undo(): Editor,
|
2020-03-06 18:24:58 +08:00
|
|
|
undo(): Editor,
|
2020-03-06 18:02:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class History extends Extension {
|
|
|
|
|
|
|
|
name = 'history'
|
|
|
|
|
|
|
|
init() {
|
|
|
|
this.editor.registerCommand('undo', (next, { view }) => {
|
|
|
|
undo(view.state, view.dispatch)
|
|
|
|
next()
|
|
|
|
})
|
2020-03-06 18:24:58 +08:00
|
|
|
|
|
|
|
this.editor.registerCommand('redo', (next, { view }) => {
|
|
|
|
redo(view.state, view.dispatch)
|
|
|
|
next()
|
|
|
|
})
|
2020-03-06 18:02:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
get plugins() {
|
|
|
|
return [
|
|
|
|
history()
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
// commands() {
|
|
|
|
// return {
|
|
|
|
// undo: () => undo,
|
|
|
|
// redo: () => redo,
|
|
|
|
// undoDepth: () => undoDepth,
|
|
|
|
// redoDepth: () => redoDepth,
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|