@@ -42,28 +42,32 @@ export type DraggableData = {
4242 lastX : number , lastY : number ,
4343} ;
4444
45- export type DraggableEventHandler = ( e : MouseEvent , data : DraggableData ) => void ;
45+ export type DraggableEventHandler = ( e : MouseEvent , data : DraggableData ) => void | false ;
4646
4747export type ControlPosition = { x : number , y : number } ;
4848export type PositionOffsetControlPosition = { x : number | string , y : number | string } ;
4949
50- export type DraggableCoreProps = {
50+ export type DraggableCoreDefaultProps = {
5151 allowAnyClick : boolean ,
52- cancel : string ,
53- children : ReactElement < any > ,
5452 disabled : boolean ,
5553 enableUserSelectHack : boolean ,
56- offsetParent : HTMLElement ,
57- grid : [ number , number ] ,
58- handle : string ,
59- nodeRef ?: ?React . ElementRef < any > ,
6054 onStart : DraggableEventHandler ,
6155 onDrag : DraggableEventHandler ,
6256 onStop : DraggableEventHandler ,
6357 onMouseDown : ( e : MouseEvent ) => void ,
6458 scale : number ,
6559} ;
6660
61+ export type DraggableCoreProps = {
62+ ...DraggableCoreDefaultProps ,
63+ cancel : string ,
64+ children : ReactElement < any > ,
65+ offsetParent : HTMLElement ,
66+ grid : [ number , number ] ,
67+ handle : string ,
68+ nodeRef ?: ?React . ElementRef < any > ,
69+ } ;
70+
6771//
6872// Define <DraggableCore>.
6973//
@@ -73,7 +77,7 @@ export type DraggableCoreProps = {
7377
7478export default class DraggableCore extends React . Component < DraggableCoreProps , DraggableCoreState > {
7579
76- static displayName = 'DraggableCore' ;
80+ static displayName : ? string = 'DraggableCore' ;
7781
7882 static propTypes = {
7983 /**
@@ -111,7 +115,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
111115 * `grid` specifies the x and y that dragging should snap to.
112116 */
113117 grid : PropTypes . arrayOf ( PropTypes . number ) ,
114-
118+
115119 /**
116120 * `handle` specifies a selector to be used as the handle that initiates drag.
117121 *
@@ -212,30 +216,25 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
212216 transform : dontSetMe
213217 } ;
214218
215- static defaultProps = {
219+ static defaultProps : DraggableCoreDefaultProps = {
216220 allowAnyClick : false , // by default only accept left click
217- cancel : null ,
218221 disabled : false ,
219222 enableUserSelectHack : true ,
220- offsetParent : null ,
221- handle : null ,
222- grid : null ,
223- transform : null ,
224223 onStart : function ( ) { } ,
225224 onDrag : function ( ) { } ,
226225 onStop : function ( ) { } ,
227226 onMouseDown : function ( ) { } ,
228227 scale : 1 ,
229228 } ;
230229
231- state = {
230+ state : DraggableCoreState = {
232231 dragging : false ,
233232 // Used while dragging to determine deltas.
234233 lastX : NaN , lastY : NaN ,
235234 touchIdentifier : null
236235 } ;
237236
238- mounted = false ;
237+ mounted : boolean = false ;
239238
240239 componentDidMount ( ) {
241240 this . mounted = true ;
@@ -266,7 +265,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
266265 // React Strict Mode compatibility: if `nodeRef` is passed, we will use it instead of trying to find
267266 // the underlying DOM node ourselves. See the README for more information.
268267 findDOMNode ( ) : ?HTMLElement {
269- return this . props . nodeRef ? this . props . nodeRef . current : ReactDOM . findDOMNode ( this ) ;
268+ return this . props ? .nodeRef ?. current ?? ReactDOM . findDOMNode ( this ) ;
270269 }
271270
272271 handleDragStart : EventHandler < MouseTouchEvent > = ( e ) => {
@@ -441,7 +440,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
441440 return this . handleDragStop ( e ) ;
442441 } ;
443442
444- render ( ) {
443+ render ( ) : React . Element < any > {
445444 // Reuse the child provided
446445 // This makes it flexible to use whatever element is wanted (div, ul, etc)
447446 return React . cloneElement ( React . Children . only ( this . props . children ) , {
@@ -450,7 +449,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
450449 onMouseDown : this . onMouseDown ,
451450 onMouseUp : this . onMouseUp ,
452451 // onTouchStart is added on `componentDidMount` so they can be added with
453- // {passive: false}, which allows it to cancel. See
452+ // {passive: false}, which allows it to cancel. See
454453 // https://developers.google.com/web/updates/2017/01/scrolling-intervention
455454 onTouchEnd : this . onTouchEnd
456455 } ) ;
0 commit comments