@@ -78,7 +78,17 @@ class Box extends PureComponent {
78
78
const left = e . clientX - deltaX ;
79
79
const top = e . clientY - deltaY ;
80
80
81
- const currentPosition = calculateBoundariesForDrag ( left , top , boxWidth , boxHeight , boundingBoxDimensions ) ;
81
+ let currentPosition = this . props . boundToParent ?
82
+ calculateBoundariesForDrag ( left , top , boxWidth , boxHeight , boundingBoxDimensions ) :
83
+ {
84
+ left,
85
+ top,
86
+ width : this . props . position . width ,
87
+ height : this . props . position . height ,
88
+ x : left ,
89
+ y : top ,
90
+ node : this . box . current
91
+ } ;
82
92
data = {
83
93
x : currentPosition . left ,
84
94
y : currentPosition . top ,
@@ -268,37 +278,40 @@ class Box extends PureComponent {
268
278
const type = target . id . replace ( 'resize-' , '' ) ;
269
279
270
280
const { position : { cx, cy } , size : { width, height } } = getNewStyle ( type , rect , deltaW , deltaH , 10 , 10 ) ; // Use a better way to set minWidth and minHeight
271
- const currentPosition = centerToTopLeft ( { cx, cy, width, height, rotateAngle } ) ;
281
+ const tempPosition = centerToTopLeft ( { cx, cy, width, height, rotateAngle } ) ;
272
282
273
283
data = {
274
- width : currentPosition . width ,
275
- height : currentPosition . height ,
276
- x : currentPosition . left ,
277
- y : currentPosition . top ,
278
- left : currentPosition . left ,
279
- top : currentPosition . top ,
284
+ width : tempPosition . width ,
285
+ height : tempPosition . height ,
286
+ x : tempPosition . left ,
287
+ y : tempPosition . top ,
288
+ left : tempPosition . left ,
289
+ top : tempPosition . top ,
280
290
rotateAngle,
281
291
node : this . box . current
282
292
} ;
283
293
284
294
// if (rotateAngle !== 0) {
285
295
// data = {
286
- // width: currentPosition .width,
287
- // height: currentPosition .height,
288
- // x: currentPosition .left,
289
- // y: currentPosition .top,
290
- // left: currentPosition .left,
291
- // top: currentPosition .top,
296
+ // width: tempPosition .width,
297
+ // height: tempPosition .height,
298
+ // x: tempPosition .left,
299
+ // y: tempPosition .top,
300
+ // left: tempPosition .left,
301
+ // top: tempPosition .top,
292
302
// rotateAngle,
293
303
// node: this.box.current
294
304
// };
295
305
// }
296
306
297
307
// Calculate the restrictions if resize goes out of bounds
298
- const restrictResizeWithinBoundaries = calculateBoundariesForResize ( data . left , data . top , currentPosition . width , currentPosition . height , boundingBoxPosition ) ;
299
- data = Object . assign ( { } , data , restrictResizeWithinBoundaries , {
300
- x : restrictResizeWithinBoundaries . left ,
301
- y : restrictResizeWithinBoundaries . top
308
+ const currentPosition = this . props . boundToParent ?
309
+ calculateBoundariesForResize ( data . left , data . top , tempPosition . width , tempPosition . height , boundingBoxPosition ) :
310
+ Object . assign ( { } , data ) ;
311
+
312
+ data = Object . assign ( { } , data , currentPosition , {
313
+ x : currentPosition . left ,
314
+ y : currentPosition . top
302
315
} ) ;
303
316
304
317
this . props . onResize && this . props . onResize ( e , data ) ;
@@ -499,6 +512,7 @@ class Box extends PureComponent {
499
512
}
500
513
501
514
Box . propTypes = {
515
+ boundToParent : PropTypes . bool ,
502
516
drag : PropTypes . bool ,
503
517
getBoundingBoxElement : PropTypes . func ,
504
518
id : PropTypes . string ,
0 commit comments