-
Notifications
You must be signed in to change notification settings - Fork 31
/
color.ts
33 lines (28 loc) · 1.03 KB
/
color.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 { ColorOptions as TiptapColorOptions } from '@tiptap/extension-color'
import { Color as TiptapColor } from '@tiptap/extension-color'
import ColorActionButton from './components/ColorActionButton.vue'
export interface ColorOptions extends TiptapColorOptions, GeneralOptions<ColorOptions> {}
export const Color = /* @__PURE__*/ TiptapColor.extend<ColorOptions>({
addOptions() {
return {
...this.parent?.(),
button: ({ editor, t }) => ({
component: ColorActionButton,
componentProps: {
action: (color?: unknown) => {
if (typeof color === 'string') editor.commands.setColor(color)
},
isActive: () => {
const { color } = editor.getAttributes('textStyle')
if (!color) return false
return editor.isActive({ color }) || false
},
disabled: !editor.can().setColor(''),
icon: 'color',
tooltip: t('editor.color.tooltip')
}
})
}
}
})