@@ -137,14 +137,17 @@ export const nestComponentAction: ActionConfig = {
137
137
requiresInput : false ,
138
138
isNested : true ,
139
139
execute : async ( params : ActionExecuteParams ) => {
140
- const { selectedEditorComponent, selectedNestComponent, editorState } = params ;
141
-
140
+ // const { selectedEditorComponent, selectedNestComponent, editorState, actionPayload } = params;
141
+ const { editorState, actionPayload, selectedComponent : selectedNestComponent } = params ;
142
+ const { name, layout, target : selectedEditorComponent , ...otherProps } = actionPayload ;
143
+
142
144
if ( ! selectedEditorComponent || ! selectedNestComponent || ! editorState ) {
143
145
message . error ( 'Parent component, child component, and editor state are required' ) ;
144
146
return ;
145
147
}
146
148
147
- const parentComponentInfo = getEditorComponentInfo ( editorState , selectedEditorComponent ) ;
149
+ const [ editorComponent , ...childComponents ] = selectedEditorComponent . split ( '.' ) ;
150
+ const parentComponentInfo = getEditorComponentInfo ( editorState , editorComponent ) ;
148
151
149
152
if ( ! parentComponentInfo ) {
150
153
message . error ( `Parent component "${ selectedEditorComponent } " not found` ) ;
@@ -174,10 +177,15 @@ export const nestComponentAction: ActionConfig = {
174
177
}
175
178
176
179
try {
177
-
180
+ let compName = name ;
178
181
const nameGenerator = editorState . getNameGenerator ( ) ;
179
182
const compInfo = parseCompType ( selectedNestComponent ) ;
180
- const compName = nameGenerator . genItemName ( compInfo . compName ) ;
183
+ if ( ! compName ) {
184
+ compName = nameGenerator . genItemName ( compInfo . compName ) ;
185
+ }
186
+ // const nameGenerator = editorState.getNameGenerator();
187
+ // const compInfo = parseCompType(selectedNestComponent);
188
+ // const compName = nameGenerator.genItemName(compInfo.compName);
181
189
const key = genRandomKey ( ) ;
182
190
183
191
const manifest = uiCompRegistry [ selectedNestComponent ] ;
@@ -193,15 +201,33 @@ export const nestComponentAction: ActionConfig = {
193
201
defaultDataFn = manifest ?. defaultDataFn ;
194
202
}
195
203
204
+ let compDefaultValue = defaultDataFn ? defaultDataFn ( compName , nameGenerator , editorState ) : undefined ;
205
+ const compInitialValue = {
206
+ ...( compDefaultValue as any || { } ) ,
207
+ ...otherProps ,
208
+ }
209
+
196
210
const widgetValue : GridItemDataType = {
197
211
compType : selectedNestComponent ,
198
212
name : compName ,
199
- comp : defaultDataFn ? defaultDataFn ( compName , nameGenerator , editorState ) : undefined ,
213
+ comp : compInitialValue ,
200
214
} ;
201
215
202
216
const parentContainer = parentItem . children . comp ;
203
-
204
- const realContainer = parentContainer . realSimpleContainer ( ) ;
217
+ let originalContainer = parentContainer ;
218
+ for ( const childComponent of childComponents ) {
219
+ originalContainer = originalContainer . children [ childComponent ] ;
220
+ }
221
+ if ( originalContainer ?. children ?. [ 0 ] ?. children ?. view ) {
222
+ originalContainer = originalContainer ?. children ?. [ 0 ] ?. children ?. view ;
223
+ }
224
+
225
+ if ( ! originalContainer ) {
226
+ message . error ( `Container "${ selectedEditorComponent } " cannot accept nested components` ) ;
227
+ return ;
228
+ }
229
+
230
+ const realContainer = originalContainer . realSimpleContainer ( ) ;
205
231
if ( ! realContainer ) {
206
232
message . error ( `Container "${ selectedEditorComponent } " cannot accept nested components` ) ;
207
233
return ;
@@ -223,6 +249,7 @@ export const nestComponentAction: ActionConfig = {
223
249
h : layoutInfo . h || 5 ,
224
250
pos : itemPos ,
225
251
isDragging : false ,
252
+ ...( layout || { } ) ,
226
253
} ;
227
254
228
255
realContainer . dispatch (
0 commit comments