tiptap/packages/extension-history/src/history.ts

63 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-06-05 03:56:29 +08:00
import { Extension } from '@tiptap/core'
feat(pm): new prosemirror package for dependency resolving * chore:(core): migrate to tsup * chore: migrate blockquote and bold to tsup * chore: migrated bubble-menu and bullet-list to tsup * chore: migrated more packages to tsup * chore: migrate code and character extensions to tsup * chore: update package.json to simplify build for all packages * chore: move all packages to tsup as a build process * chore: change ci build task * feat(pm): add prosemirror meta package * rfix: resolve issues with build paths & export mappings * docs: update documentation to include notes for @tiptap/pm * chore(pm): update tsconfig * chore(packages): update packages * fix(pm): add package export infos & fix dependencies * chore(general): start moving to pm package as deps * chore: move to tiptap pm package internally * fix(demos): fix demos working with new pm package * fix(tables): fix tables package * fix(tables): fix tables package * chore(demos): pinned typescript version * chore: remove unnecessary tsconfig * chore: fix netlify build * fix(demos): fix package resolving for pm packages * fix(tests): fix package resolving for pm packages * fix(tests): fix package resolving for pm packages * chore(tests): fix tests not running correctly after pm package * chore(pm): add files to files array * chore: update build workflow * chore(tests): increase timeout time back to 12s * chore(docs): update docs * chore(docs): update installation guides & pm information to docs * chore(docs): add link to prosemirror docs * fix(vue-3): add missing build step * chore(docs): comment out cdn link * chore(docs): remove semicolons from docs * chore(docs): remove unnecessary installation note * chore(docs): remove unnecessary installation note
2023-02-03 00:37:33 +08:00
import { history, redo, undo } from '@tiptap/pm/history'
2020-03-06 18:02:35 +08:00
2020-09-10 00:55:19 +08:00
export interface HistoryOptions {
2020-09-28 03:29:51 +08:00
depth: number,
newGroupDelay: number,
2020-04-14 04:32:39 +08:00
}
2021-02-10 16:59:35 +08:00
declare module '@tiptap/core' {
2021-06-05 03:56:29 +08:00
interface Commands<ReturnType> {
2021-02-16 18:27:58 +08:00
history: {
/**
* Undo recent changes
*/
2021-06-05 03:56:29 +08:00
undo: () => ReturnType,
2021-02-16 18:27:58 +08:00
/**
* Reapply reverted changes
*/
2021-06-05 03:56:29 +08:00
redo: () => ReturnType,
2021-02-16 18:27:58 +08:00
}
2021-02-10 16:59:35 +08:00
}
}
2021-02-11 01:25:08 +08:00
export const History = Extension.create<HistoryOptions>({
2020-12-01 21:55:11 +08:00
name: 'history',
addOptions() {
return {
depth: 100,
newGroupDelay: 500,
}
2020-10-22 18:34:49 +08:00
},
addCommands() {
return {
2021-02-10 16:59:35 +08:00
undo: () => ({ state, dispatch }) => {
2020-10-22 18:34:49 +08:00
return undo(state, dispatch)
},
2021-02-10 16:59:35 +08:00
redo: () => ({ state, dispatch }) => {
2020-10-22 18:34:49 +08:00
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(),
2021-07-15 05:51:53 +08:00
// Russian keyboard layouts
'Mod-я': () => this.editor.commands.undo(),
'Shift-Mod-я': () => this.editor.commands.redo(),
2020-10-22 18:34:49 +08:00
}
},
})