-
Notifications
You must be signed in to change notification settings - Fork 32
/
markdown-theme.ts
59 lines (51 loc) · 1.7 KB
/
markdown-theme.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
57
58
59
import type { MarkdownThemeProps } from '@/constants/define'
import type { GeneralOptions } from '@/type'
import type { Item } from './components/ActionMenuButton.vue'
import { DEFAULT_MARKDOWN_THEME_LIST } from '@/constants/define'
import { useContext } from '@/hooks'
import { Extension } from '@tiptap/core'
import ActionMenuButton from './components/ActionMenuButton.vue'
/**
* Represents the interface for Markdown theme options, extending GeneralOptions.
*/
export interface MarkdownThemeOptions extends GeneralOptions<MarkdownThemeOptions> {
/**
* List of available Markdown theme properties
*
* @default DEFAULT_MARKDOWN_THEME_LIST
*/
markdownThemes: MarkdownThemeProps[]
}
export const MarkdownTheme = /* @__PURE__*/ Extension.create<MarkdownThemeOptions>({
name: 'markdownTheme',
addOptions() {
return {
...this.parent?.(),
markdownThemes: DEFAULT_MARKDOWN_THEME_LIST,
button: ({ editor, extension, t }) => {
const { state } = useContext()
const markdownThemes =
[...DEFAULT_MARKDOWN_THEME_LIST, ...extension.options.markdownThemes] as MarkdownThemeProps[]
const items: Item[] = markdownThemes.map(k => ({
title: t(k.title),
isActive: () => {
return state.defaultMarkdownTheme === k.value
},
action: () => {
state.defaultMarkdownTheme = k.value
},
divider: k.divider ?? false,
default: k.default ?? false
}))
return {
component: ActionMenuButton,
componentProps: {
icon: 'markdownTheme',
tooltip: t('editor.markdownTheme.tooltip'),
items
}
}
}
}
}
})