2020-04-13 19:58:30 +08:00
|
|
|
import { Extension, CommandSpec } from '@tiptap/core'
|
2020-03-06 18:02:35 +08:00
|
|
|
import {
|
|
|
|
history,
|
|
|
|
undo,
|
|
|
|
redo,
|
|
|
|
undoDepth,
|
|
|
|
redoDepth,
|
|
|
|
} from 'prosemirror-history'
|
|
|
|
|
|
|
|
declare module '@tiptap/core/src/Editor' {
|
|
|
|
interface Editor {
|
|
|
|
undo(): Editor,
|
2020-04-02 19:36:18 +08:00
|
|
|
redo(): Editor,
|
2020-03-06 18:02:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 04:32:39 +08:00
|
|
|
interface HistoryOptions {
|
|
|
|
historyPluginOptions?: Object,
|
|
|
|
}
|
|
|
|
|
2020-03-06 18:02:35 +08:00
|
|
|
export default class History extends Extension {
|
|
|
|
|
|
|
|
name = 'history'
|
2020-04-14 04:32:39 +08:00
|
|
|
|
2020-04-14 04:33:43 +08:00
|
|
|
constructor(options?: HistoryOptions) {
|
2020-04-14 04:32:39 +08:00
|
|
|
super(options)
|
|
|
|
}
|
2020-03-06 18:02:35 +08:00
|
|
|
|
2020-04-14 04:32:39 +08:00
|
|
|
defaultOptions(): HistoryOptions {
|
2020-04-13 20:03:39 +08:00
|
|
|
return {
|
|
|
|
historyPluginOptions: {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-02 20:34:07 +08:00
|
|
|
commands(): CommandSpec {
|
|
|
|
return {
|
|
|
|
undo: (next, { view }) => {
|
|
|
|
undo(view.state, view.dispatch)
|
|
|
|
next()
|
|
|
|
},
|
|
|
|
redo: (next, { view }) => {
|
|
|
|
redo(view.state, view.dispatch)
|
|
|
|
next()
|
|
|
|
},
|
|
|
|
}
|
2020-03-06 18:02:35 +08:00
|
|
|
}
|
|
|
|
|
2020-04-02 19:36:18 +08:00
|
|
|
keys() {
|
|
|
|
return {
|
|
|
|
'Mod-z': () => this.editor.undo(),
|
|
|
|
'Mod-y': () => this.editor.redo(),
|
|
|
|
'Shift-Mod-z': () => this.editor.redo(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 06:58:48 +08:00
|
|
|
plugins() {
|
2020-03-06 18:02:35 +08:00
|
|
|
return [
|
2020-04-13 20:03:39 +08:00
|
|
|
history(this.options.historyPluginOptions)
|
2020-03-06 18:02:35 +08:00
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|