@@ -29,7 +29,6 @@ type Orientation = 'horizontal' | 'vertical';
29
29
30
30
type ResizeActionType =
31
31
| 'ACTION_SET_DID_MOUNT'
32
- | 'ACTION_SET_IS_RESIZING'
33
32
| 'ACTION_SET_HORIZONTAL_PERCENTAGE'
34
33
| 'ACTION_SET_VERTICAL_PERCENTAGE' ;
35
34
@@ -40,7 +39,6 @@ type ResizeAction = {
40
39
41
40
type ResizeState = {
42
41
horizontalPercentage : number ,
43
- isResizing : boolean ,
44
42
verticalPercentage : number ,
45
43
} ;
46
44
@@ -81,82 +79,81 @@ function Components(_: {}) {
81
79
return ( ) => clearTimeout ( timeoutID ) ;
82
80
} , [ horizontalPercentage , verticalPercentage ] ) ;
83
81
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
+ }
85
98
86
- const onResizeStart = ( ) =>
87
- dispatch ( { type : 'ACTION_SET_IS_RESIZING' , payload : true } ) ;
99
+ const resizeElement = resizeElementRef . current ;
100
+ const wrapperElement = wrapperElementRef . current ;
88
101
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
+ }
94
105
95
- // $FlowFixMe[missing-local-annot]
96
- onResize = event => {
97
- const resizeElement = resizeElementRef . current ;
98
- const wrapperElement = wrapperElementRef . current ;
106
+ event . preventDefault ( ) ;
99
107
100
- if ( ! isResizing || wrapperElement === null || resizeElement === null ) {
101
- return ;
102
- }
108
+ const orientation = getOrientation ( wrapperElement ) ;
103
109
104
- event . preventDefault ( ) ;
110
+ const { height , width , left , top } = wrapperElement . getBoundingClientRect ( ) ;
105
111
106
- const orientation = getOrientation ( wrapperElement ) ;
112
+ const currentMousePosition =
113
+ orientation === 'horizontal' ? event . clientX - left : event . clientY - top ;
107
114
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 ;
109
120
110
- const currentMousePosition =
111
- orientation === 'horizontal'
112
- ? event . clientX - left
113
- : event . clientY - top ;
121
+ const isMousePositionInBounds =
122
+ currentMousePosition > boundaryMin && currentMousePosition < boundaryMax ;
114
123
115
- const boundaryMin = MINIMUM_SIZE ;
116
- const boundaryMax =
124
+ if ( isMousePositionInBounds ) {
125
+ const resizedElementDimension =
126
+ orientation === 'horizontal' ? width : height ;
127
+ const actionType =
117
128
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
+ } ;
144
141
145
142
return (
146
143
< SettingsModalContextController >
147
144
< 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 } >
154
146
< Fragment >
155
147
< div ref = { resizeElementRef } className = { styles . TreeWrapper } >
156
148
< Tree />
157
149
</ div >
158
150
< 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
+ />
160
157
</ div >
161
158
< div className = { styles . InspectedElementWrapper } >
162
159
< NativeStyleContextController >
@@ -193,18 +190,12 @@ function initResizeState(): ResizeState {
193
190
194
191
return {
195
192
horizontalPercentage,
196
- isResizing : false ,
197
193
verticalPercentage,
198
194
} ;
199
195
}
200
196
201
197
function resizeReducer ( state : ResizeState , action : ResizeAction ) : ResizeState {
202
198
switch ( action . type ) {
203
- case 'ACTION_SET_IS_RESIZING' :
204
- return {
205
- ...state ,
206
- isResizing : action . payload ,
207
- } ;
208
199
case 'ACTION_SET_HORIZONTAL_PERCENTAGE' :
209
200
return {
210
201
...state ,
0 commit comments