replace extensions

This commit is contained in:
Philipp Kühn
2020-09-08 23:44:45 +02:00
parent 678b6444d2
commit 26ecc20a50
16 changed files with 590 additions and 491 deletions

View File

@@ -1,4 +1,4 @@
import { Extension, CommandSpec } from '@tiptap/core'
import { Extension } from '@tiptap/core'
import {
history,
undo,
@@ -15,48 +15,30 @@ declare module '@tiptap/core/src/Editor' {
}
interface HistoryOptions {
historyPluginOptions?: Object,
historyPluginOptions: Object,
}
export default class History extends Extension {
name = 'history'
constructor(options: Partial<HistoryOptions> = {}) {
super(options)
}
defaultOptions(): HistoryOptions {
return {
historyPluginOptions: {},
}
}
commands(): CommandSpec {
return {
undo: (next, { view }) => () => {
undo(view.state, view.dispatch)
next()
},
redo: (next, { view }) => () => {
redo(view.state, view.dispatch)
next()
},
}
}
keys() {
return {
'Mod-z': () => this.editor.undo(),
'Mod-y': () => this.editor.redo(),
'Shift-Mod-z': () => this.editor.redo(),
}
}
plugins() {
return [
history(this.options.historyPluginOptions)
]
}
}
export default new Extension<HistoryOptions>()
.name('history')
.defaults({
historyPluginOptions: {},
})
.commands(() => ({
undo: (next, { view }) => () => {
undo(view.state, view.dispatch)
next()
},
redo: (next, { view }) => () => {
redo(view.state, view.dispatch)
next()
},
}))
.keys(({ editor }) => ({
'Mod-z': () => editor.undo(),
'Mod-y': () => editor.redo(),
'Shift-Mod-z': () => editor.redo(),
}))
.plugins(({ options }) => [
history(options.historyPluginOptions)
])
.create()