6
6
ComponentInt ,
7
7
ApplicationStateInt ,
8
8
ChildrenInt ,
9
- ChildInt
9
+ ChildInt ,
10
+ ComponentsInt ,
11
+ PropInt
10
12
} from "./interfaces" ;
11
13
12
14
const initialComponentState : ComponentInt = {
@@ -226,7 +228,7 @@ export const deleteChild = (
226
228
227
229
// delete the CHILD from the copied array
228
230
const indexToDelete = parentComponentCopy . childrenArray . findIndex (
229
- elem => elem . childId === childId
231
+ ( elem : ChildInt ) => elem . childId === childId
230
232
) ;
231
233
if ( indexToDelete < 0 ) {
232
234
return window . alert ( "No such child component found" ) ;
@@ -255,8 +257,22 @@ export const deleteChild = (
255
257
} ;
256
258
257
259
export const handleTransform = (
258
- state ,
259
- { componentId, childId, x, y, width, height }
260
+ state : ApplicationStateInt ,
261
+ {
262
+ componentId,
263
+ childId,
264
+ x,
265
+ y,
266
+ width,
267
+ height
268
+ } : {
269
+ componentId : number ;
270
+ childId : number ;
271
+ x : number ;
272
+ y : number ;
273
+ width : number ;
274
+ height : number ;
275
+ }
260
276
) => {
261
277
if ( childId === - 1 ) {
262
278
// the pseudochild has been transformed, its position is stored in the component
@@ -319,7 +335,7 @@ export const handleTransform = (
319
335
focusCHild : newFocusChild
320
336
} ;
321
337
322
- const components = [
338
+ const components : ComponentsInt = [
323
339
...state . components . filter ( comp => {
324
340
if ( comp . id !== componentId ) return comp ;
325
341
} ) ,
@@ -332,7 +348,10 @@ export const handleTransform = (
332
348
} ;
333
349
} ;
334
350
335
- export const deleteComponent = ( state , { componentId } ) => {
351
+ export const deleteComponent = (
352
+ state : ApplicationStateInt ,
353
+ { componentId } : { componentId : number }
354
+ ) => {
336
355
if ( componentId === 1 ) {
337
356
return {
338
357
...state
@@ -357,14 +376,16 @@ export const deleteComponent = (state, { componentId }) => {
357
376
} ;
358
377
359
378
export const changeFocusComponent = (
360
- state ,
361
- { title = state . focusComponent . title }
379
+ state : ApplicationStateInt ,
380
+ { title = state . focusComponent . title } : { title : string }
362
381
) => {
363
382
/** ****************
364
383
* if the prm TITLE is a blank Object it means REFRESH focusd Components.
365
384
* sometimes we update state like adding Children/Props etc and we want those changes to be reflected in focus component
366
385
************************************************* */
367
- const newFocusComp = state . components . find ( comp => comp . title === title ) ;
386
+ const newFocusComp : ComponentInt = state . components . find (
387
+ comp => comp . title === title
388
+ ) ;
368
389
// set the "focus child" to the focus child of this particular component .
369
390
// const newFocusChildId = newFocusComp.focusChildId;
370
391
@@ -380,6 +401,7 @@ export const changeFocusComponent = (
380
401
}
381
402
382
403
const result = getSelectable ( newFocusComp , state . components ) ;
404
+ //const {selectableChildren, ancestors }: {selectableChildren: } = result;
383
405
384
406
return {
385
407
...state ,
@@ -390,11 +412,14 @@ export const changeFocusComponent = (
390
412
} ;
391
413
} ;
392
414
393
- export const changeFocusChild = ( state , { childId } ) => {
415
+ export const changeFocusChild = (
416
+ state : ApplicationStateInt ,
417
+ { childId } : { childId : number }
418
+ ) => {
394
419
const focComp = state . components . find (
395
420
comp => comp . title === state . focusComponent . title
396
421
) ;
397
- let newFocusChild = focComp . childrenArray . find (
422
+ let newFocusChild : ChildInt = focComp . childrenArray . find (
398
423
child => child . childId === childId
399
424
) ;
400
425
@@ -409,8 +434,11 @@ export const changeFocusChild = (state, { childId }) => {
409
434
width : focComp . position . width ,
410
435
height : focComp . position . height
411
436
} ,
412
- draggable : true ,
413
- color : focComp . color
437
+ // draggable: true,
438
+ color : focComp . color ,
439
+ childType : "" ,
440
+ htmlElement : "" ,
441
+ HTMLInfo : { }
414
442
} ;
415
443
}
416
444
@@ -420,42 +448,66 @@ export const changeFocusChild = (state, { childId }) => {
420
448
} ;
421
449
} ;
422
450
423
- export const changeComponentFocusChild = ( state , { componentId, childId } ) => {
424
- const component = state . components . find ( comp => comp . id === componentId ) ;
425
- const modifiedComponent = cloneDeep ( component ) ;
451
+ export const changeComponentFocusChild = (
452
+ state : ApplicationStateInt ,
453
+ { componentId, childId } : { componentId : number ; childId : number }
454
+ ) => {
455
+ const component : ComponentInt = state . components . find (
456
+ comp => comp . id === componentId
457
+ ) ;
458
+ const modifiedComponent : any = cloneDeep ( component ) ;
426
459
modifiedComponent . focusChildId = childId ;
427
- const components = state . components . filter ( comp => comp . id !== componentId ) ;
460
+ const components : ComponentsInt = state . components . filter (
461
+ comp => comp . id !== componentId
462
+ ) ;
428
463
return {
429
464
...state ,
430
465
components : [ modifiedComponent , ...components ]
431
466
} ;
432
467
} ;
433
468
434
- export const exportFilesSuccess = ( state , { status, dir } ) => ( {
469
+ export const exportFilesSuccess = (
470
+ state : ApplicationStateInt ,
471
+ { status, dir } : { status : boolean ; dir : string }
472
+ ) => ( {
435
473
...state ,
436
474
successOpen : status ,
437
475
appDir : dir ,
438
476
loading : false
439
477
} ) ;
440
478
441
- export const exportFilesError = ( state , { status, err } ) => ( {
479
+ export const exportFilesError = (
480
+ state : ApplicationStateInt ,
481
+ { status, err } : { status : boolean ; err : string }
482
+ ) => ( {
442
483
...state ,
443
484
errorOpen : status ,
444
485
appDir : err ,
445
486
loading : false
446
487
} ) ;
447
488
448
- export const handleClose = ( state , status ) => ( {
489
+ export const handleClose = ( state : ApplicationStateInt , status : string ) => ( {
449
490
...state ,
450
491
errorOpen : status ,
451
492
successOpen : status
452
493
} ) ;
453
494
454
- export const openExpansionPanel = ( state , { component } ) => ( {
495
+ export const openExpansionPanel = (
496
+ state : ApplicationStateInt ,
497
+ { component } : { component : ComponentInt }
498
+ ) => ( {
455
499
...state
456
500
} ) ;
457
501
458
- export const addProp = ( state , { key, value = null , required, type } ) => {
502
+ export const addProp = (
503
+ state : ApplicationStateInt ,
504
+ {
505
+ key,
506
+ value = null ,
507
+ required,
508
+ type
509
+ } : { key : string ; value : string ; required : boolean ; type : string }
510
+ ) => {
459
511
if ( ! state . focusComponent . id ) {
460
512
console . log ( "Add prop error. no focused component " ) ;
461
513
return state ;
@@ -474,13 +526,13 @@ export const addProp = (state, { key, value = null, required, type }) => {
474
526
} ;
475
527
const newProps = [ ...selectedComponent . props , newProp ] ;
476
528
477
- const modifiedComponent = {
529
+ const modifiedComponent : ComponentInt = {
478
530
...selectedComponent ,
479
531
props : newProps ,
480
532
nextPropId : selectedComponent . nextPropId + 1
481
533
} ;
482
534
483
- const newComponents = state . components . filter (
535
+ const newComponents : ComponentsInt = state . components . filter (
484
536
comp => comp . id !== selectedComponent . id
485
537
) ;
486
538
newComponents . push ( modifiedComponent ) ;
@@ -491,18 +543,18 @@ export const addProp = (state, { key, value = null, required, type }) => {
491
543
} ;
492
544
} ;
493
545
494
- export const deleteProp = ( state , propId ) => {
546
+ export const deleteProp = ( state : ApplicationStateInt , propId : number ) => {
495
547
if ( ! state . focusComponent . id ) {
496
548
console . log ( "Delete prop error. no focused component " ) ;
497
549
return state ;
498
550
}
499
551
500
- const modifiedComponent = cloneDeep (
552
+ const modifiedComponent : any = cloneDeep (
501
553
state . components . find ( comp => comp . id === state . focusComponent . id )
502
554
) ;
503
555
504
556
const indexToDelete = modifiedComponent . props . findIndex (
505
- prop => prop . id === propId
557
+ ( prop : PropInt ) => prop . id === propId
506
558
) ;
507
559
if ( indexToDelete === - 1 ) {
508
560
console . log (
0 commit comments