@@ -22,23 +22,32 @@ import {
22
22
text ,
23
23
} from '@maily-to/core/blocks' ;
24
24
import {
25
+ getSlashCommandSuggestions ,
25
26
getVariableSuggestions ,
26
27
HTMLCodeBlockExtension ,
27
28
RepeatExtension ,
29
+ SlashCommandExtension ,
28
30
VariableExtension ,
29
31
Variables ,
30
32
} from '@maily-to/core/extensions' ;
31
33
import { ReactNodeViewRenderer } from '@tiptap/react' ;
34
+ import { searchSlashCommands } from '@maily-to/core-digest/extensions' ;
35
+ import { StepResponseDto } from '@novu/shared' ;
36
+ import { createDigestBlock } from './blocks/digest' ;
37
+ import {
38
+ CalculateVariablesProps ,
39
+ insertVariableToEditor ,
40
+ isInsideRepeatBlock ,
41
+ VariableFrom ,
42
+ } from './variables/variables' ;
32
43
import { ForView } from './views/for-view' ;
33
44
import { createVariableView } from './views/variable-view' ;
34
45
import { MailyVariablesListView } from './views/maily-variables-list-view' ;
35
46
import { HTMLCodeBlockView } from './views/html-view' ;
36
- import { CalculateVariablesProps , insertVariableToEditor , VariableFrom } from './variables/variables' ;
37
47
import { VariablePill } from '@/components/variable/variable-pill' ;
38
48
import { IsAllowedVariable } from '@/utils/parseStepVariables' ;
39
- import { StepResponseDto } from '@novu/shared' ;
40
- import { createDigestBlock } from './blocks/digest' ;
41
49
50
+ import type { Editor as TiptapEditor } from '@tiptap/core' ;
42
51
export const VARIABLE_TRIGGER_CHARACTER = '{{' ;
43
52
44
53
/**
@@ -117,12 +126,29 @@ export const createEditorBlocks = (props: {
117
126
return blocks ;
118
127
} ;
119
128
129
+ const getAvailableBlocks = ( blocks : BlockGroupItem [ ] , editor : TiptapEditor | null ) => {
130
+ // 'Repeat' and 'Digest' blocks can't be used inside another 'Repeat' block
131
+ const isInsideRepeat = editor && isInsideRepeatBlock ( editor ) ;
132
+
133
+ if ( isInsideRepeat ) {
134
+ const filteredBlocks = [ 'Repeat' , 'Digest block' ] ;
135
+
136
+ return blocks . map ( ( block ) => ( {
137
+ ...block ,
138
+ commands : block . commands . filter ( ( cmd ) => ! filteredBlocks . includes ( cmd . title ) ) ,
139
+ } ) ) ;
140
+ }
141
+
142
+ return blocks ;
143
+ } ;
144
+
120
145
export const createExtensions = ( props : {
121
146
handleCalculateVariables : ( props : CalculateVariablesProps ) => Variables | undefined ;
122
147
parsedVariables : { isAllowedVariable : IsAllowedVariable } ;
148
+ blocks : BlockGroupItem [ ] ;
123
149
isEnhancedDigestEnabled : boolean ;
124
150
} ) => {
125
- const { handleCalculateVariables, parsedVariables, isEnhancedDigestEnabled } = props ;
151
+ const { handleCalculateVariables, parsedVariables, blocks , isEnhancedDigestEnabled } = props ;
126
152
127
153
return [
128
154
RepeatExtension . extend ( {
@@ -139,6 +165,14 @@ export const createExtensions = (props: {
139
165
} ;
140
166
} ,
141
167
} ) ,
168
+ SlashCommandExtension . configure ( {
169
+ suggestion : {
170
+ ...getSlashCommandSuggestions ( blocks ) ,
171
+ items : ( { query, editor } ) => {
172
+ return searchSlashCommands ( query , editor , getAvailableBlocks ( blocks , editor ) ) ;
173
+ } ,
174
+ } ,
175
+ } ) ,
142
176
VariableExtension . extend ( {
143
177
addNodeView ( ) {
144
178
return ReactNodeViewRenderer ( createVariableView ( parsedVariables . isAllowedVariable ) , {
0 commit comments