mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-09-13 12:29:58 +02:00
Filter context menu items through isActionEnabled
.
This commit is contained in:
@@ -6167,20 +6167,29 @@ class App extends React.Component<AppProps, AppState> {
|
||||
type: "canvas" | "element" | "custom",
|
||||
source?: string,
|
||||
): ContextMenuItems => {
|
||||
const options: ContextMenuItems = [];
|
||||
let addedCustom = false;
|
||||
const custom: ContextMenuItems = [];
|
||||
this.actionManager
|
||||
.getCustomActions({ data: { source } })
|
||||
.forEach((action) => {
|
||||
addedCustom = true;
|
||||
options.push(action);
|
||||
});
|
||||
.getCustomActions({ data: { source: source ?? "" } })
|
||||
.forEach((action) => custom.push(action));
|
||||
if (type === "custom") {
|
||||
return options;
|
||||
return custom;
|
||||
}
|
||||
if (addedCustom) {
|
||||
options.push(CONTEXT_MENU_SEPARATOR);
|
||||
if (custom.length > 0) {
|
||||
custom.push(CONTEXT_MENU_SEPARATOR);
|
||||
}
|
||||
const standard: ContextMenuItems = this._getContextMenuItems(type).filter(
|
||||
(item) =>
|
||||
!item ||
|
||||
item === CONTEXT_MENU_SEPARATOR ||
|
||||
this.actionManager.isActionEnabled(item, { guardsOnly: true }),
|
||||
);
|
||||
return [...custom, ...standard];
|
||||
};
|
||||
|
||||
private _getContextMenuItems = (
|
||||
type: "canvas" | "element",
|
||||
): ContextMenuItems => {
|
||||
const options: ContextMenuItems = [];
|
||||
|
||||
options.push(actionCopyAsPng, actionCopyAsSvg);
|
||||
|
||||
|
Reference in New Issue
Block a user