@@ -224,6 +224,27 @@ export default class CommandHelper {
224
224
) ;
225
225
}
226
226
227
+ /**
228
+ * 创建组件组合添加命令
229
+ *
230
+ * @param uDataList 组件数据
231
+ * @param rDataList 组件数据
232
+ * @param store 画板
233
+ * @returns
234
+ */
235
+ static createGroupAddedCommand ( uDataList : Array < ICommandElementObject > , rDataList : Array < ICommandElementObject > , store : IStageStore ) : ICommand < IElementCommandPayload > {
236
+ const command = new GroupAddedCommand (
237
+ nanoid ( ) ,
238
+ {
239
+ type : ElementCommandTypes . GroupAdded ,
240
+ uDataList,
241
+ rDataList,
242
+ } ,
243
+ store ,
244
+ ) ;
245
+ return command ;
246
+ }
247
+
227
248
/**
228
249
* 组合创建命令
229
250
*
@@ -232,36 +253,45 @@ export default class CommandHelper {
232
253
* @param store 画板
233
254
* @returns
234
255
*/
235
- static async createGroupAddedCommand ( elements : IElement [ ] , groupAddFunction : ( ) => { group : IElementGroup ; elements : IElement [ ] } , store : IStageStore ) : Promise < ICommand < IElementCommandPayload > > {
256
+ static async createGroupAddedCommandBy ( elements : IElement [ ] , groupAddFunction : ( ) => { group : IElementGroup ; elements : IElement [ ] } , store : IStageStore ) : Promise < ICommand < IElementCommandPayload > > {
236
257
const uDataList : Array < IGroupCommandElementObject > = await Promise . all (
237
258
elements . map ( async element => ( { model : { id : element . id } , isGroupSubject : ! element . isGroupSubject , ...CommandHelper . createRearrangeModel ( element ) } ) ) ,
238
259
) ;
239
- const { group, elements : newElements } = groupAddFunction ( ) ;
260
+ const { group, elements : newElements } = groupAddFunction ( ) || { } ;
240
261
if ( group ) {
241
262
uDataList . push ( {
242
263
model : { id : group . id } ,
243
264
isGroup : true ,
244
265
} as IGroupCommandElementObject ) ;
245
266
const rDataList = await CommandHelper . createGroupAddedDataList ( group , newElements ) ;
246
- const command = new GroupAddedCommand (
247
- nanoid ( ) ,
248
- {
249
- type : ElementCommandTypes . GroupAdded ,
250
- uDataList,
251
- rDataList,
252
- } ,
253
- store ,
254
- ) ;
255
- return command ;
267
+ return CommandHelper . createGroupAddedCommand ( uDataList , rDataList , store ) ;
256
268
}
257
269
}
258
270
271
+ /**
272
+ * 创建组件组合移除命令
273
+ *
274
+ * @param elements 组件列表
275
+ * @param store 画板
276
+ */
277
+ static createGroupRemovedCommand ( uDataList : Array < ICommandElementObject > , store : IStageStore ) : ICommand < IElementCommandPayload > {
278
+ const command = new GroupRemovedCommand (
279
+ nanoid ( ) ,
280
+ {
281
+ type : ElementCommandTypes . GroupRemoved ,
282
+ uDataList,
283
+ } ,
284
+ store ,
285
+ ) ;
286
+ return command ;
287
+ }
288
+
259
289
/**
260
290
* 创建组件组合取消命令
261
291
*
262
292
* @param groups 组合列表
263
293
*/
264
- static async createGroupRemovedCommand ( groups : IElementGroup [ ] , store : IStageStore ) : Promise < ICommand < IElementCommandPayload > > {
294
+ static async createGroupRemovedCommandBy ( groups : IElementGroup [ ] , store : IStageStore ) : Promise < ICommand < IElementCommandPayload > > {
265
295
const uDataList : Array < IGroupCommandElementObject > = [ ] ;
266
296
await Promise . all (
267
297
groups . map ( async group => {
@@ -278,15 +308,7 @@ export default class CommandHelper {
278
308
} ) ;
279
309
} ) ,
280
310
) ;
281
- const command = new GroupRemovedCommand (
282
- nanoid ( ) ,
283
- {
284
- type : ElementCommandTypes . GroupRemoved ,
285
- uDataList,
286
- } ,
287
- store ,
288
- ) ;
289
- return command ;
311
+ return CommandHelper . createGroupRemovedCommand ( uDataList , store ) ;
290
312
}
291
313
292
314
/**
0 commit comments