Update to latest Action changes.

This commit is contained in:
Daniel J. Geiger 2023-01-07 15:47:19 -06:00
parent 45faf7d58f
commit ace031e992
6 changed files with 51 additions and 72 deletions

View file

@ -75,7 +75,7 @@ export class ActionManager {
this.app = app;
}
public registerActionGuards() {
registerActionGuards() {
const disablers = getActionDisablers();
for (const d in disablers) {
const dName = d as ActionName;
@ -90,7 +90,7 @@ export class ActionManager {
}
}
private registerDisableFn(name: ActionName, disabler: DisableFn) {
registerDisableFn(name: ActionName, disabler: DisableFn) {
if (!(name in this.disablers)) {
this.disablers[name] = [] as DisableFn[];
}
@ -99,7 +99,7 @@ export class ActionManager {
}
}
private registerEnableFn(name: Action["name"], enabler: EnableFn) {
registerEnableFn(name: Action["name"], enabler: EnableFn) {
if (!(name in this.enablers)) {
this.enablers[name] = [] as EnableFn[];
}
@ -108,6 +108,25 @@ export class ActionManager {
}
}
getCustomActions(opts?: {
elements?: readonly ExcalidrawElement[];
data?: Record<string, any>;
guardsOnly?: boolean;
}): Action[] {
// For testing
if (this === undefined) {
return [];
}
const customActions: Action[] = [];
for (const key in this.actions) {
const action = this.actions[key];
if (!isActionName(action.name) && this.isActionEnabled(action, opts)) {
customActions.push(action);
}
}
return customActions;
}
registerAction(action: Action) {
this.actions[action.name] = action;
}