@@ -29,7 +29,6 @@ type Orientation = 'horizontal' | 'vertical';
2929
3030type ResizeActionType =
3131 | 'ACTION_SET_DID_MOUNT'
32- | 'ACTION_SET_IS_RESIZING'
3332 | 'ACTION_SET_HORIZONTAL_PERCENTAGE'
3433 | 'ACTION_SET_VERTICAL_PERCENTAGE' ;
3534
@@ -40,7 +39,6 @@ type ResizeAction = {
4039
4140type ResizeState = {
4241 horizontalPercentage : number ,
43- isResizing : boolean ,
4442 verticalPercentage : number ,
4543} ;
4644
@@ -81,82 +79,81 @@ function Components(_: {}) {
8179 return ( ) => clearTimeout ( timeoutID ) ;
8280 } , [ horizontalPercentage , verticalPercentage ] ) ;
8381
84- const { isResizing} = state ;
82+ const onResizeStart = ( event : SyntheticPointerEvent < HTMLElement > ) => {
83+ const element = event . currentTarget ;
84+ element . setPointerCapture ( event . pointerId ) ;
85+ } ;
86+
87+ const onResizeEnd = ( event : SyntheticPointerEvent < HTMLElement > ) => {
88+ const element = event . currentTarget ;
89+ element . releasePointerCapture ( event . pointerId ) ;
90+ } ;
91+
92+ const onResize = ( event : SyntheticPointerEvent < HTMLElement > ) => {
93+ const element = event . currentTarget ;
94+ const isResizing = element . hasPointerCapture ( event . pointerId ) ;
95+ if ( ! isResizing ) {
96+ return ;
97+ }
8598
86- const onResizeStart = ( ) =>
87- dispatch ( { type : 'ACTION_SET_IS_RESIZING' , payload : true } ) ;
99+ const resizeElement = resizeElementRef . current ;
100+ const wrapperElement = wrapperElementRef . current ;
88101
89- let onResize ;
90- let onResizeEnd ;
91- if ( isResizing ) {
92- onResizeEnd = ( ) =>
93- dispatch ( { type : 'ACTION_SET_IS_RESIZING' , payload : false } ) ;
102+ if ( wrapperElement === null || resizeElement === null ) {
103+ return ;
104+ }
94105
95- // $FlowFixMe[missing-local-annot]
96- onResize = event => {
97- const resizeElement = resizeElementRef . current ;
98- const wrapperElement = wrapperElementRef . current ;
106+ event . preventDefault ( ) ;
99107
100- if ( ! isResizing || wrapperElement === null || resizeElement === null ) {
101- return ;
102- }
108+ const orientation = getOrientation ( wrapperElement ) ;
103109
104- event . preventDefault ( ) ;
110+ const { height , width , left , top } = wrapperElement . getBoundingClientRect ( ) ;
105111
106- const orientation = getOrientation ( wrapperElement ) ;
112+ const currentMousePosition =
113+ orientation === 'horizontal' ? event . clientX - left : event . clientY - top ;
107114
108- const { height, width, left, top} = wrapperElement . getBoundingClientRect ( ) ;
115+ const boundaryMin = MINIMUM_SIZE ;
116+ const boundaryMax =
117+ orientation === 'horizontal'
118+ ? width - MINIMUM_SIZE
119+ : height - MINIMUM_SIZE ;
109120
110- const currentMousePosition =
111- orientation === 'horizontal'
112- ? event . clientX - left
113- : event . clientY - top ;
121+ const isMousePositionInBounds =
122+ currentMousePosition > boundaryMin && currentMousePosition < boundaryMax ;
114123
115- const boundaryMin = MINIMUM_SIZE ;
116- const boundaryMax =
124+ if ( isMousePositionInBounds ) {
125+ const resizedElementDimension =
126+ orientation === 'horizontal' ? width : height ;
127+ const actionType =
117128 orientation === 'horizontal'
118- ? width - MINIMUM_SIZE
119- : height - MINIMUM_SIZE ;
120-
121- const isMousePositionInBounds =
122- currentMousePosition > boundaryMin &&
123- currentMousePosition < boundaryMax ;
124-
125- if ( isMousePositionInBounds ) {
126- const resizedElementDimension =
127- orientation === 'horizontal' ? width : height ;
128- const actionType =
129- orientation === 'horizontal'
130- ? 'ACTION_SET_HORIZONTAL_PERCENTAGE'
131- : 'ACTION_SET_VERTICAL_PERCENTAGE' ;
132- const percentage =
133- ( currentMousePosition / resizedElementDimension ) * 100 ;
134-
135- setResizeCSSVariable ( resizeElement , orientation , percentage ) ;
136-
137- dispatch ( {
138- type : actionType ,
139- payload : currentMousePosition / resizedElementDimension ,
140- } ) ;
141- }
142- } ;
143- }
129+ ? 'ACTION_SET_HORIZONTAL_PERCENTAGE'
130+ : 'ACTION_SET_VERTICAL_PERCENTAGE' ;
131+ const percentage = ( currentMousePosition / resizedElementDimension ) * 100 ;
132+
133+ setResizeCSSVariable ( resizeElement , orientation , percentage ) ;
134+
135+ dispatch ( {
136+ type : actionType ,
137+ payload : currentMousePosition / resizedElementDimension ,
138+ } ) ;
139+ }
140+ } ;
144141
145142 return (
146143 < SettingsModalContextController >
147144 < OwnersListContextController >
148- < div
149- ref = { wrapperElementRef }
150- className = { styles . Components }
151- onMouseMove = { onResize }
152- onMouseLeave = { onResizeEnd }
153- onMouseUp = { onResizeEnd } >
145+ < div ref = { wrapperElementRef } className = { styles . Components } >
154146 < Fragment >
155147 < div ref = { resizeElementRef } className = { styles . TreeWrapper } >
156148 < Tree />
157149 </ div >
158150 < div className = { styles . ResizeBarWrapper } >
159- < div onMouseDown = { onResizeStart } className = { styles . ResizeBar } />
151+ < div
152+ onPointerDown = { onResizeStart }
153+ onPointerMove = { onResize }
154+ onPointerUp = { onResizeEnd }
155+ className = { styles . ResizeBar }
156+ />
160157 </ div >
161158 < div className = { styles . InspectedElementWrapper } >
162159 < NativeStyleContextController >
@@ -193,18 +190,12 @@ function initResizeState(): ResizeState {
193190
194191 return {
195192 horizontalPercentage,
196- isResizing : false ,
197193 verticalPercentage,
198194 } ;
199195}
200196
201197function resizeReducer ( state : ResizeState , action : ResizeAction ) : ResizeState {
202198 switch ( action . type ) {
203- case 'ACTION_SET_IS_RESIZING' :
204- return {
205- ...state ,
206- isResizing : action . payload ,
207- } ;
208199 case 'ACTION_SET_HORIZONTAL_PERCENTAGE' :
209200 return {
210201 ...state ,
0 commit comments