1
1
<template >
2
- <div class =" component-display grid-bg" :style =" mockBg" >
2
+ <div class =" component-display grid-bg" :style =" mockBg" v-on:click = " handleClick " >
3
3
<!-- <p>{{ userImage }}</p> -->
4
4
<VueDraggableResizable
5
5
class-name =" component-box"
6
6
v-for =" componentData in activeRouteArray"
7
+ ref =" boxes"
7
8
:key =" componentData.componentName"
9
+ :id =" componentData.componentName"
8
10
:x =" componentData.x"
9
11
:y =" componentData.y + 20"
10
12
:z =" componentData.z"
11
13
:w =" componentData.w"
12
14
:h =" componentData.h"
13
15
:parent =" true"
16
+ :preventDeactivation =" true"
14
17
@activated =" onActivated(componentData)"
15
18
@deactivated =" onDeactivated(componentData)"
16
19
@dragging =" onDrag"
@@ -68,7 +71,7 @@ import { mapState, mapActions } from "vuex";
68
71
import VueDraggableResizable from " vue-draggable-resizable" ;
69
72
// import ChildrenMultiselect from '../components/ChildrenMultiselect'
70
73
import " vue-draggable-resizable/dist/VueDraggableResizable.css" ;
71
-
74
+ // :preventDeactivation="true"
72
75
export default {
73
76
name: " ComponentDisplay" ,
74
77
components: {
@@ -91,7 +94,7 @@ export default {
91
94
window .addEventListener (" keyup" , event => {
92
95
if (event .key === " Backspace" ) {
93
96
if (this .activeComponent && this .activeComponentData .isActive ) {
94
- console .log (' this:' , this )
97
+ // console.log('this:', this)
95
98
this .$store .dispatch (" deleteActiveComponent" );
96
99
}
97
100
}
@@ -171,6 +174,30 @@ export default {
171
174
: {};
172
175
}
173
176
},
177
+
178
+ 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
+ })
188
+ }
189
+ else {
190
+ this .$refs .boxes .forEach ((element )=> {
191
+ if (this .activeComponent === element .$attrs .id )
192
+ {
193
+ element .enabled = true
194
+ element .$emit (' activated' )
195
+ element .$emit (' update:active' , true )
196
+ }
197
+ })
198
+ }
199
+ },
200
+
174
201
methods: {
175
202
... mapActions ([
176
203
" setActiveComponent" ,
@@ -200,11 +227,30 @@ export default {
200
227
this .activeComponentData .z = z;
201
228
},
202
229
onActivated (componentData ) {
230
+ this .$refs .boxes .forEach ((element )=> {
231
+ if (element .$attrs .id !== componentData .componentName ){
232
+ element .enabled = false ;
233
+ element .$emit (' deactivated' )
234
+ element .$emit (' update:active' , false )
235
+ }
236
+ })
203
237
this .setActiveComponent (componentData .componentName );
204
238
this .activeComponentData .isActive = true ;
239
+
205
240
},
206
- onDeactivated () {
241
+
242
+ // deactivated is emitted before activated
243
+
244
+ onDeactivated (componentData ) {
245
+ if (this .activeComponent !== ' ' ){
207
246
this .activeComponentData .isActive = false ;
247
+ }
248
+ // console.log("Componentdataname", componentData.componentName)
249
+ // console.log("active component",this.activeComponent)
250
+ // if(componentData.componentName === this.activeComponent)
251
+ // {
252
+ // console.log("We just clicked without making a new active component")
253
+ // }
208
254
},
209
255
onDoubleClick (compData ) {
210
256
this .setActiveComponent (compData .componentName );
@@ -236,12 +282,18 @@ export default {
236
282
this .activeComponentData .z = this .counter ;
237
283
this .componentMap [this .activeComponent ].z = this .counter ;
238
284
239
- }
285
+ },
240
286
// @dblclick.native="onDoubleClick(componentData)"
241
287
// onDoubleClick (compData) {
242
288
// this.setActiveComponent(compData.componentName)
243
289
// this.activeComponentData.isActive = true
244
290
// }
291
+ handleClick (event ){
292
+ if (event .target .className === " component-display grid-bg" )
293
+ {
294
+ this .setActiveComponent (' ' )
295
+ }
296
+ }
245
297
}
246
298
};
247
299
</script >
0 commit comments