mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Filter context menu items through isActionEnabled
.
This commit is contained in:
parent
01432813a6
commit
a5bd54b86d
5 changed files with 51 additions and 35 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue