1
1
import React , { Component , PropTypes } from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
- import Manager from '../Manager' ;
4
- import { closest , events , vendorPrefix , limit , getElementMargin } from '../utils' ;
3
+ import { omit } from 'lodash'
5
4
import invariant from 'invariant' ;
6
5
6
+ import Manager from '../Manager' ;
7
+ import { closest , events , vendorPrefix , limit , getElementMargin , provideDisplayName } from '../utils' ;
8
+
7
9
// Export Higher Order Sortable Container Component
8
- export default function SortableContainer ( WrappedComponent , config = { withRef : false } ) {
10
+ export default function sortableContainer ( WrappedComponent , config = { withRef : false } ) {
9
11
return class extends Component {
10
12
constructor ( props ) {
11
13
super ( props ) ;
@@ -24,9 +26,7 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
24
26
this . state = { } ;
25
27
}
26
28
27
- static displayName = ( WrappedComponent . displayName ) ? `SortableList(${ WrappedComponent . displayName } )` : 'SortableList' ;
28
-
29
- static WrappedComponent = WrappedComponent ;
29
+ static displayName = provideDisplayName ( 'sortableList' , WrappedComponent ) ;
30
30
31
31
static defaultProps = {
32
32
axis : 'y' ,
@@ -43,11 +43,7 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
43
43
}
44
44
} ,
45
45
lockToContainerEdges : false ,
46
- lockOffset : '50%' ,
47
- getHelperDimensions : ( { node} ) => ( {
48
- width : node . offsetWidth ,
49
- height : node . offsetHeight
50
- } )
46
+ lockOffset : '50%'
51
47
} ;
52
48
53
49
static propTypes = {
@@ -71,8 +67,7 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
71
67
PropTypes . string ,
72
68
PropTypes . arrayOf ( PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) )
73
69
] ) ,
74
- getContainer : PropTypes . func ,
75
- getHelperDimensions : PropTypes . func
70
+ getContainer : PropTypes . func
76
71
} ;
77
72
78
73
static childContextTypes = {
@@ -168,22 +163,17 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
168
163
const active = this . manager . getActive ( ) ;
169
164
170
165
if ( active ) {
171
- const { axis, onSortStart, helperClass, hideSortableGhost, useWindowAsScrollContainer, getHelperDimensions } = this . props ;
166
+ const { axis, onSortStart, helperClass, hideSortableGhost, useWindowAsScrollContainer} = this . props ;
172
167
let { node, collection} = active ;
173
168
const { index} = node . sortableInfo ;
174
169
const margin = getElementMargin ( node ) ;
175
170
176
171
const containerBoundingRect = this . container . getBoundingClientRect ( ) ;
177
- const dimensions = getHelperDimensions ( { index, node, collection} )
178
172
179
173
this . node = node ;
180
- this . width = dimensions . width
181
- this . height = dimensions . height
182
174
this . margin = margin ;
183
175
this . width = node . offsetWidth ;
184
176
this . height = node . offsetHeight ;
185
- this . halfWidth = this . width / 2 ;
186
- this . halfHeight = this . height / 2 ;
187
177
this . marginOffset = {
188
178
x : this . margin . left + this . margin . right ,
189
179
y : Math . max ( this . margin . top , this . margin . bottom )
@@ -219,12 +209,12 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
219
209
this . minTranslate = { } ;
220
210
this . maxTranslate = { } ;
221
211
if ( this . axis . x ) {
222
- this . minTranslate . x = ( ( useWindowAsScrollContainer ) ? 0 : containerBoundingRect . left ) - this . boundingClientRect . left - this . halfWidth ;
223
- this . maxTranslate . x = ( ( useWindowAsScrollContainer ) ? this . contentWindow . innerWidth : containerBoundingRect . left + containerBoundingRect . width ) - this . boundingClientRect . left - this . halfWidth ;
212
+ this . minTranslate . x = ( ( useWindowAsScrollContainer ) ? 0 : containerBoundingRect . left ) - this . boundingClientRect . left - ( this . width / 2 ) ;
213
+ this . maxTranslate . x = ( ( useWindowAsScrollContainer ) ? this . contentWindow . innerWidth : containerBoundingRect . left + containerBoundingRect . width ) - this . boundingClientRect . left - ( this . width / 2 ) ;
224
214
}
225
215
if ( this . axis . y ) {
226
- this . minTranslate . y = ( ( useWindowAsScrollContainer ) ? 0 : containerBoundingRect . top ) - this . boundingClientRect . top - this . halfHeight ;
227
- this . maxTranslate . y = ( ( useWindowAsScrollContainer ) ? this . contentWindow . innerHeight : containerBoundingRect . top + containerBoundingRect . height ) - this . boundingClientRect . top - this . halfHeight ;
216
+ this . minTranslate . y = ( ( useWindowAsScrollContainer ) ? 0 : containerBoundingRect . top ) - this . boundingClientRect . top - ( this . height / 2 ) ;
217
+ this . maxTranslate . y = ( ( useWindowAsScrollContainer ) ? this . contentWindow . innerHeight : containerBoundingRect . top + containerBoundingRect . height ) - this . boundingClientRect . top - ( this . height / 2 ) ;
228
218
}
229
219
230
220
if ( helperClass ) {
@@ -400,12 +390,12 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
400
390
if ( lockToContainerEdges ) {
401
391
const [ minLockOffset , maxLockOffset ] = this . getLockPixelOffsets ( ) ;
402
392
const minOffset = {
403
- x : this . halfWidth - minLockOffset . x ,
404
- y : this . halfHeight - minLockOffset . y
393
+ x : ( this . width / 2 ) - minLockOffset . x ,
394
+ y : ( this . height / 2 ) - minLockOffset . y
405
395
} ;
406
396
const maxOffset = {
407
- x : this . halfWidth - maxLockOffset . x ,
408
- y : this . halfHeight - maxLockOffset . y
397
+ x : ( this . width / 2 ) - maxLockOffset . x ,
398
+ y : ( this . height / 2 ) - maxLockOffset . y
409
399
} ;
410
400
411
401
translate . x = limit (
@@ -449,12 +439,10 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
449
439
let { node, edgeOffset} = nodes [ i ] ;
450
440
const index = node . sortableInfo . index ;
451
441
const width = node . offsetWidth ;
452
- const halfWidth = width / 2 ;
453
442
const height = node . offsetHeight ;
454
- const halfHeight = height / 2 ;
455
443
const offset = {
456
- width : ( this . width > width ) ? halfWidth : this . halfWidth ,
457
- height : ( this . height > height ) ? halfHeight : this . halfHeight
444
+ width : ( this . width > width ) ? ( width / 2 ) : ( this . width / 2 ) ,
445
+ height : ( this . height > height ) ? ( height / 2 ) : ( this . height / 2 )
458
446
} ;
459
447
let translate = {
460
448
x : 0 ,
@@ -580,21 +568,21 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
580
568
y : 10
581
569
} ;
582
570
583
- if ( translate . y >= this . maxTranslate . y - this . halfHeight ) {
571
+ if ( translate . y >= this . maxTranslate . y - ( this . height / 2 ) ) {
584
572
direction . y = 1 ; // Scroll Down
585
- speed . y = acceleration . y * Math . abs ( ( this . maxTranslate . y - this . halfHeight - translate . y ) / this . height ) ;
573
+ speed . y = acceleration . y * Math . abs ( ( this . maxTranslate . y - ( this . height / 2 ) - translate . y ) / this . height ) ;
586
574
}
587
- else if ( translate . x >= this . maxTranslate . x - this . halfWidth ) {
575
+ else if ( translate . x >= this . maxTranslate . x - ( this . width / 2 ) ) {
588
576
direction . x = 1 ; // Scroll Right
589
- speed . x = acceleration . x * Math . abs ( ( this . maxTranslate . x - this . halfWidth - translate . x ) / this . width ) ;
577
+ speed . x = acceleration . x * Math . abs ( ( this . maxTranslate . x - ( this . width / 2 ) - translate . x ) / this . width ) ;
590
578
}
591
- else if ( translate . y <= this . minTranslate . y + this . halfHeight ) {
579
+ else if ( translate . y <= this . minTranslate . y + ( this . height / 2 ) ) {
592
580
direction . y = - 1 ; // Scroll Up
593
- speed . y = acceleration . y * Math . abs ( ( translate . y - this . halfHeight - this . minTranslate . y ) / this . height ) ;
581
+ speed . y = acceleration . y * Math . abs ( ( translate . y - ( this . height / 2 ) - this . minTranslate . y ) / this . height ) ;
594
582
}
595
- else if ( translate . x <= this . minTranslate . x + this . halfWidth ) {
583
+ else if ( translate . x <= this . minTranslate . x + ( this . width / 2 ) ) {
596
584
direction . x = - 1 ; // Scroll Left
597
- speed . x = acceleration . x * Math . abs ( ( translate . x - this . halfWidth - this . minTranslate . x ) / this . width ) ;
585
+ speed . x = acceleration . x * Math . abs ( ( translate . x - ( this . width / 2 ) - this . minTranslate . x ) / this . width ) ;
598
586
}
599
587
600
588
if ( this . autoscrollInterval ) {
@@ -627,7 +615,33 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
627
615
render ( ) {
628
616
const ref = ( config . withRef ) ? 'wrappedInstance' : null ;
629
617
630
- return < WrappedComponent ref = { ref } { ...this . props } { ...this . state } /> ;
618
+ return (
619
+ < WrappedComponent
620
+ ref = { ref }
621
+ { ...omit ( this . props ,
622
+ 'contentWindow' ,
623
+ 'useWindowAsScrollContainer' ,
624
+ 'distance' ,
625
+ 'helperClass' ,
626
+ 'hideSortableGhost' ,
627
+ 'transitionDuration' ,
628
+ 'useDragHandle' ,
629
+ 'pressDelay' ,
630
+
631
+ 'shouldCancelStart' ,
632
+ 'onSortStart' ,
633
+ 'onSortMove' ,
634
+ 'onSortEnd' ,
635
+
636
+ 'axis' ,
637
+ 'lockAxis' ,
638
+ 'lockOffset' ,
639
+ 'lockToContainerEdges' ,
640
+
641
+ 'getContainer' ,
642
+ ) }
643
+ />
644
+ ) ;
631
645
}
632
646
} ;
633
647
}
0 commit comments