From 6ec259a0e71174651bae95d4628138bf6fd68742 Mon Sep 17 00:00:00 2001 From: kj_sh604 Date: Sun, 15 Mar 2026 16:19:35 -0400 Subject: refactor: packages/ --- .../excalidraw/element/ElementCanvasButtons.tsx | 63 ++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 packages/excalidraw/element/ElementCanvasButtons.tsx (limited to 'packages/excalidraw/element/ElementCanvasButtons.tsx') diff --git a/packages/excalidraw/element/ElementCanvasButtons.tsx b/packages/excalidraw/element/ElementCanvasButtons.tsx new file mode 100644 index 0000000..1bcad97 --- /dev/null +++ b/packages/excalidraw/element/ElementCanvasButtons.tsx @@ -0,0 +1,63 @@ +import type { AppState } from "../types"; +import { sceneCoordsToViewportCoords } from "../utils"; +import type { ElementsMap, NonDeletedExcalidrawElement } from "./types"; +import { getElementAbsoluteCoords } from "."; +import { useExcalidrawAppState } from "../components/App"; + +import "./ElementCanvasButtons.scss"; + +const CONTAINER_PADDING = 5; + +const getContainerCoords = ( + element: NonDeletedExcalidrawElement, + appState: AppState, + elementsMap: ElementsMap, +) => { + const [x1, y1] = getElementAbsoluteCoords(element, elementsMap); + const { x: viewportX, y: viewportY } = sceneCoordsToViewportCoords( + { sceneX: x1 + element.width, sceneY: y1 }, + appState, + ); + const x = viewportX - appState.offsetLeft + 10; + const y = viewportY - appState.offsetTop; + return { x, y }; +}; + +export const ElementCanvasButtons = ({ + children, + element, + elementsMap, +}: { + children: React.ReactNode; + element: NonDeletedExcalidrawElement; + elementsMap: ElementsMap; +}) => { + const appState = useExcalidrawAppState(); + + if ( + appState.contextMenu || + appState.newElement || + appState.resizingElement || + appState.isRotating || + appState.openMenu || + appState.viewModeEnabled + ) { + return null; + } + + const { x, y } = getContainerCoords(element, appState, elementsMap); + + return ( +
+ {children} +
+ ); +}; -- cgit v1.2.3