8
8
:key =" componentData.componentName"
9
9
:id =" componentData.componentName"
10
10
:x =" componentData.x"
11
- :y =" componentData.y + 20 "
11
+ :y =" componentData.y"
12
12
:z =" componentData.z"
13
13
:w =" componentData.w"
14
14
:h =" componentData.h"
19
19
@dragging =" onDrag"
20
20
@resizing =" onResize"
21
21
@dblclick.native =" onDoubleClick(componentData)"
22
+ @dragstop =" finishedDrag"
23
+ @resizestop =" finishedResize"
24
+ :onDragStart =" recordInitialPosition"
25
+ :onResizeStart =" recordInitialSize"
22
26
>
27
+ <!-- :onDragStart="recordInitialPosition"
28
+ :onResizeStart="recordInitialSize" -->
23
29
<div class =" component-title" >
24
30
<p >{{ componentData.componentName }}</p >
25
31
</div >
@@ -77,18 +83,20 @@ export default {
77
83
components: {
78
84
VueDraggableResizable
79
85
},
80
- data () {
86
+ data () {
81
87
// console.log("Component Map", this.componentMap);
82
88
return {
83
89
modalOpen: false ,
84
90
abilityToDelete: false ,
85
91
testOptions: [" parent" , " child" , " grandchild" ],
86
92
testModel: [],
87
93
mockImg: false ,
88
- counter: 0
94
+ counter: 0 ,
95
+ initialPosition: {x: 0 , y: 0 ,},
96
+ initialSize: {w: 0 ,h: 0 ,},
89
97
};
90
98
},
91
- mounted () {
99
+ mounted () {
92
100
// when component is mounted add ability to delete
93
101
94
102
window .addEventListener (" keyup" , event => {
@@ -176,19 +184,21 @@ export default {
176
184
}
177
185
},
178
186
updated () {
179
- console .log (" updated" )
180
- if (this .activeComponent === ' ' )
181
- {
182
- this .$refs .boxes .forEach ((element )=> {
183
- element .enabled = false ;
184
- element .$emit (' deactivated' )
185
- element .$emit (' update:active' , false )
186
- })
187
+ // console.log("updated")
188
+ if (this .activeComponent === ' ' ) {
189
+ if (this .$refs .boxes ) {
190
+ this .$refs .boxes .forEach ((element ) => {
191
+ element .enabled = false ;
192
+ element .$emit (' deactivated' )
193
+ element .$emit (' update:active' , false )
194
+ })
195
+ }
187
196
}
188
- else {
197
+ else {
189
198
this .$refs .boxes .forEach ((element )=> {
190
- if (this .activeComponent === element .$attrs .id )
191
- {
199
+ // added "element.enabled === false to stop it from emitting a change every frame the box moves
200
+ // may need to re-enable to track box movement and resizing since that stuff isn't part of a single source of truth.
201
+ if (this .activeComponent === element .$attrs .id && element .enabled === false ) {
192
202
element .enabled = true
193
203
element .$emit (' activated' )
194
204
element .$emit (' update:active' , true )
@@ -201,7 +211,11 @@ export default {
201
211
... mapActions ([
202
212
" setActiveComponent" ,
203
213
" updateComponentChildrenMultiselectValue" ,
204
- " updateActiveComponentChildrenValue"
214
+ " updateActiveComponentChildrenValue" ,
215
+ " updateComponentPosition" ,
216
+ " updateStartingPosition" ,
217
+ " updateStartingSize" ,
218
+ " updateComponentSize" ,
205
219
]),
206
220
onResize : function (x , y , width , height ) {
207
221
this .activeComponentData .x = x;
@@ -214,6 +228,70 @@ export default {
214
228
this .componentMap [this .activeComponent ].w = width;
215
229
this .componentMap [this .activeComponent ].h = height;
216
230
},
231
+
232
+ recordInitialPosition : function (e ) {
233
+ console .log (" we started a drag" )
234
+ console .log (" this.intialPosition" ,this .initialPosition )
235
+ console .log (" WHAT IS THIS" , this )
236
+ if (this .activeComponent !== e .target .id ) {
237
+ this .setActiveComponent (e .target .id )
238
+ }
239
+ this .initialPosition .x = this .activeComponentData .x
240
+ this .initialPosition .y = this .activeComponentData .y
241
+ // console.log(this.activeComponentData)
242
+ // console.log(this.activeComponentData.x)
243
+ // console.log(this.initialPosition.x)
244
+ // console.log(this.initialPosition.y)
245
+
246
+ let payload = {
247
+ x: this .initialPosition .x ,
248
+ y: this .initialPosition .y ,
249
+ activeComponent: this .activeComponent ,
250
+ routeArray: this .routes [this .activeRoute ],
251
+ activeComponentData: this .activeComponentData
252
+ }
253
+ console .log (" x: " ,payload .x ," y:" ,payload .y )
254
+ // this.updateStartingPosition(payload);
255
+ },
256
+
257
+ recordInitialSize : function (e ) {
258
+ // console.log("MAKE MY MONSTER GROW!")
259
+ this .initialSize .h = this .activeComponentData .h
260
+ this .initialSize .w = this .activeComponentData .w
261
+ this .initialPosition .x = this .activeComponentData .x
262
+ this .initialPosition .y = this .activeComponentData .y
263
+
264
+ let payload = {
265
+ h: this .initialSize .h ,
266
+ w: this .initialSize .w ,
267
+ x: this .activeComponentData .x ,
268
+ y: this .activeComponentData .y ,
269
+ activeComponent: this .activeComponent ,
270
+ routeArray: this .routes [this .activeRoute ],
271
+ activeComponentData: this .activeComponentData
272
+ }
273
+
274
+ // this.updateStartingSize(payload);
275
+
276
+ },
277
+
278
+ finishedResize : function (x ,y ,w ,h ) {
279
+ console .log (" FINISHED RESIZING" )
280
+ let payload = {
281
+ x: x,
282
+ y: y,
283
+ w: w,
284
+ h: h,
285
+ activeComponent: this .activeComponent ,
286
+ routeArray: this .routes [this .activeRoute ],
287
+ activeComponentData: this .activeComponentData
288
+ }
289
+ if (payload .x !== this .initialPosition .x || payload .y !== this .initialPosition .y ||
290
+ payload .w !== this .initialSize .w || payload .h !== this .initialSize .h ) {
291
+ this .updateComponentSize (payload)
292
+ }
293
+ },
294
+
217
295
onDrag : function (x , y ) {
218
296
this .activeComponentData .x = x;
219
297
this .activeComponentData .y = y;
@@ -222,26 +300,50 @@ export default {
222
300
this .componentMap [this .activeComponent ].y = y;
223
301
this .userImage ;
224
302
},
225
- onLayer : function (z ) {
226
- this .activeComponentData .z = z;
303
+ // onLayer: function(z) {
304
+ // this.activeComponentData.z = z;
305
+ // // Want to change the "Z" of the component found in Routes[activeRoute][whatever the component is]
306
+ // //have to do this via an action or it won't be preserved in our undo/redo
307
+ // },
308
+
309
+ finishedDrag : function (x ,y ) {
310
+ console .log (" FINISHED DRAGGING" )
311
+ let payload = {
312
+ x: x,
313
+ y: y,
314
+ activeComponent: this .activeComponent ,
315
+ routeArray: this .routes [this .activeRoute ],
316
+ activeComponentData: this .activeComponentData
317
+ }
318
+ // console.log("Payload.x = ", payload.x, "this.initialPosition.x", this.initialPosition.x)
319
+ // console.log("Payload.y = ", payload.y, "this.initialPosition.y", this.initialPosition.y)
320
+ if (payload .x !== this .initialPosition .x || payload .y !== this .initialPosition .y ) {
321
+ this .updateComponentPosition (payload);
322
+ }
227
323
},
228
- onActivated (componentData ) {
229
- this .$refs .boxes .forEach ((element )=> {
324
+
325
+ onActivated (componentData ) {
326
+ // console.log("I RAN!")
327
+ this .$refs .boxes .forEach ((element ) => {
230
328
if (element .$attrs .id !== componentData .componentName ) {
231
329
element .enabled = false ;
232
330
element .$emit (' deactivated' )
233
331
element .$emit (' update:active' , false )
234
332
}
235
333
})
236
- this .setActiveComponent (componentData .componentName );
334
+ // console.log("this is what is currently active",this.activeComponent)
335
+ // console.log("this is this", this)
336
+ // console.log('!(componentData.componentName === this.activeComponent)?',!(componentData.componentName === this.activeComponent))
337
+ if (! (componentData .componentName === this .activeComponent )) {
338
+ this .setActiveComponent (componentData .componentName );
339
+ }
237
340
this .activeComponentData .isActive = true ;
238
-
239
341
},
240
342
241
343
// deactivated is emitted before activated
242
344
243
- onDeactivated (componentData ) {
244
- if (this .activeComponent !== ' ' ) {
345
+ onDeactivated (componentData ) {
346
+ if (this .activeComponent !== ' ' ) {
245
347
this .activeComponentData .isActive = false ;
246
348
}
247
349
// console.log("Componentdataname", componentData.componentName)
@@ -251,8 +353,10 @@ export default {
251
353
// console.log("We just clicked without making a new active component")
252
354
// }
253
355
},
254
- onDoubleClick (compData ) {
255
- this .setActiveComponent (compData .componentName );
356
+ onDoubleClick (compData ) {
357
+ if (! (componentData .componentName === this .activeComponent )) {
358
+ this .setActiveComponent (componentData .componentName );
359
+ }
256
360
this .activeComponentData .isActive = true ;
257
361
},
258
362
handleAddChild () {
@@ -287,10 +391,11 @@ export default {
287
391
// this.setActiveComponent(compData.componentName)
288
392
// this.activeComponentData.isActive = true
289
393
// }
290
- handleClick (event ) {
291
- if (event .target .className === " component-display grid-bg" )
292
- {
293
- this .setActiveComponent (' ' )
394
+ handleClick (event ) {
395
+ if (event .target .className === " component-display grid-bg" ) {
396
+ if (! (' ' === this .activeComponent )) {
397
+ this .setActiveComponent (' ' );
398
+ }
294
399
}
295
400
}
296
401
}
@@ -309,7 +414,7 @@ export default {
309
414
/* width: 1rem; */
310
415
line-height : 1.2 ;
311
416
/* margin: 10px; */
312
- z-index : 0 ;
417
+ z-index : -1 ;
313
418
}
314
419
.component-children {
315
420
position : absolute ;
0 commit comments