forked from yikoyu/vuetify-pro-tiptap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext-align.ts
43 lines (36 loc) · 1.37 KB
/
text-align.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
38
39
40
41
42
43
import type { TextAlignOptions as TiptapTextAlignOptions } from '@tiptap/extension-text-align'
import { TextAlign as TiptapTextAlign } from '@tiptap/extension-text-align'
import type { Item } from './components/ActionMenuButton.vue'
import ActionMenuButton from './components/ActionMenuButton.vue'
import type { ButtonView, GeneralOptions } from '@/type'
type Alignments = 'left' | 'center' | 'right' | 'justify'
export interface TextAlignOptions extends TiptapTextAlignOptions, GeneralOptions {
button: ButtonView<TextAlignOptions>
alignments: Alignments[]
options: TextAlignOptions
}
export const TextAlign = /* @__PURE__*/ TiptapTextAlign.extend<TextAlignOptions>({
addOptions() {
return {
...this.parent?.(),
types: ['heading', 'paragraph', 'image'],
button: ({ editor, extension, t }) => {
const alignments = (extension.options?.alignments as Alignments[]) || []
const items: Item[] = alignments.map(k => ({
title: t(`editor.textalign.${k}.tooltip`),
icon: k,
isActive: () => editor.isActive({ textAlign: k }) || false,
action: () => editor.commands.setTextAlign(k)
}))
return {
component: ActionMenuButton,
componentProps: {
icon: 'center',
tooltip: t('editor.textalign.tooltip'),
items
}
}
}
}
}
})