|
5 | 5 | :style="style"
|
6 | 6 | >
|
7 | 7 | <slot></slot>
|
8 |
| - <span v-if="isResizable" ref="handle" class="vue-resizable-handle"></span> |
| 8 | + <span v-if="isResizable" ref="handle" :class="resizableHandleClass"></span> |
9 | 9 | </div>
|
10 | 10 | </template>
|
11 | 11 | <style>
|
12 | 12 | .vue-grid-item {
|
13 | 13 | transition: all 200ms ease;
|
14 |
| - transition-property: left, top; |
| 14 | + transition-property: left, top, right; |
| 15 | + /* add right for rtl */ |
15 | 16 | }
|
16 | 17 | .vue-grid-item.cssTransforms {
|
17 | 18 | transition-property: transform;
|
|
52 | 53 | box-sizing: border-box;
|
53 | 54 | cursor: se-resize;
|
54 | 55 | }
|
| 56 | +
|
| 57 | + .vue-grid-item > .vue-rtl-resizable-handle { |
| 58 | + bottom: 0; |
| 59 | + left: 0; |
| 60 | + background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTAuMDAwMDAwMDAwMDAwMDAyIiBoZWlnaHQ9IjEwLjAwMDAwMDAwMDAwMDAwMiIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KIDwhLS0gQ3JlYXRlZCB3aXRoIE1ldGhvZCBEcmF3IC0gaHR0cDovL2dpdGh1Yi5jb20vZHVvcGl4ZWwvTWV0aG9kLURyYXcvIC0tPgogPGc+CiAgPHRpdGxlPmJhY2tncm91bmQ8L3RpdGxlPgogIDxyZWN0IGZpbGw9Im5vbmUiIGlkPSJjYW52YXNfYmFja2dyb3VuZCIgaGVpZ2h0PSIxMiIgd2lkdGg9IjEyIiB5PSItMSIgeD0iLTEiLz4KICA8ZyBkaXNwbGF5PSJub25lIiBvdmVyZmxvdz0idmlzaWJsZSIgeT0iMCIgeD0iMCIgaGVpZ2h0PSIxMDAlIiB3aWR0aD0iMTAwJSIgaWQ9ImNhbnZhc0dyaWQiPgogICA8cmVjdCBmaWxsPSJ1cmwoI2dyaWRwYXR0ZXJuKSIgc3Ryb2tlLXdpZHRoPSIwIiB5PSIwIiB4PSIwIiBoZWlnaHQ9IjEwMCUiIHdpZHRoPSIxMDAlIi8+CiAgPC9nPgogPC9nPgogPGc+CiAgPHRpdGxlPkxheWVyIDE8L3RpdGxlPgogIDxsaW5lIGNhbnZhcz0iI2ZmZmZmZiIgY2FudmFzLW9wYWNpdHk9IjEiIHN0cm9rZS1saW5lY2FwPSJ1bmRlZmluZWQiIHN0cm9rZS1saW5lam9pbj0idW5kZWZpbmVkIiBpZD0ic3ZnXzEiIHkyPSItNzAuMTc4NDA3IiB4Mj0iMTI0LjQ2NDE3NSIgeTE9Ii0zOC4zOTI3MzciIHgxPSIxNDQuODIxMjg5IiBzdHJva2Utd2lkdGg9IjEuNSIgc3Ryb2tlPSIjMDAwIiBmaWxsPSJub25lIi8+CiAgPGxpbmUgc3Ryb2tlPSIjNjY2NjY2IiBzdHJva2UtbGluZWNhcD0idW5kZWZpbmVkIiBzdHJva2UtbGluZWpvaW49InVuZGVmaW5lZCIgaWQ9InN2Z181IiB5Mj0iOS4xMDY5NTciIHgyPSIwLjk0NzI0NyIgeTE9Ii0wLjAxODEyOCIgeDE9IjAuOTQ3MjQ3IiBzdHJva2Utd2lkdGg9IjIiIGZpbGw9Im5vbmUiLz4KICA8bGluZSBzdHJva2UtbGluZWNhcD0idW5kZWZpbmVkIiBzdHJva2UtbGluZWpvaW49InVuZGVmaW5lZCIgaWQ9InN2Z183IiB5Mj0iOSIgeDI9IjEwLjA3MzUyOSIgeTE9IjkiIHgxPSItMC42NTU2NCIgc3Ryb2tlLXdpZHRoPSIyIiBzdHJva2U9IiM2NjY2NjYiIGZpbGw9Im5vbmUiLz4KIDwvZz4KPC9zdmc+); |
| 61 | + background-position: bottom left; |
| 62 | + padding-left: 3px; |
| 63 | + background-repeat: no-repeat; |
| 64 | + background-origin: content-box; |
| 65 | + cursor: sw-resize; |
| 66 | + right: auto; |
| 67 | + } |
55 | 68 | </style>
|
56 | 69 | <script>
|
57 |
| - import {setTopLeft, setTransform, createMarkup, getLayoutItem} from './utils'; |
| 70 | + import {setTopLeft, setTopRight, setTransformRtl, setTransform, createMarkup, getLayoutItem} from './utils'; |
58 | 71 | import {getControlPosition, offsetXYFromParentOf, createCoreData} from './draggableUtils';
|
59 | 72 | var eventBus = require('./eventBus');
|
60 | 73 |
|
|
140 | 153 | },
|
141 | 154 | i: {
|
142 | 155 | required: true
|
143 |
| - }, |
| 156 | + } |
144 | 157 | },
|
145 | 158 | data: function() {
|
146 | 159 | return {
|
|
161 | 174 | lastY: NaN,
|
162 | 175 | lastW: NaN,
|
163 | 176 | lastH: NaN,
|
164 |
| - style: {} |
| 177 | + style: {}, |
| 178 | + rtl: false |
165 | 179 | }
|
166 | 180 | },
|
167 | 181 | created () {
|
|
172 | 186 | eventBus.$on('compact', function(layout) {
|
173 | 187 | self.compact(layout);
|
174 | 188 | });
|
| 189 | + var direction = (document.dir !=undefined) ? |
| 190 | + document.dir : |
| 191 | + document.getElementsByTagName("html")[0].getAttribute("dir"); |
| 192 | + this.rtl = (direction == "rtl"); |
| 193 | + eventBus.$on('directionchange', (direction) => { |
| 194 | + var direction = (document.dir != undefined) ? |
| 195 | + document.dir : |
| 196 | + document.getElementsByTagName("html")[0].getAttribute("dir"); |
| 197 | + this.rtl = (direction == "rtl"); |
| 198 | + this.compact(); |
| 199 | + }); |
175 | 200 | },
|
176 | 201 | mounted: function() {
|
177 | 202 | this.cols = this.$parent.colNum;
|
|
231 | 256 | }
|
232 | 257 | },
|
233 | 258 | computed: {
|
| 259 | + resizableHandleClass() { |
| 260 | + if (this.rtl) { |
| 261 | + return 'vue-resizable-handle vue-rtl-resizable-handle'; |
| 262 | + } else { |
| 263 | + return 'vue-resizable-handle'; |
| 264 | + } |
| 265 | + } |
234 | 266 | },
|
235 | 267 | methods: {
|
236 | 268 | createStyle: function() {
|
|
243 | 275 |
|
244 | 276 | if (this.isDragging) {
|
245 | 277 | pos.top = this.dragging.top;
|
246 |
| - pos.left = this.dragging.left; |
| 278 | +// Add rtl support |
| 279 | + if (this.rtl) { |
| 280 | + pos.right = this.dragging.left; |
| 281 | + } else { |
| 282 | + pos.left = this.dragging.left; |
| 283 | + } |
247 | 284 | }
|
248 | 285 | if (this.isResizing) {
|
249 | 286 | pos.width = this.resizing.width;
|
|
253 | 290 | let style;
|
254 | 291 | // CSS Transforms support (default)
|
255 | 292 | if (this.useCssTransforms) {
|
256 |
| - style = setTransform(pos.top, pos.left, pos.width, pos.height); |
| 293 | +// Add rtl support |
| 294 | + if (this.rtl) { |
| 295 | + style = setTransformRtl(pos.top, pos.right, pos.width, pos.height); |
| 296 | + } else { |
| 297 | + style = setTransform(pos.top, pos.left, pos.width, pos.height); |
| 298 | + } |
| 299 | +
|
257 | 300 | }
|
258 | 301 | // top,left (slow)
|
259 | 302 | else {
|
260 |
| - style = setTopLeft(pos.top, pos.left, pos.width, pos.height); |
| 303 | +// Add rtl support |
| 304 | + if (this.rtl) { |
| 305 | + style = setTopRight(pos.top, pos.right, pos.width, pos.height); |
| 306 | + } else { |
| 307 | + style = setTopLeft(pos.top, pos.left, pos.width, pos.height); |
| 308 | + } |
261 | 309 | }
|
262 | 310 | this.style = style;
|
263 | 311 |
|
|
280 | 328 | case "resizemove":
|
281 | 329 | // console.log("### resize => " + event.type + ", lastW=" + this.lastW + ", lastH=" + this.lastH);
|
282 | 330 | const coreEvent = createCoreData(this.lastW, this.lastH, x, y);
|
283 |
| - newSize.width = this.resizing.width + coreEvent.deltaX; |
| 331 | + if (this.rtl) { |
| 332 | + newSize.width = this.resizing.width - coreEvent.deltaX; |
| 333 | + } else { |
| 334 | + newSize.width = this.resizing.width + coreEvent.deltaX; |
| 335 | + } |
284 | 336 | newSize.height = this.resizing.height + coreEvent.deltaY;
|
285 | 337 |
|
286 | 338 | ///console.log("### resize => " + event.type + ", deltaX=" + coreEvent.deltaX + ", deltaY=" + coreEvent.deltaY);
|
|
335 | 387 | const {x, y} = position;
|
336 | 388 |
|
337 | 389 | var shouldUpdate = false;
|
338 |
| -
|
339 | 390 | const newPosition = {top: 0, left: 0};
|
340 | 391 | switch (event.type) {
|
341 | 392 | case "dragstart":
|
342 | 393 | var parentRect = event.target.offsetParent.getBoundingClientRect();
|
343 | 394 | var clientRect = event.target.getBoundingClientRect();
|
344 |
| - newPosition.left = clientRect.left - parentRect.left; |
| 395 | + if (this.rtl) { |
| 396 | + newPosition.left = (clientRect.right - parentRect.right) * -1; |
| 397 | + } else { |
| 398 | + newPosition.left = clientRect.left - parentRect.left; |
| 399 | + } |
345 | 400 | newPosition.top = clientRect.top - parentRect.top;
|
346 | 401 | this.dragging = newPosition;
|
347 | 402 | this.isDragging = true;
|
|
350 | 405 | if (!this.isDragging) return;
|
351 | 406 | parentRect = event.target.offsetParent.getBoundingClientRect();
|
352 | 407 | clientRect = event.target.getBoundingClientRect();
|
353 |
| - newPosition.left = clientRect.left - parentRect.left; |
| 408 | +// Add rtl support |
| 409 | + if (this.rtl) { |
| 410 | + newPosition.left = (clientRect.right - parentRect.right) * -1; |
| 411 | + } else { |
| 412 | + newPosition.left = clientRect.left - parentRect.left; |
| 413 | + } |
354 | 414 | newPosition.top = clientRect.top - parentRect.top;
|
355 | 415 | // console.log("### drag end => " + JSON.stringify(newPosition));
|
356 | 416 | // console.log("### DROP: " + JSON.stringify(newPosition));
|
|
360 | 420 | break;
|
361 | 421 | case "dragmove":
|
362 | 422 | const coreEvent = createCoreData(this.lastX, this.lastY, x, y);
|
363 |
| - newPosition.left = this.dragging.left + coreEvent.deltaX; |
| 423 | +// Add rtl support |
| 424 | + if (this.rtl) { |
| 425 | + newPosition.left = this.dragging.left - coreEvent.deltaX; |
| 426 | + } else { |
| 427 | + newPosition.left = this.dragging.left + coreEvent.deltaX; |
| 428 | + } |
364 | 429 | newPosition.top = this.dragging.top + coreEvent.deltaY;
|
365 | 430 | // console.log("### drag => " + event.type + ", x=" + x + ", y=" + y);
|
366 | 431 | // console.log("### drag => " + event.type + ", deltaX=" + coreEvent.deltaX + ", deltaY=" + coreEvent.deltaY);
|
|
370 | 435 | }
|
371 | 436 |
|
372 | 437 | // Get new XY
|
373 |
| - var pos = this.calcXY(newPosition.top, newPosition.left); |
| 438 | + if (this.rtl) { |
| 439 | + var pos = this.calcXY(newPosition.top, newPosition.left); |
| 440 | + } else { |
| 441 | + var pos = this.calcXY(newPosition.top, newPosition.left); |
| 442 | + } |
374 | 443 |
|
375 | 444 | this.lastX = x;
|
376 | 445 | this.lastY = y;
|
|
380 | 449 | },
|
381 | 450 | calcPosition: function(x, y, w, h) {
|
382 | 451 | const colWidth = this.calcColWidth();
|
| 452 | + // add rtl support |
| 453 | + if (this.rtl) { |
| 454 | + var out = { |
| 455 | + right: Math.round(colWidth * x + (x + 1) * this.margin[0]), |
| 456 | + top: Math.round(this.rowHeight * y + (y + 1) * this.margin[1]), |
| 457 | + // 0 * Infinity === NaN, which causes problems with resize constriants; |
| 458 | + // Fix this if it occurs. |
| 459 | + // Note we do it here rather than later because Math.round(Infinity) causes deopt |
| 460 | + width: w === Infinity ? w : Math.round(colWidth * w + Math.max(0, w - 1) * this.margin[0]), |
| 461 | + height: h === Infinity ? h : Math.round(this.rowHeight * h + Math.max(0, h - 1) * this.margin[1]) |
| 462 | + }; |
| 463 | + } else { |
| 464 | + var out = { |
| 465 | + left: Math.round(colWidth * x + (x + 1) * this.margin[0]), |
| 466 | + top: Math.round(this.rowHeight * y + (y + 1) * this.margin[1]), |
| 467 | + // 0 * Infinity === NaN, which causes problems with resize constriants; |
| 468 | + // Fix this if it occurs. |
| 469 | + // Note we do it here rather than later because Math.round(Infinity) causes deopt |
| 470 | + width: w === Infinity ? w : Math.round(colWidth * w + Math.max(0, w - 1) * this.margin[0]), |
| 471 | + height: h === Infinity ? h : Math.round(this.rowHeight * h + Math.max(0, h - 1) * this.margin[1]) |
| 472 | + }; |
| 473 | + } |
383 | 474 |
|
384 |
| - const out = { |
385 |
| - left: Math.round(colWidth * x + (x + 1) * this.margin[0]), |
386 |
| - top: Math.round(this.rowHeight * y + (y + 1) * this.margin[1]), |
387 |
| - // 0 * Infinity === NaN, which causes problems with resize constriants; |
388 |
| - // Fix this if it occurs. |
389 |
| - // Note we do it here rather than later because Math.round(Infinity) causes deopt |
390 |
| - width: w === Infinity ? w : Math.round(colWidth * w + Math.max(0, w - 1) * this.margin[0]), |
391 |
| - height: h === Infinity ? h : Math.round(this.rowHeight * h + Math.max(0, h - 1) * this.margin[1]) |
392 |
| - }; |
393 | 475 |
|
394 | 476 | return out;
|
395 | 477 | },
|
|
399 | 481 | * @param {Number} left Left position (relative to parent) in pixels.
|
400 | 482 | * @return {Object} x and y in grid units.
|
401 | 483 | */
|
| 484 | + // TODO check if this function needs change in order to support rtl. |
402 | 485 | calcXY(top, left) {
|
403 | 486 | const colWidth = this.calcColWidth();
|
404 | 487 |
|
|
0 commit comments