import React from "react"; import { AppState, Device, ExcalidrawProps } from "../types"; import { ActionManager } from "../actions/manager"; import { t } from "../i18n"; import Stack from "./Stack"; import { showSelectedShapeActions } from "../element"; import { NonDeletedExcalidrawElement } from "../element/types"; import { FixedSideContainer } from "./FixedSideContainer"; import { Island } from "./Island"; import { HintViewer } from "./HintViewer"; import { calculateScrollCenter } from "../scene"; import { SelectedShapeActions, ShapesSwitcher } from "./Actions"; import { Section } from "./Section"; import CollabButton from "./CollabButton"; import { SCROLLBAR_WIDTH, SCROLLBAR_MARGIN } from "../scene/scrollbars"; import { LockButton } from "./LockButton"; import { UserList } from "./UserList"; import { LibraryButton } from "./LibraryButton"; import { PenModeButton } from "./PenModeButton"; import { Stats } from "./Stats"; import { actionToggleStats } from "../actions"; import { MenuLinks, Separator } from "./MenuUtils"; import WelcomeScreen from "./WelcomeScreen"; import MenuItem from "./MenuItem"; import { ExportImageIcon } from "./icons"; type MobileMenuProps = { appState: AppState; actionManager: ActionManager; renderJSONExportDialog: () => React.ReactNode; renderImageExportDialog: () => React.ReactNode; setAppState: React.Component["setState"]; elements: readonly NonDeletedExcalidrawElement[]; onCollabButtonClick?: () => void; onLockToggle: () => void; onPenModeToggle: () => void; canvas: HTMLCanvasElement | null; isCollaborating: boolean; renderCustomFooter?: ( isMobile: boolean, appState: AppState, ) => JSX.Element | null; onImageAction: (data: { insertOnCanvasDirectly: boolean }) => void; renderTopRightUI?: ( isMobile: boolean, appState: AppState, ) => JSX.Element | null; renderCustomStats?: ExcalidrawProps["renderCustomStats"]; renderSidebars: () => JSX.Element | null; device: Device; renderWelcomeScreen?: boolean; }; export const MobileMenu = ({ appState, elements, actionManager, renderJSONExportDialog, renderImageExportDialog, setAppState, onCollabButtonClick, onLockToggle, onPenModeToggle, canvas, isCollaborating, renderCustomFooter, onImageAction, renderTopRightUI, renderCustomStats, renderSidebars, device, renderWelcomeScreen, }: MobileMenuProps) => { const renderToolbar = () => { return ( {renderWelcomeScreen && !appState.isLoading && ( )}
{(heading: React.ReactNode) => ( {heading} {/*
*/} { onImageAction({ insertOnCanvasDirectly: pointerType !== "mouse", }); }} />
{renderTopRightUI && renderTopRightUI(true, appState)}
{!appState.viewModeEnabled && ( )}
)}
); }; const renderAppToolbar = () => { if (appState.viewModeEnabled) { return (
{actionManager.renderAction("toggleCanvasMenu")}
); } return (
{actionManager.renderAction("toggleCanvasMenu")} {actionManager.renderAction("toggleEditMenu")} {actionManager.renderAction("undo")} {actionManager.renderAction("redo")} {actionManager.renderAction( appState.multiElement ? "finalize" : "duplicateSelection", )} {actionManager.renderAction("deleteSelectedElements")}
); }; const renderCanvasActions = () => { if (appState.viewModeEnabled) { return ( <> {renderJSONExportDialog()} setAppState({ openDialog: "imageExport" })} /> {renderImageExportDialog()} ); } return ( <> {!appState.viewModeEnabled && actionManager.renderAction("loadScene")} {renderJSONExportDialog()} {renderImageExportDialog()} setAppState({ openDialog: "imageExport" })} /> {onCollabButtonClick && ( )} {actionManager.renderAction("toggleShortcuts", undefined, true)} {!appState.viewModeEnabled && actionManager.renderAction("clearCanvas")} {!appState.viewModeEnabled && (
{t("labels.canvasBackground")}
{actionManager.renderAction("changeViewBackgroundColor")}
)} {actionManager.renderAction("toggleTheme")} ); }; return ( <> {renderSidebars()} {!appState.viewModeEnabled && renderToolbar()} {!appState.openMenu && appState.showStats && ( { actionManager.executeAction(actionToggleStats); }} renderCustomStats={renderCustomStats} /> )}
{appState.openMenu === "canvas" ? (
{renderCanvasActions()} {renderCustomFooter?.(true, appState)} {appState.collaborators.size > 0 && (
{t("labels.collaborators")}
)}
) : appState.openMenu === "shape" && !appState.viewModeEnabled && showSelectedShapeActions(appState, elements) ? (
) : null}
); };