1
- import {
2
- ComponentInt ,
3
- ComponentsInt ,
4
- PropInt
5
- } from "../utils/interfaces" ;
1
+ import { ComponentInt , ComponentsInt , PropInt } from '../utils/Interfaces.ts' ;
6
2
7
3
import {
8
4
LOAD_INIT_DATA ,
@@ -26,38 +22,34 @@ import {
26
22
ADD_PROP ,
27
23
DELETE_ALL_DATA ,
28
24
UPDATE_HTML_ATTR ,
29
- UPDATE_CHILDREN_SORT
30
- } from " ../actionTypes/index" ;
25
+ UPDATE_CHILDREN_SORT ,
26
+ } from ' ../actionTypes/index.js' ;
31
27
32
- import { loadState } from " ../localStorage" ;
33
- import createFiles from " ../utils/createFiles.util" ;
34
- import createApplicationUtil from " ../utils/createApplication.util" ;
28
+ import { loadState } from ' ../localStorage' ;
29
+ import createFiles from ' ../utils/createFiles.util.ts' ;
30
+ import createApplicationUtil from ' ../utils/createApplication.util.ts' ;
35
31
36
32
export const loadInitData = ( ) => ( dispatch : any ) => {
37
- loadState ( ) . then ( ( data : any ) =>
38
- dispatch ( {
39
- type : LOAD_INIT_DATA ,
40
- payload : {
41
- data : data ? data . workspace : { }
42
- }
43
- } )
44
- ) ;
33
+ loadState ( ) . then ( ( data : any ) => dispatch ( {
34
+ type : LOAD_INIT_DATA ,
35
+ payload : {
36
+ data : data ? data . workspace : { } ,
37
+ } ,
38
+ } ) ) ;
45
39
} ;
46
40
47
- export const addComponent = ( { title } : { title : string } ) => (
48
- dispatch : any
49
- ) => {
41
+ export const addComponent = ( { title } : { title : string } ) => ( dispatch : any ) => {
50
42
dispatch ( { type : ADD_COMPONENT , payload : { title } } ) ;
51
43
} ;
52
44
53
45
export const addChild = ( {
54
46
title,
55
47
childType,
56
- HTMLInfo
48
+ HTMLInfo,
57
49
} : {
58
- title : string ;
59
- childType : string ;
60
- HTMLInfo : object ;
50
+ title : string ;
51
+ childType : string ;
52
+ HTMLInfo : object ;
61
53
} ) => ( dispatch : any ) => {
62
54
dispatch ( { type : ADD_CHILD , payload : { title, childType, HTMLInfo } } ) ;
63
55
} ;
@@ -69,104 +61,91 @@ export const deleteChild = ({}) => (dispatch: any) => {
69
61
70
62
export const deleteComponent = ( {
71
63
componentId,
72
- stateComponents
64
+ stateComponents,
73
65
} : {
74
- componentId : number ;
75
- stateComponents : ComponentsInt ;
66
+ componentId : number ;
67
+ stateComponents : ComponentsInt ;
76
68
} ) => ( dispatch : any ) => {
77
69
// find all places where the "to be delted" is a child and do what u gotta do
78
- stateComponents . forEach ( parent => {
79
- parent . childrenArray
80
- . filter ( child => child . childComponentId === componentId )
81
- . forEach ( child => {
82
- dispatch ( {
83
- type : DELETE_CHILD ,
84
- payload : {
85
- parentId : parent . id ,
86
- childId : child . childId ,
87
- calledFromDeleteComponent : true
88
- }
89
- } ) ;
70
+ stateComponents . forEach ( ( parent ) => {
71
+ parent . childrenArray . filter ( child => child . childComponentId === componentId ) . forEach ( ( child ) => {
72
+ dispatch ( {
73
+ type : DELETE_CHILD ,
74
+ payload : {
75
+ parentId : parent . id ,
76
+ childId : child . childId ,
77
+ calledFromDeleteComponent : true ,
78
+ } ,
90
79
} ) ;
80
+ } ) ;
91
81
} ) ;
92
82
93
83
// change focus to APp
94
- dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : " App" } } ) ;
84
+ dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title : ' App' } } ) ;
95
85
// after taking care of the children delete the component
96
86
dispatch ( { type : DELETE_COMPONENT , payload : { componentId } } ) ;
97
87
} ;
98
88
99
- export const changeFocusComponent = ( { title } : { title : string } ) => (
100
- dispatch : any
101
- ) => {
89
+ export const changeFocusComponent = ( { title } : { title : string } ) => ( dispatch : any ) => {
102
90
dispatch ( { type : CHANGE_FOCUS_COMPONENT , payload : { title } } ) ;
103
91
} ;
104
92
105
93
// make sure childId is being sent in
106
- export const changeFocusChild = ( { childId } : { childId : number } ) => (
107
- dispatch : any
108
- ) => {
94
+ export const changeFocusChild = ( { childId } : { childId : number } ) => ( dispatch : any ) => {
109
95
dispatch ( { type : CHANGE_FOCUS_CHILD , payload : { childId } } ) ;
110
96
} ;
111
97
112
98
export const changeComponentFocusChild = ( {
113
99
componentId,
114
- childId
100
+ childId,
115
101
} : {
116
- componentId : number ;
117
- childId : number ;
102
+ componentId : number ;
103
+ childId : number ;
118
104
} ) => ( dispatch : any ) => {
119
105
dispatch ( {
120
106
type : CHANGE_COMPONENT_FOCUS_CHILD ,
121
- payload : { componentId, childId }
107
+ payload : { componentId, childId } ,
122
108
} ) ;
123
109
} ;
124
110
125
111
export const exportFiles = ( {
126
112
components,
127
113
path,
128
114
appName,
129
- exportAppBool
115
+ exportAppBool,
130
116
} : {
131
- components : ComponentsInt ;
132
- path : string ;
133
- appName : string ;
134
- exportAppBool : boolean ;
117
+ components : ComponentsInt ;
118
+ path : string ;
119
+ appName : string ;
120
+ exportAppBool : boolean ;
135
121
} ) => ( dispatch : any ) => {
136
122
// this dispatch sets the global state property 'loading' to true until the createFiles call resolves below
137
123
dispatch ( {
138
- type : EXPORT_FILES
124
+ type : EXPORT_FILES ,
139
125
} ) ;
140
126
141
127
createFiles ( components , path , appName , exportAppBool )
142
- . then ( dir =>
143
- dispatch ( {
144
- type : EXPORT_FILES_SUCCESS ,
145
- payload : { status : true , dir : dir [ 0 ] }
146
- } )
147
- )
148
- . catch ( err =>
149
- dispatch ( {
150
- type : EXPORT_FILES_ERROR ,
151
- payload : { status : true , err }
152
- } )
153
- ) ;
128
+ . then ( dir => dispatch ( {
129
+ type : EXPORT_FILES_SUCCESS ,
130
+ payload : { status : true , dir : dir [ 0 ] } ,
131
+ } ) )
132
+ . catch ( err => dispatch ( {
133
+ type : EXPORT_FILES_ERROR ,
134
+ payload : { status : true , err } ,
135
+ } ) ) ;
154
136
} ;
155
137
156
138
export const handleClose = ( ) => ( {
157
139
type : HANDLE_CLOSE ,
158
- payload : false
140
+ payload : false ,
159
141
} ) ;
160
142
161
143
export const handleTransform = (
162
144
componentId : number ,
163
145
childId : number ,
164
146
{
165
- x,
166
- y,
167
- width,
168
- height
169
- } : { x : number ; y : number ; width : number ; height : number }
147
+ x, y, width, height,
148
+ } : { x : number ; y : number ; width : number ; height : number } ,
170
149
) => ( {
171
150
type : HANDLE_TRANSFORM ,
172
151
payload : {
@@ -175,22 +154,22 @@ export const handleTransform = (
175
154
x,
176
155
y,
177
156
width,
178
- height
179
- }
157
+ height,
158
+ } ,
180
159
} ) ;
181
160
182
161
export const createApplication = ( {
183
162
path,
184
163
components = [ ] ,
185
164
genOption,
186
- appName = " reactype_app" ,
187
- exportAppBool
165
+ appName = ' reactype_app' ,
166
+ exportAppBool,
188
167
} : {
189
- path : string ;
190
- components : ComponentsInt ;
191
- genOption : number ;
192
- appName : string ;
193
- exportAppBool : boolean ;
168
+ path : string ;
169
+ components : ComponentsInt ;
170
+ genOption : number ;
171
+ appName : string ;
172
+ exportAppBool : boolean ;
194
173
} ) => ( dispatch : any ) => {
195
174
if ( genOption === 0 ) {
196
175
exportAppBool = false ;
@@ -199,49 +178,47 @@ export const createApplication = ({
199
178
appName,
200
179
path,
201
180
components,
202
- exportAppBool
203
- } )
181
+ exportAppBool,
182
+ } ) ,
204
183
) ;
205
184
} else if ( genOption ) {
206
185
exportAppBool = true ;
207
186
dispatch ( {
208
- type : CREATE_APPLICATION
187
+ type : CREATE_APPLICATION ,
209
188
} ) ;
210
189
createApplicationUtil ( {
211
190
path,
212
191
appName,
213
- genOption
192
+ genOption,
214
193
// exportAppBool
215
194
} )
216
195
. then ( ( ) => {
217
196
dispatch ( {
218
- type : CREATE_APPLICATION_SUCCESS
197
+ type : CREATE_APPLICATION_SUCCESS ,
219
198
} ) ;
220
199
dispatch (
221
200
exportFiles ( {
222
201
appName,
223
202
path,
224
203
components,
225
- exportAppBool
226
- } )
204
+ exportAppBool,
205
+ } ) ,
227
206
) ;
228
207
} )
229
- . catch ( err =>
230
- dispatch ( {
231
- type : CREATE_APPLICATION_ERROR ,
232
- payload : { status : true , err }
233
- } )
234
- ) ;
208
+ . catch ( err => dispatch ( {
209
+ type : CREATE_APPLICATION_ERROR ,
210
+ payload : { status : true , err } ,
211
+ } ) ) ;
235
212
}
236
213
} ;
237
214
238
215
export const openExpansionPanel = ( component : ComponentInt ) => ( {
239
216
type : OPEN_EXPANSION_PANEL ,
240
- payload : { component }
217
+ payload : { component } ,
241
218
} ) ;
242
219
243
220
export const deleteAllData = ( ) => ( {
244
- type : DELETE_ALL_DATA
221
+ type : DELETE_ALL_DATA ,
245
222
} ) ;
246
223
247
224
export const deleteProp = ( propId : number ) => ( dispatch : any ) => {
@@ -250,29 +227,23 @@ export const deleteProp = (propId: number) => (dispatch: any) => {
250
227
251
228
export const addProp = ( prop : PropInt ) => ( {
252
229
type : ADD_PROP ,
253
- payload : { ...prop }
230
+ payload : { ...prop } ,
254
231
} ) ;
255
232
256
- export const updateHtmlAttr = ( {
257
- attr,
258
- value
259
- } : {
260
- attr : string ;
261
- value : string ;
262
- } ) => ( dispatch : any ) => {
233
+ export const updateHtmlAttr = ( { attr, value } : { attr : string ; value : string } ) => (
234
+ dispatch : any ,
235
+ ) => {
263
236
dispatch ( {
264
237
type : UPDATE_HTML_ATTR ,
265
- payload : { attr, value }
238
+ payload : { attr, value } ,
266
239
} ) ;
267
240
} ;
268
241
269
- export const updateChildrenSort = ( {
270
- newSortValues
271
- } : {
272
- newSortValues : any ;
273
- } ) => ( dispatch : any ) => {
242
+ export const updateChildrenSort = ( { newSortValues } : { newSortValues : any } ) => (
243
+ dispatch : any ,
244
+ ) => {
274
245
dispatch ( {
275
246
type : UPDATE_CHILDREN_SORT ,
276
- payload : { newSortValues }
247
+ payload : { newSortValues } ,
277
248
} ) ;
278
249
} ;
0 commit comments