import clsx from "clsx"; import { Popover } from "./Popover"; import { t } from "../i18n"; import "./ContextMenu.scss"; import { getShortcutFromShortcutName, ShortcutName, } from "../actions/shortcuts"; import { Action } from "../actions/types"; import { ActionManager } from "../actions/manager"; import { useExcalidrawAppState, useExcalidrawElements, useExcalidrawSetAppState, } from "./App"; import React from "react"; export type ContextMenuItem = typeof CONTEXT_MENU_SEPARATOR | Action; export type ContextMenuItems = (ContextMenuItem | false | null | undefined)[]; type ContextMenuProps = { actionManager: ActionManager; items: ContextMenuItems; top: number; left: number; }; export const CONTEXT_MENU_SEPARATOR = "separator"; export const ContextMenu = React.memo( ({ actionManager, items, top, left }: ContextMenuProps) => { const appState = useExcalidrawAppState(); const setAppState = useExcalidrawSetAppState(); const elements = useExcalidrawElements(); const filteredItems = items.reduce((acc: ContextMenuItem[], item) => { if ( item && (item === CONTEXT_MENU_SEPARATOR || !item.predicate || item.predicate( elements, appState, actionManager.app.props, actionManager.app, )) ) { acc.push(item); } return acc; }, []); return ( setAppState({ contextMenu: null })} top={top} left={left} fitInViewport={true} offsetLeft={appState.offsetLeft} offsetTop={appState.offsetTop} viewportWidth={appState.width} viewportHeight={appState.height} > ); }, );