import { useEffect, useRef } from "react"; import type { NonDeletedSceneElementsMap } from "@excalidraw/element/types"; import { isRenderThrottlingEnabled } from "../../reactUtils"; import { renderNewElementScene } from "../../renderer/renderNewElementScene"; import type { RenderableElementsMap, StaticCanvasRenderConfig, } from "../../scene/types"; import type { AppState } from "../../types"; import type { RoughCanvas } from "roughjs/bin/canvas"; interface NewElementCanvasProps { appState: AppState; newElement: NonNullable; elementsMap: RenderableElementsMap; allElementsMap: NonDeletedSceneElementsMap; scale: number; rc: RoughCanvas; renderConfig: StaticCanvasRenderConfig; /** CSS opacity of the whole canvas — a translucent preview of a finished element */ opacity?: number; } const NewElementCanvas = (props: NewElementCanvasProps) => { const canvasRef = useRef(null); useEffect(() => { if (!canvasRef.current) { return; } renderNewElementScene( { canvas: canvasRef.current, scale: props.scale, newElement: props.newElement, elementsMap: props.elementsMap, allElementsMap: props.allElementsMap, rc: props.rc, renderConfig: props.renderConfig, appState: props.appState, }, isRenderThrottlingEnabled(), ); }); return ( ); }; export default NewElementCanvas;