-
Notifications
You must be signed in to change notification settings - Fork 31
/
subscript.ts
85 lines (71 loc) · 2.72 KB
/
subscript.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import type { ButtonViewReturn, GeneralOptions } from '@/type'
import type { Extensions } from '@tiptap/core'
import type { SubscriptExtensionOptions as TiptapSubscriptOptions } from '@tiptap/extension-subscript'
import type { SuperscriptExtensionOptions as TiptapSuperscriptOptions } from '@tiptap/extension-superscript'
import { Extension } from '@tiptap/core'
import { Subscript as TiptapSubscript } from '@tiptap/extension-subscript'
import { Superscript as TiptapSuperscript } from '@tiptap/extension-superscript'
import ActionButton from './components/ActionButton.vue'
/**
* Represents the interface for subscript and superscript options, extending GeneralOptions.
*/
export interface SubAndSuperScriptOptions extends GeneralOptions<SubAndSuperScriptOptions> {
/**
* subscript options or false, indicating whether subscript is enabled
*
* @default true
*/
subscript: Partial<TiptapSubscriptOptions> | false
/**
* superscript options or false, indicating whether superscript is enabled
*
* @default true
*/
superscript: Partial<TiptapSuperscriptOptions> | false
}
export const SubAndSuperScript = /* @__PURE__*/ Extension.create<SubAndSuperScriptOptions>({
name: 'subAndSuperScript',
addOptions() {
return {
...this.parent?.(),
button: ({ editor, extension, t }) => {
const subscript = extension.options.subscript
const superscript = extension.options.superscript
const subBtn: ButtonViewReturn = {
component: ActionButton,
componentProps: {
action: () => editor.commands.toggleSubscript(),
isActive: () => editor.isActive('subscript') || false,
disabled: !editor.can().toggleSubscript(),
icon: 'subscript',
tooltip: t('editor.subscript.tooltip')
}
}
const superBtn: ButtonViewReturn = {
component: ActionButton,
componentProps: {
action: () => editor.commands.toggleSuperscript(),
isActive: () => editor.isActive('superscript') || false,
disabled: !editor.can().toggleSuperscript(),
icon: 'superscript',
tooltip: t('editor.superscript.tooltip')
}
}
const items: ButtonViewReturn[] = []
if (subscript !== false) items.push(subBtn)
if (superscript !== false) items.push(superBtn)
return items
}
}
},
addExtensions() {
const extensions: Extensions = []
if (this.options.subscript !== false) {
extensions.push(TiptapSubscript.configure(this.options.subscript))
}
if (this.options.superscript !== false) {
extensions.push(TiptapSuperscript.configure(this.options.superscript))
}
return extensions
}
})