1
1
<template >
2
- <div v-el: item
2
+ <div ref = " item"
3
3
class =" vue-grid-item"
4
4
:class =" { 'vue-resizable' : isResizable, 'resizing' : isResizing, 'vue-draggable-dragging' : isDragging, 'cssTransforms' : useCssTransforms }"
5
5
:style =" style"
6
6
>
7
7
<slot ></slot >
8
- <!-- <pre>
9
- x: {{ x | json}}
10
- y: {{ y | json}}
11
- w: {{ w | json}}
12
- h: {{ h | json}}
13
- </pre>-->
14
- <span v-if =" isResizable" v-el:handle class =" vue-resizable-handle" ></span >
8
+ <span v-if =" isResizable" ref =" handle" class =" vue-resizable-handle" ></span >
15
9
</div >
16
10
</template >
17
11
<style >
62
56
<script >
63
57
import {setTopLeft , setTransform , createMarkup , getLayoutItem } from ' ./utils' ;
64
58
import {getControlPosition , offsetXYFromParentOf , createCoreData } from ' ./draggableUtils' ;
59
+ import eventBus from ' ./eventBus' ;
65
60
66
61
var interact = require (" interact.js" );
67
62
169
164
style: {}
170
165
}
171
166
},
172
- ready : function () {
173
- this .cols = this .$parent .colNum ;
174
- this .rowHeight = this .$parent .rowHeight ;
175
- this .margin = this .$parent .margin ;
176
- this .maxRows = this .$parent .maxRows ;
177
- this .isDraggable = this .$parent .isDraggable ;
178
- this .isResizable = this .$parent .isResizable ;
179
- this .useCssTransforms = this .$parent .useCssTransforms ;
180
- this .createStyle ();
181
-
182
- var self = this ;
183
- if (this .isDraggable ) {
184
- if (this .interactObj == null ) {
185
- this .interactObj = interact (this .$els .item );
186
- }
187
- this .interactObj
167
+ created () {
168
+ eventBus .$on (' updateWidth' , function (width ) {
169
+ this .updateWidth (width);
170
+ });
171
+ eventBus .$on (' compact' , function (layout ) {
172
+ this .compact (layout);
173
+ });
174
+ },
175
+ mounted : function () {
176
+ // this.$nextTick(function () {
177
+ this .cols = this .$parent .colNum ;
178
+ this .rowHeight = this .$parent .rowHeight ;
179
+ this .margin = this .$parent .margin !== undefined ? this .$parent .margin : [10 , 10 ];
180
+ this .maxRows = this .$parent .maxRows ;
181
+ this .isDraggable = this .$parent .isDraggable ;
182
+ this .isResizable = this .$parent .isResizable ;
183
+ this .useCssTransforms = this .$parent .useCssTransforms ;
184
+ this .createStyle ();
185
+
186
+ var self = this ;
187
+ if (this .isDraggable ) {
188
+ if (this .interactObj == null ) {
189
+ this .interactObj = interact (this .$refs .item );
190
+ }
191
+ this .interactObj
188
192
.draggable ({
189
193
})
190
194
.on (' dragstart dragmove dragend' , function (event ) {
191
195
self .handleDrag (event );
192
196
});
193
- }
194
- if (this .isResizable ) {
195
- if (this .interactObj == null ) {
196
- this .interactObj = interact (this .$els .item );
197
197
}
198
- this .interactObj
198
+ if (this .isResizable ) {
199
+ if (this .interactObj == null ) {
200
+ this .interactObj = interact (this .$refs .item );
201
+ }
202
+ this .interactObj
199
203
.resizable ({
200
204
preserveAspectRatio: false ,
201
205
edges: {left: false , right: true , bottom: true , top: false }
202
206
})
203
207
.on (' resizestart resizemove resizeend' , function (event ) {
204
208
self .handleResize (event );
205
209
});
206
- }
210
+ }
211
+ // });
207
212
},
208
213
watch: {
209
214
cols : function () {
331
336
this .lastW = x;
332
337
this .lastH = y;
333
338
334
- this .$dispatch ( " resizeEvent" , event .type , this .i , this .x , this .y , this .h , this .w );
339
+ this .$parent . resizeEvent ( event .type , this .i , this .x , this .y , this .h , this .w );
335
340
},
336
341
handleDrag (event ) {
337
342
if (this .isResizing ) return ;
385
390
this .lastX = x;
386
391
this .lastY = y;
387
392
388
- this .$dispatch ( " dragEvent" , event .type , this .i , this .x , this .y , this .w , this .h );
393
+ this .$parent . dragEvent ( event .type , this .i , this .x , this .y , this .w , this .h );
389
394
},
390
395
calcPosition : function (x , y , w , h ) {
391
396
const colWidth = this .calcColWidth ();
453
458
w = Math .max (Math .min (w, this .cols - this .x ), 0 );
454
459
h = Math .max (Math .min (h, this .maxRows - this .y ), 0 );
455
460
return {w, h};
461
+ },
462
+ updateWidth : function (width , colNum ) {
463
+ this .containerWidth = width;
464
+ if (colNum !== undefined && colNum !== null ) {
465
+ this .cols = colNum;
466
+ }
467
+ },
468
+ compact : function (layout ) {
469
+ var l = getLayoutItem (layout, this .i );
470
+ if (l !== undefined && l !== null ) {
471
+ this .x = l .x ;
472
+ this .y = l .y ;
473
+ this .h = l .h ;
474
+ this .w = l .w ;
475
+ }
476
+ this .createStyle ();
456
477
}
457
478
},
458
- events: {
479
+ /* events: {
459
480
updateWidth: function(width, colNum) {
460
481
this.containerWidth = width;
461
482
if (colNum !== undefined && colNum !== null) {
472
493
}
473
494
this.createStyle();
474
495
}
475
- }
496
+ }*/
476
497
}
477
498
</script >
0 commit comments