Make filtering of custom actions optional.
This commit is contained in:
parent
9e5948ac28
commit
ddc393bd9d
@ -117,10 +117,16 @@ export class ActionManager {
|
||||
if (this === undefined) {
|
||||
return [];
|
||||
}
|
||||
const filter =
|
||||
opts !== undefined &&
|
||||
("elements" in opts || "data" in opts || "guardsOnly" in opts);
|
||||
const customActions: Action[] = [];
|
||||
for (const key in this.actions) {
|
||||
const action = this.actions[key];
|
||||
if (!isActionName(action.name) && this.isActionEnabled(action, opts)) {
|
||||
if (
|
||||
!isActionName(action.name) &&
|
||||
(!filter || this.isActionEnabled(action, opts))
|
||||
) {
|
||||
customActions.push(action);
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user