mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: Only expose registerAction
instead of ActionManager
in the API
This commit is contained in:
parent
daf305af34
commit
c456c1e713
4 changed files with 9 additions and 16 deletions
|
@ -40,7 +40,7 @@ import {
|
||||||
import { createRedoAction, createUndoAction } from "../actions/actionHistory";
|
import { createRedoAction, createUndoAction } from "../actions/actionHistory";
|
||||||
import { ActionManager } from "../actions/manager";
|
import { ActionManager } from "../actions/manager";
|
||||||
import { actions } from "../actions/register";
|
import { actions } from "../actions/register";
|
||||||
import { ActionResult } from "../actions/types";
|
import { Action, ActionResult } from "../actions/types";
|
||||||
import { trackEvent } from "../analytics";
|
import { trackEvent } from "../analytics";
|
||||||
import {
|
import {
|
||||||
getDefaultAppState,
|
getDefaultAppState,
|
||||||
|
@ -601,7 +601,9 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
getSceneElements: this.getSceneElements,
|
getSceneElements: this.getSceneElements,
|
||||||
getAppState: () => this.state,
|
getAppState: () => this.state,
|
||||||
getFiles: () => this.files,
|
getFiles: () => this.files,
|
||||||
actionManager: this.actionManager,
|
registerAction: (action: Action) => {
|
||||||
|
this.actionManager.registerAction(action);
|
||||||
|
},
|
||||||
addSubtype: this.addSubtype,
|
addSubtype: this.addSubtype,
|
||||||
refresh: this.refresh,
|
refresh: this.refresh,
|
||||||
setToast: this.setToast,
|
setToast: this.setToast,
|
||||||
|
@ -649,11 +651,7 @@ class App extends React.Component<AppProps, AppState> {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const prep = prepareSubtype(record, subtypePrepFn, subtypeLoadedCb);
|
return prepareSubtype(record, subtypePrepFn, subtypeLoadedCb);
|
||||||
if (prep.actions) {
|
|
||||||
this.actionManager.registerAll(prep.actions);
|
|
||||||
}
|
|
||||||
return prep;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private onWindowMessage(event: MessageEvent) {
|
private onWindowMessage(event: MessageEvent) {
|
||||||
|
|
|
@ -484,6 +484,9 @@ export const useSubtype = (
|
||||||
const prep = api.addSubtype(record, subtypePrepFn);
|
const prep = api.addSubtype(record, subtypePrepFn);
|
||||||
if (prep) {
|
if (prep) {
|
||||||
addSubtypeMethods(record.subtype, prep.methods);
|
addSubtypeMethods(record.subtype, prep.methods);
|
||||||
|
if (prep.actions) {
|
||||||
|
prep.actions.forEach((action) => api.registerAction(action));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [api, record, subtypePrepFn]);
|
}, [api, record, subtypePrepFn]);
|
||||||
|
|
|
@ -22,7 +22,6 @@ import {
|
||||||
checkRefreshOnSubtypeLoad,
|
checkRefreshOnSubtypeLoad,
|
||||||
prepareSubtype,
|
prepareSubtype,
|
||||||
selectSubtype,
|
selectSubtype,
|
||||||
subtypeActionPredicate,
|
|
||||||
} from "../../element/subtypes";
|
} from "../../element/subtypes";
|
||||||
import {
|
import {
|
||||||
maybeGetSubtypeProps,
|
maybeGetSubtypeProps,
|
||||||
|
@ -42,13 +41,6 @@ const readFile = util.promisify(fs.readFile);
|
||||||
const { h } = window;
|
const { h } = window;
|
||||||
|
|
||||||
export class API {
|
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) => {
|
static addSubtype = (record: SubtypeRecord, subtypePrepFn: SubtypePrepFn) => {
|
||||||
const subtypeLoadedCb: SubtypeLoadedCb = (hasSubtype) => {
|
const subtypeLoadedCb: SubtypeLoadedCb = (hasSubtype) => {
|
||||||
if (checkRefreshOnSubtypeLoad(hasSubtype, h.elements)) {
|
if (checkRefreshOnSubtypeLoad(hasSubtype, h.elements)) {
|
||||||
|
|
|
@ -634,7 +634,7 @@ export type ExcalidrawImperativeAPI = {
|
||||||
getSceneElements: InstanceType<typeof App>["getSceneElements"];
|
getSceneElements: InstanceType<typeof App>["getSceneElements"];
|
||||||
getAppState: () => InstanceType<typeof App>["state"];
|
getAppState: () => InstanceType<typeof App>["state"];
|
||||||
getFiles: () => InstanceType<typeof App>["files"];
|
getFiles: () => InstanceType<typeof App>["files"];
|
||||||
actionManager: InstanceType<typeof App>["actionManager"];
|
registerAction: (action: Action) => void;
|
||||||
addSubtype: (
|
addSubtype: (
|
||||||
record: SubtypeRecord,
|
record: SubtypeRecord,
|
||||||
subtypePrepFn: SubtypePrepFn,
|
subtypePrepFn: SubtypePrepFn,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue