|
|
|
@ -11,6 +11,7 @@ import {
|
|
|
|
|
import { Action } from "../actions/types";
|
|
|
|
|
import { ActionManager } from "../actions/manager";
|
|
|
|
|
import { AppState } from "../types";
|
|
|
|
|
import { NonDeletedExcalidrawElement } from "../element/types";
|
|
|
|
|
|
|
|
|
|
export type ContextMenuOption = "separator" | Action;
|
|
|
|
|
|
|
|
|
@ -21,6 +22,7 @@ type ContextMenuProps = {
|
|
|
|
|
left: number;
|
|
|
|
|
actionManager: ActionManager;
|
|
|
|
|
appState: Readonly<AppState>;
|
|
|
|
|
elements: readonly NonDeletedExcalidrawElement[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const ContextMenu = ({
|
|
|
|
@ -30,6 +32,7 @@ const ContextMenu = ({
|
|
|
|
|
left,
|
|
|
|
|
actionManager,
|
|
|
|
|
appState,
|
|
|
|
|
elements,
|
|
|
|
|
}: ContextMenuProps) => {
|
|
|
|
|
return (
|
|
|
|
|
<Popover
|
|
|
|
@ -52,9 +55,14 @@ const ContextMenu = ({
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const actionName = option.name;
|
|
|
|
|
const label = option.contextItemLabel
|
|
|
|
|
? t(option.contextItemLabel)
|
|
|
|
|
: "";
|
|
|
|
|
let label = "";
|
|
|
|
|
if (option.contextItemLabel) {
|
|
|
|
|
if (typeof option.contextItemLabel === "function") {
|
|
|
|
|
label = t(option.contextItemLabel(elements, appState));
|
|
|
|
|
} else {
|
|
|
|
|
label = t(option.contextItemLabel);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return (
|
|
|
|
|
<li key={idx} data-testid={actionName} onClick={onCloseRequest}>
|
|
|
|
|
<button
|
|
|
|
@ -101,6 +109,7 @@ type ContextMenuParams = {
|
|
|
|
|
actionManager: ContextMenuProps["actionManager"];
|
|
|
|
|
appState: Readonly<AppState>;
|
|
|
|
|
container: HTMLElement;
|
|
|
|
|
elements: readonly NonDeletedExcalidrawElement[];
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleClose = (container: HTMLElement) => {
|
|
|
|
@ -129,6 +138,7 @@ export default {
|
|
|
|
|
onCloseRequest={() => handleClose(params.container)}
|
|
|
|
|
actionManager={params.actionManager}
|
|
|
|
|
appState={params.appState}
|
|
|
|
|
elements={params.elements}
|
|
|
|
|
/>,
|
|
|
|
|
getContextMenuNode(params.container),
|
|
|
|
|
);
|
|
|
|
|