@@ -92,13 +92,12 @@ Description:
9292</template >
9393
9494<script >
95-
9695import { mapState , mapActions } from " vuex" ;
9796import VueDraggableResizable from " vue-draggable-resizable" ;
97+ const cloneDeep = require (' lodash.clonedeep' )
9898// import "vue-draggable-resizable/dist/VueDraggableResizable.css";
9999// import Vue3DraggableResizable from "vue3-draggable-resizable";
100100// import "vue3-draggable-resizable/dist/Vue3DraggableResizable.css";
101-
102101export default {
103102 name: " ComponentDisplay" ,
104103 components: {
@@ -113,7 +112,7 @@ export default {
113112 mockImg: false ,
114113 initialPosition: { x: 0 , y: 0 },
115114 initialSize: { w: 0 , h: 0 },
116- htmlElements: []
115+ htmlElements: [],
117116 };
118117 },
119118 mounted () {
@@ -125,7 +124,6 @@ export default {
125124 }
126125 }
127126 });
128-
129127 window .addEventListener (" keyup" , event => {
130128 if (event .key === " Delete" ) {
131129 if (this .activeComponent ) {
@@ -141,13 +139,11 @@ export default {
141139 this .$store .dispatch (" copyActiveComponent" );
142140 }
143141 });
144-
145142 window .addEventListener (' paste' , () => {
146143 this .$store .dispatch (" pasteActiveComponent" );
147144 // console.log('pasted');
148145 })
149146 },
150-
151147 computed: {
152148 ... mapState ([
153149 " routes" ,
@@ -158,26 +154,25 @@ export default {
158154 " imagePath" ,
159155 " activeComponentObj"
160156 ]),
161-
162157 // used in VueDraggableResizeable component
163158 activeRouteArray () {
159+ // console.log(this.routes[this.activeRoute]);
164160 return this .routes [this .activeRoute ];
165161 },
166-
167162 // used to delete active component
168163 activeComponentData () {
169- return this .activeComponentObj ;
164+ // Must deep clone this so we are not directly mutating state
165+ return cloneDeep (this .activeComponentObj );
170166 },
171-
172167 // childList () {
173168 // return this.componentMap[componentData.componentName].children
174169 // },
175-
176170 options () {
177171 // checks if component has any parents and pushes them into lineage
178172 const checkParents = (component , lineage = [component .componentName ]) => {
179173 if (! Object .keys (component .parent ).length ) return lineage;
180174 for (var parents in component .parent ) {
175+ // Mutating?
181176 lineage .push (parents);
182177 checkParents (component .parent [parents], lineage);
183178 }
@@ -204,13 +199,11 @@ export default {
204199 if (! exceptions .has (component)) return component;
205200 });
206201 },
207-
208202 userImage () {
209203 const imgSrc = ` file://` + this .imagePath [this .activeRoute ];
210204 // console.log('imgSrc is: ', imgSrc)
211205 return imgSrc;
212206 },
213-
214207 // updates display with mockup image
215208 mockBg () {
216209 return this .imagePath [this .activeRoute ]
@@ -244,7 +237,6 @@ export default {
244237 });
245238 }
246239 },
247-
248240 methods: {
249241 ... mapActions ([
250242 " setActiveComponent" ,
@@ -256,7 +248,6 @@ export default {
256248 " updateStartingSize" ,
257249 " updateComponentSize"
258250 ]),
259-
260251 // records component's initial position in case of drag
261252 recordInitialPosition : function (e ) {
262253 // console.log('recording initial position: ', this.initialPosition)
@@ -266,7 +257,6 @@ export default {
266257 this .initialPosition .x = this .activeComponentData .x ;
267258 this .initialPosition .y = this .activeComponentData .y ;
268259 },
269-
270260 // records component's initial size/position in case of resize
271261 recordInitialSize : function (e ) {
272262 // console.log('recording initial size')
@@ -275,7 +265,6 @@ export default {
275265 this .initialPosition .x = this .activeComponentData .x ;
276266 this .initialPosition .y = this .activeComponentData .y ;
277267 },
278-
279268 // sets component's ending size/position
280269 finishedResize : function (x , y , w , h ) {
281270 // console.log('FINISHED RESIZING')
@@ -297,7 +286,6 @@ export default {
297286 this .updateComponentSize (payload);
298287 }
299288 },
300-
301289 finishedDrag : function (x , y ) {
302290 // console.log('FINISHED DRAGGING')
303291 let payload = {
@@ -316,36 +304,29 @@ export default {
316304 this .updateComponentPosition (payload);
317305 }
318306 },
319-
320307 /* Records size/position
321308 Add @resizing="onResize" to VueDraggableResizable #component-box to use
322-
323309 onResize: function (x, y, width, height) {
324310 this.activeComponentData.x = x
325311 this.activeComponentData.y = y
326312 this.activeComponentData.w = width
327313 this.activeComponentData.h = height
328-
329314 this.componentMap[this.activeComponent].x = x
330315 this.componentMap[this.activeComponent].y = y
331316 this.componentMap[this.activeComponent].w = width
332317 this.componentMap[this.activeComponent].h = height
333318 },
334319 */
335-
336320 /* Records component's position
337321 Add @dragging="onDrag" to VueDraggableResizable #component-box to use
338-
339322 onDrag: function (x, y) {
340323 console.log('ondrag')
341324 this.activeComponentData.x = x
342325 this.activeComponentData.y = y
343-
344326 this.componentMap[this.activeComponent].x = x
345327 this.componentMap[this.activeComponent].y = y
346328 },
347329 */
348-
349330 // unhighlights all inactive components
350331 onActivated (componentData ) {
351332 // console.log('onActivated - comp display, componentData', componentData)
@@ -364,25 +345,21 @@ export default {
364345 }
365346 this .activeComponentData .isActive = true ;
366347 },
367-
368348 // deactivated is emitted before activated
369349 onDeactivated () {
370350 if (this .activeComponent !== " " ) {
371351 this .activeComponentData .isActive = false ;
372352 }
373353 },
374-
375354 // renders modal with Update Children and Layer in it
376355 handleAddChild () {
377356 this .modalOpen = true ;
378357 },
379-
380358 // used when user selects to add child from dropdown
381359 handleSelect (value ) {
382360 // console.log('selected child component: ', value)
383361 this .updateActiveComponentChildrenValue (value);
384362 },
385-
386363 // user can change component's layer order
387364 handleLayer (e ) {
388365 // console.log('handeLayer\'s e: ', e)
@@ -397,7 +374,6 @@ export default {
397374 if (e .target .innerText === " -" && payload .z > 0 ) payload .z -- ;
398375 this .updateComponentLayer (payload);
399376 },
400-
401377 // if user clicks on display grid, resets active component to ''
402378 handleClick (event ) {
403379 if (event .target .className === " component-display grid-bg" ) {
@@ -409,7 +385,6 @@ export default {
409385 copyActiveComponent () {
410386 // console.log('copied');
411387 }
412-
413388 },
414389 watch: {
415390 activeComponent : function () {
@@ -435,7 +410,6 @@ export default {
435410 line-height : 1.2 ;
436411 z-index : -1 ;
437412}
438-
439413.component-html-info {
440414 display : flex ;
441415 font-size : 14px ;
@@ -485,7 +459,6 @@ export default {
485459 #269 ;
486460 behavior : url (/pie/PIE.htc );
487461}
488-
489462.menu {
490463 margin-bottom : 0px !important ;
491464}
@@ -517,4 +490,4 @@ export default {
517490#counter {
518491 margin-top : 20px ;
519492}
520- </style >
493+ </style >
0 commit comments