Make filtering of custom actions optional.

This commit is contained in:
Daniel J. Geiger 2023-01-08 19:30:01 -06:00
parent 9e5948ac28
commit ddc393bd9d
2 changed files with 20 additions and 14 deletions

View file

@ -6241,29 +6241,29 @@ class App extends React.Component<AppProps, AppState> {
type: "canvas" | "element" | "custom",
source?: string,
): ContextMenuItems => {
const options = this._getContextMenuItems(type, source);
return options.filter(
const custom: ContextMenuItems = [];
this.actionManager
.getCustomActions({ data: { source: source ?? "" } })
.forEach((action) => custom.push(action));
if (type === "custom") {
return custom;
}
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" | "custom",
source?: string,
type: "canvas" | "element",
): ContextMenuItems => {
const options: ContextMenuItems = [];
this.actionManager
.getCustomActions({ data: { source: source ?? "" } })
.forEach((action) => options.push(action));
if (type === "custom") {
return options;
}
if (options.length > 0) {
options.push(CONTEXT_MENU_SEPARATOR);
}
options.push(actionCopyAsPng, actionCopyAsSvg);