Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new util handler ZoomToElement, docs for handlers and many fixes
- Loading branch information
Maciej Pyrc
committed
Jun 26, 2021
1 parent
992cf22
commit e547f53
Showing
18 changed files
with
479 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { ReactZoomPanPinchContext } from "../../models"; | ||
|
||
import { animate } from "../animations/animations.utils"; | ||
import { getMousePosition } from "core/zoom/wheel.utils"; | ||
import { handleZoomToPoint } from "core/zoom/zoom.logic"; | ||
import { isExcludedNode } from "utils"; | ||
import { | ||
handleCalculateButtonZoom, | ||
resetTransformations, | ||
} from "core/handlers/handlers.utils"; | ||
|
||
export function handleDoubleClick( | ||
contextInstance: ReactZoomPanPinchContext, | ||
event: MouseEvent, | ||
): void { | ||
const { | ||
disabled, | ||
mode, | ||
step, | ||
animationTime, | ||
animationType, | ||
} = contextInstance.setup.doubleClick; | ||
|
||
if (disabled) return; | ||
|
||
if (mode === "reset") { | ||
return resetTransformations(contextInstance, animationTime, animationType); | ||
} | ||
|
||
const { scale } = contextInstance.transformState; | ||
const { contentComponent } = contextInstance; | ||
|
||
if (!contentComponent) return console.error("No ContentComponent found"); | ||
|
||
const delta = mode === "zoomOut" ? -1 : 1; | ||
|
||
const newScale = handleCalculateButtonZoom(contextInstance, delta, step); | ||
const mousePosition = getMousePosition(event, contentComponent, scale); | ||
const targetState = handleZoomToPoint( | ||
contextInstance, | ||
newScale, | ||
mousePosition.x, | ||
mousePosition.y, | ||
); | ||
|
||
if (!targetState) { | ||
return console.error( | ||
"Error during zoom event. New transformation state was not calculated.", | ||
); | ||
} | ||
|
||
animate(contextInstance, targetState, animationTime, animationType); | ||
} | ||
|
||
export const isDoubleClickAllowed = ( | ||
contextInstance: ReactZoomPanPinchContext, | ||
event: MouseEvent, | ||
): boolean => { | ||
const { isInitialized, setup, wrapperComponent } = contextInstance; | ||
const { disabled, excluded } = setup.doubleClick; | ||
|
||
const target = event.target as HTMLElement; | ||
const isWrapperChild = wrapperComponent?.contains(target); | ||
const isAllowed = isInitialized && target && isWrapperChild && !disabled; | ||
|
||
if (!isAllowed) return false; | ||
|
||
const isExcluded = isExcludedNode(target, excluded); | ||
|
||
if (isExcluded) return false; | ||
|
||
if (!isAllowed) return false; | ||
|
||
return true; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.