Skip to content

Commit

Permalink
feat: Expose ActionManager.registerAction through `ExcalidrawImpera…
Browse files Browse the repository at this point in the history
…tiveAPI` (excalidraw#6995)

* feat: Expose `ActionManager` through `ExcalidrawImperativeAPI`

* Only expose `registerAction` instead of `ActionManager`
  • Loading branch information
DanielJGeiger committed Nov 22, 2023
1 parent 7c9cf30 commit d1e4421
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -565,6 +565,12 @@ class App extends React.Component<AppProps, AppState> {
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");
Expand All @@ -585,6 +591,9 @@ class App extends React.Component<AppProps, AppState> {
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,
Expand Down Expand Up @@ -614,12 +623,6 @@ class App extends React.Component<AppProps, AppState> {
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));
Expand Down
2 changes: 2 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -621,6 +622,7 @@ export type ExcalidrawImperativeAPI = {
getSceneElements: InstanceType<typeof App>["getSceneElements"];
getAppState: () => InstanceType<typeof App>["state"];
getFiles: () => InstanceType<typeof App>["files"];
registerAction: (action: Action) => void;
refresh: InstanceType<typeof App>["refresh"];
setToast: InstanceType<typeof App>["setToast"];
addFiles: (data: BinaryFileData[]) => void;
Expand Down

0 comments on commit d1e4421

Please sign in to comment.