11import React , { Component , PropTypes } from 'react' ;
22import ReactDOM from 'react-dom' ;
3- import Manager from '../Manager' ;
4- import { closest , events , vendorPrefix , limit , getElementMargin } from '../utils' ;
3+ import { omit } from 'lodash'
54import invariant from 'invariant' ;
65
6+ import Manager from '../Manager' ;
7+ import { closest , events , vendorPrefix , limit , getElementMargin , provideDisplayName } from '../utils' ;
8+
79// Export Higher Order Sortable Container Component
8- export default function SortableContainer ( WrappedComponent , config = { withRef : false } ) {
10+ export default function sortableContainer ( WrappedComponent , config = { withRef : false } ) {
911 return class extends Component {
1012 constructor ( props ) {
1113 super ( props ) ;
@@ -24,9 +26,7 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
2426 this . state = { } ;
2527 }
2628
27- static displayName = ( WrappedComponent . displayName ) ? `SortableList(${ WrappedComponent . displayName } )` : 'SortableList' ;
28-
29- static WrappedComponent = WrappedComponent ;
29+ static displayName = provideDisplayName ( 'sortableList' , WrappedComponent ) ;
3030
3131 static defaultProps = {
3232 axis : 'y' ,
@@ -43,11 +43,7 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
4343 }
4444 } ,
4545 lockToContainerEdges : false ,
46- lockOffset : '50%' ,
47- getHelperDimensions : ( { node} ) => ( {
48- width : node . offsetWidth ,
49- height : node . offsetHeight
50- } )
46+ lockOffset : '50%'
5147 } ;
5248
5349 static propTypes = {
@@ -71,8 +67,7 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
7167 PropTypes . string ,
7268 PropTypes . arrayOf ( PropTypes . oneOfType ( [ PropTypes . number , PropTypes . string ] ) )
7369 ] ) ,
74- getContainer : PropTypes . func ,
75- getHelperDimensions : PropTypes . func
70+ getContainer : PropTypes . func
7671 } ;
7772
7873 static childContextTypes = {
@@ -168,22 +163,17 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
168163 const active = this . manager . getActive ( ) ;
169164
170165 if ( active ) {
171- const { axis, onSortStart, helperClass, hideSortableGhost, useWindowAsScrollContainer, getHelperDimensions } = this . props ;
166+ const { axis, onSortStart, helperClass, hideSortableGhost, useWindowAsScrollContainer} = this . props ;
172167 let { node, collection} = active ;
173168 const { index} = node . sortableInfo ;
174169 const margin = getElementMargin ( node ) ;
175170
176171 const containerBoundingRect = this . container . getBoundingClientRect ( ) ;
177- const dimensions = getHelperDimensions ( { index, node, collection} )
178172
179173 this . node = node ;
180- this . width = dimensions . width
181- this . height = dimensions . height
182174 this . margin = margin ;
183175 this . width = node . offsetWidth ;
184176 this . height = node . offsetHeight ;
185- this . halfWidth = this . width / 2 ;
186- this . halfHeight = this . height / 2 ;
187177 this . marginOffset = {
188178 x : this . margin . left + this . margin . right ,
189179 y : Math . max ( this . margin . top , this . margin . bottom )
@@ -219,12 +209,12 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
219209 this . minTranslate = { } ;
220210 this . maxTranslate = { } ;
221211 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 ) ;
224214 }
225215 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 ) ;
228218 }
229219
230220 if ( helperClass ) {
@@ -400,12 +390,12 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
400390 if ( lockToContainerEdges ) {
401391 const [ minLockOffset , maxLockOffset ] = this . getLockPixelOffsets ( ) ;
402392 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
405395 } ;
406396 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
409399 } ;
410400
411401 translate . x = limit (
@@ -449,12 +439,10 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
449439 let { node, edgeOffset} = nodes [ i ] ;
450440 const index = node . sortableInfo . index ;
451441 const width = node . offsetWidth ;
452- const halfWidth = width / 2 ;
453442 const height = node . offsetHeight ;
454- const halfHeight = height / 2 ;
455443 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 )
458446 } ;
459447 let translate = {
460448 x : 0 ,
@@ -580,21 +568,21 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
580568 y : 10
581569 } ;
582570
583- if ( translate . y >= this . maxTranslate . y - this . halfHeight ) {
571+ if ( translate . y >= this . maxTranslate . y - ( this . height / 2 ) ) {
584572 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 ) ;
586574 }
587- else if ( translate . x >= this . maxTranslate . x - this . halfWidth ) {
575+ else if ( translate . x >= this . maxTranslate . x - ( this . width / 2 ) ) {
588576 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 ) ;
590578 }
591- else if ( translate . y <= this . minTranslate . y + this . halfHeight ) {
579+ else if ( translate . y <= this . minTranslate . y + ( this . height / 2 ) ) {
592580 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 ) ;
594582 }
595- else if ( translate . x <= this . minTranslate . x + this . halfWidth ) {
583+ else if ( translate . x <= this . minTranslate . x + ( this . width / 2 ) ) {
596584 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 ) ;
598586 }
599587
600588 if ( this . autoscrollInterval ) {
@@ -627,7 +615,33 @@ export default function SortableContainer(WrappedComponent, config = {withRef: f
627615 render ( ) {
628616 const ref = ( config . withRef ) ? 'wrappedInstance' : null ;
629617
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+ ) ;
631645 }
632646 } ;
633647}
0 commit comments