mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
feat: support excalidrawAPI and remove refs support (#7251)
* feat: support excalidrawAPI and remove refs support * update changelog * remove ready and readyPromise * update changelog * update changelog
This commit is contained in:
parent
864c0b3ea8
commit
cee00767df
8 changed files with 32 additions and 47 deletions
|
@ -240,7 +240,6 @@ import {
|
|||
isInputLike,
|
||||
isToolIcon,
|
||||
isWritableElement,
|
||||
resolvablePromise,
|
||||
sceneCoordsToViewportCoords,
|
||||
tupleToCoors,
|
||||
viewportCoordsToSceneCoords,
|
||||
|
@ -540,7 +539,7 @@ class App extends React.Component<AppProps, AppState> {
|
|||
super(props);
|
||||
const defaultAppState = getDefaultAppState();
|
||||
const {
|
||||
excalidrawRef,
|
||||
excalidrawAPI,
|
||||
viewModeEnabled = false,
|
||||
zenModeEnabled = false,
|
||||
gridModeEnabled = false,
|
||||
|
@ -571,14 +570,8 @@ class App extends React.Component<AppProps, AppState> {
|
|||
this.rc = rough.canvas(this.canvas);
|
||||
this.renderer = new Renderer(this.scene);
|
||||
|
||||
if (excalidrawRef) {
|
||||
const readyPromise =
|
||||
("current" in excalidrawRef && excalidrawRef.current?.readyPromise) ||
|
||||
resolvablePromise<ExcalidrawImperativeAPI>();
|
||||
|
||||
if (excalidrawAPI) {
|
||||
const api: ExcalidrawImperativeAPI = {
|
||||
ready: true,
|
||||
readyPromise,
|
||||
updateScene: this.updateScene,
|
||||
updateLibrary: this.library.updateLibrary,
|
||||
addFiles: this.addFiles,
|
||||
|
@ -603,12 +596,11 @@ class App extends React.Component<AppProps, AppState> {
|
|||
onPointerDown: (cb) => this.onPointerDownEmitter.on(cb),
|
||||
onPointerUp: (cb) => this.onPointerUpEmitter.on(cb),
|
||||
} as const;
|
||||
if (typeof excalidrawRef === "function") {
|
||||
excalidrawRef(api);
|
||||
if (typeof excalidrawAPI === "function") {
|
||||
excalidrawAPI(api);
|
||||
} else {
|
||||
excalidrawRef.current = api;
|
||||
console.error("excalidrawAPI should be a function!");
|
||||
}
|
||||
readyPromise.resolve(api);
|
||||
}
|
||||
|
||||
this.excalidrawContainerValue = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue