diff --git a/src/components/App.tsx b/src/components/App.tsx index ccb01030..0892a40a 100644 --- a/src/components/App.tsx +++ b/src/components/App.tsx @@ -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, @@ -565,6 +565,12 @@ class App extends React.Component { this.id = nanoid(); this.library = new Library(this); + this.actionManager = new ActionManager( + this.syncActionResult, + () => this.state, + () => this.scene.getElementsIncludingDeleted(), + this, + ); this.scene = new Scene(); this.canvas = document.createElement("canvas"); @@ -585,6 +591,9 @@ class App extends React.Component { getSceneElements: this.getSceneElements, getAppState: () => this.state, getFiles: () => this.files, + registerAction: (action: Action) => { + this.actionManager.registerAction(action); + }, refresh: this.refresh, setToast: this.setToast, id: this.id, @@ -614,12 +623,6 @@ class App extends React.Component { onSceneUpdated: this.onSceneUpdated, }); this.history = new History(); - this.actionManager = new ActionManager( - this.syncActionResult, - () => this.state, - () => this.scene.getElementsIncludingDeleted(), - this, - ); this.actionManager.registerAll(actions); this.actionManager.registerAction(createUndoAction(this.history)); diff --git a/src/types.ts b/src/types.ts index 8884ae49..32eb044b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -18,6 +18,7 @@ import { ExcalidrawFrameElement, ExcalidrawEmbeddableElement, } from "./element/types"; +import { Action } from "./actions/types"; import { Point as RoughPoint } from "roughjs/bin/geometry"; import { LinearElementEditor } from "./element/linearElementEditor"; import { SuggestedBinding } from "./element/binding"; @@ -621,6 +622,7 @@ export type ExcalidrawImperativeAPI = { getSceneElements: InstanceType["getSceneElements"]; getAppState: () => InstanceType["state"]; getFiles: () => InstanceType["files"]; + registerAction: (action: Action) => void; refresh: InstanceType["refresh"]; setToast: InstanceType["setToast"]; addFiles: (data: BinaryFileData[]) => void;