mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-10-24 16:34:24 +02:00
Add appState offsetTop and offsetLeft to padding calculation.
Refactor collisionPadding calculation to use app state offsets.
This commit is contained in:
@@ -4,7 +4,7 @@ import React, { type ReactNode } from "react";
|
||||
|
||||
import { isInteractive } from "@excalidraw/common";
|
||||
|
||||
import { useDevice } from "./App";
|
||||
import { useApp, useDevice } from "./App";
|
||||
import { Island } from "./Island";
|
||||
|
||||
interface PropertiesPopoverProps {
|
||||
@@ -40,19 +40,20 @@ export const PropertiesPopover = React.forwardRef<
|
||||
ref,
|
||||
) => {
|
||||
const device = useDevice();
|
||||
const app = useApp();
|
||||
const { offsetTop, offsetLeft } = app.state;
|
||||
|
||||
const collisionPadding = React.useMemo(() => {
|
||||
if (!container) {
|
||||
return 8;
|
||||
}
|
||||
const rect = container.getBoundingClientRect();
|
||||
return {
|
||||
top: Math.max(8, rect.top),
|
||||
right: Math.max(8, window.innerWidth - rect.right),
|
||||
bottom: Math.max(8, window.innerHeight - rect.bottom),
|
||||
left: Math.max(8, rect.left),
|
||||
};
|
||||
}, [container]);
|
||||
const collisionPadding = container
|
||||
? (() => {
|
||||
const rect = container.getBoundingClientRect();
|
||||
return {
|
||||
top: Math.max(8, rect.top),
|
||||
right: Math.max(8, window.innerWidth - rect.right - offsetLeft),
|
||||
bottom: Math.max(8, window.innerHeight - rect.bottom - offsetTop),
|
||||
left: Math.max(8, rect.left),
|
||||
};
|
||||
})()
|
||||
: 8;
|
||||
|
||||
return (
|
||||
<Popover.Portal container={container}>
|
||||
|
||||
Reference in New Issue
Block a user