@@ -5,6 +5,7 @@ import cloneDeep from './cloneDeep.ts';
5
5
import { ComponentInt , ApplicationStateInt , ChildrenInt , ChildInt , ComponentsInt , PropInt } from './Interfaces.ts' ;
6
6
7
7
8
+
8
9
const initialComponentState : ComponentInt = {
9
10
id : 0 ,
10
11
stateful : false ,
@@ -60,7 +61,7 @@ export const addComponent = (state: ApplicationStateInt, { title }: { title: str
60
61
const totalComponents = state . totalComponents + 1 ;
61
62
const nextId = state . nextId + 1 ;
62
63
63
- const selectableChildren = state . components . map ( comp => comp . id ) . filter ( id => id !== newComponent . id ) ;
64
+ const selectableChildren = state . components . map ( ( comp : ComponentInt ) => comp . id ) . filter ( ( id : number ) => id !== newComponent . id ) ;
64
65
65
66
const ancestors : Array < number > = [ ] ;
66
67
@@ -95,14 +96,14 @@ export const addChild = (
95
96
96
97
// view represents the curretn FOCUSED COMPONENT - this is the component where the child is being added to
97
98
// we only add childrent (or do any action) to the focused omconent
98
- const view : ComponentInt = state . components . find ( comp => comp . title === state . focusComponent . title ) ;
99
+ const view : ComponentInt = state . components . find ( ( comp : ComponentInt ) => comp . title === state . focusComponent . title ) ;
99
100
100
101
// parentComponent is the component this child is generated from (ex. instance of Box has comp of Box)
101
102
let parentComponent ;
102
103
103
104
// conditional if adding an HTML component
104
105
if ( childType === 'COMP' ) {
105
- parentComponent = state . components . find ( comp => comp . title === title ) ;
106
+ parentComponent = state . components . find ( ( comp : ComponentInt ) => comp . title === title ) ;
106
107
}
107
108
108
109
interface htmlElemPositionInt {
@@ -157,7 +158,7 @@ export const addChild = (
157
158
} ;
158
159
159
160
const components = [
160
- ...state . components . filter ( comp => {
161
+ ...state . components . filter ( ( comp : ComponentInt ) => {
161
162
if ( comp . title !== view . title ) return comp ;
162
163
} ) ,
163
164
component ,
@@ -193,7 +194,7 @@ export const deleteChild = (
193
194
return state ;
194
195
}
195
196
// make a DEEP copy of the parent component (the one thats about to loose a child)
196
- const parentComponentCopy : any = cloneDeep ( state . components . find ( c => c . id === parentId ) ) ;
197
+ const parentComponentCopy : any = cloneDeep ( state . components . find ( ( comp : ComponentInt ) => comp . id === parentId ) ) ;
197
198
198
199
// delete the CHILD from the copied array
199
200
const indexToDelete = parentComponentCopy . childrenArray . findIndex ( ( elem : ChildInt ) => elem . childId === childId ) ;
@@ -208,7 +209,7 @@ export const deleteChild = (
208
209
}
209
210
210
211
const modifiedComponentArray = [
211
- ...state . components . filter ( c => c . id !== parentId ) , // all elements besides the one just changed
212
+ ...state . components . filter ( ( comp : ComponentInt ) => comp . id !== parentId ) , // all elements besides the one just changed
212
213
parentComponentCopy ,
213
214
] ;
214
215
@@ -250,7 +251,7 @@ export const handleTransform = (
250
251
) => {
251
252
if ( childId === - 1 ) {
252
253
// the pseudochild has been transformed, its position is stored in the component
253
- const component = state . components . find ( comp => comp . id === componentId ) ;
254
+ const component = state . components . find ( ( comp : ComponentInt ) => comp . id === componentId ) ;
254
255
const transformedComponent = {
255
256
...component ,
256
257
position : {
@@ -262,7 +263,7 @@ export const handleTransform = (
262
263
} ;
263
264
264
265
const components = [
265
- ...state . components . filter ( comp => {
266
+ ...state . components . filter ( ( comp : ComponentInt ) => {
266
267
if ( comp . id !== componentId ) return comp ;
267
268
} ) ,
268
269
transformedComponent ,
@@ -272,8 +273,8 @@ export const handleTransform = (
272
273
273
274
// else, a normal child has been transformed, its position lives in the children array
274
275
const child = state . components
275
- . find ( comp => comp . id === componentId )
276
- . childrenArray . find ( child => child . childId === childId ) ;
276
+ . find ( ( comp : ComponentInt ) => comp . id === componentId )
277
+ . childrenArray . find ( ( child : ChildInt ) => child . childId === childId ) ;
277
278
278
279
const transformedChild = {
279
280
...child ,
@@ -286,7 +287,7 @@ export const handleTransform = (
286
287
} ;
287
288
288
289
const children = [
289
- ...state . components . find ( comp => comp . id === componentId ) . childrenArray . filter ( child => {
290
+ ...state . components . find ( ( comp : ComponentInt ) => comp . id === componentId ) . childrenArray . filter ( ( child : ChildInt ) => {
290
291
if ( child . childId !== childId ) return child ;
291
292
} ) ,
292
293
transformedChild ,
@@ -298,13 +299,13 @@ export const handleTransform = (
298
299
}
299
300
300
301
const component = {
301
- ...state . components . find ( comp => comp . id === componentId ) ,
302
+ ...state . components . find ( ( comp : ComponentInt ) => comp . id === componentId ) ,
302
303
childrenArray : children ,
303
304
focusChild : newFocusChild ,
304
305
} ;
305
306
306
307
const components : ComponentsInt = [
307
- ...state . components . filter ( comp => {
308
+ ...state . components . filter ( ( comp : ComponentInt ) => {
308
309
if ( comp . id !== componentId ) return comp ;
309
310
} ) ,
310
311
component ,
@@ -371,12 +372,12 @@ export const changeFocusComponent = (
371
372
* if the prm TITLE is a blank Object it means REFRESH focusd Components.
372
373
* sometimes we update state like adding Children/Props etc and we want those changes to be reflected in focus component
373
374
************************************************* */
374
- const newFocusComp : ComponentInt = state . components . find ( comp => comp . title === title ) ;
375
+ const newFocusComp : ComponentInt = state . components . find ( ( comp : ComponentInt ) => comp . title === title ) ;
375
376
// set the "focus child" to the focus child of this particular component .
376
377
377
378
let newFocusChild : ChildInt | any ; // check if the components has a child saved as a Focus child
378
379
if ( newFocusComp . focusChildId > 0 ) {
379
- newFocusChild = newFocusComp . childrenArray . find ( child => child . childId === newFocusComp . focusChildId ) ;
380
+ newFocusChild = newFocusComp . childrenArray . find ( ( child : ChildInt ) => child . childId === newFocusComp . focusChildId ) ;
380
381
}
381
382
382
383
if ( ! newFocusChild ) {
@@ -395,8 +396,8 @@ export const changeFocusComponent = (
395
396
} ;
396
397
397
398
export const changeFocusChild = ( state : ApplicationStateInt , { childId } : { childId : number } ) => {
398
- const focComp = state . components . find ( comp => comp . title === state . focusComponent . title ) ;
399
- let newFocusChild : ChildInt = focComp . childrenArray . find ( child => child . childId === childId ) ;
399
+ const focComp = state . components . find ( ( comp : ComponentInt ) => comp . title === state . focusComponent . title ) ;
400
+ let newFocusChild : ChildInt = focComp . childrenArray . find ( ( child : ChildInt ) => child . childId === childId ) ;
400
401
401
402
if ( ! newFocusChild ) {
402
403
newFocusChild = {
@@ -427,10 +428,10 @@ export const changeComponentFocusChild = (
427
428
state : ApplicationStateInt ,
428
429
{ componentId, childId } : { componentId : number ; childId : number } ,
429
430
) => {
430
- const component : ComponentInt = state . components . find ( comp => comp . id === componentId ) ;
431
+ const component : ComponentInt = state . components . find ( ( comp : ComponentInt ) => comp . id === componentId ) ;
431
432
const modifiedComponent : any = cloneDeep ( component ) ;
432
433
modifiedComponent . focusChildId = childId ;
433
- const components : ComponentsInt = state . components . filter ( comp => comp . id !== componentId ) ;
434
+ const components : ComponentsInt = state . components . filter ( ( comp : ComponentInt ) => comp . id !== componentId ) ;
434
435
return {
435
436
...state ,
436
437
components : [ modifiedComponent , ...components ] ,
@@ -470,7 +471,7 @@ export const addProp = (
470
471
return state ;
471
472
}
472
473
473
- const selectedComponent = state . components . find ( comp => comp . id === state . focusComponent . id ) ;
474
+ const selectedComponent = state . components . find ( ( comp : ComponentInt ) => comp . id === state . focusComponent . id ) ;
474
475
475
476
const newProp : PropInt = {
476
477
id : selectedComponent . nextPropId ,
@@ -487,7 +488,7 @@ export const addProp = (
487
488
nextPropId : selectedComponent . nextPropId + 1 ,
488
489
} ;
489
490
490
- const newComponents : ComponentsInt = state . components . filter ( comp => comp . id !== selectedComponent . id ) ;
491
+ const newComponents : ComponentsInt = state . components . filter ( ( comp : ComponentInt ) => comp . id !== selectedComponent . id ) ;
491
492
newComponents . push ( modifiedComponent ) ;
492
493
return {
493
494
...state ,
@@ -502,7 +503,7 @@ export const deleteProp = (state: ApplicationStateInt, propId: number) => {
502
503
return state ;
503
504
}
504
505
505
- const modifiedComponent : any = cloneDeep ( state . components . find ( comp => comp . id === state . focusComponent . id ) ) ;
506
+ const modifiedComponent : any = cloneDeep ( state . components . find ( ( comp : ComponentInt ) => comp . id === state . focusComponent . id ) ) ;
506
507
507
508
const indexToDelete = modifiedComponent . props . findIndex ( ( prop : PropInt ) => prop . id === propId ) ;
508
509
if ( indexToDelete === - 1 ) {
@@ -512,7 +513,7 @@ export const deleteProp = (state: ApplicationStateInt, propId: number) => {
512
513
513
514
modifiedComponent . props . splice ( indexToDelete , 1 ) ;
514
515
515
- const newComponentsArray = state . components . filter ( comp => comp . id !== modifiedComponent . id ) ;
516
+ const newComponentsArray = state . components . filter ( ( comp : ComponentInt ) => comp . id !== modifiedComponent . id ) ;
516
517
newComponentsArray . push ( modifiedComponent ) ;
517
518
518
519
return {
@@ -532,15 +533,15 @@ export const updateHtmlAttr = (state: ApplicationStateInt, { attr, value }: { at
532
533
modifiedChild . HTMLInfo [ attr ] = value ;
533
534
534
535
const modifiedComponent : ComponentInt = JSON . parse (
535
- JSON . stringify ( state . components . find ( comp => comp . id === state . focusComponent . id ) ) ,
536
+ JSON . stringify ( state . components . find ( ( comp : ComponentInt ) => comp . id === state . focusComponent . id ) ) ,
536
537
) ;
537
538
538
539
modifiedComponent . childrenArray = modifiedComponent . childrenArray . filter (
539
- child => child . childId !== modifiedChild . childId ,
540
+ ( child : ChildInt ) => child . childId !== modifiedChild . childId ,
540
541
) ;
541
542
modifiedComponent . childrenArray . push ( modifiedChild ) ;
542
543
543
- const newComponentsArray = state . components . filter ( comp => comp . id !== modifiedComponent . id ) ;
544
+ const newComponentsArray = state . components . filter ( ( comp : ComponentInt ) => comp . id !== modifiedComponent . id ) ;
544
545
newComponentsArray . push ( modifiedComponent ) ;
545
546
546
547
return {
@@ -563,10 +564,10 @@ export const updateChildrenSort = (state: ApplicationStateInt, { newSortValues }
563
564
currChild . childSort = newSortValue ;
564
565
}
565
566
566
- const modifiedComponent = state . components . find ( comp => comp . id === state . focusComponent . id ) ;
567
+ const modifiedComponent = state . components . find ( ( comp : ComponentInt ) => comp . id === state . focusComponent . id ) ;
567
568
modifiedComponent . childrenArray = modifiedChildrenArray ;
568
569
569
- const modifiedComponentsArray = state . components . filter ( comp => comp . id !== state . focusComponent . id ) ;
570
+ const modifiedComponentsArray = state . components . filter ( ( comp : ComponentInt ) => comp . id !== state . focusComponent . id ) ;
570
571
modifiedComponentsArray . push ( modifiedComponent ) ;
571
572
572
573
return {
0 commit comments