Virtual whiteboard for sketching hand-drawn like diagrams
fix: double image dialog shown on insert (#7152)
David Luzaraaf73c8ff31f
diff --git a/src/components/Actions.tsx b/src/components/Actions.tsxindex cd5993097e..4010f98ab4 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.tsxindex 4ad7b889e9..d0f618d894 100644--- a/src/components/App.tsx+++ b/src/components/App.tsx@@ -1188,7 +1188,6 @@ class App extends React.Component<AppProps, AppState> {><LayerUIcanvas={this.canvas}- interactiveCanvas={this.interactiveCanvas}appState={this.state}files={this.files}setAppState={this.setAppState}@@ -1205,7 +1204,6 @@ class App extends React.Component<AppProps, AppState> {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<AppProps, AppState> {setActiveTool = (tool:- | {- type: ToolType;- }+ | (+ | { type: Exclude<ToolType, "image"> }+ | {+ type: Extract<ToolType, "image">;+ insertOnCanvasDirectly?: boolean;+ }+ )| { type: "custom"; customType: string },) => {const nextActiveTool = updateActiveTool(this.state, tool);@@ -3153,7 +3155,10 @@ class App extends React.Component<AppProps, AppState> {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<AppProps, AppState> {}};- 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.tsxindex 59ac60a763..580d243754 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<any, AppState>["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 = ({<ShapesSwitcherappState={appState}- interactiveCanvas={interactiveCanvas}activeTool={appState.activeTool}app={app}- onImageAction={({ pointerType }) => {- onImageAction({- insertOnCanvasDirectly: pointerType !== "mouse",- });- }}/></Stack.Row></Island>@@ -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.tsxindex b7f0ba3338..bb26fe7136 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 = ({<Stack.Row gap={1}><ShapesSwitcherappState={appState}- interactiveCanvas={interactiveCanvas}activeTool={appState.activeTool}app={app}- onImageAction={({ pointerType }) => {- onImageAction({- insertOnCanvasDirectly: pointerType !== "mouse",- });- }}/></Stack.Row></Island>