From acc9becf1a06d4192f6cd2b8e1021f0e86d021e8 Mon Sep 17 00:00:00 2001 From: infinia-yzl Date: Wed, 14 Aug 2024 15:41:54 +0800 Subject: [PATCH 1/2] feat(toggle-pan): Add toggle to switch between scroll to pan and scroll to zoom - Modify wheel behaviour to pan by default for a more natural behaviour with trackpads (https://github.com/BetterTyped/react-zoom-pan-pinch/pull/447) - Bump `react-zoom-pan-pinch` version to `3.6.1` from `3.4.4` --- apps/artboard/src/pages/builder.tsx | 13 ++++++++++- .../src/pages/builder/_components/toolbar.tsx | 22 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/apps/artboard/src/pages/builder.tsx b/apps/artboard/src/pages/builder.tsx index f339eca38..9272d6ea7 100644 --- a/apps/artboard/src/pages/builder.tsx +++ b/apps/artboard/src/pages/builder.tsx @@ -1,7 +1,7 @@ import { SectionKey } from "@reactive-resume/schema"; import { pageSizeMap, Template } from "@reactive-resume/utils"; import { AnimatePresence, motion } from "framer-motion"; -import { useEffect, useMemo, useRef } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { ReactZoomPanPinchRef, TransformComponent, TransformWrapper } from "react-zoom-pan-pinch"; import { MM_TO_PX, Page } from "../components/page"; @@ -14,6 +14,8 @@ export const BuilderLayout = () => { const layout = useArtboardStore((state) => state.resume.metadata.layout); const template = useArtboardStore((state) => state.resume.metadata.template as Template); + const [wheelPanning, setWheelPanning] = useState(true); + const Template = useMemo(() => getTemplate(template), [template]); useEffect(() => { @@ -27,6 +29,9 @@ export const BuilderLayout = () => { transformRef.current?.resetTransform(0); setTimeout(() => transformRef.current?.centerView(0.8, 0), 10); } + if (event.data.type === "TOGGLE_PAN_MODE") { + setWheelPanning(event.data.panMode); + } }; window.addEventListener("message", handleMessage); @@ -44,6 +49,12 @@ export const BuilderLayout = () => { minScale={0.4} initialScale={0.8} limitToBounds={false} + panning={{ + wheelPanning: wheelPanning, + }} + wheel={{ + wheelDisabled: wheelPanning, + }} > { const win = window.open(url, "_blank"); @@ -31,6 +34,7 @@ export const BuilderToolbar = () => { const undo = useTemporalResumeStore((state) => state.undo); const redo = useTemporalResumeStore((state) => state.redo); const frameRef = useBuilderStore((state) => state.frame.ref); + const [panMode, setPanMode] = useState(true); const id = useResumeStore((state) => state.resume.id); const isPublic = useResumeStore((state) => state.resume.visibility === "public"); @@ -59,6 +63,10 @@ export const BuilderToolbar = () => { const onZoomOut = () => frameRef?.contentWindow?.postMessage({ type: "ZOOM_OUT" }, "*"); const onResetView = () => frameRef?.contentWindow?.postMessage({ type: "RESET_VIEW" }, "*"); const onCenterView = () => frameRef?.contentWindow?.postMessage({ type: "CENTER_VIEW" }, "*"); + const onTogglePanMode = () => { + setPanMode(!panMode); // local button state + frameRef?.contentWindow?.postMessage({ type: "TOGGLE_PAN_MODE", panMode: !panMode }, "*"); // toggle artboard state + }; return ( @@ -91,6 +99,20 @@ export const BuilderToolbar = () => { + + + {panMode ? : } + + + + +