-
Notifications
You must be signed in to change notification settings - Fork 26
/
indent.ts
37 lines (32 loc) · 1.05 KB
/
indent.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
34
35
36
37
import { Extension } from '@tiptap/core'
import ActionButton from './components/ActionButton.vue'
import type { GeneralOptions } from '@/type'
export interface IndentOptions extends GeneralOptions<IndentOptions> {}
export const Indent = /* @__PURE__*/ Extension.create<IndentOptions>({
name: 'indent',
addOptions() {
return {
divider: false,
spacer: false,
button: ({ editor, t }) => {
const items: ['indent', 'outdent'] = ['indent', 'outdent']
const commands = {
indent: 'sinkListItem',
outdent: 'liftListItem'
} as const
return items.map(item => ({
component: ActionButton,
componentProps: {
action: () => {
if (item === 'indent') editor.commands.sinkListItem('listItem')
if (item === 'outdent') editor.commands.liftListItem('listItem')
},
disabled: !editor.can()[commands[item]]('listItem'),
icon: item,
tooltip: t(`editor.${item}.tooltip`)
}
}))
}
}
}
})