add new syntax to all extensions
This commit is contained in:
@@ -1,42 +1,52 @@
|
||||
import { Command, Extension } from '@tiptap/core'
|
||||
import { Command, createExtension } from '@tiptap/core'
|
||||
import {
|
||||
history,
|
||||
undo,
|
||||
redo,
|
||||
} from 'prosemirror-history'
|
||||
|
||||
declare module '@tiptap/core/src/Editor' {
|
||||
interface Commands {
|
||||
undo: () => Command,
|
||||
redo: () => Command,
|
||||
}
|
||||
}
|
||||
// declare module '@tiptap/core/src/Editor' {
|
||||
// interface Commands {
|
||||
// undo: () => Command,
|
||||
// redo: () => Command,
|
||||
// }
|
||||
// }
|
||||
|
||||
export interface HistoryOptions {
|
||||
depth: number,
|
||||
newGroupDelay: number,
|
||||
}
|
||||
|
||||
export default new Extension<HistoryOptions>()
|
||||
.name('history')
|
||||
.defaults({
|
||||
export default createExtension({
|
||||
name: 'history',
|
||||
|
||||
defaultOptions: <HistoryOptions>{
|
||||
depth: 100,
|
||||
newGroupDelay: 500,
|
||||
})
|
||||
.commands(() => ({
|
||||
undo: () => ({ state, dispatch }) => {
|
||||
return undo(state, dispatch)
|
||||
},
|
||||
redo: () => ({ state, dispatch }) => {
|
||||
return redo(state, dispatch)
|
||||
},
|
||||
}))
|
||||
.keys(({ editor }) => ({
|
||||
'Mod-z': () => editor.undo(),
|
||||
'Mod-y': () => editor.redo(),
|
||||
'Shift-Mod-z': () => editor.redo(),
|
||||
}))
|
||||
.plugins(({ options }) => [
|
||||
history(options),
|
||||
])
|
||||
.create()
|
||||
},
|
||||
|
||||
addCommands() {
|
||||
return {
|
||||
undo: () => ({ state, dispatch }) => {
|
||||
return undo(state, dispatch)
|
||||
},
|
||||
redo: () => ({ state, dispatch }) => {
|
||||
return redo(state, dispatch)
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
addProseMirrorPlugins() {
|
||||
return [
|
||||
history(this.options),
|
||||
]
|
||||
},
|
||||
|
||||
addKeyboardShortcuts() {
|
||||
return {
|
||||
'Mod-z': () => this.editor.undo(),
|
||||
'Mod-y': () => this.editor.redo(),
|
||||
'Shift-Mod-z': () => this.editor.redo(),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user