@@ -225,7 +225,6 @@ const reducer = (state: State, action: Action) => {
225
225
} ;
226
226
227
227
const nextComponentId = state . nextComponentId + 1 ;
228
- console . log ( 'add component' , components )
229
228
return {
230
229
...state ,
231
230
components,
@@ -244,7 +243,6 @@ const reducer = (state: State, action: Action) => {
244
243
245
244
const parentComponentId : number = state . canvasFocus . componentId ;
246
245
const components = [ ...state . components ] ;
247
- console . log ( 'add child' , components )
248
246
249
247
// find component (an object) that we're adding a child to
250
248
const parentComponent = findComponent ( components , parentComponentId ) ;
@@ -314,28 +312,26 @@ const reducer = (state: State, action: Action) => {
314
312
directParent . children . push ( newChild ) ;
315
313
}
316
314
317
- parentComponent . code = generateCode (
318
- components ,
319
- parentComponentId ,
320
- [ ...state . rootComponents ] ,
321
- state . projectType ,
322
- state . HTMLTypes
323
- ) ;
324
-
325
315
const canvasFocus = {
326
316
...state . canvasFocus ,
327
317
componentId : state . canvasFocus . componentId ,
328
318
childId : newChild . childId
329
319
} ;
330
320
const nextChildId = state . nextChildId + 1 ;
331
321
let nextTopSeparatorId = state . nextTopSeparatorId + 1 ;
332
- console . log ( 'canvasFocus' , canvasFocus )
333
- console . log ( 'components' , components )
334
322
// let addChildArray = components[0].children;
335
323
let addChildArray = components [ canvasFocus . componentId - 1 ] . children
336
324
addChildArray = manageSeparators . mergeSeparator ( addChildArray , 1 ) ;
337
325
if ( directParent && directParent . name === 'separator' ) nextTopSeparatorId = manageSeparators . handleSeparators ( addChildArray , 'add' ) ;
338
326
components [ canvasFocus . componentId - 1 ] . children = addChildArray ;
327
+
328
+ parentComponent . code = generateCode (
329
+ components ,
330
+ parentComponentId ,
331
+ [ ...state . rootComponents ] ,
332
+ state . projectType ,
333
+ state . HTMLTypes
334
+ ) ;
339
335
340
336
return { ...state , components, nextChildId, canvasFocus, nextTopSeparatorId } ;
341
337
}
@@ -373,6 +369,11 @@ const reducer = (state: State, action: Action) => {
373
369
const directParent = findChild ( component , newParentChildId ) ;
374
370
directParent . children . push ( child ) ;
375
371
}
372
+
373
+ let nextTopSeparatorId = state . nextTopSeparatorId ;
374
+
375
+ components [ state . canvasFocus . componentId - 1 ] . children = manageSeparators . mergeSeparator ( components [ state . canvasFocus . componentId - 1 ] . children , 0 ) ;
376
+ nextTopSeparatorId = manageSeparators . handleSeparators ( components [ state . canvasFocus . componentId - 1 ] . children , 'change position' )
376
377
377
378
component . code = generateCode (
378
379
components ,
@@ -381,11 +382,7 @@ const reducer = (state: State, action: Action) => {
381
382
state . projectType ,
382
383
state . HTMLTypes
383
384
) ;
384
-
385
- let nextTopSeparatorId = state . nextTopSeparatorId ;
386
-
387
- components [ state . canvasFocus . componentId - 1 ] . children = manageSeparators . mergeSeparator ( components [ state . canvasFocus . componentId - 1 ] . children , 0 ) ;
388
- nextTopSeparatorId = manageSeparators . handleSeparators ( components [ state . canvasFocus . componentId - 1 ] . children , 'change position' )
385
+
389
386
return { ...state , components, nextTopSeparatorId } ;
390
387
}
391
388
// Change the focus component and child
@@ -442,19 +439,18 @@ const reducer = (state: State, action: Action) => {
442
439
443
440
// delete the element from its former parent's children array
444
441
directParent . children . splice ( childIndexValue , 1 ) ;
445
-
446
- component . code = generateCode (
447
- components ,
448
- state . canvasFocus . componentId ,
449
- [ ...state . rootComponents ] ,
450
- state . projectType ,
451
- state . HTMLTypes
452
- ) ;
453
-
454
-
442
+
455
443
const canvasFocus = { ...state . canvasFocus , childId : null } ;
456
- console . log ( 'before invoking handleSep' )
457
444
let nextTopSeparatorId = manageSeparators . handleSeparators ( components [ canvasFocus . componentId - 1 ] . children , 'delete' )
445
+
446
+ component . code = generateCode (
447
+ components ,
448
+ state . canvasFocus . componentId ,
449
+ [ ...state . rootComponents ] ,
450
+ state . projectType ,
451
+ state . HTMLTypes
452
+ ) ;
453
+
458
454
return { ...state , components, canvasFocus, nextTopSeparatorId } ;
459
455
}
460
456
0 commit comments