forked from yikoyu/vuetify-pro-tiptap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase-kit.ts
193 lines (164 loc) · 5.23 KB
/
base-kit.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// StarterKit
import type { AnyExtension } from '@tiptap/core'
import type { CharacterCountOptions } from '@tiptap/extension-character-count'
import type { DropcursorOptions } from '@tiptap/extension-dropcursor'
import type { FocusOptions } from '@tiptap/extension-focus'
import type { HardBreakOptions } from '@tiptap/extension-hard-break'
import type { ListItemOptions } from '@tiptap/extension-list-item'
import type { ParagraphOptions } from '@tiptap/extension-paragraph'
import type { PlaceholderOptions } from '@tiptap/extension-placeholder'
import type { TextStyleOptions } from '@tiptap/extension-text-style'
import type { BubbleOptions } from './components/bubble'
import { NODE_TYPE_MENU } from '@/constants/define'
import { Extension } from '@tiptap/core'
import { CharacterCount } from '@tiptap/extension-character-count'
import { Document } from '@tiptap/extension-document'
import { Dropcursor } from '@tiptap/extension-dropcursor'
import Focus from '@tiptap/extension-focus'
import { Gapcursor } from '@tiptap/extension-gapcursor'
import { HardBreak } from '@tiptap/extension-hard-break'
import { ListItem } from '@tiptap/extension-list-item'
import { Paragraph } from '@tiptap/extension-paragraph'
import { Placeholder } from '@tiptap/extension-placeholder'
import { Text } from '@tiptap/extension-text'
import { TextStyle } from '@tiptap/extension-text-style'
import { defaultBubbleList, generateBubbleTypeMenu } from './components/bubble'
/**
* Represents the interface for options in the base toolkit.
*/
export interface BaseKitOptions {
/**
* Whether to enable the document option
*
* @default true
*/
document: false
/**
* Whether to enable the text option
*
* @default true
*/
text: false
/**
* Whether to enable the Gapcursor
*
* @default true
*/
gapcursor: false
/**
* Dropcursor options or false, indicating whether to enable the drop cursor
*
* @default true
*/
dropcursor: Partial<DropcursorOptions> | false
/**
* character count options or false, indicating whether to enable character count
*
* @default true
*/
characterCount: Partial<CharacterCountOptions> | false
/**
* HardBreak options or false, indicating whether to enable hard breaks
*
* @default true
*/
hardBreak: Partial<HardBreakOptions> | false
/**
* Placeholder options or false, indicating whether to enable placeholders
*
* @default true
*/
placeholder: Partial<PlaceholderOptions> | false
/**
* Paragraph options or false, indicating whether to enable paragraph functionality
*
* @default true
*/
paragraph: Partial<ParagraphOptions> | false
/**
* Focus options or false, indicating whether to enable focus functionality
*
* @default true
*/
focus: Partial<FocusOptions> | false
/**
* ListItem options or false, indicating whether to enable list item functionality
*
* @default true
*/
listItem: Partial<ListItemOptions> | false
/**
* Text Style options or false, indicating whether to enable text style functionality
*
* @default true
*/
textStyle: Partial<TextStyleOptions> | false
/**
* Bubble options, taking `BubbleOptions<BaseKitOptions>` as parameters, indicating whether to enable the bubble functionality
*/
bubble: Partial<BubbleOptions<BaseKitOptions>>
}
export const BaseKit = /* @__PURE__*/ Extension.create<BaseKitOptions>({
name: 'base-kit',
addOptions() {
return {
...this.parent?.(),
bubble: {
list: NODE_TYPE_MENU,
defaultBubbleList,
button: ({ editor, extension, t }) => {
const { list = {}, defaultBubbleList } = extension.options?.bubble ?? {}
const defaultList = defaultBubbleList?.(editor) ?? []
return generateBubbleTypeMenu(list, defaultList, { editor, extension, t })
}
}
}
},
addExtensions() {
const extensions: AnyExtension[] = []
if (this.options.placeholder !== false) {
extensions.push(
Placeholder.configure({
placeholder: '',
...this.options.placeholder
})
)
}
if (this.options.focus !== false) {
extensions.push(
Focus.configure({
className: 'focus',
...this.options.focus
})
)
}
if (this.options.document !== false) {
extensions.push(Document.configure())
}
if (this.options.text !== false) {
extensions.push(Text.configure())
}
if (this.options.gapcursor !== false) {
extensions.push(Gapcursor.configure())
}
if (this.options.dropcursor !== false) {
extensions.push(Dropcursor.configure(this.options.dropcursor))
}
if (this.options.characterCount !== false) {
extensions.push(CharacterCount.configure(this.options.characterCount))
}
if (this.options.paragraph !== false) {
extensions.push(Paragraph.configure(this.options.paragraph))
}
if (this.options.hardBreak !== false) {
extensions.push(HardBreak.configure(this.options.hardBreak))
}
if (this.options.listItem !== false) {
extensions.push(ListItem.configure(this.options.listItem))
}
if (this.options.textStyle !== false) {
extensions.push(TextStyle.configure(this.options.textStyle))
}
return extensions
}
})