mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-12-24 09:27:49 +08:00
9afadeb7fe
* add new addOptions option * replace defaultOptions with addOptions for all extensions * replace defaultOptions with addOptions for all demos * replace defaultOptions with addOptions in docs * refactoring * refactoring * drop object support for addOptions * fix optional options * fix tests
63 lines
1.2 KiB
TypeScript
63 lines
1.2 KiB
TypeScript
import { Extension } from '@tiptap/core'
|
|
import { history, undo, redo } from 'prosemirror-history'
|
|
|
|
export interface HistoryOptions {
|
|
depth: number,
|
|
newGroupDelay: number,
|
|
}
|
|
|
|
declare module '@tiptap/core' {
|
|
interface Commands<ReturnType> {
|
|
history: {
|
|
/**
|
|
* Undo recent changes
|
|
*/
|
|
undo: () => ReturnType,
|
|
/**
|
|
* Reapply reverted changes
|
|
*/
|
|
redo: () => ReturnType,
|
|
}
|
|
}
|
|
}
|
|
|
|
export const History = Extension.create<HistoryOptions>({
|
|
name: 'history',
|
|
|
|
addOptions() {
|
|
return {
|
|
depth: 100,
|
|
newGroupDelay: 500,
|
|
}
|
|
},
|
|
|
|
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.commands.undo(),
|
|
'Mod-y': () => this.editor.commands.redo(),
|
|
'Shift-Mod-z': () => this.editor.commands.redo(),
|
|
|
|
// Russian keyboard layouts
|
|
'Mod-я': () => this.editor.commands.undo(),
|
|
'Shift-Mod-я': () => this.editor.commands.redo(),
|
|
}
|
|
},
|
|
})
|