|
1 | 1 | <template> |
2 | 2 | <div ref="item" |
3 | | - class="vue-grid-item" |
4 | | - :class="{ 'vue-resizable' : resizable, 'resizing' : isResizing, 'vue-draggable-dragging' : isDragging, 'cssTransforms' : useCssTransforms }" |
5 | | - :style="style" |
6 | | - > |
| 3 | + class="vue-grid-item" |
| 4 | + :class="{ 'vue-resizable' : resizable, 'resizing' : isResizing, 'vue-draggable-dragging' : isDragging, 'cssTransforms' : useCssTransforms }" |
| 5 | + :style="style" |
| 6 | + > |
7 | 7 | <slot></slot> |
8 | 8 | <span v-if="resizable" ref="handle" :class="resizableHandleClass"></span> |
| 9 | + <span v-if="draggable" ref="dragHandle" class="vue-draggable-handle"></span> |
9 | 10 | </div> |
10 | 11 | </template> |
11 | 12 | <style> |
|
14 | 15 | transition-property: left, top, right; |
15 | 16 | /* add right for rtl */ |
16 | 17 | } |
| 18 | +
|
17 | 19 | .vue-grid-item.cssTransforms { |
18 | 20 | transition-property: transform; |
19 | 21 | } |
| 22 | +
|
20 | 23 | .vue-grid-item.resizing { |
21 | 24 | opacity: 0.6; |
22 | 25 | z-index: 3; |
|
39 | 42 | user-select: none; |
40 | 43 | } |
41 | 44 |
|
| 45 | + .vue-grid-item > .vue-draggable-handle { |
| 46 | + position: absolute; |
| 47 | + width: 20px; |
| 48 | + height: 20px; |
| 49 | + top: 0; |
| 50 | + left: 0; |
| 51 | + background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10'><circle cx='5' cy='5' r='5' fill='#999999'/></svg>") no-repeat; |
| 52 | + background-position: bottom right; |
| 53 | + padding: 0 8px 8px 0; |
| 54 | + background-repeat: no-repeat; |
| 55 | + background-origin: content-box; |
| 56 | + box-sizing: border-box; |
| 57 | + cursor: pointer; |
| 58 | + } |
| 59 | +
|
42 | 60 | .vue-grid-item > .vue-resizable-handle { |
43 | 61 | position: absolute; |
44 | 62 | width: 20px; |
|
69 | 87 | <script> |
70 | 88 | import {setTopLeft, setTopRight, setTransformRtl, setTransform, createMarkup, getLayoutItem} from './utils'; |
71 | 89 | import {getControlPosition, offsetXYFromParentOf, createCoreData} from './draggableUtils'; |
72 | | -// var eventBus = require('./eventBus'); |
| 90 | + // var eventBus = require('./eventBus'); |
73 | 91 |
|
74 | | - var interact = require("interact.js"); |
| 92 | + var interact = require("interactjs"); |
75 | 93 |
|
76 | 94 | export default { |
77 | 95 | name: "GridItem", |
78 | 96 | props: { |
79 | 97 | /*cols: { |
80 | | - type: Number, |
81 | | - required: true |
82 | | - },*/ |
| 98 | + type: Number, |
| 99 | + required: true |
| 100 | + },*/ |
83 | 101 | /*containerWidth: { |
84 | | - type: Number, |
85 | | - required: true |
86 | | -
|
87 | | - }, |
88 | | - rowHeight: { |
89 | | - type: Number, |
90 | | - required: true |
91 | | - }, |
92 | | - margin: { |
93 | | - type: Array, |
94 | | - required: true |
95 | | - }, |
96 | | - maxRows: { |
97 | | - type: Number, |
98 | | - required: true |
99 | | - },*/ |
| 102 | + type: Number, |
| 103 | + required: true |
| 104 | +
|
| 105 | + }, |
| 106 | + rowHeight: { |
| 107 | + type: Number, |
| 108 | + required: true |
| 109 | + }, |
| 110 | + margin: { |
| 111 | + type: Array, |
| 112 | + required: true |
| 113 | + }, |
| 114 | + maxRows: { |
| 115 | + type: Number, |
| 116 | + required: true |
| 117 | + },*/ |
100 | 118 | isDraggable: { |
101 | 119 | type: Boolean, |
102 | 120 | required: false, |
|
108 | 126 | default: null |
109 | 127 | }, |
110 | 128 | /*useCssTransforms: { |
111 | | - type: Boolean, |
112 | | - required: true |
113 | | - }, |
114 | | - static: { |
115 | | - type: Boolean, |
116 | | - required: false, |
117 | | - default: false |
118 | | - }, |
119 | | - */ |
| 129 | + type: Boolean, |
| 130 | + required: true |
| 131 | + }, |
| 132 | + static: { |
| 133 | + type: Boolean, |
| 134 | + required: false, |
| 135 | + default: false |
| 136 | + }, |
| 137 | + */ |
120 | 138 | minH: { |
121 | 139 | type: Number, |
122 | 140 | required: false, |
|
168 | 186 | } |
169 | 187 | }, |
170 | 188 | inject: ["eventBus"], |
171 | | - data: function() { |
| 189 | + data: function () { |
172 | 190 | return { |
173 | 191 | cols: 1, |
174 | 192 | containerWidth: 100, |
|
203 | 221 | var self = this; |
204 | 222 |
|
205 | 223 | // Accessible refernces of functions for removing in beforeDestroy |
206 | | - self.updateWidthHandler = function(width) { |
| 224 | + self.updateWidthHandler = function (width) { |
207 | 225 | self.updateWidth(width); |
208 | 226 | }; |
209 | 227 |
|
210 | | - self.compactHandler = function(layout) { |
| 228 | + self.compactHandler = function (layout) { |
211 | 229 | self.compact(layout); |
212 | 230 | }; |
213 | 231 |
|
214 | | - self.setDraggableHandler = function(isDraggable) { |
| 232 | + self.setDraggableHandler = function (isDraggable) { |
215 | 233 | if (self.isDraggable === null) { |
216 | 234 | self.draggable = isDraggable; |
217 | 235 | } |
218 | 236 | }; |
219 | 237 |
|
220 | | - self.setResizableHandler = function(isResizable) { |
| 238 | + self.setResizableHandler = function (isResizable) { |
221 | 239 | if (self.isResizable === null) { |
222 | 240 | self.resizable = isResizable; |
223 | 241 | } |
224 | 242 | }; |
225 | 243 |
|
226 | | - self.setRowHeightHandler = function(rowHeight) { |
| 244 | + self.setRowHeightHandler = function (rowHeight) { |
227 | 245 | self.rowHeight = rowHeight; |
228 | 246 | }; |
229 | 247 |
|
|
243 | 261 | this.eventBus.$on('directionchange', self.directionchangeHandler); |
244 | 262 |
|
245 | 263 | /*this.eventBus.$on('setColNum', function(colNum) { |
246 | | - self.cols = colNum; |
247 | | - });*/ |
248 | | - var direction = (document.dir !=undefined) ? |
| 264 | + self.cols = colNum; |
| 265 | + });*/ |
| 266 | + var direction = (document.dir != undefined) ? |
249 | 267 | document.dir : |
250 | 268 | document.getElementsByTagName("html")[0].getAttribute("dir"); |
251 | 269 | this.rtl = (direction == "rtl"); |
252 | 270 | }, |
253 | 271 | beforeDestroy: function(){ |
254 | 272 | var self = this; |
255 | | -
|
256 | 273 | //Remove listeners |
257 | 274 | this.eventBus.$off('updateWidth', self.updateWidthHandler); |
258 | 275 | this.eventBus.$off('compact', self.compactHandler); |
|
261 | 278 | this.eventBus.$off('setRowHeight', self.setRowHeightHandler); |
262 | 279 | this.eventBus.$off('directionchange', self.directionchangeHandler); |
263 | 280 | }, |
264 | | - mounted: function() { |
| 281 | + mounted: function () { |
265 | 282 | this.cols = this.$parent.colNum; |
266 | 283 | this.rowHeight = this.$parent.rowHeight; |
267 | 284 | this.containerWidth = this.$parent.width !== null ? this.$parent.width : 100; |
|
281 | 298 | this.createStyle(); |
282 | 299 | }, |
283 | 300 | watch: { |
284 | | - isDraggable: function() { |
| 301 | + isDraggable: function () { |
285 | 302 | this.draggable = this.isDraggable; |
286 | 303 | }, |
287 | | - draggable: function() { |
| 304 | + draggable: function () { |
288 | 305 | var self = this; |
289 | 306 | if (this.interactObj == null) { |
290 | 307 | this.interactObj = interact(this.$refs.item, {ignoreFrom: this.dragIgnoreFrom}); |
291 | 308 | } |
292 | 309 | if (this.draggable) { |
293 | | - this.interactObj.draggable({}); |
| 310 | + this.interactObj.draggable({allowFrom: '.vue-draggable-handle'}); |
294 | 311 | if (!this.dragEventSet) { |
295 | 312 | this.dragEventSet = true; |
296 | 313 | this.interactObj.on('dragstart dragmove dragend', function (event) { |
|
299 | 316 | } |
300 | 317 | } else { |
301 | 318 | this.interactObj.draggable({ |
302 | | - enabled:false |
303 | | - }); |
| 319 | + enabled: false |
| 320 | + }); |
304 | 321 | } |
305 | 322 | }, |
306 | | - isResizable: function() { |
307 | | - this.resizable = this.isResizable; |
| 323 | + isResizable: function () { |
| 324 | + this.resizable = this.isResizable; |
308 | 325 | }, |
309 | | - resizable: function() { |
| 326 | + resizable: function () { |
310 | 327 | var self = this; |
311 | 328 | if (this.interactObj == null) { |
312 | 329 | this.interactObj = interact(this.$refs.item, {ignoreFrom: this.resizeIgnoreFrom}); |
|
326 | 343 | } |
327 | 344 | } else { |
328 | 345 | this.interactObj.resizable({ |
329 | | - enabled:false |
| 346 | + enabled: false |
330 | 347 | }); |
331 | 348 | } |
332 | 349 | }, |
333 | | - rowHeight: function() { |
| 350 | + rowHeight: function () { |
334 | 351 | this.createStyle(); |
335 | 352 | }, |
336 | | - cols: function() { |
| 353 | + cols: function () { |
337 | 354 | this.createStyle(); |
338 | 355 | }, |
339 | | - containerWidth: function() { |
| 356 | + containerWidth: function () { |
340 | 357 | this.createStyle(); |
341 | 358 | }, |
342 | | - x: function() { |
| 359 | + x: function () { |
343 | 360 | this.createStyle(); |
344 | 361 | }, |
345 | | - y: function() { |
| 362 | + y: function () { |
346 | 363 | this.createStyle(); |
347 | 364 | }, |
348 | | - h: function() { |
| 365 | + h: function () { |
349 | 366 | this.createStyle(); |
350 | 367 | }, |
351 | | - w: function() { |
| 368 | + w: function () { |
352 | 369 | this.createStyle(); |
353 | 370 | } |
354 | 371 | }, |
|
362 | 379 | } |
363 | 380 | }, |
364 | 381 | methods: { |
365 | | - createStyle: function() { |
| 382 | + createStyle: function () { |
366 | 383 | if (this.x + this.w > this.cols) { |
367 | 384 | this.x = 0; |
368 | 385 | this.w = this.cols; |
|
407 | 424 | this.style = style; |
408 | 425 |
|
409 | 426 | }, |
410 | | - handleResize: function(event) { |
| 427 | + handleResize: function (event) { |
411 | 428 | const position = getControlPosition(event); |
412 | 429 | // Get the current drag point from the event. This is used as the offset. |
413 | 430 | if (position == null) return; // not possible but satisfies flow |
|
559 | 576 | } |
560 | 577 | this.eventBus.$emit("dragEvent", event.type, this.i, pos.x, pos.y, this.h, this.w); |
561 | 578 | }, |
562 | | - calcPosition: function(x, y, w, h) { |
| 579 | + calcPosition: function (x, y, w, h) { |
563 | 580 | const colWidth = this.calcColWidth(); |
564 | 581 | // add rtl support |
565 | 582 | if (this.rtl) { |
|
640 | 657 | h = Math.max(Math.min(h, this.maxRows - this.y), 0); |
641 | 658 | return {w, h}; |
642 | 659 | }, |
643 | | - updateWidth: function(width, colNum) { |
| 660 | + updateWidth: function (width, colNum) { |
644 | 661 | this.containerWidth = width; |
645 | 662 | if (colNum !== undefined && colNum !== null) { |
646 | 663 | this.cols = colNum; |
647 | 664 | } |
648 | 665 | }, |
649 | | - compact: function() { |
| 666 | + compact: function () { |
650 | 667 | this.createStyle(); |
651 | 668 | } |
652 | 669 | }, |
|
0 commit comments