@@ -92,13 +92,12 @@ Description:
92
92
</template >
93
93
94
94
<script >
95
-
96
95
import { mapState , mapActions } from " vuex" ;
97
96
import VueDraggableResizable from " vue-draggable-resizable" ;
97
+ const cloneDeep = require (' lodash.clonedeep' )
98
98
// import "vue-draggable-resizable/dist/VueDraggableResizable.css";
99
99
// import Vue3DraggableResizable from "vue3-draggable-resizable";
100
100
// import "vue3-draggable-resizable/dist/Vue3DraggableResizable.css";
101
-
102
101
export default {
103
102
name: " ComponentDisplay" ,
104
103
components: {
@@ -113,7 +112,7 @@ export default {
113
112
mockImg: false ,
114
113
initialPosition: { x: 0 , y: 0 },
115
114
initialSize: { w: 0 , h: 0 },
116
- htmlElements: []
115
+ htmlElements: [],
117
116
};
118
117
},
119
118
mounted () {
@@ -125,7 +124,6 @@ export default {
125
124
}
126
125
}
127
126
});
128
-
129
127
window .addEventListener (" keyup" , event => {
130
128
if (event .key === " Delete" ) {
131
129
if (this .activeComponent ) {
@@ -141,13 +139,11 @@ export default {
141
139
this .$store .dispatch (" copyActiveComponent" );
142
140
}
143
141
});
144
-
145
142
window .addEventListener (' paste' , () => {
146
143
this .$store .dispatch (" pasteActiveComponent" );
147
144
// console.log('pasted');
148
145
})
149
146
},
150
-
151
147
computed: {
152
148
... mapState ([
153
149
" routes" ,
@@ -158,26 +154,25 @@ export default {
158
154
" imagePath" ,
159
155
" activeComponentObj"
160
156
]),
161
-
162
157
// used in VueDraggableResizeable component
163
158
activeRouteArray () {
159
+ // console.log(this.routes[this.activeRoute]);
164
160
return this .routes [this .activeRoute ];
165
161
},
166
-
167
162
// used to delete active component
168
163
activeComponentData () {
169
- return this .activeComponentObj ;
164
+ // Must deep clone this so we are not directly mutating state
165
+ return cloneDeep (this .activeComponentObj );
170
166
},
171
-
172
167
// childList () {
173
168
// return this.componentMap[componentData.componentName].children
174
169
// },
175
-
176
170
options () {
177
171
// checks if component has any parents and pushes them into lineage
178
172
const checkParents = (component , lineage = [component .componentName ]) => {
179
173
if (! Object .keys (component .parent ).length ) return lineage;
180
174
for (var parents in component .parent ) {
175
+ // Mutating?
181
176
lineage .push (parents);
182
177
checkParents (component .parent [parents], lineage);
183
178
}
@@ -204,13 +199,11 @@ export default {
204
199
if (! exceptions .has (component)) return component;
205
200
});
206
201
},
207
-
208
202
userImage () {
209
203
const imgSrc = ` file://` + this .imagePath [this .activeRoute ];
210
204
// console.log('imgSrc is: ', imgSrc)
211
205
return imgSrc;
212
206
},
213
-
214
207
// updates display with mockup image
215
208
mockBg () {
216
209
return this .imagePath [this .activeRoute ]
@@ -244,7 +237,6 @@ export default {
244
237
});
245
238
}
246
239
},
247
-
248
240
methods: {
249
241
... mapActions ([
250
242
" setActiveComponent" ,
@@ -256,7 +248,6 @@ export default {
256
248
" updateStartingSize" ,
257
249
" updateComponentSize"
258
250
]),
259
-
260
251
// records component's initial position in case of drag
261
252
recordInitialPosition : function (e ) {
262
253
// console.log('recording initial position: ', this.initialPosition)
@@ -266,7 +257,6 @@ export default {
266
257
this .initialPosition .x = this .activeComponentData .x ;
267
258
this .initialPosition .y = this .activeComponentData .y ;
268
259
},
269
-
270
260
// records component's initial size/position in case of resize
271
261
recordInitialSize : function (e ) {
272
262
// console.log('recording initial size')
@@ -275,7 +265,6 @@ export default {
275
265
this .initialPosition .x = this .activeComponentData .x ;
276
266
this .initialPosition .y = this .activeComponentData .y ;
277
267
},
278
-
279
268
// sets component's ending size/position
280
269
finishedResize : function (x , y , w , h ) {
281
270
// console.log('FINISHED RESIZING')
@@ -297,7 +286,6 @@ export default {
297
286
this .updateComponentSize (payload);
298
287
}
299
288
},
300
-
301
289
finishedDrag : function (x , y ) {
302
290
// console.log('FINISHED DRAGGING')
303
291
let payload = {
@@ -316,36 +304,29 @@ export default {
316
304
this .updateComponentPosition (payload);
317
305
}
318
306
},
319
-
320
307
/* Records size/position
321
308
Add @resizing="onResize" to VueDraggableResizable #component-box to use
322
-
323
309
onResize: function (x, y, width, height) {
324
310
this.activeComponentData.x = x
325
311
this.activeComponentData.y = y
326
312
this.activeComponentData.w = width
327
313
this.activeComponentData.h = height
328
-
329
314
this.componentMap[this.activeComponent].x = x
330
315
this.componentMap[this.activeComponent].y = y
331
316
this.componentMap[this.activeComponent].w = width
332
317
this.componentMap[this.activeComponent].h = height
333
318
},
334
319
*/
335
-
336
320
/* Records component's position
337
321
Add @dragging="onDrag" to VueDraggableResizable #component-box to use
338
-
339
322
onDrag: function (x, y) {
340
323
console.log('ondrag')
341
324
this.activeComponentData.x = x
342
325
this.activeComponentData.y = y
343
-
344
326
this.componentMap[this.activeComponent].x = x
345
327
this.componentMap[this.activeComponent].y = y
346
328
},
347
329
*/
348
-
349
330
// unhighlights all inactive components
350
331
onActivated (componentData ) {
351
332
// console.log('onActivated - comp display, componentData', componentData)
@@ -364,25 +345,21 @@ export default {
364
345
}
365
346
this .activeComponentData .isActive = true ;
366
347
},
367
-
368
348
// deactivated is emitted before activated
369
349
onDeactivated () {
370
350
if (this .activeComponent !== " " ) {
371
351
this .activeComponentData .isActive = false ;
372
352
}
373
353
},
374
-
375
354
// renders modal with Update Children and Layer in it
376
355
handleAddChild () {
377
356
this .modalOpen = true ;
378
357
},
379
-
380
358
// used when user selects to add child from dropdown
381
359
handleSelect (value ) {
382
360
// console.log('selected child component: ', value)
383
361
this .updateActiveComponentChildrenValue (value);
384
362
},
385
-
386
363
// user can change component's layer order
387
364
handleLayer (e ) {
388
365
// console.log('handeLayer\'s e: ', e)
@@ -397,7 +374,6 @@ export default {
397
374
if (e .target .innerText === " -" && payload .z > 0 ) payload .z -- ;
398
375
this .updateComponentLayer (payload);
399
376
},
400
-
401
377
// if user clicks on display grid, resets active component to ''
402
378
handleClick (event ) {
403
379
if (event .target .className === " component-display grid-bg" ) {
@@ -409,7 +385,6 @@ export default {
409
385
copyActiveComponent () {
410
386
// console.log('copied');
411
387
}
412
-
413
388
},
414
389
watch: {
415
390
activeComponent : function () {
@@ -435,7 +410,6 @@ export default {
435
410
line-height : 1.2 ;
436
411
z-index : -1 ;
437
412
}
438
-
439
413
.component-html-info {
440
414
display : flex ;
441
415
font-size : 14px ;
@@ -485,7 +459,6 @@ export default {
485
459
#269 ;
486
460
behavior : url (/pie/PIE.htc );
487
461
}
488
-
489
462
.menu {
490
463
margin-bottom : 0px !important ;
491
464
}
@@ -517,4 +490,4 @@ export default {
517
490
#counter {
518
491
margin-top : 20px ;
519
492
}
520
- </style >
493
+ </style >
0 commit comments