From 19608b712f908806f73e65b9eadd89d26f7e4f9f Mon Sep 17 00:00:00 2001 From: Ryan Di Date: Mon, 12 May 2025 16:23:18 +1000 Subject: [PATCH] improve debug --- excalidraw-app/App.tsx | 69 ++++++++++++++++++++++++++++++++---------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/excalidraw-app/App.tsx b/excalidraw-app/App.tsx index ef56541e7..40d7f5aaf 100644 --- a/excalidraw-app/App.tsx +++ b/excalidraw-app/App.tsx @@ -67,6 +67,8 @@ import { import { useApp } from "@excalidraw/excalidraw/components/App"; +import { clamp } from "@excalidraw/math"; + import type { RemoteExcalidrawElement } from "@excalidraw/excalidraw/data/reconcile"; import type { RestoredDataState } from "@excalidraw/excalidraw/data/restore"; import type { @@ -173,9 +175,9 @@ const ConstraintsSettings = ({ const [activeFrameId, setActiveFrameId] = useState(null); useEffect(() => { - const hash = new URLSearchParams(window.location.hash.slice(1)); - hash.set("constraints", encodeConstraints(constraints)); - window.location.hash = decodeURIComponent(hash.toString()); + const params = new URLSearchParams(window.location.search); + params.set("constraints", encodeConstraints(constraints)); + history.replaceState(null, "", `?${params.toString()}`); constraints.enabled ? excalidrawAPI.setScrollConstraints(constraints) @@ -205,6 +207,26 @@ const ConstraintsSettings = ({ }); }, [excalidrawAPI]); + const parseValue = ( + value: string, + opts?: { + min?: number; + max?: number; + }, + ) => { + const { min = -Infinity, max = Infinity } = opts || {}; + let parsedValue = parseInt(value); + if (isNaN(parsedValue)) { + parsedValue = 0; + } + return clamp(parsedValue, min, max); + }; + + const inputStyle = { + width: "4rem", + height: "1rem", + }; + return (
enabled:{" "} @@ -237,54 +260,66 @@ const ConstraintsSettings = ({ x:{" "} + onChange={(e) => { setConstraints((s) => ({ ...s, - x: parseInt(e.target.value) ?? 0, - })) - } + x: parseValue(e.target.value), + })); + }} + style={inputStyle} /> y:{" "} setConstraints((s) => ({ ...s, - y: parseInt(e.target.value) ?? 0, + y: parseValue(e.target.value), })) } + style={inputStyle} /> w:{" "} setConstraints((s) => ({ ...s, - width: parseInt(e.target.value) ?? 200, + width: parseValue(e.target.value, { + min: 200, + }), })) } + style={inputStyle} /> h:{" "} setConstraints((s) => ({ ...s, - height: parseInt(e.target.value) ?? 200, + height: parseValue(e.target.value, { + min: 200, + }), })) } + style={inputStyle} /> zoomFactor: overscrollAllowance: lockZoom:{" "}