@@ -113,6 +113,51 @@ export const addChild = (state, { title }) => {
113
113
} ;
114
114
} ;
115
115
116
+ export const handleTransform = ( state , {
117
+ componentId, childId, x, y, width, height,
118
+ } ) => {
119
+ console . log ( 'componentId and childId: ' , componentId , childId ) ;
120
+ console . log ( 'state.focuscomponent: ' , state . focusComponent ) ;
121
+
122
+ const child = state . components
123
+ . find ( comp => comp . id === componentId )
124
+ . childrenArray . find ( child => child . childId === childId ) ;
125
+
126
+ const transformedChild = {
127
+ ...child ,
128
+ position : {
129
+ x,
130
+ y,
131
+ width,
132
+ height,
133
+ } ,
134
+ } ;
135
+
136
+ const children = [
137
+ ...state . components . find ( comp => comp . id === componentId ) . childrenArray . filter ( ( child ) => {
138
+ if ( child . childId !== childId ) return child ;
139
+ } ) ,
140
+ transformedChild ,
141
+ ] ;
142
+
143
+ const component = {
144
+ ...state . components . find ( comp => comp . id === componentId ) ,
145
+ childrenArray : children ,
146
+ } ;
147
+
148
+ const components = [
149
+ ...state . components . filter ( ( comp ) => {
150
+ if ( comp . id !== componentId ) return comp ;
151
+ } ) ,
152
+ component ,
153
+ ] ;
154
+
155
+ return {
156
+ ...state ,
157
+ components,
158
+ } ;
159
+ } ;
160
+
116
161
export const updateComponent = (
117
162
state ,
118
163
{
@@ -255,7 +300,10 @@ export const reassignParent = (state, { index, id, parentIds = [] }) => {
255
300
// Give the parent all children of it's to be deleted child
256
301
if ( parentIds . includes ( comp . id ) ) {
257
302
const prevChildrenIds = comp . childrenIds ;
258
- return { ...comp , childrenIds : [ ...new Set ( prevChildrenIds . concat ( childrenIds ) ) ] } ;
303
+ return {
304
+ ...comp ,
305
+ childrenIds : [ ...new Set ( prevChildrenIds . concat ( childrenIds ) ) ] ,
306
+ } ;
259
307
}
260
308
return comp ;
261
309
} ) ;
@@ -291,26 +339,26 @@ export const handleClose = (state, status) => ({
291
339
successOpen : status ,
292
340
} ) ;
293
341
294
- export const updatePosition = ( state , { id, x, y } ) => {
295
- const components = state . components . map ( ( component ) => {
296
- if ( component . id === id ) {
297
- return {
298
- ...component ,
299
- position : {
300
- x,
301
- y,
302
- width : component . position . width ,
303
- height : component . position . height ,
304
- } ,
305
- } ;
306
- }
307
- return component ;
308
- } ) ;
309
- return {
310
- ...state ,
311
- components,
312
- } ;
313
- } ;
342
+ // export const updatePosition = (state, { id, x, y }) => {
343
+ // const components = state.components.map(component => {
344
+ // if (component.id === id) {
345
+ // return {
346
+ // ...component,
347
+ // position: {
348
+ // x,
349
+ // y,
350
+ // width: component.position.width,
351
+ // height: component.position.height
352
+ // }
353
+ // };
354
+ // }
355
+ // return component;
356
+ // });
357
+ // return {
358
+ // ...state,
359
+ // components
360
+ // };
361
+ // };
314
362
315
363
/**
316
364
* Applies the new x and y coordinates, as well as, the new width
@@ -326,32 +374,7 @@ export const updatePosition = (state, { id, x, y }) => {
326
374
* @param {number } height - updated height
327
375
*/
328
376
329
- export const handleTransform = ( state , {
330
- componentId, childId, x, y, width, height,
331
- } ) => {
332
- console . log ( 'componentId and childId: ' , componentId , childId ) ;
333
- console . log ( 'state.focuscomponent: ' , state . focusComponent ) ;
334
- // const components = state.components
335
- // .find(comp => comp.id === componentId)
336
- // .childrenArray.map((child) => {
337
- // if (child.childId === childId) {
338
- // return {
339
- // ...child,
340
- // position: {
341
- // x,
342
- // y,
343
- // width,
344
- // height,
345
- // },
346
- // };
347
- // }
348
- // return child;
349
- // });
350
- return {
351
- ...state ,
352
- // components,
353
- } ;
354
- } ;
377
+ // handleTransform used to be here
355
378
356
379
/**
357
380
* Toggles the drag of the group, as well as all components. If the group is draggable the
0 commit comments