@@ -17,15 +17,18 @@ import {
1717 getTransformStyles ,
1818 makePassiveEventOption ,
1919 getCenterPosition ,
20+ isExcludedNode ,
2021} from "../utils" ;
2122import { handleCancelAnimation } from "./animations/animations.utils" ;
22- import { isWheelAllowed } from "./wheel/wheel.utils" ;
23+ import { isWheelAllowed , isWheelPanningAllowed } from "./wheel/wheel.utils" ;
2324import { isPinchAllowed , isPinchStartAllowed } from "./pinch/pinch.utils" ;
2425import { handleCalculateBounds } from "./bounds/bounds.utils" ;
2526import {
2627 handleWheelStart ,
2728 handleWheelZoom ,
2829 handleWheelStop ,
30+ handleWheelPanningStop ,
31+ handleWheelPanningStart ,
2932} from "./wheel/wheel.logic" ;
3033import {
3134 getPaddingValue ,
@@ -135,6 +138,16 @@ export class ZoomPanPinch {
135138 this . onWheelPanning ,
136139 passive ,
137140 ) ;
141+ this . wrapperComponent ?. addEventListener (
142+ "keyup" ,
143+ this . setKeyUnPressed ,
144+ passive ,
145+ ) ;
146+ this . wrapperComponent ?. addEventListener (
147+ "keydown" ,
148+ this . setKeyPressed ,
149+ passive ,
150+ ) ;
138151 // Panning on window to allow panning when mouse is out of component wrapper
139152 currentWindow ?. addEventListener ( "mousedown" , this . onPanningStart , passive ) ;
140153 currentWindow ?. addEventListener ( "mousemove" , this . onPanning , passive ) ;
@@ -163,7 +176,21 @@ export class ZoomPanPinch {
163176 currentWindow ?. removeEventListener ( "keyup" , this . setKeyUnPressed , passive ) ;
164177 currentWindow ?. removeEventListener ( "keydown" , this . setKeyPressed , passive ) ;
165178 document . removeEventListener ( "mouseleave" , this . clearPanning , passive ) ;
166-
179+ this . wrapperComponent ?. removeEventListener (
180+ "wheel" ,
181+ this . onWheelPanning ,
182+ passive ,
183+ ) ;
184+ this . wrapperComponent ?. removeEventListener (
185+ "keyup" ,
186+ this . setKeyUnPressed ,
187+ passive ,
188+ ) ;
189+ this . wrapperComponent ?. removeEventListener (
190+ "keydown" ,
191+ this . setKeyPressed ,
192+ passive ,
193+ ) ;
167194 handleCancelAnimation ( this ) ;
168195 this . observer ?. disconnect ( ) ;
169196 } ;
@@ -222,56 +249,55 @@ export class ZoomPanPinch {
222249 const isAllowed = isWheelAllowed ( this , event ) ;
223250 if ( ! isAllowed ) return ;
224251
225- const keysPressed = this . isPressingKeys ( this . setup . wheel . activationKeys ) ;
226- if ( ! keysPressed ) return ;
227-
228252 handleWheelStart ( this , event ) ;
229253 handleWheelZoom ( this , event ) ;
230254 handleWheelStop ( this , event ) ;
231255 } ;
232256
233257 /// ///////
234- // Pan
258+ // Track Pad Panning
235259 /// ///////
236260
237261 onWheelPanning = ( event : WheelEvent ) : void => {
238- const { disabled, wheel, panning } = this . setup ;
239- if (
240- ! this . wrapperComponent ||
241- ! this . contentComponent ||
242- disabled ||
243- ! wheel . wheelDisabled ||
244- panning . disabled ||
245- ! panning . wheelPanning ||
246- event . ctrlKey
247- ) {
248- return ;
249- }
262+ const { onPanning } = this . props ;
263+ const { trackPadPanning } = this . setup ;
264+ const { lockAxisX, lockAxisY } = trackPadPanning ;
265+
266+ const isAllowed = isWheelPanningAllowed ( this , event ) ;
267+
268+ if ( ! isAllowed ) return ;
250269
251270 event . preventDefault ( ) ;
252271 event . stopPropagation ( ) ;
253272
254273 const { positionX, positionY } = this . state ;
255274 const mouseX = positionX - event . deltaX ;
256275 const mouseY = positionY - event . deltaY ;
257- const newPositionX = panning . lockAxisX ? positionX : mouseX ;
258- const newPositionY = panning . lockAxisY ? positionY : mouseY ;
276+ const newPositionX = lockAxisX ? positionX : mouseX ;
277+ const newPositionY = lockAxisY ? positionY : mouseY ;
259278
260279 const { sizeX, sizeY } = this . setup . autoAlignment ;
261280 const paddingValueX = getPaddingValue ( this , sizeX ) ;
262281 const paddingValueY = getPaddingValue ( this , sizeY ) ;
263282
264283 if ( newPositionX === positionX && newPositionY === positionY ) return ;
265284
285+ handleWheelPanningStart ( this , event ) ;
266286 handleNewPosition (
267287 this ,
268288 newPositionX ,
269289 newPositionY ,
270290 paddingValueX ,
271291 paddingValueY ,
272292 ) ;
293+ handleCallback ( getContext ( this ) , event , onPanning ) ;
294+ handleWheelPanningStop ( this , event ) ;
273295 } ;
274296
297+ /// ///////
298+ // Pan
299+ /// ///////
300+
275301 onPanningStart = ( event : MouseEvent ) : void => {
276302 const { disabled } = this . setup ;
277303 const { onPanningStart } = this . props ;
@@ -315,10 +341,11 @@ export class ZoomPanPinch {
315341 } ;
316342
317343 onPanningStop = ( event : MouseEvent | TouchEvent ) : void => {
344+ const { velocityDisabled } = this . setup . panning ;
318345 const { onPanningStop } = this . props ;
319346
320347 if ( this . isPanning ) {
321- handlePanningEnd ( this ) ;
348+ handlePanningEnd ( this , velocityDisabled ) ;
322349 handleCallback ( getContext ( this ) , event , onPanningStop ) ;
323350 }
324351 } ;
@@ -456,6 +483,11 @@ export class ZoomPanPinch {
456483
457484 setKeyPressed = ( e : KeyboardEvent ) : void => {
458485 this . pressedKeys [ e . key ] = true ;
486+ console . log (
487+ Object . entries ( this . pressedKeys )
488+ . filter ( ( [ , pressed ] ) => pressed )
489+ . map ( ( [ key ] ) => key ) ,
490+ ) ;
459491 } ;
460492
461493 setKeyUnPressed = ( e : KeyboardEvent ) : void => {
0 commit comments