feat: support scroll to center to single element and rename setScrollToContent (#3482)

Co-authored-by: Aakansha Doshi <aakansha1216@gmail.com>
This commit is contained in:
David Luzar 2021-04-25 12:28:41 +02:00 committed by GitHub
parent 5c42cb5be4
commit 5cc3f7db80
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 5 deletions

View file

@ -287,7 +287,7 @@ export type ExcalidrawImperativeAPI = {
history: {
clear: InstanceType<typeof App>["resetHistory"];
};
setScrollToContent: InstanceType<typeof App>["setScrollToContent"];
scrollToContent: InstanceType<typeof App>["scrollToContent"];
getSceneElements: InstanceType<typeof App>["getSceneElements"];
getAppState: () => InstanceType<typeof App>["state"];
refresh: InstanceType<typeof App>["refresh"];
@ -361,7 +361,7 @@ class App extends React.Component<AppProps, AppState> {
history: {
clear: this.resetHistory,
},
setScrollToContent: this.setScrollToContent,
scrollToContent: this.scrollToContent,
getSceneElements: this.getSceneElements,
getAppState: () => this.state,
refresh: this.refresh,
@ -1421,9 +1421,17 @@ class App extends React.Component<AppProps, AppState> {
this.actionManager.executeAction(actionToggleStats);
};
setScrollToContent = (remoteElements: readonly ExcalidrawElement[]) => {
scrollToContent = (
target:
| ExcalidrawElement
| readonly ExcalidrawElement[] = this.scene.getElements(),
) => {
this.setState({
...calculateScrollCenter(remoteElements, this.state, this.canvas),
...calculateScrollCenter(
Array.isArray(target) ? target : [target],
this.state,
this.canvas,
),
});
};