|
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 | | - beforeDestroy: function(){ |
| 271 | + beforeDestroy: function () { |
254 | 272 | //Remove listeners |
255 | 273 | this.eventBus.$off('updateWidth', self.updateWidthHandler); |
256 | 274 | this.eventBus.$off('compact', self.compactHandler); |
|
259 | 277 | this.eventBus.$off('setRowHeight', self.setRowHeightHandler); |
260 | 278 | this.eventBus.$off('directionchange', self.directionchangeHandler); |
261 | 279 | }, |
262 | | - mounted: function() { |
| 280 | + mounted: function () { |
263 | 281 | this.cols = this.$parent.colNum; |
264 | 282 | this.rowHeight = this.$parent.rowHeight; |
265 | 283 | this.containerWidth = this.$parent.width !== null ? this.$parent.width : 100; |
|
279 | 297 | this.createStyle(); |
280 | 298 | }, |
281 | 299 | watch: { |
282 | | - isDraggable: function() { |
| 300 | + isDraggable: function () { |
283 | 301 | this.draggable = this.isDraggable; |
284 | 302 | }, |
285 | | - draggable: function() { |
| 303 | + draggable: function () { |
286 | 304 | var self = this; |
287 | 305 | if (this.interactObj == null) { |
288 | 306 | this.interactObj = interact(this.$refs.item, {ignoreFrom: this.dragIgnoreFrom}); |
289 | 307 | } |
290 | 308 | if (this.draggable) { |
291 | | - this.interactObj.draggable({}); |
| 309 | + this.interactObj.draggable({allowFrom: '.vue-draggable-handle'}); |
292 | 310 | if (!this.dragEventSet) { |
293 | 311 | this.dragEventSet = true; |
294 | 312 | this.interactObj.on('dragstart dragmove dragend', function (event) { |
|
297 | 315 | } |
298 | 316 | } else { |
299 | 317 | this.interactObj.draggable({ |
300 | | - enabled:false |
301 | | - }); |
| 318 | + enabled: false |
| 319 | + }); |
302 | 320 | } |
303 | 321 | }, |
304 | | - isResizable: function() { |
305 | | - this.resizable = this.isResizable; |
| 322 | + isResizable: function () { |
| 323 | + this.resizable = this.isResizable; |
306 | 324 | }, |
307 | | - resizable: function() { |
| 325 | + resizable: function () { |
308 | 326 | var self = this; |
309 | 327 | if (this.interactObj == null) { |
310 | 328 | this.interactObj = interact(this.$refs.item, {ignoreFrom: resizeIgnoreFrom}); |
|
324 | 342 | } |
325 | 343 | } else { |
326 | 344 | this.interactObj.resizable({ |
327 | | - enabled:false |
| 345 | + enabled: false |
328 | 346 | }); |
329 | 347 | } |
330 | 348 | }, |
331 | | - rowHeight: function() { |
| 349 | + rowHeight: function () { |
332 | 350 | this.createStyle(); |
333 | 351 | }, |
334 | | - cols: function() { |
| 352 | + cols: function () { |
335 | 353 | this.createStyle(); |
336 | 354 | }, |
337 | | - containerWidth: function() { |
| 355 | + containerWidth: function () { |
338 | 356 | this.createStyle(); |
339 | 357 | }, |
340 | | - x: function() { |
| 358 | + x: function () { |
341 | 359 | this.createStyle(); |
342 | 360 | }, |
343 | | - y: function() { |
| 361 | + y: function () { |
344 | 362 | this.createStyle(); |
345 | 363 | }, |
346 | | - h: function() { |
| 364 | + h: function () { |
347 | 365 | this.createStyle(); |
348 | 366 | }, |
349 | | - w: function() { |
| 367 | + w: function () { |
350 | 368 | this.createStyle(); |
351 | 369 | } |
352 | 370 | }, |
|
360 | 378 | } |
361 | 379 | }, |
362 | 380 | methods: { |
363 | | - createStyle: function() { |
| 381 | + createStyle: function () { |
364 | 382 | if (this.x + this.w > this.cols) { |
365 | 383 | this.x = 0; |
366 | 384 | this.w = this.cols; |
|
405 | 423 | this.style = style; |
406 | 424 |
|
407 | 425 | }, |
408 | | - handleResize: function(event) { |
| 426 | + handleResize: function (event) { |
409 | 427 | const position = getControlPosition(event); |
410 | 428 | // Get the current drag point from the event. This is used as the offset. |
411 | 429 | if (position == null) return; // not possible but satisfies flow |
|
557 | 575 | } |
558 | 576 | this.eventBus.$emit("dragEvent", event.type, this.i, pos.x, pos.y, this.h, this.w); |
559 | 577 | }, |
560 | | - calcPosition: function(x, y, w, h) { |
| 578 | + calcPosition: function (x, y, w, h) { |
561 | 579 | const colWidth = this.calcColWidth(); |
562 | 580 | // add rtl support |
563 | 581 | if (this.rtl) { |
|
638 | 656 | h = Math.max(Math.min(h, this.maxRows - this.y), 0); |
639 | 657 | return {w, h}; |
640 | 658 | }, |
641 | | - updateWidth: function(width, colNum) { |
| 659 | + updateWidth: function (width, colNum) { |
642 | 660 | this.containerWidth = width; |
643 | 661 | if (colNum !== undefined && colNum !== null) { |
644 | 662 | this.cols = colNum; |
645 | 663 | } |
646 | 664 | }, |
647 | | - compact: function() { |
| 665 | + compact: function () { |
648 | 666 | this.createStyle(); |
649 | 667 | } |
650 | 668 | }, |
|
0 commit comments