This commit is contained in:
barnabasmolnar
2026-04-07 23:44:27 +02:00
parent 7dbd62a30c
commit fe3ba884f6
3 changed files with 24 additions and 18 deletions
@@ -4,9 +4,10 @@ import { Excalidraw } from "@excalidraw/excalidraw";
import "@excalidraw/excalidraw/index.css"; import "@excalidraw/excalidraw/index.css";
import App from "../../with-script-in-browser/components/ExampleApp";
import type { ScrollConstraints } from "@excalidraw/excalidraw/types"; import type { ScrollConstraints } from "@excalidraw/excalidraw/types";
import App from "../../with-script-in-browser/components/ExampleApp";
const scrollConstraints: ScrollConstraints = { const scrollConstraints: ScrollConstraints = {
x: 0, x: 0,
y: 0, y: 0,
@@ -25,9 +26,7 @@ const ExcalidrawWrapper: React.FC = () => {
useCustom={(api: any, args?: any[]) => {}} useCustom={(api: any, args?: any[]) => {}}
excalidrawLib={excalidrawLib} excalidrawLib={excalidrawLib}
> >
<Excalidraw <Excalidraw scrollConstraints={scrollConstraints} />
// scrollConstraints={scrollConstraints}
/>
</App> </App>
</> </>
); );
+9 -11
View File
@@ -4531,18 +4531,16 @@ class App extends React.Component<AppProps, AppState> {
this.setState({ shouldCacheIgnoreZoom: false }); this.setState({ shouldCacheIgnoreZoom: false });
}, },
}); });
} else if (scrollConstraints) {
this.setState({
scrollX,
scrollY,
zoom,
scrollConstraints,
viewModeEnabled: true,
});
} else { } else {
if (scrollConstraints) { this.setState({ scrollX, scrollY, zoom });
this.setState({
scrollX,
scrollY,
zoom,
scrollConstraints,
viewModeEnabled: true,
});
} else {
this.setState({ scrollX, scrollY, zoom });
}
} }
}; };
+12 -3
View File
@@ -1,6 +1,7 @@
import type { AppState, NormalizedZoomValue } from "../types";
import { constrainScrollState } from "./scrollConstraints"; import { constrainScrollState } from "./scrollConstraints";
import type { AppState, NormalizedZoomValue } from "../types";
/** /**
* When zooming out with scroll constraints active, the cursor-anchored zoom may * When zooming out with scroll constraints active, the cursor-anchored zoom may
* produce a scroll position outside the valid bounds, causing a snap-back. * produce a scroll position outside the valid bounds, causing a snap-back.
@@ -30,11 +31,19 @@ export const getConstrainedZoomAnchor = (
const newScrollY = state.scrollY + appLayerY * factor; const newScrollY = state.scrollY + appLayerY * factor;
const constrained = constrainScrollState( const constrained = constrainScrollState(
{ ...state, scrollX: newScrollX, scrollY: newScrollY, zoom: { value: nextZoom } }, {
...state,
scrollX: newScrollX,
scrollY: newScrollY,
zoom: { value: nextZoom },
},
"rigid", "rigid",
); );
if (constrained.scrollX === newScrollX && constrained.scrollY === newScrollY) { if (
constrained.scrollX === newScrollX &&
constrained.scrollY === newScrollY
) {
return { viewportX, viewportY }; return { viewportX, viewportY };
} }