Dont allow resize window off screen
Some checks are pending
Tests / tests (push) Waiting to run

This commit is contained in:
Dustin Brett 2025-02-13 18:44:37 -08:00
parent 4e344e7be2
commit a878c530c6

View File

@ -67,7 +67,7 @@ const useRnd = (id: string): Props => {
) => { ) => {
const [, x, y] = const [, x, y] =
/translate\((-?\d+)px, (-?\d+)px\)/.exec(transform) || []; /translate\((-?\d+)px, (-?\d+)px\)/.exec(transform) || [];
const newPositon = const newPosition =
typeof x === "string" && typeof y === "string" typeof x === "string" && typeof y === "string"
? { x: pxToNum(x), y: pxToNum(y) } ? { x: pxToNum(x), y: pxToNum(y) }
: resizePosition; : resizePosition;
@ -76,21 +76,29 @@ const useRnd = (id: string): Props => {
const newSize = { height: pxToNum(height), width: pxToNum(width) }; const newSize = { height: pxToNum(height), width: pxToNum(width) };
if (newPositon.y < 0) { if (newPosition.y < 0) {
newSize.height += newPositon.y; newSize.height += newPosition.y;
newPositon.y = 0; newPosition.y = 0;
} }
setSize(newSize); if (
setPosition(newPositon); !isWindowOutsideBounds(
setWindowStates((currentWindowStates) => ({ { position: newPosition, size: newSize },
...currentWindowStates, getWindowViewport(),
[id]: { true
...currentWindowStates[id], )
position: newPositon, ) {
size: newSize, setSize(newSize);
}, setPosition(newPosition);
})); setWindowStates((currentWindowStates) => ({
...currentWindowStates,
[id]: {
...currentWindowStates[id],
position: newPosition,
size: newSize,
},
}));
}
}, },
[id, setPosition, setSize, setWindowStates] [id, setPosition, setSize, setWindowStates]
); );