diff --git a/src/components/Actions.tsx b/src/components/Actions.tsx index cd599309..4010f98a 100644 --- a/src/components/Actions.tsx +++ b/src/components/Actions.tsx @@ -1,7 +1,7 @@ import React, { useState } from "react"; import { ActionManager } from "../actions/manager"; import { getNonDeletedElements } from "../element"; -import { ExcalidrawElement, PointerType } from "../element/types"; +import { ExcalidrawElement } from "../element/types"; import { t } from "../i18n"; import { useDevice } from "../components/App"; import { @@ -213,15 +213,11 @@ export const SelectedShapeActions = ({ }; export const ShapesSwitcher = ({ - interactiveCanvas, activeTool, - onImageAction, appState, app, }: { - interactiveCanvas: HTMLCanvasElement | null; activeTool: UIAppState["activeTool"]; - onImageAction: (data: { pointerType: PointerType | null }) => void; appState: UIAppState; app: AppClassProperties; }) => { @@ -263,9 +259,13 @@ export const ShapesSwitcher = ({ if (appState.activeTool.type !== value) { trackEvent("toolbar", value, "ui"); } - app.setActiveTool({ type: value }); if (value === "image") { - onImageAction({ pointerType }); + app.setActiveTool({ + type: value, + insertOnCanvasDirectly: pointerType !== "mouse", + }); + } else { + app.setActiveTool({ type: value }); } }} /> diff --git a/src/components/App.tsx b/src/components/App.tsx index 4ad7b889..d0f618d8 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -1188,7 +1188,6 @@ class App extends React.Component { > { this.state.zenModeEnabled } UIOptions={this.props.UIOptions} - onImageAction={this.onImageAction} onExportImage={this.onExportImage} renderWelcomeScreen={ !this.state.isLoading && @@ -3135,9 +3133,13 @@ class App extends React.Component { setActiveTool = ( tool: - | { - type: ToolType; - } + | ( + | { type: Exclude } + | { + type: Extract; + insertOnCanvasDirectly?: boolean; + } + ) | { type: "custom"; customType: string }, ) => { const nextActiveTool = updateActiveTool(this.state, tool); @@ -3153,7 +3155,10 @@ class App extends React.Component { this.setState({ suggestedBindings: [] }); } if (nextActiveTool.type === "image") { - this.onImageAction(); + this.onImageAction({ + insertOnCanvasDirectly: + (tool.type === "image" && tool.insertOnCanvasDirectly) ?? false, + }); } this.setState((prevState) => { @@ -7353,9 +7358,11 @@ class App extends React.Component { } }; - private onImageAction = async ( - { insertOnCanvasDirectly } = { insertOnCanvasDirectly: false }, - ) => { + private onImageAction = async ({ + insertOnCanvasDirectly, + }: { + insertOnCanvasDirectly: boolean; + }) => { try { const clientX = this.state.width / 2 + this.state.offsetLeft; const clientY = this.state.height / 2 + this.state.offsetTop; diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsx index 59ac60a7..580d2437 100644 --- a/src/components/LayerUI.tsx +++ b/src/components/LayerUI.tsx @@ -62,7 +62,6 @@ interface LayerUIProps { appState: UIAppState; files: BinaryFiles; canvas: HTMLCanvasElement; - interactiveCanvas: HTMLCanvasElement | null; setAppState: React.Component["setState"]; elements: readonly NonDeletedExcalidrawElement[]; onLockToggle: () => void; @@ -73,7 +72,6 @@ interface LayerUIProps { renderTopRightUI?: ExcalidrawProps["renderTopRightUI"]; renderCustomStats?: ExcalidrawProps["renderCustomStats"]; UIOptions: AppProps["UIOptions"]; - onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void; onExportImage: AppClassProperties["onExportImage"]; renderWelcomeScreen: boolean; children?: React.ReactNode; @@ -123,7 +121,6 @@ const LayerUI = ({ setAppState, elements, canvas, - interactiveCanvas, onLockToggle, onHandToolToggle, onPenModeToggle, @@ -131,7 +128,6 @@ const LayerUI = ({ renderTopRightUI, renderCustomStats, UIOptions, - onImageAction, onExportImage, renderWelcomeScreen, children, @@ -280,14 +276,8 @@ const LayerUI = ({ { - onImageAction({ - insertOnCanvasDirectly: pointerType !== "mouse", - }); - }} /> @@ -472,8 +462,6 @@ const LayerUI = ({ onLockToggle={onLockToggle} onHandToolToggle={onHandToolToggle} onPenModeToggle={onPenModeToggle} - interactiveCanvas={interactiveCanvas} - onImageAction={onImageAction} renderTopRightUI={renderTopRightUI} renderCustomStats={renderCustomStats} renderSidebars={renderSidebars} @@ -560,18 +548,8 @@ const areEqual = (prevProps: LayerUIProps, nextProps: LayerUIProps) => { return false; } - const { - canvas: _pC, - interactiveCanvas: _pIC, - appState: prevAppState, - ...prev - } = prevProps; - const { - canvas: _nC, - interactiveCanvas: _nIC, - appState: nextAppState, - ...next - } = nextProps; + const { canvas: _pC, appState: prevAppState, ...prev } = prevProps; + const { canvas: _nC, appState: nextAppState, ...next } = nextProps; return ( isShallowEqual( diff --git a/src/components/MobileMenu.tsx b/src/components/MobileMenu.tsx index b7f0ba33..bb26fe71 100644 --- a/src/components/MobileMenu.tsx +++ b/src/components/MobileMenu.tsx @@ -36,9 +36,7 @@ type MobileMenuProps = { onLockToggle: () => void; onHandToolToggle: () => void; onPenModeToggle: () => void; - interactiveCanvas: HTMLCanvasElement | null; - onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void; renderTopRightUI?: ( isMobile: boolean, appState: UIAppState, @@ -58,8 +56,7 @@ export const MobileMenu = ({ onLockToggle, onHandToolToggle, onPenModeToggle, - interactiveCanvas, - onImageAction, + renderTopRightUI, renderCustomStats, renderSidebars, @@ -85,14 +82,8 @@ export const MobileMenu = ({ { - onImageAction({ - insertOnCanvasDirectly: pointerType !== "mouse", - }); - }} />