-
Notifications
You must be signed in to change notification settings - Fork 31
/
history.ts
33 lines (28 loc) · 1 KB
/
history.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import type { GeneralOptions } from '@/type'
import type { HistoryOptions as TiptapHistoryOptions } from '@tiptap/extension-history'
import { History as TiptapHistory } from '@tiptap/extension-history'
import ActionButton from './components/ActionButton.vue'
export interface HistoryOptions extends TiptapHistoryOptions, GeneralOptions<HistoryOptions> {}
export const History = /* @__PURE__*/ TiptapHistory.extend<HistoryOptions>({
addOptions() {
return {
...this.parent?.(),
depth: 10,
button: ({ editor, t }) => {
const historys: ['undo', 'redo'] = ['undo', 'redo']
return historys.map(item => ({
component: ActionButton,
componentProps: {
action: () => {
if (item === 'undo') editor.commands.undo()
if (item === 'redo') editor.commands.redo()
},
disabled: !editor.can()[item](),
icon: item,
tooltip: t(`editor.${item}.tooltip`)
}
}))
}
}
}
})