55 :style =" style"
66 >
77 <slot ></slot >
8- <span v-if =" isResizable" ref =" handle" class =" vue-resizable-handle " ></span >
8+ <span v-if =" isResizable" ref =" handle" : class =" resizableHandleClass " ></span >
99 </div >
1010</template >
1111<style >
1212 .vue-grid-item {
1313 transition : all 200ms ease ;
14- transition-property : left , top ;
14+ transition-property : left , top , right ;
15+ /* add right for rtl */
1516 }
1617 .vue-grid-item.cssTransforms {
1718 transition-property : transform;
5253 box-sizing : border-box ;
5354 cursor : se-resize ;
5455 }
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+ }
5568 </style >
5669<script >
57- import {setTopLeft , setTransform , createMarkup , getLayoutItem } from ' ./utils' ;
70+ import {setTopLeft , setTopRight , setTransformRtl , setTransform , createMarkup , getLayoutItem } from ' ./utils' ;
5871 import {getControlPosition , offsetXYFromParentOf , createCoreData } from ' ./draggableUtils' ;
5972 var eventBus = require (' ./eventBus' );
6073
140153 },
141154 i: {
142155 required: true
143- },
156+ }
144157 },
145158 data : function () {
146159 return {
161174 lastY: NaN ,
162175 lastW: NaN ,
163176 lastH: NaN ,
164- style: {}
177+ style: {},
178+ rtl: false
165179 }
166180 },
167181 created () {
172186 eventBus .$on (' compact' , function (layout ) {
173187 self .compact (layout);
174188 });
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+ });
175200 },
176201 mounted : function () {
177202 this .cols = this .$parent .colNum ;
231256 }
232257 },
233258 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+ }
234266 },
235267 methods: {
236268 createStyle : function () {
243275
244276 if (this .isDragging ) {
245277 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+ }
247284 }
248285 if (this .isResizing ) {
249286 pos .width = this .resizing .width ;
253290 let style;
254291 // CSS Transforms support (default)
255292 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+
257300 }
258301 // top,left (slow)
259302 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+ }
261309 }
262310 this .style = style;
263311
280328 case " resizemove" :
281329// console.log("### resize => " + event.type + ", lastW=" + this.lastW + ", lastH=" + this.lastH);
282330 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+ }
284336 newSize .height = this .resizing .height + coreEvent .deltaY ;
285337
286338 // /console.log("### resize => " + event.type + ", deltaX=" + coreEvent.deltaX + ", deltaY=" + coreEvent.deltaY);
334386 const {x , y } = position;
335387
336388 var shouldUpdate = false ;
337-
338389 const newPosition = {top: 0 , left: 0 };
339390 switch (event .type ) {
340391 case " dragstart" :
341392 var parentRect = event .target .offsetParent .getBoundingClientRect ();
342393 var clientRect = event .target .getBoundingClientRect ();
343- newPosition .left = clientRect .left - parentRect .left ;
394+ if (this .rtl ) {
395+ newPosition .left = (clientRect .right - parentRect .right ) * - 1 ;
396+ } else {
397+ newPosition .left = clientRect .left - parentRect .left ;
398+ }
344399 newPosition .top = clientRect .top - parentRect .top ;
345400 this .dragging = newPosition;
346401 this .isDragging = true ;
349404 if (! this .isDragging ) return ;
350405 parentRect = event .target .offsetParent .getBoundingClientRect ();
351406 clientRect = event .target .getBoundingClientRect ();
352- newPosition .left = clientRect .left - parentRect .left ;
407+ // Add rtl support
408+ if (this .rtl ) {
409+ newPosition .left = (clientRect .right - parentRect .right ) * - 1 ;
410+ } else {
411+ newPosition .left = clientRect .left - parentRect .left ;
412+ }
353413 newPosition .top = clientRect .top - parentRect .top ;
354414// console.log("### drag end => " + JSON.stringify(newPosition));
355415// console.log("### DROP: " + JSON.stringify(newPosition));
359419 break ;
360420 case " dragmove" :
361421 const coreEvent = createCoreData (this .lastX , this .lastY , x, y);
362- newPosition .left = this .dragging .left + coreEvent .deltaX ;
422+ // Add rtl support
423+ if (this .rtl ) {
424+ newPosition .left = this .dragging .left - coreEvent .deltaX ;
425+ } else {
426+ newPosition .left = this .dragging .left + coreEvent .deltaX ;
427+ }
363428 newPosition .top = this .dragging .top + coreEvent .deltaY ;
364429// console.log("### drag => " + event.type + ", x=" + x + ", y=" + y);
365430// console.log("### drag => " + event.type + ", deltaX=" + coreEvent.deltaX + ", deltaY=" + coreEvent.deltaY);
369434 }
370435
371436 // Get new XY
372- var pos = this .calcXY (newPosition .top , newPosition .left );
437+ if (this .rtl ) {
438+ var pos = this .calcXY (newPosition .top , newPosition .left );
439+ } else {
440+ var pos = this .calcXY (newPosition .top , newPosition .left );
441+ }
373442
374443 this .lastX = x;
375444 this .lastY = y;
378447 },
379448 calcPosition : function (x , y , w , h ) {
380449 const colWidth = this .calcColWidth ();
450+ // add rtl support
451+ if (this .rtl ) {
452+ var out = {
453+ right: Math .round (colWidth * x + (x + 1 ) * this .margin [0 ]),
454+ top: Math .round (this .rowHeight * y + (y + 1 ) * this .margin [1 ]),
455+ // 0 * Infinity === NaN, which causes problems with resize constriants;
456+ // Fix this if it occurs.
457+ // Note we do it here rather than later because Math.round(Infinity) causes deopt
458+ width: w === Infinity ? w : Math .round (colWidth * w + Math .max (0 , w - 1 ) * this .margin [0 ]),
459+ height: h === Infinity ? h : Math .round (this .rowHeight * h + Math .max (0 , h - 1 ) * this .margin [1 ])
460+ };
461+ } else {
462+ var out = {
463+ left: Math .round (colWidth * x + (x + 1 ) * this .margin [0 ]),
464+ top: Math .round (this .rowHeight * y + (y + 1 ) * this .margin [1 ]),
465+ // 0 * Infinity === NaN, which causes problems with resize constriants;
466+ // Fix this if it occurs.
467+ // Note we do it here rather than later because Math.round(Infinity) causes deopt
468+ width: w === Infinity ? w : Math .round (colWidth * w + Math .max (0 , w - 1 ) * this .margin [0 ]),
469+ height: h === Infinity ? h : Math .round (this .rowHeight * h + Math .max (0 , h - 1 ) * this .margin [1 ])
470+ };
471+ }
381472
382- const out = {
383- left: Math .round (colWidth * x + (x + 1 ) * this .margin [0 ]),
384- top: Math .round (this .rowHeight * y + (y + 1 ) * this .margin [1 ]),
385- // 0 * Infinity === NaN, which causes problems with resize constriants;
386- // Fix this if it occurs.
387- // Note we do it here rather than later because Math.round(Infinity) causes deopt
388- width: w === Infinity ? w : Math .round (colWidth * w + Math .max (0 , w - 1 ) * this .margin [0 ]),
389- height: h === Infinity ? h : Math .round (this .rowHeight * h + Math .max (0 , h - 1 ) * this .margin [1 ])
390- };
391473
392474 return out;
393475 },
397479 * @param {Number} left Left position (relative to parent) in pixels.
398480 * @return {Object} x and y in grid units.
399481 */
482+ // TODO check if this function needs change in order to support rtl.
400483 calcXY (top , left ) {
401484 const colWidth = this .calcColWidth ();
402485
454537 }
455538 },
456539 }
457- </script >
540+ </script >
0 commit comments