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);
334
386
const {x , y } = position;
335
387
336
388
var shouldUpdate = false ;
337
-
338
389
const newPosition = {top: 0 , left: 0 };
339
390
switch (event .type ) {
340
391
case " dragstart" :
341
392
var parentRect = event .target .offsetParent .getBoundingClientRect ();
342
393
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
+ }
344
399
newPosition .top = clientRect .top - parentRect .top ;
345
400
this .dragging = newPosition;
346
401
this .isDragging = true ;
349
404
if (! this .isDragging ) return ;
350
405
parentRect = event .target .offsetParent .getBoundingClientRect ();
351
406
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
+ }
353
413
newPosition .top = clientRect .top - parentRect .top ;
354
414
// console.log("### drag end => " + JSON.stringify(newPosition));
355
415
// console.log("### DROP: " + JSON.stringify(newPosition));
359
419
break ;
360
420
case " dragmove" :
361
421
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
+ }
363
428
newPosition .top = this .dragging .top + coreEvent .deltaY ;
364
429
// console.log("### drag => " + event.type + ", x=" + x + ", y=" + y);
365
430
// console.log("### drag => " + event.type + ", deltaX=" + coreEvent.deltaX + ", deltaY=" + coreEvent.deltaY);
369
434
}
370
435
371
436
// 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
+ }
373
442
374
443
this .lastX = x;
375
444
this .lastY = y;
378
447
},
379
448
calcPosition : function (x , y , w , h ) {
380
449
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
+ }
381
472
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
- };
391
473
392
474
return out;
393
475
},
397
479
* @param {Number} left Left position (relative to parent) in pixels.
398
480
* @return {Object} x and y in grid units.
399
481
*/
482
+ // TODO check if this function needs change in order to support rtl.
400
483
calcXY (top , left ) {
401
484
const colWidth = this .calcColWidth ();
402
485
454
537
}
455
538
},
456
539
}
457
- </script >
540
+ </script >
0 commit comments