Files
tiptap/packages/extension-history/src/index.ts
Philipp Kühn 0c9ce26c02 Revert "use global namespace"
This reverts commit 24c3a9abd3.

# Conflicts:
#	packages/core/src/Editor.ts
2020-11-16 16:58:30 +01:00

54 lines
1.0 KiB
TypeScript

import { Command, Extension } from '@tiptap/core'
import { history, undo, redo } from 'prosemirror-history'
export interface HistoryOptions {
depth: number,
newGroupDelay: number,
}
const History = Extension.create({
defaultOptions: <HistoryOptions>{
depth: 100,
newGroupDelay: 500,
},
addCommands() {
return {
/**
* Undo recent changes
*/
undo: (): Command => ({ state, dispatch }) => {
return undo(state, dispatch)
},
/**
* Reapply reverted changes
*/
redo: (): Command => ({ state, dispatch }) => {
return redo(state, dispatch)
},
}
},
addProseMirrorPlugins() {
return [
history(this.options),
]
},
addKeyboardShortcuts() {
return {
'Mod-z': () => this.editor.commands.undo(),
'Mod-y': () => this.editor.commands.redo(),
'Shift-Mod-z': () => this.editor.commands.redo(),
}
},
})
export default History
declare module '@tiptap/core' {
interface AllExtensions {
History: typeof History,
}
}