-
Notifications
You must be signed in to change notification settings - Fork 31
/
heading.ts
56 lines (48 loc) · 1.98 KB
/
heading.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
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { GeneralOptions } from '@/type'
import type { Extension } from '@tiptap/core'
import type { HeadingOptions as TiptapHeadingOptions } from '@tiptap/extension-heading'
import type { BaseKitOptions } from './base-kit'
import type { Item } from './components/ActionMenuButton.vue'
import { Heading as TiptapHeading } from '@tiptap/extension-heading'
import ActionMenuButton from './components/ActionMenuButton.vue'
export interface HeadingOptions extends TiptapHeadingOptions, GeneralOptions<HeadingOptions> {}
export const Heading = /* @__PURE__*/ TiptapHeading.extend<HeadingOptions>({
addOptions() {
return {
...this.parent?.(),
levels: [1, 2, 3, 4, 5, 6],
button: ({ editor, extension, t }) => {
const { extensions = [] } = editor.extensionManager ?? []
const levels = extension.options?.levels || []
const baseKitExt = extensions.find(k => k.name === 'base-kit') as Extension<BaseKitOptions>
const items: Item[] = levels.map(level => ({
action: () => editor.commands.toggleHeading({ level }),
isActive: () => editor.isActive('heading', { level }) || false,
disabled: !editor.can().toggleHeading({ level }),
icon: `h${level}`,
title: t(`editor.heading.h${level}.tooltip`)
}))
if (baseKitExt && baseKitExt.options.paragraph !== false) {
items.unshift({
action: () => editor.commands.setParagraph(),
isActive: () => editor.isActive('paragraph') || false,
disabled: !editor.can().setParagraph(),
icon: 'p',
title: t('editor.paragraph.tooltip'),
divider: true
})
}
const disabled = items.filter(k => k.disabled).length === items.length
return {
component: ActionMenuButton,
componentProps: {
icon: 'heading',
tooltip: t('editor.heading.tooltip'),
disabled,
items
}
}
}
}
}
})