1
+ import { imageBlockSchema } from '@milkdown/kit/component/image-block'
1
2
import { editorViewCtx } from '@milkdown/kit/core'
3
+ import type { Ctx } from '@milkdown/kit/ctx'
2
4
import {
3
5
blockquoteSchema ,
4
6
bulletListSchema ,
@@ -9,13 +11,15 @@ import {
9
11
orderedListSchema ,
10
12
paragraphSchema ,
11
13
} from '@milkdown/kit/preset/commonmark'
12
- import { TextSelection } from '@milkdown/kit/prose/state'
13
- import { imageBlockSchema } from '@milkdown/kit/component/image-block'
14
14
import { createTable } from '@milkdown/kit/preset/gfm'
15
+ import { TextSelection } from '@milkdown/kit/prose/state'
16
+ import { CrepeFeature } from '../../..'
17
+ import { FeaturesCtx } from '../../../core/slice'
15
18
import {
16
19
bulletListIcon ,
17
20
codeIcon ,
18
21
dividerIcon ,
22
+ functionsIcon ,
19
23
h1Icon ,
20
24
h2Icon ,
21
25
h3Icon ,
@@ -28,20 +32,16 @@ import {
28
32
tableIcon ,
29
33
textIcon ,
30
34
todoListIcon ,
31
- functionsIcon ,
32
35
} from '../../../icons'
33
36
import type { BlockEditFeatureConfig } from '../index'
37
+ import { GroupBuilder } from './group-builder'
34
38
import type { MenuItemGroup } from './utils'
35
39
import {
36
40
clearContentAndAddBlockType ,
37
41
clearContentAndSetBlockType ,
38
42
clearContentAndWrapInBlockType ,
39
43
clearRange ,
40
44
} from './utils'
41
- import { GroupBuilder } from './group-builder'
42
- import type { Ctx } from '@milkdown/kit/ctx'
43
- import { FeaturesCtx } from '../../../core/slice'
44
- import { CrepeFeature } from '../../..'
45
45
46
46
export function getGroups (
47
47
filter ?: string ,
@@ -50,6 +50,8 @@ export function getGroups(
50
50
) {
51
51
const flags = ctx ?. get ( FeaturesCtx )
52
52
const isLatexEnabled = flags ?. includes ( CrepeFeature . Latex )
53
+ const isImageBlockEnabled = flags ?. includes ( CrepeFeature . ImageBlock )
54
+ const isTableEnabled = flags ?. includes ( CrepeFeature . Table )
53
55
54
56
const groupBuilder = new GroupBuilder ( )
55
57
groupBuilder
@@ -211,9 +213,13 @@ export function getGroups(
211
213
} ,
212
214
} )
213
215
214
- const advancedGroup = groupBuilder
215
- . addGroup ( 'advanced' , config ?. slashMenuAdvancedGroupLabel ?? 'Advanced' )
216
- . addItem ( 'image' , {
216
+ const advancedGroup = groupBuilder . addGroup (
217
+ 'advanced' ,
218
+ config ?. slashMenuAdvancedGroupLabel ?? 'Advanced'
219
+ )
220
+
221
+ if ( isImageBlockEnabled ) {
222
+ advancedGroup . addItem ( 'image' , {
217
223
label : config ?. slashMenuImageLabel ?? 'Image' ,
218
224
icon : config ?. slashMenuImageIcon ?.( ) ?? imageIcon ,
219
225
onRun : ( ctx ) => {
@@ -224,18 +230,22 @@ export function getGroups(
224
230
command ( state , dispatch )
225
231
} ,
226
232
} )
227
- . addItem ( 'code' , {
228
- label : config ?. slashMenuCodeBlockLabel ?? 'Code' ,
229
- icon : config ?. slashMenuCodeBlockIcon ?.( ) ?? codeIcon ,
230
- onRun : ( ctx ) => {
231
- const view = ctx . get ( editorViewCtx )
232
- const { dispatch, state } = view
233
+ }
233
234
234
- const command = clearContentAndAddBlockType ( codeBlockSchema . type ( ctx ) )
235
- command ( state , dispatch )
236
- } ,
237
- } )
238
- . addItem ( 'table' , {
235
+ advancedGroup . addItem ( 'code' , {
236
+ label : config ?. slashMenuCodeBlockLabel ?? 'Code' ,
237
+ icon : config ?. slashMenuCodeBlockIcon ?.( ) ?? codeIcon ,
238
+ onRun : ( ctx ) => {
239
+ const view = ctx . get ( editorViewCtx )
240
+ const { dispatch, state } = view
241
+
242
+ const command = clearContentAndAddBlockType ( codeBlockSchema . type ( ctx ) )
243
+ command ( state , dispatch )
244
+ } ,
245
+ } )
246
+
247
+ if ( isTableEnabled ) {
248
+ advancedGroup . addItem ( 'table' , {
239
249
label : config ?. slashMenuTableLabel ?? 'Table' ,
240
250
icon : config ?. slashMenuTableIcon ?.( ) ?? tableIcon ,
241
251
onRun : ( ctx ) => {
@@ -260,6 +270,7 @@ export function getGroups(
260
270
} )
261
271
} ,
262
272
} )
273
+ }
263
274
264
275
if ( isLatexEnabled ) {
265
276
advancedGroup . addItem ( 'math' , {
0 commit comments