Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/image viewer: tweak
Adorian Doran3725a1535467
diff --git a/apps/client/src/widgets/react/ImageViewer.tsx b/apps/client/src/widgets/react/ImageViewer.tsxindex c3e599cd04..2ef4426e52 100644--- a/apps/client/src/widgets/react/ImageViewer.tsx+++ b/apps/client/src/widgets/react/ImageViewer.tsx@@ -7,6 +7,7 @@ interface ImageViewerProps {src: string;imgClassName?: string;alt?: string;+ minScale?: number;maxScale?: number;/** Exposes the zoom/pan instance so the parent can drive zoom in/out/reset. */apiRef?: Ref<ReactZoomPanPinchRef>;@@ -16,12 +17,16 @@ interface ImageViewerProps {* Interactive image viewer: the image is fit to the viewport on load, then the user can zoom* (wheel/pinch/buttons) and pan (drag). Double-clicking resets back to the fitted view.*/-export default function ImageViewer({ src, imgClassName, alt = "", maxScale = 50, apiRef }: ImageViewerProps) {+export default function ImageViewer({ src, imgClassName, alt = "", minScale = 0.5, maxScale = 50, apiRef }: ImageViewerProps) {return (<TransformWrapperref={apiRef}+ minScale={minScale}maxScale={maxScale}centerOnInit+ centerZoomedOut+ wheel={{ step: 0.0085 }}+ autoAlignment={{ disabled: true }}doubleClick={{ mode: "reset" }}><TransformComponent wrapperClass="image-viewer-viewport" contentClass="image-viewer-content">diff --git a/apps/client/src/widgets/type_widgets/Image.tsx b/apps/client/src/widgets/type_widgets/Image.tsxindex d65d41b854..dee60fc0b5 100644--- a/apps/client/src/widgets/type_widgets/Image.tsx+++ b/apps/client/src/widgets/type_widgets/Image.tsx@@ -11,6 +11,8 @@ import ImageViewer from "../react/ImageViewer";import { refToJQuerySelector } from "../react/react_utils";import { TypeWidgetProps } from "./type_widget";+const ZOOM_STEP = 0.5;+export default function Image({ note, ntxId }: TypeWidgetProps) {const containerRef = useRef<HTMLDivElement>(null);const copyRef = useRef<HTMLDivElement>(null);@@ -33,8 +35,8 @@ export default function Image({ note, ntxId }: TypeWidgetProps) {useTriliumEvents([ "imageZoomIn", "imageZoomOut", "imageZoomReset" ], ({ ntxId: eventNtxId }, eventName) => {const zoom = zoomRef.current;if (eventNtxId !== ntxId || !zoom) return;- if (eventName === "imageZoomIn") zoom.zoomIn();- else if (eventName === "imageZoomOut") zoom.zoomOut();+ if (eventName === "imageZoomIn") zoom.zoomIn(ZOOM_STEP);+ else if (eventName === "imageZoomOut") zoom.zoomOut(ZOOM_STEP);else zoom.resetTransform();});