fix: Only expose registerAction instead of ActionManager in the API

This commit is contained in:
Daniel J. Geiger 2023-11-03 19:12:46 -05:00
parent daf305af34
commit c456c1e713
4 changed files with 9 additions and 16 deletions

View file

@ -40,7 +40,7 @@ import {
import { createRedoAction, createUndoAction } from "../actions/actionHistory";
import { ActionManager } from "../actions/manager";
import { actions } from "../actions/register";
import { ActionResult } from "../actions/types";
import { Action, ActionResult } from "../actions/types";
import { trackEvent } from "../analytics";
import {
getDefaultAppState,
@ -601,7 +601,9 @@ class App extends React.Component<AppProps, AppState> {
getSceneElements: this.getSceneElements,
getAppState: () => this.state,
getFiles: () => this.files,
actionManager: this.actionManager,
registerAction: (action: Action) => {
this.actionManager.registerAction(action);
},
addSubtype: this.addSubtype,
refresh: this.refresh,
setToast: this.setToast,
@ -649,11 +651,7 @@ class App extends React.Component<AppProps, AppState> {
this.refresh();
}
};
const prep = prepareSubtype(record, subtypePrepFn, subtypeLoadedCb);
if (prep.actions) {
this.actionManager.registerAll(prep.actions);
}
return prep;
return prepareSubtype(record, subtypePrepFn, subtypeLoadedCb);
}
private onWindowMessage(event: MessageEvent) {

View file

@ -484,6 +484,9 @@ export const useSubtype = (
const prep = api.addSubtype(record, subtypePrepFn);
if (prep) {
addSubtypeMethods(record.subtype, prep.methods);
if (prep.actions) {
prep.actions.forEach((action) => api.registerAction(action));
}
}
}
}, [api, record, subtypePrepFn]);

View file

@ -22,7 +22,6 @@ import {
checkRefreshOnSubtypeLoad,
prepareSubtype,
selectSubtype,
subtypeActionPredicate,
} from "../../element/subtypes";
import {
maybeGetSubtypeProps,
@ -42,13 +41,6 @@ const readFile = util.promisify(fs.readFile);
const { h } = window;
export class API {
constructor() {
h.app.actionManager.registerActionPredicate(subtypeActionPredicate);
if (true) {
// Call `prepareSubtype()` here for `@excalidraw/excalidraw`-specific subtypes
}
}
static addSubtype = (record: SubtypeRecord, subtypePrepFn: SubtypePrepFn) => {
const subtypeLoadedCb: SubtypeLoadedCb = (hasSubtype) => {
if (checkRefreshOnSubtypeLoad(hasSubtype, h.elements)) {

View file

@ -634,7 +634,7 @@ export type ExcalidrawImperativeAPI = {
getSceneElements: InstanceType<typeof App>["getSceneElements"];
getAppState: () => InstanceType<typeof App>["state"];
getFiles: () => InstanceType<typeof App>["files"];
actionManager: InstanceType<typeof App>["actionManager"];
registerAction: (action: Action) => void;
addSubtype: (
record: SubtypeRecord,
subtypePrepFn: SubtypePrepFn,