1- import React , { Component , CSSProperties } from 'react' ;
2- import PropTypes from 'prop-types' ;
3- import { smoothDnD as container , ContainerOptions , SmoothDnD } from 'smooth-dnd' ;
4- import { dropHandlers } from 'smooth-dnd' ;
1+ import React , { Component , CSSProperties , PropsWithChildren } from "react" ;
2+ import PropTypes from "prop-types" ;
3+ import {
4+ smoothDnD as container ,
5+ ContainerOptions ,
6+ SmoothDnD ,
7+ } from "smooth-dnd" ;
8+ import { dropHandlers } from "smooth-dnd" ;
59
610container . dropHandler = dropHandlers . reactDropHandler ( ) . handler ;
711container . wrapChild = false ;
812
913interface ContainerProps extends ContainerOptions {
10- children : React . ReactNode ;
11- render ?: ( rootRef : React . RefObject < any > ) => React . ReactElement ;
12- style ?: CSSProperties ;
14+ render ?: ( rootRef : React . RefObject < any > ) => React . ReactElement ;
15+ style ?: CSSProperties ;
1316}
1417
15- class Container extends Component < ContainerProps > {
16- public static propTypes = {
17- behaviour : PropTypes . oneOf ( [ ' move' , ' copy' , ' drop-zone' , ' contain' ] ) ,
18- groupName : PropTypes . string ,
19- orientation : PropTypes . oneOf ( [ ' horizontal' , ' vertical' ] ) ,
20- style : PropTypes . object ,
21- dragHandleSelector : PropTypes . string ,
22- nonDragAreaSelector : PropTypes . string ,
23- dragBeginDelay : PropTypes . number ,
24- animationDuration : PropTypes . number ,
25- autoScrollEnabled : PropTypes . bool ,
26- lockAxis : PropTypes . string ,
27- dragClass : PropTypes . string ,
28- dropClass : PropTypes . string ,
29- onDragStart : PropTypes . func ,
30- onDragEnd : PropTypes . func ,
31- onDrop : PropTypes . func ,
32- getChildPayload : PropTypes . func ,
33- shouldAnimateDrop : PropTypes . func ,
34- shouldAcceptDrop : PropTypes . func ,
35- onDragEnter : PropTypes . func ,
36- onDragLeave : PropTypes . func ,
37- render : PropTypes . func ,
38- getGhostParent : PropTypes . func ,
18+ class Container extends Component < PropsWithChildren < ContainerProps > > {
19+ public static propTypes = {
20+ behaviour : PropTypes . oneOf ( [ " move" , " copy" , " drop-zone" , " contain" ] ) ,
21+ groupName : PropTypes . string ,
22+ orientation : PropTypes . oneOf ( [ " horizontal" , " vertical" ] ) ,
23+ style : PropTypes . object ,
24+ dragHandleSelector : PropTypes . string ,
25+ nonDragAreaSelector : PropTypes . string ,
26+ dragBeginDelay : PropTypes . number ,
27+ animationDuration : PropTypes . number ,
28+ autoScrollEnabled : PropTypes . bool ,
29+ lockAxis : PropTypes . string ,
30+ dragClass : PropTypes . string ,
31+ dropClass : PropTypes . string ,
32+ onDragStart : PropTypes . func ,
33+ onDragEnd : PropTypes . func ,
34+ onDrop : PropTypes . func ,
35+ getChildPayload : PropTypes . func ,
36+ shouldAnimateDrop : PropTypes . func ,
37+ shouldAcceptDrop : PropTypes . func ,
38+ onDragEnter : PropTypes . func ,
39+ onDragLeave : PropTypes . func ,
40+ render : PropTypes . func ,
41+ getGhostParent : PropTypes . func ,
3942 removeOnDropOut : PropTypes . bool ,
4043 dropPlaceholder : PropTypes . oneOfType ( [
4144 PropTypes . shape ( {
@@ -45,19 +48,19 @@ class Container extends Component<ContainerProps> {
4548 } ) ,
4649 PropTypes . bool ,
4750 ] ) ,
48- } ;
51+ } ;
4952
50- public static defaultProps = {
51- behaviour : ' move' ,
52- orientation : ' vertical' ,
53- } ;
53+ public static defaultProps = {
54+ behaviour : " move" ,
55+ orientation : " vertical" ,
56+ } ;
5457
55- prevContainer : null ;
56- container : SmoothDnD = null ! ;
57- containerRef : React . RefObject < any > = React . createRef ( ) ;
58+ prevContainer : null ;
59+ container : SmoothDnD = null ! ;
60+ containerRef : React . RefObject < any > = React . createRef ( ) ;
5861 constructor ( props : ContainerProps ) {
5962 super ( props ) ;
60- this . getContainerOptions = this . getContainerOptions . bind ( this ) ;
63+ this . getContainerOptions = this . getContainerOptions . bind ( this ) ;
6164 this . getContainer = this . getContainer . bind ( this ) ;
6265 this . isObjectTypePropsChanged = this . isObjectTypePropsChanged . bind ( this ) ;
6366 this . prevContainer = null ;
@@ -77,13 +80,16 @@ class Container extends Component<ContainerProps> {
7780 if ( this . getContainer ( ) ) {
7881 if ( this . prevContainer && this . prevContainer !== this . getContainer ( ) ) {
7982 this . container . dispose ( ) ;
80- this . container = container ( this . getContainer ( ) , this . getContainerOptions ( ) ) ;
83+ this . container = container (
84+ this . getContainer ( ) ,
85+ this . getContainerOptions ( )
86+ ) ;
8187 this . prevContainer = this . getContainer ( ) ;
8288 return ;
8389 }
8490
8591 if ( this . isObjectTypePropsChanged ( prevProps ) ) {
86- this . container . setOptions ( this . getContainerOptions ( ) )
92+ this . container . setOptions ( this . getContainerOptions ( ) ) ;
8793 }
8894 }
8995 }
@@ -96,7 +102,7 @@ class Container extends Component<ContainerProps> {
96102 if ( containerOptions . hasOwnProperty ( key ) ) {
97103 const prop = containerOptions [ key ] ;
98104
99- if ( typeof prop !== ' function' && prop !== prevProps [ key ] ) {
105+ if ( typeof prop !== " function" && prop !== prevProps [ key ] ) {
100106 return true ;
101107 }
102108 }
@@ -107,35 +113,38 @@ class Container extends Component<ContainerProps> {
107113
108114 render ( ) {
109115 if ( this . props . render ) {
110- return this . props . render ( this . containerRef ) ;
116+ return this . props . render ( this . containerRef ) ;
111117 } else {
112118 return (
113119 < div style = { this . props . style } ref = { this . containerRef } >
114120 { this . props . children }
115121 </ div >
116122 ) ;
117123 }
118- }
119-
124+ }
125+
120126 getContainer ( ) {
121- return this . containerRef . current ;
122- }
127+ return this . containerRef . current ;
128+ }
123129
124130 getContainerOptions ( ) : ContainerOptions {
125- return Object . keys ( this . props ) . reduce ( ( result : ContainerOptions , key : string ) => {
126- const optionName = key as keyof ContainerOptions ;
127- const prop = this . props [ optionName ] ;
128-
129- if ( typeof prop === 'function' ) {
130- result [ optionName ] = ( ...params : any [ ] ) => {
131- return ( this . props [ optionName ] as Function ) ( ...params ) ;
131+ return Object . keys ( this . props ) . reduce (
132+ ( result : ContainerOptions , key : string ) => {
133+ const optionName = key as keyof ContainerOptions ;
134+ const prop = this . props [ optionName ] ;
135+
136+ if ( typeof prop === "function" ) {
137+ result [ optionName ] = ( ...params : any [ ] ) => {
138+ return ( this . props [ optionName ] as Function ) ( ...params ) ;
139+ } ;
140+ } else {
141+ result [ optionName ] = prop ;
132142 }
133- } else {
134- result [ optionName ] = prop ;
135- }
136143
137- return result ;
138- } , { } ) as ContainerOptions ;
144+ return result ;
145+ } ,
146+ { }
147+ ) as ContainerOptions ;
139148 }
140149}
141150
0 commit comments